source: src/Common/PassVisitor.impl.h@ 044ae62

ADT
Last change on this file since 044ae62 was f4e01f1, checked in by JiadaL <j82liang@…>, 3 years ago

Save progress

  • Property mode set to 100644
File size: 114.9 KB
Line 
1#pragma once
2// IWYU pragma: private, include "PassVisitor.h"
3
4#define VISIT_START( node ) \
5 __attribute__((unused)) \
6 ChildrenGuard children_guard( get_visit_children_ptr() ); \
7 __attribute__((unused)) \
8 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \
9 call_previsit( node ); \
10
11#define VISIT_END( node ) \
12 call_postvisit( node ); \
13
14#define MUTATE_START( node ) \
15 __attribute__((unused)) \
16 ChildrenGuard children_guard( get_visit_children_ptr() ); \
17 __attribute__((unused)) \
18 guard_value_impl guard( at_cleanup_impl(pass, 0) ); \
19 call_premutate( node ); \
20
21#define MUTATE_END( type, node ) \
22 auto __return = call_postmutate< type * >( node ); \
23 assert( __return ); \
24 return __return;
25
26
27template<typename T>
28static inline bool empty( T * ptr ) {
29 return !ptr || ptr->empty();
30}
31
32typedef std::list< Statement * > StmtList_t;
33typedef std::list< Declaration * > DeclList_t;
34
35template<typename iterator_t>
36static inline void splice( iterator_t it, DeclList_t * decls ) {
37 std::transform(
38 decls->begin(),
39 decls->end(),
40 it,
41 [](Declaration * decl) -> auto {
42 return new DeclStmt( decl );
43 }
44 );
45 decls->clear();
46}
47
48template< typename pass_type >
49inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {
50 DeclList_t* beforeDecls = visitor.get_beforeDecls();
51 DeclList_t* afterDecls = visitor.get_afterDecls();
52 SemanticErrorException errors;
53
54 pass_visitor_stats.depth++;
55 pass_visitor_stats.max->push(pass_visitor_stats.depth);
56 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
57 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
58
59
60 // splice in new declarations after previous decl
61 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
62
63 if ( i == decls.end() ) break;
64
65 try {
66 // run visitor on declaration
67 maybeAccept_impl( *i, visitor );
68 } catch( SemanticErrorException &e ) {
69 errors.append( e );
70 }
71
72 // splice in new declarations before current decl
73 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
74 }
75 pass_visitor_stats.depth--;
76 if ( ! errors.isEmpty() ) {
77 throw errors;
78 }
79}
80
81template< typename pass_type >
82inline void acceptAll( const std::list< const Declaration * > & decls, PassVisitor< pass_type >& visitor ) {
83 SemanticErrorException errors;
84
85 pass_visitor_stats.depth++;
86 pass_visitor_stats.max->push(pass_visitor_stats.depth);
87 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
88 for ( const Declaration * decl : decls ) {
89 try {
90 // run visitor on declaration
91 maybeAccept_impl( decl, visitor );
92 }
93 catch( SemanticErrorException &e ) {
94 errors.append( e );
95 }
96 }
97 pass_visitor_stats.depth--;
98 if ( ! errors.isEmpty() ) {
99 throw errors;
100 }
101}
102
103template< typename pass_type >
104inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
105 DeclList_t* beforeDecls = mutator.get_beforeDecls();
106 DeclList_t* afterDecls = mutator.get_afterDecls();
107 SemanticErrorException errors;
108
109 pass_visitor_stats.depth++;
110 pass_visitor_stats.max->push(pass_visitor_stats.depth);
111 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
112 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
113 // splice in new declarations after previous decl
114 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
115
116 if ( i == decls.end() ) break;
117 try {
118 // run mutator on declaration
119 maybeMutate_impl( *i, mutator );
120 } catch( SemanticErrorException &e ) {
121 errors.append( e );
122 }
123
124 // splice in new declarations before current decl
125 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
126 }
127 pass_visitor_stats.depth--;
128 if ( ! errors.isEmpty() ) {
129 throw errors;
130 }
131}
132
133template< typename TreeType, typename pass_type >
134inline void maybeAccept_impl( TreeType * tree, PassVisitor< pass_type > & visitor ) {
135 if ( ! visitor.get_visit_children() ) return;
136 if ( tree ) {
137 tree->accept( visitor );
138 }
139}
140
141template< typename TreeType, typename pass_type >
142inline void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_type > & visitor ) {
143 if ( ! visitor.get_visit_children() ) return;
144 if ( tree ) {
145 tree->accept( visitor );
146 }
147}
148
149template< typename Container, typename pass_type >
150inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) {
151 if ( ! visitor.get_visit_children() ) return;
152 SemanticErrorException errors;
153
154 pass_visitor_stats.depth++;
155 pass_visitor_stats.max->push(pass_visitor_stats.depth);
156 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
157 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
158 try {
159 if ( *i ) {
160 (*i)->accept( visitor );
161 }
162 } catch( SemanticErrorException &e ) {
163 errors.append( e );
164 }
165 }
166 pass_visitor_stats.depth--;
167 if ( ! errors.isEmpty() ) {
168 throw errors;
169 }
170}
171
172template< typename Container, typename pass_type >
173inline void maybeAccept_impl( const Container & container, PassVisitor< pass_type > & visitor ) {
174 if ( ! visitor.get_visit_children() ) return;
175 SemanticErrorException errors;
176
177 pass_visitor_stats.depth++;
178 pass_visitor_stats.max->push(pass_visitor_stats.depth);
179 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
180 for ( const auto & i : container ) {
181 try {
182 if ( i ) {
183 i->accept( visitor );
184 }
185 } catch( SemanticErrorException &e ) {
186 errors.append( e );
187 }
188 }
189 pass_visitor_stats.depth--;
190 if ( ! errors.isEmpty() ) {
191 throw errors;
192 }
193}
194
195template< typename TreeType, typename pass_type >
196inline void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_type > & mutator ) {
197 if ( ! mutator.get_visit_children() ) return;
198
199 if ( tree ) {
200 tree = strict_dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) );
201 }
202}
203
204template< typename Container, typename pass_type >
205inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
206
207 if ( ! mutator.get_visit_children() ) return;
208 SemanticErrorException errors;
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 ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
214 try {
215 if ( *i ) {
216 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
217 assert( *i );
218 } // if
219 } catch( SemanticErrorException &e ) {
220 errors.append( e );
221 } // try
222 } // for
223 pass_visitor_stats.depth--;
224 if ( ! errors.isEmpty() ) {
225 throw errors;
226 } // if
227}
228
229template< typename pass_type >
230template< typename func_t >
231void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
232 if ( ! get_visit_children() ) return;
233 SemanticErrorException errors;
234
235 // don't want statements from outer CompoundStmts to be added to this CompoundStmt
236 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() );
237 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () );
238 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() );
239 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () );
240
241 StmtList_t* beforeStmts = get_beforeStmts();
242 StmtList_t* afterStmts = get_afterStmts();
243 DeclList_t* beforeDecls = get_beforeDecls();
244 DeclList_t* afterDecls = get_afterDecls();
245
246 pass_visitor_stats.depth++;
247 pass_visitor_stats.max->push(pass_visitor_stats.depth);
248 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
249 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
250
251 if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); }
252 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
253
254 try {
255 func( *i );
256 assert( *i );
257 assert(( empty( beforeStmts ) && empty( afterStmts ))
258 || ( empty( beforeDecls ) && empty( afterDecls )) );
259
260 } catch ( SemanticErrorException &e ) {
261 errors.append( e );
262 }
263
264 if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); }
265 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
266 }
267 pass_visitor_stats.depth--;
268
269 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
270 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
271 if ( !errors.isEmpty() ) { throw errors; }
272}
273
274template< typename pass_type >
275void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
276 handleStatementList( statements, [this]( Statement * stmt) {
277 maybeAccept_impl( stmt, *this );
278 });
279}
280
281template< typename pass_type >
282void PassVisitor< pass_type >::visitStatementList( const std::list< Statement * > & statements ) {
283 if ( ! get_visit_children() ) return;
284 SemanticErrorException errors;
285
286 pass_visitor_stats.depth++;
287 pass_visitor_stats.max->push(pass_visitor_stats.depth);
288 pass_visitor_stats.avg->push(pass_visitor_stats.depth);
289 for ( const Statement * i : statements ) {
290 try {
291 maybeAccept_impl( i, *this );
292 } catch ( SemanticErrorException &e ) {
293 errors.append( e );
294 }
295 }
296 pass_visitor_stats.depth--;
297 if ( !errors.isEmpty() ) { throw errors; }
298}
299
300template< typename pass_type >
301void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
302 handleStatementList( statements, [this]( Statement *& stmt) {
303 maybeMutate_impl( stmt, *this );
304 });
305}
306
307
308template< typename pass_type >
309template< typename func_t >
310Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) {
311 if ( ! get_visit_children() ) return stmt;
312
313 // don't want statements from outer CompoundStmts to be added to this CompoundStmt
314 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
315 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() );
316 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () );
317 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() );
318 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () );
319
320 Statement *newStmt = func( stmt );
321
322 StmtList_t* beforeStmts = get_beforeStmts();
323 StmtList_t* afterStmts = get_afterStmts();
324 DeclList_t* beforeDecls = get_beforeDecls();
325 DeclList_t* afterDecls = get_afterDecls();
326
327 if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; }
328 assert(( empty( beforeStmts ) && empty( afterStmts ))
329 || ( empty( beforeDecls ) && empty( afterDecls )) );
330
331 CompoundStmt *compound = new CompoundStmt();
332 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); }
333 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
334 compound->get_kids().push_back( newStmt );
335 if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); }
336 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
337 return compound;
338}
339
340template< typename pass_type >
341Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
342 return handleStatement( stmt, [this]( Statement * stmt ) {
343 maybeAccept_impl( stmt, *this );
344 return stmt;
345 });
346}
347
348template< typename pass_type >
349void PassVisitor< pass_type >::visitStatement( const Statement * stmt ) {
350 if ( ! get_visit_children() ) return;
351
352 // don't want statements from outer CompoundStmts to be added to this CompoundStmt
353 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
354
355 maybeAccept_impl( stmt, *this );
356}
357
358template< typename pass_type >
359Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
360 return handleStatement( stmt, [this]( Statement * stmt ) {
361 maybeMutate_impl( stmt, *this );
362 return stmt;
363 });
364}
365
366template< typename pass_type >
367template< typename func_t >
368Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) {
369 if ( ! get_visit_children() ) return expr;
370 if( !expr ) return nullptr;
371
372 auto env_ptr = get_env_ptr();
373 if ( env_ptr && expr->get_env() ) {
374 *env_ptr = expr->get_env();
375 }
376
377 // should env be moved onto the result of the mutate?
378 return func( expr );
379}
380
381template< typename pass_type >
382Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) {
383 return handleExpression(expr, [this]( Expression * expr ) {
384 maybeAccept_impl( expr, *this );
385 return expr;
386 });
387}
388
389template< typename pass_type >
390void PassVisitor< pass_type >::visitExpression( const Expression * expr ) {
391 if ( ! get_visit_children() ) return;
392 if( !expr ) return;
393
394 auto env_ptr = get_env_ptr();
395 if ( env_ptr && expr->get_env() ) {
396 *env_ptr = expr->get_env();
397 }
398
399 maybeAccept_impl( expr, *this );
400}
401
402template< typename pass_type >
403Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
404 return handleExpression(expr, [this]( Expression * expr ) {
405 maybeMutate_impl( expr, *this );
406 return expr;
407 });
408}
409
410template< typename TreeType, typename VisitorType >
411inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) {
412 if ( ! visitor.get_visit_children() ) return;
413 auto guard = makeFuncGuard(
414 [&visitor]() { visitor.indexerScopeEnter(); },
415 [&visitor]() { visitor.indexerScopeLeave(); }
416 );
417 maybeAccept_impl( tree, visitor );
418}
419
420template< typename TreeType, typename VisitorType >
421inline void indexerScopedAccept( const TreeType * tree, VisitorType & visitor ) {
422 if ( ! visitor.get_visit_children() ) return;
423 auto guard = makeFuncGuard(
424 [&visitor]() { visitor.indexerScopeEnter(); },
425 [&visitor]() { visitor.indexerScopeLeave(); }
426 );
427 maybeAccept_impl( tree, visitor );
428}
429
430template< typename TreeType, typename MutatorType >
431inline void indexerScopedMutate( TreeType *& tree, MutatorType & mutator ) {
432 if ( ! mutator.get_visit_children() ) return;
433 auto guard = makeFuncGuard(
434 [&mutator]() { mutator.indexerScopeEnter(); },
435 [&mutator]() { mutator.indexerScopeLeave(); }
436 );
437 maybeMutate_impl( tree, mutator );
438}
439
440//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
441//========================================================================================================================================================================
442//========================================================================================================================================================================
443//========================================================================================================================================================================
444//========================================================================================================================================================================
445//========================================================================================================================================================================
446//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
447
448// A NOTE ON THE ORDER OF TRAVERSAL
449//
450// Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is
451// no such thing as a recursive type or typedef.
452//
453// typedef struct { T *x; } T; // never allowed
454//
455// for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the
456// members are traversed, and then the complete type should be added (assuming the type is completed by this particular
457// declaration).
458//
459// struct T { struct T *x; }; // allowed
460//
461// It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that
462// traversal may modify the definition of the type and these modifications should be visible when the symbol table is
463// queried later in this pass.
464//
465// TODO: figure out whether recursive contexts are sensible/possible/reasonable.
466
467//--------------------------------------------------------------------------
468// ObjectDecl
469template< typename pass_type >
470void PassVisitor< pass_type >::visit( ObjectDecl * node ) {
471 VISIT_START( node );
472
473 indexerScopedAccept( node->type , *this );
474 maybeAccept_impl ( node->init , *this );
475 maybeAccept_impl ( node->bitfieldWidth, *this );
476 maybeAccept_impl ( node->attributes , *this );
477
478 indexerAddId( node );
479
480 VISIT_END( node );
481}
482
483template< typename pass_type >
484void PassVisitor< pass_type >::visit( const ObjectDecl * node ) {
485 VISIT_START( node );
486
487 maybeAccept_impl( node->type , *this );
488 maybeAccept_impl( node->init , *this );
489 maybeAccept_impl( node->bitfieldWidth, *this );
490 maybeAccept_impl( node->attributes , *this );
491
492 VISIT_END( node );
493}
494
495template< typename pass_type >
496DeclarationWithType * PassVisitor< pass_type >::mutate( ObjectDecl * node ) {
497 MUTATE_START( node );
498
499 indexerScopedMutate( node->type , *this );
500 maybeMutate_impl ( node->init , *this );
501 maybeMutate_impl ( node->bitfieldWidth, *this );
502 maybeMutate_impl ( node->attributes , *this );
503
504 indexerAddId( node );
505
506 MUTATE_END( DeclarationWithType, node );
507}
508
509//--------------------------------------------------------------------------
510// FunctionDecl
511template< typename pass_type >
512void PassVisitor< pass_type >::visit( FunctionDecl * node ) {
513 VISIT_START( node );
514
515 indexerAddId( node );
516
517 maybeAccept_impl( node->withExprs, *this );
518 {
519 // with clause introduces a level of scope (for the with expression members).
520 // with clause exprs are added to the indexer before parameters so that parameters
521 // shadow with exprs and not the other way around.
522 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
523 indexerAddWith( node->withExprs, node );
524 {
525 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
526 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
527 static ObjectDecl func(
528 "__func__", noStorageClasses, LinkageSpec::C, nullptr,
529 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
530 nullptr
531 );
532 indexerAddId( &func );
533 maybeAccept_impl( node->type, *this );
534 // First remember that we are now within a function.
535 ValueGuard< bool > oldInFunction( inFunction );
536 inFunction = true;
537 // The function body needs to have the same scope as parameters.
538 // A CompoundStmt will not enter a new scope if atFunctionTop is true.
539 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
540 atFunctionTop = true;
541 maybeAccept_impl( node->statements, *this );
542 maybeAccept_impl( node->attributes, *this );
543 }
544 }
545
546 VISIT_END( node );
547}
548
549template< typename pass_type >
550void PassVisitor< pass_type >::visit( const FunctionDecl * node ) {
551 VISIT_START( node );
552
553 indexerAddId( node );
554
555 maybeAccept_impl( node->withExprs, *this );
556 {
557 // with clause introduces a level of scope (for the with expression members).
558 // with clause exprs are added to the indexer before parameters so that parameters
559 // shadow with exprs and not the other way around.
560 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
561 indexerAddWith( node->withExprs, node );
562 {
563 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
564 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
565 static ObjectDecl func(
566 "__func__", noStorageClasses, LinkageSpec::C, nullptr,
567 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
568 nullptr
569 );
570 indexerAddId( &func );
571 maybeAccept_impl( node->type, *this );
572 // First remember that we are now within a function.
573 ValueGuard< bool > oldInFunction( inFunction );
574 inFunction = true;
575 // The function body needs to have the same scope as parameters.
576 // A CompoundStmt will not enter a new scope if atFunctionTop is true.
577 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
578 atFunctionTop = true;
579 maybeAccept_impl( node->statements, *this );
580 maybeAccept_impl( node->attributes, *this );
581 }
582 }
583
584 VISIT_END( node );
585}
586
587template< typename pass_type >
588DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) {
589 MUTATE_START( node );
590
591 indexerAddId( node );
592
593 {
594 // with clause introduces a level of scope (for the with expression members).
595 // with clause exprs are added to the indexer before parameters so that parameters
596 // shadow with exprs and not the other way around.
597 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
598 indexerAddWith( node->withExprs, node );
599 {
600 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
601 // implicit add __func__ identifier as specified in the C manual 6.4.2.2
602 static ObjectDecl func(
603 "__func__", noStorageClasses, LinkageSpec::C, nullptr,
604 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ),
605 nullptr
606 );
607 indexerAddId( &func );
608 maybeMutate_impl( node->type, *this );
609 maybeMutate_impl( node->attributes, *this );
610 // First remember that we are now within a function.
611 ValueGuard< bool > oldInFunction( inFunction );
612 inFunction = true;
613 // The function body needs to have the same scope as parameters.
614 // A CompoundStmt will not enter a new scope if atFunctionTop is true.
615 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
616 atFunctionTop = true;
617 maybeMutate_impl( node->statements, *this );
618 }
619 }
620
621 MUTATE_END( DeclarationWithType, node );
622}
623
624//--------------------------------------------------------------------------
625// StructDecl
626template< typename pass_type >
627void PassVisitor< pass_type >::visit( StructDecl * node ) {
628 VISIT_START( node );
629
630 // make up a forward declaration and add it before processing the members
631 // needs to be on the heap because addStruct saves the pointer
632 indexerAddStructFwd( node );
633
634 {
635 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
636 maybeAccept_impl( node->parameters, *this );
637 maybeAccept_impl( node->members , *this );
638 maybeAccept_impl( node->attributes, *this );
639 }
640
641 // this addition replaces the forward declaration
642 indexerAddStruct( node );
643
644 VISIT_END( node );
645}
646
647template< typename pass_type >
648void PassVisitor< pass_type >::visit( const StructDecl * node ) {
649 VISIT_START( node );
650
651 // make up a forward declaration and add it before processing the members
652 // needs to be on the heap because addStruct saves the pointer
653 indexerAddStructFwd( node );
654
655 {
656 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
657 maybeAccept_impl( node->parameters, *this );
658 maybeAccept_impl( node->members , *this );
659 maybeAccept_impl( node->attributes, *this );
660 }
661
662 // this addition replaces the forward declaration
663 indexerAddStruct( node );
664
665 VISIT_END( node );
666}
667
668template< typename pass_type >
669Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) {
670 MUTATE_START( node );
671
672 // make up a forward declaration and add it before processing the members
673 // needs to be on the heap because addStruct saves the pointer
674 indexerAddStructFwd( node );
675
676 {
677 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
678 maybeMutate_impl( node->parameters, *this );
679 maybeMutate_impl( node->members , *this );
680 maybeMutate_impl( node->attributes, *this );
681 }
682
683 // this addition replaces the forward declaration
684 indexerAddStruct( node );
685
686 MUTATE_END( Declaration, node );
687}
688
689//--------------------------------------------------------------------------
690// UnionDecl
691template< typename pass_type >
692void PassVisitor< pass_type >::visit( UnionDecl * node ) {
693 VISIT_START( node );
694
695 // make up a forward declaration and add it before processing the members
696 indexerAddUnionFwd( node );
697
698 {
699 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
700 maybeAccept_impl( node->parameters, *this );
701 maybeAccept_impl( node->members , *this );
702 maybeAccept_impl( node->attributes, *this );
703 }
704
705 indexerAddUnion( node );
706
707 VISIT_END( node );
708}
709template< typename pass_type >
710void PassVisitor< pass_type >::visit( const UnionDecl * node ) {
711 VISIT_START( node );
712
713 // make up a forward declaration and add it before processing the members
714 indexerAddUnionFwd( node );
715
716 {
717 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
718 maybeAccept_impl( node->parameters, *this );
719 maybeAccept_impl( node->members , *this );
720 maybeAccept_impl( node->attributes, *this );
721 }
722
723 indexerAddUnion( node );
724
725 VISIT_END( node );
726}
727
728template< typename pass_type >
729Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) {
730 MUTATE_START( node );
731
732 // make up a forward declaration and add it before processing the members
733 indexerAddUnionFwd( node );
734
735 {
736 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
737 maybeMutate_impl( node->parameters, *this );
738 maybeMutate_impl( node->members , *this );
739 maybeMutate_impl( node->attributes, *this );
740 }
741
742 indexerAddUnion( node );
743
744 MUTATE_END( Declaration, node );
745}
746
747//--------------------------------------------------------------------------
748// EnumDecl
749template< typename pass_type >
750void PassVisitor< pass_type >::visit( EnumDecl * node ) {
751 VISIT_START( node );
752
753 indexerAddEnum( node );
754
755 // unlike structs, traits, and unions, enums inject their members into the global scope
756 maybeAccept_impl( node->parameters, *this );
757 maybeAccept_impl( node->members , *this );
758 maybeAccept_impl( node->attributes, *this );
759
760 VISIT_END( node );
761}
762
763template< typename pass_type >
764void PassVisitor< pass_type >::visit( const EnumDecl * node ) {
765 VISIT_START( node );
766
767 indexerAddEnum( node );
768
769 // unlike structs, traits, and unions, enums inject their members into the global scope
770 maybeAccept_impl( node->parameters, *this );
771 maybeAccept_impl( node->members , *this );
772 maybeAccept_impl( node->attributes, *this );
773
774 VISIT_END( node );
775}
776
777template< typename pass_type >
778Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) {
779 MUTATE_START( node );
780
781 indexerAddEnum( node );
782
783 // unlike structs, traits, and unions, enums inject their members into the global scope
784 maybeMutate_impl( node->parameters, *this );
785 maybeMutate_impl( node->members , *this );
786 maybeMutate_impl( node->attributes, *this );
787
788 MUTATE_END( Declaration, node );
789}
790
791template< typename pass_type >
792void PassVisitor< pass_type >::visit( AdtDecl * node ) {
793 VISIT_START( node );
794
795 indexerAddAdtFwd( node );
796
797 // unlike structs, traits, and unions, enums inject their members into the global scope
798 maybeAccept_impl( node->data_constructors, *this );
799 maybeAccept_impl( node->data_union, *this );
800 maybeAccept_impl( node->tag, *this );
801
802 maybeAccept_impl( node->parameters, *this );
803 maybeAccept_impl( node->members , *this );
804 maybeAccept_impl( node->attributes, *this );
805
806 VISIT_END( node );
807}
808
809template< typename pass_type >
810void PassVisitor< pass_type >::visit( const AdtDecl * node ) {
811 VISIT_START( node );
812
813 indexerAddAdtFwd( node );
814
815 maybeAccept_impl( node->data_constructors, *this );
816 maybeAccept_impl( node->data_union, *this );
817 maybeAccept_impl( node->tag, *this );
818
819 maybeAccept_impl( node->parameters, *this );
820 maybeAccept_impl( node->members , *this );
821 maybeAccept_impl( node->attributes, *this );
822
823
824 VISIT_END( node );
825}
826
827template< typename pass_type >
828Declaration * PassVisitor< pass_type >::mutate( AdtDecl * node ) {
829 MUTATE_START( node );
830
831 indexerAddAdtFwd( node );
832
833 maybeMutate_impl( node->data_constructors, *this );
834 maybeMutate_impl( node->data_union, *this );
835 maybeMutate_impl( node->tag, *this );
836
837 maybeMutate_impl( node->parameters, *this );
838 maybeMutate_impl( node->members , *this );
839 maybeMutate_impl( node->attributes, *this );
840
841 MUTATE_END( Declaration, node );
842}
843
844//--------------------------------------------------------------------------
845// TraitDecl
846template< typename pass_type >
847void PassVisitor< pass_type >::visit( TraitDecl * node ) {
848 VISIT_START( node );
849
850 {
851 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
852 maybeAccept_impl( node->parameters, *this );
853 maybeAccept_impl( node->members , *this );
854 maybeAccept_impl( node->attributes, *this );
855 }
856
857 indexerAddTrait( node );
858
859 VISIT_END( node );
860}
861
862template< typename pass_type >
863void PassVisitor< pass_type >::visit( const TraitDecl * node ) {
864 VISIT_START( node );
865
866 {
867 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
868 maybeAccept_impl( node->parameters, *this );
869 maybeAccept_impl( node->members , *this );
870 maybeAccept_impl( node->attributes, *this );
871 }
872
873 indexerAddTrait( node );
874
875 VISIT_END( node );
876}
877
878template< typename pass_type >
879Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) {
880 MUTATE_START( node );
881
882 {
883 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
884 maybeMutate_impl( node->parameters, *this );
885 maybeMutate_impl( node->members , *this );
886 maybeMutate_impl( node->attributes, *this );
887 }
888
889 indexerAddTrait( node );
890
891 MUTATE_END( Declaration, node );
892}
893
894//--------------------------------------------------------------------------
895// TypeDecl
896template< typename pass_type >
897void PassVisitor< pass_type >::visit( TypeDecl * node ) {
898 VISIT_START( node );
899
900 {
901 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
902 maybeAccept_impl( node->base , *this );
903 }
904
905 // see A NOTE ON THE ORDER OF TRAVERSAL, above
906 // note that assertions come after the type is added to the symtab, since they are not part of the type proper
907 // and may depend on the type itself
908 indexerAddType( node );
909
910 maybeAccept_impl( node->assertions, *this );
911
912 indexerScopedAccept( node->init, *this );
913
914 VISIT_END( node );
915}
916
917
918template< typename pass_type >
919void PassVisitor< pass_type >::visit( const TypeDecl * node ) {
920 VISIT_START( node );
921
922 {
923 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
924 maybeAccept_impl( node->base , *this );
925 }
926
927 // see A NOTE ON THE ORDER OF TRAVERSAL, above
928 // note that assertions come after the type is added to the symtab, since they are not part of the type proper
929 // and may depend on the type itself
930 indexerAddType( node );
931
932 maybeAccept_impl( node->assertions, *this );
933
934 indexerScopedAccept( node->init, *this );
935
936 VISIT_END( node );
937}
938
939template< typename pass_type >
940Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
941 MUTATE_START( node );
942
943 {
944 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
945 maybeMutate_impl( node->base , *this );
946 }
947
948 // see A NOTE ON THE ORDER OF TRAVERSAL, above
949 // note that assertions come after the type is added to the symtab, since they are not part of the type proper
950 // and may depend on the type itself
951 indexerAddType( node );
952
953 maybeMutate_impl( node->assertions, *this );
954
955 indexerScopedMutate( node->init, *this );
956
957 MUTATE_END( Declaration, node );
958}
959
960//--------------------------------------------------------------------------
961// TypedefDecl
962template< typename pass_type >
963void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
964 VISIT_START( node );
965
966 {
967 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
968 maybeAccept_impl( node->base , *this );
969 }
970
971 indexerAddType( node );
972
973 maybeAccept_impl( node->assertions, *this );
974
975 VISIT_END( node );
976}
977
978template< typename pass_type >
979void PassVisitor< pass_type >::visit( const TypedefDecl * node ) {
980 VISIT_START( node );
981
982 {
983 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
984 maybeAccept_impl( node->base , *this );
985 }
986
987 indexerAddType( node );
988
989 maybeAccept_impl( node->assertions, *this );
990
991 VISIT_END( node );
992}
993
994template< typename pass_type >
995Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) {
996 MUTATE_START( node );
997
998 {
999 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1000 maybeMutate_impl( node->base , *this );
1001 }
1002
1003 indexerAddType( node );
1004
1005 maybeMutate_impl( node->assertions, *this );
1006
1007 MUTATE_END( Declaration, node );
1008}
1009
1010//--------------------------------------------------------------------------
1011// AsmDecl
1012template< typename pass_type >
1013void PassVisitor< pass_type >::visit( AsmDecl * node ) {
1014 VISIT_START( node );
1015
1016 maybeAccept_impl( node->stmt, *this );
1017
1018 VISIT_END( node );
1019}
1020
1021template< typename pass_type >
1022void PassVisitor< pass_type >::visit( const AsmDecl * node ) {
1023 VISIT_START( node );
1024
1025 maybeAccept_impl( node->stmt, *this );
1026
1027 VISIT_END( node );
1028}
1029
1030template< typename pass_type >
1031AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) {
1032 MUTATE_START( node );
1033
1034 maybeMutate_impl( node->stmt, *this );
1035
1036 MUTATE_END( AsmDecl, node );
1037}
1038
1039//--------------------------------------------------------------------------
1040// DirectiveDecl
1041template< typename pass_type >
1042void PassVisitor< pass_type >::visit( DirectiveDecl * node ) {
1043 VISIT_START( node );
1044
1045 maybeAccept_impl( node->stmt, *this );
1046
1047 VISIT_END( node );
1048}
1049
1050template< typename pass_type >
1051void PassVisitor< pass_type >::visit( const DirectiveDecl * node ) {
1052 VISIT_START( node );
1053
1054 maybeAccept_impl( node->stmt, *this );
1055
1056 VISIT_END( node );
1057}
1058
1059template< typename pass_type >
1060DirectiveDecl * PassVisitor< pass_type >::mutate( DirectiveDecl * node ) {
1061 MUTATE_START( node );
1062
1063 maybeMutate_impl( node->stmt, *this );
1064
1065 MUTATE_END( DirectiveDecl, node );
1066}
1067
1068//--------------------------------------------------------------------------
1069// StaticAssertDecl
1070template< typename pass_type >
1071void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) {
1072 VISIT_START( node );
1073
1074 node->condition = visitExpression( node->condition );
1075 maybeAccept_impl( node->message, *this );
1076
1077 VISIT_END( node );
1078}
1079
1080template< typename pass_type >
1081void PassVisitor< pass_type >::visit( const StaticAssertDecl * node ) {
1082 VISIT_START( node );
1083
1084 visitExpression( node->condition );
1085 maybeAccept_impl( node->message, *this );
1086
1087 VISIT_END( node );
1088}
1089
1090template< typename pass_type >
1091StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
1092 MUTATE_START( node );
1093
1094 node->condition = mutateExpression( node->condition );
1095 maybeMutate_impl( node->message, *this );
1096
1097 MUTATE_END( StaticAssertDecl, node );
1098}
1099
1100//--------------------------------------------------------------------------
1101// InlineMemberDecl
1102template< typename pass_type >
1103void PassVisitor< pass_type >::visit( InlineMemberDecl * node ) {
1104 VISIT_START( node );
1105
1106 maybeAccept_impl( node->type, *this );
1107
1108 VISIT_END( node );
1109}
1110
1111template< typename pass_type >
1112void PassVisitor< pass_type >::visit( const InlineMemberDecl * node ) {
1113 VISIT_START( node );
1114
1115 maybeAccept_impl( node->type, *this );
1116
1117 VISIT_END( node );
1118}
1119
1120template< typename pass_type >
1121DeclarationWithType * PassVisitor< pass_type >::mutate( InlineMemberDecl * node ) {
1122 MUTATE_START( node );
1123
1124 maybeMutate_impl( node->type, *this );
1125
1126 MUTATE_END( DeclarationWithType, node );
1127}
1128
1129//--------------------------------------------------------------------------
1130// CompoundStmt
1131template< typename pass_type >
1132void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
1133 VISIT_START( node );
1134 {
1135 // Do not enter a new scope if atFunctionTop is true, don't leave one either.
1136 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
1137 auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
1138 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } );
1139 atFunctionTop = false;
1140 visitStatementList( node->kids );
1141 }
1142 VISIT_END( node );
1143}
1144
1145template< typename pass_type >
1146void PassVisitor< pass_type >::visit( const CompoundStmt * node ) {
1147 VISIT_START( node );
1148 {
1149 // Do not enter a new scope if atFunctionTop is true, don't leave one either.
1150 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
1151 auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
1152 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } );
1153 atFunctionTop = false;
1154 visitStatementList( node->kids );
1155 }
1156 VISIT_END( node );
1157}
1158
1159template< typename pass_type >
1160CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
1161 MUTATE_START( node );
1162 {
1163 // Do not enter a new scope if atFunctionTop is true, don't leave one either.
1164 ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
1165 auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
1166 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } );
1167 atFunctionTop = false;
1168 mutateStatementList( node->kids );
1169 }
1170 MUTATE_END( CompoundStmt, node );
1171}
1172
1173//--------------------------------------------------------------------------
1174// ExprStmt
1175template< typename pass_type >
1176void PassVisitor< pass_type >::visit( ExprStmt * node ) {
1177 VISIT_START( node );
1178
1179 visitExpression( node->expr );
1180
1181 VISIT_END( node );
1182}
1183
1184template< typename pass_type >
1185void PassVisitor< pass_type >::visit( const ExprStmt * node ) {
1186 VISIT_START( node );
1187
1188 visitExpression( node->expr );
1189
1190 VISIT_END( node );
1191}
1192
1193template< typename pass_type >
1194Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
1195 MUTATE_START( node );
1196
1197 node->expr = mutateExpression( node->expr );
1198
1199 MUTATE_END( Statement, node );
1200}
1201
1202//--------------------------------------------------------------------------
1203// AsmStmt
1204template< typename pass_type >
1205void PassVisitor< pass_type >::visit( AsmStmt * node ) {
1206 VISIT_START( node )
1207
1208 maybeAccept_impl( node->instruction, *this );
1209 maybeAccept_impl( node->output, *this );
1210 maybeAccept_impl( node->input, *this );
1211 maybeAccept_impl( node->clobber, *this );
1212
1213 VISIT_END( node );
1214}
1215
1216template< typename pass_type >
1217void PassVisitor< pass_type >::visit( const AsmStmt * node ) {
1218 VISIT_START( node )
1219
1220 maybeAccept_impl( node->instruction, *this );
1221 maybeAccept_impl( node->output, *this );
1222 maybeAccept_impl( node->input, *this );
1223 maybeAccept_impl( node->clobber, *this );
1224
1225 VISIT_END( node );
1226}
1227
1228template< typename pass_type >
1229Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
1230 MUTATE_START( node );
1231
1232 maybeMutate_impl( node->instruction, *this );
1233 maybeMutate_impl( node->output, *this );
1234 maybeMutate_impl( node->input, *this );
1235 maybeMutate_impl( node->clobber, *this );
1236
1237 MUTATE_END( Statement, node );
1238}
1239
1240//--------------------------------------------------------------------------
1241// AsmStmt
1242template< typename pass_type >
1243void PassVisitor< pass_type >::visit( DirectiveStmt * node ) {
1244 VISIT_START( node )
1245
1246 VISIT_END( node );
1247}
1248
1249template< typename pass_type >
1250void PassVisitor< pass_type >::visit( const DirectiveStmt * node ) {
1251 VISIT_START( node )
1252
1253 VISIT_END( node );
1254}
1255
1256template< typename pass_type >
1257Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
1258 MUTATE_START( node );
1259
1260 MUTATE_END( Statement, node );
1261}
1262
1263//--------------------------------------------------------------------------
1264// IfStmt
1265template< typename pass_type >
1266void PassVisitor< pass_type >::visit( IfStmt * node ) {
1267 VISIT_START( node );
1268 {
1269 // if statements introduce a level of scope (for the initialization)
1270 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1271 maybeAccept_impl( node->initialization, *this );
1272 visitExpression ( node->condition );
1273 node->then = visitStatement( node->then );
1274 node->else_ = visitStatement( node->else_ );
1275 }
1276 VISIT_END( node );
1277}
1278
1279template< typename pass_type >
1280void PassVisitor< pass_type >::visit( const IfStmt * node ) {
1281 VISIT_START( node );
1282 {
1283 // if statements introduce a level of scope (for the initialization)
1284 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1285 maybeAccept_impl( node->initialization, *this );
1286 visitExpression ( node->condition );
1287 visitStatement ( node->then );
1288 visitStatement ( node->else_ );
1289 }
1290 VISIT_END( node );
1291}
1292
1293template< typename pass_type >
1294Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
1295 MUTATE_START( node );
1296 {
1297 // if statements introduce a level of scope (for the initialization)
1298 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1299 maybeMutate_impl( node->initialization, *this );
1300 node->condition = mutateExpression( node->condition );
1301 node->then = mutateStatement ( node->then );
1302 node->else_ = mutateStatement ( node->else_ );
1303 }
1304 MUTATE_END( Statement, node );
1305}
1306
1307//--------------------------------------------------------------------------
1308// WhileDoStmt
1309template< typename pass_type >
1310void PassVisitor< pass_type >::visit( WhileDoStmt * node ) {
1311 VISIT_START( node );
1312
1313 {
1314 // while statements introduce a level of scope (for the initialization)
1315 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1316 maybeAccept_impl( node->initialization, *this );
1317 visitExpression ( node->condition );
1318 node->body = visitStatement( node->body );
1319 }
1320
1321 VISIT_END( node );
1322}
1323
1324template< typename pass_type >
1325void PassVisitor< pass_type >::visit( const WhileDoStmt * node ) {
1326 VISIT_START( node );
1327
1328 {
1329 // while statements introduce a level of scope (for the initialization)
1330 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1331 maybeAccept_impl( node->initialization, *this );
1332 visitExpression ( node->condition );
1333 visitStatement ( node->body );
1334 }
1335
1336 VISIT_END( node );
1337}
1338
1339template< typename pass_type >
1340Statement * PassVisitor< pass_type >::mutate( WhileDoStmt * node ) {
1341 MUTATE_START( node );
1342
1343 {
1344 // while statements introduce a level of scope (for the initialization)
1345 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1346 maybeMutate_impl( node->initialization, *this );
1347 node->condition = mutateExpression( node->condition );
1348 node->body = mutateStatement ( node->body );
1349 }
1350
1351
1352 MUTATE_END( Statement, node );
1353}
1354
1355//--------------------------------------------------------------------------
1356// ForStmt
1357template< typename pass_type >
1358void PassVisitor< pass_type >::visit( ForStmt * node ) {
1359 VISIT_START( node );
1360 {
1361 // for statements introduce a level of scope (for the initialization)
1362 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1363 maybeAccept_impl( node->initialization, *this );
1364 visitExpression( node->condition );
1365 visitExpression( node->increment );
1366 node->body = visitStatement( node->body );
1367 }
1368 VISIT_END( node );
1369}
1370
1371template< typename pass_type >
1372void PassVisitor< pass_type >::visit( const ForStmt * node ) {
1373 VISIT_START( node );
1374 {
1375 // for statements introduce a level of scope (for the initialization)
1376 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1377 maybeAccept_impl( node->initialization, *this );
1378 visitExpression( node->condition );
1379 visitExpression( node->increment );
1380 visitStatement ( node->body );
1381 }
1382 VISIT_END( node );
1383}
1384
1385template< typename pass_type >
1386Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
1387 MUTATE_START( node );
1388 {
1389 // for statements introduce a level of scope (for the initialization)
1390 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1391 maybeMutate_impl( node->initialization, *this );
1392 node->condition = mutateExpression( node->condition );
1393 node->increment = mutateExpression( node->increment );
1394 node->body = mutateStatement ( node->body );
1395 }
1396 MUTATE_END( Statement, node );
1397}
1398
1399//--------------------------------------------------------------------------
1400// SwitchStmt
1401template< typename pass_type >
1402void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
1403 VISIT_START( node );
1404
1405 visitExpression ( node->condition );
1406 visitStatementList( node->statements );
1407
1408 VISIT_END( node );
1409}
1410
1411template< typename pass_type >
1412void PassVisitor< pass_type >::visit( const SwitchStmt * node ) {
1413 VISIT_START( node );
1414
1415 visitExpression ( node->condition );
1416 visitStatementList( node->statements );
1417
1418 VISIT_END( node );
1419}
1420
1421template< typename pass_type >
1422Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
1423 MUTATE_START( node );
1424
1425 node->condition = mutateExpression( node->condition );
1426 mutateStatementList( node->statements );
1427
1428 MUTATE_END( Statement, node );
1429}
1430
1431//--------------------------------------------------------------------------
1432// CaseStmt
1433template< typename pass_type >
1434void PassVisitor< pass_type >::visit( CaseStmt * node ) {
1435 VISIT_START( node );
1436
1437 visitExpression ( node->condition );
1438 visitStatementList( node->stmts );
1439
1440 VISIT_END( node );
1441}
1442
1443template< typename pass_type >
1444void PassVisitor< pass_type >::visit( const CaseStmt * node ) {
1445 VISIT_START( node );
1446
1447 visitExpression ( node->condition );
1448 visitStatementList( node->stmts );
1449
1450 VISIT_END( node );
1451}
1452
1453template< typename pass_type >
1454Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
1455 MUTATE_START( node );
1456
1457 node->condition = mutateExpression( node->condition );
1458 mutateStatementList( node->stmts );
1459
1460 MUTATE_END( Statement, node );
1461}
1462
1463//--------------------------------------------------------------------------
1464// BranchStmt
1465template< typename pass_type >
1466void PassVisitor< pass_type >::visit( BranchStmt * node ) {
1467 VISIT_START( node );
1468 VISIT_END( node );
1469}
1470
1471template< typename pass_type >
1472void PassVisitor< pass_type >::visit( const BranchStmt * node ) {
1473 VISIT_START( node );
1474 VISIT_END( node );
1475}
1476
1477template< typename pass_type >
1478Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
1479 MUTATE_START( node );
1480 MUTATE_END( Statement, node );
1481}
1482
1483//--------------------------------------------------------------------------
1484// ReturnStmt
1485template< typename pass_type >
1486void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
1487 VISIT_START( node );
1488
1489 visitExpression( node->expr );
1490
1491 VISIT_END( node );
1492}
1493
1494template< typename pass_type >
1495void PassVisitor< pass_type >::visit( const ReturnStmt * node ) {
1496 VISIT_START( node );
1497
1498 visitExpression( node->expr );
1499
1500 VISIT_END( node );
1501}
1502
1503template< typename pass_type >
1504Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
1505 MUTATE_START( node );
1506
1507 node->expr = mutateExpression( node->expr );
1508
1509 MUTATE_END( Statement, node );
1510}
1511
1512//--------------------------------------------------------------------------
1513// ThrowStmt
1514template< typename pass_type >
1515void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
1516 VISIT_START( node );
1517
1518 maybeAccept_impl( node->expr, *this );
1519 maybeAccept_impl( node->target, *this );
1520
1521 VISIT_END( node );
1522}
1523
1524template< typename pass_type >
1525void PassVisitor< pass_type >::visit( const ThrowStmt * node ) {
1526 VISIT_START( node );
1527
1528 maybeAccept_impl( node->expr, *this );
1529 maybeAccept_impl( node->target, *this );
1530
1531 VISIT_END( node );
1532}
1533
1534template< typename pass_type >
1535Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
1536 MUTATE_START( node );
1537
1538 maybeMutate_impl( node->expr, *this );
1539 maybeMutate_impl( node->target, *this );
1540
1541 MUTATE_END( Statement, node );
1542}
1543
1544//--------------------------------------------------------------------------
1545// TryStmt
1546template< typename pass_type >
1547void PassVisitor< pass_type >::visit( TryStmt * node ) {
1548 VISIT_START( node );
1549
1550 maybeAccept_impl( node->block , *this );
1551 maybeAccept_impl( node->handlers , *this );
1552 maybeAccept_impl( node->finallyBlock, *this );
1553
1554 VISIT_END( node );
1555}
1556
1557template< typename pass_type >
1558void PassVisitor< pass_type >::visit( const TryStmt * node ) {
1559 VISIT_START( node );
1560
1561 maybeAccept_impl( node->block , *this );
1562 maybeAccept_impl( node->handlers , *this );
1563 maybeAccept_impl( node->finallyBlock, *this );
1564
1565 VISIT_END( node );
1566}
1567
1568template< typename pass_type >
1569Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
1570 MUTATE_START( node );
1571
1572 maybeMutate_impl( node->block , *this );
1573 maybeMutate_impl( node->handlers , *this );
1574 maybeMutate_impl( node->finallyBlock, *this );
1575
1576 MUTATE_END( Statement, node );
1577}
1578
1579//--------------------------------------------------------------------------
1580// CatchStmt
1581template< typename pass_type >
1582void PassVisitor< pass_type >::visit( CatchStmt * node ) {
1583 VISIT_START( node );
1584 {
1585 // catch statements introduce a level of scope (for the caught exception)
1586 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1587 maybeAccept_impl( node->decl, *this );
1588 node->cond = visitExpression( node->cond );
1589 node->body = visitStatement ( node->body );
1590 }
1591 VISIT_END( node );
1592}
1593
1594template< typename pass_type >
1595void PassVisitor< pass_type >::visit( const CatchStmt * node ) {
1596 VISIT_START( node );
1597 {
1598 // catch statements introduce a level of scope (for the caught exception)
1599 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1600 maybeAccept_impl( node->decl, *this );
1601 visitExpression ( node->cond );
1602 visitStatement ( node->body );
1603 }
1604 VISIT_END( node );
1605}
1606
1607template< typename pass_type >
1608Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
1609 MUTATE_START( node );
1610 {
1611 // catch statements introduce a level of scope (for the caught exception)
1612 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1613 maybeMutate_impl( node->decl, *this );
1614 node->cond = mutateExpression( node->cond );
1615 node->body = mutateStatement ( node->body );
1616 }
1617 MUTATE_END( Statement, node );
1618}
1619
1620//--------------------------------------------------------------------------
1621// FinallyStmt
1622template< typename pass_type >
1623void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
1624 VISIT_START( node );
1625
1626 maybeAccept_impl( node->block, *this );
1627
1628 VISIT_END( node );
1629}
1630
1631template< typename pass_type >
1632void PassVisitor< pass_type >::visit( const FinallyStmt * node ) {
1633 VISIT_START( node );
1634
1635 maybeAccept_impl( node->block, *this );
1636
1637 VISIT_END( node );
1638}
1639
1640template< typename pass_type >
1641Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
1642 MUTATE_START( node );
1643
1644 maybeMutate_impl( node->block, *this );
1645
1646 MUTATE_END( Statement, node );
1647}
1648
1649//--------------------------------------------------------------------------
1650// SuspendStmt
1651template< typename pass_type >
1652void PassVisitor< pass_type >::visit( SuspendStmt * node ) {
1653 VISIT_START( node );
1654
1655 maybeAccept_impl( node->then , *this );
1656
1657 VISIT_END( node );
1658}
1659
1660template< typename pass_type >
1661void PassVisitor< pass_type >::visit( const SuspendStmt * node ) {
1662 VISIT_START( node );
1663
1664 maybeAccept_impl( node->then , *this );
1665
1666 VISIT_END( node );
1667}
1668
1669template< typename pass_type >
1670Statement * PassVisitor< pass_type >::mutate( SuspendStmt * node ) {
1671 MUTATE_START( node );
1672
1673 maybeMutate_impl( node->then , *this );
1674
1675 MUTATE_END( Statement, node );
1676}
1677
1678//--------------------------------------------------------------------------
1679// WaitForStmt
1680template< typename pass_type >
1681void PassVisitor< pass_type >::visit( WaitForStmt * node ) {
1682 VISIT_START( node );
1683
1684 for( auto & clause : node->clauses ) {
1685 maybeAccept_impl( clause.target.function, *this );
1686 maybeAccept_impl( clause.target.arguments, *this );
1687
1688 maybeAccept_impl( clause.statement, *this );
1689 maybeAccept_impl( clause.condition, *this );
1690 }
1691
1692 maybeAccept_impl( node->timeout.time, *this );
1693 maybeAccept_impl( node->timeout.statement, *this );
1694 maybeAccept_impl( node->timeout.condition, *this );
1695 maybeAccept_impl( node->orelse.statement, *this );
1696 maybeAccept_impl( node->orelse.condition, *this );
1697
1698 VISIT_END( node );
1699}
1700
1701template< typename pass_type >
1702void PassVisitor< pass_type >::visit( const WaitForStmt * node ) {
1703 VISIT_START( node );
1704
1705 for( auto & clause : node->clauses ) {
1706 maybeAccept_impl( clause.target.function, *this );
1707 maybeAccept_impl( clause.target.arguments, *this );
1708
1709 maybeAccept_impl( clause.statement, *this );
1710 maybeAccept_impl( clause.condition, *this );
1711 }
1712
1713 maybeAccept_impl( node->timeout.time, *this );
1714 maybeAccept_impl( node->timeout.statement, *this );
1715 maybeAccept_impl( node->timeout.condition, *this );
1716 maybeAccept_impl( node->orelse.statement, *this );
1717 maybeAccept_impl( node->orelse.condition, *this );
1718
1719 VISIT_END( node );
1720}
1721
1722template< typename pass_type >
1723Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
1724 MUTATE_START( node );
1725
1726 for( auto & clause : node->clauses ) {
1727 maybeMutate_impl( clause.target.function, *this );
1728 maybeMutate_impl( clause.target.arguments, *this );
1729
1730 maybeMutate_impl( clause.statement, *this );
1731 maybeMutate_impl( clause.condition, *this );
1732 }
1733
1734 maybeMutate_impl( node->timeout.time, *this );
1735 maybeMutate_impl( node->timeout.statement, *this );
1736 maybeMutate_impl( node->timeout.condition, *this );
1737 maybeMutate_impl( node->orelse.statement, *this );
1738 maybeMutate_impl( node->orelse.condition, *this );
1739
1740 MUTATE_END( Statement, node );
1741}
1742
1743
1744
1745//--------------------------------------------------------------------------
1746// WithStmt
1747template< typename pass_type >
1748void PassVisitor< pass_type >::visit( WithStmt * node ) {
1749 VISIT_START( node );
1750 maybeAccept_impl( node->exprs, *this );
1751 {
1752 // catch statements introduce a level of scope (for the caught exception)
1753 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1754 indexerAddWith( node->exprs, node );
1755 maybeAccept_impl( node->stmt, *this );
1756 }
1757 VISIT_END( node );
1758}
1759
1760template< typename pass_type >
1761void PassVisitor< pass_type >::visit( const WithStmt * node ) {
1762 VISIT_START( node );
1763 maybeAccept_impl( node->exprs, *this );
1764 {
1765 // catch statements introduce a level of scope (for the caught exception)
1766 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1767 indexerAddWith( node->exprs, node );
1768 maybeAccept_impl( node->stmt, *this );
1769 }
1770 VISIT_END( node );
1771}
1772
1773template< typename pass_type >
1774Declaration * PassVisitor< pass_type >::mutate( WithStmt * node ) {
1775 MUTATE_START( node );
1776 maybeMutate_impl( node->exprs, *this );
1777 {
1778 // catch statements introduce a level of scope (for the caught exception)
1779 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1780 indexerAddWith( node->exprs, node );
1781 maybeMutate_impl( node->stmt, *this );
1782 }
1783 MUTATE_END( Declaration, node );
1784}
1785
1786//--------------------------------------------------------------------------
1787// NullStmt
1788template< typename pass_type >
1789void PassVisitor< pass_type >::visit( NullStmt * node ) {
1790 VISIT_START( node );
1791 VISIT_END( node );
1792}
1793
1794template< typename pass_type >
1795void PassVisitor< pass_type >::visit( const NullStmt * node ) {
1796 VISIT_START( node );
1797 VISIT_END( node );
1798}
1799
1800template< typename pass_type >
1801NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
1802 MUTATE_START( node );
1803 MUTATE_END( NullStmt, node );
1804}
1805
1806//--------------------------------------------------------------------------
1807// DeclStmt
1808template< typename pass_type >
1809void PassVisitor< pass_type >::visit( DeclStmt * node ) {
1810 VISIT_START( node );
1811
1812 maybeAccept_impl( node->decl, *this );
1813
1814 VISIT_END( node );
1815}
1816
1817template< typename pass_type >
1818void PassVisitor< pass_type >::visit( const DeclStmt * node ) {
1819 VISIT_START( node );
1820
1821 maybeAccept_impl( node->decl, *this );
1822
1823 VISIT_END( node );
1824}
1825
1826template< typename pass_type >
1827Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
1828 MUTATE_START( node );
1829
1830 maybeMutate_impl( node->decl, *this );
1831
1832 MUTATE_END( Statement, node );
1833}
1834
1835//--------------------------------------------------------------------------
1836// ImplicitCtorDtorStmt
1837template< typename pass_type >
1838void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
1839 VISIT_START( node );
1840
1841 maybeAccept_impl( node->callStmt, *this );
1842
1843 VISIT_END( node );
1844}
1845
1846template< typename pass_type >
1847void PassVisitor< pass_type >::visit( const ImplicitCtorDtorStmt * node ) {
1848 VISIT_START( node );
1849
1850 maybeAccept_impl( node->callStmt, *this );
1851
1852 VISIT_END( node );
1853}
1854
1855template< typename pass_type >
1856Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
1857 MUTATE_START( node );
1858
1859 maybeMutate_impl( node->callStmt, *this );
1860
1861 MUTATE_END( Statement, node );
1862}
1863
1864//--------------------------------------------------------------------------
1865// MutexStmt
1866template< typename pass_type >
1867void PassVisitor< pass_type >::visit( MutexStmt * node ) {
1868 VISIT_START( node );
1869 // mutex statements introduce a level of scope (for the initialization)
1870 maybeAccept_impl( node->mutexObjs, *this );
1871 {
1872 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1873 node->stmt = visitStatement( node->stmt );
1874 }
1875 VISIT_END( node );
1876}
1877
1878template< typename pass_type >
1879void PassVisitor< pass_type >::visit( const MutexStmt * node ) {
1880 VISIT_START( node );
1881 maybeAccept_impl( node->mutexObjs, *this );
1882 {
1883 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1884 visitStatement( node->stmt );
1885 }
1886 VISIT_END( node );
1887}
1888
1889template< typename pass_type >
1890Statement * PassVisitor< pass_type >::mutate( MutexStmt * node ) {
1891 MUTATE_START( node );
1892 maybeMutate_impl( node->mutexObjs, *this );
1893 {
1894 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1895 node->stmt = mutateStatement( node->stmt );
1896 }
1897 MUTATE_END( Statement, node );
1898}
1899
1900//--------------------------------------------------------------------------
1901// ApplicationExpr
1902template< typename pass_type >
1903void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
1904 VISIT_START( node );
1905
1906 indexerScopedAccept( node->result , *this );
1907 maybeAccept_impl ( node->function, *this );
1908 maybeAccept_impl ( node->args , *this );
1909
1910 VISIT_END( node );
1911}
1912
1913template< typename pass_type >
1914void PassVisitor< pass_type >::visit( const ApplicationExpr * node ) {
1915 VISIT_START( node );
1916
1917 indexerScopedAccept( node->result , *this );
1918 maybeAccept_impl ( node->function, *this );
1919 maybeAccept_impl ( node->args , *this );
1920
1921 VISIT_END( node );
1922}
1923
1924template< typename pass_type >
1925Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) {
1926 MUTATE_START( node );
1927
1928 indexerScopedMutate( node->env , *this );
1929 indexerScopedMutate( node->result , *this );
1930 maybeMutate_impl ( node->function, *this );
1931 maybeMutate_impl ( node->args , *this );
1932
1933 MUTATE_END( Expression, node );
1934}
1935
1936//--------------------------------------------------------------------------
1937// UntypedExpr
1938template< typename pass_type >
1939void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
1940 VISIT_START( node );
1941
1942 // maybeAccept_impl( node->get_env(), *this );
1943 indexerScopedAccept( node->result, *this );
1944
1945 for ( auto expr : node->args ) {
1946 visitExpression( expr );
1947 }
1948
1949 VISIT_END( node );
1950}
1951
1952template< typename pass_type >
1953void PassVisitor< pass_type >::visit( const UntypedExpr * node ) {
1954 VISIT_START( node );
1955
1956 indexerScopedAccept( node->result, *this );
1957
1958 for ( auto expr : node->args ) {
1959 visitExpression( expr );
1960 }
1961
1962 VISIT_END( node );
1963}
1964
1965template< typename pass_type >
1966Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
1967 MUTATE_START( node );
1968
1969 indexerScopedMutate( node->env , *this );
1970 indexerScopedMutate( node->result, *this );
1971
1972 for ( auto& expr : node->args ) {
1973 expr = mutateExpression( expr );
1974 }
1975
1976 MUTATE_END( Expression, node );
1977}
1978
1979//--------------------------------------------------------------------------
1980// NameExpr
1981template< typename pass_type >
1982void PassVisitor< pass_type >::visit( NameExpr * node ) {
1983 VISIT_START( node );
1984
1985 indexerScopedAccept( node->result, *this );
1986
1987 VISIT_END( node );
1988}
1989
1990template< typename pass_type >
1991void PassVisitor< pass_type >::visit( const NameExpr * node ) {
1992 VISIT_START( node );
1993
1994 indexerScopedAccept( node->result, *this );
1995
1996 VISIT_END( node );
1997}
1998
1999template< typename pass_type >
2000Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
2001 MUTATE_START( node );
2002
2003 indexerScopedMutate( node->env , *this );
2004 indexerScopedMutate( node->result, *this );
2005
2006 MUTATE_END( Expression, node );
2007}
2008
2009//--------------------------------------------------------------------------
2010// QualifiedNameExpr
2011template< typename pass_type >
2012void PassVisitor< pass_type >::visit( QualifiedNameExpr * node ) {
2013 VISIT_START( node );
2014
2015 indexerScopedAccept( node->result, *this );
2016 maybeAccept_impl( node->type_decl, *this );
2017
2018 VISIT_END( node );
2019}
2020
2021template< typename pass_type >
2022void PassVisitor< pass_type >::visit( const QualifiedNameExpr * node ) {
2023 VISIT_START( node );
2024
2025 indexerScopedAccept( node->result, *this );
2026 maybeAccept_impl( node->type_decl, *this );
2027
2028 VISIT_END( node );
2029}
2030
2031template< typename pass_type >
2032Expression * PassVisitor< pass_type >::mutate( QualifiedNameExpr * node ) {
2033 MUTATE_START( node );
2034
2035 indexerScopedMutate( node->env , *this );
2036 indexerScopedMutate( node->result, *this );
2037 maybeMutate_impl( node->type_decl, *this );
2038
2039 MUTATE_END( Expression, node );
2040}
2041
2042//--------------------------------------------------------------------------
2043// CastExpr
2044template< typename pass_type >
2045void PassVisitor< pass_type >::visit( CastExpr * node ) {
2046 VISIT_START( node );
2047
2048 indexerScopedAccept( node->result, *this );
2049 maybeAccept_impl ( node->arg , *this );
2050
2051 VISIT_END( node );
2052}
2053
2054template< typename pass_type >
2055void PassVisitor< pass_type >::visit( const CastExpr * node ) {
2056 VISIT_START( node );
2057
2058 indexerScopedAccept( node->result, *this );
2059 maybeAccept_impl ( node->arg , *this );
2060
2061 VISIT_END( node );
2062}
2063
2064template< typename pass_type >
2065Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
2066 MUTATE_START( node );
2067
2068 indexerScopedMutate( node->env , *this );
2069 indexerScopedMutate( node->result, *this );
2070 maybeMutate_impl ( node->arg , *this );
2071
2072 MUTATE_END( Expression, node );
2073}
2074
2075//--------------------------------------------------------------------------
2076// KeywordCastExpr
2077template< typename pass_type >
2078void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
2079 VISIT_START( node );
2080
2081 indexerScopedAccept( node->result, *this );
2082 maybeAccept_impl ( node->arg , *this );
2083
2084 VISIT_END( node );
2085}
2086
2087template< typename pass_type >
2088void PassVisitor< pass_type >::visit( const KeywordCastExpr * node ) {
2089 VISIT_START( node );
2090
2091 indexerScopedAccept( node->result, *this );
2092 maybeAccept_impl ( node->arg , *this );
2093
2094 VISIT_END( node );
2095}
2096
2097template< typename pass_type >
2098Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
2099 MUTATE_START( node );
2100
2101 indexerScopedMutate( node->env , *this );
2102 indexerScopedMutate( node->result, *this );
2103 maybeMutate_impl ( node->arg , *this );
2104
2105 MUTATE_END( Expression, node );
2106}
2107
2108//--------------------------------------------------------------------------
2109// VirtualCastExpr
2110template< typename pass_type >
2111void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) {
2112 VISIT_START( node );
2113
2114 indexerScopedAccept( node->result, *this );
2115 maybeAccept_impl ( node->arg, *this );
2116
2117 VISIT_END( node );
2118}
2119
2120template< typename pass_type >
2121void PassVisitor< pass_type >::visit( const VirtualCastExpr * node ) {
2122 VISIT_START( node );
2123
2124 indexerScopedAccept( node->result, *this );
2125 maybeAccept_impl ( node->arg, *this );
2126
2127 VISIT_END( node );
2128}
2129
2130template< typename pass_type >
2131Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
2132 MUTATE_START( node );
2133
2134 indexerScopedMutate( node->env , *this );
2135 indexerScopedMutate( node->result, *this );
2136 maybeMutate_impl ( node->arg , *this );
2137
2138 MUTATE_END( Expression, node );
2139}
2140
2141//--------------------------------------------------------------------------
2142// AddressExpr
2143template< typename pass_type >
2144void PassVisitor< pass_type >::visit( AddressExpr * node ) {
2145 VISIT_START( node );
2146
2147 indexerScopedAccept( node->result, *this );
2148 maybeAccept_impl ( node->arg , *this );
2149
2150 VISIT_END( node );
2151}
2152
2153template< typename pass_type >
2154void PassVisitor< pass_type >::visit( const AddressExpr * node ) {
2155 VISIT_START( node );
2156
2157 indexerScopedAccept( node->result, *this );
2158 maybeAccept_impl ( node->arg , *this );
2159
2160 VISIT_END( node );
2161}
2162
2163template< typename pass_type >
2164Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
2165 MUTATE_START( node );
2166
2167 indexerScopedMutate( node->env , *this );
2168 indexerScopedMutate( node->result, *this );
2169 maybeMutate_impl ( node->arg , *this );
2170
2171 MUTATE_END( Expression, node );
2172}
2173
2174//--------------------------------------------------------------------------
2175// LabelAddressExpr
2176template< typename pass_type >
2177void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
2178 VISIT_START( node );
2179
2180 indexerScopedAccept( node->result, *this );
2181
2182 VISIT_END( node );
2183}
2184
2185template< typename pass_type >
2186void PassVisitor< pass_type >::visit( const LabelAddressExpr * node ) {
2187 VISIT_START( node );
2188
2189 indexerScopedAccept( node->result, *this );
2190
2191 VISIT_END( node );
2192}
2193
2194template< typename pass_type >
2195Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
2196 MUTATE_START( node );
2197
2198 indexerScopedMutate( node->env , *this );
2199 indexerScopedMutate( node->result, *this );
2200
2201 MUTATE_END( Expression, node );
2202}
2203
2204//--------------------------------------------------------------------------
2205// UntypedMemberExpr
2206template< typename pass_type >
2207void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
2208 VISIT_START( node );
2209
2210 indexerScopedAccept( node->result , *this );
2211 maybeAccept_impl ( node->aggregate, *this );
2212 maybeAccept_impl ( node->member , *this );
2213
2214 VISIT_END( node );
2215}
2216
2217template< typename pass_type >
2218void PassVisitor< pass_type >::visit( const UntypedMemberExpr * node ) {
2219 VISIT_START( node );
2220
2221 indexerScopedAccept( node->result , *this );
2222 maybeAccept_impl ( node->aggregate, *this );
2223 maybeAccept_impl ( node->member , *this );
2224
2225 VISIT_END( node );
2226}
2227
2228template< typename pass_type >
2229Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) {
2230 MUTATE_START( node );
2231
2232 indexerScopedMutate( node->env , *this );
2233 indexerScopedMutate( node->result , *this );
2234 maybeMutate_impl ( node->aggregate, *this );
2235 maybeMutate_impl ( node->member , *this );
2236
2237 MUTATE_END( Expression, node );
2238}
2239
2240//--------------------------------------------------------------------------
2241// MemberExpr
2242template< typename pass_type >
2243void PassVisitor< pass_type >::visit( MemberExpr * node ) {
2244 VISIT_START( node );
2245
2246 indexerScopedAccept( node->result , *this );
2247 maybeAccept_impl ( node->aggregate, *this );
2248
2249 VISIT_END( node );
2250}
2251
2252template< typename pass_type >
2253void PassVisitor< pass_type >::visit( const MemberExpr * node ) {
2254 VISIT_START( node );
2255
2256 indexerScopedAccept( node->result , *this );
2257 maybeAccept_impl ( node->aggregate, *this );
2258
2259 VISIT_END( node );
2260}
2261
2262template< typename pass_type >
2263Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
2264 MUTATE_START( node );
2265
2266 indexerScopedMutate( node->env , *this );
2267 indexerScopedMutate( node->result , *this );
2268 maybeMutate_impl ( node->aggregate, *this );
2269
2270 MUTATE_END( Expression, node );
2271}
2272
2273//--------------------------------------------------------------------------
2274// VariableExpr
2275template< typename pass_type >
2276void PassVisitor< pass_type >::visit( VariableExpr * node ) {
2277 VISIT_START( node );
2278
2279 indexerScopedAccept( node->result, *this );
2280
2281 VISIT_END( node );
2282}
2283
2284template< typename pass_type >
2285void PassVisitor< pass_type >::visit( const VariableExpr * node ) {
2286 VISIT_START( node );
2287
2288 indexerScopedAccept( node->result, *this );
2289
2290 VISIT_END( node );
2291}
2292
2293template< typename pass_type >
2294Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
2295 MUTATE_START( node );
2296
2297 indexerScopedMutate( node->env , *this );
2298 indexerScopedMutate( node->result, *this );
2299
2300 MUTATE_END( Expression, node );
2301}
2302
2303//--------------------------------------------------------------------------
2304// ConstantExpr
2305template< typename pass_type >
2306void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
2307 VISIT_START( node );
2308
2309 indexerScopedAccept( node->result , *this );
2310 maybeAccept_impl ( &node->constant, *this );
2311
2312 VISIT_END( node );
2313}
2314
2315template< typename pass_type >
2316void PassVisitor< pass_type >::visit( const ConstantExpr * node ) {
2317 VISIT_START( node );
2318
2319 indexerScopedAccept( node->result , *this );
2320 maybeAccept_impl ( &node->constant, *this );
2321
2322 VISIT_END( node );
2323}
2324
2325template< typename pass_type >
2326Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) {
2327 MUTATE_START( node );
2328
2329 indexerScopedMutate( node->env , *this );
2330 indexerScopedMutate( node->result, *this );
2331 Constant * ptr = &node->constant;
2332 maybeMutate_impl( ptr, *this );
2333 node->constant = *ptr;
2334
2335 MUTATE_END( Expression, node );
2336}
2337
2338//--------------------------------------------------------------------------
2339// SizeofExpr
2340template< typename pass_type >
2341void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
2342 VISIT_START( node );
2343
2344 indexerScopedAccept( node->result, *this );
2345 if ( node->get_isType() ) {
2346 maybeAccept_impl( node->type, *this );
2347 } else {
2348 maybeAccept_impl( node->expr, *this );
2349 }
2350
2351 VISIT_END( node );
2352}
2353
2354template< typename pass_type >
2355void PassVisitor< pass_type >::visit( const SizeofExpr * node ) {
2356 VISIT_START( node );
2357
2358 indexerScopedAccept( node->result, *this );
2359 if ( node->get_isType() ) {
2360 maybeAccept_impl( node->type, *this );
2361 } else {
2362 maybeAccept_impl( node->expr, *this );
2363 }
2364
2365 VISIT_END( node );
2366}
2367
2368template< typename pass_type >
2369Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
2370 MUTATE_START( node );
2371
2372 indexerScopedMutate( node->env , *this );
2373 indexerScopedMutate( node->result, *this );
2374 if ( node->get_isType() ) {
2375 maybeMutate_impl( node->type, *this );
2376 } else {
2377 maybeMutate_impl( node->expr, *this );
2378 }
2379
2380 MUTATE_END( Expression, node );
2381}
2382
2383//--------------------------------------------------------------------------
2384// AlignofExpr
2385template< typename pass_type >
2386void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
2387 VISIT_START( node );
2388
2389 indexerScopedAccept( node->result, *this );
2390 if ( node->get_isType() ) {
2391 maybeAccept_impl( node->type, *this );
2392 } else {
2393 maybeAccept_impl( node->expr, *this );
2394 }
2395
2396 VISIT_END( node );
2397}
2398
2399template< typename pass_type >
2400void PassVisitor< pass_type >::visit( const AlignofExpr * node ) {
2401 VISIT_START( node );
2402
2403 indexerScopedAccept( node->result, *this );
2404 if ( node->get_isType() ) {
2405 maybeAccept_impl( node->type, *this );
2406 } else {
2407 maybeAccept_impl( node->expr, *this );
2408 }
2409
2410 VISIT_END( node );
2411}
2412
2413template< typename pass_type >
2414Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
2415 MUTATE_START( node );
2416
2417 indexerScopedMutate( node->env , *this );
2418 indexerScopedMutate( node->result, *this );
2419 if ( node->get_isType() ) {
2420 maybeMutate_impl( node->type, *this );
2421 } else {
2422 maybeMutate_impl( node->expr, *this );
2423 }
2424
2425 MUTATE_END( Expression, node );
2426}
2427
2428//--------------------------------------------------------------------------
2429// UntypedOffsetofExpr
2430template< typename pass_type >
2431void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
2432 VISIT_START( node );
2433
2434 indexerScopedAccept( node->result, *this );
2435 maybeAccept_impl ( node->type , *this );
2436
2437 VISIT_END( node );
2438}
2439
2440template< typename pass_type >
2441void PassVisitor< pass_type >::visit( const UntypedOffsetofExpr * node ) {
2442 VISIT_START( node );
2443
2444 indexerScopedAccept( node->result, *this );
2445 maybeAccept_impl ( node->type , *this );
2446
2447 VISIT_END( node );
2448}
2449
2450template< typename pass_type >
2451Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
2452 MUTATE_START( node );
2453
2454 indexerScopedMutate( node->env , *this );
2455 indexerScopedMutate( node->result, *this );
2456 maybeMutate_impl ( node->type , *this );
2457
2458 MUTATE_END( Expression, node );
2459}
2460
2461//--------------------------------------------------------------------------
2462// OffsetofExpr
2463template< typename pass_type >
2464void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
2465 VISIT_START( node );
2466
2467 indexerScopedAccept( node->result, *this );
2468 maybeAccept_impl ( node->type , *this );
2469
2470 VISIT_END( node );
2471}
2472
2473template< typename pass_type >
2474void PassVisitor< pass_type >::visit( const OffsetofExpr * node ) {
2475 VISIT_START( node );
2476
2477 indexerScopedAccept( node->result, *this );
2478 maybeAccept_impl ( node->type , *this );
2479
2480 VISIT_END( node );
2481}
2482
2483template< typename pass_type >
2484Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
2485 MUTATE_START( node );
2486
2487 indexerScopedMutate( node->env , *this );
2488 indexerScopedMutate( node->result, *this );
2489 maybeMutate_impl ( node->type , *this );
2490
2491 MUTATE_END( Expression, node );
2492}
2493
2494//--------------------------------------------------------------------------
2495// OffsetPackExpr
2496template< typename pass_type >
2497void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
2498 VISIT_START( node );
2499
2500 indexerScopedAccept( node->result, *this );
2501 maybeAccept_impl ( node->type , *this );
2502
2503 VISIT_END( node );
2504}
2505
2506template< typename pass_type >
2507void PassVisitor< pass_type >::visit( const OffsetPackExpr * node ) {
2508 VISIT_START( node );
2509
2510 indexerScopedAccept( node->result, *this );
2511 maybeAccept_impl ( node->type , *this );
2512
2513 VISIT_END( node );
2514}
2515
2516template< typename pass_type >
2517Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
2518 MUTATE_START( node );
2519
2520 indexerScopedMutate( node->env , *this );
2521 indexerScopedMutate( node->result, *this );
2522 maybeMutate_impl ( node->type , *this );
2523
2524 MUTATE_END( Expression, node );
2525}
2526
2527//--------------------------------------------------------------------------
2528// LogicalExpr
2529template< typename pass_type >
2530void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
2531 VISIT_START( node );
2532
2533 indexerScopedAccept( node->result, *this );
2534 maybeAccept_impl ( node->arg1 , *this );
2535 maybeAccept_impl ( node->arg2 , *this );
2536
2537 VISIT_END( node );
2538}
2539
2540template< typename pass_type >
2541void PassVisitor< pass_type >::visit( const LogicalExpr * node ) {
2542 VISIT_START( node );
2543
2544 indexerScopedAccept( node->result, *this );
2545 maybeAccept_impl ( node->arg1 , *this );
2546 maybeAccept_impl ( node->arg2 , *this );
2547
2548 VISIT_END( node );
2549}
2550
2551template< typename pass_type >
2552Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) {
2553 MUTATE_START( node );
2554
2555 indexerScopedMutate( node->env , *this );
2556 indexerScopedMutate( node->result, *this );
2557 maybeMutate_impl ( node->arg1 , *this );
2558 maybeMutate_impl ( node->arg2 , *this );
2559
2560 MUTATE_END( Expression, node );
2561}
2562
2563//--------------------------------------------------------------------------
2564// ConditionalExpr
2565template< typename pass_type >
2566void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
2567 VISIT_START( node );
2568
2569 indexerScopedAccept( node->result, *this );
2570 maybeAccept_impl ( node->arg1 , *this );
2571 maybeAccept_impl ( node->arg2 , *this );
2572 maybeAccept_impl ( node->arg3 , *this );
2573
2574 VISIT_END( node );
2575}
2576
2577template< typename pass_type >
2578void PassVisitor< pass_type >::visit( const ConditionalExpr * node ) {
2579 VISIT_START( node );
2580
2581 indexerScopedAccept( node->result, *this );
2582 maybeAccept_impl ( node->arg1 , *this );
2583 maybeAccept_impl ( node->arg2 , *this );
2584 maybeAccept_impl ( node->arg3 , *this );
2585
2586 VISIT_END( node );
2587}
2588
2589template< typename pass_type >
2590Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
2591 MUTATE_START( node );
2592
2593 indexerScopedMutate( node->env , *this );
2594 indexerScopedMutate( node->result, *this );
2595 maybeMutate_impl ( node->arg1 , *this );
2596 maybeMutate_impl ( node->arg2 , *this );
2597 maybeMutate_impl ( node->arg3 , *this );
2598
2599 MUTATE_END( Expression, node );
2600}
2601
2602//--------------------------------------------------------------------------
2603// CommaExpr
2604template< typename pass_type >
2605void PassVisitor< pass_type >::visit( CommaExpr * node ) {
2606 VISIT_START( node );
2607
2608 indexerScopedAccept( node->result, *this );
2609 maybeAccept_impl ( node->arg1 , *this );
2610 maybeAccept_impl ( node->arg2 , *this );
2611
2612 VISIT_END( node );
2613}
2614
2615template< typename pass_type >
2616void PassVisitor< pass_type >::visit( const CommaExpr * node ) {
2617 VISIT_START( node );
2618
2619 indexerScopedAccept( node->result, *this );
2620 maybeAccept_impl ( node->arg1 , *this );
2621 maybeAccept_impl ( node->arg2 , *this );
2622
2623 VISIT_END( node );
2624}
2625
2626template< typename pass_type >
2627Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
2628 MUTATE_START( node );
2629
2630 indexerScopedMutate( node->env , *this );
2631 indexerScopedMutate( node->result, *this );
2632 maybeMutate_impl ( node->arg1 , *this );
2633 maybeMutate_impl ( node->arg2 , *this );
2634
2635 MUTATE_END( Expression, node );
2636}
2637
2638//--------------------------------------------------------------------------
2639// TypeExpr
2640template< typename pass_type >
2641void PassVisitor< pass_type >::visit( TypeExpr * node ) {
2642 VISIT_START( node );
2643
2644 indexerScopedAccept( node->result, *this );
2645 maybeAccept_impl ( node->type, *this );
2646
2647 VISIT_END( node );
2648}
2649
2650template< typename pass_type >
2651void PassVisitor< pass_type >::visit( const TypeExpr * node ) {
2652 VISIT_START( node );
2653
2654 indexerScopedAccept( node->result, *this );
2655 maybeAccept_impl ( node->type, *this );
2656
2657 VISIT_END( node );
2658}
2659
2660template< typename pass_type >
2661Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
2662 MUTATE_START( node );
2663
2664 indexerScopedMutate( node->env , *this );
2665 indexerScopedMutate( node->result, *this );
2666 maybeMutate_impl ( node->type , *this );
2667
2668 MUTATE_END( Expression, node );
2669}
2670
2671//--------------------------------------------------------------------------
2672// DimensionExpr
2673template< typename pass_type >
2674void PassVisitor< pass_type >::visit( DimensionExpr * node ) {
2675 VISIT_START( node );
2676
2677 indexerScopedAccept( node->result, *this );
2678
2679 VISIT_END( node );
2680}
2681
2682template< typename pass_type >
2683void PassVisitor< pass_type >::visit( const DimensionExpr * node ) {
2684 VISIT_START( node );
2685
2686 indexerScopedAccept( node->result, *this );
2687
2688 VISIT_END( node );
2689}
2690
2691template< typename pass_type >
2692Expression * PassVisitor< pass_type >::mutate( DimensionExpr * node ) {
2693 MUTATE_START( node );
2694
2695 indexerScopedMutate( node->env , *this );
2696 indexerScopedMutate( node->result, *this );
2697
2698 MUTATE_END( Expression, node );
2699}
2700
2701//--------------------------------------------------------------------------
2702// AsmExpr
2703template< typename pass_type >
2704void PassVisitor< pass_type >::visit( AsmExpr * node ) {
2705 VISIT_START( node );
2706
2707 indexerScopedAccept( node->result , *this );
2708 maybeAccept_impl ( node->constraint, *this );
2709 maybeAccept_impl ( node->operand , *this );
2710
2711 VISIT_END( node );
2712}
2713
2714template< typename pass_type >
2715void PassVisitor< pass_type >::visit( const AsmExpr * node ) {
2716 VISIT_START( node );
2717
2718 indexerScopedAccept( node->result , *this );
2719 maybeAccept_impl ( node->constraint, *this );
2720 maybeAccept_impl ( node->operand , *this );
2721
2722 VISIT_END( node );
2723}
2724
2725template< typename pass_type >
2726Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) {
2727 MUTATE_START( node );
2728
2729 indexerScopedMutate( node->env , *this );
2730 indexerScopedMutate( node->result , *this );
2731 maybeMutate_impl ( node->constraint, *this );
2732 maybeMutate_impl ( node->operand , *this );
2733
2734 MUTATE_END( Expression, node );
2735}
2736
2737//--------------------------------------------------------------------------
2738// ImplicitCopyCtorExpr
2739template< typename pass_type >
2740void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
2741 VISIT_START( node );
2742
2743 indexerScopedAccept( node->result , *this );
2744 maybeAccept_impl ( node->callExpr , *this );
2745
2746 VISIT_END( node );
2747}
2748
2749template< typename pass_type >
2750void PassVisitor< pass_type >::visit( const ImplicitCopyCtorExpr * node ) {
2751 VISIT_START( node );
2752
2753 indexerScopedAccept( node->result , *this );
2754 maybeAccept_impl ( node->callExpr , *this );
2755
2756 VISIT_END( node );
2757}
2758
2759template< typename pass_type >
2760Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) {
2761 MUTATE_START( node );
2762
2763 indexerScopedMutate( node->env , *this );
2764 indexerScopedMutate( node->result , *this );
2765 maybeMutate_impl ( node->callExpr , *this );
2766
2767 MUTATE_END( Expression, node );
2768}
2769
2770//--------------------------------------------------------------------------
2771// ConstructorExpr
2772template< typename pass_type >
2773void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
2774 VISIT_START( node );
2775
2776 indexerScopedAccept( node->result , *this );
2777 maybeAccept_impl ( node->callExpr, *this );
2778
2779 VISIT_END( node );
2780}
2781
2782template< typename pass_type >
2783void PassVisitor< pass_type >::visit( const ConstructorExpr * node ) {
2784 VISIT_START( node );
2785
2786 indexerScopedAccept( node->result , *this );
2787 maybeAccept_impl ( node->callExpr, *this );
2788
2789 VISIT_END( node );
2790}
2791
2792template< typename pass_type >
2793Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) {
2794 MUTATE_START( node );
2795
2796 indexerScopedMutate( node->env , *this );
2797 indexerScopedMutate( node->result , *this );
2798 maybeMutate_impl ( node->callExpr, *this );
2799
2800 MUTATE_END( Expression, node );
2801}
2802
2803//--------------------------------------------------------------------------
2804// CompoundLiteralExpr
2805template< typename pass_type >
2806void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
2807 VISIT_START( node );
2808
2809 indexerScopedAccept( node->result , *this );
2810 maybeAccept_impl ( node->initializer, *this );
2811
2812 VISIT_END( node );
2813}
2814
2815template< typename pass_type >
2816void PassVisitor< pass_type >::visit( const CompoundLiteralExpr * node ) {
2817 VISIT_START( node );
2818
2819 indexerScopedAccept( node->result , *this );
2820 maybeAccept_impl ( node->initializer, *this );
2821
2822 VISIT_END( node );
2823}
2824
2825template< typename pass_type >
2826Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
2827 MUTATE_START( node );
2828
2829 indexerScopedMutate( node->env , *this );
2830 indexerScopedMutate( node->result , *this );
2831 maybeMutate_impl ( node->initializer, *this );
2832
2833 MUTATE_END( Expression, node );
2834}
2835
2836//--------------------------------------------------------------------------
2837// RangeExpr
2838template< typename pass_type >
2839void PassVisitor< pass_type >::visit( RangeExpr * node ) {
2840 VISIT_START( node );
2841
2842 indexerScopedAccept( node->result, *this );
2843 maybeAccept_impl ( node->low , *this );
2844 maybeAccept_impl ( node->high , *this );
2845
2846 VISIT_END( node );
2847}
2848
2849template< typename pass_type >
2850void PassVisitor< pass_type >::visit( const RangeExpr * node ) {
2851 VISIT_START( node );
2852
2853 indexerScopedAccept( node->result, *this );
2854 maybeAccept_impl ( node->low , *this );
2855 maybeAccept_impl ( node->high , *this );
2856
2857 VISIT_END( node );
2858}
2859
2860template< typename pass_type >
2861Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
2862 MUTATE_START( node );
2863
2864 indexerScopedMutate( node->env , *this );
2865 indexerScopedMutate( node->result, *this );
2866 maybeMutate_impl ( node->low , *this );
2867 maybeMutate_impl ( node->high , *this );
2868
2869 MUTATE_END( Expression, node );
2870}
2871
2872//--------------------------------------------------------------------------
2873// UntypedTupleExpr
2874template< typename pass_type >
2875void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
2876 VISIT_START( node );
2877
2878 indexerScopedAccept( node->result, *this );
2879 maybeAccept_impl ( node->exprs , *this );
2880
2881 VISIT_END( node );
2882}
2883
2884template< typename pass_type >
2885void PassVisitor< pass_type >::visit( const UntypedTupleExpr * node ) {
2886 VISIT_START( node );
2887
2888 indexerScopedAccept( node->result, *this );
2889 maybeAccept_impl ( node->exprs , *this );
2890
2891 VISIT_END( node );
2892}
2893
2894template< typename pass_type >
2895Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
2896 MUTATE_START( node );
2897
2898 indexerScopedMutate( node->env , *this );
2899 indexerScopedMutate( node->result, *this );
2900 maybeMutate_impl ( node->exprs , *this );
2901
2902 MUTATE_END( Expression, node );
2903}
2904
2905//--------------------------------------------------------------------------
2906// TupleExpr
2907template< typename pass_type >
2908void PassVisitor< pass_type >::visit( TupleExpr * node ) {
2909 VISIT_START( node );
2910
2911 indexerScopedAccept( node->result, *this );
2912 maybeAccept_impl ( node->exprs , *this );
2913
2914 VISIT_END( node );
2915}
2916
2917template< typename pass_type >
2918void PassVisitor< pass_type >::visit( const TupleExpr * node ) {
2919 VISIT_START( node );
2920
2921 indexerScopedAccept( node->result, *this );
2922 maybeAccept_impl ( node->exprs , *this );
2923
2924 VISIT_END( node );
2925}
2926
2927template< typename pass_type >
2928Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
2929 MUTATE_START( node );
2930
2931 indexerScopedMutate( node->env , *this );
2932 indexerScopedMutate( node->result, *this );
2933 maybeMutate_impl ( node->exprs , *this );
2934
2935 MUTATE_END( Expression, node );
2936}
2937
2938//--------------------------------------------------------------------------
2939// TupleIndexExpr
2940template< typename pass_type >
2941void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
2942 VISIT_START( node );
2943
2944 indexerScopedAccept( node->result, *this );
2945 maybeAccept_impl ( node->tuple , *this );
2946
2947 VISIT_END( node );
2948}
2949
2950template< typename pass_type >
2951void PassVisitor< pass_type >::visit( const TupleIndexExpr * node ) {
2952 VISIT_START( node );
2953
2954 indexerScopedAccept( node->result, *this );
2955 maybeAccept_impl ( node->tuple , *this );
2956
2957 VISIT_END( node );
2958}
2959
2960template< typename pass_type >
2961Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
2962 MUTATE_START( node );
2963
2964 indexerScopedMutate( node->env , *this );
2965 indexerScopedMutate( node->result, *this );
2966 maybeMutate_impl ( node->tuple , *this );
2967
2968 MUTATE_END( Expression, node );
2969}
2970
2971//--------------------------------------------------------------------------
2972// TupleAssignExpr
2973template< typename pass_type >
2974void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
2975 VISIT_START( node );
2976
2977 indexerScopedAccept( node->result , *this );
2978 maybeAccept_impl ( node->stmtExpr, *this );
2979
2980 VISIT_END( node );
2981}
2982
2983template< typename pass_type >
2984void PassVisitor< pass_type >::visit( const TupleAssignExpr * node ) {
2985 VISIT_START( node );
2986
2987 indexerScopedAccept( node->result , *this );
2988 maybeAccept_impl( node->stmtExpr, *this );
2989
2990 VISIT_END( node );
2991}
2992
2993template< typename pass_type >
2994Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) {
2995 MUTATE_START( node );
2996
2997 indexerScopedMutate( node->env , *this );
2998 indexerScopedMutate( node->result , *this );
2999 maybeMutate_impl ( node->stmtExpr, *this );
3000
3001 MUTATE_END( Expression, node );
3002}
3003
3004//--------------------------------------------------------------------------
3005// StmtExpr
3006template< typename pass_type >
3007void PassVisitor< pass_type >::visit( StmtExpr * node ) {
3008 VISIT_START( node );
3009
3010 // don't want statements from outer CompoundStmts to be added to this StmtExpr
3011 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
3012 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
3013 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
3014
3015 indexerScopedAccept( node->result , *this );
3016 maybeAccept_impl ( node->statements , *this );
3017 maybeAccept_impl ( node->returnDecls, *this );
3018 maybeAccept_impl ( node->dtors , *this );
3019
3020 VISIT_END( node );
3021}
3022
3023template< typename pass_type >
3024void PassVisitor< pass_type >::visit( const StmtExpr * node ) {
3025 VISIT_START( node );
3026
3027 // don't want statements from outer CompoundStmts to be added to this StmtExpr
3028 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
3029 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
3030 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
3031
3032 indexerScopedAccept( node->result , *this );
3033 maybeAccept_impl ( node->statements , *this );
3034 maybeAccept_impl ( node->returnDecls, *this );
3035 maybeAccept_impl ( node->dtors , *this );
3036
3037 VISIT_END( node );
3038}
3039
3040template< typename pass_type >
3041Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
3042 MUTATE_START( node );
3043
3044 // don't want statements from outer CompoundStmts to be added to this StmtExpr
3045 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() );
3046 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
3047 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
3048
3049 indexerScopedMutate( node->result , *this );
3050 maybeMutate_impl ( node->statements , *this );
3051 maybeMutate_impl ( node->returnDecls, *this );
3052 maybeMutate_impl ( node->dtors , *this );
3053
3054 MUTATE_END( Expression, node );
3055}
3056
3057//--------------------------------------------------------------------------
3058// UniqueExpr
3059template< typename pass_type >
3060void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
3061 VISIT_START( node );
3062
3063 indexerScopedAccept( node->result, *this );
3064 maybeAccept_impl ( node->expr , *this );
3065
3066 VISIT_END( node );
3067}
3068
3069template< typename pass_type >
3070void PassVisitor< pass_type >::visit( const UniqueExpr * node ) {
3071 VISIT_START( node );
3072
3073 indexerScopedAccept( node->result, *this );
3074 maybeAccept_impl ( node->expr , *this );
3075
3076 VISIT_END( node );
3077}
3078
3079template< typename pass_type >
3080Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
3081 MUTATE_START( node );
3082
3083 indexerScopedMutate( node->env , *this );
3084 indexerScopedMutate( node->result, *this );
3085 maybeMutate_impl ( node->expr , *this );
3086
3087 MUTATE_END( Expression, node );
3088}
3089
3090//--------------------------------------------------------------------------
3091// UntypedInitExpr
3092template< typename pass_type >
3093void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) {
3094 VISIT_START( node );
3095
3096 indexerScopedAccept( node->result, *this );
3097 maybeAccept_impl ( node->expr , *this );
3098 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
3099
3100 VISIT_END( node );
3101}
3102
3103template< typename pass_type >
3104void PassVisitor< pass_type >::visit( const UntypedInitExpr * node ) {
3105 VISIT_START( node );
3106
3107 indexerScopedAccept( node->result, *this );
3108 maybeAccept_impl ( node->expr , *this );
3109 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
3110
3111 VISIT_END( node );
3112}
3113
3114template< typename pass_type >
3115Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
3116 MUTATE_START( node );
3117
3118 indexerScopedMutate( node->env , *this );
3119 indexerScopedMutate( node->result, *this );
3120 maybeMutate_impl ( node->expr , *this );
3121 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
3122
3123 MUTATE_END( Expression, node );
3124}
3125
3126//--------------------------------------------------------------------------
3127// InitExpr
3128template< typename pass_type >
3129void PassVisitor< pass_type >::visit( InitExpr * node ) {
3130 VISIT_START( node );
3131
3132 indexerScopedAccept( node->result, *this );
3133 maybeAccept_impl ( node->expr , *this );
3134 maybeAccept_impl ( node->designation, *this );
3135
3136 VISIT_END( node );
3137}
3138
3139template< typename pass_type >
3140void PassVisitor< pass_type >::visit( const InitExpr * node ) {
3141 VISIT_START( node );
3142
3143 indexerScopedAccept( node->result, *this );
3144 maybeAccept_impl ( node->expr , *this );
3145 maybeAccept_impl ( node->designation, *this );
3146
3147 VISIT_END( node );
3148}
3149
3150template< typename pass_type >
3151Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
3152 MUTATE_START( node );
3153
3154 indexerScopedMutate( node->env , *this );
3155 indexerScopedMutate( node->result, *this );
3156 maybeMutate_impl ( node->expr , *this );
3157 maybeMutate_impl ( node->designation, *this );
3158
3159 MUTATE_END( Expression, node );
3160}
3161
3162//--------------------------------------------------------------------------
3163// DeletedExpr
3164template< typename pass_type >
3165void PassVisitor< pass_type >::visit( DeletedExpr * node ) {
3166 VISIT_START( node );
3167
3168 indexerScopedAccept( node->result, *this );
3169 maybeAccept_impl ( node->expr, *this );
3170 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
3171
3172 VISIT_END( node );
3173}
3174
3175template< typename pass_type >
3176void PassVisitor< pass_type >::visit( const DeletedExpr * node ) {
3177 VISIT_START( node );
3178
3179 indexerScopedAccept( node->result, *this );
3180 maybeAccept_impl ( node->expr, *this );
3181 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
3182
3183 VISIT_END( node );
3184}
3185
3186template< typename pass_type >
3187Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
3188 MUTATE_START( node );
3189
3190 indexerScopedMutate( node->env, *this );
3191 indexerScopedMutate( node->result, *this );
3192 maybeMutate_impl( node->expr, *this );
3193
3194 MUTATE_END( Expression, node );
3195}
3196
3197//--------------------------------------------------------------------------
3198// DefaultArgExpr
3199template< typename pass_type >
3200void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
3201 VISIT_START( node );
3202
3203 indexerScopedAccept( node->result, *this );
3204 maybeAccept_impl ( node->expr, *this );
3205
3206 VISIT_END( node );
3207}
3208
3209template< typename pass_type >
3210void PassVisitor< pass_type >::visit( const DefaultArgExpr * node ) {
3211 VISIT_START( node );
3212
3213 indexerScopedAccept( node->result, *this );
3214 maybeAccept_impl ( node->expr, *this );
3215
3216 VISIT_END( node );
3217}
3218
3219template< typename pass_type >
3220Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
3221 MUTATE_START( node );
3222
3223 indexerScopedMutate( node->env, *this );
3224 indexerScopedMutate( node->result, *this );
3225 maybeMutate_impl( node->expr, *this );
3226
3227 MUTATE_END( Expression, node );
3228}
3229
3230//--------------------------------------------------------------------------
3231// GenericExpr
3232template< typename pass_type >
3233void PassVisitor< pass_type >::visit( GenericExpr * node ) {
3234 VISIT_START( node );
3235
3236 indexerScopedAccept( node->result, *this );
3237 maybeAccept_impl( node->control, *this );
3238 for ( GenericExpr::Association & assoc : node->associations ) {
3239 indexerScopedAccept( assoc.type, *this );
3240 maybeAccept_impl( assoc.expr, *this );
3241 }
3242
3243 VISIT_END( node );
3244}
3245
3246template< typename pass_type >
3247void PassVisitor< pass_type >::visit( const GenericExpr * node ) {
3248 VISIT_START( node );
3249
3250 indexerScopedAccept( node->result, *this );
3251 maybeAccept_impl( node->control, *this );
3252 for ( const GenericExpr::Association & assoc : node->associations ) {
3253 indexerScopedAccept( assoc.type, *this );
3254 maybeAccept_impl( assoc.expr, *this );
3255 }
3256
3257 VISIT_END( node );
3258}
3259
3260template< typename pass_type >
3261Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) {
3262 MUTATE_START( node );
3263
3264 indexerScopedMutate( node->env, *this );
3265 indexerScopedMutate( node->result, *this );
3266 maybeMutate_impl( node->control, *this );
3267 for ( GenericExpr::Association & assoc : node->associations ) {
3268 indexerScopedMutate( assoc.type, *this );
3269 maybeMutate_impl( assoc.expr, *this );
3270 }
3271
3272 MUTATE_END( Expression, node );
3273}
3274
3275//--------------------------------------------------------------------------
3276// VoidType
3277template< typename pass_type >
3278void PassVisitor< pass_type >::visit( VoidType * node ) {
3279 VISIT_START( node );
3280
3281 maybeAccept_impl( node->forall, *this );
3282
3283 VISIT_END( node );
3284}
3285
3286template< typename pass_type >
3287void PassVisitor< pass_type >::visit( const VoidType * node ) {
3288 VISIT_START( node );
3289
3290 maybeAccept_impl( node->forall, *this );
3291
3292 VISIT_END( node );
3293}
3294
3295template< typename pass_type >
3296Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
3297 MUTATE_START( node );
3298
3299 maybeMutate_impl( node->forall, *this );
3300
3301 MUTATE_END( Type, node );
3302}
3303
3304//--------------------------------------------------------------------------
3305// BasicType
3306template< typename pass_type >
3307void PassVisitor< pass_type >::visit( BasicType * node ) {
3308 VISIT_START( node );
3309
3310 maybeAccept_impl( node->forall, *this );
3311
3312 VISIT_END( node );
3313}
3314
3315template< typename pass_type >
3316void PassVisitor< pass_type >::visit( const BasicType * node ) {
3317 VISIT_START( node );
3318
3319 maybeAccept_impl( node->forall, *this );
3320
3321 VISIT_END( node );
3322}
3323
3324template< typename pass_type >
3325Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
3326 MUTATE_START( node );
3327
3328 maybeMutate_impl( node->forall, *this );
3329
3330 MUTATE_END( Type, node );
3331}
3332
3333//--------------------------------------------------------------------------
3334// PointerType
3335template< typename pass_type >
3336void PassVisitor< pass_type >::visit( PointerType * node ) {
3337 VISIT_START( node );
3338
3339 maybeAccept_impl( node->forall, *this );
3340 maybeAccept_impl( node->dimension, *this );
3341 maybeAccept_impl( node->base, *this );
3342
3343 VISIT_END( node );
3344}
3345
3346template< typename pass_type >
3347void PassVisitor< pass_type >::visit( const PointerType * node ) {
3348 VISIT_START( node );
3349
3350 maybeAccept_impl( node->forall, *this );
3351 maybeAccept_impl( node->dimension, *this );
3352 maybeAccept_impl( node->base, *this );
3353
3354 VISIT_END( node );
3355}
3356
3357template< typename pass_type >
3358Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
3359 MUTATE_START( node );
3360
3361 maybeMutate_impl( node->forall, *this );
3362 maybeMutate_impl( node->dimension, *this );
3363 maybeMutate_impl( node->base, *this );
3364
3365 MUTATE_END( Type, node );
3366}
3367
3368//--------------------------------------------------------------------------
3369// ArrayType
3370template< typename pass_type >
3371void PassVisitor< pass_type >::visit( ArrayType * node ) {
3372 VISIT_START( node );
3373
3374 maybeAccept_impl( node->forall, *this );
3375 maybeAccept_impl( node->dimension, *this );
3376 maybeAccept_impl( node->base, *this );
3377
3378 VISIT_END( node );
3379}
3380
3381template< typename pass_type >
3382void PassVisitor< pass_type >::visit( const ArrayType * node ) {
3383 VISIT_START( node );
3384
3385 maybeAccept_impl( node->forall, *this );
3386 maybeAccept_impl( node->dimension, *this );
3387 maybeAccept_impl( node->base, *this );
3388
3389 VISIT_END( node );
3390}
3391
3392template< typename pass_type >
3393Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
3394 MUTATE_START( node );
3395
3396 maybeMutate_impl( node->forall, *this );
3397 maybeMutate_impl( node->dimension, *this );
3398 maybeMutate_impl( node->base, *this );
3399
3400 MUTATE_END( Type, node );
3401}
3402
3403//--------------------------------------------------------------------------
3404// ReferenceType
3405template< typename pass_type >
3406void PassVisitor< pass_type >::visit( ReferenceType * node ) {
3407 VISIT_START( node );
3408
3409 maybeAccept_impl( node->forall, *this );
3410 maybeAccept_impl( node->base, *this );
3411
3412 VISIT_END( node );
3413}
3414
3415template< typename pass_type >
3416void PassVisitor< pass_type >::visit( const ReferenceType * node ) {
3417 VISIT_START( node );
3418
3419 maybeAccept_impl( node->forall, *this );
3420 maybeAccept_impl( node->base, *this );
3421
3422 VISIT_END( node );
3423}
3424
3425template< typename pass_type >
3426Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
3427 MUTATE_START( node );
3428
3429 maybeMutate_impl( node->forall, *this );
3430 maybeMutate_impl( node->base, *this );
3431
3432 MUTATE_END( Type, node );
3433}
3434
3435//--------------------------------------------------------------------------
3436// QualifiedType
3437template< typename pass_type >
3438void PassVisitor< pass_type >::visit( QualifiedType * node ) {
3439 VISIT_START( node );
3440
3441 maybeAccept_impl( node->forall, *this );
3442 maybeAccept_impl( node->parent, *this );
3443 maybeAccept_impl( node->child, *this );
3444
3445 VISIT_END( node );
3446}
3447
3448template< typename pass_type >
3449void PassVisitor< pass_type >::visit( const QualifiedType * node ) {
3450 VISIT_START( node );
3451
3452 maybeAccept_impl( node->forall, *this );
3453 maybeAccept_impl( node->parent, *this );
3454 maybeAccept_impl( node->child, *this );
3455
3456 VISIT_END( node );
3457}
3458
3459template< typename pass_type >
3460Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) {
3461 MUTATE_START( node );
3462
3463 maybeMutate_impl( node->forall, *this );
3464 maybeMutate_impl( node->parent, *this );
3465 maybeMutate_impl( node->child, *this );
3466
3467 MUTATE_END( Type, node );
3468}
3469
3470//--------------------------------------------------------------------------
3471// FunctionType
3472template< typename pass_type >
3473void PassVisitor< pass_type >::visit( FunctionType * node ) {
3474 VISIT_START( node );
3475
3476 maybeAccept_impl( node->forall, *this );
3477 maybeAccept_impl( node->returnVals, *this );
3478 maybeAccept_impl( node->parameters, *this );
3479
3480 VISIT_END( node );
3481}
3482
3483template< typename pass_type >
3484void PassVisitor< pass_type >::visit( const FunctionType * node ) {
3485 VISIT_START( node );
3486
3487 maybeAccept_impl( node->forall, *this );
3488 maybeAccept_impl( node->returnVals, *this );
3489 maybeAccept_impl( node->parameters, *this );
3490
3491 VISIT_END( node );
3492}
3493
3494template< typename pass_type >
3495Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
3496 MUTATE_START( node );
3497
3498 maybeMutate_impl( node->forall, *this );
3499 maybeMutate_impl( node->returnVals, *this );
3500 maybeMutate_impl( node->parameters, *this );
3501
3502 MUTATE_END( Type, node );
3503}
3504
3505//--------------------------------------------------------------------------
3506// StructInstType
3507template< typename pass_type >
3508void PassVisitor< pass_type >::visit( StructInstType * node ) {
3509 VISIT_START( node );
3510
3511 indexerAddStruct( node->name );
3512
3513 {
3514 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3515 maybeAccept_impl( node->forall , *this );
3516 maybeAccept_impl( node->parameters, *this );
3517 }
3518
3519 VISIT_END( node );
3520}
3521
3522template< typename pass_type >
3523void PassVisitor< pass_type >::visit( const StructInstType * node ) {
3524 VISIT_START( node );
3525
3526 indexerAddStruct( node->name );
3527
3528 {
3529 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3530 maybeAccept_impl( node->forall , *this );
3531 maybeAccept_impl( node->parameters, *this );
3532 }
3533
3534 VISIT_END( node );
3535}
3536
3537template< typename pass_type >
3538Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
3539 MUTATE_START( node );
3540
3541 indexerAddStruct( node->name );
3542
3543 {
3544 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3545 maybeMutate_impl( node->forall , *this );
3546 maybeMutate_impl( node->parameters, *this );
3547 }
3548
3549 MUTATE_END( Type, node );
3550}
3551
3552//--------------------------------------------------------------------------
3553// UnionInstType
3554template< typename pass_type >
3555void PassVisitor< pass_type >::visit( UnionInstType * node ) {
3556 VISIT_START( node );
3557
3558 indexerAddUnion( node->name );
3559
3560 {
3561 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3562 maybeAccept_impl( node->forall , *this );
3563 maybeAccept_impl( node->parameters, *this );
3564 }
3565
3566 VISIT_END( node );
3567}
3568
3569template< typename pass_type >
3570void PassVisitor< pass_type >::visit( const UnionInstType * node ) {
3571 VISIT_START( node );
3572
3573 indexerAddUnion( node->name );
3574
3575 {
3576 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3577 maybeAccept_impl( node->forall , *this );
3578 maybeAccept_impl( node->parameters, *this );
3579 }
3580
3581 VISIT_END( node );
3582}
3583
3584template< typename pass_type >
3585Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
3586 MUTATE_START( node );
3587
3588 indexerAddUnion( node->name );
3589
3590 {
3591 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3592 maybeMutate_impl( node->forall , *this );
3593 maybeMutate_impl( node->parameters, *this );
3594 }
3595
3596 MUTATE_END( Type, node );
3597}
3598
3599//--------------------------------------------------------------------------
3600// EnumInstType
3601template< typename pass_type >
3602void PassVisitor< pass_type >::visit( EnumInstType * node ) {
3603 VISIT_START( node );
3604
3605 maybeAccept_impl( node->forall, *this );
3606 maybeAccept_impl( node->parameters, *this );
3607
3608 VISIT_END( node );
3609}
3610
3611template< typename pass_type >
3612void PassVisitor< pass_type >::visit( const EnumInstType * node ) {
3613 VISIT_START( node );
3614
3615 maybeAccept_impl( node->forall, *this );
3616 maybeAccept_impl( node->parameters, *this );
3617
3618 VISIT_END( node );
3619}
3620
3621template< typename pass_type >
3622Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
3623 MUTATE_START( node );
3624
3625 maybeMutate_impl( node->forall, *this );
3626 maybeMutate_impl( node->parameters, *this );
3627
3628 MUTATE_END( Type, node );
3629}
3630
3631//--------------------------------------------------------------------------
3632// TraitInstType
3633template< typename pass_type >
3634void PassVisitor< pass_type >::visit( TraitInstType * node ) {
3635 VISIT_START( node );
3636
3637 maybeAccept_impl( node->forall , *this );
3638 maybeAccept_impl( node->parameters, *this );
3639
3640 VISIT_END( node );
3641}
3642
3643template< typename pass_type >
3644void PassVisitor< pass_type >::visit( const TraitInstType * node ) {
3645 VISIT_START( node );
3646
3647 maybeAccept_impl( node->forall , *this );
3648 maybeAccept_impl( node->parameters, *this );
3649
3650 VISIT_END( node );
3651}
3652
3653template< typename pass_type >
3654Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
3655 MUTATE_START( node );
3656
3657 maybeMutate_impl( node->forall , *this );
3658 maybeMutate_impl( node->parameters, *this );
3659
3660 MUTATE_END( Type, node );
3661}
3662
3663//--------------------------------------------------------------------------
3664// TypeInstType
3665template< typename pass_type >
3666void PassVisitor< pass_type >::visit( TypeInstType * node ) {
3667 VISIT_START( node );
3668
3669 maybeAccept_impl( node->forall , *this );
3670 maybeAccept_impl( node->parameters, *this );
3671
3672 VISIT_END( node );
3673}
3674
3675template< typename pass_type >
3676void PassVisitor< pass_type >::visit( const TypeInstType * node ) {
3677 VISIT_START( node );
3678
3679 maybeAccept_impl( node->forall , *this );
3680 maybeAccept_impl( node->parameters, *this );
3681
3682 VISIT_END( node );
3683}
3684
3685template< typename pass_type >
3686Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
3687 MUTATE_START( node );
3688
3689 maybeMutate_impl( node->forall , *this );
3690 maybeMutate_impl( node->parameters, *this );
3691
3692 MUTATE_END( Type, node );
3693}
3694
3695//--------------------------------------------------------------------------
3696// TupleType
3697template< typename pass_type >
3698void PassVisitor< pass_type >::visit( TupleType * node ) {
3699 VISIT_START( node );
3700
3701 maybeAccept_impl( node->forall, *this );
3702 maybeAccept_impl( node->types, *this );
3703 maybeAccept_impl( node->members, *this );
3704
3705 VISIT_END( node );
3706}
3707
3708template< typename pass_type >
3709void PassVisitor< pass_type >::visit( const TupleType * node ) {
3710 VISIT_START( node );
3711
3712 maybeAccept_impl( node->forall, *this );
3713 maybeAccept_impl( node->types, *this );
3714 maybeAccept_impl( node->members, *this );
3715
3716 VISIT_END( node );
3717}
3718
3719template< typename pass_type >
3720Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
3721 MUTATE_START( node );
3722
3723 maybeMutate_impl( node->forall, *this );
3724 maybeMutate_impl( node->types, *this );
3725 maybeMutate_impl( node->members, *this );
3726
3727 MUTATE_END( Type, node );
3728}
3729
3730//--------------------------------------------------------------------------
3731// TypeofType
3732template< typename pass_type >
3733void PassVisitor< pass_type >::visit( TypeofType * node ) {
3734 VISIT_START( node );
3735
3736 assert( node->expr );
3737 maybeAccept_impl( node->expr, *this );
3738
3739 VISIT_END( node );
3740}
3741
3742template< typename pass_type >
3743void PassVisitor< pass_type >::visit( const TypeofType * node ) {
3744 VISIT_START( node );
3745
3746 assert( node->expr );
3747 maybeAccept_impl( node->expr, *this );
3748
3749 VISIT_END( node );
3750}
3751
3752template< typename pass_type >
3753Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
3754 MUTATE_START( node );
3755
3756 assert( node->expr );
3757 maybeMutate_impl( node->expr, *this );
3758
3759 MUTATE_END( Type, node );
3760}
3761
3762//--------------------------------------------------------------------------
3763// VTableType
3764template< typename pass_type >
3765void PassVisitor< pass_type >::visit( VTableType * node ) {
3766 VISIT_START( node );
3767
3768 // Forall qualifiers should be on base type, not here
3769 // maybeAccept_impl( node->forall, *this );
3770 maybeAccept_impl( node->base, *this );
3771
3772 VISIT_END( node );
3773}
3774
3775template< typename pass_type >
3776void PassVisitor< pass_type >::visit( const VTableType * node ) {
3777 VISIT_START( node );
3778
3779 // Forall qualifiers should be on base type, not here
3780 // maybeAccept_impl( node->forall, *this );
3781 maybeAccept_impl( node->base, *this );
3782
3783 VISIT_END( node );
3784}
3785
3786template< typename pass_type >
3787Type * PassVisitor< pass_type >::mutate( VTableType * node ) {
3788 MUTATE_START( node );
3789
3790 // Forall qualifiers should be on base type, not here
3791 // maybeMutate_impl( node->forall, *this );
3792 maybeMutate_impl( node->base, *this );
3793
3794 MUTATE_END( Type, node );
3795}
3796
3797//--------------------------------------------------------------------------
3798// AttrType
3799template< typename pass_type >
3800void PassVisitor< pass_type >::visit( AttrType * node ) {
3801 VISIT_START( node );
3802
3803 if ( node->isType ) {
3804 assert( node->type );
3805 maybeAccept_impl( node->type, *this );
3806 } else {
3807 assert( node->expr );
3808 maybeAccept_impl( node->expr, *this );
3809 } // if
3810
3811 VISIT_END( node );
3812}
3813
3814template< typename pass_type >
3815void PassVisitor< pass_type >::visit( const AttrType * node ) {
3816 VISIT_START( node );
3817
3818 if ( node->isType ) {
3819 assert( node->type );
3820 maybeAccept_impl( node->type, *this );
3821 } else {
3822 assert( node->expr );
3823 maybeAccept_impl( node->expr, *this );
3824 } // if
3825
3826 VISIT_END( node );
3827}
3828
3829template< typename pass_type >
3830Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
3831 MUTATE_START( node );
3832
3833 if ( node->isType ) {
3834 assert( node->type );
3835 maybeMutate_impl( node->type, *this );
3836 } else {
3837 assert( node->expr );
3838 maybeMutate_impl( node->expr, *this );
3839 } // if
3840
3841 MUTATE_END( Type, node );
3842}
3843
3844//--------------------------------------------------------------------------
3845// VarArgsType
3846template< typename pass_type >
3847void PassVisitor< pass_type >::visit( VarArgsType * node ) {
3848 VISIT_START( node );
3849
3850 maybeAccept_impl( node->forall, *this );
3851
3852 VISIT_END( node );
3853}
3854
3855template< typename pass_type >
3856void PassVisitor< pass_type >::visit( const VarArgsType * node ) {
3857 VISIT_START( node );
3858
3859 maybeAccept_impl( node->forall, *this );
3860
3861 VISIT_END( node );
3862}
3863
3864template< typename pass_type >
3865Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
3866 MUTATE_START( node );
3867
3868 maybeMutate_impl( node->forall, *this );
3869
3870 MUTATE_END( Type, node );
3871}
3872
3873//--------------------------------------------------------------------------
3874// ZeroType
3875template< typename pass_type >
3876void PassVisitor< pass_type >::visit( ZeroType * node ) {
3877 VISIT_START( node );
3878
3879 maybeAccept_impl( node->forall, *this );
3880
3881 VISIT_END( node );
3882}
3883
3884template< typename pass_type >
3885void PassVisitor< pass_type >::visit( const ZeroType * node ) {
3886 VISIT_START( node );
3887
3888 maybeAccept_impl( node->forall, *this );
3889
3890 VISIT_END( node );
3891}
3892
3893template< typename pass_type >
3894Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
3895 MUTATE_START( node );
3896
3897 maybeMutate_impl( node->forall, *this );
3898
3899 MUTATE_END( Type, node );
3900}
3901
3902//--------------------------------------------------------------------------
3903// OneType
3904template< typename pass_type >
3905void PassVisitor< pass_type >::visit( OneType * node ) {
3906 VISIT_START( node );
3907
3908 maybeAccept_impl( node->forall, *this );
3909
3910 VISIT_END( node );
3911}
3912
3913template< typename pass_type >
3914void PassVisitor< pass_type >::visit( const OneType * node ) {
3915 VISIT_START( node );
3916
3917 maybeAccept_impl( node->forall, *this );
3918
3919 VISIT_END( node );
3920}
3921
3922template< typename pass_type >
3923Type * PassVisitor< pass_type >::mutate( OneType * node ) {
3924 MUTATE_START( node );
3925
3926 maybeMutate_impl( node->forall, *this );
3927
3928 MUTATE_END( Type, node );
3929}
3930
3931//--------------------------------------------------------------------------
3932// GlobalScopeType
3933template< typename pass_type >
3934void PassVisitor< pass_type >::visit( GlobalScopeType * node ) {
3935 VISIT_START( node );
3936
3937 maybeAccept_impl( node->forall, *this );
3938
3939 VISIT_END( node );
3940}
3941
3942template< typename pass_type >
3943void PassVisitor< pass_type >::visit( const GlobalScopeType * node ) {
3944 VISIT_START( node );
3945
3946 maybeAccept_impl( node->forall, *this );
3947
3948 VISIT_END( node );
3949}
3950
3951template< typename pass_type >
3952Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) {
3953 MUTATE_START( node );
3954
3955 maybeMutate_impl( node->forall, *this );
3956
3957 MUTATE_END( Type, node );
3958}
3959
3960//--------------------------------------------------------------------------
3961// Designation
3962template< typename pass_type >
3963void PassVisitor< pass_type >::visit( Designation * node ) {
3964 VISIT_START( node );
3965
3966 maybeAccept_impl( node->designators, *this );
3967
3968 VISIT_END( node );
3969}
3970
3971template< typename pass_type >
3972void PassVisitor< pass_type >::visit( const Designation * node ) {
3973 VISIT_START( node );
3974
3975 maybeAccept_impl( node->designators, *this );
3976
3977 VISIT_END( node );
3978}
3979
3980template< typename pass_type >
3981Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
3982 MUTATE_START( node );
3983
3984 maybeMutate_impl( node->designators, *this );
3985
3986 MUTATE_END( Designation, node );
3987}
3988
3989//--------------------------------------------------------------------------
3990// SingleInit
3991template< typename pass_type >
3992void PassVisitor< pass_type >::visit( SingleInit * node ) {
3993 VISIT_START( node );
3994
3995 visitExpression( node->value );
3996
3997 VISIT_END( node );
3998}
3999
4000template< typename pass_type >
4001void PassVisitor< pass_type >::visit( const SingleInit * node ) {
4002 VISIT_START( node );
4003
4004 visitExpression( node->value );
4005
4006 VISIT_END( node );
4007}
4008
4009template< typename pass_type >
4010Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
4011 MUTATE_START( node );
4012
4013 node->value = mutateExpression( node->value );
4014
4015 MUTATE_END( Initializer, node );
4016}
4017
4018//--------------------------------------------------------------------------
4019// ListInit
4020template< typename pass_type >
4021void PassVisitor< pass_type >::visit( ListInit * node ) {
4022 VISIT_START( node );
4023
4024 maybeAccept_impl( node->designations, *this );
4025 maybeAccept_impl( node->initializers, *this );
4026
4027 VISIT_END( node );
4028}
4029
4030template< typename pass_type >
4031void PassVisitor< pass_type >::visit( const ListInit * node ) {
4032 VISIT_START( node );
4033
4034 maybeAccept_impl( node->designations, *this );
4035 maybeAccept_impl( node->initializers, *this );
4036
4037 VISIT_END( node );
4038}
4039
4040template< typename pass_type >
4041Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
4042 MUTATE_START( node );
4043
4044 maybeMutate_impl( node->designations, *this );
4045 maybeMutate_impl( node->initializers, *this );
4046
4047 MUTATE_END( Initializer, node );
4048}
4049
4050//--------------------------------------------------------------------------
4051// ConstructorInit
4052template< typename pass_type >
4053void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
4054 VISIT_START( node );
4055
4056 maybeAccept_impl( node->ctor, *this );
4057 maybeAccept_impl( node->dtor, *this );
4058 maybeAccept_impl( node->init, *this );
4059
4060 VISIT_END( node );
4061}
4062
4063template< typename pass_type >
4064void PassVisitor< pass_type >::visit( const ConstructorInit * node ) {
4065 VISIT_START( node );
4066
4067 maybeAccept_impl( node->ctor, *this );
4068 maybeAccept_impl( node->dtor, *this );
4069 maybeAccept_impl( node->init, *this );
4070
4071 VISIT_END( node );
4072}
4073
4074template< typename pass_type >
4075Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
4076 MUTATE_START( node );
4077
4078 maybeMutate_impl( node->ctor, *this );
4079 maybeMutate_impl( node->dtor, *this );
4080 maybeMutate_impl( node->init, *this );
4081
4082 MUTATE_END( Initializer, node );
4083}
4084
4085//--------------------------------------------------------------------------
4086// Constant
4087template< typename pass_type >
4088void PassVisitor< pass_type >::visit( Constant * node ) {
4089 VISIT_START( node );
4090
4091 VISIT_END( node );
4092}
4093
4094template< typename pass_type >
4095void PassVisitor< pass_type >::visit( const Constant * node ) {
4096 VISIT_START( node );
4097
4098 VISIT_END( node );
4099}
4100
4101template< typename pass_type >
4102Constant * PassVisitor< pass_type >::mutate( Constant * node ) {
4103 MUTATE_START( node );
4104
4105 MUTATE_END( Constant, node );
4106}
4107
4108//--------------------------------------------------------------------------
4109// Attribute
4110template< typename pass_type >
4111void PassVisitor< pass_type >::visit( Attribute * node ) {
4112 VISIT_START( node );
4113
4114 maybeAccept_impl( node->parameters, *this );
4115
4116 VISIT_END( node );
4117}
4118
4119template< typename pass_type >
4120void PassVisitor< pass_type >::visit( const Attribute * node ) {
4121 VISIT_START( node );
4122
4123 maybeAccept_impl( node->parameters, *this );
4124
4125 VISIT_END( node );
4126}
4127
4128template< typename pass_type >
4129Attribute * PassVisitor< pass_type >::mutate( Attribute * node ) {
4130 MUTATE_START( node );
4131
4132 maybeMutate_impl( node->parameters, *this );
4133
4134 MUTATE_END( Attribute, node );
4135}
4136
4137//--------------------------------------------------------------------------
4138// TypeSubstitution
4139template< typename pass_type >
4140TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
4141 MUTATE_START( node );
4142
4143 for ( auto & p : node->typeEnv ) {
4144 indexerScopedMutate( p.second, *this );
4145 }
4146 for ( auto & p : node->varEnv ) {
4147 indexerScopedMutate( p.second, *this );
4148 }
4149
4150 MUTATE_END( TypeSubstitution, node );
4151}
4152
4153#undef VISIT_START
4154#undef VISIT_END
4155
4156#undef MUTATE_START
4157#undef MUTATE_END
Note: See TracBrowser for help on using the repository browser.