Changes in src/AST/Pass.impl.hpp [f8143a6:c600df1]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
rf8143a6 rc600df1 34 34 __pass::previsit( core, node, 0 ); 35 35 36 #define VISIT( code... ) \ 37 /* if this node should visit its children */ \ 38 if ( __visit_children() ) { \ 39 /* visit the children */ \ 40 code \ 41 } 42 36 43 #define VISIT_END( type, node ) \ 37 44 /* call the implementation of the postvisit of this pass */ \ … … 79 86 80 87 template<typename it_t, template <class...> class container_t> 81 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) {82 if(empty( stmts)) return;83 84 std::move( stmts->begin(), stmts->end(), it);85 stmts->clear();88 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * decls, bool * mutated = nullptr ) { 89 if(empty(decls)) return; 90 91 std::move(decls->begin(), decls->end(), it); 92 decls->clear(); 86 93 if(mutated) *mutated = true; 87 94 } … … 123 130 return !new_val.empty(); 124 131 } 125 }126 127 128 template< typename core_t >129 template< typename node_t >130 template< typename object_t, typename super_t, typename field_t >131 void ast::Pass< core_t >::result1< node_t >::apply(object_t * object, field_t super_t::* field) {132 object->*field = value;133 132 } 134 133 … … 139 138 !std::is_base_of<ast::Expr, node_t>::value && 140 139 !std::is_base_of<ast::Stmt, node_t>::value 141 , ast::Pass< core_t >::result1< 142 typename std::remove_pointer< decltype( node->accept(*this) ) >::type 143 > 140 , decltype( node->accept(*this) ) 144 141 >::type 145 142 { … … 150 147 static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR"); 151 148 152 auto nval = node->accept( *this ); 153 ast::Pass< core_t >::result1< 154 typename std::remove_pointer< decltype( node->accept(*this) ) >::type 155 > res; 156 res.differs = nval != node; 157 res.value = nval; 158 return res; 149 return node->accept( *this ); 159 150 } 160 151 161 152 template< typename core_t > 162 ast::Pass< core_t >::result1<ast::Expr>ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {153 const ast::Expr * ast::Pass< core_t >::call_accept( const ast::Expr * expr ) { 163 154 __pedantic_pass_assert( __visit_children() ); 164 155 __pedantic_pass_assert( expr ); … … 169 160 } 170 161 171 auto nval = expr->accept( *this ); 172 return { nval != expr, nval }; 162 return expr->accept( *this ); 173 163 } 174 164 175 165 template< typename core_t > 176 ast::Pass< core_t >::result1<ast::Stmt>ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {166 const ast::Stmt * ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) { 177 167 __pedantic_pass_assert( __visit_children() ); 178 168 __pedantic_pass_assert( stmt ); 179 169 180 const ast::Stmt * nval = stmt->accept( *this ); 181 return { nval != stmt, nval }; 170 return stmt->accept( *this ); 182 171 } 183 172 184 173 template< typename core_t > 185 ast::Pass< core_t >::result1<ast::Stmt>ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {174 const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) { 186 175 __pedantic_pass_assert( __visit_children() ); 187 176 __pedantic_pass_assert( stmt ); … … 208 197 // If the pass doesn't want to add anything then we are done 209 198 if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) { 210 return { nstmt != stmt, nstmt };199 return nstmt; 211 200 } 212 201 … … 230 219 __pass::take_all( std::back_inserter( compound->kids ), stmts_after ); 231 220 232 return {true, compound};221 return compound; 233 222 } 234 223 235 224 template< typename core_t > 236 225 template< template <class...> class container_t > 237 template< typename object_t, typename super_t, typename field_t > 238 void ast::Pass< core_t >::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) { 239 auto & container = object->*field; 240 __pedantic_pass_assert( container.size() <= values.size() ); 241 242 auto cit = enumerate(container).begin(); 243 244 container_t<ptr<Stmt>> nvals; 245 for(delta & d : values) { 246 if( d.is_old ) { 247 __pedantic_pass_assert( cit.idx <= d.old_idx ); 248 std::advance( cit, d.old_idx - cit.idx ); 249 nvals.push_back( std::move( (*cit).val) ); 250 } else { 251 nvals.push_back( std::move(d.nval) ); 252 } 253 } 254 255 object->*field = std::move(nvals); 256 } 257 258 template< typename core_t > 259 template< template <class...> class container_t > 260 ast::Pass< core_t >::resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { 226 container_t< ptr<Stmt> > ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { 261 227 __pedantic_pass_assert( __visit_children() ); 262 228 if( statements.empty() ) return {}; … … 285 251 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 286 252 287 resultNstmt<container_t> new_kids; 288 for( auto value : enumerate( statements ) ) { 253 bool mutated = false; 254 container_t< ptr<Stmt> > new_kids; 255 for( const Stmt * stmt : statements ) { 289 256 try { 290 size_t i = value.idx;291 const Stmt * stmt = value.val;292 257 __pedantic_pass_assert( stmt ); 293 258 const ast::Stmt * new_stmt = stmt->accept( *this ); 294 259 assert( new_stmt ); 295 if(new_stmt != stmt ) { new_kids.differs = true; }260 if(new_stmt != stmt ) mutated = true; 296 261 297 262 // Make sure that it is either adding statements or declartions but not both … … 303 268 304 269 // Take all the statements which should have gone after, N/A for first iteration 305 new_kids.take_all( decls_before);306 new_kids.take_all( stmts_before);270 __pass::take_all( std::back_inserter( new_kids ), decls_before, &mutated ); 271 __pass::take_all( std::back_inserter( new_kids ), stmts_before, &mutated ); 307 272 308 273 // Now add the statement if there is one 309 if(new_stmt != stmt) { 310 new_kids.values.emplace_back( new_stmt, i, false ); 311 } else { 312 new_kids.values.emplace_back( nullptr, i, true ); 313 } 274 new_kids.emplace_back( new_stmt ); 314 275 315 276 // Take all the declarations that go before 316 new_kids.take_all( decls_after);317 new_kids.take_all( stmts_after);277 __pass::take_all( std::back_inserter( new_kids ), decls_after, &mutated ); 278 __pass::take_all( std::back_inserter( new_kids ), stmts_after, &mutated ); 318 279 } 319 280 catch ( SemanticErrorException &e ) { … … 324 285 if ( !errors.isEmpty() ) { throw errors; } 325 286 326 return new_kids;287 return mutated ? new_kids : container_t< ptr<Stmt> >(); 327 288 } 328 289 329 290 template< typename core_t > 330 291 template< template <class...> class container_t, typename node_t > 331 template< typename object_t, typename super_t, typename field_t > 332 void ast::Pass< core_t >::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) { 333 auto & container = object->*field; 334 __pedantic_pass_assert( container.size() == values.size() ); 335 336 for(size_t i = 0; i < container.size(); i++) { 337 // Take all the elements that are different in 'values' 338 // and swap them into 'container' 339 if( values[i] != nullptr ) std::swap(container[i], values[i]); 340 } 341 342 // Now the original containers should still have the unchanged values 343 // but also contain the new values 344 } 345 346 template< typename core_t > 347 template< template <class...> class container_t, typename node_t > 348 ast::Pass< core_t >::resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { 292 container_t< ast::ptr<node_t> > ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { 349 293 __pedantic_pass_assert( __visit_children() ); 350 294 if( container.empty() ) return {}; … … 356 300 357 301 bool mutated = false; 358 container_t< ptr<node_t>> new_kids;302 container_t< ast::ptr<node_t> > new_kids; 359 303 for ( const node_t * node : container ) { 360 304 try { 361 305 __pedantic_pass_assert( node ); 362 306 const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) ); 363 if(new_stmt != node ) { 364 mutated = true; 365 new_kids.emplace_back( new_stmt ); 366 } else { 367 new_kids.emplace_back( nullptr ); 368 } 369 307 if(new_stmt != node ) mutated = true; 308 309 new_kids.emplace_back( new_stmt ); 370 310 } 371 311 catch( SemanticErrorException &e ) { … … 373 313 } 374 314 } 375 376 __pedantic_pass_assert( new_kids.size() == container.size() );377 315 pass_visitor_stats.depth--; 378 316 if ( ! errors.isEmpty() ) { throw errors; } 379 317 380 return ast::Pass< core_t >::resultN<container_t, node_t>{ mutated, new_kids };318 return mutated ? new_kids : container_t< ast::ptr<node_t> >(); 381 319 } 382 320 … … 396 334 auto new_val = call_accept( old_val ); 397 335 398 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");399 400 if( new_val.differs) {336 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR"); 337 338 if( __pass::differs(old_val, new_val) ) { 401 339 auto new_parent = __pass::mutate<core_t>(parent); 402 new_ val.apply(new_parent, child);340 new_parent->*child = new_val; 403 341 parent = new_parent; 404 342 } … … 422 360 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR"); 423 361 424 if( new_val.differs) {362 if( __pass::differs(old_val, new_val) ) { 425 363 auto new_parent = __pass::mutate<core_t>(parent); 426 new_ val.apply( new_parent, child );364 new_parent->*child = new_val; 427 365 parent = new_parent; 428 366 } … … 514 452 VISIT_START( node ); 515 453 516 if ( __visit_children() ) {454 VISIT( 517 455 { 518 456 guard_symtab guard { *this }; … … 522 460 maybe_accept( node, &ObjectDecl::bitfieldWidth ); 523 461 maybe_accept( node, &ObjectDecl::attributes ); 524 }462 ) 525 463 526 464 __pass::symtab::addId( core, 0, node ); … … 537 475 __pass::symtab::addId( core, 0, node ); 538 476 539 if ( __visit_children() ) { 540 maybe_accept( node, &FunctionDecl::withExprs ); 541 } 477 VISIT(maybe_accept( node, &FunctionDecl::withExprs );) 542 478 { 543 479 // with clause introduces a level of scope (for the with expression members). … … 557 493 } }; 558 494 __pass::symtab::addId( core, 0, func ); 559 if ( __visit_children() ) {495 VISIT( 560 496 // parameter declarations 561 497 maybe_accept( node, &FunctionDecl::params ); … … 573 509 maybe_accept( node, &FunctionDecl::stmts ); 574 510 maybe_accept( node, &FunctionDecl::attributes ); 575 }511 ) 576 512 } 577 513 } … … 590 526 __pass::symtab::addStructFwd( core, 0, node ); 591 527 592 if ( __visit_children() ){528 VISIT({ 593 529 guard_symtab guard { * this }; 594 530 maybe_accept( node, &StructDecl::params ); 595 531 maybe_accept( node, &StructDecl::members ); 596 532 maybe_accept( node, &StructDecl::attributes ); 597 } 533 }) 598 534 599 535 // this addition replaces the forward declaration … … 612 548 __pass::symtab::addUnionFwd( core, 0, node ); 613 549 614 if ( __visit_children() ){550 VISIT({ 615 551 guard_symtab guard { * this }; 616 552 maybe_accept( node, &UnionDecl::params ); 617 553 maybe_accept( node, &UnionDecl::members ); 618 554 maybe_accept( node, &UnionDecl::attributes ); 619 } 555 }) 620 556 621 557 __pass::symtab::addUnion( core, 0, node ); … … 632 568 __pass::symtab::addEnum( core, 0, node ); 633 569 634 if ( __visit_children() ) {570 VISIT( 635 571 // unlike structs, traits, and unions, enums inject their members into the global scope 636 572 maybe_accept( node, &EnumDecl::params ); 637 573 maybe_accept( node, &EnumDecl::members ); 638 574 maybe_accept( node, &EnumDecl::attributes ); 639 }575 ) 640 576 641 577 VISIT_END( Decl, node ); … … 648 584 VISIT_START( node ); 649 585 650 if ( __visit_children() ){586 VISIT({ 651 587 guard_symtab guard { *this }; 652 588 maybe_accept( node, &TraitDecl::params ); 653 589 maybe_accept( node, &TraitDecl::members ); 654 590 maybe_accept( node, &TraitDecl::attributes ); 655 } 591 }) 656 592 657 593 __pass::symtab::addTrait( core, 0, node ); … … 666 602 VISIT_START( node ); 667 603 668 if ( __visit_children() ){604 VISIT({ 669 605 guard_symtab guard { *this }; 670 606 maybe_accept( node, &TypeDecl::base ); 671 } 607 }) 672 608 673 609 // see A NOTE ON THE ORDER OF TRAVERSAL, above … … 676 612 __pass::symtab::addType( core, 0, node ); 677 613 678 if ( __visit_children() ) {614 VISIT( 679 615 maybe_accept( node, &TypeDecl::assertions ); 680 616 … … 683 619 maybe_accept( node, &TypeDecl::init ); 684 620 } 685 }621 ) 686 622 687 623 VISIT_END( Decl, node ); … … 694 630 VISIT_START( node ); 695 631 696 if ( __visit_children() ){632 VISIT({ 697 633 guard_symtab guard { *this }; 698 634 maybe_accept( node, &TypedefDecl::base ); 699 } 635 }) 700 636 701 637 __pass::symtab::addType( core, 0, node ); 702 638 703 if ( __visit_children() ) { 704 maybe_accept( node, &TypedefDecl::assertions ); 705 } 639 VISIT( maybe_accept( node, &TypedefDecl::assertions ); ) 706 640 707 641 VISIT_END( Decl, node ); … … 714 648 VISIT_START( node ); 715 649 716 if ( __visit_children() ) {650 VISIT( 717 651 maybe_accept( node, &AsmDecl::stmt ); 718 }652 ) 719 653 720 654 VISIT_END( AsmDecl, node ); … … 727 661 VISIT_START( node ); 728 662 729 if ( __visit_children() ) {663 VISIT( 730 664 maybe_accept( node, &DirectiveDecl::stmt ); 731 }665 ) 732 666 733 667 VISIT_END( DirectiveDecl, node ); … … 740 674 VISIT_START( node ); 741 675 742 if ( __visit_children() ) {676 VISIT( 743 677 maybe_accept( node, &StaticAssertDecl::cond ); 744 678 maybe_accept( node, &StaticAssertDecl::msg ); 745 }679 ) 746 680 747 681 VISIT_END( StaticAssertDecl, node ); … … 753 687 const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) { 754 688 VISIT_START( node ); 755 756 if ( __visit_children() ) { 689 VISIT( 757 690 // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result. 758 691 auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() { … … 771 704 guard_scope guard3 { *this }; 772 705 maybe_accept( node, &CompoundStmt::kids ); 773 } 774 706 ) 775 707 VISIT_END( CompoundStmt, node ); 776 708 } … … 782 714 VISIT_START( node ); 783 715 784 if ( __visit_children() ) {716 VISIT( 785 717 maybe_accept( node, &ExprStmt::expr ); 786 }718 ) 787 719 788 720 VISIT_END( Stmt, node ); … … 795 727 VISIT_START( node ) 796 728 797 if ( __visit_children() ) {729 VISIT( 798 730 maybe_accept( node, &AsmStmt::instruction ); 799 731 maybe_accept( node, &AsmStmt::output ); 800 732 maybe_accept( node, &AsmStmt::input ); 801 733 maybe_accept( node, &AsmStmt::clobber ); 802 }734 ) 803 735 804 736 VISIT_END( Stmt, node ); … … 820 752 VISIT_START( node ); 821 753 822 if ( __visit_children() ){754 VISIT({ 823 755 // if statements introduce a level of scope (for the initialization) 824 756 guard_symtab guard { *this }; 825 757 maybe_accept( node, &IfStmt::inits ); 826 758 maybe_accept( node, &IfStmt::cond ); 827 maybe_accept_as_compound( node, &IfStmt::then );828 maybe_accept_as_compound( node, &IfStmt::else _);829 } 759 maybe_accept_as_compound( node, &IfStmt::thenPart ); 760 maybe_accept_as_compound( node, &IfStmt::elsePart ); 761 }) 830 762 831 763 VISIT_END( Stmt, node ); … … 833 765 834 766 //-------------------------------------------------------------------------- 835 // While DoStmt836 template< typename core_t > 837 const ast::Stmt * ast::Pass< core_t >::visit( const ast::While DoStmt * node ) {838 VISIT_START( node ); 839 840 if ( __visit_children() ){767 // WhileStmt 768 template< typename core_t > 769 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileStmt * node ) { 770 VISIT_START( node ); 771 772 VISIT({ 841 773 // while statements introduce a level of scope (for the initialization) 842 774 guard_symtab guard { *this }; 843 maybe_accept( node, &While DoStmt::inits );844 maybe_accept( node, &While DoStmt::cond );845 maybe_accept_as_compound( node, &While DoStmt::body );846 } 775 maybe_accept( node, &WhileStmt::inits ); 776 maybe_accept( node, &WhileStmt::cond ); 777 maybe_accept_as_compound( node, &WhileStmt::body ); 778 }) 847 779 848 780 VISIT_END( Stmt, node ); … … 855 787 VISIT_START( node ); 856 788 857 if ( __visit_children() ){789 VISIT({ 858 790 // for statements introduce a level of scope (for the initialization) 859 791 guard_symtab guard { *this }; … … 863 795 maybe_accept( node, &ForStmt::inc ); 864 796 maybe_accept_as_compound( node, &ForStmt::body ); 865 } 797 }) 866 798 867 799 VISIT_END( Stmt, node ); … … 874 806 VISIT_START( node ); 875 807 876 if ( __visit_children() ) {808 VISIT( 877 809 maybe_accept( node, &SwitchStmt::cond ); 878 810 maybe_accept( node, &SwitchStmt::stmts ); 879 }811 ) 880 812 881 813 VISIT_END( Stmt, node ); … … 888 820 VISIT_START( node ); 889 821 890 if ( __visit_children() ) {822 VISIT( 891 823 maybe_accept( node, &CaseStmt::cond ); 892 824 maybe_accept( node, &CaseStmt::stmts ); 893 }825 ) 894 826 895 827 VISIT_END( Stmt, node ); … … 910 842 VISIT_START( node ); 911 843 912 if ( __visit_children() ) {844 VISIT( 913 845 maybe_accept( node, &ReturnStmt::expr ); 914 }846 ) 915 847 916 848 VISIT_END( Stmt, node ); … … 923 855 VISIT_START( node ); 924 856 925 if ( __visit_children() ) {857 VISIT( 926 858 maybe_accept( node, &ThrowStmt::expr ); 927 859 maybe_accept( node, &ThrowStmt::target ); 928 }860 ) 929 861 930 862 VISIT_END( Stmt, node ); … … 937 869 VISIT_START( node ); 938 870 939 if ( __visit_children() ) {871 VISIT( 940 872 maybe_accept( node, &TryStmt::body ); 941 873 maybe_accept( node, &TryStmt::handlers ); 942 874 maybe_accept( node, &TryStmt::finally ); 943 }875 ) 944 876 945 877 VISIT_END( Stmt, node ); … … 952 884 VISIT_START( node ); 953 885 954 if ( __visit_children() ){886 VISIT({ 955 887 // catch statements introduce a level of scope (for the caught exception) 956 888 guard_symtab guard { *this }; … … 958 890 maybe_accept( node, &CatchStmt::cond ); 959 891 maybe_accept_as_compound( node, &CatchStmt::body ); 960 } 892 }) 961 893 962 894 VISIT_END( Stmt, node ); … … 969 901 VISIT_START( node ); 970 902 971 if ( __visit_children() ) {903 VISIT( 972 904 maybe_accept( node, &FinallyStmt::body ); 973 }905 ) 974 906 975 907 VISIT_END( Stmt, node ); … … 982 914 VISIT_START( node ); 983 915 984 if ( __visit_children() ) {916 VISIT( 985 917 maybe_accept( node, &SuspendStmt::then ); 986 }918 ) 987 919 988 920 VISIT_END( Stmt, node ); … … 1002 934 // } 1003 935 1004 if ( __visit_children() ){936 VISIT({ 1005 937 std::vector<WaitForStmt::Clause> new_clauses; 1006 938 new_clauses.reserve( node->clauses.size() ); … … 1010 942 const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr; 1011 943 if(func != clause.target.func) mutated = true; 1012 else func = nullptr;1013 944 1014 945 std::vector<ptr<Expr>> new_args; … … 1016 947 for( const auto & arg : clause.target.args ) { 1017 948 auto a = arg->accept(*this); 1018 if( a != arg ) { 1019 mutated = true; 1020 new_args.push_back( a ); 1021 } else 1022 new_args.push_back( nullptr ); 949 new_args.push_back( a ); 950 if( a != arg ) mutated = true; 1023 951 } 1024 952 1025 953 const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr; 1026 954 if(stmt != clause.stmt) mutated = true; 1027 else stmt = nullptr;1028 955 1029 956 const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr; 1030 957 if(cond != clause.cond) mutated = true; 1031 else cond = nullptr;1032 958 1033 959 new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } ); … … 1036 962 if(mutated) { 1037 963 auto n = __pass::mutate<core_t>(node); 1038 for(size_t i = 0; i < new_clauses.size(); i++) { 1039 if(new_clauses.at(i).target.func != nullptr) std::swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func); 1040 1041 for(size_t j = 0; j < new_clauses.at(i).target.args.size(); j++) { 1042 if(new_clauses.at(i).target.args.at(j) != nullptr) std::swap(n->clauses.at(i).target.args.at(j), new_clauses.at(i).target.args.at(j)); 1043 } 1044 1045 if(new_clauses.at(i).stmt != nullptr) std::swap(n->clauses.at(i).stmt, new_clauses.at(i).stmt); 1046 if(new_clauses.at(i).cond != nullptr) std::swap(n->clauses.at(i).cond, new_clauses.at(i).cond); 1047 } 964 n->clauses = std::move( new_clauses ); 1048 965 node = n; 1049 966 } 1050 } 967 }) 1051 968 1052 969 #define maybe_accept(field) \ 1053 970 if(node->field) { \ 1054 971 auto nval = call_accept( node->field ); \ 1055 if(nval .differs) { \972 if(nval != node->field ) { \ 1056 973 auto nparent = __pass::mutate<core_t>(node); \ 1057 nparent->field = nval .value; \974 nparent->field = nval; \ 1058 975 node = nparent; \ 1059 976 } \ 1060 977 } 1061 978 1062 if ( __visit_children() ) {979 VISIT( 1063 980 maybe_accept( timeout.time ); 1064 981 maybe_accept( timeout.stmt ); … … 1066 983 maybe_accept( orElse.stmt ); 1067 984 maybe_accept( orElse.cond ); 1068 }985 ) 1069 986 1070 987 #undef maybe_accept … … 1079 996 VISIT_START( node ); 1080 997 1081 if ( __visit_children() ) {998 VISIT( 1082 999 maybe_accept( node, &WithStmt::exprs ); 1083 1000 { … … 1087 1004 maybe_accept( node, &WithStmt::stmt ); 1088 1005 } 1089 } 1090 1006 ) 1091 1007 VISIT_END( Stmt, node ); 1092 1008 } … … 1106 1022 VISIT_START( node ); 1107 1023 1108 if ( __visit_children() ) {1024 VISIT( 1109 1025 maybe_accept( node, &DeclStmt::decl ); 1110 }1026 ) 1111 1027 1112 1028 VISIT_END( Stmt, node ); … … 1121 1037 // For now this isn't visited, it is unclear if this causes problem 1122 1038 // if all tests are known to pass, remove this code 1123 if ( __visit_children() ) {1039 VISIT( 1124 1040 maybe_accept( node, &ImplicitCtorDtorStmt::callStmt ); 1125 }1041 ) 1126 1042 1127 1043 VISIT_END( Stmt, node ); … … 1134 1050 VISIT_START( node ); 1135 1051 1136 if ( __visit_children() ){1052 VISIT({ 1137 1053 // mutex statements introduce a level of scope (for the initialization) 1138 1054 guard_symtab guard { *this }; 1139 1055 maybe_accept( node, &MutexStmt::stmt ); 1140 1056 maybe_accept( node, &MutexStmt::mutexObjs ); 1141 } 1057 }) 1142 1058 1143 1059 VISIT_END( Stmt, node ); … … 1150 1066 VISIT_START( node ); 1151 1067 1152 if ( __visit_children() ) {1068 VISIT( 1153 1069 { 1154 1070 guard_symtab guard { *this }; … … 1157 1073 maybe_accept( node, &ApplicationExpr::func ); 1158 1074 maybe_accept( node, &ApplicationExpr::args ); 1159 }1075 ) 1160 1076 1161 1077 VISIT_END( Expr, node ); … … 1168 1084 VISIT_START( node ); 1169 1085 1170 if ( __visit_children() ) {1086 VISIT( 1171 1087 { 1172 1088 guard_symtab guard { *this }; … … 1175 1091 1176 1092 maybe_accept( node, &UntypedExpr::args ); 1177 }1093 ) 1178 1094 1179 1095 VISIT_END( Expr, node ); … … 1186 1102 VISIT_START( node ); 1187 1103 1188 if ( __visit_children() ){1104 VISIT({ 1189 1105 guard_symtab guard { *this }; 1190 1106 maybe_accept( node, &NameExpr::result ); 1191 } 1107 }) 1192 1108 1193 1109 VISIT_END( Expr, node ); … … 1200 1116 VISIT_START( node ); 1201 1117 1202 if ( __visit_children() ) { 1203 { 1118 VISIT({ 1204 1119 guard_symtab guard { *this }; 1205 1120 maybe_accept( node, &CastExpr::result ); 1206 1121 } 1207 1122 maybe_accept( node, &CastExpr::arg ); 1208 }1123 ) 1209 1124 1210 1125 VISIT_END( Expr, node ); … … 1217 1132 VISIT_START( node ); 1218 1133 1219 if ( __visit_children() ) { 1220 { 1134 VISIT({ 1221 1135 guard_symtab guard { *this }; 1222 1136 maybe_accept( node, &KeywordCastExpr::result ); 1223 1137 } 1224 1138 maybe_accept( node, &KeywordCastExpr::arg ); 1225 }1139 ) 1226 1140 1227 1141 VISIT_END( Expr, node ); … … 1234 1148 VISIT_START( node ); 1235 1149 1236 if ( __visit_children() ) { 1237 { 1150 VISIT({ 1238 1151 guard_symtab guard { *this }; 1239 1152 maybe_accept( node, &VirtualCastExpr::result ); 1240 1153 } 1241 1154 maybe_accept( node, &VirtualCastExpr::arg ); 1242 }1155 ) 1243 1156 1244 1157 VISIT_END( Expr, node ); … … 1251 1164 VISIT_START( node ); 1252 1165 1253 if ( __visit_children() ) { 1254 { 1166 VISIT({ 1255 1167 guard_symtab guard { *this }; 1256 1168 maybe_accept( node, &AddressExpr::result ); 1257 1169 } 1258 1170 maybe_accept( node, &AddressExpr::arg ); 1259 }1171 ) 1260 1172 1261 1173 VISIT_END( Expr, node ); … … 1268 1180 VISIT_START( node ); 1269 1181 1270 if ( __visit_children() ){1182 VISIT({ 1271 1183 guard_symtab guard { *this }; 1272 1184 maybe_accept( node, &LabelAddressExpr::result ); 1273 } 1185 }) 1274 1186 1275 1187 VISIT_END( Expr, node ); … … 1282 1194 VISIT_START( node ); 1283 1195 1284 if ( __visit_children() ) { 1285 { 1196 VISIT({ 1286 1197 guard_symtab guard { *this }; 1287 1198 maybe_accept( node, &UntypedMemberExpr::result ); … … 1289 1200 maybe_accept( node, &UntypedMemberExpr::aggregate ); 1290 1201 maybe_accept( node, &UntypedMemberExpr::member ); 1291 }1202 ) 1292 1203 1293 1204 VISIT_END( Expr, node ); … … 1300 1211 VISIT_START( node ); 1301 1212 1302 if ( __visit_children() ) { 1303 { 1213 VISIT({ 1304 1214 guard_symtab guard { *this }; 1305 1215 maybe_accept( node, &MemberExpr::result ); 1306 1216 } 1307 1217 maybe_accept( node, &MemberExpr::aggregate ); 1308 }1218 ) 1309 1219 1310 1220 VISIT_END( Expr, node ); … … 1317 1227 VISIT_START( node ); 1318 1228 1319 if ( __visit_children() ){1229 VISIT({ 1320 1230 guard_symtab guard { *this }; 1321 1231 maybe_accept( node, &VariableExpr::result ); 1322 } 1232 }) 1323 1233 1324 1234 VISIT_END( Expr, node ); … … 1331 1241 VISIT_START( node ); 1332 1242 1333 if ( __visit_children() ){1243 VISIT({ 1334 1244 guard_symtab guard { *this }; 1335 1245 maybe_accept( node, &ConstantExpr::result ); 1336 } 1246 }) 1337 1247 1338 1248 VISIT_END( Expr, node ); … … 1345 1255 VISIT_START( node ); 1346 1256 1347 if ( __visit_children() ) { 1348 { 1257 VISIT({ 1349 1258 guard_symtab guard { *this }; 1350 1259 maybe_accept( node, &SizeofExpr::result ); … … 1355 1264 maybe_accept( node, &SizeofExpr::expr ); 1356 1265 } 1357 }1266 ) 1358 1267 1359 1268 VISIT_END( Expr, node ); … … 1366 1275 VISIT_START( node ); 1367 1276 1368 if ( __visit_children() ) { 1369 { 1277 VISIT({ 1370 1278 guard_symtab guard { *this }; 1371 1279 maybe_accept( node, &AlignofExpr::result ); … … 1376 1284 maybe_accept( node, &AlignofExpr::expr ); 1377 1285 } 1378 }1286 ) 1379 1287 1380 1288 VISIT_END( Expr, node ); … … 1387 1295 VISIT_START( node ); 1388 1296 1389 if ( __visit_children() ) { 1390 { 1297 VISIT({ 1391 1298 guard_symtab guard { *this }; 1392 1299 maybe_accept( node, &UntypedOffsetofExpr::result ); 1393 1300 } 1394 1301 maybe_accept( node, &UntypedOffsetofExpr::type ); 1395 }1302 ) 1396 1303 1397 1304 VISIT_END( Expr, node ); … … 1404 1311 VISIT_START( node ); 1405 1312 1406 if ( __visit_children() ) { 1407 { 1313 VISIT({ 1408 1314 guard_symtab guard { *this }; 1409 1315 maybe_accept( node, &OffsetofExpr::result ); 1410 1316 } 1411 1317 maybe_accept( node, &OffsetofExpr::type ); 1412 }1318 ) 1413 1319 1414 1320 VISIT_END( Expr, node ); … … 1421 1327 VISIT_START( node ); 1422 1328 1423 if ( __visit_children() ) { 1424 { 1329 VISIT({ 1425 1330 guard_symtab guard { *this }; 1426 1331 maybe_accept( node, &OffsetPackExpr::result ); 1427 1332 } 1428 1333 maybe_accept( node, &OffsetPackExpr::type ); 1429 }1334 ) 1430 1335 1431 1336 VISIT_END( Expr, node ); … … 1438 1343 VISIT_START( node ); 1439 1344 1440 if ( __visit_children() ) { 1441 { 1345 VISIT({ 1442 1346 guard_symtab guard { *this }; 1443 1347 maybe_accept( node, &LogicalExpr::result ); … … 1445 1349 maybe_accept( node, &LogicalExpr::arg1 ); 1446 1350 maybe_accept( node, &LogicalExpr::arg2 ); 1447 }1351 ) 1448 1352 1449 1353 VISIT_END( Expr, node ); … … 1456 1360 VISIT_START( node ); 1457 1361 1458 if ( __visit_children() ) { 1459 { 1362 VISIT({ 1460 1363 guard_symtab guard { *this }; 1461 1364 maybe_accept( node, &ConditionalExpr::result ); … … 1464 1367 maybe_accept( node, &ConditionalExpr::arg2 ); 1465 1368 maybe_accept( node, &ConditionalExpr::arg3 ); 1466 }1369 ) 1467 1370 1468 1371 VISIT_END( Expr, node ); … … 1475 1378 VISIT_START( node ); 1476 1379 1477 if ( __visit_children() ) { 1478 { 1380 VISIT({ 1479 1381 guard_symtab guard { *this }; 1480 1382 maybe_accept( node, &CommaExpr::result ); … … 1482 1384 maybe_accept( node, &CommaExpr::arg1 ); 1483 1385 maybe_accept( node, &CommaExpr::arg2 ); 1484 }1386 ) 1485 1387 1486 1388 VISIT_END( Expr, node ); … … 1493 1395 VISIT_START( node ); 1494 1396 1495 if ( __visit_children() ) { 1496 { 1397 VISIT({ 1497 1398 guard_symtab guard { *this }; 1498 1399 maybe_accept( node, &TypeExpr::result ); 1499 1400 } 1500 1401 maybe_accept( node, &TypeExpr::type ); 1501 }1402 ) 1502 1403 1503 1404 VISIT_END( Expr, node ); … … 1510 1411 VISIT_START( node ); 1511 1412 1512 if ( __visit_children() ) { 1513 { 1413 VISIT({ 1514 1414 guard_symtab guard { *this }; 1515 1415 maybe_accept( node, &AsmExpr::result ); … … 1517 1417 maybe_accept( node, &AsmExpr::constraint ); 1518 1418 maybe_accept( node, &AsmExpr::operand ); 1519 }1419 ) 1520 1420 1521 1421 VISIT_END( Expr, node ); … … 1528 1428 VISIT_START( node ); 1529 1429 1530 if ( __visit_children() ) { 1531 { 1430 VISIT({ 1532 1431 guard_symtab guard { *this }; 1533 1432 maybe_accept( node, &ImplicitCopyCtorExpr::result ); 1534 1433 } 1535 1434 maybe_accept( node, &ImplicitCopyCtorExpr::callExpr ); 1536 }1435 ) 1537 1436 1538 1437 VISIT_END( Expr, node ); … … 1545 1444 VISIT_START( node ); 1546 1445 1547 if ( __visit_children() ) { 1548 { 1446 VISIT({ 1549 1447 guard_symtab guard { *this }; 1550 1448 maybe_accept( node, &ConstructorExpr::result ); 1551 1449 } 1552 1450 maybe_accept( node, &ConstructorExpr::callExpr ); 1553 }1451 ) 1554 1452 1555 1453 VISIT_END( Expr, node ); … … 1562 1460 VISIT_START( node ); 1563 1461 1564 if ( __visit_children() ) { 1565 { 1462 VISIT({ 1566 1463 guard_symtab guard { *this }; 1567 1464 maybe_accept( node, &CompoundLiteralExpr::result ); 1568 1465 } 1569 1466 maybe_accept( node, &CompoundLiteralExpr::init ); 1570 }1467 ) 1571 1468 1572 1469 VISIT_END( Expr, node ); … … 1579 1476 VISIT_START( node ); 1580 1477 1581 if ( __visit_children() ) { 1582 { 1478 VISIT({ 1583 1479 guard_symtab guard { *this }; 1584 1480 maybe_accept( node, &RangeExpr::result ); … … 1586 1482 maybe_accept( node, &RangeExpr::low ); 1587 1483 maybe_accept( node, &RangeExpr::high ); 1588 }1484 ) 1589 1485 1590 1486 VISIT_END( Expr, node ); … … 1597 1493 VISIT_START( node ); 1598 1494 1599 if ( __visit_children() ) { 1600 { 1495 VISIT({ 1601 1496 guard_symtab guard { *this }; 1602 1497 maybe_accept( node, &UntypedTupleExpr::result ); 1603 1498 } 1604 1499 maybe_accept( node, &UntypedTupleExpr::exprs ); 1605 }1500 ) 1606 1501 1607 1502 VISIT_END( Expr, node ); … … 1614 1509 VISIT_START( node ); 1615 1510 1616 if ( __visit_children() ) { 1617 { 1511 VISIT({ 1618 1512 guard_symtab guard { *this }; 1619 1513 maybe_accept( node, &TupleExpr::result ); 1620 1514 } 1621 1515 maybe_accept( node, &TupleExpr::exprs ); 1622 }1516 ) 1623 1517 1624 1518 VISIT_END( Expr, node ); … … 1631 1525 VISIT_START( node ); 1632 1526 1633 if ( __visit_children() ) { 1634 { 1527 VISIT({ 1635 1528 guard_symtab guard { *this }; 1636 1529 maybe_accept( node, &TupleIndexExpr::result ); 1637 1530 } 1638 1531 maybe_accept( node, &TupleIndexExpr::tuple ); 1639 }1532 ) 1640 1533 1641 1534 VISIT_END( Expr, node ); … … 1648 1541 VISIT_START( node ); 1649 1542 1650 if ( __visit_children() ) { 1651 { 1543 VISIT({ 1652 1544 guard_symtab guard { *this }; 1653 1545 maybe_accept( node, &TupleAssignExpr::result ); 1654 1546 } 1655 1547 maybe_accept( node, &TupleAssignExpr::stmtExpr ); 1656 }1548 ) 1657 1549 1658 1550 VISIT_END( Expr, node ); … … 1665 1557 VISIT_START( node ); 1666 1558 1667 if ( __visit_children() ) { 1668 // don't want statements from outer CompoundStmts to be added to this StmtExpr 1559 VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr 1669 1560 // get the stmts that will need to be spliced in 1670 1561 auto stmts_before = __pass::stmtsToAddBefore( core, 0); … … 1683 1574 maybe_accept( node, &StmtExpr::returnDecls ); 1684 1575 maybe_accept( node, &StmtExpr::dtors ); 1685 }1576 ) 1686 1577 1687 1578 VISIT_END( Expr, node ); … … 1694 1585 VISIT_START( node ); 1695 1586 1696 if ( __visit_children() ) { 1697 { 1587 VISIT({ 1698 1588 guard_symtab guard { *this }; 1699 1589 maybe_accept( node, &UniqueExpr::result ); 1700 1590 } 1701 1591 maybe_accept( node, &UniqueExpr::expr ); 1702 }1592 ) 1703 1593 1704 1594 VISIT_END( Expr, node ); … … 1711 1601 VISIT_START( node ); 1712 1602 1713 if ( __visit_children() ) { 1714 { 1603 VISIT({ 1715 1604 guard_symtab guard { *this }; 1716 1605 maybe_accept( node, &UntypedInitExpr::result ); … … 1718 1607 maybe_accept( node, &UntypedInitExpr::expr ); 1719 1608 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. 1720 }1609 ) 1721 1610 1722 1611 VISIT_END( Expr, node ); … … 1729 1618 VISIT_START( node ); 1730 1619 1731 if ( __visit_children() ) { 1732 { 1620 VISIT({ 1733 1621 guard_symtab guard { *this }; 1734 1622 maybe_accept( node, &InitExpr::result ); … … 1736 1624 maybe_accept( node, &InitExpr::expr ); 1737 1625 maybe_accept( node, &InitExpr::designation ); 1738 }1626 ) 1739 1627 1740 1628 VISIT_END( Expr, node ); … … 1747 1635 VISIT_START( node ); 1748 1636 1749 if ( __visit_children() ) { 1750 { 1637 VISIT({ 1751 1638 guard_symtab guard { *this }; 1752 1639 maybe_accept( node, &DeletedExpr::result ); … … 1754 1641 maybe_accept( node, &DeletedExpr::expr ); 1755 1642 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. 1756 }1643 ) 1757 1644 1758 1645 VISIT_END( Expr, node ); … … 1765 1652 VISIT_START( node ); 1766 1653 1767 if ( __visit_children() ) { 1768 { 1654 VISIT({ 1769 1655 guard_symtab guard { *this }; 1770 1656 maybe_accept( node, &DefaultArgExpr::result ); 1771 1657 } 1772 1658 maybe_accept( node, &DefaultArgExpr::expr ); 1773 }1659 ) 1774 1660 1775 1661 VISIT_END( Expr, node ); … … 1782 1668 VISIT_START( node ); 1783 1669 1784 if ( __visit_children() ) { 1785 { 1670 VISIT({ 1786 1671 guard_symtab guard { *this }; 1787 1672 maybe_accept( node, &GenericExpr::result ); … … 1812 1697 node = n; 1813 1698 } 1814 }1699 ) 1815 1700 1816 1701 VISIT_END( Expr, node ); … … 1841 1726 VISIT_START( node ); 1842 1727 1843 if ( __visit_children() ) {1728 VISIT( 1844 1729 // xxx - should PointerType visit/mutate dimension? 1845 1730 maybe_accept( node, &PointerType::base ); 1846 }1731 ) 1847 1732 1848 1733 VISIT_END( Type, node ); … … 1855 1740 VISIT_START( node ); 1856 1741 1857 if ( __visit_children() ) {1742 VISIT( 1858 1743 maybe_accept( node, &ArrayType::dimension ); 1859 1744 maybe_accept( node, &ArrayType::base ); 1860 }1745 ) 1861 1746 1862 1747 VISIT_END( Type, node ); … … 1869 1754 VISIT_START( node ); 1870 1755 1871 if ( __visit_children() ) {1756 VISIT( 1872 1757 maybe_accept( node, &ReferenceType::base ); 1873 }1758 ) 1874 1759 1875 1760 VISIT_END( Type, node ); … … 1882 1767 VISIT_START( node ); 1883 1768 1884 if ( __visit_children() ) {1769 VISIT( 1885 1770 maybe_accept( node, &QualifiedType::parent ); 1886 1771 maybe_accept( node, &QualifiedType::child ); 1887 }1772 ) 1888 1773 1889 1774 VISIT_END( Type, node ); … … 1896 1781 VISIT_START( node ); 1897 1782 1898 if ( __visit_children() ){1783 VISIT({ 1899 1784 // guard_forall_subs forall_guard { *this, node }; 1900 1785 // mutate_forall( node ); … … 1902 1787 maybe_accept( node, &FunctionType::returns ); 1903 1788 maybe_accept( node, &FunctionType::params ); 1904 } 1789 }) 1905 1790 1906 1791 VISIT_END( Type, node ); … … 1915 1800 __pass::symtab::addStruct( core, 0, node->name ); 1916 1801 1917 if ( __visit_children() ){1802 VISIT({ 1918 1803 guard_symtab guard { *this }; 1919 1804 maybe_accept( node, &StructInstType::params ); 1920 } 1805 }) 1921 1806 1922 1807 VISIT_END( Type, node ); … … 1931 1816 __pass::symtab::addUnion( core, 0, node->name ); 1932 1817 1933 if ( __visit_children() ){1818 VISIT({ 1934 1819 guard_symtab guard { *this }; 1935 1820 maybe_accept( node, &UnionInstType::params ); 1936 } 1821 }) 1937 1822 1938 1823 VISIT_END( Type, node ); … … 1945 1830 VISIT_START( node ); 1946 1831 1947 if ( __visit_children() ){1832 VISIT({ 1948 1833 maybe_accept( node, &EnumInstType::params ); 1949 } 1834 }) 1950 1835 1951 1836 VISIT_END( Type, node ); … … 1958 1843 VISIT_START( node ); 1959 1844 1960 if ( __visit_children() ){1845 VISIT({ 1961 1846 maybe_accept( node, &TraitInstType::params ); 1962 } 1847 }) 1963 1848 1964 1849 VISIT_END( Type, node ); … … 1971 1856 VISIT_START( node ); 1972 1857 1973 if ( __visit_children() ) {1858 VISIT( 1974 1859 { 1975 1860 maybe_accept( node, &TypeInstType::params ); … … 1977 1862 // ensure that base re-bound if doing substitution 1978 1863 __pass::forall::replace( core, 0, node ); 1979 }1864 ) 1980 1865 1981 1866 VISIT_END( Type, node ); … … 1988 1873 VISIT_START( node ); 1989 1874 1990 if ( __visit_children() ) {1875 VISIT( 1991 1876 maybe_accept( node, &TupleType::types ); 1992 1877 maybe_accept( node, &TupleType::members ); 1993 }1878 ) 1994 1879 1995 1880 VISIT_END( Type, node ); … … 2002 1887 VISIT_START( node ); 2003 1888 2004 if ( __visit_children() ) {1889 VISIT( 2005 1890 maybe_accept( node, &TypeofType::expr ); 2006 }1891 ) 2007 1892 2008 1893 VISIT_END( Type, node ); … … 2015 1900 VISIT_START( node ); 2016 1901 2017 if ( __visit_children() ) {1902 VISIT( 2018 1903 maybe_accept( node, &VTableType::base ); 2019 }1904 ) 2020 1905 2021 1906 VISIT_END( Type, node ); … … 2065 1950 VISIT_START( node ); 2066 1951 2067 if ( __visit_children() ) { 2068 maybe_accept( node, &Designation::designators ); 2069 } 1952 VISIT( maybe_accept( node, &Designation::designators ); ) 2070 1953 2071 1954 VISIT_END( Designation, node ); … … 2078 1961 VISIT_START( node ); 2079 1962 2080 if ( __visit_children() ) {1963 VISIT( 2081 1964 maybe_accept( node, &SingleInit::value ); 2082 }1965 ) 2083 1966 2084 1967 VISIT_END( Init, node ); … … 2091 1974 VISIT_START( node ); 2092 1975 2093 if ( __visit_children() ) {1976 VISIT( 2094 1977 maybe_accept( node, &ListInit::designations ); 2095 1978 maybe_accept( node, &ListInit::initializers ); 2096 }1979 ) 2097 1980 2098 1981 VISIT_END( Init, node ); … … 2105 1988 VISIT_START( node ); 2106 1989 2107 if ( __visit_children() ) {1990 VISIT( 2108 1991 maybe_accept( node, &ConstructorInit::ctor ); 2109 1992 maybe_accept( node, &ConstructorInit::dtor ); 2110 1993 maybe_accept( node, &ConstructorInit::init ); 2111 }1994 ) 2112 1995 2113 1996 VISIT_END( Init, node ); … … 2120 2003 VISIT_START( node ); 2121 2004 2122 if ( __visit_children() ) {2005 VISIT( 2123 2006 maybe_accept( node, &Attribute::params ); 2124 }2007 ) 2125 2008 2126 2009 VISIT_END( Attribute, node ); … … 2133 2016 VISIT_START( node ); 2134 2017 2135 if ( __visit_children() ) {2018 VISIT( 2136 2019 { 2137 2020 bool mutated = false; … … 2149 2032 } 2150 2033 } 2151 }2034 ) 2152 2035 2153 2036 VISIT_END( TypeSubstitution, node ); … … 2155 2038 2156 2039 #undef VISIT_START 2040 #undef VISIT 2157 2041 #undef VISIT_END
Note:
See TracChangeset
for help on using the changeset viewer.