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