Changeset 49c9773 for src/InitTweak
- Timestamp:
- Jun 1, 2017, 10:58:24 PM (9 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:
- acd738aa, d3ed39f
- Parents:
- 6065b3aa (diff), b1d4d60 (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
-
src/InitTweak/FixInit.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r6065b3aa r49c9773 20 20 #include <unordered_map> 21 21 #include <unordered_set> 22 22 23 #include "InitTweak.h" 23 24 #include "GenInit.h" 24 25 #include "FixInit.h" 25 26 #include "FixGlobalInit.h" 27 #include "CodeGen/GenType.h" // for warning/error messages 28 #include "Common/PassVisitor.h" 29 #include "GenPoly/DeclMutator.h" 30 #include "GenPoly/PolyMutator.h" 26 31 #include "ResolvExpr/Resolver.h" 27 32 #include "ResolvExpr/typeops.h" 33 #include "SymTab/Autogen.h" 34 #include "SymTab/Indexer.h" 35 #include "SynTree/AddStmtVisitor.h" 36 #include "SynTree/Attribute.h" 28 37 #include "SynTree/Declaration.h" 29 #include "SynTree/Type.h"30 38 #include "SynTree/Expression.h" 31 #include "SynTree/Attribute.h"32 #include "SynTree/Statement.h"33 39 #include "SynTree/Initializer.h" 34 40 #include "SynTree/Mutator.h" 35 #include "SymTab/Indexer.h" 36 #include "SymTab/Autogen.h" 37 #include "GenPoly/PolyMutator.h" 38 #include "GenPoly/DeclMutator.h" 39 #include "SynTree/AddStmtVisitor.h" 40 #include "CodeGen/GenType.h" // for warning/error messages 41 #include "SynTree/Statement.h" 42 #include "SynTree/Type.h" 41 43 #include "Tuples/Tuples.h" 42 44 … … 54 56 typedef std::unordered_map< int, int > UnqCount; 55 57 56 class InsertImplicitCalls final : public GenPoly::PolyMutator{58 class InsertImplicitCalls { 57 59 public: 58 60 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 61 63 62 64 InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {} 63 typedef GenPoly::PolyMutator Parent; 64 using Parent::mutate; 65 virtual Expression * mutate( ApplicationExpr * appExpr ) override; 66 virtual Expression * mutate( StmtExpr * stmtExpr ) override; 65 66 Expression * postmutate( ApplicationExpr * appExpr ); 67 void premutate( StmtExpr * stmtExpr ); 67 68 68 69 // collects environments for relevant nodes 69 70 EnvMap & envMap; 71 TypeSubstitution * env; //Magically populated by the PassVisitor 70 72 }; 71 73 … … 190 192 }; 191 193 192 class FixInit final : public GenPoly::PolyMutator{194 class FixInit { 193 195 public: 194 196 /// expand each object declaration to use its constructor after it is declared. 195 197 static void fixInitializers( std::list< Declaration * > &translationUnit ); 196 198 197 typedef GenPoly::PolyMutator Parent; 198 using Parent::mutate; 199 virtual DeclarationWithType * mutate( ObjectDecl *objDecl ) override; 199 DeclarationWithType * postmutate( ObjectDecl *objDecl ); 200 200 201 201 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor 202 203 }; 203 204 … … 300 301 namespace { 301 302 void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) { 302 InsertImplicitCallsinserter( envMap );303 PassVisitor<InsertImplicitCalls> inserter( envMap ); 303 304 mutateAll( translationUnit, inserter ); 304 305 } … … 310 311 311 312 void FixInit::fixInitializers( std::list< Declaration * > & translationUnit ) { 312 FixInitfixer;313 PassVisitor<FixInit> fixer; 313 314 314 315 // can't use mutateAll, because need to insert declarations at top-level … … 318 319 try { 319 320 *i = maybeMutate( *i, fixer ); 320 translationUnit.splice( i, fixer. staticDtorDecls );321 translationUnit.splice( i, fixer.pass.staticDtorDecls ); 321 322 } catch( SemanticError &e ) { 322 323 e.set_location( (*i)->location ); … … 350 351 } 351 352 352 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) { 353 appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) ); 353 Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) { 354 354 assert( appExpr ); 355 355 … … 393 393 } 394 394 395 Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {395 void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) { 396 396 assert( env ); 397 397 envMap[stmtExpr] = env; 398 return Parent::mutate( stmtExpr );399 398 } 400 399 … … 696 695 } 697 696 698 DeclarationWithType *FixInit::mutate( ObjectDecl *objDecl ) { 699 // first recursively handle pieces of ObjectDecl so that they aren't missed by other visitors when the init 700 // is removed from the ObjectDecl 701 objDecl = dynamic_cast< ObjectDecl * >( Parent::mutate( objDecl ) ); 697 DeclarationWithType *FixInit::postmutate( ObjectDecl *objDecl ) { 698 // since this removes the init field from objDecl, it must occur after children are mutated (i.e. postmutate) 702 699 if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) { 703 700 // a decision should have been made by the resolver, so ctor and init are not both non-NULL
Note:
See TracChangeset
for help on using the changeset viewer.