Changes in / [4a58895:676cc8c]
- Location:
- src
- Files:
-
- 6 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r4a58895 r676cc8c 1 1 #pragma once 2 3 #include <stack> 2 4 3 5 #include "SynTree/Mutator.h" … … 11 13 #include "SynTree/Constant.h" 12 14 13 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 14 // Deep magic (a.k.a template meta programming) to make the templated visitor work 15 // Basically the goal is to make 2 previsit_impl 16 // 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of 17 // 'pass.previsit( node )' that compiles will be used for that node for that type 18 // This requires that this option only compile for passes that actually define an appropriate visit. 19 // SFINAE will make sure the compilation errors in this function don't halt the build. 20 // See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE 21 // 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing. 22 // This is needed only to eliminate the need for passes to specify any kind of handlers. 23 // The second implementation only works because it has a lower priority. This is due to the bogus last parameter. 24 // The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0 25 // the first implementation takes priority in regards to overloading. 26 // Mutator functions work along the same principal 27 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 28 // Visit 29 template<typename pass_type, typename node_type> 30 static inline auto previsit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.previsit( node ), void() ) { 31 pass.previsit( node ); 32 } 33 34 template<typename pass_type, typename node_type> 35 static inline void previsit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {} 36 37 38 template<typename pass_type, typename node_type> 39 static inline auto postvisit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postvisit( node ), void() ) { 40 pass.postvisit( node ); 41 } 42 43 template<typename pass_type, typename node_type> 44 static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {} 45 46 // Mutate 47 template<typename pass_type, typename node_type> 48 static inline auto premutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.premutate( node ), void() ) { 49 return pass.premutate( node ); 50 } 51 52 template<typename pass_type, typename node_type> 53 static inline void premutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {} 54 55 56 template<typename return_type, typename pass_type, typename node_type> 57 static inline auto postmutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postmutate( node ) ) { 58 return pass.postmutate( node ); 59 } 60 61 template<typename return_type, typename pass_type, typename node_type> 62 static inline return_type postmutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) { return node; } 15 #include "PassVisitor.proto.h" 63 16 64 17 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 256 209 257 210 private: 258 template<typename node_type> 259 auto call_previsit ( node_type * node ) 260 -> decltype( previsit_impl ( pass, node, 0 ), void() ) 261 { 262 previsit_impl ( pass, node, 0 ); 263 } 264 265 template<typename node_type> 266 auto call_postvisit( node_type * node ) 267 -> decltype( postvisit_impl( pass, node, 0 ), void() ) 268 { 269 postvisit_impl( pass, node, 0 ); 270 } 271 272 template<typename node_type> 273 auto call_premutate ( node_type * node ) 274 -> decltype( premutate_impl( pass, node, 0 ), void() ) 275 { 276 premutate_impl( pass, node, 0 ); 277 } 278 279 template<typename return_type, typename node_type> 280 auto call_postmutate ( node_type * node ) 281 -> decltype( postmutate_impl<return_type>( pass, node, 0 ) ) 282 { 283 return postmutate_impl<return_type>( pass, node, 0 ); 284 } 211 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } 212 template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } 213 214 template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); } 215 template<typename return_type, typename node_type> return_type call_postmutate ( node_type * node ) { return postmutate_impl<return_type>( pass, node, 0 ); } 216 217 void call_beginScope() { begin_scope_impl( pass, 0 ); } 218 void call_endScope () { end_scope_impl ( pass, 0 ); } 219 220 void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } 221 222 void visitStatementList( std::list< Statement* > &statements ); 223 void mutateStatementList( std::list< Statement* > &statements ); 224 225 Statement * visitStatement( Statement * stmt ); 226 Statement * mutateStatement( Statement * stmt ); 227 228 void visitExpression( Expression * expr ); 229 Expression * mutateExpression( Expression * expr ); 230 231 232 TypeSubstitution ** get_env_ptr () { return env_impl ( pass, 0); } 233 std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } 234 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } 285 235 }; 286 236 -
src/Common/PassVisitor.impl.h
r4a58895 r676cc8c 1 1 #pragma once 2 3 #define MUTATE_START( node ) \ 4 call_premutate( node ); \ 5 6 7 #define MUTATE_END( type, node ) \ 8 return call_postmutate< type * >( node ); \ 9 2 10 3 11 #define VISIT_BODY( node ) \ … … 6 14 call_postvisit( node ); \ 7 15 8 #define MUTATE_BODY( type, node ) \ 9 call_premutate( node ); \ 10 Mutator::mutate( node ); \ 11 auto ret = call_postmutate< type * >( node ); \ 12 return ret; \ 13 14 15 16 17 #define MUTATE_BODY( type, node ) \ 18 MUTATE_START( node ); \ 19 Mutator::mutate( node ); \ 20 MUTATE_END( type, node ); \ 21 22 23 24 template<typename T> 25 static inline bool empty( T * ptr ) { 26 return !ptr || ptr->empty(); 27 } 28 29 typedef std::list< Statement * > StmtList_t; 30 31 template< typename pass_type > 32 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 33 SemanticError errors; 34 35 StmtList_t* beforeStmts = get_beforeStmts(); 36 StmtList_t* afterStmts = get_afterStmts(); 37 38 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 39 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 40 try { 41 *i = (*i)->accept( *this ); 42 } catch ( SemanticError &e ) { 43 errors.append( e ); 44 } 45 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 46 } 47 48 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 49 if ( !errors.isEmpty() ) { throw errors; } 50 } 51 52 template< typename pass_type > 53 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 54 SemanticError errors; 55 56 StmtList_t* beforeStmts = get_beforeStmts(); 57 StmtList_t* afterStmts = get_afterStmts(); 58 59 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 60 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 61 try { 62 *i = (*i)->acceptMutator( *this ); 63 } catch ( SemanticError &e ) { 64 errors.append( e ); 65 } 66 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 67 } 68 69 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 70 if ( !errors.isEmpty() ) { throw errors; } 71 } 72 73 template< typename pass_type > 74 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 75 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 76 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 77 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 78 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 79 80 Statement *newStmt = maybeVisit( stmt, *this ); 81 82 StmtList_t* beforeStmts = get_beforeStmts(); 83 StmtList_t* afterStmts = get_afterStmts(); 84 85 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 86 87 CompoundStmt *compound = new CompoundStmt( noLabels ); 88 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 89 compound->get_kids().push_back( newStmt ); 90 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 91 return compound; 92 } 93 94 template< typename pass_type > 95 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 96 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 97 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 98 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 99 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 100 101 Statement *newStmt = maybeMutate( stmt, *this ); 102 103 StmtList_t* beforeStmts = get_beforeStmts(); 104 StmtList_t* afterStmts = get_afterStmts(); 105 106 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 107 108 CompoundStmt *compound = new CompoundStmt( noLabels ); 109 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 110 compound->get_kids().push_back( newStmt ); 111 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 112 return compound; 113 } 114 115 116 117 template< typename pass_type > 118 void PassVisitor< pass_type >::visitExpression( Expression * expr ) { 119 if( !expr ) return; 120 121 auto env_ptr = get_env_ptr(); 122 if ( env_ptr && expr->get_env() ) { 123 *env_ptr = expr->get_env(); 124 } 125 // xxx - should env be cloned (or moved) onto the result of the mutate? 126 expr->accept( *this ); 127 } 128 129 template< typename pass_type > 130 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 131 if( !expr ) return nullptr; 132 133 auto env_ptr = get_env_ptr(); 134 if ( env_ptr && expr->get_env() ) { 135 *env_ptr = expr->get_env(); 136 } 137 // xxx - should env be cloned (or moved) onto the result of the mutate? 138 return expr->acceptMutator( *this ); 139 } 140 141 142 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 16 143 17 144 template< typename pass_type > … … 66 193 67 194 template< typename pass_type > 195 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) { 196 MUTATE_START( node ); 197 call_beginScope(); 198 199 mutateStatementList( node->get_kids() ); 200 201 call_endScope(); 202 MUTATE_END( CompoundStmt, node ); 203 } 204 205 template< typename pass_type > 68 206 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 69 207 VISIT_BODY( node ); … … 71 209 72 210 template< typename pass_type > 211 Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) { 212 MUTATE_START( node ); 213 214 node->set_expr( mutateExpression( node->get_expr() ) ); 215 216 MUTATE_END( Statement, node ); 217 } 218 219 template< typename pass_type > 73 220 void PassVisitor< pass_type >::visit( AsmStmt * node ) { 74 221 VISIT_BODY( node ); … … 81 228 82 229 template< typename pass_type > 230 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 231 MUTATE_START( node ); 232 233 node->set_condition( mutateExpression( node->get_condition() ) ); 234 node->set_thenPart ( mutateStatement ( node->get_thenPart() ) ); 235 node->set_elsePart ( mutateStatement ( node->get_elsePart() ) ); 236 237 MUTATE_END( Statement, node ); 238 } 239 240 template< typename pass_type > 83 241 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 84 242 VISIT_BODY( node ); … … 86 244 87 245 template< typename pass_type > 246 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { 247 MUTATE_START( node ); 248 249 node->set_condition( mutateExpression( node->get_condition() ) ); 250 node->set_body( mutateStatement( node->get_body() ) ); 251 252 MUTATE_END( Statement, node ); 253 } 254 255 256 template< typename pass_type > 88 257 void PassVisitor< pass_type >::visit( ForStmt * node ) { 89 258 VISIT_BODY( node ); … … 91 260 92 261 template< typename pass_type > 262 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { 263 MUTATE_START( node ); 264 265 mutateAll( node->get_initialization(), *this ); 266 node->set_condition( mutateExpression( node->get_condition() ) ); 267 node->set_increment( mutateExpression( node->get_increment() ) ); 268 node->set_body( mutateStatement( node->get_body() ) ); 269 270 MUTATE_END( Statement, node ); 271 } 272 273 template< typename pass_type > 93 274 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 94 275 VISIT_BODY( node ); … … 96 277 97 278 template< typename pass_type > 279 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { 280 MUTATE_START( node ); 281 282 node->set_condition( mutateExpression( node->get_condition() ) ); 283 mutateStatementList( node->get_statements() ); 284 285 MUTATE_END( Statement, node ); 286 } 287 288 template< typename pass_type > 98 289 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 99 290 VISIT_BODY( node ); … … 101 292 102 293 template< typename pass_type > 294 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { 295 MUTATE_START( node ); 296 297 node->set_condition( mutateExpression( node->get_condition() ) ); 298 mutateStatementList( node->get_statements() ); 299 300 MUTATE_END( Statement, node ); 301 } 302 303 template< typename pass_type > 103 304 void PassVisitor< pass_type >::visit( BranchStmt * node ) { 104 305 VISIT_BODY( node ); … … 111 312 112 313 template< typename pass_type > 314 Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) { 315 MUTATE_START( node ); 316 317 node->set_expr( mutateExpression( node->get_expr() ) ); 318 319 MUTATE_END( Statement, node ); 320 } 321 322 template< typename pass_type > 113 323 void PassVisitor< pass_type >::visit( TryStmt * node ) { 114 324 VISIT_BODY( node ); … … 116 326 117 327 template< typename pass_type > 328 Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) { 329 MUTATE_START( node ); 330 331 node->set_block( maybeMutate( node->get_block(), *this ) ); 332 mutateAll( node->get_catchers(), *this ); 333 334 MUTATE_END( Statement, node ); 335 } 336 337 template< typename pass_type > 118 338 void PassVisitor< pass_type >::visit( CatchStmt * node ) { 119 339 VISIT_BODY( node ); … … 121 341 122 342 template< typename pass_type > 343 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { 344 MUTATE_START( node ); 345 346 node->set_body( mutateStatement( node->get_body() ) ); 347 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 348 349 MUTATE_END( Statement, node ); 350 } 351 352 template< typename pass_type > 123 353 void PassVisitor< pass_type >::visit( FinallyStmt * node ) { 124 354 VISIT_BODY( node ); … … 151 381 152 382 template< typename pass_type > 383 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) { 384 MUTATE_START( node ); 385 386 for ( auto& expr : node->get_args() ) { 387 expr = mutateExpression( expr ); 388 } 389 390 MUTATE_END( Expression, node ); 391 } 392 393 template< typename pass_type > 153 394 void PassVisitor< pass_type >::visit( NameExpr * node ) { 154 395 VISIT_BODY( node ); … … 301 542 302 543 template< typename pass_type > 544 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { 545 MUTATE_START( node ); 546 547 // don't want statements from outer CompoundStmts to be added to this StmtExpr 548 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 549 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 550 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 551 552 Mutator::mutate( node ); 553 554 MUTATE_END( Expression, node ); 555 } 556 557 template< typename pass_type > 303 558 void PassVisitor< pass_type >::visit( UniqueExpr * node ) { 304 559 VISIT_BODY( node ); … … 388 643 void PassVisitor< pass_type >::visit( SingleInit * node ) { 389 644 VISIT_BODY( node ); 645 } 646 647 template< typename pass_type > 648 Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) { 649 MUTATE_START( node ); 650 651 node->set_value( mutateExpression( node->get_value() ) ); 652 653 MUTATE_END( Initializer, node ); 390 654 } 391 655 … … 458 722 459 723 template< typename pass_type > 460 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {461 MUTATE_BODY( CompoundStmt, node );462 }463 464 template< typename pass_type >465 Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {466 MUTATE_BODY( Statement, node );467 }468 469 template< typename pass_type >470 724 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { 471 725 MUTATE_BODY( Statement, node ); … … 473 727 474 728 template< typename pass_type > 475 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {476 MUTATE_BODY( Statement, node );477 }478 479 template< typename pass_type >480 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {481 MUTATE_BODY( Statement, node );482 }483 484 template< typename pass_type >485 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {486 MUTATE_BODY( Statement, node );487 }488 489 template< typename pass_type >490 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {491 MUTATE_BODY( Statement, node );492 }493 494 template< typename pass_type >495 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {496 MUTATE_BODY( Statement, node );497 }498 499 template< typename pass_type >500 729 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { 501 730 MUTATE_BODY( Statement, node ); … … 503 732 504 733 template< typename pass_type > 505 Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {506 MUTATE_BODY( Statement, node );507 }508 509 template< typename pass_type >510 Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {511 MUTATE_BODY( Statement, node );512 }513 514 template< typename pass_type >515 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {516 MUTATE_BODY( Statement, node );517 }518 519 template< typename pass_type >520 734 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 521 735 MUTATE_BODY( Statement, node ); … … 543 757 544 758 template< typename pass_type > 545 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {546 MUTATE_BODY( Expression, node );547 }548 549 template< typename pass_type >550 759 Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) { 551 760 MUTATE_BODY( Expression, node ); … … 693 902 694 903 template< typename pass_type > 695 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {696 MUTATE_BODY( Expression, node );697 }698 699 template< typename pass_type >700 904 Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) { 701 905 MUTATE_BODY( Expression, node ); … … 780 984 Type * PassVisitor< pass_type >::mutate( OneType * node ) { 781 985 MUTATE_BODY( Type, node ); 782 }783 784 template< typename pass_type >785 Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {786 MUTATE_BODY( Initializer, node );787 986 } 788 987 -
src/Common/utility.h
r4a58895 r676cc8c 244 244 ValueGuard(T& inRef) : old(inRef), ref(inRef) {} 245 245 ~ValueGuard() { ref = old; } 246 }; 247 248 template< typename T > 249 struct ValueGuardPtr { 250 T old; 251 T* ref; 252 253 ValueGuardPtr(T * inRef) : old( inRef ? *inRef : T() ), ref(inRef) {} 254 ~ValueGuardPtr() { if( ref ) *ref = old; } 255 }; 256 257 template< typename T > 258 struct ValueGuardPtr< std::list< T > > { 259 std::list< T > old; 260 std::list< T >* ref; 261 262 ValueGuardPtr( std::list< T > * inRef) : old(), ref(inRef) { 263 if( ref ) { swap( *ref, old ); } 264 } 265 ~ValueGuardPtr() { if( ref ) { swap( *ref, old ); } } 246 266 }; 247 267 -
src/InitTweak/FixInit.cc
r4a58895 r676cc8c 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 … … 300 302 namespace { 301 303 void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) { 302 InsertImplicitCallsinserter( envMap );304 PassVisitor<InsertImplicitCalls> inserter( envMap ); 303 305 mutateAll( translationUnit, inserter ); 304 306 } … … 350 352 } 351 353 352 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) { 353 appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) ); 354 Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) { 354 355 assert( appExpr ); 355 356 … … 393 394 } 394 395 395 Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {396 void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) { 396 397 assert( env ); 397 398 envMap[stmtExpr] = env; 398 return Parent::mutate( stmtExpr );399 399 } 400 400
Note: See TracChangeset
for help on using the changeset viewer.