Changeset 376c632a for src/AST


Ignore:
Timestamp:
Feb 1, 2022, 10:10:46 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
7b2c8c3c
Parents:
f681823 (diff), 89a5a1f (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Copy.hpp

    rf681823 r376c632a  
    1010// Created On       : Wed Jul 10 16:13:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Nov 11  9:22:00 2021
    13 // Update Count     : 2
     12// Last Modified On : Wed Dec 15 11:07:00 2021
     13// Update Count     : 3
    1414//
    1515
     
    5252Node * deepCopy<Node>( const Node * localRoot );
    5353
     54template<typename node_t, enum Node::ref_type ref_t>
     55node_t * shallowCopy( const ptr_base<node_t, ref_t> & localRoot ) {
     56        return shallowCopy( localRoot.get() );
     57}
     58
     59template<typename node_t, enum Node::ref_type ref_t>
     60node_t * deepCopy( const ptr_base<node_t, ref_t> & localRoot ) {
     61        return deepCopy( localRoot.get() );
     62}
     63
    5464}
    5565
  • src/AST/Node.hpp

    rf681823 r376c632a  
    188188        }
    189189
     190        ptr_base & operator=( const node_t * node ) {
     191                assign( node );
     192                return *this;
     193        }
     194
    190195        template<typename o_node_t>
    191196        ptr_base & operator=( const o_node_t * node ) {
  • src/AST/Pass.impl.hpp

    rf681823 r376c632a  
    3333        /* call the implementation of the previsit of this pass */ \
    3434        __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         }
    4235
    4336#define VISIT_END( type, node ) \
     
    452445        VISIT_START( node );
    453446
    454         VISIT(
     447        if ( __visit_children() ) {
    455448                {
    456449                        guard_symtab guard { *this };
     
    460453                maybe_accept( node, &ObjectDecl::bitfieldWidth );
    461454                maybe_accept( node, &ObjectDecl::attributes    );
    462         )
     455        }
    463456
    464457        __pass::symtab::addId( core, 0, node );
     
    475468        __pass::symtab::addId( core, 0, node );
    476469
    477         VISIT(maybe_accept( node, &FunctionDecl::withExprs );)
     470        if ( __visit_children() ) {
     471                maybe_accept( node, &FunctionDecl::withExprs );
     472        }
    478473        {
    479474                // with clause introduces a level of scope (for the with expression members).
     
    493488                        } };
    494489                        __pass::symtab::addId( core, 0, func );
    495                         VISIT(
     490                        if ( __visit_children() ) {
    496491                                // parameter declarations
    497492                                maybe_accept( node, &FunctionDecl::params );
     
    509504                                maybe_accept( node, &FunctionDecl::stmts );
    510505                                maybe_accept( node, &FunctionDecl::attributes );
    511                         )
     506                        }
    512507                }
    513508        }
     
    526521        __pass::symtab::addStructFwd( core, 0, node );
    527522
    528         VISIT({
     523        if ( __visit_children() ) {
    529524                guard_symtab guard { * this };
    530525                maybe_accept( node, &StructDecl::params     );
    531526                maybe_accept( node, &StructDecl::members    );
    532527                maybe_accept( node, &StructDecl::attributes );
    533         })
     528        }
    534529
    535530        // this addition replaces the forward declaration
     
    548543        __pass::symtab::addUnionFwd( core, 0, node );
    549544
    550         VISIT({
     545        if ( __visit_children() ) {
    551546                guard_symtab guard { * this };
    552547                maybe_accept( node, &UnionDecl::params     );
    553548                maybe_accept( node, &UnionDecl::members    );
    554549                maybe_accept( node, &UnionDecl::attributes );
    555         })
     550        }
    556551
    557552        __pass::symtab::addUnion( core, 0, node );
     
    568563        __pass::symtab::addEnum( core, 0, node );
    569564
    570         VISIT(
     565        if ( __visit_children() ) {
    571566                // unlike structs, traits, and unions, enums inject their members into the global scope
    572567                maybe_accept( node, &EnumDecl::params     );
    573568                maybe_accept( node, &EnumDecl::members    );
    574569                maybe_accept( node, &EnumDecl::attributes );
    575         )
     570        }
    576571
    577572        VISIT_END( Decl, node );
     
    584579        VISIT_START( node );
    585580
    586         VISIT({
     581        if ( __visit_children() ) {
    587582                guard_symtab guard { *this };
    588583                maybe_accept( node, &TraitDecl::params     );
    589584                maybe_accept( node, &TraitDecl::members    );
    590585                maybe_accept( node, &TraitDecl::attributes );
    591         })
     586        }
    592587
    593588        __pass::symtab::addTrait( core, 0, node );
     
    602597        VISIT_START( node );
    603598
    604         VISIT({
     599        if ( __visit_children() ) {
    605600                guard_symtab guard { *this };
    606601                maybe_accept( node, &TypeDecl::base   );
    607         })
     602        }
    608603
    609604        // see A NOTE ON THE ORDER OF TRAVERSAL, above
     
    612607        __pass::symtab::addType( core, 0, node );
    613608
    614         VISIT(
     609        if ( __visit_children() ) {
    615610                maybe_accept( node, &TypeDecl::assertions );
    616611
     
    619614                        maybe_accept( node, &TypeDecl::init );
    620615                }
    621         )
     616        }
    622617
    623618        VISIT_END( Decl, node );
     
    630625        VISIT_START( node );
    631626
    632         VISIT({
     627        if ( __visit_children() ) {
    633628                guard_symtab guard { *this };
    634629                maybe_accept( node, &TypedefDecl::base   );
    635         })
     630        }
    636631
    637632        __pass::symtab::addType( core, 0, node );
    638633
    639         VISIT( maybe_accept( node, &TypedefDecl::assertions ); )
     634        if ( __visit_children() ) {
     635                maybe_accept( node, &TypedefDecl::assertions );
     636        }
    640637
    641638        VISIT_END( Decl, node );
     
    648645        VISIT_START( node );
    649646
    650         VISIT(
     647        if ( __visit_children() ) {
    651648                maybe_accept( node, &AsmDecl::stmt );
    652         )
     649        }
    653650
    654651        VISIT_END( AsmDecl, node );
     
    661658        VISIT_START( node );
    662659
    663         VISIT(
     660        if ( __visit_children() ) {
    664661                maybe_accept( node, &DirectiveDecl::stmt );
    665         )
     662        }
    666663
    667664        VISIT_END( DirectiveDecl, node );
     
    674671        VISIT_START( node );
    675672
    676         VISIT(
     673        if ( __visit_children() ) {
    677674                maybe_accept( node, &StaticAssertDecl::cond );
    678675                maybe_accept( node, &StaticAssertDecl::msg  );
    679         )
     676        }
    680677
    681678        VISIT_END( StaticAssertDecl, node );
     
    687684const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) {
    688685        VISIT_START( node );
    689         VISIT(
     686
     687        if ( __visit_children() ) {
    690688                // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.
    691689                auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {
     
    704702                guard_scope guard3 { *this };
    705703                maybe_accept( node, &CompoundStmt::kids );
    706         )
     704        }
     705
    707706        VISIT_END( CompoundStmt, node );
    708707}
     
    714713        VISIT_START( node );
    715714
    716         VISIT(
     715        if ( __visit_children() ) {
    717716                maybe_accept( node, &ExprStmt::expr );
    718         )
     717        }
    719718
    720719        VISIT_END( Stmt, node );
     
    727726        VISIT_START( node )
    728727
    729         VISIT(
     728        if ( __visit_children() ) {
    730729                maybe_accept( node, &AsmStmt::instruction );
    731730                maybe_accept( node, &AsmStmt::output      );
    732731                maybe_accept( node, &AsmStmt::input       );
    733732                maybe_accept( node, &AsmStmt::clobber     );
    734         )
     733        }
    735734
    736735        VISIT_END( Stmt, node );
     
    752751        VISIT_START( node );
    753752
    754         VISIT({
     753        if ( __visit_children() ) {
    755754                // if statements introduce a level of scope (for the initialization)
    756755                guard_symtab guard { *this };
     
    759758                maybe_accept_as_compound( node, &IfStmt::thenPart );
    760759                maybe_accept_as_compound( node, &IfStmt::elsePart );
    761         })
     760        }
    762761
    763762        VISIT_END( Stmt, node );
     
    770769        VISIT_START( node );
    771770
    772         VISIT({
     771        if ( __visit_children() ) {
    773772                // while statements introduce a level of scope (for the initialization)
    774773                guard_symtab guard { *this };
     
    776775                maybe_accept( node, &WhileStmt::cond  );
    777776                maybe_accept_as_compound( node, &WhileStmt::body  );
    778         })
     777        }
    779778
    780779        VISIT_END( Stmt, node );
     
    787786        VISIT_START( node );
    788787
    789         VISIT({
     788        if ( __visit_children() ) {
    790789                // for statements introduce a level of scope (for the initialization)
    791790                guard_symtab guard { *this };
     
    795794                maybe_accept( node, &ForStmt::inc   );
    796795                maybe_accept_as_compound( node, &ForStmt::body  );
    797         })
     796        }
    798797
    799798        VISIT_END( Stmt, node );
     
    806805        VISIT_START( node );
    807806
    808         VISIT(
     807        if ( __visit_children() ) {
    809808                maybe_accept( node, &SwitchStmt::cond  );
    810809                maybe_accept( node, &SwitchStmt::stmts );
    811         )
     810        }
    812811
    813812        VISIT_END( Stmt, node );
     
    820819        VISIT_START( node );
    821820
    822         VISIT(
     821        if ( __visit_children() ) {
    823822                maybe_accept( node, &CaseStmt::cond  );
    824823                maybe_accept( node, &CaseStmt::stmts );
    825         )
     824        }
    826825
    827826        VISIT_END( Stmt, node );
     
    842841        VISIT_START( node );
    843842
    844         VISIT(
     843        if ( __visit_children() ) {
    845844                maybe_accept( node, &ReturnStmt::expr );
    846         )
     845        }
    847846
    848847        VISIT_END( Stmt, node );
     
    855854        VISIT_START( node );
    856855
    857         VISIT(
     856        if ( __visit_children() ) {
    858857                maybe_accept( node, &ThrowStmt::expr   );
    859858                maybe_accept( node, &ThrowStmt::target );
    860         )
     859        }
    861860
    862861        VISIT_END( Stmt, node );
     
    869868        VISIT_START( node );
    870869
    871         VISIT(
     870        if ( __visit_children() ) {
    872871                maybe_accept( node, &TryStmt::body     );
    873872                maybe_accept( node, &TryStmt::handlers );
    874873                maybe_accept( node, &TryStmt::finally  );
    875         )
     874        }
    876875
    877876        VISIT_END( Stmt, node );
     
    884883        VISIT_START( node );
    885884
    886         VISIT({
     885        if ( __visit_children() ) {
    887886                // catch statements introduce a level of scope (for the caught exception)
    888887                guard_symtab guard { *this };
     
    890889                maybe_accept( node, &CatchStmt::cond );
    891890                maybe_accept_as_compound( node, &CatchStmt::body );
    892         })
     891        }
    893892
    894893        VISIT_END( Stmt, node );
     
    901900        VISIT_START( node );
    902901
    903         VISIT(
     902        if ( __visit_children() ) {
    904903                maybe_accept( node, &FinallyStmt::body );
    905         )
     904        }
    906905
    907906        VISIT_END( Stmt, node );
     
    914913        VISIT_START( node );
    915914
    916         VISIT(
     915        if ( __visit_children() ) {
    917916                maybe_accept( node, &SuspendStmt::then   );
    918         )
     917        }
    919918
    920919        VISIT_END( Stmt, node );
     
    934933                // }
    935934
    936         VISIT({
     935        if ( __visit_children() ) {
    937936                std::vector<WaitForStmt::Clause> new_clauses;
    938937                new_clauses.reserve( node->clauses.size() );
     
    965964                        node = n;
    966965                }
    967         })
     966        }
    968967
    969968        #define maybe_accept(field) \
     
    977976                }
    978977
    979         VISIT(
     978        if ( __visit_children() ) {
    980979                maybe_accept( timeout.time );
    981980                maybe_accept( timeout.stmt );
     
    983982                maybe_accept( orElse.stmt  );
    984983                maybe_accept( orElse.cond  );
    985         )
     984        }
    986985
    987986        #undef maybe_accept
     
    996995        VISIT_START( node );
    997996
    998         VISIT(
     997        if ( __visit_children() ) {
    999998                maybe_accept( node, &WithStmt::exprs );
    1000999                {
     
    10041003                        maybe_accept( node, &WithStmt::stmt );
    10051004                }
    1006         )
     1005        }
     1006
    10071007        VISIT_END( Stmt, node );
    10081008}
     
    10221022        VISIT_START( node );
    10231023
    1024         VISIT(
     1024        if ( __visit_children() ) {
    10251025                maybe_accept( node, &DeclStmt::decl );
    1026         )
     1026        }
    10271027
    10281028        VISIT_END( Stmt, node );
     
    10371037        // For now this isn't visited, it is unclear if this causes problem
    10381038        // if all tests are known to pass, remove this code
    1039         VISIT(
     1039        if ( __visit_children() ) {
    10401040                maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
    1041         )
     1041        }
    10421042
    10431043        VISIT_END( Stmt, node );
     
    10501050        VISIT_START( node );
    10511051
    1052         VISIT({
     1052        if ( __visit_children() ) {
    10531053                // mutex statements introduce a level of scope (for the initialization)
    10541054                guard_symtab guard { *this };
    10551055                maybe_accept( node, &MutexStmt::stmt );
    10561056                maybe_accept( node, &MutexStmt::mutexObjs );
    1057         })
     1057        }
    10581058
    10591059        VISIT_END( Stmt, node );
     
    10661066        VISIT_START( node );
    10671067
    1068         VISIT(
     1068        if ( __visit_children() ) {
    10691069                {
    10701070                        guard_symtab guard { *this };
     
    10731073                maybe_accept( node, &ApplicationExpr::func );
    10741074                maybe_accept( node, &ApplicationExpr::args );
    1075         )
     1075        }
    10761076
    10771077        VISIT_END( Expr, node );
     
    10841084        VISIT_START( node );
    10851085
    1086         VISIT(
     1086        if ( __visit_children() ) {
    10871087                {
    10881088                        guard_symtab guard { *this };
     
    10911091
    10921092                maybe_accept( node, &UntypedExpr::args );
    1093         )
     1093        }
    10941094
    10951095        VISIT_END( Expr, node );
     
    11021102        VISIT_START( node );
    11031103
    1104         VISIT({
     1104        if ( __visit_children() ) {
    11051105                guard_symtab guard { *this };
    11061106                maybe_accept( node, &NameExpr::result );
    1107         })
     1107        }
    11081108
    11091109        VISIT_END( Expr, node );
     
    11161116        VISIT_START( node );
    11171117
    1118         VISIT({
     1118        if ( __visit_children() ) {
     1119                {
    11191120                        guard_symtab guard { *this };
    11201121                        maybe_accept( node, &CastExpr::result );
    11211122                }
    11221123                maybe_accept( node, &CastExpr::arg );
    1123         )
     1124        }
    11241125
    11251126        VISIT_END( Expr, node );
     
    11321133        VISIT_START( node );
    11331134
    1134         VISIT({
     1135        if ( __visit_children() ) {
     1136                {
    11351137                        guard_symtab guard { *this };
    11361138                        maybe_accept( node, &KeywordCastExpr::result );
    11371139                }
    11381140                maybe_accept( node, &KeywordCastExpr::arg );
    1139         )
     1141        }
    11401142
    11411143        VISIT_END( Expr, node );
     
    11481150        VISIT_START( node );
    11491151
    1150         VISIT({
     1152        if ( __visit_children() ) {
     1153                {
    11511154                        guard_symtab guard { *this };
    11521155                        maybe_accept( node, &VirtualCastExpr::result );
    11531156                }
    11541157                maybe_accept( node, &VirtualCastExpr::arg );
    1155         )
     1158        }
    11561159
    11571160        VISIT_END( Expr, node );
     
    11641167        VISIT_START( node );
    11651168
    1166         VISIT({
     1169        if ( __visit_children() ) {
     1170                {
    11671171                        guard_symtab guard { *this };
    11681172                        maybe_accept( node, &AddressExpr::result );
    11691173                }
    11701174                maybe_accept( node, &AddressExpr::arg );
    1171         )
     1175        }
    11721176
    11731177        VISIT_END( Expr, node );
     
    11801184        VISIT_START( node );
    11811185
    1182         VISIT({
     1186        if ( __visit_children() ) {
    11831187                guard_symtab guard { *this };
    11841188                maybe_accept( node, &LabelAddressExpr::result );
    1185         })
     1189        }
    11861190
    11871191        VISIT_END( Expr, node );
     
    11941198        VISIT_START( node );
    11951199
    1196         VISIT({
     1200        if ( __visit_children() ) {
     1201                {
    11971202                        guard_symtab guard { *this };
    11981203                        maybe_accept( node, &UntypedMemberExpr::result );
     
    12001205                maybe_accept( node, &UntypedMemberExpr::aggregate );
    12011206                maybe_accept( node, &UntypedMemberExpr::member    );
    1202         )
     1207        }
    12031208
    12041209        VISIT_END( Expr, node );
     
    12111216        VISIT_START( node );
    12121217
    1213         VISIT({
     1218        if ( __visit_children() ) {
     1219                {
    12141220                        guard_symtab guard { *this };
    12151221                        maybe_accept( node, &MemberExpr::result );
    12161222                }
    12171223                maybe_accept( node, &MemberExpr::aggregate );
    1218         )
     1224        }
    12191225
    12201226        VISIT_END( Expr, node );
     
    12271233        VISIT_START( node );
    12281234
    1229         VISIT({
     1235        if ( __visit_children() ) {
    12301236                guard_symtab guard { *this };
    12311237                maybe_accept( node, &VariableExpr::result );
    1232         })
     1238        }
    12331239
    12341240        VISIT_END( Expr, node );
     
    12411247        VISIT_START( node );
    12421248
    1243         VISIT({
     1249        if ( __visit_children() ) {
    12441250                guard_symtab guard { *this };
    12451251                maybe_accept( node, &ConstantExpr::result );
    1246         })
     1252        }
    12471253
    12481254        VISIT_END( Expr, node );
     
    12551261        VISIT_START( node );
    12561262
    1257         VISIT({
     1263        if ( __visit_children() ) {
     1264                {
    12581265                        guard_symtab guard { *this };
    12591266                        maybe_accept( node, &SizeofExpr::result );
     
    12641271                        maybe_accept( node, &SizeofExpr::expr );
    12651272                }
    1266         )
     1273        }
    12671274
    12681275        VISIT_END( Expr, node );
     
    12751282        VISIT_START( node );
    12761283
    1277         VISIT({
     1284        if ( __visit_children() ) {
     1285                {
    12781286                        guard_symtab guard { *this };
    12791287                        maybe_accept( node, &AlignofExpr::result );
     
    12841292                        maybe_accept( node, &AlignofExpr::expr );
    12851293                }
    1286         )
     1294        }
    12871295
    12881296        VISIT_END( Expr, node );
     
    12951303        VISIT_START( node );
    12961304
    1297         VISIT({
     1305        if ( __visit_children() ) {
     1306                {
    12981307                        guard_symtab guard { *this };
    12991308                        maybe_accept( node, &UntypedOffsetofExpr::result );
    13001309                }
    13011310                maybe_accept( node, &UntypedOffsetofExpr::type   );
    1302         )
     1311        }
    13031312
    13041313        VISIT_END( Expr, node );
     
    13111320        VISIT_START( node );
    13121321
    1313         VISIT({
     1322        if ( __visit_children() ) {
     1323                {
    13141324                        guard_symtab guard { *this };
    13151325                        maybe_accept( node, &OffsetofExpr::result );
    13161326                }
    13171327                maybe_accept( node, &OffsetofExpr::type   );
    1318         )
     1328        }
    13191329
    13201330        VISIT_END( Expr, node );
     
    13271337        VISIT_START( node );
    13281338
    1329         VISIT({
     1339        if ( __visit_children() ) {
     1340                {
    13301341                        guard_symtab guard { *this };
    13311342                        maybe_accept( node, &OffsetPackExpr::result );
    13321343                }
    13331344                maybe_accept( node, &OffsetPackExpr::type   );
    1334         )
     1345        }
    13351346
    13361347        VISIT_END( Expr, node );
     
    13431354        VISIT_START( node );
    13441355
    1345         VISIT({
     1356        if ( __visit_children() ) {
     1357                {
    13461358                        guard_symtab guard { *this };
    13471359                        maybe_accept( node, &LogicalExpr::result );
     
    13491361                maybe_accept( node, &LogicalExpr::arg1 );
    13501362                maybe_accept( node, &LogicalExpr::arg2 );
    1351         )
     1363        }
    13521364
    13531365        VISIT_END( Expr, node );
     
    13601372        VISIT_START( node );
    13611373
    1362         VISIT({
     1374        if ( __visit_children() ) {
     1375                {
    13631376                        guard_symtab guard { *this };
    13641377                        maybe_accept( node, &ConditionalExpr::result );
     
    13671380                maybe_accept( node, &ConditionalExpr::arg2 );
    13681381                maybe_accept( node, &ConditionalExpr::arg3 );
    1369         )
     1382        }
    13701383
    13711384        VISIT_END( Expr, node );
     
    13781391        VISIT_START( node );
    13791392
    1380         VISIT({
     1393        if ( __visit_children() ) {
     1394                {
    13811395                        guard_symtab guard { *this };
    13821396                        maybe_accept( node, &CommaExpr::result );
     
    13841398                maybe_accept( node, &CommaExpr::arg1 );
    13851399                maybe_accept( node, &CommaExpr::arg2 );
    1386         )
     1400        }
    13871401
    13881402        VISIT_END( Expr, node );
     
    13951409        VISIT_START( node );
    13961410
    1397         VISIT({
     1411        if ( __visit_children() ) {
     1412                {
    13981413                        guard_symtab guard { *this };
    13991414                        maybe_accept( node, &TypeExpr::result );
    14001415                }
    14011416                maybe_accept( node, &TypeExpr::type );
    1402         )
     1417        }
    14031418
    14041419        VISIT_END( Expr, node );
     
    14111426        VISIT_START( node );
    14121427
    1413         VISIT({
     1428        if ( __visit_children() ) {
     1429                {
    14141430                        guard_symtab guard { *this };
    14151431                        maybe_accept( node, &AsmExpr::result );
     
    14171433                maybe_accept( node, &AsmExpr::constraint );
    14181434                maybe_accept( node, &AsmExpr::operand    );
    1419         )
     1435        }
    14201436
    14211437        VISIT_END( Expr, node );
     
    14281444        VISIT_START( node );
    14291445
    1430         VISIT({
     1446        if ( __visit_children() ) {
     1447                {
    14311448                        guard_symtab guard { *this };
    14321449                        maybe_accept( node, &ImplicitCopyCtorExpr::result );
    14331450                }
    14341451                maybe_accept( node, &ImplicitCopyCtorExpr::callExpr    );
    1435         )
     1452        }
    14361453
    14371454        VISIT_END( Expr, node );
     
    14441461        VISIT_START( node );
    14451462
    1446         VISIT({
     1463        if ( __visit_children() ) {
     1464                {
    14471465                        guard_symtab guard { *this };
    14481466                        maybe_accept( node, &ConstructorExpr::result );
    14491467                }
    14501468                maybe_accept( node, &ConstructorExpr::callExpr );
    1451         )
     1469        }
    14521470
    14531471        VISIT_END( Expr, node );
     
    14601478        VISIT_START( node );
    14611479
    1462         VISIT({
     1480        if ( __visit_children() ) {
     1481                {
    14631482                        guard_symtab guard { *this };
    14641483                        maybe_accept( node, &CompoundLiteralExpr::result );
    14651484                }
    14661485                maybe_accept( node, &CompoundLiteralExpr::init );
    1467         )
     1486        }
    14681487
    14691488        VISIT_END( Expr, node );
     
    14761495        VISIT_START( node );
    14771496
    1478         VISIT({
     1497        if ( __visit_children() ) {
     1498                {
    14791499                        guard_symtab guard { *this };
    14801500                        maybe_accept( node, &RangeExpr::result );
     
    14821502                maybe_accept( node, &RangeExpr::low    );
    14831503                maybe_accept( node, &RangeExpr::high   );
    1484         )
     1504        }
    14851505
    14861506        VISIT_END( Expr, node );
     
    14931513        VISIT_START( node );
    14941514
    1495         VISIT({
     1515        if ( __visit_children() ) {
     1516                {
    14961517                        guard_symtab guard { *this };
    14971518                        maybe_accept( node, &UntypedTupleExpr::result );
    14981519                }
    14991520                maybe_accept( node, &UntypedTupleExpr::exprs  );
    1500         )
     1521        }
    15011522
    15021523        VISIT_END( Expr, node );
     
    15091530        VISIT_START( node );
    15101531
    1511         VISIT({
     1532        if ( __visit_children() ) {
     1533                {
    15121534                        guard_symtab guard { *this };
    15131535                        maybe_accept( node, &TupleExpr::result );
    15141536                }
    15151537                maybe_accept( node, &TupleExpr::exprs  );
    1516         )
     1538        }
    15171539
    15181540        VISIT_END( Expr, node );
     
    15251547        VISIT_START( node );
    15261548
    1527         VISIT({
     1549        if ( __visit_children() ) {
     1550                {
    15281551                        guard_symtab guard { *this };
    15291552                        maybe_accept( node, &TupleIndexExpr::result );
    15301553                }
    15311554                maybe_accept( node, &TupleIndexExpr::tuple  );
    1532         )
     1555        }
    15331556
    15341557        VISIT_END( Expr, node );
     
    15411564        VISIT_START( node );
    15421565
    1543         VISIT({
     1566        if ( __visit_children() ) {
     1567                {
    15441568                        guard_symtab guard { *this };
    15451569                        maybe_accept( node, &TupleAssignExpr::result );
    15461570                }
    15471571                maybe_accept( node, &TupleAssignExpr::stmtExpr );
    1548         )
     1572        }
    15491573
    15501574        VISIT_END( Expr, node );
     
    15571581        VISIT_START( node );
    15581582
    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
    15601585                // get the stmts that will need to be spliced in
    15611586                auto stmts_before = __pass::stmtsToAddBefore( core, 0);
     
    15741599                maybe_accept( node, &StmtExpr::returnDecls );
    15751600                maybe_accept( node, &StmtExpr::dtors       );
    1576         )
     1601        }
    15771602
    15781603        VISIT_END( Expr, node );
     
    15851610        VISIT_START( node );
    15861611
    1587         VISIT({
     1612        if ( __visit_children() ) {
     1613                {
    15881614                        guard_symtab guard { *this };
    15891615                        maybe_accept( node, &UniqueExpr::result );
    15901616                }
    15911617                maybe_accept( node, &UniqueExpr::expr   );
    1592         )
     1618        }
    15931619
    15941620        VISIT_END( Expr, node );
     
    16011627        VISIT_START( node );
    16021628
    1603         VISIT({
     1629        if ( __visit_children() ) {
     1630                {
    16041631                        guard_symtab guard { *this };
    16051632                        maybe_accept( node, &UntypedInitExpr::result );
     
    16071634                maybe_accept( node, &UntypedInitExpr::expr   );
    16081635                // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
    1609         )
     1636        }
    16101637
    16111638        VISIT_END( Expr, node );
     
    16181645        VISIT_START( node );
    16191646
    1620         VISIT({
     1647        if ( __visit_children() ) {
     1648                {
    16211649                        guard_symtab guard { *this };
    16221650                        maybe_accept( node, &InitExpr::result );
     
    16241652                maybe_accept( node, &InitExpr::expr   );
    16251653                maybe_accept( node, &InitExpr::designation );
    1626         )
     1654        }
    16271655
    16281656        VISIT_END( Expr, node );
     
    16351663        VISIT_START( node );
    16361664
    1637         VISIT({
     1665        if ( __visit_children() ) {
     1666                {
    16381667                        guard_symtab guard { *this };
    16391668                        maybe_accept( node, &DeletedExpr::result );
     
    16411670                maybe_accept( node, &DeletedExpr::expr );
    16421671                // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
    1643         )
     1672        }
    16441673
    16451674        VISIT_END( Expr, node );
     
    16521681        VISIT_START( node );
    16531682
    1654         VISIT({
     1683        if ( __visit_children() ) {
     1684                {
    16551685                        guard_symtab guard { *this };
    16561686                        maybe_accept( node, &DefaultArgExpr::result );
    16571687                }
    16581688                maybe_accept( node, &DefaultArgExpr::expr );
    1659         )
     1689        }
    16601690
    16611691        VISIT_END( Expr, node );
     
    16681698        VISIT_START( node );
    16691699
    1670         VISIT({
     1700        if ( __visit_children() ) {
     1701                {
    16711702                        guard_symtab guard { *this };
    16721703                        maybe_accept( node, &GenericExpr::result );
     
    16971728                        node = n;
    16981729                }
    1699         )
     1730        }
    17001731
    17011732        VISIT_END( Expr, node );
     
    17261757        VISIT_START( node );
    17271758
    1728         VISIT(
     1759        if ( __visit_children() ) {
    17291760                // xxx - should PointerType visit/mutate dimension?
    17301761                maybe_accept( node, &PointerType::base );
    1731         )
     1762        }
    17321763
    17331764        VISIT_END( Type, node );
     
    17401771        VISIT_START( node );
    17411772
    1742         VISIT(
     1773        if ( __visit_children() ) {
    17431774                maybe_accept( node, &ArrayType::dimension );
    17441775                maybe_accept( node, &ArrayType::base );
    1745         )
     1776        }
    17461777
    17471778        VISIT_END( Type, node );
     
    17541785        VISIT_START( node );
    17551786
    1756         VISIT(
     1787        if ( __visit_children() ) {
    17571788                maybe_accept( node, &ReferenceType::base );
    1758         )
     1789        }
    17591790
    17601791        VISIT_END( Type, node );
     
    17671798        VISIT_START( node );
    17681799
    1769         VISIT(
     1800        if ( __visit_children() ) {
    17701801                maybe_accept( node, &QualifiedType::parent );
    17711802                maybe_accept( node, &QualifiedType::child );
    1772         )
     1803        }
    17731804
    17741805        VISIT_END( Type, node );
     
    17811812        VISIT_START( node );
    17821813
    1783         VISIT({
     1814        if ( __visit_children() ) {
    17841815                // guard_forall_subs forall_guard { *this, node };
    17851816                // mutate_forall( node );
     
    17871818                maybe_accept( node, &FunctionType::returns );
    17881819                maybe_accept( node, &FunctionType::params  );
    1789         })
     1820        }
    17901821
    17911822        VISIT_END( Type, node );
     
    18001831        __pass::symtab::addStruct( core, 0, node->name );
    18011832
    1802         VISIT({
     1833        if ( __visit_children() ) {
    18031834                guard_symtab guard { *this };
    18041835                maybe_accept( node, &StructInstType::params );
    1805         })
     1836        }
    18061837
    18071838        VISIT_END( Type, node );
     
    18161847        __pass::symtab::addUnion( core, 0, node->name );
    18171848
    1818         VISIT({
     1849        if ( __visit_children() ) {
    18191850                guard_symtab guard { *this };
    18201851                maybe_accept( node, &UnionInstType::params );
    1821         })
     1852        }
    18221853
    18231854        VISIT_END( Type, node );
     
    18301861        VISIT_START( node );
    18311862
    1832         VISIT({
     1863        if ( __visit_children() ) {
    18331864                maybe_accept( node, &EnumInstType::params );
    1834         })
     1865        }
    18351866
    18361867        VISIT_END( Type, node );
     
    18431874        VISIT_START( node );
    18441875
    1845         VISIT({
     1876        if ( __visit_children() ) {
    18461877                maybe_accept( node, &TraitInstType::params );
    1847         })
     1878        }
    18481879
    18491880        VISIT_END( Type, node );
     
    18561887        VISIT_START( node );
    18571888
    1858         VISIT(
     1889        if ( __visit_children() ) {
    18591890                {
    18601891                        maybe_accept( node, &TypeInstType::params );
     
    18621893                // ensure that base re-bound if doing substitution
    18631894                __pass::forall::replace( core, 0, node );
    1864         )
     1895        }
    18651896
    18661897        VISIT_END( Type, node );
     
    18731904        VISIT_START( node );
    18741905
    1875         VISIT(
     1906        if ( __visit_children() ) {
    18761907                maybe_accept( node, &TupleType::types );
    18771908                maybe_accept( node, &TupleType::members );
    1878         )
     1909        }
    18791910
    18801911        VISIT_END( Type, node );
     
    18871918        VISIT_START( node );
    18881919
    1889         VISIT(
     1920        if ( __visit_children() ) {
    18901921                maybe_accept( node, &TypeofType::expr );
    1891         )
     1922        }
    18921923
    18931924        VISIT_END( Type, node );
     
    19001931        VISIT_START( node );
    19011932
    1902         VISIT(
     1933        if ( __visit_children() ) {
    19031934                maybe_accept( node, &VTableType::base );
    1904         )
     1935        }
    19051936
    19061937        VISIT_END( Type, node );
     
    19501981        VISIT_START( node );
    19511982
    1952         VISIT( maybe_accept( node, &Designation::designators ); )
     1983        if ( __visit_children() ) {
     1984                maybe_accept( node, &Designation::designators );
     1985        }
    19531986
    19541987        VISIT_END( Designation, node );
     
    19611994        VISIT_START( node );
    19621995
    1963         VISIT(
     1996        if ( __visit_children() ) {
    19641997                maybe_accept( node, &SingleInit::value );
    1965         )
     1998        }
    19661999
    19672000        VISIT_END( Init, node );
     
    19742007        VISIT_START( node );
    19752008
    1976         VISIT(
     2009        if ( __visit_children() ) {
    19772010                maybe_accept( node, &ListInit::designations );
    19782011                maybe_accept( node, &ListInit::initializers );
    1979         )
     2012        }
    19802013
    19812014        VISIT_END( Init, node );
     
    19882021        VISIT_START( node );
    19892022
    1990         VISIT(
     2023        if ( __visit_children() ) {
    19912024                maybe_accept( node, &ConstructorInit::ctor );
    19922025                maybe_accept( node, &ConstructorInit::dtor );
    19932026                maybe_accept( node, &ConstructorInit::init );
    1994         )
     2027        }
    19952028
    19962029        VISIT_END( Init, node );
     
    20032036        VISIT_START( node );
    20042037
    2005         VISIT(
     2038        if ( __visit_children() ) {
    20062039                maybe_accept( node, &Attribute::params );
    2007         )
     2040        }
    20082041
    20092042        VISIT_END( Attribute, node );
     
    20162049        VISIT_START( node );
    20172050
    2018         VISIT(
     2051        if ( __visit_children() ) {
    20192052                {
    20202053                        bool mutated = false;
     
    20322065                        }
    20332066                }
    2034         )
     2067        }
    20352068
    20362069        VISIT_END( TypeSubstitution, node );
     
    20382071
    20392072#undef VISIT_START
    2040 #undef VISIT
    20412073#undef VISIT_END
  • src/AST/Stmt.hpp

    rf681823 r376c632a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May  8 13:00:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 17 12:45:00 2019
    13 // Update Count     : 5
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jan 31 22:38:53 2022
     13// Update Count     : 12
    1414//
    1515
     
    1717
    1818#include <list>
    19 #include <utility>                // for move
     19#include <utility>                                                                              // for move
    2020#include <vector>
    2121
    2222#include "Label.hpp"
    23 #include "Node.hpp"               // for node, ptr
     23#include "Node.hpp"                                                                             // for node, ptr
    2424#include "ParseNode.hpp"
    2525#include "Visitor.hpp"
     
    2727
    2828// 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                                                                                                   \
    3030    template<typename node_t> friend node_t * mutate(const node_t * node); \
    3131        template<typename node_t> friend node_t * shallowCopy(const node_t * node);
    3232
    3333namespace ast {
    34 
    3534class Expr;
    3635
    37 /// Base statement node
     36// Base statement node
    3837class Stmt : public ParseNode {
    39 public:
     38  public:
    4039        std::vector<Label> labels;
    4140
    4241        Stmt( const CodeLocation & loc, std::vector<Label> && labels = {} )
    43         : ParseNode(loc), labels(std::move(labels)) {}
     42                : ParseNode(loc), labels(std::move(labels)) {}
    4443
    4544        Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
    4645
    4746        const Stmt * accept( Visitor & v ) const override = 0;
    48 private:
     47  private:
    4948        Stmt * clone() const override = 0;
    5049        MUTATE_FRIEND
    5150};
    5251
    53 /// Compound statement `{ ... }`
     52// Compound statement: { ... }
    5453class CompoundStmt final : public Stmt {
    55 public:
     54  public:
    5655        std::list<ptr<Stmt>> kids;
    5756
    5857        CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {},
    59                 std::vector<Label>&& labels = {} )
    60         : Stmt(loc, std::move(labels)), kids(std::move(ks)) {}
     58                                 std::vector<Label>&& labels = {} )
     59                : Stmt(loc, std::move(labels)), kids(std::move(ks)) {}
    6160
    6261        CompoundStmt( const CompoundStmt& o );
     
    6766
    6867        const CompoundStmt * accept( Visitor & v ) const override { return v.visit( this ); }
    69 private:
     68  private:
    7069        CompoundStmt * clone() const override { return new CompoundStmt{ *this }; }
    7170        MUTATE_FRIEND
    7271};
    7372
    74 /// Empty statment `;`
     73// Empty statment: ;
    7574class NullStmt final : public Stmt {
    76 public:
     75  public:
    7776        NullStmt( const CodeLocation & loc, std::vector<Label> && labels = {} )
    78         : Stmt(loc, std::move(labels)) {}
     77                : Stmt(loc, std::move(labels)) {}
    7978
    8079        const NullStmt * accept( Visitor & v ) const override { return v.visit( this ); }
    81 private:
     80  private:
    8281        NullStmt * clone() const override { return new NullStmt{ *this }; }
    8382        MUTATE_FRIEND
    8483};
    8584
    86 /// Expression wrapped by statement
     85// Expression wrapped by statement
    8786class ExprStmt final : public Stmt {
    88 public:
     87  public:
    8988        ptr<Expr> expr;
    9089
    9190        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:
     91                : Stmt(loc, std::move(labels)), expr(e) {}
     92
     93        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     94  private:
    9695        ExprStmt * clone() const override { return new ExprStmt{ *this }; }
    9796        MUTATE_FRIEND
    9897};
    9998
    100 /// Assembly statement `asm ... ( "..." : ... )`
     99// Assembly statement: asm ... ( "..." : ... )
    101100class AsmStmt final : public Stmt {
    102 public:
     101  public:
    103102        bool isVolatile;
    104103        ptr<Expr> instruction;
     
    108107
    109108        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:
     109                         std::vector<ptr<Expr>> && output, std::vector<ptr<Expr>> && input,
     110                         std::vector<ptr<ConstantExpr>> && clobber, std::vector<Label> && gotoLabels,
     111                         std::vector<Label> && labels = {})
     112                : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction),
     113                  output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)),
     114                  gotoLabels(std::move(gotoLabels)) {}
     115
     116        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     117  private:
    119118        AsmStmt * clone() const override { return new AsmStmt{ *this }; }
    120119        MUTATE_FRIEND
    121120};
    122121
    123 /// C-preprocessor directive `#...`
     122// C-preprocessor directive: #...
    124123class DirectiveStmt final : public Stmt {
    125 public:
     124  public:
    126125        std::string directive;
    127126
    128127        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:
     128                                   std::vector<Label> && labels = {} )
     129                : Stmt(loc, std::move(labels)), directive(directive) {}
     130
     131        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     132  private:
    134133        DirectiveStmt * clone() const override { return new DirectiveStmt{ *this }; }
    135134        MUTATE_FRIEND
    136135};
    137136
    138 /// If conditional statement `if (...) ... else ...`
     137// If statement: if (...) ... else ...
    139138class IfStmt final : public Stmt {
    140 public:
     139  public:
    141140        ptr<Expr> cond;
    142141        ptr<Stmt> thenPart;
     
    145144
    146145        IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * thenPart,
    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:
     146                        const Stmt * elsePart = nullptr, std::vector<ptr<Stmt>> && inits = {},
     147                        std::vector<Label> && labels = {} )
     148                : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart),
     149                  inits(std::move(inits)) {}
     150
     151        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     152  private:
    154153        IfStmt * clone() const override { return new IfStmt{ *this }; }
    155154        MUTATE_FRIEND
    156155};
    157156
    158 /// Switch or choose conditional statement `switch (...) { ... }`
     157// Switch or choose statement: switch (...) { ... }
    159158class SwitchStmt final : public Stmt {
    160 public:
     159  public:
    161160        ptr<Expr> cond;
    162161        std::vector<ptr<Stmt>> stmts;
    163162
    164163        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:
     164                                std::vector<Label> && labels = {} )
     165                : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
     166
     167        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     168  private:
    170169        SwitchStmt * clone() const override { return new SwitchStmt{ *this }; }
    171170        MUTATE_FRIEND
    172171};
    173172
    174 /// Case label `case ...:` `default:`
     173// Case label: case ...: or default:
    175174class CaseStmt final : public Stmt {
    176 public:
    177         /// Null for the default label.
     175  public:
     176        // Null for the default label.
    178177        ptr<Expr> cond;
    179178        std::vector<ptr<Stmt>> stmts;
    180179
    181180        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)) {}
     181                          std::vector<Label> && labels = {} )
     182                : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
    184183
    185184        bool isDefault() const { return !cond; }
    186185
    187186        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    188 private:
     187  private:
    189188        CaseStmt * clone() const override { return new CaseStmt{ *this }; }
    190189        MUTATE_FRIEND
    191190};
    192191
    193 /// While loop `while (...) ...` `do ... while (...);
     192// While loop: while (...) ... else ... or do ... while (...) else ...;
    194193class WhileStmt final : public Stmt {
    195 public:
     194  public:
    196195        ptr<Expr> cond;
    197196        ptr<Stmt> body;
     197        ptr<Stmt> elsePart;
    198198        std::vector<ptr<Stmt>> inits;
    199199        bool isDoWhile;
    200200
    201201        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:
     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)), isDoWhile(isDoWhile) {}
     204
     205        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     206  private:
    208207        WhileStmt * clone() const override { return new WhileStmt{ *this }; }
    209208        MUTATE_FRIEND
    210209};
    211210
    212 /// For loop `for (... ; ... ; ...) ...`
     211// For loop: for (... ; ... ; ...) ... else ...
    213212class ForStmt final : public Stmt {
    214 public:
     213  public:
    215214        std::vector<ptr<Stmt>> inits;
    216215        ptr<Expr> cond;
    217216        ptr<Expr> inc;
    218217        ptr<Stmt> body;
     218        ptr<Stmt> elsePart;
    219219
    220220        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                         const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} )
     222                : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body) {}
     223
     224        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     225  private:
    227226        ForStmt * clone() const override { return new ForStmt{ *this }; }
    228227        MUTATE_FRIEND
    229228};
    230229
    231 /// Branch control flow statement `goto ...` `break` `continue` `fallthru`
     230// Branch control flow statement: goto ... or break or continue or fallthru
    232231class BranchStmt final : public Stmt {
    233 public:
     232  public:
    234233        enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault };
    235234        static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault;
     
    241240
    242241        BranchStmt( const CodeLocation & loc, Kind kind, Label target,
    243                 std::vector<Label> && labels = {} );
     242                                std::vector<Label> && labels = {} );
    244243        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) {}
     244                                std::vector<Label> && labels = {} )
     245                : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc),
     246                  computedTarget(computedTarget), kind(Goto) {}
    248247
    249248        const char * kindName() const { return kindNames[kind]; }
    250249
    251250        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    252 private:
     251  private:
    253252        BranchStmt * clone() const override { return new BranchStmt{ *this }; }
    254253        MUTATE_FRIEND
     
    257256};
    258257
    259 /// Return statement `return ...`
     258// Return statement: return ...
    260259class ReturnStmt final : public Stmt {
    261 public:
     260  public:
    262261        ptr<Expr> expr;
    263262
    264263        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:
     264                : Stmt(loc, std::move(labels)), expr(expr) {}
     265
     266        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     267  private:
    269268        ReturnStmt * clone() const override { return new ReturnStmt{ *this }; }
    270269        MUTATE_FRIEND
    271270};
    272271
    273 /// Kind of exception
     272// Kind of exception
    274273enum ExceptionKind { Terminate, Resume };
    275274
    276 /// Throw statement `throw ...`
     275// Throw statement: throw ...
    277276class ThrowStmt final : public Stmt {
    278 public:
     277  public:
    279278        ptr<Expr> expr;
    280279        ptr<Expr> target;
     
    284283                const CodeLocation & loc, ExceptionKind kind, const Expr * expr, const Expr * target,
    285284                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:
     285                : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {}
     286
     287        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     288  private:
    290289        ThrowStmt * clone() const override { return new ThrowStmt{ *this }; }
    291290        MUTATE_FRIEND
    292291};
    293292
    294 /// Try statement `try { ... } ...`
     293// Try statement: try { ... } ...
    295294class TryStmt final : public Stmt {
    296 public:
     295  public:
    297296        ptr<CompoundStmt> body;
    298297        std::vector<ptr<CatchStmt>> handlers;
     
    303302                std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally,
    304303                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:
     304                : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {}
     305
     306        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     307  private:
    309308        TryStmt * clone() const override { return new TryStmt{ *this }; }
    310309        MUTATE_FRIEND
    311310};
    312311
    313 /// Catch clause of try statement
     312// Catch clause of try statement
    314313class CatchStmt final : public Stmt {
    315 public:
     314  public:
    316315        ptr<Decl> decl;
    317316        ptr<Expr> cond;
     
    322321                const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
    323322                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:
     323                : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}
     324
     325        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     326  private:
    328327        CatchStmt * clone() const override { return new CatchStmt{ *this }; }
    329328        MUTATE_FRIEND
    330329};
    331330
    332 /// Finally clause of try statement
     331// Finally clause of try statement
    333332class FinallyStmt final : public Stmt {
    334 public:
     333  public:
    335334        ptr<CompoundStmt> body;
    336335
    337336        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:
     337                                 std::vector<Label> && labels = {} )
     338                : Stmt(loc, std::move(labels)), body(body) {}
     339
     340        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     341  private:
    343342        FinallyStmt * clone() const override { return new FinallyStmt{ *this }; }
    344343        MUTATE_FRIEND
    345344};
    346345
    347 /// Suspend statement
     346// Suspend statement
    348347class SuspendStmt final : public Stmt {
    349 public:
     348  public:
    350349        ptr<CompoundStmt> then;
    351350        enum Type { None, Coroutine, Generator } type = None;
    352351
    353352        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                : Stmt(loc, std::move(labels)), then(then), type(type) {}
     354
     355        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     356  private:
    358357        SuspendStmt * clone() const override { return new SuspendStmt{ *this }; }
    359358        MUTATE_FRIEND
    360359};
    361360
    362 /// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`
     361// Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...
    363362class WaitForStmt final : public Stmt {
    364 public:
     363  public:
    365364        struct Target {
    366365                ptr<Expr> func;
     
    390389
    391390        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                : Stmt(loc, std::move(labels)) {}
     392
     393        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     394  private:
    396395        WaitForStmt * clone() const override { return new WaitForStmt{ *this }; }
    397396        MUTATE_FRIEND
    398397};
    399398
    400 /// Any declaration in a (compound) statement.
     399// Any declaration in a (compound) statement.
    401400class DeclStmt final : public Stmt {
    402 public:
     401  public:
    403402        ptr<Decl> decl;
    404403
    405404        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                : Stmt(loc, std::move(labels)), decl(decl) {}
     406
     407        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     408  private:
    410409        DeclStmt * clone() const override { return new DeclStmt{ *this }; }
    411410        MUTATE_FRIEND
    412411};
    413412
    414 /// Represents an implicit application of a constructor or destructor.
     413// Represents an implicit application of a constructor or destructor.
    415414class ImplicitCtorDtorStmt final : public Stmt {
    416 public:
     415  public:
    417416        ptr<Stmt> callStmt;
    418417
    419418        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:
     419                                                  std::vector<Label> && labels = {} )
     420                : Stmt(loc, std::move(labels)), callStmt(callStmt) {}
     421
     422        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     423  private:
    425424        ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; }
    426425        MUTATE_FRIEND
    427426};
    428427
    429 /// Mutex Statement
     428// Mutex Statement
    430429class MutexStmt final : public Stmt {
    431 public:
     430  public:
    432431        ptr<Stmt> stmt;
    433432        std::vector<ptr<Expr>> mutexObjs;
    434433
    435434        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:
     435                           std::vector<ptr<Expr>> && mutexes, std::vector<Label> && labels = {} )
     436                : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {}
     437
     438        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     439  private:
    441440        MutexStmt * clone() const override { return new MutexStmt{ *this }; }
    442441        MUTATE_FRIEND
    443442};
    444 
    445 }
     443} // namespace ast
    446444
    447445#undef MUTATE_FRIEND
    448446
    449447// Local Variables: //
    450 // tab-width: 4 //
    451448// mode: c++ //
    452 // compile-command: "make install" //
    453449// End: //
Note: See TracChangeset for help on using the changeset viewer.