Changeset a31b384
- Timestamp:
- Sep 25, 2017, 7:28:28 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 7c40a24
- Parents:
- 201182a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r201182a ra31b384 38 38 #include "Lvalue.h" // for generalizedLvalue 39 39 #include "Parser/LinkageSpec.h" // for C, Spec, Cforall, Intrinsic 40 #include "PolyMutator.h" // for PolyMutator41 40 #include "ResolvExpr/TypeEnvironment.h" // for EqvClass 42 41 #include "ResolvExpr/typeops.h" // for typesCompatible … … 130 129 /// * Moves polymorphic returns in function types to pointer-type parameters 131 130 /// * adds type size and assertion parameters to parameter lists 132 class Pass2 final : public PolyMutator { 133 public: 134 template< typename DeclClass > 135 DeclClass *handleDecl( DeclClass *decl ); 136 template< typename AggDecl > 137 AggDecl * handleAggDecl( AggDecl * aggDecl ); 138 139 typedef PolyMutator Parent; 140 using Parent::mutate; 141 virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override; 142 virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override; 143 virtual StructDecl *mutate( StructDecl *structDecl ) override; 144 virtual UnionDecl *mutate( UnionDecl *unionDecl ) override; 145 virtual TraitDecl *mutate( TraitDecl *unionDecl ) override; 146 virtual TypeDecl *mutate( TypeDecl *typeDecl ) override; 147 virtual TypedefDecl *mutate( TypedefDecl *typedefDecl ) override; 148 virtual Type *mutate( PointerType *pointerType ) override; 149 virtual Type *mutate( FunctionType *funcType ) override; 131 struct Pass2 final : public BoxPass, public WithGuards { 132 void handleAggDecl(); 133 134 DeclarationWithType * postmutate( FunctionDecl *functionDecl ); 135 void premutate( StructDecl *structDecl ); 136 void premutate( UnionDecl *unionDecl ); 137 void premutate( TraitDecl *unionDecl ); 138 void premutate( TypeDecl *typeDecl ); 139 void premutate( PointerType *pointerType ); 140 void premutate( FunctionType *funcType ); 150 141 151 142 private: … … 246 237 PassVisitor<LayoutFunctionBuilder> layoutBuilder; 247 238 PassVisitor<Pass1> pass1; 248 Pass 2pass2;239 PassVisitor<Pass2> pass2; 249 240 PassVisitor<PolyGenericCalculator> polyCalculator; 250 241 PassVisitor<Pass3> pass3; … … 252 243 acceptAll( translationUnit, layoutBuilder ); 253 244 mutateAll( translationUnit, pass1 ); 254 mutate TranslationUnit/*All*/( translationUnit, pass2 );245 mutateAll( translationUnit, pass2 ); 255 246 mutateAll( translationUnit, polyCalculator ); 256 247 mutateAll( translationUnit, pass3 ); … … 1254 1245 } 1255 1246 1256 template< typename DeclClass > 1257 DeclClass * Pass2::handleDecl( DeclClass *decl ) { 1258 DeclClass *ret = static_cast< DeclClass *>( Parent::mutate( decl ) ); 1259 1260 return ret; 1261 } 1262 1263 DeclarationWithType * Pass2::mutate( FunctionDecl *functionDecl ) { 1264 functionDecl = strict_dynamic_cast< FunctionDecl * > ( handleDecl( functionDecl ) ); 1247 DeclarationWithType * Pass2::postmutate( FunctionDecl *functionDecl ) { 1265 1248 FunctionType * ftype = functionDecl->get_functionType(); 1266 1249 if ( ! ftype->get_returnVals().empty() && functionDecl->get_statements() ) { … … 1286 1269 } 1287 1270 1288 ObjectDecl * Pass2::mutate( ObjectDecl *objectDecl ) { 1289 return handleDecl( objectDecl ); 1290 } 1291 1292 template< typename AggDecl > 1293 AggDecl * Pass2::handleAggDecl( AggDecl * aggDecl ) { 1271 void Pass2::premutate( StructDecl * ) { 1294 1272 // prevent tyVars from leaking into containing scope 1295 scopeTyVars.beginScope(); 1296 Parent::mutate( aggDecl ); 1297 scopeTyVars.endScope(); 1298 return aggDecl; 1299 } 1300 1301 StructDecl * Pass2::mutate( StructDecl *aggDecl ) { 1302 return handleAggDecl( aggDecl ); 1303 } 1304 1305 UnionDecl * Pass2::mutate( UnionDecl *aggDecl ) { 1306 return handleAggDecl( aggDecl ); 1307 } 1308 1309 TraitDecl * Pass2::mutate( TraitDecl *aggDecl ) { 1310 return handleAggDecl( aggDecl ); 1311 } 1312 1313 TypeDecl * Pass2::mutate( TypeDecl *typeDecl ) { 1273 GuardScope( scopeTyVars ); 1274 } 1275 1276 void Pass2::premutate( UnionDecl * ) { 1277 // prevent tyVars from leaking into containing scope 1278 GuardScope( scopeTyVars ); 1279 } 1280 1281 void Pass2::premutate( TraitDecl * ) { 1282 // prevent tyVars from leaking into containing scope 1283 GuardScope( scopeTyVars ); 1284 } 1285 1286 void Pass2::premutate( TypeDecl *typeDecl ) { 1314 1287 addToTyVarMap( typeDecl, scopeTyVars ); 1315 if ( typeDecl->get_base() ) { 1316 return handleDecl( typeDecl ); 1317 } else { 1318 return dynamic_cast<TypeDecl*>( Parent::mutate( typeDecl ) ); 1319 } 1320 } 1321 1322 TypedefDecl * Pass2::mutate( TypedefDecl *typedefDecl ) { 1323 return handleDecl( typedefDecl ); 1324 } 1325 1326 Type * Pass2::mutate( PointerType *pointerType ) { 1327 scopeTyVars.beginScope(); 1288 } 1289 1290 void Pass2::premutate( PointerType *pointerType ) { 1291 GuardScope( scopeTyVars ); 1328 1292 makeTyVarMap( pointerType, scopeTyVars ); 1329 1330 Type *ret = Parent::mutate( pointerType ); 1331 1332 scopeTyVars.endScope(); 1333 return ret; 1334 } 1335 1336 Type *Pass2::mutate( FunctionType *funcType ) { 1337 scopeTyVars.beginScope(); 1338 1293 } 1294 1295 void Pass2::premutate( FunctionType *funcType ) { 1296 GuardScope( scopeTyVars ); 1339 1297 makeTyVarMap( funcType, scopeTyVars ); 1340 1298 … … 1375 1333 // move all assertions into parameter list 1376 1334 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1377 // *assert = (*assert)->acceptMutator( *this );1378 1335 // assertion parameters may not be used in body, pass along with unused attribute. 1379 1336 (*assert)->get_attributes().push_back( new Attribute( "unused" ) ); … … 1411 1368 } 1412 1369 } 1413 1414 1370 seenTypes.insert( typeName ); 1415 1371 } … … 1419 1375 funcType->get_parameters().splice( last, inferredParams ); 1420 1376 addAdapters( funcType ); 1421 mutateAll( funcType->get_returnVals(), *this );1422 mutateAll( funcType->get_parameters(), *this );1423 1424 scopeTyVars.endScope();1425 return funcType;1426 1377 } 1427 1378
Note: See TracChangeset
for help on using the changeset viewer.