Changes in / [acd738aa:49c9773]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.impl.h

    racd738aa r49c9773  
    11#pragma once
    2 
    3 #define VISIT_START( node )  \
    4         call_previsit( node ); \
    5 
    6 #define VISIT_END( node )                \
    7         return call_postvisit( node ); \
    82
    93#define MUTATE_START( node )  \
    104        call_premutate( node ); \
    115
     6
    127#define MUTATE_END( type, node )                \
    138        return call_postmutate< type * >( node ); \
     
    1510
    1611#define VISIT_BODY( node )    \
    17         VISIT_START( node );  \
     12        call_previsit( node );  \
    1813        Visitor::visit( node ); \
    19         VISIT_END( node ); \
     14        call_postvisit( node ); \
    2015
    2116
     
    4439                if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    4540                try {
    46                         (*i)->accept( *this );
     41                        *i = (*i)->accept( *this );
    4742                } catch ( SemanticError &e ) {
    4843                        errors.append( e );
     
    8378        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    8479
    85         maybeAccept( stmt, *this );
     80        Statement *newStmt = maybeVisit( stmt, *this );
    8681
    8782        StmtList_t* beforeStmts = get_beforeStmts();
    8883        StmtList_t* afterStmts  = get_afterStmts();
    8984
    90         if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }
     85        if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
    9186
    9287        CompoundStmt *compound = new CompoundStmt( noLabels );
    9388        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    94         compound->get_kids().push_back( stmt );
     89        compound->get_kids().push_back( newStmt );
    9590        if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    9691        return compound;
     
    192187}
    193188
    194 //--------------------------------------------------------------------------
    195 // CompoundStmt
    196189template< typename pass_type >
    197190void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
    198         VISIT_START( node );
    199         call_beginScope();
    200 
    201         visitStatementList( node->get_kids() );
    202 
    203         call_endScope();
    204         VISIT_END( node );
     191        VISIT_BODY( node );
    205192}
    206193
     
    216203}
    217204
    218 //--------------------------------------------------------------------------
    219 // ExprStmt
    220205template< typename pass_type >
    221206void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    222         VISIT_START( node );
    223         call_beginScope();
    224 
    225         visitExpression( node->get_expr() );
    226 
    227         call_endScope();
    228         VISIT_END( node );
     207        VISIT_BODY( node );
    229208}
    230209
     
    243222}
    244223
    245 //--------------------------------------------------------------------------
    246 // IfStmt
    247224template< typename pass_type >
    248225void PassVisitor< pass_type >::visit( IfStmt * node ) {
    249         VISIT_START( node );
    250 
    251         visitExpression( node->get_condition() );
    252         node->set_thenPart ( visitStatement( node->get_thenPart() ) );
    253         node->set_elsePart ( visitStatement( node->get_elsePart() ) );
    254 
    255         VISIT_END( node );
     226        VISIT_BODY( node );
    256227}
    257228
     
    267238}
    268239
    269 //--------------------------------------------------------------------------
    270 // WhileStmt
    271240template< typename pass_type >
    272241void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    273         VISIT_START( node );
    274 
    275         visitExpression( node->get_condition() );
    276         node->set_body( visitStatement( node->get_body() ) );
    277 
    278         VISIT_END( node );
     242        VISIT_BODY( node );
    279243}
    280244
     
    289253}
    290254
    291 //--------------------------------------------------------------------------
    292 // WhileStmt
     255
    293256template< typename pass_type >
    294257void PassVisitor< pass_type >::visit( ForStmt * node ) {
    295         VISIT_START( node );
    296 
    297         acceptAll( node->get_initialization(), *this );
    298         visitExpression( node->get_condition() );
    299         visitExpression( node->get_increment() );
    300         node->set_body( visitStatement( node->get_body() ) );
    301 
    302         VISIT_END( node );
     258        VISIT_BODY( node );
    303259}
    304260
     
    308264
    309265        mutateAll( node->get_initialization(), *this );
    310         node->set_condition( mutateExpression( node->get_condition() ) );
    311         node->set_increment( mutateExpression( node->get_increment() ) );
    312         node->set_body( mutateStatement( node->get_body() ) );
     266        node->set_condition(  mutateExpression( node->get_condition() ) );
     267        node->set_increment(  mutateExpression( node->get_increment() ) );
     268        node->set_body(  mutateStatement( node->get_body() ) );
    313269
    314270        MUTATE_END( Statement, node );
    315271}
    316272
    317 //--------------------------------------------------------------------------
    318 // SwitchStmt
    319273template< typename pass_type >
    320274void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    321         VISIT_START( node );
    322 
    323         visitExpression( node->get_condition() );
    324         visitStatementList( node->get_statements() );
    325 
    326         VISIT_END( node );
     275        VISIT_BODY( node );
    327276}
    328277
     
    337286}
    338287
    339 //--------------------------------------------------------------------------
    340 // SwitchStmt
    341288template< typename pass_type >
    342289void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    343         VISIT_START( node );
    344        
    345         visitExpression( node->get_condition() );
    346         visitStatementList( node->get_statements() );
    347        
    348         VISIT_END( node );
     290        VISIT_BODY( node );
    349291}
    350292
     
    364306}
    365307
    366 //--------------------------------------------------------------------------
    367 // ReturnStmt
    368308template< typename pass_type >
    369309void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
    370         VISIT_START( node );
    371 
    372         visitExpression( node->get_expr() );
    373 
    374         VISIT_END( node );
     310        VISIT_BODY( node );
    375311}
    376312
     
    384320}
    385321
    386 //--------------------------------------------------------------------------
    387 // TryStmt
    388322template< typename pass_type >
    389323void PassVisitor< pass_type >::visit( TryStmt * node ) {
    390         VISIT_START( node );
    391 
    392         maybeAccept( node->get_block(), *this );
    393         acceptAll( node->get_catchers(), *this );
    394 
    395         VISIT_END( node );
     324        VISIT_BODY( node );
    396325}
    397326
     
    406335}
    407336
    408 //--------------------------------------------------------------------------
    409 // CatchStmt
    410337template< typename pass_type >
    411338void PassVisitor< pass_type >::visit( CatchStmt * node ) {
    412         VISIT_START( node );
    413 
    414         node->set_body( visitStatement( node->get_body() ) );
    415         maybeAccept( node->get_decl(), *this );
    416 
    417         VISIT_END( node );
     339        VISIT_BODY( node );
    418340}
    419341
     
    453375}
    454376
    455 //--------------------------------------------------------------------------
    456 // UntypedExpr
    457377template< typename pass_type >
    458378void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
    459         VISIT_START( node );
    460 
    461         for ( auto expr : node->get_args() ) {
    462                 visitExpression( expr );
    463         }
    464 
    465         VISIT_END( node );
     379        VISIT_BODY( node );
    466380}
    467381
     
    622536}
    623537
    624 //--------------------------------------------------------------------------
    625 // UntypedExpr
    626538template< typename pass_type >
    627539void PassVisitor< pass_type >::visit( StmtExpr * node ) {
    628         VISIT_START( node );
    629 
    630         // don't want statements from outer CompoundStmts to be added to this StmtExpr
    631         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    632         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    633         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    634 
    635         Visitor::visit( node );
    636 
    637         VISIT_END( node );
     540        VISIT_BODY( node );
    638541}
    639542
     
    737640}
    738641
    739 //--------------------------------------------------------------------------
    740 // UntypedExpr
    741642template< typename pass_type >
    742643void PassVisitor< pass_type >::visit( SingleInit * node ) {
    743         VISIT_START( node );
    744 
    745         visitExpression( node->get_value() );
    746 
    747         VISIT_END( node );
     644        VISIT_BODY( node );
    748645}
    749646
Note: See TracChangeset for help on using the changeset viewer.