source: src/Common/PassVisitor.impl.h@ 893e106

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

Removed all traces of SubRange which didn't actually exist and made some more fields public

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