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

ast-experimental
Last change on this file since bccd70a was bccd70a, checked in by Andrew Beach <ajbeach@…>, 13 months ago

Removed internal code from TypeSubstitution? header. It caused a chain of include problems, which have been corrected.

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