source: src/AST/Pass.impl.hpp@ 45444c3

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 45444c3 was c6c682cf, checked in by Andrew Beach <ajbeach@…>, 5 years ago

This should make the value of Pass[Visitor]::inFunction match the expected value.

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