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