Changes in src/InitTweak/FixInit.cc [aff3af4:0661678]
- File:
-
- 1 edited
-
src/InitTweak/FixInit.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
raff3af4 r0661678 20 20 #include <unordered_map> 21 21 #include <unordered_set> 22 23 22 #include "InitTweak.h" 24 23 #include "GenInit.h" 25 24 #include "FixInit.h" 26 25 #include "FixGlobalInit.h" 27 #include "CodeGen/GenType.h" // for warning/error messages28 #include "Common/PassVisitor.h"29 #include "GenPoly/DeclMutator.h"30 #include "GenPoly/PolyMutator.h"31 26 #include "ResolvExpr/Resolver.h" 32 27 #include "ResolvExpr/typeops.h" 33 #include "Sy mTab/Autogen.h"34 #include "Sy mTab/Indexer.h"35 #include "SynTree/ AddStmtVisitor.h"28 #include "SynTree/Declaration.h" 29 #include "SynTree/Type.h" 30 #include "SynTree/Expression.h" 36 31 #include "SynTree/Attribute.h" 37 #include "SynTree/Declaration.h" 38 #include "SynTree/Expression.h" 32 #include "SynTree/Statement.h" 39 33 #include "SynTree/Initializer.h" 40 34 #include "SynTree/Mutator.h" 41 #include "SynTree/Statement.h" 42 #include "SynTree/Type.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 43 41 #include "Tuples/Tuples.h" 44 42 … … 56 54 typedef std::unordered_map< int, int > UnqCount; 57 55 58 class InsertImplicitCalls {56 class InsertImplicitCalls final : public GenPoly::PolyMutator { 59 57 public: 60 58 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 63 61 64 62 InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {} 65 66 Expression * postmutate( ApplicationExpr * appExpr ); 67 void premutate( StmtExpr * stmtExpr ); 63 typedef GenPoly::PolyMutator Parent; 64 using Parent::mutate; 65 virtual Expression * mutate( ApplicationExpr * appExpr ) override; 66 virtual Expression * mutate( StmtExpr * stmtExpr ) override; 68 67 69 68 // collects environments for relevant nodes 70 69 EnvMap & envMap; 71 TypeSubstitution * env; //Magically populated by the PassVisitor72 70 }; 73 71 … … 192 190 }; 193 191 194 class FixInit {192 class FixInit final : public GenPoly::PolyMutator { 195 193 public: 196 194 /// expand each object declaration to use its constructor after it is declared. 197 195 static void fixInitializers( std::list< Declaration * > &translationUnit ); 198 196 199 DeclarationWithType * postmutate( ObjectDecl *objDecl ); 197 typedef GenPoly::PolyMutator Parent; 198 using Parent::mutate; 199 virtual DeclarationWithType * mutate( ObjectDecl *objDecl ) override; 200 200 201 201 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor203 202 }; 204 203 … … 301 300 namespace { 302 301 void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) { 303 PassVisitor<InsertImplicitCalls>inserter( envMap );302 InsertImplicitCalls inserter( envMap ); 304 303 mutateAll( translationUnit, inserter ); 305 304 } … … 311 310 312 311 void FixInit::fixInitializers( std::list< Declaration * > & translationUnit ) { 313 PassVisitor<FixInit>fixer;312 FixInit fixer; 314 313 315 314 // can't use mutateAll, because need to insert declarations at top-level … … 319 318 try { 320 319 *i = maybeMutate( *i, fixer ); 321 translationUnit.splice( i, fixer. pass.staticDtorDecls );320 translationUnit.splice( i, fixer.staticDtorDecls ); 322 321 } catch( SemanticError &e ) { 323 322 e.set_location( (*i)->location ); … … 351 350 } 352 351 353 Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) { 352 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) { 353 appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) ); 354 354 assert( appExpr ); 355 355 … … 393 393 } 394 394 395 void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) {395 Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) { 396 396 assert( env ); 397 397 envMap[stmtExpr] = env; 398 return Parent::mutate( stmtExpr ); 398 399 } 399 400 … … 695 696 } 696 697 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) 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 ) ); 699 702 if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) { 700 703 // 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.