source: src/Common/PassVisitor.impl.h @ 7a37f25

new-envwith_gc
Last change on this file since 7a37f25 was 1cdfa82, checked in by Aaron Moss <a3moss@…>, 6 years ago

Merge remote-tracking branch 'origin/master' into with_gc

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