Changeset 2f42718 for src/GenPoly


Ignore:
Timestamp:
Feb 22, 2019, 10:43:29 AM (7 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
no_list
Parents:
43e0949
Message:

Parameters and return value of functions are now vectors (and some related clean-up)

Location:
src/GenPoly
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r43e0949 r2f42718  
    286286                        TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );
    287287                        std::string paramName = mangleType( &paramType );
    288                         layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
    289                         layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
     288                        layoutFnType->parameters.push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
     289                        layoutFnType->parameters.push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
    290290                }
    291291        }
     
    367367
    368368                ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
    369                 layoutFnType->get_parameters().push_back( sizeParam );
     369                layoutFnType->parameters.push_back( sizeParam );
    370370                ObjectDecl *alignParam = new ObjectDecl( alignofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
    371                 layoutFnType->get_parameters().push_back( alignParam );
     371                layoutFnType->parameters.push_back( alignParam );
    372372                ObjectDecl *offsetParam = new ObjectDecl( offsetofName( structDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
    373                 layoutFnType->get_parameters().push_back( offsetParam );
     373                layoutFnType->parameters.push_back( offsetParam );
    374374                addOtypeParams( layoutFnType, otypeParams );
    375375
     
    428428
    429429                ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType, 0 );
    430                 layoutFnType->get_parameters().push_back( sizeParam );
     430                layoutFnType->parameters.push_back( sizeParam );
    431431                ObjectDecl *alignParam = new ObjectDecl( alignofName( unionDecl->get_name() ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignOutType->clone(), 0 );
    432                 layoutFnType->get_parameters().push_back( alignParam );
     432                layoutFnType->parameters.push_back( alignParam );
    433433                addOtypeParams( layoutFnType, otypeParams );
    434434
     
    468468                        // to take those polymorphic types as pointers. Therefore, there can be two different functions
    469469                        // with the same mangled name, so we need to further mangle the names.
    470                         for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) {
    471                                 if ( isPolyType( (*retval)->get_type(), tyVars ) ) {
     470                        for ( auto retval : function->returnVals ) {
     471                                if ( isPolyType( retval->get_type(), tyVars ) ) {
    472472                                        name << "P";
    473473                                } else {
     
    476476                        }
    477477                        name << "_";
    478                         std::list< DeclarationWithType *> &paramList = function->get_parameters();
    479                         for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    480                                 if ( isPolyType( (*arg)->get_type(), tyVars ) ) {
     478                        auto & paramList = function->parameters;
     479                        for ( auto arg : paramList ) {
     480                                if ( isPolyType( arg->get_type(), tyVars ) ) {
    481481                                        name << "P";
    482482                                } else {
     
    518518                                makeTyVarMap( functionType, scopeTyVars );
    519519
    520                                 std::list< DeclarationWithType *> &paramList = functionType->parameters;
    521                                 std::list< FunctionType *> functions;
    522                                 for ( Type::ForallList::iterator tyVar = functionType->forall.begin(); tyVar != functionType->forall.end(); ++tyVar ) {
    523                                         for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert ) {
    524                                                 findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter );
     520                                auto & paramList = functionType->parameters;
     521                                std::vector< FunctionType *> functions;
     522                                for ( auto tyVar : functionType->forall ) {
     523                                        for ( auto assert : tyVar->assertions ) {
     524                                                findFunction( assert->get_type(), functions, scopeTyVars, needsAdapter );
    525525                                        } // for
    526526                                } // for
    527                                 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    528                                         findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );
     527                                for ( auto arg : paramList ) {
     528                                        findFunction( arg->get_type(), functions, scopeTyVars, needsAdapter );
    529529                                } // for
    530530
    531                                 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    532                                         std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
     531                                for ( auto funType : functions ) {
     532                                        std::string mangleName = mangleAdapterName( funType, scopeTyVars );
    533533                                        if ( adapters.find( mangleName ) == adapters.end() ) {
    534534                                                std::string adapterName = makeAdapterName( mangleName );
    535                                                 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), nullptr ) ) );
     535                                                adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) );
    536536                                        } // if
    537537                                } // for
     
    612612                        assert( funcType );
    613613
    614                         std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();
     614                        std::vector< DeclarationWithType* >::const_iterator fnParm = funcType->parameters.begin();
    615615                        std::list< Expression* >::const_iterator fnArg = arg;
    616616                        std::set< std::string > seenTypes; ///< names for generic types we've seen
     
    624624
    625625                        // add type information args for presently unseen types in parameter list
    626                         for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
     626                        for ( ; fnParm != funcType->parameters.end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
    627627                                if ( ! (*fnArg)->get_result() ) continue;
    628628                                Type * argType = (*fnArg)->get_result();
     
    708708//                      if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
    709709                        if ( isDynRet( function, tyVars ) ) {
    710                                 ret = addRetParam( appExpr, function->get_returnVals().front()->get_type(), arg );
     710                                ret = addRetParam( appExpr, function->returnVals.front()->get_type(), arg );
    711711                        } // if
    712712                        std::string mangleName = mangleAdapterName( function, tyVars );
     
    786786                }
    787787
    788                 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
    789                         for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->parameters.end(); ++param, ++arg ) {
    790                                 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( *param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() );
    791                                 addCast( *arg, (*param)->get_type(), exprTyVars );
    792                                 boxParam( (*param)->get_type(), *arg, exprTyVars );
     788                void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator & arg, const TyVarMap &exprTyVars ) {
     789                        for ( auto param : function->parameters ) {
     790                                assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() );
     791                                addCast( *arg, param->get_type(), exprTyVars );
     792                                boxParam( param->get_type(), *arg, exprTyVars );
     793                                ++arg;
    793794                        } // for
    794795                }
     
    796797                void Pass1::addInferredParams( ApplicationExpr *appExpr, FunctionType *functionType, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) {
    797798                        std::list< Expression *>::iterator cur = arg;
    798                         for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar ) {
    799                                 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert ) {
    800                                         InferredParams::const_iterator inferParam = appExpr->inferParams.find( (*assert)->get_uniqueId() );
    801                                         assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( *assert ).c_str(), toString( appExpr ).c_str() );
     799                        for ( auto tyVar : functionType->forall ) {
     800                                for ( auto assert : tyVar->assertions ) {
     801                                        InferredParams::const_iterator inferParam = appExpr->inferParams.find( assert->get_uniqueId() );
     802                                        assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( assert ).c_str(), toString( appExpr ).c_str() );
    802803                                        Expression *newExpr = inferParam->second.expr->clone();
    803                                         addCast( newExpr, (*assert)->get_type(), tyVars );
    804                                         boxParam( (*assert)->get_type(), newExpr, tyVars );
     804                                        addCast( newExpr, assert->get_type(), tyVars );
     805                                        boxParam( assert->get_type(), newExpr, tyVars );
    805806                                        appExpr->get_args().insert( cur, newExpr );
    806807                                } // for
     
    813814                        // make a new parameter that is a pointer to the type of the old return value
    814815                        retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) );
    815                         funcType->get_parameters().push_front( retParm );
     816                        funcType->parameters.insert( funcType->parameters.begin(), retParm );
    816817
    817818                        // we don't need the return value any more
    818                         funcType->get_returnVals().clear();
     819                        funcType->returnVals.clear();
    819820                }
    820821
     
    825826                                makeRetParm( adapter );
    826827                        } // if
    827                         adapter->get_parameters().push_front( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ) );
     828                        adapter->parameters.insert( adapter->parameters.begin(), new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ) );
    828829                        return adapter;
    829830                }
     
    844845                }
    845846
    846                 void addAdapterParams( ApplicationExpr *adapteeApp, std::list< DeclarationWithType *>::iterator arg, std::list< DeclarationWithType *>::iterator param, std::list< DeclarationWithType *>::iterator paramEnd, std::list< DeclarationWithType *>::iterator realParam, const TyVarMap &tyVars ) {
     847                void addAdapterParams( ApplicationExpr *adapteeApp, std::vector< DeclarationWithType *>::iterator arg, std::vector< DeclarationWithType *>::iterator param, std::vector< DeclarationWithType *>::iterator paramEnd, std::vector< DeclarationWithType *>::iterator realParam, const TyVarMap &tyVars ) {
    847848                        UniqueName paramNamer( "_p" );
    848849                        for ( ; param != paramEnd; ++param, ++arg, ++realParam ) {
     
    858859                        FunctionType *adapterType = makeAdapterType( adaptee, tyVars );
    859860                        adapterType = ScrubTyVars::scrub( adapterType, tyVars );
    860                         DeclarationWithType *adapteeDecl = adapterType->get_parameters().front();
     861                        DeclarationWithType *adapteeDecl = adapterType->parameters.front();
    861862                        adapteeDecl->set_name( "_adaptee" );
    862863                        // do not carry over attributes to real type parameters/return values
     
    877878                        for ( ; tyParam != adapterType->get_forall().end(); ++tyArg, ++tyParam, ++realTyParam ) {
    878879                                assert( tyArg != realType->get_forall().end() );
    879                                 std::list< DeclarationWithType *>::iterator assertArg = (*tyArg)->get_assertions().begin();
    880                                 std::list< DeclarationWithType *>::iterator assertParam = (*tyParam)->get_assertions().begin();
    881                                 std::list< DeclarationWithType *>::iterator realAssertParam = (*realTyParam)->get_assertions().begin();
    882                                 for ( ; assertParam != (*tyParam)->get_assertions().end(); ++assertArg, ++assertParam, ++realAssertParam ) {
    883                                         assert( assertArg != (*tyArg)->get_assertions().end() );
     880                                std::vector< DeclarationWithType *>::iterator assertArg = (*tyArg)->assertions.begin();
     881                                std::vector< DeclarationWithType *>::iterator assertParam = (*tyParam)->assertions.begin();
     882                                std::vector< DeclarationWithType *>::iterator realAssertParam = (*realTyParam)->assertions.begin();
     883                                for ( ; assertParam != (*tyParam)->assertions.end(); ++assertArg, ++assertParam, ++realAssertParam ) {
     884                                        assert( assertArg != (*tyArg)->assertions.end() );
    884885                                        adapteeApp->get_args().push_back( makeAdapterArg( *assertParam, *assertArg, *realAssertParam, tyVars ) );
    885886                                } // for
    886887                        } // for
    887888
    888                         std::list< DeclarationWithType *>::iterator arg = realType->get_parameters().begin();
    889                         std::list< DeclarationWithType *>::iterator param = adapterType->get_parameters().begin();
    890                         std::list< DeclarationWithType *>::iterator realParam = adaptee->get_parameters().begin();
     889                        std::vector< DeclarationWithType *>::iterator arg = realType->parameters.begin();
     890                        std::vector< DeclarationWithType *>::iterator param = adapterType->parameters.begin();
     891                        std::vector< DeclarationWithType *>::iterator realParam = adaptee->parameters.begin();
    891892                        param++;                // skip adaptee parameter in the adapter type
    892                         if ( realType->get_returnVals().empty() ) {
     893                        if ( realType->returnVals.empty() ) {
    893894                                // void return
    894                                 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
     895                                addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars );
    895896                                bodyStmt = new ExprStmt( adapteeApp );
    896                         } else if ( isDynType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     897                        } else if ( isDynType( adaptee->returnVals.front()->get_type(), tyVars ) ) {
    897898                                // return type T
    898899                                if ( (*param)->get_name() == "" ) {
     
    901902                                } // if
    902903                                UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    903                                 UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->get_returnVals().front()->get_type()->clone() ) ) );
     904                                UntypedExpr *deref = UntypedExpr::createDeref( new CastExpr( new VariableExpr( *param++ ), new PointerType( Type::Qualifiers(), realType->returnVals.front()->get_type()->clone() ) ) );
    904905                                assign->get_args().push_back( deref );
    905                                 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
     906                                addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars );
    906907                                assign->get_args().push_back( adapteeApp );
    907908                                bodyStmt = new ExprStmt( assign );
    908909                        } else {
    909910                                // adapter for a function that returns a monomorphic value
    910                                 addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
     911                                addAdapterParams( adapteeApp, arg, param, adapterType->parameters.end(), realParam, tyVars );
    911912                                bodyStmt = new ReturnStmt( adapteeApp );
    912913                        } // if
     
    919920                void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {
    920921                        // collect a list of function types passed as parameters or implicit parameters (assertions)
    921                         std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
    922                         std::list< FunctionType *> functions;
    923                         for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar ) {
    924                                 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert ) {
    925                                         findFunction( (*assert)->get_type(), functions, exprTyVars, needsAdapter );
     922                        auto & paramList = functionType->parameters;
     923                        std::vector< FunctionType *> functions;
     924                        for ( auto tyVar : functionType->forall ) {
     925                                for ( auto assert : tyVar->assertions ) {
     926                                        findFunction( assert->get_type(), functions, exprTyVars, needsAdapter );
    926927                                } // for
    927928                        } // for
    928                         for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    929                                 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );
     929                        for ( auto arg : paramList ) {
     930                                findFunction( arg->get_type(), functions, exprTyVars, needsAdapter );
    930931                        } // for
    931932
     
    934935                        std::set< std::string > adaptersDone;
    935936
    936                         for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    937                                 FunctionType *originalFunction = (*funType)->clone();
    938                                 FunctionType *realFunction = (*funType)->clone();
     937                        for ( auto funType : functions ) {
     938                                FunctionType * originalFunction = funType->clone();
     939                                FunctionType * realFunction = funType->clone();
    939940                                std::string mangleName = SymTab::Mangler::mangle( realFunction );
    940941
     
    954955                                        if ( adapter == adapters.end() ) {
    955956                                                // adapter has not been created yet in the current scope, so define it
    956                                                 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
     957                                                FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars );
    957958                                                std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    958959                                                adapter = answer.first;
     
    12551256
    12561257                void Pass2::addAdapters( FunctionType *functionType ) {
    1257                         std::list< DeclarationWithType *> &paramList = functionType->parameters;
    1258                         std::list< FunctionType *> functions;
    1259                         for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    1260                                 Type *orig = (*arg)->get_type();
     1258                        auto & paramList = functionType->parameters;
     1259                        std::vector< FunctionType *> functions;
     1260                        for ( auto arg : paramList ) {
     1261                                Type *orig = arg->get_type();
    12611262                                findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter );
    1262                                 (*arg)->set_type( orig );
     1263                                arg->set_type( orig );
    12631264                        }
    12641265                        std::set< std::string > adaptersDone;
    1265                         for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    1266                                 std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
     1266                        for ( auto funType : functions ) {
     1267                                std::string mangleName = mangleAdapterName( funType, scopeTyVars );
    12671268                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
    12681269                                        std::string adapterName = makeAdapterName( mangleName );
    12691270                                        // adapter may not be used in body, pass along with unused attribute.
    1270                                         paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
     1271                                        paramList.insert( paramList.begin(), new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
    12711272                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
    12721273                                }
    12731274                        }
    1274 //  deleteAll( functions );
    12751275                }
    12761276
     
    13241324
    13251325                void Pass2::premutate( FunctionType *funcType ) {
     1326
     1327
     1328
     1329
     1330
     1331
     1332
     1333
     1334
     1335
     1336
     1337
     1338
     1339
     1340
     1341
     1342
     1343
     1344
    13261345                        GuardScope( scopeTyVars );
    13271346                        makeTyVarMap( funcType, scopeTyVars );
     
    13291348                        // move polymorphic return type to parameter list
    13301349                        if ( isDynRet( funcType ) ) {
    1331                                 ObjectDecl *ret = strict_dynamic_cast< ObjectDecl* >( funcType->get_returnVals().front() );
     1350                                ObjectDecl *ret = strict_dynamic_cast< ObjectDecl* >( funcType->returnVals.front() );
    13321351                                ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) );
    1333                                 funcType->get_parameters().push_front( ret );
    1334                                 funcType->get_returnVals().pop_front();
     1352                                funcType->parameters.insert( funcType->parameters.begin(), ret );
     1353                                funcType->returnVals.erase(funcType->returnVals.begin());
    13351354                                ret->set_init( nullptr ); // xxx - memory leak?
    13361355                        }
    13371356
    1338                         // add size/align and assertions for type parameters to parameter list
    1339                         std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
    1340                         std::list< DeclarationWithType *> inferredParams;
     1357                        // create a list of parameters after adding new ones
     1358                        std::vector<DeclarationWithType *> newParams;
     1359                        std::vector<DeclarationWithType *> inferredParams;
     1360
     1361                        // reserve some memory for these vectors
     1362                        // Number of elements needed should be somewhat linear with the number of parameters / forall
     1363                        // "somewhat linear" == 2X
     1364                        newParams.reserve(funcType->parameters.size() * 2 + funcType->forall.size() * 2);
     1365                        inferredParams.reserve(funcType->forall.size() * 2);
     1366
    13411367                        // size/align/offset parameters may not be used in body, pass along with unused attribute.
    13421368                        ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0,
     
    13441370                        ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0,
    13451371                                           new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
    1346                         for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    1347                                 ObjectDecl *sizeParm, *alignParm;
     1372
     1373                        // We do this several time, create a functor for it
     1374                        auto pushObj = [&newObj, &newParams]( const std::string & name ) {
     1375                                auto parm = newObj.clone();
     1376                                parm->set_name( name );
     1377                                newParams.push_back( parm );
     1378                        };
     1379
     1380                        // add size/align and assertions for type parameters to parameter list
     1381                        for ( auto tyParm : funcType->forall ) {
    13481382                                // add all size and alignment parameters to parameter list
    1349                                 if ( (*tyParm)->isComplete() ) {
    1350                                         TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
     1383                                if ( tyParm->isComplete() ) {
     1384                                        TypeInstType parmType( Type::Qualifiers(), tyParm->get_name(), tyParm );
    13511385                                        std::string parmName = mangleType( &parmType );
    1352 
    1353                                         sizeParm = newObj.clone();
    1354                                         sizeParm->set_name( sizeofName( parmName ) );
    1355                                         last = funcType->get_parameters().insert( last, sizeParm );
    1356                                         ++last;
    1357 
    1358                                         alignParm = newObj.clone();
    1359                                         alignParm->set_name( alignofName( parmName ) );
    1360                                         last = funcType->get_parameters().insert( last, alignParm );
    1361                                         ++last;
     1386                                        pushObj( sizeofName( parmName ) );
     1387                                        pushObj( alignofName( parmName ) );
    13621388                                }
    13631389                                // move all assertions into parameter list
    1364                                 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
     1390                                // move all assertions into parameter list
     1391                                for ( auto assert : tyParm->assertions ) {
    13651392                                        // assertion parameters may not be used in body, pass along with unused attribute.
    1366                                         (*assert)->get_attributes().push_back( new Attribute( "unused" ) );
    1367                                         inferredParams.push_back( *assert );
    1368                                 }
    1369                                 (*tyParm)->get_assertions().clear();
     1393                                        assert->attributes.push_back( new Attribute( "unused" ) );
     1394                                        inferredParams.push_back( assert );
     1395                                }
     1396                                tyParm->assertions.clear();
    13701397                        }
    13711398
    13721399                        // add size/align for generic parameter types to parameter list
    13731400                        std::set< std::string > seenTypes; // sizeofName for generic types we've seen
    1374                         for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
    1375                                 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );
    1376                                 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
     1401                        for ( DeclarationWithType * fnParm : funcType->parameters )
     1402                        {
     1403                                Type *polyType = isPolyType( fnParm->get_type(), scopeTyVars );
     1404                                if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) )
     1405                                {
    13771406                                        std::string typeName = mangleType( polyType );
    13781407                                        if ( seenTypes.count( typeName ) ) continue;
    13791408
    1380                                         ObjectDecl *sizeParm, *alignParm, *offsetParm;
    1381                                         sizeParm = newObj.clone();
    1382                                         sizeParm->set_name( sizeofName( typeName ) );
    1383                                         last = funcType->get_parameters().insert( last, sizeParm );
    1384                                         ++last;
    1385 
    1386                                         alignParm = newObj.clone();
    1387                                         alignParm->set_name( alignofName( typeName ) );
    1388                                         last = funcType->get_parameters().insert( last, alignParm );
    1389                                         ++last;
     1409                                        pushObj( sizeofName ( typeName ) );
     1410                                        pushObj( alignofName( typeName ) );
    13901411
    13911412                                        if ( StructInstType *polyBaseStruct = dynamic_cast< StructInstType* >( polyType ) ) {
    13921413                                                // NOTE zero-length arrays are illegal in C, so empty structs have no offset array
    13931414                                                if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) {
    1394                                                         offsetParm = newPtr.clone();
    1395                                                         offsetParm->set_name( offsetofName( typeName ) );
    1396                                                         last = funcType->get_parameters().insert( last, offsetParm );
    1397                                                         ++last;
     1415                                                        auto offset = newPtr.clone();
     1416                                                        offset->set_name( offsetofName( typeName ) );
     1417                                                        newParams.push_back( offset );
    13981418                                                }
    13991419                                        }
     
    14031423
    14041424                        // splice assertion parameters into parameter list
    1405                         funcType->get_parameters().splice( last, inferredParams );
     1425                        std::copy( inferredParams      , std::back_inserter(newParams) );
     1426                        std::copy( funcType->parameters, std::back_inserter(newParams) );
     1427
     1428                        funcType->parameters.swap(newParams);
     1429
    14061430                        addAdapters( funcType );
    14071431                }
     
    14701494
    14711495                        // make sure that any type information passed into the function is accounted for
    1472                         for ( std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); fnParm != funcType->get_parameters().end(); ++fnParm ) {
     1496                        for ( auto fnParm : funcType->parameters ) {
    14731497                                // condition here duplicates that in Pass2::mutate( FunctionType* )
    1474                                 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );
     1498                                Type *polyType = isPolyType( fnParm->get_type(), scopeTyVars );
    14751499                                if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
    14761500                                        knownLayouts.insert( mangleType( polyType ) );
  • src/GenPoly/FindFunction.cc

    r43e0949 r2f42718  
    2929        class FindFunction : public WithGuards, public WithVisitorRef<FindFunction>, public WithShortCircuiting {
    3030          public:
    31                 FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );
     31                FindFunction( std::vector< FunctionType* > & functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate );
    3232
    3333                void premutate( FunctionType * functionType );
     
    3737                void handleForall( const Type::ForallList &forall );
    3838
    39                 std::list< FunctionType* > &functions;
     39                std::vector< FunctionType* > &functions;
    4040                TyVarMap tyVars;
    4141                bool replaceMode;
     
    4343        };
    4444
    45         void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
     45        void findFunction( Type *type, std::vector< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
    4646                PassVisitor<FindFunction> finder( functions, tyVars, false, predicate );
    4747                type->acceptMutator( finder );
    4848        }
    4949
    50         void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
     50        void findAndReplaceFunction( Type *&type, std::vector< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ) {
    5151                PassVisitor<FindFunction> finder( functions, tyVars, true, predicate );
    5252                type = type->acceptMutator( finder );
    5353        }
    5454
    55         FindFunction::FindFunction( std::list< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )
     55        FindFunction::FindFunction( std::vector< FunctionType* > &functions, const TyVarMap &tyVars, bool replaceMode, FindFunctionPredicate predicate )
    5656                : functions( functions ), tyVars( tyVars ), replaceMode( replaceMode ), predicate( predicate ) {
    5757        }
     
    7070                GuardScope( tyVars );
    7171                handleForall( functionType->get_forall() );
    72                 mutateAll( functionType->get_returnVals(), *visitor );
     72                mutateAll( functionType->returnVals, *visitor );
    7373        }
    7474
  • src/GenPoly/FindFunction.h

    r43e0949 r2f42718  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FindFunction.h -- 
     7// FindFunction.h --
    88//
    99// Author           : Richard C. Bilson
     
    2727
    2828        /// recursively walk `type`, placing all functions that match `predicate` under `tyVars` into `functions`
    29         void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
     29        void findFunction( Type *type, std::vector< FunctionType* > & functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
    3030        /// like `findFunction`, but also replaces the function type with void ()(void)
    31         void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
     31        void findAndReplaceFunction( Type *&type, std::vector< FunctionType* > & functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
    3232} // namespace GenPoly
    3333
  • src/GenPoly/GenPoly.cc

    r43e0949 r2f42718  
    144144
    145145        ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &forallTypes ) {
    146                 if ( function->get_returnVals().empty() ) return 0;
    147 
    148                 return (ReferenceToType*)isDynType( function->get_returnVals().front()->get_type(), forallTypes );
     146                if ( function->returnVals.empty() ) return 0;
     147
     148                return (ReferenceToType*)isDynType( function->returnVals.front()->get_type(), forallTypes );
    149149        }
    150150
    151151        ReferenceToType *isDynRet( FunctionType *function ) {
    152                 if ( function->get_returnVals().empty() ) return 0;
     152                if ( function->returnVals.empty() ) return 0;
    153153
    154154                TyVarMap forallTypes( TypeDecl::Data{} );
    155155                makeTyVarMap( function, forallTypes );
    156                 return (ReferenceToType*)isDynType( function->get_returnVals().front()->get_type(), forallTypes );
     156                return (ReferenceToType*)isDynType( function->returnVals.front()->get_type(), forallTypes );
    157157        }
    158158
    159159        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    160 //              if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    161 //                      return true;
    162 //              } // if
    163160                if ( isDynRet( adaptee, tyVars ) ) return true;
    164161
    165                 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) {
    166 //                      if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) {
    167                         if ( isDynType( (*innerArg)->get_type(), tyVars ) ) {
     162                for ( auto innerArg : adaptee->parameters ) {
     163                        if ( isDynType( innerArg->get_type(), tyVars ) ) {
    168164                                return true;
    169165                        } // if
     
    315311                /// Flattens a declaration list
    316312                template<typename Output>
    317                 void flattenList( list< DeclarationWithType* > src, Output out ) {
     313                void flattenList( vector< DeclarationWithType* > src, Output out ) {
    318314                        for ( DeclarationWithType* decl : src ) {
    319315                                ResolvExpr::flatten( decl->get_type(), out );
     
    323319                /// Flattens a list of types
    324320                template<typename Output>
    325                 void flattenList( list< Type* > src, Output out ) {
     321                void flattenList( vector< Type* > src, Output out ) {
    326322                        for ( Type* ty : src ) {
    327323                                ResolvExpr::flatten( ty, out );
     
    395391
    396392                        vector<Type*> aparams, bparams;
    397                         flattenList( af->get_parameters(), back_inserter( aparams ) );
    398                         flattenList( bf->get_parameters(), back_inserter( bparams ) );
     393                        flattenList( af->parameters, back_inserter( aparams ) );
     394                        flattenList( bf->parameters, back_inserter( bparams ) );
    399395                        if ( aparams.size() != bparams.size() ) return false;
    400396
    401397                        vector<Type*> areturns, breturns;
    402                         flattenList( af->get_returnVals(), back_inserter( areturns ) );
    403                         flattenList( bf->get_returnVals(), back_inserter( breturns ) );
     398                        flattenList( af->returnVals, back_inserter( areturns ) );
     399                        flattenList( bf->returnVals, back_inserter( breturns ) );
    404400                        if ( areturns.size() != breturns.size() ) return false;
    405401
     
    429425
    430426                        vector<Type*> atypes, btypes;
    431                         flattenList( at->get_types(), back_inserter( atypes ) );
    432                         flattenList( bt->get_types(), back_inserter( btypes ) );
     427                        flattenList( at->types, back_inserter( atypes ) );
     428                        flattenList( bt->types, back_inserter( btypes ) );
    433429                        if ( atypes.size() != btypes.size() ) return false;
    434430
  • src/GenPoly/Specialize.cc

    r43e0949 r2f42718  
    9191                if ( tuple1 && tuple2 ) {
    9292                        if ( tuple1->size() != tuple2->size() ) return false;
    93                         for ( auto types : group_iterate( tuple1->get_types(), tuple2->get_types() ) ) {
     93                        for ( auto types : group_iterate( tuple1->types, tuple2->types ) ) {
    9494                                if ( ! matchingTupleStructure( std::get<0>( types ), std::get<1>( types ) ) ) return false;
    9595                        }
     
    115115        size_t functionParameterSize( FunctionType * ftype ) {
    116116                size_t sz = 0;
    117                 for ( DeclarationWithType * p : ftype->get_parameters() ) {
     117                for ( DeclarationWithType * p : ftype->parameters ) {
    118118                        sz += singleParameterSize( p->get_type() );
    119119                }
     
    227227                }
    228228                std::unique_ptr< FunctionType > actualTypeManager( actualType ); // for RAII
    229                 std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin();
    230                 std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end();
     229                auto actualBegin = actualType->parameters.begin();
     230                auto actualEnd   = actualType->parameters.end();
    231231
    232232                std::list< Expression * > args;
    233                 for ( DeclarationWithType* param : thunkFunc->get_functionType()->get_parameters() ) {
     233                for ( DeclarationWithType* param : thunkFunc->get_functionType()->parameters ) {
    234234                        // name each thunk parameter and explode it - these are then threaded back into the actual function call.
    235235                        param->set_name( paramNamer.newName() );
     
    281281                FunctionType *function = getFunctionType( appExpr->function->result );
    282282                assert( function );
    283                 std::list< DeclarationWithType* >::iterator formal;
     283                std::vector< DeclarationWithType* >::iterator formal;
    284284                std::list< Expression* >::iterator actual;
    285                 for ( formal = function->get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {
     285                for ( formal = function->parameters.begin(), actual = appExpr->get_args().begin(); formal != function->parameters.end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {
    286286                        *actual = doSpecialization( (*formal)->get_type(), *actual, &appExpr->inferParams );
    287287                }
Note: See TracChangeset for help on using the changeset viewer.