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

ADT
Last change on this file since fa2c005 was fa2c005, checked in by JiadaL <j82liang@…>, 12 months ago

Finish Adt POC

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