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

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since d5631b3 was 954c954, checked in by Fangren Yu <f37yu@…>, 5 years ago

Move function argument and return variable declarations from FunctionType to FunctionDecl

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