source: src/AST/Pass.impl.hpp @ 9cc3a18

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9cc3a18 was 2d019af, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

parser global pragmas, fixes #241

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