Changeset 0b1ca47 for src


Ignore:
Timestamp:
Oct 28, 2022, 6:04:29 PM (18 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
7a2057a
Parents:
f1f481a
Message:

Cleaning old box pass for easier translation. Changed over for loops, with extra const. Also an extra comment in another file I found.

Location:
src/GenPoly
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rf1f481a r0b1ca47  
    249249                std::list< TypeDecl * > otypeDecls;
    250250
    251                 for ( std::list< TypeDecl* >::const_iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
    252                         if ( (*decl)->isComplete() ) {
    253                                 otypeDecls.push_back( *decl );
     251                for ( TypeDecl * const decl : decls ) {
     252                        if ( decl->isComplete() ) {
     253                                otypeDecls.push_back( decl );
    254254                        }
    255255                }
     
    262262                BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    263263
    264                 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
    265                         TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param );
     264                for ( TypeDecl * const param : otypeParams ) {
     265                        TypeInstType paramType( Type::Qualifiers(), param->get_name(), param );
    266266                        std::string paramName = mangleType( &paramType );
    267267                        layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) );
     
    411411                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
    412412                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
    413                 for ( std::list< Declaration* >::const_iterator member = unionDecl->get_members().begin(); member != unionDecl->get_members().end(); ++member ) {
    414                         DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member );
     413                for ( Declaration * const member : unionDecl->members ) {
     414                        DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( member );
    415415                        assert( dwt );
    416416                        Type *memberType = dwt->get_type();
     
    440440                        // to take those polymorphic types as pointers. Therefore, there can be two different functions
    441441                        // with the same mangled name, so we need to further mangle the names.
    442                         for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) {
    443                                 if ( isPolyType( (*retval)->get_type(), tyVars ) ) {
     442                        for ( DeclarationWithType * const ret : function->get_returnVals() ) {
     443                                if ( isPolyType( ret->get_type(), tyVars ) ) {
    444444                                        name << "P";
    445445                                } else {
     
    448448                        }
    449449                        name << "_";
    450                         std::list< DeclarationWithType *> &paramList = function->get_parameters();
    451                         for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    452                                 if ( isPolyType( (*arg)->get_type(), tyVars ) ) {
     450                        for ( DeclarationWithType * const arg : function->get_parameters() ) {
     451                                if ( isPolyType( arg->get_type(), tyVars ) ) {
    453452                                        name << "P";
    454453                                } else {
     
    492491                                std::list< DeclarationWithType *> &paramList = functionType->parameters;
    493492                                std::list< FunctionType *> functions;
    494                                 for ( Type::ForallList::iterator tyVar = functionType->forall.begin(); tyVar != functionType->forall.end(); ++tyVar ) {
    495                                         for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert ) {
    496                                                 findFunction( (*assert)->get_type(), functions, scopeTyVars, needsAdapter );
     493                                for ( TypeDecl * const tyVar : functionType->forall ) {
     494                                        for ( DeclarationWithType * const assert : tyVar->assertions ) {
     495                                                findFunction( assert->get_type(), functions, scopeTyVars, needsAdapter );
    497496                                        } // for
    498497                                } // for
    499                                 for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    500                                         findFunction( (*arg)->get_type(), functions, scopeTyVars, needsAdapter );
     498                                for ( DeclarationWithType * const arg : paramList ) {
     499                                        findFunction( arg->get_type(), functions, scopeTyVars, needsAdapter );
    501500                                } // for
    502501
    503                                 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    504                                         std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
     502                                for ( FunctionType * const funType : functions ) {
     503                                        std::string mangleName = mangleAdapterName( funType, scopeTyVars );
    505504                                        if ( adapters.find( mangleName ) == adapters.end() ) {
    506505                                                std::string adapterName = makeAdapterName( mangleName );
    507                                                 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), nullptr ) ) );
     506                                                adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) );
    508507                                        } // if
    509508                                } // for
     
    562561                void Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
    563562                        // pass size/align for type variables
    564                         for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
     563                        for ( std::pair<std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
    565564                                ResolvExpr::EqvClass eqvClass;
    566565                                assert( env );
    567                                 if ( tyParm->second.isComplete ) {
    568                                         Type *concrete = env->lookup( tyParm->first );
     566                                if ( tyParam.second.isComplete ) {
     567                                        Type *concrete = env->lookup( tyParam.first );
    569568                                        if ( concrete ) {
    570569                                                arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) );
     
    574573                                        } else {
    575574                                                // xxx - should this be an assertion?
    576                                                 SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParm->first, " in application " ) );
     575                                                SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParam.first, " in application " ) );
    577576                                        } // if
    578577                                } // if
     
    890889                void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {
    891890                        // collect a list of function types passed as parameters or implicit parameters (assertions)
    892                         std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
    893                         std::list< FunctionType *> functions;
    894                         for ( Type::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar ) {
    895                                 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->get_assertions().begin(); assert != (*tyVar)->get_assertions().end(); ++assert ) {
    896                                         findFunction( (*assert)->get_type(), functions, exprTyVars, needsAdapter );
     891                        std::list< FunctionType*> functions;
     892                        for ( TypeDecl * const tyVar : functionType->get_forall() ) {
     893                                for ( DeclarationWithType * const assert : tyVar->get_assertions() ) {
     894                                        findFunction( assert->get_type(), functions, exprTyVars, needsAdapter );
    897895                                } // for
    898896                        } // for
    899                         for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    900                                 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );
     897                        for ( DeclarationWithType * const arg : functionType->get_parameters() ) {
     898                                findFunction( arg->get_type(), functions, exprTyVars, needsAdapter );
    901899                        } // for
    902900
     
    905903                        std::set< std::string > adaptersDone;
    906904
    907                         for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    908                                 FunctionType *originalFunction = (*funType)->clone();
    909                                 FunctionType *realFunction = (*funType)->clone();
     905                        for ( FunctionType * const funType : functions ) {
     906                                FunctionType *originalFunction = funType->clone();
     907                                FunctionType *realFunction = funType->clone();
    910908                                std::string mangleName = SymTab::Mangler::mangle( realFunction );
    911909
     
    925923                                        if ( adapter == adapters.end() ) {
    926924                                                // adapter has not been created yet in the current scope, so define it
    927                                                 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
     925                                                FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars );
    928926                                                std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    929927                                                adapter = answer.first;
     
    12281226                        std::list< DeclarationWithType *> &paramList = functionType->parameters;
    12291227                        std::list< FunctionType *> functions;
    1230                         for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    1231                                 Type *orig = (*arg)->get_type();
     1228                        for (  DeclarationWithType * const arg : functionType->parameters ) {
     1229                                Type *orig = arg->get_type();
    12321230                                findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter );
    1233                                 (*arg)->set_type( orig );
     1231                                arg->set_type( orig );
    12341232                        }
    12351233                        std::set< std::string > adaptersDone;
    1236                         for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    1237                                 std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
     1234                        for ( FunctionType * const funType : functions ) {
     1235                                std::string mangleName = mangleAdapterName( funType, scopeTyVars );
    12381236                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
    12391237                                        std::string adapterName = makeAdapterName( mangleName );
    12401238                                        // adapter may not be used in body, pass along with unused attribute.
    1241                                         paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
     1239                                        paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
    12421240                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
    12431241                                }
     
    13161314                        ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0,
    13171315                                           new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
    1318                         for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
     1316                        for ( TypeDecl * const tyParam : funcType->get_forall() ) {
    13191317                                ObjectDecl *sizeParm, *alignParm;
    13201318                                // add all size and alignment parameters to parameter list
    1321                                 if ( (*tyParm)->isComplete() ) {
    1322                                         TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
     1319                                if ( tyParam->isComplete() ) {
     1320                                        TypeInstType parmType( Type::Qualifiers(), tyParam->get_name(), tyParam );
    13231321                                        std::string parmName = mangleType( &parmType );
    13241322
     
    13341332                                }
    13351333                                // move all assertions into parameter list
    1336                                 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
     1334                                for ( DeclarationWithType * const assert : tyParam->get_assertions() ) {
    13371335                                        // assertion parameters may not be used in body, pass along with unused attribute.
    1338                                         (*assert)->get_attributes().push_back( new Attribute( "unused" ) );
    1339                                         inferredParams.push_back( *assert );
    1340                                 }
    1341                                 (*tyParm)->get_assertions().clear();
     1336                                        assert->get_attributes().push_back( new Attribute( "unused" ) );
     1337                                        inferredParams.push_back( assert );
     1338                                }
     1339                                tyParam->get_assertions().clear();
    13421340                        }
    13431341
    13441342                        // add size/align for generic parameter types to parameter list
    13451343                        std::set< std::string > seenTypes; // sizeofName for generic types we've seen
    1346                         for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
    1347                                 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );
     1344                        for ( DeclarationWithType * const fnParam : funcType->get_parameters() ) {
     1345                                Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars );
    13481346                                if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
    13491347                                        std::string typeName = mangleType( polyType );
     
    14641462
    14651463                        // make sure that any type information passed into the function is accounted for
    1466                         for ( std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); fnParm != funcType->get_parameters().end(); ++fnParm ) {
     1464                        for ( DeclarationWithType * const fnParam : funcType->get_parameters() ) {
    14671465                                // condition here duplicates that in Pass2::mutate( FunctionType* )
    1468                                 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );
     1466                                Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars );
    14691467                                if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
    14701468                                        knownLayouts.insert( mangleType( polyType ) );
     
    15391537                /// Finds the member in the base list that matches the given declaration; returns its index, or -1 if not present
    15401538                long findMember( DeclarationWithType *memberDecl, std::list< Declaration* > &baseDecls ) {
    1541                         long i = 0;
    1542                         for(std::list< Declaration* >::const_iterator decl = baseDecls.begin(); decl != baseDecls.end(); ++decl, ++i ) {
    1543                                 if ( memberDecl->get_name() != (*decl)->get_name() )
     1539                        for ( auto pair : enumerate( baseDecls ) ) {
     1540                                Declaration * decl = pair.val;
     1541                                size_t i = pair.idx;
     1542                                if ( memberDecl->get_name() != decl->get_name() )
    15441543                                        continue;
    15451544
    15461545                                if ( memberDecl->get_name().empty() ) {
    15471546                                        // plan-9 field: match on unique_id
    1548                                         if ( memberDecl->get_uniqueId() == (*decl)->get_uniqueId() )
     1547                                        if ( memberDecl->get_uniqueId() == decl->get_uniqueId() )
    15491548                                                return i;
    15501549                                        else
     
    15521551                                }
    15531552
    1554                                 DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( *decl );
     1553                                DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( decl );
    15551554
    15561555                                if ( memberDecl->get_mangleName().empty() || declWithType->get_mangleName().empty() ) {
     
    16631662
    16641663                void PolyGenericCalculator::addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams ) {
    1665                         for ( std::list< Type* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
    1666                                 if ( findGeneric( *param ) ) {
     1664                        for ( Type * const param : otypeParams ) {
     1665                                if ( findGeneric( param ) ) {
    16671666                                        // push size/align vars for a generic parameter back
    1668                                         std::string paramName = mangleType( *param );
     1667                                        std::string paramName = mangleType( param );
    16691668                                        layoutCall->get_args().push_back( new NameExpr( sizeofName( paramName ) ) );
    16701669                                        layoutCall->get_args().push_back( new NameExpr( alignofName( paramName ) ) );
    16711670                                } else {
    1672                                         layoutCall->get_args().push_back( new SizeofExpr( (*param)->clone() ) );
    1673                                         layoutCall->get_args().push_back( new AlignofExpr( (*param)->clone() ) );
     1671                                        layoutCall->get_args().push_back( new SizeofExpr( param->clone() ) );
     1672                                        layoutCall->get_args().push_back( new AlignofExpr( param->clone() ) );
    16741673                                }
    16751674                        }
     
    19321931// compile-command: "make install" //
    19331932// End: //
     1933
  • src/GenPoly/InstantiateGenericNew.cpp

    rf1f481a r0b1ca47  
    476476};
    477477
    478 // I think this and the UnionInstType can be made into a template function.
    479478ast::Type const * GenericInstantiator::postvisit(
    480479                ast::StructInstType const * inst ) {
Note: See TracChangeset for help on using the changeset viewer.