source: src/Common/PassVisitor.impl.h@ effe5b0

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since effe5b0 was 342146e1, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Old pass visitor no longer leaks macros

  • Property mode set to 100644
File size: 79.0 KB
Line 
1#pragma once
2// IWYU pragma: private, include "PassVisitor.h"
3
4#define VISIT_START( node ) \
5 __attribute__((unused)) \
6 ChildrenGuard children_guard( get_visit_children_ptr() ); \
7 __attribute__((unused)) \
8 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \
9 call_previsit( node ); \
10
11#define VISIT_END( node ) \
12 call_postvisit( node ); \
13
14#define MUTATE_START( node ) \
15 __attribute__((unused)) \
16 ChildrenGuard children_guard( get_visit_children_ptr() ); \
17 __attribute__((unused)) \
18 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \
19 call_premutate( node ); \
20
21#define MUTATE_END( type, node ) \
22 auto __return = call_postmutate< type * >( node ); \
23 assert( __return ); \
24 return __return;
25
26
27template<typename T>
28static inline bool empty( T * ptr ) {
29 return !ptr || ptr->empty();
30}
31
32typedef std::list< Statement * > StmtList_t;
33typedef std::list< Declaration * > DeclList_t;
34
35template<typename iterator_t>
36static inline void splice( iterator_t it, DeclList_t * decls ) {
37 std::transform(
38 decls->begin(),
39 decls->end(),
40 it,
41 [](Declaration * decl) -> auto {
42 return new DeclStmt( decl );
43 }
44 );
45 decls->clear();
46}
47
48template< typename pass_type >
49inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {
50 DeclList_t* beforeDecls = visitor.get_beforeDecls();
51 DeclList_t* afterDecls = visitor.get_afterDecls();
52 SemanticErrorException errors;
53
54 pass_visitor_stats.depth++;
55 pass_visitor_stats.max->push(pass_visitor_stats.depth);
56 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
57 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
58
59
60 // splice in new declarations after previous decl
61 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
62
63 if ( i == decls.end() ) break;
64
65 try {
66 // run visitor on declaration
67 maybeAccept_impl( *i, visitor );
68 } catch( SemanticErrorException &e ) {
69 errors.append( e );
70 }
71
72 // splice in new declarations before current decl
73 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
74 }
75 pass_visitor_stats.depth--;
76 if ( ! errors.isEmpty() ) {
77 throw errors;
78 }
79}
80
81template< typename pass_type >
82inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
83 DeclList_t* beforeDecls = mutator.get_beforeDecls();
84 DeclList_t* afterDecls = mutator.get_afterDecls();
85 SemanticErrorException errors;
86
87 pass_visitor_stats.depth++;
88 pass_visitor_stats.max->push(pass_visitor_stats.depth);
89 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
90 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
91 // splice in new declarations after previous decl
92 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
93
94 if ( i == decls.end() ) break;
95 try {
96 // run mutator on declaration
97 maybeMutate_impl( *i, mutator );
98 } catch( SemanticErrorException &e ) {
99 errors.append( e );
100 }
101
102 // splice in new declarations before current decl
103 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
104 }
105 pass_visitor_stats.depth--;
106 if ( ! errors.isEmpty() ) {
107 throw errors;
108 }
109}
110
111template< typename TreeType, typename pass_type >
112inline void maybeAccept_impl( TreeType * tree, PassVisitor< pass_type > & visitor ) {
113 if ( ! visitor.get_visit_children() ) return;
114 if ( tree ) {
115 tree->accept( visitor );
116 }
117}
118
119template< typename Container, typename pass_type >
120inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) {
121 if ( ! visitor.get_visit_children() ) return;
122 SemanticErrorException errors;
123
124 pass_visitor_stats.depth++;
125 pass_visitor_stats.max->push(pass_visitor_stats.depth);
126 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
127 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
128 try {
129 if ( *i ) {
130 (*i)->accept( visitor );
131 }
132 } catch( SemanticErrorException &e ) {
133 errors.append( e );
134 }
135 }
136 pass_visitor_stats.depth--;
137 if ( ! errors.isEmpty() ) {
138 throw errors;
139 }
140}
141
142template< typename TreeType, typename pass_type >
143inline void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_type > & mutator ) {
144 if ( ! mutator.get_visit_children() ) return;
145
146 if ( tree ) {
147 tree = strict_dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) );
148 }
149}
150
151template< typename Container, typename pass_type >
152inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
153
154 if ( ! mutator.get_visit_children() ) return;
155 SemanticErrorException errors;
156
157 pass_visitor_stats.depth++;
158 pass_visitor_stats.max->push(pass_visitor_stats.depth);
159 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
160 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
161 try {
162 if ( *i ) {
163 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
164 assert( *i );
165 } // if
166 } catch( SemanticErrorException &e ) {
167 errors.append( e );
168 } // try
169 } // for
170 pass_visitor_stats.depth--;
171 if ( ! errors.isEmpty() ) {
172 throw errors;
173 } // if
174}
175
176template< typename pass_type >
177template< typename func_t >
178void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
179 if ( ! get_visit_children() ) return;
180 SemanticErrorException errors;
181
182 // don't want statements from outer CompoundStmts to be added to this CompoundStmt
183 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() );
184 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () );
185 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() );
186 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () );
187
188 StmtList_t* beforeStmts = get_beforeStmts();
189 StmtList_t* afterStmts = get_afterStmts();
190 DeclList_t* beforeDecls = get_beforeDecls();
191 DeclList_t* afterDecls = get_afterDecls();
192
193 pass_visitor_stats.depth++;
194 pass_visitor_stats.max->push(pass_visitor_stats.depth);
195 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
196 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
197
198 if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); }
199 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
200
201 try {
202 func( *i );
203 assert( *i );
204 assert(( empty( beforeStmts ) && empty( afterStmts ))
205 || ( empty( beforeDecls ) && empty( afterDecls )) );
206
207 } catch ( SemanticErrorException &e ) {
208 errors.append( e );
209 }
210
211 if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); }
212 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
213 }
214 pass_visitor_stats.depth--;
215
216 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
217 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
218 if ( !errors.isEmpty() ) { throw errors; }
219}
220
221template< typename pass_type >
222void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
223 handleStatementList( statements, [this]( Statement * stmt) {
224 maybeAccept_impl( stmt, *this );
225 });
226}
227
228template< typename pass_type >
229void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
230 handleStatementList( statements, [this]( Statement *& stmt) {
231 maybeMutate_impl( stmt, *this );
232 });
233}
234
235
236template< typename pass_type >
237template< typename func_t >
238Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) {
239 if ( ! get_visit_children() ) return stmt;
240
241 // don't want statements from outer CompoundStmts to be added to this CompoundStmt
242 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
243 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() );
244 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () );
245 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() );
246 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () );
247
248 Statement *newStmt = func( stmt );
249
250 StmtList_t* beforeStmts = get_beforeStmts();
251 StmtList_t* afterStmts = get_afterStmts();
252 DeclList_t* beforeDecls = get_beforeDecls();
253 DeclList_t* afterDecls = get_afterDecls();
254
255 if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; }
256 assert(( empty( beforeStmts ) && empty( afterStmts ))
257 || ( empty( beforeDecls ) && empty( afterDecls )) );
258
259 CompoundStmt *compound = new CompoundStmt();
260 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); }
261 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
262 compound->get_kids().push_back( newStmt );
263 if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); }
264 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
265 return compound;
266}
267
268template< typename pass_type >
269Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
270 return handleStatement( stmt, [this]( Statement * stmt ) {
271 maybeAccept_impl( stmt, *this );
272 return stmt;
273 });
274}
275
276template< typename pass_type >
277Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
278 return handleStatement( stmt, [this]( Statement * stmt ) {
279 maybeMutate_impl( stmt, *this );
280 return stmt;
281 });
282}
283
284template< typename pass_type >
285template< typename func_t >
286Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) {
287 if ( ! get_visit_children() ) return expr;
288 if( !expr ) return nullptr;
289
290 auto env_ptr = get_env_ptr();
291 if ( env_ptr && expr->get_env() ) {
292 *env_ptr = expr->get_env();
293 }
294
295 // should env be moved onto the result of the mutate?
296 return func( expr );
297}
298
299template< typename pass_type >
300Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) {
301 return handleExpression(expr, [this]( Expression * expr ) {
302 maybeAccept_impl( expr, *this );
303 return expr;
304 });
305}
306
307template< typename pass_type >
308Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
309 return handleExpression(expr, [this]( Expression * expr ) {
310 maybeMutate_impl( expr, *this );
311 return expr;
312 });
313}
314
315template< typename TreeType, typename VisitorType >
316inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) {
317 if ( ! visitor.get_visit_children() ) return;
318 auto guard = makeFuncGuard(
319 [&visitor]() { visitor.indexerScopeEnter(); },
320 [&visitor]() { visitor.indexerScopeLeave(); }
321 );
322 maybeAccept_impl( tree, visitor );
323}
324
325template< typename TreeType, typename MutatorType >
326inline void indexerScopedMutate( TreeType *& tree, MutatorType & mutator ) {
327 if ( ! mutator.get_visit_children() ) return;
328 auto guard = makeFuncGuard(
329 [&mutator]() { mutator.indexerScopeEnter(); },
330 [&mutator]() { mutator.indexerScopeLeave(); }
331 );
332 maybeMutate_impl( tree, mutator );
333}
334
335//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
336//========================================================================================================================================================================
337//========================================================================================================================================================================
338//========================================================================================================================================================================
339//========================================================================================================================================================================
340//========================================================================================================================================================================
341//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
342
343// A NOTE ON THE ORDER OF TRAVERSAL
344//
345// Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is
346// no such thing as a recursive type or typedef.
347//
348// typedef struct { T *x; } T; // never allowed
349//
350// for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the
351// members are traversed, and then the complete type should be added (assuming the type is completed by this particular
352// declaration).
353//
354// struct T { struct T *x; }; // allowed
355//
356// It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that
357// traversal may modify the definition of the type and these modifications should be visible when the symbol table is
358// queried later in this pass.
359//
360// TODO: figure out whether recursive contexts are sensible/possible/reasonable.
361
362//--------------------------------------------------------------------------
363// ObjectDecl
364template< typename pass_type >
365void PassVisitor< pass_type >::visit( ObjectDecl * node ) {
366 VISIT_START( node );
367
368 indexerScopedAccept( node->type , *this );
369 maybeAccept_impl ( node->init , *this );
370 maybeAccept_impl ( node->bitfieldWidth, *this );
371 maybeAccept_impl ( node->attributes , *this );
372
373 indexerAddId( node );
374
375 VISIT_END( node );
376}
377
378template< typename pass_type >
379DeclarationWithType * PassVisitor< pass_type >::mutate( ObjectDecl * node ) {
380 MUTATE_START( node );
381
382 indexerScopedMutate( node->type , *this );
383 maybeMutate_impl ( node->init , *this );
384 maybeMutate_impl ( node->bitfieldWidth, *this );
385 maybeMutate_impl ( node->attributes , *this );
386
387 indexerAddId( node );
388
389 MUTATE_END( DeclarationWithType, node );
390}
391
392//--------------------------------------------------------------------------
393// FunctionDecl
394template< typename pass_type >
395void PassVisitor< pass_type >::visit( FunctionDecl * node ) {
396 VISIT_START( node );
397
398 indexerAddId( node );
399
400 maybeAccept_impl( node->withExprs, *this );
401 {
402 // with clause introduces a level of scope (for the with expression members).
403 // with clause exprs are added to the indexer before parameters so that parameters
404 // shadow with exprs and not the other way around.
405 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
406 indexerAddWith( node->withExprs, node );
407 {
408 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
409 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
410 static ObjectDecl func(
411 "__func__", noStorageClasses, LinkageSpec::C, nullptr,
412 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
413 nullptr
414 );
415 indexerAddId( &func );
416 maybeAccept_impl( node->type, *this );
417 // function body needs to have the same scope as parameters - CompoundStmt will not enter
418 // a new scope if inFunction is true
419 ValueGuard< bool > oldInFunction( inFunction );
420 inFunction = true;
421 maybeAccept_impl( node->statements, *this );
422 maybeAccept_impl( node->attributes, *this );
423 }
424 }
425
426 VISIT_END( node );
427}
428
429template< typename pass_type >
430DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) {
431 MUTATE_START( node );
432
433 indexerAddId( node );
434
435 {
436 // with clause introduces a level of scope (for the with expression members).
437 // with clause exprs are added to the indexer before parameters so that parameters
438 // shadow with exprs and not the other way around.
439 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
440 indexerAddWith( node->withExprs, node );
441 {
442 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
443 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
444 static ObjectDecl func(
445 "__func__", noStorageClasses, LinkageSpec::C, nullptr,
446 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
447 nullptr
448 );
449 indexerAddId( &func );
450 maybeMutate_impl( node->type, *this );
451 // function body needs to have the same scope as parameters - CompoundStmt will not enter
452 // a new scope if inFunction is true
453 ValueGuard< bool > oldInFunction( inFunction );
454 inFunction = true;
455 maybeMutate_impl( node->statements, *this );
456 maybeMutate_impl( node->attributes, *this );
457 }
458 }
459
460 MUTATE_END( DeclarationWithType, node );
461}
462
463//--------------------------------------------------------------------------
464// StructDecl
465template< typename pass_type >
466void PassVisitor< pass_type >::visit( StructDecl * node ) {
467 VISIT_START( node );
468
469 // make up a forward declaration and add it before processing the members
470 // needs to be on the heap because addStruct saves the pointer
471 indexerAddStructFwd( node );
472
473 {
474 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
475 maybeAccept_impl( node->parameters, *this );
476 maybeAccept_impl( node->members , *this );
477 }
478
479 // this addition replaces the forward declaration
480 indexerAddStruct( node );
481
482 VISIT_END( node );
483}
484
485template< typename pass_type >
486Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) {
487 MUTATE_START( node );
488
489 // make up a forward declaration and add it before processing the members
490 // needs to be on the heap because addStruct saves the pointer
491 indexerAddStructFwd( node );
492
493 {
494 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
495 maybeMutate_impl( node->parameters, *this );
496 maybeMutate_impl( node->members , *this );
497 }
498
499 // this addition replaces the forward declaration
500 indexerAddStruct( node );
501
502 MUTATE_END( Declaration, node );
503}
504
505//--------------------------------------------------------------------------
506// UnionDecl
507template< typename pass_type >
508void PassVisitor< pass_type >::visit( UnionDecl * node ) {
509 VISIT_START( node );
510
511 // make up a forward declaration and add it before processing the members
512 indexerAddUnionFwd( node );
513
514 {
515 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
516 maybeAccept_impl( node->parameters, *this );
517 maybeAccept_impl( node->members , *this );
518 }
519
520 indexerAddUnion( node );
521
522 VISIT_END( node );
523}
524
525template< typename pass_type >
526Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) {
527 MUTATE_START( node );
528
529 // make up a forward declaration and add it before processing the members
530 indexerAddUnionFwd( node );
531
532 {
533 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
534 maybeMutate_impl( node->parameters, *this );
535 maybeMutate_impl( node->members , *this );
536 }
537
538 indexerAddUnion( node );
539
540 MUTATE_END( Declaration, node );
541}
542
543//--------------------------------------------------------------------------
544// EnumDecl
545template< typename pass_type >
546void PassVisitor< pass_type >::visit( EnumDecl * node ) {
547 VISIT_START( node );
548
549 indexerAddEnum( node );
550
551 // unlike structs, traits, and unions, enums inject their members into the global scope
552 maybeAccept_impl( node->parameters, *this );
553 maybeAccept_impl( node->members , *this );
554
555 VISIT_END( node );
556}
557
558template< typename pass_type >
559Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) {
560 MUTATE_START( node );
561
562 indexerAddEnum( node );
563
564 // unlike structs, traits, and unions, enums inject their members into the global scope
565 maybeMutate_impl( node->parameters, *this );
566 maybeMutate_impl( node->members , *this );
567
568 MUTATE_END( Declaration, node );
569}
570
571//--------------------------------------------------------------------------
572// TraitDecl
573template< typename pass_type >
574void PassVisitor< pass_type >::visit( TraitDecl * node ) {
575 VISIT_START( node );
576
577 {
578 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
579 maybeAccept_impl( node->parameters, *this );
580 maybeAccept_impl( node->members , *this );
581 }
582
583 indexerAddTrait( node );
584
585 VISIT_END( node );
586}
587
588template< typename pass_type >
589Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) {
590 MUTATE_START( node );
591
592 {
593 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
594 maybeMutate_impl( node->parameters, *this );
595 maybeMutate_impl( node->members , *this );
596 }
597
598 indexerAddTrait( node );
599
600 MUTATE_END( Declaration, node );
601}
602
603//--------------------------------------------------------------------------
604// TypeDecl
605template< typename pass_type >
606void PassVisitor< pass_type >::visit( TypeDecl * node ) {
607 VISIT_START( node );
608
609 {
610 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
611 maybeAccept_impl( node->parameters, *this );
612 maybeAccept_impl( node->base , *this );
613 }
614
615 // see A NOTE ON THE ORDER OF TRAVERSAL, above
616 // note that assertions come after the type is added to the symtab, since they are not part of the type proper
617 // and may depend on the type itself
618 indexerAddType( node );
619
620 maybeAccept_impl( node->assertions, *this );
621
622 indexerScopedAccept( node->init, *this );
623
624 VISIT_END( node );
625}
626
627template< typename pass_type >
628Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
629 MUTATE_START( node );
630
631 {
632 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
633 maybeMutate_impl( node->parameters, *this );
634 maybeMutate_impl( node->base , *this );
635 }
636
637 // see A NOTE ON THE ORDER OF TRAVERSAL, above
638 // note that assertions come after the type is added to the symtab, since they are not part of the type proper
639 // and may depend on the type itself
640 indexerAddType( node );
641
642 maybeMutate_impl( node->assertions, *this );
643
644 indexerScopedMutate( node->init, *this );
645
646 MUTATE_END( Declaration, node );
647}
648
649//--------------------------------------------------------------------------
650// TypedefDecl
651template< typename pass_type >
652void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
653 VISIT_START( node );
654
655 {
656 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
657 maybeAccept_impl( node->parameters, *this );
658 maybeAccept_impl( node->base , *this );
659 }
660
661 indexerAddType( node );
662
663 maybeAccept_impl( node->assertions, *this );
664
665 VISIT_END( node );
666}
667
668template< typename pass_type >
669Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) {
670 MUTATE_START( node );
671
672 {
673 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
674 maybeMutate_impl( node->parameters, *this );
675 maybeMutate_impl( node->base , *this );
676 }
677
678 indexerAddType( node );
679
680 maybeMutate_impl( node->assertions, *this );
681
682 MUTATE_END( Declaration, node );
683}
684
685//--------------------------------------------------------------------------
686// AsmDecl
687template< typename pass_type >
688void PassVisitor< pass_type >::visit( AsmDecl * node ) {
689 VISIT_START( node );
690
691 maybeAccept_impl( node->stmt, *this );
692
693 VISIT_END( node );
694}
695
696template< typename pass_type >
697AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) {
698 MUTATE_START( node );
699
700 maybeMutate_impl( node->stmt, *this );
701
702 MUTATE_END( AsmDecl, node );
703}
704
705//--------------------------------------------------------------------------
706// StaticAssertDecl
707template< typename pass_type >
708void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) {
709 VISIT_START( node );
710
711 node->condition = visitExpression( node->condition );
712 maybeAccept_impl( node->message, *this );
713
714 VISIT_END( node );
715}
716
717template< typename pass_type >
718StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
719 MUTATE_START( node );
720
721 node->condition = mutateExpression( node->condition );
722 maybeMutate_impl( node->message, *this );
723
724 MUTATE_END( StaticAssertDecl, node );
725}
726
727//--------------------------------------------------------------------------
728// CompoundStmt
729template< typename pass_type >
730void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
731 VISIT_START( node );
732 {
733 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
734 ValueGuard< bool > oldInFunction( inFunction );
735 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
736 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } );
737 inFunction = false;
738 visitStatementList( node->kids );
739 }
740 VISIT_END( node );
741}
742
743template< typename pass_type >
744CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
745 MUTATE_START( node );
746 {
747 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
748 ValueGuard< bool > oldInFunction( inFunction );
749 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
750 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } );
751 inFunction = false;
752 mutateStatementList( node->kids );
753 }
754 MUTATE_END( CompoundStmt, node );
755}
756
757//--------------------------------------------------------------------------
758// ExprStmt
759template< typename pass_type >
760void PassVisitor< pass_type >::visit( ExprStmt * node ) {
761 VISIT_START( node );
762
763 visitExpression( node->expr );
764
765 VISIT_END( node );
766}
767
768template< typename pass_type >
769Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
770 MUTATE_START( node );
771
772 node->expr = mutateExpression( node->expr );
773
774 MUTATE_END( Statement, node );
775}
776
777//--------------------------------------------------------------------------
778// AsmStmt
779template< typename pass_type >
780void PassVisitor< pass_type >::visit( AsmStmt * node ) {
781 VISIT_START( node )
782
783 maybeAccept_impl( node->instruction, *this );
784 maybeAccept_impl( node->output, *this );
785 maybeAccept_impl( node->input, *this );
786 maybeAccept_impl( node->clobber, *this );
787
788 VISIT_END( node );
789}
790
791template< typename pass_type >
792Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
793 MUTATE_START( node );
794
795 maybeMutate_impl( node->instruction, *this );
796 maybeMutate_impl( node->output, *this );
797 maybeMutate_impl( node->input, *this );
798 maybeMutate_impl( node->clobber, *this );
799
800 MUTATE_END( Statement, node );
801}
802
803//--------------------------------------------------------------------------
804// AsmStmt
805template< typename pass_type >
806void PassVisitor< pass_type >::visit( DirectiveStmt * node ) {
807 VISIT_START( node )
808
809 VISIT_END( node );
810}
811
812template< typename pass_type >
813Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
814 MUTATE_START( node );
815
816 MUTATE_END( Statement, node );
817}
818
819//--------------------------------------------------------------------------
820// IfStmt
821template< typename pass_type >
822void PassVisitor< pass_type >::visit( IfStmt * node ) {
823 VISIT_START( node );
824 {
825 // if statements introduce a level of scope (for the initialization)
826 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
827 maybeAccept_impl( node->get_initialization(), *this );
828 visitExpression ( node->condition );
829 node->thenPart = visitStatement( node->thenPart );
830 node->elsePart = visitStatement( node->elsePart );
831 }
832 VISIT_END( node );
833}
834
835template< typename pass_type >
836Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
837 MUTATE_START( node );
838 {
839 // if statements introduce a level of scope (for the initialization)
840 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
841 maybeMutate_impl( node->get_initialization(), *this );
842 node->condition = mutateExpression( node->condition );
843 node->thenPart = mutateStatement ( node->thenPart );
844 node->elsePart = mutateStatement ( node->elsePart );
845 }
846 MUTATE_END( Statement, node );
847}
848
849//--------------------------------------------------------------------------
850// WhileStmt
851template< typename pass_type >
852void PassVisitor< pass_type >::visit( WhileStmt * node ) {
853 VISIT_START( node );
854
855 {
856 // while statements introduce a level of scope (for the initialization)
857 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
858 maybeAccept_impl( node->initialization, *this );
859 visitExpression ( node->condition );
860 node->body = visitStatement( node->body );
861 }
862
863 VISIT_END( node );
864}
865
866template< typename pass_type >
867Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
868 MUTATE_START( node );
869
870 {
871 // while statements introduce a level of scope (for the initialization)
872 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
873 maybeMutate_impl( node->initialization, *this );
874 node->condition = mutateExpression( node->condition );
875 node->body = mutateStatement ( node->body );
876 }
877
878
879 MUTATE_END( Statement, node );
880}
881
882//--------------------------------------------------------------------------
883// ForStmt
884template< typename pass_type >
885void PassVisitor< pass_type >::visit( ForStmt * node ) {
886 VISIT_START( node );
887 {
888 // for statements introduce a level of scope (for the initialization)
889 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
890 maybeAccept_impl( node->initialization, *this );
891 visitExpression( node->condition );
892 visitExpression( node->increment );
893 node->body = visitStatement( node->body );
894 }
895 VISIT_END( node );
896}
897
898template< typename pass_type >
899Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
900 MUTATE_START( node );
901 {
902 // for statements introduce a level of scope (for the initialization)
903 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
904 maybeMutate_impl( node->initialization, *this );
905 node->condition = mutateExpression( node->condition );
906 node->increment = mutateExpression( node->increment );
907 node->body = mutateStatement ( node->body );
908 }
909 MUTATE_END( Statement, node );
910}
911
912//--------------------------------------------------------------------------
913// SwitchStmt
914template< typename pass_type >
915void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
916 VISIT_START( node );
917
918 visitExpression ( node->condition );
919 visitStatementList( node->statements );
920
921 VISIT_END( node );
922}
923
924template< typename pass_type >
925Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
926 MUTATE_START( node );
927
928 node->condition = mutateExpression( node->condition );
929 mutateStatementList( node->statements );
930
931 MUTATE_END( Statement, node );
932}
933
934//--------------------------------------------------------------------------
935// CaseStmt
936template< typename pass_type >
937void PassVisitor< pass_type >::visit( CaseStmt * node ) {
938 VISIT_START( node );
939
940 visitExpression ( node->condition );
941 visitStatementList( node->stmts );
942
943 VISIT_END( node );
944}
945
946template< typename pass_type >
947Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
948 MUTATE_START( node );
949
950 node->condition = mutateExpression( node->condition );
951 mutateStatementList( node->stmts );
952
953 MUTATE_END( Statement, node );
954}
955
956//--------------------------------------------------------------------------
957// BranchStmt
958template< typename pass_type >
959void PassVisitor< pass_type >::visit( BranchStmt * node ) {
960 VISIT_START( node );
961 VISIT_END( node );
962}
963
964template< typename pass_type >
965Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
966 MUTATE_START( node );
967 MUTATE_END( Statement, node );
968}
969
970//--------------------------------------------------------------------------
971// ReturnStmt
972template< typename pass_type >
973void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
974 VISIT_START( node );
975
976 visitExpression( node->expr );
977
978 VISIT_END( node );
979}
980
981template< typename pass_type >
982Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
983 MUTATE_START( node );
984
985 node->expr = mutateExpression( node->expr );
986
987 MUTATE_END( Statement, node );
988}
989
990//--------------------------------------------------------------------------
991// ThrowStmt
992
993template< typename pass_type >
994void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
995 VISIT_START( node );
996
997 maybeAccept_impl( node->expr, *this );
998 maybeAccept_impl( node->target, *this );
999
1000 VISIT_END( node );
1001}
1002
1003template< typename pass_type >
1004Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
1005 MUTATE_START( node );
1006
1007 maybeMutate_impl( node->expr, *this );
1008 maybeMutate_impl( node->target, *this );
1009
1010 MUTATE_END( Statement, node );
1011}
1012
1013//--------------------------------------------------------------------------
1014// TryStmt
1015template< typename pass_type >
1016void PassVisitor< pass_type >::visit( TryStmt * node ) {
1017 VISIT_START( node );
1018
1019 maybeAccept_impl( node->block , *this );
1020 maybeAccept_impl( node->handlers , *this );
1021 maybeAccept_impl( node->finallyBlock, *this );
1022
1023 VISIT_END( node );
1024}
1025
1026template< typename pass_type >
1027Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
1028 MUTATE_START( node );
1029
1030 maybeMutate_impl( node->block , *this );
1031 maybeMutate_impl( node->handlers , *this );
1032 maybeMutate_impl( node->finallyBlock, *this );
1033
1034 MUTATE_END( Statement, node );
1035}
1036
1037//--------------------------------------------------------------------------
1038// CatchStmt
1039template< typename pass_type >
1040void PassVisitor< pass_type >::visit( CatchStmt * node ) {
1041 VISIT_START( node );
1042 {
1043 // catch statements introduce a level of scope (for the caught exception)
1044 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1045 maybeAccept_impl( node->decl, *this );
1046 node->cond = visitExpression( node->cond );
1047 node->body = visitStatement ( node->body );
1048 }
1049 VISIT_END( node );
1050}
1051
1052template< typename pass_type >
1053Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
1054 MUTATE_START( node );
1055 {
1056 // catch statements introduce a level of scope (for the caught exception)
1057 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1058 maybeMutate_impl( node->decl, *this );
1059 node->cond = mutateExpression( node->cond );
1060 node->body = mutateStatement ( node->body );
1061 }
1062 MUTATE_END( Statement, node );
1063}
1064
1065//--------------------------------------------------------------------------
1066// FinallyStmt
1067template< typename pass_type >
1068void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
1069 VISIT_START( node );
1070
1071 maybeAccept_impl( node->block, *this );
1072
1073 VISIT_END( node );
1074}
1075
1076template< typename pass_type >
1077Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
1078 MUTATE_START( node );
1079
1080 maybeMutate_impl( node->block, *this );
1081
1082 MUTATE_END( Statement, node );
1083}
1084
1085//--------------------------------------------------------------------------
1086// WaitForStmt
1087template< typename pass_type >
1088void PassVisitor< pass_type >::visit( WaitForStmt * node ) {
1089 VISIT_START( node );
1090
1091 for( auto & clause : node->clauses ) {
1092 maybeAccept_impl( clause.target.function, *this );
1093 maybeAccept_impl( clause.target.arguments, *this );
1094
1095 maybeAccept_impl( clause.statement, *this );
1096 maybeAccept_impl( clause.condition, *this );
1097 }
1098
1099 maybeAccept_impl( node->timeout.time, *this );
1100 maybeAccept_impl( node->timeout.statement, *this );
1101 maybeAccept_impl( node->timeout.condition, *this );
1102 maybeAccept_impl( node->orelse.statement, *this );
1103 maybeAccept_impl( node->orelse.condition, *this );
1104
1105 VISIT_END( node );
1106}
1107
1108template< typename pass_type >
1109Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
1110 MUTATE_START( node );
1111
1112 for( auto & clause : node->clauses ) {
1113 maybeMutate_impl( clause.target.function, *this );
1114 maybeMutate_impl( clause.target.arguments, *this );
1115
1116 maybeMutate_impl( clause.statement, *this );
1117 maybeMutate_impl( clause.condition, *this );
1118 }
1119
1120 maybeMutate_impl( node->timeout.time, *this );
1121 maybeMutate_impl( node->timeout.statement, *this );
1122 maybeMutate_impl( node->timeout.condition, *this );
1123 maybeMutate_impl( node->orelse.statement, *this );
1124 maybeMutate_impl( node->orelse.condition, *this );
1125
1126 MUTATE_END( Statement, node );
1127}
1128
1129
1130
1131//--------------------------------------------------------------------------
1132// NullStmt
1133template< typename pass_type >
1134void PassVisitor< pass_type >::visit( WithStmt * node ) {
1135 VISIT_START( node );
1136 maybeAccept_impl( node->exprs, *this );
1137 {
1138 // catch statements introduce a level of scope (for the caught exception)
1139 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1140 indexerAddWith( node->exprs, node );
1141 maybeAccept_impl( node->stmt, *this );
1142 }
1143 VISIT_END( node );
1144}
1145
1146template< typename pass_type >
1147Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {
1148 MUTATE_START( node );
1149 maybeMutate_impl( node->exprs, *this );
1150 {
1151 // catch statements introduce a level of scope (for the caught exception)
1152 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1153 indexerAddWith( node->exprs, node );
1154 maybeMutate_impl( node->stmt, *this );
1155 }
1156 MUTATE_END( Statement, node );
1157}
1158
1159//--------------------------------------------------------------------------
1160// NullStmt
1161template< typename pass_type >
1162void PassVisitor< pass_type >::visit( NullStmt * node ) {
1163 VISIT_START( node );
1164 VISIT_END( node );
1165}
1166
1167template< typename pass_type >
1168NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
1169 MUTATE_START( node );
1170 MUTATE_END( NullStmt, node );
1171}
1172
1173//--------------------------------------------------------------------------
1174// DeclStmt
1175template< typename pass_type >
1176void PassVisitor< pass_type >::visit( DeclStmt * node ) {
1177 VISIT_START( node );
1178
1179 maybeAccept_impl( node->decl, *this );
1180
1181 VISIT_END( node );
1182}
1183
1184template< typename pass_type >
1185Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
1186 MUTATE_START( node );
1187
1188 maybeMutate_impl( node->decl, *this );
1189
1190 MUTATE_END( Statement, node );
1191}
1192
1193//--------------------------------------------------------------------------
1194// ImplicitCtorDtorStmt
1195template< typename pass_type >
1196void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
1197 VISIT_START( node );
1198
1199 maybeAccept_impl( node->callStmt, *this );
1200
1201 VISIT_END( node );
1202}
1203
1204template< typename pass_type >
1205Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
1206 MUTATE_START( node );
1207
1208 maybeMutate_impl( node->callStmt, *this );
1209
1210 MUTATE_END( Statement, node );
1211}
1212
1213//--------------------------------------------------------------------------
1214// ApplicationExpr
1215template< typename pass_type >
1216void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
1217 VISIT_START( node );
1218
1219 indexerScopedAccept( node->result , *this );
1220 maybeAccept_impl ( node->function, *this );
1221 maybeAccept_impl ( node->args , *this );
1222
1223 VISIT_END( node );
1224}
1225
1226template< typename pass_type >
1227Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) {
1228 MUTATE_START( node );
1229
1230 indexerScopedMutate( node->env , *this );
1231 indexerScopedMutate( node->result , *this );
1232 maybeMutate_impl ( node->function, *this );
1233 maybeMutate_impl ( node->args , *this );
1234
1235 MUTATE_END( Expression, node );
1236}
1237
1238//--------------------------------------------------------------------------
1239// UntypedExpr
1240template< typename pass_type >
1241void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
1242 VISIT_START( node );
1243
1244 // maybeAccept_impl( node->get_env(), *this );
1245 indexerScopedAccept( node->result, *this );
1246
1247 for ( auto expr : node->args ) {
1248 visitExpression( expr );
1249 }
1250
1251 VISIT_END( node );
1252}
1253
1254template< typename pass_type >
1255Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
1256 MUTATE_START( node );
1257
1258 indexerScopedMutate( node->env , *this );
1259 indexerScopedMutate( node->result, *this );
1260
1261 for ( auto& expr : node->args ) {
1262 expr = mutateExpression( expr );
1263 }
1264
1265 MUTATE_END( Expression, node );
1266}
1267
1268//--------------------------------------------------------------------------
1269// NameExpr
1270template< typename pass_type >
1271void PassVisitor< pass_type >::visit( NameExpr * node ) {
1272 VISIT_START( node );
1273
1274 indexerScopedAccept( node->result, *this );
1275
1276 VISIT_END( node );
1277}
1278
1279template< typename pass_type >
1280Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
1281 MUTATE_START( node );
1282
1283 indexerScopedMutate( node->env , *this );
1284 indexerScopedMutate( node->result, *this );
1285
1286 MUTATE_END( Expression, node );
1287}
1288
1289//--------------------------------------------------------------------------
1290// CastExpr
1291template< typename pass_type >
1292void PassVisitor< pass_type >::visit( CastExpr * node ) {
1293 VISIT_START( node );
1294
1295 indexerScopedAccept( node->result, *this );
1296 maybeAccept_impl ( node->arg , *this );
1297
1298 VISIT_END( node );
1299}
1300
1301template< typename pass_type >
1302Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
1303 MUTATE_START( node );
1304
1305 indexerScopedMutate( node->env , *this );
1306 indexerScopedMutate( node->result, *this );
1307 maybeMutate_impl ( node->arg , *this );
1308
1309 MUTATE_END( Expression, node );
1310}
1311
1312//--------------------------------------------------------------------------
1313// KeywordCastExpr
1314template< typename pass_type >
1315void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
1316 VISIT_START( node );
1317
1318 indexerScopedAccept( node->result, *this );
1319 maybeAccept_impl ( node->arg , *this );
1320
1321 VISIT_END( node );
1322}
1323
1324template< typename pass_type >
1325Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
1326 MUTATE_START( node );
1327
1328 indexerScopedMutate( node->env , *this );
1329 indexerScopedMutate( node->result, *this );
1330 maybeMutate_impl ( node->arg , *this );
1331
1332 MUTATE_END( Expression, node );
1333}
1334
1335//--------------------------------------------------------------------------
1336// VirtualCastExpr
1337template< typename pass_type >
1338void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) {
1339 VISIT_START( node );
1340
1341 indexerScopedAccept( node->result, *this );
1342 maybeAccept_impl( node->arg, *this );
1343
1344 VISIT_END( node );
1345}
1346
1347template< typename pass_type >
1348Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
1349 MUTATE_START( node );
1350
1351 indexerScopedMutate( node->env , *this );
1352 indexerScopedMutate( node->result, *this );
1353 maybeMutate_impl ( node->arg , *this );
1354
1355 MUTATE_END( Expression, node );
1356}
1357
1358//--------------------------------------------------------------------------
1359// AddressExpr
1360template< typename pass_type >
1361void PassVisitor< pass_type >::visit( AddressExpr * node ) {
1362 VISIT_START( node );
1363
1364 indexerScopedAccept( node->result, *this );
1365 maybeAccept_impl ( node->arg , *this );
1366
1367 VISIT_END( node );
1368}
1369
1370template< typename pass_type >
1371Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
1372 MUTATE_START( node );
1373
1374 indexerScopedMutate( node->env , *this );
1375 indexerScopedMutate( node->result, *this );
1376 maybeMutate_impl ( node->arg , *this );
1377
1378 MUTATE_END( Expression, node );
1379}
1380
1381//--------------------------------------------------------------------------
1382// LabelAddressExpr
1383template< typename pass_type >
1384void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
1385 VISIT_START( node );
1386
1387 indexerScopedAccept( node->result, *this );
1388
1389 VISIT_END( node );
1390}
1391
1392template< typename pass_type >
1393Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
1394 MUTATE_START( node );
1395
1396 indexerScopedMutate( node->env , *this );
1397 indexerScopedMutate( node->result, *this );
1398
1399 MUTATE_END( Expression, node );
1400}
1401
1402//--------------------------------------------------------------------------
1403// UntypedMemberExpr
1404template< typename pass_type >
1405void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
1406 VISIT_START( node );
1407
1408 indexerScopedAccept( node->result , *this );
1409 maybeAccept_impl ( node->aggregate, *this );
1410 maybeAccept_impl ( node->member , *this );
1411
1412 VISIT_END( node );
1413}
1414
1415template< typename pass_type >
1416Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) {
1417 MUTATE_START( node );
1418
1419 indexerScopedMutate( node->env , *this );
1420 indexerScopedMutate( node->result , *this );
1421 maybeMutate_impl ( node->aggregate, *this );
1422 maybeMutate_impl ( node->member , *this );
1423
1424 MUTATE_END( Expression, node );
1425}
1426
1427//--------------------------------------------------------------------------
1428// MemberExpr
1429template< typename pass_type >
1430void PassVisitor< pass_type >::visit( MemberExpr * node ) {
1431 VISIT_START( node );
1432
1433 indexerScopedAccept( node->result , *this );
1434 maybeAccept_impl ( node->aggregate, *this );
1435
1436 VISIT_END( node );
1437}
1438
1439template< typename pass_type >
1440Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
1441 MUTATE_START( node );
1442
1443 indexerScopedMutate( node->env , *this );
1444 indexerScopedMutate( node->result , *this );
1445 maybeMutate_impl ( node->aggregate, *this );
1446
1447 MUTATE_END( Expression, node );
1448}
1449
1450//--------------------------------------------------------------------------
1451// VariableExpr
1452template< typename pass_type >
1453void PassVisitor< pass_type >::visit( VariableExpr * node ) {
1454 VISIT_START( node );
1455
1456 indexerScopedAccept( node->result, *this );
1457
1458 VISIT_END( node );
1459}
1460
1461template< typename pass_type >
1462Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
1463 MUTATE_START( node );
1464
1465 indexerScopedMutate( node->env , *this );
1466 indexerScopedMutate( node->result, *this );
1467
1468 MUTATE_END( Expression, node );
1469}
1470
1471//--------------------------------------------------------------------------
1472// ConstantExpr
1473template< typename pass_type >
1474void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
1475 VISIT_START( node );
1476
1477 indexerScopedAccept( node->result , *this );
1478 maybeAccept_impl ( &node->constant, *this );
1479
1480 VISIT_END( node );
1481}
1482
1483template< typename pass_type >
1484Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) {
1485 MUTATE_START( node );
1486
1487 indexerScopedMutate( node->env , *this );
1488 indexerScopedMutate( node->result, *this );
1489 Constant * ptr = &node->constant;
1490 maybeMutate_impl( ptr, *this );
1491 node->constant = *ptr;
1492
1493 MUTATE_END( Expression, node );
1494}
1495
1496//--------------------------------------------------------------------------
1497// SizeofExpr
1498template< typename pass_type >
1499void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
1500 VISIT_START( node );
1501
1502 indexerScopedAccept( node->result, *this );
1503 if ( node->get_isType() ) {
1504 maybeAccept_impl( node->type, *this );
1505 } else {
1506 maybeAccept_impl( node->expr, *this );
1507 }
1508
1509 VISIT_END( node );
1510}
1511
1512template< typename pass_type >
1513Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
1514 MUTATE_START( node );
1515
1516 indexerScopedMutate( node->env , *this );
1517 indexerScopedMutate( node->result, *this );
1518 if ( node->get_isType() ) {
1519 maybeMutate_impl( node->type, *this );
1520 } else {
1521 maybeMutate_impl( node->expr, *this );
1522 }
1523
1524 MUTATE_END( Expression, node );
1525}
1526
1527//--------------------------------------------------------------------------
1528// AlignofExpr
1529template< typename pass_type >
1530void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
1531 VISIT_START( node );
1532
1533 indexerScopedAccept( node->result, *this );
1534 if ( node->get_isType() ) {
1535 maybeAccept_impl( node->type, *this );
1536 } else {
1537 maybeAccept_impl( node->expr, *this );
1538 }
1539
1540 VISIT_END( node );
1541}
1542
1543template< typename pass_type >
1544Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
1545 MUTATE_START( node );
1546
1547 indexerScopedMutate( node->env , *this );
1548 indexerScopedMutate( node->result, *this );
1549 if ( node->get_isType() ) {
1550 maybeMutate_impl( node->type, *this );
1551 } else {
1552 maybeMutate_impl( node->expr, *this );
1553 }
1554
1555 MUTATE_END( Expression, node );
1556}
1557
1558//--------------------------------------------------------------------------
1559// UntypedOffsetofExpr
1560template< typename pass_type >
1561void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
1562 VISIT_START( node );
1563
1564 indexerScopedAccept( node->result, *this );
1565 maybeAccept_impl ( node->type , *this );
1566
1567 VISIT_END( node );
1568}
1569
1570template< typename pass_type >
1571Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
1572 MUTATE_START( node );
1573
1574 indexerScopedMutate( node->env , *this );
1575 indexerScopedMutate( node->result, *this );
1576 maybeMutate_impl ( node->type , *this );
1577
1578 MUTATE_END( Expression, node );
1579}
1580
1581//--------------------------------------------------------------------------
1582// OffsetofExpr
1583template< typename pass_type >
1584void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
1585 VISIT_START( node );
1586
1587 indexerScopedAccept( node->result, *this );
1588 maybeAccept_impl ( node->type , *this );
1589
1590 VISIT_END( node );
1591}
1592
1593template< typename pass_type >
1594Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
1595 MUTATE_START( node );
1596
1597 indexerScopedMutate( node->env , *this );
1598 indexerScopedMutate( node->result, *this );
1599 maybeMutate_impl ( node->type , *this );
1600
1601 MUTATE_END( Expression, node );
1602}
1603
1604//--------------------------------------------------------------------------
1605// OffsetPackExpr
1606template< typename pass_type >
1607void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
1608 VISIT_START( node );
1609
1610 indexerScopedAccept( node->result, *this );
1611 maybeAccept_impl ( node->type , *this );
1612
1613 VISIT_END( node );
1614}
1615
1616template< typename pass_type >
1617Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
1618 MUTATE_START( node );
1619
1620 indexerScopedMutate( node->env , *this );
1621 indexerScopedMutate( node->result, *this );
1622 maybeMutate_impl ( node->type , *this );
1623
1624 MUTATE_END( Expression, node );
1625}
1626
1627//--------------------------------------------------------------------------
1628// AttrExpr
1629template< typename pass_type >
1630void PassVisitor< pass_type >::visit( AttrExpr * node ) {
1631 VISIT_START( node );
1632
1633 indexerScopedAccept( node->result, *this );
1634 if ( node->get_isType() ) {
1635 maybeAccept_impl( node->type, *this );
1636 } else {
1637 maybeAccept_impl( node->expr, *this );
1638 }
1639
1640 VISIT_END( node );
1641}
1642
1643template< typename pass_type >
1644Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) {
1645 MUTATE_START( node );
1646
1647 indexerScopedMutate( node->env , *this );
1648 indexerScopedMutate( node->result, *this );
1649 if ( node->get_isType() ) {
1650 maybeMutate_impl( node->type, *this );
1651 } else {
1652 maybeMutate_impl( node->expr, *this );
1653 }
1654
1655 MUTATE_END( Expression, node );
1656}
1657
1658//--------------------------------------------------------------------------
1659// LogicalExpr
1660template< typename pass_type >
1661void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
1662 VISIT_START( node );
1663
1664 indexerScopedAccept( node->result, *this );
1665 maybeAccept_impl ( node->arg1 , *this );
1666 maybeAccept_impl ( node->arg2 , *this );
1667
1668 VISIT_END( node );
1669}
1670
1671template< typename pass_type >
1672Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) {
1673 MUTATE_START( node );
1674
1675 indexerScopedMutate( node->env , *this );
1676 indexerScopedMutate( node->result, *this );
1677 maybeMutate_impl ( node->arg1 , *this );
1678 maybeMutate_impl ( node->arg2 , *this );
1679
1680 MUTATE_END( Expression, node );
1681}
1682
1683//--------------------------------------------------------------------------
1684// ConditionalExpr
1685template< typename pass_type >
1686void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
1687 VISIT_START( node );
1688
1689 indexerScopedAccept( node->result, *this );
1690 maybeAccept_impl ( node->arg1 , *this );
1691 maybeAccept_impl ( node->arg2 , *this );
1692 maybeAccept_impl ( node->arg3 , *this );
1693
1694 VISIT_END( node );
1695}
1696
1697template< typename pass_type >
1698Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
1699 MUTATE_START( node );
1700
1701 indexerScopedMutate( node->env , *this );
1702 indexerScopedMutate( node->result, *this );
1703 maybeMutate_impl ( node->arg1 , *this );
1704 maybeMutate_impl ( node->arg2 , *this );
1705 maybeMutate_impl ( node->arg3 , *this );
1706
1707 MUTATE_END( Expression, node );
1708}
1709
1710//--------------------------------------------------------------------------
1711// CommaExpr
1712template< typename pass_type >
1713void PassVisitor< pass_type >::visit( CommaExpr * node ) {
1714 VISIT_START( node );
1715
1716 indexerScopedAccept( node->result, *this );
1717 maybeAccept_impl ( node->arg1 , *this );
1718 maybeAccept_impl ( node->arg2 , *this );
1719
1720 VISIT_END( node );
1721}
1722
1723template< typename pass_type >
1724Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
1725 MUTATE_START( node );
1726
1727 indexerScopedMutate( node->env , *this );
1728 indexerScopedMutate( node->result, *this );
1729 maybeMutate_impl ( node->arg1 , *this );
1730 maybeMutate_impl ( node->arg2 , *this );
1731
1732 MUTATE_END( Expression, node );
1733}
1734
1735//--------------------------------------------------------------------------
1736// TypeExpr
1737template< typename pass_type >
1738void PassVisitor< pass_type >::visit( TypeExpr * node ) {
1739 VISIT_START( node );
1740
1741 indexerScopedAccept( node->result, *this );
1742 maybeAccept_impl ( node->type, *this );
1743
1744 VISIT_END( node );
1745}
1746
1747template< typename pass_type >
1748Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
1749 MUTATE_START( node );
1750
1751 indexerScopedMutate( node->env , *this );
1752 indexerScopedMutate( node->result, *this );
1753 maybeMutate_impl ( node->type , *this );
1754
1755 MUTATE_END( Expression, node );
1756}
1757
1758//--------------------------------------------------------------------------
1759// AsmExpr
1760template< typename pass_type >
1761void PassVisitor< pass_type >::visit( AsmExpr * node ) {
1762 VISIT_START( node );
1763
1764 indexerScopedAccept( node->result , *this );
1765 maybeAccept_impl ( node->inout , *this );
1766 maybeAccept_impl ( node->constraint, *this );
1767 maybeAccept_impl ( node->operand , *this );
1768
1769 VISIT_END( node );
1770}
1771
1772template< typename pass_type >
1773Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) {
1774 MUTATE_START( node );
1775
1776 indexerScopedMutate( node->env , *this );
1777 indexerScopedMutate( node->result , *this );
1778 maybeMutate_impl ( node->inout , *this );
1779 maybeMutate_impl ( node->constraint, *this );
1780 maybeMutate_impl ( node->operand , *this );
1781
1782 MUTATE_END( Expression, node );
1783}
1784
1785//--------------------------------------------------------------------------
1786// ImplicitCopyCtorExpr
1787template< typename pass_type >
1788void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
1789 VISIT_START( node );
1790
1791 indexerScopedAccept( node->result , *this );
1792 maybeAccept_impl ( node->callExpr , *this );
1793 maybeAccept_impl ( node->tempDecls , *this );
1794 maybeAccept_impl ( node->returnDecls, *this );
1795 maybeAccept_impl ( node->dtors , *this );
1796
1797 VISIT_END( node );
1798}
1799
1800template< typename pass_type >
1801Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) {
1802 MUTATE_START( node );
1803
1804 indexerScopedMutate( node->env , *this );
1805 indexerScopedMutate( node->result , *this );
1806 maybeMutate_impl ( node->callExpr , *this );
1807 maybeMutate_impl ( node->tempDecls , *this );
1808 maybeMutate_impl ( node->returnDecls, *this );
1809 maybeMutate_impl ( node->dtors , *this );
1810
1811 MUTATE_END( Expression, node );
1812}
1813
1814//--------------------------------------------------------------------------
1815// ConstructorExpr
1816template< typename pass_type >
1817void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
1818 VISIT_START( node );
1819
1820 indexerScopedAccept( node->result , *this );
1821 maybeAccept_impl ( node->callExpr, *this );
1822
1823 VISIT_END( node );
1824}
1825
1826template< typename pass_type >
1827Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) {
1828 MUTATE_START( node );
1829
1830 indexerScopedMutate( node->env , *this );
1831 indexerScopedMutate( node->result , *this );
1832 maybeMutate_impl ( node->callExpr, *this );
1833
1834 MUTATE_END( Expression, node );
1835}
1836
1837//--------------------------------------------------------------------------
1838// CompoundLiteralExpr
1839template< typename pass_type >
1840void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
1841 VISIT_START( node );
1842
1843 indexerScopedAccept( node->result , *this );
1844 maybeAccept_impl ( node->initializer, *this );
1845
1846 VISIT_END( node );
1847}
1848
1849template< typename pass_type >
1850Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
1851 MUTATE_START( node );
1852
1853 indexerScopedMutate( node->env , *this );
1854 indexerScopedMutate( node->result , *this );
1855 maybeMutate_impl ( node->initializer, *this );
1856
1857 MUTATE_END( Expression, node );
1858}
1859
1860//--------------------------------------------------------------------------
1861// RangeExpr
1862template< typename pass_type >
1863void PassVisitor< pass_type >::visit( RangeExpr * node ) {
1864 VISIT_START( node );
1865
1866 indexerScopedAccept( node->result, *this );
1867 maybeAccept_impl ( node->low , *this );
1868 maybeAccept_impl ( node->high , *this );
1869
1870 VISIT_END( node );
1871}
1872
1873template< typename pass_type >
1874Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
1875 MUTATE_START( node );
1876
1877 indexerScopedMutate( node->env , *this );
1878 indexerScopedMutate( node->result, *this );
1879 maybeMutate_impl ( node->low , *this );
1880 maybeMutate_impl ( node->high , *this );
1881
1882 MUTATE_END( Expression, node );
1883}
1884
1885//--------------------------------------------------------------------------
1886// UntypedTupleExpr
1887template< typename pass_type >
1888void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
1889 VISIT_START( node );
1890
1891 indexerScopedAccept( node->result, *this );
1892 maybeAccept_impl ( node->exprs , *this );
1893
1894 VISIT_END( node );
1895}
1896
1897template< typename pass_type >
1898Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
1899 MUTATE_START( node );
1900
1901 indexerScopedMutate( node->env , *this );
1902 indexerScopedMutate( node->result, *this );
1903 maybeMutate_impl ( node->exprs , *this );
1904
1905 MUTATE_END( Expression, node );
1906}
1907
1908//--------------------------------------------------------------------------
1909// TupleExpr
1910template< typename pass_type >
1911void PassVisitor< pass_type >::visit( TupleExpr * node ) {
1912 VISIT_START( node );
1913
1914 indexerScopedAccept( node->result, *this );
1915 maybeAccept_impl ( node->exprs , *this );
1916
1917 VISIT_END( node );
1918}
1919
1920template< typename pass_type >
1921Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
1922 MUTATE_START( node );
1923
1924 indexerScopedMutate( node->env , *this );
1925 indexerScopedMutate( node->result, *this );
1926 maybeMutate_impl ( node->exprs , *this );
1927
1928 MUTATE_END( Expression, node );
1929}
1930
1931//--------------------------------------------------------------------------
1932// TupleIndexExpr
1933template< typename pass_type >
1934void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
1935 VISIT_START( node );
1936
1937 indexerScopedAccept( node->result, *this );
1938 maybeAccept_impl ( node->tuple , *this );
1939
1940 VISIT_END( node );
1941}
1942
1943template< typename pass_type >
1944Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
1945 MUTATE_START( node );
1946
1947 indexerScopedMutate( node->env , *this );
1948 indexerScopedMutate( node->result, *this );
1949 maybeMutate_impl ( node->tuple , *this );
1950
1951 MUTATE_END( Expression, node );
1952}
1953
1954//--------------------------------------------------------------------------
1955// TupleAssignExpr
1956template< typename pass_type >
1957void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
1958 VISIT_START( node );
1959
1960 indexerScopedAccept( node->result , *this );
1961 maybeAccept_impl ( node->stmtExpr, *this );
1962
1963 VISIT_END( node );
1964}
1965
1966template< typename pass_type >
1967Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) {
1968 MUTATE_START( node );
1969
1970 indexerScopedMutate( node->env , *this );
1971 indexerScopedMutate( node->result , *this );
1972 maybeMutate_impl ( node->stmtExpr, *this );
1973
1974 MUTATE_END( Expression, node );
1975}
1976
1977//--------------------------------------------------------------------------
1978// StmtExpr
1979template< typename pass_type >
1980void PassVisitor< pass_type >::visit( StmtExpr * node ) {
1981 VISIT_START( node );
1982
1983 // don't want statements from outer CompoundStmts to be added to this StmtExpr
1984 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
1985 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
1986 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
1987
1988 indexerScopedAccept( node->result , *this );
1989 maybeAccept_impl ( node->statements , *this );
1990 maybeAccept_impl ( node->returnDecls, *this );
1991 maybeAccept_impl ( node->dtors , *this );
1992
1993 VISIT_END( node );
1994}
1995
1996template< typename pass_type >
1997Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
1998 MUTATE_START( node );
1999
2000 // don't want statements from outer CompoundStmts to be added to this StmtExpr
2001 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
2002 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
2003 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
2004
2005 indexerScopedMutate( node->result , *this );
2006 maybeMutate_impl ( node->statements , *this );
2007 maybeMutate_impl ( node->returnDecls, *this );
2008 maybeMutate_impl ( node->dtors , *this );
2009
2010 MUTATE_END( Expression, node );
2011}
2012
2013//--------------------------------------------------------------------------
2014// UniqueExpr
2015template< typename pass_type >
2016void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
2017 VISIT_START( node );
2018
2019 indexerScopedAccept( node->result, *this );
2020 maybeAccept_impl ( node->expr , *this );
2021
2022 VISIT_END( node );
2023}
2024
2025template< typename pass_type >
2026Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
2027 MUTATE_START( node );
2028
2029 indexerScopedMutate( node->env , *this );
2030 indexerScopedMutate( node->result, *this );
2031 maybeMutate_impl ( node->expr , *this );
2032
2033 MUTATE_END( Expression, node );
2034}
2035
2036//--------------------------------------------------------------------------
2037// UntypedInitExpr
2038template< typename pass_type >
2039void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) {
2040 VISIT_START( node );
2041
2042 indexerScopedAccept( node->result, *this );
2043 maybeAccept_impl ( node->expr , *this );
2044 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
2045
2046 VISIT_END( node );
2047}
2048
2049template< typename pass_type >
2050Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
2051 MUTATE_START( node );
2052
2053 indexerScopedMutate( node->env , *this );
2054 indexerScopedMutate( node->result, *this );
2055 maybeMutate_impl ( node->expr , *this );
2056 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
2057
2058 MUTATE_END( Expression, node );
2059}
2060
2061//--------------------------------------------------------------------------
2062// InitExpr
2063template< typename pass_type >
2064void PassVisitor< pass_type >::visit( InitExpr * node ) {
2065 VISIT_START( node );
2066
2067 indexerScopedAccept( node->result, *this );
2068 maybeAccept_impl ( node->expr , *this );
2069 maybeAccept_impl ( node->designation, *this );
2070
2071 VISIT_END( node );
2072}
2073
2074template< typename pass_type >
2075Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
2076 MUTATE_START( node );
2077
2078 indexerScopedMutate( node->env , *this );
2079 indexerScopedMutate( node->result, *this );
2080 maybeMutate_impl ( node->expr , *this );
2081 maybeMutate_impl ( node->designation, *this );
2082
2083 MUTATE_END( Expression, node );
2084}
2085
2086//--------------------------------------------------------------------------
2087// DeletedExpr
2088template< typename pass_type >
2089void PassVisitor< pass_type >::visit( DeletedExpr * node ) {
2090 VISIT_START( node );
2091
2092 indexerScopedAccept( node->result, *this );
2093 maybeAccept_impl( node->expr, *this );
2094 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
2095
2096 VISIT_END( node );
2097}
2098
2099template< typename pass_type >
2100Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
2101 MUTATE_START( node );
2102
2103 indexerScopedMutate( node->env, *this );
2104 indexerScopedMutate( node->result, *this );
2105 maybeMutate_impl( node->expr, *this );
2106
2107 MUTATE_END( Expression, node );
2108}
2109
2110//--------------------------------------------------------------------------
2111// DefaultArgExpr
2112template< typename pass_type >
2113void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
2114 VISIT_START( node );
2115
2116 indexerScopedAccept( node->result, *this );
2117 maybeAccept_impl( node->expr, *this );
2118
2119 VISIT_END( node );
2120}
2121
2122template< typename pass_type >
2123Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
2124 MUTATE_START( node );
2125
2126 indexerScopedMutate( node->env, *this );
2127 indexerScopedMutate( node->result, *this );
2128 maybeMutate_impl( node->expr, *this );
2129
2130 MUTATE_END( Expression, node );
2131}
2132
2133//--------------------------------------------------------------------------
2134// GenericExpr
2135template< typename pass_type >
2136void PassVisitor< pass_type >::visit( GenericExpr * node ) {
2137 VISIT_START( node );
2138
2139 indexerScopedAccept( node->result, *this );
2140 maybeAccept_impl( node->control, *this );
2141 for ( GenericExpr::Association & assoc : node->associations ) {
2142 indexerScopedAccept( assoc.type, *this );
2143 maybeAccept_impl( assoc.expr, *this );
2144 }
2145
2146 VISIT_END( node );
2147}
2148
2149template< typename pass_type >
2150Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) {
2151 MUTATE_START( node );
2152
2153 indexerScopedMutate( node->env, *this );
2154 indexerScopedMutate( node->result, *this );
2155 maybeMutate_impl( node->control, *this );
2156 for ( GenericExpr::Association & assoc : node->associations ) {
2157 indexerScopedMutate( assoc.type, *this );
2158 maybeMutate_impl( assoc.expr, *this );
2159 }
2160
2161 MUTATE_END( Expression, node );
2162}
2163
2164//--------------------------------------------------------------------------
2165// VoidType
2166template< typename pass_type >
2167void PassVisitor< pass_type >::visit( VoidType * node ) {
2168 VISIT_START( node );
2169
2170 maybeAccept_impl( node->forall, *this );
2171
2172 VISIT_END( node );
2173}
2174
2175template< typename pass_type >
2176Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
2177 MUTATE_START( node );
2178
2179 maybeMutate_impl( node->forall, *this );
2180
2181 MUTATE_END( Type, node );
2182}
2183
2184//--------------------------------------------------------------------------
2185// BasicType
2186template< typename pass_type >
2187void PassVisitor< pass_type >::visit( BasicType * node ) {
2188 VISIT_START( node );
2189
2190 maybeAccept_impl( node->forall, *this );
2191
2192 VISIT_END( node );
2193}
2194
2195template< typename pass_type >
2196Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
2197 MUTATE_START( node );
2198
2199 maybeMutate_impl( node->forall, *this );
2200
2201 MUTATE_END( Type, node );
2202}
2203
2204//--------------------------------------------------------------------------
2205// PointerType
2206template< typename pass_type >
2207void PassVisitor< pass_type >::visit( PointerType * node ) {
2208 VISIT_START( node );
2209
2210 maybeAccept_impl( node->forall, *this );
2211 // xxx - should PointerType visit/mutate dimension?
2212 maybeAccept_impl( node->base, *this );
2213
2214 VISIT_END( node );
2215}
2216
2217template< typename pass_type >
2218Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
2219 MUTATE_START( node );
2220
2221 maybeMutate_impl( node->forall, *this );
2222 // xxx - should PointerType visit/mutate dimension?
2223 maybeMutate_impl( node->base, *this );
2224
2225 MUTATE_END( Type, node );
2226}
2227
2228//--------------------------------------------------------------------------
2229// ArrayType
2230template< typename pass_type >
2231void PassVisitor< pass_type >::visit( ArrayType * node ) {
2232 VISIT_START( node );
2233
2234 maybeAccept_impl( node->forall, *this );
2235 maybeAccept_impl( node->dimension, *this );
2236 maybeAccept_impl( node->base, *this );
2237
2238 VISIT_END( node );
2239}
2240
2241template< typename pass_type >
2242Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
2243 MUTATE_START( node );
2244
2245 maybeMutate_impl( node->forall, *this );
2246 maybeMutate_impl( node->dimension, *this );
2247 maybeMutate_impl( node->base, *this );
2248
2249 MUTATE_END( Type, node );
2250}
2251
2252//--------------------------------------------------------------------------
2253// ReferenceType
2254template< typename pass_type >
2255void PassVisitor< pass_type >::visit( ReferenceType * node ) {
2256 VISIT_START( node );
2257
2258 maybeAccept_impl( node->forall, *this );
2259 maybeAccept_impl( node->base, *this );
2260
2261 VISIT_END( node );
2262}
2263
2264template< typename pass_type >
2265Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
2266 MUTATE_START( node );
2267
2268 maybeMutate_impl( node->forall, *this );
2269 maybeMutate_impl( node->base, *this );
2270
2271 MUTATE_END( Type, node );
2272}
2273
2274//--------------------------------------------------------------------------
2275// QualifiedType
2276template< typename pass_type >
2277void PassVisitor< pass_type >::visit( QualifiedType * node ) {
2278 VISIT_START( node );
2279
2280 maybeAccept_impl( node->forall, *this );
2281 maybeAccept_impl( node->parent, *this );
2282 maybeAccept_impl( node->child, *this );
2283
2284 VISIT_END( node );
2285}
2286
2287template< typename pass_type >
2288Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) {
2289 MUTATE_START( node );
2290
2291 maybeMutate_impl( node->forall, *this );
2292 maybeMutate_impl( node->parent, *this );
2293 maybeMutate_impl( node->child, *this );
2294
2295 MUTATE_END( Type, node );
2296}
2297
2298//--------------------------------------------------------------------------
2299// FunctionType
2300template< typename pass_type >
2301void PassVisitor< pass_type >::visit( FunctionType * node ) {
2302 VISIT_START( node );
2303
2304 maybeAccept_impl( node->forall, *this );
2305 maybeAccept_impl( node->returnVals, *this );
2306 maybeAccept_impl( node->parameters, *this );
2307
2308 VISIT_END( node );
2309}
2310
2311template< typename pass_type >
2312Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
2313 MUTATE_START( node );
2314
2315 maybeMutate_impl( node->forall, *this );
2316 maybeMutate_impl( node->returnVals, *this );
2317 maybeMutate_impl( node->parameters, *this );
2318
2319 MUTATE_END( Type, node );
2320}
2321
2322//--------------------------------------------------------------------------
2323// StructInstType
2324template< typename pass_type >
2325void PassVisitor< pass_type >::visit( StructInstType * node ) {
2326 VISIT_START( node );
2327
2328 indexerAddStruct( node->name );
2329
2330 {
2331 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2332 maybeAccept_impl( node->forall , *this );
2333 maybeAccept_impl( node->parameters, *this );
2334 }
2335
2336 VISIT_END( node );
2337}
2338
2339template< typename pass_type >
2340Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
2341 MUTATE_START( node );
2342
2343 indexerAddStruct( node->name );
2344
2345 {
2346 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2347 maybeMutate_impl( node->forall , *this );
2348 maybeMutate_impl( node->parameters, *this );
2349 }
2350
2351 MUTATE_END( Type, node );
2352}
2353
2354//--------------------------------------------------------------------------
2355// UnionInstType
2356template< typename pass_type >
2357void PassVisitor< pass_type >::visit( UnionInstType * node ) {
2358 VISIT_START( node );
2359
2360 indexerAddStruct( node->name );
2361
2362 {
2363 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2364 maybeAccept_impl( node->forall , *this );
2365 maybeAccept_impl( node->parameters, *this );
2366 }
2367
2368 VISIT_END( node );
2369}
2370
2371template< typename pass_type >
2372Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
2373 MUTATE_START( node );
2374
2375 indexerAddStruct( node->name );
2376
2377 {
2378 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2379 maybeMutate_impl( node->forall , *this );
2380 maybeMutate_impl( node->parameters, *this );
2381 }
2382
2383 MUTATE_END( Type, node );
2384}
2385
2386//--------------------------------------------------------------------------
2387// EnumInstType
2388template< typename pass_type >
2389void PassVisitor< pass_type >::visit( EnumInstType * node ) {
2390 VISIT_START( node );
2391
2392 maybeAccept_impl( node->forall, *this );
2393 maybeAccept_impl( node->parameters, *this );
2394
2395 VISIT_END( node );
2396}
2397
2398template< typename pass_type >
2399Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
2400 MUTATE_START( node );
2401
2402 maybeMutate_impl( node->forall, *this );
2403 maybeMutate_impl( node->parameters, *this );
2404
2405 MUTATE_END( Type, node );
2406}
2407
2408//--------------------------------------------------------------------------
2409// TraitInstType
2410template< typename pass_type >
2411void PassVisitor< pass_type >::visit( TraitInstType * node ) {
2412 VISIT_START( node );
2413
2414 maybeAccept_impl( node->forall , *this );
2415 maybeAccept_impl( node->parameters, *this );
2416
2417 VISIT_END( node );
2418}
2419
2420template< typename pass_type >
2421Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
2422 MUTATE_START( node );
2423
2424 maybeMutate_impl( node->forall , *this );
2425 maybeMutate_impl( node->parameters, *this );
2426
2427 MUTATE_END( Type, node );
2428}
2429
2430//--------------------------------------------------------------------------
2431// TypeInstType
2432template< typename pass_type >
2433void PassVisitor< pass_type >::visit( TypeInstType * node ) {
2434 VISIT_START( node );
2435
2436 maybeAccept_impl( node->forall , *this );
2437 maybeAccept_impl( node->parameters, *this );
2438
2439 VISIT_END( node );
2440}
2441
2442template< typename pass_type >
2443Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
2444 MUTATE_START( node );
2445
2446 maybeMutate_impl( node->forall , *this );
2447 maybeMutate_impl( node->parameters, *this );
2448
2449 MUTATE_END( Type, node );
2450}
2451
2452//--------------------------------------------------------------------------
2453// TupleType
2454template< typename pass_type >
2455void PassVisitor< pass_type >::visit( TupleType * node ) {
2456 VISIT_START( node );
2457
2458 maybeAccept_impl( node->forall, *this );
2459 maybeAccept_impl( node->types, *this );
2460 maybeAccept_impl( node->members, *this );
2461
2462 VISIT_END( node );
2463}
2464
2465template< typename pass_type >
2466Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
2467 MUTATE_START( node );
2468
2469 maybeMutate_impl( node->forall, *this );
2470 maybeMutate_impl( node->types, *this );
2471 maybeMutate_impl( node->members, *this );
2472
2473 MUTATE_END( Type, node );
2474}
2475
2476//--------------------------------------------------------------------------
2477// TypeofType
2478template< typename pass_type >
2479void PassVisitor< pass_type >::visit( TypeofType * node ) {
2480 VISIT_START( node );
2481
2482 assert( node->expr );
2483 maybeAccept_impl( node->expr, *this );
2484
2485 VISIT_END( node );
2486}
2487
2488template< typename pass_type >
2489Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
2490 MUTATE_START( node );
2491
2492 assert( node->expr );
2493 maybeMutate_impl( node->expr, *this );
2494
2495 MUTATE_END( Type, node );
2496}
2497
2498//--------------------------------------------------------------------------
2499// AttrType
2500template< typename pass_type >
2501void PassVisitor< pass_type >::visit( AttrType * node ) {
2502 VISIT_START( node );
2503
2504 if ( node->isType ) {
2505 assert( node->type );
2506 maybeAccept_impl( node->type, *this );
2507 } else {
2508 assert( node->expr );
2509 maybeAccept_impl( node->expr, *this );
2510 } // if
2511
2512 VISIT_END( node );
2513}
2514
2515template< typename pass_type >
2516Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
2517 MUTATE_START( node );
2518
2519 if ( node->isType ) {
2520 assert( node->type );
2521 maybeMutate_impl( node->type, *this );
2522 } else {
2523 assert( node->expr );
2524 maybeMutate_impl( node->expr, *this );
2525 } // if
2526
2527 MUTATE_END( Type, node );
2528}
2529
2530//--------------------------------------------------------------------------
2531// VarArgsType
2532template< typename pass_type >
2533void PassVisitor< pass_type >::visit( VarArgsType * node ) {
2534 VISIT_START( node );
2535
2536 maybeAccept_impl( node->forall, *this );
2537
2538 VISIT_END( node );
2539}
2540
2541template< typename pass_type >
2542Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
2543 MUTATE_START( node );
2544
2545 maybeMutate_impl( node->forall, *this );
2546
2547 MUTATE_END( Type, node );
2548}
2549
2550//--------------------------------------------------------------------------
2551// ZeroType
2552template< typename pass_type >
2553void PassVisitor< pass_type >::visit( ZeroType * node ) {
2554 VISIT_START( node );
2555
2556 maybeAccept_impl( node->forall, *this );
2557
2558 VISIT_END( node );
2559}
2560
2561template< typename pass_type >
2562Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
2563 MUTATE_START( node );
2564
2565 maybeMutate_impl( node->forall, *this );
2566
2567 MUTATE_END( Type, node );
2568}
2569
2570//--------------------------------------------------------------------------
2571// OneType
2572template< typename pass_type >
2573void PassVisitor< pass_type >::visit( OneType * node ) {
2574 VISIT_START( node );
2575
2576 maybeAccept_impl( node->forall, *this );
2577
2578 VISIT_END( node );
2579}
2580
2581template< typename pass_type >
2582Type * PassVisitor< pass_type >::mutate( OneType * node ) {
2583 MUTATE_START( node );
2584
2585 maybeMutate_impl( node->forall, *this );
2586
2587 MUTATE_END( Type, node );
2588}
2589
2590//--------------------------------------------------------------------------
2591// GlobalScopeType
2592template< typename pass_type >
2593void PassVisitor< pass_type >::visit( GlobalScopeType * node ) {
2594 VISIT_START( node );
2595
2596 maybeAccept_impl( node->forall, *this );
2597
2598 VISIT_END( node );
2599}
2600
2601template< typename pass_type >
2602Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) {
2603 MUTATE_START( node );
2604
2605 maybeMutate_impl( node->forall, *this );
2606
2607 MUTATE_END( Type, node );
2608}
2609
2610//--------------------------------------------------------------------------
2611// Designation
2612template< typename pass_type >
2613void PassVisitor< pass_type >::visit( Designation * node ) {
2614 VISIT_START( node );
2615
2616 maybeAccept_impl( node->designators, *this );
2617
2618 VISIT_END( node );
2619}
2620
2621template< typename pass_type >
2622Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
2623 MUTATE_START( node );
2624
2625 maybeMutate_impl( node->designators, *this );
2626
2627 MUTATE_END( Designation, node );
2628}
2629
2630//--------------------------------------------------------------------------
2631// SingleInit
2632template< typename pass_type >
2633void PassVisitor< pass_type >::visit( SingleInit * node ) {
2634 VISIT_START( node );
2635
2636 visitExpression( node->value );
2637
2638 VISIT_END( node );
2639}
2640
2641template< typename pass_type >
2642Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
2643 MUTATE_START( node );
2644
2645 node->value = mutateExpression( node->value );
2646
2647 MUTATE_END( Initializer, node );
2648}
2649
2650//--------------------------------------------------------------------------
2651// ListInit
2652template< typename pass_type >
2653void PassVisitor< pass_type >::visit( ListInit * node ) {
2654 VISIT_START( node );
2655
2656 maybeAccept_impl( node->designations, *this );
2657 maybeAccept_impl( node->initializers, *this );
2658
2659 VISIT_END( node );
2660}
2661
2662template< typename pass_type >
2663Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
2664 MUTATE_START( node );
2665
2666 maybeMutate_impl( node->designations, *this );
2667 maybeMutate_impl( node->initializers, *this );
2668
2669 MUTATE_END( Initializer, node );
2670}
2671
2672//--------------------------------------------------------------------------
2673// ConstructorInit
2674template< typename pass_type >
2675void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
2676 VISIT_START( node );
2677
2678 maybeAccept_impl( node->ctor, *this );
2679 maybeAccept_impl( node->dtor, *this );
2680 maybeAccept_impl( node->init, *this );
2681
2682 VISIT_END( node );
2683}
2684
2685template< typename pass_type >
2686Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
2687 MUTATE_START( node );
2688
2689 maybeMutate_impl( node->ctor, *this );
2690 maybeMutate_impl( node->dtor, *this );
2691 maybeMutate_impl( node->init, *this );
2692
2693 MUTATE_END( Initializer, node );
2694}
2695
2696//--------------------------------------------------------------------------
2697// Attribute
2698template< typename pass_type >
2699void PassVisitor< pass_type >::visit( Constant * node ) {
2700 VISIT_START( node );
2701
2702 VISIT_END( node );
2703}
2704
2705template< typename pass_type >
2706Constant * PassVisitor< pass_type >::mutate( Constant * node ) {
2707 MUTATE_START( node );
2708
2709 MUTATE_END( Constant, node );
2710}
2711
2712//--------------------------------------------------------------------------
2713// Attribute
2714template< typename pass_type >
2715void PassVisitor< pass_type >::visit( Attribute * node ) {
2716 VISIT_START( node );
2717
2718 maybeAccept_impl( node->parameters, *this );
2719
2720 VISIT_END( node );
2721}
2722
2723template< typename pass_type >
2724Attribute * PassVisitor< pass_type >::mutate( Attribute * node ) {
2725 MUTATE_START( node );
2726
2727 maybeMutate_impl( node->parameters, *this );
2728
2729 MUTATE_END( Attribute, node );
2730}
2731
2732//--------------------------------------------------------------------------
2733// TypeSubstitution
2734template< typename pass_type >
2735TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
2736 MUTATE_START( node );
2737
2738 for ( auto & p : node->typeEnv ) {
2739 indexerScopedMutate( p.second, *this );
2740 }
2741 for ( auto & p : node->varEnv ) {
2742 indexerScopedMutate( p.second, *this );
2743 }
2744
2745 MUTATE_END( TypeSubstitution, node );
2746}
2747
2748#undef VISIT_START
2749#undef VISIT_END
2750
2751#undef MUTATE_START
2752#undef MUTATE_END
Note: See TracBrowser for help on using the repository browser.