Ignore:
File:
1 edited

Legend:

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

    rd8893ca rc194661  
    5555                it,
    5656                [](Declaration * decl) -> auto {
    57                         return new DeclStmt( noLabels, decl );
     57                        return new DeclStmt( decl );
    5858                }
    5959        );
     
    6262
    6363template< typename pass_type >
    64 static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {
     64inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {
    6565        DeclList_t* beforeDecls = visitor.get_beforeDecls();
    6666        DeclList_t* afterDecls  = visitor.get_afterDecls();
    67         SemanticError errors;
     67        SemanticErrorException errors;
    6868
    6969        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     
    7676                        // run visitor on declaration
    7777                        maybeAccept_impl( *i, visitor );
    78                 } catch( SemanticError &e ) {
    79                         e.set_location( (*i)->location );
     78                } catch( SemanticErrorException &e ) {
    8079                        errors.append( e );
    8180                }
     
    9089
    9190template< typename pass_type >
    92 static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
     91inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
    9392        DeclList_t* beforeDecls = mutator.get_beforeDecls();
    9493        DeclList_t* afterDecls  = mutator.get_afterDecls();
    95         SemanticError errors;
     94        SemanticErrorException errors;
    9695
    9796        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     
    103102                        // run mutator on declaration
    104103                        maybeMutate_impl( *i, mutator );
    105                 } catch( SemanticError &e ) {
    106                         e.set_location( (*i)->location );
     104                } catch( SemanticErrorException &e ) {
    107105                        errors.append( e );
    108106                }
     
    127125inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) {
    128126        if ( ! visitor.get_visit_children() ) return;
    129         SemanticError errors;
     127        SemanticErrorException errors;
    130128        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    131129                try {
     
    133131                                (*i)->accept( visitor );
    134132                        }
    135                 } catch( SemanticError &e ) {
    136                         e.set_location( (*i)->location );
     133                } catch( SemanticErrorException &e ) {
    137134                        errors.append( e );
    138135                }
     
    155152inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
    156153        if ( ! mutator.get_visit_children() ) return;
    157         SemanticError errors;
     154        SemanticErrorException errors;
    158155        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    159156                try {
     
    162159                                assert( *i );
    163160                        } // if
    164                 } catch( SemanticError &e ) {
    165                         e.set_location( (*i)->location );
     161                } catch( SemanticErrorException &e ) {
    166162                        errors.append( e );
    167163                } // try
     
    176172void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
    177173        if ( ! get_visit_children() ) return;
    178         SemanticError errors;
     174        SemanticErrorException errors;
    179175
    180176        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     
    199195                            || ( empty( beforeDecls ) && empty( afterDecls )) );
    200196
    201                 } catch ( SemanticError &e ) {
    202                         e.set_location( (*i)->location );
     197                } catch ( SemanticErrorException &e ) {
    203198                        errors.append( e );
    204199                }
     
    251246            || ( empty( beforeDecls ) && empty( afterDecls )) );
    252247
    253         CompoundStmt *compound = new CompoundStmt( noLabels );
     248        CompoundStmt *compound = new CompoundStmt();
    254249        if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); }
    255250        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
     
    365360        maybeAccept_impl   ( node->attributes   , *this );
    366361
    367         if ( node->name != "" ) {
    368                 indexerAddId( node );
    369         }
     362        indexerAddId( node );
    370363
    371364        VISIT_END( node );
     
    381374        maybeMutate_impl   ( node->attributes   , *this );
    382375
    383         if ( node->name != "" ) {
    384                 indexerAddId( node );
    385         }
     376        indexerAddId( node );
    386377
    387378        MUTATE_END( DeclarationWithType, node );
     
    394385        VISIT_START( node );
    395386
    396         if ( node->name != "" ) {
    397                 indexerAddId( node );
    398         }
    399 
     387        indexerAddId( node );
     388
     389        maybeAccept_impl( node->withExprs, *this );
    400390        {
     391                // with clause introduces a level of scope (for the with expression members).
     392                // with clause exprs are added to the indexer before parameters so that parameters
     393                // shadow with exprs and not the other way around.
    401394                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    402                 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    403                 static ObjectDecl func(
    404                         "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    405                         new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    406                         nullptr
    407                 );
    408                 indexerAddId( &func );
    409                 maybeAccept_impl( node->type, *this );
    410                 maybeAccept_impl( node->statements, *this );
    411                 maybeAccept_impl( node->attributes, *this );
     395                indexerAddWith( node->withExprs, node );
     396                {
     397                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     398                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
     399                        static ObjectDecl func(
     400                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
     401                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
     402                                nullptr
     403                        );
     404                        indexerAddId( &func );
     405                        maybeAccept_impl( node->type, *this );
     406                        // function body needs to have the same scope as parameters - CompoundStmt will not enter
     407                        // a new scope if inFunction is true
     408                        ValueGuard< bool > oldInFunction( inFunction );
     409                        inFunction = true;
     410                        maybeAccept_impl( node->statements, *this );
     411                        maybeAccept_impl( node->attributes, *this );
     412                }
    412413        }
    413414
     
    419420        MUTATE_START( node );
    420421
    421         if ( node->name != "" ) {
    422                 indexerAddId( node );
    423         }
     422        indexerAddId( node );
    424423
    425424        {
     425                // with clause introduces a level of scope (for the with expression members).
     426                // with clause exprs are added to the indexer before parameters so that parameters
     427                // shadow with exprs and not the other way around.
    426428                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    427                 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    428                 static ObjectDecl func(
    429                         "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    430                         new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    431                         nullptr
    432                 );
    433                 indexerAddId( &func );
    434                 maybeMutate_impl( node->type, *this );
    435                 maybeMutate_impl( node->statements, *this );
    436                 maybeMutate_impl( node->attributes, *this );
     429                indexerAddWith( node->withExprs, node );
     430                {
     431                        auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     432                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
     433                        static ObjectDecl func(
     434                                "__func__", noStorageClasses, LinkageSpec::C, nullptr,
     435                                new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
     436                                nullptr
     437                        );
     438                        indexerAddId( &func );
     439                        maybeMutate_impl( node->type, *this );
     440                        // function body needs to have the same scope as parameters - CompoundStmt will not enter
     441                        // a new scope if inFunction is true
     442                        ValueGuard< bool > oldInFunction( inFunction );
     443                        inFunction = true;
     444                        maybeMutate_impl( node->statements, *this );
     445                        maybeMutate_impl( node->attributes, *this );
     446                }
    437447        }
    438448
     
    683693
    684694//--------------------------------------------------------------------------
     695// StaticAssertDecl
     696template< typename pass_type >
     697void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) {
     698        VISIT_START( node );
     699
     700        node->condition = visitExpression( node->condition );
     701        maybeAccept_impl( node->message, *this );
     702
     703        VISIT_END( node );
     704}
     705
     706template< typename pass_type >
     707StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
     708        MUTATE_START( node );
     709
     710        node->condition = mutateExpression( node->condition );
     711        maybeMutate_impl( node->message, *this );
     712
     713        MUTATE_END( StaticAssertDecl, node );
     714}
     715
     716//--------------------------------------------------------------------------
    685717// CompoundStmt
    686718template< typename pass_type >
     
    688720        VISIT_START( node );
    689721        {
    690                 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     722                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     723                ValueGuard< bool > oldInFunction( inFunction );
     724                auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
    691725                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
     726                inFunction = false;
    692727                visitStatementList( node->kids );
    693728        }
     
    699734        MUTATE_START( node );
    700735        {
    701                 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     736                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     737                ValueGuard< bool > oldInFunction( inFunction );
     738                auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
    702739                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
     740                inFunction = false;
    703741                mutateStatementList( node->kids );
    704742        }
     
    730768template< typename pass_type >
    731769void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    732         VISIT_BODY( node );
     770        VISIT_START( node )
     771
     772        maybeAccept_impl( node->instruction, *this );
     773        maybeAccept_impl( node->output, *this );
     774        maybeAccept_impl( node->input, *this );
     775        maybeAccept_impl( node->clobber, *this );
     776
     777        VISIT_END( node );
    733778}
    734779
    735780template< typename pass_type >
    736781Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    737         MUTATE_BODY( Statement, node );
     782        MUTATE_START( node );
     783
     784        maybeMutate_impl( node->instruction, *this );
     785        maybeMutate_impl( node->output, *this );
     786        maybeMutate_impl( node->input, *this );
     787        maybeMutate_impl( node->clobber, *this );
     788
     789        MUTATE_END( Statement, node );
     790}
     791
     792//--------------------------------------------------------------------------
     793// AsmStmt
     794template< typename pass_type >
     795void PassVisitor< pass_type >::visit( DirectiveStmt * node ) {
     796        VISIT_START( node )
     797
     798        VISIT_END( node );
     799}
     800
     801template< typename pass_type >
     802Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
     803        MUTATE_START( node );
     804
     805        MUTATE_END( Statement, node );
    738806}
    739807
     
    774842        VISIT_START( node );
    775843
    776         visitExpression( node->condition );
    777         node->body = visitStatement( node->body );
     844        {
     845                // while statements introduce a level of scope (for the initialization)
     846                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     847                maybeAccept_impl( node->initialization, *this );
     848                visitExpression ( node->condition );
     849                node->body = visitStatement( node->body );
     850        }
    778851
    779852        VISIT_END( node );
     
    784857        MUTATE_START( node );
    785858
    786         node->condition = mutateExpression( node->condition );
    787         node->body      = mutateStatement ( node->body      );
     859        {
     860                // while statements introduce a level of scope (for the initialization)
     861                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     862                maybeMutate_impl( node->initialization, *this );
     863                node->condition = mutateExpression( node->condition );
     864                node->body      = mutateStatement ( node->body      );
     865        }
     866
    788867
    789868        MUTATE_END( Statement, node );
     
    868947template< typename pass_type >
    869948void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    870         VISIT_BODY( node );
     949        VISIT_START( node );
     950        VISIT_END( node );
    871951}
    872952
    873953template< typename pass_type >
    874954Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
    875         MUTATE_BODY( Statement, node );
     955        MUTATE_START( node );
     956        MUTATE_END( Statement, node );
    876957}
    877958
     
    901982template< typename pass_type >
    902983void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
    903         VISIT_BODY( node );
     984        VISIT_START( node );
     985
     986        maybeAccept_impl( node->expr, *this );
     987        maybeAccept_impl( node->target, *this );
     988
     989        VISIT_END( node );
    904990}
    905991
    906992template< typename pass_type >
    907993Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
    908         MUTATE_BODY( Statement, node );
     994        MUTATE_START( node );
     995
     996        maybeMutate_impl( node->expr, *this );
     997        maybeMutate_impl( node->target, *this );
     998
     999        MUTATE_END( Statement, node );
    9091000}
    9101001
     
    9651056template< typename pass_type >
    9661057void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
    967         VISIT_BODY( node );
     1058        VISIT_START( node );
     1059
     1060        maybeAccept_impl( node->block, *this );
     1061
     1062        VISIT_END( node );
    9681063}
    9691064
    9701065template< typename pass_type >
    9711066Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    972         MUTATE_BODY( Statement, node );
     1067        MUTATE_START( node );
     1068
     1069        maybeMutate_impl( node->block, *this );
     1070
     1071        MUTATE_END( Statement, node );
    9731072}
    9741073
     
    9771076template< typename pass_type >
    9781077void PassVisitor< pass_type >::visit( WaitForStmt * node ) {
    979         VISIT_BODY( node );
     1078        VISIT_START( node );
     1079
     1080        for( auto & clause : node->clauses ) {
     1081                maybeAccept_impl( clause.target.function, *this );
     1082                maybeAccept_impl( clause.target.arguments, *this );
     1083
     1084                maybeAccept_impl( clause.statement, *this );
     1085                maybeAccept_impl( clause.condition, *this );
     1086        }
     1087
     1088        maybeAccept_impl( node->timeout.time, *this );
     1089        maybeAccept_impl( node->timeout.statement, *this );
     1090        maybeAccept_impl( node->timeout.condition, *this );
     1091        maybeAccept_impl( node->orelse.statement, *this );
     1092        maybeAccept_impl( node->orelse.condition, *this );
     1093
     1094        VISIT_END( node );
    9801095}
    9811096
    9821097template< typename pass_type >
    9831098Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
    984         MUTATE_BODY( Statement, node );
     1099        MUTATE_START( node );
     1100
     1101        for( auto & clause : node->clauses ) {
     1102                maybeMutate_impl( clause.target.function, *this );
     1103                maybeMutate_impl( clause.target.arguments, *this );
     1104
     1105                maybeMutate_impl( clause.statement, *this );
     1106                maybeMutate_impl( clause.condition, *this );
     1107        }
     1108
     1109        maybeMutate_impl( node->timeout.time, *this );
     1110        maybeMutate_impl( node->timeout.statement, *this );
     1111        maybeMutate_impl( node->timeout.condition, *this );
     1112        maybeMutate_impl( node->orelse.statement, *this );
     1113        maybeMutate_impl( node->orelse.condition, *this );
     1114
     1115        MUTATE_END( Statement, node );
    9851116}
    9861117
     
    9961127                // catch statements introduce a level of scope (for the caught exception)
    9971128                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    998                 indexerAddWith( node );
     1129                indexerAddWith( node->exprs, node );
    9991130                maybeAccept_impl( node->stmt, *this );
    10001131        }
     
    10091140                // catch statements introduce a level of scope (for the caught exception)
    10101141                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1011                 indexerAddWith( node );
     1142                indexerAddWith( node->exprs, node );
    10121143                maybeMutate_impl( node->stmt, *this );
    10131144        }
     
    10191150template< typename pass_type >
    10201151void PassVisitor< pass_type >::visit( NullStmt * node ) {
    1021         VISIT_BODY( node );
     1152        VISIT_START( node );
     1153        VISIT_END( node );
    10221154}
    10231155
    10241156template< typename pass_type >
    10251157NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
    1026         MUTATE_BODY( NullStmt, node );
     1158        MUTATE_START( node );
     1159        MUTATE_END( NullStmt, node );
    10271160}
    10281161
     
    10311164template< typename pass_type >
    10321165void PassVisitor< pass_type >::visit( DeclStmt * node ) {
    1033         VISIT_BODY( node );
     1166        VISIT_START( node );
     1167
     1168        maybeAccept_impl( node->decl, *this );
     1169
     1170        VISIT_END( node );
    10341171}
    10351172
    10361173template< typename pass_type >
    10371174Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
    1038         MUTATE_BODY( Statement, node );
     1175        MUTATE_START( node );
     1176
     1177        maybeMutate_impl( node->decl, *this );
     1178
     1179        MUTATE_END( Statement, node );
    10391180}
    10401181
     
    10431184template< typename pass_type >
    10441185void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
    1045         VISIT_BODY( node );
     1186        VISIT_START( node );
     1187
     1188        maybeAccept_impl( node->callStmt, *this );
     1189
     1190        VISIT_END( node );
    10461191}
    10471192
    10481193template< typename pass_type >
    10491194Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
    1050         MUTATE_BODY( Statement, node );
     1195        MUTATE_START( node );
     1196
     1197        maybeMutate_impl( node->callStmt, *this );
     1198
     1199        MUTATE_END( Statement, node );
    10511200}
    10521201
     
    11411290template< typename pass_type >
    11421291Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
     1292        MUTATE_START( node );
     1293
     1294        indexerScopedMutate( node->env   , *this );
     1295        indexerScopedMutate( node->result, *this );
     1296        maybeMutate_impl   ( node->arg   , *this );
     1297
     1298        MUTATE_END( Expression, node );
     1299}
     1300
     1301//--------------------------------------------------------------------------
     1302// KeywordCastExpr
     1303template< typename pass_type >
     1304void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
     1305        VISIT_START( node );
     1306
     1307        indexerScopedAccept( node->result, *this );
     1308        maybeAccept_impl        ( node->arg   , *this );
     1309
     1310        VISIT_END( node );
     1311}
     1312
     1313template< typename pass_type >
     1314Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
    11431315        MUTATE_START( node );
    11441316
     
    14041576        indexerScopedAccept( node->result, *this );
    14051577        maybeAccept_impl   ( node->type  , *this );
    1406         maybeAccept_impl   ( node->member, *this );
    14071578
    14081579        VISIT_END( node );
     
    14161587        indexerScopedMutate( node->result, *this );
    14171588        maybeMutate_impl   ( node->type  , *this );
    1418         maybeMutate_impl   ( node->member, *this );
    14191589
    14201590        MUTATE_END( Expression, node );
     
    18532023}
    18542024
     2025//--------------------------------------------------------------------------
     2026// UntypedInitExpr
     2027template< typename pass_type >
     2028void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) {
     2029        VISIT_START( node );
     2030
     2031        indexerScopedAccept( node->result, *this );
     2032        maybeAccept_impl   ( node->expr  , *this );
     2033        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
     2034
     2035        VISIT_END( node );
     2036}
     2037
     2038template< typename pass_type >
     2039Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
     2040        MUTATE_START( node );
     2041
     2042        indexerScopedMutate( node->env   , *this );
     2043        indexerScopedMutate( node->result, *this );
     2044        maybeMutate_impl   ( node->expr  , *this );
     2045        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
     2046
     2047        MUTATE_END( Expression, node );
     2048}
     2049
     2050//--------------------------------------------------------------------------
     2051// InitExpr
     2052template< typename pass_type >
     2053void PassVisitor< pass_type >::visit( InitExpr * node ) {
     2054        VISIT_START( node );
     2055
     2056        indexerScopedAccept( node->result, *this );
     2057        maybeAccept_impl   ( node->expr  , *this );
     2058        maybeAccept_impl   ( node->designation, *this );
     2059
     2060        VISIT_END( node );
     2061}
     2062
     2063template< typename pass_type >
     2064Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
     2065        MUTATE_START( node );
     2066
     2067        indexerScopedMutate( node->env   , *this );
     2068        indexerScopedMutate( node->result, *this );
     2069        maybeMutate_impl   ( node->expr  , *this );
     2070        maybeMutate_impl   ( node->designation, *this );
     2071
     2072        MUTATE_END( Expression, node );
     2073}
     2074
     2075//--------------------------------------------------------------------------
     2076// DeletedExpr
     2077template< typename pass_type >
     2078void PassVisitor< pass_type >::visit( DeletedExpr * node ) {
     2079        VISIT_START( node );
     2080
     2081        indexerScopedAccept( node->result, *this );
     2082        maybeAccept_impl( node->expr, *this );
     2083        // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
     2084
     2085        VISIT_END( node );
     2086}
     2087
     2088template< typename pass_type >
     2089Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
     2090        MUTATE_START( node );
     2091
     2092        indexerScopedMutate( node->env, *this );
     2093        indexerScopedMutate( node->result, *this );
     2094        maybeMutate_impl( node->expr, *this );
     2095
     2096        MUTATE_END( Expression, node );
     2097}
     2098
     2099//--------------------------------------------------------------------------
     2100// DefaultArgExpr
     2101template< typename pass_type >
     2102void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
     2103        VISIT_START( node );
     2104
     2105        indexerScopedAccept( node->result, *this );
     2106        maybeAccept_impl( node->expr, *this );
     2107
     2108        VISIT_END( node );
     2109}
     2110
     2111template< typename pass_type >
     2112Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
     2113        MUTATE_START( node );
     2114
     2115        indexerScopedMutate( node->env, *this );
     2116        indexerScopedMutate( node->result, *this );
     2117        maybeMutate_impl( node->expr, *this );
     2118
     2119        MUTATE_END( Expression, node );
     2120}
     2121
     2122//--------------------------------------------------------------------------
     2123// GenericExpr
     2124template< typename pass_type >
     2125void PassVisitor< pass_type >::visit( GenericExpr * node ) {
     2126        VISIT_START( node );
     2127
     2128        indexerScopedAccept( node->result, *this );
     2129        maybeAccept_impl( node->control, *this );
     2130        for ( GenericExpr::Association & assoc : node->associations ) {
     2131                indexerScopedAccept( assoc.type, *this );
     2132                maybeAccept_impl( assoc.expr, *this );
     2133        }
     2134
     2135        VISIT_END( node );
     2136}
     2137
     2138template< typename pass_type >
     2139Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) {
     2140        MUTATE_START( node );
     2141
     2142        indexerScopedMutate( node->env, *this );
     2143        indexerScopedMutate( node->result, *this );
     2144        maybeMutate_impl( node->control, *this );
     2145        for ( GenericExpr::Association & assoc : node->associations ) {
     2146                indexerScopedMutate( assoc.type, *this );
     2147                maybeMutate_impl( assoc.expr, *this );
     2148        }
     2149
     2150        MUTATE_END( Expression, node );
     2151}
     2152
     2153//--------------------------------------------------------------------------
     2154// VoidType
    18552155template< typename pass_type >
    18562156void PassVisitor< pass_type >::visit( VoidType * node ) {
    1857         VISIT_BODY( node );
    1858 }
    1859 
     2157        VISIT_START( node );
     2158
     2159        maybeAccept_impl( node->forall, *this );
     2160
     2161        VISIT_END( node );
     2162}
     2163
     2164template< typename pass_type >
     2165Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
     2166        MUTATE_START( node );
     2167
     2168        maybeMutate_impl( node->forall, *this );
     2169
     2170        MUTATE_END( Type, node );
     2171}
     2172
     2173//--------------------------------------------------------------------------
     2174// BasicType
    18602175template< typename pass_type >
    18612176void PassVisitor< pass_type >::visit( BasicType * node ) {
    1862         VISIT_BODY( node );
    1863 }
    1864 
     2177        VISIT_START( node );
     2178
     2179        maybeAccept_impl( node->forall, *this );
     2180
     2181        VISIT_END( node );
     2182}
     2183
     2184template< typename pass_type >
     2185Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
     2186        MUTATE_START( node );
     2187
     2188        maybeMutate_impl( node->forall, *this );
     2189
     2190        MUTATE_END( Type, node );
     2191}
     2192
     2193//--------------------------------------------------------------------------
     2194// PointerType
    18652195template< typename pass_type >
    18662196void PassVisitor< pass_type >::visit( PointerType * node ) {
    1867         VISIT_BODY( node );
    1868 }
    1869 
     2197        VISIT_START( node );
     2198
     2199        maybeAccept_impl( node->forall, *this );
     2200        // xxx - should PointerType visit/mutate dimension?
     2201        maybeAccept_impl( node->base, *this );
     2202
     2203        VISIT_END( node );
     2204}
     2205
     2206template< typename pass_type >
     2207Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
     2208        MUTATE_START( node );
     2209
     2210        maybeMutate_impl( node->forall, *this );
     2211        // xxx - should PointerType visit/mutate dimension?
     2212        maybeMutate_impl( node->base, *this );
     2213
     2214        MUTATE_END( Type, node );
     2215}
     2216
     2217//--------------------------------------------------------------------------
     2218// ArrayType
    18702219template< typename pass_type >
    18712220void PassVisitor< pass_type >::visit( ArrayType * node ) {
    1872         VISIT_BODY( node );
    1873 }
    1874 
     2221        VISIT_START( node );
     2222
     2223        maybeAccept_impl( node->forall, *this );
     2224        maybeAccept_impl( node->dimension, *this );
     2225        maybeAccept_impl( node->base, *this );
     2226
     2227        VISIT_END( node );
     2228}
     2229
     2230template< typename pass_type >
     2231Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
     2232        MUTATE_START( node );
     2233
     2234        maybeMutate_impl( node->forall, *this );
     2235        maybeMutate_impl( node->dimension, *this );
     2236        maybeMutate_impl( node->base, *this );
     2237
     2238        MUTATE_END( Type, node );
     2239}
     2240
     2241//--------------------------------------------------------------------------
     2242// ReferenceType
    18752243template< typename pass_type >
    18762244void PassVisitor< pass_type >::visit( ReferenceType * node ) {
    1877         VISIT_BODY( node );
    1878 }
    1879 
     2245        VISIT_START( node );
     2246
     2247        maybeAccept_impl( node->forall, *this );
     2248        maybeAccept_impl( node->base, *this );
     2249
     2250        VISIT_END( node );
     2251}
     2252
     2253template< typename pass_type >
     2254Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
     2255        MUTATE_START( node );
     2256
     2257        maybeMutate_impl( node->forall, *this );
     2258        maybeMutate_impl( node->base, *this );
     2259
     2260        MUTATE_END( Type, node );
     2261}
     2262
     2263//--------------------------------------------------------------------------
     2264// QualifiedType
     2265template< typename pass_type >
     2266void PassVisitor< pass_type >::visit( QualifiedType * node ) {
     2267        VISIT_START( node );
     2268
     2269        maybeAccept_impl( node->forall, *this );
     2270        maybeAccept_impl( node->parent, *this );
     2271        maybeAccept_impl( node->child, *this );
     2272
     2273        VISIT_END( node );
     2274}
     2275
     2276template< typename pass_type >
     2277Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) {
     2278        MUTATE_START( node );
     2279
     2280        maybeMutate_impl( node->forall, *this );
     2281        maybeMutate_impl( node->parent, *this );
     2282        maybeMutate_impl( node->child, *this );
     2283
     2284        MUTATE_END( Type, node );
     2285}
     2286
     2287//--------------------------------------------------------------------------
     2288// FunctionType
    18802289template< typename pass_type >
    18812290void PassVisitor< pass_type >::visit( FunctionType * node ) {
    1882         VISIT_BODY( node );
     2291        VISIT_START( node );
     2292
     2293        maybeAccept_impl( node->forall, *this );
     2294        maybeAccept_impl( node->returnVals, *this );
     2295        maybeAccept_impl( node->parameters, *this );
     2296
     2297        VISIT_END( node );
     2298}
     2299
     2300template< typename pass_type >
     2301Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
     2302        MUTATE_START( node );
     2303
     2304        maybeMutate_impl( node->forall, *this );
     2305        maybeMutate_impl( node->returnVals, *this );
     2306        maybeMutate_impl( node->parameters, *this );
     2307
     2308        MUTATE_END( Type, node );
    18832309}
    18842310
     
    19512377template< typename pass_type >
    19522378void PassVisitor< pass_type >::visit( EnumInstType * node ) {
    1953         VISIT_BODY( node );
     2379        VISIT_START( node );
     2380
     2381        maybeAccept_impl( node->forall, *this );
     2382        maybeAccept_impl( node->parameters, *this );
     2383
     2384        VISIT_END( node );
    19542385}
    19552386
    19562387template< typename pass_type >
    19572388Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
    1958         MUTATE_BODY( Type, node );
     2389        MUTATE_START( node );
     2390
     2391        maybeMutate_impl( node->forall, *this );
     2392        maybeMutate_impl( node->parameters, *this );
     2393
     2394        MUTATE_END( Type, node );
    19592395}
    19602396
     
    19852421template< typename pass_type >
    19862422void PassVisitor< pass_type >::visit( TypeInstType * node ) {
    1987         VISIT_BODY( node );
    1988 }
    1989 
     2423        VISIT_START( node );
     2424
     2425        maybeAccept_impl( node->forall    , *this );
     2426        maybeAccept_impl( node->parameters, *this );
     2427
     2428        VISIT_END( node );
     2429}
     2430
     2431template< typename pass_type >
     2432Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
     2433        MUTATE_START( node );
     2434
     2435        maybeMutate_impl( node->forall    , *this );
     2436        maybeMutate_impl( node->parameters, *this );
     2437
     2438        MUTATE_END( Type, node );
     2439}
     2440
     2441//--------------------------------------------------------------------------
     2442// TupleType
    19902443template< typename pass_type >
    19912444void PassVisitor< pass_type >::visit( TupleType * node ) {
    1992         VISIT_BODY( node );
    1993 }
    1994 
     2445        VISIT_START( node );
     2446
     2447        maybeAccept_impl( node->forall, *this );
     2448        maybeAccept_impl( node->types, *this );
     2449        maybeAccept_impl( node->members, *this );
     2450
     2451        VISIT_END( node );
     2452}
     2453
     2454template< typename pass_type >
     2455Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
     2456        MUTATE_START( node );
     2457
     2458        maybeMutate_impl( node->forall, *this );
     2459        maybeMutate_impl( node->types, *this );
     2460        maybeMutate_impl( node->members, *this );
     2461
     2462        MUTATE_END( Type, node );
     2463}
     2464
     2465//--------------------------------------------------------------------------
     2466// TypeofType
    19952467template< typename pass_type >
    19962468void PassVisitor< pass_type >::visit( TypeofType * node ) {
    1997         VISIT_BODY( node );
    1998 }
    1999 
     2469        VISIT_START( node );
     2470
     2471        assert( node->expr );
     2472        maybeAccept_impl( node->expr, *this );
     2473
     2474        VISIT_END( node );
     2475}
     2476
     2477template< typename pass_type >
     2478Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
     2479        MUTATE_START( node );
     2480
     2481        assert( node->expr );
     2482        maybeMutate_impl( node->expr, *this );
     2483
     2484        MUTATE_END( Type, node );
     2485}
     2486
     2487//--------------------------------------------------------------------------
     2488// AttrType
    20002489template< typename pass_type >
    20012490void PassVisitor< pass_type >::visit( AttrType * node ) {
    2002         VISIT_BODY( node );
    2003 }
    2004 
     2491        VISIT_START( node );
     2492
     2493        if ( node->isType ) {
     2494                assert( node->type );
     2495                maybeAccept_impl( node->type, *this );
     2496        } else {
     2497                assert( node->expr );
     2498                maybeAccept_impl( node->expr, *this );
     2499        } // if
     2500
     2501        VISIT_END( node );
     2502}
     2503
     2504template< typename pass_type >
     2505Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
     2506        MUTATE_START( node );
     2507
     2508        if ( node->isType ) {
     2509                assert( node->type );
     2510                maybeMutate_impl( node->type, *this );
     2511        } else {
     2512                assert( node->expr );
     2513                maybeMutate_impl( node->expr, *this );
     2514        } // if
     2515
     2516        MUTATE_END( Type, node );
     2517}
     2518
     2519//--------------------------------------------------------------------------
     2520// VarArgsType
    20052521template< typename pass_type >
    20062522void PassVisitor< pass_type >::visit( VarArgsType * node ) {
    2007         VISIT_BODY( node );
    2008 }
    2009 
     2523        VISIT_START( node );
     2524
     2525        maybeAccept_impl( node->forall, *this );
     2526
     2527        VISIT_END( node );
     2528}
     2529
     2530template< typename pass_type >
     2531Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
     2532        MUTATE_START( node );
     2533
     2534        maybeMutate_impl( node->forall, *this );
     2535
     2536        MUTATE_END( Type, node );
     2537}
     2538
     2539//--------------------------------------------------------------------------
     2540// ZeroType
    20102541template< typename pass_type >
    20112542void PassVisitor< pass_type >::visit( ZeroType * node ) {
    2012         VISIT_BODY( node );
    2013 }
    2014 
     2543        VISIT_START( node );
     2544
     2545        maybeAccept_impl( node->forall, *this );
     2546
     2547        VISIT_END( node );
     2548}
     2549
     2550template< typename pass_type >
     2551Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
     2552        MUTATE_START( node );
     2553
     2554        maybeMutate_impl( node->forall, *this );
     2555
     2556        MUTATE_END( Type, node );
     2557}
     2558
     2559//--------------------------------------------------------------------------
     2560// OneType
    20152561template< typename pass_type >
    20162562void PassVisitor< pass_type >::visit( OneType * node ) {
    2017         VISIT_BODY( node );
    2018 }
    2019 
     2563        VISIT_START( node );
     2564
     2565        maybeAccept_impl( node->forall, *this );
     2566
     2567        VISIT_END( node );
     2568}
     2569
     2570template< typename pass_type >
     2571Type * PassVisitor< pass_type >::mutate( OneType * node ) {
     2572        MUTATE_START( node );
     2573
     2574        maybeMutate_impl( node->forall, *this );
     2575
     2576        MUTATE_END( Type, node );
     2577}
     2578
     2579//--------------------------------------------------------------------------
     2580// GlobalScopeType
     2581template< typename pass_type >
     2582void PassVisitor< pass_type >::visit( GlobalScopeType * node ) {
     2583        VISIT_START( node );
     2584
     2585        maybeAccept_impl( node->forall, *this );
     2586
     2587        VISIT_END( node );
     2588}
     2589
     2590template< typename pass_type >
     2591Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) {
     2592        MUTATE_START( node );
     2593
     2594        maybeMutate_impl( node->forall, *this );
     2595
     2596        MUTATE_END( Type, node );
     2597}
     2598
     2599//--------------------------------------------------------------------------
     2600// Designation
    20202601template< typename pass_type >
    20212602void PassVisitor< pass_type >::visit( Designation * node ) {
    20222603        VISIT_START( node );
    20232604
    2024         maybeAccept_impl( node->get_designators(), *this );
     2605        maybeAccept_impl( node->designators, *this );
    20252606
    20262607        VISIT_END( node );
     
    20312612        MUTATE_START( node );
    20322613
    2033         maybeMutate_impl( node->get_designators(), *this );
     2614        maybeMutate_impl( node->designators, *this );
    20342615
    20352616        MUTATE_END( Designation, node );
     
    20422623        VISIT_START( node );
    20432624
    2044         visitExpression( node->get_value() );
     2625        visitExpression( node->value );
    20452626
    20462627        VISIT_END( node );
     
    20512632        MUTATE_START( node );
    20522633
    2053         node->set_value( mutateExpression( node->get_value() ) );
     2634        node->value = mutateExpression( node->value );
    20542635
    20552636        MUTATE_END( Initializer, node );
    20562637}
    20572638
     2639//--------------------------------------------------------------------------
     2640// ListInit
    20582641template< typename pass_type >
    20592642void PassVisitor< pass_type >::visit( ListInit * node ) {
    2060         VISIT_BODY( node );
    2061 }
    2062 
     2643        VISIT_START( node );
     2644
     2645        maybeAccept_impl( node->designations, *this );
     2646        maybeAccept_impl( node->initializers, *this );
     2647
     2648        VISIT_END( node );
     2649}
     2650
     2651template< typename pass_type >
     2652Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
     2653        MUTATE_START( node );
     2654
     2655        maybeMutate_impl( node->designations, *this );
     2656        maybeMutate_impl( node->initializers, *this );
     2657
     2658        MUTATE_END( Initializer, node );
     2659}
     2660
     2661//--------------------------------------------------------------------------
     2662// ConstructorInit
    20632663template< typename pass_type >
    20642664void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
    2065         VISIT_BODY( node );
    2066 }
    2067 
     2665        VISIT_START( node );
     2666
     2667        maybeAccept_impl( node->ctor, *this );
     2668        maybeAccept_impl( node->dtor, *this );
     2669        maybeAccept_impl( node->init, *this );
     2670
     2671        VISIT_END( node );
     2672}
     2673
     2674template< typename pass_type >
     2675Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
     2676        MUTATE_START( node );
     2677
     2678        maybeMutate_impl( node->ctor, *this );
     2679        maybeMutate_impl( node->dtor, *this );
     2680        maybeMutate_impl( node->init, *this );
     2681
     2682        MUTATE_END( Initializer, node );
     2683}
     2684
     2685//--------------------------------------------------------------------------
     2686// Subrange
    20682687template< typename pass_type >
    20692688void PassVisitor< pass_type >::visit( Subrange * node ) {
    2070         VISIT_BODY( node );
    2071 }
    2072 
     2689        VISIT_START( node );
     2690
     2691        VISIT_END( node );
     2692}
     2693
     2694template< typename pass_type >
     2695Subrange * PassVisitor< pass_type >::mutate( Subrange * node  )  {
     2696        MUTATE_START( node );
     2697
     2698        MUTATE_END( Subrange, node );
     2699}
     2700
     2701//--------------------------------------------------------------------------
     2702// Attribute
    20732703template< typename pass_type >
    20742704void PassVisitor< pass_type >::visit( Constant * node ) {
    2075         VISIT_BODY( node );
    2076 }
    2077 
     2705        VISIT_START( node );
     2706
     2707        VISIT_END( node );
     2708}
     2709
     2710template< typename pass_type >
     2711Constant * PassVisitor< pass_type >::mutate( Constant * node  )  {
     2712        MUTATE_START( node );
     2713
     2714        MUTATE_END( Constant, node );
     2715}
     2716
     2717//--------------------------------------------------------------------------
     2718// Attribute
    20782719template< typename pass_type >
    20792720void PassVisitor< pass_type >::visit( Attribute * node ) {
    2080         VISIT_BODY( node );
    2081 }
    2082 
    2083 //---------------------------------------------------------------------------------------------------------------
    2084 template< typename pass_type >
    2085 Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
    2086         MUTATE_BODY( Type, node );
    2087 }
    2088 
    2089 template< typename pass_type >
    2090 Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
    2091         MUTATE_BODY( Type, node );
    2092 }
    2093 
    2094 template< typename pass_type >
    2095 Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
    2096         MUTATE_BODY( Type, node );
    2097 }
    2098 
    2099 template< typename pass_type >
    2100 Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
    2101         MUTATE_BODY( Type, node );
    2102 }
    2103 
    2104 template< typename pass_type >
    2105 Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
    2106         MUTATE_BODY( Type, node );
    2107 }
    2108 
    2109 template< typename pass_type >
    2110 Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
    2111         MUTATE_BODY( Type, node );
    2112 }
    2113 
    2114 template< typename pass_type >
    2115 Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
    2116         MUTATE_BODY( Type, node );
    2117 }
    2118 
    2119 template< typename pass_type >
    2120 Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
    2121         MUTATE_BODY( Type, node );
    2122 }
    2123 
    2124 template< typename pass_type >
    2125 Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
    2126         MUTATE_BODY( Type, node );
    2127 }
    2128 
    2129 template< typename pass_type >
    2130 Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
    2131         MUTATE_BODY( Type, node );
    2132 }
    2133 
    2134 template< typename pass_type >
    2135 Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
    2136         MUTATE_BODY( Type, node );
    2137 }
    2138 
    2139 template< typename pass_type >
    2140 Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
    2141         MUTATE_BODY( Type, node );
    2142 }
    2143 
    2144 template< typename pass_type >
    2145 Type * PassVisitor< pass_type >::mutate( OneType * node ) {
    2146         MUTATE_BODY( Type, node );
    2147 }
    2148 
    2149 template< typename pass_type >
    2150 Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
    2151         MUTATE_BODY( Initializer, node );
    2152 }
    2153 
    2154 template< typename pass_type >
    2155 Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
    2156         MUTATE_BODY( Initializer, node );
    2157 }
    2158 
    2159 template< typename pass_type >
    2160 Subrange * PassVisitor< pass_type >::mutate( Subrange * node  )  {
    2161         MUTATE_BODY( Subrange, node );
    2162 }
    2163 
    2164 template< typename pass_type >
    2165 Constant * PassVisitor< pass_type >::mutate( Constant * node  )  {
    2166         MUTATE_BODY( Constant, node );
     2721        VISIT_START( node );
     2722
     2723        maybeAccept_impl( node->parameters, *this );
     2724
     2725        VISIT_END( node );
    21672726}
    21682727
    21692728template< typename pass_type >
    21702729Attribute * PassVisitor< pass_type >::mutate( Attribute * node  )  {
    2171         MUTATE_BODY( Attribute, node );
    2172 }
    2173 
     2730        MUTATE_START( node );
     2731
     2732        maybeMutate_impl( node->parameters, *this );
     2733
     2734        MUTATE_END( Attribute, node );
     2735}
     2736
     2737//--------------------------------------------------------------------------
     2738// TypeSubstitution
    21742739template< typename pass_type >
    21752740TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
Note: See TracChangeset for help on using the changeset viewer.