Changes in / [7e23d0a:02ec390]


Ignore:
Location:
src
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:40:51 2015
    13 // Update Count     : 133
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Aug 11 16:22:35 2015
     13// Update Count     : 89
    1414//
    1515
     
    4747        namespace {
    4848                const std::list<Label> noLabels;
    49 
    50                 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    5149
    5250                class Pass1 : public PolyMutator {
     
    8078                        ObjectDecl *makeTemporary( Type *type );
    8179
    82                         typedef std::map< std::string, DeclarationWithType *> AdapterMap;
     80                        typedef std::map< std::string, FunctionDecl *> AdapterMap;
    8381                        std::map< std::string, DeclarationWithType *> assignOps;
    8482                        std::stack< AdapterMap > adapters;
     
    146144                }
    147145
     146                bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) {
     147                        bool doTransform = false;
     148                        if ( ! function->get_returnVals().empty() ) {
     149                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) {
     150       
     151                                        // figure out if the return type is specified by a type parameter
     152                                        for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) {
     153                                                if ( (*tyVar)->get_name() == typeInst->get_name() ) {
     154                                                        doTransform = true;
     155                                                        name = typeInst->get_name();
     156                                                        break;
     157                                                } // if
     158                                        } // for
     159                                        if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) {
     160                                                doTransform = true;
     161                                        } // if
     162                                } // if
     163                        } // if
     164                        return doTransform;
     165                }
     166
     167                bool isPolyRet( FunctionType *function, std::string &name ) {
     168                        TyVarMap dummyTyVars;
     169                        return isPolyRet( function, name, dummyTyVars );
     170                }
     171
     172                bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {
     173                        std::string dummyString;
     174                        return isPolyRet( function, dummyString, otherTyVars );
     175                }
     176
    148177                Pass1::Pass1()
    149178                        : useRetval( false ), tempNamer( "_temp" ) {
    150                         adapters.push(AdapterMap());
    151179                }
    152180
     
    182210
    183211                DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) {
    184                         if ( functionDecl->get_statements() ) {         // empty routine body ?
    185                                 doBeginScope();
     212                        if ( functionDecl->get_statements() ) {
    186213                                TyVarMap oldtyVars = scopeTyVars;
    187214                                DeclarationWithType *oldRetval = retval;
    188215                                bool oldUseRetval = useRetval;
    189 
    190                                 // process polymorphic return value
     216       
    191217                                retval = 0;
    192218                                std::string typeName;
     
    201227                                } // if
    202228       
    203                                 FunctionType *functionType = functionDecl->get_functionType();
     229                                scopeTyVars.clear();
     230///     std::cerr << "clear\n";
    204231                                makeTyVarMap( functionDecl->get_functionType(), scopeTyVars );
    205232                                findAssignOps( functionDecl->get_functionType()->get_forall() );
    206 
    207                                 std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
    208                                 std::list< FunctionType *> functions;
    209                                 for ( std::list< TypeDecl *>::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar ) {
    210                                         for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert ) {
    211                                                 findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter );
    212                                         } // for
    213                                 } // for
    214                                 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    215                                         findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );
    216                                 } // for
    217                                 AdapterMap & adapters = Pass1::adapters.top();
    218                                 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    219                                         std::string mangleName = SymTab::Mangler::mangle( *funType );
    220                                         if ( isPolyRet( *funType, scopeTyVars ) ) {
    221                                                 // if the return type involved polymorphic types, then the adapter will need to take those
    222                                                 // polymorphic types as pointers. Therefore, there can be two different functions with the same
    223                                                 // mangled name, so we need the mangled names to be different.
    224                                                 mangleName += "polyret_";
    225                                         } // if
    226                                         if ( adapters.find( mangleName ) == adapters.end() ) {
    227                                                 std::string adapterName = makeAdapterName( mangleName );
    228                                                 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) ) );
    229                                         } // if
    230                                 } // for
    231 
    232233                                functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) );
    233234 
    234235                                scopeTyVars = oldtyVars;
    235                                 // std::cerr << "end FunctionDecl: ";
    236                                 // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
    237                                 //      std::cerr << i->first << " ";
    238                                 // }
    239                                 // std::cerr << "\n";
     236///    std::cerr << "end FunctionDecl: ";
     237///    for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
     238///       std::cerr << i->first << " ";
     239///    }
     240///    std::cerr << "\n";
    240241                                retval = oldRetval;
    241242                                useRetval = oldUseRetval;
    242                                 doEndScope();
     243                                // doEndScope();
    243244                        } // if
    244245                        return functionDecl;
     
    348349                        } // if
    349350                        std::string mangleName = SymTab::Mangler::mangle( function );
    350                         if ( isPolyRet( function, tyVars ) ) {
    351                                 mangleName += "polyret_";
    352                         } // if
    353351                        std::string adapterName = makeAdapterName( mangleName );
    354352
     
    459457///       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
    460458///     } else {
    461                                 if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) {
    462                                         UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    463                                         deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) );
    464                                         deref->get_results().push_back( arg->get_type()->clone() );
    465                                         return deref;
    466                                 } // if
     459                                UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     460                                deref->get_args().push_back( new CastExpr( new VariableExpr( param ), new PointerType( Type::Qualifiers(), arg->get_type()->clone() ) ) );
     461                                deref->get_results().push_back( arg->get_type()->clone() );
     462                                return deref;
    467463///     }
    468464                        } // if
     
    548544                        } // for
    549545
    550                         // parameter function types for which an appropriate adapter has been generated.  we cannot use the types
    551                         // after applying substitutions, since two different parameter types may be unified to the same type
     546                        // parameter function types for which an appropriate adapter has been generated.
     547                        // we cannot use the types after applying substitutions, since two different
     548                        // parameter types may be unified to the same type
    552549                        std::set< std::string > adaptersDone;
    553550
     
    557554                                std::string mangleName = SymTab::Mangler::mangle( realFunction );
    558555
    559                                 // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this
    560                                 // pre-substitution parameter function type.
     556                                // only attempt to create an adapter or pass one as a parameter if we haven't
     557                                // already done so for this pre-substitution parameter function type.
    561558                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
     559                                        std::string mangleName = SymTab::Mangler::mangle( realFunction );
    562560                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
    563561                                       
    564                                         // apply substitution to type variables to figure out what the adapter's type should look like
     562                                        // apply substitution to type variables to figure out what the
     563                                        // adapter's type should look like
    565564                                        assert( env );
    566565                                        env->apply( realFunction );
    567566                                        mangleName = SymTab::Mangler::mangle( realFunction );
    568567
    569                                         if ( isPolyRet( originalFunction, exprTyVars ) ) {
    570                                                 mangleName += "polyret_";
     568                                        if ( needsAdapter( realFunction, exprTyVars, true ) ) {
     569                                                // the function still contains type variables, which means we are in a polymorphic
     570                                                // context and the adapter function is a parameter - call the parameter and don't
     571                                                // create a new adapter.
     572                                                appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) );
     573                                        } else {
     574                                                if ( isPolyRet( originalFunction, exprTyVars ) ) {
     575                                                        // if the return type involved polymorphic types, then
     576                                                        // the adapter will need to take those polymorphic types
     577                                                        // as pointers. Therefore, there can be two different
     578                                                        // functions with the same mangled name, so we need two adapter map
     579                                                        // stacks and also we need the mangled names to be different.
     580                                                        mangleName += "polyret_";
     581                                                }
     582
     583                                                AdapterMap & adapters = Pass1::adapters.top();
     584                                                AdapterMap::iterator adapter = adapters.find( mangleName );
     585                                                if ( adapter == adapters.end() ) {
     586                                                        // adapter has not been created yet in the current scope, so define it
     587                                                        FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
     588                                                        adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) );
     589                                                        stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) );
     590                                                } // if
     591                                                assert( adapter != adapters.end() );
     592
     593                                                // add the appropriate adapter as a parameter
     594                                                appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
    571595                                        } // if
    572 
    573                                         AdapterMap & adapters = Pass1::adapters.top();
    574                                         AdapterMap::iterator adapter = adapters.find( mangleName );
    575                                         if ( adapter == adapters.end() ) {
    576                                                 // adapter has not been created yet in the current scope, so define it
    577                                                 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
    578                                                 adapter = adapters.insert( adapters.begin(), std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    579                                                 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) );
    580                                         } // if
    581                                         assert( adapter != adapters.end() );
    582 
    583                                         // add the appropriate adapter as a parameter
    584                                         appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
    585596                                } // if
    586597                        } // for
    587                 } // passAdapters
     598                }
    588599
    589600                TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
     
    758769
    759770                Expression *Pass1::mutate( ApplicationExpr *appExpr ) {
    760                         // std::cerr << "mutate appExpr: ";
    761                         // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
    762                         //      std::cerr << i->first << " ";
    763                         // }
    764                         // std::cerr << "\n";
     771///    std::cerr << "mutate appExpr: ";
     772///    for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
     773///       std::cerr << i->first << " ";
     774///    }
     775///    std::cerr << "\n";
    765776                        bool oldUseRetval = useRetval;
    766777                        useRetval = false;
     
    788799                                ret = addPolyRetParam( appExpr, function, typeName, arg );
    789800                        } else if ( needsAdapter( function, scopeTyVars ) ) {
    790                                 // std::cerr << "needs adapter: ";
    791                                 // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
    792                                 //      std::cerr << i->first << " ";
    793                                 // }
    794                                 // std::cerr << "\n";
     801///    std::cerr << "needs adapter: ";
     802///    for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
     803///       std::cerr << i->first << " ";
     804///    }
     805///    std::cerr << "\n";
    795806                                // change the application so it calls the adapter rather than the passed function
    796807                                ret = applyAdapter( appExpr, function, arg, scopeTyVars );
     
    902913                        // actually, maybe this could (should?) push
    903914                        // a copy of the current map
    904                         adapters.push(adapters.top());
     915                        adapters.push(AdapterMap());
    905916                }
    906917
     
    924935                        for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    925936                                std::string mangleName = SymTab::Mangler::mangle( *funType );
    926                                 if ( isPolyRet( *funType, scopeTyVars ) ) {
    927                                         mangleName += "polyret_";
    928                                 } // if
    929937                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
    930938                                        std::string adapterName = makeAdapterName( mangleName );
     
    9921000                        for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    9931001                                ObjectDecl *thisParm;
    994                                 // add all size parameters to parameter list
    9951002                                if ( (*tyParm)->get_kind() == TypeDecl::Any ) {
    9961003                                        thisParm = newObj->clone();
     
    9991006                                        ++last;
    10001007                                }
    1001                                 // move all assertions into parameter list
    10021008                                for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
    10031009///      *assert = (*assert)->acceptMutator( *this );
  • src/GenPoly/Box.h

    r7e23d0a r02ec390  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:24:01 2015
    13 // Update Count     : 5
     12// Last Modified On : Tue May 19 07:32:33 2015
     13// Update Count     : 2
    1414//
    1515
  • src/GenPoly/GenPoly.cc

    r7e23d0a r02ec390  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:23:44 2015
    13 // Update Count     : 10
     12// Last Modified On : Tue May 19 07:37:46 2015
     13// Update Count     : 1
    1414//
    1515
     
    2121
    2222namespace GenPoly {
    23         // A function needs an adapter if it returns a polymorphic value or if any of its
    24         // parameters have polymorphic type
    25         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    26                 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    27                         return true;
    28                 } // if
    29                 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) {
    30                         if ( isPolyVal( (*innerArg)->get_type(), tyVars ) ) {
     23        // interface functions
     24        bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
     25                return isPolyVal( type, tyVars, false );
     26        }
     27
     28        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 
     29                return needsAdapter( adaptee, tyVars, false );
     30        }
     31
     32        bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) {
     33                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
     34                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    3135                                return true;
    3236                        } // if
    33                 } // for
     37                        return considerAllTyVars;
     38                } // if
    3439                return false;
    3540        }
    3641
    37         bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) {
    38                 bool doTransform = false;
    39                 if ( ! function->get_returnVals().empty() ) {
    40                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) {
    41        
    42                                 // figure out if the return type is specified by a type parameter
    43                                 for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) {
    44                                         if ( (*tyVar)->get_name() == typeInst->get_name() ) {
    45                                                 doTransform = true;
    46                                                 name = typeInst->get_name();
    47                                                 break;
    48                                         } // if
    49                                 } // for
    50                                 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) {
    51                                         doTransform = true;
    52                                 } // if
     42        // A function needs an adapter if it returns a polymorphic value or if any of its
     43        // parameters have polymorphic type
     44        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) {
     45                bool needsAdapter = false;
     46                if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) {
     47                        needsAdapter = true;
     48                } // if
     49                for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); ! needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) {
     50                        if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) {
     51                                needsAdapter = true;
    5352                        } // if
    54                 } // if
    55                 return doTransform;
    56         }
    57 
    58         bool isPolyRet( FunctionType *function, std::string &name ) {
    59                 TyVarMap dummyTyVars;
    60                 return isPolyRet( function, name, dummyTyVars );
    61         }
    62 
    63         bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {
    64                 std::string dummyString;
    65                 return isPolyRet( function, dummyString, otherTyVars );
    66         }
    67 
    68         bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
    69                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    70                         if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    71                                 return true;
    72                         } // if
    73                 } // if
    74                 return false;
     53                } // for
     54                return needsAdapter;
    7555        }
    7656
  • src/GenPoly/GenPoly.h

    r7e23d0a r02ec390  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:24:03 2015
    13 // Update Count     : 4
     12// Last Modified On : Tue May 19 07:38:34 2015
     13// Update Count     : 1
    1414//
    1515
     
    2525        typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
    2626
     27        // considerAllTyVars allows ignoring the contents of the TyVarMap parameter, for the situations where
     28        // it is important only that a TypeInstType node exists.
     29
    2730        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
    28         bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars );
    29         bool isPolyRet( FunctionType *function, std::string &name );
    30         bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars );
    31 //      bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
     31        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars );
     32        bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
    3233        bool isPolyVal( Type *type, const TyVarMap &tyVars );
     34        bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars );
    3335        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    3436} // namespace GenPoly
  • src/Parser/LinkageSpec.cc

    r7e23d0a r02ec390  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:22:09 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 19 15:53:05 2015
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat May 16 13:23:21 2015
     13// Update Count     : 2
    1414//
    1515
     
    7979}
    8080
    81 
    82 bool LinkageSpec::isOverridable( Type t ) {
    83         switch ( t ) {
    84           case Intrinsic:
    85           case AutoGen:
    86                 return true;
    87           case Cforall:
    88           case C:
    89           case Compiler:
    90                 return false;
    91         }
    92         assert( false );
    93         return false;
    94 }
    95 
    9681bool LinkageSpec::isBuiltin( Type t ) {
    9782        switch ( t ) {
  • src/Parser/LinkageSpec.h

    r7e23d0a r02ec390  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:24:28 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Aug 18 14:11:55 2015
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat May 16 13:26:14 2015
     13// Update Count     : 3
    1414//
    1515
     
    3434        static bool isGeneratable( Type );
    3535        static bool isOverloadable( Type );
    36         static bool isOverridable( Type );
    3736        static bool isBuiltin( Type );
    3837};
  • src/ResolvExpr/CastCost.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 06:57:43 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Oct 05 14:48:45 2015
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 06:59:10 2015
     13// Update Count     : 2
    1414//
    1515
     
    5656                                return Cost::infinity;
    5757                        } else {
    58                                 // xxx - why are we adding cost 0 here?
    5958                                return converter.get_cost() + Cost( 0, 0, 0 );
    6059                        } // if
     
    8382                                newEnv.add( pointerType->get_forall() );
    8483                                newEnv.add( pointerType->get_base()->get_forall() );
    85                                 int castResult = ptrsCastable( pointerType->get_base(), destAsPtr->get_base(), newEnv, indexer );
    86                                 if ( castResult > 0 ) {
     84                                int assignResult = ptrsCastable( pointerType->get_base(), destAsPtr->get_base(), newEnv, indexer );
     85                                if ( assignResult > 0 ) {
    8786                                        cost = Cost( 0, 0, 1 );
    88                                 } else if ( castResult < 0 ) {
     87                                } else if ( assignResult < 0 ) {
    8988                                        cost = Cost( 1, 0, 0 );
    9089                                } // if
  • src/ResolvExpr/PtrsAssignable.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 11:44:11 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Sep 21 14:34:58 2015
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 11:47:36 2015
     13// Update Count     : 2
    1414//
    1515
     
    106106        void PtrsAssignable::visit( TypeInstType *inst ) {
    107107                EqvClass eqvClass;
    108                 if ( env.lookup( inst->get_name(), eqvClass ) && eqvClass.type ) {
     108                if ( env.lookup( inst->get_name(), eqvClass ) ) {
    109109                        result = ptrsAssignable( eqvClass.type, dest, env );
    110110                } else {
  • src/ResolvExpr/PtrsCastable.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 11:48:00 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Oct 05 14:49:12 2015
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 11:51:17 2015
     13// Update Count     : 2
    1414//
    1515
     
    133133
    134134        void PtrsCastable::visit(TypeInstType *inst) {
    135                 result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1;
     135                result = objectCast( inst, env, indexer ) && objectCast( dest, env, indexer ) ? 1 : -1;
    136136        }
    137137
  • src/ResolvExpr/Unify.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:27:10 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Sep 02 14:43:22 2015
    13 // Update Count     : 36
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jun 26 14:57:05 2015
     13// Update Count     : 7
    1414//
    1515
     
    2828
    2929
    30 // #define DEBUG
     30//#define DEBUG
    3131
    3232namespace ResolvExpr {
     
    8181        bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    8282                TypeEnvironment newEnv;
    83                 OpenVarSet openVars, closedVars; // added closedVars
     83                OpenVarSet openVars;
    8484                AssertionSet needAssertions, haveAssertions;
    8585                Type *newFirst = first->clone(), *newSecond = second->clone();
    8686                env.apply( newFirst );
    8787                env.apply( newSecond );
    88 
    89                 // do we need to do this? Seems like we do, types should be able to be compatible if they
    90                 // have free variables that can unify
    91                 findOpenVars( newFirst, openVars, closedVars, needAssertions, haveAssertions, false );
    92                 findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );
    93 
    9488                bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    9589                delete newFirst;
     
    432426
    433427        void Unify::visit(ArrayType *arrayType) {
     428                // XXX -- compare array dimension
    434429                ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 );
    435                 // to unify, array types must both be VLA or both not VLA
    436                 // and must both have a dimension expression or not have a dimension
    437                 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen()
    438                                 && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0)
    439                                         || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) {
    440 
    441                         // not positive this is correct in all cases, but it's needed for typedefs
    442                         if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) {
    443                                 return;
    444                         }
    445 
    446                         if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() &&
    447                                 arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0 ) {
    448                                 ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() );
    449                                 ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() );
    450                                 assert(ce1 && ce2);
    451 
    452                                 Constant * c1 = ce1->get_constant();
    453                                 Constant * c2 = ce2->get_constant();
    454 
    455                                 if ( c1->get_value() != c2->get_value() ) {
    456                                         // does not unify if the dimension is different
    457                                         return;
    458                                 }
    459                         }
    460 
     430                if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
    461431                        result = unifyExact( arrayType->get_base(), otherArray->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    462432                } // if
     
    466436        bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
    467437                for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
    468                         // Type * commonType;
    469                         // if ( ! unifyInexact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) {
    470438                        if ( ! unifyExact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
    471439                                return false;
     
    482450                FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 );
    483451                if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) {
    484 
     452 
    485453                        if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    486454       
  • src/SymTab/IdTable.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 17:04:02 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Oct 07 12:21:13 2015
    13 // Update Count     : 73
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 17:07:43 2015
     13// Update Count     : 3
    1414//
    1515
     
    3737                        for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
    3838                                std::stack< DeclEntry >& entry = inner->second;
    39                                 // xxx - should be while?
    4039                                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    4140                                        entry.pop();
     
    5352                if ( decl->get_linkage() == LinkageSpec::C ) {
    5453                        manglename = name;
    55                 } else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
    56                         // mangle the name without including the appropriate suffix
    57                         // this will make it so that overridable routines are placed
    58                         // into the same "bucket" as their user defined versions.
    59                         manglename = Mangler::mangle( decl, false );
    6054                } else {
    6155                        manglename = Mangler::mangle( decl );
     
    6660
    6761                if ( it == declTable.end() ) {
    68                         // first time this name mangling has been defined
    6962                        declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    7063                } else {
    7164                        std::stack< DeclEntry >& entry = it->second;
    7265                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    73                                 // if we're giving the same name mangling to things of
    74                                 //  different types then there is something wrong
    75                                 Declaration *old = entry.top().first;
    76                                 assert( (dynamic_cast<ObjectDecl*>( decl ) && dynamic_cast<ObjectDecl*>( old ) )
    77                                   || (dynamic_cast<FunctionDecl*>( decl ) && dynamic_cast<FunctionDecl*>( old ) ) );
    78 
    79                                 if ( LinkageSpec::isOverridable( old->get_linkage() ) ) {
    80                                         // new definition shadows the autogenerated one, even at the same scope
    81                                         declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    82                                 } else if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
    83                                         // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
    84                                         // we should ignore outermost pointer qualifiers, except _Atomic?
     66                                if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
    8567                                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
    86                                         FunctionDecl *oldentry = dynamic_cast< FunctionDecl* >( old );
    87                                         if ( newentry && oldentry ) {
    88                                                 if ( newentry->get_statements() && oldentry->get_statements() ) {
    89                                                         throw SemanticError( "duplicate function definition for 1 ", decl );
    90                                                 } // if
     68                                        FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first );
     69                                        if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
     70                                                throw SemanticError( "duplicate function definition for ", decl );
    9171                                        } else {
    92                                                 // two objects with the same mangled name defined in the same scope.
    93                                                 // both objects must be marked extern or both must be intrinsic for this to be okay
    94                                                 // xxx - perhaps it's actually if either is intrinsic then this is okay?
    95                                                 //       might also need to be same storage class?
    9672                                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
    97                                                 ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( old );
    98                                                 if (newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
    99                                                         throw SemanticError( "duplicate definition for 3 ", decl );
     73                                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
     74                                                if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) {
     75                                                        throw SemanticError( "duplicate definition for ", decl );
    10076                                                } // if
    10177                                        } // if
     
    10480                                } // if
    10581                        } else {
    106                                 // new scope level - shadow existing definition
    10782                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    10883                        } // if
    10984                } // if
    110                 // this ensures that no two declarations with the same unmangled name both have C linkage
     85                // ensure the set of routines with C linkage cannot be overloaded
    11186                for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
    11287                        if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) {
  • src/SymTab/Mangler.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:40:29 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 19 15:52:24 2015
    13 // Update Count     : 19
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jun  8 15:12:12 2015
     13// Update Count     : 8
    1414//
    1515
     
    3030
    3131namespace SymTab {
    32         Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) {
     32        Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {
    3333        }
    3434
     
    4141                nextVarNum = rhs.nextVarNum;
    4242                isTopLevel = rhs.isTopLevel;
    43                 mangleOverridable = rhs.mangleOverridable;
    4443        }
    4544
     
    6059                mangleName << "__";
    6160                maybeAccept( declaration->get_type(), *this );
    62                 if ( mangleOverridable && LinkageSpec::isOverridable( declaration->get_linkage() ) ) {
    63                         // want to be able to override autogenerated and intrinsic routines,
    64                         // so they need a different name mangling
    65                         if ( declaration->get_linkage() == LinkageSpec::AutoGen ) {
    66                                 mangleName << "autogen__";
    67                         } else if ( declaration->get_linkage() == LinkageSpec::Intrinsic ) {
    68                                 mangleName << "intrinsic__";
    69                         } else {
    70                                 // if we add another kind of overridable function, this has to change
    71                                 assert( false );
    72                         } // if
    73                 }
    7461                isTopLevel = wasTopLevel;
    7562        }
     
    227214                                varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
    228215                                for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    229                                         Mangler sub_mangler( mangleOverridable );
     216                                        Mangler sub_mangler;
    230217                                        sub_mangler.nextVarNum = nextVarNum;
    231218                                        sub_mangler.isTopLevel = false;
  • src/SymTab/Mangler.h

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:44:03 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 19 15:48:46 2015
    13 // Update Count     : 14
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jun  8 14:47:14 2015
     13// Update Count     : 5
    1414//
    1515
     
    2525          public:
    2626                template< typename SynTreeClass >
    27             static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients
     27            static std::string mangle( SynTreeClass *decl ); // interface to clients
    2828
    2929///   using Visitor::visit;
     
    5050                int nextVarNum;
    5151                bool isTopLevel;
    52                 bool mangleOverridable;
    5352 
    54                 Mangler( bool mangleOverridable );
     53                Mangler();
    5554                Mangler( const Mangler & );
    5655 
     
    6261
    6362        template< typename SynTreeClass >
    64         std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
    65                 Mangler mangler( mangleOverridable );
     63        std::string Mangler::mangle( SynTreeClass *decl ) {
     64                Mangler mangler;
    6665                maybeAccept( decl, mangler );
    6766                return mangler.get_mangleName();
  • src/SymTab/Validate.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Nov 20 16:33:52 2015
    13 // Update Count     : 201
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Aug 11 16:59:35 2015
     13// Update Count     : 196
    1414//
    1515
     
    5454#include "MakeLibCfa.h"
    5555#include "TypeEquality.h"
    56 #include "ResolvExpr/typeops.h"
    5756
    5857#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    126125        };
    127126
    128         class AutogenerateRoutines : public Visitor {
     127        class AddStructAssignment : public Visitor {
    129128          public:
    130129                /// Generates assignment operators for aggregate types as required
    131                 static void autogenerateRoutines( std::list< Declaration * > &translationUnit );
     130                static void addStructAssignment( std::list< Declaration * > &translationUnit );
    132131
    133132                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
     
    152151                virtual void visit( CatchStmt *catchStmt );
    153152
    154                 AutogenerateRoutines() : functionNesting( 0 ) {}
     153                AddStructAssignment() : functionNesting( 0 ) {}
    155154          private:
    156155                template< typename StmtClass > void visitStatement( StmtClass *stmt );
     
    196195                acceptAll( translationUnit, pass1 );
    197196                acceptAll( translationUnit, pass2 );
    198                 AutogenerateRoutines::autogenerateRoutines( translationUnit );
     197                // need to collect all of the assignment operators prior to
     198                // this point and only generate assignment operators if one doesn't exist
     199                AddStructAssignment::addStructAssignment( translationUnit );
    199200                acceptAll( translationUnit, pass3 );
    200201        }
     
    500501        static const std::list< std::string > noLabels;
    501502
    502         void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) {
    503                 AutogenerateRoutines visitor;
     503        void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
     504                AddStructAssignment visitor;
    504505                acceptAndAdd( translationUnit, visitor, false );
    505506        }
     
    703704        }
    704705
    705         void AutogenerateRoutines::visit( EnumDecl *enumDecl ) {
     706        void AddStructAssignment::visit( EnumDecl *enumDecl ) {
    706707                if ( ! enumDecl->get_members().empty() ) {
    707708                        EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() );
     
    712713        }
    713714
    714         void AutogenerateRoutines::visit( StructDecl *structDecl ) {
     715        void AddStructAssignment::visit( StructDecl *structDecl ) {
    715716                if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
    716717                        StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
     
    721722        }
    722723
    723         void AutogenerateRoutines::visit( UnionDecl *unionDecl ) {
     724        void AddStructAssignment::visit( UnionDecl *unionDecl ) {
    724725                if ( ! unionDecl->get_members().empty() ) {
    725726                        UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
     
    729730        }
    730731
    731         void AutogenerateRoutines::visit( TypeDecl *typeDecl ) {
     732        void AddStructAssignment::visit( TypeDecl *typeDecl ) {
    732733                CompoundStmt *stmts = 0;
    733734                TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
     
    757758        }
    758759
    759         void AutogenerateRoutines::visit( FunctionType *) {
     760        void AddStructAssignment::visit( FunctionType *) {
    760761                // ensure that we don't add assignment ops for types defined as part of the function
    761762        }
    762763
    763         void AutogenerateRoutines::visit( PointerType *) {
     764        void AddStructAssignment::visit( PointerType *) {
    764765                // ensure that we don't add assignment ops for types defined as part of the pointer
    765766        }
    766767
    767         void AutogenerateRoutines::visit( ContextDecl *) {
     768        void AddStructAssignment::visit( ContextDecl *) {
    768769                // ensure that we don't add assignment ops for types defined as part of the context
    769770        }
    770771
    771772        template< typename StmtClass >
    772         inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) {
     773        inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {
    773774                std::set< std::string > oldStructs = structsDone;
    774775                addVisit( stmt, *this );
     
    776777        }
    777778
    778         void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) {
     779        void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
    779780                maybeAccept( functionDecl->get_functionType(), *this );
    780781                acceptAll( functionDecl->get_oldDecls(), *this );
     
    784785        }
    785786
    786         void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) {
     787        void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
    787788                visitStatement( compoundStmt );
    788789        }
    789790
    790         void AutogenerateRoutines::visit( IfStmt *ifStmt ) {
     791        void AddStructAssignment::visit( IfStmt *ifStmt ) {
    791792                visitStatement( ifStmt );
    792793        }
    793794
    794         void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {
     795        void AddStructAssignment::visit( WhileStmt *whileStmt ) {
    795796                visitStatement( whileStmt );
    796797        }
    797798
    798         void AutogenerateRoutines::visit( ForStmt *forStmt ) {
     799        void AddStructAssignment::visit( ForStmt *forStmt ) {
    799800                visitStatement( forStmt );
    800801        }
    801802
    802         void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) {
     803        void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
    803804                visitStatement( switchStmt );
    804805        }
    805806
    806         void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) {
     807        void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
    807808                visitStatement( switchStmt );
    808809        }
    809810
    810         void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
     811        void AddStructAssignment::visit( CaseStmt *caseStmt ) {
    811812                visitStatement( caseStmt );
    812813        }
    813814
    814         void AutogenerateRoutines::visit( CatchStmt *cathStmt ) {
     815        void AddStructAssignment::visit( CatchStmt *cathStmt ) {
    815816                visitStatement( cathStmt );
    816817        }
     
    856857                        Type * t1 = tyDecl->get_base();
    857858                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    858                         if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
     859                        if ( ! typeEquals( t1, t2, true ) ) {
    859860                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    860861                        }
  • src/SynTree/Mutator.h

    r7e23d0a r02ec390  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 22:26:16 2015
    13 // Update Count     : 8
     12// Last Modified On : Thu Jul 23 23:24:18 2015
     13// Update Count     : 7
    1414//
    1515#include <cassert>
     
    103103inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) {
    104104        if ( tree ) {
    105                 TreeType *newnode = dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) );
     105                TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );
    106106                assert( newnode );
    107107                return newnode;
  • src/SynTree/ObjectDecl.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Sep 29 14:13:01 2015
    13 // Update Count     : 18
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jul 13 18:08:27 2015
     13// Update Count     : 16
    1414//
    1515
     
    5252                get_type()->print( os, indent );
    5353        } else {
    54                 os << " untyped entity ";
     54                os << "untyped entity ";
    5555        } // if
    5656
    5757        if ( init ) {
    58                 os << " with initializer ";
     58                os << "with initializer ";
    5959                init->print( os, indent );
    6060        } // if
    6161
    6262        if ( bitfieldWidth ) {
    63                 os << " with bitfield width ";
     63                os << "with bitfield width ";
    6464                bitfieldWidth->print( os );
    6565        } // if
  • src/SynTree/Type.h

    r7e23d0a r02ec390  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 20 12:54:09 2015
    13 // Update Count     : 15
     12// Last Modified On : Thu Jul  9 16:46:15 2015
     13// Update Count     : 14
    1414//
    1515
     
    201201        std::list<DeclarationWithType*> parameters;
    202202
    203         // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
    204         // This could be because of
     203        // does the function accept a variable number of arguments following the arguments
     204        // specified in the parameters list.    This could be because of
    205205        // - an ellipsis in a prototype declaration
    206206        // - an unprototyped declaration
     
    239239
    240240        /// Accesses generic parameters of base struct (NULL if none such)
    241         std::list<TypeDecl*> * get_baseParameters();
     241        std::list<TypeDecl*>* get_baseParameters();
    242242       
    243243        /// Looks up the members of this struct named "name" and places them into "foundDecls".
     
    266266
    267267        /// Accesses generic parameters of base union (NULL if none such)
    268         std::list<TypeDecl*> * get_baseParameters();
     268        std::list<TypeDecl*>* get_baseParameters();
    269269       
    270270        /// looks up the members of this union named "name" and places them into "foundDecls"
  • src/examples/Makefile.am

    r7e23d0a r02ec390  
    1111## Created On       : Sun May 31 09:08:15 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Fri Nov 20 16:03:46 2015
    14 ## Update Count     : 24
     13## Last Modified On : Thu Jun  4 23:13:10 2015
     14## Update Count     : 22
    1515###############################################################################
    1616
     
    1919CC = @CFA_BINDIR@/cfa
    2020
    21 noinst_PROGRAMS = fstream_test vector_test # build but do not install
    22 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c
     21noinst_PROGRAMS = fstream_test vector_test
     22fstream_test_SOURCES = iostream.c fstream.c fstream_test.c
    2323vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c
  • src/examples/Makefile.in

    r7e23d0a r02ec390  
    4949PROGRAMS = $(noinst_PROGRAMS)
    5050am_fstream_test_OBJECTS = iostream.$(OBJEXT) fstream.$(OBJEXT) \
    51         fstream_test.$(OBJEXT) iterator.$(OBJEXT)
     51        fstream_test.$(OBJEXT)
    5252fstream_test_OBJECTS = $(am_fstream_test_OBJECTS)
    5353fstream_test_LDADD = $(LDADD)
     
    176176top_builddir = @top_builddir@
    177177top_srcdir = @top_srcdir@
    178 fstream_test_SOURCES = iostream.c fstream.c fstream_test.c iterator.c
     178fstream_test_SOURCES = iostream.c fstream.c fstream_test.c
    179179vector_test_SOURCES = vector_int.c fstream.c iostream.c array.c iterator.c vector_test.c
    180180all: all-am
  • src/examples/fstream.c

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 22:43:31 2015
    13 // Update Count     : 4
     12// Last Modified On : Wed May 27 18:12:33 2015
     13// Update Count     : 2
    1414//
    1515
     
    3030                fwrite( data, size, 1, os->file );
    3131                os->fail = ferror( os->file );
    32         } // if
     32        }
    3333        return os;
    34 } // write
     34}
    3535
    3636int fail( ofstream *os ) {
    3737        return os->fail;
    38 } // fail
     38}
    3939
    4040static ofstream *make_ofstream() {
     
    4242        new_stream->fail = 0;
    4343        return new_stream;
    44 } // make_ofstream
     44}
    4545
    4646ofstream *ofstream_stdout() {
     
    4848        stdout_stream->file = stdout;
    4949        return stdout_stream;
    50 } // ofstream_stdout
     50}
    5151
    5252ofstream *ofstream_stderr() {
     
    5454        stderr_stream->file = stderr;
    5555        return stderr_stream;
    56 } // ofstream_stderr
     56}
    5757
    5858ofstream *ofstream_fromfile( const char *name ) {
  • src/examples/hello.c

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 20 16:02:50 2015
    13 // Update Count     : 3
     12// Last Modified On : Wed May 27 18:14:58 2015
     13// Update Count     : 1
    1414//
    1515
     
    2828// Local Variables: //
    2929// tab-width: 4 //
    30 // compile-command: "cfa hello.c fstream.o iostream.o iterator.o" //
     30// compile-command: "cfa hello.c fstream.o iostream.o" //
    3131// End: //
  • src/examples/iostream.c

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov 20 13:19:19 2015
    13 // Update Count     : 9
     12// Last Modified On : Wed May 27 18:18:13 2015
     13// Update Count     : 2
    1414//
    1515
     
    1717extern "C" {
    1818#include <stdio.h>
    19 #include <string.h>                                                                             // strlen
     19//#include <string.h>
     20//#include <ctype.h>
     21        typedef long unsigned int size_t;
     22        size_t strlen(const char *s);
    2023}
    2124
     
    2326ostype * ?<<?( ostype *os, char c ) {
    2427        return write( os, &c, 1 );
    25 } // ?<<?
     28}
    2629
    2730forall( dtype ostype | ostream( ostype ) )
    2831ostype * ?<<?( ostype *os, int i ) {
    29         char buffer[32];                                                                        // larger than the largest integer
     32        char buffer[20];      // larger than the largest integer
    3033        sprintf( buffer, "%d", i );
    3134        return write( os, buffer, strlen( buffer ) );
    32 } // ?<<?
     35}
    3336
    3437forall( dtype ostype | ostream( ostype ) )
    3538ostype * ?<<?( ostype *os, double d ) {
    36         char buffer[32];                                                                        // larger than the largest double
     39        char buffer[32];      // larger than the largest double
    3740        sprintf( buffer, "%g", d );
    3841        return write( os, buffer, strlen( buffer ) );
    39 } // ?<<?
     42}
    4043
    4144forall( dtype ostype | ostream( ostype ) )
    4245ostype * ?<<?( ostype *os, const char *cp ) {
    4346        return write( os, cp, strlen( cp ) );
    44 } // ?<<?
    45 
    46 forall( dtype ostype | ostream( ostype ) )
    47 ostype * ?<<?( ostype *os, const void *p ) {
    48         char buffer[32];                                                                        // larger than the largest pointer
    49         sprintf( buffer, "%p", p );
    50         return write( os, buffer, strlen( buffer ) );
    51 } // ?<<?
    52 
    53 forall( type elt_type | writeable( elt_type ),
    54                 type iterator_type | iterator( iterator_type, elt_type ),
    55                 dtype os_type | ostream( os_type ) )
    56 void write( iterator_type begin, iterator_type end, os_type *os ) {
    57         void print( elt_type i ) {
    58                 os << i << ' ';
    59         }
    60         for_each( begin, end, print );
    61 } // ?<<?
    62 
    63 forall( type elt_type | writeable( elt_type ),
    64                 type iterator_type | iterator( iterator_type, elt_type ),
    65                 dtype os_type | ostream( os_type ) )
    66 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
    67         void print( elt_type i ) {
    68                 os << i << ' ';
    69         }
    70         for_each_reverse( begin, end, print );
    71 } // ?<<?
    72 
     47}
    7348
    7449forall( dtype istype | istream( istype ) )
    7550istype * ?>>?( istype *is, char *cp ) {
    7651        return read( is, cp, 1 );
    77 } // ?>>?
     52}
    7853
    7954forall( dtype istype | istream( istype ) )
     
    9772        unread( is, cur );
    9873        return is;
    99 } // ?>>?
     74}
    10075
    10176// Local Variables: //
  • src/examples/iostream.h

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:56:51 2015
    13 // Update Count     : 5
     12// Last Modified On : Wed May 27 18:18:46 2015
     13// Update Count     : 1
    1414//
    1515
    1616#ifndef IOSTREAM_H
    1717#define IOSTREAM_H
    18 
    19 #include "iterator.h"
    2018
    2119typedef unsigned long streamsize_type;
     
    3634forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
    3735forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
    38 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * );
    39 
    40 // writes the range [begin, end) to the given stream
    41 forall( type elt_type | writeable( elt_type ),
    42                 type iterator_type | iterator( iterator_type, elt_type ),
    43                 dtype os_type | ostream( os_type ) )
    44 void write( iterator_type begin, iterator_type end, os_type *os );
    45 
    46 forall( type elt_type | writeable( elt_type ),
    47                 type iterator_type | iterator( iterator_type, elt_type ),
    48                 dtype os_type | ostream( os_type ) )
    49 void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    5036
    5137
  • src/examples/iterator.c

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:54:37 2015
    13 // Update Count     : 24
     12// Last Modified On : Wed May 27 18:41:41 2015
     13// Update Count     : 3
    1414//
    1515
    1616#include "iterator.h"
    1717
    18 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
    19 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
    20         for ( iterator_type i = begin; i != end; ++i ) {
    21                 func( *i );
     18/// forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     19/// void
     20/// for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) )
     21/// {
     22///   iterator_type i;
     23///   for ( i = begin; i != end; ++i ) {
     24///      func( *i );
     25///   }
     26/// }
     27
     28forall( type elt_type | writeable( elt_type ),
     29                type iterator_type | iterator( iterator_type, elt_type ),
     30                dtype os_type | ostream( os_type ) )
     31void write_all( iterator_type begin, iterator_type end, os_type *os ) {
     32        iterator_type i;
     33        for ( i = begin; i != end; ++i ) {
     34                os << *i << ' ';
    2235        }
    2336}
    2437
    25 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
    26 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
    27         for ( iterator_type i = end; i != begin; ) {
     38forall( type elt_type | writeable( elt_type ),
     39                type iterator_type | iterator( iterator_type, elt_type ),
     40                dtype os_type | ostream( os_type ) )
     41void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     42        iterator_type i; // "= end;" does not work
     43        i = end;
     44        do {
    2845                --i;
    29                 func( *i );
    30         }
     46                os << *i << ' ';
     47        } while ( i != begin );
    3148}
    3249
  • src/examples/iterator.h

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:58:28 2015
    13 // Update Count     : 6
     12// Last Modified On : Wed May 27 18:41:57 2015
     13// Update Count     : 3
    1414//
    1515
    1616#ifndef ITERATOR_H
    1717#define ITERATOR_H
     18
     19#include "iostream.h"
    1820
    1921// An iterator can be used to traverse a data structure.
     
    3234};
    3335
    34 context iterator_for( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
     36context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
    3537//      [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
    3638        iterator_type begin( collection_type );
     
    4143void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
    4244
    43 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
    44 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
     45// writes the range [begin, end) to the given stream
     46forall( type elt_type | writeable( elt_type ),
     47                type iterator_type | iterator( iterator_type, elt_type ),
     48                dtype os_type | ostream( os_type ) )
     49void write_all( iterator_type begin, iterator_type end, os_type *os );
     50
     51forall( type elt_type | writeable( elt_type ),
     52                type iterator_type | iterator( iterator_type, elt_type ),
     53                dtype os_type | ostream( os_type ) )
     54void write_reverse( iterator_type begin, iterator_type end, os_type *os );
    4555
    4656#endif // ITERATOR_H
  • src/examples/vector_test.c

    r7e23d0a r02ec390  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:54:34 2015
    13 // Update Count     : 9
     12// Last Modified On : Wed May 27 18:42:55 2015
     13// Update Count     : 2
    1414//
    1515
     
    2929        sout << "enter N elements and C-d on a separate line:\n";
    3030        for ( ;; ) {
    31                 sin >> &num;
     31        sin >> &num;
    3232          if ( fail( sin ) || eof( sin ) ) break;
    33                 append( &vec, num );
     33        append( &vec, num );
    3434        }
    3535        // write out the numbers
    3636
    3737        sout << "Array elements:\n";
    38         write( begin( vec ), end( vec ), sout );
     38//      write_all( begin( vec ), end( vec ), sout );
     39//      sout << "\n";
     40        for ( int index = 0; index <= last( vec ); index += 1 ) {
     41        sout << vec[ index ] << " ";
     42        }
    3943        sout << "\n";
    40 
     44#if 1
    4145        sout << "Array elements reversed:\n";
    4246        write_reverse( begin( vec ), end( vec ), sout );
    4347        sout << "\n";
     48#endif
    4449}
     50
     51// ../bin/cfa vector_test.c fstream.o iostream.o vector_int.o iterator.o array.o
    4552
    4653// Local Variables: //
  • src/libcfa/prelude.cf

    r7e23d0a r02ec390  
    77// Author           : Glen Ditchfield
    88// Created On       : Sat Nov 29 07:23:41 2014
    9 // Last Modified By : Rob Schluntz
    10 // Last Modified On : Thu Nov 19 11:09:47 2015
    11 // Update Count     : 76
     9// Last Modified By : Peter A. Buhr
     10// Last Modified On : Tue Jun  9 14:43:47 2015
     11// Update Count     : 75
    1212//
    1313
  • src/main.cc

    r7e23d0a r02ec390  
    99// Author           : Richard C. Bilson
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 22:31:40 2015
    13 // Update Count     : 168
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Jul 30 16:08:18 2015
     13// Update Count     : 167
    1414//
    1515
     
    227227                } // if
    228228
    229                 // add the assignment statement after the initialization of a type parameter
     229                // add the assignment statement after the
     230                // initialization of a type parameter
    230231                OPTPRINT( "validate" )
    231232                SymTab::validate( translationUnit, symtabp );
Note: See TracChangeset for help on using the changeset viewer.