Changeset 7821d6c for src/Common
- Timestamp:
- Oct 3, 2017, 2:55:17 PM (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:
- 680620d
- Parents:
- 21b7161 (diff), e1ff775 (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. - Location:
- src/Common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r21b7161 r7821d6c 4 4 5 5 #include <stack> 6 7 #include "Common/utility.h" 6 8 7 9 #include "SynTree/Mutator.h" … … 239 241 template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 240 242 template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 243 template< typename TreeType, typename pass_t > friend void maybeAccept_impl( TreeType * tree, PassVisitor< pass_t > & visitor ); 244 template< typename TreeType, typename pass_t > friend void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_t > & mutator ); 245 template< typename Container, typename pass_t > friend void maybeAccept_impl( Container & container, PassVisitor< pass_t > & visitor ); 246 template< typename Container, typename pass_t > friend void maybeMutate_impl( Container & container, PassVisitor< pass_t > & mutator ); 241 247 242 248 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } … … 273 279 std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); } 274 280 275 void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } 281 bool get_visit_children () { bool_ref * ptr = visit_children_impl(pass, 0); return ptr ? *ptr : true; } 282 bool_ref * get_visit_children_ptr() { return visit_children_impl(pass, 0); } 276 283 277 284 void indexerScopeEnter () { indexer_impl_enterScope ( pass, 0 ); } -
src/Common/PassVisitor.impl.h
r21b7161 r7821d6c 2 2 // IWYU pragma: private, include "PassVisitor.h" 3 3 4 #define VISIT_START( node ) \ 5 __attribute__((unused)) \ 4 #define VISIT_START( node ) \ 5 __attribute__((unused)) \ 6 ChildrenGuard children_guard( get_visit_children_ptr() ); \ 7 __attribute__((unused)) \ 6 8 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ 7 bool visit_children = true; \ 8 set_visit_children( visit_children ); \ 9 call_previsit( node ); \ 10 if( visit_children ) { \ 9 call_previsit( node ); \ 11 10 12 11 #define VISIT_END( node ) \ 13 } \14 12 call_postvisit( node ); \ 15 13 16 #define MUTATE_START( node ) \ 17 __attribute__((unused)) \ 14 #define MUTATE_START( node ) \ 15 __attribute__((unused)) \ 16 ChildrenGuard children_guard( get_visit_children_ptr() ); \ 17 __attribute__((unused)) \ 18 18 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ 19 bool visit_children = true; \ 20 set_visit_children( visit_children ); \ 21 call_premutate( node ); \ 22 if( visit_children ) { \ 19 call_premutate( node ); \ 23 20 24 21 #define MUTATE_END( type, node ) \ 25 } \26 22 return call_postmutate< type * >( node ); \ 27 23 28 24 29 #define VISIT_BODY( node ) \ 30 VISIT_START( node ); \ 31 Visitor::visit( node ); \ 32 VISIT_END( node ); \ 33 34 35 #define MUTATE_BODY( type, node ) \ 36 MUTATE_START( node ); \ 37 Mutator::mutate( node ); \ 38 MUTATE_END( type, node ); \ 25 #define VISIT_BODY( node ) \ 26 VISIT_START( node ); \ 27 if( children_guard ) { \ 28 Visitor::visit( node ); \ 29 } \ 30 VISIT_END( node ); \ 31 32 33 #define MUTATE_BODY( type, node ) \ 34 MUTATE_START( node ); \ 35 if( children_guard ) { \ 36 Mutator::mutate( node ); \ 37 } \ 38 MUTATE_END( type, node ); \ 39 39 40 40 … … 63 63 template< typename pass_type > 64 64 static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) { 65 66 65 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 67 66 DeclList_t* afterDecls = visitor.get_afterDecls(); … … 76 75 try { 77 76 // run visitor on declaration 78 maybeAccept ( *i, visitor );77 maybeAccept_impl( *i, visitor ); 79 78 } catch( SemanticError &e ) { 80 79 e.set_location( (*i)->location ); … … 92 91 template< typename pass_type > 93 92 static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { 94 95 93 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 96 94 DeclList_t* afterDecls = mutator.get_afterDecls(); … … 104 102 try { 105 103 // run mutator on declaration 106 *i = maybeMutate( *i, mutator );104 maybeMutate_impl( *i, mutator ); 107 105 } catch( SemanticError &e ) { 108 106 e.set_location( (*i)->location ); … … 118 116 } 119 117 120 template< typename Container, typename VisitorType > 121 inline void maybeAccept( Container &container, VisitorType &visitor ) { 118 template< typename TreeType, typename pass_type > 119 inline void maybeAccept_impl( TreeType * tree, PassVisitor< pass_type > & visitor ) { 120 if ( ! visitor.get_visit_children() ) return; 121 if ( tree ) { 122 tree->accept( visitor ); 123 } 124 } 125 126 template< typename Container, typename pass_type > 127 inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) { 128 if ( ! visitor.get_visit_children() ) return; 122 129 SemanticError errors; 123 130 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { … … 136 143 } 137 144 138 template< typename Container, typename MutatorType > 139 inline void maybeMutateRef( Container &container, MutatorType &mutator ) { 145 template< typename TreeType, typename pass_type > 146 inline void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_type > & mutator ) { 147 if ( ! mutator.get_visit_children() ) return; 148 149 if ( tree ) { 150 tree = strict_dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) ); 151 } 152 } 153 154 template< typename Container, typename pass_type > 155 inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) { 156 if ( ! mutator.get_visit_children() ) return; 140 157 SemanticError errors; 141 158 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 142 159 try { 143 160 if ( *i ) { 144 /// *i = (*i)->acceptMutator( mutator );145 161 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); 146 162 assert( *i ); … … 159 175 template< typename func_t > 160 176 void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { 177 if ( ! get_visit_children() ) return; 161 178 SemanticError errors; 162 179 … … 199 216 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 200 217 handleStatementList( statements, [this]( Statement * stmt) { 201 stmt->accept(*this );218 maybeAccept_impl( stmt, *this ); 202 219 }); 203 220 } … … 206 223 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 207 224 handleStatementList( statements, [this]( Statement *& stmt) { 208 stmt = stmt->acceptMutator(*this );225 maybeMutate_impl( stmt, *this ); 209 226 }); 210 227 } … … 214 231 template< typename func_t > 215 232 Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) { 233 if ( ! get_visit_children() ) return stmt; 234 216 235 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 217 236 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr () ); … … 244 263 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 245 264 return handleStatement( stmt, [this]( Statement * stmt ) { 246 maybeAccept ( stmt, *this );265 maybeAccept_impl( stmt, *this ); 247 266 return stmt; 248 267 }); … … 252 271 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 253 272 return handleStatement( stmt, [this]( Statement * stmt ) { 254 return maybeMutate( stmt, *this ); 273 maybeMutate_impl( stmt, *this ); 274 return stmt; 255 275 }); 256 276 } … … 259 279 template< typename func_t > 260 280 Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) { 281 if ( ! get_visit_children() ) return expr; 261 282 if( !expr ) return nullptr; 262 283 … … 266 287 } 267 288 268 // should env be cloned (or moved)onto the result of the mutate?289 // should env be moved onto the result of the mutate? 269 290 return func( expr ); 270 291 } … … 273 294 Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) { 274 295 return handleExpression(expr, [this]( Expression * expr ) { 275 expr->accept(*this );296 maybeAccept_impl( expr, *this ); 276 297 return expr; 277 298 }); … … 281 302 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 282 303 return handleExpression(expr, [this]( Expression * expr ) { 283 return expr->acceptMutator( *this ); 304 maybeMutate_impl( expr, *this ); 305 return expr; 284 306 }); 307 } 308 309 template< typename TreeType, typename VisitorType > 310 inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) { 311 if ( ! visitor.get_visit_children() ) return; 312 auto guard = makeFuncGuard( 313 [&visitor]() { visitor.indexerScopeEnter(); }, 314 [&visitor]() { visitor.indexerScopeLeave(); } 315 ); 316 maybeAccept_impl( tree, visitor ); 317 } 318 319 template< typename TreeType, typename MutatorType > 320 inline void indexerScopedMutate( TreeType *& tree, MutatorType & mutator ) { 321 if ( ! mutator.get_visit_children() ) return; 322 auto guard = makeFuncGuard( 323 [&mutator]() { mutator.indexerScopeEnter(); }, 324 [&mutator]() { mutator.indexerScopeLeave(); } 325 ); 326 maybeMutate_impl( tree, mutator ); 285 327 } 286 328 … … 319 361 320 362 indexerScopedAccept( node->type , *this ); 321 maybeAccept 322 maybeAccept 323 maybeAccept 363 maybeAccept_impl ( node->init , *this ); 364 maybeAccept_impl ( node->bitfieldWidth, *this ); 365 maybeAccept_impl ( node->attributes , *this ); 324 366 325 367 if ( node->name != "" ) { … … 335 377 336 378 indexerScopedMutate( node->type , *this ); 337 maybeMutate Ref( node->init , *this );338 maybeMutate Ref( node->bitfieldWidth, *this );339 maybeMutate Ref( node->attributes , *this );379 maybeMutate_impl ( node->init , *this ); 380 maybeMutate_impl ( node->bitfieldWidth, *this ); 381 maybeMutate_impl ( node->attributes , *this ); 340 382 341 383 if ( node->name != "" ) { … … 358 400 { 359 401 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 360 maybeAccept ( node->type, *this );361 maybeAccept ( node->statements, *this );362 maybeAccept ( node->attributes, *this );402 maybeAccept_impl( node->type, *this ); 403 maybeAccept_impl( node->statements, *this ); 404 maybeAccept_impl( node->attributes, *this ); 363 405 } 364 406 … … 376 418 { 377 419 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 378 maybeMutate Ref( node->type, *this );379 maybeMutate Ref( node->statements, *this );380 maybeMutate Ref( node->attributes, *this );420 maybeMutate_impl( node->type, *this ); 421 maybeMutate_impl( node->statements, *this ); 422 maybeMutate_impl( node->attributes, *this ); 381 423 } 382 424 … … 396 438 { 397 439 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 398 maybeAccept ( node->parameters, *this );399 maybeAccept ( node->members , *this );440 maybeAccept_impl( node->parameters, *this ); 441 maybeAccept_impl( node->members , *this ); 400 442 } 401 443 … … 416 458 { 417 459 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 418 maybeMutate Ref( node->parameters, *this );419 maybeMutate Ref( node->members , *this );460 maybeMutate_impl( node->parameters, *this ); 461 maybeMutate_impl( node->members , *this ); 420 462 } 421 463 … … 437 479 { 438 480 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 439 maybeAccept ( node->parameters, *this );440 maybeAccept ( node->members , *this );481 maybeAccept_impl( node->parameters, *this ); 482 maybeAccept_impl( node->members , *this ); 441 483 } 442 484 … … 455 497 { 456 498 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 457 maybeMutate Ref( node->parameters, *this );458 maybeMutate Ref( node->members , *this );499 maybeMutate_impl( node->parameters, *this ); 500 maybeMutate_impl( node->members , *this ); 459 501 } 460 502 … … 473 515 474 516 // unlike structs, traits, and unions, enums inject their members into the global scope 475 maybeAccept ( node->parameters, *this );476 maybeAccept ( node->members , *this );517 maybeAccept_impl( node->parameters, *this ); 518 maybeAccept_impl( node->members , *this ); 477 519 478 520 VISIT_END( node ); … … 486 528 487 529 // unlike structs, traits, and unions, enums inject their members into the global scope 488 maybeMutate Ref( node->parameters, *this );489 maybeMutate Ref( node->members , *this );530 maybeMutate_impl( node->parameters, *this ); 531 maybeMutate_impl( node->members , *this ); 490 532 491 533 MUTATE_END( Declaration, node ); … … 500 542 { 501 543 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 502 maybeAccept ( node->parameters, *this );503 maybeAccept ( node->members , *this );544 maybeAccept_impl( node->parameters, *this ); 545 maybeAccept_impl( node->members , *this ); 504 546 } 505 547 … … 515 557 { 516 558 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 517 maybeMutate Ref( node->parameters, *this );518 maybeMutate Ref( node->members , *this );559 maybeMutate_impl( node->parameters, *this ); 560 maybeMutate_impl( node->members , *this ); 519 561 } 520 562 … … 532 574 { 533 575 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 534 maybeAccept ( node->parameters, *this );535 maybeAccept ( node->base , *this );576 maybeAccept_impl( node->parameters, *this ); 577 maybeAccept_impl( node->base , *this ); 536 578 } 537 579 … … 541 583 indexerAddType( node ); 542 584 543 maybeAccept ( node->assertions, *this );585 maybeAccept_impl( node->assertions, *this ); 544 586 545 587 indexerScopedAccept( node->init, *this ); … … 554 596 { 555 597 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 556 maybeMutate Ref( node->parameters, *this );557 maybeMutate Ref( node->base , *this );598 maybeMutate_impl( node->parameters, *this ); 599 maybeMutate_impl( node->base , *this ); 558 600 } 559 601 … … 563 605 indexerAddType( node ); 564 606 565 maybeMutate Ref( node->assertions, *this );607 maybeMutate_impl( node->assertions, *this ); 566 608 567 609 indexerScopedMutate( node->init, *this ); … … 578 620 { 579 621 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 580 maybeAccept ( node->parameters, *this );581 maybeAccept ( node->base , *this );622 maybeAccept_impl( node->parameters, *this ); 623 maybeAccept_impl( node->base , *this ); 582 624 } 583 625 584 626 indexerAddType( node ); 585 627 586 maybeAccept ( node->assertions, *this );628 maybeAccept_impl( node->assertions, *this ); 587 629 588 630 VISIT_END( node ); … … 595 637 { 596 638 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 597 maybeMutate Ref( node->parameters, *this );598 maybeMutate Ref( node->base , *this );639 maybeMutate_impl( node->parameters, *this ); 640 maybeMutate_impl( node->base , *this ); 599 641 } 600 642 601 643 indexerAddType( node ); 602 644 603 maybeMutate Ref( node->assertions, *this );645 maybeMutate_impl( node->assertions, *this ); 604 646 605 647 MUTATE_END( Declaration, node ); … … 612 654 VISIT_START( node ); 613 655 614 maybeAccept ( node->stmt, *this );656 maybeAccept_impl( node->stmt, *this ); 615 657 616 658 VISIT_END( node ); … … 621 663 MUTATE_START( node ); 622 664 623 maybeMutate Ref( node->stmt, *this );665 maybeMutate_impl( node->stmt, *this ); 624 666 625 667 MUTATE_END( AsmDecl, node ); … … 690 732 // if statements introduce a level of scope (for the initialization) 691 733 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 692 acceptAll( node->get_initialization(), *this );693 visitExpression ( node->condition );734 maybeAccept_impl( node->get_initialization(), *this ); 735 visitExpression ( node->condition ); 694 736 node->thenPart = visitStatement( node->thenPart ); 695 737 node->elsePart = visitStatement( node->elsePart ); … … 704 746 // if statements introduce a level of scope (for the initialization) 705 747 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 706 maybeMutate Ref( node->get_initialization(), *this );748 maybeMutate_impl( node->get_initialization(), *this ); 707 749 node->condition = mutateExpression( node->condition ); 708 750 node->thenPart = mutateStatement ( node->thenPart ); … … 742 784 // for statements introduce a level of scope (for the initialization) 743 785 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 744 maybeAccept ( node->initialization, *this );786 maybeAccept_impl( node->initialization, *this ); 745 787 visitExpression( node->condition ); 746 788 visitExpression( node->increment ); … … 756 798 // for statements introduce a level of scope (for the initialization) 757 799 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 758 maybeMutate Ref( node->initialization, *this );800 maybeMutate_impl( node->initialization, *this ); 759 801 node->condition = mutateExpression( node->condition ); 760 802 node->increment = mutateExpression( node->increment ); … … 859 901 VISIT_START( node ); 860 902 861 maybeAccept ( node->block , *this );862 maybeAccept ( node->handlers , *this );863 maybeAccept ( node->finallyBlock, *this );903 maybeAccept_impl( node->block , *this ); 904 maybeAccept_impl( node->handlers , *this ); 905 maybeAccept_impl( node->finallyBlock, *this ); 864 906 865 907 VISIT_END( node ); … … 870 912 MUTATE_START( node ); 871 913 872 maybeMutate Ref( node->block , *this );873 maybeMutate Ref( node->handlers , *this );874 maybeMutate Ref( node->finallyBlock, *this );914 maybeMutate_impl( node->block , *this ); 915 maybeMutate_impl( node->handlers , *this ); 916 maybeMutate_impl( node->finallyBlock, *this ); 875 917 876 918 MUTATE_END( Statement, node ); … … 885 927 // catch statements introduce a level of scope (for the caught exception) 886 928 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 887 maybeAccept ( node->decl, *this );929 maybeAccept_impl( node->decl, *this ); 888 930 node->cond = visitExpression( node->cond ); 889 931 node->body = visitStatement ( node->body ); … … 898 940 // catch statements introduce a level of scope (for the caught exception) 899 941 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 900 maybeMutate Ref( node->decl, *this );942 maybeMutate_impl( node->decl, *this ); 901 943 node->cond = mutateExpression( node->cond ); 902 944 node->body = mutateStatement ( node->body ); … … 972 1014 973 1015 indexerScopedAccept( node->result , *this ); 974 maybeAccept ( node->function, *this );975 maybeAccept ( node->args , *this );1016 maybeAccept_impl ( node->function, *this ); 1017 maybeAccept_impl ( node->args , *this ); 976 1018 977 1019 VISIT_END( node ); … … 984 1026 indexerScopedMutate( node->env , *this ); 985 1027 indexerScopedMutate( node->result , *this ); 986 maybeMutate Ref( node->function, *this );987 maybeMutate Ref( node->args , *this );1028 maybeMutate_impl ( node->function, *this ); 1029 maybeMutate_impl ( node->args , *this ); 988 1030 989 1031 MUTATE_END( Expression, node ); … … 996 1038 VISIT_START( node ); 997 1039 998 // maybeAccept ( node->get_env(), *this );1040 // maybeAccept_impl( node->get_env(), *this ); 999 1041 indexerScopedAccept( node->result, *this ); 1000 1042 … … 1048 1090 1049 1091 indexerScopedAccept( node->result, *this ); 1050 maybeAccept ( node->arg , *this );1092 maybeAccept_impl ( node->arg , *this ); 1051 1093 1052 1094 VISIT_END( node ); … … 1059 1101 indexerScopedMutate( node->env , *this ); 1060 1102 indexerScopedMutate( node->result, *this ); 1061 maybeMutate Ref( node->arg , *this );1103 maybeMutate_impl ( node->arg , *this ); 1062 1104 1063 1105 MUTATE_END( Expression, node ); … … 1071 1113 1072 1114 indexerScopedAccept( node->result, *this ); 1073 maybeAccept ( node->arg, *this );1115 maybeAccept_impl( node->arg, *this ); 1074 1116 1075 1117 VISIT_END( node ); … … 1082 1124 indexerScopedMutate( node->env , *this ); 1083 1125 indexerScopedMutate( node->result, *this ); 1084 maybeMutate Ref( node->arg , *this );1126 maybeMutate_impl ( node->arg , *this ); 1085 1127 1086 1128 MUTATE_END( Expression, node ); … … 1094 1136 1095 1137 indexerScopedAccept( node->result, *this ); 1096 maybeAccept 1138 maybeAccept_impl ( node->arg , *this ); 1097 1139 1098 1140 VISIT_END( node ); … … 1105 1147 indexerScopedMutate( node->env , *this ); 1106 1148 indexerScopedMutate( node->result, *this ); 1107 maybeMutate Ref( node->arg , *this );1149 maybeMutate_impl ( node->arg , *this ); 1108 1150 1109 1151 MUTATE_END( Expression, node ); … … 1138 1180 1139 1181 indexerScopedAccept( node->result , *this ); 1140 maybeAccept 1141 maybeAccept 1182 maybeAccept_impl ( node->aggregate, *this ); 1183 maybeAccept_impl ( node->member , *this ); 1142 1184 1143 1185 VISIT_END( node ); … … 1150 1192 indexerScopedMutate( node->env , *this ); 1151 1193 indexerScopedMutate( node->result , *this ); 1152 maybeMutate Ref( node->aggregate, *this );1153 maybeMutate Ref( node->member , *this );1194 maybeMutate_impl ( node->aggregate, *this ); 1195 maybeMutate_impl ( node->member , *this ); 1154 1196 1155 1197 MUTATE_END( Expression, node ); … … 1163 1205 1164 1206 indexerScopedAccept( node->result , *this ); 1165 maybeAccept 1207 maybeAccept_impl ( node->aggregate, *this ); 1166 1208 1167 1209 VISIT_END( node ); … … 1174 1216 indexerScopedMutate( node->env , *this ); 1175 1217 indexerScopedMutate( node->result , *this ); 1176 maybeMutate Ref( node->aggregate, *this );1218 maybeMutate_impl ( node->aggregate, *this ); 1177 1219 1178 1220 MUTATE_END( Expression, node ); … … 1207 1249 1208 1250 indexerScopedAccept( node->result , *this ); 1209 maybeAccept 1251 maybeAccept_impl ( &node->constant, *this ); 1210 1252 1211 1253 VISIT_END( node ); … … 1218 1260 indexerScopedMutate( node->env , *this ); 1219 1261 indexerScopedMutate( node->result, *this ); 1220 node->constant = *maybeMutate( &node->constant, *this ); 1262 Constant * ptr = &node->constant; 1263 maybeMutate_impl( ptr, *this ); 1264 node->constant = *ptr; 1221 1265 1222 1266 MUTATE_END( Expression, node ); … … 1231 1275 indexerScopedAccept( node->result, *this ); 1232 1276 if ( node->get_isType() ) { 1233 maybeAccept ( node->type, *this );1277 maybeAccept_impl( node->type, *this ); 1234 1278 } else { 1235 maybeAccept ( node->expr, *this );1279 maybeAccept_impl( node->expr, *this ); 1236 1280 } 1237 1281 … … 1246 1290 indexerScopedMutate( node->result, *this ); 1247 1291 if ( node->get_isType() ) { 1248 maybeMutate Ref( node->type, *this );1292 maybeMutate_impl( node->type, *this ); 1249 1293 } else { 1250 maybeMutate Ref( node->expr, *this );1294 maybeMutate_impl( node->expr, *this ); 1251 1295 } 1252 1296 … … 1262 1306 indexerScopedAccept( node->result, *this ); 1263 1307 if ( node->get_isType() ) { 1264 maybeAccept ( node->type, *this );1308 maybeAccept_impl( node->type, *this ); 1265 1309 } else { 1266 maybeAccept ( node->expr, *this );1310 maybeAccept_impl( node->expr, *this ); 1267 1311 } 1268 1312 … … 1277 1321 indexerScopedMutate( node->result, *this ); 1278 1322 if ( node->get_isType() ) { 1279 maybeMutate Ref( node->type, *this );1323 maybeMutate_impl( node->type, *this ); 1280 1324 } else { 1281 maybeMutate Ref( node->expr, *this );1325 maybeMutate_impl( node->expr, *this ); 1282 1326 } 1283 1327 … … 1292 1336 1293 1337 indexerScopedAccept( node->result, *this ); 1294 maybeAccept 1338 maybeAccept_impl ( node->type , *this ); 1295 1339 1296 1340 VISIT_END( node ); … … 1303 1347 indexerScopedMutate( node->env , *this ); 1304 1348 indexerScopedMutate( node->result, *this ); 1305 maybeMutate Ref( node->type , *this );1349 maybeMutate_impl ( node->type , *this ); 1306 1350 1307 1351 MUTATE_END( Expression, node ); … … 1315 1359 1316 1360 indexerScopedAccept( node->result, *this ); 1317 maybeAccept 1318 maybeAccept 1361 maybeAccept_impl ( node->type , *this ); 1362 maybeAccept_impl ( node->member, *this ); 1319 1363 1320 1364 VISIT_END( node ); … … 1327 1371 indexerScopedMutate( node->env , *this ); 1328 1372 indexerScopedMutate( node->result, *this ); 1329 maybeMutate Ref( node->type , *this );1330 maybeMutate Ref( node->member, *this );1373 maybeMutate_impl ( node->type , *this ); 1374 maybeMutate_impl ( node->member, *this ); 1331 1375 1332 1376 MUTATE_END( Expression, node ); … … 1340 1384 1341 1385 indexerScopedAccept( node->result, *this ); 1342 maybeAccept 1386 maybeAccept_impl ( node->type , *this ); 1343 1387 1344 1388 VISIT_END( node ); … … 1351 1395 indexerScopedMutate( node->env , *this ); 1352 1396 indexerScopedMutate( node->result, *this ); 1353 maybeMutate Ref( node->type , *this );1397 maybeMutate_impl ( node->type , *this ); 1354 1398 1355 1399 MUTATE_END( Expression, node ); … … 1364 1408 indexerScopedAccept( node->result, *this ); 1365 1409 if ( node->get_isType() ) { 1366 maybeAccept ( node->type, *this );1410 maybeAccept_impl( node->type, *this ); 1367 1411 } else { 1368 maybeAccept ( node->expr, *this );1412 maybeAccept_impl( node->expr, *this ); 1369 1413 } 1370 1414 … … 1379 1423 indexerScopedMutate( node->result, *this ); 1380 1424 if ( node->get_isType() ) { 1381 maybeMutate Ref( node->type, *this );1425 maybeMutate_impl( node->type, *this ); 1382 1426 } else { 1383 maybeMutate Ref( node->expr, *this );1427 maybeMutate_impl( node->expr, *this ); 1384 1428 } 1385 1429 … … 1394 1438 1395 1439 indexerScopedAccept( node->result, *this ); 1396 maybeAccept 1397 maybeAccept 1440 maybeAccept_impl ( node->arg1 , *this ); 1441 maybeAccept_impl ( node->arg2 , *this ); 1398 1442 1399 1443 VISIT_END( node ); … … 1406 1450 indexerScopedMutate( node->env , *this ); 1407 1451 indexerScopedMutate( node->result, *this ); 1408 maybeMutate Ref( node->arg1 , *this );1409 maybeMutate Ref( node->arg2 , *this );1452 maybeMutate_impl ( node->arg1 , *this ); 1453 maybeMutate_impl ( node->arg2 , *this ); 1410 1454 1411 1455 MUTATE_END( Expression, node ); … … 1419 1463 1420 1464 indexerScopedAccept( node->result, *this ); 1421 maybeAccept ( node->arg1 , *this );1422 maybeAccept ( node->arg2 , *this );1423 maybeAccept ( node->arg3 , *this );1465 maybeAccept_impl ( node->arg1 , *this ); 1466 maybeAccept_impl ( node->arg2 , *this ); 1467 maybeAccept_impl ( node->arg3 , *this ); 1424 1468 1425 1469 VISIT_END( node ); … … 1432 1476 indexerScopedMutate( node->env , *this ); 1433 1477 indexerScopedMutate( node->result, *this ); 1434 maybeMutate Ref( node->arg1 , *this );1435 maybeMutate Ref( node->arg2 , *this );1436 maybeMutate Ref( node->arg3 , *this );1478 maybeMutate_impl ( node->arg1 , *this ); 1479 maybeMutate_impl ( node->arg2 , *this ); 1480 maybeMutate_impl ( node->arg3 , *this ); 1437 1481 1438 1482 MUTATE_END( Expression, node ); … … 1446 1490 1447 1491 indexerScopedAccept( node->result, *this ); 1448 maybeAccept 1449 maybeAccept 1492 maybeAccept_impl ( node->arg1 , *this ); 1493 maybeAccept_impl ( node->arg2 , *this ); 1450 1494 1451 1495 VISIT_END( node ); … … 1458 1502 indexerScopedMutate( node->env , *this ); 1459 1503 indexerScopedMutate( node->result, *this ); 1460 maybeMutate Ref( node->arg1 , *this );1461 maybeMutate Ref( node->arg2 , *this );1504 maybeMutate_impl ( node->arg1 , *this ); 1505 maybeMutate_impl ( node->arg2 , *this ); 1462 1506 1463 1507 MUTATE_END( Expression, node ); … … 1471 1515 1472 1516 indexerScopedAccept( node->result, *this ); 1473 maybeAccept 1517 maybeAccept_impl ( node->type, *this ); 1474 1518 1475 1519 VISIT_END( node ); … … 1482 1526 indexerScopedMutate( node->env , *this ); 1483 1527 indexerScopedMutate( node->result, *this ); 1484 maybeMutate Ref( node->type , *this );1528 maybeMutate_impl ( node->type , *this ); 1485 1529 1486 1530 MUTATE_END( Expression, node ); … … 1494 1538 1495 1539 indexerScopedAccept( node->result , *this ); 1496 maybeAccept 1497 maybeAccept 1498 maybeAccept 1540 maybeAccept_impl ( node->inout , *this ); 1541 maybeAccept_impl ( node->constraint, *this ); 1542 maybeAccept_impl ( node->operand , *this ); 1499 1543 1500 1544 VISIT_END( node ); … … 1507 1551 indexerScopedMutate( node->env , *this ); 1508 1552 indexerScopedMutate( node->result , *this ); 1509 maybeMutate Ref( node->inout , *this );1510 maybeMutate Ref( node->constraint, *this );1511 maybeMutate Ref( node->operand , *this );1553 maybeMutate_impl ( node->inout , *this ); 1554 maybeMutate_impl ( node->constraint, *this ); 1555 maybeMutate_impl ( node->operand , *this ); 1512 1556 1513 1557 MUTATE_END( Expression, node ); … … 1521 1565 1522 1566 indexerScopedAccept( node->result , *this ); 1523 maybeAccept 1524 maybeAccept 1525 maybeAccept 1526 maybeAccept 1567 maybeAccept_impl ( node->callExpr , *this ); 1568 maybeAccept_impl ( node->tempDecls , *this ); 1569 maybeAccept_impl ( node->returnDecls, *this ); 1570 maybeAccept_impl ( node->dtors , *this ); 1527 1571 1528 1572 VISIT_END( node ); … … 1535 1579 indexerScopedMutate( node->env , *this ); 1536 1580 indexerScopedMutate( node->result , *this ); 1537 maybeMutate Ref( node->callExpr , *this );1538 maybeMutate Ref( node->tempDecls , *this );1539 maybeMutate Ref( node->returnDecls, *this );1540 maybeMutate Ref( node->dtors , *this );1581 maybeMutate_impl ( node->callExpr , *this ); 1582 maybeMutate_impl ( node->tempDecls , *this ); 1583 maybeMutate_impl ( node->returnDecls, *this ); 1584 maybeMutate_impl ( node->dtors , *this ); 1541 1585 1542 1586 MUTATE_END( Expression, node ); … … 1550 1594 1551 1595 indexerScopedAccept( node->result , *this ); 1552 maybeAccept 1596 maybeAccept_impl ( node->callExpr, *this ); 1553 1597 1554 1598 VISIT_END( node ); … … 1561 1605 indexerScopedMutate( node->env , *this ); 1562 1606 indexerScopedMutate( node->result , *this ); 1563 maybeMutate Ref( node->callExpr, *this );1607 maybeMutate_impl ( node->callExpr, *this ); 1564 1608 1565 1609 MUTATE_END( Expression, node ); … … 1573 1617 1574 1618 indexerScopedAccept( node->result , *this ); 1575 maybeAccept 1619 maybeAccept_impl ( node->initializer, *this ); 1576 1620 1577 1621 VISIT_END( node ); … … 1584 1628 indexerScopedMutate( node->env , *this ); 1585 1629 indexerScopedMutate( node->result , *this ); 1586 maybeMutate Ref( node->initializer, *this );1630 maybeMutate_impl ( node->initializer, *this ); 1587 1631 1588 1632 MUTATE_END( Expression, node ); … … 1596 1640 1597 1641 indexerScopedAccept( node->result, *this ); 1598 maybeAccept 1599 maybeAccept 1642 maybeAccept_impl ( node->low , *this ); 1643 maybeAccept_impl ( node->high , *this ); 1600 1644 1601 1645 VISIT_END( node ); … … 1608 1652 indexerScopedMutate( node->env , *this ); 1609 1653 indexerScopedMutate( node->result, *this ); 1610 maybeMutate Ref( node->low , *this );1611 maybeMutate Ref( node->high , *this );1654 maybeMutate_impl ( node->low , *this ); 1655 maybeMutate_impl ( node->high , *this ); 1612 1656 1613 1657 MUTATE_END( Expression, node ); … … 1621 1665 1622 1666 indexerScopedAccept( node->result, *this ); 1623 maybeAccept 1667 maybeAccept_impl ( node->exprs , *this ); 1624 1668 1625 1669 VISIT_END( node ); … … 1632 1676 indexerScopedMutate( node->env , *this ); 1633 1677 indexerScopedMutate( node->result, *this ); 1634 maybeMutate Ref( node->exprs , *this );1678 maybeMutate_impl ( node->exprs , *this ); 1635 1679 1636 1680 MUTATE_END( Expression, node ); … … 1644 1688 1645 1689 indexerScopedAccept( node->result, *this ); 1646 maybeAccept 1690 maybeAccept_impl ( node->exprs , *this ); 1647 1691 1648 1692 VISIT_END( node ); … … 1655 1699 indexerScopedMutate( node->env , *this ); 1656 1700 indexerScopedMutate( node->result, *this ); 1657 maybeMutate Ref( node->exprs , *this );1701 maybeMutate_impl ( node->exprs , *this ); 1658 1702 1659 1703 MUTATE_END( Expression, node ); … … 1667 1711 1668 1712 indexerScopedAccept( node->result, *this ); 1669 maybeAccept 1713 maybeAccept_impl ( node->tuple , *this ); 1670 1714 1671 1715 VISIT_END( node ); … … 1678 1722 indexerScopedMutate( node->env , *this ); 1679 1723 indexerScopedMutate( node->result, *this ); 1680 maybeMutate Ref( node->tuple , *this );1724 maybeMutate_impl ( node->tuple , *this ); 1681 1725 1682 1726 MUTATE_END( Expression, node ); … … 1690 1734 1691 1735 indexerScopedAccept( node->result , *this ); 1692 maybeAccept 1736 maybeAccept_impl ( node->stmtExpr, *this ); 1693 1737 1694 1738 VISIT_END( node ); … … 1701 1745 indexerScopedMutate( node->env , *this ); 1702 1746 indexerScopedMutate( node->result , *this ); 1703 maybeMutate Ref( node->stmtExpr, *this );1747 maybeMutate_impl ( node->stmtExpr, *this ); 1704 1748 1705 1749 MUTATE_END( Expression, node ); … … 1718 1762 1719 1763 indexerScopedAccept( node->result , *this ); 1720 maybeAccept 1721 maybeAccept 1722 maybeAccept 1764 maybeAccept_impl ( node->statements , *this ); 1765 maybeAccept_impl ( node->returnDecls, *this ); 1766 maybeAccept_impl ( node->dtors , *this ); 1723 1767 1724 1768 VISIT_END( node ); … … 1735 1779 1736 1780 indexerScopedMutate( node->result , *this ); 1737 maybeMutate Ref( node->statements , *this );1738 maybeMutate Ref( node->returnDecls, *this );1739 maybeMutate Ref( node->dtors , *this );1781 maybeMutate_impl ( node->statements , *this ); 1782 maybeMutate_impl ( node->returnDecls, *this ); 1783 maybeMutate_impl ( node->dtors , *this ); 1740 1784 1741 1785 MUTATE_END( Expression, node ); … … 1749 1793 1750 1794 indexerScopedAccept( node->result, *this ); 1751 maybeAccept 1795 maybeAccept_impl ( node->expr , *this ); 1752 1796 1753 1797 VISIT_END( node ); … … 1760 1804 indexerScopedMutate( node->env , *this ); 1761 1805 indexerScopedMutate( node->result, *this ); 1762 maybeMutate Ref( node->expr , *this );1806 maybeMutate_impl ( node->expr , *this ); 1763 1807 1764 1808 MUTATE_END( Expression, node ); … … 1805 1849 { 1806 1850 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1807 maybeAccept ( node->forall , *this );1808 maybeAccept ( node->parameters, *this );1851 maybeAccept_impl( node->forall , *this ); 1852 maybeAccept_impl( node->parameters, *this ); 1809 1853 } 1810 1854 … … 1820 1864 { 1821 1865 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1822 maybeMutate Ref( node->forall , *this );1823 maybeMutate Ref( node->parameters, *this );1866 maybeMutate_impl( node->forall , *this ); 1867 maybeMutate_impl( node->parameters, *this ); 1824 1868 } 1825 1869 … … 1837 1881 { 1838 1882 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1839 maybeAccept ( node->forall , *this );1840 maybeAccept ( node->parameters, *this );1883 maybeAccept_impl( node->forall , *this ); 1884 maybeAccept_impl( node->parameters, *this ); 1841 1885 } 1842 1886 … … 1852 1896 { 1853 1897 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1854 maybeMutate Ref( node->forall , *this );1855 maybeMutate Ref( node->parameters, *this );1898 maybeMutate_impl( node->forall , *this ); 1899 maybeMutate_impl( node->parameters, *this ); 1856 1900 } 1857 1901 … … 1877 1921 VISIT_START( node ); 1878 1922 1879 maybeAccept ( node->forall , *this );1880 maybeAccept ( node->parameters, *this );1923 maybeAccept_impl( node->forall , *this ); 1924 maybeAccept_impl( node->parameters, *this ); 1881 1925 1882 1926 VISIT_END( node ); … … 1887 1931 MUTATE_START( node ); 1888 1932 1889 maybeMutate Ref( node->forall , *this );1890 maybeMutate Ref( node->parameters, *this );1933 maybeMutate_impl( node->forall , *this ); 1934 maybeMutate_impl( node->parameters, *this ); 1891 1935 1892 1936 MUTATE_END( Type, node ); … … 1934 1978 VISIT_START( node ); 1935 1979 1936 maybeAccept ( node->get_designators(), *this );1980 maybeAccept_impl( node->get_designators(), *this ); 1937 1981 1938 1982 VISIT_END( node ); … … 1943 1987 MUTATE_START( node ); 1944 1988 1945 maybeMutate Ref( node->get_designators(), *this );1989 maybeMutate_impl( node->get_designators(), *this ); 1946 1990 1947 1991 MUTATE_END( Designation, node ); -
src/Common/PassVisitor.proto.h
r21b7161 r7821d6c 46 46 ~bool_ref() = default; 47 47 48 operator bool() { return *m_ref; }48 operator bool() { return m_ref ? *m_ref : true; } 49 49 bool operator=( bool val ) { return *m_ref = val; } 50 50 51 51 private: 52 52 53 template<typename pass> 54 friend class PassVisitor; 55 56 void set( bool & val ) { m_ref = &val; }; 57 58 bool * m_ref; 53 friend class ChildrenGuard; 54 55 bool * set( bool & val ) { 56 bool * prev = m_ref; 57 m_ref = &val; 58 return prev; 59 } 60 61 bool * m_ref = nullptr; 59 62 }; 60 63 61 template< typename TreeType, typename VisitorType > 62 inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) { 63 auto guard = makeFuncGuard( 64 [&visitor]() { visitor.indexerScopeEnter(); },65 [&visitor]() { visitor.indexerScopeLeave(); }66 );67 maybeAccept( tree, visitor );68 }69 70 template< typename TreeType, typename MutatorType > 71 inline void indexerScopedMutate( TreeType *& tree, MutatorType & mutator) {72 auto guard = makeFuncGuard(73 [&mutator]() { mutator.indexerScopeEnter(); },74 [&mutator]() { mutator.indexerScopeLeave();}75 ); 76 tree = maybeMutate( tree, mutator );77 } 78 79 template< typename TreeType, typename MutatorType > 80 inline void maybeMutateRef( TreeType *& tree, MutatorType & mutator ) { 81 tree = maybeMutate( tree, mutator );82 } 64 class ChildrenGuard { 65 public: 66 67 ChildrenGuard( bool_ref * ref ) 68 : m_val ( true ) 69 , m_prev( ref ? ref->set( m_val ) : nullptr ) 70 , m_ref ( ref ) 71 {} 72 73 ~ChildrenGuard() { 74 if( m_ref ) { 75 m_ref->set( *m_prev ); 76 } 77 } 78 79 operator bool() { return m_val; } 80 81 private: 82 bool m_val; 83 bool * m_prev; 84 bool_ref * m_ref; 85 }; 83 86 84 87 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.