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

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since be5e34b was 293dc1c, checked in by Andrew Beach <ajbeach@…>, 4 years ago

TranslationUnit? is now used at the top-level of the new-ast passes.

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