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

Last change on this file since f2898df was 59c8dff, checked in by JiadaL <j82liang@…>, 20 months ago

Draft Implementation for enum position pesudo function (posE). EnumPosExpr is mostly irrelevant for now. It is used in development/code probing and will be removed later

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