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

Last change on this file since a750c71b was 36dfdac, checked in by Michael Brooks <mlbrooks@…>, 9 months ago

Enable partial autogen for types declared inside functions.

Done by giving pass cores finer grained error-recovery points, which causes Resolver's existing error-recovery logic to kick in for autogens within function bodies.

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