source: src/Common/PassVisitor.impl.h@ 401e61f

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since 401e61f was ee3c93d, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add support for while loops with control declarations

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