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

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 b91e8c1 was 9a705dc8, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Implement concurrency keyword casts

  • Property mode set to 100644
File size: 74.3 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// KeywordCastExpr
1262template< typename pass_type >
1263void PassVisitor< pass_type >::visit( KeywordCastExpr * 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( KeywordCastExpr * 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// VirtualCastExpr
1285template< typename pass_type >
1286void PassVisitor< pass_type >::visit( VirtualCastExpr * 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( VirtualCastExpr * 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// AddressExpr
1308template< typename pass_type >
1309void PassVisitor< pass_type >::visit( AddressExpr * node ) {
1310 VISIT_START( node );
1311
1312 indexerScopedAccept( node->result, *this );
1313 maybeAccept_impl ( node->arg , *this );
1314
1315 VISIT_END( node );
1316}
1317
1318template< typename pass_type >
1319Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
1320 MUTATE_START( node );
1321
1322 indexerScopedMutate( node->env , *this );
1323 indexerScopedMutate( node->result, *this );
1324 maybeMutate_impl ( node->arg , *this );
1325
1326 MUTATE_END( Expression, node );
1327}
1328
1329//--------------------------------------------------------------------------
1330// LabelAddressExpr
1331template< typename pass_type >
1332void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
1333 VISIT_START( node );
1334
1335 indexerScopedAccept( node->result, *this );
1336
1337 VISIT_END( node );
1338}
1339
1340template< typename pass_type >
1341Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
1342 MUTATE_START( node );
1343
1344 indexerScopedMutate( node->env , *this );
1345 indexerScopedMutate( node->result, *this );
1346
1347 MUTATE_END( Expression, node );
1348}
1349
1350//--------------------------------------------------------------------------
1351// UntypedMemberExpr
1352template< typename pass_type >
1353void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
1354 VISIT_START( node );
1355
1356 indexerScopedAccept( node->result , *this );
1357 maybeAccept_impl ( node->aggregate, *this );
1358 maybeAccept_impl ( node->member , *this );
1359
1360 VISIT_END( node );
1361}
1362
1363template< typename pass_type >
1364Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) {
1365 MUTATE_START( node );
1366
1367 indexerScopedMutate( node->env , *this );
1368 indexerScopedMutate( node->result , *this );
1369 maybeMutate_impl ( node->aggregate, *this );
1370 maybeMutate_impl ( node->member , *this );
1371
1372 MUTATE_END( Expression, node );
1373}
1374
1375//--------------------------------------------------------------------------
1376// MemberExpr
1377template< typename pass_type >
1378void PassVisitor< pass_type >::visit( MemberExpr * node ) {
1379 VISIT_START( node );
1380
1381 indexerScopedAccept( node->result , *this );
1382 maybeAccept_impl ( node->aggregate, *this );
1383
1384 VISIT_END( node );
1385}
1386
1387template< typename pass_type >
1388Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
1389 MUTATE_START( node );
1390
1391 indexerScopedMutate( node->env , *this );
1392 indexerScopedMutate( node->result , *this );
1393 maybeMutate_impl ( node->aggregate, *this );
1394
1395 MUTATE_END( Expression, node );
1396}
1397
1398//--------------------------------------------------------------------------
1399// VariableExpr
1400template< typename pass_type >
1401void PassVisitor< pass_type >::visit( VariableExpr * node ) {
1402 VISIT_START( node );
1403
1404 indexerScopedAccept( node->result, *this );
1405
1406 VISIT_END( node );
1407}
1408
1409template< typename pass_type >
1410Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
1411 MUTATE_START( node );
1412
1413 indexerScopedMutate( node->env , *this );
1414 indexerScopedMutate( node->result, *this );
1415
1416 MUTATE_END( Expression, node );
1417}
1418
1419//--------------------------------------------------------------------------
1420// ConstantExpr
1421template< typename pass_type >
1422void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
1423 VISIT_START( node );
1424
1425 indexerScopedAccept( node->result , *this );
1426 maybeAccept_impl ( &node->constant, *this );
1427
1428 VISIT_END( node );
1429}
1430
1431template< typename pass_type >
1432Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) {
1433 MUTATE_START( node );
1434
1435 indexerScopedMutate( node->env , *this );
1436 indexerScopedMutate( node->result, *this );
1437 Constant * ptr = &node->constant;
1438 maybeMutate_impl( ptr, *this );
1439 node->constant = *ptr;
1440
1441 MUTATE_END( Expression, node );
1442}
1443
1444//--------------------------------------------------------------------------
1445// SizeofExpr
1446template< typename pass_type >
1447void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
1448 VISIT_START( node );
1449
1450 indexerScopedAccept( node->result, *this );
1451 if ( node->get_isType() ) {
1452 maybeAccept_impl( node->type, *this );
1453 } else {
1454 maybeAccept_impl( node->expr, *this );
1455 }
1456
1457 VISIT_END( node );
1458}
1459
1460template< typename pass_type >
1461Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
1462 MUTATE_START( node );
1463
1464 indexerScopedMutate( node->env , *this );
1465 indexerScopedMutate( node->result, *this );
1466 if ( node->get_isType() ) {
1467 maybeMutate_impl( node->type, *this );
1468 } else {
1469 maybeMutate_impl( node->expr, *this );
1470 }
1471
1472 MUTATE_END( Expression, node );
1473}
1474
1475//--------------------------------------------------------------------------
1476// AlignofExpr
1477template< typename pass_type >
1478void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
1479 VISIT_START( node );
1480
1481 indexerScopedAccept( node->result, *this );
1482 if ( node->get_isType() ) {
1483 maybeAccept_impl( node->type, *this );
1484 } else {
1485 maybeAccept_impl( node->expr, *this );
1486 }
1487
1488 VISIT_END( node );
1489}
1490
1491template< typename pass_type >
1492Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
1493 MUTATE_START( node );
1494
1495 indexerScopedMutate( node->env , *this );
1496 indexerScopedMutate( node->result, *this );
1497 if ( node->get_isType() ) {
1498 maybeMutate_impl( node->type, *this );
1499 } else {
1500 maybeMutate_impl( node->expr, *this );
1501 }
1502
1503 MUTATE_END( Expression, node );
1504}
1505
1506//--------------------------------------------------------------------------
1507// UntypedOffsetofExpr
1508template< typename pass_type >
1509void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * 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( UntypedOffsetofExpr * 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// OffsetofExpr
1531template< typename pass_type >
1532void PassVisitor< pass_type >::visit( OffsetofExpr * 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( OffsetofExpr * 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// OffsetPackExpr
1554template< typename pass_type >
1555void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
1556 VISIT_START( node );
1557
1558 indexerScopedAccept( node->result, *this );
1559 maybeAccept_impl ( node->type , *this );
1560
1561 VISIT_END( node );
1562}
1563
1564template< typename pass_type >
1565Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
1566 MUTATE_START( node );
1567
1568 indexerScopedMutate( node->env , *this );
1569 indexerScopedMutate( node->result, *this );
1570 maybeMutate_impl ( node->type , *this );
1571
1572 MUTATE_END( Expression, node );
1573}
1574
1575//--------------------------------------------------------------------------
1576// AttrExpr
1577template< typename pass_type >
1578void PassVisitor< pass_type >::visit( AttrExpr * node ) {
1579 VISIT_START( node );
1580
1581 indexerScopedAccept( node->result, *this );
1582 if ( node->get_isType() ) {
1583 maybeAccept_impl( node->type, *this );
1584 } else {
1585 maybeAccept_impl( node->expr, *this );
1586 }
1587
1588 VISIT_END( node );
1589}
1590
1591template< typename pass_type >
1592Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) {
1593 MUTATE_START( node );
1594
1595 indexerScopedMutate( node->env , *this );
1596 indexerScopedMutate( node->result, *this );
1597 if ( node->get_isType() ) {
1598 maybeMutate_impl( node->type, *this );
1599 } else {
1600 maybeMutate_impl( node->expr, *this );
1601 }
1602
1603 MUTATE_END( Expression, node );
1604}
1605
1606//--------------------------------------------------------------------------
1607// LogicalExpr
1608template< typename pass_type >
1609void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
1610 VISIT_START( node );
1611
1612 indexerScopedAccept( node->result, *this );
1613 maybeAccept_impl ( node->arg1 , *this );
1614 maybeAccept_impl ( node->arg2 , *this );
1615
1616 VISIT_END( node );
1617}
1618
1619template< typename pass_type >
1620Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) {
1621 MUTATE_START( node );
1622
1623 indexerScopedMutate( node->env , *this );
1624 indexerScopedMutate( node->result, *this );
1625 maybeMutate_impl ( node->arg1 , *this );
1626 maybeMutate_impl ( node->arg2 , *this );
1627
1628 MUTATE_END( Expression, node );
1629}
1630
1631//--------------------------------------------------------------------------
1632// ConditionalExpr
1633template< typename pass_type >
1634void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
1635 VISIT_START( node );
1636
1637 indexerScopedAccept( node->result, *this );
1638 maybeAccept_impl ( node->arg1 , *this );
1639 maybeAccept_impl ( node->arg2 , *this );
1640 maybeAccept_impl ( node->arg3 , *this );
1641
1642 VISIT_END( node );
1643}
1644
1645template< typename pass_type >
1646Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
1647 MUTATE_START( node );
1648
1649 indexerScopedMutate( node->env , *this );
1650 indexerScopedMutate( node->result, *this );
1651 maybeMutate_impl ( node->arg1 , *this );
1652 maybeMutate_impl ( node->arg2 , *this );
1653 maybeMutate_impl ( node->arg3 , *this );
1654
1655 MUTATE_END( Expression, node );
1656}
1657
1658//--------------------------------------------------------------------------
1659// CommaExpr
1660template< typename pass_type >
1661void PassVisitor< pass_type >::visit( CommaExpr * node ) {
1662 VISIT_START( node );
1663
1664 indexerScopedAccept( node->result, *this );
1665 maybeAccept_impl ( node->arg1 , *this );
1666 maybeAccept_impl ( node->arg2 , *this );
1667
1668 VISIT_END( node );
1669}
1670
1671template< typename pass_type >
1672Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
1673 MUTATE_START( node );
1674
1675 indexerScopedMutate( node->env , *this );
1676 indexerScopedMutate( node->result, *this );
1677 maybeMutate_impl ( node->arg1 , *this );
1678 maybeMutate_impl ( node->arg2 , *this );
1679
1680 MUTATE_END( Expression, node );
1681}
1682
1683//--------------------------------------------------------------------------
1684// TypeExpr
1685template< typename pass_type >
1686void PassVisitor< pass_type >::visit( TypeExpr * node ) {
1687 VISIT_START( node );
1688
1689 indexerScopedAccept( node->result, *this );
1690 maybeAccept_impl ( node->type, *this );
1691
1692 VISIT_END( node );
1693}
1694
1695template< typename pass_type >
1696Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
1697 MUTATE_START( node );
1698
1699 indexerScopedMutate( node->env , *this );
1700 indexerScopedMutate( node->result, *this );
1701 maybeMutate_impl ( node->type , *this );
1702
1703 MUTATE_END( Expression, node );
1704}
1705
1706//--------------------------------------------------------------------------
1707// AsmExpr
1708template< typename pass_type >
1709void PassVisitor< pass_type >::visit( AsmExpr * node ) {
1710 VISIT_START( node );
1711
1712 indexerScopedAccept( node->result , *this );
1713 maybeAccept_impl ( node->inout , *this );
1714 maybeAccept_impl ( node->constraint, *this );
1715 maybeAccept_impl ( node->operand , *this );
1716
1717 VISIT_END( node );
1718}
1719
1720template< typename pass_type >
1721Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) {
1722 MUTATE_START( node );
1723
1724 indexerScopedMutate( node->env , *this );
1725 indexerScopedMutate( node->result , *this );
1726 maybeMutate_impl ( node->inout , *this );
1727 maybeMutate_impl ( node->constraint, *this );
1728 maybeMutate_impl ( node->operand , *this );
1729
1730 MUTATE_END( Expression, node );
1731}
1732
1733//--------------------------------------------------------------------------
1734// ImplicitCopyCtorExpr
1735template< typename pass_type >
1736void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
1737 VISIT_START( node );
1738
1739 indexerScopedAccept( node->result , *this );
1740 maybeAccept_impl ( node->callExpr , *this );
1741 maybeAccept_impl ( node->tempDecls , *this );
1742 maybeAccept_impl ( node->returnDecls, *this );
1743 maybeAccept_impl ( node->dtors , *this );
1744
1745 VISIT_END( node );
1746}
1747
1748template< typename pass_type >
1749Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) {
1750 MUTATE_START( node );
1751
1752 indexerScopedMutate( node->env , *this );
1753 indexerScopedMutate( node->result , *this );
1754 maybeMutate_impl ( node->callExpr , *this );
1755 maybeMutate_impl ( node->tempDecls , *this );
1756 maybeMutate_impl ( node->returnDecls, *this );
1757 maybeMutate_impl ( node->dtors , *this );
1758
1759 MUTATE_END( Expression, node );
1760}
1761
1762//--------------------------------------------------------------------------
1763// ConstructorExpr
1764template< typename pass_type >
1765void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
1766 VISIT_START( node );
1767
1768 indexerScopedAccept( node->result , *this );
1769 maybeAccept_impl ( node->callExpr, *this );
1770
1771 VISIT_END( node );
1772}
1773
1774template< typename pass_type >
1775Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) {
1776 MUTATE_START( node );
1777
1778 indexerScopedMutate( node->env , *this );
1779 indexerScopedMutate( node->result , *this );
1780 maybeMutate_impl ( node->callExpr, *this );
1781
1782 MUTATE_END( Expression, node );
1783}
1784
1785//--------------------------------------------------------------------------
1786// CompoundLiteralExpr
1787template< typename pass_type >
1788void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
1789 VISIT_START( node );
1790
1791 indexerScopedAccept( node->result , *this );
1792 maybeAccept_impl ( node->initializer, *this );
1793
1794 VISIT_END( node );
1795}
1796
1797template< typename pass_type >
1798Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
1799 MUTATE_START( node );
1800
1801 indexerScopedMutate( node->env , *this );
1802 indexerScopedMutate( node->result , *this );
1803 maybeMutate_impl ( node->initializer, *this );
1804
1805 MUTATE_END( Expression, node );
1806}
1807
1808//--------------------------------------------------------------------------
1809// RangeExpr
1810template< typename pass_type >
1811void PassVisitor< pass_type >::visit( RangeExpr * node ) {
1812 VISIT_START( node );
1813
1814 indexerScopedAccept( node->result, *this );
1815 maybeAccept_impl ( node->low , *this );
1816 maybeAccept_impl ( node->high , *this );
1817
1818 VISIT_END( node );
1819}
1820
1821template< typename pass_type >
1822Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
1823 MUTATE_START( node );
1824
1825 indexerScopedMutate( node->env , *this );
1826 indexerScopedMutate( node->result, *this );
1827 maybeMutate_impl ( node->low , *this );
1828 maybeMutate_impl ( node->high , *this );
1829
1830 MUTATE_END( Expression, node );
1831}
1832
1833//--------------------------------------------------------------------------
1834// UntypedTupleExpr
1835template< typename pass_type >
1836void PassVisitor< pass_type >::visit( UntypedTupleExpr * 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( UntypedTupleExpr * 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// TupleExpr
1858template< typename pass_type >
1859void PassVisitor< pass_type >::visit( TupleExpr * node ) {
1860 VISIT_START( node );
1861
1862 indexerScopedAccept( node->result, *this );
1863 maybeAccept_impl ( node->exprs , *this );
1864
1865 VISIT_END( node );
1866}
1867
1868template< typename pass_type >
1869Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
1870 MUTATE_START( node );
1871
1872 indexerScopedMutate( node->env , *this );
1873 indexerScopedMutate( node->result, *this );
1874 maybeMutate_impl ( node->exprs , *this );
1875
1876 MUTATE_END( Expression, node );
1877}
1878
1879//--------------------------------------------------------------------------
1880// TupleIndexExpr
1881template< typename pass_type >
1882void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
1883 VISIT_START( node );
1884
1885 indexerScopedAccept( node->result, *this );
1886 maybeAccept_impl ( node->tuple , *this );
1887
1888 VISIT_END( node );
1889}
1890
1891template< typename pass_type >
1892Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
1893 MUTATE_START( node );
1894
1895 indexerScopedMutate( node->env , *this );
1896 indexerScopedMutate( node->result, *this );
1897 maybeMutate_impl ( node->tuple , *this );
1898
1899 MUTATE_END( Expression, node );
1900}
1901
1902//--------------------------------------------------------------------------
1903// TupleAssignExpr
1904template< typename pass_type >
1905void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
1906 VISIT_START( node );
1907
1908 indexerScopedAccept( node->result , *this );
1909 maybeAccept_impl ( node->stmtExpr, *this );
1910
1911 VISIT_END( node );
1912}
1913
1914template< typename pass_type >
1915Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) {
1916 MUTATE_START( node );
1917
1918 indexerScopedMutate( node->env , *this );
1919 indexerScopedMutate( node->result , *this );
1920 maybeMutate_impl ( node->stmtExpr, *this );
1921
1922 MUTATE_END( Expression, node );
1923}
1924
1925//--------------------------------------------------------------------------
1926// StmtExpr
1927template< typename pass_type >
1928void PassVisitor< pass_type >::visit( StmtExpr * node ) {
1929 VISIT_START( node );
1930
1931 // don't want statements from outer CompoundStmts to be added to this StmtExpr
1932 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() );
1933 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
1934 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
1935
1936 indexerScopedAccept( node->result , *this );
1937 maybeAccept_impl ( node->statements , *this );
1938 maybeAccept_impl ( node->returnDecls, *this );
1939 maybeAccept_impl ( node->dtors , *this );
1940
1941 VISIT_END( node );
1942}
1943
1944template< typename pass_type >
1945Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
1946 MUTATE_START( node );
1947
1948 // don't want statements from outer CompoundStmts to be added to this StmtExpr
1949 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() );
1950 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
1951 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
1952
1953 indexerScopedMutate( node->result , *this );
1954 maybeMutate_impl ( node->statements , *this );
1955 maybeMutate_impl ( node->returnDecls, *this );
1956 maybeMutate_impl ( node->dtors , *this );
1957
1958 MUTATE_END( Expression, node );
1959}
1960
1961//--------------------------------------------------------------------------
1962// UniqueExpr
1963template< typename pass_type >
1964void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
1965 VISIT_START( node );
1966
1967 indexerScopedAccept( node->result, *this );
1968 maybeAccept_impl ( node->expr , *this );
1969
1970 VISIT_END( node );
1971}
1972
1973template< typename pass_type >
1974Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
1975 MUTATE_START( node );
1976
1977 indexerScopedMutate( node->env , *this );
1978 indexerScopedMutate( node->result, *this );
1979 maybeMutate_impl ( node->expr , *this );
1980
1981 MUTATE_END( Expression, node );
1982}
1983
1984//--------------------------------------------------------------------------
1985// UntypedInitExpr
1986template< typename pass_type >
1987void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) {
1988 VISIT_START( node );
1989
1990 indexerScopedAccept( node->result, *this );
1991 maybeAccept_impl ( node->expr , *this );
1992 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
1993
1994 VISIT_END( node );
1995}
1996
1997template< typename pass_type >
1998Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
1999 MUTATE_START( node );
2000
2001 indexerScopedMutate( node->env , *this );
2002 indexerScopedMutate( node->result, *this );
2003 maybeMutate_impl ( node->expr , *this );
2004 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
2005
2006 MUTATE_END( Expression, node );
2007}
2008
2009//--------------------------------------------------------------------------
2010// InitExpr
2011template< typename pass_type >
2012void PassVisitor< pass_type >::visit( InitExpr * node ) {
2013 VISIT_START( node );
2014
2015 indexerScopedAccept( node->result, *this );
2016 maybeAccept_impl ( node->expr , *this );
2017 maybeAccept_impl ( node->designation, *this );
2018
2019 VISIT_END( node );
2020}
2021
2022template< typename pass_type >
2023Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
2024 MUTATE_START( node );
2025
2026 indexerScopedMutate( node->env , *this );
2027 indexerScopedMutate( node->result, *this );
2028 maybeMutate_impl ( node->expr , *this );
2029 maybeMutate_impl ( node->designation, *this );
2030
2031 MUTATE_END( Expression, node );
2032}
2033
2034//--------------------------------------------------------------------------
2035// DeletedExpr
2036template< typename pass_type >
2037void PassVisitor< pass_type >::visit( DeletedExpr * node ) {
2038 VISIT_START( node );
2039
2040 indexerScopedAccept( node->result, *this );
2041 maybeAccept_impl( node->expr, *this );
2042 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
2043
2044 VISIT_END( node );
2045}
2046
2047template< typename pass_type >
2048Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
2049 MUTATE_START( node );
2050
2051 indexerScopedMutate( node->env, *this );
2052 indexerScopedMutate( node->result, *this );
2053 maybeMutate_impl( node->expr, *this );
2054
2055 MUTATE_END( Expression, node );
2056}
2057
2058//--------------------------------------------------------------------------
2059// VoidType
2060template< typename pass_type >
2061void PassVisitor< pass_type >::visit( VoidType * node ) {
2062 VISIT_START( node );
2063
2064 maybeAccept_impl( node->forall, *this );
2065
2066 VISIT_END( node );
2067}
2068
2069template< typename pass_type >
2070Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
2071 MUTATE_START( node );
2072
2073 maybeMutate_impl( node->forall, *this );
2074
2075 MUTATE_END( Type, node );
2076}
2077
2078//--------------------------------------------------------------------------
2079// BasicType
2080template< typename pass_type >
2081void PassVisitor< pass_type >::visit( BasicType * node ) {
2082 VISIT_START( node );
2083
2084 maybeAccept_impl( node->forall, *this );
2085
2086 VISIT_END( node );
2087}
2088
2089template< typename pass_type >
2090Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
2091 MUTATE_START( node );
2092
2093 maybeMutate_impl( node->forall, *this );
2094
2095 MUTATE_END( Type, node );
2096}
2097
2098//--------------------------------------------------------------------------
2099// PointerType
2100template< typename pass_type >
2101void PassVisitor< pass_type >::visit( PointerType * node ) {
2102 VISIT_START( node );
2103
2104 maybeAccept_impl( node->forall, *this );
2105 // xxx - should PointerType visit/mutate dimension?
2106 maybeAccept_impl( node->base, *this );
2107
2108 VISIT_END( node );
2109}
2110
2111template< typename pass_type >
2112Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
2113 MUTATE_START( node );
2114
2115 maybeMutate_impl( node->forall, *this );
2116 // xxx - should PointerType visit/mutate dimension?
2117 maybeMutate_impl( node->base, *this );
2118
2119 MUTATE_END( Type, node );
2120}
2121
2122//--------------------------------------------------------------------------
2123// ArrayType
2124template< typename pass_type >
2125void PassVisitor< pass_type >::visit( ArrayType * node ) {
2126 VISIT_START( node );
2127
2128 maybeAccept_impl( node->forall, *this );
2129 maybeAccept_impl( node->dimension, *this );
2130 maybeAccept_impl( node->base, *this );
2131
2132 VISIT_END( node );
2133}
2134
2135template< typename pass_type >
2136Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
2137 MUTATE_START( node );
2138
2139 maybeMutate_impl( node->forall, *this );
2140 maybeMutate_impl( node->dimension, *this );
2141 maybeMutate_impl( node->base, *this );
2142
2143 MUTATE_END( Type, node );
2144}
2145
2146//--------------------------------------------------------------------------
2147// ReferenceType
2148template< typename pass_type >
2149void PassVisitor< pass_type >::visit( ReferenceType * node ) {
2150 VISIT_START( node );
2151
2152 maybeAccept_impl( node->forall, *this );
2153 maybeAccept_impl( node->base, *this );
2154
2155 VISIT_END( node );
2156}
2157
2158template< typename pass_type >
2159Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
2160 MUTATE_START( node );
2161
2162 maybeMutate_impl( node->forall, *this );
2163 maybeMutate_impl( node->base, *this );
2164
2165 MUTATE_END( Type, node );
2166}
2167
2168//--------------------------------------------------------------------------
2169// FunctionType
2170template< typename pass_type >
2171void PassVisitor< pass_type >::visit( FunctionType * node ) {
2172 VISIT_START( node );
2173
2174 maybeAccept_impl( node->forall, *this );
2175 maybeAccept_impl( node->returnVals, *this );
2176 maybeAccept_impl( node->parameters, *this );
2177
2178 VISIT_END( node );
2179}
2180
2181template< typename pass_type >
2182Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
2183 MUTATE_START( node );
2184
2185 maybeMutate_impl( node->forall, *this );
2186 maybeMutate_impl( node->returnVals, *this );
2187 maybeMutate_impl( node->parameters, *this );
2188
2189 MUTATE_END( Type, node );
2190}
2191
2192//--------------------------------------------------------------------------
2193// StructInstType
2194template< typename pass_type >
2195void PassVisitor< pass_type >::visit( StructInstType * node ) {
2196 VISIT_START( node );
2197
2198 indexerAddStruct( node->name );
2199
2200 {
2201 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2202 maybeAccept_impl( node->forall , *this );
2203 maybeAccept_impl( node->parameters, *this );
2204 }
2205
2206 VISIT_END( node );
2207}
2208
2209template< typename pass_type >
2210Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
2211 MUTATE_START( node );
2212
2213 indexerAddStruct( node->name );
2214
2215 {
2216 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2217 maybeMutate_impl( node->forall , *this );
2218 maybeMutate_impl( node->parameters, *this );
2219 }
2220
2221 MUTATE_END( Type, node );
2222}
2223
2224//--------------------------------------------------------------------------
2225// UnionInstType
2226template< typename pass_type >
2227void PassVisitor< pass_type >::visit( UnionInstType * node ) {
2228 VISIT_START( node );
2229
2230 indexerAddStruct( node->name );
2231
2232 {
2233 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2234 maybeAccept_impl( node->forall , *this );
2235 maybeAccept_impl( node->parameters, *this );
2236 }
2237
2238 VISIT_END( node );
2239}
2240
2241template< typename pass_type >
2242Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
2243 MUTATE_START( node );
2244
2245 indexerAddStruct( node->name );
2246
2247 {
2248 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
2249 maybeMutate_impl( node->forall , *this );
2250 maybeMutate_impl( node->parameters, *this );
2251 }
2252
2253 MUTATE_END( Type, node );
2254}
2255
2256//--------------------------------------------------------------------------
2257// EnumInstType
2258template< typename pass_type >
2259void PassVisitor< pass_type >::visit( EnumInstType * node ) {
2260 VISIT_START( node );
2261
2262 maybeAccept_impl( node->forall, *this );
2263 maybeAccept_impl( node->parameters, *this );
2264
2265 VISIT_END( node );
2266}
2267
2268template< typename pass_type >
2269Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
2270 MUTATE_START( node );
2271
2272 maybeMutate_impl( node->forall, *this );
2273 maybeMutate_impl( node->parameters, *this );
2274
2275 MUTATE_END( Type, node );
2276}
2277
2278//--------------------------------------------------------------------------
2279// TraitInstType
2280template< typename pass_type >
2281void PassVisitor< pass_type >::visit( TraitInstType * node ) {
2282 VISIT_START( node );
2283
2284 maybeAccept_impl( node->forall , *this );
2285 maybeAccept_impl( node->parameters, *this );
2286
2287 VISIT_END( node );
2288}
2289
2290template< typename pass_type >
2291Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
2292 MUTATE_START( node );
2293
2294 maybeMutate_impl( node->forall , *this );
2295 maybeMutate_impl( node->parameters, *this );
2296
2297 MUTATE_END( Type, node );
2298}
2299
2300//--------------------------------------------------------------------------
2301// TypeInstType
2302template< typename pass_type >
2303void PassVisitor< pass_type >::visit( TypeInstType * node ) {
2304 VISIT_START( node );
2305
2306 maybeAccept_impl( node->forall , *this );
2307 maybeAccept_impl( node->parameters, *this );
2308
2309 VISIT_END( node );
2310}
2311
2312template< typename pass_type >
2313Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
2314 MUTATE_START( node );
2315
2316 maybeMutate_impl( node->forall , *this );
2317 maybeMutate_impl( node->parameters, *this );
2318
2319 MUTATE_END( Type, node );
2320}
2321
2322//--------------------------------------------------------------------------
2323// TupleType
2324template< typename pass_type >
2325void PassVisitor< pass_type >::visit( TupleType * node ) {
2326 VISIT_START( node );
2327
2328 maybeAccept_impl( node->forall, *this );
2329 maybeAccept_impl( node->types, *this );
2330 maybeAccept_impl( node->members, *this );
2331
2332 VISIT_END( node );
2333}
2334
2335template< typename pass_type >
2336Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
2337 MUTATE_START( node );
2338
2339 maybeMutate_impl( node->forall, *this );
2340 maybeMutate_impl( node->types, *this );
2341 maybeMutate_impl( node->members, *this );
2342
2343 MUTATE_END( Type, node );
2344}
2345
2346//--------------------------------------------------------------------------
2347// TypeofType
2348template< typename pass_type >
2349void PassVisitor< pass_type >::visit( TypeofType * node ) {
2350 VISIT_START( node );
2351
2352 assert( node->expr );
2353 maybeAccept_impl( node->expr, *this );
2354
2355 VISIT_END( node );
2356}
2357
2358template< typename pass_type >
2359Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
2360 MUTATE_START( node );
2361
2362 assert( node->expr );
2363 maybeMutate_impl( node->expr, *this );
2364
2365 MUTATE_END( Type, node );
2366}
2367
2368//--------------------------------------------------------------------------
2369// AttrType
2370template< typename pass_type >
2371void PassVisitor< pass_type >::visit( AttrType * node ) {
2372 VISIT_START( node );
2373
2374 if ( node->isType ) {
2375 assert( node->type );
2376 maybeAccept_impl( node->type, *this );
2377 } else {
2378 assert( node->expr );
2379 maybeAccept_impl( node->expr, *this );
2380 } // if
2381
2382 VISIT_END( node );
2383}
2384
2385template< typename pass_type >
2386Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
2387 MUTATE_START( node );
2388
2389 if ( node->isType ) {
2390 assert( node->type );
2391 maybeMutate_impl( node->type, *this );
2392 } else {
2393 assert( node->expr );
2394 maybeMutate_impl( node->expr, *this );
2395 } // if
2396
2397 MUTATE_END( Type, node );
2398}
2399
2400//--------------------------------------------------------------------------
2401// VarArgsType
2402template< typename pass_type >
2403void PassVisitor< pass_type >::visit( VarArgsType * node ) {
2404 VISIT_START( node );
2405
2406 maybeAccept_impl( node->forall, *this );
2407
2408 VISIT_END( node );
2409}
2410
2411template< typename pass_type >
2412Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
2413 MUTATE_START( node );
2414
2415 maybeMutate_impl( node->forall, *this );
2416
2417 MUTATE_END( Type, node );
2418}
2419
2420//--------------------------------------------------------------------------
2421// ZeroType
2422template< typename pass_type >
2423void PassVisitor< pass_type >::visit( ZeroType * node ) {
2424 VISIT_START( node );
2425
2426 maybeAccept_impl( node->forall, *this );
2427
2428 VISIT_END( node );
2429}
2430
2431template< typename pass_type >
2432Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
2433 MUTATE_START( node );
2434
2435 maybeMutate_impl( node->forall, *this );
2436
2437 MUTATE_END( Type, node );
2438}
2439
2440//--------------------------------------------------------------------------
2441// OneType
2442template< typename pass_type >
2443void PassVisitor< pass_type >::visit( OneType * node ) {
2444 VISIT_START( node );
2445
2446 maybeAccept_impl( node->forall, *this );
2447
2448 VISIT_END( node );
2449}
2450
2451template< typename pass_type >
2452Type * PassVisitor< pass_type >::mutate( OneType * node ) {
2453 MUTATE_START( node );
2454
2455 maybeMutate_impl( node->forall, *this );
2456
2457 MUTATE_END( Type, node );
2458}
2459
2460//--------------------------------------------------------------------------
2461// Designation
2462template< typename pass_type >
2463void PassVisitor< pass_type >::visit( Designation * node ) {
2464 VISIT_START( node );
2465
2466 maybeAccept_impl( node->designators, *this );
2467
2468 VISIT_END( node );
2469}
2470
2471template< typename pass_type >
2472Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
2473 MUTATE_START( node );
2474
2475 maybeMutate_impl( node->designators, *this );
2476
2477 MUTATE_END( Designation, node );
2478}
2479
2480//--------------------------------------------------------------------------
2481// SingleInit
2482template< typename pass_type >
2483void PassVisitor< pass_type >::visit( SingleInit * node ) {
2484 VISIT_START( node );
2485
2486 visitExpression( node->value );
2487
2488 VISIT_END( node );
2489}
2490
2491template< typename pass_type >
2492Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
2493 MUTATE_START( node );
2494
2495 node->value = mutateExpression( node->value );
2496
2497 MUTATE_END( Initializer, node );
2498}
2499
2500//--------------------------------------------------------------------------
2501// ListInit
2502template< typename pass_type >
2503void PassVisitor< pass_type >::visit( ListInit * node ) {
2504 VISIT_START( node );
2505
2506 maybeAccept_impl( node->designations, *this );
2507 maybeAccept_impl( node->initializers, *this );
2508
2509 VISIT_END( node );
2510}
2511
2512template< typename pass_type >
2513Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
2514 MUTATE_START( node );
2515
2516 maybeMutate_impl( node->designations, *this );
2517 maybeMutate_impl( node->initializers, *this );
2518
2519 MUTATE_END( Initializer, node );
2520}
2521
2522//--------------------------------------------------------------------------
2523// ConstructorInit
2524template< typename pass_type >
2525void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
2526 VISIT_START( node );
2527
2528 maybeAccept_impl( node->ctor, *this );
2529 maybeAccept_impl( node->dtor, *this );
2530 maybeAccept_impl( node->init, *this );
2531
2532 VISIT_END( node );
2533}
2534
2535template< typename pass_type >
2536Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
2537 MUTATE_START( node );
2538
2539 maybeMutate_impl( node->ctor, *this );
2540 maybeMutate_impl( node->dtor, *this );
2541 maybeMutate_impl( node->init, *this );
2542
2543 MUTATE_END( Initializer, node );
2544}
2545
2546//--------------------------------------------------------------------------
2547// Subrange
2548template< typename pass_type >
2549void PassVisitor< pass_type >::visit( Subrange * node ) {
2550 VISIT_START( node );
2551
2552 VISIT_END( node );
2553}
2554
2555template< typename pass_type >
2556Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) {
2557 MUTATE_START( node );
2558
2559 MUTATE_END( Subrange, node );
2560}
2561
2562//--------------------------------------------------------------------------
2563// Attribute
2564template< typename pass_type >
2565void PassVisitor< pass_type >::visit( Constant * node ) {
2566 VISIT_START( node );
2567
2568 VISIT_END( node );
2569}
2570
2571template< typename pass_type >
2572Constant * PassVisitor< pass_type >::mutate( Constant * node ) {
2573 MUTATE_START( node );
2574
2575 MUTATE_END( Constant, node );
2576}
2577
2578//--------------------------------------------------------------------------
2579// Attribute
2580template< typename pass_type >
2581void PassVisitor< pass_type >::visit( Attribute * node ) {
2582 VISIT_START( node );
2583
2584 maybeAccept_impl( node->parameters, *this );
2585
2586 VISIT_END( node );
2587}
2588
2589template< typename pass_type >
2590Attribute * PassVisitor< pass_type >::mutate( Attribute * node ) {
2591 MUTATE_START( node );
2592
2593 maybeMutate_impl( node->parameters, *this );
2594
2595 MUTATE_END( Attribute, node );
2596}
2597
2598//--------------------------------------------------------------------------
2599// TypeSubstitution
2600template< typename pass_type >
2601TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
2602 MUTATE_START( node );
2603
2604 for ( auto & p : node->typeEnv ) {
2605 indexerScopedMutate( p.second, *this );
2606 }
2607 for ( auto & p : node->varEnv ) {
2608 indexerScopedMutate( p.second, *this );
2609 }
2610
2611 MUTATE_END( TypeSubstitution, node );
2612}
Note: See TracBrowser for help on using the repository browser.