source: src/AST/Pass.impl.hpp@ 451d958

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since 451d958 was c600df1, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Added ast::WithConstTranslationUnit to give access to the surrounding TranslationUnit.

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