source: src/Common/PassVisitor.impl.h @ 12daa43

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 12daa43 was 798a8b3, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Attributes are now correctly visited when replacing typedefs

  • Property mode set to 100644
File size: 109.2 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                        // First remember that we are now within a function.
610                        ValueGuard< bool > oldInFunction( inFunction );
611                        inFunction = true;
612                        // The function body needs to have the same scope as parameters.
613                        // A CompoundStmt will not enter a new scope if atFunctionTop is true.
614                        ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
615                        atFunctionTop = true;
616                        maybeMutate_impl( node->statements, *this );
617                        maybeMutate_impl( node->attributes, *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
791//--------------------------------------------------------------------------
792// TraitDecl
793template< typename pass_type >
794void PassVisitor< pass_type >::visit( TraitDecl * node ) {
795        VISIT_START( node );
796
797        {
798                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
799                maybeAccept_impl( node->parameters, *this );
800                maybeAccept_impl( node->members   , *this );
801                maybeAccept_impl( node->attributes, *this );
802        }
803
804        indexerAddTrait( node );
805
806        VISIT_END( node );
807}
808
809template< typename pass_type >
810void PassVisitor< pass_type >::visit( const TraitDecl * node ) {
811        VISIT_START( node );
812
813        {
814                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
815                maybeAccept_impl( node->parameters, *this );
816                maybeAccept_impl( node->members   , *this );
817                maybeAccept_impl( node->attributes, *this );
818        }
819
820        indexerAddTrait( node );
821
822        VISIT_END( node );
823}
824
825template< typename pass_type >
826Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) {
827        MUTATE_START( node );
828
829        {
830                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
831                maybeMutate_impl( node->parameters, *this );
832                maybeMutate_impl( node->members   , *this );
833                maybeMutate_impl( node->attributes, *this );
834        }
835
836        indexerAddTrait( node );
837
838        MUTATE_END( Declaration, node );
839}
840
841//--------------------------------------------------------------------------
842// TypeDecl
843template< typename pass_type >
844void PassVisitor< pass_type >::visit( TypeDecl * node ) {
845        VISIT_START( node );
846
847        {
848                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
849                maybeAccept_impl( node->base      , *this );
850        }
851
852        // see A NOTE ON THE ORDER OF TRAVERSAL, above
853        // note that assertions come after the type is added to the symtab, since they are not part of the type proper
854        // and may depend on the type itself
855        indexerAddType( node );
856
857        maybeAccept_impl( node->assertions, *this );
858
859        indexerScopedAccept( node->init, *this );
860
861        VISIT_END( node );
862}
863
864
865template< typename pass_type >
866void PassVisitor< pass_type >::visit( const TypeDecl * node ) {
867        VISIT_START( node );
868
869        {
870                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
871                maybeAccept_impl( node->base      , *this );
872        }
873
874        // see A NOTE ON THE ORDER OF TRAVERSAL, above
875        // note that assertions come after the type is added to the symtab, since they are not part of the type proper
876        // and may depend on the type itself
877        indexerAddType( node );
878
879        maybeAccept_impl( node->assertions, *this );
880
881        indexerScopedAccept( node->init, *this );
882
883        VISIT_END( node );
884}
885
886template< typename pass_type >
887Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
888        MUTATE_START( node );
889
890        {
891                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
892                maybeMutate_impl( node->base      , *this );
893        }
894
895        // see A NOTE ON THE ORDER OF TRAVERSAL, above
896        // note that assertions come after the type is added to the symtab, since they are not part of the type proper
897        // and may depend on the type itself
898        indexerAddType( node );
899
900        maybeMutate_impl( node->assertions, *this );
901
902        indexerScopedMutate( node->init, *this );
903
904        MUTATE_END( Declaration, node );
905}
906
907//--------------------------------------------------------------------------
908// TypedefDecl
909template< typename pass_type >
910void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
911        VISIT_START( node );
912
913        {
914                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
915                maybeAccept_impl( node->base      , *this );
916        }
917
918        indexerAddType( node );
919
920        maybeAccept_impl( node->assertions, *this );
921
922        VISIT_END( node );
923}
924
925template< typename pass_type >
926void PassVisitor< pass_type >::visit( const TypedefDecl * node ) {
927        VISIT_START( node );
928
929        {
930                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
931                maybeAccept_impl( node->base      , *this );
932        }
933
934        indexerAddType( node );
935
936        maybeAccept_impl( node->assertions, *this );
937
938        VISIT_END( node );
939}
940
941template< typename pass_type >
942Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) {
943        MUTATE_START( node );
944
945        {
946                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
947                maybeMutate_impl( node->base      , *this );
948        }
949
950        indexerAddType( node );
951
952        maybeMutate_impl( node->assertions, *this );
953
954        MUTATE_END( Declaration, node );
955}
956
957//--------------------------------------------------------------------------
958// AsmDecl
959template< typename pass_type >
960void PassVisitor< pass_type >::visit( AsmDecl * node ) {
961        VISIT_START( node );
962
963        maybeAccept_impl( node->stmt, *this );
964
965        VISIT_END( node );
966}
967
968template< typename pass_type >
969void PassVisitor< pass_type >::visit( const AsmDecl * node ) {
970        VISIT_START( node );
971
972        maybeAccept_impl( node->stmt, *this );
973
974        VISIT_END( node );
975}
976
977template< typename pass_type >
978AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) {
979        MUTATE_START( node );
980
981        maybeMutate_impl( node->stmt, *this );
982
983        MUTATE_END( AsmDecl, node );
984}
985
986//--------------------------------------------------------------------------
987// DirectiveDecl
988template< typename pass_type >
989void PassVisitor< pass_type >::visit( DirectiveDecl * node ) {
990        VISIT_START( node );
991
992        maybeAccept_impl( node->stmt, *this );
993
994        VISIT_END( node );
995}
996
997template< typename pass_type >
998void PassVisitor< pass_type >::visit( const DirectiveDecl * node ) {
999        VISIT_START( node );
1000
1001        maybeAccept_impl( node->stmt, *this );
1002
1003        VISIT_END( node );
1004}
1005
1006template< typename pass_type >
1007DirectiveDecl * PassVisitor< pass_type >::mutate( DirectiveDecl * node ) {
1008        MUTATE_START( node );
1009
1010        maybeMutate_impl( node->stmt, *this );
1011
1012        MUTATE_END( DirectiveDecl, node );
1013}
1014
1015//--------------------------------------------------------------------------
1016// StaticAssertDecl
1017template< typename pass_type >
1018void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) {
1019        VISIT_START( node );
1020
1021        node->condition = visitExpression( node->condition );
1022        maybeAccept_impl( node->message, *this );
1023
1024        VISIT_END( node );
1025}
1026
1027template< typename pass_type >
1028void PassVisitor< pass_type >::visit( const StaticAssertDecl * node ) {
1029        VISIT_START( node );
1030
1031        visitExpression( node->condition );
1032        maybeAccept_impl( node->message, *this );
1033
1034        VISIT_END( node );
1035}
1036
1037template< typename pass_type >
1038StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
1039        MUTATE_START( node );
1040
1041        node->condition = mutateExpression( node->condition );
1042        maybeMutate_impl( node->message, *this );
1043
1044        MUTATE_END( StaticAssertDecl, node );
1045}
1046
1047//--------------------------------------------------------------------------
1048// CompoundStmt
1049template< typename pass_type >
1050void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
1051        VISIT_START( node );
1052        {
1053                // Do not enter a new scope if atFunctionTop is true, don't leave one either.
1054                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
1055                auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
1056                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
1057                atFunctionTop = false;
1058                visitStatementList( node->kids );
1059        }
1060        VISIT_END( node );
1061}
1062
1063template< typename pass_type >
1064void PassVisitor< pass_type >::visit( const CompoundStmt * node ) {
1065        VISIT_START( node );
1066        {
1067                // Do not enter a new scope if atFunctionTop is true, don't leave one either.
1068                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
1069                auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
1070                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
1071                atFunctionTop = false;
1072                visitStatementList( node->kids );
1073        }
1074        VISIT_END( node );
1075}
1076
1077template< typename pass_type >
1078CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
1079        MUTATE_START( node );
1080        {
1081                // Do not enter a new scope if atFunctionTop is true, don't leave one either.
1082                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
1083                auto guard1 = makeFuncGuard( [this, go = !atFunctionTop]() { if ( go ) indexerScopeEnter(); }, [this, go = !atFunctionTop]() { if ( go ) indexerScopeLeave(); } );
1084                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
1085                atFunctionTop = false;
1086                mutateStatementList( node->kids );
1087        }
1088        MUTATE_END( CompoundStmt, node );
1089}
1090
1091//--------------------------------------------------------------------------
1092// ExprStmt
1093template< typename pass_type >
1094void PassVisitor< pass_type >::visit( ExprStmt * node ) {
1095        VISIT_START( node );
1096
1097        visitExpression( node->expr );
1098
1099        VISIT_END( node );
1100}
1101
1102template< typename pass_type >
1103void PassVisitor< pass_type >::visit( const ExprStmt * node ) {
1104        VISIT_START( node );
1105
1106        visitExpression( node->expr );
1107
1108        VISIT_END( node );
1109}
1110
1111template< typename pass_type >
1112Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
1113        MUTATE_START( node );
1114
1115        node->expr = mutateExpression( node->expr );
1116
1117        MUTATE_END( Statement, node );
1118}
1119
1120//--------------------------------------------------------------------------
1121// AsmStmt
1122template< typename pass_type >
1123void PassVisitor< pass_type >::visit( AsmStmt * node ) {
1124        VISIT_START( node )
1125
1126        maybeAccept_impl( node->instruction, *this );
1127        maybeAccept_impl( node->output, *this );
1128        maybeAccept_impl( node->input, *this );
1129        maybeAccept_impl( node->clobber, *this );
1130
1131        VISIT_END( node );
1132}
1133
1134template< typename pass_type >
1135void PassVisitor< pass_type >::visit( const AsmStmt * node ) {
1136        VISIT_START( node )
1137
1138        maybeAccept_impl( node->instruction, *this );
1139        maybeAccept_impl( node->output, *this );
1140        maybeAccept_impl( node->input, *this );
1141        maybeAccept_impl( node->clobber, *this );
1142
1143        VISIT_END( node );
1144}
1145
1146template< typename pass_type >
1147Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
1148        MUTATE_START( node );
1149
1150        maybeMutate_impl( node->instruction, *this );
1151        maybeMutate_impl( node->output, *this );
1152        maybeMutate_impl( node->input, *this );
1153        maybeMutate_impl( node->clobber, *this );
1154
1155        MUTATE_END( Statement, node );
1156}
1157
1158//--------------------------------------------------------------------------
1159// AsmStmt
1160template< typename pass_type >
1161void PassVisitor< pass_type >::visit( DirectiveStmt * node ) {
1162        VISIT_START( node )
1163
1164        VISIT_END( node );
1165}
1166
1167template< typename pass_type >
1168void PassVisitor< pass_type >::visit( const DirectiveStmt * node ) {
1169        VISIT_START( node )
1170
1171        VISIT_END( node );
1172}
1173
1174template< typename pass_type >
1175Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
1176        MUTATE_START( node );
1177
1178        MUTATE_END( Statement, node );
1179}
1180
1181//--------------------------------------------------------------------------
1182// IfStmt
1183template< typename pass_type >
1184void PassVisitor< pass_type >::visit( IfStmt * node ) {
1185        VISIT_START( node );
1186        {
1187                // if statements introduce a level of scope (for the initialization)
1188                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1189                maybeAccept_impl( node->initialization, *this );
1190                visitExpression ( node->condition );
1191                node->thenPart = visitStatement( node->thenPart );
1192                node->elsePart = visitStatement( node->elsePart );
1193        }
1194        VISIT_END( node );
1195}
1196
1197template< typename pass_type >
1198void PassVisitor< pass_type >::visit( const IfStmt * node ) {
1199        VISIT_START( node );
1200        {
1201                // if statements introduce a level of scope (for the initialization)
1202                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1203                maybeAccept_impl( node->initialization, *this );
1204                visitExpression ( node->condition );
1205                visitStatement  ( node->thenPart );
1206                visitStatement  ( node->elsePart );
1207        }
1208        VISIT_END( node );
1209}
1210
1211template< typename pass_type >
1212Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
1213        MUTATE_START( node );
1214        {
1215                // if statements introduce a level of scope (for the initialization)
1216                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1217                maybeMutate_impl( node->initialization, *this );
1218                node->condition = mutateExpression( node->condition );
1219                node->thenPart  = mutateStatement ( node->thenPart  );
1220                node->elsePart  = mutateStatement ( node->elsePart  );
1221        }
1222        MUTATE_END( Statement, node );
1223}
1224
1225//--------------------------------------------------------------------------
1226// WhileStmt
1227template< typename pass_type >
1228void PassVisitor< pass_type >::visit( WhileStmt * node ) {
1229        VISIT_START( node );
1230
1231        {
1232                // while statements introduce a level of scope (for the initialization)
1233                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1234                maybeAccept_impl( node->initialization, *this );
1235                visitExpression ( node->condition );
1236                node->body = visitStatement( node->body );
1237        }
1238
1239        VISIT_END( node );
1240}
1241
1242template< typename pass_type >
1243void PassVisitor< pass_type >::visit( const WhileStmt * node ) {
1244        VISIT_START( node );
1245
1246        {
1247                // while statements introduce a level of scope (for the initialization)
1248                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1249                maybeAccept_impl( node->initialization, *this );
1250                visitExpression ( node->condition );
1251                visitStatement  ( node->body );
1252        }
1253
1254        VISIT_END( node );
1255}
1256
1257template< typename pass_type >
1258Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
1259        MUTATE_START( node );
1260
1261        {
1262                // while statements introduce a level of scope (for the initialization)
1263                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1264                maybeMutate_impl( node->initialization, *this );
1265                node->condition = mutateExpression( node->condition );
1266                node->body      = mutateStatement ( node->body      );
1267        }
1268
1269
1270        MUTATE_END( Statement, node );
1271}
1272
1273//--------------------------------------------------------------------------
1274// ForStmt
1275template< typename pass_type >
1276void PassVisitor< pass_type >::visit( ForStmt * node ) {
1277        VISIT_START( node );
1278        {
1279                // for statements introduce a level of scope (for the initialization)
1280                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1281                maybeAccept_impl( node->initialization, *this );
1282                visitExpression( node->condition );
1283                visitExpression( node->increment );
1284                node->body = visitStatement( node->body );
1285        }
1286        VISIT_END( node );
1287}
1288
1289template< typename pass_type >
1290void PassVisitor< pass_type >::visit( const ForStmt * node ) {
1291        VISIT_START( node );
1292        {
1293                // for statements introduce a level of scope (for the initialization)
1294                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1295                maybeAccept_impl( node->initialization, *this );
1296                visitExpression( node->condition );
1297                visitExpression( node->increment );
1298                visitStatement ( node->body );
1299        }
1300        VISIT_END( node );
1301}
1302
1303template< typename pass_type >
1304Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
1305        MUTATE_START( node );
1306        {
1307                // for statements introduce a level of scope (for the initialization)
1308                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1309                maybeMutate_impl( node->initialization, *this );
1310                node->condition = mutateExpression( node->condition );
1311                node->increment = mutateExpression( node->increment );
1312                node->body      = mutateStatement ( node->body      );
1313        }
1314        MUTATE_END( Statement, node );
1315}
1316
1317//--------------------------------------------------------------------------
1318// SwitchStmt
1319template< typename pass_type >
1320void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
1321        VISIT_START( node );
1322
1323        visitExpression   ( node->condition  );
1324        visitStatementList( node->statements );
1325
1326        VISIT_END( node );
1327}
1328
1329template< typename pass_type >
1330void PassVisitor< pass_type >::visit( const SwitchStmt * node ) {
1331        VISIT_START( node );
1332
1333        visitExpression   ( node->condition  );
1334        visitStatementList( node->statements );
1335
1336        VISIT_END( node );
1337}
1338
1339template< typename pass_type >
1340Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
1341        MUTATE_START( node );
1342
1343        node->condition = mutateExpression( node->condition );
1344        mutateStatementList( node->statements );
1345
1346        MUTATE_END( Statement, node );
1347}
1348
1349//--------------------------------------------------------------------------
1350// CaseStmt
1351template< typename pass_type >
1352void PassVisitor< pass_type >::visit( CaseStmt * node ) {
1353        VISIT_START( node );
1354
1355        visitExpression   ( node->condition );
1356        visitStatementList( node->stmts     );
1357
1358        VISIT_END( node );
1359}
1360
1361template< typename pass_type >
1362void PassVisitor< pass_type >::visit( const CaseStmt * node ) {
1363        VISIT_START( node );
1364
1365        visitExpression   ( node->condition );
1366        visitStatementList( node->stmts     );
1367
1368        VISIT_END( node );
1369}
1370
1371template< typename pass_type >
1372Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
1373        MUTATE_START( node );
1374
1375        node->condition = mutateExpression( node->condition );
1376        mutateStatementList( node->stmts );
1377
1378        MUTATE_END( Statement, node );
1379}
1380
1381//--------------------------------------------------------------------------
1382// BranchStmt
1383template< typename pass_type >
1384void PassVisitor< pass_type >::visit( BranchStmt * node ) {
1385        VISIT_START( node );
1386        VISIT_END( node );
1387}
1388
1389template< typename pass_type >
1390void PassVisitor< pass_type >::visit( const BranchStmt * node ) {
1391        VISIT_START( node );
1392        VISIT_END( node );
1393}
1394
1395template< typename pass_type >
1396Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
1397        MUTATE_START( node );
1398        MUTATE_END( Statement, node );
1399}
1400
1401//--------------------------------------------------------------------------
1402// ReturnStmt
1403template< typename pass_type >
1404void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
1405        VISIT_START( node );
1406
1407        visitExpression( node->expr );
1408
1409        VISIT_END( node );
1410}
1411
1412template< typename pass_type >
1413void PassVisitor< pass_type >::visit( const ReturnStmt * node ) {
1414        VISIT_START( node );
1415
1416        visitExpression( node->expr );
1417
1418        VISIT_END( node );
1419}
1420
1421template< typename pass_type >
1422Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
1423        MUTATE_START( node );
1424
1425        node->expr = mutateExpression( node->expr );
1426
1427        MUTATE_END( Statement, node );
1428}
1429
1430//--------------------------------------------------------------------------
1431// ThrowStmt
1432template< typename pass_type >
1433void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
1434        VISIT_START( node );
1435
1436        maybeAccept_impl( node->expr, *this );
1437        maybeAccept_impl( node->target, *this );
1438
1439        VISIT_END( node );
1440}
1441
1442template< typename pass_type >
1443void PassVisitor< pass_type >::visit( const ThrowStmt * node ) {
1444        VISIT_START( node );
1445
1446        maybeAccept_impl( node->expr, *this );
1447        maybeAccept_impl( node->target, *this );
1448
1449        VISIT_END( node );
1450}
1451
1452template< typename pass_type >
1453Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
1454        MUTATE_START( node );
1455
1456        maybeMutate_impl( node->expr, *this );
1457        maybeMutate_impl( node->target, *this );
1458
1459        MUTATE_END( Statement, node );
1460}
1461
1462//--------------------------------------------------------------------------
1463// TryStmt
1464template< typename pass_type >
1465void PassVisitor< pass_type >::visit( TryStmt * node ) {
1466        VISIT_START( node );
1467
1468        maybeAccept_impl( node->block       , *this );
1469        maybeAccept_impl( node->handlers    , *this );
1470        maybeAccept_impl( node->finallyBlock, *this );
1471
1472        VISIT_END( node );
1473}
1474
1475template< typename pass_type >
1476void PassVisitor< pass_type >::visit( const TryStmt * node ) {
1477        VISIT_START( node );
1478
1479        maybeAccept_impl( node->block       , *this );
1480        maybeAccept_impl( node->handlers    , *this );
1481        maybeAccept_impl( node->finallyBlock, *this );
1482
1483        VISIT_END( node );
1484}
1485
1486template< typename pass_type >
1487Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
1488        MUTATE_START( node );
1489
1490        maybeMutate_impl( node->block       , *this );
1491        maybeMutate_impl( node->handlers    , *this );
1492        maybeMutate_impl( node->finallyBlock, *this );
1493
1494        MUTATE_END( Statement, node );
1495}
1496
1497//--------------------------------------------------------------------------
1498// CatchStmt
1499template< typename pass_type >
1500void PassVisitor< pass_type >::visit( CatchStmt * node ) {
1501        VISIT_START( node );
1502        {
1503                // catch statements introduce a level of scope (for the caught exception)
1504                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1505                maybeAccept_impl( node->decl, *this );
1506                node->cond = visitExpression( node->cond );
1507                node->body = visitStatement ( node->body );
1508        }
1509        VISIT_END( node );
1510}
1511
1512template< typename pass_type >
1513void PassVisitor< pass_type >::visit( const CatchStmt * node ) {
1514        VISIT_START( node );
1515        {
1516                // catch statements introduce a level of scope (for the caught exception)
1517                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1518                maybeAccept_impl( node->decl, *this );
1519                visitExpression ( node->cond );
1520                visitStatement  ( node->body );
1521        }
1522        VISIT_END( node );
1523}
1524
1525template< typename pass_type >
1526Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
1527        MUTATE_START( node );
1528        {
1529                // catch statements introduce a level of scope (for the caught exception)
1530                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1531                maybeMutate_impl( node->decl, *this );
1532                node->cond = mutateExpression( node->cond );
1533                node->body = mutateStatement ( node->body );
1534        }
1535        MUTATE_END( Statement, node );
1536}
1537
1538//--------------------------------------------------------------------------
1539// FinallyStmt
1540template< typename pass_type >
1541void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
1542        VISIT_START( node );
1543
1544        maybeAccept_impl( node->block, *this );
1545
1546        VISIT_END( node );
1547}
1548
1549template< typename pass_type >
1550void PassVisitor< pass_type >::visit( const FinallyStmt * node ) {
1551        VISIT_START( node );
1552
1553        maybeAccept_impl( node->block, *this );
1554
1555        VISIT_END( node );
1556}
1557
1558template< typename pass_type >
1559Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
1560        MUTATE_START( node );
1561
1562        maybeMutate_impl( node->block, *this );
1563
1564        MUTATE_END( Statement, node );
1565}
1566
1567//--------------------------------------------------------------------------
1568// SuspendStmt
1569template< typename pass_type >
1570void PassVisitor< pass_type >::visit( SuspendStmt * node ) {
1571        VISIT_START( node );
1572
1573        maybeAccept_impl( node->then  , *this );
1574
1575        VISIT_END( node );
1576}
1577
1578template< typename pass_type >
1579void PassVisitor< pass_type >::visit( const SuspendStmt * node ) {
1580        VISIT_START( node );
1581
1582        maybeAccept_impl( node->then  , *this );
1583
1584        VISIT_END( node );
1585}
1586
1587template< typename pass_type >
1588Statement * PassVisitor< pass_type >::mutate( SuspendStmt * node ) {
1589        MUTATE_START( node );
1590
1591        maybeMutate_impl( node->then  , *this );
1592
1593        MUTATE_END( Statement, node );
1594}
1595
1596//--------------------------------------------------------------------------
1597// WaitForStmt
1598template< typename pass_type >
1599void PassVisitor< pass_type >::visit( WaitForStmt * node ) {
1600        VISIT_START( node );
1601
1602        for( auto & clause : node->clauses ) {
1603                maybeAccept_impl( clause.target.function, *this );
1604                maybeAccept_impl( clause.target.arguments, *this );
1605
1606                maybeAccept_impl( clause.statement, *this );
1607                maybeAccept_impl( clause.condition, *this );
1608        }
1609
1610        maybeAccept_impl( node->timeout.time, *this );
1611        maybeAccept_impl( node->timeout.statement, *this );
1612        maybeAccept_impl( node->timeout.condition, *this );
1613        maybeAccept_impl( node->orelse.statement, *this );
1614        maybeAccept_impl( node->orelse.condition, *this );
1615
1616        VISIT_END( node );
1617}
1618
1619template< typename pass_type >
1620void PassVisitor< pass_type >::visit( const WaitForStmt * node ) {
1621        VISIT_START( node );
1622
1623        for( auto & clause : node->clauses ) {
1624                maybeAccept_impl( clause.target.function, *this );
1625                maybeAccept_impl( clause.target.arguments, *this );
1626
1627                maybeAccept_impl( clause.statement, *this );
1628                maybeAccept_impl( clause.condition, *this );
1629        }
1630
1631        maybeAccept_impl( node->timeout.time, *this );
1632        maybeAccept_impl( node->timeout.statement, *this );
1633        maybeAccept_impl( node->timeout.condition, *this );
1634        maybeAccept_impl( node->orelse.statement, *this );
1635        maybeAccept_impl( node->orelse.condition, *this );
1636
1637        VISIT_END( node );
1638}
1639
1640template< typename pass_type >
1641Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) {
1642        MUTATE_START( node );
1643
1644        for( auto & clause : node->clauses ) {
1645                maybeMutate_impl( clause.target.function, *this );
1646                maybeMutate_impl( clause.target.arguments, *this );
1647
1648                maybeMutate_impl( clause.statement, *this );
1649                maybeMutate_impl( clause.condition, *this );
1650        }
1651
1652        maybeMutate_impl( node->timeout.time, *this );
1653        maybeMutate_impl( node->timeout.statement, *this );
1654        maybeMutate_impl( node->timeout.condition, *this );
1655        maybeMutate_impl( node->orelse.statement, *this );
1656        maybeMutate_impl( node->orelse.condition, *this );
1657
1658        MUTATE_END( Statement, node );
1659}
1660
1661
1662
1663//--------------------------------------------------------------------------
1664// WithStmt
1665template< typename pass_type >
1666void PassVisitor< pass_type >::visit( WithStmt * node ) {
1667        VISIT_START( node );
1668        maybeAccept_impl( node->exprs, *this );
1669        {
1670                // catch statements introduce a level of scope (for the caught exception)
1671                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1672                indexerAddWith( node->exprs, node );
1673                maybeAccept_impl( node->stmt, *this );
1674        }
1675        VISIT_END( node );
1676}
1677
1678template< typename pass_type >
1679void PassVisitor< pass_type >::visit( const WithStmt * node ) {
1680        VISIT_START( node );
1681        maybeAccept_impl( node->exprs, *this );
1682        {
1683                // catch statements introduce a level of scope (for the caught exception)
1684                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1685                indexerAddWith( node->exprs, node );
1686                maybeAccept_impl( node->stmt, *this );
1687        }
1688        VISIT_END( node );
1689}
1690
1691template< typename pass_type >
1692Declaration * PassVisitor< pass_type >::mutate( WithStmt * node ) {
1693        MUTATE_START( node );
1694        maybeMutate_impl( node->exprs, *this );
1695        {
1696                // catch statements introduce a level of scope (for the caught exception)
1697                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
1698                indexerAddWith( node->exprs, node );
1699                maybeMutate_impl( node->stmt, *this );
1700        }
1701        MUTATE_END( Declaration, node );
1702}
1703
1704//--------------------------------------------------------------------------
1705// NullStmt
1706template< typename pass_type >
1707void PassVisitor< pass_type >::visit( NullStmt * node ) {
1708        VISIT_START( node );
1709        VISIT_END( node );
1710}
1711
1712template< typename pass_type >
1713void PassVisitor< pass_type >::visit( const NullStmt * node ) {
1714        VISIT_START( node );
1715        VISIT_END( node );
1716}
1717
1718template< typename pass_type >
1719NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) {
1720        MUTATE_START( node );
1721        MUTATE_END( NullStmt, node );
1722}
1723
1724//--------------------------------------------------------------------------
1725// DeclStmt
1726template< typename pass_type >
1727void PassVisitor< pass_type >::visit( DeclStmt * node ) {
1728        VISIT_START( node );
1729
1730        maybeAccept_impl( node->decl, *this );
1731
1732        VISIT_END( node );
1733}
1734
1735template< typename pass_type >
1736void PassVisitor< pass_type >::visit( const DeclStmt * node ) {
1737        VISIT_START( node );
1738
1739        maybeAccept_impl( node->decl, *this );
1740
1741        VISIT_END( node );
1742}
1743
1744template< typename pass_type >
1745Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) {
1746        MUTATE_START( node );
1747
1748        maybeMutate_impl( node->decl, *this );
1749
1750        MUTATE_END( Statement, node );
1751}
1752
1753//--------------------------------------------------------------------------
1754// ImplicitCtorDtorStmt
1755template< typename pass_type >
1756void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
1757        VISIT_START( node );
1758
1759        maybeAccept_impl( node->callStmt, *this );
1760
1761        VISIT_END( node );
1762}
1763
1764template< typename pass_type >
1765void PassVisitor< pass_type >::visit( const ImplicitCtorDtorStmt * node ) {
1766        VISIT_START( node );
1767
1768        maybeAccept_impl( node->callStmt, *this );
1769
1770        VISIT_END( node );
1771}
1772
1773template< typename pass_type >
1774Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {
1775        MUTATE_START( node );
1776
1777        maybeMutate_impl( node->callStmt, *this );
1778
1779        MUTATE_END( Statement, node );
1780}
1781
1782//--------------------------------------------------------------------------
1783// ApplicationExpr
1784template< typename pass_type >
1785void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
1786        VISIT_START( node );
1787
1788        indexerScopedAccept( node->result  , *this );
1789        maybeAccept_impl   ( node->function, *this );
1790        maybeAccept_impl   ( node->args    , *this );
1791
1792        VISIT_END( node );
1793}
1794
1795template< typename pass_type >
1796void PassVisitor< pass_type >::visit( const ApplicationExpr * node ) {
1797        VISIT_START( node );
1798
1799        indexerScopedAccept( node->result  , *this );
1800        maybeAccept_impl   ( node->function, *this );
1801        maybeAccept_impl   ( node->args    , *this );
1802
1803        VISIT_END( node );
1804}
1805
1806template< typename pass_type >
1807Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) {
1808        MUTATE_START( node );
1809
1810        indexerScopedMutate( node->env     , *this );
1811        indexerScopedMutate( node->result  , *this );
1812        maybeMutate_impl   ( node->function, *this );
1813        maybeMutate_impl   ( node->args    , *this );
1814
1815        MUTATE_END( Expression, node );
1816}
1817
1818//--------------------------------------------------------------------------
1819// UntypedExpr
1820template< typename pass_type >
1821void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
1822        VISIT_START( node );
1823
1824        // maybeAccept_impl( node->get_env(), *this );
1825        indexerScopedAccept( node->result, *this );
1826
1827        for ( auto expr : node->args ) {
1828                visitExpression( expr );
1829        }
1830
1831        VISIT_END( node );
1832}
1833
1834template< typename pass_type >
1835void PassVisitor< pass_type >::visit( const UntypedExpr * node ) {
1836        VISIT_START( node );
1837
1838        indexerScopedAccept( node->result, *this );
1839
1840        for ( auto expr : node->args ) {
1841                visitExpression( expr );
1842        }
1843
1844        VISIT_END( node );
1845}
1846
1847template< typename pass_type >
1848Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
1849        MUTATE_START( node );
1850
1851        indexerScopedMutate( node->env   , *this );
1852        indexerScopedMutate( node->result, *this );
1853
1854        for ( auto& expr : node->args ) {
1855                expr = mutateExpression( expr );
1856        }
1857
1858        MUTATE_END( Expression, node );
1859}
1860
1861//--------------------------------------------------------------------------
1862// NameExpr
1863template< typename pass_type >
1864void PassVisitor< pass_type >::visit( NameExpr * node ) {
1865        VISIT_START( node );
1866
1867        indexerScopedAccept( node->result, *this );
1868
1869        VISIT_END( node );
1870}
1871
1872template< typename pass_type >
1873void PassVisitor< pass_type >::visit( const NameExpr * node ) {
1874        VISIT_START( node );
1875
1876        indexerScopedAccept( node->result, *this );
1877
1878        VISIT_END( node );
1879}
1880
1881template< typename pass_type >
1882Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
1883        MUTATE_START( node );
1884
1885        indexerScopedMutate( node->env   , *this );
1886        indexerScopedMutate( node->result, *this );
1887
1888        MUTATE_END( Expression, node );
1889}
1890
1891//--------------------------------------------------------------------------
1892// CastExpr
1893template< typename pass_type >
1894void PassVisitor< pass_type >::visit( CastExpr * node ) {
1895        VISIT_START( node );
1896
1897        indexerScopedAccept( node->result, *this );
1898        maybeAccept_impl   ( node->arg   , *this );
1899
1900        VISIT_END( node );
1901}
1902
1903template< typename pass_type >
1904void PassVisitor< pass_type >::visit( const CastExpr * node ) {
1905        VISIT_START( node );
1906
1907        indexerScopedAccept( node->result, *this );
1908        maybeAccept_impl   ( node->arg   , *this );
1909
1910        VISIT_END( node );
1911}
1912
1913template< typename pass_type >
1914Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) {
1915        MUTATE_START( node );
1916
1917        indexerScopedMutate( node->env   , *this );
1918        indexerScopedMutate( node->result, *this );
1919        maybeMutate_impl   ( node->arg   , *this );
1920
1921        MUTATE_END( Expression, node );
1922}
1923
1924//--------------------------------------------------------------------------
1925// KeywordCastExpr
1926template< typename pass_type >
1927void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
1928        VISIT_START( node );
1929
1930        indexerScopedAccept( node->result, *this );
1931        maybeAccept_impl        ( node->arg   , *this );
1932
1933        VISIT_END( node );
1934}
1935
1936template< typename pass_type >
1937void PassVisitor< pass_type >::visit( const KeywordCastExpr * node ) {
1938        VISIT_START( node );
1939
1940        indexerScopedAccept( node->result, *this );
1941        maybeAccept_impl   ( node->arg   , *this );
1942
1943        VISIT_END( node );
1944}
1945
1946template< typename pass_type >
1947Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
1948        MUTATE_START( node );
1949
1950        indexerScopedMutate( node->env   , *this );
1951        indexerScopedMutate( node->result, *this );
1952        maybeMutate_impl   ( node->arg   , *this );
1953
1954        MUTATE_END( Expression, node );
1955}
1956
1957//--------------------------------------------------------------------------
1958// VirtualCastExpr
1959template< typename pass_type >
1960void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) {
1961        VISIT_START( node );
1962
1963        indexerScopedAccept( node->result, *this );
1964        maybeAccept_impl   ( node->arg, *this );
1965
1966        VISIT_END( node );
1967}
1968
1969template< typename pass_type >
1970void PassVisitor< pass_type >::visit( const VirtualCastExpr * node ) {
1971        VISIT_START( node );
1972
1973        indexerScopedAccept( node->result, *this );
1974        maybeAccept_impl   ( node->arg, *this );
1975
1976        VISIT_END( node );
1977}
1978
1979template< typename pass_type >
1980Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) {
1981        MUTATE_START( node );
1982
1983        indexerScopedMutate( node->env   , *this );
1984        indexerScopedMutate( node->result, *this );
1985        maybeMutate_impl   ( node->arg   , *this );
1986
1987        MUTATE_END( Expression, node );
1988}
1989
1990//--------------------------------------------------------------------------
1991// AddressExpr
1992template< typename pass_type >
1993void PassVisitor< pass_type >::visit( AddressExpr * node ) {
1994        VISIT_START( node );
1995
1996        indexerScopedAccept( node->result, *this );
1997        maybeAccept_impl   ( node->arg   , *this );
1998
1999        VISIT_END( node );
2000}
2001
2002template< typename pass_type >
2003void PassVisitor< pass_type >::visit( const AddressExpr * node ) {
2004        VISIT_START( node );
2005
2006        indexerScopedAccept( node->result, *this );
2007        maybeAccept_impl   ( node->arg   , *this );
2008
2009        VISIT_END( node );
2010}
2011
2012template< typename pass_type >
2013Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) {
2014        MUTATE_START( node );
2015
2016        indexerScopedMutate( node->env   , *this );
2017        indexerScopedMutate( node->result, *this );
2018        maybeMutate_impl   ( node->arg   , *this );
2019
2020        MUTATE_END( Expression, node );
2021}
2022
2023//--------------------------------------------------------------------------
2024// LabelAddressExpr
2025template< typename pass_type >
2026void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
2027        VISIT_START( node );
2028
2029        indexerScopedAccept( node->result, *this );
2030
2031        VISIT_END( node );
2032}
2033
2034template< typename pass_type >
2035void PassVisitor< pass_type >::visit( const LabelAddressExpr * node ) {
2036        VISIT_START( node );
2037
2038        indexerScopedAccept( node->result, *this );
2039
2040        VISIT_END( node );
2041}
2042
2043template< typename pass_type >
2044Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) {
2045        MUTATE_START( node );
2046
2047        indexerScopedMutate( node->env   , *this );
2048        indexerScopedMutate( node->result, *this );
2049
2050        MUTATE_END( Expression, node );
2051}
2052
2053//--------------------------------------------------------------------------
2054// UntypedMemberExpr
2055template< typename pass_type >
2056void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
2057        VISIT_START( node );
2058
2059        indexerScopedAccept( node->result   , *this );
2060        maybeAccept_impl   ( node->aggregate, *this );
2061        maybeAccept_impl   ( node->member   , *this );
2062
2063        VISIT_END( node );
2064}
2065
2066template< typename pass_type >
2067void PassVisitor< pass_type >::visit( const UntypedMemberExpr * node ) {
2068        VISIT_START( node );
2069
2070        indexerScopedAccept( node->result   , *this );
2071        maybeAccept_impl   ( node->aggregate, *this );
2072        maybeAccept_impl   ( node->member   , *this );
2073
2074        VISIT_END( node );
2075}
2076
2077template< typename pass_type >
2078Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) {
2079        MUTATE_START( node );
2080
2081        indexerScopedMutate( node->env      , *this );
2082        indexerScopedMutate( node->result   , *this );
2083        maybeMutate_impl   ( node->aggregate, *this );
2084        maybeMutate_impl   ( node->member   , *this );
2085
2086        MUTATE_END( Expression, node );
2087}
2088
2089//--------------------------------------------------------------------------
2090// MemberExpr
2091template< typename pass_type >
2092void PassVisitor< pass_type >::visit( MemberExpr * node ) {
2093        VISIT_START( node );
2094
2095        indexerScopedAccept( node->result   , *this );
2096        maybeAccept_impl   ( node->aggregate, *this );
2097
2098        VISIT_END( node );
2099}
2100
2101template< typename pass_type >
2102void PassVisitor< pass_type >::visit( const MemberExpr * node ) {
2103        VISIT_START( node );
2104
2105        indexerScopedAccept( node->result   , *this );
2106        maybeAccept_impl   ( node->aggregate, *this );
2107
2108        VISIT_END( node );
2109}
2110
2111template< typename pass_type >
2112Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) {
2113        MUTATE_START( node );
2114
2115        indexerScopedMutate( node->env      , *this );
2116        indexerScopedMutate( node->result   , *this );
2117        maybeMutate_impl   ( node->aggregate, *this );
2118
2119        MUTATE_END( Expression, node );
2120}
2121
2122//--------------------------------------------------------------------------
2123// VariableExpr
2124template< typename pass_type >
2125void PassVisitor< pass_type >::visit( VariableExpr * node ) {
2126        VISIT_START( node );
2127
2128        indexerScopedAccept( node->result, *this );
2129
2130        VISIT_END( node );
2131}
2132
2133template< typename pass_type >
2134void PassVisitor< pass_type >::visit( const VariableExpr * node ) {
2135        VISIT_START( node );
2136
2137        indexerScopedAccept( node->result, *this );
2138
2139        VISIT_END( node );
2140}
2141
2142template< typename pass_type >
2143Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) {
2144        MUTATE_START( node );
2145
2146        indexerScopedMutate( node->env   , *this );
2147        indexerScopedMutate( node->result, *this );
2148
2149        MUTATE_END( Expression, node );
2150}
2151
2152//--------------------------------------------------------------------------
2153// ConstantExpr
2154template< typename pass_type >
2155void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
2156        VISIT_START( node );
2157
2158        indexerScopedAccept( node->result   , *this );
2159        maybeAccept_impl   ( &node->constant, *this );
2160
2161        VISIT_END( node );
2162}
2163
2164template< typename pass_type >
2165void PassVisitor< pass_type >::visit( const ConstantExpr * node ) {
2166        VISIT_START( node );
2167
2168        indexerScopedAccept( node->result   , *this );
2169        maybeAccept_impl   ( &node->constant, *this );
2170
2171        VISIT_END( node );
2172}
2173
2174template< typename pass_type >
2175Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) {
2176        MUTATE_START( node );
2177
2178        indexerScopedMutate( node->env   , *this );
2179        indexerScopedMutate( node->result, *this );
2180        Constant * ptr = &node->constant;
2181        maybeMutate_impl( ptr, *this );
2182        node->constant = *ptr;
2183
2184        MUTATE_END( Expression, node );
2185}
2186
2187//--------------------------------------------------------------------------
2188// SizeofExpr
2189template< typename pass_type >
2190void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
2191        VISIT_START( node );
2192
2193        indexerScopedAccept( node->result, *this );
2194        if ( node->get_isType() ) {
2195                maybeAccept_impl( node->type, *this );
2196        } else {
2197                maybeAccept_impl( node->expr, *this );
2198        }
2199
2200        VISIT_END( node );
2201}
2202
2203template< typename pass_type >
2204void PassVisitor< pass_type >::visit( const SizeofExpr * node ) {
2205        VISIT_START( node );
2206
2207        indexerScopedAccept( node->result, *this );
2208        if ( node->get_isType() ) {
2209                maybeAccept_impl( node->type, *this );
2210        } else {
2211                maybeAccept_impl( node->expr, *this );
2212        }
2213
2214        VISIT_END( node );
2215}
2216
2217template< typename pass_type >
2218Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) {
2219        MUTATE_START( node );
2220
2221        indexerScopedMutate( node->env   , *this );
2222        indexerScopedMutate( node->result, *this );
2223        if ( node->get_isType() ) {
2224                maybeMutate_impl( node->type, *this );
2225        } else {
2226                maybeMutate_impl( node->expr, *this );
2227        }
2228
2229        MUTATE_END( Expression, node );
2230}
2231
2232//--------------------------------------------------------------------------
2233// AlignofExpr
2234template< typename pass_type >
2235void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
2236        VISIT_START( node );
2237
2238        indexerScopedAccept( node->result, *this );
2239        if ( node->get_isType() ) {
2240                maybeAccept_impl( node->type, *this );
2241        } else {
2242                maybeAccept_impl( node->expr, *this );
2243        }
2244
2245        VISIT_END( node );
2246}
2247
2248template< typename pass_type >
2249void PassVisitor< pass_type >::visit( const AlignofExpr * node ) {
2250        VISIT_START( node );
2251
2252        indexerScopedAccept( node->result, *this );
2253        if ( node->get_isType() ) {
2254                maybeAccept_impl( node->type, *this );
2255        } else {
2256                maybeAccept_impl( node->expr, *this );
2257        }
2258
2259        VISIT_END( node );
2260}
2261
2262template< typename pass_type >
2263Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) {
2264        MUTATE_START( node );
2265
2266        indexerScopedMutate( node->env   , *this );
2267        indexerScopedMutate( node->result, *this );
2268        if ( node->get_isType() ) {
2269                maybeMutate_impl( node->type, *this );
2270        } else {
2271                maybeMutate_impl( node->expr, *this );
2272        }
2273
2274        MUTATE_END( Expression, node );
2275}
2276
2277//--------------------------------------------------------------------------
2278// UntypedOffsetofExpr
2279template< typename pass_type >
2280void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
2281        VISIT_START( node );
2282
2283        indexerScopedAccept( node->result, *this );
2284        maybeAccept_impl   ( node->type  , *this );
2285
2286        VISIT_END( node );
2287}
2288
2289template< typename pass_type >
2290void PassVisitor< pass_type >::visit( const UntypedOffsetofExpr * node ) {
2291        VISIT_START( node );
2292
2293        indexerScopedAccept( node->result, *this );
2294        maybeAccept_impl   ( node->type  , *this );
2295
2296        VISIT_END( node );
2297}
2298
2299template< typename pass_type >
2300Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) {
2301        MUTATE_START( node );
2302
2303        indexerScopedMutate( node->env   , *this );
2304        indexerScopedMutate( node->result, *this );
2305        maybeMutate_impl   ( node->type  , *this );
2306
2307        MUTATE_END( Expression, node );
2308}
2309
2310//--------------------------------------------------------------------------
2311// OffsetofExpr
2312template< typename pass_type >
2313void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
2314        VISIT_START( node );
2315
2316        indexerScopedAccept( node->result, *this );
2317        maybeAccept_impl   ( node->type  , *this );
2318
2319        VISIT_END( node );
2320}
2321
2322template< typename pass_type >
2323void PassVisitor< pass_type >::visit( const OffsetofExpr * node ) {
2324        VISIT_START( node );
2325
2326        indexerScopedAccept( node->result, *this );
2327        maybeAccept_impl   ( node->type  , *this );
2328
2329        VISIT_END( node );
2330}
2331
2332template< typename pass_type >
2333Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) {
2334        MUTATE_START( node );
2335
2336        indexerScopedMutate( node->env   , *this );
2337        indexerScopedMutate( node->result, *this );
2338        maybeMutate_impl   ( node->type  , *this );
2339
2340        MUTATE_END( Expression, node );
2341}
2342
2343//--------------------------------------------------------------------------
2344// OffsetPackExpr
2345template< typename pass_type >
2346void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
2347        VISIT_START( node );
2348
2349        indexerScopedAccept( node->result, *this );
2350        maybeAccept_impl   ( node->type  , *this );
2351
2352        VISIT_END( node );
2353}
2354
2355template< typename pass_type >
2356void PassVisitor< pass_type >::visit( const OffsetPackExpr * node ) {
2357        VISIT_START( node );
2358
2359        indexerScopedAccept( node->result, *this );
2360        maybeAccept_impl   ( node->type  , *this );
2361
2362        VISIT_END( node );
2363}
2364
2365template< typename pass_type >
2366Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) {
2367        MUTATE_START( node );
2368
2369        indexerScopedMutate( node->env   , *this );
2370        indexerScopedMutate( node->result, *this );
2371        maybeMutate_impl   ( node->type  , *this );
2372
2373        MUTATE_END( Expression, node );
2374}
2375
2376//--------------------------------------------------------------------------
2377// LogicalExpr
2378template< typename pass_type >
2379void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
2380        VISIT_START( node );
2381
2382        indexerScopedAccept( node->result, *this );
2383        maybeAccept_impl   ( node->arg1  , *this );
2384        maybeAccept_impl   ( node->arg2  , *this );
2385
2386        VISIT_END( node );
2387}
2388
2389template< typename pass_type >
2390void PassVisitor< pass_type >::visit( const LogicalExpr * node ) {
2391        VISIT_START( node );
2392
2393        indexerScopedAccept( node->result, *this );
2394        maybeAccept_impl   ( node->arg1  , *this );
2395        maybeAccept_impl   ( node->arg2  , *this );
2396
2397        VISIT_END( node );
2398}
2399
2400template< typename pass_type >
2401Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) {
2402        MUTATE_START( node );
2403
2404        indexerScopedMutate( node->env   , *this );
2405        indexerScopedMutate( node->result, *this );
2406        maybeMutate_impl   ( node->arg1  , *this );
2407        maybeMutate_impl   ( node->arg2  , *this );
2408
2409        MUTATE_END( Expression, node );
2410}
2411
2412//--------------------------------------------------------------------------
2413// ConditionalExpr
2414template< typename pass_type >
2415void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
2416        VISIT_START( node );
2417
2418        indexerScopedAccept( node->result, *this );
2419        maybeAccept_impl        ( node->arg1  , *this );
2420        maybeAccept_impl        ( node->arg2  , *this );
2421        maybeAccept_impl        ( node->arg3  , *this );
2422
2423        VISIT_END( node );
2424}
2425
2426template< typename pass_type >
2427void PassVisitor< pass_type >::visit( const ConditionalExpr * node ) {
2428        VISIT_START( node );
2429
2430        indexerScopedAccept( node->result, *this );
2431        maybeAccept_impl   ( node->arg1  , *this );
2432        maybeAccept_impl   ( node->arg2  , *this );
2433        maybeAccept_impl   ( node->arg3  , *this );
2434
2435        VISIT_END( node );
2436}
2437
2438template< typename pass_type >
2439Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) {
2440        MUTATE_START( node );
2441
2442        indexerScopedMutate( node->env   , *this );
2443        indexerScopedMutate( node->result, *this );
2444        maybeMutate_impl   ( node->arg1  , *this );
2445        maybeMutate_impl   ( node->arg2  , *this );
2446        maybeMutate_impl   ( node->arg3  , *this );
2447
2448        MUTATE_END( Expression, node );
2449}
2450
2451//--------------------------------------------------------------------------
2452// CommaExpr
2453template< typename pass_type >
2454void PassVisitor< pass_type >::visit( CommaExpr * node ) {
2455        VISIT_START( node );
2456
2457        indexerScopedAccept( node->result, *this );
2458        maybeAccept_impl   ( node->arg1  , *this );
2459        maybeAccept_impl   ( node->arg2  , *this );
2460
2461        VISIT_END( node );
2462}
2463
2464template< typename pass_type >
2465void PassVisitor< pass_type >::visit( const CommaExpr * node ) {
2466        VISIT_START( node );
2467
2468        indexerScopedAccept( node->result, *this );
2469        maybeAccept_impl   ( node->arg1  , *this );
2470        maybeAccept_impl   ( node->arg2  , *this );
2471
2472        VISIT_END( node );
2473}
2474
2475template< typename pass_type >
2476Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) {
2477        MUTATE_START( node );
2478
2479        indexerScopedMutate( node->env   , *this );
2480        indexerScopedMutate( node->result, *this );
2481        maybeMutate_impl   ( node->arg1  , *this );
2482        maybeMutate_impl   ( node->arg2  , *this );
2483
2484        MUTATE_END( Expression, node );
2485}
2486
2487//--------------------------------------------------------------------------
2488// TypeExpr
2489template< typename pass_type >
2490void PassVisitor< pass_type >::visit( TypeExpr * node ) {
2491        VISIT_START( node );
2492
2493        indexerScopedAccept( node->result, *this );
2494        maybeAccept_impl   ( node->type, *this );
2495
2496        VISIT_END( node );
2497}
2498
2499template< typename pass_type >
2500void PassVisitor< pass_type >::visit( const TypeExpr * node ) {
2501        VISIT_START( node );
2502
2503        indexerScopedAccept( node->result, *this );
2504        maybeAccept_impl   ( node->type, *this );
2505
2506        VISIT_END( node );
2507}
2508
2509template< typename pass_type >
2510Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) {
2511        MUTATE_START( node );
2512
2513        indexerScopedMutate( node->env   , *this );
2514        indexerScopedMutate( node->result, *this );
2515        maybeMutate_impl   ( node->type  , *this );
2516
2517        MUTATE_END( Expression, node );
2518}
2519
2520//--------------------------------------------------------------------------
2521// AsmExpr
2522template< typename pass_type >
2523void PassVisitor< pass_type >::visit( AsmExpr * node ) {
2524        VISIT_START( node );
2525
2526        indexerScopedAccept( node->result    , *this );
2527        maybeAccept_impl   ( node->constraint, *this );
2528        maybeAccept_impl   ( node->operand   , *this );
2529
2530        VISIT_END( node );
2531}
2532
2533template< typename pass_type >
2534void PassVisitor< pass_type >::visit( const AsmExpr * node ) {
2535        VISIT_START( node );
2536
2537        indexerScopedAccept( node->result    , *this );
2538        maybeAccept_impl   ( node->constraint, *this );
2539        maybeAccept_impl   ( node->operand   , *this );
2540
2541        VISIT_END( node );
2542}
2543
2544template< typename pass_type >
2545Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) {
2546        MUTATE_START( node );
2547
2548        indexerScopedMutate( node->env       , *this );
2549        indexerScopedMutate( node->result    , *this );
2550        maybeMutate_impl   ( node->constraint, *this );
2551        maybeMutate_impl   ( node->operand   , *this );
2552
2553        MUTATE_END( Expression, node );
2554}
2555
2556//--------------------------------------------------------------------------
2557// ImplicitCopyCtorExpr
2558template< typename pass_type >
2559void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
2560        VISIT_START( node );
2561
2562        indexerScopedAccept( node->result    , *this );
2563        maybeAccept_impl   ( node->callExpr  , *this );
2564
2565        VISIT_END( node );
2566}
2567
2568template< typename pass_type >
2569void PassVisitor< pass_type >::visit( const ImplicitCopyCtorExpr * node ) {
2570        VISIT_START( node );
2571
2572        indexerScopedAccept( node->result    , *this );
2573        maybeAccept_impl   ( node->callExpr  , *this );
2574
2575        VISIT_END( node );
2576}
2577
2578template< typename pass_type >
2579Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) {
2580        MUTATE_START( node );
2581
2582        indexerScopedMutate( node->env       , *this );
2583        indexerScopedMutate( node->result    , *this );
2584        maybeMutate_impl   ( node->callExpr  , *this );
2585
2586        MUTATE_END( Expression, node );
2587}
2588
2589//--------------------------------------------------------------------------
2590// ConstructorExpr
2591template< typename pass_type >
2592void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
2593        VISIT_START( node );
2594
2595        indexerScopedAccept( node->result  , *this );
2596        maybeAccept_impl   ( node->callExpr, *this );
2597
2598        VISIT_END( node );
2599}
2600
2601template< typename pass_type >
2602void PassVisitor< pass_type >::visit( const ConstructorExpr * node ) {
2603        VISIT_START( node );
2604
2605        indexerScopedAccept( node->result  , *this );
2606        maybeAccept_impl   ( node->callExpr, *this );
2607
2608        VISIT_END( node );
2609}
2610
2611template< typename pass_type >
2612Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) {
2613        MUTATE_START( node );
2614
2615        indexerScopedMutate( node->env     , *this );
2616        indexerScopedMutate( node->result  , *this );
2617        maybeMutate_impl   ( node->callExpr, *this );
2618
2619        MUTATE_END( Expression, node );
2620}
2621
2622//--------------------------------------------------------------------------
2623// CompoundLiteralExpr
2624template< typename pass_type >
2625void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
2626        VISIT_START( node );
2627
2628        indexerScopedAccept( node->result     , *this );
2629        maybeAccept_impl   ( node->initializer, *this );
2630
2631        VISIT_END( node );
2632}
2633
2634template< typename pass_type >
2635void PassVisitor< pass_type >::visit( const CompoundLiteralExpr * node ) {
2636        VISIT_START( node );
2637
2638        indexerScopedAccept( node->result     , *this );
2639        maybeAccept_impl   ( node->initializer, *this );
2640
2641        VISIT_END( node );
2642}
2643
2644template< typename pass_type >
2645Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) {
2646        MUTATE_START( node );
2647
2648        indexerScopedMutate( node->env        , *this );
2649        indexerScopedMutate( node->result     , *this );
2650        maybeMutate_impl     ( node->initializer, *this );
2651
2652        MUTATE_END( Expression, node );
2653}
2654
2655//--------------------------------------------------------------------------
2656// RangeExpr
2657template< typename pass_type >
2658void PassVisitor< pass_type >::visit( RangeExpr * node ) {
2659        VISIT_START( node );
2660
2661        indexerScopedAccept( node->result, *this );
2662        maybeAccept_impl   ( node->low   , *this );
2663        maybeAccept_impl   ( node->high  , *this );
2664
2665        VISIT_END( node );
2666}
2667
2668template< typename pass_type >
2669void PassVisitor< pass_type >::visit( const RangeExpr * node ) {
2670        VISIT_START( node );
2671
2672        indexerScopedAccept( node->result, *this );
2673        maybeAccept_impl   ( node->low   , *this );
2674        maybeAccept_impl   ( node->high  , *this );
2675
2676        VISIT_END( node );
2677}
2678
2679template< typename pass_type >
2680Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
2681        MUTATE_START( node );
2682
2683        indexerScopedMutate( node->env   , *this );
2684        indexerScopedMutate( node->result, *this );
2685        maybeMutate_impl   ( node->low   , *this );
2686        maybeMutate_impl   ( node->high  , *this );
2687
2688        MUTATE_END( Expression, node );
2689}
2690
2691//--------------------------------------------------------------------------
2692// UntypedTupleExpr
2693template< typename pass_type >
2694void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
2695        VISIT_START( node );
2696
2697        indexerScopedAccept( node->result, *this );
2698        maybeAccept_impl   ( node->exprs , *this );
2699
2700        VISIT_END( node );
2701}
2702
2703template< typename pass_type >
2704void PassVisitor< pass_type >::visit( const UntypedTupleExpr * node ) {
2705        VISIT_START( node );
2706
2707        indexerScopedAccept( node->result, *this );
2708        maybeAccept_impl   ( node->exprs , *this );
2709
2710        VISIT_END( node );
2711}
2712
2713template< typename pass_type >
2714Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) {
2715        MUTATE_START( node );
2716
2717        indexerScopedMutate( node->env   , *this );
2718        indexerScopedMutate( node->result, *this );
2719        maybeMutate_impl   ( node->exprs , *this );
2720
2721        MUTATE_END( Expression, node );
2722}
2723
2724//--------------------------------------------------------------------------
2725// TupleExpr
2726template< typename pass_type >
2727void PassVisitor< pass_type >::visit( TupleExpr * node ) {
2728        VISIT_START( node );
2729
2730        indexerScopedAccept( node->result, *this );
2731        maybeAccept_impl   ( node->exprs , *this );
2732
2733        VISIT_END( node );
2734}
2735
2736template< typename pass_type >
2737void PassVisitor< pass_type >::visit( const TupleExpr * node ) {
2738        VISIT_START( node );
2739
2740        indexerScopedAccept( node->result, *this );
2741        maybeAccept_impl   ( node->exprs , *this );
2742
2743        VISIT_END( node );
2744}
2745
2746template< typename pass_type >
2747Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) {
2748        MUTATE_START( node );
2749
2750        indexerScopedMutate( node->env   , *this );
2751        indexerScopedMutate( node->result, *this );
2752        maybeMutate_impl   ( node->exprs , *this );
2753
2754        MUTATE_END( Expression, node );
2755}
2756
2757//--------------------------------------------------------------------------
2758// TupleIndexExpr
2759template< typename pass_type >
2760void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
2761        VISIT_START( node );
2762
2763        indexerScopedAccept( node->result, *this );
2764        maybeAccept_impl   ( node->tuple , *this );
2765
2766        VISIT_END( node );
2767}
2768
2769template< typename pass_type >
2770void PassVisitor< pass_type >::visit( const TupleIndexExpr * node ) {
2771        VISIT_START( node );
2772
2773        indexerScopedAccept( node->result, *this );
2774        maybeAccept_impl   ( node->tuple , *this );
2775
2776        VISIT_END( node );
2777}
2778
2779template< typename pass_type >
2780Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
2781        MUTATE_START( node );
2782
2783        indexerScopedMutate( node->env   , *this );
2784        indexerScopedMutate( node->result, *this );
2785        maybeMutate_impl   ( node->tuple , *this );
2786
2787        MUTATE_END( Expression, node );
2788}
2789
2790//--------------------------------------------------------------------------
2791// TupleAssignExpr
2792template< typename pass_type >
2793void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
2794        VISIT_START( node );
2795
2796        indexerScopedAccept( node->result  , *this );
2797        maybeAccept_impl   ( node->stmtExpr, *this );
2798
2799        VISIT_END( node );
2800}
2801
2802template< typename pass_type >
2803void PassVisitor< pass_type >::visit( const TupleAssignExpr * node ) {
2804        VISIT_START( node );
2805
2806        indexerScopedAccept( node->result  , *this );
2807        maybeAccept_impl( node->stmtExpr, *this );
2808
2809        VISIT_END( node );
2810}
2811
2812template< typename pass_type >
2813Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) {
2814        MUTATE_START( node );
2815
2816        indexerScopedMutate( node->env     , *this );
2817        indexerScopedMutate( node->result  , *this );
2818        maybeMutate_impl   ( node->stmtExpr, *this );
2819
2820        MUTATE_END( Expression, node );
2821}
2822
2823//--------------------------------------------------------------------------
2824// StmtExpr
2825template< typename pass_type >
2826void PassVisitor< pass_type >::visit( StmtExpr * node ) {
2827        VISIT_START( node );
2828
2829        // don't want statements from outer CompoundStmts to be added to this StmtExpr
2830        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
2831        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
2832        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
2833
2834        indexerScopedAccept( node->result     , *this );
2835        maybeAccept_impl   ( node->statements , *this );
2836        maybeAccept_impl   ( node->returnDecls, *this );
2837        maybeAccept_impl   ( node->dtors      , *this );
2838
2839        VISIT_END( node );
2840}
2841
2842template< typename pass_type >
2843void PassVisitor< pass_type >::visit( const StmtExpr * node ) {
2844        VISIT_START( node );
2845
2846        // don't want statements from outer CompoundStmts to be added to this StmtExpr
2847        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
2848        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
2849        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
2850
2851        indexerScopedAccept( node->result     , *this );
2852        maybeAccept_impl   ( node->statements , *this );
2853        maybeAccept_impl   ( node->returnDecls, *this );
2854        maybeAccept_impl   ( node->dtors      , *this );
2855
2856        VISIT_END( node );
2857}
2858
2859template< typename pass_type >
2860Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
2861        MUTATE_START( node );
2862
2863        // don't want statements from outer CompoundStmts to be added to this StmtExpr
2864        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
2865        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
2866        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
2867
2868        indexerScopedMutate( node->result     , *this );
2869        maybeMutate_impl   ( node->statements , *this );
2870        maybeMutate_impl   ( node->returnDecls, *this );
2871        maybeMutate_impl   ( node->dtors      , *this );
2872
2873        MUTATE_END( Expression, node );
2874}
2875
2876//--------------------------------------------------------------------------
2877// UniqueExpr
2878template< typename pass_type >
2879void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
2880        VISIT_START( node );
2881
2882        indexerScopedAccept( node->result, *this );
2883        maybeAccept_impl   ( node->expr  , *this );
2884
2885        VISIT_END( node );
2886}
2887
2888template< typename pass_type >
2889void PassVisitor< pass_type >::visit( const UniqueExpr * node ) {
2890        VISIT_START( node );
2891
2892        indexerScopedAccept( node->result, *this );
2893        maybeAccept_impl   ( node->expr  , *this );
2894
2895        VISIT_END( node );
2896}
2897
2898template< typename pass_type >
2899Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
2900        MUTATE_START( node );
2901
2902        indexerScopedMutate( node->env   , *this );
2903        indexerScopedMutate( node->result, *this );
2904        maybeMutate_impl   ( node->expr  , *this );
2905
2906        MUTATE_END( Expression, node );
2907}
2908
2909//--------------------------------------------------------------------------
2910// UntypedInitExpr
2911template< typename pass_type >
2912void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) {
2913        VISIT_START( node );
2914
2915        indexerScopedAccept( node->result, *this );
2916        maybeAccept_impl   ( node->expr  , *this );
2917        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
2918
2919        VISIT_END( node );
2920}
2921
2922template< typename pass_type >
2923void PassVisitor< pass_type >::visit( const UntypedInitExpr * node ) {
2924        VISIT_START( node );
2925
2926        indexerScopedAccept( node->result, *this );
2927        maybeAccept_impl   ( node->expr  , *this );
2928        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
2929
2930        VISIT_END( node );
2931}
2932
2933template< typename pass_type >
2934Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) {
2935        MUTATE_START( node );
2936
2937        indexerScopedMutate( node->env   , *this );
2938        indexerScopedMutate( node->result, *this );
2939        maybeMutate_impl   ( node->expr  , *this );
2940        // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
2941
2942        MUTATE_END( Expression, node );
2943}
2944
2945//--------------------------------------------------------------------------
2946// InitExpr
2947template< typename pass_type >
2948void PassVisitor< pass_type >::visit( InitExpr * node ) {
2949        VISIT_START( node );
2950
2951        indexerScopedAccept( node->result, *this );
2952        maybeAccept_impl   ( node->expr  , *this );
2953        maybeAccept_impl   ( node->designation, *this );
2954
2955        VISIT_END( node );
2956}
2957
2958template< typename pass_type >
2959void PassVisitor< pass_type >::visit( const InitExpr * node ) {
2960        VISIT_START( node );
2961
2962        indexerScopedAccept( node->result, *this );
2963        maybeAccept_impl   ( node->expr  , *this );
2964        maybeAccept_impl   ( node->designation, *this );
2965
2966        VISIT_END( node );
2967}
2968
2969template< typename pass_type >
2970Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) {
2971        MUTATE_START( node );
2972
2973        indexerScopedMutate( node->env   , *this );
2974        indexerScopedMutate( node->result, *this );
2975        maybeMutate_impl   ( node->expr  , *this );
2976        maybeMutate_impl   ( node->designation, *this );
2977
2978        MUTATE_END( Expression, node );
2979}
2980
2981//--------------------------------------------------------------------------
2982// DeletedExpr
2983template< typename pass_type >
2984void PassVisitor< pass_type >::visit( DeletedExpr * node ) {
2985        VISIT_START( node );
2986
2987        indexerScopedAccept( node->result, *this );
2988        maybeAccept_impl   ( node->expr, *this );
2989        // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
2990
2991        VISIT_END( node );
2992}
2993
2994template< typename pass_type >
2995void PassVisitor< pass_type >::visit( const DeletedExpr * node ) {
2996        VISIT_START( node );
2997
2998        indexerScopedAccept( node->result, *this );
2999        maybeAccept_impl   ( node->expr, *this );
3000        // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
3001
3002        VISIT_END( node );
3003}
3004
3005template< typename pass_type >
3006Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
3007        MUTATE_START( node );
3008
3009        indexerScopedMutate( node->env, *this );
3010        indexerScopedMutate( node->result, *this );
3011        maybeMutate_impl( node->expr, *this );
3012
3013        MUTATE_END( Expression, node );
3014}
3015
3016//--------------------------------------------------------------------------
3017// DefaultArgExpr
3018template< typename pass_type >
3019void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
3020        VISIT_START( node );
3021
3022        indexerScopedAccept( node->result, *this );
3023        maybeAccept_impl   ( node->expr, *this );
3024
3025        VISIT_END( node );
3026}
3027
3028template< typename pass_type >
3029void PassVisitor< pass_type >::visit( const DefaultArgExpr * node ) {
3030        VISIT_START( node );
3031
3032        indexerScopedAccept( node->result, *this );
3033        maybeAccept_impl   ( node->expr, *this );
3034
3035        VISIT_END( node );
3036}
3037
3038template< typename pass_type >
3039Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
3040        MUTATE_START( node );
3041
3042        indexerScopedMutate( node->env, *this );
3043        indexerScopedMutate( node->result, *this );
3044        maybeMutate_impl( node->expr, *this );
3045
3046        MUTATE_END( Expression, node );
3047}
3048
3049//--------------------------------------------------------------------------
3050// GenericExpr
3051template< typename pass_type >
3052void PassVisitor< pass_type >::visit( GenericExpr * node ) {
3053        VISIT_START( node );
3054
3055        indexerScopedAccept( node->result, *this );
3056        maybeAccept_impl( node->control, *this );
3057        for ( GenericExpr::Association & assoc : node->associations ) {
3058                indexerScopedAccept( assoc.type, *this );
3059                maybeAccept_impl( assoc.expr, *this );
3060        }
3061
3062        VISIT_END( node );
3063}
3064
3065template< typename pass_type >
3066void PassVisitor< pass_type >::visit( const GenericExpr * node ) {
3067        VISIT_START( node );
3068
3069        indexerScopedAccept( node->result, *this );
3070        maybeAccept_impl( node->control, *this );
3071        for ( const GenericExpr::Association & assoc : node->associations ) {
3072                indexerScopedAccept( assoc.type, *this );
3073                maybeAccept_impl( assoc.expr, *this );
3074        }
3075
3076        VISIT_END( node );
3077}
3078
3079template< typename pass_type >
3080Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) {
3081        MUTATE_START( node );
3082
3083        indexerScopedMutate( node->env, *this );
3084        indexerScopedMutate( node->result, *this );
3085        maybeMutate_impl( node->control, *this );
3086        for ( GenericExpr::Association & assoc : node->associations ) {
3087                indexerScopedMutate( assoc.type, *this );
3088                maybeMutate_impl( assoc.expr, *this );
3089        }
3090
3091        MUTATE_END( Expression, node );
3092}
3093
3094//--------------------------------------------------------------------------
3095// VoidType
3096template< typename pass_type >
3097void PassVisitor< pass_type >::visit( VoidType * node ) {
3098        VISIT_START( node );
3099
3100        maybeAccept_impl( node->forall, *this );
3101
3102        VISIT_END( node );
3103}
3104
3105template< typename pass_type >
3106void PassVisitor< pass_type >::visit( const VoidType * node ) {
3107        VISIT_START( node );
3108
3109        maybeAccept_impl( node->forall, *this );
3110
3111        VISIT_END( node );
3112}
3113
3114template< typename pass_type >
3115Type * PassVisitor< pass_type >::mutate( VoidType * node ) {
3116        MUTATE_START( node );
3117
3118        maybeMutate_impl( node->forall, *this );
3119
3120        MUTATE_END( Type, node );
3121}
3122
3123//--------------------------------------------------------------------------
3124// BasicType
3125template< typename pass_type >
3126void PassVisitor< pass_type >::visit( BasicType * node ) {
3127        VISIT_START( node );
3128
3129        maybeAccept_impl( node->forall, *this );
3130
3131        VISIT_END( node );
3132}
3133
3134template< typename pass_type >
3135void PassVisitor< pass_type >::visit( const BasicType * node ) {
3136        VISIT_START( node );
3137
3138        maybeAccept_impl( node->forall, *this );
3139
3140        VISIT_END( node );
3141}
3142
3143template< typename pass_type >
3144Type * PassVisitor< pass_type >::mutate( BasicType * node ) {
3145        MUTATE_START( node );
3146
3147        maybeMutate_impl( node->forall, *this );
3148
3149        MUTATE_END( Type, node );
3150}
3151
3152//--------------------------------------------------------------------------
3153// PointerType
3154template< typename pass_type >
3155void PassVisitor< pass_type >::visit( PointerType * node ) {
3156        VISIT_START( node );
3157
3158        maybeAccept_impl( node->forall, *this );
3159        // xxx - should PointerType visit/mutate dimension?
3160        maybeAccept_impl( node->base, *this );
3161
3162        VISIT_END( node );
3163}
3164
3165template< typename pass_type >
3166void PassVisitor< pass_type >::visit( const PointerType * node ) {
3167        VISIT_START( node );
3168
3169        maybeAccept_impl( node->forall, *this );
3170        // xxx - should PointerType visit/mutate dimension?
3171        maybeAccept_impl( node->base, *this );
3172
3173        VISIT_END( node );
3174}
3175
3176template< typename pass_type >
3177Type * PassVisitor< pass_type >::mutate( PointerType * node ) {
3178        MUTATE_START( node );
3179
3180        maybeMutate_impl( node->forall, *this );
3181        // xxx - should PointerType visit/mutate dimension?
3182        maybeMutate_impl( node->base, *this );
3183
3184        MUTATE_END( Type, node );
3185}
3186
3187//--------------------------------------------------------------------------
3188// ArrayType
3189template< typename pass_type >
3190void PassVisitor< pass_type >::visit( ArrayType * node ) {
3191        VISIT_START( node );
3192
3193        maybeAccept_impl( node->forall, *this );
3194        maybeAccept_impl( node->dimension, *this );
3195        maybeAccept_impl( node->base, *this );
3196
3197        VISIT_END( node );
3198}
3199
3200template< typename pass_type >
3201void PassVisitor< pass_type >::visit( const ArrayType * node ) {
3202        VISIT_START( node );
3203
3204        maybeAccept_impl( node->forall, *this );
3205        maybeAccept_impl( node->dimension, *this );
3206        maybeAccept_impl( node->base, *this );
3207
3208        VISIT_END( node );
3209}
3210
3211template< typename pass_type >
3212Type * PassVisitor< pass_type >::mutate( ArrayType * node ) {
3213        MUTATE_START( node );
3214
3215        maybeMutate_impl( node->forall, *this );
3216        maybeMutate_impl( node->dimension, *this );
3217        maybeMutate_impl( node->base, *this );
3218
3219        MUTATE_END( Type, node );
3220}
3221
3222//--------------------------------------------------------------------------
3223// ReferenceType
3224template< typename pass_type >
3225void PassVisitor< pass_type >::visit( ReferenceType * node ) {
3226        VISIT_START( node );
3227
3228        maybeAccept_impl( node->forall, *this );
3229        maybeAccept_impl( node->base, *this );
3230
3231        VISIT_END( node );
3232}
3233
3234template< typename pass_type >
3235void PassVisitor< pass_type >::visit( const ReferenceType * node ) {
3236        VISIT_START( node );
3237
3238        maybeAccept_impl( node->forall, *this );
3239        maybeAccept_impl( node->base, *this );
3240
3241        VISIT_END( node );
3242}
3243
3244template< typename pass_type >
3245Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) {
3246        MUTATE_START( node );
3247
3248        maybeMutate_impl( node->forall, *this );
3249        maybeMutate_impl( node->base, *this );
3250
3251        MUTATE_END( Type, node );
3252}
3253
3254//--------------------------------------------------------------------------
3255// QualifiedType
3256template< typename pass_type >
3257void PassVisitor< pass_type >::visit( QualifiedType * node ) {
3258        VISIT_START( node );
3259
3260        maybeAccept_impl( node->forall, *this );
3261        maybeAccept_impl( node->parent, *this );
3262        maybeAccept_impl( node->child, *this );
3263
3264        VISIT_END( node );
3265}
3266
3267template< typename pass_type >
3268void PassVisitor< pass_type >::visit( const QualifiedType * node ) {
3269        VISIT_START( node );
3270
3271        maybeAccept_impl( node->forall, *this );
3272        maybeAccept_impl( node->parent, *this );
3273        maybeAccept_impl( node->child, *this );
3274
3275        VISIT_END( node );
3276}
3277
3278template< typename pass_type >
3279Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) {
3280        MUTATE_START( node );
3281
3282        maybeMutate_impl( node->forall, *this );
3283        maybeMutate_impl( node->parent, *this );
3284        maybeMutate_impl( node->child, *this );
3285
3286        MUTATE_END( Type, node );
3287}
3288
3289//--------------------------------------------------------------------------
3290// FunctionType
3291template< typename pass_type >
3292void PassVisitor< pass_type >::visit( FunctionType * node ) {
3293        VISIT_START( node );
3294
3295        maybeAccept_impl( node->forall, *this );
3296        maybeAccept_impl( node->returnVals, *this );
3297        maybeAccept_impl( node->parameters, *this );
3298
3299        VISIT_END( node );
3300}
3301
3302template< typename pass_type >
3303void PassVisitor< pass_type >::visit( const FunctionType * node ) {
3304        VISIT_START( node );
3305
3306        maybeAccept_impl( node->forall, *this );
3307        maybeAccept_impl( node->returnVals, *this );
3308        maybeAccept_impl( node->parameters, *this );
3309
3310        VISIT_END( node );
3311}
3312
3313template< typename pass_type >
3314Type * PassVisitor< pass_type >::mutate( FunctionType * node ) {
3315        MUTATE_START( node );
3316
3317        maybeMutate_impl( node->forall, *this );
3318        maybeMutate_impl( node->returnVals, *this );
3319        maybeMutate_impl( node->parameters, *this );
3320
3321        MUTATE_END( Type, node );
3322}
3323
3324//--------------------------------------------------------------------------
3325// StructInstType
3326template< typename pass_type >
3327void PassVisitor< pass_type >::visit( StructInstType * node ) {
3328        VISIT_START( node );
3329
3330        indexerAddStruct( node->name );
3331
3332        {
3333                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3334                maybeAccept_impl( node->forall    , *this );
3335                maybeAccept_impl( node->parameters, *this );
3336        }
3337
3338        VISIT_END( node );
3339}
3340
3341template< typename pass_type >
3342void PassVisitor< pass_type >::visit( const StructInstType * node ) {
3343        VISIT_START( node );
3344
3345        indexerAddStruct( node->name );
3346
3347        {
3348                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3349                maybeAccept_impl( node->forall    , *this );
3350                maybeAccept_impl( node->parameters, *this );
3351        }
3352
3353        VISIT_END( node );
3354}
3355
3356template< typename pass_type >
3357Type * PassVisitor< pass_type >::mutate( StructInstType * node ) {
3358        MUTATE_START( node );
3359
3360        indexerAddStruct( node->name );
3361
3362        {
3363                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3364                maybeMutate_impl( node->forall    , *this );
3365                maybeMutate_impl( node->parameters, *this );
3366        }
3367
3368        MUTATE_END( Type, node );
3369}
3370
3371//--------------------------------------------------------------------------
3372// UnionInstType
3373template< typename pass_type >
3374void PassVisitor< pass_type >::visit( UnionInstType * node ) {
3375        VISIT_START( node );
3376
3377        indexerAddUnion( node->name );
3378
3379        {
3380                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3381                maybeAccept_impl( node->forall    , *this );
3382                maybeAccept_impl( node->parameters, *this );
3383        }
3384
3385        VISIT_END( node );
3386}
3387
3388template< typename pass_type >
3389void PassVisitor< pass_type >::visit( const UnionInstType * node ) {
3390        VISIT_START( node );
3391
3392        indexerAddUnion( node->name );
3393
3394        {
3395                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3396                maybeAccept_impl( node->forall    , *this );
3397                maybeAccept_impl( node->parameters, *this );
3398        }
3399
3400        VISIT_END( node );
3401}
3402
3403template< typename pass_type >
3404Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) {
3405        MUTATE_START( node );
3406
3407        indexerAddUnion( node->name );
3408
3409        {
3410                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
3411                maybeMutate_impl( node->forall    , *this );
3412                maybeMutate_impl( node->parameters, *this );
3413        }
3414
3415        MUTATE_END( Type, node );
3416}
3417
3418//--------------------------------------------------------------------------
3419// EnumInstType
3420template< typename pass_type >
3421void PassVisitor< pass_type >::visit( EnumInstType * node ) {
3422        VISIT_START( node );
3423
3424        maybeAccept_impl( node->forall, *this );
3425        maybeAccept_impl( node->parameters, *this );
3426
3427        VISIT_END( node );
3428}
3429
3430template< typename pass_type >
3431void PassVisitor< pass_type >::visit( const EnumInstType * node ) {
3432        VISIT_START( node );
3433
3434        maybeAccept_impl( node->forall, *this );
3435        maybeAccept_impl( node->parameters, *this );
3436
3437        VISIT_END( node );
3438}
3439
3440template< typename pass_type >
3441Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) {
3442        MUTATE_START( node );
3443
3444        maybeMutate_impl( node->forall, *this );
3445        maybeMutate_impl( node->parameters, *this );
3446
3447        MUTATE_END( Type, node );
3448}
3449
3450//--------------------------------------------------------------------------
3451// TraitInstType
3452template< typename pass_type >
3453void PassVisitor< pass_type >::visit( TraitInstType * node ) {
3454        VISIT_START( node );
3455
3456        maybeAccept_impl( node->forall    , *this );
3457        maybeAccept_impl( node->parameters, *this );
3458
3459        VISIT_END( node );
3460}
3461
3462template< typename pass_type >
3463void PassVisitor< pass_type >::visit( const TraitInstType * node ) {
3464        VISIT_START( node );
3465
3466        maybeAccept_impl( node->forall    , *this );
3467        maybeAccept_impl( node->parameters, *this );
3468
3469        VISIT_END( node );
3470}
3471
3472template< typename pass_type >
3473Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) {
3474        MUTATE_START( node );
3475
3476        maybeMutate_impl( node->forall    , *this );
3477        maybeMutate_impl( node->parameters, *this );
3478
3479        MUTATE_END( Type, node );
3480}
3481
3482//--------------------------------------------------------------------------
3483// TypeInstType
3484template< typename pass_type >
3485void PassVisitor< pass_type >::visit( TypeInstType * node ) {
3486        VISIT_START( node );
3487
3488        maybeAccept_impl( node->forall    , *this );
3489        maybeAccept_impl( node->parameters, *this );
3490
3491        VISIT_END( node );
3492}
3493
3494template< typename pass_type >
3495void PassVisitor< pass_type >::visit( const TypeInstType * node ) {
3496        VISIT_START( node );
3497
3498        maybeAccept_impl( node->forall    , *this );
3499        maybeAccept_impl( node->parameters, *this );
3500
3501        VISIT_END( node );
3502}
3503
3504template< typename pass_type >
3505Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) {
3506        MUTATE_START( node );
3507
3508        maybeMutate_impl( node->forall    , *this );
3509        maybeMutate_impl( node->parameters, *this );
3510
3511        MUTATE_END( Type, node );
3512}
3513
3514//--------------------------------------------------------------------------
3515// TupleType
3516template< typename pass_type >
3517void PassVisitor< pass_type >::visit( TupleType * node ) {
3518        VISIT_START( node );
3519
3520        maybeAccept_impl( node->forall, *this );
3521        maybeAccept_impl( node->types, *this );
3522        maybeAccept_impl( node->members, *this );
3523
3524        VISIT_END( node );
3525}
3526
3527template< typename pass_type >
3528void PassVisitor< pass_type >::visit( const TupleType * node ) {
3529        VISIT_START( node );
3530
3531        maybeAccept_impl( node->forall, *this );
3532        maybeAccept_impl( node->types, *this );
3533        maybeAccept_impl( node->members, *this );
3534
3535        VISIT_END( node );
3536}
3537
3538template< typename pass_type >
3539Type * PassVisitor< pass_type >::mutate( TupleType * node ) {
3540        MUTATE_START( node );
3541
3542        maybeMutate_impl( node->forall, *this );
3543        maybeMutate_impl( node->types, *this );
3544        maybeMutate_impl( node->members, *this );
3545
3546        MUTATE_END( Type, node );
3547}
3548
3549//--------------------------------------------------------------------------
3550// TypeofType
3551template< typename pass_type >
3552void PassVisitor< pass_type >::visit( TypeofType * node ) {
3553        VISIT_START( node );
3554
3555        assert( node->expr );
3556        maybeAccept_impl( node->expr, *this );
3557
3558        VISIT_END( node );
3559}
3560
3561template< typename pass_type >
3562void PassVisitor< pass_type >::visit( const TypeofType * node ) {
3563        VISIT_START( node );
3564
3565        assert( node->expr );
3566        maybeAccept_impl( node->expr, *this );
3567
3568        VISIT_END( node );
3569}
3570
3571template< typename pass_type >
3572Type * PassVisitor< pass_type >::mutate( TypeofType * node ) {
3573        MUTATE_START( node );
3574
3575        assert( node->expr );
3576        maybeMutate_impl( node->expr, *this );
3577
3578        MUTATE_END( Type, node );
3579}
3580
3581//--------------------------------------------------------------------------
3582// AttrType
3583template< typename pass_type >
3584void PassVisitor< pass_type >::visit( AttrType * node ) {
3585        VISIT_START( node );
3586
3587        if ( node->isType ) {
3588                assert( node->type );
3589                maybeAccept_impl( node->type, *this );
3590        } else {
3591                assert( node->expr );
3592                maybeAccept_impl( node->expr, *this );
3593        } // if
3594
3595        VISIT_END( node );
3596}
3597
3598template< typename pass_type >
3599void PassVisitor< pass_type >::visit( const AttrType * node ) {
3600        VISIT_START( node );
3601
3602        if ( node->isType ) {
3603                assert( node->type );
3604                maybeAccept_impl( node->type, *this );
3605        } else {
3606                assert( node->expr );
3607                maybeAccept_impl( node->expr, *this );
3608        } // if
3609
3610        VISIT_END( node );
3611}
3612
3613template< typename pass_type >
3614Type * PassVisitor< pass_type >::mutate( AttrType * node ) {
3615        MUTATE_START( node );
3616
3617        if ( node->isType ) {
3618                assert( node->type );
3619                maybeMutate_impl( node->type, *this );
3620        } else {
3621                assert( node->expr );
3622                maybeMutate_impl( node->expr, *this );
3623        } // if
3624
3625        MUTATE_END( Type, node );
3626}
3627
3628//--------------------------------------------------------------------------
3629// VarArgsType
3630template< typename pass_type >
3631void PassVisitor< pass_type >::visit( VarArgsType * node ) {
3632        VISIT_START( node );
3633
3634        maybeAccept_impl( node->forall, *this );
3635
3636        VISIT_END( node );
3637}
3638
3639template< typename pass_type >
3640void PassVisitor< pass_type >::visit( const VarArgsType * node ) {
3641        VISIT_START( node );
3642
3643        maybeAccept_impl( node->forall, *this );
3644
3645        VISIT_END( node );
3646}
3647
3648template< typename pass_type >
3649Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) {
3650        MUTATE_START( node );
3651
3652        maybeMutate_impl( node->forall, *this );
3653
3654        MUTATE_END( Type, node );
3655}
3656
3657//--------------------------------------------------------------------------
3658// ZeroType
3659template< typename pass_type >
3660void PassVisitor< pass_type >::visit( ZeroType * node ) {
3661        VISIT_START( node );
3662
3663        maybeAccept_impl( node->forall, *this );
3664
3665        VISIT_END( node );
3666}
3667
3668template< typename pass_type >
3669void PassVisitor< pass_type >::visit( const ZeroType * node ) {
3670        VISIT_START( node );
3671
3672        maybeAccept_impl( node->forall, *this );
3673
3674        VISIT_END( node );
3675}
3676
3677template< typename pass_type >
3678Type * PassVisitor< pass_type >::mutate( ZeroType * node ) {
3679        MUTATE_START( node );
3680
3681        maybeMutate_impl( node->forall, *this );
3682
3683        MUTATE_END( Type, node );
3684}
3685
3686//--------------------------------------------------------------------------
3687// OneType
3688template< typename pass_type >
3689void PassVisitor< pass_type >::visit( OneType * node ) {
3690        VISIT_START( node );
3691
3692        maybeAccept_impl( node->forall, *this );
3693
3694        VISIT_END( node );
3695}
3696
3697template< typename pass_type >
3698void PassVisitor< pass_type >::visit( const OneType * node ) {
3699        VISIT_START( node );
3700
3701        maybeAccept_impl( node->forall, *this );
3702
3703        VISIT_END( node );
3704}
3705
3706template< typename pass_type >
3707Type * PassVisitor< pass_type >::mutate( OneType * node ) {
3708        MUTATE_START( node );
3709
3710        maybeMutate_impl( node->forall, *this );
3711
3712        MUTATE_END( Type, node );
3713}
3714
3715//--------------------------------------------------------------------------
3716// GlobalScopeType
3717template< typename pass_type >
3718void PassVisitor< pass_type >::visit( GlobalScopeType * node ) {
3719        VISIT_START( node );
3720
3721        maybeAccept_impl( node->forall, *this );
3722
3723        VISIT_END( node );
3724}
3725
3726template< typename pass_type >
3727void PassVisitor< pass_type >::visit( const GlobalScopeType * node ) {
3728        VISIT_START( node );
3729
3730        maybeAccept_impl( node->forall, *this );
3731
3732        VISIT_END( node );
3733}
3734
3735template< typename pass_type >
3736Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) {
3737        MUTATE_START( node );
3738
3739        maybeMutate_impl( node->forall, *this );
3740
3741        MUTATE_END( Type, node );
3742}
3743
3744//--------------------------------------------------------------------------
3745// Designation
3746template< typename pass_type >
3747void PassVisitor< pass_type >::visit( Designation * node ) {
3748        VISIT_START( node );
3749
3750        maybeAccept_impl( node->designators, *this );
3751
3752        VISIT_END( node );
3753}
3754
3755template< typename pass_type >
3756void PassVisitor< pass_type >::visit( const Designation * node ) {
3757        VISIT_START( node );
3758
3759        maybeAccept_impl( node->designators, *this );
3760
3761        VISIT_END( node );
3762}
3763
3764template< typename pass_type >
3765Designation * PassVisitor< pass_type >::mutate( Designation * node ) {
3766        MUTATE_START( node );
3767
3768        maybeMutate_impl( node->designators, *this );
3769
3770        MUTATE_END( Designation, node );
3771}
3772
3773//--------------------------------------------------------------------------
3774// SingleInit
3775template< typename pass_type >
3776void PassVisitor< pass_type >::visit( SingleInit * node ) {
3777        VISIT_START( node );
3778
3779        visitExpression( node->value );
3780
3781        VISIT_END( node );
3782}
3783
3784template< typename pass_type >
3785void PassVisitor< pass_type >::visit( const SingleInit * node ) {
3786        VISIT_START( node );
3787
3788        visitExpression( node->value );
3789
3790        VISIT_END( node );
3791}
3792
3793template< typename pass_type >
3794Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
3795        MUTATE_START( node );
3796
3797        node->value = mutateExpression( node->value );
3798
3799        MUTATE_END( Initializer, node );
3800}
3801
3802//--------------------------------------------------------------------------
3803// ListInit
3804template< typename pass_type >
3805void PassVisitor< pass_type >::visit( ListInit * node ) {
3806        VISIT_START( node );
3807
3808        maybeAccept_impl( node->designations, *this );
3809        maybeAccept_impl( node->initializers, *this );
3810
3811        VISIT_END( node );
3812}
3813
3814template< typename pass_type >
3815void PassVisitor< pass_type >::visit( const ListInit * node ) {
3816        VISIT_START( node );
3817
3818        maybeAccept_impl( node->designations, *this );
3819        maybeAccept_impl( node->initializers, *this );
3820
3821        VISIT_END( node );
3822}
3823
3824template< typename pass_type >
3825Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) {
3826        MUTATE_START( node );
3827
3828        maybeMutate_impl( node->designations, *this );
3829        maybeMutate_impl( node->initializers, *this );
3830
3831        MUTATE_END( Initializer, node );
3832}
3833
3834//--------------------------------------------------------------------------
3835// ConstructorInit
3836template< typename pass_type >
3837void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
3838        VISIT_START( node );
3839
3840        maybeAccept_impl( node->ctor, *this );
3841        maybeAccept_impl( node->dtor, *this );
3842        maybeAccept_impl( node->init, *this );
3843
3844        VISIT_END( node );
3845}
3846
3847template< typename pass_type >
3848void PassVisitor< pass_type >::visit( const ConstructorInit * node ) {
3849        VISIT_START( node );
3850
3851        maybeAccept_impl( node->ctor, *this );
3852        maybeAccept_impl( node->dtor, *this );
3853        maybeAccept_impl( node->init, *this );
3854
3855        VISIT_END( node );
3856}
3857
3858template< typename pass_type >
3859Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) {
3860        MUTATE_START( node );
3861
3862        maybeMutate_impl( node->ctor, *this );
3863        maybeMutate_impl( node->dtor, *this );
3864        maybeMutate_impl( node->init, *this );
3865
3866        MUTATE_END( Initializer, node );
3867}
3868
3869//--------------------------------------------------------------------------
3870// Constant
3871template< typename pass_type >
3872void PassVisitor< pass_type >::visit( Constant * node ) {
3873        VISIT_START( node );
3874
3875        VISIT_END( node );
3876}
3877
3878template< typename pass_type >
3879void PassVisitor< pass_type >::visit( const Constant * node ) {
3880        VISIT_START( node );
3881
3882        VISIT_END( node );
3883}
3884
3885template< typename pass_type >
3886Constant * PassVisitor< pass_type >::mutate( Constant * node  )  {
3887        MUTATE_START( node );
3888
3889        MUTATE_END( Constant, node );
3890}
3891
3892//--------------------------------------------------------------------------
3893// Attribute
3894template< typename pass_type >
3895void PassVisitor< pass_type >::visit( Attribute * node ) {
3896        VISIT_START( node );
3897
3898        maybeAccept_impl( node->parameters, *this );
3899
3900        VISIT_END( node );
3901}
3902
3903template< typename pass_type >
3904void PassVisitor< pass_type >::visit( const Attribute * node ) {
3905        VISIT_START( node );
3906
3907        maybeAccept_impl( node->parameters, *this );
3908
3909        VISIT_END( node );
3910}
3911
3912template< typename pass_type >
3913Attribute * PassVisitor< pass_type >::mutate( Attribute * node  )  {
3914        MUTATE_START( node );
3915
3916        maybeMutate_impl( node->parameters, *this );
3917
3918        MUTATE_END( Attribute, node );
3919}
3920
3921//--------------------------------------------------------------------------
3922// TypeSubstitution
3923template< typename pass_type >
3924TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
3925        MUTATE_START( node );
3926
3927        for ( auto & p : node->typeEnv ) {
3928                indexerScopedMutate( p.second, *this );
3929        }
3930        for ( auto & p : node->varEnv ) {
3931                indexerScopedMutate( p.second, *this );
3932        }
3933
3934        MUTATE_END( TypeSubstitution, node );
3935}
3936
3937#undef VISIT_START
3938#undef VISIT_END
3939
3940#undef MUTATE_START
3941#undef MUTATE_END
Note: See TracBrowser for help on using the repository browser.