source: src/Common/PassVisitor.impl.h@ 32cab5b

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 32cab5b was f6e3e34, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add StaticAssertDecl node

  • Property mode set to 100644
File size: 73.7 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 maybeAccept_impl( node->condition, *this );
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 maybeMutate_impl( node->condition, *this );
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// IfStmt
780template< typename pass_type >
781void PassVisitor< pass_type >::visit( IfStmt * node ) {
782 VISIT_START( node );
783 {
784 // if statements introduce a level of scope (for the initialization)
785 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
786 maybeAccept_impl( node->get_initialization(), *this );
787 visitExpression ( node->condition );
788 node->thenPart = visitStatement( node->thenPart );
789 node->elsePart = visitStatement( node->elsePart );
790 }
791 VISIT_END( node );
792}
793
794template< typename pass_type >
795Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
796 MUTATE_START( node );
797 {
798 // if statements introduce a level of scope (for the initialization)
799 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
800 maybeMutate_impl( node->get_initialization(), *this );
801 node->condition = mutateExpression( node->condition );
802 node->thenPart = mutateStatement ( node->thenPart );
803 node->elsePart = mutateStatement ( node->elsePart );
804 }
805 MUTATE_END( Statement, node );
806}
807
808//--------------------------------------------------------------------------
809// WhileStmt
810template< typename pass_type >
811void PassVisitor< pass_type >::visit( WhileStmt * node ) {
812 VISIT_START( node );
813
814 visitExpression( node->condition );
815 node->body = visitStatement( node->body );
816
817 VISIT_END( node );
818}
819
820template< typename pass_type >
821Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
822 MUTATE_START( node );
823
824 node->condition = mutateExpression( node->condition );
825 node->body = mutateStatement ( node->body );
826
827 MUTATE_END( Statement, node );
828}
829
830//--------------------------------------------------------------------------
831// ForStmt
832template< typename pass_type >
833void PassVisitor< pass_type >::visit( ForStmt * node ) {
834 VISIT_START( node );
835 {
836 // for statements introduce a level of scope (for the initialization)
837 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
838 maybeAccept_impl( node->initialization, *this );
839 visitExpression( node->condition );
840 visitExpression( node->increment );
841 node->body = visitStatement( node->body );
842 }
843 VISIT_END( node );
844}
845
846template< typename pass_type >
847Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
848 MUTATE_START( node );
849 {
850 // for statements introduce a level of scope (for the initialization)
851 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
852 maybeMutate_impl( node->initialization, *this );
853 node->condition = mutateExpression( node->condition );
854 node->increment = mutateExpression( node->increment );
855 node->body = mutateStatement ( node->body );
856 }
857 MUTATE_END( Statement, node );
858}
859
860//--------------------------------------------------------------------------
861// SwitchStmt
862template< typename pass_type >
863void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
864 VISIT_START( node );
865
866 visitExpression ( node->condition );
867 visitStatementList( node->statements );
868
869 VISIT_END( node );
870}
871
872template< typename pass_type >
873Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
874 MUTATE_START( node );
875
876 node->condition = mutateExpression( node->condition );
877 mutateStatementList( node->statements );
878
879 MUTATE_END( Statement, node );
880}
881
882//--------------------------------------------------------------------------
883// CaseStmt
884template< typename pass_type >
885void PassVisitor< pass_type >::visit( CaseStmt * node ) {
886 VISIT_START( node );
887
888 visitExpression ( node->condition );
889 visitStatementList( node->stmts );
890
891 VISIT_END( node );
892}
893
894template< typename pass_type >
895Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
896 MUTATE_START( node );
897
898 node->condition = mutateExpression( node->condition );
899 mutateStatementList( node->stmts );
900
901 MUTATE_END( Statement, node );
902}
903
904//--------------------------------------------------------------------------
905// BranchStmt
906template< typename pass_type >
907void PassVisitor< pass_type >::visit( BranchStmt * node ) {
908 VISIT_START( node );
909 VISIT_END( node );
910}
911
912template< typename pass_type >
913Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
914 MUTATE_START( node );
915 MUTATE_END( Statement, node );
916}
917
918//--------------------------------------------------------------------------
919// ReturnStmt
920template< typename pass_type >
921void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
922 VISIT_START( node );
923
924 visitExpression( node->expr );
925
926 VISIT_END( node );
927}
928
929template< typename pass_type >
930Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
931 MUTATE_START( node );
932
933 node->expr = mutateExpression( node->expr );
934
935 MUTATE_END( Statement, node );
936}
937
938//--------------------------------------------------------------------------
939// ThrowStmt
940
941template< typename pass_type >
942void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
943 VISIT_START( node );
944
945 maybeAccept_impl( node->expr, *this );
946 maybeAccept_impl( node->target, *this );
947
948 VISIT_END( node );
949}
950
951template< typename pass_type >
952Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
953 MUTATE_START( node );
954
955 maybeMutate_impl( node->expr, *this );
956 maybeMutate_impl( node->target, *this );
957
958 MUTATE_END( Statement, node );
959}
960
961//--------------------------------------------------------------------------
962// TryStmt
963template< typename pass_type >
964void PassVisitor< pass_type >::visit( TryStmt * node ) {
965 VISIT_START( node );
966
967 maybeAccept_impl( node->block , *this );
968 maybeAccept_impl( node->handlers , *this );
969 maybeAccept_impl( node->finallyBlock, *this );
970
971 VISIT_END( node );
972}
973
974template< typename pass_type >
975Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
976 MUTATE_START( node );
977
978 maybeMutate_impl( node->block , *this );
979 maybeMutate_impl( node->handlers , *this );
980 maybeMutate_impl( node->finallyBlock, *this );
981
982 MUTATE_END( Statement, node );
983}
984
985//--------------------------------------------------------------------------
986// CatchStmt
987template< typename pass_type >
988void PassVisitor< pass_type >::visit( CatchStmt * node ) {
989 VISIT_START( node );
990 {
991 // catch statements introduce a level of scope (for the caught exception)
992 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
993 maybeAccept_impl( node->decl, *this );
994 node->cond = visitExpression( node->cond );
995 node->body = visitStatement ( node->body );
996 }
997 VISIT_END( node );
998}
999
1000template< typename pass_type >
1001Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
1002 MUTATE_START( node );
1003 {
1004 // catch statements introduce a level of scope (for the caught exception)
1005 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1006 maybeMutate_impl( node->decl, *this );
1007 node->cond = mutateExpression( node->cond );
1008 node->body = mutateStatement ( node->body );
1009 }
1010 MUTATE_END( Statement, node );
1011}
1012
1013//--------------------------------------------------------------------------
1014// FinallyStmt
1015template< typename pass_type >
1016void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
1017 VISIT_START( node );
1018
1019 maybeAccept_impl( node->block, *this );
1020
1021 VISIT_END( node );
1022}
1023
1024template< typename pass_type >
1025Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
1026 MUTATE_START( node );
1027
1028 maybeMutate_impl( node->block, *this );
1029
1030 MUTATE_END( Statement, node );
1031}
1032
1033//--------------------------------------------------------------------------
1034// WaitForStmt
1035template< typename pass_type >
1036void PassVisitor< pass_type >::visit( WaitForStmt * node ) {
1037 VISIT_START( node );
1038
1039 for( auto & clause : node->clauses ) {
1040 maybeAccept_impl( clause.target.function, *this );
1041 maybeAccept_impl( clause.target.arguments, *this );
1042
1043 maybeAccept_impl( clause.statement, *this );
1044 maybeAccept_impl( clause.condition, *this );
1045 }
1046
1047 maybeAccept_impl( node->timeout.time, *this );
1048 maybeAccept_impl( node->timeout.statement, *this );
1049 maybeAccept_impl( node->timeout.condition, *this );
1050 maybeAccept_impl( node->orelse.statement, *this );
1051 maybeAccept_impl( node->orelse.condition, *this );
1052
1053 VISIT_END( node );
1054}
1055
1056template< typename pass_type >
1057Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
1058 MUTATE_START( node );
1059
1060 for( auto & clause : node->clauses ) {
1061 maybeMutate_impl( clause.target.function, *this );
1062 maybeMutate_impl( clause.target.arguments, *this );
1063
1064 maybeMutate_impl( clause.statement, *this );
1065 maybeMutate_impl( clause.condition, *this );
1066 }
1067
1068 maybeMutate_impl( node->timeout.time, *this );
1069 maybeMutate_impl( node->timeout.statement, *this );
1070 maybeMutate_impl( node->timeout.condition, *this );
1071 maybeMutate_impl( node->orelse.statement, *this );
1072 maybeMutate_impl( node->orelse.condition, *this );
1073
1074 MUTATE_END( Statement, node );
1075}
1076
1077
1078
1079//--------------------------------------------------------------------------
1080// NullStmt
1081template< typename pass_type >
1082void PassVisitor< pass_type >::visit( WithStmt * node ) {
1083 VISIT_START( node );
1084 maybeAccept_impl( node->exprs, *this );
1085 {
1086 // catch statements introduce a level of scope (for the caught exception)
1087 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1088 indexerAddWith( node->exprs, node );
1089 maybeAccept_impl( node->stmt, *this );
1090 }
1091 VISIT_END( node );
1092}
1093
1094template< typename pass_type >
1095Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) {
1096 MUTATE_START( node );
1097 maybeMutate_impl( node->exprs, *this );
1098 {
1099 // catch statements introduce a level of scope (for the caught exception)
1100 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1101 indexerAddWith( node->exprs, node );
1102 maybeMutate_impl( node->stmt, *this );
1103 }
1104 MUTATE_END( Statement, node );
1105}
1106
1107//--------------------------------------------------------------------------
1108// NullStmt
1109template< typename pass_type >
1110void PassVisitor< pass_type >::visit( NullStmt * node ) {
1111 VISIT_START( node );
1112 VISIT_END( node );
1113}
1114
1115template< typename pass_type >
1116NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
1117 MUTATE_START( node );
1118 MUTATE_END( NullStmt, node );
1119}
1120
1121//--------------------------------------------------------------------------
1122// DeclStmt
1123template< typename pass_type >
1124void PassVisitor< pass_type >::visit( DeclStmt * node ) {
1125 VISIT_START( node );
1126
1127 maybeAccept_impl( node->decl, *this );
1128
1129 VISIT_END( node );
1130}
1131
1132template< typename pass_type >
1133Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
1134 MUTATE_START( node );
1135
1136 maybeMutate_impl( node->decl, *this );
1137
1138 MUTATE_END( Statement, node );
1139}
1140
1141//--------------------------------------------------------------------------
1142// ImplicitCtorDtorStmt
1143template< typename pass_type >
1144void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
1145 VISIT_START( node );
1146
1147 maybeAccept_impl( node->callStmt, *this );
1148
1149 VISIT_END( node );
1150}
1151
1152template< typename pass_type >
1153Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
1154 MUTATE_START( node );
1155
1156 maybeMutate_impl( node->callStmt, *this );
1157
1158 MUTATE_END( Statement, node );
1159}
1160
1161//--------------------------------------------------------------------------
1162// ApplicationExpr
1163template< typename pass_type >
1164void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
1165 VISIT_START( node );
1166
1167 indexerScopedAccept( node->result , *this );
1168 maybeAccept_impl ( node->function, *this );
1169 maybeAccept_impl ( node->args , *this );
1170
1171 VISIT_END( node );
1172}
1173
1174template< typename pass_type >
1175Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) {
1176 MUTATE_START( node );
1177
1178 indexerScopedMutate( node->env , *this );
1179 indexerScopedMutate( node->result , *this );
1180 maybeMutate_impl ( node->function, *this );
1181 maybeMutate_impl ( node->args , *this );
1182
1183 MUTATE_END( Expression, node );
1184}
1185
1186//--------------------------------------------------------------------------
1187// UntypedExpr
1188template< typename pass_type >
1189void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
1190 VISIT_START( node );
1191
1192 // maybeAccept_impl( node->get_env(), *this );
1193 indexerScopedAccept( node->result, *this );
1194
1195 for ( auto expr : node->args ) {
1196 visitExpression( expr );
1197 }
1198
1199 VISIT_END( node );
1200}
1201
1202template< typename pass_type >
1203Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
1204 MUTATE_START( node );
1205
1206 indexerScopedMutate( node->env , *this );
1207 indexerScopedMutate( node->result, *this );
1208
1209 for ( auto& expr : node->args ) {
1210 expr = mutateExpression( expr );
1211 }
1212
1213 MUTATE_END( Expression, node );
1214}
1215
1216//--------------------------------------------------------------------------
1217// NameExpr
1218template< typename pass_type >
1219void PassVisitor< pass_type >::visit( NameExpr * node ) {
1220 VISIT_START( node );
1221
1222 indexerScopedAccept( node->result, *this );
1223
1224 VISIT_END( node );
1225}
1226
1227template< typename pass_type >
1228Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
1229 MUTATE_START( node );
1230
1231 indexerScopedMutate( node->env , *this );
1232 indexerScopedMutate( node->result, *this );
1233
1234 MUTATE_END( Expression, node );
1235}
1236
1237//--------------------------------------------------------------------------
1238// CastExpr
1239template< typename pass_type >
1240void PassVisitor< pass_type >::visit( CastExpr * node ) {
1241 VISIT_START( node );
1242
1243 indexerScopedAccept( node->result, *this );
1244 maybeAccept_impl ( node->arg , *this );
1245
1246 VISIT_END( node );
1247}
1248
1249template< typename pass_type >
1250Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
1251 MUTATE_START( node );
1252
1253 indexerScopedMutate( node->env , *this );
1254 indexerScopedMutate( node->result, *this );
1255 maybeMutate_impl ( node->arg , *this );
1256
1257 MUTATE_END( Expression, node );
1258}
1259
1260//--------------------------------------------------------------------------
1261// VirtualCastExpr
1262template< typename pass_type >
1263void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) {
1264 VISIT_START( node );
1265
1266 indexerScopedAccept( node->result, *this );
1267 maybeAccept_impl( node->arg, *this );
1268
1269 VISIT_END( node );
1270}
1271
1272template< typename pass_type >
1273Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
1274 MUTATE_START( node );
1275
1276 indexerScopedMutate( node->env , *this );
1277 indexerScopedMutate( node->result, *this );
1278 maybeMutate_impl ( node->arg , *this );
1279
1280 MUTATE_END( Expression, node );
1281}
1282
1283//--------------------------------------------------------------------------
1284// AddressExpr
1285template< typename pass_type >
1286void PassVisitor< pass_type >::visit( AddressExpr * node ) {
1287 VISIT_START( node );
1288
1289 indexerScopedAccept( node->result, *this );
1290 maybeAccept_impl ( node->arg , *this );
1291
1292 VISIT_END( node );
1293}
1294
1295template< typename pass_type >
1296Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
1297 MUTATE_START( node );
1298
1299 indexerScopedMutate( node->env , *this );
1300 indexerScopedMutate( node->result, *this );
1301 maybeMutate_impl ( node->arg , *this );
1302
1303 MUTATE_END( Expression, node );
1304}
1305
1306//--------------------------------------------------------------------------
1307// LabelAddressExpr
1308template< typename pass_type >
1309void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
1310 VISIT_START( node );
1311
1312 indexerScopedAccept( node->result, *this );
1313
1314 VISIT_END( node );
1315}
1316
1317template< typename pass_type >
1318Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
1319 MUTATE_START( node );
1320
1321 indexerScopedMutate( node->env , *this );
1322 indexerScopedMutate( node->result, *this );
1323
1324 MUTATE_END( Expression, node );
1325}
1326
1327//--------------------------------------------------------------------------
1328// UntypedMemberExpr
1329template< typename pass_type >
1330void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
1331 VISIT_START( node );
1332
1333 indexerScopedAccept( node->result , *this );
1334 maybeAccept_impl ( node->aggregate, *this );
1335 maybeAccept_impl ( node->member , *this );
1336
1337 VISIT_END( node );
1338}
1339
1340template< typename pass_type >
1341Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) {
1342 MUTATE_START( node );
1343
1344 indexerScopedMutate( node->env , *this );
1345 indexerScopedMutate( node->result , *this );
1346 maybeMutate_impl ( node->aggregate, *this );
1347 maybeMutate_impl ( node->member , *this );
1348
1349 MUTATE_END( Expression, node );
1350}
1351
1352//--------------------------------------------------------------------------
1353// MemberExpr
1354template< typename pass_type >
1355void PassVisitor< pass_type >::visit( MemberExpr * node ) {
1356 VISIT_START( node );
1357
1358 indexerScopedAccept( node->result , *this );
1359 maybeAccept_impl ( node->aggregate, *this );
1360
1361 VISIT_END( node );
1362}
1363
1364template< typename pass_type >
1365Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
1366 MUTATE_START( node );
1367
1368 indexerScopedMutate( node->env , *this );
1369 indexerScopedMutate( node->result , *this );
1370 maybeMutate_impl ( node->aggregate, *this );
1371
1372 MUTATE_END( Expression, node );
1373}
1374
1375//--------------------------------------------------------------------------
1376// VariableExpr
1377template< typename pass_type >
1378void PassVisitor< pass_type >::visit( VariableExpr * node ) {
1379 VISIT_START( node );
1380
1381 indexerScopedAccept( node->result, *this );
1382
1383 VISIT_END( node );
1384}
1385
1386template< typename pass_type >
1387Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
1388 MUTATE_START( node );
1389
1390 indexerScopedMutate( node->env , *this );
1391 indexerScopedMutate( node->result, *this );
1392
1393 MUTATE_END( Expression, node );
1394}
1395
1396//--------------------------------------------------------------------------
1397// ConstantExpr
1398template< typename pass_type >
1399void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
1400 VISIT_START( node );
1401
1402 indexerScopedAccept( node->result , *this );
1403 maybeAccept_impl ( &node->constant, *this );
1404
1405 VISIT_END( node );
1406}
1407
1408template< typename pass_type >
1409Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) {
1410 MUTATE_START( node );
1411
1412 indexerScopedMutate( node->env , *this );
1413 indexerScopedMutate( node->result, *this );
1414 Constant * ptr = &node->constant;
1415 maybeMutate_impl( ptr, *this );
1416 node->constant = *ptr;
1417
1418 MUTATE_END( Expression, node );
1419}
1420
1421//--------------------------------------------------------------------------
1422// SizeofExpr
1423template< typename pass_type >
1424void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
1425 VISIT_START( node );
1426
1427 indexerScopedAccept( node->result, *this );
1428 if ( node->get_isType() ) {
1429 maybeAccept_impl( node->type, *this );
1430 } else {
1431 maybeAccept_impl( node->expr, *this );
1432 }
1433
1434 VISIT_END( node );
1435}
1436
1437template< typename pass_type >
1438Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
1439 MUTATE_START( node );
1440
1441 indexerScopedMutate( node->env , *this );
1442 indexerScopedMutate( node->result, *this );
1443 if ( node->get_isType() ) {
1444 maybeMutate_impl( node->type, *this );
1445 } else {
1446 maybeMutate_impl( node->expr, *this );
1447 }
1448
1449 MUTATE_END( Expression, node );
1450}
1451
1452//--------------------------------------------------------------------------
1453// AlignofExpr
1454template< typename pass_type >
1455void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
1456 VISIT_START( node );
1457
1458 indexerScopedAccept( node->result, *this );
1459 if ( node->get_isType() ) {
1460 maybeAccept_impl( node->type, *this );
1461 } else {
1462 maybeAccept_impl( node->expr, *this );
1463 }
1464
1465 VISIT_END( node );
1466}
1467
1468template< typename pass_type >
1469Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
1470 MUTATE_START( node );
1471
1472 indexerScopedMutate( node->env , *this );
1473 indexerScopedMutate( node->result, *this );
1474 if ( node->get_isType() ) {
1475 maybeMutate_impl( node->type, *this );
1476 } else {
1477 maybeMutate_impl( node->expr, *this );
1478 }
1479
1480 MUTATE_END( Expression, node );
1481}
1482
1483//--------------------------------------------------------------------------
1484// UntypedOffsetofExpr
1485template< typename pass_type >
1486void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
1487 VISIT_START( node );
1488
1489 indexerScopedAccept( node->result, *this );
1490 maybeAccept_impl ( node->type , *this );
1491
1492 VISIT_END( node );
1493}
1494
1495template< typename pass_type >
1496Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
1497 MUTATE_START( node );
1498
1499 indexerScopedMutate( node->env , *this );
1500 indexerScopedMutate( node->result, *this );
1501 maybeMutate_impl ( node->type , *this );
1502
1503 MUTATE_END( Expression, node );
1504}
1505
1506//--------------------------------------------------------------------------
1507// OffsetofExpr
1508template< typename pass_type >
1509void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
1510 VISIT_START( node );
1511
1512 indexerScopedAccept( node->result, *this );
1513 maybeAccept_impl ( node->type , *this );
1514
1515 VISIT_END( node );
1516}
1517
1518template< typename pass_type >
1519Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
1520 MUTATE_START( node );
1521
1522 indexerScopedMutate( node->env , *this );
1523 indexerScopedMutate( node->result, *this );
1524 maybeMutate_impl ( node->type , *this );
1525
1526 MUTATE_END( Expression, node );
1527}
1528
1529//--------------------------------------------------------------------------
1530// OffsetPackExpr
1531template< typename pass_type >
1532void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
1533 VISIT_START( node );
1534
1535 indexerScopedAccept( node->result, *this );
1536 maybeAccept_impl ( node->type , *this );
1537
1538 VISIT_END( node );
1539}
1540
1541template< typename pass_type >
1542Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
1543 MUTATE_START( node );
1544
1545 indexerScopedMutate( node->env , *this );
1546 indexerScopedMutate( node->result, *this );
1547 maybeMutate_impl ( node->type , *this );
1548
1549 MUTATE_END( Expression, node );
1550}
1551
1552//--------------------------------------------------------------------------
1553// AttrExpr
1554template< typename pass_type >
1555void PassVisitor< pass_type >::visit( AttrExpr * node ) {
1556 VISIT_START( node );
1557
1558 indexerScopedAccept( node->result, *this );
1559 if ( node->get_isType() ) {
1560 maybeAccept_impl( node->type, *this );
1561 } else {
1562 maybeAccept_impl( node->expr, *this );
1563 }
1564
1565 VISIT_END( node );
1566}
1567
1568template< typename pass_type >
1569Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) {
1570 MUTATE_START( node );
1571
1572 indexerScopedMutate( node->env , *this );
1573 indexerScopedMutate( node->result, *this );
1574 if ( node->get_isType() ) {
1575 maybeMutate_impl( node->type, *this );
1576 } else {
1577 maybeMutate_impl( node->expr, *this );
1578 }
1579
1580 MUTATE_END( Expression, node );
1581}
1582
1583//--------------------------------------------------------------------------
1584// LogicalExpr
1585template< typename pass_type >
1586void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
1587 VISIT_START( node );
1588
1589 indexerScopedAccept( node->result, *this );
1590 maybeAccept_impl ( node->arg1 , *this );
1591 maybeAccept_impl ( node->arg2 , *this );
1592
1593 VISIT_END( node );
1594}
1595
1596template< typename pass_type >
1597Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) {
1598 MUTATE_START( node );
1599
1600 indexerScopedMutate( node->env , *this );
1601 indexerScopedMutate( node->result, *this );
1602 maybeMutate_impl ( node->arg1 , *this );
1603 maybeMutate_impl ( node->arg2 , *this );
1604
1605 MUTATE_END( Expression, node );
1606}
1607
1608//--------------------------------------------------------------------------
1609// ConditionalExpr
1610template< typename pass_type >
1611void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
1612 VISIT_START( node );
1613
1614 indexerScopedAccept( node->result, *this );
1615 maybeAccept_impl ( node->arg1 , *this );
1616 maybeAccept_impl ( node->arg2 , *this );
1617 maybeAccept_impl ( node->arg3 , *this );
1618
1619 VISIT_END( node );
1620}
1621
1622template< typename pass_type >
1623Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
1624 MUTATE_START( node );
1625
1626 indexerScopedMutate( node->env , *this );
1627 indexerScopedMutate( node->result, *this );
1628 maybeMutate_impl ( node->arg1 , *this );
1629 maybeMutate_impl ( node->arg2 , *this );
1630 maybeMutate_impl ( node->arg3 , *this );
1631
1632 MUTATE_END( Expression, node );
1633}
1634
1635//--------------------------------------------------------------------------
1636// CommaExpr
1637template< typename pass_type >
1638void PassVisitor< pass_type >::visit( CommaExpr * node ) {
1639 VISIT_START( node );
1640
1641 indexerScopedAccept( node->result, *this );
1642 maybeAccept_impl ( node->arg1 , *this );
1643 maybeAccept_impl ( node->arg2 , *this );
1644
1645 VISIT_END( node );
1646}
1647
1648template< typename pass_type >
1649Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
1650 MUTATE_START( node );
1651
1652 indexerScopedMutate( node->env , *this );
1653 indexerScopedMutate( node->result, *this );
1654 maybeMutate_impl ( node->arg1 , *this );
1655 maybeMutate_impl ( node->arg2 , *this );
1656
1657 MUTATE_END( Expression, node );
1658}
1659
1660//--------------------------------------------------------------------------
1661// TypeExpr
1662template< typename pass_type >
1663void PassVisitor< pass_type >::visit( TypeExpr * node ) {
1664 VISIT_START( node );
1665
1666 indexerScopedAccept( node->result, *this );
1667 maybeAccept_impl ( node->type, *this );
1668
1669 VISIT_END( node );
1670}
1671
1672template< typename pass_type >
1673Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
1674 MUTATE_START( node );
1675
1676 indexerScopedMutate( node->env , *this );
1677 indexerScopedMutate( node->result, *this );
1678 maybeMutate_impl ( node->type , *this );
1679
1680 MUTATE_END( Expression, node );
1681}
1682
1683//--------------------------------------------------------------------------
1684// AsmExpr
1685template< typename pass_type >
1686void PassVisitor< pass_type >::visit( AsmExpr * node ) {
1687 VISIT_START( node );
1688
1689 indexerScopedAccept( node->result , *this );
1690 maybeAccept_impl ( node->inout , *this );
1691 maybeAccept_impl ( node->constraint, *this );
1692 maybeAccept_impl ( node->operand , *this );
1693
1694 VISIT_END( node );
1695}
1696
1697template< typename pass_type >
1698Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) {
1699 MUTATE_START( node );
1700
1701 indexerScopedMutate( node->env , *this );
1702 indexerScopedMutate( node->result , *this );
1703 maybeMutate_impl ( node->inout , *this );
1704 maybeMutate_impl ( node->constraint, *this );
1705 maybeMutate_impl ( node->operand , *this );
1706
1707 MUTATE_END( Expression, node );
1708}
1709
1710//--------------------------------------------------------------------------
1711// ImplicitCopyCtorExpr
1712template< typename pass_type >
1713void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
1714 VISIT_START( node );
1715
1716 indexerScopedAccept( node->result , *this );
1717 maybeAccept_impl ( node->callExpr , *this );
1718 maybeAccept_impl ( node->tempDecls , *this );
1719 maybeAccept_impl ( node->returnDecls, *this );
1720 maybeAccept_impl ( node->dtors , *this );
1721
1722 VISIT_END( node );
1723}
1724
1725template< typename pass_type >
1726Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) {
1727 MUTATE_START( node );
1728
1729 indexerScopedMutate( node->env , *this );
1730 indexerScopedMutate( node->result , *this );
1731 maybeMutate_impl ( node->callExpr , *this );
1732 maybeMutate_impl ( node->tempDecls , *this );
1733 maybeMutate_impl ( node->returnDecls, *this );
1734 maybeMutate_impl ( node->dtors , *this );
1735
1736 MUTATE_END( Expression, node );
1737}
1738
1739//--------------------------------------------------------------------------
1740// ConstructorExpr
1741template< typename pass_type >
1742void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
1743 VISIT_START( node );
1744
1745 indexerScopedAccept( node->result , *this );
1746 maybeAccept_impl ( node->callExpr, *this );
1747
1748 VISIT_END( node );
1749}
1750
1751template< typename pass_type >
1752Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) {
1753 MUTATE_START( node );
1754
1755 indexerScopedMutate( node->env , *this );
1756 indexerScopedMutate( node->result , *this );
1757 maybeMutate_impl ( node->callExpr, *this );
1758
1759 MUTATE_END( Expression, node );
1760}
1761
1762//--------------------------------------------------------------------------
1763// CompoundLiteralExpr
1764template< typename pass_type >
1765void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
1766 VISIT_START( node );
1767
1768 indexerScopedAccept( node->result , *this );
1769 maybeAccept_impl ( node->initializer, *this );
1770
1771 VISIT_END( node );
1772}
1773
1774template< typename pass_type >
1775Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
1776 MUTATE_START( node );
1777
1778 indexerScopedMutate( node->env , *this );
1779 indexerScopedMutate( node->result , *this );
1780 maybeMutate_impl ( node->initializer, *this );
1781
1782 MUTATE_END( Expression, node );
1783}
1784
1785//--------------------------------------------------------------------------
1786// RangeExpr
1787template< typename pass_type >
1788void PassVisitor< pass_type >::visit( RangeExpr * node ) {
1789 VISIT_START( node );
1790
1791 indexerScopedAccept( node->result, *this );
1792 maybeAccept_impl ( node->low , *this );
1793 maybeAccept_impl ( node->high , *this );
1794
1795 VISIT_END( node );
1796}
1797
1798template< typename pass_type >
1799Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
1800 MUTATE_START( node );
1801
1802 indexerScopedMutate( node->env , *this );
1803 indexerScopedMutate( node->result, *this );
1804 maybeMutate_impl ( node->low , *this );
1805 maybeMutate_impl ( node->high , *this );
1806
1807 MUTATE_END( Expression, node );
1808}
1809
1810//--------------------------------------------------------------------------
1811// UntypedTupleExpr
1812template< typename pass_type >
1813void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
1814 VISIT_START( node );
1815
1816 indexerScopedAccept( node->result, *this );
1817 maybeAccept_impl ( node->exprs , *this );
1818
1819 VISIT_END( node );
1820}
1821
1822template< typename pass_type >
1823Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
1824 MUTATE_START( node );
1825
1826 indexerScopedMutate( node->env , *this );
1827 indexerScopedMutate( node->result, *this );
1828 maybeMutate_impl ( node->exprs , *this );
1829
1830 MUTATE_END( Expression, node );
1831}
1832
1833//--------------------------------------------------------------------------
1834// TupleExpr
1835template< typename pass_type >
1836void PassVisitor< pass_type >::visit( TupleExpr * node ) {
1837 VISIT_START( node );
1838
1839 indexerScopedAccept( node->result, *this );
1840 maybeAccept_impl ( node->exprs , *this );
1841
1842 VISIT_END( node );
1843}
1844
1845template< typename pass_type >
1846Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
1847 MUTATE_START( node );
1848
1849 indexerScopedMutate( node->env , *this );
1850 indexerScopedMutate( node->result, *this );
1851 maybeMutate_impl ( node->exprs , *this );
1852
1853 MUTATE_END( Expression, node );
1854}
1855
1856//--------------------------------------------------------------------------
1857// TupleIndexExpr
1858template< typename pass_type >
1859void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
1860 VISIT_START( node );
1861
1862 indexerScopedAccept( node->result, *this );
1863 maybeAccept_impl ( node->tuple , *this );
1864
1865 VISIT_END( node );
1866}
1867
1868template< typename pass_type >
1869Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
1870 MUTATE_START( node );
1871
1872 indexerScopedMutate( node->env , *this );
1873 indexerScopedMutate( node->result, *this );
1874 maybeMutate_impl ( node->tuple , *this );
1875
1876 MUTATE_END( Expression, node );
1877}
1878
1879//--------------------------------------------------------------------------
1880// TupleAssignExpr
1881template< typename pass_type >
1882void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
1883 VISIT_START( node );
1884
1885 indexerScopedAccept( node->result , *this );
1886 maybeAccept_impl ( node->stmtExpr, *this );
1887
1888 VISIT_END( node );
1889}
1890
1891template< typename pass_type >
1892Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) {
1893 MUTATE_START( node );
1894
1895 indexerScopedMutate( node->env , *this );
1896 indexerScopedMutate( node->result , *this );
1897 maybeMutate_impl ( node->stmtExpr, *this );
1898
1899 MUTATE_END( Expression, node );
1900}
1901
1902//--------------------------------------------------------------------------
1903// StmtExpr
1904template< typename pass_type >
1905void PassVisitor< pass_type >::visit( StmtExpr * node ) {
1906 VISIT_START( node );
1907
1908 // don't want statements from outer CompoundStmts to be added to this StmtExpr
1909 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() );
1910 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
1911 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
1912
1913 indexerScopedAccept( node->result , *this );
1914 maybeAccept_impl ( node->statements , *this );
1915 maybeAccept_impl ( node->returnDecls, *this );
1916 maybeAccept_impl ( node->dtors , *this );
1917
1918 VISIT_END( node );
1919}
1920
1921template< typename pass_type >
1922Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
1923 MUTATE_START( node );
1924
1925 // don't want statements from outer CompoundStmts to be added to this StmtExpr
1926 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() );
1927 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
1928 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
1929
1930 indexerScopedMutate( node->result , *this );
1931 maybeMutate_impl ( node->statements , *this );
1932 maybeMutate_impl ( node->returnDecls, *this );
1933 maybeMutate_impl ( node->dtors , *this );
1934
1935 MUTATE_END( Expression, node );
1936}
1937
1938//--------------------------------------------------------------------------
1939// UniqueExpr
1940template< typename pass_type >
1941void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
1942 VISIT_START( node );
1943
1944 indexerScopedAccept( node->result, *this );
1945 maybeAccept_impl ( node->expr , *this );
1946
1947 VISIT_END( node );
1948}
1949
1950template< typename pass_type >
1951Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
1952 MUTATE_START( node );
1953
1954 indexerScopedMutate( node->env , *this );
1955 indexerScopedMutate( node->result, *this );
1956 maybeMutate_impl ( node->expr , *this );
1957
1958 MUTATE_END( Expression, node );
1959}
1960
1961//--------------------------------------------------------------------------
1962// UntypedInitExpr
1963template< typename pass_type >
1964void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) {
1965 VISIT_START( node );
1966
1967 indexerScopedAccept( node->result, *this );
1968 maybeAccept_impl ( node->expr , *this );
1969 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
1970
1971 VISIT_END( node );
1972}
1973
1974template< typename pass_type >
1975Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
1976 MUTATE_START( node );
1977
1978 indexerScopedMutate( node->env , *this );
1979 indexerScopedMutate( node->result, *this );
1980 maybeMutate_impl ( node->expr , *this );
1981 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
1982
1983 MUTATE_END( Expression, node );
1984}
1985
1986//--------------------------------------------------------------------------
1987// InitExpr
1988template< typename pass_type >
1989void PassVisitor< pass_type >::visit( InitExpr * node ) {
1990 VISIT_START( node );
1991
1992 indexerScopedAccept( node->result, *this );
1993 maybeAccept_impl ( node->expr , *this );
1994 maybeAccept_impl ( node->designation, *this );
1995
1996 VISIT_END( node );
1997}
1998
1999template< typename pass_type >
2000Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
2001 MUTATE_START( node );
2002
2003 indexerScopedMutate( node->env , *this );
2004 indexerScopedMutate( node->result, *this );
2005 maybeMutate_impl ( node->expr , *this );
2006 maybeMutate_impl ( node->designation, *this );
2007
2008 MUTATE_END( Expression, node );
2009}
2010
2011//--------------------------------------------------------------------------
2012// DeletedExpr
2013template< typename pass_type >
2014void PassVisitor< pass_type >::visit( DeletedExpr * node ) {
2015 VISIT_START( node );
2016
2017 indexerScopedAccept( node->result, *this );
2018 maybeAccept_impl( node->expr, *this );
2019 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
2020
2021 VISIT_END( node );
2022}
2023
2024template< typename pass_type >
2025Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
2026 MUTATE_START( node );
2027
2028 indexerScopedMutate( node->env, *this );
2029 indexerScopedMutate( node->result, *this );
2030 maybeMutate_impl( node->expr, *this );
2031
2032 MUTATE_END( Expression, node );
2033}
2034
2035//--------------------------------------------------------------------------
2036// VoidType
2037template< typename pass_type >
2038void PassVisitor< pass_type >::visit( VoidType * node ) {
2039 VISIT_START( node );
2040
2041 maybeAccept_impl( node->forall, *this );
2042
2043 VISIT_END( node );
2044}
2045
2046template< typename pass_type >
2047Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
2048 MUTATE_START( node );
2049
2050 maybeMutate_impl( node->forall, *this );
2051
2052 MUTATE_END( Type, node );
2053}
2054
2055//--------------------------------------------------------------------------
2056// BasicType
2057template< typename pass_type >
2058void PassVisitor< pass_type >::visit( BasicType * node ) {
2059 VISIT_START( node );
2060
2061 maybeAccept_impl( node->forall, *this );
2062
2063 VISIT_END( node );
2064}
2065
2066template< typename pass_type >
2067Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
2068 MUTATE_START( node );
2069
2070 maybeMutate_impl( node->forall, *this );
2071
2072 MUTATE_END( Type, node );
2073}
2074
2075//--------------------------------------------------------------------------
2076// PointerType
2077template< typename pass_type >
2078void PassVisitor< pass_type >::visit( PointerType * node ) {
2079 VISIT_START( node );
2080
2081 maybeAccept_impl( node->forall, *this );
2082 // xxx - should PointerType visit/mutate dimension?
2083 maybeAccept_impl( node->base, *this );
2084
2085 VISIT_END( node );
2086}
2087
2088template< typename pass_type >
2089Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
2090 MUTATE_START( node );
2091
2092 maybeMutate_impl( node->forall, *this );
2093 // xxx - should PointerType visit/mutate dimension?
2094 maybeMutate_impl( node->base, *this );
2095
2096 MUTATE_END( Type, node );
2097}
2098
2099//--------------------------------------------------------------------------
2100// ArrayType
2101template< typename pass_type >
2102void PassVisitor< pass_type >::visit( ArrayType * node ) {
2103 VISIT_START( node );
2104
2105 maybeAccept_impl( node->forall, *this );
2106 maybeAccept_impl( node->dimension, *this );
2107 maybeAccept_impl( node->base, *this );
2108
2109 VISIT_END( node );
2110}
2111
2112template< typename pass_type >
2113Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
2114 MUTATE_START( node );
2115
2116 maybeMutate_impl( node->forall, *this );
2117 maybeMutate_impl( node->dimension, *this );
2118 maybeMutate_impl( node->base, *this );
2119
2120 MUTATE_END( Type, node );
2121}
2122
2123//--------------------------------------------------------------------------
2124// ReferenceType
2125template< typename pass_type >
2126void PassVisitor< pass_type >::visit( ReferenceType * node ) {
2127 VISIT_START( node );
2128
2129 maybeAccept_impl( node->forall, *this );
2130 maybeAccept_impl( node->base, *this );
2131
2132 VISIT_END( node );
2133}
2134
2135template< typename pass_type >
2136Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
2137 MUTATE_START( node );
2138
2139 maybeMutate_impl( node->forall, *this );
2140 maybeMutate_impl( node->base, *this );
2141
2142 MUTATE_END( Type, node );
2143}
2144
2145//--------------------------------------------------------------------------
2146// FunctionType
2147template< typename pass_type >
2148void PassVisitor< pass_type >::visit( FunctionType * node ) {
2149 VISIT_START( node );
2150
2151 maybeAccept_impl( node->forall, *this );
2152 maybeAccept_impl( node->returnVals, *this );
2153 maybeAccept_impl( node->parameters, *this );
2154
2155 VISIT_END( node );
2156}
2157
2158template< typename pass_type >
2159Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
2160 MUTATE_START( node );
2161
2162 maybeMutate_impl( node->forall, *this );
2163 maybeMutate_impl( node->returnVals, *this );
2164 maybeMutate_impl( node->parameters, *this );
2165
2166 MUTATE_END( Type, node );
2167}
2168
2169//--------------------------------------------------------------------------
2170// StructInstType
2171template< typename pass_type >
2172void PassVisitor< pass_type >::visit( StructInstType * node ) {
2173 VISIT_START( node );
2174
2175 indexerAddStruct( node->name );
2176
2177 {
2178 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2179 maybeAccept_impl( node->forall , *this );
2180 maybeAccept_impl( node->parameters, *this );
2181 }
2182
2183 VISIT_END( node );
2184}
2185
2186template< typename pass_type >
2187Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
2188 MUTATE_START( node );
2189
2190 indexerAddStruct( node->name );
2191
2192 {
2193 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2194 maybeMutate_impl( node->forall , *this );
2195 maybeMutate_impl( node->parameters, *this );
2196 }
2197
2198 MUTATE_END( Type, node );
2199}
2200
2201//--------------------------------------------------------------------------
2202// UnionInstType
2203template< typename pass_type >
2204void PassVisitor< pass_type >::visit( UnionInstType * node ) {
2205 VISIT_START( node );
2206
2207 indexerAddStruct( node->name );
2208
2209 {
2210 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2211 maybeAccept_impl( node->forall , *this );
2212 maybeAccept_impl( node->parameters, *this );
2213 }
2214
2215 VISIT_END( node );
2216}
2217
2218template< typename pass_type >
2219Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
2220 MUTATE_START( node );
2221
2222 indexerAddStruct( node->name );
2223
2224 {
2225 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2226 maybeMutate_impl( node->forall , *this );
2227 maybeMutate_impl( node->parameters, *this );
2228 }
2229
2230 MUTATE_END( Type, node );
2231}
2232
2233//--------------------------------------------------------------------------
2234// EnumInstType
2235template< typename pass_type >
2236void PassVisitor< pass_type >::visit( EnumInstType * node ) {
2237 VISIT_START( node );
2238
2239 maybeAccept_impl( node->forall, *this );
2240 maybeAccept_impl( node->parameters, *this );
2241
2242 VISIT_END( node );
2243}
2244
2245template< typename pass_type >
2246Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
2247 MUTATE_START( node );
2248
2249 maybeMutate_impl( node->forall, *this );
2250 maybeMutate_impl( node->parameters, *this );
2251
2252 MUTATE_END( Type, node );
2253}
2254
2255//--------------------------------------------------------------------------
2256// TraitInstType
2257template< typename pass_type >
2258void PassVisitor< pass_type >::visit( TraitInstType * node ) {
2259 VISIT_START( node );
2260
2261 maybeAccept_impl( node->forall , *this );
2262 maybeAccept_impl( node->parameters, *this );
2263
2264 VISIT_END( node );
2265}
2266
2267template< typename pass_type >
2268Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
2269 MUTATE_START( node );
2270
2271 maybeMutate_impl( node->forall , *this );
2272 maybeMutate_impl( node->parameters, *this );
2273
2274 MUTATE_END( Type, node );
2275}
2276
2277//--------------------------------------------------------------------------
2278// TypeInstType
2279template< typename pass_type >
2280void PassVisitor< pass_type >::visit( TypeInstType * node ) {
2281 VISIT_START( node );
2282
2283 maybeAccept_impl( node->forall , *this );
2284 maybeAccept_impl( node->parameters, *this );
2285
2286 VISIT_END( node );
2287}
2288
2289template< typename pass_type >
2290Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
2291 MUTATE_START( node );
2292
2293 maybeMutate_impl( node->forall , *this );
2294 maybeMutate_impl( node->parameters, *this );
2295
2296 MUTATE_END( Type, node );
2297}
2298
2299//--------------------------------------------------------------------------
2300// TupleType
2301template< typename pass_type >
2302void PassVisitor< pass_type >::visit( TupleType * node ) {
2303 VISIT_START( node );
2304
2305 maybeAccept_impl( node->forall, *this );
2306 maybeAccept_impl( node->types, *this );
2307 maybeAccept_impl( node->members, *this );
2308
2309 VISIT_END( node );
2310}
2311
2312template< typename pass_type >
2313Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
2314 MUTATE_START( node );
2315
2316 maybeMutate_impl( node->forall, *this );
2317 maybeMutate_impl( node->types, *this );
2318 maybeMutate_impl( node->members, *this );
2319
2320 MUTATE_END( Type, node );
2321}
2322
2323//--------------------------------------------------------------------------
2324// TypeofType
2325template< typename pass_type >
2326void PassVisitor< pass_type >::visit( TypeofType * node ) {
2327 VISIT_START( node );
2328
2329 assert( node->expr );
2330 maybeAccept_impl( node->expr, *this );
2331
2332 VISIT_END( node );
2333}
2334
2335template< typename pass_type >
2336Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
2337 MUTATE_START( node );
2338
2339 assert( node->expr );
2340 maybeMutate_impl( node->expr, *this );
2341
2342 MUTATE_END( Type, node );
2343}
2344
2345//--------------------------------------------------------------------------
2346// AttrType
2347template< typename pass_type >
2348void PassVisitor< pass_type >::visit( AttrType * node ) {
2349 VISIT_START( node );
2350
2351 if ( node->isType ) {
2352 assert( node->type );
2353 maybeAccept_impl( node->type, *this );
2354 } else {
2355 assert( node->expr );
2356 maybeAccept_impl( node->expr, *this );
2357 } // if
2358
2359 VISIT_END( node );
2360}
2361
2362template< typename pass_type >
2363Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
2364 MUTATE_START( node );
2365
2366 if ( node->isType ) {
2367 assert( node->type );
2368 maybeMutate_impl( node->type, *this );
2369 } else {
2370 assert( node->expr );
2371 maybeMutate_impl( node->expr, *this );
2372 } // if
2373
2374 MUTATE_END( Type, node );
2375}
2376
2377//--------------------------------------------------------------------------
2378// VarArgsType
2379template< typename pass_type >
2380void PassVisitor< pass_type >::visit( VarArgsType * node ) {
2381 VISIT_START( node );
2382
2383 maybeAccept_impl( node->forall, *this );
2384
2385 VISIT_END( node );
2386}
2387
2388template< typename pass_type >
2389Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
2390 MUTATE_START( node );
2391
2392 maybeMutate_impl( node->forall, *this );
2393
2394 MUTATE_END( Type, node );
2395}
2396
2397//--------------------------------------------------------------------------
2398// ZeroType
2399template< typename pass_type >
2400void PassVisitor< pass_type >::visit( ZeroType * node ) {
2401 VISIT_START( node );
2402
2403 maybeAccept_impl( node->forall, *this );
2404
2405 VISIT_END( node );
2406}
2407
2408template< typename pass_type >
2409Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
2410 MUTATE_START( node );
2411
2412 maybeMutate_impl( node->forall, *this );
2413
2414 MUTATE_END( Type, node );
2415}
2416
2417//--------------------------------------------------------------------------
2418// OneType
2419template< typename pass_type >
2420void PassVisitor< pass_type >::visit( OneType * node ) {
2421 VISIT_START( node );
2422
2423 maybeAccept_impl( node->forall, *this );
2424
2425 VISIT_END( node );
2426}
2427
2428template< typename pass_type >
2429Type * PassVisitor< pass_type >::mutate( OneType * node ) {
2430 MUTATE_START( node );
2431
2432 maybeMutate_impl( node->forall, *this );
2433
2434 MUTATE_END( Type, node );
2435}
2436
2437//--------------------------------------------------------------------------
2438// Designation
2439template< typename pass_type >
2440void PassVisitor< pass_type >::visit( Designation * node ) {
2441 VISIT_START( node );
2442
2443 maybeAccept_impl( node->designators, *this );
2444
2445 VISIT_END( node );
2446}
2447
2448template< typename pass_type >
2449Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
2450 MUTATE_START( node );
2451
2452 maybeMutate_impl( node->designators, *this );
2453
2454 MUTATE_END( Designation, node );
2455}
2456
2457//--------------------------------------------------------------------------
2458// SingleInit
2459template< typename pass_type >
2460void PassVisitor< pass_type >::visit( SingleInit * node ) {
2461 VISIT_START( node );
2462
2463 visitExpression( node->value );
2464
2465 VISIT_END( node );
2466}
2467
2468template< typename pass_type >
2469Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
2470 MUTATE_START( node );
2471
2472 node->value = mutateExpression( node->value );
2473
2474 MUTATE_END( Initializer, node );
2475}
2476
2477//--------------------------------------------------------------------------
2478// ListInit
2479template< typename pass_type >
2480void PassVisitor< pass_type >::visit( ListInit * node ) {
2481 VISIT_START( node );
2482
2483 maybeAccept_impl( node->designations, *this );
2484 maybeAccept_impl( node->initializers, *this );
2485
2486 VISIT_END( node );
2487}
2488
2489template< typename pass_type >
2490Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
2491 MUTATE_START( node );
2492
2493 maybeMutate_impl( node->designations, *this );
2494 maybeMutate_impl( node->initializers, *this );
2495
2496 MUTATE_END( Initializer, node );
2497}
2498
2499//--------------------------------------------------------------------------
2500// ConstructorInit
2501template< typename pass_type >
2502void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
2503 VISIT_START( node );
2504
2505 maybeAccept_impl( node->ctor, *this );
2506 maybeAccept_impl( node->dtor, *this );
2507 maybeAccept_impl( node->init, *this );
2508
2509 VISIT_END( node );
2510}
2511
2512template< typename pass_type >
2513Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
2514 MUTATE_START( node );
2515
2516 maybeMutate_impl( node->ctor, *this );
2517 maybeMutate_impl( node->dtor, *this );
2518 maybeMutate_impl( node->init, *this );
2519
2520 MUTATE_END( Initializer, node );
2521}
2522
2523//--------------------------------------------------------------------------
2524// Subrange
2525template< typename pass_type >
2526void PassVisitor< pass_type >::visit( Subrange * node ) {
2527 VISIT_START( node );
2528
2529 VISIT_END( node );
2530}
2531
2532template< typename pass_type >
2533Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) {
2534 MUTATE_START( node );
2535
2536 MUTATE_END( Subrange, node );
2537}
2538
2539//--------------------------------------------------------------------------
2540// Attribute
2541template< typename pass_type >
2542void PassVisitor< pass_type >::visit( Constant * node ) {
2543 VISIT_START( node );
2544
2545 VISIT_END( node );
2546}
2547
2548template< typename pass_type >
2549Constant * PassVisitor< pass_type >::mutate( Constant * node ) {
2550 MUTATE_START( node );
2551
2552 MUTATE_END( Constant, node );
2553}
2554
2555//--------------------------------------------------------------------------
2556// Attribute
2557template< typename pass_type >
2558void PassVisitor< pass_type >::visit( Attribute * node ) {
2559 VISIT_START( node );
2560
2561 maybeAccept_impl( node->parameters, *this );
2562
2563 VISIT_END( node );
2564}
2565
2566template< typename pass_type >
2567Attribute * PassVisitor< pass_type >::mutate( Attribute * node ) {
2568 MUTATE_START( node );
2569
2570 maybeMutate_impl( node->parameters, *this );
2571
2572 MUTATE_END( Attribute, node );
2573}
2574
2575//--------------------------------------------------------------------------
2576// TypeSubstitution
2577template< typename pass_type >
2578TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
2579 MUTATE_START( node );
2580
2581 for ( auto & p : node->typeEnv ) {
2582 indexerScopedMutate( p.second, *this );
2583 }
2584 for ( auto & p : node->varEnv ) {
2585 indexerScopedMutate( p.second, *this );
2586 }
2587
2588 MUTATE_END( TypeSubstitution, node );
2589}
Note: See TracBrowser for help on using the repository browser.