Changeset 24d6572 for src/GenPoly/Box.cc
- Timestamp:
- Jun 12, 2023, 2:45:32 PM (2 years ago)
- Branches:
- ast-experimental, master
- Children:
- 62d62db
- Parents:
- 34b4268 (diff), 251ce80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r34b4268 r24d6572 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Dec 13 23:40:34 201913 // Update Count : 34 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Dec 19 16:36:00 2022 13 // Update Count : 348 14 14 // 15 16 #include "Box.h" 15 17 16 18 #include <algorithm> // for mismatch … … 24 26 #include <utility> // for pair 25 27 26 #include "Box.h"27 28 28 #include "CodeGen/OperatorTable.h" 29 29 #include "Common/PassVisitor.h" // for PassVisitor … … 31 31 #include "Common/SemanticError.h" // for SemanticError 32 32 #include "Common/UniqueName.h" // for UniqueName 33 #include "Common/ utility.h" // for toString33 #include "Common/ToString.hpp" // for toCString 34 34 #include "FindFunction.h" // for findFunction, findAndReplace... 35 35 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::const_i... … … 37 37 #include "InitTweak/InitTweak.h" // for getFunctionName, isAssignment 38 38 #include "Lvalue.h" // for generalizedLvalue 39 #include "ResolvExpr/ typeops.h"// for typesCompatible39 #include "ResolvExpr/Unify.h" // for typesCompatible 40 40 #include "ScopedSet.h" // for ScopedSet, ScopedSet<>::iter... 41 41 #include "ScrubTyVars.h" // for ScrubTyVars … … 72 72 }; 73 73 74 /// Updates the call sites of polymorphic functions. 74 75 /// Replaces polymorphic return types with out-parameters, 75 76 /// replaces calls to polymorphic functions with adapter calls, 76 77 /// and adds appropriate type variables to the function call. 77 class Pass1 final : public BoxPass, public WithConstTypeSubstitution, public WithStmtsToAdd, public WithGuards, public WithVisitorRef<Pass1>, public WithShortCircuiting {78 class CallAdapter final : public BoxPass, public WithConstTypeSubstitution, public WithStmtsToAdd, public WithGuards, public WithVisitorRef<CallAdapter>, public WithShortCircuiting { 78 79 public: 79 Pass1(); 80 80 CallAdapter(); 81 82 void premutate( Declaration * declaration ); 81 83 void premutate( FunctionDecl * functionDecl ); 82 84 void premutate( TypeDecl * typeDecl ); … … 138 140 }; 139 141 142 /// Updates declarations (and types) that require adapters. 140 143 /// * Moves polymorphic returns in function types to pointer-type parameters 141 144 /// * adds type size and assertion parameters to parameter lists 142 struct Pass2final : public BoxPass, public WithGuards {145 struct DeclAdapter final : public BoxPass, public WithGuards { 143 146 void handleAggDecl(); 144 147 … … 210 213 }; 211 214 215 /// Erases unneeded/unwanted polymorphic information. 212 216 /// Replaces initialization of polymorphic values with alloca, 213 217 /// declaration of dtype/ftype with appropriate void expression, 214 218 /// sizeof expressions of polymorphic types with the proper variable, 215 219 /// and strips fields from generic struct declarations. 216 struct Pass3 final : public BoxPass, public WithGuards { 217 template< typename DeclClass > 218 void handleDecl( DeclClass * decl, Type * type ); 219 220 struct Eraser final { 220 221 void premutate( ObjectDecl * objectDecl ); 221 222 void premutate( FunctionDecl * functionDecl ); … … 223 224 void premutate( StructDecl * structDecl ); 224 225 void premutate( UnionDecl * unionDecl ); 225 void premutate( TypeDecl * typeDecl );226 void premutate( PointerType * pointerType );227 void premutate( FunctionType * funcType );228 226 }; 229 227 } // anonymous namespace … … 231 229 void box( std::list< Declaration *>& translationUnit ) { 232 230 PassVisitor<LayoutFunctionBuilder> layoutBuilder; 233 PassVisitor< Pass1> pass1;234 PassVisitor< Pass2> pass2;231 PassVisitor<CallAdapter> callAdapter; 232 PassVisitor<DeclAdapter> declAdapter; 235 233 PassVisitor<PolyGenericCalculator> polyCalculator; 236 PassVisitor< Pass3> pass3;234 PassVisitor<Eraser> eraser; 237 235 238 236 acceptAll( translationUnit, layoutBuilder ); 239 mutateAll( translationUnit, pass1);240 mutateAll( translationUnit, pass2);237 mutateAll( translationUnit, callAdapter ); 238 mutateAll( translationUnit, declAdapter ); 241 239 mutateAll( translationUnit, polyCalculator ); 242 mutateAll( translationUnit, pass3);240 mutateAll( translationUnit, eraser ); 243 241 } 244 242 245 ////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////////243 ////////////////////////////////// LayoutFunctionBuilder //////////////////////////////////////// 246 244 247 245 /// Get a list of type declarations that will affect a layout function … … 423 421 } 424 422 425 ////////////////////////////////////////// Pass1 ////////////////////////////////////////////////////423 ////////////////////////////////////////////// CallAdapter ////////////////////////////////////// 426 424 427 425 namespace { 428 426 std::string makePolyMonoSuffix( FunctionType const * function, const TyVarMap &tyVars ) { 429 std::stringstream name;430 431 427 // NOTE: this function previously used isPolyObj, which failed to produce 432 428 // the correct thing in some situations. It's not clear to me why this wasn't working. … … 435 431 // to take those polymorphic types as pointers. Therefore, there can be two different functions 436 432 // with the same mangled name, so we need to further mangle the names. 433 std::stringstream name; 437 434 for ( DeclarationWithType const * const ret : function->returnVals ) { 438 if ( isPolyType( ret->get_type(), tyVars ) ) { 439 name << "P"; 440 } else { 441 name << "M"; 442 } 443 } 444 name << "_"; 435 name << ( isPolyType( ret->get_type(), tyVars ) ? 'P' : 'M' ); 436 } 437 name << '_'; 445 438 for ( DeclarationWithType const * const arg : function->parameters ) { 446 if ( isPolyType( arg->get_type(), tyVars ) ) { 447 name << "P"; 448 } else { 449 name << "M"; 450 } 451 } // for 439 name << ( isPolyType( arg->get_type(), tyVars ) ? 'P' : 'M' ); 440 } 452 441 return name.str(); 453 442 } … … 465 454 Type *replaceWithConcrete( Type *type, TypeSubstitution const * env, bool doClone = true ); 466 455 467 Pass1::Pass1() : tempNamer( "_temp" ) {} 468 469 void Pass1::premutate( FunctionDecl *functionDecl ) { 456 CallAdapter::CallAdapter() : tempNamer( "_temp" ) {} 457 458 void CallAdapter::premutate( Declaration * ) { 459 // Prevent type declaration information from leaking out. 460 GuardScope( scopeTyVars ); 461 } 462 463 void CallAdapter::premutate( FunctionDecl *functionDecl ) { 470 464 if ( functionDecl->get_statements() ) { // empty routine body ? 471 465 // std::cerr << "mutating function: " << functionDecl->get_mangleName() << std::endl; … … 500 494 for ( FunctionType const * const funType : functions ) { 501 495 std::string mangleName = mangleAdapterName( funType, scopeTyVars ); 502 if ( adapters.find( mangleName ) == adapters.end() ) {496 if ( !adapters.contains( mangleName ) ) { 503 497 std::string adapterName = makeAdapterName( mangleName ); 504 498 adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) ); … … 509 503 } 510 504 511 void Pass1::premutate( TypeDecl *typeDecl ) {505 void CallAdapter::premutate( TypeDecl *typeDecl ) { 512 506 addToTyVarMap( typeDecl, scopeTyVars ); 513 507 } 514 508 515 void Pass1::premutate( CommaExpr *commaExpr ) {509 void CallAdapter::premutate( CommaExpr *commaExpr ) { 516 510 // Attempting to find application expressions that were mutated by the copy constructor passes 517 511 // to use an explicit return variable, so that the variable can be reused as a parameter to the … … 531 525 } 532 526 533 std::list< Expression *>::iterator Pass1::passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ) {527 std::list< Expression *>::iterator CallAdapter::passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ) { 534 528 Type *polyType = isPolyType( parmType, exprTyVars ); 535 529 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { … … 558 552 } 559 553 560 std::list< Expression *>::iterator Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, const TyVarMap &exprTyVars ) {554 std::list< Expression *>::iterator CallAdapter::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, const TyVarMap &exprTyVars ) { 561 555 assert( env ); 562 556 std::list< Expression *>::iterator arg = appExpr->args.begin(); … … 568 562 // even when converted to strings, sort in the original order. 569 563 // (At least, that is the best explination I have.) 570 for ( std::pair< std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {564 for ( std::pair<const std::string, TypeDecl::Data> const & tyParam : exprTyVars ) { 571 565 if ( !tyParam.second.isComplete ) continue; 572 566 Type *concrete = env->lookup( tyParam.first ); … … 611 605 } 612 606 613 ObjectDecl * Pass1::makeTemporary( Type *type ) {607 ObjectDecl *CallAdapter::makeTemporary( Type *type ) { 614 608 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, type, 0 ); 615 609 stmtsToAddBefore.push_back( new DeclStmt( newObj ) ); … … 617 611 } 618 612 619 Expression * Pass1::addRetParam( ApplicationExpr *appExpr, Type *retType ) {613 Expression *CallAdapter::addRetParam( ApplicationExpr *appExpr, Type *retType ) { 620 614 // Create temporary to hold return value of polymorphic function and produce that temporary as a result 621 615 // using a comma expression. … … 680 674 } 681 675 682 Expression * Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType ) {676 Expression *CallAdapter::addDynRetParam( ApplicationExpr *appExpr, Type *dynType ) { 683 677 Type *concrete = replaceWithConcrete( dynType, env ); 684 678 // add out-parameter for return value … … 686 680 } 687 681 688 Expression * Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function ) {682 Expression *CallAdapter::applyAdapter( ApplicationExpr *appExpr, FunctionType *function ) { 689 683 Expression *ret = appExpr; 690 684 if ( isDynRet( function, scopeTyVars ) ) { … … 735 729 } 736 730 737 void Pass1::boxParam( Expression *&arg, Type *param, const TyVarMap &exprTyVars ) {731 void CallAdapter::boxParam( Expression *&arg, Type *param, const TyVarMap &exprTyVars ) { 738 732 assertf( arg->result, "arg does not have result: %s", toString( arg ).c_str() ); 739 733 addCast( arg, param, exprTyVars ); … … 770 764 } 771 765 772 void Pass1::boxParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *function, const TyVarMap &exprTyVars ) {766 void CallAdapter::boxParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *function, const TyVarMap &exprTyVars ) { 773 767 for ( DeclarationWithType * param : function->parameters ) { 774 768 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() ); … … 778 772 } 779 773 780 void Pass1::addInferredParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *functionType, const TyVarMap &tyVars ) {774 void CallAdapter::addInferredParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *functionType, const TyVarMap &tyVars ) { 781 775 for ( TypeDecl * const tyVar : functionType->forall ) { 782 776 for ( DeclarationWithType * const assert : tyVar->assertions ) { … … 846 840 } 847 841 848 FunctionDecl * Pass1::makeAdapter( FunctionType const *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) {842 FunctionDecl *CallAdapter::makeAdapter( FunctionType const *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) { 849 843 FunctionType *adapterType = makeAdapterType( adaptee, tyVars ); 850 844 adapterType = ScrubTyVars::scrub( adapterType, tyVars ); … … 906 900 } 907 901 908 void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {902 void CallAdapter::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) { 909 903 // collect a list of function types passed as parameters or implicit parameters (assertions) 910 904 std::list<FunctionType const *> functions; … … 923 917 924 918 for ( FunctionType const * const funType : functions ) { 925 FunctionType *originalFunction = funType->clone(); 926 FunctionType *realFunction = funType->clone(); 927 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 919 std::string mangleName = SymTab::Mangler::mangle( funType ); 928 920 929 921 // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this 930 922 // pre-substitution parameter function type. 931 923 // The second part of the insert result is "is the value new". 932 if ( adaptersDone.insert( mangleName ).second ) { 933 934 // apply substitution to type variables to figure out what the adapter's type should look like 935 assert( env ); 936 env->apply( realFunction ); 937 mangleName = SymTab::Mangler::mangle( realFunction ); 938 mangleName += makePolyMonoSuffix( originalFunction, exprTyVars ); 939 940 typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter; 941 AdapterIter adapter = adapters.find( mangleName ); 942 if ( adapter == adapters.end() ) { 943 // adapter has not been created yet in the current scope, so define it 944 FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars ); 945 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) ); 946 adapter = answer.first; 947 stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) ); 948 } // if 949 assert( adapter != adapters.end() ); 950 951 // add the appropriate adapter as a parameter 952 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 924 if ( !adaptersDone.insert( mangleName ).second ) continue; 925 926 // Apply substitution to type variables to figure out what the adapter's type should look like. 927 assert( env ); 928 FunctionType *realType = funType->clone(); 929 env->apply( realType ); 930 mangleName = SymTab::Mangler::mangle( realType ); 931 mangleName += makePolyMonoSuffix( funType, exprTyVars ); 932 933 typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter; 934 AdapterIter adapter = adapters.find( mangleName ); 935 if ( adapter == adapters.end() ) { 936 // Adapter has not been created yet in the current scope, so define it. 937 FunctionDecl *newAdapter = makeAdapter( funType, realType, mangleName, exprTyVars ); 938 std::pair< AdapterIter, bool > answer = adapters.insert( mangleName, newAdapter ); 939 adapter = answer.first; 940 stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) ); 953 941 } // if 942 assert( adapter != adapters.end() ); 943 944 // Add the appropriate adapter as a parameter. 945 appExpr->args.push_front( new VariableExpr( adapter->second ) ); 954 946 } // for 955 947 } // passAdapters … … 974 966 } 975 967 976 Expression * Pass1::handleIntrinsics( ApplicationExpr *appExpr ) {968 Expression *CallAdapter::handleIntrinsics( ApplicationExpr *appExpr ) { 977 969 if ( VariableExpr *varExpr = dynamic_cast< VariableExpr *>( appExpr->function ) ) { 978 970 if ( varExpr->var->linkage == LinkageSpec::Intrinsic ) { … … 1097 1089 } 1098 1090 1099 Expression * Pass1::postmutate( ApplicationExpr *appExpr ) {1091 Expression *CallAdapter::postmutate( ApplicationExpr *appExpr ) { 1100 1092 // std::cerr << "mutate appExpr: " << InitTweak::getFunctionName( appExpr ) << std::endl; 1101 1093 // for ( auto tyVar : scopeTyVars ) { … … 1169 1161 } 1170 1162 1171 Expression * Pass1::postmutate( UntypedExpr *expr ) {1163 Expression * CallAdapter::postmutate( UntypedExpr *expr ) { 1172 1164 if ( isPolyDeref( expr, scopeTyVars, env ) ) { 1173 1165 Expression *ret = expr->args.front(); … … 1179 1171 } 1180 1172 1181 void Pass1::premutate( AddressExpr * ) { visit_children = false; }1182 1183 Expression * Pass1::postmutate( AddressExpr * addrExpr ) {1173 void CallAdapter::premutate( AddressExpr * ) { visit_children = false; } 1174 1175 Expression * CallAdapter::postmutate( AddressExpr * addrExpr ) { 1184 1176 assert( addrExpr->arg->result && ! addrExpr->arg->result->isVoid() ); 1185 1177 … … 1212 1204 } 1213 1205 1214 void Pass1::premutate( ReturnStmt *returnStmt ) {1206 void CallAdapter::premutate( ReturnStmt *returnStmt ) { 1215 1207 if ( retval && returnStmt->expr ) { 1216 1208 assert( returnStmt->expr->result && ! returnStmt->expr->result->isVoid() ); … … 1220 1212 } 1221 1213 1222 void Pass1::premutate( PointerType *pointerType ) {1214 void CallAdapter::premutate( PointerType *pointerType ) { 1223 1215 GuardScope( scopeTyVars ); 1224 1216 makeTyVarMap( pointerType, scopeTyVars ); 1225 1217 } 1226 1218 1227 void Pass1::premutate( FunctionType *functionType ) {1219 void CallAdapter::premutate( FunctionType *functionType ) { 1228 1220 GuardScope( scopeTyVars ); 1229 1221 makeTyVarMap( functionType, scopeTyVars ); 1230 1222 } 1231 1223 1232 void Pass1::beginScope() {1224 void CallAdapter::beginScope() { 1233 1225 adapters.beginScope(); 1234 1226 } 1235 1227 1236 void Pass1::endScope() {1228 void CallAdapter::endScope() { 1237 1229 adapters.endScope(); 1238 1230 } 1239 1231 1240 ////////////////////////////////////////// Pass2 ////////////////////////////////////////////////////1241 1242 void Pass2::addAdapters( FunctionType *functionType ) {1232 ////////////////////////////////////////// DeclAdapter ////////////////////////////////////////// 1233 1234 void DeclAdapter::addAdapters( FunctionType *functionType ) { 1243 1235 std::list< FunctionType const *> functions; 1244 1236 for ( DeclarationWithType * const arg : functionType->parameters ) { … … 1260 1252 } 1261 1253 1262 DeclarationWithType * Pass2::postmutate( FunctionDecl *functionDecl ) {1254 DeclarationWithType * DeclAdapter::postmutate( FunctionDecl *functionDecl ) { 1263 1255 FunctionType * ftype = functionDecl->type; 1264 1256 if ( ! ftype->returnVals.empty() && functionDecl->statements ) { … … 1285 1277 } 1286 1278 1287 void Pass2::premutate( StructDecl * ) {1279 void DeclAdapter::premutate( StructDecl * ) { 1288 1280 // prevent tyVars from leaking into containing scope 1289 1281 GuardScope( scopeTyVars ); 1290 1282 } 1291 1283 1292 void Pass2::premutate( UnionDecl * ) {1284 void DeclAdapter::premutate( UnionDecl * ) { 1293 1285 // prevent tyVars from leaking into containing scope 1294 1286 GuardScope( scopeTyVars ); 1295 1287 } 1296 1288 1297 void Pass2::premutate( TraitDecl * ) {1289 void DeclAdapter::premutate( TraitDecl * ) { 1298 1290 // prevent tyVars from leaking into containing scope 1299 1291 GuardScope( scopeTyVars ); 1300 1292 } 1301 1293 1302 void Pass2::premutate( TypeDecl *typeDecl ) {1294 void DeclAdapter::premutate( TypeDecl *typeDecl ) { 1303 1295 addToTyVarMap( typeDecl, scopeTyVars ); 1304 1296 } 1305 1297 1306 void Pass2::premutate( PointerType *pointerType ) {1298 void DeclAdapter::premutate( PointerType *pointerType ) { 1307 1299 GuardScope( scopeTyVars ); 1308 1300 makeTyVarMap( pointerType, scopeTyVars ); 1309 1301 } 1310 1302 1311 void Pass2::premutate( FunctionType *funcType ) {1303 void DeclAdapter::premutate( FunctionType *funcType ) { 1312 1304 GuardScope( scopeTyVars ); 1313 1305 makeTyVarMap( funcType, scopeTyVars ); … … 1393 1385 } 1394 1386 1395 ////////////////////////////////////////// PolyGenericCalculator //////////////////////////////// ////////////////////1387 ////////////////////////////////////////// PolyGenericCalculator //////////////////////////////// 1396 1388 1397 1389 PolyGenericCalculator::PolyGenericCalculator() … … 1474 1466 // make sure that any type information passed into the function is accounted for 1475 1467 for ( DeclarationWithType * const fnParam : funcType->get_parameters() ) { 1476 // condition here duplicates that in Pass2::mutate( FunctionType* )1468 // condition here duplicates that in DeclAdapter::mutate( FunctionType* ) 1477 1469 Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars ); 1478 1470 if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) { … … 1501 1493 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( ty ) ) { 1502 1494 // do not try to monomorphize generic parameters 1503 if ( scopeTyVars. find( typeInst->get_name() ) != scopeTyVars.end() && ! genericParams.count( typeInst->name ) ) {1495 if ( scopeTyVars.contains( typeInst->get_name() ) && ! genericParams.count( typeInst->name ) ) { 1504 1496 // polymorphic aggregate members should be converted into monomorphic members. 1505 1497 // Using char[size_T] here respects the expected sizing rules of an aggregate type. … … 1710 1702 1711 1703 if ( auto typeInst = dynamic_cast< TypeInstType const * >( ty ) ) { 1712 if ( scopeTyVars. find( typeInst->get_name() ) != scopeTyVars.end() ) {1704 if ( scopeTyVars.contains( typeInst->get_name() ) ) { 1713 1705 // NOTE assumes here that getting put in the scopeTyVars included having the layout variables set 1714 1706 return true; … … 1718 1710 // check if this type already has a layout generated for it 1719 1711 std::string typeName = mangleType( ty ); 1720 if ( knownLayouts. find( typeName ) != knownLayouts.end() ) return true;1712 if ( knownLayouts.contains( typeName ) ) return true; 1721 1713 1722 1714 // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized … … 1755 1747 // check if this type already has a layout generated for it 1756 1748 std::string typeName = mangleType( ty ); 1757 if ( knownLayouts. find( typeName ) != knownLayouts.end() ) return true;1749 if ( knownLayouts.contains( typeName ) ) return true; 1758 1750 1759 1751 // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized … … 1846 1838 } else { 1847 1839 std::string offsetName = offsetofName( mangleType( ty ) ); 1848 if ( knownOffsets. find( offsetName ) != knownOffsets.end() ) {1840 if ( knownOffsets.contains( offsetName ) ) { 1849 1841 // use the already-generated offsets for this type 1850 1842 ret = new NameExpr( offsetName ); … … 1884 1876 } 1885 1877 1886 ////////////////////////////////////////// Pass3 //////////////////////////////////////////////////// 1887 1888 template< typename DeclClass > 1889 void Pass3::handleDecl( DeclClass * decl, Type * type ) { 1890 GuardScope( scopeTyVars ); 1891 makeTyVarMap( type, scopeTyVars ); 1892 ScrubTyVars::scrubAll( decl ); 1893 } 1894 1895 void Pass3::premutate( ObjectDecl * objectDecl ) { 1896 handleDecl( objectDecl, objectDecl->type ); 1897 } 1898 1899 void Pass3::premutate( FunctionDecl * functionDecl ) { 1900 handleDecl( functionDecl, functionDecl->type ); 1901 } 1902 1903 void Pass3::premutate( TypedefDecl * typedefDecl ) { 1904 handleDecl( typedefDecl, typedefDecl->base ); 1878 ////////////////////////////////////////// Eraser /////////////////////////////////////////////// 1879 1880 void Eraser::premutate( ObjectDecl * objectDecl ) { 1881 ScrubTyVars::scrubAll( objectDecl ); 1882 } 1883 1884 void Eraser::premutate( FunctionDecl * functionDecl ) { 1885 ScrubTyVars::scrubAll( functionDecl ); 1886 } 1887 1888 void Eraser::premutate( TypedefDecl * typedefDecl ) { 1889 ScrubTyVars::scrubAll( typedefDecl ); 1905 1890 } 1906 1891 1907 1892 /// Strips the members from a generic aggregate 1908 void stripGenericMembers(AggregateDecl * decl) {1893 static void stripGenericMembers( AggregateDecl * decl ) { 1909 1894 if ( ! decl->parameters.empty() ) decl->members.clear(); 1910 1895 } 1911 1896 1912 void Pass3::premutate( StructDecl * structDecl ) {1897 void Eraser::premutate( StructDecl * structDecl ) { 1913 1898 stripGenericMembers( structDecl ); 1914 1899 } 1915 1900 1916 void Pass3::premutate( UnionDecl * unionDecl ) {1901 void Eraser::premutate( UnionDecl * unionDecl ) { 1917 1902 stripGenericMembers( unionDecl ); 1918 }1919 1920 void Pass3::premutate( TypeDecl * typeDecl ) {1921 addToTyVarMap( typeDecl, scopeTyVars );1922 }1923 1924 void Pass3::premutate( PointerType * pointerType ) {1925 GuardScope( scopeTyVars );1926 makeTyVarMap( pointerType, scopeTyVars );1927 }1928 1929 void Pass3::premutate( FunctionType * functionType ) {1930 GuardScope( scopeTyVars );1931 makeTyVarMap( functionType, scopeTyVars );1932 1903 } 1933 1904 } // anonymous namespace … … 1939 1910 // compile-command: "make install" // 1940 1911 // End: // 1941
Note:
See TracChangeset
for help on using the changeset viewer.