Changeset 579263a for src/Common


Ignore:
Timestamp:
Jun 26, 2017, 4:48:35 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
bb1cd95
Parents:
e4d829b (diff), 2a7b3ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into designations

Conflicts:

src/InitTweak/FixInit.cc
src/SymTab/Autogen.h
src/SynTree/Initializer.cc
src/SynTree/Initializer.h
src/Tuples/TupleExpansion.cc

Location:
src/Common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    re4d829b r579263a  
    1212#include "SynTree/Expression.h"
    1313#include "SynTree/Constant.h"
     14#include "SynTree/TypeSubstitution.h"
    1415
    1516#include "PassVisitor.proto.h"
     
    1819// Templated visitor type
    1920// To use declare a PassVisitor< YOUR VISITOR TYPE >
    20 // The visitor type should specify the previsit/postvisit for types that are desired.
     21// The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired.
     22// Note: previsit/postvisit/premutate/postmutate must be **public** members
     23//
     24// Several additional features are available through inheritance
     25// | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression
     26// | WithStmtsToAdd       - provides the ability to insert statements before or after the current statement by adding new statements into
     27//                          stmtsToAddBefore or stmtsToAddAfter respectively.
     28// | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
     29// | WithGuards           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
     30//                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
    2131//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    2232template< typename pass_type >
    2333class PassVisitor final : public Visitor, public Mutator {
    2434public:
    25         PassVisitor() = default;
    2635
    2736        template< typename... Args >
    2837        PassVisitor(Args &&... args)
    2938                : pass( std::forward<Args>( args )... )
    30         {}
     39        {
     40                typedef PassVisitor<pass_type> this_t;
     41                this_t * const * visitor = visitor_impl(pass, 0);
     42                if(visitor) {
     43                        *const_cast<this_t **>( visitor ) = this;
     44                }
     45        }
    3146
    3247        virtual ~PassVisitor() = default;
     
    5469        virtual void visit( BranchStmt *branchStmt ) override final;
    5570        virtual void visit( ReturnStmt *returnStmt ) override final;
     71        virtual void visit( ThrowStmt *throwStmt ) override final;
    5672        virtual void visit( TryStmt *tryStmt ) override final;
    5773        virtual void visit( CatchStmt *catchStmt ) override final;
     
    85101        virtual void visit( ConstructorExpr * ctorExpr ) override final;
    86102        virtual void visit( CompoundLiteralExpr *compLitExpr ) override final;
    87         virtual void visit( UntypedValofExpr *valofExpr ) override final;
    88103        virtual void visit( RangeExpr *rangeExpr ) override final;
    89104        virtual void visit( UntypedTupleExpr *tupleExpr ) override final;
    90105        virtual void visit( TupleExpr *tupleExpr ) override final;
    91106        virtual void visit( TupleIndexExpr *tupleExpr ) override final;
    92         virtual void visit( MemberTupleExpr *tupleExpr ) override final;
    93107        virtual void visit( TupleAssignExpr *assignExpr ) override final;
    94108        virtual void visit( StmtExpr * stmtExpr ) override final;
     
    140154        virtual Statement* mutate( BranchStmt *branchStmt ) override final;
    141155        virtual Statement* mutate( ReturnStmt *returnStmt ) override final;
     156        virtual Statement* mutate( ThrowStmt *throwStmt ) override final;
    142157        virtual Statement* mutate( TryStmt *returnStmt ) override final;
    143158        virtual Statement* mutate( CatchStmt *catchStmt ) override final;
     
    171186        virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final;
    172187        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final;
    173         virtual Expression* mutate( UntypedValofExpr *valofExpr ) override final;
    174188        virtual Expression* mutate( RangeExpr *rangeExpr ) override final;
    175189        virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final;
    176190        virtual Expression* mutate( TupleExpr *tupleExpr ) override final;
    177191        virtual Expression* mutate( TupleIndexExpr *tupleExpr ) override final;
    178         virtual Expression* mutate( MemberTupleExpr *tupleExpr ) override final;
    179192        virtual Expression* mutate( TupleAssignExpr *assignExpr ) override final;
    180193        virtual Expression* mutate( StmtExpr * stmtExpr ) override final;
     
    207220
    208221private:
     222        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     223        template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
     224
    209225        template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); }
    210226        template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); }
     
    218234        void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); }
    219235
    220         void visitStatementList( std::list< Statement* > &statements );
     236        template< typename func_t >
     237        void handleStatementList( std::list< Statement * > & statements, func_t func );
     238        void visitStatementList ( std::list< Statement* > &statements );
    221239        void mutateStatementList( std::list< Statement* > &statements );
    222240
    223         Statement * visitStatement( Statement * stmt );
     241        template< typename func_t >
     242        Statement * handleStatement( Statement * stmt, func_t func );
     243        Statement * visitStatement ( Statement * stmt );
    224244        Statement * mutateStatement( Statement * stmt );
    225245
    226         void visitExpression( Expression * expr );
     246        template< typename func_t >
     247        Expression * handleExpression( Expression * expr, func_t func );
     248        Expression * visitExpression ( Expression * expr );
    227249        Expression * mutateExpression( Expression * expr );
    228250
     
    231253        std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    232254        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
    233         bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); }
     255        std::list< Declaration* > *     get_beforeDecls() { return declsToAddBefore_impl( pass, 0); }
     256        std::list< Declaration* > *     get_afterDecls () { return declsToAddAfter_impl ( pass, 0); }
     257
     258        void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
     259
     260        guard_value_impl init_guard() {
     261                guard_value_impl guard;
     262                auto at_cleanup = at_cleanup_impl(pass, 0);
     263                if( at_cleanup ) {
     264                        *at_cleanup = [&guard]( cleanup_func_t && func, void* val ) {
     265                                guard.push( std::move( func ), val );
     266                        };
     267                }
     268                return guard;
     269        }
     270};
     271
     272template<typename pass_type, typename T>
     273void GuardValue( pass_type * pass, T& val ) {
     274        pass->at_cleanup( [ val ]( void * newVal ) {
     275                * static_cast< T * >( newVal ) = val;
     276        }, static_cast< void * >( & val ) );
     277}
     278
     279class WithTypeSubstitution {
     280protected:
     281        WithTypeSubstitution() = default;
     282        ~WithTypeSubstitution() = default;
     283
     284public:
     285        TypeSubstitution * env = nullptr;
     286};
     287
     288class WithStmtsToAdd {
     289protected:
     290        WithStmtsToAdd() = default;
     291        ~WithStmtsToAdd() = default;
     292
     293public:
     294        std::list< Statement* > stmtsToAddBefore;
     295        std::list< Statement* > stmtsToAddAfter;
     296};
     297
     298class WithDeclsToAdd {
     299protected:
     300        WithDeclsToAdd() = default;
     301        ~WithDeclsToAdd() = default;
     302
     303public:
     304        std::list< Declaration* > declsToAddBefore;
     305        std::list< Declaration* > declsToAddAfter;
     306};
     307
     308class WithShortCircuiting {
     309protected:
     310        WithShortCircuiting() = default;
     311        ~WithShortCircuiting() = default;
     312
     313public:
     314        bool_ref visit_children;
     315};
     316
     317class WithGuards {
     318protected:
     319        WithGuards() = default;
     320        ~WithGuards() = default;
     321
     322public:
     323        at_cleanup_t at_cleanup;
     324
     325        template< typename T >
     326        void GuardValue( T& val ) {
     327                at_cleanup( [ val ]( void * newVal ) {
     328                        * static_cast< T * >( newVal ) = val;
     329                }, static_cast< void * >( & val ) );
     330        }
     331
     332        template< typename T >
     333        void GuardScope( T& val ) {
     334                val.beginScope();
     335                at_cleanup( []( void * val ) {
     336                        static_cast< T * >( val )->endScope();
     337                }, static_cast< void * >( & val ) );
     338        }
     339
     340        template< typename Func >
     341        void GuardAction( Func func ) {
     342                at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr );
     343        }
     344};
     345
     346template<typename pass_type>
     347class WithVisitorRef {
     348protected:
     349        WithVisitorRef() {}
     350        ~WithVisitorRef() {}
     351
     352public:
     353        PassVisitor<pass_type> * const visitor = nullptr;
    234354};
    235355
  • src/Common/PassVisitor.impl.h

    re4d829b r579263a  
    11#pragma once
    22
    3 #define VISIT_START( node )  \
    4         call_previsit( node ); \
    5         if( visit_children() ) { \
    6 
    7 #define VISIT_END( node )            \
    8         }                              \
    9         return call_postvisit( node ); \
    10 
    11 #define MUTATE_START( node )  \
    12         call_premutate( node ); \
    13         if( visit_children() ) { \
     3#define VISIT_START( node )                     \
     4        __attribute__((unused))                   \
     5        const auto & guard = init_guard();        \
     6        bool visit_children = true;               \
     7        set_visit_children( visit_children );   \
     8        call_previsit( node );                    \
     9        if( visit_children ) {                    \
     10
     11#define VISIT_END( node )                       \
     12        }                                         \
     13        call_postvisit( node );                   \
     14
     15#define MUTATE_START( node )                    \
     16        __attribute__((unused))                   \
     17        const auto & guard = init_guard();        \
     18        bool visit_children = true;               \
     19        set_visit_children( visit_children );   \
     20        call_premutate( node );                   \
     21        if( visit_children ) {                    \
    1422
    1523#define MUTATE_END( type, node )                \
     
    1826
    1927
    20 #define VISIT_BODY( node )    \
    21         VISIT_START( node );  \
    22         Visitor::visit( node ); \
    23         VISIT_END( node ); \
     28#define VISIT_BODY( node )        \
     29        VISIT_START( node );        \
     30        Visitor::visit( node );     \
     31        VISIT_END( node );          \
    2432
    2533
     
    3644}
    3745
    38 typedef std::list< Statement * > StmtList_t;
    39 
    40 template< typename pass_type >
    41 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
     46typedef std::list< Statement   * > StmtList_t;
     47typedef std::list< Declaration * > DeclList_t;
     48
     49template<typename iterator_t>
     50static inline void splice( iterator_t it, DeclList_t * decls ) {
     51        std::transform(
     52                decls->begin(),
     53                decls->end(),
     54                it,
     55                [](Declaration * decl) -> auto {
     56                        return new DeclStmt( noLabels, decl );
     57                }
     58        );
     59        decls->clear();
     60}
     61
     62template< typename pass_type >
     63static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {
     64
     65        DeclList_t* beforeDecls = visitor.get_beforeDecls();
     66        DeclList_t* afterDecls  = visitor.get_afterDecls();
     67
     68        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     69                // splice in new declarations after previous decl
     70                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     71
     72                if ( i == decls.end() ) break;
     73
     74                // run mutator on declaration
     75                maybeAccept( *i, visitor );
     76
     77                // splice in new declarations before current decl
     78                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
     79        }
     80}
     81
     82template< typename pass_type >
     83static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {
     84
     85        DeclList_t* beforeDecls = mutator.get_beforeDecls();
     86        DeclList_t* afterDecls  = mutator.get_afterDecls();
     87
     88        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     89                // splice in new declarations after previous decl
     90                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     91
     92                if ( i == decls.end() ) break;
     93
     94                // run mutator on declaration
     95                *i = maybeMutate( *i, mutator );
     96
     97                // splice in new declarations before current decl
     98                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
     99        }
     100}
     101
     102template< typename pass_type >
     103template< typename func_t >
     104void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
    42105        SemanticError errors;
     106
     107        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     108        ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() );
     109        ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () );
     110        ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() );
     111        ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () );
    43112
    44113        StmtList_t* beforeStmts = get_beforeStmts();
    45114        StmtList_t* afterStmts  = get_afterStmts();
     115        DeclList_t* beforeDecls = get_beforeDecls();
     116        DeclList_t* afterDecls  = get_afterDecls();
    46117
    47118        for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
     119
     120                if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); }
    48121                if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
     122
    49123                try {
    50                         (*i)->accept( *this );
     124                        func( *i );
     125                        assert(( empty( beforeStmts ) && empty( afterStmts ))
     126                            || ( empty( beforeDecls ) && empty( afterDecls )) );
     127
    51128                } catch ( SemanticError &e ) {
    52129                        errors.append( e );
    53130                }
     131
     132                if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); }
    54133                if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    55134        }
    56135
     136        if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
    57137        if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
    58138        if ( !errors.isEmpty() ) { throw errors; }
     
    60140
    61141template< typename pass_type >
     142void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
     143        handleStatementList( statements, [this]( Statement * stmt) {
     144                stmt->accept( *this );
     145        });
     146}
     147
     148template< typename pass_type >
    62149void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
    63         SemanticError errors;
     150        handleStatementList( statements, [this]( Statement *& stmt) {
     151                stmt = stmt->acceptMutator( *this );
     152        });
     153}
     154
     155
     156template< typename pass_type >
     157template< typename func_t >
     158Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) {
     159        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     160        ValueGuardPtr< TypeSubstitution * >  oldEnv        ( get_env_ptr    () );
     161        ValueGuardPtr< DeclList_t >          oldBeforeDecls( get_beforeDecls() );
     162        ValueGuardPtr< DeclList_t >          oldAfterDecls ( get_afterDecls () );
     163        ValueGuardPtr< StmtList_t >          oldBeforeStmts( get_beforeStmts() );
     164        ValueGuardPtr< StmtList_t >          oldAfterStmts ( get_afterStmts () );
     165
     166        Statement *newStmt = func( stmt );
    64167
    65168        StmtList_t* beforeStmts = get_beforeStmts();
    66169        StmtList_t* afterStmts  = get_afterStmts();
    67 
    68         for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    69                 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    70                 try {
    71                         *i = (*i)->acceptMutator( *this );
    72                 } catch ( SemanticError &e ) {
    73                         errors.append( e );
    74                 }
    75                 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    76         }
    77 
    78         if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
    79         if ( !errors.isEmpty() ) { throw errors; }
    80 }
    81 
    82 template< typename pass_type >
    83 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
    84         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    85         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    86         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    87         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    88 
    89         maybeAccept( stmt, *this );
    90 
    91         StmtList_t* beforeStmts = get_beforeStmts();
    92         StmtList_t* afterStmts  = get_afterStmts();
    93 
    94         if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }
     170        DeclList_t* beforeDecls = get_beforeDecls();
     171        DeclList_t* afterDecls  = get_afterDecls();
     172
     173        if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; }
     174        assert(( empty( beforeStmts ) && empty( afterStmts ))
     175            || ( empty( beforeDecls ) && empty( afterDecls )) );
    95176
    96177        CompoundStmt *compound = new CompoundStmt( noLabels );
     178        if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); }
    97179        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    98         compound->get_kids().push_back( stmt );
     180        compound->get_kids().push_back( newStmt );
     181        if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); }
    99182        if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    100183        return compound;
     
    102185
    103186template< typename pass_type >
     187Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
     188        return handleStatement( stmt, [this]( Statement * stmt ) {
     189                maybeAccept( stmt, *this );
     190                return stmt;
     191        });
     192}
     193
     194template< typename pass_type >
    104195Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
    105         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    106         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    107         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    108         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    109 
    110         Statement *newStmt = maybeMutate( stmt, *this );
    111 
    112         StmtList_t* beforeStmts = get_beforeStmts();
    113         StmtList_t* afterStmts  = get_afterStmts();
    114 
    115         if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
    116 
    117         CompoundStmt *compound = new CompoundStmt( noLabels );
    118         if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    119         compound->get_kids().push_back( newStmt );
    120         if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    121         return compound;
    122 }
    123 
    124 
    125 
    126 template< typename pass_type >
    127 void PassVisitor< pass_type >::visitExpression( Expression * expr ) {
    128         if( !expr ) return;
     196        return handleStatement( stmt, [this]( Statement * stmt ) {
     197                return maybeMutate( stmt, *this );
     198        });
     199}
     200
     201template< typename pass_type >
     202template< typename func_t >
     203Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) {
     204        if( !expr ) return nullptr;
    129205
    130206        auto env_ptr = get_env_ptr();
     
    132208                *env_ptr = expr->get_env();
    133209        }
    134         // xxx - should env be cloned (or moved) onto the result of the mutate?
    135         expr->accept( *this );
     210
     211        // should env be cloned (or moved) onto the result of the mutate?
     212        return func( expr );
     213}
     214
     215template< typename pass_type >
     216Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) {
     217        return handleExpression(expr, [this]( Expression * expr ) {
     218                expr->accept( *this );
     219                return expr;
     220        });
    136221}
    137222
    138223template< typename pass_type >
    139224Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
    140         if( !expr ) return nullptr;
    141 
    142         auto env_ptr = get_env_ptr();
    143         if ( env_ptr && expr->get_env() ) {
    144                 *env_ptr = expr->get_env();
    145         }
    146         // xxx - should env be cloned (or moved) onto the result of the mutate?
    147         return expr->acceptMutator( *this );
    148 }
    149 
     225        return handleExpression(expr, [this]( Expression * expr ) {
     226                return expr->acceptMutator( *this );
     227        });
     228}
    150229
    151230//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    153232template< typename pass_type >
    154233void PassVisitor< pass_type >::visit( ObjectDecl * node ) {
    155         VISIT_BODY( node ); 
     234        VISIT_BODY( node );
    156235}
    157236
    158237template< typename pass_type >
    159238void PassVisitor< pass_type >::visit( FunctionDecl * node ) {
    160         VISIT_BODY( node ); 
     239        VISIT_BODY( node );
    161240}
    162241
    163242template< typename pass_type >
    164243void PassVisitor< pass_type >::visit( StructDecl * node ) {
    165         VISIT_BODY( node ); 
     244        VISIT_BODY( node );
    166245}
    167246
    168247template< typename pass_type >
    169248void PassVisitor< pass_type >::visit( UnionDecl * node ) {
    170         VISIT_BODY( node ); 
     249        VISIT_BODY( node );
    171250}
    172251
    173252template< typename pass_type >
    174253void PassVisitor< pass_type >::visit( EnumDecl * node ) {
    175         VISIT_BODY( node ); 
     254        VISIT_BODY( node );
    176255}
    177256
    178257template< typename pass_type >
    179258void PassVisitor< pass_type >::visit( TraitDecl * node ) {
    180         VISIT_BODY( node ); 
     259        VISIT_BODY( node );
    181260}
    182261
    183262template< typename pass_type >
    184263void PassVisitor< pass_type >::visit( TypeDecl * node ) {
    185         VISIT_BODY( node ); 
     264        VISIT_BODY( node );
    186265}
    187266
    188267template< typename pass_type >
    189268void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
    190         VISIT_BODY( node ); 
     269        VISIT_BODY( node );
    191270}
    192271
    193272template< typename pass_type >
    194273void PassVisitor< pass_type >::visit( AsmDecl * node ) {
    195         VISIT_BODY( node ); 
     274        VISIT_BODY( node );
    196275}
    197276
     
    225304void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    226305        VISIT_START( node );
    227         call_beginScope();
    228306
    229307        visitExpression( node->get_expr() );
    230308
    231         call_endScope();
    232309        VISIT_END( node );
    233310}
     
    242319}
    243320
     321//--------------------------------------------------------------------------
     322// AsmStmt
    244323template< typename pass_type >
    245324void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    246         VISIT_BODY( node );
     325        VISIT_BODY( node );
     326}
     327
     328template< typename pass_type >
     329Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
     330        MUTATE_BODY( Statement, node );
    247331}
    248332
     
    251335template< typename pass_type >
    252336void PassVisitor< pass_type >::visit( IfStmt * node ) {
    253         VISIT_START( node ); 
     337        VISIT_START( node );
    254338
    255339        visitExpression( node->get_condition() );
     
    262346template< typename pass_type >
    263347Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    264         MUTATE_START( node ); 
     348        MUTATE_START( node );
    265349
    266350        node->set_condition( mutateExpression( node->get_condition() ) );
     
    275359template< typename pass_type >
    276360void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    277         VISIT_START( node ); 
     361        VISIT_START( node );
    278362
    279363        visitExpression( node->get_condition() );
     
    285369template< typename pass_type >
    286370Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
    287         MUTATE_START( node ); 
     371        MUTATE_START( node );
    288372
    289373        node->set_condition( mutateExpression( node->get_condition() ) );
     
    294378
    295379//--------------------------------------------------------------------------
    296 // WhileStmt
     380// ForStmt
    297381template< typename pass_type >
    298382void PassVisitor< pass_type >::visit( ForStmt * node ) {
    299         VISIT_START( node ); 
     383        VISIT_START( node );
    300384
    301385        acceptAll( node->get_initialization(), *this );
     
    309393template< typename pass_type >
    310394Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    311         MUTATE_START( node ); 
     395        MUTATE_START( node );
    312396
    313397        mutateAll( node->get_initialization(), *this );
     
    323407template< typename pass_type >
    324408void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    325         VISIT_START( node ); 
     409        VISIT_START( node );
    326410
    327411        visitExpression( node->get_condition() );
     
    333417template< typename pass_type >
    334418Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    335         MUTATE_START( node ); 
    336        
     419        MUTATE_START( node );
     420
    337421        node->set_condition( mutateExpression( node->get_condition() ) );
    338422        mutateStatementList( node->get_statements() );
    339        
     423
    340424        MUTATE_END( Statement, node );
    341425}
    342426
    343427//--------------------------------------------------------------------------
    344 // SwitchStmt
     428// CaseStmt
    345429template< typename pass_type >
    346430void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    347         VISIT_START( node ); 
    348        
     431        VISIT_START( node );
     432
    349433        visitExpression( node->get_condition() );
    350434        visitStatementList( node->get_statements() );
    351        
     435
    352436        VISIT_END( node );
    353437}
     
    355439template< typename pass_type >
    356440Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    357         MUTATE_START( node ); 
    358        
     441        MUTATE_START( node );
     442
    359443        node->set_condition(  mutateExpression( node->get_condition() ) );
    360444        mutateStatementList( node->get_statements() );
    361        
     445
    362446        MUTATE_END( Statement, node );
    363447}
    364448
     449//--------------------------------------------------------------------------
     450// BranchStmt
    365451template< typename pass_type >
    366452void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    367         VISIT_BODY( node );
     453        VISIT_BODY( node );
     454}
     455
     456template< typename pass_type >
     457Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
     458        MUTATE_BODY( Statement, node );
    368459}
    369460
     
    386477
    387478        MUTATE_END( Statement, node );
     479}
     480
     481//--------------------------------------------------------------------------
     482// ThrowStmt
     483
     484template< typename pass_type >
     485void PassVisitor< pass_type >::visit( ThrowStmt * node ) {
     486        VISIT_BODY( node );
     487}
     488
     489template< typename pass_type >
     490Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) {
     491        MUTATE_BODY( Statement, node );
    388492}
    389493
     
    396500        maybeAccept( node->get_block(), *this );
    397501        acceptAll( node->get_catchers(), *this );
     502        maybeAccept( node->get_finally(), *this );
    398503
    399504        VISIT_END( node );
     
    406511        node->set_block(  maybeMutate( node->get_block(), *this ) );
    407512        mutateAll( node->get_catchers(), *this );
    408        
     513        node->set_finally( maybeMutate( node->get_finally(), *this ) );
     514
    409515        MUTATE_END( Statement, node );
    410516}
     
    416522        VISIT_START( node );
    417523
     524        maybeAccept( node->get_decl(), *this );
     525        node->set_cond( visitExpression( node->get_cond() ) );
    418526        node->set_body( visitStatement( node->get_body() ) );
    419         maybeAccept( node->get_decl(), *this );
    420527
    421528        VISIT_END( node );
     
    425532Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    426533        MUTATE_START( node );
    427        
    428         node->set_body(  mutateStatement( node->get_body() ) );
    429         node->set_decl(  maybeMutate( node->get_decl(), *this ) );
    430        
     534
     535        node->set_decl( maybeMutate( node->get_decl(), *this ) );
     536        node->set_cond( mutateExpression( node->get_cond() ) );
     537        node->set_body( mutateStatement( node->get_body() ) );
     538
    431539        MUTATE_END( Statement, node );
    432540}
     
    434542template< typename pass_type >
    435543void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
    436         VISIT_BODY( node ); 
     544        VISIT_BODY( node );
    437545}
    438546
    439547template< typename pass_type >
    440548void PassVisitor< pass_type >::visit( NullStmt * node ) {
    441         VISIT_BODY( node ); 
     549        VISIT_BODY( node );
    442550}
    443551
    444552template< typename pass_type >
    445553void PassVisitor< pass_type >::visit( DeclStmt * node ) {
    446         VISIT_BODY( node ); 
     554        VISIT_BODY( node );
    447555}
    448556
    449557template< typename pass_type >
    450558void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
    451         VISIT_BODY( node ); 
     559        VISIT_BODY( node );
    452560}
    453561
    454562template< typename pass_type >
    455563void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
    456         VISIT_BODY( node ); 
     564        VISIT_BODY( node );
    457565}
    458566
     
    462570void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
    463571        VISIT_START( node );
     572
     573        // maybeAccept( node->get_env(), *this );
     574        maybeAccept( node->get_result(), *this );
    464575
    465576        for ( auto expr : node->get_args() ) {
     
    474585        MUTATE_START( node );
    475586
     587        node->set_env( maybeMutate( node->get_env(), *this ) );
     588        node->set_result( maybeMutate( node->get_result(), *this ) );
     589
    476590        for ( auto& expr : node->get_args() ) {
    477591                expr = mutateExpression( expr );
     
    483597template< typename pass_type >
    484598void PassVisitor< pass_type >::visit( NameExpr * node ) {
    485         VISIT_BODY( node ); 
     599        VISIT_BODY( node );
    486600}
    487601
    488602template< typename pass_type >
    489603void PassVisitor< pass_type >::visit( CastExpr * node ) {
    490         VISIT_BODY( node ); 
     604        VISIT_BODY( node );
    491605}
    492606
    493607template< typename pass_type >
    494608void PassVisitor< pass_type >::visit( AddressExpr * node ) {
    495         VISIT_BODY( node ); 
     609        VISIT_BODY( node );
    496610}
    497611
    498612template< typename pass_type >
    499613void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
    500         VISIT_BODY( node ); 
     614        VISIT_BODY( node );
    501615}
    502616
    503617template< typename pass_type >
    504618void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
    505         VISIT_BODY( node ); 
     619        VISIT_BODY( node );
    506620}
    507621
    508622template< typename pass_type >
    509623void PassVisitor< pass_type >::visit( MemberExpr * node ) {
    510         VISIT_BODY( node ); 
     624        VISIT_BODY( node );
    511625}
    512626
    513627template< typename pass_type >
    514628void PassVisitor< pass_type >::visit( VariableExpr * node ) {
    515         VISIT_BODY( node ); 
     629        VISIT_BODY( node );
    516630}
    517631
    518632template< typename pass_type >
    519633void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
    520         VISIT_BODY( node ); 
     634        VISIT_BODY( node );
    521635}
    522636
    523637template< typename pass_type >
    524638void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
    525         VISIT_BODY( node ); 
     639        VISIT_BODY( node );
    526640}
    527641
    528642template< typename pass_type >
    529643void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
    530         VISIT_BODY( node ); 
     644        VISIT_BODY( node );
    531645}
    532646
    533647template< typename pass_type >
    534648void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
    535         VISIT_BODY( node ); 
     649        VISIT_BODY( node );
    536650}
    537651
    538652template< typename pass_type >
    539653void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
    540         VISIT_BODY( node ); 
     654        VISIT_BODY( node );
    541655}
    542656
    543657template< typename pass_type >
    544658void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
    545         VISIT_BODY( node ); 
     659        VISIT_BODY( node );
    546660}
    547661
    548662template< typename pass_type >
    549663void PassVisitor< pass_type >::visit( AttrExpr * node ) {
    550         VISIT_BODY( node ); 
     664        VISIT_BODY( node );
    551665}
    552666
    553667template< typename pass_type >
    554668void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
    555         VISIT_BODY( node ); 
     669        VISIT_BODY( node );
    556670}
    557671
    558672template< typename pass_type >
    559673void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
    560         VISIT_BODY( node ); 
     674        VISIT_BODY( node );
    561675}
    562676
    563677template< typename pass_type >
    564678void PassVisitor< pass_type >::visit( CommaExpr * node ) {
    565         VISIT_BODY( node ); 
     679        VISIT_BODY( node );
    566680}
    567681
    568682template< typename pass_type >
    569683void PassVisitor< pass_type >::visit( TypeExpr * node ) {
    570         VISIT_BODY( node ); 
     684        VISIT_BODY( node );
    571685}
    572686
    573687template< typename pass_type >
    574688void PassVisitor< pass_type >::visit( AsmExpr * node ) {
    575         VISIT_BODY( node ); 
     689        VISIT_BODY( node );
    576690}
    577691
    578692template< typename pass_type >
    579693void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
    580         VISIT_BODY( node ); 
     694        VISIT_BODY( node );
    581695}
    582696
    583697template< typename pass_type >
    584698void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
    585         VISIT_BODY( node ); 
     699        VISIT_BODY( node );
    586700}
    587701
    588702template< typename pass_type >
    589703void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
    590         VISIT_BODY( node );
    591 }
    592 
    593 template< typename pass_type >
    594 void PassVisitor< pass_type >::visit( UntypedValofExpr * node ) {
    595         VISIT_BODY( node );
     704        VISIT_BODY( node );
    596705}
    597706
    598707template< typename pass_type >
    599708void PassVisitor< pass_type >::visit( RangeExpr * node ) {
    600         VISIT_BODY( node ); 
     709        VISIT_BODY( node );
    601710}
    602711
    603712template< typename pass_type >
    604713void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
    605         VISIT_BODY( node ); 
     714        VISIT_BODY( node );
    606715}
    607716
    608717template< typename pass_type >
    609718void PassVisitor< pass_type >::visit( TupleExpr * node ) {
    610         VISIT_BODY( node ); 
     719        VISIT_BODY( node );
    611720}
    612721
    613722template< typename pass_type >
    614723void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
    615         VISIT_BODY( node );
    616 }
    617 
    618 template< typename pass_type >
    619 void PassVisitor< pass_type >::visit( MemberTupleExpr * node ) {
    620         VISIT_BODY( node );
     724        VISIT_BODY( node );
    621725}
    622726
    623727template< typename pass_type >
    624728void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
    625         VISIT_BODY( node ); 
     729        VISIT_BODY( node );
    626730}
    627731
     
    645749Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    646750        MUTATE_START( node );
    647        
     751
    648752        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    649753        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     
    658762template< typename pass_type >
    659763void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
    660         VISIT_BODY( node ); 
     764        VISIT_BODY( node );
    661765}
    662766
    663767template< typename pass_type >
    664768void PassVisitor< pass_type >::visit( VoidType * node ) {
    665         VISIT_BODY( node ); 
     769        VISIT_BODY( node );
    666770}
    667771
    668772template< typename pass_type >
    669773void PassVisitor< pass_type >::visit( BasicType * node ) {
    670         VISIT_BODY( node ); 
     774        VISIT_BODY( node );
    671775}
    672776
    673777template< typename pass_type >
    674778void PassVisitor< pass_type >::visit( PointerType * node ) {
    675         VISIT_BODY( node ); 
     779        VISIT_BODY( node );
    676780}
    677781
    678782template< typename pass_type >
    679783void PassVisitor< pass_type >::visit( ArrayType * node ) {
    680         VISIT_BODY( node ); 
     784        VISIT_BODY( node );
    681785}
    682786
    683787template< typename pass_type >
    684788void PassVisitor< pass_type >::visit( FunctionType * node ) {
    685         VISIT_BODY( node ); 
     789        VISIT_BODY( node );
    686790}
    687791
    688792template< typename pass_type >
    689793void PassVisitor< pass_type >::visit( StructInstType * node ) {
    690         VISIT_BODY( node ); 
     794        VISIT_BODY( node );
    691795}
    692796
    693797template< typename pass_type >
    694798void PassVisitor< pass_type >::visit( UnionInstType * node ) {
    695         VISIT_BODY( node ); 
     799        VISIT_BODY( node );
    696800}
    697801
    698802template< typename pass_type >
    699803void PassVisitor< pass_type >::visit( EnumInstType * node ) {
    700         VISIT_BODY( node ); 
     804        VISIT_BODY( node );
    701805}
    702806
    703807template< typename pass_type >
    704808void PassVisitor< pass_type >::visit( TraitInstType * node ) {
    705         VISIT_BODY( node ); 
     809        VISIT_BODY( node );
    706810}
    707811
    708812template< typename pass_type >
    709813void PassVisitor< pass_type >::visit( TypeInstType * node ) {
    710         VISIT_BODY( node ); 
     814        VISIT_BODY( node );
    711815}
    712816
    713817template< typename pass_type >
    714818void PassVisitor< pass_type >::visit( TupleType * node ) {
    715         VISIT_BODY( node ); 
     819        VISIT_BODY( node );
    716820}
    717821
    718822template< typename pass_type >
    719823void PassVisitor< pass_type >::visit( TypeofType * node ) {
    720         VISIT_BODY( node ); 
     824        VISIT_BODY( node );
    721825}
    722826
    723827template< typename pass_type >
    724828void PassVisitor< pass_type >::visit( AttrType * node ) {
    725         VISIT_BODY( node ); 
     829        VISIT_BODY( node );
    726830}
    727831
    728832template< typename pass_type >
    729833void PassVisitor< pass_type >::visit( VarArgsType * node ) {
    730         VISIT_BODY( node ); 
     834        VISIT_BODY( node );
    731835}
    732836
    733837template< typename pass_type >
    734838void PassVisitor< pass_type >::visit( ZeroType * node ) {
    735         VISIT_BODY( node ); 
     839        VISIT_BODY( node );
    736840}
    737841
    738842template< typename pass_type >
    739843void PassVisitor< pass_type >::visit( OneType * node ) {
    740         VISIT_BODY( node ); 
     844        VISIT_BODY( node );
    741845}
    742846
     
    763867template< typename pass_type >
    764868void PassVisitor< pass_type >::visit( ListInit * node ) {
    765         VISIT_BODY( node ); 
     869        VISIT_BODY( node );
    766870}
    767871
    768872template< typename pass_type >
    769873void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
    770         VISIT_BODY( node ); 
     874        VISIT_BODY( node );
    771875}
    772876
    773877template< typename pass_type >
    774878void PassVisitor< pass_type >::visit( Subrange * node ) {
    775         VISIT_BODY( node ); 
     879        VISIT_BODY( node );
    776880}
    777881
    778882template< typename pass_type >
    779883void PassVisitor< pass_type >::visit( Constant * node ) {
    780         VISIT_BODY( node ); 
     884        VISIT_BODY( node );
    781885}
    782886
     
    829933
    830934template< typename pass_type >
    831 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    832         MUTATE_BODY( Statement, node );
    833 }
    834 
    835 template< typename pass_type >
    836 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
    837         MUTATE_BODY( Statement, node );
    838 }
    839 
    840 template< typename pass_type >
    841935Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    842936        MUTATE_BODY( Statement, node );
     
    9741068
    9751069template< typename pass_type >
    976 Expression * PassVisitor< pass_type >::mutate( UntypedValofExpr * node ) {
    977         MUTATE_BODY( Expression, node );
    978 }
    979 
    980 template< typename pass_type >
    9811070Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
    9821071        MUTATE_BODY( Expression, node );
     
    9951084template< typename pass_type >
    9961085Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) {
    997         MUTATE_BODY( Expression, node );
    998 }
    999 
    1000 template< typename pass_type >
    1001 Expression * PassVisitor< pass_type >::mutate( MemberTupleExpr * node ) {
    10021086        MUTATE_BODY( Expression, node );
    10031087}
  • src/Common/PassVisitor.proto.h

    re4d829b r579263a  
    11#pragma once
     2
     3template<typename pass_type>
     4class PassVisitor;
     5
     6typedef std::function<void( void * )> cleanup_func_t;
     7
     8class guard_value_impl {
     9public:
     10        guard_value_impl() = default;
     11
     12        ~guard_value_impl() {
     13                while( !cleanups.empty() ) {
     14                        auto& cleanup = cleanups.top();
     15                        cleanup.func( cleanup.val );
     16                        cleanups.pop();
     17                }
     18        }
     19
     20        void push( cleanup_func_t && func, void* val ) {
     21                cleanups.emplace( std::move(func), val );
     22        }
     23
     24private:
     25        struct cleanup_t {
     26                cleanup_func_t func;
     27                void * val;
     28
     29                cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {}
     30        };
     31
     32        std::stack< cleanup_t > cleanups;
     33};
     34
     35typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;
     36
     37class bool_ref {
     38public:
     39        bool_ref() = default;
     40        ~bool_ref() = default;
     41
     42        operator bool() { return *m_ref; }
     43        bool operator=( bool val ) { return *m_ref = val; }
     44
     45private:
     46
     47        template<typename pass>
     48        friend class PassVisitor;
     49
     50        void set( bool & val ) { m_ref = &val; };
     51
     52        bool * m_ref;
     53};
    254
    355//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    456// Deep magic (a.k.a template meta programming) to make the templated visitor work
    557// Basically the goal is to make 2 previsit_impl
    6 // 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of 
     58// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
    759//     'pass.previsit( node )' that compiles will be used for that node for that type
    860//     This requires that this option only compile for passes that actually define an appropriate visit.
     
    1870// Visit
    1971template<typename pass_type, typename node_type>
    20 static inline auto previsit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.previsit( node ), void() ) {
     72static inline auto previsit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.previsit( node ), void() ) {
    2173        pass.previsit( node );
    2274}
     
    2779
    2880template<typename pass_type, typename node_type>
    29 static inline auto postvisit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postvisit( node ), void() ) {
     81static inline auto postvisit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.postvisit( node ), void() ) {
    3082        pass.postvisit( node );
    3183}
     
    3688// Mutate
    3789template<typename pass_type, typename node_type>
    38 static inline auto premutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.premutate( node ), void() ) {
     90static inline auto premutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.premutate( node ), void() ) {
    3991        return pass.premutate( node );
    4092}
     
    4597
    4698template<typename return_type, typename pass_type, typename node_type>
    47 static inline auto postmutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postmutate( node ) ) {
     99static inline auto postmutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.postmutate( node ) ) {
    48100        return pass.postmutate( node );
    49101}
     
    54106// Begin/End scope
    55107template<typename pass_type>
    56 static inline auto begin_scope_impl( pass_type& pass, __attribute__((unused)) int unused ) ->decltype( pass.beginScope(), void() ) {
     108static inline auto begin_scope_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( pass.beginScope(), void() ) {
    57109        pass.beginScope();
    58110}
     
    63115
    64116template<typename pass_type>
    65 static inline auto end_scope_impl( pass_type& pass, __attribute__((unused)) int unused ) ->decltype( pass.endScope(), void() ) {
     117static inline auto end_scope_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( pass.endScope(), void() ) {
    66118        pass.endScope();
    67119}
     
    73125#define FIELD_PTR( type, name )                                                                                                        \
    74126template<typename pass_type>                                                                                                           \
    75 static inline auto name##_impl( pass_type& pass, __attribute__((unused)) int unused ) ->decltype( &pass.name ) { return &pass.name; } \
     127static inline auto name##_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( &pass.name ) { return &pass.name; } \
    76128                                                                                                                                       \
    77129template<typename pass_type>                                                                                                           \
     
    81133FIELD_PTR( std::list< Statement* >, stmtsToAddBefore )
    82134FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
    83 FIELD_PTR( bool, skip_children )
     135FIELD_PTR( std::list< Declaration* >, declsToAddBefore )
     136FIELD_PTR( std::list< Declaration* >, declsToAddAfter  )
     137FIELD_PTR( bool_ref, visit_children )
     138FIELD_PTR( at_cleanup_t, at_cleanup )
     139FIELD_PTR( PassVisitor<pass_type> * const, visitor )
Note: See TracChangeset for help on using the changeset viewer.