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

ADTast-experimentalpthread-emulation
Last change on this file since 4962741 was e8616b6, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Changed the default Linkage on ast::ObjectDecl? from C to Cforall. There appears to be only one internal name that actually needed to be C.

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