Changeset b1e63ac5 for src/InitTweak/GenInit.cc
- Timestamp:
- Jul 4, 2017, 9:40:16 AM (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:
- 208e5be
- Parents:
- 9c951e3 (diff), f7cb0bc (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/InitTweak/GenInit.cc
r9c951e3 rb1e63ac5 16 16 #include <stack> 17 17 #include <list> 18 19 #include "InitTweak.h" 18 20 #include "GenInit.h" 19 #include "InitTweak.h" 21 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 20 30 #include "SynTree/Declaration.h" 21 #include "SynTree/Type.h"22 31 #include "SynTree/Expression.h" 23 #include "SynTree/Statement.h"24 32 #include "SynTree/Initializer.h" 25 33 #include "SynTree/Mutator.h" 34 #include "SynTree/Statement.h" 35 #include "SynTree/Type.h" 36 26 37 #include "SymTab/Autogen.h" 27 38 #include "SymTab/Mangler.h" 28 #include "GenPoly/PolyMutator.h"29 #include "GenPoly/DeclMutator.h"30 #include "GenPoly/ScopedSet.h"31 #include "ResolvExpr/typeops.h"32 39 33 40 namespace InitTweak { … … 37 44 } 38 45 39 class ReturnFixer final : public GenPoly::PolyMutator { 40 public: 46 struct ReturnFixer : public WithStmtsToAdd, public WithGuards { 41 47 /// consistently allocates a temporary variable for the return value 42 48 /// of a function so that anything which the resolver decides can be constructed … … 44 50 static void makeReturnTemp( std::list< Declaration * > &translationUnit ); 45 51 46 ReturnFixer(); 47 48 typedef GenPoly::PolyMutator Parent; 49 using Parent::mutate; 50 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 51 virtual Statement * mutate( ReturnStmt * returnStmt ) override; 52 void premutate( FunctionDecl *functionDecl ); 53 void premutate( ReturnStmt * returnStmt ); 52 54 53 55 protected: … … 56 58 }; 57 59 58 class CtorDtor final : public GenPoly::PolyMutator { 59 public: 60 typedef GenPoly::PolyMutator Parent; 61 using Parent::mutate; 60 struct CtorDtor : public WithGuards, public WithShortCircuiting { 62 61 /// create constructor and destructor statements for object declarations. 63 62 /// the actual call statements will be added in after the resolver has run … … 66 65 static void generateCtorDtor( std::list< Declaration * > &translationUnit ); 67 66 68 virtual DeclarationWithType * mutate( ObjectDecl * ) override; 69 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 67 void previsit( ObjectDecl * ); 68 void previsit( FunctionDecl *functionDecl ); 69 70 70 // should not traverse into any of these declarations to find objects 71 71 // that need to be constructed or destructed 72 v irtual Declaration* mutate( StructDecl *aggregateDecl ) override;73 v irtual Declaration* mutate( UnionDecl *aggregateDecl ) override { return aggregateDecl; }74 v irtual Declaration* mutate( EnumDecl *aggregateDecl ) override { return aggregateDecl; }75 v irtual Declaration* mutate( TraitDecl *aggregateDecl ) override { return aggregateDecl; }76 v irtual TypeDecl* mutate( TypeDecl *typeDecl ) override { return typeDecl; }77 v irtual Declaration* mutate( TypedefDecl *typeDecl ) override { return typeDecl; }78 79 v irtual Type * mutate( FunctionType *funcType ) override { return funcType; }80 81 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 ); 82 82 83 83 private: … … 131 131 132 132 void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) { 133 ReturnFixerfixer;133 PassVisitor<ReturnFixer> fixer; 134 134 mutateAll( translationUnit, fixer ); 135 135 } 136 136 137 ReturnFixer::ReturnFixer() {} 138 139 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) { 137 void ReturnFixer::premutate( ReturnStmt *returnStmt ) { 140 138 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals(); 141 139 assert( returnVals.size() == 0 || returnVals.size() == 1 ); … … 148 146 construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) ); 149 147 construct->get_args().push_back( returnStmt->get_expr() ); 150 stmtsToAdd .push_back(new ExprStmt(noLabels, construct));148 stmtsToAddBefore.push_back(new ExprStmt(noLabels, construct)); 151 149 152 150 // return the retVal object 153 151 returnStmt->set_expr( new VariableExpr( returnVals.front() ) ); 154 152 } // if 155 return returnStmt; 156 } 157 158 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 159 ValueGuard< FunctionType * > oldFtype( ftype ); 160 ValueGuard< std::string > oldFuncName( funcName ); 153 } 154 155 void ReturnFixer::premutate( FunctionDecl *functionDecl ) { 156 GuardValue( ftype ); 157 GuardValue( funcName ); 161 158 162 159 ftype = functionDecl->get_functionType(); 163 160 funcName = functionDecl->get_name(); 164 return Parent::mutate( functionDecl );165 161 } 166 162 … … 212 208 213 209 void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) { 214 CtorDtorctordtor;215 mutateAll( translationUnit, ctordtor );210 PassVisitor<CtorDtor> ctordtor; 211 acceptAll( translationUnit, ctordtor ); 216 212 } 217 213 … … 291 287 } 292 288 293 DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) {289 void CtorDtor::previsit( ObjectDecl * objDecl ) { 294 290 handleDWT( objDecl ); 295 291 // hands off if @=, extern, builtin, etc. … … 303 299 objDecl->set_init( genCtorInit( objDecl ) ); 304 300 } 305 return Parent::mutate( objDecl ); 306 } 307 308 DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) { 309 ValueGuard< bool > oldInFunc = inFunction; 301 } 302 303 void CtorDtor::previsit( FunctionDecl *functionDecl ) { 304 GuardValue( inFunction ); 310 305 inFunction = true; 311 306 312 307 handleDWT( functionDecl ); 313 308 314 managedTypes.beginScope();309 GuardScope( managedTypes ); 315 310 // go through assertions and recursively add seen ctor/dtors 316 311 for ( auto & tyDecl : functionDecl->get_functionType()->get_forall() ) { 317 312 for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) { 318 assertion = assertion->acceptMutator( *this);313 handleDWT( assertion ); 319 314 } 320 315 } 321 // parameters should not be constructed and destructed, so don't mutate FunctionType 322 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 323 324 managedTypes.endScope(); 325 return functionDecl; 326 } 327 328 Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) { 316 317 PassVisitor<CtorDtor> newCtorDtor; 318 newCtorDtor.pass = *this; 319 maybeAccept( functionDecl->get_statements(), newCtorDtor ); 320 visit_children = false; // do not try and construct parameters or forall parameters - must happen after maybeAccept 321 } 322 323 void CtorDtor::previsit( StructDecl *aggregateDecl ) { 324 visit_children = false; // do not try to construct and destruct aggregate members 325 329 326 // don't construct members, but need to take note if there is a managed member, 330 327 // because that means that this type is also managed … … 338 335 } 339 336 } 340 return aggregateDecl; 341 } 342 343 CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) { 344 managedTypes.beginScope(); 345 CompoundStmt * stmt = Parent::mutate( compoundStmt ); 346 managedTypes.endScope(); 347 return stmt; 348 } 349 337 } 338 339 void CtorDtor::previsit( CompoundStmt * compoundStmt ) { 340 GuardScope( managedTypes ); 341 } 350 342 } // namespace InitTweak 351 343
Note: See TracChangeset
for help on using the changeset viewer.