Changes in src/InitTweak/GenInit.cc [9ff56e7:4eb31f2b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r9ff56e7 r4eb31f2b 21 21 22 22 #include "Common/PassVisitor.h" 23 24 #include "GenPoly/DeclMutator.h"25 #include "GenPoly/PolyMutator.h"26 #include "GenPoly/ScopedSet.h"27 28 #include "ResolvExpr/typeops.h"29 23 30 24 #include "SynTree/Declaration.h" … … 38 32 #include "SymTab/Mangler.h" 39 33 34 #include "GenPoly/DeclMutator.h" 35 #include "GenPoly/PolyMutator.h" 36 #include "GenPoly/ScopedSet.h" 37 38 #include "ResolvExpr/typeops.h" 39 40 40 namespace InitTweak { 41 41 namespace { … … 44 44 } 45 45 46 struct ReturnFixer : public WithStmtsToAdd, public WithGuards { 46 class ReturnFixer : public WithStmtsToAdd, public WithScopes { 47 public: 47 48 /// consistently allocates a temporary variable for the return value 48 49 /// of a function so that anything which the resolver decides can be constructed … … 58 59 }; 59 60 60 struct CtorDtor : public WithGuards, public WithShortCircuiting { 61 class CtorDtor final : public GenPoly::PolyMutator { 62 public: 63 typedef GenPoly::PolyMutator Parent; 64 using Parent::mutate; 61 65 /// create constructor and destructor statements for object declarations. 62 66 /// the actual call statements will be added in after the resolver has run … … 65 69 static void generateCtorDtor( std::list< Declaration * > &translationUnit ); 66 70 67 void previsit( ObjectDecl * ); 68 void previsit( FunctionDecl *functionDecl ); 69 71 virtual DeclarationWithType * mutate( ObjectDecl * ) override; 72 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 70 73 // should not traverse into any of these declarations to find objects 71 74 // that need to be constructed or destructed 72 void previsit( StructDecl *aggregateDecl ); 73 void previsit( __attribute__((unused)) UnionDecl * aggregateDecl ) { visit_children = false; } 74 void previsit( __attribute__((unused)) EnumDecl * aggregateDecl ) { visit_children = false; } 75 void previsit( __attribute__((unused)) TraitDecl * aggregateDecl ) { visit_children = false; } 76 void previsit( __attribute__((unused)) TypeDecl * typeDecl ) { visit_children = false; } 77 void previsit( __attribute__((unused)) TypedefDecl * typeDecl ) { visit_children = false; } 78 void previsit( __attribute__((unused)) FunctionType * funcType ) { visit_children = false; } 79 80 void previsit( CompoundStmt * compoundStmt ); 75 virtual Declaration* mutate( StructDecl *aggregateDecl ) override; 76 virtual Declaration* mutate( UnionDecl *aggregateDecl ) override { return aggregateDecl; } 77 virtual Declaration* mutate( EnumDecl *aggregateDecl ) override { return aggregateDecl; } 78 virtual Declaration* mutate( TraitDecl *aggregateDecl ) override { return aggregateDecl; } 79 virtual TypeDecl* mutate( TypeDecl *typeDecl ) override { return typeDecl; } 80 virtual Declaration* mutate( TypedefDecl *typeDecl ) override { return typeDecl; } 81 82 virtual Type * mutate( FunctionType *funcType ) override { return funcType; } 83 84 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override; 81 85 82 86 private: … … 207 211 208 212 void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) { 209 PassVisitor<CtorDtor>ctordtor;210 acceptAll( translationUnit, ctordtor );213 CtorDtor ctordtor; 214 mutateAll( translationUnit, ctordtor ); 211 215 } 212 216 … … 285 289 } 286 290 287 void CtorDtor::previsit( ObjectDecl * objDecl ) {291 DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) { 288 292 handleDWT( objDecl ); 289 293 // hands off if @=, extern, builtin, etc. … … 297 301 objDecl->set_init( genCtorInit( objDecl ) ); 298 302 } 299 } 300 301 void CtorDtor::previsit( FunctionDecl *functionDecl ) { 302 GuardValue( inFunction ); 303 return Parent::mutate( objDecl ); 304 } 305 306 DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) { 307 ValueGuard< bool > oldInFunc = inFunction; 303 308 inFunction = true; 304 309 305 310 handleDWT( functionDecl ); 306 311 307 GuardScope( managedTypes);312 managedTypes.beginScope(); 308 313 // go through assertions and recursively add seen ctor/dtors 309 314 for ( auto & tyDecl : functionDecl->get_functionType()->get_forall() ) { … … 312 317 } 313 318 } 314 315 PassVisitor<CtorDtor> newCtorDtor; 316 newCtorDtor.pass = *this; 317 maybeAccept( functionDecl->get_statements(), newCtorDtor ); 318 visit_children = false; // do not try and construct parameters or forall parameters - must happen after maybeAccept 319 } 320 321 void CtorDtor::previsit( StructDecl *aggregateDecl ) { 322 visit_children = false; // do not try to construct and destruct aggregate members 323 319 // parameters should not be constructed and destructed, so don't mutate FunctionType 320 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 321 322 managedTypes.endScope(); 323 return functionDecl; 324 } 325 326 Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) { 324 327 // don't construct members, but need to take note if there is a managed member, 325 328 // because that means that this type is also managed … … 333 336 } 334 337 } 335 } 336 337 void CtorDtor::previsit( __attribute__((unused)) CompoundStmt * compoundStmt ) { 338 GuardScope( managedTypes ); 339 } 338 return aggregateDecl; 339 } 340 341 CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) { 342 managedTypes.beginScope(); 343 CompoundStmt * stmt = Parent::mutate( compoundStmt ); 344 managedTypes.endScope(); 345 return stmt; 346 } 347 340 348 } // namespace InitTweak 341 349
Note:
See TracChangeset
for help on using the changeset viewer.