source: src/Common/PassVisitor.impl.h @ 28f3a19

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

Merge branch 'master' into with_gc

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