source: src/AST/Pass.impl.hpp@ 7e1cb79

ADT ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 7e1cb79 was 798a8b3, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Attributes are now correctly visited when replacing typedefs

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