- Timestamp:
- Oct 28, 2022, 6:04:29 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 7a2057a
- Parents:
- f1f481a
- Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
rf1f481a r0b1ca47 249 249 std::list< TypeDecl * > otypeDecls; 250 250 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 ); 254 254 } 255 255 } … … 262 262 BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 263 263 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 ); 266 266 std::string paramName = mangleType( ¶mType ); 267 267 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); … … 411 411 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) ); 412 412 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 ); 415 415 assert( dwt ); 416 416 Type *memberType = dwt->get_type(); … … 440 440 // to take those polymorphic types as pointers. Therefore, there can be two different functions 441 441 // 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 ) ) { 444 444 name << "P"; 445 445 } else { … … 448 448 } 449 449 name << "_"; 450 std::list< DeclarationWithType *> ¶mList = 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 ) ) { 453 452 name << "P"; 454 453 } else { … … 492 491 std::list< DeclarationWithType *> ¶mList = functionType->parameters; 493 492 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 ); 497 496 } // for 498 497 } // 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 ); 501 500 } // for 502 501 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 ); 505 504 if ( adapters.find( mangleName ) == adapters.end() ) { 506 505 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 ) ) ); 508 507 } // if 509 508 } // for … … 562 561 void Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 563 562 // 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 ) { 565 564 ResolvExpr::EqvClass eqvClass; 566 565 assert( env ); 567 if ( tyPar m->second.isComplete ) {568 Type *concrete = env->lookup( tyPar m->first );566 if ( tyParam.second.isComplete ) { 567 Type *concrete = env->lookup( tyParam.first ); 569 568 if ( concrete ) { 570 569 arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) ); … … 574 573 } else { 575 574 // xxx - should this be an assertion? 576 SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyPar m->first, " in application " ) );575 SemanticError( appExpr, toString( *env, "\nunbound type variable: ", tyParam.first, " in application " ) ); 577 576 } // if 578 577 } // if … … 890 889 void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) { 891 890 // collect a list of function types passed as parameters or implicit parameters (assertions) 892 std::list< DeclarationWithType *> ¶mList = 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 ); 897 895 } // for 898 896 } // 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 ); 901 899 } // for 902 900 … … 905 903 std::set< std::string > adaptersDone; 906 904 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(); 910 908 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 911 909 … … 925 923 if ( adapter == adapters.end() ) { 926 924 // 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 ); 928 926 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) ); 929 927 adapter = answer.first; … … 1228 1226 std::list< DeclarationWithType *> ¶mList = functionType->parameters; 1229 1227 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(); 1232 1230 findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter ); 1233 (*arg)->set_type( orig );1231 arg->set_type( orig ); 1234 1232 } 1235 1233 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 ); 1238 1236 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 1239 1237 std::string adapterName = makeAdapterName( mangleName ); 1240 1238 // 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" ) } ) ); 1242 1240 adaptersDone.insert( adaptersDone.begin(), mangleName ); 1243 1241 } … … 1316 1314 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1317 1315 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() ) { 1319 1317 ObjectDecl *sizeParm, *alignParm; 1320 1318 // 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 ); 1323 1321 std::string parmName = mangleType( &parmType ); 1324 1322 … … 1334 1332 } 1335 1333 // 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() ) { 1337 1335 // 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(); 1342 1340 } 1343 1341 1344 1342 // add size/align for generic parameter types to parameter list 1345 1343 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 ); 1348 1346 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { 1349 1347 std::string typeName = mangleType( polyType ); … … 1464 1462 1465 1463 // 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() ) { 1467 1465 // condition here duplicates that in Pass2::mutate( FunctionType* ) 1468 Type *polyType = isPolyType( (*fnParm)->get_type(), scopeTyVars );1466 Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars ); 1469 1467 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { 1470 1468 knownLayouts.insert( mangleType( polyType ) ); … … 1539 1537 /// Finds the member in the base list that matches the given declaration; returns its index, or -1 if not present 1540 1538 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() ) 1544 1543 continue; 1545 1544 1546 1545 if ( memberDecl->get_name().empty() ) { 1547 1546 // plan-9 field: match on unique_id 1548 if ( memberDecl->get_uniqueId() == (*decl)->get_uniqueId() )1547 if ( memberDecl->get_uniqueId() == decl->get_uniqueId() ) 1549 1548 return i; 1550 1549 else … … 1552 1551 } 1553 1552 1554 DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( *decl );1553 DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( decl ); 1555 1554 1556 1555 if ( memberDecl->get_mangleName().empty() || declWithType->get_mangleName().empty() ) { … … 1663 1662 1664 1663 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 ) ) { 1667 1666 // push size/align vars for a generic parameter back 1668 std::string paramName = mangleType( *param );1667 std::string paramName = mangleType( param ); 1669 1668 layoutCall->get_args().push_back( new NameExpr( sizeofName( paramName ) ) ); 1670 1669 layoutCall->get_args().push_back( new NameExpr( alignofName( paramName ) ) ); 1671 1670 } 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() ) ); 1674 1673 } 1675 1674 } … … 1932 1931 // compile-command: "make install" // 1933 1932 // End: // 1933 -
src/GenPoly/InstantiateGenericNew.cpp
rf1f481a r0b1ca47 476 476 }; 477 477 478 // I think this and the UnionInstType can be made into a template function.479 478 ast::Type const * GenericInstantiator::postvisit( 480 479 ast::StructInstType const * inst ) {
Note: See TracChangeset
for help on using the changeset viewer.