- Timestamp:
- Feb 4, 2022, 10:10:34 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- f8143a6
- Parents:
- 5f3ba11 (diff), 67e86ae6 (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/AST
- Files:
-
- 11 edited
-
Convert.cpp (modified) (7 diffs)
-
Copy.hpp (modified) (2 diffs)
-
Fwd.hpp (modified) (2 diffs)
-
Node.cpp (modified) (2 diffs)
-
Node.hpp (modified) (1 diff)
-
Pass.hpp (modified) (1 diff)
-
Pass.impl.hpp (modified) (118 diffs)
-
Print.cpp (modified) (2 diffs)
-
Stmt.cpp (modified) (2 diffs)
-
Stmt.hpp (modified) (9 diffs)
-
Visitor.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r5f3ba11 rb56ad5e 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Jul 14 16:15:00 202113 // Update Count : 3711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 13:19:22 2022 13 // Update Count : 41 14 14 // 15 15 … … 393 393 auto stmt = new IfStmt( 394 394 get<Expression>().accept1( node->cond ), 395 get<Statement>().accept1( node->then Part),396 get<Statement>().accept1( node->else Part),395 get<Statement>().accept1( node->then ), 396 get<Statement>().accept1( node->else_ ), 397 397 get<Statement>().acceptL( node->inits ) 398 398 ); … … 419 419 } 420 420 421 const ast::Stmt * visit( const ast::While Stmt * node ) override final {421 const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { 422 422 if ( inCache( node ) ) return nullptr; 423 423 auto inits = get<Statement>().acceptL( node->inits ); 424 auto stmt = new While Stmt(424 auto stmt = new WhileDoStmt( 425 425 get<Expression>().accept1( node->cond ), 426 426 get<Statement>().accept1( node->body ), 427 get<Statement>().accept1( node->else_ ), 427 428 inits, 428 429 node->isDoWhile … … 437 438 get<Expression>().accept1( node->cond ), 438 439 get<Expression>().accept1( node->inc ), 439 get<Statement>().accept1( node->body ) 440 get<Statement>().accept1( node->body ), 441 get<Statement>().accept1( node->else_ ) 440 442 ); 441 443 return stmtPostamble( stmt, node ); … … 1872 1874 old->location, 1873 1875 GET_ACCEPT_1(condition, Expr), 1874 GET_ACCEPT_1(then Part, Stmt),1875 GET_ACCEPT_1(else Part, Stmt),1876 GET_ACCEPT_1(then, Stmt), 1877 GET_ACCEPT_1(else_, Stmt), 1876 1878 GET_ACCEPT_V(initialization, Stmt), 1877 1879 GET_LABELS_V(old->labels) … … 1902 1904 } 1903 1905 1904 virtual void visit( const While Stmt * old ) override final {1906 virtual void visit( const WhileDoStmt * old ) override final { 1905 1907 if ( inCache( old ) ) return; 1906 this->node = new ast::While Stmt(1908 this->node = new ast::WhileDoStmt( 1907 1909 old->location, 1908 1910 GET_ACCEPT_1(condition, Expr), 1909 1911 GET_ACCEPT_1(body, Stmt), 1912 GET_ACCEPT_1(else_, Stmt), 1910 1913 GET_ACCEPT_V(initialization, Stmt), 1911 1914 old->isDoWhile, … … 1923 1926 GET_ACCEPT_1(increment, Expr), 1924 1927 GET_ACCEPT_1(body, Stmt), 1928 GET_ACCEPT_1(else_, Stmt), 1925 1929 GET_LABELS_V(old->labels) 1926 1930 ); -
src/AST/Copy.hpp
r5f3ba11 rb56ad5e 10 10 // Created On : Wed Jul 10 16:13:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Nov 11 9:22:00 202113 // Update Count : 212 // Last Modified On : Wed Dec 15 11:07:00 2021 13 // Update Count : 3 14 14 // 15 15 … … 52 52 Node * deepCopy<Node>( const Node * localRoot ); 53 53 54 template<typename node_t, enum Node::ref_type ref_t> 55 node_t * shallowCopy( const ptr_base<node_t, ref_t> & localRoot ) { 56 return shallowCopy( localRoot.get() ); 57 } 58 59 template<typename node_t, enum Node::ref_type ref_t> 60 node_t * deepCopy( const ptr_base<node_t, ref_t> & localRoot ) { 61 return deepCopy( localRoot.get() ); 62 } 63 54 64 } 55 65 -
src/AST/Fwd.hpp
r5f3ba11 rb56ad5e 10 10 // Created On : Wed May 8 16:05:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:37:39 202113 // Update Count : 412 // Last Modified On : Tue Feb 1 09:08:33 2022 13 // Update Count : 5 14 14 // 15 15 … … 44 44 class DirectiveStmt; 45 45 class IfStmt; 46 class While Stmt;46 class WhileDoStmt; 47 47 class ForStmt; 48 48 class SwitchStmt; -
src/AST/Node.cpp
r5f3ba11 rb56ad5e 10 10 // Created On : Thu May 16 14:16:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:25:06 202113 // Update Count : 212 // Last Modified On : Tue Feb 1 09:09:39 2022 13 // Update Count : 3 14 14 // 15 15 … … 146 146 template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::weak >; 147 147 template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::strong >; 148 template class ast::ptr_base< ast::While Stmt, ast::Node::ref_type::weak >;149 template class ast::ptr_base< ast::While Stmt, ast::Node::ref_type::strong >;148 template class ast::ptr_base< ast::WhileDoStmt, ast::Node::ref_type::weak >; 149 template class ast::ptr_base< ast::WhileDoStmt, ast::Node::ref_type::strong >; 150 150 template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::weak >; 151 151 template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::strong >; -
src/AST/Node.hpp
r5f3ba11 rb56ad5e 188 188 } 189 189 190 ptr_base & operator=( const node_t * node ) { 191 assign( node ); 192 return *this; 193 } 194 190 195 template<typename o_node_t> 191 196 ptr_base & operator=( const o_node_t * node ) { -
src/AST/Pass.hpp
r5f3ba11 rb56ad5e 146 146 const ast::Stmt * visit( const ast::DirectiveStmt * ) override final; 147 147 const ast::Stmt * visit( const ast::IfStmt * ) override final; 148 const ast::Stmt * visit( const ast::While Stmt* ) override final;148 const ast::Stmt * visit( const ast::WhileDoStmt * ) override final; 149 149 const ast::Stmt * visit( const ast::ForStmt * ) override final; 150 150 const ast::Stmt * visit( const ast::SwitchStmt * ) override final; -
src/AST/Pass.impl.hpp
r5f3ba11 rb56ad5e 33 33 /* call the implementation of the previsit of this pass */ \ 34 34 __pass::previsit( core, node, 0 ); 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 35 43 36 #define VISIT_END( type, node ) \ … … 452 445 VISIT_START( node ); 453 446 454 VISIT(447 if ( __visit_children() ) { 455 448 { 456 449 guard_symtab guard { *this }; … … 460 453 maybe_accept( node, &ObjectDecl::bitfieldWidth ); 461 454 maybe_accept( node, &ObjectDecl::attributes ); 462 )455 } 463 456 464 457 __pass::symtab::addId( core, 0, node ); … … 475 468 __pass::symtab::addId( core, 0, node ); 476 469 477 VISIT(maybe_accept( node, &FunctionDecl::withExprs );) 470 if ( __visit_children() ) { 471 maybe_accept( node, &FunctionDecl::withExprs ); 472 } 478 473 { 479 474 // with clause introduces a level of scope (for the with expression members). … … 493 488 } }; 494 489 __pass::symtab::addId( core, 0, func ); 495 VISIT(490 if ( __visit_children() ) { 496 491 // parameter declarations 497 492 maybe_accept( node, &FunctionDecl::params ); … … 509 504 maybe_accept( node, &FunctionDecl::stmts ); 510 505 maybe_accept( node, &FunctionDecl::attributes ); 511 )506 } 512 507 } 513 508 } … … 526 521 __pass::symtab::addStructFwd( core, 0, node ); 527 522 528 VISIT({523 if ( __visit_children() ) { 529 524 guard_symtab guard { * this }; 530 525 maybe_accept( node, &StructDecl::params ); 531 526 maybe_accept( node, &StructDecl::members ); 532 527 maybe_accept( node, &StructDecl::attributes ); 533 } )528 } 534 529 535 530 // this addition replaces the forward declaration … … 548 543 __pass::symtab::addUnionFwd( core, 0, node ); 549 544 550 VISIT({545 if ( __visit_children() ) { 551 546 guard_symtab guard { * this }; 552 547 maybe_accept( node, &UnionDecl::params ); 553 548 maybe_accept( node, &UnionDecl::members ); 554 549 maybe_accept( node, &UnionDecl::attributes ); 555 } )550 } 556 551 557 552 __pass::symtab::addUnion( core, 0, node ); … … 568 563 __pass::symtab::addEnum( core, 0, node ); 569 564 570 VISIT(565 if ( __visit_children() ) { 571 566 // unlike structs, traits, and unions, enums inject their members into the global scope 572 567 maybe_accept( node, &EnumDecl::params ); 573 568 maybe_accept( node, &EnumDecl::members ); 574 569 maybe_accept( node, &EnumDecl::attributes ); 575 )570 } 576 571 577 572 VISIT_END( Decl, node ); … … 584 579 VISIT_START( node ); 585 580 586 VISIT({581 if ( __visit_children() ) { 587 582 guard_symtab guard { *this }; 588 583 maybe_accept( node, &TraitDecl::params ); 589 584 maybe_accept( node, &TraitDecl::members ); 590 585 maybe_accept( node, &TraitDecl::attributes ); 591 } )586 } 592 587 593 588 __pass::symtab::addTrait( core, 0, node ); … … 602 597 VISIT_START( node ); 603 598 604 VISIT({599 if ( __visit_children() ) { 605 600 guard_symtab guard { *this }; 606 601 maybe_accept( node, &TypeDecl::base ); 607 } )602 } 608 603 609 604 // see A NOTE ON THE ORDER OF TRAVERSAL, above … … 612 607 __pass::symtab::addType( core, 0, node ); 613 608 614 VISIT(609 if ( __visit_children() ) { 615 610 maybe_accept( node, &TypeDecl::assertions ); 616 611 … … 619 614 maybe_accept( node, &TypeDecl::init ); 620 615 } 621 )616 } 622 617 623 618 VISIT_END( Decl, node ); … … 630 625 VISIT_START( node ); 631 626 632 VISIT({627 if ( __visit_children() ) { 633 628 guard_symtab guard { *this }; 634 629 maybe_accept( node, &TypedefDecl::base ); 635 } )630 } 636 631 637 632 __pass::symtab::addType( core, 0, node ); 638 633 639 VISIT( maybe_accept( node, &TypedefDecl::assertions ); ) 634 if ( __visit_children() ) { 635 maybe_accept( node, &TypedefDecl::assertions ); 636 } 640 637 641 638 VISIT_END( Decl, node ); … … 648 645 VISIT_START( node ); 649 646 650 VISIT(647 if ( __visit_children() ) { 651 648 maybe_accept( node, &AsmDecl::stmt ); 652 )649 } 653 650 654 651 VISIT_END( AsmDecl, node ); … … 661 658 VISIT_START( node ); 662 659 663 VISIT(660 if ( __visit_children() ) { 664 661 maybe_accept( node, &DirectiveDecl::stmt ); 665 )662 } 666 663 667 664 VISIT_END( DirectiveDecl, node ); … … 674 671 VISIT_START( node ); 675 672 676 VISIT(673 if ( __visit_children() ) { 677 674 maybe_accept( node, &StaticAssertDecl::cond ); 678 675 maybe_accept( node, &StaticAssertDecl::msg ); 679 )676 } 680 677 681 678 VISIT_END( StaticAssertDecl, node ); … … 687 684 const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) { 688 685 VISIT_START( node ); 689 VISIT( 686 687 if ( __visit_children() ) { 690 688 // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result. 691 689 auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() { … … 704 702 guard_scope guard3 { *this }; 705 703 maybe_accept( node, &CompoundStmt::kids ); 706 ) 704 } 705 707 706 VISIT_END( CompoundStmt, node ); 708 707 } … … 714 713 VISIT_START( node ); 715 714 716 VISIT(715 if ( __visit_children() ) { 717 716 maybe_accept( node, &ExprStmt::expr ); 718 )717 } 719 718 720 719 VISIT_END( Stmt, node ); … … 727 726 VISIT_START( node ) 728 727 729 VISIT(728 if ( __visit_children() ) { 730 729 maybe_accept( node, &AsmStmt::instruction ); 731 730 maybe_accept( node, &AsmStmt::output ); 732 731 maybe_accept( node, &AsmStmt::input ); 733 732 maybe_accept( node, &AsmStmt::clobber ); 734 )733 } 735 734 736 735 VISIT_END( Stmt, node ); … … 752 751 VISIT_START( node ); 753 752 754 VISIT({753 if ( __visit_children() ) { 755 754 // if statements introduce a level of scope (for the initialization) 756 755 guard_symtab guard { *this }; 757 756 maybe_accept( node, &IfStmt::inits ); 758 757 maybe_accept( node, &IfStmt::cond ); 759 maybe_accept_as_compound( node, &IfStmt::then Part);760 maybe_accept_as_compound( node, &IfStmt::else Part);761 } )758 maybe_accept_as_compound( node, &IfStmt::then ); 759 maybe_accept_as_compound( node, &IfStmt::else_ ); 760 } 762 761 763 762 VISIT_END( Stmt, node ); … … 765 764 766 765 //-------------------------------------------------------------------------- 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({766 // WhileDoStmt 767 template< typename core_t > 768 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileDoStmt * node ) { 769 VISIT_START( node ); 770 771 if ( __visit_children() ) { 773 772 // while statements introduce a level of scope (for the initialization) 774 773 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 } )774 maybe_accept( node, &WhileDoStmt::inits ); 775 maybe_accept( node, &WhileDoStmt::cond ); 776 maybe_accept_as_compound( node, &WhileDoStmt::body ); 777 } 779 778 780 779 VISIT_END( Stmt, node ); … … 787 786 VISIT_START( node ); 788 787 789 VISIT({788 if ( __visit_children() ) { 790 789 // for statements introduce a level of scope (for the initialization) 791 790 guard_symtab guard { *this }; … … 795 794 maybe_accept( node, &ForStmt::inc ); 796 795 maybe_accept_as_compound( node, &ForStmt::body ); 797 } )796 } 798 797 799 798 VISIT_END( Stmt, node ); … … 806 805 VISIT_START( node ); 807 806 808 VISIT(807 if ( __visit_children() ) { 809 808 maybe_accept( node, &SwitchStmt::cond ); 810 809 maybe_accept( node, &SwitchStmt::stmts ); 811 )810 } 812 811 813 812 VISIT_END( Stmt, node ); … … 820 819 VISIT_START( node ); 821 820 822 VISIT(821 if ( __visit_children() ) { 823 822 maybe_accept( node, &CaseStmt::cond ); 824 823 maybe_accept( node, &CaseStmt::stmts ); 825 )824 } 826 825 827 826 VISIT_END( Stmt, node ); … … 842 841 VISIT_START( node ); 843 842 844 VISIT(843 if ( __visit_children() ) { 845 844 maybe_accept( node, &ReturnStmt::expr ); 846 )845 } 847 846 848 847 VISIT_END( Stmt, node ); … … 855 854 VISIT_START( node ); 856 855 857 VISIT(856 if ( __visit_children() ) { 858 857 maybe_accept( node, &ThrowStmt::expr ); 859 858 maybe_accept( node, &ThrowStmt::target ); 860 )859 } 861 860 862 861 VISIT_END( Stmt, node ); … … 869 868 VISIT_START( node ); 870 869 871 VISIT(870 if ( __visit_children() ) { 872 871 maybe_accept( node, &TryStmt::body ); 873 872 maybe_accept( node, &TryStmt::handlers ); 874 873 maybe_accept( node, &TryStmt::finally ); 875 )874 } 876 875 877 876 VISIT_END( Stmt, node ); … … 884 883 VISIT_START( node ); 885 884 886 VISIT({885 if ( __visit_children() ) { 887 886 // catch statements introduce a level of scope (for the caught exception) 888 887 guard_symtab guard { *this }; … … 890 889 maybe_accept( node, &CatchStmt::cond ); 891 890 maybe_accept_as_compound( node, &CatchStmt::body ); 892 } )891 } 893 892 894 893 VISIT_END( Stmt, node ); … … 901 900 VISIT_START( node ); 902 901 903 VISIT(902 if ( __visit_children() ) { 904 903 maybe_accept( node, &FinallyStmt::body ); 905 )904 } 906 905 907 906 VISIT_END( Stmt, node ); … … 914 913 VISIT_START( node ); 915 914 916 VISIT(915 if ( __visit_children() ) { 917 916 maybe_accept( node, &SuspendStmt::then ); 918 )917 } 919 918 920 919 VISIT_END( Stmt, node ); … … 934 933 // } 935 934 936 VISIT({935 if ( __visit_children() ) { 937 936 std::vector<WaitForStmt::Clause> new_clauses; 938 937 new_clauses.reserve( node->clauses.size() ); … … 965 964 node = n; 966 965 } 967 } )966 } 968 967 969 968 #define maybe_accept(field) \ … … 977 976 } 978 977 979 VISIT(978 if ( __visit_children() ) { 980 979 maybe_accept( timeout.time ); 981 980 maybe_accept( timeout.stmt ); … … 983 982 maybe_accept( orElse.stmt ); 984 983 maybe_accept( orElse.cond ); 985 )984 } 986 985 987 986 #undef maybe_accept … … 996 995 VISIT_START( node ); 997 996 998 VISIT(997 if ( __visit_children() ) { 999 998 maybe_accept( node, &WithStmt::exprs ); 1000 999 { … … 1004 1003 maybe_accept( node, &WithStmt::stmt ); 1005 1004 } 1006 ) 1005 } 1006 1007 1007 VISIT_END( Stmt, node ); 1008 1008 } … … 1022 1022 VISIT_START( node ); 1023 1023 1024 VISIT(1024 if ( __visit_children() ) { 1025 1025 maybe_accept( node, &DeclStmt::decl ); 1026 )1026 } 1027 1027 1028 1028 VISIT_END( Stmt, node ); … … 1037 1037 // For now this isn't visited, it is unclear if this causes problem 1038 1038 // if all tests are known to pass, remove this code 1039 VISIT(1039 if ( __visit_children() ) { 1040 1040 maybe_accept( node, &ImplicitCtorDtorStmt::callStmt ); 1041 )1041 } 1042 1042 1043 1043 VISIT_END( Stmt, node ); … … 1050 1050 VISIT_START( node ); 1051 1051 1052 VISIT({1052 if ( __visit_children() ) { 1053 1053 // mutex statements introduce a level of scope (for the initialization) 1054 1054 guard_symtab guard { *this }; 1055 1055 maybe_accept( node, &MutexStmt::stmt ); 1056 1056 maybe_accept( node, &MutexStmt::mutexObjs ); 1057 } )1057 } 1058 1058 1059 1059 VISIT_END( Stmt, node ); … … 1066 1066 VISIT_START( node ); 1067 1067 1068 VISIT(1068 if ( __visit_children() ) { 1069 1069 { 1070 1070 guard_symtab guard { *this }; … … 1073 1073 maybe_accept( node, &ApplicationExpr::func ); 1074 1074 maybe_accept( node, &ApplicationExpr::args ); 1075 )1075 } 1076 1076 1077 1077 VISIT_END( Expr, node ); … … 1084 1084 VISIT_START( node ); 1085 1085 1086 VISIT(1086 if ( __visit_children() ) { 1087 1087 { 1088 1088 guard_symtab guard { *this }; … … 1091 1091 1092 1092 maybe_accept( node, &UntypedExpr::args ); 1093 )1093 } 1094 1094 1095 1095 VISIT_END( Expr, node ); … … 1102 1102 VISIT_START( node ); 1103 1103 1104 VISIT({1104 if ( __visit_children() ) { 1105 1105 guard_symtab guard { *this }; 1106 1106 maybe_accept( node, &NameExpr::result ); 1107 } )1107 } 1108 1108 1109 1109 VISIT_END( Expr, node ); … … 1116 1116 VISIT_START( node ); 1117 1117 1118 VISIT({ 1118 if ( __visit_children() ) { 1119 { 1119 1120 guard_symtab guard { *this }; 1120 1121 maybe_accept( node, &CastExpr::result ); 1121 1122 } 1122 1123 maybe_accept( node, &CastExpr::arg ); 1123 )1124 } 1124 1125 1125 1126 VISIT_END( Expr, node ); … … 1132 1133 VISIT_START( node ); 1133 1134 1134 VISIT({ 1135 if ( __visit_children() ) { 1136 { 1135 1137 guard_symtab guard { *this }; 1136 1138 maybe_accept( node, &KeywordCastExpr::result ); 1137 1139 } 1138 1140 maybe_accept( node, &KeywordCastExpr::arg ); 1139 )1141 } 1140 1142 1141 1143 VISIT_END( Expr, node ); … … 1148 1150 VISIT_START( node ); 1149 1151 1150 VISIT({ 1152 if ( __visit_children() ) { 1153 { 1151 1154 guard_symtab guard { *this }; 1152 1155 maybe_accept( node, &VirtualCastExpr::result ); 1153 1156 } 1154 1157 maybe_accept( node, &VirtualCastExpr::arg ); 1155 )1158 } 1156 1159 1157 1160 VISIT_END( Expr, node ); … … 1164 1167 VISIT_START( node ); 1165 1168 1166 VISIT({ 1169 if ( __visit_children() ) { 1170 { 1167 1171 guard_symtab guard { *this }; 1168 1172 maybe_accept( node, &AddressExpr::result ); 1169 1173 } 1170 1174 maybe_accept( node, &AddressExpr::arg ); 1171 )1175 } 1172 1176 1173 1177 VISIT_END( Expr, node ); … … 1180 1184 VISIT_START( node ); 1181 1185 1182 VISIT({1186 if ( __visit_children() ) { 1183 1187 guard_symtab guard { *this }; 1184 1188 maybe_accept( node, &LabelAddressExpr::result ); 1185 } )1189 } 1186 1190 1187 1191 VISIT_END( Expr, node ); … … 1194 1198 VISIT_START( node ); 1195 1199 1196 VISIT({ 1200 if ( __visit_children() ) { 1201 { 1197 1202 guard_symtab guard { *this }; 1198 1203 maybe_accept( node, &UntypedMemberExpr::result ); … … 1200 1205 maybe_accept( node, &UntypedMemberExpr::aggregate ); 1201 1206 maybe_accept( node, &UntypedMemberExpr::member ); 1202 )1207 } 1203 1208 1204 1209 VISIT_END( Expr, node ); … … 1211 1216 VISIT_START( node ); 1212 1217 1213 VISIT({ 1218 if ( __visit_children() ) { 1219 { 1214 1220 guard_symtab guard { *this }; 1215 1221 maybe_accept( node, &MemberExpr::result ); 1216 1222 } 1217 1223 maybe_accept( node, &MemberExpr::aggregate ); 1218 )1224 } 1219 1225 1220 1226 VISIT_END( Expr, node ); … … 1227 1233 VISIT_START( node ); 1228 1234 1229 VISIT({1235 if ( __visit_children() ) { 1230 1236 guard_symtab guard { *this }; 1231 1237 maybe_accept( node, &VariableExpr::result ); 1232 } )1238 } 1233 1239 1234 1240 VISIT_END( Expr, node ); … … 1241 1247 VISIT_START( node ); 1242 1248 1243 VISIT({1249 if ( __visit_children() ) { 1244 1250 guard_symtab guard { *this }; 1245 1251 maybe_accept( node, &ConstantExpr::result ); 1246 } )1252 } 1247 1253 1248 1254 VISIT_END( Expr, node ); … … 1255 1261 VISIT_START( node ); 1256 1262 1257 VISIT({ 1263 if ( __visit_children() ) { 1264 { 1258 1265 guard_symtab guard { *this }; 1259 1266 maybe_accept( node, &SizeofExpr::result ); … … 1264 1271 maybe_accept( node, &SizeofExpr::expr ); 1265 1272 } 1266 )1273 } 1267 1274 1268 1275 VISIT_END( Expr, node ); … … 1275 1282 VISIT_START( node ); 1276 1283 1277 VISIT({ 1284 if ( __visit_children() ) { 1285 { 1278 1286 guard_symtab guard { *this }; 1279 1287 maybe_accept( node, &AlignofExpr::result ); … … 1284 1292 maybe_accept( node, &AlignofExpr::expr ); 1285 1293 } 1286 )1294 } 1287 1295 1288 1296 VISIT_END( Expr, node ); … … 1295 1303 VISIT_START( node ); 1296 1304 1297 VISIT({ 1305 if ( __visit_children() ) { 1306 { 1298 1307 guard_symtab guard { *this }; 1299 1308 maybe_accept( node, &UntypedOffsetofExpr::result ); 1300 1309 } 1301 1310 maybe_accept( node, &UntypedOffsetofExpr::type ); 1302 )1311 } 1303 1312 1304 1313 VISIT_END( Expr, node ); … … 1311 1320 VISIT_START( node ); 1312 1321 1313 VISIT({ 1322 if ( __visit_children() ) { 1323 { 1314 1324 guard_symtab guard { *this }; 1315 1325 maybe_accept( node, &OffsetofExpr::result ); 1316 1326 } 1317 1327 maybe_accept( node, &OffsetofExpr::type ); 1318 )1328 } 1319 1329 1320 1330 VISIT_END( Expr, node ); … … 1327 1337 VISIT_START( node ); 1328 1338 1329 VISIT({ 1339 if ( __visit_children() ) { 1340 { 1330 1341 guard_symtab guard { *this }; 1331 1342 maybe_accept( node, &OffsetPackExpr::result ); 1332 1343 } 1333 1344 maybe_accept( node, &OffsetPackExpr::type ); 1334 )1345 } 1335 1346 1336 1347 VISIT_END( Expr, node ); … … 1343 1354 VISIT_START( node ); 1344 1355 1345 VISIT({ 1356 if ( __visit_children() ) { 1357 { 1346 1358 guard_symtab guard { *this }; 1347 1359 maybe_accept( node, &LogicalExpr::result ); … … 1349 1361 maybe_accept( node, &LogicalExpr::arg1 ); 1350 1362 maybe_accept( node, &LogicalExpr::arg2 ); 1351 )1363 } 1352 1364 1353 1365 VISIT_END( Expr, node ); … … 1360 1372 VISIT_START( node ); 1361 1373 1362 VISIT({ 1374 if ( __visit_children() ) { 1375 { 1363 1376 guard_symtab guard { *this }; 1364 1377 maybe_accept( node, &ConditionalExpr::result ); … … 1367 1380 maybe_accept( node, &ConditionalExpr::arg2 ); 1368 1381 maybe_accept( node, &ConditionalExpr::arg3 ); 1369 )1382 } 1370 1383 1371 1384 VISIT_END( Expr, node ); … … 1378 1391 VISIT_START( node ); 1379 1392 1380 VISIT({ 1393 if ( __visit_children() ) { 1394 { 1381 1395 guard_symtab guard { *this }; 1382 1396 maybe_accept( node, &CommaExpr::result ); … … 1384 1398 maybe_accept( node, &CommaExpr::arg1 ); 1385 1399 maybe_accept( node, &CommaExpr::arg2 ); 1386 )1400 } 1387 1401 1388 1402 VISIT_END( Expr, node ); … … 1395 1409 VISIT_START( node ); 1396 1410 1397 VISIT({ 1411 if ( __visit_children() ) { 1412 { 1398 1413 guard_symtab guard { *this }; 1399 1414 maybe_accept( node, &TypeExpr::result ); 1400 1415 } 1401 1416 maybe_accept( node, &TypeExpr::type ); 1402 )1417 } 1403 1418 1404 1419 VISIT_END( Expr, node ); … … 1411 1426 VISIT_START( node ); 1412 1427 1413 VISIT({ 1428 if ( __visit_children() ) { 1429 { 1414 1430 guard_symtab guard { *this }; 1415 1431 maybe_accept( node, &AsmExpr::result ); … … 1417 1433 maybe_accept( node, &AsmExpr::constraint ); 1418 1434 maybe_accept( node, &AsmExpr::operand ); 1419 )1435 } 1420 1436 1421 1437 VISIT_END( Expr, node ); … … 1428 1444 VISIT_START( node ); 1429 1445 1430 VISIT({ 1446 if ( __visit_children() ) { 1447 { 1431 1448 guard_symtab guard { *this }; 1432 1449 maybe_accept( node, &ImplicitCopyCtorExpr::result ); 1433 1450 } 1434 1451 maybe_accept( node, &ImplicitCopyCtorExpr::callExpr ); 1435 )1452 } 1436 1453 1437 1454 VISIT_END( Expr, node ); … … 1444 1461 VISIT_START( node ); 1445 1462 1446 VISIT({ 1463 if ( __visit_children() ) { 1464 { 1447 1465 guard_symtab guard { *this }; 1448 1466 maybe_accept( node, &ConstructorExpr::result ); 1449 1467 } 1450 1468 maybe_accept( node, &ConstructorExpr::callExpr ); 1451 )1469 } 1452 1470 1453 1471 VISIT_END( Expr, node ); … … 1460 1478 VISIT_START( node ); 1461 1479 1462 VISIT({ 1480 if ( __visit_children() ) { 1481 { 1463 1482 guard_symtab guard { *this }; 1464 1483 maybe_accept( node, &CompoundLiteralExpr::result ); 1465 1484 } 1466 1485 maybe_accept( node, &CompoundLiteralExpr::init ); 1467 )1486 } 1468 1487 1469 1488 VISIT_END( Expr, node ); … … 1476 1495 VISIT_START( node ); 1477 1496 1478 VISIT({ 1497 if ( __visit_children() ) { 1498 { 1479 1499 guard_symtab guard { *this }; 1480 1500 maybe_accept( node, &RangeExpr::result ); … … 1482 1502 maybe_accept( node, &RangeExpr::low ); 1483 1503 maybe_accept( node, &RangeExpr::high ); 1484 )1504 } 1485 1505 1486 1506 VISIT_END( Expr, node ); … … 1493 1513 VISIT_START( node ); 1494 1514 1495 VISIT({ 1515 if ( __visit_children() ) { 1516 { 1496 1517 guard_symtab guard { *this }; 1497 1518 maybe_accept( node, &UntypedTupleExpr::result ); 1498 1519 } 1499 1520 maybe_accept( node, &UntypedTupleExpr::exprs ); 1500 )1521 } 1501 1522 1502 1523 VISIT_END( Expr, node ); … … 1509 1530 VISIT_START( node ); 1510 1531 1511 VISIT({ 1532 if ( __visit_children() ) { 1533 { 1512 1534 guard_symtab guard { *this }; 1513 1535 maybe_accept( node, &TupleExpr::result ); 1514 1536 } 1515 1537 maybe_accept( node, &TupleExpr::exprs ); 1516 )1538 } 1517 1539 1518 1540 VISIT_END( Expr, node ); … … 1525 1547 VISIT_START( node ); 1526 1548 1527 VISIT({ 1549 if ( __visit_children() ) { 1550 { 1528 1551 guard_symtab guard { *this }; 1529 1552 maybe_accept( node, &TupleIndexExpr::result ); 1530 1553 } 1531 1554 maybe_accept( node, &TupleIndexExpr::tuple ); 1532 )1555 } 1533 1556 1534 1557 VISIT_END( Expr, node ); … … 1541 1564 VISIT_START( node ); 1542 1565 1543 VISIT({ 1566 if ( __visit_children() ) { 1567 { 1544 1568 guard_symtab guard { *this }; 1545 1569 maybe_accept( node, &TupleAssignExpr::result ); 1546 1570 } 1547 1571 maybe_accept( node, &TupleAssignExpr::stmtExpr ); 1548 )1572 } 1549 1573 1550 1574 VISIT_END( Expr, node ); … … 1557 1581 VISIT_START( node ); 1558 1582 1559 VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr 1583 if ( __visit_children() ) { 1584 // don't want statements from outer CompoundStmts to be added to this StmtExpr 1560 1585 // get the stmts that will need to be spliced in 1561 1586 auto stmts_before = __pass::stmtsToAddBefore( core, 0); … … 1574 1599 maybe_accept( node, &StmtExpr::returnDecls ); 1575 1600 maybe_accept( node, &StmtExpr::dtors ); 1576 )1601 } 1577 1602 1578 1603 VISIT_END( Expr, node ); … … 1585 1610 VISIT_START( node ); 1586 1611 1587 VISIT({ 1612 if ( __visit_children() ) { 1613 { 1588 1614 guard_symtab guard { *this }; 1589 1615 maybe_accept( node, &UniqueExpr::result ); 1590 1616 } 1591 1617 maybe_accept( node, &UniqueExpr::expr ); 1592 )1618 } 1593 1619 1594 1620 VISIT_END( Expr, node ); … … 1601 1627 VISIT_START( node ); 1602 1628 1603 VISIT({ 1629 if ( __visit_children() ) { 1630 { 1604 1631 guard_symtab guard { *this }; 1605 1632 maybe_accept( node, &UntypedInitExpr::result ); … … 1607 1634 maybe_accept( node, &UntypedInitExpr::expr ); 1608 1635 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. 1609 )1636 } 1610 1637 1611 1638 VISIT_END( Expr, node ); … … 1618 1645 VISIT_START( node ); 1619 1646 1620 VISIT({ 1647 if ( __visit_children() ) { 1648 { 1621 1649 guard_symtab guard { *this }; 1622 1650 maybe_accept( node, &InitExpr::result ); … … 1624 1652 maybe_accept( node, &InitExpr::expr ); 1625 1653 maybe_accept( node, &InitExpr::designation ); 1626 )1654 } 1627 1655 1628 1656 VISIT_END( Expr, node ); … … 1635 1663 VISIT_START( node ); 1636 1664 1637 VISIT({ 1665 if ( __visit_children() ) { 1666 { 1638 1667 guard_symtab guard { *this }; 1639 1668 maybe_accept( node, &DeletedExpr::result ); … … 1641 1670 maybe_accept( node, &DeletedExpr::expr ); 1642 1671 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. 1643 )1672 } 1644 1673 1645 1674 VISIT_END( Expr, node ); … … 1652 1681 VISIT_START( node ); 1653 1682 1654 VISIT({ 1683 if ( __visit_children() ) { 1684 { 1655 1685 guard_symtab guard { *this }; 1656 1686 maybe_accept( node, &DefaultArgExpr::result ); 1657 1687 } 1658 1688 maybe_accept( node, &DefaultArgExpr::expr ); 1659 )1689 } 1660 1690 1661 1691 VISIT_END( Expr, node ); … … 1668 1698 VISIT_START( node ); 1669 1699 1670 VISIT({ 1700 if ( __visit_children() ) { 1701 { 1671 1702 guard_symtab guard { *this }; 1672 1703 maybe_accept( node, &GenericExpr::result ); … … 1697 1728 node = n; 1698 1729 } 1699 )1730 } 1700 1731 1701 1732 VISIT_END( Expr, node ); … … 1726 1757 VISIT_START( node ); 1727 1758 1728 VISIT(1759 if ( __visit_children() ) { 1729 1760 // xxx - should PointerType visit/mutate dimension? 1730 1761 maybe_accept( node, &PointerType::base ); 1731 )1762 } 1732 1763 1733 1764 VISIT_END( Type, node ); … … 1740 1771 VISIT_START( node ); 1741 1772 1742 VISIT(1773 if ( __visit_children() ) { 1743 1774 maybe_accept( node, &ArrayType::dimension ); 1744 1775 maybe_accept( node, &ArrayType::base ); 1745 )1776 } 1746 1777 1747 1778 VISIT_END( Type, node ); … … 1754 1785 VISIT_START( node ); 1755 1786 1756 VISIT(1787 if ( __visit_children() ) { 1757 1788 maybe_accept( node, &ReferenceType::base ); 1758 )1789 } 1759 1790 1760 1791 VISIT_END( Type, node ); … … 1767 1798 VISIT_START( node ); 1768 1799 1769 VISIT(1800 if ( __visit_children() ) { 1770 1801 maybe_accept( node, &QualifiedType::parent ); 1771 1802 maybe_accept( node, &QualifiedType::child ); 1772 )1803 } 1773 1804 1774 1805 VISIT_END( Type, node ); … … 1781 1812 VISIT_START( node ); 1782 1813 1783 VISIT({1814 if ( __visit_children() ) { 1784 1815 // guard_forall_subs forall_guard { *this, node }; 1785 1816 // mutate_forall( node ); … … 1787 1818 maybe_accept( node, &FunctionType::returns ); 1788 1819 maybe_accept( node, &FunctionType::params ); 1789 } )1820 } 1790 1821 1791 1822 VISIT_END( Type, node ); … … 1800 1831 __pass::symtab::addStruct( core, 0, node->name ); 1801 1832 1802 VISIT({1833 if ( __visit_children() ) { 1803 1834 guard_symtab guard { *this }; 1804 1835 maybe_accept( node, &StructInstType::params ); 1805 } )1836 } 1806 1837 1807 1838 VISIT_END( Type, node ); … … 1816 1847 __pass::symtab::addUnion( core, 0, node->name ); 1817 1848 1818 VISIT({1849 if ( __visit_children() ) { 1819 1850 guard_symtab guard { *this }; 1820 1851 maybe_accept( node, &UnionInstType::params ); 1821 } )1852 } 1822 1853 1823 1854 VISIT_END( Type, node ); … … 1830 1861 VISIT_START( node ); 1831 1862 1832 VISIT({1863 if ( __visit_children() ) { 1833 1864 maybe_accept( node, &EnumInstType::params ); 1834 } )1865 } 1835 1866 1836 1867 VISIT_END( Type, node ); … … 1843 1874 VISIT_START( node ); 1844 1875 1845 VISIT({1876 if ( __visit_children() ) { 1846 1877 maybe_accept( node, &TraitInstType::params ); 1847 } )1878 } 1848 1879 1849 1880 VISIT_END( Type, node ); … … 1856 1887 VISIT_START( node ); 1857 1888 1858 VISIT(1889 if ( __visit_children() ) { 1859 1890 { 1860 1891 maybe_accept( node, &TypeInstType::params ); … … 1862 1893 // ensure that base re-bound if doing substitution 1863 1894 __pass::forall::replace( core, 0, node ); 1864 )1895 } 1865 1896 1866 1897 VISIT_END( Type, node ); … … 1873 1904 VISIT_START( node ); 1874 1905 1875 VISIT(1906 if ( __visit_children() ) { 1876 1907 maybe_accept( node, &TupleType::types ); 1877 1908 maybe_accept( node, &TupleType::members ); 1878 )1909 } 1879 1910 1880 1911 VISIT_END( Type, node ); … … 1887 1918 VISIT_START( node ); 1888 1919 1889 VISIT(1920 if ( __visit_children() ) { 1890 1921 maybe_accept( node, &TypeofType::expr ); 1891 )1922 } 1892 1923 1893 1924 VISIT_END( Type, node ); … … 1900 1931 VISIT_START( node ); 1901 1932 1902 VISIT(1933 if ( __visit_children() ) { 1903 1934 maybe_accept( node, &VTableType::base ); 1904 )1935 } 1905 1936 1906 1937 VISIT_END( Type, node ); … … 1950 1981 VISIT_START( node ); 1951 1982 1952 VISIT( maybe_accept( node, &Designation::designators ); ) 1983 if ( __visit_children() ) { 1984 maybe_accept( node, &Designation::designators ); 1985 } 1953 1986 1954 1987 VISIT_END( Designation, node ); … … 1961 1994 VISIT_START( node ); 1962 1995 1963 VISIT(1996 if ( __visit_children() ) { 1964 1997 maybe_accept( node, &SingleInit::value ); 1965 )1998 } 1966 1999 1967 2000 VISIT_END( Init, node ); … … 1974 2007 VISIT_START( node ); 1975 2008 1976 VISIT(2009 if ( __visit_children() ) { 1977 2010 maybe_accept( node, &ListInit::designations ); 1978 2011 maybe_accept( node, &ListInit::initializers ); 1979 )2012 } 1980 2013 1981 2014 VISIT_END( Init, node ); … … 1988 2021 VISIT_START( node ); 1989 2022 1990 VISIT(2023 if ( __visit_children() ) { 1991 2024 maybe_accept( node, &ConstructorInit::ctor ); 1992 2025 maybe_accept( node, &ConstructorInit::dtor ); 1993 2026 maybe_accept( node, &ConstructorInit::init ); 1994 )2027 } 1995 2028 1996 2029 VISIT_END( Init, node ); … … 2003 2036 VISIT_START( node ); 2004 2037 2005 VISIT(2038 if ( __visit_children() ) { 2006 2039 maybe_accept( node, &Attribute::params ); 2007 )2040 } 2008 2041 2009 2042 VISIT_END( Attribute, node ); … … 2016 2049 VISIT_START( node ); 2017 2050 2018 VISIT(2051 if ( __visit_children() ) { 2019 2052 { 2020 2053 bool mutated = false; … … 2032 2065 } 2033 2066 } 2034 )2067 } 2035 2068 2036 2069 VISIT_END( TypeSubstitution, node ); … … 2038 2071 2039 2072 #undef VISIT_START 2040 #undef VISIT2041 2073 #undef VISIT_END -
src/AST/Print.cpp
r5f3ba11 rb56ad5e 511 511 ++indent; 512 512 os << indent; 513 safe_print( node->then Part);514 --indent; 515 516 if ( node->else Part!= 0 ) {513 safe_print( node->then ); 514 --indent; 515 516 if ( node->else_ != 0 ) { 517 517 os << indent << "... else:" << endl; 518 518 ++indent; 519 519 os << indent; 520 node->else Part->accept( *this );520 node->else_->accept( *this ); 521 521 --indent; 522 522 } // if … … 524 524 } 525 525 526 virtual const ast::Stmt * visit( const ast::While Stmt * node ) override final {526 virtual const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { 527 527 if ( node->isDoWhile ) { os << "Do-"; } 528 528 os << "While on condition:" << endl; -
src/AST/Stmt.cpp
r5f3ba11 rb56ad5e 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed May 15 15:53:00 201913 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 19:01:20 2022 13 // Update Count : 3 14 14 // 15 15 … … 56 56 57 57 // --- BranchStmt 58 BranchStmt::BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels )59 : Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) {58 BranchStmt::BranchStmt( const CodeLocation& loc, Kind kind, Label target, const std::vector<Label>&& labels ) 59 : Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) { 60 60 // Make sure a syntax error hasn't slipped through. 61 61 assert( Goto != kind || !target.empty() ); -
src/AST/Stmt.hpp
r5f3ba11 rb56ad5e 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri May 17 12:45:00 201913 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 20:06:41 2022 13 // Update Count : 34 14 14 // 15 15 … … 17 17 18 18 #include <list> 19 #include <utility> // for move19 #include <utility> // for move 20 20 #include <vector> 21 21 22 22 #include "Label.hpp" 23 #include "Node.hpp" // for node, ptr23 #include "Node.hpp" // for node, ptr 24 24 #include "ParseNode.hpp" 25 25 #include "Visitor.hpp" … … 27 27 28 28 // Must be included in *all* AST classes; should be #undef'd at the end of the file 29 #define MUTATE_FRIEND \29 #define MUTATE_FRIEND \ 30 30 template<typename node_t> friend node_t * mutate(const node_t * node); \ 31 31 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 32 32 33 33 namespace ast { 34 35 34 class Expr; 36 35 37 // /Base statement node36 // Base statement node 38 37 class Stmt : public ParseNode { 39 public:38 public: 40 39 std::vector<Label> labels; 41 40 42 Stmt( const CodeLocation & loc, std::vector<Label> && labels = {} )43 : ParseNode(loc), labels(std::move(labels)) {}44 45 Stmt(const Stmt & o) : ParseNode(o), labels(o.labels) {}41 Stmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 42 : ParseNode(loc), labels(std::move(labels)) {} 43 44 Stmt(const Stmt & o) : ParseNode(o), labels(o.labels) {} 46 45 47 46 const Stmt * accept( Visitor & v ) const override = 0; 48 private:47 private: 49 48 Stmt * clone() const override = 0; 50 49 MUTATE_FRIEND 51 50 }; 52 51 53 // / Compound statement `{ ... }`52 // Compound statement: { ... } 54 53 class CompoundStmt final : public Stmt { 55 public:54 public: 56 55 std::list<ptr<Stmt>> kids; 57 56 58 CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {}, 59 std::vector<Label>&& labels = {} ) 60 : Stmt(loc, std::move(labels)), kids(std::move(ks)) {} 61 62 CompoundStmt( const CompoundStmt& o ); 63 CompoundStmt( CompoundStmt&& o ) = default; 57 CompoundStmt(const CodeLocation & loc, const std::list<ptr<Stmt>> && ks = {}, const std::vector<Label> && labels = {} ) 58 : Stmt(loc, std::move(labels)), kids(std::move(ks)) {} 59 60 CompoundStmt( const CompoundStmt & o ); 61 CompoundStmt( CompoundStmt && o ) = default; 64 62 65 63 void push_back( const Stmt * s ) { kids.emplace_back( s ); } … … 67 65 68 66 const CompoundStmt * accept( Visitor & v ) const override { return v.visit( this ); } 69 private:67 private: 70 68 CompoundStmt * clone() const override { return new CompoundStmt{ *this }; } 71 69 MUTATE_FRIEND 72 70 }; 73 71 74 // / Empty statment `;`72 // Empty statment: ; 75 73 class NullStmt final : public Stmt { 76 public:77 NullStmt( const CodeLocation & loc, std::vector<Label> && labels = {} )78 : Stmt(loc, std::move(labels)) {}74 public: 75 NullStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 76 : Stmt(loc, std::move(labels)) {} 79 77 80 78 const NullStmt * accept( Visitor & v ) const override { return v.visit( this ); } 81 private:79 private: 82 80 NullStmt * clone() const override { return new NullStmt{ *this }; } 83 81 MUTATE_FRIEND 84 82 }; 85 83 86 // /Expression wrapped by statement84 // Expression wrapped by statement 87 85 class ExprStmt final : public Stmt { 88 public:86 public: 89 87 ptr<Expr> expr; 90 88 91 ExprStmt( const CodeLocation & loc, const Expr* e, std::vector<Label>&& labels = {} )92 : Stmt(loc, std::move(labels)), expr(e) {}93 94 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 95 private:89 ExprStmt( const CodeLocation & loc, const Expr* e, const std::vector<Label> && labels = {} ) 90 : Stmt(loc, std::move(labels)), expr(e) {} 91 92 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 93 private: 96 94 ExprStmt * clone() const override { return new ExprStmt{ *this }; } 97 95 MUTATE_FRIEND 98 96 }; 99 97 100 // / Assembly statement `asm ... ( "..." : ... )`98 // Assembly statement: asm ... ( "..." : ... ) 101 99 class AsmStmt final : public Stmt { 102 public:100 public: 103 101 bool isVolatile; 104 102 ptr<Expr> instruction; … … 108 106 109 107 AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction, 110 std::vector<ptr<Expr>> && output,std::vector<ptr<Expr>> && input,111 std::vector<ptr<ConstantExpr>> && clobber,std::vector<Label> && gotoLabels,112 std::vector<Label> && labels = {})113 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction),114 output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)),115 gotoLabels(std::move(gotoLabels)) {}116 117 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 118 private:108 const std::vector<ptr<Expr>> && output, const std::vector<ptr<Expr>> && input, 109 const std::vector<ptr<ConstantExpr>> && clobber, const std::vector<Label> && gotoLabels, 110 const std::vector<Label> && labels = {}) 111 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction), 112 output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)), 113 gotoLabels(std::move(gotoLabels)) {} 114 115 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 116 private: 119 117 AsmStmt * clone() const override { return new AsmStmt{ *this }; } 120 118 MUTATE_FRIEND 121 119 }; 122 120 123 // / C-preprocessor directive `#...`121 // C-preprocessor directive: #... 124 122 class DirectiveStmt final : public Stmt { 125 public:123 public: 126 124 std::string directive; 127 125 128 126 DirectiveStmt( const CodeLocation & loc, const std::string & directive, 129 std::vector<Label> && labels = {} )130 : Stmt(loc, std::move(labels)), directive(directive) {}131 132 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 133 private:127 std::vector<Label> && labels = {} ) 128 : Stmt(loc, std::move(labels)), directive(directive) {} 129 130 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 131 private: 134 132 DirectiveStmt * clone() const override { return new DirectiveStmt{ *this }; } 135 133 MUTATE_FRIEND 136 134 }; 137 135 138 // / If conditional statement `if (...) ... else ...`136 // If statement: if (...) ... else ... 139 137 class IfStmt final : public Stmt { 140 public:141 ptr<Expr> cond; 142 ptr<Stmt> then Part;143 ptr<Stmt> else Part;138 public: 139 ptr<Expr> cond; 140 ptr<Stmt> then; 141 ptr<Stmt> else_; 144 142 std::vector<ptr<Stmt>> inits; 145 143 146 IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * then Part,147 const Stmt * elsePart = nullptr,std::vector<ptr<Stmt>> && inits = {},148 std::vector<Label> && labels = {} )149 : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart),150 inits(std::move(inits)) {}151 152 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 153 private:144 IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * then, 145 const Stmt * else_ = nullptr, const std::vector<ptr<Stmt>> && inits = {}, 146 const std::vector<Label> && labels = {} ) 147 : Stmt(loc, std::move(labels)), cond(cond), then(then), else_(else_), 148 inits(std::move(inits)) {} 149 150 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 151 private: 154 152 IfStmt * clone() const override { return new IfStmt{ *this }; } 155 153 MUTATE_FRIEND 156 154 }; 157 155 158 // / Switch or choose conditional statement `switch (...) { ... }`156 // Switch or choose statement: switch (...) { ... } 159 157 class SwitchStmt final : public Stmt { 160 public:158 public: 161 159 ptr<Expr> cond; 162 160 std::vector<ptr<Stmt>> stmts; 163 161 164 SwitchStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts,165 std::vector<Label> && labels = {} )166 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}167 168 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 169 private:162 SwitchStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 163 const std::vector<Label> && labels = {} ) 164 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 165 166 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 167 private: 170 168 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 171 169 MUTATE_FRIEND 172 170 }; 173 171 174 // / Case label `case ...:` `default:`172 // Case label: case ...: or default: 175 173 class CaseStmt final : public Stmt { 176 public:177 // /Null for the default label.174 public: 175 // Null for the default label. 178 176 ptr<Expr> cond; 179 177 std::vector<ptr<Stmt>> stmts; 180 178 181 CaseStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts,182 std::vector<Label> && labels = {} )183 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}179 CaseStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 184 182 185 183 bool isDefault() const { return !cond; } 186 184 187 185 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 188 private:186 private: 189 187 CaseStmt * clone() const override { return new CaseStmt{ *this }; } 190 188 MUTATE_FRIEND 191 189 }; 192 190 193 // / While loop `while (...) ...` `do ... while (...);194 class While Stmt final : public Stmt {195 public:191 // While loop: while (...) ... else ... or do ... while (...) else ...; 192 class WhileDoStmt final : public Stmt { 193 public: 196 194 ptr<Expr> cond; 197 195 ptr<Stmt> body; 196 ptr<Stmt> else_; 198 197 std::vector<ptr<Stmt>> inits; 199 198 bool isDoWhile; 200 199 201 WhileStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, 202 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} ) 203 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), 204 isDoWhile(isDoWhile) {} 205 206 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 207 private: 208 WhileStmt * clone() const override { return new WhileStmt{ *this }; } 209 MUTATE_FRIEND 210 }; 211 212 /// For loop `for (... ; ... ; ...) ...` 200 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, 201 const std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, const std::vector<Label> && labels = {} ) 202 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {} 203 204 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, const Stmt * else_, 205 const std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, const std::vector<Label> && labels = {} ) 206 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {} 207 208 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 209 private: 210 WhileDoStmt * clone() const override { return new WhileDoStmt{ *this }; } 211 MUTATE_FRIEND 212 }; 213 214 // For loop: for (... ; ... ; ...) ... else ... 213 215 class ForStmt final : public Stmt { 214 public:216 public: 215 217 std::vector<ptr<Stmt>> inits; 216 218 ptr<Expr> cond; 217 219 ptr<Expr> inc; 218 220 ptr<Stmt> body; 219 220 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond, 221 const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} ) 222 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), 223 body(body) {} 224 225 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 226 private: 221 ptr<Stmt> else_; 222 223 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 224 const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} ) 225 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {} 226 227 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 228 const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} ) 229 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {} 230 231 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 232 private: 227 233 ForStmt * clone() const override { return new ForStmt{ *this }; } 228 234 MUTATE_FRIEND 229 235 }; 230 236 231 // / Branch control flow statement `goto ...` `break` `continue` `fallthru`237 // Branch control flow statement: goto ... or break or continue or fallthru 232 238 class BranchStmt final : public Stmt { 233 public:239 public: 234 240 enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault }; 235 241 static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault; … … 240 246 Kind kind; 241 247 242 BranchStmt( const CodeLocation & loc, Kind kind, Label target, 243 std::vector<Label> && labels = {} ); 244 BranchStmt( const CodeLocation & loc, const Expr * computedTarget, 245 std::vector<Label> && labels = {} ) 246 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), 247 computedTarget(computedTarget), kind(Goto) {} 248 BranchStmt( const CodeLocation & loc, Kind kind, Label target, const std::vector<Label> && labels = {} ); 249 BranchStmt( const CodeLocation & loc, const Expr * computedTarget, const std::vector<Label> && labels = {} ) 250 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), computedTarget(computedTarget), kind(Goto) {} 248 251 249 252 const char * kindName() const { return kindNames[kind]; } 250 253 251 254 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 252 private:255 private: 253 256 BranchStmt * clone() const override { return new BranchStmt{ *this }; } 254 257 MUTATE_FRIEND … … 257 260 }; 258 261 259 // / Return statement `return ...`262 // Return statement: return ... 260 263 class ReturnStmt final : public Stmt { 261 public:264 public: 262 265 ptr<Expr> expr; 263 266 264 ReturnStmt( const CodeLocation & loc, const Expr * expr, std::vector<Label> && labels = {} )265 : Stmt(loc, std::move(labels)), expr(expr) {}266 267 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 268 private:267 ReturnStmt( const CodeLocation & loc, const Expr * expr, const std::vector<Label> && labels = {} ) 268 : Stmt(loc, std::move(labels)), expr(expr) {} 269 270 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 271 private: 269 272 ReturnStmt * clone() const override { return new ReturnStmt{ *this }; } 270 273 MUTATE_FRIEND 271 274 }; 272 275 273 // /Kind of exception276 // Kind of exception 274 277 enum ExceptionKind { Terminate, Resume }; 275 278 276 // / Throw statement `throw ...`279 // Throw statement: throw ... 277 280 class ThrowStmt final : public Stmt { 278 public:281 public: 279 282 ptr<Expr> expr; 280 283 ptr<Expr> target; 281 284 ExceptionKind kind; 282 285 283 ThrowStmt( 284 const CodeLocation & loc, ExceptionKind kind, const Expr * expr, const Expr * target, 285 std::vector<Label> && labels = {} ) 286 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} 287 288 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 289 private: 286 ThrowStmt( const CodeLocation & loc, ExceptionKind kind, const Expr * expr, 287 const Expr * target, const std::vector<Label> && labels = {} ) 288 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} 289 290 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 291 private: 290 292 ThrowStmt * clone() const override { return new ThrowStmt{ *this }; } 291 293 MUTATE_FRIEND 292 294 }; 293 295 294 // / Try statement `try { ... } ...`296 // Try statement: try { ... } ... 295 297 class TryStmt final : public Stmt { 296 public:298 public: 297 299 ptr<CompoundStmt> body; 298 300 std::vector<ptr<CatchStmt>> handlers; 299 301 ptr<FinallyStmt> finally; 300 302 301 TryStmt( 302 const CodeLocation & loc, const CompoundStmt * body, 303 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally, 304 std::vector<Label> && labels = {} ) 305 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} 306 307 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 308 private: 303 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 304 const std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally, 305 const std::vector<Label> && labels = {} ) 306 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} 307 308 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 309 private: 309 310 TryStmt * clone() const override { return new TryStmt{ *this }; } 310 311 MUTATE_FRIEND 311 312 }; 312 313 313 // /Catch clause of try statement314 // Catch clause of try statement 314 315 class CatchStmt final : public Stmt { 315 public:316 public: 316 317 ptr<Decl> decl; 317 318 ptr<Expr> cond; … … 319 320 ExceptionKind kind; 320 321 321 CatchStmt( 322 const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 323 const Stmt * body, std::vector<Label> && labels = {} ) 324 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} 325 326 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 327 private: 322 CatchStmt( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 323 const Stmt * body, const std::vector<Label> && labels = {} ) 324 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} 325 326 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 327 private: 328 328 CatchStmt * clone() const override { return new CatchStmt{ *this }; } 329 329 MUTATE_FRIEND 330 330 }; 331 331 332 // /Finally clause of try statement332 // Finally clause of try statement 333 333 class FinallyStmt final : public Stmt { 334 public:334 public: 335 335 ptr<CompoundStmt> body; 336 336 337 337 FinallyStmt( const CodeLocation & loc, const CompoundStmt * body, 338 std::vector<Label> && labels = {} )339 : Stmt(loc, std::move(labels)), body(body) {}340 341 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 342 private:338 std::vector<Label> && labels = {} ) 339 : Stmt(loc, std::move(labels)), body(body) {} 340 341 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 342 private: 343 343 FinallyStmt * clone() const override { return new FinallyStmt{ *this }; } 344 344 MUTATE_FRIEND 345 345 }; 346 346 347 // /Suspend statement347 // Suspend statement 348 348 class SuspendStmt final : public Stmt { 349 public:349 public: 350 350 ptr<CompoundStmt> then; 351 351 enum Type { None, Coroutine, Generator } type = None; 352 352 353 SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, std::vector<Label> && labels = {} )354 : Stmt(loc, std::move(labels)), then(then), type(type) {}355 356 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 357 private:353 SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, const std::vector<Label> && labels = {} ) 354 : Stmt(loc, std::move(labels)), then(then), type(type) {} 355 356 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 357 private: 358 358 SuspendStmt * clone() const override { return new SuspendStmt{ *this }; } 359 359 MUTATE_FRIEND 360 360 }; 361 361 362 // / Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`362 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ... 363 363 class WaitForStmt final : public Stmt { 364 public:364 public: 365 365 struct Target { 366 366 ptr<Expr> func; … … 389 389 OrElse orElse; 390 390 391 WaitForStmt( const CodeLocation & loc, std::vector<Label> && labels = {} )392 : Stmt(loc, std::move(labels)) {}393 394 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 395 private:391 WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 392 : Stmt(loc, std::move(labels)) {} 393 394 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 395 private: 396 396 WaitForStmt * clone() const override { return new WaitForStmt{ *this }; } 397 397 MUTATE_FRIEND 398 398 }; 399 399 400 // /Any declaration in a (compound) statement.400 // Any declaration in a (compound) statement. 401 401 class DeclStmt final : public Stmt { 402 public:402 public: 403 403 ptr<Decl> decl; 404 404 405 DeclStmt( const CodeLocation & loc, const Decl * decl, std::vector<Label> && labels = {} )406 : Stmt(loc, std::move(labels)), decl(decl) {}407 408 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 409 private:405 DeclStmt( const CodeLocation & loc, const Decl * decl, const std::vector<Label> && labels = {} ) 406 : Stmt(loc, std::move(labels)), decl(decl) {} 407 408 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 409 private: 410 410 DeclStmt * clone() const override { return new DeclStmt{ *this }; } 411 411 MUTATE_FRIEND 412 412 }; 413 413 414 // /Represents an implicit application of a constructor or destructor.414 // Represents an implicit application of a constructor or destructor. 415 415 class ImplicitCtorDtorStmt final : public Stmt { 416 public:416 public: 417 417 ptr<Stmt> callStmt; 418 418 419 419 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt, 420 std::vector<Label> && labels = {} )421 : Stmt(loc, std::move(labels)), callStmt(callStmt) {}422 423 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 424 private:420 std::vector<Label> && labels = {} ) 421 : Stmt(loc, std::move(labels)), callStmt(callStmt) {} 422 423 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 424 private: 425 425 ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 426 426 MUTATE_FRIEND 427 427 }; 428 428 429 // /Mutex Statement429 // Mutex Statement 430 430 class MutexStmt final : public Stmt { 431 public:431 public: 432 432 ptr<Stmt> stmt; 433 433 std::vector<ptr<Expr>> mutexObjs; 434 434 435 435 MutexStmt( const CodeLocation & loc, const Stmt * stmt, 436 std::vector<ptr<Expr>> && mutexes,std::vector<Label> && labels = {} )437 : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {}438 439 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 440 private:436 const std::vector<ptr<Expr>> && mutexes, const std::vector<Label> && labels = {} ) 437 : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {} 438 439 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 440 private: 441 441 MutexStmt * clone() const override { return new MutexStmt{ *this }; } 442 442 MUTATE_FRIEND 443 443 }; 444 445 } 444 } // namespace ast 446 445 447 446 #undef MUTATE_FRIEND 448 447 449 448 // Local Variables: // 450 // tab-width: 4 //451 449 // mode: c++ // 452 // compile-command: "make install" //453 450 // End: // -
src/AST/Visitor.hpp
r5f3ba11 rb56ad5e 10 10 // Created On : Thr May 9 15:28:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 12 18:25:07 202113 // Update Count : 112 // Last Modified On : Tue Feb 1 09:09:34 2022 13 // Update Count : 2 14 14 // 15 15 … … 38 38 virtual const ast::Stmt * visit( const ast::DirectiveStmt * ) = 0; 39 39 virtual const ast::Stmt * visit( const ast::IfStmt * ) = 0; 40 virtual const ast::Stmt * visit( const ast::While Stmt* ) = 0;40 virtual const ast::Stmt * visit( const ast::WhileDoStmt * ) = 0; 41 41 virtual const ast::Stmt * visit( const ast::ForStmt * ) = 0; 42 42 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) = 0;
Note:
See TracChangeset
for help on using the changeset viewer.