Ignore:
File:
1 edited

Legend:

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

    r033ff37 ree3c93d  
    2020
    2121#define MUTATE_END( type, node )                \
    22         auto __return = call_postmutate< type * >( node ); \
    23         assert( __return ); \
    24         return __return;
     22        return call_postmutate< type * >( node ); \
     23
     24
     25#define VISIT_BODY( node )          \
     26        VISIT_START( node );          \
     27        if( children_guard ) {        \
     28                Visitor::visit( node ); \
     29        }                             \
     30        VISIT_END( node );            \
     31
     32
     33#define MUTATE_BODY( type, node )    \
     34        MUTATE_START( node );          \
     35        if( children_guard ) {         \
     36                Mutator::mutate( node ); \
     37        }                              \
     38        MUTATE_END( type, node );      \
     39
    2540
    2641
     
    5267        SemanticErrorException errors;
    5368
    54         pass_visitor_stats.depth++;
    55         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    56         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    5769        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
    58 
    59 
    6070                // splice in new declarations after previous decl
    6171                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     
    7383                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    7484        }
    75         pass_visitor_stats.depth--;
    76         if ( ! errors.isEmpty() ) {
    77                 throw errors;
    78         }
    79 }
    80 
    81 template< typename pass_type >
    82 inline void acceptAll( const std::list< const Declaration * > & decls, PassVisitor< pass_type >& visitor ) {
    83         SemanticErrorException errors;
    84 
    85         pass_visitor_stats.depth++;
    86         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    87         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    88         for ( const Declaration * decl : decls ) {
    89                 try {
    90                         // run visitor on declaration
    91                         maybeAccept_impl( decl, visitor );
    92                 }
    93                 catch( SemanticErrorException &e ) {
    94                         errors.append( e );
    95                 }
    96         }
    97         pass_visitor_stats.depth--;
    9885        if ( ! errors.isEmpty() ) {
    9986                throw errors;
     
    10794        SemanticErrorException errors;
    10895
    109         pass_visitor_stats.depth++;
    110         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    111         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    11296        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
    11397                // splice in new declarations after previous decl
     
    125109                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    126110        }
    127         pass_visitor_stats.depth--;
    128111        if ( ! errors.isEmpty() ) {
    129112                throw errors;
     
    139122}
    140123
    141 template< typename TreeType, typename pass_type >
    142 inline void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_type > & visitor ) {
    143         if ( ! visitor.get_visit_children() ) return;
    144         if ( tree ) {
    145                 tree->accept( visitor );
    146         }
    147 }
    148 
    149124template< typename Container, typename pass_type >
    150125inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) {
    151126        if ( ! visitor.get_visit_children() ) return;
    152127        SemanticErrorException errors;
    153 
    154         pass_visitor_stats.depth++;
    155         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    156         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    157128        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    158129                try {
     
    164135                }
    165136        }
    166         pass_visitor_stats.depth--;
    167         if ( ! errors.isEmpty() ) {
    168                 throw errors;
    169         }
    170 }
    171 
    172 template< typename Container, typename pass_type >
    173 inline void maybeAccept_impl( const Container & container, PassVisitor< pass_type > & visitor ) {
    174         if ( ! visitor.get_visit_children() ) return;
    175         SemanticErrorException errors;
    176 
    177         pass_visitor_stats.depth++;
    178         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    179         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    180         for ( const auto & i : container ) {
    181                 try {
    182                         if ( i ) {
    183                                 i->accept( visitor );
    184                         }
    185                 } catch( SemanticErrorException &e ) {
    186                         errors.append( e );
    187                 }
    188         }
    189         pass_visitor_stats.depth--;
    190137        if ( ! errors.isEmpty() ) {
    191138                throw errors;
     
    204151template< typename Container, typename pass_type >
    205152inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
    206 
    207153        if ( ! mutator.get_visit_children() ) return;
    208154        SemanticErrorException errors;
    209 
    210         pass_visitor_stats.depth++;
    211         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    212         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    213155        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    214156                try {
     
    221163                } // try
    222164        } // for
    223         pass_visitor_stats.depth--;
    224165        if ( ! errors.isEmpty() ) {
    225166                throw errors;
     
    244185        DeclList_t* afterDecls  = get_afterDecls();
    245186
    246         pass_visitor_stats.depth++;
    247         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    248         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    249187        for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    250188
     
    254192                try {
    255193                        func( *i );
    256                         assert( *i );
    257194                        assert(( empty( beforeStmts ) && empty( afterStmts ))
    258195                            || ( empty( beforeDecls ) && empty( afterDecls )) );
     
    265202                if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    266203        }
    267         pass_visitor_stats.depth--;
    268204
    269205        if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
     
    280216
    281217template< typename pass_type >
    282 void PassVisitor< pass_type >::visitStatementList( const std::list< Statement * > & statements ) {
    283         if ( ! get_visit_children() ) return;
    284         SemanticErrorException errors;
    285 
    286         pass_visitor_stats.depth++;
    287         pass_visitor_stats.max->push(pass_visitor_stats.depth);
    288         pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    289         for ( const Statement * i : statements ) {
    290                 try {
    291                         maybeAccept_impl( i, *this );
    292                 } catch ( SemanticErrorException &e ) {
    293                         errors.append( e );
    294                 }
    295         }
    296         pass_visitor_stats.depth--;
    297         if ( !errors.isEmpty() ) { throw errors; }
    298 }
    299 
    300 template< typename pass_type >
    301218void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
    302219        handleStatementList( statements, [this]( Statement *& stmt) {
     
    312229
    313230        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    314         ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
     231        ValueGuardPtr< TypeSubstitution * >  oldEnv        ( get_env_ptr    () );
    315232        ValueGuardPtr< DeclList_t >          oldBeforeDecls( get_beforeDecls() );
    316233        ValueGuardPtr< DeclList_t >          oldAfterDecls ( get_afterDecls () );
     
    347264
    348265template< typename pass_type >
    349 void PassVisitor< pass_type >::visitStatement( const Statement * stmt ) {
    350         if ( ! get_visit_children() ) return;
    351 
    352         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    353         ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    354 
    355         maybeAccept_impl( stmt, *this );
    356 }
    357 
    358 template< typename pass_type >
    359266Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
    360267        return handleStatement( stmt, [this]( Statement * stmt ) {
     
    388295
    389296template< typename pass_type >
    390 void PassVisitor< pass_type >::visitExpression( const Expression * expr ) {
    391         if ( ! get_visit_children() ) return;
    392         if( !expr ) return;
    393 
    394         auto env_ptr = get_env_ptr();
    395         if ( env_ptr && expr->get_env() ) {
    396                 *env_ptr = expr->get_env();
    397         }
    398 
    399         maybeAccept_impl( expr, *this );
    400 }
    401 
    402 template< typename pass_type >
    403297Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
    404298        return handleExpression(expr, [this]( Expression * expr ) {
     
    410304template< typename TreeType, typename VisitorType >
    411305inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) {
    412         if ( ! visitor.get_visit_children() ) return;
    413         auto guard = makeFuncGuard(
    414                 [&visitor]() { visitor.indexerScopeEnter(); },
    415                 [&visitor]() { visitor.indexerScopeLeave(); }
    416         );
    417         maybeAccept_impl( tree, visitor );
    418 }
    419 
    420 template< typename TreeType, typename VisitorType >
    421 inline void indexerScopedAccept( const TreeType * tree, VisitorType & visitor ) {
    422306        if ( ! visitor.get_visit_children() ) return;
    423307        auto guard = makeFuncGuard(
     
    482366
    483367template< typename pass_type >
    484 void PassVisitor< pass_type >::visit( const ObjectDecl * node ) {
    485         VISIT_START( node );
    486 
    487         maybeAccept_impl( node->type         , *this );
    488         maybeAccept_impl( node->init         , *this );
    489         maybeAccept_impl( node->bitfieldWidth, *this );
    490         maybeAccept_impl( node->attributes   , *this );
    491 
    492         VISIT_END( node );
    493 }
    494 
    495 template< typename pass_type >
    496368DeclarationWithType * PassVisitor< pass_type >::mutate( ObjectDecl * node ) {
    497369        MUTATE_START( node );
     
    532404                        indexerAddId( &func );
    533405                        maybeAccept_impl( node->type, *this );
    534                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    535                         // a new scope if inFunction is true
    536                         ValueGuard< bool > oldInFunction( inFunction );
    537                         inFunction = true;
    538                         maybeAccept_impl( node->statements, *this );
    539                         maybeAccept_impl( node->attributes, *this );
    540                 }
    541         }
    542 
    543         VISIT_END( node );
    544 }
    545 
    546 template< typename pass_type >
    547 void PassVisitor< pass_type >::visit( const FunctionDecl * node ) {
    548         VISIT_START( node );
    549 
    550         indexerAddId( node );
    551 
    552         maybeAccept_impl( node->withExprs, *this );
    553         {
    554                 // with clause introduces a level of scope (for the with expression members).
    555                 // with clause exprs are added to the indexer before parameters so that parameters
    556                 // shadow with exprs and not the other way around.
    557                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    558                 indexerAddWith( node->withExprs, node );
    559                 {
    560                         auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    561                         // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    562                         static ObjectDecl func(
    563                                 "__func__", noStorageClasses, LinkageSpec::C, nullptr,
    564                                 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
    565                                 nullptr
    566                         );
    567                         indexerAddId( &func );
    568                         maybeAccept_impl( node->type, *this );
    569                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    570                         // a new scope if inFunction is true
    571                         ValueGuard< bool > oldInFunction( inFunction );
    572                         inFunction = true;
    573406                        maybeAccept_impl( node->statements, *this );
    574407                        maybeAccept_impl( node->attributes, *this );
     
    601434                        indexerAddId( &func );
    602435                        maybeMutate_impl( node->type, *this );
    603                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    604                         // a new scope if inFunction is true
    605                         ValueGuard< bool > oldInFunction( inFunction );
    606                         inFunction = true;
    607436                        maybeMutate_impl( node->statements, *this );
    608437                        maybeMutate_impl( node->attributes, *this );
     
    636465
    637466template< typename pass_type >
    638 void PassVisitor< pass_type >::visit( const StructDecl * node ) {
    639         VISIT_START( node );
     467Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) {
     468        MUTATE_START( node );
    640469
    641470        // make up a forward declaration and add it before processing the members
     
    645474        {
    646475                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     476                maybeMutate_impl( node->parameters, *this );
     477                maybeMutate_impl( node->members   , *this );
     478        }
     479
     480        // this addition replaces the forward declaration
     481        indexerAddStruct( node );
     482
     483        MUTATE_END( Declaration, node );
     484}
     485
     486//--------------------------------------------------------------------------
     487// UnionDecl
     488template< typename pass_type >
     489void PassVisitor< pass_type >::visit( UnionDecl * node ) {
     490        VISIT_START( node );
     491
     492        // make up a forward declaration and add it before processing the members
     493        indexerAddUnionFwd( node );
     494
     495        {
     496                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    647497                maybeAccept_impl( node->parameters, *this );
    648498                maybeAccept_impl( node->members   , *this );
    649499        }
    650500
    651         // this addition replaces the forward declaration
    652         indexerAddStruct( node );
    653 
    654         VISIT_END( node );
    655 }
    656 
    657 template< typename pass_type >
    658 Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) {
     501        indexerAddUnion( node );
     502
     503        VISIT_END( node );
     504}
     505
     506template< typename pass_type >
     507Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) {
    659508        MUTATE_START( node );
    660509
    661510        // make up a forward declaration and add it before processing the members
    662         // needs to be on the heap because addStruct saves the pointer
    663         indexerAddStructFwd( node );
     511        indexerAddUnionFwd( node );
    664512
    665513        {
     
    669517        }
    670518
    671         // this addition replaces the forward declaration
    672         indexerAddStruct( node );
    673 
    674         MUTATE_END( Declaration, node );
    675 }
    676 
    677 //--------------------------------------------------------------------------
    678 // UnionDecl
    679 template< typename pass_type >
    680 void PassVisitor< pass_type >::visit( UnionDecl * node ) {
    681         VISIT_START( node );
    682 
    683         // make up a forward declaration and add it before processing the members
    684         indexerAddUnionFwd( node );
    685 
    686         {
    687                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    688                 maybeAccept_impl( node->parameters, *this );
    689                 maybeAccept_impl( node->members   , *this );
    690         }
    691 
    692         indexerAddUnion( node );
    693 
    694         VISIT_END( node );
    695 }
    696 template< typename pass_type >
    697 void PassVisitor< pass_type >::visit( const UnionDecl * node ) {
    698         VISIT_START( node );
    699 
    700         // make up a forward declaration and add it before processing the members
    701         indexerAddUnionFwd( node );
    702 
    703         {
    704                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    705                 maybeAccept_impl( node->parameters, *this );
    706                 maybeAccept_impl( node->members   , *this );
    707         }
    708 
    709         indexerAddUnion( node );
    710 
    711         VISIT_END( node );
    712 }
    713 
    714 template< typename pass_type >
    715 Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) {
    716         MUTATE_START( node );
    717 
    718         // make up a forward declaration and add it before processing the members
    719         indexerAddUnionFwd( node );
    720 
    721         {
    722                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    723                 maybeMutate_impl( node->parameters, *this );
    724                 maybeMutate_impl( node->members   , *this );
    725         }
    726 
    727519        indexerAddUnion( node );
    728520
     
    746538
    747539template< typename pass_type >
    748 void PassVisitor< pass_type >::visit( const EnumDecl * node ) {
    749         VISIT_START( node );
    750 
    751         indexerAddEnum( node );
    752 
    753         // unlike structs, traits, and unions, enums inject their members into the global scope
    754         maybeAccept_impl( node->parameters, *this );
    755         maybeAccept_impl( node->members   , *this );
    756 
    757         VISIT_END( node );
    758 }
    759 
    760 template< typename pass_type >
    761540Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) {
    762541        MUTATE_START( node );
     
    775554template< typename pass_type >
    776555void PassVisitor< pass_type >::visit( TraitDecl * node ) {
    777         VISIT_START( node );
    778 
    779         {
    780                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    781                 maybeAccept_impl( node->parameters, *this );
    782                 maybeAccept_impl( node->members   , *this );
    783         }
    784 
    785         indexerAddTrait( node );
    786 
    787         VISIT_END( node );
    788 }
    789 
    790 template< typename pass_type >
    791 void PassVisitor< pass_type >::visit( const TraitDecl * node ) {
    792556        VISIT_START( node );
    793557
     
    842606}
    843607
    844 
    845 template< typename pass_type >
    846 void PassVisitor< pass_type >::visit( const TypeDecl * node ) {
    847         VISIT_START( node );
     608template< typename pass_type >
     609Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
     610        MUTATE_START( node );
    848611
    849612        {
    850613                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    851                 maybeAccept_impl( node->parameters, *this );
    852                 maybeAccept_impl( node->base      , *this );
     614                maybeMutate_impl( node->parameters, *this );
     615                maybeMutate_impl( node->base      , *this );
    853616        }
    854617
     
    858621        indexerAddType( node );
    859622
     623        maybeMutate_impl( node->assertions, *this );
     624
     625        indexerScopedMutate( node->init, *this );
     626
     627        MUTATE_END( Declaration, node );
     628}
     629
     630//--------------------------------------------------------------------------
     631// TypedefDecl
     632template< typename pass_type >
     633void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
     634        VISIT_START( node );
     635
     636        {
     637                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     638                maybeAccept_impl( node->parameters, *this );
     639                maybeAccept_impl( node->base      , *this );
     640        }
     641
     642        indexerAddType( node );
     643
    860644        maybeAccept_impl( node->assertions, *this );
    861645
    862         indexerScopedAccept( node->init, *this );
    863 
    864         VISIT_END( node );
    865 }
    866 
    867 template< typename pass_type >
    868 Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
     646        VISIT_END( node );
     647}
     648
     649template< typename pass_type >
     650Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) {
    869651        MUTATE_START( node );
    870652
     
    875657        }
    876658
    877         // see A NOTE ON THE ORDER OF TRAVERSAL, above
    878         // note that assertions come after the type is added to the symtab, since they are not part of the type proper
    879         // and may depend on the type itself
    880659        indexerAddType( node );
    881660
    882661        maybeMutate_impl( node->assertions, *this );
    883662
    884         indexerScopedMutate( node->init, *this );
    885 
    886663        MUTATE_END( Declaration, node );
    887664}
    888665
    889666//--------------------------------------------------------------------------
    890 // TypedefDecl
    891 template< typename pass_type >
    892 void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
    893         VISIT_START( node );
    894 
    895         {
    896                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    897                 maybeAccept_impl( node->parameters, *this );
    898                 maybeAccept_impl( node->base      , *this );
    899         }
    900 
    901         indexerAddType( node );
    902 
    903         maybeAccept_impl( node->assertions, *this );
    904 
    905         VISIT_END( node );
    906 }
    907 
    908 template< typename pass_type >
    909 void PassVisitor< pass_type >::visit( const TypedefDecl * node ) {
    910         VISIT_START( node );
    911 
    912         {
    913                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    914                 maybeAccept_impl( node->parameters, *this );
    915                 maybeAccept_impl( node->base      , *this );
    916         }
    917 
    918         indexerAddType( node );
    919 
    920         maybeAccept_impl( node->assertions, *this );
    921 
    922         VISIT_END( node );
    923 }
    924 
    925 template< typename pass_type >
    926 Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) {
    927         MUTATE_START( node );
    928 
    929         {
    930                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    931                 maybeMutate_impl( node->parameters, *this );
    932                 maybeMutate_impl( node->base      , *this );
    933         }
    934 
    935         indexerAddType( node );
    936 
    937         maybeMutate_impl( node->assertions, *this );
    938 
    939         MUTATE_END( Declaration, node );
    940 }
    941 
    942 //--------------------------------------------------------------------------
    943667// AsmDecl
    944668template< typename pass_type >
    945669void PassVisitor< pass_type >::visit( AsmDecl * node ) {
    946         VISIT_START( node );
    947 
    948         maybeAccept_impl( node->stmt, *this );
    949 
    950         VISIT_END( node );
    951 }
    952 
    953 template< typename pass_type >
    954 void PassVisitor< pass_type >::visit( const AsmDecl * node ) {
    955670        VISIT_START( node );
    956671
     
    982697
    983698template< typename pass_type >
    984 void PassVisitor< pass_type >::visit( const StaticAssertDecl * node ) {
    985         VISIT_START( node );
    986 
    987         visitExpression( node->condition );
    988         maybeAccept_impl( node->message, *this );
    989 
    990         VISIT_END( node );
    991 }
    992 
    993 template< typename pass_type >
    994699StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
    995700        MUTATE_START( node );
     
    1007712        VISIT_START( node );
    1008713        {
    1009                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    1010                 ValueGuard< bool > oldInFunction( inFunction );
    1011                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     714                auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1012715                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    1013                 inFunction = false;
    1014716                visitStatementList( node->kids );
    1015717        }
     
    1018720
    1019721template< typename pass_type >
    1020 void PassVisitor< pass_type >::visit( const CompoundStmt * node ) {
    1021         VISIT_START( node );
    1022         {
    1023                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    1024                 ValueGuard< bool > oldInFunction( inFunction );
    1025                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     722CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
     723        MUTATE_START( node );
     724        {
     725                auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1026726                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    1027                 inFunction = false;
    1028                 visitStatementList( node->kids );
    1029         }
    1030         VISIT_END( node );
    1031 }
    1032 
    1033 template< typename pass_type >
    1034 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
    1035         MUTATE_START( node );
    1036         {
    1037                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    1038                 ValueGuard< bool > oldInFunction( inFunction );
    1039                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
    1040                 auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    1041                 inFunction = false;
    1042727                mutateStatementList( node->kids );
    1043728        }
     
    1049734template< typename pass_type >
    1050735void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    1051         VISIT_START( node );
    1052 
    1053         visitExpression( node->expr );
    1054 
    1055         VISIT_END( node );
    1056 }
    1057 
    1058 template< typename pass_type >
    1059 void PassVisitor< pass_type >::visit( const ExprStmt * node ) {
    1060736        VISIT_START( node );
    1061737
     
    1089765
    1090766template< typename pass_type >
    1091 void PassVisitor< pass_type >::visit( const AsmStmt * node ) {
    1092         VISIT_START( node )
    1093 
    1094         maybeAccept_impl( node->instruction, *this );
    1095         maybeAccept_impl( node->output, *this );
    1096         maybeAccept_impl( node->input, *this );
    1097         maybeAccept_impl( node->clobber, *this );
    1098 
    1099         VISIT_END( node );
    1100 }
    1101 
    1102 template< typename pass_type >
    1103767Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    1104768        MUTATE_START( node );
     
    1122786
    1123787template< typename pass_type >
    1124 void PassVisitor< pass_type >::visit( const DirectiveStmt * node ) {
    1125         VISIT_START( node )
    1126 
    1127         VISIT_END( node );
    1128 }
    1129 
    1130 template< typename pass_type >
    1131788Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
    1132789        MUTATE_START( node );
     
    1143800                // if statements introduce a level of scope (for the initialization)
    1144801                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1145                 maybeAccept_impl( node->initialization, *this );
     802                maybeAccept_impl( node->get_initialization(), *this );
    1146803                visitExpression ( node->condition );
    1147804                node->thenPart = visitStatement( node->thenPart );
     
    1152809
    1153810template< typename pass_type >
    1154 void PassVisitor< pass_type >::visit( const IfStmt * node ) {
    1155         VISIT_START( node );
     811Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
     812        MUTATE_START( node );
    1156813        {
    1157814                // if statements introduce a level of scope (for the initialization)
    1158815                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1159                 maybeAccept_impl( node->initialization, *this );
    1160                 visitExpression ( node->condition );
    1161                 visitStatement  ( node->thenPart );
    1162                 visitStatement  ( node->elsePart );
    1163         }
    1164         VISIT_END( node );
    1165 }
    1166 
    1167 template< typename pass_type >
    1168 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    1169         MUTATE_START( node );
    1170         {
    1171                 // if statements introduce a level of scope (for the initialization)
    1172                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1173                 maybeMutate_impl( node->initialization, *this );
     816                maybeMutate_impl( node->get_initialization(), *this );
    1174817                node->condition = mutateExpression( node->condition );
    1175818                node->thenPart  = mutateStatement ( node->thenPart  );
     
    1191834                visitExpression ( node->condition );
    1192835                node->body = visitStatement( node->body );
    1193         }
    1194 
    1195         VISIT_END( node );
    1196 }
    1197 
    1198 template< typename pass_type >
    1199 void PassVisitor< pass_type >::visit( const WhileStmt * node ) {
    1200         VISIT_START( node );
    1201 
    1202         {
    1203                 // while statements introduce a level of scope (for the initialization)
    1204                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1205                 maybeAccept_impl( node->initialization, *this );
    1206                 visitExpression ( node->condition );
    1207                 visitStatement  ( node->body );
    1208836        }
    1209837
     
    1244872
    1245873template< typename pass_type >
    1246 void PassVisitor< pass_type >::visit( const ForStmt * node ) {
    1247         VISIT_START( node );
    1248         {
    1249                 // for statements introduce a level of scope (for the initialization)
    1250                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1251                 maybeAccept_impl( node->initialization, *this );
    1252                 visitExpression( node->condition );
    1253                 visitExpression( node->increment );
    1254                 visitStatement ( node->body );
    1255         }
    1256         VISIT_END( node );
    1257 }
    1258 
    1259 template< typename pass_type >
    1260874Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    1261875        MUTATE_START( node );
     
    1284898
    1285899template< typename pass_type >
    1286 void PassVisitor< pass_type >::visit( const SwitchStmt * node ) {
    1287         VISIT_START( node );
    1288 
    1289         visitExpression   ( node->condition  );
    1290         visitStatementList( node->statements );
    1291 
    1292         VISIT_END( node );
    1293 }
    1294 
    1295 template< typename pass_type >
    1296900Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    1297901        MUTATE_START( node );
     
    1316920
    1317921template< typename pass_type >
    1318 void PassVisitor< pass_type >::visit( const CaseStmt * node ) {
    1319         VISIT_START( node );
    1320 
    1321         visitExpression   ( node->condition );
    1322         visitStatementList( node->stmts     );
    1323 
    1324         VISIT_END( node );
    1325 }
    1326 
    1327 template< typename pass_type >
    1328922Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    1329923        MUTATE_START( node );
     
    1344938
    1345939template< typename pass_type >
    1346 void PassVisitor< pass_type >::visit( const BranchStmt * node ) {
    1347         VISIT_START( node );
    1348         VISIT_END( node );
    1349 }
    1350 
    1351 template< typename pass_type >
    1352940Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
    1353941        MUTATE_START( node );
     
    1367955
    1368956template< typename pass_type >
    1369 void PassVisitor< pass_type >::visit( const ReturnStmt * node ) {
    1370         VISIT_START( node );
    1371 
    1372         visitExpression( node->expr );
    1373 
    1374         VISIT_END( node );
    1375 }
    1376 
    1377 template< typename pass_type >
    1378957Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
    1379958        MUTATE_START( node );
     
    1386965//--------------------------------------------------------------------------
    1387966// ThrowStmt
     967
    1388968template< typename pass_type >
    1389969void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
     
    1397977
    1398978template< typename pass_type >
    1399 void PassVisitor< pass_type >::visit( const ThrowStmt * node ) {
    1400         VISIT_START( node );
    1401 
    1402         maybeAccept_impl( node->expr, *this );
    1403         maybeAccept_impl( node->target, *this );
    1404 
    1405         VISIT_END( node );
    1406 }
    1407 
    1408 template< typename pass_type >
    1409979Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
    1410980        MUTATE_START( node );
     
    1420990template< typename pass_type >
    1421991void PassVisitor< pass_type >::visit( TryStmt * node ) {
    1422         VISIT_START( node );
    1423 
    1424         maybeAccept_impl( node->block       , *this );
    1425         maybeAccept_impl( node->handlers    , *this );
    1426         maybeAccept_impl( node->finallyBlock, *this );
    1427 
    1428         VISIT_END( node );
    1429 }
    1430 
    1431 template< typename pass_type >
    1432 void PassVisitor< pass_type >::visit( const TryStmt * node ) {
    1433992        VISIT_START( node );
    1434993
     
    14671026
    14681027template< typename pass_type >
    1469 void PassVisitor< pass_type >::visit( const CatchStmt * node ) {
    1470         VISIT_START( node );
    1471         {
    1472                 // catch statements introduce a level of scope (for the caught exception)
    1473                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1474                 maybeAccept_impl( node->decl, *this );
    1475                 visitExpression ( node->cond );
    1476                 visitStatement  ( node->body );
    1477         }
    1478         VISIT_END( node );
    1479 }
    1480 
    1481 template< typename pass_type >
    14821028Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    14831029        MUTATE_START( node );
     
    15041050
    15051051template< typename pass_type >
    1506 void PassVisitor< pass_type >::visit( const FinallyStmt * node ) {
    1507         VISIT_START( node );
    1508 
    1509         maybeAccept_impl( node->block, *this );
    1510 
    1511         VISIT_END( node );
    1512 }
    1513 
    1514 template< typename pass_type >
    15151052Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    15161053        MUTATE_START( node );
     
    15451082
    15461083template< typename pass_type >
    1547 void PassVisitor< pass_type >::visit( const WaitForStmt * node ) {
    1548         VISIT_START( node );
    1549 
    1550         for( auto & clause : node->clauses ) {
    1551                 maybeAccept_impl( clause.target.function, *this );
    1552                 maybeAccept_impl( clause.target.arguments, *this );
    1553 
    1554                 maybeAccept_impl( clause.statement, *this );
    1555                 maybeAccept_impl( clause.condition, *this );
    1556         }
    1557 
    1558         maybeAccept_impl( node->timeout.time, *this );
    1559         maybeAccept_impl( node->timeout.statement, *this );
    1560         maybeAccept_impl( node->timeout.condition, *this );
    1561         maybeAccept_impl( node->orelse.statement, *this );
    1562         maybeAccept_impl( node->orelse.condition, *this );
    1563 
    1564         VISIT_END( node );
    1565 }
    1566 
    1567 template< typename pass_type >
    15681084Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
    15691085        MUTATE_START( node );
     
    15891105
    15901106//--------------------------------------------------------------------------
    1591 // WithStmt
     1107// NullStmt
    15921108template< typename pass_type >
    15931109void PassVisitor< pass_type >::visit( WithStmt * node ) {
     
    16041120
    16051121template< typename pass_type >
    1606 void PassVisitor< pass_type >::visit( const WithStmt * node ) {
    1607         VISIT_START( node );
    1608         maybeAccept_impl( node->exprs, *this );
    1609         {
    1610                 // catch statements introduce a level of scope (for the caught exception)
    1611                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    1612                 indexerAddWith( node->exprs, node );
    1613                 maybeAccept_impl( node->stmt, *this );
    1614         }
    1615         VISIT_END( node );
    1616 }
    1617 
    1618 template< typename pass_type >
    1619 Declaration * PassVisitor< pass_type >::mutate( WithStmt * node ) {
     1122Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {
    16201123        MUTATE_START( node );
    16211124        maybeMutate_impl( node->exprs, *this );
     
    16261129                maybeMutate_impl( node->stmt, *this );
    16271130        }
    1628         MUTATE_END( Declaration, node );
     1131        MUTATE_END( Statement, node );
    16291132}
    16301133
     
    16381141
    16391142template< typename pass_type >
    1640 void PassVisitor< pass_type >::visit( const NullStmt * node ) {
    1641         VISIT_START( node );
    1642         VISIT_END( node );
    1643 }
    1644 
    1645 template< typename pass_type >
    16461143NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
    16471144        MUTATE_START( node );
     
    16611158
    16621159template< typename pass_type >
    1663 void PassVisitor< pass_type >::visit( const DeclStmt * node ) {
    1664         VISIT_START( node );
    1665 
    1666         maybeAccept_impl( node->decl, *this );
    1667 
    1668         VISIT_END( node );
    1669 }
    1670 
    1671 template< typename pass_type >
    16721160Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
    16731161        MUTATE_START( node );
     
    16901178
    16911179template< typename pass_type >
    1692 void PassVisitor< pass_type >::visit( const ImplicitCtorDtorStmt * node ) {
    1693         VISIT_START( node );
    1694 
    1695         maybeAccept_impl( node->callStmt, *this );
    1696 
    1697         VISIT_END( node );
    1698 }
    1699 
    1700 template< typename pass_type >
    17011180Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
    17021181        MUTATE_START( node );
     
    17141193
    17151194        indexerScopedAccept( node->result  , *this );
    1716         maybeAccept_impl   ( node->function, *this );
    1717         maybeAccept_impl   ( node->args    , *this );
    1718 
    1719         VISIT_END( node );
    1720 }
    1721 
    1722 template< typename pass_type >
    1723 void PassVisitor< pass_type >::visit( const ApplicationExpr * node ) {
    1724         VISIT_START( node );
    1725 
    1726         indexerScopedAccept( node->result  , *this );
    1727         maybeAccept_impl   ( node->function, *this );
    1728         maybeAccept_impl   ( node->args    , *this );
     1195        maybeAccept_impl        ( node->function, *this );
     1196        maybeAccept_impl        ( node->args    , *this );
    17291197
    17301198        VISIT_END( node );
     
    17601228
    17611229template< typename pass_type >
    1762 void PassVisitor< pass_type >::visit( const UntypedExpr * node ) {
    1763         VISIT_START( node );
    1764 
    1765         indexerScopedAccept( node->result, *this );
    1766 
    1767         for ( auto expr : node->args ) {
    1768                 visitExpression( expr );
    1769         }
    1770 
    1771         VISIT_END( node );
    1772 }
    1773 
    1774 template< typename pass_type >
    17751230Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
    17761231        MUTATE_START( node );
     
    17981253
    17991254template< typename pass_type >
    1800 void PassVisitor< pass_type >::visit( const NameExpr * node ) {
     1255Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
     1256        MUTATE_START( node );
     1257
     1258        indexerScopedMutate( node->env   , *this );
     1259        indexerScopedMutate( node->result, *this );
     1260
     1261        MUTATE_END( Expression, node );
     1262}
     1263
     1264//--------------------------------------------------------------------------
     1265// CastExpr
     1266template< typename pass_type >
     1267void PassVisitor< pass_type >::visit( CastExpr * node ) {
    18011268        VISIT_START( node );
    18021269
    18031270        indexerScopedAccept( node->result, *this );
    1804 
    1805         VISIT_END( node );
    1806 }
    1807 
    1808 template< typename pass_type >
    1809 Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
     1271        maybeAccept_impl        ( node->arg   , *this );
     1272
     1273        VISIT_END( node );
     1274}
     1275
     1276template< typename pass_type >
     1277Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
    18101278        MUTATE_START( node );
    18111279
    18121280        indexerScopedMutate( node->env   , *this );
    18131281        indexerScopedMutate( node->result, *this );
    1814 
    1815         MUTATE_END( Expression, node );
    1816 }
    1817 
    1818 //--------------------------------------------------------------------------
    1819 // CastExpr
    1820 template< typename pass_type >
    1821 void PassVisitor< pass_type >::visit( CastExpr * node ) {
     1282        maybeMutate_impl   ( node->arg   , *this );
     1283
     1284        MUTATE_END( Expression, node );
     1285}
     1286
     1287//--------------------------------------------------------------------------
     1288// KeywordCastExpr
     1289template< typename pass_type >
     1290void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
     1291        VISIT_START( node );
     1292
     1293        indexerScopedAccept( node->result, *this );
     1294        maybeAccept_impl        ( node->arg   , *this );
     1295
     1296        VISIT_END( node );
     1297}
     1298
     1299template< typename pass_type >
     1300Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
     1301        MUTATE_START( node );
     1302
     1303        indexerScopedMutate( node->env   , *this );
     1304        indexerScopedMutate( node->result, *this );
     1305        maybeMutate_impl   ( node->arg   , *this );
     1306
     1307        MUTATE_END( Expression, node );
     1308}
     1309
     1310//--------------------------------------------------------------------------
     1311// VirtualCastExpr
     1312template< typename pass_type >
     1313void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) {
     1314        VISIT_START( node );
     1315
     1316        indexerScopedAccept( node->result, *this );
     1317        maybeAccept_impl( node->arg, *this );
     1318
     1319        VISIT_END( node );
     1320}
     1321
     1322template< typename pass_type >
     1323Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
     1324        MUTATE_START( node );
     1325
     1326        indexerScopedMutate( node->env   , *this );
     1327        indexerScopedMutate( node->result, *this );
     1328        maybeMutate_impl   ( node->arg   , *this );
     1329
     1330        MUTATE_END( Expression, node );
     1331}
     1332
     1333//--------------------------------------------------------------------------
     1334// AddressExpr
     1335template< typename pass_type >
     1336void PassVisitor< pass_type >::visit( AddressExpr * node ) {
    18221337        VISIT_START( node );
    18231338
     
    18291344
    18301345template< typename pass_type >
    1831 void PassVisitor< pass_type >::visit( const CastExpr * node ) {
     1346Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
     1347        MUTATE_START( node );
     1348
     1349        indexerScopedMutate( node->env   , *this );
     1350        indexerScopedMutate( node->result, *this );
     1351        maybeMutate_impl   ( node->arg   , *this );
     1352
     1353        MUTATE_END( Expression, node );
     1354}
     1355
     1356//--------------------------------------------------------------------------
     1357// LabelAddressExpr
     1358template< typename pass_type >
     1359void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
    18321360        VISIT_START( node );
    18331361
    18341362        indexerScopedAccept( node->result, *this );
    1835         maybeAccept_impl   ( node->arg   , *this );
    1836 
    1837         VISIT_END( node );
    1838 }
    1839 
    1840 template< typename pass_type >
    1841 Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
     1363
     1364        VISIT_END( node );
     1365}
     1366
     1367template< typename pass_type >
     1368Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
    18421369        MUTATE_START( node );
    18431370
    18441371        indexerScopedMutate( node->env   , *this );
    18451372        indexerScopedMutate( node->result, *this );
    1846         maybeMutate_impl   ( node->arg   , *this );
    1847 
    1848         MUTATE_END( Expression, node );
    1849 }
    1850 
    1851 //--------------------------------------------------------------------------
    1852 // KeywordCastExpr
    1853 template< typename pass_type >
    1854 void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
    1855         VISIT_START( node );
    1856 
    1857         indexerScopedAccept( node->result, *this );
    1858         maybeAccept_impl        ( node->arg   , *this );
    1859 
    1860         VISIT_END( node );
    1861 }
    1862 
    1863 template< typename pass_type >
    1864 void PassVisitor< pass_type >::visit( const KeywordCastExpr * node ) {
    1865         VISIT_START( node );
    1866 
    1867         indexerScopedAccept( node->result, *this );
    1868         maybeAccept_impl   ( node->arg   , *this );
    1869 
    1870         VISIT_END( node );
    1871 }
    1872 
    1873 template< typename pass_type >
    1874 Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
    1875         MUTATE_START( node );
    1876 
    1877         indexerScopedMutate( node->env   , *this );
    1878         indexerScopedMutate( node->result, *this );
    1879         maybeMutate_impl   ( node->arg   , *this );
    1880 
    1881         MUTATE_END( Expression, node );
    1882 }
    1883 
    1884 //--------------------------------------------------------------------------
    1885 // VirtualCastExpr
    1886 template< typename pass_type >
    1887 void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) {
    1888         VISIT_START( node );
    1889 
    1890         indexerScopedAccept( node->result, *this );
    1891         maybeAccept_impl   ( node->arg, *this );
    1892 
    1893         VISIT_END( node );
    1894 }
    1895 
    1896 template< typename pass_type >
    1897 void PassVisitor< pass_type >::visit( const VirtualCastExpr * node ) {
    1898         VISIT_START( node );
    1899 
    1900         indexerScopedAccept( node->result, *this );
    1901         maybeAccept_impl   ( node->arg, *this );
    1902 
    1903         VISIT_END( node );
    1904 }
    1905 
    1906 template< typename pass_type >
    1907 Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
    1908         MUTATE_START( node );
    1909 
    1910         indexerScopedMutate( node->env   , *this );
    1911         indexerScopedMutate( node->result, *this );
    1912         maybeMutate_impl   ( node->arg   , *this );
    1913 
    1914         MUTATE_END( Expression, node );
    1915 }
    1916 
    1917 //--------------------------------------------------------------------------
    1918 // AddressExpr
    1919 template< typename pass_type >
    1920 void PassVisitor< pass_type >::visit( AddressExpr * node ) {
    1921         VISIT_START( node );
    1922 
    1923         indexerScopedAccept( node->result, *this );
    1924         maybeAccept_impl   ( node->arg   , *this );
    1925 
    1926         VISIT_END( node );
    1927 }
    1928 
    1929 template< typename pass_type >
    1930 void PassVisitor< pass_type >::visit( const AddressExpr * node ) {
    1931         VISIT_START( node );
    1932 
    1933         indexerScopedAccept( node->result, *this );
    1934         maybeAccept_impl   ( node->arg   , *this );
    1935 
    1936         VISIT_END( node );
    1937 }
    1938 
    1939 template< typename pass_type >
    1940 Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
    1941         MUTATE_START( node );
    1942 
    1943         indexerScopedMutate( node->env   , *this );
    1944         indexerScopedMutate( node->result, *this );
    1945         maybeMutate_impl   ( node->arg   , *this );
    1946 
    1947         MUTATE_END( Expression, node );
    1948 }
    1949 
    1950 //--------------------------------------------------------------------------
    1951 // LabelAddressExpr
    1952 template< typename pass_type >
    1953 void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
    1954         VISIT_START( node );
    1955 
    1956         indexerScopedAccept( node->result, *this );
    1957 
    1958         VISIT_END( node );
    1959 }
    1960 
    1961 template< typename pass_type >
    1962 void PassVisitor< pass_type >::visit( const LabelAddressExpr * node ) {
    1963         VISIT_START( node );
    1964 
    1965         indexerScopedAccept( node->result, *this );
    1966 
    1967         VISIT_END( node );
    1968 }
    1969 
    1970 template< typename pass_type >
    1971 Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
    1972         MUTATE_START( node );
    1973 
    1974         indexerScopedMutate( node->env   , *this );
    1975         indexerScopedMutate( node->result, *this );
    19761373
    19771374        MUTATE_END( Expression, node );
     
    19821379template< typename pass_type >
    19831380void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
    1984         VISIT_START( node );
    1985 
    1986         indexerScopedAccept( node->result   , *this );
    1987         maybeAccept_impl   ( node->aggregate, *this );
    1988         maybeAccept_impl   ( node->member   , *this );
    1989 
    1990         VISIT_END( node );
    1991 }
    1992 
    1993 template< typename pass_type >
    1994 void PassVisitor< pass_type >::visit( const UntypedMemberExpr * node ) {
    19951381        VISIT_START( node );
    19961382
     
    20271413
    20281414template< typename pass_type >
    2029 void PassVisitor< pass_type >::visit( const MemberExpr * node ) {
    2030         VISIT_START( node );
    2031 
    2032         indexerScopedAccept( node->result   , *this );
    2033         maybeAccept_impl   ( node->aggregate, *this );
    2034 
    2035         VISIT_END( node );
    2036 }
    2037 
    2038 template< typename pass_type >
    20391415Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
    20401416        MUTATE_START( node );
     
    20591435
    20601436template< typename pass_type >
    2061 void PassVisitor< pass_type >::visit( const VariableExpr * node ) {
    2062         VISIT_START( node );
    2063 
    2064         indexerScopedAccept( node->result, *this );
    2065 
    2066         VISIT_END( node );
    2067 }
    2068 
    2069 template< typename pass_type >
    20701437Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
    20711438        MUTATE_START( node );
     
    20811448template< typename pass_type >
    20821449void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
    2083         VISIT_START( node );
    2084 
    2085         indexerScopedAccept( node->result   , *this );
    2086         maybeAccept_impl   ( &node->constant, *this );
    2087 
    2088         VISIT_END( node );
    2089 }
    2090 
    2091 template< typename pass_type >
    2092 void PassVisitor< pass_type >::visit( const ConstantExpr * node ) {
    20931450        VISIT_START( node );
    20941451
     
    21291486
    21301487template< typename pass_type >
    2131 void PassVisitor< pass_type >::visit( const SizeofExpr * node ) {
     1488Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
     1489        MUTATE_START( node );
     1490
     1491        indexerScopedMutate( node->env   , *this );
     1492        indexerScopedMutate( node->result, *this );
     1493        if ( node->get_isType() ) {
     1494                maybeMutate_impl( node->type, *this );
     1495        } else {
     1496                maybeMutate_impl( node->expr, *this );
     1497        }
     1498
     1499        MUTATE_END( Expression, node );
     1500}
     1501
     1502//--------------------------------------------------------------------------
     1503// AlignofExpr
     1504template< typename pass_type >
     1505void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
    21321506        VISIT_START( node );
    21331507
     
    21431517
    21441518template< typename pass_type >
    2145 Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
     1519Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
    21461520        MUTATE_START( node );
    21471521
     
    21581532
    21591533//--------------------------------------------------------------------------
    2160 // AlignofExpr
    2161 template< typename pass_type >
    2162 void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
     1534// UntypedOffsetofExpr
     1535template< typename pass_type >
     1536void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
     1537        VISIT_START( node );
     1538
     1539        indexerScopedAccept( node->result, *this );
     1540        maybeAccept_impl   ( node->type  , *this );
     1541
     1542        VISIT_END( node );
     1543}
     1544
     1545template< typename pass_type >
     1546Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
     1547        MUTATE_START( node );
     1548
     1549        indexerScopedMutate( node->env   , *this );
     1550        indexerScopedMutate( node->result, *this );
     1551        maybeMutate_impl   ( node->type  , *this );
     1552
     1553        MUTATE_END( Expression, node );
     1554}
     1555
     1556//--------------------------------------------------------------------------
     1557// OffsetofExpr
     1558template< typename pass_type >
     1559void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
     1560        VISIT_START( node );
     1561
     1562        indexerScopedAccept( node->result, *this );
     1563        maybeAccept_impl   ( node->type  , *this );
     1564
     1565        VISIT_END( node );
     1566}
     1567
     1568template< typename pass_type >
     1569Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
     1570        MUTATE_START( node );
     1571
     1572        indexerScopedMutate( node->env   , *this );
     1573        indexerScopedMutate( node->result, *this );
     1574        maybeMutate_impl   ( node->type  , *this );
     1575
     1576        MUTATE_END( Expression, node );
     1577}
     1578
     1579//--------------------------------------------------------------------------
     1580// OffsetPackExpr
     1581template< typename pass_type >
     1582void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
     1583        VISIT_START( node );
     1584
     1585        indexerScopedAccept( node->result, *this );
     1586        maybeAccept_impl   ( node->type  , *this );
     1587
     1588        VISIT_END( node );
     1589}
     1590
     1591template< typename pass_type >
     1592Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
     1593        MUTATE_START( node );
     1594
     1595        indexerScopedMutate( node->env   , *this );
     1596        indexerScopedMutate( node->result, *this );
     1597        maybeMutate_impl   ( node->type  , *this );
     1598
     1599        MUTATE_END( Expression, node );
     1600}
     1601
     1602//--------------------------------------------------------------------------
     1603// AttrExpr
     1604template< typename pass_type >
     1605void PassVisitor< pass_type >::visit( AttrExpr * node ) {
    21631606        VISIT_START( node );
    21641607
     
    21741617
    21751618template< typename pass_type >
    2176 void PassVisitor< pass_type >::visit( const AlignofExpr * node ) {
    2177         VISIT_START( node );
    2178 
    2179         indexerScopedAccept( node->result, *this );
    2180         if ( node->get_isType() ) {
    2181                 maybeAccept_impl( node->type, *this );
    2182         } else {
    2183                 maybeAccept_impl( node->expr, *this );
    2184         }
    2185 
    2186         VISIT_END( node );
    2187 }
    2188 
    2189 template< typename pass_type >
    2190 Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
     1619Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) {
    21911620        MUTATE_START( node );
    21921621
     
    22031632
    22041633//--------------------------------------------------------------------------
    2205 // UntypedOffsetofExpr
    2206 template< typename pass_type >
    2207 void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
    2208         VISIT_START( node );
    2209 
    2210         indexerScopedAccept( node->result, *this );
    2211         maybeAccept_impl   ( node->type  , *this );
    2212 
    2213         VISIT_END( node );
    2214 }
    2215 
    2216 template< typename pass_type >
    2217 void PassVisitor< pass_type >::visit( const UntypedOffsetofExpr * node ) {
    2218         VISIT_START( node );
    2219 
    2220         indexerScopedAccept( node->result, *this );
    2221         maybeAccept_impl   ( node->type  , *this );
    2222 
    2223         VISIT_END( node );
    2224 }
    2225 
    2226 template< typename pass_type >
    2227 Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
    2228         MUTATE_START( node );
    2229 
    2230         indexerScopedMutate( node->env   , *this );
    2231         indexerScopedMutate( node->result, *this );
    2232         maybeMutate_impl   ( node->type  , *this );
    2233 
    2234         MUTATE_END( Expression, node );
    2235 }
    2236 
    2237 //--------------------------------------------------------------------------
    2238 // OffsetofExpr
    2239 template< typename pass_type >
    2240 void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
    2241         VISIT_START( node );
    2242 
    2243         indexerScopedAccept( node->result, *this );
    2244         maybeAccept_impl   ( node->type  , *this );
    2245 
    2246         VISIT_END( node );
    2247 }
    2248 
    2249 template< typename pass_type >
    2250 void PassVisitor< pass_type >::visit( const OffsetofExpr * node ) {
    2251         VISIT_START( node );
    2252 
    2253         indexerScopedAccept( node->result, *this );
    2254         maybeAccept_impl   ( node->type  , *this );
    2255 
    2256         VISIT_END( node );
    2257 }
    2258 
    2259 template< typename pass_type >
    2260 Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
    2261         MUTATE_START( node );
    2262 
    2263         indexerScopedMutate( node->env   , *this );
    2264         indexerScopedMutate( node->result, *this );
    2265         maybeMutate_impl   ( node->type  , *this );
    2266 
    2267         MUTATE_END( Expression, node );
    2268 }
    2269 
    2270 //--------------------------------------------------------------------------
    2271 // OffsetPackExpr
    2272 template< typename pass_type >
    2273 void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
    2274         VISIT_START( node );
    2275 
    2276         indexerScopedAccept( node->result, *this );
    2277         maybeAccept_impl   ( node->type  , *this );
    2278 
    2279         VISIT_END( node );
    2280 }
    2281 
    2282 template< typename pass_type >
    2283 void PassVisitor< pass_type >::visit( const OffsetPackExpr * node ) {
    2284         VISIT_START( node );
    2285 
    2286         indexerScopedAccept( node->result, *this );
    2287         maybeAccept_impl   ( node->type  , *this );
    2288 
    2289         VISIT_END( node );
    2290 }
    2291 
    2292 template< typename pass_type >
    2293 Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
    2294         MUTATE_START( node );
    2295 
    2296         indexerScopedMutate( node->env   , *this );
    2297         indexerScopedMutate( node->result, *this );
    2298         maybeMutate_impl   ( node->type  , *this );
    2299 
    2300         MUTATE_END( Expression, node );
    2301 }
    2302 
    2303 //--------------------------------------------------------------------------
    23041634// LogicalExpr
    23051635template< typename pass_type >
    23061636void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
    2307         VISIT_START( node );
    2308 
    2309         indexerScopedAccept( node->result, *this );
    2310         maybeAccept_impl   ( node->arg1  , *this );
    2311         maybeAccept_impl   ( node->arg2  , *this );
    2312 
    2313         VISIT_END( node );
    2314 }
    2315 
    2316 template< typename pass_type >
    2317 void PassVisitor< pass_type >::visit( const LogicalExpr * node ) {
    23181637        VISIT_START( node );
    23191638
     
    23521671
    23531672template< typename pass_type >
    2354 void PassVisitor< pass_type >::visit( const ConditionalExpr * node ) {
     1673Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
     1674        MUTATE_START( node );
     1675
     1676        indexerScopedMutate( node->env   , *this );
     1677        indexerScopedMutate( node->result, *this );
     1678        maybeMutate_impl   ( node->arg1  , *this );
     1679        maybeMutate_impl   ( node->arg2  , *this );
     1680        maybeMutate_impl   ( node->arg3  , *this );
     1681
     1682        MUTATE_END( Expression, node );
     1683}
     1684
     1685//--------------------------------------------------------------------------
     1686// CommaExpr
     1687template< typename pass_type >
     1688void PassVisitor< pass_type >::visit( CommaExpr * node ) {
    23551689        VISIT_START( node );
    23561690
     
    23581692        maybeAccept_impl   ( node->arg1  , *this );
    23591693        maybeAccept_impl   ( node->arg2  , *this );
    2360         maybeAccept_impl   ( node->arg3  , *this );
    2361 
    2362         VISIT_END( node );
    2363 }
    2364 
    2365 template< typename pass_type >
    2366 Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
     1694
     1695        VISIT_END( node );
     1696}
     1697
     1698template< typename pass_type >
     1699Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
    23671700        MUTATE_START( node );
    23681701
     
    23711704        maybeMutate_impl   ( node->arg1  , *this );
    23721705        maybeMutate_impl   ( node->arg2  , *this );
    2373         maybeMutate_impl   ( node->arg3  , *this );
    2374 
    2375         MUTATE_END( Expression, node );
    2376 }
    2377 
    2378 //--------------------------------------------------------------------------
    2379 // CommaExpr
    2380 template< typename pass_type >
    2381 void PassVisitor< pass_type >::visit( CommaExpr * node ) {
    2382         VISIT_START( node );
    2383 
    2384         indexerScopedAccept( node->result, *this );
    2385         maybeAccept_impl   ( node->arg1  , *this );
    2386         maybeAccept_impl   ( node->arg2  , *this );
    2387 
    2388         VISIT_END( node );
    2389 }
    2390 
    2391 template< typename pass_type >
    2392 void PassVisitor< pass_type >::visit( const CommaExpr * node ) {
    2393         VISIT_START( node );
    2394 
    2395         indexerScopedAccept( node->result, *this );
    2396         maybeAccept_impl   ( node->arg1  , *this );
    2397         maybeAccept_impl   ( node->arg2  , *this );
    2398 
    2399         VISIT_END( node );
    2400 }
    2401 
    2402 template< typename pass_type >
    2403 Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
    2404         MUTATE_START( node );
    2405 
    2406         indexerScopedMutate( node->env   , *this );
    2407         indexerScopedMutate( node->result, *this );
    2408         maybeMutate_impl   ( node->arg1  , *this );
    2409         maybeMutate_impl   ( node->arg2  , *this );
    24101706
    24111707        MUTATE_END( Expression, node );
     
    24251721
    24261722template< typename pass_type >
    2427 void PassVisitor< pass_type >::visit( const TypeExpr * node ) {
    2428         VISIT_START( node );
    2429 
    2430         indexerScopedAccept( node->result, *this );
    2431         maybeAccept_impl   ( node->type, *this );
    2432 
    2433         VISIT_END( node );
    2434 }
    2435 
    2436 template< typename pass_type >
    24371723Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
    24381724        MUTATE_START( node );
     
    24491735template< typename pass_type >
    24501736void PassVisitor< pass_type >::visit( AsmExpr * node ) {
    2451         VISIT_START( node );
    2452 
    2453         indexerScopedAccept( node->result    , *this );
    2454         maybeAccept_impl   ( node->inout     , *this );
    2455         maybeAccept_impl   ( node->constraint, *this );
    2456         maybeAccept_impl   ( node->operand   , *this );
    2457 
    2458         VISIT_END( node );
    2459 }
    2460 
    2461 template< typename pass_type >
    2462 void PassVisitor< pass_type >::visit( const AsmExpr * node ) {
    24631737        VISIT_START( node );
    24641738
     
    24901764        VISIT_START( node );
    24911765
    2492         indexerScopedAccept( node->result    , *this );
    2493         maybeAccept_impl   ( node->callExpr  , *this );
    2494 
    2495         VISIT_END( node );
    2496 }
    2497 
    2498 template< typename pass_type >
    2499 void PassVisitor< pass_type >::visit( const ImplicitCopyCtorExpr * node ) {
    2500         VISIT_START( node );
    2501 
    2502         indexerScopedAccept( node->result    , *this );
    2503         maybeAccept_impl   ( node->callExpr  , *this );
     1766        indexerScopedAccept( node->result     , *this );
     1767        maybeAccept_impl   ( node->callExpr   , *this );
     1768        maybeAccept_impl   ( node->tempDecls  , *this );
     1769        maybeAccept_impl   ( node->returnDecls, *this );
     1770        maybeAccept_impl   ( node->dtors      , *this );
    25041771
    25051772        VISIT_END( node );
     
    25101777        MUTATE_START( node );
    25111778
    2512         indexerScopedMutate( node->env       , *this );
    2513         indexerScopedMutate( node->result    , *this );
    2514         maybeMutate_impl   ( node->callExpr  , *this );
     1779        indexerScopedMutate( node->env        , *this );
     1780        indexerScopedMutate( node->result     , *this );
     1781        maybeMutate_impl   ( node->callExpr   , *this );
     1782        maybeMutate_impl   ( node->tempDecls  , *this );
     1783        maybeMutate_impl   ( node->returnDecls, *this );
     1784        maybeMutate_impl   ( node->dtors      , *this );
    25151785
    25161786        MUTATE_END( Expression, node );
     
    25211791template< typename pass_type >
    25221792void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
    2523         VISIT_START( node );
    2524 
    2525         indexerScopedAccept( node->result  , *this );
    2526         maybeAccept_impl   ( node->callExpr, *this );
    2527 
    2528         VISIT_END( node );
    2529 }
    2530 
    2531 template< typename pass_type >
    2532 void PassVisitor< pass_type >::visit( const ConstructorExpr * node ) {
    25331793        VISIT_START( node );
    25341794
     
    25631823
    25641824template< typename pass_type >
    2565 void PassVisitor< pass_type >::visit( const CompoundLiteralExpr * node ) {
    2566         VISIT_START( node );
    2567 
    2568         indexerScopedAccept( node->result     , *this );
    2569         maybeAccept_impl   ( node->initializer, *this );
    2570 
    2571         VISIT_END( node );
    2572 }
    2573 
    2574 template< typename pass_type >
    25751825Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
    25761826        MUTATE_START( node );
     
    25971847
    25981848template< typename pass_type >
    2599 void PassVisitor< pass_type >::visit( const RangeExpr * node ) {
    2600         VISIT_START( node );
    2601 
    2602         indexerScopedAccept( node->result, *this );
    2603         maybeAccept_impl   ( node->low   , *this );
    2604         maybeAccept_impl   ( node->high  , *this );
    2605 
    2606         VISIT_END( node );
    2607 }
    2608 
    2609 template< typename pass_type >
    26101849Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
    26111850        MUTATE_START( node );
     
    26321871
    26331872template< typename pass_type >
    2634 void PassVisitor< pass_type >::visit( const UntypedTupleExpr * node ) {
     1873Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
     1874        MUTATE_START( node );
     1875
     1876        indexerScopedMutate( node->env   , *this );
     1877        indexerScopedMutate( node->result, *this );
     1878        maybeMutate_impl   ( node->exprs , *this );
     1879
     1880        MUTATE_END( Expression, node );
     1881}
     1882
     1883//--------------------------------------------------------------------------
     1884// TupleExpr
     1885template< typename pass_type >
     1886void PassVisitor< pass_type >::visit( TupleExpr * node ) {
    26351887        VISIT_START( node );
    26361888
     
    26421894
    26431895template< typename pass_type >
    2644 Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
    2645         MUTATE_START( node );
    2646 
    2647         indexerScopedMutate( node->env   , *this );
    2648         indexerScopedMutate( node->result, *this );
    2649         maybeMutate_impl   ( node->exprs , *this );
    2650 
    2651         MUTATE_END( Expression, node );
    2652 }
    2653 
    2654 //--------------------------------------------------------------------------
    2655 // TupleExpr
    2656 template< typename pass_type >
    2657 void PassVisitor< pass_type >::visit( TupleExpr * node ) {
    2658         VISIT_START( node );
    2659 
    2660         indexerScopedAccept( node->result, *this );
    2661         maybeAccept_impl   ( node->exprs , *this );
    2662 
    2663         VISIT_END( node );
    2664 }
    2665 
    2666 template< typename pass_type >
    2667 void PassVisitor< pass_type >::visit( const TupleExpr * node ) {
    2668         VISIT_START( node );
    2669 
    2670         indexerScopedAccept( node->result, *this );
    2671         maybeAccept_impl   ( node->exprs , *this );
    2672 
    2673         VISIT_END( node );
    2674 }
    2675 
    2676 template< typename pass_type >
    26771896Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
    26781897        MUTATE_START( node );
     
    26981917
    26991918template< typename pass_type >
    2700 void PassVisitor< pass_type >::visit( const TupleIndexExpr * node ) {
    2701         VISIT_START( node );
    2702 
    2703         indexerScopedAccept( node->result, *this );
    2704         maybeAccept_impl   ( node->tuple , *this );
    2705 
    2706         VISIT_END( node );
    2707 }
    2708 
    2709 template< typename pass_type >
    27101919Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
    27111920        MUTATE_START( node );
     
    27261935        indexerScopedAccept( node->result  , *this );
    27271936        maybeAccept_impl   ( node->stmtExpr, *this );
    2728 
    2729         VISIT_END( node );
    2730 }
    2731 
    2732 template< typename pass_type >
    2733 void PassVisitor< pass_type >::visit( const TupleAssignExpr * node ) {
    2734         VISIT_START( node );
    2735 
    2736         indexerScopedAccept( node->result  , *this );
    2737         maybeAccept_impl( node->stmtExpr, *this );
    27381937
    27391938        VISIT_END( node );
     
    27581957
    27591958        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    2760         ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
     1959        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    27611960        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    27621961        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     
    27711970
    27721971template< typename pass_type >
    2773 void PassVisitor< pass_type >::visit( const StmtExpr * node ) {
    2774         VISIT_START( node );
     1972Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
     1973        MUTATE_START( node );
    27751974
    27761975        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    2777         ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    2778         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    2779         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    2780 
    2781         indexerScopedAccept( node->result     , *this );
    2782         maybeAccept_impl   ( node->statements , *this );
    2783         maybeAccept_impl   ( node->returnDecls, *this );
    2784         maybeAccept_impl   ( node->dtors      , *this );
    2785 
    2786         VISIT_END( node );
    2787 }
    2788 
    2789 template< typename pass_type >
    2790 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    2791         MUTATE_START( node );
    2792 
    2793         // don't want statements from outer CompoundStmts to be added to this StmtExpr
    2794         ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
     1976        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    27951977        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    27961978        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     
    28171999
    28182000template< typename pass_type >
    2819 void PassVisitor< pass_type >::visit( const UniqueExpr * node ) {
    2820         VISIT_START( node );
    2821 
    2822         indexerScopedAccept( node->result, *this );
    2823         maybeAccept_impl   ( node->expr  , *this );
    2824 
    2825         VISIT_END( node );
    2826 }
    2827 
    2828 template< typename pass_type >
    28292001Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
    28302002        MUTATE_START( node );
     
    28512023
    28522024template< typename pass_type >
    2853 void PassVisitor< pass_type >::visit( const UntypedInitExpr * node ) {
    2854         VISIT_START( node );
    2855 
    2856         indexerScopedAccept( node->result, *this );
    2857         maybeAccept_impl   ( node->expr  , *this );
    2858         // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
    2859 
    2860         VISIT_END( node );
    2861 }
    2862 
    2863 template< typename pass_type >
    28642025Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
    28652026        MUTATE_START( node );
     
    28872048
    28882049template< typename pass_type >
    2889 void PassVisitor< pass_type >::visit( const InitExpr * node ) {
    2890         VISIT_START( node );
    2891 
    2892         indexerScopedAccept( node->result, *this );
    2893         maybeAccept_impl   ( node->expr  , *this );
    2894         maybeAccept_impl   ( node->designation, *this );
    2895 
    2896         VISIT_END( node );
    2897 }
    2898 
    2899 template< typename pass_type >
    29002050Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
    29012051        MUTATE_START( node );
     
    29162066
    29172067        indexerScopedAccept( node->result, *this );
    2918         maybeAccept_impl   ( node->expr, *this );
     2068        maybeAccept_impl( node->expr, *this );
    29192069        // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
    29202070
     
    29232073
    29242074template< typename pass_type >
    2925 void PassVisitor< pass_type >::visit( const DeletedExpr * node ) {
    2926         VISIT_START( node );
    2927 
    2928         indexerScopedAccept( node->result, *this );
    2929         maybeAccept_impl   ( node->expr, *this );
    2930         // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
    2931 
    2932         VISIT_END( node );
    2933 }
    2934 
    2935 template< typename pass_type >
    29362075Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
    2937         MUTATE_START( node );
    2938 
    2939         indexerScopedMutate( node->env, *this );
    2940         indexerScopedMutate( node->result, *this );
    2941         maybeMutate_impl( node->expr, *this );
    2942 
    2943         MUTATE_END( Expression, node );
    2944 }
    2945 
    2946 //--------------------------------------------------------------------------
    2947 // DefaultArgExpr
    2948 template< typename pass_type >
    2949 void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
    2950         VISIT_START( node );
    2951 
    2952         indexerScopedAccept( node->result, *this );
    2953         maybeAccept_impl   ( node->expr, *this );
    2954 
    2955         VISIT_END( node );
    2956 }
    2957 
    2958 template< typename pass_type >
    2959 void PassVisitor< pass_type >::visit( const DefaultArgExpr * node ) {
    2960         VISIT_START( node );
    2961 
    2962         indexerScopedAccept( node->result, *this );
    2963         maybeAccept_impl   ( node->expr, *this );
    2964 
    2965         VISIT_END( node );
    2966 }
    2967 
    2968 template< typename pass_type >
    2969 Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
    29702076        MUTATE_START( node );
    29712077
     
    29942100
    29952101template< typename pass_type >
    2996 void PassVisitor< pass_type >::visit( const GenericExpr * node ) {
    2997         VISIT_START( node );
    2998 
    2999         indexerScopedAccept( node->result, *this );
    3000         maybeAccept_impl( node->control, *this );
    3001         for ( const GenericExpr::Association & assoc : node->associations ) {
    3002                 indexerScopedAccept( assoc.type, *this );
    3003                 maybeAccept_impl( assoc.expr, *this );
    3004         }
    3005 
    3006         VISIT_END( node );
    3007 }
    3008 
    3009 template< typename pass_type >
    30102102Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) {
    30112103        MUTATE_START( node );
     
    30342126
    30352127template< typename pass_type >
    3036 void PassVisitor< pass_type >::visit( const VoidType * node ) {
    3037         VISIT_START( node );
    3038 
    3039         maybeAccept_impl( node->forall, *this );
    3040 
    3041         VISIT_END( node );
    3042 }
    3043 
    3044 template< typename pass_type >
    30452128Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
    30462129        MUTATE_START( node );
     
    30552138template< typename pass_type >
    30562139void PassVisitor< pass_type >::visit( BasicType * node ) {
    3057         VISIT_START( node );
    3058 
    3059         maybeAccept_impl( node->forall, *this );
    3060 
    3061         VISIT_END( node );
    3062 }
    3063 
    3064 template< typename pass_type >
    3065 void PassVisitor< pass_type >::visit( const BasicType * node ) {
    30662140        VISIT_START( node );
    30672141
     
    30942168
    30952169template< typename pass_type >
    3096 void PassVisitor< pass_type >::visit( const PointerType * node ) {
    3097         VISIT_START( node );
    3098 
    3099         maybeAccept_impl( node->forall, *this );
    3100         // xxx - should PointerType visit/mutate dimension?
    3101         maybeAccept_impl( node->base, *this );
    3102 
    3103         VISIT_END( node );
    3104 }
    3105 
    3106 template< typename pass_type >
    31072170Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
    31082171        MUTATE_START( node );
     
    31292192
    31302193template< typename pass_type >
    3131 void PassVisitor< pass_type >::visit( const ArrayType * node ) {
    3132         VISIT_START( node );
    3133 
    3134         maybeAccept_impl( node->forall, *this );
    3135         maybeAccept_impl( node->dimension, *this );
    3136         maybeAccept_impl( node->base, *this );
    3137 
    3138         VISIT_END( node );
    3139 }
    3140 
    3141 template< typename pass_type >
    31422194Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
    31432195        MUTATE_START( node );
     
    31632215
    31642216template< typename pass_type >
    3165 void PassVisitor< pass_type >::visit( const ReferenceType * node ) {
    3166         VISIT_START( node );
    3167 
    3168         maybeAccept_impl( node->forall, *this );
    3169         maybeAccept_impl( node->base, *this );
    3170 
    3171         VISIT_END( node );
    3172 }
    3173 
    3174 template< typename pass_type >
    31752217Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
    31762218        MUTATE_START( node );
     
    31782220        maybeMutate_impl( node->forall, *this );
    31792221        maybeMutate_impl( node->base, *this );
    3180 
    3181         MUTATE_END( Type, node );
    3182 }
    3183 
    3184 //--------------------------------------------------------------------------
    3185 // QualifiedType
    3186 template< typename pass_type >
    3187 void PassVisitor< pass_type >::visit( QualifiedType * node ) {
    3188         VISIT_START( node );
    3189 
    3190         maybeAccept_impl( node->forall, *this );
    3191         maybeAccept_impl( node->parent, *this );
    3192         maybeAccept_impl( node->child, *this );
    3193 
    3194         VISIT_END( node );
    3195 }
    3196 
    3197 template< typename pass_type >
    3198 void PassVisitor< pass_type >::visit( const QualifiedType * node ) {
    3199         VISIT_START( node );
    3200 
    3201         maybeAccept_impl( node->forall, *this );
    3202         maybeAccept_impl( node->parent, *this );
    3203         maybeAccept_impl( node->child, *this );
    3204 
    3205         VISIT_END( node );
    3206 }
    3207 
    3208 template< typename pass_type >
    3209 Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) {
    3210         MUTATE_START( node );
    3211 
    3212         maybeMutate_impl( node->forall, *this );
    3213         maybeMutate_impl( node->parent, *this );
    3214         maybeMutate_impl( node->child, *this );
    32152222
    32162223        MUTATE_END( Type, node );
     
    32312238
    32322239template< typename pass_type >
    3233 void PassVisitor< pass_type >::visit( const FunctionType * node ) {
    3234         VISIT_START( node );
    3235 
    3236         maybeAccept_impl( node->forall, *this );
    3237         maybeAccept_impl( node->returnVals, *this );
    3238         maybeAccept_impl( node->parameters, *this );
    3239 
    3240         VISIT_END( node );
    3241 }
    3242 
    3243 template< typename pass_type >
    32442240Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
    32452241        MUTATE_START( node );
     
    32702266
    32712267template< typename pass_type >
    3272 void PassVisitor< pass_type >::visit( const StructInstType * node ) {
     2268Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
     2269        MUTATE_START( node );
     2270
     2271        indexerAddStruct( node->name );
     2272
     2273        {
     2274                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     2275                maybeMutate_impl( node->forall    , *this );
     2276                maybeMutate_impl( node->parameters, *this );
     2277        }
     2278
     2279        MUTATE_END( Type, node );
     2280}
     2281
     2282//--------------------------------------------------------------------------
     2283// UnionInstType
     2284template< typename pass_type >
     2285void PassVisitor< pass_type >::visit( UnionInstType * node ) {
    32732286        VISIT_START( node );
    32742287
     
    32852298
    32862299template< typename pass_type >
    3287 Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
     2300Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
    32882301        MUTATE_START( node );
    32892302
     
    33002313
    33012314//--------------------------------------------------------------------------
    3302 // UnionInstType
    3303 template< typename pass_type >
    3304 void PassVisitor< pass_type >::visit( UnionInstType * node ) {
    3305         VISIT_START( node );
    3306 
    3307         indexerAddStruct( node->name );
    3308 
    3309         {
    3310                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    3311                 maybeAccept_impl( node->forall    , *this );
    3312                 maybeAccept_impl( node->parameters, *this );
    3313         }
    3314 
    3315         VISIT_END( node );
    3316 }
    3317 
    3318 template< typename pass_type >
    3319 void PassVisitor< pass_type >::visit( const UnionInstType * node ) {
    3320         VISIT_START( node );
    3321 
    3322         indexerAddStruct( node->name );
    3323 
    3324         {
    3325                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    3326                 maybeAccept_impl( node->forall    , *this );
    3327                 maybeAccept_impl( node->parameters, *this );
    3328         }
    3329 
    3330         VISIT_END( node );
    3331 }
    3332 
    3333 template< typename pass_type >
    3334 Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
    3335         MUTATE_START( node );
    3336 
    3337         indexerAddStruct( node->name );
    3338 
    3339         {
    3340                 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    3341                 maybeMutate_impl( node->forall    , *this );
    3342                 maybeMutate_impl( node->parameters, *this );
    3343         }
    3344 
    3345         MUTATE_END( Type, node );
    3346 }
    3347 
    3348 //--------------------------------------------------------------------------
    33492315// EnumInstType
    33502316template< typename pass_type >
     
    33592325
    33602326template< typename pass_type >
    3361 void PassVisitor< pass_type >::visit( const EnumInstType * node ) {
    3362         VISIT_START( node );
    3363 
    3364         maybeAccept_impl( node->forall, *this );
    3365         maybeAccept_impl( node->parameters, *this );
    3366 
    3367         VISIT_END( node );
    3368 }
    3369 
    3370 template< typename pass_type >
    33712327Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
    33722328        MUTATE_START( node );
     
    33912347
    33922348template< typename pass_type >
    3393 void PassVisitor< pass_type >::visit( const TraitInstType * node ) {
    3394         VISIT_START( node );
    3395 
    3396         maybeAccept_impl( node->forall    , *this );
    3397         maybeAccept_impl( node->parameters, *this );
    3398 
    3399         VISIT_END( node );
    3400 }
    3401 
    3402 template< typename pass_type >
    34032349Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
    34042350        MUTATE_START( node );
     
    34142360template< typename pass_type >
    34152361void PassVisitor< pass_type >::visit( TypeInstType * node ) {
    3416         VISIT_START( node );
    3417 
    3418         maybeAccept_impl( node->forall    , *this );
    3419         maybeAccept_impl( node->parameters, *this );
    3420 
    3421         VISIT_END( node );
    3422 }
    3423 
    3424 template< typename pass_type >
    3425 void PassVisitor< pass_type >::visit( const TypeInstType * node ) {
    34262362        VISIT_START( node );
    34272363
     
    34562392
    34572393template< typename pass_type >
    3458 void PassVisitor< pass_type >::visit( const TupleType * node ) {
    3459         VISIT_START( node );
    3460 
    3461         maybeAccept_impl( node->forall, *this );
    3462         maybeAccept_impl( node->types, *this );
    3463         maybeAccept_impl( node->members, *this );
    3464 
    3465         VISIT_END( node );
    3466 }
    3467 
    3468 template< typename pass_type >
    34692394Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
    34702395        MUTATE_START( node );
     
    34812406template< typename pass_type >
    34822407void PassVisitor< pass_type >::visit( TypeofType * node ) {
    3483         VISIT_START( node );
    3484 
    3485         assert( node->expr );
    3486         maybeAccept_impl( node->expr, *this );
    3487 
    3488         VISIT_END( node );
    3489 }
    3490 
    3491 template< typename pass_type >
    3492 void PassVisitor< pass_type >::visit( const TypeofType * node ) {
    34932408        VISIT_START( node );
    34942409
     
    35272442
    35282443template< typename pass_type >
    3529 void PassVisitor< pass_type >::visit( const AttrType * node ) {
    3530         VISIT_START( node );
    3531 
    3532         if ( node->isType ) {
    3533                 assert( node->type );
    3534                 maybeAccept_impl( node->type, *this );
    3535         } else {
    3536                 assert( node->expr );
    3537                 maybeAccept_impl( node->expr, *this );
    3538         } // if
    3539 
    3540         VISIT_END( node );
    3541 }
    3542 
    3543 template< typename pass_type >
    35442444Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
    35452445        MUTATE_START( node );
     
    35682468
    35692469template< typename pass_type >
    3570 void PassVisitor< pass_type >::visit( const VarArgsType * node ) {
     2470Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
     2471        MUTATE_START( node );
     2472
     2473        maybeMutate_impl( node->forall, *this );
     2474
     2475        MUTATE_END( Type, node );
     2476}
     2477
     2478//--------------------------------------------------------------------------
     2479// ZeroType
     2480template< typename pass_type >
     2481void PassVisitor< pass_type >::visit( ZeroType * node ) {
    35712482        VISIT_START( node );
    35722483
     
    35772488
    35782489template< typename pass_type >
    3579 Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
     2490Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
    35802491        MUTATE_START( node );
    35812492
     
    35862497
    35872498//--------------------------------------------------------------------------
    3588 // ZeroType
    3589 template< typename pass_type >
    3590 void PassVisitor< pass_type >::visit( ZeroType * node ) {
     2499// OneType
     2500template< typename pass_type >
     2501void PassVisitor< pass_type >::visit( OneType * node ) {
    35912502        VISIT_START( node );
    35922503
     
    35972508
    35982509template< typename pass_type >
    3599 void PassVisitor< pass_type >::visit( const ZeroType * node ) {
    3600         VISIT_START( node );
    3601 
    3602         maybeAccept_impl( node->forall, *this );
    3603 
    3604         VISIT_END( node );
    3605 }
    3606 
    3607 template< typename pass_type >
    3608 Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
     2510Type * PassVisitor< pass_type >::mutate( OneType * node ) {
    36092511        MUTATE_START( node );
    36102512
     
    36152517
    36162518//--------------------------------------------------------------------------
    3617 // OneType
    3618 template< typename pass_type >
    3619 void PassVisitor< pass_type >::visit( OneType * node ) {
    3620         VISIT_START( node );
    3621 
    3622         maybeAccept_impl( node->forall, *this );
    3623 
    3624         VISIT_END( node );
    3625 }
    3626 
    3627 template< typename pass_type >
    3628 void PassVisitor< pass_type >::visit( const OneType * node ) {
    3629         VISIT_START( node );
    3630 
    3631         maybeAccept_impl( node->forall, *this );
    3632 
    3633         VISIT_END( node );
    3634 }
    3635 
    3636 template< typename pass_type >
    3637 Type * PassVisitor< pass_type >::mutate( OneType * node ) {
    3638         MUTATE_START( node );
    3639 
    3640         maybeMutate_impl( node->forall, *this );
    3641 
    3642         MUTATE_END( Type, node );
    3643 }
    3644 
    3645 //--------------------------------------------------------------------------
    3646 // GlobalScopeType
    3647 template< typename pass_type >
    3648 void PassVisitor< pass_type >::visit( GlobalScopeType * node ) {
    3649         VISIT_START( node );
    3650 
    3651         maybeAccept_impl( node->forall, *this );
    3652 
    3653         VISIT_END( node );
    3654 }
    3655 
    3656 template< typename pass_type >
    3657 void PassVisitor< pass_type >::visit( const GlobalScopeType * node ) {
    3658         VISIT_START( node );
    3659 
    3660         maybeAccept_impl( node->forall, *this );
    3661 
    3662         VISIT_END( node );
    3663 }
    3664 
    3665 template< typename pass_type >
    3666 Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) {
    3667         MUTATE_START( node );
    3668 
    3669         maybeMutate_impl( node->forall, *this );
    3670 
    3671         MUTATE_END( Type, node );
    3672 }
    3673 
    3674 //--------------------------------------------------------------------------
    36752519// Designation
    36762520template< typename pass_type >
     
    36842528
    36852529template< typename pass_type >
    3686 void PassVisitor< pass_type >::visit( const Designation * node ) {
    3687         VISIT_START( node );
    3688 
    3689         maybeAccept_impl( node->designators, *this );
    3690 
    3691         VISIT_END( node );
    3692 }
    3693 
    3694 template< typename pass_type >
    36952530Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
    36962531        MUTATE_START( node );
     
    37132548
    37142549template< typename pass_type >
    3715 void PassVisitor< pass_type >::visit( const SingleInit * node ) {
    3716         VISIT_START( node );
    3717 
    3718         visitExpression( node->value );
    3719 
    3720         VISIT_END( node );
    3721 }
    3722 
    3723 template< typename pass_type >
    37242550Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
    37252551        MUTATE_START( node );
     
    37342560template< typename pass_type >
    37352561void PassVisitor< pass_type >::visit( ListInit * node ) {
    3736         VISIT_START( node );
    3737 
    3738         maybeAccept_impl( node->designations, *this );
    3739         maybeAccept_impl( node->initializers, *this );
    3740 
    3741         VISIT_END( node );
    3742 }
    3743 
    3744 template< typename pass_type >
    3745 void PassVisitor< pass_type >::visit( const ListInit * node ) {
    37462562        VISIT_START( node );
    37472563
     
    37762592
    37772593template< typename pass_type >
    3778 void PassVisitor< pass_type >::visit( const ConstructorInit * node ) {
    3779         VISIT_START( node );
    3780 
    3781         maybeAccept_impl( node->ctor, *this );
    3782         maybeAccept_impl( node->dtor, *this );
    3783         maybeAccept_impl( node->init, *this );
    3784 
    3785         VISIT_END( node );
    3786 }
    3787 
    3788 template< typename pass_type >
    37892594Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
    37902595        MUTATE_START( node );
     
    37982603
    37992604//--------------------------------------------------------------------------
     2605// Subrange
     2606template< typename pass_type >
     2607void PassVisitor< pass_type >::visit( Subrange * node ) {
     2608        VISIT_START( node );
     2609
     2610        VISIT_END( node );
     2611}
     2612
     2613template< typename pass_type >
     2614Subrange * PassVisitor< pass_type >::mutate( Subrange * node  )  {
     2615        MUTATE_START( node );
     2616
     2617        MUTATE_END( Subrange, node );
     2618}
     2619
     2620//--------------------------------------------------------------------------
    38002621// Attribute
    38012622template< typename pass_type >
     
    38072628
    38082629template< typename pass_type >
    3809 void PassVisitor< pass_type >::visit( const Constant * node ) {
    3810         VISIT_START( node );
    3811 
    3812         VISIT_END( node );
    3813 }
    3814 
    3815 template< typename pass_type >
    38162630Constant * PassVisitor< pass_type >::mutate( Constant * node  )  {
    38172631        MUTATE_START( node );
     
    38242638template< typename pass_type >
    38252639void PassVisitor< pass_type >::visit( Attribute * node ) {
    3826         VISIT_START( node );
    3827 
    3828         maybeAccept_impl( node->parameters, *this );
    3829 
    3830         VISIT_END( node );
    3831 }
    3832 
    3833 template< typename pass_type >
    3834 void PassVisitor< pass_type >::visit( const Attribute * node ) {
    38352640        VISIT_START( node );
    38362641
     
    38642669        MUTATE_END( TypeSubstitution, node );
    38652670}
    3866 
    3867 #undef VISIT_START
    3868 #undef VISIT_END
    3869 
    3870 #undef MUTATE_START
    3871 #undef MUTATE_END
Note: See TracChangeset for help on using the changeset viewer.