source: src/AST/Pass.impl.hpp @ b0be3713

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since b0be3713 was 6739590, checked in by Andrew Beach <ajbeach@…>, 2 years ago

A small spacing fix.

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