source: src/AST/Pass.impl.hpp @ 334801b

ast-experimental
Last change on this file since 334801b was 334801b, checked in by Andrew Beach <ajbeach@…>, 16 months ago

Simplify one of the Pass::visit methods for CompoundStmt?. It repeats two lines to move the conditional code into different if clauses.

  • Property mode set to 100644
File size: 63.6 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// ast::Pass.impl.hpp --
8//
9// Author           : Thierry Delisle
10// Created On       : Thu May 09 15::37::05 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#pragma once
17// IWYU pragma: private, include "AST/Pass.hpp"
18
19#include <type_traits>
20#include <unordered_map>
21
22#include "AST/Copy.hpp"
23#include "AST/TranslationUnit.hpp"
24#include "AST/TypeSubstitution.hpp"
25
26#define VISIT_START( node ) \
27        using namespace ast; \
28        /* back-up the last known code location */ \
29        __attribute__((unused)) auto loc_guard = ast::__pass::make_location_guard( core, node, 0 ); \
30        /* back-up the visit children */ \
31        __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \
32        /* setup the scope for passes that want to run code at exit */ \
33        __attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (core, 0) ); \
34        /* begin tracing memory allocation if requested by this pass */ \
35        __pass::beginTrace( core, 0 ); \
36        /* call the implementation of the previsit of this pass */ \
37        __pass::previsit( core, node, 0 );
38
39#define VISIT_END( type, node ) \
40        /* call the implementation of the postvisit of this pass */ \
41        auto __return = __pass::postvisit( core, node, 0 ); \
42        assertf(__return, "post visit should never return null"); \
43        /* end tracing memory allocation if requested by this pass */ \
44        __pass::endTrace( core, 0 ); \
45        return __return;
46
47#ifdef PEDANTIC_PASS_ASSERT
48#define __pedantic_pass_assert(...) assert(__VA_ARGS__)
49#define __pedantic_pass_assertf(...) assertf(__VA_ARGS__)
50#else
51#define __pedantic_pass_assert(...)
52#define __pedantic_pass_assertf(...)
53#endif
54
55namespace ast {
56        template<typename node_t>
57        node_t * shallowCopy( const node_t * node );
58
59        namespace __pass {
60                // Check if this is either a null pointer or a pointer to an empty container
61                template<typename T>
62                static inline bool empty( T * ptr ) {
63                        return !ptr || ptr->empty();
64                }
65
66                template< typename core_t, typename node_t >
67                static inline node_t* mutate(const node_t *node) {
68                        return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node);
69                }
70
71                //------------------------------
72                template<typename it_t, template <class...> class container_t>
73                static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) {
74                        if(empty(decls)) return;
75
76                        std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto {
77                                        return new DeclStmt( decl->location, decl );
78                                });
79                        decls->clear();
80                        if(mutated) *mutated = true;
81                }
82
83                template<typename it_t, template <class...> class container_t>
84                static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) {
85                        if(empty(stmts)) return;
86
87                        std::move(stmts->begin(), stmts->end(), it);
88                        stmts->clear();
89                        if(mutated) *mutated = true;
90                }
91
92                //------------------------------
93                /// Check if should be skipped, different for pointers and containers
94                template<typename node_t>
95                bool skip( const ast::ptr<node_t> & val) {
96                        return !val;
97                }
98
99                template< template <class...> class container_t, typename node_t >
100                bool skip( const container_t<ast::ptr< node_t >> & val ) {
101                        return val.empty();
102                }
103
104                //------------------------------
105                /// Get the value to visit, different for pointers and containers
106                template<typename node_t>
107                auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) {
108                        return val.get();
109                }
110
111                template<typename node_t>
112                const node_t & get( const node_t & val, long) {
113                        return val;
114                }
115
116                //------------------------------
117                /// Check if value was mutated, different for pointers and containers
118                template<typename lhs_t, typename rhs_t>
119                bool differs( const lhs_t * old_val, const rhs_t * new_val ) {
120                        return old_val != new_val;
121                }
122
123                template< template <class...> class container_t, typename node_t >
124                bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) {
125                        return !new_val.empty();
126                }
127        }
128
129        template< typename core_t >
130        template< typename node_t >
131        auto ast::Pass< core_t >::call_accept( const node_t * node )
132                -> typename ast::Pass< core_t >::template generic_call_accept_result<node_t>::type
133        {
134                __pedantic_pass_assert( __visit_children() );
135                __pedantic_pass_assert( node );
136
137                static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR");
138                static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR");
139
140                auto nval = node->accept( *this );
141                __pass::result1<
142                        typename std::remove_pointer< decltype( node->accept(*this) ) >::type
143                > res;
144                res.differs = nval != node;
145                res.value = nval;
146                return res;
147        }
148
149        template< typename core_t >
150        __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
151                __pedantic_pass_assert( __visit_children() );
152                __pedantic_pass_assert( expr );
153
154                auto nval = expr->accept( *this );
155                return { nval != expr, nval };
156        }
157
158        template< typename core_t >
159        __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
160                __pedantic_pass_assert( __visit_children() );
161                __pedantic_pass_assert( stmt );
162
163                const ast::Stmt * nval = stmt->accept( *this );
164                return { nval != stmt, nval };
165        }
166
167        template< typename core_t >
168        __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept_top( const ast::Expr * expr ) {
169                __pedantic_pass_assert( __visit_children() );
170                __pedantic_pass_assert( expr );
171
172                const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
173                if ( typeSubs_ptr && expr->env ) {
174                        *typeSubs_ptr = expr->env;
175                }
176
177                auto nval = expr->accept( *this );
178                return { nval != expr, nval };
179        }
180
181        template< typename core_t >
182        __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
183                __pedantic_pass_assert( __visit_children() );
184                __pedantic_pass_assert( stmt );
185
186                // add a few useful symbols to the scope
187                using __pass::empty;
188
189                // get the stmts/decls that will need to be spliced in
190                auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
191                auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
192                auto decls_before = __pass::declsToAddBefore( core, 0 );
193                auto decls_after  = __pass::declsToAddAfter ( core, 0 );
194
195                // These may be modified by subnode but most be restored once we exit this statemnet.
196                ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::typeSubs( core, 0 ) );
197                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
198                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
199                ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
200                ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
201
202                // Now is the time to actually visit the node
203                const ast::Stmt * nstmt = stmt->accept( *this );
204
205                // If the pass doesn't want to add anything then we are done
206                if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
207                        return { nstmt != stmt, nstmt };
208                }
209
210                // Make sure that it is either adding statements or declartions but not both
211                // this is because otherwise the order would be awkward to predict
212                assert(( empty( stmts_before ) && empty( stmts_after ))
213                    || ( empty( decls_before ) && empty( decls_after )) );
214
215                // Create a new Compound Statement to hold the new decls/stmts
216                ast::CompoundStmt * compound = new ast::CompoundStmt( stmt->location );
217
218                // Take all the declarations that go before
219                __pass::take_all( std::back_inserter( compound->kids ), decls_before );
220                __pass::take_all( std::back_inserter( compound->kids ), stmts_before );
221
222                // Insert the original declaration
223                compound->kids.emplace_back( nstmt );
224
225                // Insert all the declarations that go before
226                __pass::take_all( std::back_inserter( compound->kids ), decls_after );
227                __pass::take_all( std::back_inserter( compound->kids ), stmts_after );
228
229                return {true, compound};
230        }
231
232        template< typename core_t >
233        template< template <class...> class container_t >
234        __pass::template resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
235                __pedantic_pass_assert( __visit_children() );
236                if( statements.empty() ) return {};
237
238                // We are going to aggregate errors for all these statements
239                SemanticErrorException errors;
240
241                // add a few useful symbols to the scope
242                using __pass::empty;
243
244                // get the stmts/decls that will need to be spliced in
245                auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
246                auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
247                auto decls_before = __pass::declsToAddBefore( core, 0 );
248                auto decls_after  = __pass::declsToAddAfter ( core, 0 );
249
250                // These may be modified by subnode but most be restored once we exit this statemnet.
251                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
252                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
253                ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before );
254                ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after  );
255
256                // update pass statitistics
257                pass_visitor_stats.depth++;
258                pass_visitor_stats.max->push(pass_visitor_stats.depth);
259                pass_visitor_stats.avg->push(pass_visitor_stats.depth);
260
261                __pass::resultNstmt<container_t> new_kids;
262                for( auto value : enumerate( statements ) ) {
263                        try {
264                                size_t i = value.idx;
265                                const Stmt * stmt = value.val;
266                                __pedantic_pass_assert( stmt );
267                                const ast::Stmt * new_stmt = stmt->accept( *this );
268                                assert( new_stmt );
269                                if(new_stmt != stmt ) { new_kids.differs = true; }
270
271                                // Make sure that it is either adding statements or declartions but not both
272                                // this is because otherwise the order would be awkward to predict
273                                assert(( empty( stmts_before ) && empty( stmts_after ))
274                                    || ( empty( decls_before ) && empty( decls_after )) );
275
276                                // Take all the statements which should have gone after, N/A for first iteration
277                                new_kids.take_all( decls_before );
278                                new_kids.take_all( stmts_before );
279
280                                // Now add the statement if there is one
281                                if(new_stmt != stmt) {
282                                        new_kids.values.emplace_back( new_stmt, i, false );
283                                } else {
284                                        new_kids.values.emplace_back( nullptr, i, true );
285                                }
286
287                                // Take all the declarations that go before
288                                new_kids.take_all( decls_after );
289                                new_kids.take_all( stmts_after );
290                        }
291                        catch ( SemanticErrorException &e ) {
292                                errors.append( e );
293                        }
294                }
295                pass_visitor_stats.depth--;
296                if ( !errors.isEmpty() ) { throw errors; }
297
298                return new_kids;
299        }
300
301        template< typename core_t >
302        template< template <class...> class container_t, typename node_t >
303        __pass::template resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
304                __pedantic_pass_assert( __visit_children() );
305                if( container.empty() ) return {};
306                SemanticErrorException errors;
307
308                pass_visitor_stats.depth++;
309                pass_visitor_stats.max->push(pass_visitor_stats.depth);
310                pass_visitor_stats.avg->push(pass_visitor_stats.depth);
311
312                bool mutated = false;
313                container_t<ptr<node_t>> new_kids;
314                for ( const node_t * node : container ) {
315                        try {
316                                __pedantic_pass_assert( node );
317                                const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) );
318                                if(new_stmt != node ) {
319                                        mutated = true;
320                                        new_kids.emplace_back( new_stmt );
321                                } else {
322                                        new_kids.emplace_back( nullptr );
323                                }
324
325                        }
326                        catch( SemanticErrorException &e ) {
327                                errors.append( e );
328                        }
329                }
330
331                __pedantic_pass_assert( new_kids.size() == container.size() );
332                pass_visitor_stats.depth--;
333                if ( ! errors.isEmpty() ) { throw errors; }
334
335                return ast::__pass::resultN<container_t, node_t>{ mutated, new_kids };
336        }
337
338        template< typename core_t >
339        template<typename node_t, typename super_t, typename field_t>
340        void ast::Pass< core_t >::maybe_accept(
341                const node_t * & parent,
342                field_t super_t::*field
343        ) {
344                static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
345
346                if(__pass::skip(parent->*field)) return;
347                const auto & old_val = __pass::get(parent->*field, 0);
348
349                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
350
351                auto new_val = call_accept( old_val );
352
353                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
354
355                if( new_val.differs ) {
356                        auto new_parent = __pass::mutate<core_t>(parent);
357                        new_val.apply(new_parent, field);
358                        parent = new_parent;
359                }
360        }
361
362        template< typename core_t >
363        template<typename node_t, typename super_t, typename field_t>
364        void ast::Pass< core_t >::maybe_accept_top(
365                const node_t * & parent,
366                field_t super_t::*field
367        ) {
368                static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
369
370                if(__pass::skip(parent->*field)) return;
371                const auto & old_val = __pass::get(parent->*field, 0);
372
373                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
374
375                auto new_val = call_accept_top( old_val );
376
377                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
378
379                if( new_val.differs ) {
380                        auto new_parent = __pass::mutate<core_t>(parent);
381                        new_val.apply(new_parent, field);
382                        parent = new_parent;
383                }
384        }
385
386        template< typename core_t >
387        template<typename node_t, typename super_t, typename field_t>
388        void ast::Pass< core_t >::maybe_accept_as_compound(
389                const node_t * & parent,
390                field_t super_t::*child
391        ) {
392                static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
393
394                if(__pass::skip(parent->*child)) return;
395                const auto & old_val = __pass::get(parent->*child, 0);
396
397                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
398
399                auto new_val = call_accept_as_compound( old_val );
400
401                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
402
403                if( new_val.differs ) {
404                        auto new_parent = __pass::mutate<core_t>(parent);
405                        new_val.apply( new_parent, child );
406                        parent = new_parent;
407                }
408        }
409
410}
411
412//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
413//========================================================================================================================================================================
414//========================================================================================================================================================================
415//========================================================================================================================================================================
416//========================================================================================================================================================================
417//========================================================================================================================================================================
418//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
419
420template< typename core_t >
421inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< core_t > & visitor ) {
422        // We are going to aggregate errors for all these statements
423        SemanticErrorException errors;
424
425        // add a few useful symbols to the scope
426        using __pass::empty;
427
428        // get the stmts/decls that will need to be spliced in
429        auto decls_before = __pass::declsToAddBefore( visitor.core, 0);
430        auto decls_after  = __pass::declsToAddAfter ( visitor.core, 0);
431
432        // update pass statitistics
433        pass_visitor_stats.depth++;
434        pass_visitor_stats.max->push(pass_visitor_stats.depth);
435        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
436
437        for ( std::list< ast::ptr<ast::Decl> >::iterator i = decls.begin(); ; ++i ) {
438                // splice in new declarations after previous decl
439                if ( !empty( decls_after ) ) { decls.splice( i, *decls_after ); }
440
441                if ( i == decls.end() ) break;
442
443                try {
444                        // run visitor on declaration
445                        ast::ptr<ast::Decl> & node = *i;
446                        assert( node );
447                        node = node->accept( visitor );
448                }
449                catch( SemanticErrorException &e ) {
450                        if (__pass::on_error (visitor.core, *i, 0))
451                                errors.append( e );
452                }
453
454                // splice in new declarations before current decl
455                if ( !empty( decls_before ) ) { decls.splice( i, *decls_before ); }
456        }
457        pass_visitor_stats.depth--;
458        if ( !errors.isEmpty() ) { throw errors; }
459}
460
461template< typename core_t >
462inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) {
463        if ( auto ptr = __pass::translation_unit::get_cptr( visitor.core, 0 ) ) {
464                ValueGuard<const TranslationUnit *> guard( *ptr );
465                *ptr = &unit;
466                return ast::accept_all( unit.decls, visitor );
467        } else {
468                return ast::accept_all( unit.decls, visitor );
469        }
470}
471
472// A NOTE ON THE ORDER OF TRAVERSAL
473//
474// Types and typedefs have their base types visited before they are added to the type table.  This is ok, since there is
475// no such thing as a recursive type or typedef.
476//
477//             typedef struct { T *x; } T; // never allowed
478//
479// for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the
480// members are traversed, and then the complete type should be added (assuming the type is completed by this particular
481// declaration).
482//
483//             struct T { struct T *x; }; // allowed
484//
485// It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that
486// traversal may modify the definition of the type and these modifications should be visible when the symbol table is
487// queried later in this pass.
488
489//--------------------------------------------------------------------------
490// ObjectDecl
491template< typename core_t >
492const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::ObjectDecl * node ) {
493        VISIT_START( node );
494
495        if ( __visit_children() ) {
496                {
497                        guard_symtab guard { *this };
498                        maybe_accept( node, &ObjectDecl::type );
499                }
500                maybe_accept( node, &ObjectDecl::init          );
501                maybe_accept( node, &ObjectDecl::bitfieldWidth );
502                maybe_accept( node, &ObjectDecl::attributes    );
503        }
504
505        __pass::symtab::addId( core, 0, node );
506
507        VISIT_END( DeclWithType, node );
508}
509
510//--------------------------------------------------------------------------
511// FunctionDecl
512template< typename core_t >
513const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::FunctionDecl * node ) {
514        VISIT_START( node );
515
516        __pass::symtab::addId( core, 0, node );
517
518        if ( __visit_children() ) {
519                maybe_accept( node, &FunctionDecl::withExprs );
520        }
521        {
522                // with clause introduces a level of scope (for the with expression members).
523                // with clause exprs are added to the symbol table before parameters so that parameters
524                // shadow with exprs and not the other way around.
525                guard_symtab guard { *this };
526                __pass::symtab::addWith( core, 0, node->withExprs, node );
527                {
528                        guard_symtab guard { *this };
529                        // implicit add __func__ identifier as specified in the C manual 6.4.2.2
530                        // This is a C name and so has C linkage.
531                        static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{
532                                CodeLocation{}, "__func__",
533                                new ast::ArrayType{
534                                        new ast::BasicType{ ast::BasicType::Char, ast::CV::Const },
535                                        nullptr, VariableLen, DynamicDim
536                                },
537                                nullptr,
538                                ast::Storage::Classes(),
539                                ast::Linkage::C,
540                        } };
541                        __pass::symtab::addId( core, 0, func );
542                        if ( __visit_children() ) {
543                                maybe_accept( node, &FunctionDecl::type_params );
544                                maybe_accept( node, &FunctionDecl::assertions );
545                                maybe_accept( node, &FunctionDecl::params );
546                                maybe_accept( node, &FunctionDecl::returns );
547                                maybe_accept( node, &FunctionDecl::type );
548                                maybe_accept( node, &FunctionDecl::attributes );
549                                // First remember that we are now within a function.
550                                ValueGuard< bool > oldInFunction( inFunction );
551                                inFunction = true;
552                                // The function body needs to have the same scope as parameters.
553                                // A CompoundStmt will not enter a new scope if atFunctionTop is true.
554                                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
555                                atFunctionTop = true;
556                                maybe_accept( node, &FunctionDecl::stmts );
557                        }
558                }
559        }
560
561        VISIT_END( DeclWithType, node );
562}
563
564//--------------------------------------------------------------------------
565// StructDecl
566template< typename core_t >
567const ast::Decl * ast::Pass< core_t >::visit( const ast::StructDecl * node ) {
568        VISIT_START( node );
569
570        // make up a forward declaration and add it before processing the members
571        // needs to be on the heap because addStruct saves the pointer
572        __pass::symtab::addStructFwd( core, 0, node );
573
574        if ( __visit_children() ) {
575                guard_symtab guard { * this };
576                maybe_accept( node, &StructDecl::params     );
577                maybe_accept( node, &StructDecl::members    );
578                maybe_accept( node, &StructDecl::attributes );
579        }
580
581        // this addition replaces the forward declaration
582        __pass::symtab::addStruct( core, 0, node );
583
584        VISIT_END( Decl, node );
585}
586
587//--------------------------------------------------------------------------
588// UnionDecl
589template< typename core_t >
590const ast::Decl * ast::Pass< core_t >::visit( const ast::UnionDecl * node ) {
591        VISIT_START( node );
592
593        // make up a forward declaration and add it before processing the members
594        __pass::symtab::addUnionFwd( core, 0, node );
595
596        if ( __visit_children() ) {
597                guard_symtab guard { * this };
598                maybe_accept( node, &UnionDecl::params     );
599                maybe_accept( node, &UnionDecl::members    );
600                maybe_accept( node, &UnionDecl::attributes );
601        }
602
603        __pass::symtab::addUnion( core, 0, node );
604
605        VISIT_END( Decl, node );
606}
607
608//--------------------------------------------------------------------------
609// EnumDecl
610template< typename core_t >
611const ast::Decl * ast::Pass< core_t >::visit( const ast::EnumDecl * node ) {
612        VISIT_START( node );
613
614        __pass::symtab::addEnum( core, 0, node );
615
616        if ( __visit_children() ) {
617                if ( node->hide == ast::EnumDecl::EnumHiding::Hide ) {
618                        guard_symtab guard { *this };
619                        maybe_accept( node, &EnumDecl::base );
620                        maybe_accept( node, &EnumDecl::params     );
621                        maybe_accept( node, &EnumDecl::members    );
622                        maybe_accept( node, &EnumDecl::attributes );
623                } else {
624                        maybe_accept( node, &EnumDecl::base );
625                        maybe_accept( node, &EnumDecl::params     );
626                        maybe_accept( node, &EnumDecl::members    );
627                        maybe_accept( node, &EnumDecl::attributes );
628                }
629        }
630
631        VISIT_END( Decl, node );
632}
633
634//--------------------------------------------------------------------------
635// TraitDecl
636template< typename core_t >
637const ast::Decl * ast::Pass< core_t >::visit( const ast::TraitDecl * node ) {
638        VISIT_START( node );
639
640        if ( __visit_children() ) {
641                guard_symtab guard { *this };
642                maybe_accept( node, &TraitDecl::params     );
643                maybe_accept( node, &TraitDecl::members    );
644                maybe_accept( node, &TraitDecl::attributes );
645        }
646
647        __pass::symtab::addTrait( core, 0, node );
648
649        VISIT_END( Decl, node );
650}
651
652//--------------------------------------------------------------------------
653// TypeDecl
654template< typename core_t >
655const ast::Decl * ast::Pass< core_t >::visit( const ast::TypeDecl * node ) {
656        VISIT_START( node );
657
658        if ( __visit_children() ) {
659                guard_symtab guard { *this };
660                maybe_accept( node, &TypeDecl::base   );
661        }
662
663        // see A NOTE ON THE ORDER OF TRAVERSAL, above
664        // note that assertions come after the type is added to the symtab, since they are not part of the type proper
665        // and may depend on the type itself
666        __pass::symtab::addType( core, 0, node );
667
668        if ( __visit_children() ) {
669                maybe_accept( node, &TypeDecl::assertions );
670
671                {
672                        guard_symtab guard { *this };
673                        maybe_accept( node, &TypeDecl::init );
674                }
675        }
676
677        VISIT_END( Decl, node );
678}
679
680//--------------------------------------------------------------------------
681// TypedefDecl
682template< typename core_t >
683const ast::Decl * ast::Pass< core_t >::visit( const ast::TypedefDecl * node ) {
684        VISIT_START( node );
685
686        if ( __visit_children() ) {
687                guard_symtab guard { *this };
688                maybe_accept( node, &TypedefDecl::base   );
689        }
690
691        __pass::symtab::addType( core, 0, node );
692
693        if ( __visit_children() ) {
694                maybe_accept( node, &TypedefDecl::assertions );
695        }
696
697        VISIT_END( Decl, node );
698}
699
700//--------------------------------------------------------------------------
701// AsmDecl
702template< typename core_t >
703const ast::AsmDecl * ast::Pass< core_t >::visit( const ast::AsmDecl * node ) {
704        VISIT_START( node );
705
706        if ( __visit_children() ) {
707                maybe_accept( node, &AsmDecl::stmt );
708        }
709
710        VISIT_END( AsmDecl, node );
711}
712
713//--------------------------------------------------------------------------
714// DirectiveDecl
715template< typename core_t >
716const ast::DirectiveDecl * ast::Pass< core_t >::visit( const ast::DirectiveDecl * node ) {
717        VISIT_START( node );
718
719        if ( __visit_children() ) {
720                maybe_accept( node, &DirectiveDecl::stmt );
721        }
722
723        VISIT_END( DirectiveDecl, node );
724}
725
726//--------------------------------------------------------------------------
727// StaticAssertDecl
728template< typename core_t >
729const ast::StaticAssertDecl * ast::Pass< core_t >::visit( const ast::StaticAssertDecl * node ) {
730        VISIT_START( node );
731
732        if ( __visit_children() ) {
733                maybe_accept_top( node, &StaticAssertDecl::cond );
734                maybe_accept( node, &StaticAssertDecl::msg  );
735        }
736
737        VISIT_END( StaticAssertDecl, node );
738}
739
740//--------------------------------------------------------------------------
741// InlineMemberDecl
742template< typename core_t >
743const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::InlineMemberDecl * node ) {
744        VISIT_START( node );
745
746        if ( __visit_children() ) {
747                {
748                        guard_symtab guard { *this };
749                        maybe_accept( node, &InlineMemberDecl::type );
750                }
751        }
752
753        VISIT_END( DeclWithType, node );
754}
755
756//--------------------------------------------------------------------------
757// CompoundStmt
758template< typename core_t >
759const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) {
760        VISIT_START( node );
761
762        if ( __visit_children() ) {
763                // Do not enter (or leave) a new symbol table scope if atFunctionTop.
764                // But always enter (and leave) a new general scope.
765                if ( atFunctionTop ) {
766                        ValueGuard< bool > guard1( atFunctionTop );
767                        atFunctionTop = false;
768                        guard_scope guard2( *this );
769                        maybe_accept( node, &CompoundStmt::kids );
770                } else {
771                        guard_symtab guard1( *this );
772                        guard_scope guard2( *this );
773                        maybe_accept( node, &CompoundStmt::kids );
774                }
775        }
776
777        VISIT_END( CompoundStmt, node );
778}
779
780//--------------------------------------------------------------------------
781// ExprStmt
782template< typename core_t >
783const ast::Stmt * ast::Pass< core_t >::visit( const ast::ExprStmt * node ) {
784        VISIT_START( node );
785
786        if ( __visit_children() ) {
787                maybe_accept_top( node, &ExprStmt::expr );
788        }
789
790        VISIT_END( Stmt, node );
791}
792
793//--------------------------------------------------------------------------
794// AsmStmt
795template< typename core_t >
796const ast::Stmt * ast::Pass< core_t >::visit( const ast::AsmStmt * node ) {
797        VISIT_START( node )
798
799        if ( __visit_children() ) {
800                maybe_accept( node, &AsmStmt::instruction );
801                maybe_accept( node, &AsmStmt::output      );
802                maybe_accept( node, &AsmStmt::input       );
803                maybe_accept( node, &AsmStmt::clobber     );
804        }
805
806        VISIT_END( Stmt, node );
807}
808
809//--------------------------------------------------------------------------
810// DirectiveStmt
811template< typename core_t >
812const ast::Stmt * ast::Pass< core_t >::visit( const ast::DirectiveStmt * node ) {
813        VISIT_START( node )
814
815        VISIT_END( Stmt, node );
816}
817
818//--------------------------------------------------------------------------
819// IfStmt
820template< typename core_t >
821const ast::Stmt * ast::Pass< core_t >::visit( const ast::IfStmt * node ) {
822        VISIT_START( node );
823
824        if ( __visit_children() ) {
825                // if statements introduce a level of scope (for the initialization)
826                guard_symtab guard { *this };
827                maybe_accept( node, &IfStmt::inits    );
828                maybe_accept_top( node, &IfStmt::cond     );
829                maybe_accept_as_compound( node, &IfStmt::then );
830                maybe_accept_as_compound( node, &IfStmt::else_ );
831        }
832
833        VISIT_END( Stmt, node );
834}
835
836//--------------------------------------------------------------------------
837// WhileDoStmt
838template< typename core_t >
839const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileDoStmt * node ) {
840        VISIT_START( node );
841
842        if ( __visit_children() ) {
843                // while statements introduce a level of scope (for the initialization)
844                guard_symtab guard { *this };
845                maybe_accept( node, &WhileDoStmt::inits );
846                maybe_accept_top( node, &WhileDoStmt::cond  );
847                maybe_accept_as_compound( node, &WhileDoStmt::body  );
848        }
849
850        VISIT_END( Stmt, node );
851}
852
853//--------------------------------------------------------------------------
854// ForStmt
855template< typename core_t >
856const ast::Stmt * ast::Pass< core_t >::visit( const ast::ForStmt * node ) {
857        VISIT_START( node );
858
859        if ( __visit_children() ) {
860                // for statements introduce a level of scope (for the initialization)
861                guard_symtab guard { *this };
862                // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later.
863                maybe_accept( node, &ForStmt::inits );
864                maybe_accept_top( node, &ForStmt::cond  );
865                maybe_accept_top( node, &ForStmt::inc   );
866                maybe_accept_as_compound( node, &ForStmt::body  );
867        }
868
869        VISIT_END( Stmt, node );
870}
871
872//--------------------------------------------------------------------------
873// SwitchStmt
874template< typename core_t >
875const ast::Stmt * ast::Pass< core_t >::visit( const ast::SwitchStmt * node ) {
876        VISIT_START( node );
877
878        if ( __visit_children() ) {
879                maybe_accept_top( node, &SwitchStmt::cond  );
880                maybe_accept( node, &SwitchStmt::cases );
881        }
882
883        VISIT_END( Stmt, node );
884}
885
886//--------------------------------------------------------------------------
887// CaseClause
888template< typename core_t >
889const ast::CaseClause * ast::Pass< core_t >::visit( const ast::CaseClause * node ) {
890        VISIT_START( node );
891
892        if ( __visit_children() ) {
893                maybe_accept_top( node, &CaseClause::cond  );
894                maybe_accept( node, &CaseClause::stmts );
895        }
896
897        VISIT_END( CaseClause, node );
898}
899
900//--------------------------------------------------------------------------
901// BranchStmt
902template< typename core_t >
903const ast::Stmt * ast::Pass< core_t >::visit( const ast::BranchStmt * node ) {
904        VISIT_START( node );
905        VISIT_END( Stmt, node );
906}
907
908//--------------------------------------------------------------------------
909// ReturnStmt
910template< typename core_t >
911const ast::Stmt * ast::Pass< core_t >::visit( const ast::ReturnStmt * node ) {
912        VISIT_START( node );
913
914        if ( __visit_children() ) {
915                maybe_accept_top( node, &ReturnStmt::expr );
916        }
917
918        VISIT_END( Stmt, node );
919}
920
921//--------------------------------------------------------------------------
922// ThrowStmt
923template< typename core_t >
924const ast::Stmt * ast::Pass< core_t >::visit( const ast::ThrowStmt * node ) {
925        VISIT_START( node );
926
927        if ( __visit_children() ) {
928                maybe_accept( node, &ThrowStmt::expr   );
929                maybe_accept( node, &ThrowStmt::target );
930        }
931
932        VISIT_END( Stmt, node );
933}
934
935//--------------------------------------------------------------------------
936// TryStmt
937template< typename core_t >
938const ast::Stmt * ast::Pass< core_t >::visit( const ast::TryStmt * node ) {
939        VISIT_START( node );
940
941        if ( __visit_children() ) {
942                maybe_accept( node, &TryStmt::body     );
943                maybe_accept( node, &TryStmt::handlers );
944                maybe_accept( node, &TryStmt::finally  );
945        }
946
947        VISIT_END( Stmt, node );
948}
949
950//--------------------------------------------------------------------------
951// CatchClause
952template< typename core_t >
953const ast::CatchClause * ast::Pass< core_t >::visit( const ast::CatchClause * node ) {
954        VISIT_START( node );
955
956        if ( __visit_children() ) {
957                // catch statements introduce a level of scope (for the caught exception)
958                guard_symtab guard { *this };
959                maybe_accept( node, &CatchClause::decl );
960                maybe_accept_top( node, &CatchClause::cond );
961                maybe_accept_as_compound( node, &CatchClause::body );
962        }
963
964        VISIT_END( CatchClause, node );
965}
966
967//--------------------------------------------------------------------------
968// FinallyClause
969template< typename core_t >
970const ast::FinallyClause * ast::Pass< core_t >::visit( const ast::FinallyClause * node ) {
971        VISIT_START( node );
972
973        if ( __visit_children() ) {
974                maybe_accept( node, &FinallyClause::body );
975        }
976
977        VISIT_END( FinallyClause, node );
978}
979
980//--------------------------------------------------------------------------
981// FinallyStmt
982template< typename core_t >
983const ast::Stmt * ast::Pass< core_t >::visit( const ast::SuspendStmt * node ) {
984        VISIT_START( node );
985
986        if ( __visit_children() ) {
987                maybe_accept( node, &SuspendStmt::then   );
988        }
989
990        VISIT_END( Stmt, node );
991}
992
993//--------------------------------------------------------------------------
994// WhenClause
995template< typename core_t >
996const ast::WhenClause * ast::Pass< core_t >::visit( const ast::WhenClause * node ) {
997        VISIT_START( node );
998
999        if ( __visit_children() ) {
1000                maybe_accept( node, &WhenClause::target );
1001                maybe_accept( node, &WhenClause::stmt );
1002                maybe_accept( node, &WhenClause::when_cond );
1003        }
1004
1005        VISIT_END( WhenClause, node );
1006}
1007
1008//--------------------------------------------------------------------------
1009// WaitForStmt
1010template< typename core_t >
1011const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitForStmt * node ) {
1012        VISIT_START( node );
1013
1014        if ( __visit_children() ) {
1015                maybe_accept( node, &WaitForStmt::clauses );
1016                maybe_accept( node, &WaitForStmt::timeout_time );
1017                maybe_accept( node, &WaitForStmt::timeout_stmt );
1018                maybe_accept( node, &WaitForStmt::timeout_cond );
1019                maybe_accept( node, &WaitForStmt::else_stmt );
1020                maybe_accept( node, &WaitForStmt::else_cond );
1021        }
1022
1023        VISIT_END( Stmt, node );
1024}
1025
1026//--------------------------------------------------------------------------
1027// WaitForClause
1028template< typename core_t >
1029const ast::WaitForClause * ast::Pass< core_t >::visit( const ast::WaitForClause * node ) {
1030        VISIT_START( node );
1031
1032        if ( __visit_children() ) {
1033                maybe_accept( node, &WaitForClause::target );
1034                maybe_accept( node, &WaitForClause::target_args );
1035                maybe_accept( node, &WaitForClause::stmt );
1036                maybe_accept( node, &WaitForClause::when_cond );
1037        }
1038
1039        VISIT_END( WaitForClause, node );
1040}
1041
1042//--------------------------------------------------------------------------
1043// WaitUntilStmt
1044template< typename core_t >
1045const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitUntilStmt * node ) {
1046        VISIT_START( node );
1047
1048        if ( __visit_children() ) {
1049                maybe_accept( node, &WaitUntilStmt::clauses );
1050                maybe_accept( node, &WaitUntilStmt::timeout_time );
1051                maybe_accept( node, &WaitUntilStmt::timeout_stmt );
1052                maybe_accept( node, &WaitUntilStmt::timeout_cond );
1053                maybe_accept( node, &WaitUntilStmt::else_stmt );
1054                maybe_accept( node, &WaitUntilStmt::else_cond );
1055        }
1056
1057        VISIT_END( Stmt, node );
1058}
1059
1060//--------------------------------------------------------------------------
1061// WithStmt
1062template< typename core_t >
1063const ast::Decl * ast::Pass< core_t >::visit( const ast::WithStmt * node ) {
1064        VISIT_START( node );
1065
1066        if ( __visit_children() ) {
1067                maybe_accept( node, &WithStmt::exprs );
1068                {
1069                        // catch statements introduce a level of scope (for the caught exception)
1070                        guard_symtab guard { *this };
1071                        __pass::symtab::addWith( core, 0, node->exprs, node );
1072                        maybe_accept( node, &WithStmt::stmt );
1073                }
1074        }
1075
1076        VISIT_END( Stmt, node );
1077}
1078
1079//--------------------------------------------------------------------------
1080// NullStmt
1081template< typename core_t >
1082const ast::NullStmt * ast::Pass< core_t >::visit( const ast::NullStmt * node ) {
1083        VISIT_START( node );
1084        VISIT_END( NullStmt, node );
1085}
1086
1087//--------------------------------------------------------------------------
1088// DeclStmt
1089template< typename core_t >
1090const ast::Stmt * ast::Pass< core_t >::visit( const ast::DeclStmt * node ) {
1091        VISIT_START( node );
1092
1093        if ( __visit_children() ) {
1094                maybe_accept( node, &DeclStmt::decl );
1095        }
1096
1097        VISIT_END( Stmt, node );
1098}
1099
1100//--------------------------------------------------------------------------
1101// ImplicitCtorDtorStmt
1102template< typename core_t >
1103const ast::Stmt * ast::Pass< core_t >::visit( const ast::ImplicitCtorDtorStmt * node ) {
1104        VISIT_START( node );
1105
1106        // For now this isn't visited, it is unclear if this causes problem
1107        // if all tests are known to pass, remove this code
1108        if ( __visit_children() ) {
1109                maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
1110        }
1111
1112        VISIT_END( Stmt, node );
1113}
1114
1115//--------------------------------------------------------------------------
1116// MutexStmt
1117template< typename core_t >
1118const ast::Stmt * ast::Pass< core_t >::visit( const ast::MutexStmt * node ) {
1119        VISIT_START( node );
1120
1121        if ( __visit_children() ) {
1122                // mutex statements introduce a level of scope (for the initialization)
1123                guard_symtab guard { *this };
1124                maybe_accept( node, &MutexStmt::stmt );
1125                maybe_accept( node, &MutexStmt::mutexObjs );
1126        }
1127
1128        VISIT_END( Stmt, node );
1129}
1130
1131//--------------------------------------------------------------------------
1132// ApplicationExpr
1133template< typename core_t >
1134const ast::Expr * ast::Pass< core_t >::visit( const ast::ApplicationExpr * node ) {
1135        VISIT_START( node );
1136
1137        if ( __visit_children() ) {
1138                {
1139                        guard_symtab guard { *this };
1140                        maybe_accept( node, &ApplicationExpr::result );
1141                }
1142                maybe_accept( node, &ApplicationExpr::func );
1143                maybe_accept( node, &ApplicationExpr::args );
1144        }
1145
1146        VISIT_END( Expr, node );
1147}
1148
1149//--------------------------------------------------------------------------
1150// UntypedExpr
1151template< typename core_t >
1152const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedExpr * node ) {
1153        VISIT_START( node );
1154
1155        if ( __visit_children() ) {
1156                {
1157                        guard_symtab guard { *this };
1158                        maybe_accept( node, &UntypedExpr::result );
1159                }
1160
1161                maybe_accept( node, &UntypedExpr::args );
1162        }
1163
1164        VISIT_END( Expr, node );
1165}
1166
1167//--------------------------------------------------------------------------
1168// NameExpr
1169template< typename core_t >
1170const ast::Expr * ast::Pass< core_t >::visit( const ast::NameExpr * node ) {
1171        VISIT_START( node );
1172
1173        if ( __visit_children() ) {
1174                guard_symtab guard { *this };
1175                maybe_accept( node, &NameExpr::result );
1176        }
1177
1178        VISIT_END( Expr, node );
1179}
1180
1181//--------------------------------------------------------------------------
1182// QualifiedNameExpr
1183template< typename core_t >
1184const ast::Expr * ast::Pass< core_t >::visit( const ast::QualifiedNameExpr * node ) {
1185        VISIT_START( node );
1186        if ( __visit_children() ) {
1187                guard_symtab guard { *this };
1188                maybe_accept( node, &QualifiedNameExpr::type_decl );
1189        }
1190        VISIT_END( Expr, node );
1191}
1192
1193//--------------------------------------------------------------------------
1194// CastExpr
1195template< typename core_t >
1196const ast::Expr * ast::Pass< core_t >::visit( const ast::CastExpr * node ) {
1197        VISIT_START( node );
1198
1199        if ( __visit_children() ) {
1200                {
1201                        guard_symtab guard { *this };
1202                        maybe_accept( node, &CastExpr::result );
1203                }
1204                maybe_accept( node, &CastExpr::arg );
1205        }
1206
1207        VISIT_END( Expr, node );
1208}
1209
1210//--------------------------------------------------------------------------
1211// KeywordCastExpr
1212template< typename core_t >
1213const ast::Expr * ast::Pass< core_t >::visit( const ast::KeywordCastExpr * node ) {
1214        VISIT_START( node );
1215
1216        if ( __visit_children() ) {
1217                {
1218                        guard_symtab guard { *this };
1219                        maybe_accept( node, &KeywordCastExpr::result );
1220                }
1221                maybe_accept( node, &KeywordCastExpr::arg );
1222        }
1223
1224        VISIT_END( Expr, node );
1225}
1226
1227//--------------------------------------------------------------------------
1228// VirtualCastExpr
1229template< typename core_t >
1230const ast::Expr * ast::Pass< core_t >::visit( const ast::VirtualCastExpr * node ) {
1231        VISIT_START( node );
1232
1233        if ( __visit_children() ) {
1234                {
1235                        guard_symtab guard { *this };
1236                        maybe_accept( node, &VirtualCastExpr::result );
1237                }
1238                maybe_accept( node, &VirtualCastExpr::arg );
1239        }
1240
1241        VISIT_END( Expr, node );
1242}
1243
1244//--------------------------------------------------------------------------
1245// AddressExpr
1246template< typename core_t >
1247const ast::Expr * ast::Pass< core_t >::visit( const ast::AddressExpr * node ) {
1248        VISIT_START( node );
1249
1250        if ( __visit_children() ) {
1251                {
1252                        guard_symtab guard { *this };
1253                        maybe_accept( node, &AddressExpr::result );
1254                }
1255                maybe_accept( node, &AddressExpr::arg );
1256        }
1257
1258        VISIT_END( Expr, node );
1259}
1260
1261//--------------------------------------------------------------------------
1262// LabelAddressExpr
1263template< typename core_t >
1264const ast::Expr * ast::Pass< core_t >::visit( const ast::LabelAddressExpr * node ) {
1265        VISIT_START( node );
1266
1267        if ( __visit_children() ) {
1268                guard_symtab guard { *this };
1269                maybe_accept( node, &LabelAddressExpr::result );
1270        }
1271
1272        VISIT_END( Expr, node );
1273}
1274
1275//--------------------------------------------------------------------------
1276// UntypedMemberExpr
1277template< typename core_t >
1278const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedMemberExpr * node ) {
1279        VISIT_START( node );
1280
1281        if ( __visit_children() ) {
1282                {
1283                        guard_symtab guard { *this };
1284                        maybe_accept( node, &UntypedMemberExpr::result );
1285                }
1286                maybe_accept( node, &UntypedMemberExpr::aggregate );
1287                maybe_accept( node, &UntypedMemberExpr::member    );
1288        }
1289
1290        VISIT_END( Expr, node );
1291}
1292
1293//--------------------------------------------------------------------------
1294// MemberExpr
1295template< typename core_t >
1296const ast::Expr * ast::Pass< core_t >::visit( const ast::MemberExpr * node ) {
1297        VISIT_START( node );
1298
1299        if ( __visit_children() ) {
1300                {
1301                        guard_symtab guard { *this };
1302                        maybe_accept( node, &MemberExpr::result );
1303                }
1304                maybe_accept( node, &MemberExpr::aggregate );
1305        }
1306
1307        VISIT_END( Expr, node );
1308}
1309
1310//--------------------------------------------------------------------------
1311// VariableExpr
1312template< typename core_t >
1313const ast::Expr * ast::Pass< core_t >::visit( const ast::VariableExpr * node ) {
1314        VISIT_START( node );
1315
1316        if ( __visit_children() ) {
1317                guard_symtab guard { *this };
1318                maybe_accept( node, &VariableExpr::result );
1319        }
1320
1321        VISIT_END( Expr, node );
1322}
1323
1324//--------------------------------------------------------------------------
1325// ConstantExpr
1326template< typename core_t >
1327const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstantExpr * node ) {
1328        VISIT_START( node );
1329
1330        if ( __visit_children() ) {
1331                guard_symtab guard { *this };
1332                maybe_accept( node, &ConstantExpr::result );
1333        }
1334
1335        VISIT_END( Expr, node );
1336}
1337
1338//--------------------------------------------------------------------------
1339// SizeofExpr
1340template< typename core_t >
1341const ast::Expr * ast::Pass< core_t >::visit( const ast::SizeofExpr * node ) {
1342        VISIT_START( node );
1343
1344        if ( __visit_children() ) {
1345                {
1346                        guard_symtab guard { *this };
1347                        maybe_accept( node, &SizeofExpr::result );
1348                }
1349                if ( node->type ) {
1350                        maybe_accept( node, &SizeofExpr::type );
1351                } else {
1352                        maybe_accept( node, &SizeofExpr::expr );
1353                }
1354        }
1355
1356        VISIT_END( Expr, node );
1357}
1358
1359//--------------------------------------------------------------------------
1360// AlignofExpr
1361template< typename core_t >
1362const ast::Expr * ast::Pass< core_t >::visit( const ast::AlignofExpr * node ) {
1363        VISIT_START( node );
1364
1365        if ( __visit_children() ) {
1366                {
1367                        guard_symtab guard { *this };
1368                        maybe_accept( node, &AlignofExpr::result );
1369                }
1370                if ( node->type ) {
1371                        maybe_accept( node, &AlignofExpr::type );
1372                } else {
1373                        maybe_accept( node, &AlignofExpr::expr );
1374                }
1375        }
1376
1377        VISIT_END( Expr, node );
1378}
1379
1380//--------------------------------------------------------------------------
1381// UntypedOffsetofExpr
1382template< typename core_t >
1383const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedOffsetofExpr * node ) {
1384        VISIT_START( node );
1385
1386        if ( __visit_children() ) {
1387                {
1388                        guard_symtab guard { *this };
1389                        maybe_accept( node, &UntypedOffsetofExpr::result );
1390                }
1391                maybe_accept( node, &UntypedOffsetofExpr::type   );
1392        }
1393
1394        VISIT_END( Expr, node );
1395}
1396
1397//--------------------------------------------------------------------------
1398// OffsetofExpr
1399template< typename core_t >
1400const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetofExpr * node ) {
1401        VISIT_START( node );
1402
1403        if ( __visit_children() ) {
1404                {
1405                        guard_symtab guard { *this };
1406                        maybe_accept( node, &OffsetofExpr::result );
1407                }
1408                maybe_accept( node, &OffsetofExpr::type   );
1409        }
1410
1411        VISIT_END( Expr, node );
1412}
1413
1414//--------------------------------------------------------------------------
1415// OffsetPackExpr
1416template< typename core_t >
1417const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetPackExpr * node ) {
1418        VISIT_START( node );
1419
1420        if ( __visit_children() ) {
1421                {
1422                        guard_symtab guard { *this };
1423                        maybe_accept( node, &OffsetPackExpr::result );
1424                }
1425                maybe_accept( node, &OffsetPackExpr::type   );
1426        }
1427
1428        VISIT_END( Expr, node );
1429}
1430
1431//--------------------------------------------------------------------------
1432// LogicalExpr
1433template< typename core_t >
1434const ast::Expr * ast::Pass< core_t >::visit( const ast::LogicalExpr * node ) {
1435        VISIT_START( node );
1436
1437        if ( __visit_children() ) {
1438                {
1439                        guard_symtab guard { *this };
1440                        maybe_accept( node, &LogicalExpr::result );
1441                }
1442                maybe_accept( node, &LogicalExpr::arg1 );
1443                maybe_accept( node, &LogicalExpr::arg2 );
1444        }
1445
1446        VISIT_END( Expr, node );
1447}
1448
1449//--------------------------------------------------------------------------
1450// ConditionalExpr
1451template< typename core_t >
1452const ast::Expr * ast::Pass< core_t >::visit( const ast::ConditionalExpr * node ) {
1453        VISIT_START( node );
1454
1455        if ( __visit_children() ) {
1456                {
1457                        guard_symtab guard { *this };
1458                        maybe_accept( node, &ConditionalExpr::result );
1459                }
1460                maybe_accept( node, &ConditionalExpr::arg1 );
1461                maybe_accept( node, &ConditionalExpr::arg2 );
1462                maybe_accept( node, &ConditionalExpr::arg3 );
1463        }
1464
1465        VISIT_END( Expr, node );
1466}
1467
1468//--------------------------------------------------------------------------
1469// CommaExpr
1470template< typename core_t >
1471const ast::Expr * ast::Pass< core_t >::visit( const ast::CommaExpr * node ) {
1472        VISIT_START( node );
1473
1474        if ( __visit_children() ) {
1475                {
1476                        guard_symtab guard { *this };
1477                        maybe_accept( node, &CommaExpr::result );
1478                }
1479                maybe_accept( node, &CommaExpr::arg1 );
1480                maybe_accept( node, &CommaExpr::arg2 );
1481        }
1482
1483        VISIT_END( Expr, node );
1484}
1485
1486//--------------------------------------------------------------------------
1487// TypeExpr
1488template< typename core_t >
1489const ast::Expr * ast::Pass< core_t >::visit( const ast::TypeExpr * node ) {
1490        VISIT_START( node );
1491
1492        if ( __visit_children() ) {
1493                {
1494                        guard_symtab guard { *this };
1495                        maybe_accept( node, &TypeExpr::result );
1496                }
1497                maybe_accept( node, &TypeExpr::type );
1498        }
1499
1500        VISIT_END( Expr, node );
1501}
1502
1503//--------------------------------------------------------------------------
1504// DimensionExpr
1505template< typename core_t >
1506const ast::Expr * ast::Pass< core_t >::visit( const ast::DimensionExpr * node ) {
1507        VISIT_START( node );
1508
1509        if ( __visit_children() ) {
1510                guard_symtab guard { *this };
1511                maybe_accept( node, &DimensionExpr::result );
1512        }
1513
1514        VISIT_END( Expr, node );
1515}
1516
1517//--------------------------------------------------------------------------
1518// AsmExpr
1519template< typename core_t >
1520const ast::Expr * ast::Pass< core_t >::visit( const ast::AsmExpr * node ) {
1521        VISIT_START( node );
1522
1523        if ( __visit_children() ) {
1524                {
1525                        guard_symtab guard { *this };
1526                        maybe_accept( node, &AsmExpr::result );
1527                }
1528                maybe_accept( node, &AsmExpr::constraint );
1529                maybe_accept( node, &AsmExpr::operand    );
1530        }
1531
1532        VISIT_END( Expr, node );
1533}
1534
1535//--------------------------------------------------------------------------
1536// ImplicitCopyCtorExpr
1537template< typename core_t >
1538const ast::Expr * ast::Pass< core_t >::visit( const ast::ImplicitCopyCtorExpr * node ) {
1539        VISIT_START( node );
1540
1541        if ( __visit_children() ) {
1542                {
1543                        guard_symtab guard { *this };
1544                        maybe_accept( node, &ImplicitCopyCtorExpr::result );
1545                }
1546                maybe_accept( node, &ImplicitCopyCtorExpr::callExpr    );
1547        }
1548
1549        VISIT_END( Expr, node );
1550}
1551
1552//--------------------------------------------------------------------------
1553// ConstructorExpr
1554template< typename core_t >
1555const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstructorExpr * node ) {
1556        VISIT_START( node );
1557
1558        if ( __visit_children() ) {
1559                {
1560                        guard_symtab guard { *this };
1561                        maybe_accept( node, &ConstructorExpr::result );
1562                }
1563                maybe_accept( node, &ConstructorExpr::callExpr );
1564        }
1565
1566        VISIT_END( Expr, node );
1567}
1568
1569//--------------------------------------------------------------------------
1570// CompoundLiteralExpr
1571template< typename core_t >
1572const ast::Expr * ast::Pass< core_t >::visit( const ast::CompoundLiteralExpr * node ) {
1573        VISIT_START( node );
1574
1575        if ( __visit_children() ) {
1576                {
1577                        guard_symtab guard { *this };
1578                        maybe_accept( node, &CompoundLiteralExpr::result );
1579                }
1580                maybe_accept( node, &CompoundLiteralExpr::init );
1581        }
1582
1583        VISIT_END( Expr, node );
1584}
1585
1586//--------------------------------------------------------------------------
1587// RangeExpr
1588template< typename core_t >
1589const ast::Expr * ast::Pass< core_t >::visit( const ast::RangeExpr * node ) {
1590        VISIT_START( node );
1591
1592        if ( __visit_children() ) {
1593                {
1594                        guard_symtab guard { *this };
1595                        maybe_accept( node, &RangeExpr::result );
1596                }
1597                maybe_accept( node, &RangeExpr::low    );
1598                maybe_accept( node, &RangeExpr::high   );
1599        }
1600
1601        VISIT_END( Expr, node );
1602}
1603
1604//--------------------------------------------------------------------------
1605// UntypedTupleExpr
1606template< typename core_t >
1607const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedTupleExpr * node ) {
1608        VISIT_START( node );
1609
1610        if ( __visit_children() ) {
1611                {
1612                        guard_symtab guard { *this };
1613                        maybe_accept( node, &UntypedTupleExpr::result );
1614                }
1615                maybe_accept( node, &UntypedTupleExpr::exprs  );
1616        }
1617
1618        VISIT_END( Expr, node );
1619}
1620
1621//--------------------------------------------------------------------------
1622// TupleExpr
1623template< typename core_t >
1624const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleExpr * node ) {
1625        VISIT_START( node );
1626
1627        if ( __visit_children() ) {
1628                {
1629                        guard_symtab guard { *this };
1630                        maybe_accept( node, &TupleExpr::result );
1631                }
1632                maybe_accept( node, &TupleExpr::exprs  );
1633        }
1634
1635        VISIT_END( Expr, node );
1636}
1637
1638//--------------------------------------------------------------------------
1639// TupleIndexExpr
1640template< typename core_t >
1641const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleIndexExpr * node ) {
1642        VISIT_START( node );
1643
1644        if ( __visit_children() ) {
1645                {
1646                        guard_symtab guard { *this };
1647                        maybe_accept( node, &TupleIndexExpr::result );
1648                }
1649                maybe_accept( node, &TupleIndexExpr::tuple  );
1650        }
1651
1652        VISIT_END( Expr, node );
1653}
1654
1655//--------------------------------------------------------------------------
1656// TupleAssignExpr
1657template< typename core_t >
1658const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleAssignExpr * node ) {
1659        VISIT_START( node );
1660
1661        if ( __visit_children() ) {
1662                {
1663                        guard_symtab guard { *this };
1664                        maybe_accept( node, &TupleAssignExpr::result );
1665                }
1666                maybe_accept( node, &TupleAssignExpr::stmtExpr );
1667        }
1668
1669        VISIT_END( Expr, node );
1670}
1671
1672//--------------------------------------------------------------------------
1673// StmtExpr
1674template< typename core_t >
1675const ast::Expr * ast::Pass< core_t >::visit( const ast::StmtExpr * node ) {
1676        VISIT_START( node );
1677
1678        if ( __visit_children() ) {
1679                // don't want statements from outer CompoundStmts to be added to this StmtExpr
1680                // get the stmts that will need to be spliced in
1681                auto stmts_before = __pass::stmtsToAddBefore( core, 0);
1682                auto stmts_after  = __pass::stmtsToAddAfter ( core, 0);
1683
1684                // These may be modified by subnode but most be restored once we exit this statemnet.
1685                ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::typeSubs( core, 0 ) );
1686                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
1687                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
1688
1689                {
1690                        guard_symtab guard { *this };
1691                        maybe_accept( node, &StmtExpr::result );
1692                }
1693                maybe_accept( node, &StmtExpr::stmts       );
1694                maybe_accept( node, &StmtExpr::returnDecls );
1695                maybe_accept( node, &StmtExpr::dtors       );
1696        }
1697
1698        VISIT_END( Expr, node );
1699}
1700
1701//--------------------------------------------------------------------------
1702// UniqueExpr
1703template< typename core_t >
1704const ast::Expr * ast::Pass< core_t >::visit( const ast::UniqueExpr * node ) {
1705        VISIT_START( node );
1706
1707        if ( __visit_children() ) {
1708                {
1709                        guard_symtab guard { *this };
1710                        maybe_accept( node, &UniqueExpr::result );
1711                }
1712                maybe_accept( node, &UniqueExpr::expr   );
1713        }
1714
1715        VISIT_END( Expr, node );
1716}
1717
1718//--------------------------------------------------------------------------
1719// UntypedInitExpr
1720template< typename core_t >
1721const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedInitExpr * node ) {
1722        VISIT_START( node );
1723
1724        if ( __visit_children() ) {
1725                {
1726                        guard_symtab guard { *this };
1727                        maybe_accept( node, &UntypedInitExpr::result );
1728                }
1729                maybe_accept( node, &UntypedInitExpr::expr   );
1730                // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
1731        }
1732
1733        VISIT_END( Expr, node );
1734}
1735
1736//--------------------------------------------------------------------------
1737// InitExpr
1738template< typename core_t >
1739const ast::Expr * ast::Pass< core_t >::visit( const ast::InitExpr * node ) {
1740        VISIT_START( node );
1741
1742        if ( __visit_children() ) {
1743                {
1744                        guard_symtab guard { *this };
1745                        maybe_accept( node, &InitExpr::result );
1746                }
1747                maybe_accept( node, &InitExpr::expr   );
1748                maybe_accept( node, &InitExpr::designation );
1749        }
1750
1751        VISIT_END( Expr, node );
1752}
1753
1754//--------------------------------------------------------------------------
1755// DeletedExpr
1756template< typename core_t >
1757const ast::Expr * ast::Pass< core_t >::visit( const ast::DeletedExpr * node ) {
1758        VISIT_START( node );
1759
1760        if ( __visit_children() ) {
1761                {
1762                        guard_symtab guard { *this };
1763                        maybe_accept( node, &DeletedExpr::result );
1764                }
1765                maybe_accept( node, &DeletedExpr::expr );
1766                // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
1767        }
1768
1769        VISIT_END( Expr, node );
1770}
1771
1772//--------------------------------------------------------------------------
1773// DefaultArgExpr
1774template< typename core_t >
1775const ast::Expr * ast::Pass< core_t >::visit( const ast::DefaultArgExpr * node ) {
1776        VISIT_START( node );
1777
1778        if ( __visit_children() ) {
1779                {
1780                        guard_symtab guard { *this };
1781                        maybe_accept( node, &DefaultArgExpr::result );
1782                }
1783                maybe_accept( node, &DefaultArgExpr::expr );
1784        }
1785
1786        VISIT_END( Expr, node );
1787}
1788
1789//--------------------------------------------------------------------------
1790// GenericExpr
1791template< typename core_t >
1792const ast::Expr * ast::Pass< core_t >::visit( const ast::GenericExpr * node ) {
1793        VISIT_START( node );
1794
1795        if ( __visit_children() ) {
1796                {
1797                        guard_symtab guard { *this };
1798                        maybe_accept( node, &GenericExpr::result );
1799                }
1800                maybe_accept( node, &GenericExpr::control );
1801
1802                std::vector<GenericExpr::Association> new_kids;
1803                new_kids.reserve(node->associations.size());
1804                bool mutated = false;
1805                for( const auto & assoc : node->associations ) {
1806                        const Type * type = nullptr;
1807                        if( assoc.type ) {
1808                                guard_symtab guard { *this };
1809                                type = assoc.type->accept( *this );
1810                                if( type != assoc.type ) mutated = true;
1811                        }
1812                        const Expr * expr = nullptr;
1813                        if( assoc.expr ) {
1814                                expr = assoc.expr->accept( *this );
1815                                if( expr != assoc.expr ) mutated = true;
1816                        }
1817                        new_kids.emplace_back( type, expr );
1818                }
1819
1820                if(mutated) {
1821                        auto n = __pass::mutate<core_t>(node);
1822                        n->associations = std::move( new_kids );
1823                        node = n;
1824                }
1825        }
1826
1827        VISIT_END( Expr, node );
1828}
1829
1830//--------------------------------------------------------------------------
1831// VoidType
1832template< typename core_t >
1833const ast::Type * ast::Pass< core_t >::visit( const ast::VoidType * node ) {
1834        VISIT_START( node );
1835
1836        VISIT_END( Type, node );
1837}
1838
1839//--------------------------------------------------------------------------
1840// BasicType
1841template< typename core_t >
1842const ast::Type * ast::Pass< core_t >::visit( const ast::BasicType * node ) {
1843        VISIT_START( node );
1844
1845        VISIT_END( Type, node );
1846}
1847
1848//--------------------------------------------------------------------------
1849// PointerType
1850template< typename core_t >
1851const ast::Type * ast::Pass< core_t >::visit( const ast::PointerType * node ) {
1852        VISIT_START( node );
1853
1854        if ( __visit_children() ) {
1855                maybe_accept( node, &PointerType::dimension );
1856                maybe_accept( node, &PointerType::base );
1857        }
1858
1859        VISIT_END( Type, node );
1860}
1861
1862//--------------------------------------------------------------------------
1863// ArrayType
1864template< typename core_t >
1865const ast::Type * ast::Pass< core_t >::visit( const ast::ArrayType * node ) {
1866        VISIT_START( node );
1867
1868        if ( __visit_children() ) {
1869                maybe_accept( node, &ArrayType::dimension );
1870                maybe_accept( node, &ArrayType::base );
1871        }
1872
1873        VISIT_END( Type, node );
1874}
1875
1876//--------------------------------------------------------------------------
1877// ReferenceType
1878template< typename core_t >
1879const ast::Type * ast::Pass< core_t >::visit( const ast::ReferenceType * node ) {
1880        VISIT_START( node );
1881
1882        if ( __visit_children() ) {
1883                maybe_accept( node, &ReferenceType::base );
1884        }
1885
1886        VISIT_END( Type, node );
1887}
1888
1889//--------------------------------------------------------------------------
1890// QualifiedType
1891template< typename core_t >
1892const ast::Type * ast::Pass< core_t >::visit( const ast::QualifiedType * node ) {
1893        VISIT_START( node );
1894
1895        if ( __visit_children() ) {
1896                maybe_accept( node, &QualifiedType::parent );
1897                maybe_accept( node, &QualifiedType::child );
1898        }
1899
1900        VISIT_END( Type, node );
1901}
1902
1903//--------------------------------------------------------------------------
1904// FunctionType
1905template< typename core_t >
1906const ast::Type * ast::Pass< core_t >::visit( const ast::FunctionType * node ) {
1907        VISIT_START( node );
1908
1909        if ( __visit_children() ) {
1910                // guard_forall_subs forall_guard { *this, node };
1911                // mutate_forall( node );
1912                maybe_accept( node, &FunctionType::assertions );
1913                maybe_accept( node, &FunctionType::returns );
1914                maybe_accept( node, &FunctionType::params  );
1915        }
1916
1917        VISIT_END( Type, node );
1918}
1919
1920//--------------------------------------------------------------------------
1921// StructInstType
1922template< typename core_t >
1923const ast::Type * ast::Pass< core_t >::visit( const ast::StructInstType * node ) {
1924        VISIT_START( node );
1925
1926        __pass::symtab::addStruct( core, 0, node->name );
1927
1928        if ( __visit_children() ) {
1929                guard_symtab guard { *this };
1930                maybe_accept( node, &StructInstType::params );
1931        }
1932
1933        VISIT_END( Type, node );
1934}
1935
1936//--------------------------------------------------------------------------
1937// UnionInstType
1938template< typename core_t >
1939const ast::Type * ast::Pass< core_t >::visit( const ast::UnionInstType * node ) {
1940        VISIT_START( node );
1941
1942        __pass::symtab::addUnion( core, 0, node->name );
1943
1944        if ( __visit_children() ) {
1945                guard_symtab guard { *this };
1946                maybe_accept( node, &UnionInstType::params );
1947        }
1948
1949        VISIT_END( Type, node );
1950}
1951
1952//--------------------------------------------------------------------------
1953// EnumInstType
1954template< typename core_t >
1955const ast::Type * ast::Pass< core_t >::visit( const ast::EnumInstType * node ) {
1956        VISIT_START( node );
1957
1958        if ( __visit_children() ) {
1959                maybe_accept( node, &EnumInstType::params );
1960        }
1961
1962        VISIT_END( Type, node );
1963}
1964
1965//--------------------------------------------------------------------------
1966// TraitInstType
1967template< typename core_t >
1968const ast::Type * ast::Pass< core_t >::visit( const ast::TraitInstType * node ) {
1969        VISIT_START( node );
1970
1971        if ( __visit_children() ) {
1972                maybe_accept( node, &TraitInstType::params );
1973        }
1974
1975        VISIT_END( Type, node );
1976}
1977
1978//--------------------------------------------------------------------------
1979// TypeInstType
1980template< typename core_t >
1981const ast::Type * ast::Pass< core_t >::visit( const ast::TypeInstType * node ) {
1982        VISIT_START( node );
1983
1984        if ( __visit_children() ) {
1985                {
1986                        maybe_accept( node, &TypeInstType::params );
1987                }
1988                // ensure that base re-bound if doing substitution
1989                __pass::forall::replace( core, 0, node );
1990        }
1991
1992        VISIT_END( Type, node );
1993}
1994
1995//--------------------------------------------------------------------------
1996// TupleType
1997template< typename core_t >
1998const ast::Type * ast::Pass< core_t >::visit( const ast::TupleType * node ) {
1999        VISIT_START( node );
2000
2001        if ( __visit_children() ) {
2002                maybe_accept( node, &TupleType::types );
2003        }
2004
2005        VISIT_END( Type, node );
2006}
2007
2008//--------------------------------------------------------------------------
2009// TypeofType
2010template< typename core_t >
2011const ast::Type * ast::Pass< core_t >::visit( const ast::TypeofType * node ) {
2012        VISIT_START( node );
2013
2014        if ( __visit_children() ) {
2015                maybe_accept( node, &TypeofType::expr );
2016        }
2017
2018        VISIT_END( Type, node );
2019}
2020
2021//--------------------------------------------------------------------------
2022// VTableType
2023template< typename core_t >
2024const ast::Type * ast::Pass< core_t >::visit( const ast::VTableType * node ) {
2025        VISIT_START( node );
2026
2027        if ( __visit_children() ) {
2028                maybe_accept( node, &VTableType::base );
2029        }
2030
2031        VISIT_END( Type, node );
2032}
2033
2034//--------------------------------------------------------------------------
2035// VarArgsType
2036template< typename core_t >
2037const ast::Type * ast::Pass< core_t >::visit( const ast::VarArgsType * node ) {
2038        VISIT_START( node );
2039
2040        VISIT_END( Type, node );
2041}
2042
2043//--------------------------------------------------------------------------
2044// ZeroType
2045template< typename core_t >
2046const ast::Type * ast::Pass< core_t >::visit( const ast::ZeroType * node ) {
2047        VISIT_START( node );
2048
2049        VISIT_END( Type, node );
2050}
2051
2052//--------------------------------------------------------------------------
2053// OneType
2054template< typename core_t >
2055const ast::Type * ast::Pass< core_t >::visit( const ast::OneType * node ) {
2056        VISIT_START( node );
2057
2058        VISIT_END( Type, node );
2059}
2060
2061//--------------------------------------------------------------------------
2062// GlobalScopeType
2063template< typename core_t >
2064const ast::Type * ast::Pass< core_t >::visit( const ast::GlobalScopeType * node ) {
2065        VISIT_START( node );
2066
2067        VISIT_END( Type, node );
2068}
2069
2070
2071//--------------------------------------------------------------------------
2072// Designation
2073template< typename core_t >
2074const ast::Designation * ast::Pass< core_t >::visit( const ast::Designation * node ) {
2075        VISIT_START( node );
2076
2077        if ( __visit_children() ) {
2078                maybe_accept( node, &Designation::designators );
2079        }
2080
2081        VISIT_END( Designation, node );
2082}
2083
2084//--------------------------------------------------------------------------
2085// SingleInit
2086template< typename core_t >
2087const ast::Init * ast::Pass< core_t >::visit( const ast::SingleInit * node ) {
2088        VISIT_START( node );
2089
2090        if ( __visit_children() ) {
2091                maybe_accept_top( node, &SingleInit::value );
2092        }
2093
2094        VISIT_END( Init, node );
2095}
2096
2097//--------------------------------------------------------------------------
2098// ListInit
2099template< typename core_t >
2100const ast::Init * ast::Pass< core_t >::visit( const ast::ListInit * node ) {
2101        VISIT_START( node );
2102
2103        if ( __visit_children() ) {
2104                maybe_accept( node, &ListInit::designations );
2105                maybe_accept( node, &ListInit::initializers );
2106        }
2107
2108        VISIT_END( Init, node );
2109}
2110
2111//--------------------------------------------------------------------------
2112// ConstructorInit
2113template< typename core_t >
2114const ast::Init * ast::Pass< core_t >::visit( const ast::ConstructorInit * node ) {
2115        VISIT_START( node );
2116
2117        if ( __visit_children() ) {
2118                maybe_accept( node, &ConstructorInit::ctor );
2119                maybe_accept( node, &ConstructorInit::dtor );
2120                maybe_accept( node, &ConstructorInit::init );
2121        }
2122
2123        VISIT_END( Init, node );
2124}
2125
2126//--------------------------------------------------------------------------
2127// Attribute
2128template< typename core_t >
2129const ast::Attribute * ast::Pass< core_t >::visit( const ast::Attribute * node  )  {
2130        VISIT_START( node );
2131
2132        if ( __visit_children() ) {
2133                maybe_accept( node, &Attribute::params );
2134        }
2135
2136        VISIT_END( Attribute, node );
2137}
2138
2139//--------------------------------------------------------------------------
2140// TypeSubstitution
2141template< typename core_t >
2142const ast::TypeSubstitution * ast::Pass< core_t >::visit( const ast::TypeSubstitution * node ) {
2143        VISIT_START( node );
2144
2145        if ( __visit_children() ) {
2146                bool mutated = false;
2147                ast::TypeSubstitution::TypeMap new_map;
2148                for ( const auto & p : node->typeMap ) {
2149                        guard_symtab guard { *this };
2150                        auto new_node = p.second->accept( *this );
2151                        if (new_node != p.second) mutated = true;
2152                        new_map.insert({ p.first, new_node });
2153                }
2154                if (mutated) {
2155                        auto new_node = __pass::mutate<core_t>( node );
2156                        new_node->typeMap.swap( new_map );
2157                        node = new_node;
2158                }
2159        }
2160
2161        VISIT_END( TypeSubstitution, node );
2162}
2163
2164#undef __pedantic_pass_assertf
2165#undef __pedantic_pass_assert
2166#undef VISIT_START
2167#undef VISIT_END
Note: See TracBrowser for help on using the repository browser.