source: src/AST/Pass.impl.hpp @ 2377ca2

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

Updated some names on mutate functions to me more consistent with some 'better' names we came up with more recently.

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