Changes in / [4a58895:676cc8c]


Ignore:
Location:
src
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r4a58895 r676cc8c  
    11#pragma once
     2
     3#include <stack>
    24
    35#include "SynTree/Mutator.h"
     
    1113#include "SynTree/Constant.h"
    1214
    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
    29 template<typename pass_type, typename node_type>
    30 static 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 
    34 template<typename pass_type, typename node_type>
    35 static inline void previsit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
    36 
    37 
    38 template<typename pass_type, typename node_type>
    39 static 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 
    43 template<typename pass_type, typename node_type>
    44 static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
    45 
    46 // Mutate
    47 template<typename pass_type, typename node_type>
    48 static 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 
    52 template<typename pass_type, typename node_type>
    53 static inline void premutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
    54 
    55 
    56 template<typename return_type, typename pass_type, typename node_type>
    57 static 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 
    61 template<typename return_type, typename pass_type, typename node_type>
    62 static inline return_type postmutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) { return node; }
     15#include "PassVisitor.proto.h"
    6316
    6417//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    256209
    257210private:
    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         }
     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); }
    285235};
    286236
  • src/Common/PassVisitor.impl.h

    r4a58895 r676cc8c  
    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
    210
    311#define VISIT_BODY( node )    \
     
    614        call_postvisit( node ); \
    715
    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 
     16
     17#define MUTATE_BODY( type, node ) \
     18        MUTATE_START( node );       \
     19        Mutator::mutate( node );    \
     20        MUTATE_END( type, node );   \
     21
     22
     23
     24template<typename T>
     25static inline bool empty( T * ptr ) {
     26        return !ptr || ptr->empty();
     27}
     28
     29typedef std::list< Statement * > StmtList_t;
     30
     31template< typename pass_type >
     32void 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
     52template< typename pass_type >
     53void 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
     73template< typename pass_type >
     74Statement * 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
     94template< typename pass_type >
     95Statement * 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
     117template< typename pass_type >
     118void 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
     129template< typename pass_type >
     130Expression * 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//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    16143
    17144template< typename pass_type >
     
    66193
    67194template< typename pass_type >
     195CompoundStmt * 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
     205template< typename pass_type >
    68206void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    69207        VISIT_BODY( node );
     
    71209
    72210template< typename pass_type >
     211Statement * 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
     219template< typename pass_type >
    73220void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    74221        VISIT_BODY( node );
     
    81228
    82229template< typename pass_type >
     230Statement * 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
     240template< typename pass_type >
    83241void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    84242        VISIT_BODY( node );
     
    86244
    87245template< typename pass_type >
     246Statement * 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
     256template< typename pass_type >
    88257void PassVisitor< pass_type >::visit( ForStmt * node ) {
    89258        VISIT_BODY( node );
     
    91260
    92261template< typename pass_type >
     262Statement * 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
     273template< typename pass_type >
    93274void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    94275        VISIT_BODY( node );
     
    96277
    97278template< typename pass_type >
     279Statement * 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
     288template< typename pass_type >
    98289void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    99290        VISIT_BODY( node );
     
    101292
    102293template< typename pass_type >
     294Statement * 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
     303template< typename pass_type >
    103304void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    104305        VISIT_BODY( node );
     
    111312
    112313template< typename pass_type >
     314Statement * 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
     322template< typename pass_type >
    113323void PassVisitor< pass_type >::visit( TryStmt * node ) {
    114324        VISIT_BODY( node );
     
    116326
    117327template< typename pass_type >
     328Statement * 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
     337template< typename pass_type >
    118338void PassVisitor< pass_type >::visit( CatchStmt * node ) {
    119339        VISIT_BODY( node );
     
    121341
    122342template< typename pass_type >
     343Statement * 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
     352template< typename pass_type >
    123353void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
    124354        VISIT_BODY( node );
     
    151381
    152382template< typename pass_type >
     383Expression * 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
     393template< typename pass_type >
    153394void PassVisitor< pass_type >::visit( NameExpr * node ) {
    154395        VISIT_BODY( node );
     
    301542
    302543template< typename pass_type >
     544Expression * 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
     557template< typename pass_type >
    303558void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
    304559        VISIT_BODY( node );
     
    388643void PassVisitor< pass_type >::visit( SingleInit * node ) {
    389644        VISIT_BODY( node );
     645}
     646
     647template< typename pass_type >
     648Initializer * 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 );
    390654}
    391655
     
    458722
    459723template< typename pass_type >
    460 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) {
    461         MUTATE_BODY( CompoundStmt, node );
    462 }
    463 
    464 template< typename pass_type >
    465 Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) {
    466         MUTATE_BODY( Statement, node );
    467 }
    468 
    469 template< typename pass_type >
    470724Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {
    471725        MUTATE_BODY( Statement, node );
     
    473727
    474728template< typename pass_type >
    475 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    476         MUTATE_BODY( Statement, node );
    477 }
    478 
    479 template< typename pass_type >
    480 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
    481         MUTATE_BODY( Statement, node );
    482 }
    483 
    484 template< typename pass_type >
    485 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    486         MUTATE_BODY( Statement, node );
    487 }
    488 
    489 template< typename pass_type >
    490 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    491         MUTATE_BODY( Statement, node );
    492 }
    493 
    494 template< typename pass_type >
    495 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    496         MUTATE_BODY( Statement, node );
    497 }
    498 
    499 template< typename pass_type >
    500729Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {
    501730        MUTATE_BODY( Statement, node );
     
    503732
    504733template< typename pass_type >
    505 Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) {
    506         MUTATE_BODY( Statement, node );
    507 }
    508 
    509 template< typename pass_type >
    510 Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) {
    511         MUTATE_BODY( Statement, node );
    512 }
    513 
    514 template< typename pass_type >
    515 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    516         MUTATE_BODY( Statement, node );
    517 }
    518 
    519 template< typename pass_type >
    520734Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) {
    521735        MUTATE_BODY( Statement, node );
     
    543757
    544758template< typename pass_type >
    545 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
    546         MUTATE_BODY( Expression, node );
    547 }
    548 
    549 template< typename pass_type >
    550759Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) {
    551760        MUTATE_BODY( Expression, node );
     
    693902
    694903template< typename pass_type >
    695 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    696         MUTATE_BODY( Expression, node );
    697 }
    698 
    699 template< typename pass_type >
    700904Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) {
    701905        MUTATE_BODY( Expression, node );
     
    780984Type * PassVisitor< pass_type >::mutate( OneType * node ) {
    781985        MUTATE_BODY( Type, node );
    782 }
    783 
    784 template< typename pass_type >
    785 Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) {
    786         MUTATE_BODY( Initializer, node );
    787986}
    788987
  • src/Common/utility.h

    r4a58895 r676cc8c  
    244244        ValueGuard(T& inRef) : old(inRef), ref(inRef) {}
    245245        ~ValueGuard() { ref = old; }
     246};
     247
     248template< typename T >
     249struct 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
     257template< typename T >
     258struct 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 ); } }
    246266};
    247267
  • src/InitTweak/FixInit.cc

    r4a58895 r676cc8c  
    2020#include <unordered_map>
    2121#include <unordered_set>
     22
    2223#include "InitTweak.h"
    2324#include "GenInit.h"
    2425#include "FixInit.h"
    2526#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"
    2631#include "ResolvExpr/Resolver.h"
    2732#include "ResolvExpr/typeops.h"
     33#include "SymTab/Autogen.h"
     34#include "SymTab/Indexer.h"
     35#include "SynTree/AddStmtVisitor.h"
     36#include "SynTree/Attribute.h"
    2837#include "SynTree/Declaration.h"
    29 #include "SynTree/Type.h"
    3038#include "SynTree/Expression.h"
    31 #include "SynTree/Attribute.h"
    32 #include "SynTree/Statement.h"
    3339#include "SynTree/Initializer.h"
    3440#include "SynTree/Mutator.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
     41#include "SynTree/Statement.h"
     42#include "SynTree/Type.h"
    4143#include "Tuples/Tuples.h"
    4244
     
    5456                typedef std::unordered_map< int, int > UnqCount;
    5557
    56                 class InsertImplicitCalls final : public GenPoly::PolyMutator {
     58                class InsertImplicitCalls {
    5759                public:
    5860                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     
    6163
    6264                        InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {}
    63                         typedef GenPoly::PolyMutator Parent;
    64                         using Parent::mutate;
    65                         virtual Expression * mutate( ApplicationExpr * appExpr ) override;
    66                         virtual Expression * mutate( StmtExpr * stmtExpr ) override;
     65
     66                        Expression * postmutate( ApplicationExpr * appExpr );
     67                        void premutate( StmtExpr * stmtExpr );
    6768
    6869                        // collects environments for relevant nodes
    6970                        EnvMap & envMap;
     71                        TypeSubstitution * env; //Magically populated by the PassVisitor
    7072                };
    7173
     
    300302        namespace {
    301303                void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) {
    302                         InsertImplicitCalls inserter( envMap );
     304                        PassVisitor<InsertImplicitCalls> inserter( envMap );
    303305                        mutateAll( translationUnit, inserter );
    304306                }
     
    350352                }
    351353
    352                 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) {
    353                         appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) );
     354                Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) {
    354355                        assert( appExpr );
    355356
     
    393394                }
    394395
    395                 Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {
     396                void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) {
    396397                        assert( env );
    397398                        envMap[stmtExpr] = env;
    398                         return Parent::mutate( stmtExpr );
    399399                }
    400400
Note: See TracChangeset for help on using the changeset viewer.