Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r3e5dd913 r665f432  
    2020#include <unordered_map>
    2121
    22 #include "AST/TranslationUnit.hpp"
    2322#include "AST/TypeSubstitution.hpp"
    2423
     
    2625        using namespace ast; \
    2726        /* back-up the visit children */ \
    28         __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \
     27        __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(pass, 0) ); \
    2928        /* setup the scope for passes that want to run code at exit */ \
    30         __attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (core, 0) ); \
    31         /* begin tracing memory allocation if requested by this pass */ \
    32         __pass::beginTrace( core, 0 ); \
     29        __attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (pass, 0) ); \
    3330        /* call the implementation of the previsit of this pass */ \
    34         __pass::previsit( core, node, 0 );
     31        __pass::previsit( pass, node, 0 );
    3532
    3633#define VISIT( code... ) \
     
    4340#define VISIT_END( type, node ) \
    4441        /* call the implementation of the postvisit of this pass */ \
    45         auto __return = __pass::postvisit( core, node, 0 ); \
     42        auto __return = __pass::postvisit( pass, node, 0 ); \
    4643        assertf(__return, "post visit should never return null"); \
    47         /* end tracing memory allocation if requested by this pass */ \
    48         __pass::endTrace( core, 0 ); \
    4944        return __return;
    5045
     
    5853
    5954namespace ast {
    60         template<typename node_t>
    61         node_t * shallowCopy( const node_t * node );
    62 
    6355        namespace __pass {
    6456                // Check if this is either a null pointer or a pointer to an empty container
     
    6860                }
    6961
    70                 template< typename core_t, typename node_t >
    71                 static inline node_t* mutate(const node_t *node) {
    72                         return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node);
    73                 }
    74 
    7562                //------------------------------
    7663                template<typename it_t, template <class...> class container_t>
     
    132119        }
    133120
    134         template< typename core_t >
     121        template< typename pass_t >
    135122        template< typename node_t >
    136         auto ast::Pass< core_t >::call_accept( const node_t * node )
     123        auto ast::Pass< pass_t >::call_accept( const node_t * node )
    137124                -> typename std::enable_if<
    138125                                !std::is_base_of<ast::Expr, node_t>::value &&
     
    140127                        , decltype( node->accept(*this) )
    141128                >::type
     129
    142130        {
    143131                __pedantic_pass_assert( __visit_children() );
    144                 __pedantic_pass_assert( node );
     132                __pedantic_pass_assert( expr );
    145133
    146134                static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR");
     
    150138        }
    151139
    152         template< typename core_t >
    153         const ast::Expr * ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
     140        template< typename pass_t >
     141        const ast::Expr * ast::Pass< pass_t >::call_accept( const ast::Expr * expr ) {
    154142                __pedantic_pass_assert( __visit_children() );
    155143                __pedantic_pass_assert( expr );
    156144
    157                 const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
    158                 if ( typeSubs_ptr && expr->env ) {
    159                         *typeSubs_ptr = expr->env;
     145                const ast::TypeSubstitution ** env_ptr = __pass::env( pass, 0);
     146                if ( env_ptr && expr->env ) {
     147                        *env_ptr = expr->env;
    160148                }
    161149
     
    163151        }
    164152
    165         template< typename core_t >
    166         const ast::Stmt * ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
     153        template< typename pass_t >
     154        const ast::Stmt * ast::Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {
    167155                __pedantic_pass_assert( __visit_children() );
    168156                __pedantic_pass_assert( stmt );
    169157
    170                 return stmt->accept( *this );
    171         }
    172 
    173         template< typename core_t >
    174         const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
    175                 __pedantic_pass_assert( __visit_children() );
    176                 __pedantic_pass_assert( stmt );
    177 
    178158                // add a few useful symbols to the scope
    179159                using __pass::empty;
    180160
    181161                // get the stmts/decls that will need to be spliced in
    182                 auto stmts_before = __pass::stmtsToAddBefore( core, 0);
    183                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0);
    184                 auto decls_before = __pass::declsToAddBefore( core, 0);
    185                 auto decls_after  = __pass::declsToAddAfter ( core, 0);
     162                auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
     163                auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
     164                auto decls_before = __pass::declsToAddBefore( pass, 0);
     165                auto decls_after  = __pass::declsToAddAfter ( pass, 0);
    186166
    187167                // These may be modified by subnode but most be restored once we exit this statemnet.
    188                 ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::typeSubs( core, 0 ) );
     168                ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( pass, 0) );
    189169                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    190170                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     
    222202        }
    223203
    224         template< typename core_t >
     204        template< typename pass_t >
    225205        template< template <class...> class container_t >
    226         container_t< ptr<Stmt> > ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
     206        container_t< ptr<Stmt> > ast::Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    227207                __pedantic_pass_assert( __visit_children() );
    228208                if( statements.empty() ) return {};
     
    235215
    236216                // get the stmts/decls that will need to be spliced in
    237                 auto stmts_before = __pass::stmtsToAddBefore( core, 0);
    238                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0);
    239                 auto decls_before = __pass::declsToAddBefore( core, 0);
    240                 auto decls_after  = __pass::declsToAddAfter ( core, 0);
     217                auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
     218                auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
     219                auto decls_before = __pass::declsToAddBefore( pass, 0);
     220                auto decls_after  = __pass::declsToAddAfter ( pass, 0);
    241221
    242222                // These may be modified by subnode but most be restored once we exit this statemnet.
     
    288268        }
    289269
    290         template< typename core_t >
     270        template< typename pass_t >
    291271        template< template <class...> class container_t, typename node_t >
    292         container_t< ast::ptr<node_t> > ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
     272        container_t< ast::ptr<node_t> > ast::Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    293273                __pedantic_pass_assert( __visit_children() );
    294274                if( container.empty() ) return {};
     
    319299        }
    320300
    321         template< typename core_t >
     301        template< typename pass_t >
    322302        template<typename node_t, typename parent_t, typename child_t>
    323         void ast::Pass< core_t >::maybe_accept(
     303        void ast::Pass< pass_t >::maybe_accept(
    324304                const node_t * & parent,
    325305                child_t parent_t::*child
     
    337317
    338318                if( __pass::differs(old_val, new_val) ) {
    339                         auto new_parent = __pass::mutate<core_t>(parent);
    340                         new_parent->*child = new_val;
    341                         parent = new_parent;
    342                 }
    343         }
    344 
    345         template< typename core_t >
    346         template<typename node_t, typename parent_t, typename child_t>
    347         void ast::Pass< core_t >::maybe_accept_as_compound(
    348                 const node_t * & parent,
    349                 child_t parent_t::*child
    350         ) {
    351                 static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" );
    352 
    353                 if(__pass::skip(parent->*child)) return;
    354                 const auto & old_val = __pass::get(parent->*child, 0);
    355 
    356                 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
    357 
    358                 auto new_val = call_accept_as_compound( old_val );
    359 
    360                 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
    361 
    362                 if( __pass::differs(old_val, new_val) ) {
    363                         auto new_parent = __pass::mutate<core_t>(parent);
     319                        auto new_parent = mutate(parent);
    364320                        new_parent->*child = new_val;
    365321                        parent = new_parent;
     
    377333//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    378334
    379 template< typename core_t >
    380 inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< core_t > & visitor ) {
     335template< typename pass_t >
     336inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {
    381337        // We are going to aggregate errors for all these statements
    382338        SemanticErrorException errors;
     
    386342
    387343        // get the stmts/decls that will need to be spliced in
    388         auto decls_before = __pass::declsToAddBefore( visitor.core, 0);
    389         auto decls_after  = __pass::declsToAddAfter ( visitor.core, 0);
     344        auto decls_before = __pass::declsToAddBefore( visitor.pass, 0);
     345        auto decls_after  = __pass::declsToAddAfter ( visitor.pass, 0);
    390346
    391347        // update pass statitistics
     
    407363                }
    408364                catch( SemanticErrorException &e ) {
    409                         if (__pass::on_error (visitor.core, *i, 0))
    410                                 errors.append( e );
     365                        errors.append( e );
    411366                }
    412367
     
    416371        pass_visitor_stats.depth--;
    417372        if ( !errors.isEmpty() ) { throw errors; }
    418 }
    419 
    420 template< typename core_t >
    421 inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) {
    422         return ast::accept_all( unit.decls, visitor );
    423373}
    424374
     
    442392//--------------------------------------------------------------------------
    443393// ObjectDecl
    444 template< typename core_t >
    445 const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::ObjectDecl * node ) {
     394template< typename pass_t >
     395const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {
    446396        VISIT_START( node );
    447397
     
    456406        )
    457407
    458         __pass::symtab::addId( core, 0, node );
     408        __pass::symtab::addId( pass, 0, node );
    459409
    460410        VISIT_END( DeclWithType, node );
     
    463413//--------------------------------------------------------------------------
    464414// FunctionDecl
    465 template< typename core_t >
    466 const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::FunctionDecl * node ) {
    467         VISIT_START( node );
    468 
    469         __pass::symtab::addId( core, 0, node );
     415template< typename pass_t >
     416const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::FunctionDecl * node ) {
     417        VISIT_START( node );
     418
     419        __pass::symtab::addId( pass, 0, node );
    470420
    471421        VISIT(maybe_accept( node, &FunctionDecl::withExprs );)
     
    475425                // shadow with exprs and not the other way around.
    476426                guard_symtab guard { *this };
    477                 __pass::symtab::addWith( core, 0, node->withExprs, node );
     427                __pass::symtab::addWith( pass, 0, node->withExprs, node );
    478428                {
    479429                        guard_symtab guard { *this };
    480430                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
    481                         static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{
    482                                 CodeLocation{}, "__func__",
    483                                 new ast::ArrayType{
    484                                         new ast::BasicType{ ast::BasicType::Char, ast::CV::Const },
     431                        static ast::ObjectDecl func(
     432                                node->location, "__func__",
     433                                new ast::ArrayType(
     434                                        new ast::BasicType( ast::BasicType::Char, ast::CV::Qualifiers( ast::CV::Const ) ),
    485435                                        nullptr, VariableLen, DynamicDim
    486                                 }
    487                         } };
    488                         __pass::symtab::addId( core, 0, func );
     436                                )
     437                        );
     438                        __pass::symtab::addId( pass, 0, &func );
    489439                        VISIT(
    490                                 // parameter declarations
    491                                 maybe_accept( node, &FunctionDecl::params );
    492                                 maybe_accept( node, &FunctionDecl::returns );
    493                                 // type params and assertions
    494                                 maybe_accept( node, &FunctionDecl::type_params );
    495                                 maybe_accept( node, &FunctionDecl::assertions );
    496                                 // First remember that we are now within a function.
     440                                maybe_accept( node, &FunctionDecl::type );
     441                                // function body needs to have the same scope as parameters - CompoundStmt will not enter
     442                                // a new scope if inFunction is true
    497443                                ValueGuard< bool > oldInFunction( inFunction );
    498444                                inFunction = true;
    499                                 // The function body needs to have the same scope as parameters.
    500                                 // A CompoundStmt will not enter a new scope if atFunctionTop is true.
    501                                 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
    502                                 atFunctionTop = true;
    503445                                maybe_accept( node, &FunctionDecl::stmts );
    504446                                maybe_accept( node, &FunctionDecl::attributes );
     
    512454//--------------------------------------------------------------------------
    513455// StructDecl
    514 template< typename core_t >
    515 const ast::Decl * ast::Pass< core_t >::visit( const ast::StructDecl * node ) {
     456template< typename pass_t >
     457const ast::Decl * ast::Pass< pass_t >::visit( const ast::StructDecl * node ) {
    516458        VISIT_START( node );
    517459
    518460        // make up a forward declaration and add it before processing the members
    519461        // needs to be on the heap because addStruct saves the pointer
    520         __pass::symtab::addStructFwd( core, 0, node );
     462        __pass::symtab::addStructFwd( pass, 0, node );
    521463
    522464        VISIT({
     
    527469
    528470        // this addition replaces the forward declaration
    529         __pass::symtab::addStruct( core, 0, node );
     471        __pass::symtab::addStruct( pass, 0, node );
    530472
    531473        VISIT_END( Decl, node );
     
    534476//--------------------------------------------------------------------------
    535477// UnionDecl
    536 template< typename core_t >
    537 const ast::Decl * ast::Pass< core_t >::visit( const ast::UnionDecl * node ) {
     478template< typename pass_t >
     479const ast::Decl * ast::Pass< pass_t >::visit( const ast::UnionDecl * node ) {
    538480        VISIT_START( node );
    539481
    540482        // make up a forward declaration and add it before processing the members
    541         __pass::symtab::addUnionFwd( core, 0, node );
     483        __pass::symtab::addUnionFwd( pass, 0, node );
    542484
    543485        VISIT({
     
    547489        })
    548490
    549         __pass::symtab::addUnion( core, 0, node );
     491        __pass::symtab::addUnion( pass, 0, node );
    550492
    551493        VISIT_END( Decl, node );
     
    554496//--------------------------------------------------------------------------
    555497// EnumDecl
    556 template< typename core_t >
    557 const ast::Decl * ast::Pass< core_t >::visit( const ast::EnumDecl * node ) {
    558         VISIT_START( node );
    559 
    560         __pass::symtab::addEnum( core, 0, node );
     498template< typename pass_t >
     499const ast::Decl * ast::Pass< pass_t >::visit( const ast::EnumDecl * node ) {
     500        VISIT_START( node );
     501
     502        __pass::symtab::addEnum( pass, 0, node );
    561503
    562504        VISIT(
     
    571513//--------------------------------------------------------------------------
    572514// TraitDecl
    573 template< typename core_t >
    574 const ast::Decl * ast::Pass< core_t >::visit( const ast::TraitDecl * node ) {
     515template< typename pass_t >
     516const ast::Decl * ast::Pass< pass_t >::visit( const ast::TraitDecl * node ) {
    575517        VISIT_START( node );
    576518
     
    581523        })
    582524
    583         __pass::symtab::addTrait( core, 0, node );
     525        __pass::symtab::addTrait( pass, 0, node );
    584526
    585527        VISIT_END( Decl, node );
     
    588530//--------------------------------------------------------------------------
    589531// TypeDecl
    590 template< typename core_t >
    591 const ast::Decl * ast::Pass< core_t >::visit( const ast::TypeDecl * node ) {
     532template< typename pass_t >
     533const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypeDecl * node ) {
    592534        VISIT_START( node );
    593535
    594536        VISIT({
    595537                guard_symtab guard { *this };
     538                maybe_accept( node, &TypeDecl::params );
    596539                maybe_accept( node, &TypeDecl::base   );
    597540        })
     
    600543        // note that assertions come after the type is added to the symtab, since they are not part of the type proper
    601544        // and may depend on the type itself
    602         __pass::symtab::addType( core, 0, node );
     545        __pass::symtab::addType( pass, 0, node );
    603546
    604547        VISIT(
     
    616559//--------------------------------------------------------------------------
    617560// TypedefDecl
    618 template< typename core_t >
    619 const ast::Decl * ast::Pass< core_t >::visit( const ast::TypedefDecl * node ) {
     561template< typename pass_t >
     562const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypedefDecl * node ) {
    620563        VISIT_START( node );
    621564
    622565        VISIT({
    623566                guard_symtab guard { *this };
     567                maybe_accept( node, &TypedefDecl::params );
    624568                maybe_accept( node, &TypedefDecl::base   );
    625569        })
    626570
    627         __pass::symtab::addType( core, 0, node );
     571        __pass::symtab::addType( pass, 0, node );
    628572
    629573        VISIT( maybe_accept( node, &TypedefDecl::assertions ); )
     
    634578//--------------------------------------------------------------------------
    635579// AsmDecl
    636 template< typename core_t >
    637 const ast::AsmDecl * ast::Pass< core_t >::visit( const ast::AsmDecl * node ) {
     580template< typename pass_t >
     581const ast::AsmDecl * ast::Pass< pass_t >::visit( const ast::AsmDecl * node ) {
    638582        VISIT_START( node );
    639583
     
    647591//--------------------------------------------------------------------------
    648592// StaticAssertDecl
    649 template< typename core_t >
    650 const ast::StaticAssertDecl * ast::Pass< core_t >::visit( const ast::StaticAssertDecl * node ) {
     593template< typename pass_t >
     594const ast::StaticAssertDecl * ast::Pass< pass_t >::visit( const ast::StaticAssertDecl * node ) {
    651595        VISIT_START( node );
    652596
     
    661605//--------------------------------------------------------------------------
    662606// CompoundStmt
    663 template< typename core_t >
    664 const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) {
    665         VISIT_START( node );
    666         VISIT(
    667                 // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.
    668                 auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {
    669                         if ( enterScope ) {
    670                                 __pass::symtab::enter(core, 0);
    671                                 __pass::scope::enter(core, 0);
    672                         }
    673                 }, [this, leaveScope = !this->atFunctionTop]() {
    674                         if ( leaveScope ) {
    675                                 __pass::symtab::leave(core, 0);
    676                                 __pass::scope::leave(core, 0);
    677                         }
     607template< typename pass_t >
     608const ast::CompoundStmt * ast::Pass< pass_t >::visit( const ast::CompoundStmt * node ) {
     609        VISIT_START( node );
     610        VISIT({
     611                // do not enter a new scope if inFunction is true - needs to check old state before the assignment
     612                auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() {
     613                        if ( ! inFunction ) __pass::symtab::enter(pass, 0);
     614                }, [this, inFunction = this->inFunction]() {
     615                        if ( ! inFunction ) __pass::symtab::leave(pass, 0);
    678616                });
    679                 ValueGuard< bool > guard2( atFunctionTop );
    680                 atFunctionTop = false;
     617                ValueGuard< bool > guard2( inFunction );
    681618                guard_scope guard3 { *this };
     619                inFunction = false;
    682620                maybe_accept( node, &CompoundStmt::kids );
    683         )
     621        })
    684622        VISIT_END( CompoundStmt, node );
    685623}
     
    687625//--------------------------------------------------------------------------
    688626// ExprStmt
    689 template< typename core_t >
    690 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ExprStmt * node ) {
     627template< typename pass_t >
     628const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ExprStmt * node ) {
    691629        VISIT_START( node );
    692630
     
    700638//--------------------------------------------------------------------------
    701639// AsmStmt
    702 template< typename core_t >
    703 const ast::Stmt * ast::Pass< core_t >::visit( const ast::AsmStmt * node ) {
     640template< typename pass_t >
     641const ast::Stmt * ast::Pass< pass_t >::visit( const ast::AsmStmt * node ) {
    704642        VISIT_START( node )
    705643
     
    716654//--------------------------------------------------------------------------
    717655// DirectiveStmt
    718 template< typename core_t >
    719 const ast::Stmt * ast::Pass< core_t >::visit( const ast::DirectiveStmt * node ) {
     656template< typename pass_t >
     657const ast::Stmt * ast::Pass< pass_t >::visit( const ast::DirectiveStmt * node ) {
    720658        VISIT_START( node )
    721659
     
    725663//--------------------------------------------------------------------------
    726664// IfStmt
    727 template< typename core_t >
    728 const ast::Stmt * ast::Pass< core_t >::visit( const ast::IfStmt * node ) {
     665template< typename pass_t >
     666const ast::Stmt * ast::Pass< pass_t >::visit( const ast::IfStmt * node ) {
    729667        VISIT_START( node );
    730668
     
    734672                maybe_accept( node, &IfStmt::inits    );
    735673                maybe_accept( node, &IfStmt::cond     );
    736                 maybe_accept_as_compound( node, &IfStmt::thenPart );
    737                 maybe_accept_as_compound( node, &IfStmt::elsePart );
     674                maybe_accept( node, &IfStmt::thenPart );
     675                maybe_accept( node, &IfStmt::elsePart );
    738676        })
    739677
     
    743681//--------------------------------------------------------------------------
    744682// WhileStmt
    745 template< typename core_t >
    746 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileStmt * node ) {
     683template< typename pass_t >
     684const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WhileStmt * node ) {
    747685        VISIT_START( node );
    748686
     
    752690                maybe_accept( node, &WhileStmt::inits );
    753691                maybe_accept( node, &WhileStmt::cond  );
    754                 maybe_accept_as_compound( node, &WhileStmt::body  );
     692                maybe_accept( node, &WhileStmt::body  );
    755693        })
    756694
     
    760698//--------------------------------------------------------------------------
    761699// ForStmt
    762 template< typename core_t >
    763 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ForStmt * node ) {
     700template< typename pass_t >
     701const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ForStmt * node ) {
    764702        VISIT_START( node );
    765703
     
    767705                // for statements introduce a level of scope (for the initialization)
    768706                guard_symtab guard { *this };
    769                 // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later.
    770707                maybe_accept( node, &ForStmt::inits );
    771708                maybe_accept( node, &ForStmt::cond  );
    772709                maybe_accept( node, &ForStmt::inc   );
    773                 maybe_accept_as_compound( node, &ForStmt::body  );
     710                maybe_accept( node, &ForStmt::body  );
    774711        })
    775712
     
    779716//--------------------------------------------------------------------------
    780717// SwitchStmt
    781 template< typename core_t >
    782 const ast::Stmt * ast::Pass< core_t >::visit( const ast::SwitchStmt * node ) {
     718template< typename pass_t >
     719const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SwitchStmt * node ) {
    783720        VISIT_START( node );
    784721
     
    793730//--------------------------------------------------------------------------
    794731// CaseStmt
    795 template< typename core_t >
    796 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt * node ) {
     732template< typename pass_t >
     733const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CaseStmt * node ) {
    797734        VISIT_START( node );
    798735
     
    807744//--------------------------------------------------------------------------
    808745// BranchStmt
    809 template< typename core_t >
    810 const ast::Stmt * ast::Pass< core_t >::visit( const ast::BranchStmt * node ) {
     746template< typename pass_t >
     747const ast::Stmt * ast::Pass< pass_t >::visit( const ast::BranchStmt * node ) {
    811748        VISIT_START( node );
    812749        VISIT_END( Stmt, node );
     
    815752//--------------------------------------------------------------------------
    816753// ReturnStmt
    817 template< typename core_t >
    818 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ReturnStmt * node ) {
     754template< typename pass_t >
     755const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ReturnStmt * node ) {
    819756        VISIT_START( node );
    820757
     
    828765//--------------------------------------------------------------------------
    829766// ThrowStmt
    830 template< typename core_t >
    831 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ThrowStmt * node ) {
     767template< typename pass_t >
     768const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ThrowStmt * node ) {
    832769        VISIT_START( node );
    833770
     
    842779//--------------------------------------------------------------------------
    843780// TryStmt
    844 template< typename core_t >
    845 const ast::Stmt * ast::Pass< core_t >::visit( const ast::TryStmt * node ) {
     781template< typename pass_t >
     782const ast::Stmt * ast::Pass< pass_t >::visit( const ast::TryStmt * node ) {
    846783        VISIT_START( node );
    847784
     
    857794//--------------------------------------------------------------------------
    858795// CatchStmt
    859 template< typename core_t >
    860 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt * node ) {
     796template< typename pass_t >
     797const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CatchStmt * node ) {
    861798        VISIT_START( node );
    862799
     
    866803                maybe_accept( node, &CatchStmt::decl );
    867804                maybe_accept( node, &CatchStmt::cond );
    868                 maybe_accept_as_compound( node, &CatchStmt::body );
     805                maybe_accept( node, &CatchStmt::body );
    869806        })
    870807
     
    874811//--------------------------------------------------------------------------
    875812// FinallyStmt
    876 template< typename core_t >
    877 const ast::Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt * node ) {
     813template< typename pass_t >
     814const ast::Stmt * ast::Pass< pass_t >::visit( const ast::FinallyStmt * node ) {
    878815        VISIT_START( node );
    879816
     
    886823
    887824//--------------------------------------------------------------------------
    888 // FinallyStmt
    889 template< typename core_t >
    890 const ast::Stmt * ast::Pass< core_t >::visit( const ast::SuspendStmt * node ) {
    891         VISIT_START( node );
    892 
    893         VISIT(
    894                 maybe_accept( node, &SuspendStmt::then   );
    895         )
    896 
    897         VISIT_END( Stmt, node );
    898 }
    899 
    900 //--------------------------------------------------------------------------
    901825// WaitForStmt
    902 template< typename core_t >
    903 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitForStmt * node ) {
     826template< typename pass_t >
     827const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WaitForStmt * node ) {
    904828        VISIT_START( node );
    905829                // for( auto & clause : node->clauses ) {
     
    938862
    939863                if(mutated) {
    940                         auto n = __pass::mutate<core_t>(node);
     864                        auto n = mutate(node);
    941865                        n->clauses = std::move( new_clauses );
    942866                        node = n;
     
    948872                        auto nval = call_accept( node->field ); \
    949873                        if(nval != node->field ) { \
    950                                 auto nparent = __pass::mutate<core_t>(node); \
     874                                auto nparent = mutate(node); \
    951875                                nparent->field = nval; \
    952876                                node = nparent; \
     
    969893//--------------------------------------------------------------------------
    970894// WithStmt
    971 template< typename core_t >
    972 const ast::Decl * ast::Pass< core_t >::visit( const ast::WithStmt * node ) {
     895template< typename pass_t >
     896const ast::Decl * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) {
    973897        VISIT_START( node );
    974898
     
    978902                        // catch statements introduce a level of scope (for the caught exception)
    979903                        guard_symtab guard { *this };
    980                         __pass::symtab::addWith( core, 0, node->exprs, node );
     904                        __pass::symtab::addWith( pass, 0, node->exprs, node );
    981905                        maybe_accept( node, &WithStmt::stmt );
    982906                }
     
    987911//--------------------------------------------------------------------------
    988912// NullStmt
    989 template< typename core_t >
    990 const ast::NullStmt * ast::Pass< core_t >::visit( const ast::NullStmt * node ) {
     913template< typename pass_t >
     914const ast::NullStmt * ast::Pass< pass_t >::visit( const ast::NullStmt * node ) {
    991915        VISIT_START( node );
    992916        VISIT_END( NullStmt, node );
     
    995919//--------------------------------------------------------------------------
    996920// DeclStmt
    997 template< typename core_t >
    998 const ast::Stmt * ast::Pass< core_t >::visit( const ast::DeclStmt * node ) {
     921template< typename pass_t >
     922const ast::Stmt * ast::Pass< pass_t >::visit( const ast::DeclStmt * node ) {
    999923        VISIT_START( node );
    1000924
     
    1008932//--------------------------------------------------------------------------
    1009933// ImplicitCtorDtorStmt
    1010 template< typename core_t >
    1011 const ast::Stmt * ast::Pass< core_t >::visit( const ast::ImplicitCtorDtorStmt * node ) {
     934template< typename pass_t >
     935const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ImplicitCtorDtorStmt * node ) {
    1012936        VISIT_START( node );
    1013937
    1014938        // For now this isn't visited, it is unclear if this causes problem
    1015939        // if all tests are known to pass, remove this code
    1016         VISIT(
    1017                 maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
    1018         )
     940        // VISIT(
     941        //      maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
     942        // )
    1019943
    1020944        VISIT_END( Stmt, node );
     
    1023947//--------------------------------------------------------------------------
    1024948// ApplicationExpr
    1025 template< typename core_t >
    1026 const ast::Expr * ast::Pass< core_t >::visit( const ast::ApplicationExpr * node ) {
     949template< typename pass_t >
     950const ast::Expr * ast::Pass< pass_t >::visit( const ast::ApplicationExpr * node ) {
    1027951        VISIT_START( node );
    1028952
     
    1041965//--------------------------------------------------------------------------
    1042966// UntypedExpr
    1043 template< typename core_t >
    1044 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedExpr * node ) {
     967template< typename pass_t >
     968const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedExpr * node ) {
    1045969        VISIT_START( node );
    1046970
     
    1059983//--------------------------------------------------------------------------
    1060984// NameExpr
    1061 template< typename core_t >
    1062 const ast::Expr * ast::Pass< core_t >::visit( const ast::NameExpr * node ) {
     985template< typename pass_t >
     986const ast::Expr * ast::Pass< pass_t >::visit( const ast::NameExpr * node ) {
    1063987        VISIT_START( node );
    1064988
     
    1073997//--------------------------------------------------------------------------
    1074998// CastExpr
    1075 template< typename core_t >
    1076 const ast::Expr * ast::Pass< core_t >::visit( const ast::CastExpr * node ) {
     999template< typename pass_t >
     1000const ast::Expr * ast::Pass< pass_t >::visit( const ast::CastExpr * node ) {
    10771001        VISIT_START( node );
    10781002
     
    10891013//--------------------------------------------------------------------------
    10901014// KeywordCastExpr
    1091 template< typename core_t >
    1092 const ast::Expr * ast::Pass< core_t >::visit( const ast::KeywordCastExpr * node ) {
     1015template< typename pass_t >
     1016const ast::Expr * ast::Pass< pass_t >::visit( const ast::KeywordCastExpr * node ) {
    10931017        VISIT_START( node );
    10941018
     
    11051029//--------------------------------------------------------------------------
    11061030// VirtualCastExpr
    1107 template< typename core_t >
    1108 const ast::Expr * ast::Pass< core_t >::visit( const ast::VirtualCastExpr * node ) {
     1031template< typename pass_t >
     1032const ast::Expr * ast::Pass< pass_t >::visit( const ast::VirtualCastExpr * node ) {
    11091033        VISIT_START( node );
    11101034
     
    11211045//--------------------------------------------------------------------------
    11221046// AddressExpr
    1123 template< typename core_t >
    1124 const ast::Expr * ast::Pass< core_t >::visit( const ast::AddressExpr * node ) {
     1047template< typename pass_t >
     1048const ast::Expr * ast::Pass< pass_t >::visit( const ast::AddressExpr * node ) {
    11251049        VISIT_START( node );
    11261050
     
    11371061//--------------------------------------------------------------------------
    11381062// LabelAddressExpr
    1139 template< typename core_t >
    1140 const ast::Expr * ast::Pass< core_t >::visit( const ast::LabelAddressExpr * node ) {
     1063template< typename pass_t >
     1064const ast::Expr * ast::Pass< pass_t >::visit( const ast::LabelAddressExpr * node ) {
    11411065        VISIT_START( node );
    11421066
     
    11511075//--------------------------------------------------------------------------
    11521076// UntypedMemberExpr
    1153 template< typename core_t >
    1154 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedMemberExpr * node ) {
     1077template< typename pass_t >
     1078const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedMemberExpr * node ) {
    11551079        VISIT_START( node );
    11561080
     
    11681092//--------------------------------------------------------------------------
    11691093// MemberExpr
    1170 template< typename core_t >
    1171 const ast::Expr * ast::Pass< core_t >::visit( const ast::MemberExpr * node ) {
     1094template< typename pass_t >
     1095const ast::Expr * ast::Pass< pass_t >::visit( const ast::MemberExpr * node ) {
    11721096        VISIT_START( node );
    11731097
     
    11841108//--------------------------------------------------------------------------
    11851109// VariableExpr
    1186 template< typename core_t >
    1187 const ast::Expr * ast::Pass< core_t >::visit( const ast::VariableExpr * node ) {
     1110template< typename pass_t >
     1111const ast::Expr * ast::Pass< pass_t >::visit( const ast::VariableExpr * node ) {
    11881112        VISIT_START( node );
    11891113
     
    11981122//--------------------------------------------------------------------------
    11991123// ConstantExpr
    1200 template< typename core_t >
    1201 const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstantExpr * node ) {
     1124template< typename pass_t >
     1125const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstantExpr * node ) {
    12021126        VISIT_START( node );
    12031127
     
    12121136//--------------------------------------------------------------------------
    12131137// SizeofExpr
    1214 template< typename core_t >
    1215 const ast::Expr * ast::Pass< core_t >::visit( const ast::SizeofExpr * node ) {
     1138template< typename pass_t >
     1139const ast::Expr * ast::Pass< pass_t >::visit( const ast::SizeofExpr * node ) {
    12161140        VISIT_START( node );
    12171141
     
    12321156//--------------------------------------------------------------------------
    12331157// AlignofExpr
    1234 template< typename core_t >
    1235 const ast::Expr * ast::Pass< core_t >::visit( const ast::AlignofExpr * node ) {
     1158template< typename pass_t >
     1159const ast::Expr * ast::Pass< pass_t >::visit( const ast::AlignofExpr * node ) {
    12361160        VISIT_START( node );
    12371161
     
    12521176//--------------------------------------------------------------------------
    12531177// UntypedOffsetofExpr
    1254 template< typename core_t >
    1255 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedOffsetofExpr * node ) {
     1178template< typename pass_t >
     1179const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedOffsetofExpr * node ) {
    12561180        VISIT_START( node );
    12571181
     
    12681192//--------------------------------------------------------------------------
    12691193// OffsetofExpr
    1270 template< typename core_t >
    1271 const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetofExpr * node ) {
     1194template< typename pass_t >
     1195const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetofExpr * node ) {
    12721196        VISIT_START( node );
    12731197
     
    12841208//--------------------------------------------------------------------------
    12851209// OffsetPackExpr
    1286 template< typename core_t >
    1287 const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetPackExpr * node ) {
     1210template< typename pass_t >
     1211const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetPackExpr * node ) {
    12881212        VISIT_START( node );
    12891213
     
    13001224//--------------------------------------------------------------------------
    13011225// LogicalExpr
    1302 template< typename core_t >
    1303 const ast::Expr * ast::Pass< core_t >::visit( const ast::LogicalExpr * node ) {
     1226template< typename pass_t >
     1227const ast::Expr * ast::Pass< pass_t >::visit( const ast::LogicalExpr * node ) {
    13041228        VISIT_START( node );
    13051229
     
    13171241//--------------------------------------------------------------------------
    13181242// ConditionalExpr
    1319 template< typename core_t >
    1320 const ast::Expr * ast::Pass< core_t >::visit( const ast::ConditionalExpr * node ) {
     1243template< typename pass_t >
     1244const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConditionalExpr * node ) {
    13211245        VISIT_START( node );
    13221246
     
    13351259//--------------------------------------------------------------------------
    13361260// CommaExpr
    1337 template< typename core_t >
    1338 const ast::Expr * ast::Pass< core_t >::visit( const ast::CommaExpr * node ) {
     1261template< typename pass_t >
     1262const ast::Expr * ast::Pass< pass_t >::visit( const ast::CommaExpr * node ) {
    13391263        VISIT_START( node );
    13401264
     
    13521276//--------------------------------------------------------------------------
    13531277// TypeExpr
    1354 template< typename core_t >
    1355 const ast::Expr * ast::Pass< core_t >::visit( const ast::TypeExpr * node ) {
     1278template< typename pass_t >
     1279const ast::Expr * ast::Pass< pass_t >::visit( const ast::TypeExpr * node ) {
    13561280        VISIT_START( node );
    13571281
     
    13681292//--------------------------------------------------------------------------
    13691293// AsmExpr
    1370 template< typename core_t >
    1371 const ast::Expr * ast::Pass< core_t >::visit( const ast::AsmExpr * node ) {
     1294template< typename pass_t >
     1295const ast::Expr * ast::Pass< pass_t >::visit( const ast::AsmExpr * node ) {
    13721296        VISIT_START( node );
    13731297
     
    13851309//--------------------------------------------------------------------------
    13861310// ImplicitCopyCtorExpr
    1387 template< typename core_t >
    1388 const ast::Expr * ast::Pass< core_t >::visit( const ast::ImplicitCopyCtorExpr * node ) {
     1311template< typename pass_t >
     1312const ast::Expr * ast::Pass< pass_t >::visit( const ast::ImplicitCopyCtorExpr * node ) {
    13891313        VISIT_START( node );
    13901314
     
    14011325//--------------------------------------------------------------------------
    14021326// ConstructorExpr
    1403 template< typename core_t >
    1404 const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstructorExpr * node ) {
     1327template< typename pass_t >
     1328const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstructorExpr * node ) {
    14051329        VISIT_START( node );
    14061330
     
    14171341//--------------------------------------------------------------------------
    14181342// CompoundLiteralExpr
    1419 template< typename core_t >
    1420 const ast::Expr * ast::Pass< core_t >::visit( const ast::CompoundLiteralExpr * node ) {
     1343template< typename pass_t >
     1344const ast::Expr * ast::Pass< pass_t >::visit( const ast::CompoundLiteralExpr * node ) {
    14211345        VISIT_START( node );
    14221346
     
    14331357//--------------------------------------------------------------------------
    14341358// RangeExpr
    1435 template< typename core_t >
    1436 const ast::Expr * ast::Pass< core_t >::visit( const ast::RangeExpr * node ) {
     1359template< typename pass_t >
     1360const ast::Expr * ast::Pass< pass_t >::visit( const ast::RangeExpr * node ) {
    14371361        VISIT_START( node );
    14381362
     
    14501374//--------------------------------------------------------------------------
    14511375// UntypedTupleExpr
    1452 template< typename core_t >
    1453 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedTupleExpr * node ) {
     1376template< typename pass_t >
     1377const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedTupleExpr * node ) {
    14541378        VISIT_START( node );
    14551379
     
    14661390//--------------------------------------------------------------------------
    14671391// TupleExpr
    1468 template< typename core_t >
    1469 const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleExpr * node ) {
     1392template< typename pass_t >
     1393const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleExpr * node ) {
    14701394        VISIT_START( node );
    14711395
     
    14821406//--------------------------------------------------------------------------
    14831407// TupleIndexExpr
    1484 template< typename core_t >
    1485 const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleIndexExpr * node ) {
     1408template< typename pass_t >
     1409const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleIndexExpr * node ) {
    14861410        VISIT_START( node );
    14871411
     
    14981422//--------------------------------------------------------------------------
    14991423// TupleAssignExpr
    1500 template< typename core_t >
    1501 const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleAssignExpr * node ) {
     1424template< typename pass_t >
     1425const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleAssignExpr * node ) {
    15021426        VISIT_START( node );
    15031427
     
    15141438//--------------------------------------------------------------------------
    15151439// StmtExpr
    1516 template< typename core_t >
    1517 const ast::Expr * ast::Pass< core_t >::visit( const ast::StmtExpr * node ) {
     1440template< typename pass_t >
     1441const ast::Expr * ast::Pass< pass_t >::visit( const ast::StmtExpr * node ) {
    15181442        VISIT_START( node );
    15191443
    15201444        VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr
    15211445                // get the stmts that will need to be spliced in
    1522                 auto stmts_before = __pass::stmtsToAddBefore( core, 0);
    1523                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0);
     1446                auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
     1447                auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
    15241448
    15251449                // These may be modified by subnode but most be restored once we exit this statemnet.
    1526                 ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::typeSubs( core, 0 ) );
     1450                ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::env( pass, 0) );
    15271451                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    15281452                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     
    15421466//--------------------------------------------------------------------------
    15431467// UniqueExpr
    1544 template< typename core_t >
    1545 const ast::Expr * ast::Pass< core_t >::visit( const ast::UniqueExpr * node ) {
     1468template< typename pass_t >
     1469const ast::Expr * ast::Pass< pass_t >::visit( const ast::UniqueExpr * node ) {
    15461470        VISIT_START( node );
    15471471
     
    15581482//--------------------------------------------------------------------------
    15591483// UntypedInitExpr
    1560 template< typename core_t >
    1561 const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedInitExpr * node ) {
     1484template< typename pass_t >
     1485const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedInitExpr * node ) {
    15621486        VISIT_START( node );
    15631487
     
    15751499//--------------------------------------------------------------------------
    15761500// InitExpr
    1577 template< typename core_t >
    1578 const ast::Expr * ast::Pass< core_t >::visit( const ast::InitExpr * node ) {
     1501template< typename pass_t >
     1502const ast::Expr * ast::Pass< pass_t >::visit( const ast::InitExpr * node ) {
    15791503        VISIT_START( node );
    15801504
     
    15921516//--------------------------------------------------------------------------
    15931517// DeletedExpr
    1594 template< typename core_t >
    1595 const ast::Expr * ast::Pass< core_t >::visit( const ast::DeletedExpr * node ) {
     1518template< typename pass_t >
     1519const ast::Expr * ast::Pass< pass_t >::visit( const ast::DeletedExpr * node ) {
    15961520        VISIT_START( node );
    15971521
     
    16091533//--------------------------------------------------------------------------
    16101534// DefaultArgExpr
    1611 template< typename core_t >
    1612 const ast::Expr * ast::Pass< core_t >::visit( const ast::DefaultArgExpr * node ) {
     1535template< typename pass_t >
     1536const ast::Expr * ast::Pass< pass_t >::visit( const ast::DefaultArgExpr * node ) {
    16131537        VISIT_START( node );
    16141538
     
    16251549//--------------------------------------------------------------------------
    16261550// GenericExpr
    1627 template< typename core_t >
    1628 const ast::Expr * ast::Pass< core_t >::visit( const ast::GenericExpr * node ) {
     1551template< typename pass_t >
     1552const ast::Expr * ast::Pass< pass_t >::visit( const ast::GenericExpr * node ) {
    16291553        VISIT_START( node );
    16301554
     
    16541578
    16551579                if(mutated) {
    1656                         auto n = __pass::mutate<core_t>(node);
     1580                        auto n = mutate(node);
    16571581                        n->associations = std::move( new_kids );
    16581582                        node = n;
     
    16651589//--------------------------------------------------------------------------
    16661590// VoidType
    1667 template< typename core_t >
    1668 const ast::Type * ast::Pass< core_t >::visit( const ast::VoidType * node ) {
     1591template< typename pass_t >
     1592const ast::Type * ast::Pass< pass_t >::visit( const ast::VoidType * node ) {
    16691593        VISIT_START( node );
    16701594
     
    16741598//--------------------------------------------------------------------------
    16751599// BasicType
    1676 template< typename core_t >
    1677 const ast::Type * ast::Pass< core_t >::visit( const ast::BasicType * node ) {
     1600template< typename pass_t >
     1601const ast::Type * ast::Pass< pass_t >::visit( const ast::BasicType * node ) {
    16781602        VISIT_START( node );
    16791603
     
    16831607//--------------------------------------------------------------------------
    16841608// PointerType
    1685 template< typename core_t >
    1686 const ast::Type * ast::Pass< core_t >::visit( const ast::PointerType * node ) {
     1609template< typename pass_t >
     1610const ast::Type * ast::Pass< pass_t >::visit( const ast::PointerType * node ) {
    16871611        VISIT_START( node );
    16881612
     
    16971621//--------------------------------------------------------------------------
    16981622// ArrayType
    1699 template< typename core_t >
    1700 const ast::Type * ast::Pass< core_t >::visit( const ast::ArrayType * node ) {
     1623template< typename pass_t >
     1624const ast::Type * ast::Pass< pass_t >::visit( const ast::ArrayType * node ) {
    17011625        VISIT_START( node );
    17021626
     
    17111635//--------------------------------------------------------------------------
    17121636// ReferenceType
    1713 template< typename core_t >
    1714 const ast::Type * ast::Pass< core_t >::visit( const ast::ReferenceType * node ) {
     1637template< typename pass_t >
     1638const ast::Type * ast::Pass< pass_t >::visit( const ast::ReferenceType * node ) {
    17151639        VISIT_START( node );
    17161640
     
    17241648//--------------------------------------------------------------------------
    17251649// QualifiedType
    1726 template< typename core_t >
    1727 const ast::Type * ast::Pass< core_t >::visit( const ast::QualifiedType * node ) {
     1650template< typename pass_t >
     1651const ast::Type * ast::Pass< pass_t >::visit( const ast::QualifiedType * node ) {
    17281652        VISIT_START( node );
    17291653
     
    17381662//--------------------------------------------------------------------------
    17391663// FunctionType
    1740 template< typename core_t >
    1741 const ast::Type * ast::Pass< core_t >::visit( const ast::FunctionType * node ) {
    1742         VISIT_START( node );
    1743 
    1744         VISIT({
    1745                 // guard_forall_subs forall_guard { *this, node };
    1746                 // mutate_forall( node );
    1747                 maybe_accept( node, &FunctionType::assertions );
     1664template< typename pass_t >
     1665const ast::Type * ast::Pass< pass_t >::visit( const ast::FunctionType * node ) {
     1666        VISIT_START( node );
     1667
     1668        VISIT(
     1669                maybe_accept( node, &FunctionType::forall  );
    17481670                maybe_accept( node, &FunctionType::returns );
    17491671                maybe_accept( node, &FunctionType::params  );
    1750         })
     1672        )
    17511673
    17521674        VISIT_END( Type, node );
     
    17551677//--------------------------------------------------------------------------
    17561678// StructInstType
    1757 template< typename core_t >
    1758 const ast::Type * ast::Pass< core_t >::visit( const ast::StructInstType * node ) {
    1759         VISIT_START( node );
    1760 
    1761         __pass::symtab::addStruct( core, 0, node->name );
     1679template< typename pass_t >
     1680const ast::Type * ast::Pass< pass_t >::visit( const ast::StructInstType * node ) {
     1681        VISIT_START( node );
     1682
     1683        __pass::symtab::addStruct( pass, 0, node->name );
    17621684
    17631685        VISIT({
    17641686                guard_symtab guard { *this };
     1687                maybe_accept( node, &StructInstType::forall );
    17651688                maybe_accept( node, &StructInstType::params );
    17661689        })
     
    17711694//--------------------------------------------------------------------------
    17721695// UnionInstType
    1773 template< typename core_t >
    1774 const ast::Type * ast::Pass< core_t >::visit( const ast::UnionInstType * node ) {
    1775         VISIT_START( node );
    1776 
    1777         __pass::symtab::addUnion( core, 0, node->name );
    1778 
    1779         VISIT({
     1696template< typename pass_t >
     1697const ast::Type * ast::Pass< pass_t >::visit( const ast::UnionInstType * node ) {
     1698        VISIT_START( node );
     1699
     1700        __pass::symtab::addStruct( pass, 0, node->name );
     1701
     1702        {
    17801703                guard_symtab guard { *this };
     1704                maybe_accept( node, &UnionInstType::forall );
    17811705                maybe_accept( node, &UnionInstType::params );
    1782         })
     1706        }
    17831707
    17841708        VISIT_END( Type, node );
     
    17871711//--------------------------------------------------------------------------
    17881712// EnumInstType
    1789 template< typename core_t >
    1790 const ast::Type * ast::Pass< core_t >::visit( const ast::EnumInstType * node ) {
    1791         VISIT_START( node );
    1792 
    1793         VISIT({
     1713template< typename pass_t >
     1714const ast::Type * ast::Pass< pass_t >::visit( const ast::EnumInstType * node ) {
     1715        VISIT_START( node );
     1716
     1717        VISIT(
     1718                maybe_accept( node, &EnumInstType::forall );
    17941719                maybe_accept( node, &EnumInstType::params );
    1795         })
     1720        )
    17961721
    17971722        VISIT_END( Type, node );
     
    18001725//--------------------------------------------------------------------------
    18011726// TraitInstType
    1802 template< typename core_t >
    1803 const ast::Type * ast::Pass< core_t >::visit( const ast::TraitInstType * node ) {
    1804         VISIT_START( node );
    1805 
    1806         VISIT({
     1727template< typename pass_t >
     1728const ast::Type * ast::Pass< pass_t >::visit( const ast::TraitInstType * node ) {
     1729        VISIT_START( node );
     1730
     1731        VISIT(
     1732                maybe_accept( node, &TraitInstType::forall );
    18071733                maybe_accept( node, &TraitInstType::params );
    1808         })
     1734        )
    18091735
    18101736        VISIT_END( Type, node );
     
    18131739//--------------------------------------------------------------------------
    18141740// TypeInstType
    1815 template< typename core_t >
    1816 const ast::Type * ast::Pass< core_t >::visit( const ast::TypeInstType * node ) {
    1817         VISIT_START( node );
    1818 
    1819         VISIT(
    1820                 {
    1821                         maybe_accept( node, &TypeInstType::params );
    1822                 }
    1823                 // ensure that base re-bound if doing substitution
    1824                 __pass::forall::replace( core, 0, node );
     1741template< typename pass_t >
     1742const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeInstType * node ) {
     1743        VISIT_START( node );
     1744
     1745        VISIT(
     1746                maybe_accept( node, &TypeInstType::forall );
     1747                maybe_accept( node, &TypeInstType::params );
    18251748        )
    18261749
     
    18301753//--------------------------------------------------------------------------
    18311754// TupleType
    1832 template< typename core_t >
    1833 const ast::Type * ast::Pass< core_t >::visit( const ast::TupleType * node ) {
     1755template< typename pass_t >
     1756const ast::Type * ast::Pass< pass_t >::visit( const ast::TupleType * node ) {
    18341757        VISIT_START( node );
    18351758
     
    18441767//--------------------------------------------------------------------------
    18451768// TypeofType
    1846 template< typename core_t >
    1847 const ast::Type * ast::Pass< core_t >::visit( const ast::TypeofType * node ) {
     1769template< typename pass_t >
     1770const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeofType * node ) {
    18481771        VISIT_START( node );
    18491772
     
    18571780//--------------------------------------------------------------------------
    18581781// VarArgsType
    1859 template< typename core_t >
    1860 const ast::Type * ast::Pass< core_t >::visit( const ast::VarArgsType * node ) {
     1782template< typename pass_t >
     1783const ast::Type * ast::Pass< pass_t >::visit( const ast::VarArgsType * node ) {
    18611784        VISIT_START( node );
    18621785
     
    18661789//--------------------------------------------------------------------------
    18671790// ZeroType
    1868 template< typename core_t >
    1869 const ast::Type * ast::Pass< core_t >::visit( const ast::ZeroType * node ) {
     1791template< typename pass_t >
     1792const ast::Type * ast::Pass< pass_t >::visit( const ast::ZeroType * node ) {
    18701793        VISIT_START( node );
    18711794
     
    18751798//--------------------------------------------------------------------------
    18761799// OneType
    1877 template< typename core_t >
    1878 const ast::Type * ast::Pass< core_t >::visit( const ast::OneType * node ) {
     1800template< typename pass_t >
     1801const ast::Type * ast::Pass< pass_t >::visit( const ast::OneType * node ) {
    18791802        VISIT_START( node );
    18801803
     
    18841807//--------------------------------------------------------------------------
    18851808// GlobalScopeType
    1886 template< typename core_t >
    1887 const ast::Type * ast::Pass< core_t >::visit( const ast::GlobalScopeType * node ) {
     1809template< typename pass_t >
     1810const ast::Type * ast::Pass< pass_t >::visit( const ast::GlobalScopeType * node ) {
    18881811        VISIT_START( node );
    18891812
     
    18941817//--------------------------------------------------------------------------
    18951818// Designation
    1896 template< typename core_t >
    1897 const ast::Designation * ast::Pass< core_t >::visit( const ast::Designation * node ) {
     1819template< typename pass_t >
     1820const ast::Designation * ast::Pass< pass_t >::visit( const ast::Designation * node ) {
    18981821        VISIT_START( node );
    18991822
     
    19051828//--------------------------------------------------------------------------
    19061829// SingleInit
    1907 template< typename core_t >
    1908 const ast::Init * ast::Pass< core_t >::visit( const ast::SingleInit * node ) {
     1830template< typename pass_t >
     1831const ast::Init * ast::Pass< pass_t >::visit( const ast::SingleInit * node ) {
    19091832        VISIT_START( node );
    19101833
     
    19181841//--------------------------------------------------------------------------
    19191842// ListInit
    1920 template< typename core_t >
    1921 const ast::Init * ast::Pass< core_t >::visit( const ast::ListInit * node ) {
     1843template< typename pass_t >
     1844const ast::Init * ast::Pass< pass_t >::visit( const ast::ListInit * node ) {
    19221845        VISIT_START( node );
    19231846
     
    19321855//--------------------------------------------------------------------------
    19331856// ConstructorInit
    1934 template< typename core_t >
    1935 const ast::Init * ast::Pass< core_t >::visit( const ast::ConstructorInit * node ) {
     1857template< typename pass_t >
     1858const ast::Init * ast::Pass< pass_t >::visit( const ast::ConstructorInit * node ) {
    19361859        VISIT_START( node );
    19371860
     
    19471870//--------------------------------------------------------------------------
    19481871// Attribute
    1949 template< typename core_t >
    1950 const ast::Attribute * ast::Pass< core_t >::visit( const ast::Attribute * node  )  {
     1872template< typename pass_t >
     1873const ast::Attribute * ast::Pass< pass_t >::visit( const ast::Attribute * node  )  {
    19511874        VISIT_START( node );
    19521875
     
    19601883//--------------------------------------------------------------------------
    19611884// TypeSubstitution
    1962 template< typename core_t >
    1963 const ast::TypeSubstitution * ast::Pass< core_t >::visit( const ast::TypeSubstitution * node ) {
     1885template< typename pass_t >
     1886const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {
    19641887        VISIT_START( node );
    19651888
     
    19671890                {
    19681891                        bool mutated = false;
    1969                         std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map;
     1892                        std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
    19701893                        for ( const auto & p : node->typeEnv ) {
    19711894                                guard_symtab guard { *this };
    19721895                                auto new_node = p.second->accept( *this );
    1973                                 if (new_node != p.second) mutated = true;
     1896                                if (new_node != p.second) mutated = false;
    19741897                                new_map.insert({ p.first, new_node });
    19751898                        }
    19761899                        if (mutated) {
    1977                                 auto new_node = __pass::mutate<core_t>( node );
     1900                                auto new_node = mutate( node );
    19781901                                new_node->typeEnv.swap( new_map );
    19791902                                node = new_node;
    19801903                        }
    19811904                }
     1905
     1906                {
     1907                        bool mutated = false;
     1908                        std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
     1909                        for ( const auto & p : node->varEnv ) {
     1910                                guard_symtab guard { *this };
     1911                                auto new_node = p.second->accept( *this );
     1912                                if (new_node != p.second) mutated = false;
     1913                                new_map.insert({ p.first, new_node });
     1914                        }
     1915                        if (mutated) {
     1916                                auto new_node = mutate( node );
     1917                                new_node->varEnv.swap( new_map );
     1918                                node = new_node;
     1919                        }
     1920                }
    19821921        )
    19831922
Note: See TracChangeset for help on using the changeset viewer.