Changes in / [676cc8c:4a58895]


Ignore:
Location:
src
Files:
6 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r676cc8c r4a58895  
    11#pragma once
    2 
    3 #include <stack>
    42
    53#include "SynTree/Mutator.h"
     
    1311#include "SynTree/Constant.h"
    1412
    15 #include "PassVisitor.proto.h"
     13//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     14// Deep magic (a.k.a template meta programming) to make the templated visitor work
     15// Basically the goal is to make 2 previsit_impl
     16// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
     17//     'pass.previsit( node )' that compiles will be used for that node for that type
     18//     This requires that this option only compile for passes that actually define an appropriate visit.
     19//     SFINAE will make sure the compilation errors in this function don't halt the build.
     20//     See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE
     21// 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing.
     22//     This is needed only to eliminate the need for passes to specify any kind of handlers.
     23//     The second implementation only works because it has a lower priority. This is due to the bogus last parameter.
     24//     The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0
     25//     the first implementation takes priority in regards to overloading.
     26// Mutator functions work along the same principal
     27//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     28// Visit
     29template<typename pass_type, typename node_type>
     30static inline auto previsit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.previsit( node ), void() ) {
     31        pass.previsit( node );
     32}
     33
     34template<typename pass_type, typename node_type>
     35static inline void previsit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
     36
     37
     38template<typename pass_type, typename node_type>
     39static inline auto postvisit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postvisit( node ), void() ) {
     40        pass.postvisit( node );
     41}
     42
     43template<typename pass_type, typename node_type>
     44static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
     45
     46// Mutate
     47template<typename pass_type, typename node_type>
     48static inline auto premutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.premutate( node ), void() ) {
     49        return pass.premutate( node );
     50}
     51
     52template<typename pass_type, typename node_type>
     53static inline void premutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
     54
     55
     56template<typename return_type, typename pass_type, typename node_type>
     57static inline auto postmutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postmutate( node ) ) {
     58        return pass.postmutate( node );
     59}
     60
     61template<typename return_type, typename pass_type, typename node_type>
     62static inline return_type postmutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) { return node; }
    1663
    1764//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    209256
    210257private:
    211         template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); }
    212         template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); }
    213 
    214         template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); }
    215         template<typename return_type, typename node_type> return_type call_postmutate ( node_type * node ) { return postmutate_impl<return_type>( pass, node, 0 ); }
    216 
    217         void call_beginScope() { begin_scope_impl( pass, 0 ); }
    218         void call_endScope  () { end_scope_impl  ( pass, 0 ); }
    219 
    220         void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); }
    221 
    222         void visitStatementList( std::list< Statement* > &statements );
    223         void mutateStatementList( std::list< Statement* > &statements );
    224 
    225         Statement * visitStatement( Statement * stmt );
    226         Statement * mutateStatement( Statement * stmt );
    227 
    228         void visitExpression( Expression * expr );
    229         Expression * mutateExpression( Expression * expr );
    230 
    231 
    232         TypeSubstitution **             get_env_ptr    () { return env_impl             ( pass, 0); }
    233         std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    234         std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
     258        template<typename node_type>
     259        auto call_previsit ( node_type * node )
     260                -> decltype( previsit_impl ( pass, node, 0 ), void() )
     261        {
     262                previsit_impl ( pass, node, 0 );
     263        }
     264
     265        template<typename node_type>
     266        auto call_postvisit( node_type * node )
     267                -> decltype( postvisit_impl( pass, node, 0 ), void() )
     268        {
     269                postvisit_impl( pass, node, 0 );
     270        }
     271
     272        template<typename node_type>
     273        auto call_premutate ( node_type * node )
     274                -> decltype( premutate_impl( pass, node, 0 ), void() )
     275        {
     276                premutate_impl( pass, node, 0 );
     277        }
     278
     279        template<typename return_type, typename node_type>
     280        auto call_postmutate ( node_type * node )
     281                -> decltype( postmutate_impl<return_type>( pass, node, 0 ) )
     282        {
     283                return postmutate_impl<return_type>( pass, node, 0 );
     284        }
    235285};
    236286
  • src/Common/PassVisitor.impl.h

    r676cc8c r4a58895  
    11#pragma once
    2 
    3 #define MUTATE_START( node )  \
    4         call_premutate( node ); \
    5 
    6 
    7 #define MUTATE_END( type, node )                \
    8         return call_postmutate< type * >( node ); \
    9 
    102
    113#define VISIT_BODY( node )    \
     
    146        call_postvisit( node ); \
    157
    16 
    17 #define MUTATE_BODY( type, node ) \
    18         MUTATE_START( node );       \
    19         Mutator::mutate( node );    \
    20         MUTATE_END( type, node );   \
    21 
    22 
    23 
    24 template<typename T>
    25 static inline bool empty( T * ptr ) {
    26         return !ptr || ptr->empty();
    27 }
    28 
    29 typedef std::list< Statement * > StmtList_t;
    30 
    31 template< typename pass_type >
    32 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) {
    33         SemanticError errors;
    34 
    35         StmtList_t* beforeStmts = get_beforeStmts();
    36         StmtList_t* afterStmts  = get_afterStmts();
    37 
    38         for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    39                 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    40                 try {
    41                         *i = (*i)->accept( *this );
    42                 } catch ( SemanticError &e ) {
    43                         errors.append( e );
    44                 }
    45                 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    46         }
    47 
    48         if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
    49         if ( !errors.isEmpty() ) { throw errors; }
    50 }
    51 
    52 template< typename pass_type >
    53 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) {
    54         SemanticError errors;
    55 
    56         StmtList_t* beforeStmts = get_beforeStmts();
    57         StmtList_t* afterStmts  = get_afterStmts();
    58 
    59         for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    60                 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    61                 try {
    62                         *i = (*i)->acceptMutator( *this );
    63                 } catch ( SemanticError &e ) {
    64                         errors.append( e );
    65                 }
    66                 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    67         }
    68 
    69         if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); }
    70         if ( !errors.isEmpty() ) { throw errors; }
    71 }
    72 
    73 template< typename pass_type >
    74 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
    75         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    76         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    77         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    78         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    79 
    80         Statement *newStmt = maybeVisit( stmt, *this );
    81 
    82         StmtList_t* beforeStmts = get_beforeStmts();
    83         StmtList_t* afterStmts  = get_afterStmts();
    84 
    85         if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
    86 
    87         CompoundStmt *compound = new CompoundStmt( noLabels );
    88         if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    89         compound->get_kids().push_back( newStmt );
    90         if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    91         return compound;
    92 }
    93 
    94 template< typename pass_type >
    95 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) {
    96         // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    97         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    98         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    99         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    100 
    101         Statement *newStmt = maybeMutate( stmt, *this );
    102 
    103         StmtList_t* beforeStmts = get_beforeStmts();
    104         StmtList_t* afterStmts  = get_afterStmts();
    105 
    106         if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
    107 
    108         CompoundStmt *compound = new CompoundStmt( noLabels );
    109         if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    110         compound->get_kids().push_back( newStmt );
    111         if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    112         return compound;
    113 }
    114 
    115 
    116 
    117 template< typename pass_type >
    118 void PassVisitor< pass_type >::visitExpression( Expression * expr ) {
    119         if( !expr ) return;
    120 
    121         auto env_ptr = get_env_ptr();
    122         if ( env_ptr && expr->get_env() ) {
    123                 *env_ptr = expr->get_env();
    124         }
    125         // xxx - should env be cloned (or moved) onto the result of the mutate?
    126         expr->accept( *this );
    127 }
    128 
    129 template< typename pass_type >
    130 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) {
    131         if( !expr ) return nullptr;
    132 
    133         auto env_ptr = get_env_ptr();
    134         if ( env_ptr && expr->get_env() ) {
    135                 *env_ptr = expr->get_env();
    136         }
    137         // xxx - should env be cloned (or moved) onto the result of the mutate?
    138         return expr->acceptMutator( *this );
    139 }
    140 
    141 
    142 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     8#define MUTATE_BODY( type, node )                   \
     9        call_premutate( node );                       \
     10        Mutator::mutate( node );                      \
     11        auto ret = call_postmutate< type * >( node ); \
     12        return ret;                                   \
     13
     14
     15
    14316
    14417template< typename pass_type >
     
    19366
    19467template< typename pass_type >
    195 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
    196         MUTATE_START( node );
    197         call_beginScope();
    198 
    199         mutateStatementList( node->get_kids() );
    200 
    201         call_endScope();
    202         MUTATE_END( CompoundStmt, node );
    203 }
    204 
    205 template< typename pass_type >
    20668void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    20769        VISIT_BODY( node );
     
    20971
    21072template< typename pass_type >
    211 Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
    212         MUTATE_START( node );
    213 
    214         node->set_expr( mutateExpression( node->get_expr() ) );
    215 
    216         MUTATE_END( Statement, node );
    217 }
    218 
    219 template< typename pass_type >
    22073void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    22174        VISIT_BODY( node );
     
    22881
    22982template< typename pass_type >
    230 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    231         MUTATE_START( node );
    232 
    233         node->set_condition( mutateExpression( node->get_condition() ) );
    234         node->set_thenPart ( mutateStatement ( node->get_thenPart()  ) );
    235         node->set_elsePart ( mutateStatement ( node->get_elsePart()  ) );
    236 
    237         MUTATE_END( Statement, node );
    238 }
    239 
    240 template< typename pass_type >
    24183void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    24284        VISIT_BODY( node );
     
    24486
    24587template< typename pass_type >
    246 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
    247         MUTATE_START( node );
    248 
    249         node->set_condition( mutateExpression( node->get_condition() ) );
    250         node->set_body( mutateStatement( node->get_body() ) );
    251 
    252         MUTATE_END( Statement, node );
    253 }
    254 
    255 
    256 template< typename pass_type >
    25788void PassVisitor< pass_type >::visit( ForStmt * node ) {
    25889        VISIT_BODY( node );
     
    26091
    26192template< typename pass_type >
    262 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    263         MUTATE_START( node );
    264 
    265         mutateAll( node->get_initialization(), *this );
    266         node->set_condition(  mutateExpression( node->get_condition() ) );
    267         node->set_increment(  mutateExpression( node->get_increment() ) );
    268         node->set_body(  mutateStatement( node->get_body() ) );
    269 
    270         MUTATE_END( Statement, node );
    271 }
    272 
    273 template< typename pass_type >
    27493void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    27594        VISIT_BODY( node );
     
    27796
    27897template< typename pass_type >
    279 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    280         MUTATE_START( node );
    281        
    282         node->set_condition( mutateExpression( node->get_condition() ) );
    283         mutateStatementList( node->get_statements() );
    284        
    285         MUTATE_END( Statement, node );
    286 }
    287 
    288 template< typename pass_type >
    28998void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    29099        VISIT_BODY( node );
     
    292101
    293102template< typename pass_type >
    294 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    295         MUTATE_START( node );
    296        
    297         node->set_condition(  mutateExpression( node->get_condition() ) );
    298         mutateStatementList( node->get_statements() );
    299        
    300         MUTATE_END( Statement, node );
    301 }
    302 
    303 template< typename pass_type >
    304103void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    305104        VISIT_BODY( node );
     
    312111
    313112template< typename pass_type >
    314 Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
    315         MUTATE_START( node );
    316 
    317         node->set_expr( mutateExpression( node->get_expr() ) );
    318 
    319         MUTATE_END( Statement, node );
    320 }
    321 
    322 template< typename pass_type >
    323113void PassVisitor< pass_type >::visit( TryStmt * node ) {
    324114        VISIT_BODY( node );
     
    326116
    327117template< typename pass_type >
    328 Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
    329         MUTATE_START( node );
    330 
    331         node->set_block(  maybeMutate( node->get_block(), *this ) );
    332         mutateAll( node->get_catchers(), *this );
    333        
    334         MUTATE_END( Statement, node );
    335 }
    336 
    337 template< typename pass_type >
    338118void PassVisitor< pass_type >::visit( CatchStmt * node ) {
    339119        VISIT_BODY( node );
     
    341121
    342122template< typename pass_type >
    343 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    344         MUTATE_START( node );
    345        
    346         node->set_body(  mutateStatement( node->get_body() ) );
    347         node->set_decl(  maybeMutate( node->get_decl(), *this ) );
    348        
    349         MUTATE_END( Statement, node );
    350 }
    351 
    352 template< typename pass_type >
    353123void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
    354124        VISIT_BODY( node );
     
    381151
    382152template< typename pass_type >
    383 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
    384         MUTATE_START( node );
    385 
    386         for ( auto& expr : node->get_args() ) {
    387                 expr = mutateExpression( expr );
    388         }
    389 
    390         MUTATE_END( Expression, node );
    391 }
    392 
    393 template< typename pass_type >
    394153void PassVisitor< pass_type >::visit( NameExpr * node ) {
    395154        VISIT_BODY( node );
     
    542301
    543302template< typename pass_type >
    544 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    545         MUTATE_START( node );
    546        
    547         // don't want statements from outer CompoundStmts to be added to this StmtExpr
    548         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
    549         ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    550         ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    551 
    552         Mutator::mutate( node );
    553 
    554         MUTATE_END( Expression, node );
    555 }
    556 
    557 template< typename pass_type >
    558303void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
    559304        VISIT_BODY( node );
     
    643388void PassVisitor< pass_type >::visit( SingleInit * node ) {
    644389        VISIT_BODY( node );
    645 }
    646 
    647 template< typename pass_type >
    648 Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
    649         MUTATE_START( node );
    650 
    651         node->set_value( mutateExpression( node->get_value() ) );
    652 
    653         MUTATE_END( Initializer, node );
    654390}
    655391
     
    722458
    723459template< typename pass_type >
     460CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
     461        MUTATE_BODY( CompoundStmt, node );
     462}
     463
     464template< typename pass_type >
     465Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
     466        MUTATE_BODY( Statement, node );
     467}
     468
     469template< typename pass_type >
    724470Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    725471        MUTATE_BODY( Statement, node );
     
    727473
    728474template< typename pass_type >
     475Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
     476        MUTATE_BODY( Statement, node );
     477}
     478
     479template< typename pass_type >
     480Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
     481        MUTATE_BODY( Statement, node );
     482}
     483
     484template< typename pass_type >
     485Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
     486        MUTATE_BODY( Statement, node );
     487}
     488
     489template< typename pass_type >
     490Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
     491        MUTATE_BODY( Statement, node );
     492}
     493
     494template< typename pass_type >
     495Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
     496        MUTATE_BODY( Statement, node );
     497}
     498
     499template< typename pass_type >
    729500Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
     501        MUTATE_BODY( Statement, node );
     502}
     503
     504template< typename pass_type >
     505Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
     506        MUTATE_BODY( Statement, node );
     507}
     508
     509template< typename pass_type >
     510Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
     511        MUTATE_BODY( Statement, node );
     512}
     513
     514template< typename pass_type >
     515Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    730516        MUTATE_BODY( Statement, node );
    731517}
     
    757543
    758544template< typename pass_type >
     545Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
     546        MUTATE_BODY( Expression, node );
     547}
     548
     549template< typename pass_type >
    759550Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
    760551        MUTATE_BODY( Expression, node );
     
    902693
    903694template< typename pass_type >
     695Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
     696        MUTATE_BODY( Expression, node );
     697}
     698
     699template< typename pass_type >
    904700Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
    905701        MUTATE_BODY( Expression, node );
     
    984780Type * PassVisitor< pass_type >::mutate( OneType * node ) {
    985781        MUTATE_BODY( Type, node );
     782}
     783
     784template< typename pass_type >
     785Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
     786        MUTATE_BODY( Initializer, node );
    986787}
    987788
  • src/Common/utility.h

    r676cc8c r4a58895  
    244244        ValueGuard(T& inRef) : old(inRef), ref(inRef) {}
    245245        ~ValueGuard() { ref = old; }
    246 };
    247 
    248 template< typename T >
    249 struct ValueGuardPtr {
    250         T old;
    251         T* ref;
    252 
    253         ValueGuardPtr(T * inRef) : old( inRef ? *inRef : T() ), ref(inRef) {}
    254         ~ValueGuardPtr() { if( ref ) *ref = old; }
    255 };
    256 
    257 template< typename T >
    258 struct ValueGuardPtr< std::list< T > > {
    259         std::list< T > old;
    260         std::list< T >* ref;
    261 
    262         ValueGuardPtr( std::list< T > * inRef) : old(), ref(inRef) {
    263                 if( ref ) { swap( *ref, old ); }
    264         }
    265         ~ValueGuardPtr() { if( ref ) { swap( *ref, old ); } }
    266246};
    267247
  • src/InitTweak/FixInit.cc

    r676cc8c r4a58895  
    2020#include <unordered_map>
    2121#include <unordered_set>
    22 
    2322#include "InitTweak.h"
    2423#include "GenInit.h"
    2524#include "FixInit.h"
    2625#include "FixGlobalInit.h"
    27 #include "CodeGen/GenType.h"  // for warning/error messages
    28 #include "Common/PassVisitor.h"
    29 #include "GenPoly/DeclMutator.h"
    30 #include "GenPoly/PolyMutator.h"
    3126#include "ResolvExpr/Resolver.h"
    3227#include "ResolvExpr/typeops.h"
    33 #include "SymTab/Autogen.h"
    34 #include "SymTab/Indexer.h"
    35 #include "SynTree/AddStmtVisitor.h"
     28#include "SynTree/Declaration.h"
     29#include "SynTree/Type.h"
     30#include "SynTree/Expression.h"
    3631#include "SynTree/Attribute.h"
    37 #include "SynTree/Declaration.h"
    38 #include "SynTree/Expression.h"
     32#include "SynTree/Statement.h"
    3933#include "SynTree/Initializer.h"
    4034#include "SynTree/Mutator.h"
    41 #include "SynTree/Statement.h"
    42 #include "SynTree/Type.h"
     35#include "SymTab/Indexer.h"
     36#include "SymTab/Autogen.h"
     37#include "GenPoly/PolyMutator.h"
     38#include "GenPoly/DeclMutator.h"
     39#include "SynTree/AddStmtVisitor.h"
     40#include "CodeGen/GenType.h"  // for warning/error messages
    4341#include "Tuples/Tuples.h"
    4442
     
    5654                typedef std::unordered_map< int, int > UnqCount;
    5755
    58                 class InsertImplicitCalls {
     56                class InsertImplicitCalls final : public GenPoly::PolyMutator {
    5957                public:
    6058                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     
    6361
    6462                        InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {}
    65 
    66                         Expression * postmutate( ApplicationExpr * appExpr );
    67                         void premutate( StmtExpr * stmtExpr );
     63                        typedef GenPoly::PolyMutator Parent;
     64                        using Parent::mutate;
     65                        virtual Expression * mutate( ApplicationExpr * appExpr ) override;
     66                        virtual Expression * mutate( StmtExpr * stmtExpr ) override;
    6867
    6968                        // collects environments for relevant nodes
    7069                        EnvMap & envMap;
    71                         TypeSubstitution * env; //Magically populated by the PassVisitor
    7270                };
    7371
     
    302300        namespace {
    303301                void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) {
    304                         PassVisitor<InsertImplicitCalls> inserter( envMap );
     302                        InsertImplicitCalls inserter( envMap );
    305303                        mutateAll( translationUnit, inserter );
    306304                }
     
    352350                }
    353351
    354                 Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) {
     352                Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) {
     353                        appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) );
    355354                        assert( appExpr );
    356355
     
    394393                }
    395394
    396                 void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) {
     395                Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {
    397396                        assert( env );
    398397                        envMap[stmtExpr] = env;
     398                        return Parent::mutate( stmtExpr );
    399399                }
    400400
Note: See TracChangeset for help on using the changeset viewer.