Ignore:
File:
1 edited

Legend:

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

    rf8143a6 rc600df1  
    3434        __pass::previsit( core, node, 0 );
    3535
     36#define VISIT( code... ) \
     37        /* if this node should visit its children */ \
     38        if ( __visit_children() ) { \
     39                /* visit the children */ \
     40                code \
     41        }
     42
    3643#define VISIT_END( type, node ) \
    3744        /* call the implementation of the postvisit of this pass */ \
     
    7986
    8087                template<typename it_t, template <class...> class container_t>
    81                 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) {
    82                         if(empty(stmts)) return;
    83 
    84                         std::move(stmts->begin(), stmts->end(), it);
    85                         stmts->clear();
     88                static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * decls, bool * mutated = nullptr ) {
     89                        if(empty(decls)) return;
     90
     91                        std::move(decls->begin(), decls->end(), it);
     92                        decls->clear();
    8693                        if(mutated) *mutated = true;
    8794                }
     
    123130                        return !new_val.empty();
    124131                }
    125         }
    126 
    127 
    128         template< typename core_t >
    129         template< typename node_t >
    130         template< typename object_t, typename super_t, typename field_t >
    131         void ast::Pass< core_t >::result1< node_t >::apply(object_t * object, field_t super_t::* field) {
    132                 object->*field = value;
    133132        }
    134133
     
    139138                                !std::is_base_of<ast::Expr, node_t>::value &&
    140139                                !std::is_base_of<ast::Stmt, node_t>::value
    141                         , ast::Pass< core_t >::result1<
    142                                 typename std::remove_pointer< decltype( node->accept(*this) ) >::type
    143                         >
     140                        , decltype( node->accept(*this) )
    144141                >::type
    145142        {
     
    150147                static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR");
    151148
    152                 auto nval = node->accept( *this );
    153                 ast::Pass< core_t >::result1<
    154                         typename std::remove_pointer< decltype( node->accept(*this) ) >::type
    155                 > res;
    156                 res.differs = nval != node;
    157                 res.value = nval;
    158                 return res;
     149                return node->accept( *this );
    159150        }
    160151
    161152        template< typename core_t >
    162         ast::Pass< core_t >::result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
     153        const ast::Expr * ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
    163154                __pedantic_pass_assert( __visit_children() );
    164155                __pedantic_pass_assert( expr );
     
    169160                }
    170161
    171                 auto nval = expr->accept( *this );
    172                 return { nval != expr, nval };
     162                return expr->accept( *this );
    173163        }
    174164
    175165        template< typename core_t >
    176         ast::Pass< core_t >::result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
     166        const ast::Stmt * ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
    177167                __pedantic_pass_assert( __visit_children() );
    178168                __pedantic_pass_assert( stmt );
    179169
    180                 const ast::Stmt * nval = stmt->accept( *this );
    181                 return { nval != stmt, nval };
     170                return stmt->accept( *this );
    182171        }
    183172
    184173        template< typename core_t >
    185         ast::Pass< core_t >::result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
     174        const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
    186175                __pedantic_pass_assert( __visit_children() );
    187176                __pedantic_pass_assert( stmt );
     
    208197                // If the pass doesn't want to add anything then we are done
    209198                if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
    210                         return { nstmt != stmt, nstmt };
     199                        return nstmt;
    211200                }
    212201
     
    230219                __pass::take_all( std::back_inserter( compound->kids ), stmts_after );
    231220
    232                 return {true, compound};
     221                return compound;
    233222        }
    234223
    235224        template< typename core_t >
    236225        template< template <class...> class container_t >
    237         template< typename object_t, typename super_t, typename field_t >
    238         void ast::Pass< core_t >::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {
    239                 auto & container = object->*field;
    240                 __pedantic_pass_assert( container.size() <= values.size() );
    241 
    242                 auto cit = enumerate(container).begin();
    243 
    244                 container_t<ptr<Stmt>> nvals;
    245                 for(delta & d : values) {
    246                         if( d.is_old ) {
    247                                 __pedantic_pass_assert( cit.idx <= d.old_idx );
    248                                 std::advance( cit, d.old_idx - cit.idx );
    249                                 nvals.push_back( std::move( (*cit).val) );
    250                         } else {
    251                                 nvals.push_back( std::move(d.nval) );
    252                         }
    253                 }
    254 
    255                 object->*field = std::move(nvals);
    256         }
    257 
    258         template< typename core_t >
    259         template< template <class...> class container_t >
    260         ast::Pass< core_t >::resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
     226        container_t< ptr<Stmt> > ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    261227                __pedantic_pass_assert( __visit_children() );
    262228                if( statements.empty() ) return {};
     
    285251                pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    286252
    287                 resultNstmt<container_t> new_kids;
    288                 for( auto value : enumerate( statements ) ) {
     253                bool mutated = false;
     254                container_t< ptr<Stmt> > new_kids;
     255                for( const Stmt * stmt : statements ) {
    289256                        try {
    290                                 size_t i = value.idx;
    291                                 const Stmt * stmt = value.val;
    292257                                __pedantic_pass_assert( stmt );
    293258                                const ast::Stmt * new_stmt = stmt->accept( *this );
    294259                                assert( new_stmt );
    295                                 if(new_stmt != stmt ) { new_kids.differs = true; }
     260                                if(new_stmt != stmt ) mutated = true;
    296261
    297262                                // Make sure that it is either adding statements or declartions but not both
     
    303268
    304269                                // Take all the statements which should have gone after, N/A for first iteration
    305                                 new_kids.take_all( decls_before );
    306                                 new_kids.take_all( stmts_before );
     270                                __pass::take_all( std::back_inserter( new_kids ), decls_before, &mutated );
     271                                __pass::take_all( std::back_inserter( new_kids ), stmts_before, &mutated );
    307272
    308273                                // Now add the statement if there is one
    309                                 if(new_stmt != stmt) {
    310                                         new_kids.values.emplace_back( new_stmt, i, false );
    311                                 } else {
    312                                         new_kids.values.emplace_back( nullptr, i, true );
    313                                 }
     274                                new_kids.emplace_back( new_stmt );
    314275
    315276                                // Take all the declarations that go before
    316                                 new_kids.take_all( decls_after );
    317                                 new_kids.take_all( stmts_after );
     277                                __pass::take_all( std::back_inserter( new_kids ), decls_after, &mutated );
     278                                __pass::take_all( std::back_inserter( new_kids ), stmts_after, &mutated );
    318279                        }
    319280                        catch ( SemanticErrorException &e ) {
     
    324285                if ( !errors.isEmpty() ) { throw errors; }
    325286
    326                 return new_kids;
     287                return mutated ? new_kids : container_t< ptr<Stmt> >();
    327288        }
    328289
    329290        template< typename core_t >
    330291        template< template <class...> class container_t, typename node_t >
    331         template< typename object_t, typename super_t, typename field_t >
    332         void ast::Pass< core_t >::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {
    333                 auto & container = object->*field;
    334                 __pedantic_pass_assert( container.size() == values.size() );
    335 
    336                 for(size_t i = 0; i < container.size(); i++) {
    337                         // Take all the elements that are different in 'values'
    338                         // and swap them into 'container'
    339                         if( values[i] != nullptr ) std::swap(container[i], values[i]);
    340                 }
    341 
    342                 // Now the original containers should still have the unchanged values
    343                 // but also contain the new values
    344         }
    345 
    346         template< typename core_t >
    347         template< template <class...> class container_t, typename node_t >
    348         ast::Pass< core_t >::resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
     292        container_t< ast::ptr<node_t> > ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    349293                __pedantic_pass_assert( __visit_children() );
    350294                if( container.empty() ) return {};
     
    356300
    357301                bool mutated = false;
    358                 container_t<ptr<node_t>> new_kids;
     302                container_t< ast::ptr<node_t> > new_kids;
    359303                for ( const node_t * node : container ) {
    360304                        try {
    361305                                __pedantic_pass_assert( node );
    362306                                const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) );
    363                                 if(new_stmt != node ) {
    364                                         mutated = true;
    365                                         new_kids.emplace_back( new_stmt );
    366                                 } else {
    367                                         new_kids.emplace_back( nullptr );
    368                                 }
    369 
     307                                if(new_stmt != node ) mutated = true;
     308
     309                                new_kids.emplace_back( new_stmt );
    370310                        }
    371311                        catch( SemanticErrorException &e ) {
     
    373313                        }
    374314                }
    375 
    376                 __pedantic_pass_assert( new_kids.size() == container.size() );
    377315                pass_visitor_stats.depth--;
    378316                if ( ! errors.isEmpty() ) { throw errors; }
    379317
    380                 return ast::Pass< core_t >::resultN<container_t, node_t>{ mutated,  new_kids };
     318                return mutated ? new_kids : container_t< ast::ptr<node_t> >();
    381319        }
    382320
     
    396334                auto new_val = call_accept( old_val );
    397335
    398                 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
    399 
    400                 if( new_val.differs ) {
     336                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
     337
     338                if( __pass::differs(old_val, new_val) ) {
    401339                        auto new_parent = __pass::mutate<core_t>(parent);
    402                         new_val.apply(new_parent, child);
     340                        new_parent->*child = new_val;
    403341                        parent = new_parent;
    404342                }
     
    422360                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
    423361
    424                 if( new_val.differs ) {
     362                if( __pass::differs(old_val, new_val) ) {
    425363                        auto new_parent = __pass::mutate<core_t>(parent);
    426                         new_val.apply( new_parent, child );
     364                        new_parent->*child = new_val;
    427365                        parent = new_parent;
    428366                }
     
    514452        VISIT_START( node );
    515453
    516         if ( __visit_children() ) {
     454        VISIT(
    517455                {
    518456                        guard_symtab guard { *this };
     
    522460                maybe_accept( node, &ObjectDecl::bitfieldWidth );
    523461                maybe_accept( node, &ObjectDecl::attributes    );
    524         }
     462        )
    525463
    526464        __pass::symtab::addId( core, 0, node );
     
    537475        __pass::symtab::addId( core, 0, node );
    538476
    539         if ( __visit_children() ) {
    540                 maybe_accept( node, &FunctionDecl::withExprs );
    541         }
     477        VISIT(maybe_accept( node, &FunctionDecl::withExprs );)
    542478        {
    543479                // with clause introduces a level of scope (for the with expression members).
     
    557493                        } };
    558494                        __pass::symtab::addId( core, 0, func );
    559                         if ( __visit_children() ) {
     495                        VISIT(
    560496                                // parameter declarations
    561497                                maybe_accept( node, &FunctionDecl::params );
     
    573509                                maybe_accept( node, &FunctionDecl::stmts );
    574510                                maybe_accept( node, &FunctionDecl::attributes );
    575                         }
     511                        )
    576512                }
    577513        }
     
    590526        __pass::symtab::addStructFwd( core, 0, node );
    591527
    592         if ( __visit_children() ) {
     528        VISIT({
    593529                guard_symtab guard { * this };
    594530                maybe_accept( node, &StructDecl::params     );
    595531                maybe_accept( node, &StructDecl::members    );
    596532                maybe_accept( node, &StructDecl::attributes );
    597         }
     533        })
    598534
    599535        // this addition replaces the forward declaration
     
    612548        __pass::symtab::addUnionFwd( core, 0, node );
    613549
    614         if ( __visit_children() ) {
     550        VISIT({
    615551                guard_symtab guard { * this };
    616552                maybe_accept( node, &UnionDecl::params     );
    617553                maybe_accept( node, &UnionDecl::members    );
    618554                maybe_accept( node, &UnionDecl::attributes );
    619         }
     555        })
    620556
    621557        __pass::symtab::addUnion( core, 0, node );
     
    632568        __pass::symtab::addEnum( core, 0, node );
    633569
    634         if ( __visit_children() ) {
     570        VISIT(
    635571                // unlike structs, traits, and unions, enums inject their members into the global scope
    636572                maybe_accept( node, &EnumDecl::params     );
    637573                maybe_accept( node, &EnumDecl::members    );
    638574                maybe_accept( node, &EnumDecl::attributes );
    639         }
     575        )
    640576
    641577        VISIT_END( Decl, node );
     
    648584        VISIT_START( node );
    649585
    650         if ( __visit_children() ) {
     586        VISIT({
    651587                guard_symtab guard { *this };
    652588                maybe_accept( node, &TraitDecl::params     );
    653589                maybe_accept( node, &TraitDecl::members    );
    654590                maybe_accept( node, &TraitDecl::attributes );
    655         }
     591        })
    656592
    657593        __pass::symtab::addTrait( core, 0, node );
     
    666602        VISIT_START( node );
    667603
    668         if ( __visit_children() ) {
     604        VISIT({
    669605                guard_symtab guard { *this };
    670606                maybe_accept( node, &TypeDecl::base   );
    671         }
     607        })
    672608
    673609        // see A NOTE ON THE ORDER OF TRAVERSAL, above
     
    676612        __pass::symtab::addType( core, 0, node );
    677613
    678         if ( __visit_children() ) {
     614        VISIT(
    679615                maybe_accept( node, &TypeDecl::assertions );
    680616
     
    683619                        maybe_accept( node, &TypeDecl::init );
    684620                }
    685         }
     621        )
    686622
    687623        VISIT_END( Decl, node );
     
    694630        VISIT_START( node );
    695631
    696         if ( __visit_children() ) {
     632        VISIT({
    697633                guard_symtab guard { *this };
    698634                maybe_accept( node, &TypedefDecl::base   );
    699         }
     635        })
    700636
    701637        __pass::symtab::addType( core, 0, node );
    702638
    703         if ( __visit_children() ) {
    704                 maybe_accept( node, &TypedefDecl::assertions );
    705         }
     639        VISIT( maybe_accept( node, &TypedefDecl::assertions ); )
    706640
    707641        VISIT_END( Decl, node );
     
    714648        VISIT_START( node );
    715649
    716         if ( __visit_children() ) {
     650        VISIT(
    717651                maybe_accept( node, &AsmDecl::stmt );
    718         }
     652        )
    719653
    720654        VISIT_END( AsmDecl, node );
     
    727661        VISIT_START( node );
    728662
    729         if ( __visit_children() ) {
     663        VISIT(
    730664                maybe_accept( node, &DirectiveDecl::stmt );
    731         }
     665        )
    732666
    733667        VISIT_END( DirectiveDecl, node );
     
    740674        VISIT_START( node );
    741675
    742         if ( __visit_children() ) {
     676        VISIT(
    743677                maybe_accept( node, &StaticAssertDecl::cond );
    744678                maybe_accept( node, &StaticAssertDecl::msg  );
    745         }
     679        )
    746680
    747681        VISIT_END( StaticAssertDecl, node );
     
    753687const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) {
    754688        VISIT_START( node );
    755 
    756         if ( __visit_children() ) {
     689        VISIT(
    757690                // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.
    758691                auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {
     
    771704                guard_scope guard3 { *this };
    772705                maybe_accept( node, &CompoundStmt::kids );
    773         }
    774 
     706        )
    775707        VISIT_END( CompoundStmt, node );
    776708}
     
    782714        VISIT_START( node );
    783715
    784         if ( __visit_children() ) {
     716        VISIT(
    785717                maybe_accept( node, &ExprStmt::expr );
    786         }
     718        )
    787719
    788720        VISIT_END( Stmt, node );
     
    795727        VISIT_START( node )
    796728
    797         if ( __visit_children() ) {
     729        VISIT(
    798730                maybe_accept( node, &AsmStmt::instruction );
    799731                maybe_accept( node, &AsmStmt::output      );
    800732                maybe_accept( node, &AsmStmt::input       );
    801733                maybe_accept( node, &AsmStmt::clobber     );
    802         }
     734        )
    803735
    804736        VISIT_END( Stmt, node );
     
    820752        VISIT_START( node );
    821753
    822         if ( __visit_children() ) {
     754        VISIT({
    823755                // if statements introduce a level of scope (for the initialization)
    824756                guard_symtab guard { *this };
    825757                maybe_accept( node, &IfStmt::inits    );
    826758                maybe_accept( node, &IfStmt::cond     );
    827                 maybe_accept_as_compound( node, &IfStmt::then );
    828                 maybe_accept_as_compound( node, &IfStmt::else_ );
    829         }
     759                maybe_accept_as_compound( node, &IfStmt::thenPart );
     760                maybe_accept_as_compound( node, &IfStmt::elsePart );
     761        })
    830762
    831763        VISIT_END( Stmt, node );
     
    833765
    834766//--------------------------------------------------------------------------
    835 // WhileDoStmt
    836 template< typename core_t >
    837 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileDoStmt * node ) {
    838         VISIT_START( node );
    839 
    840         if ( __visit_children() ) {
     767// WhileStmt
     768template< typename core_t >
     769const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileStmt * node ) {
     770        VISIT_START( node );
     771
     772        VISIT({
    841773                // while statements introduce a level of scope (for the initialization)
    842774                guard_symtab guard { *this };
    843                 maybe_accept( node, &WhileDoStmt::inits );
    844                 maybe_accept( node, &WhileDoStmt::cond  );
    845                 maybe_accept_as_compound( node, &WhileDoStmt::body  );
    846         }
     775                maybe_accept( node, &WhileStmt::inits );
     776                maybe_accept( node, &WhileStmt::cond  );
     777                maybe_accept_as_compound( node, &WhileStmt::body  );
     778        })
    847779
    848780        VISIT_END( Stmt, node );
     
    855787        VISIT_START( node );
    856788
    857         if ( __visit_children() ) {
     789        VISIT({
    858790                // for statements introduce a level of scope (for the initialization)
    859791                guard_symtab guard { *this };
     
    863795                maybe_accept( node, &ForStmt::inc   );
    864796                maybe_accept_as_compound( node, &ForStmt::body  );
    865         }
     797        })
    866798
    867799        VISIT_END( Stmt, node );
     
    874806        VISIT_START( node );
    875807
    876         if ( __visit_children() ) {
     808        VISIT(
    877809                maybe_accept( node, &SwitchStmt::cond  );
    878810                maybe_accept( node, &SwitchStmt::stmts );
    879         }
     811        )
    880812
    881813        VISIT_END( Stmt, node );
     
    888820        VISIT_START( node );
    889821
    890         if ( __visit_children() ) {
     822        VISIT(
    891823                maybe_accept( node, &CaseStmt::cond  );
    892824                maybe_accept( node, &CaseStmt::stmts );
    893         }
     825        )
    894826
    895827        VISIT_END( Stmt, node );
     
    910842        VISIT_START( node );
    911843
    912         if ( __visit_children() ) {
     844        VISIT(
    913845                maybe_accept( node, &ReturnStmt::expr );
    914         }
     846        )
    915847
    916848        VISIT_END( Stmt, node );
     
    923855        VISIT_START( node );
    924856
    925         if ( __visit_children() ) {
     857        VISIT(
    926858                maybe_accept( node, &ThrowStmt::expr   );
    927859                maybe_accept( node, &ThrowStmt::target );
    928         }
     860        )
    929861
    930862        VISIT_END( Stmt, node );
     
    937869        VISIT_START( node );
    938870
    939         if ( __visit_children() ) {
     871        VISIT(
    940872                maybe_accept( node, &TryStmt::body     );
    941873                maybe_accept( node, &TryStmt::handlers );
    942874                maybe_accept( node, &TryStmt::finally  );
    943         }
     875        )
    944876
    945877        VISIT_END( Stmt, node );
     
    952884        VISIT_START( node );
    953885
    954         if ( __visit_children() ) {
     886        VISIT({
    955887                // catch statements introduce a level of scope (for the caught exception)
    956888                guard_symtab guard { *this };
     
    958890                maybe_accept( node, &CatchStmt::cond );
    959891                maybe_accept_as_compound( node, &CatchStmt::body );
    960         }
     892        })
    961893
    962894        VISIT_END( Stmt, node );
     
    969901        VISIT_START( node );
    970902
    971         if ( __visit_children() ) {
     903        VISIT(
    972904                maybe_accept( node, &FinallyStmt::body );
    973         }
     905        )
    974906
    975907        VISIT_END( Stmt, node );
     
    982914        VISIT_START( node );
    983915
    984         if ( __visit_children() ) {
     916        VISIT(
    985917                maybe_accept( node, &SuspendStmt::then   );
    986         }
     918        )
    987919
    988920        VISIT_END( Stmt, node );
     
    1002934                // }
    1003935
    1004         if ( __visit_children() ) {
     936        VISIT({
    1005937                std::vector<WaitForStmt::Clause> new_clauses;
    1006938                new_clauses.reserve( node->clauses.size() );
     
    1010942                        const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;
    1011943                        if(func != clause.target.func) mutated = true;
    1012                         else func = nullptr;
    1013944
    1014945                        std::vector<ptr<Expr>> new_args;
     
    1016947                        for( const auto & arg : clause.target.args ) {
    1017948                                auto a = arg->accept(*this);
    1018                                 if( a != arg ) {
    1019                                         mutated = true;
    1020                                         new_args.push_back( a );
    1021                                 } else
    1022                                         new_args.push_back( nullptr );
     949                                new_args.push_back( a );
     950                                if( a != arg ) mutated = true;
    1023951                        }
    1024952
    1025953                        const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;
    1026954                        if(stmt != clause.stmt) mutated = true;
    1027                         else stmt = nullptr;
    1028955
    1029956                        const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;
    1030957                        if(cond != clause.cond) mutated = true;
    1031                         else cond = nullptr;
    1032958
    1033959                        new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } );
     
    1036962                if(mutated) {
    1037963                        auto n = __pass::mutate<core_t>(node);
    1038                         for(size_t i = 0; i < new_clauses.size(); i++) {
    1039                                 if(new_clauses.at(i).target.func != nullptr) std::swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func);
    1040 
    1041                                 for(size_t j = 0; j < new_clauses.at(i).target.args.size(); j++) {
    1042                                         if(new_clauses.at(i).target.args.at(j) != nullptr) std::swap(n->clauses.at(i).target.args.at(j), new_clauses.at(i).target.args.at(j));
    1043                                 }
    1044 
    1045                                 if(new_clauses.at(i).stmt != nullptr) std::swap(n->clauses.at(i).stmt, new_clauses.at(i).stmt);
    1046                                 if(new_clauses.at(i).cond != nullptr) std::swap(n->clauses.at(i).cond, new_clauses.at(i).cond);
    1047                         }
     964                        n->clauses = std::move( new_clauses );
    1048965                        node = n;
    1049966                }
    1050         }
     967        })
    1051968
    1052969        #define maybe_accept(field) \
    1053970                if(node->field) { \
    1054971                        auto nval = call_accept( node->field ); \
    1055                         if(nval.differs ) { \
     972                        if(nval != node->field ) { \
    1056973                                auto nparent = __pass::mutate<core_t>(node); \
    1057                                 nparent->field = nval.value; \
     974                                nparent->field = nval; \
    1058975                                node = nparent; \
    1059976                        } \
    1060977                }
    1061978
    1062         if ( __visit_children() ) {
     979        VISIT(
    1063980                maybe_accept( timeout.time );
    1064981                maybe_accept( timeout.stmt );
     
    1066983                maybe_accept( orElse.stmt  );
    1067984                maybe_accept( orElse.cond  );
    1068         }
     985        )
    1069986
    1070987        #undef maybe_accept
     
    1079996        VISIT_START( node );
    1080997
    1081         if ( __visit_children() ) {
     998        VISIT(
    1082999                maybe_accept( node, &WithStmt::exprs );
    10831000                {
     
    10871004                        maybe_accept( node, &WithStmt::stmt );
    10881005                }
    1089         }
    1090 
     1006        )
    10911007        VISIT_END( Stmt, node );
    10921008}
     
    11061022        VISIT_START( node );
    11071023
    1108         if ( __visit_children() ) {
     1024        VISIT(
    11091025                maybe_accept( node, &DeclStmt::decl );
    1110         }
     1026        )
    11111027
    11121028        VISIT_END( Stmt, node );
     
    11211037        // For now this isn't visited, it is unclear if this causes problem
    11221038        // if all tests are known to pass, remove this code
    1123         if ( __visit_children() ) {
     1039        VISIT(
    11241040                maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
    1125         }
     1041        )
    11261042
    11271043        VISIT_END( Stmt, node );
     
    11341050        VISIT_START( node );
    11351051
    1136         if ( __visit_children() ) {
     1052        VISIT({
    11371053                // mutex statements introduce a level of scope (for the initialization)
    11381054                guard_symtab guard { *this };
    11391055                maybe_accept( node, &MutexStmt::stmt );
    11401056                maybe_accept( node, &MutexStmt::mutexObjs );
    1141         }
     1057        })
    11421058
    11431059        VISIT_END( Stmt, node );
     
    11501066        VISIT_START( node );
    11511067
    1152         if ( __visit_children() ) {
     1068        VISIT(
    11531069                {
    11541070                        guard_symtab guard { *this };
     
    11571073                maybe_accept( node, &ApplicationExpr::func );
    11581074                maybe_accept( node, &ApplicationExpr::args );
    1159         }
     1075        )
    11601076
    11611077        VISIT_END( Expr, node );
     
    11681084        VISIT_START( node );
    11691085
    1170         if ( __visit_children() ) {
     1086        VISIT(
    11711087                {
    11721088                        guard_symtab guard { *this };
     
    11751091
    11761092                maybe_accept( node, &UntypedExpr::args );
    1177         }
     1093        )
    11781094
    11791095        VISIT_END( Expr, node );
     
    11861102        VISIT_START( node );
    11871103
    1188         if ( __visit_children() ) {
     1104        VISIT({
    11891105                guard_symtab guard { *this };
    11901106                maybe_accept( node, &NameExpr::result );
    1191         }
     1107        })
    11921108
    11931109        VISIT_END( Expr, node );
     
    12001116        VISIT_START( node );
    12011117
    1202         if ( __visit_children() ) {
    1203                 {
     1118        VISIT({
    12041119                        guard_symtab guard { *this };
    12051120                        maybe_accept( node, &CastExpr::result );
    12061121                }
    12071122                maybe_accept( node, &CastExpr::arg );
    1208         }
     1123        )
    12091124
    12101125        VISIT_END( Expr, node );
     
    12171132        VISIT_START( node );
    12181133
    1219         if ( __visit_children() ) {
    1220                 {
     1134        VISIT({
    12211135                        guard_symtab guard { *this };
    12221136                        maybe_accept( node, &KeywordCastExpr::result );
    12231137                }
    12241138                maybe_accept( node, &KeywordCastExpr::arg );
    1225         }
     1139        )
    12261140
    12271141        VISIT_END( Expr, node );
     
    12341148        VISIT_START( node );
    12351149
    1236         if ( __visit_children() ) {
    1237                 {
     1150        VISIT({
    12381151                        guard_symtab guard { *this };
    12391152                        maybe_accept( node, &VirtualCastExpr::result );
    12401153                }
    12411154                maybe_accept( node, &VirtualCastExpr::arg );
    1242         }
     1155        )
    12431156
    12441157        VISIT_END( Expr, node );
     
    12511164        VISIT_START( node );
    12521165
    1253         if ( __visit_children() ) {
    1254                 {
     1166        VISIT({
    12551167                        guard_symtab guard { *this };
    12561168                        maybe_accept( node, &AddressExpr::result );
    12571169                }
    12581170                maybe_accept( node, &AddressExpr::arg );
    1259         }
     1171        )
    12601172
    12611173        VISIT_END( Expr, node );
     
    12681180        VISIT_START( node );
    12691181
    1270         if ( __visit_children() ) {
     1182        VISIT({
    12711183                guard_symtab guard { *this };
    12721184                maybe_accept( node, &LabelAddressExpr::result );
    1273         }
     1185        })
    12741186
    12751187        VISIT_END( Expr, node );
     
    12821194        VISIT_START( node );
    12831195
    1284         if ( __visit_children() ) {
    1285                 {
     1196        VISIT({
    12861197                        guard_symtab guard { *this };
    12871198                        maybe_accept( node, &UntypedMemberExpr::result );
     
    12891200                maybe_accept( node, &UntypedMemberExpr::aggregate );
    12901201                maybe_accept( node, &UntypedMemberExpr::member    );
    1291         }
     1202        )
    12921203
    12931204        VISIT_END( Expr, node );
     
    13001211        VISIT_START( node );
    13011212
    1302         if ( __visit_children() ) {
    1303                 {
     1213        VISIT({
    13041214                        guard_symtab guard { *this };
    13051215                        maybe_accept( node, &MemberExpr::result );
    13061216                }
    13071217                maybe_accept( node, &MemberExpr::aggregate );
    1308         }
     1218        )
    13091219
    13101220        VISIT_END( Expr, node );
     
    13171227        VISIT_START( node );
    13181228
    1319         if ( __visit_children() ) {
     1229        VISIT({
    13201230                guard_symtab guard { *this };
    13211231                maybe_accept( node, &VariableExpr::result );
    1322         }
     1232        })
    13231233
    13241234        VISIT_END( Expr, node );
     
    13311241        VISIT_START( node );
    13321242
    1333         if ( __visit_children() ) {
     1243        VISIT({
    13341244                guard_symtab guard { *this };
    13351245                maybe_accept( node, &ConstantExpr::result );
    1336         }
     1246        })
    13371247
    13381248        VISIT_END( Expr, node );
     
    13451255        VISIT_START( node );
    13461256
    1347         if ( __visit_children() ) {
    1348                 {
     1257        VISIT({
    13491258                        guard_symtab guard { *this };
    13501259                        maybe_accept( node, &SizeofExpr::result );
     
    13551264                        maybe_accept( node, &SizeofExpr::expr );
    13561265                }
    1357         }
     1266        )
    13581267
    13591268        VISIT_END( Expr, node );
     
    13661275        VISIT_START( node );
    13671276
    1368         if ( __visit_children() ) {
    1369                 {
     1277        VISIT({
    13701278                        guard_symtab guard { *this };
    13711279                        maybe_accept( node, &AlignofExpr::result );
     
    13761284                        maybe_accept( node, &AlignofExpr::expr );
    13771285                }
    1378         }
     1286        )
    13791287
    13801288        VISIT_END( Expr, node );
     
    13871295        VISIT_START( node );
    13881296
    1389         if ( __visit_children() ) {
    1390                 {
     1297        VISIT({
    13911298                        guard_symtab guard { *this };
    13921299                        maybe_accept( node, &UntypedOffsetofExpr::result );
    13931300                }
    13941301                maybe_accept( node, &UntypedOffsetofExpr::type   );
    1395         }
     1302        )
    13961303
    13971304        VISIT_END( Expr, node );
     
    14041311        VISIT_START( node );
    14051312
    1406         if ( __visit_children() ) {
    1407                 {
     1313        VISIT({
    14081314                        guard_symtab guard { *this };
    14091315                        maybe_accept( node, &OffsetofExpr::result );
    14101316                }
    14111317                maybe_accept( node, &OffsetofExpr::type   );
    1412         }
     1318        )
    14131319
    14141320        VISIT_END( Expr, node );
     
    14211327        VISIT_START( node );
    14221328
    1423         if ( __visit_children() ) {
    1424                 {
     1329        VISIT({
    14251330                        guard_symtab guard { *this };
    14261331                        maybe_accept( node, &OffsetPackExpr::result );
    14271332                }
    14281333                maybe_accept( node, &OffsetPackExpr::type   );
    1429         }
     1334        )
    14301335
    14311336        VISIT_END( Expr, node );
     
    14381343        VISIT_START( node );
    14391344
    1440         if ( __visit_children() ) {
    1441                 {
     1345        VISIT({
    14421346                        guard_symtab guard { *this };
    14431347                        maybe_accept( node, &LogicalExpr::result );
     
    14451349                maybe_accept( node, &LogicalExpr::arg1 );
    14461350                maybe_accept( node, &LogicalExpr::arg2 );
    1447         }
     1351        )
    14481352
    14491353        VISIT_END( Expr, node );
     
    14561360        VISIT_START( node );
    14571361
    1458         if ( __visit_children() ) {
    1459                 {
     1362        VISIT({
    14601363                        guard_symtab guard { *this };
    14611364                        maybe_accept( node, &ConditionalExpr::result );
     
    14641367                maybe_accept( node, &ConditionalExpr::arg2 );
    14651368                maybe_accept( node, &ConditionalExpr::arg3 );
    1466         }
     1369        )
    14671370
    14681371        VISIT_END( Expr, node );
     
    14751378        VISIT_START( node );
    14761379
    1477         if ( __visit_children() ) {
    1478                 {
     1380        VISIT({
    14791381                        guard_symtab guard { *this };
    14801382                        maybe_accept( node, &CommaExpr::result );
     
    14821384                maybe_accept( node, &CommaExpr::arg1 );
    14831385                maybe_accept( node, &CommaExpr::arg2 );
    1484         }
     1386        )
    14851387
    14861388        VISIT_END( Expr, node );
     
    14931395        VISIT_START( node );
    14941396
    1495         if ( __visit_children() ) {
    1496                 {
     1397        VISIT({
    14971398                        guard_symtab guard { *this };
    14981399                        maybe_accept( node, &TypeExpr::result );
    14991400                }
    15001401                maybe_accept( node, &TypeExpr::type );
    1501         }
     1402        )
    15021403
    15031404        VISIT_END( Expr, node );
     
    15101411        VISIT_START( node );
    15111412
    1512         if ( __visit_children() ) {
    1513                 {
     1413        VISIT({
    15141414                        guard_symtab guard { *this };
    15151415                        maybe_accept( node, &AsmExpr::result );
     
    15171417                maybe_accept( node, &AsmExpr::constraint );
    15181418                maybe_accept( node, &AsmExpr::operand    );
    1519         }
     1419        )
    15201420
    15211421        VISIT_END( Expr, node );
     
    15281428        VISIT_START( node );
    15291429
    1530         if ( __visit_children() ) {
    1531                 {
     1430        VISIT({
    15321431                        guard_symtab guard { *this };
    15331432                        maybe_accept( node, &ImplicitCopyCtorExpr::result );
    15341433                }
    15351434                maybe_accept( node, &ImplicitCopyCtorExpr::callExpr    );
    1536         }
     1435        )
    15371436
    15381437        VISIT_END( Expr, node );
     
    15451444        VISIT_START( node );
    15461445
    1547         if ( __visit_children() ) {
    1548                 {
     1446        VISIT({
    15491447                        guard_symtab guard { *this };
    15501448                        maybe_accept( node, &ConstructorExpr::result );
    15511449                }
    15521450                maybe_accept( node, &ConstructorExpr::callExpr );
    1553         }
     1451        )
    15541452
    15551453        VISIT_END( Expr, node );
     
    15621460        VISIT_START( node );
    15631461
    1564         if ( __visit_children() ) {
    1565                 {
     1462        VISIT({
    15661463                        guard_symtab guard { *this };
    15671464                        maybe_accept( node, &CompoundLiteralExpr::result );
    15681465                }
    15691466                maybe_accept( node, &CompoundLiteralExpr::init );
    1570         }
     1467        )
    15711468
    15721469        VISIT_END( Expr, node );
     
    15791476        VISIT_START( node );
    15801477
    1581         if ( __visit_children() ) {
    1582                 {
     1478        VISIT({
    15831479                        guard_symtab guard { *this };
    15841480                        maybe_accept( node, &RangeExpr::result );
     
    15861482                maybe_accept( node, &RangeExpr::low    );
    15871483                maybe_accept( node, &RangeExpr::high   );
    1588         }
     1484        )
    15891485
    15901486        VISIT_END( Expr, node );
     
    15971493        VISIT_START( node );
    15981494
    1599         if ( __visit_children() ) {
    1600                 {
     1495        VISIT({
    16011496                        guard_symtab guard { *this };
    16021497                        maybe_accept( node, &UntypedTupleExpr::result );
    16031498                }
    16041499                maybe_accept( node, &UntypedTupleExpr::exprs  );
    1605         }
     1500        )
    16061501
    16071502        VISIT_END( Expr, node );
     
    16141509        VISIT_START( node );
    16151510
    1616         if ( __visit_children() ) {
    1617                 {
     1511        VISIT({
    16181512                        guard_symtab guard { *this };
    16191513                        maybe_accept( node, &TupleExpr::result );
    16201514                }
    16211515                maybe_accept( node, &TupleExpr::exprs  );
    1622         }
     1516        )
    16231517
    16241518        VISIT_END( Expr, node );
     
    16311525        VISIT_START( node );
    16321526
    1633         if ( __visit_children() ) {
    1634                 {
     1527        VISIT({
    16351528                        guard_symtab guard { *this };
    16361529                        maybe_accept( node, &TupleIndexExpr::result );
    16371530                }
    16381531                maybe_accept( node, &TupleIndexExpr::tuple  );
    1639         }
     1532        )
    16401533
    16411534        VISIT_END( Expr, node );
     
    16481541        VISIT_START( node );
    16491542
    1650         if ( __visit_children() ) {
    1651                 {
     1543        VISIT({
    16521544                        guard_symtab guard { *this };
    16531545                        maybe_accept( node, &TupleAssignExpr::result );
    16541546                }
    16551547                maybe_accept( node, &TupleAssignExpr::stmtExpr );
    1656         }
     1548        )
    16571549
    16581550        VISIT_END( Expr, node );
     
    16651557        VISIT_START( node );
    16661558
    1667         if ( __visit_children() ) {
    1668                 // don't want statements from outer CompoundStmts to be added to this StmtExpr
     1559        VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr
    16691560                // get the stmts that will need to be spliced in
    16701561                auto stmts_before = __pass::stmtsToAddBefore( core, 0);
     
    16831574                maybe_accept( node, &StmtExpr::returnDecls );
    16841575                maybe_accept( node, &StmtExpr::dtors       );
    1685         }
     1576        )
    16861577
    16871578        VISIT_END( Expr, node );
     
    16941585        VISIT_START( node );
    16951586
    1696         if ( __visit_children() ) {
    1697                 {
     1587        VISIT({
    16981588                        guard_symtab guard { *this };
    16991589                        maybe_accept( node, &UniqueExpr::result );
    17001590                }
    17011591                maybe_accept( node, &UniqueExpr::expr   );
    1702         }
     1592        )
    17031593
    17041594        VISIT_END( Expr, node );
     
    17111601        VISIT_START( node );
    17121602
    1713         if ( __visit_children() ) {
    1714                 {
     1603        VISIT({
    17151604                        guard_symtab guard { *this };
    17161605                        maybe_accept( node, &UntypedInitExpr::result );
     
    17181607                maybe_accept( node, &UntypedInitExpr::expr   );
    17191608                // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
    1720         }
     1609        )
    17211610
    17221611        VISIT_END( Expr, node );
     
    17291618        VISIT_START( node );
    17301619
    1731         if ( __visit_children() ) {
    1732                 {
     1620        VISIT({
    17331621                        guard_symtab guard { *this };
    17341622                        maybe_accept( node, &InitExpr::result );
     
    17361624                maybe_accept( node, &InitExpr::expr   );
    17371625                maybe_accept( node, &InitExpr::designation );
    1738         }
     1626        )
    17391627
    17401628        VISIT_END( Expr, node );
     
    17471635        VISIT_START( node );
    17481636
    1749         if ( __visit_children() ) {
    1750                 {
     1637        VISIT({
    17511638                        guard_symtab guard { *this };
    17521639                        maybe_accept( node, &DeletedExpr::result );
     
    17541641                maybe_accept( node, &DeletedExpr::expr );
    17551642                // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
    1756         }
     1643        )
    17571644
    17581645        VISIT_END( Expr, node );
     
    17651652        VISIT_START( node );
    17661653
    1767         if ( __visit_children() ) {
    1768                 {
     1654        VISIT({
    17691655                        guard_symtab guard { *this };
    17701656                        maybe_accept( node, &DefaultArgExpr::result );
    17711657                }
    17721658                maybe_accept( node, &DefaultArgExpr::expr );
    1773         }
     1659        )
    17741660
    17751661        VISIT_END( Expr, node );
     
    17821668        VISIT_START( node );
    17831669
    1784         if ( __visit_children() ) {
    1785                 {
     1670        VISIT({
    17861671                        guard_symtab guard { *this };
    17871672                        maybe_accept( node, &GenericExpr::result );
     
    18121697                        node = n;
    18131698                }
    1814         }
     1699        )
    18151700
    18161701        VISIT_END( Expr, node );
     
    18411726        VISIT_START( node );
    18421727
    1843         if ( __visit_children() ) {
     1728        VISIT(
    18441729                // xxx - should PointerType visit/mutate dimension?
    18451730                maybe_accept( node, &PointerType::base );
    1846         }
     1731        )
    18471732
    18481733        VISIT_END( Type, node );
     
    18551740        VISIT_START( node );
    18561741
    1857         if ( __visit_children() ) {
     1742        VISIT(
    18581743                maybe_accept( node, &ArrayType::dimension );
    18591744                maybe_accept( node, &ArrayType::base );
    1860         }
     1745        )
    18611746
    18621747        VISIT_END( Type, node );
     
    18691754        VISIT_START( node );
    18701755
    1871         if ( __visit_children() ) {
     1756        VISIT(
    18721757                maybe_accept( node, &ReferenceType::base );
    1873         }
     1758        )
    18741759
    18751760        VISIT_END( Type, node );
     
    18821767        VISIT_START( node );
    18831768
    1884         if ( __visit_children() ) {
     1769        VISIT(
    18851770                maybe_accept( node, &QualifiedType::parent );
    18861771                maybe_accept( node, &QualifiedType::child );
    1887         }
     1772        )
    18881773
    18891774        VISIT_END( Type, node );
     
    18961781        VISIT_START( node );
    18971782
    1898         if ( __visit_children() ) {
     1783        VISIT({
    18991784                // guard_forall_subs forall_guard { *this, node };
    19001785                // mutate_forall( node );
     
    19021787                maybe_accept( node, &FunctionType::returns );
    19031788                maybe_accept( node, &FunctionType::params  );
    1904         }
     1789        })
    19051790
    19061791        VISIT_END( Type, node );
     
    19151800        __pass::symtab::addStruct( core, 0, node->name );
    19161801
    1917         if ( __visit_children() ) {
     1802        VISIT({
    19181803                guard_symtab guard { *this };
    19191804                maybe_accept( node, &StructInstType::params );
    1920         }
     1805        })
    19211806
    19221807        VISIT_END( Type, node );
     
    19311816        __pass::symtab::addUnion( core, 0, node->name );
    19321817
    1933         if ( __visit_children() ) {
     1818        VISIT({
    19341819                guard_symtab guard { *this };
    19351820                maybe_accept( node, &UnionInstType::params );
    1936         }
     1821        })
    19371822
    19381823        VISIT_END( Type, node );
     
    19451830        VISIT_START( node );
    19461831
    1947         if ( __visit_children() ) {
     1832        VISIT({
    19481833                maybe_accept( node, &EnumInstType::params );
    1949         }
     1834        })
    19501835
    19511836        VISIT_END( Type, node );
     
    19581843        VISIT_START( node );
    19591844
    1960         if ( __visit_children() ) {
     1845        VISIT({
    19611846                maybe_accept( node, &TraitInstType::params );
    1962         }
     1847        })
    19631848
    19641849        VISIT_END( Type, node );
     
    19711856        VISIT_START( node );
    19721857
    1973         if ( __visit_children() ) {
     1858        VISIT(
    19741859                {
    19751860                        maybe_accept( node, &TypeInstType::params );
     
    19771862                // ensure that base re-bound if doing substitution
    19781863                __pass::forall::replace( core, 0, node );
    1979         }
     1864        )
    19801865
    19811866        VISIT_END( Type, node );
     
    19881873        VISIT_START( node );
    19891874
    1990         if ( __visit_children() ) {
     1875        VISIT(
    19911876                maybe_accept( node, &TupleType::types );
    19921877                maybe_accept( node, &TupleType::members );
    1993         }
     1878        )
    19941879
    19951880        VISIT_END( Type, node );
     
    20021887        VISIT_START( node );
    20031888
    2004         if ( __visit_children() ) {
     1889        VISIT(
    20051890                maybe_accept( node, &TypeofType::expr );
    2006         }
     1891        )
    20071892
    20081893        VISIT_END( Type, node );
     
    20151900        VISIT_START( node );
    20161901
    2017         if ( __visit_children() ) {
     1902        VISIT(
    20181903                maybe_accept( node, &VTableType::base );
    2019         }
     1904        )
    20201905
    20211906        VISIT_END( Type, node );
     
    20651950        VISIT_START( node );
    20661951
    2067         if ( __visit_children() ) {
    2068                 maybe_accept( node, &Designation::designators );
    2069         }
     1952        VISIT( maybe_accept( node, &Designation::designators ); )
    20701953
    20711954        VISIT_END( Designation, node );
     
    20781961        VISIT_START( node );
    20791962
    2080         if ( __visit_children() ) {
     1963        VISIT(
    20811964                maybe_accept( node, &SingleInit::value );
    2082         }
     1965        )
    20831966
    20841967        VISIT_END( Init, node );
     
    20911974        VISIT_START( node );
    20921975
    2093         if ( __visit_children() ) {
     1976        VISIT(
    20941977                maybe_accept( node, &ListInit::designations );
    20951978                maybe_accept( node, &ListInit::initializers );
    2096         }
     1979        )
    20971980
    20981981        VISIT_END( Init, node );
     
    21051988        VISIT_START( node );
    21061989
    2107         if ( __visit_children() ) {
     1990        VISIT(
    21081991                maybe_accept( node, &ConstructorInit::ctor );
    21091992                maybe_accept( node, &ConstructorInit::dtor );
    21101993                maybe_accept( node, &ConstructorInit::init );
    2111         }
     1994        )
    21121995
    21131996        VISIT_END( Init, node );
     
    21202003        VISIT_START( node );
    21212004
    2122         if ( __visit_children() ) {
     2005        VISIT(
    21232006                maybe_accept( node, &Attribute::params );
    2124         }
     2007        )
    21252008
    21262009        VISIT_END( Attribute, node );
     
    21332016        VISIT_START( node );
    21342017
    2135         if ( __visit_children() ) {
     2018        VISIT(
    21362019                {
    21372020                        bool mutated = false;
     
    21492032                        }
    21502033                }
    2151         }
     2034        )
    21522035
    21532036        VISIT_END( TypeSubstitution, node );
     
    21552038
    21562039#undef VISIT_START
     2040#undef VISIT
    21572041#undef VISIT_END
Note: See TracChangeset for help on using the changeset viewer.