Changes in / [e9a3b20b:d56e5bc]


Ignore:
Location:
src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    re9a3b20b rd56e5bc  
    1818// Templated visitor type
    1919// To use declare a PassVisitor< YOUR VISITOR TYPE >
    20 // The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired.
    21 // Note: previsit/postvisit/premutate/postmutate must be **public** members
    22 //
    23 // Several additional features are available through inheritance
    24 // | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression
    25 // | WithStmtsToAdd       - provides the ability to insert statements before or after the current statement by adding new statements into
    26 //                          stmtsToAddBefore or stmtsToAddAfter respectively.
    27 // | WithShortCircuiting  - provides the ability to skip visiting child nodes; set skip_children to true if pre{visit,mutate} to skip visiting children
    28 // | WithScopes           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
    29 //                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
     20// The visitor type should specify the previsit/postvisit for types that are desired.
    3021//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    3122template< typename pass_type >
     
    9586        virtual void visit( ConstructorExpr * ctorExpr ) override final;
    9687        virtual void visit( CompoundLiteralExpr *compLitExpr ) override final;
     88        virtual void visit( UntypedValofExpr *valofExpr ) override final;
    9789        virtual void visit( RangeExpr *rangeExpr ) override final;
    9890        virtual void visit( UntypedTupleExpr *tupleExpr ) override final;
     
    180172        virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final;
    181173        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final;
     174        virtual Expression* mutate( UntypedValofExpr *valofExpr ) override final;
    182175        virtual Expression* mutate( RangeExpr *rangeExpr ) override final;
    183176        virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final;
  • src/Common/PassVisitor.impl.h

    re9a3b20b rd56e5bc  
    66        call_previsit( node );                    \
    77        if( visit_children() ) {                  \
     8                reset_visit();                      \
    89
    910#define VISIT_END( node )                       \
    1011        }                                         \
    11         reset_visit();                            \
    1212        call_postvisit( node );                   \
    1313
     
    1717        call_premutate( node );                   \
    1818        if( visit_children() ) {                  \
     19                reset_visit();                      \
    1920
    2021#define MUTATE_END( type, node )                \
    2122        }                                         \
    22         reset_visit();                            \
    2323        return call_postmutate< type * >( node ); \
    2424
     
    159159template< typename pass_type >
    160160void PassVisitor< pass_type >::visit( ObjectDecl * node ) {
    161         VISIT_BODY( node );
     161        VISIT_BODY( node ); 
    162162}
    163163
    164164template< typename pass_type >
    165165void PassVisitor< pass_type >::visit( FunctionDecl * node ) {
    166         VISIT_BODY( node );
     166        VISIT_BODY( node ); 
    167167}
    168168
    169169template< typename pass_type >
    170170void PassVisitor< pass_type >::visit( StructDecl * node ) {
    171         VISIT_BODY( node );
     171        VISIT_BODY( node ); 
    172172}
    173173
    174174template< typename pass_type >
    175175void PassVisitor< pass_type >::visit( UnionDecl * node ) {
    176         VISIT_BODY( node );
     176        VISIT_BODY( node ); 
    177177}
    178178
    179179template< typename pass_type >
    180180void PassVisitor< pass_type >::visit( EnumDecl * node ) {
    181         VISIT_BODY( node );
     181        VISIT_BODY( node ); 
    182182}
    183183
    184184template< typename pass_type >
    185185void PassVisitor< pass_type >::visit( TraitDecl * node ) {
    186         VISIT_BODY( node );
     186        VISIT_BODY( node ); 
    187187}
    188188
    189189template< typename pass_type >
    190190void PassVisitor< pass_type >::visit( TypeDecl * node ) {
    191         VISIT_BODY( node );
     191        VISIT_BODY( node ); 
    192192}
    193193
    194194template< typename pass_type >
    195195void PassVisitor< pass_type >::visit( TypedefDecl * node ) {
    196         VISIT_BODY( node );
     196        VISIT_BODY( node ); 
    197197}
    198198
    199199template< typename pass_type >
    200200void PassVisitor< pass_type >::visit( AsmDecl * node ) {
    201         VISIT_BODY( node );
     201        VISIT_BODY( node ); 
    202202}
    203203
     
    250250template< typename pass_type >
    251251void PassVisitor< pass_type >::visit( AsmStmt * node ) {
    252         VISIT_BODY( node );
     252        VISIT_BODY( node ); 
    253253}
    254254
     
    257257template< typename pass_type >
    258258void PassVisitor< pass_type >::visit( IfStmt * node ) {
    259         VISIT_START( node );
     259        VISIT_START( node ); 
    260260
    261261        visitExpression( node->get_condition() );
     
    268268template< typename pass_type >
    269269Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
    270         MUTATE_START( node );
     270        MUTATE_START( node ); 
    271271
    272272        node->set_condition( mutateExpression( node->get_condition() ) );
     
    281281template< typename pass_type >
    282282void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    283         VISIT_START( node );
     283        VISIT_START( node ); 
    284284
    285285        visitExpression( node->get_condition() );
     
    291291template< typename pass_type >
    292292Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) {
    293         MUTATE_START( node );
     293        MUTATE_START( node ); 
    294294
    295295        node->set_condition( mutateExpression( node->get_condition() ) );
     
    303303template< typename pass_type >
    304304void PassVisitor< pass_type >::visit( ForStmt * node ) {
    305         VISIT_START( node );
     305        VISIT_START( node ); 
    306306
    307307        acceptAll( node->get_initialization(), *this );
     
    315315template< typename pass_type >
    316316Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) {
    317         MUTATE_START( node );
     317        MUTATE_START( node ); 
    318318
    319319        mutateAll( node->get_initialization(), *this );
     
    329329template< typename pass_type >
    330330void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    331         VISIT_START( node );
     331        VISIT_START( node ); 
    332332
    333333        visitExpression( node->get_condition() );
     
    339339template< typename pass_type >
    340340Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) {
    341         MUTATE_START( node );
    342 
     341        MUTATE_START( node ); 
     342       
    343343        node->set_condition( mutateExpression( node->get_condition() ) );
    344344        mutateStatementList( node->get_statements() );
    345 
     345       
    346346        MUTATE_END( Statement, node );
    347347}
     
    351351template< typename pass_type >
    352352void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    353         VISIT_START( node );
    354 
     353        VISIT_START( node ); 
     354       
    355355        visitExpression( node->get_condition() );
    356356        visitStatementList( node->get_statements() );
    357 
     357       
    358358        VISIT_END( node );
    359359}
     
    361361template< typename pass_type >
    362362Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) {
    363         MUTATE_START( node );
    364 
     363        MUTATE_START( node ); 
     364       
    365365        node->set_condition(  mutateExpression( node->get_condition() ) );
    366366        mutateStatementList( node->get_statements() );
    367 
     367       
    368368        MUTATE_END( Statement, node );
    369369}
     
    371371template< typename pass_type >
    372372void PassVisitor< pass_type >::visit( BranchStmt * node ) {
    373         VISIT_BODY( node );
     373        VISIT_BODY( node ); 
    374374}
    375375
     
    425425        node->set_block(  maybeMutate( node->get_block(), *this ) );
    426426        mutateAll( node->get_catchers(), *this );
    427 
     427       
    428428        MUTATE_END( Statement, node );
    429429}
     
    444444Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) {
    445445        MUTATE_START( node );
    446 
     446       
    447447        node->set_body(  mutateStatement( node->get_body() ) );
    448448        node->set_decl(  maybeMutate( node->get_decl(), *this ) );
    449 
     449       
    450450        MUTATE_END( Statement, node );
    451451}
     
    453453template< typename pass_type >
    454454void PassVisitor< pass_type >::visit( FinallyStmt * node ) {
    455         VISIT_BODY( node );
     455        VISIT_BODY( node ); 
    456456}
    457457
    458458template< typename pass_type >
    459459void PassVisitor< pass_type >::visit( NullStmt * node ) {
    460         VISIT_BODY( node );
     460        VISIT_BODY( node ); 
    461461}
    462462
    463463template< typename pass_type >
    464464void PassVisitor< pass_type >::visit( DeclStmt * node ) {
    465         VISIT_BODY( node );
     465        VISIT_BODY( node ); 
    466466}
    467467
    468468template< typename pass_type >
    469469void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {
    470         VISIT_BODY( node );
     470        VISIT_BODY( node ); 
    471471}
    472472
    473473template< typename pass_type >
    474474void PassVisitor< pass_type >::visit( ApplicationExpr * node ) {
    475         VISIT_BODY( node );
     475        VISIT_BODY( node ); 
    476476}
    477477
     
    502502template< typename pass_type >
    503503void PassVisitor< pass_type >::visit( NameExpr * node ) {
    504         VISIT_BODY( node );
     504        VISIT_BODY( node ); 
    505505}
    506506
    507507template< typename pass_type >
    508508void PassVisitor< pass_type >::visit( CastExpr * node ) {
    509         VISIT_BODY( node );
     509        VISIT_BODY( node ); 
    510510}
    511511
    512512template< typename pass_type >
    513513void PassVisitor< pass_type >::visit( AddressExpr * node ) {
    514         VISIT_BODY( node );
     514        VISIT_BODY( node ); 
    515515}
    516516
    517517template< typename pass_type >
    518518void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) {
    519         VISIT_BODY( node );
     519        VISIT_BODY( node ); 
    520520}
    521521
    522522template< typename pass_type >
    523523void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) {
    524         VISIT_BODY( node );
     524        VISIT_BODY( node ); 
    525525}
    526526
    527527template< typename pass_type >
    528528void PassVisitor< pass_type >::visit( MemberExpr * node ) {
    529         VISIT_BODY( node );
     529        VISIT_BODY( node ); 
    530530}
    531531
    532532template< typename pass_type >
    533533void PassVisitor< pass_type >::visit( VariableExpr * node ) {
    534         VISIT_BODY( node );
     534        VISIT_BODY( node ); 
    535535}
    536536
    537537template< typename pass_type >
    538538void PassVisitor< pass_type >::visit( ConstantExpr * node ) {
    539         VISIT_BODY( node );
     539        VISIT_BODY( node ); 
    540540}
    541541
    542542template< typename pass_type >
    543543void PassVisitor< pass_type >::visit( SizeofExpr * node ) {
    544         VISIT_BODY( node );
     544        VISIT_BODY( node ); 
    545545}
    546546
    547547template< typename pass_type >
    548548void PassVisitor< pass_type >::visit( AlignofExpr * node ) {
    549         VISIT_BODY( node );
     549        VISIT_BODY( node ); 
    550550}
    551551
    552552template< typename pass_type >
    553553void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) {
    554         VISIT_BODY( node );
     554        VISIT_BODY( node ); 
    555555}
    556556
    557557template< typename pass_type >
    558558void PassVisitor< pass_type >::visit( OffsetofExpr * node ) {
    559         VISIT_BODY( node );
     559        VISIT_BODY( node ); 
    560560}
    561561
    562562template< typename pass_type >
    563563void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) {
    564         VISIT_BODY( node );
     564        VISIT_BODY( node ); 
    565565}
    566566
    567567template< typename pass_type >
    568568void PassVisitor< pass_type >::visit( AttrExpr * node ) {
    569         VISIT_BODY( node );
     569        VISIT_BODY( node ); 
    570570}
    571571
    572572template< typename pass_type >
    573573void PassVisitor< pass_type >::visit( LogicalExpr * node ) {
    574         VISIT_BODY( node );
     574        VISIT_BODY( node ); 
    575575}
    576576
    577577template< typename pass_type >
    578578void PassVisitor< pass_type >::visit( ConditionalExpr * node ) {
    579         VISIT_BODY( node );
     579        VISIT_BODY( node ); 
    580580}
    581581
    582582template< typename pass_type >
    583583void PassVisitor< pass_type >::visit( CommaExpr * node ) {
    584         VISIT_BODY( node );
     584        VISIT_BODY( node ); 
    585585}
    586586
    587587template< typename pass_type >
    588588void PassVisitor< pass_type >::visit( TypeExpr * node ) {
    589         VISIT_BODY( node );
     589        VISIT_BODY( node ); 
    590590}
    591591
    592592template< typename pass_type >
    593593void PassVisitor< pass_type >::visit( AsmExpr * node ) {
    594         VISIT_BODY( node );
     594        VISIT_BODY( node ); 
    595595}
    596596
    597597template< typename pass_type >
    598598void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) {
    599         VISIT_BODY( node );
     599        VISIT_BODY( node ); 
    600600}
    601601
    602602template< typename pass_type >
    603603void PassVisitor< pass_type >::visit( ConstructorExpr * node ) {
    604         VISIT_BODY( node );
     604        VISIT_BODY( node ); 
    605605}
    606606
    607607template< typename pass_type >
    608608void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) {
    609         VISIT_BODY( node );
     609        VISIT_BODY( node );
     610}
     611
     612template< typename pass_type >
     613void PassVisitor< pass_type >::visit( UntypedValofExpr * node ) {
     614        VISIT_BODY( node );
    610615}
    611616
    612617template< typename pass_type >
    613618void PassVisitor< pass_type >::visit( RangeExpr * node ) {
    614         VISIT_BODY( node );
     619        VISIT_BODY( node ); 
    615620}
    616621
    617622template< typename pass_type >
    618623void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) {
    619         VISIT_BODY( node );
     624        VISIT_BODY( node ); 
    620625}
    621626
    622627template< typename pass_type >
    623628void PassVisitor< pass_type >::visit( TupleExpr * node ) {
    624         VISIT_BODY( node );
     629        VISIT_BODY( node ); 
    625630}
    626631
    627632template< typename pass_type >
    628633void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) {
    629         VISIT_BODY( node );
     634        VISIT_BODY( node ); 
    630635}
    631636
    632637template< typename pass_type >
    633638void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) {
    634         VISIT_BODY( node );
     639        VISIT_BODY( node ); 
    635640}
    636641
     
    654659Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) {
    655660        MUTATE_START( node );
    656 
     661       
    657662        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    658663        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     
    667672template< typename pass_type >
    668673void PassVisitor< pass_type >::visit( UniqueExpr * node ) {
    669         VISIT_BODY( node );
     674        VISIT_BODY( node ); 
    670675}
    671676
    672677template< typename pass_type >
    673678void PassVisitor< pass_type >::visit( VoidType * node ) {
    674         VISIT_BODY( node );
     679        VISIT_BODY( node ); 
    675680}
    676681
    677682template< typename pass_type >
    678683void PassVisitor< pass_type >::visit( BasicType * node ) {
    679         VISIT_BODY( node );
     684        VISIT_BODY( node ); 
    680685}
    681686
    682687template< typename pass_type >
    683688void PassVisitor< pass_type >::visit( PointerType * node ) {
    684         VISIT_BODY( node );
     689        VISIT_BODY( node ); 
    685690}
    686691
    687692template< typename pass_type >
    688693void PassVisitor< pass_type >::visit( ArrayType * node ) {
    689         VISIT_BODY( node );
     694        VISIT_BODY( node ); 
    690695}
    691696
    692697template< typename pass_type >
    693698void PassVisitor< pass_type >::visit( FunctionType * node ) {
    694         VISIT_BODY( node );
     699        VISIT_BODY( node ); 
    695700}
    696701
    697702template< typename pass_type >
    698703void PassVisitor< pass_type >::visit( StructInstType * node ) {
    699         VISIT_BODY( node );
     704        VISIT_BODY( node ); 
    700705}
    701706
    702707template< typename pass_type >
    703708void PassVisitor< pass_type >::visit( UnionInstType * node ) {
    704         VISIT_BODY( node );
     709        VISIT_BODY( node ); 
    705710}
    706711
    707712template< typename pass_type >
    708713void PassVisitor< pass_type >::visit( EnumInstType * node ) {
    709         VISIT_BODY( node );
     714        VISIT_BODY( node ); 
    710715}
    711716
    712717template< typename pass_type >
    713718void PassVisitor< pass_type >::visit( TraitInstType * node ) {
    714         VISIT_BODY( node );
     719        VISIT_BODY( node ); 
    715720}
    716721
    717722template< typename pass_type >
    718723void PassVisitor< pass_type >::visit( TypeInstType * node ) {
    719         VISIT_BODY( node );
     724        VISIT_BODY( node ); 
    720725}
    721726
    722727template< typename pass_type >
    723728void PassVisitor< pass_type >::visit( TupleType * node ) {
    724         VISIT_BODY( node );
     729        VISIT_BODY( node ); 
    725730}
    726731
    727732template< typename pass_type >
    728733void PassVisitor< pass_type >::visit( TypeofType * node ) {
    729         VISIT_BODY( node );
     734        VISIT_BODY( node ); 
    730735}
    731736
    732737template< typename pass_type >
    733738void PassVisitor< pass_type >::visit( AttrType * node ) {
    734         VISIT_BODY( node );
     739        VISIT_BODY( node ); 
    735740}
    736741
    737742template< typename pass_type >
    738743void PassVisitor< pass_type >::visit( VarArgsType * node ) {
    739         VISIT_BODY( node );
     744        VISIT_BODY( node ); 
    740745}
    741746
    742747template< typename pass_type >
    743748void PassVisitor< pass_type >::visit( ZeroType * node ) {
    744         VISIT_BODY( node );
     749        VISIT_BODY( node ); 
    745750}
    746751
    747752template< typename pass_type >
    748753void PassVisitor< pass_type >::visit( OneType * node ) {
    749         VISIT_BODY( node );
     754        VISIT_BODY( node ); 
    750755}
    751756
     
    772777template< typename pass_type >
    773778void PassVisitor< pass_type >::visit( ListInit * node ) {
    774         VISIT_BODY( node );
     779        VISIT_BODY( node ); 
    775780}
    776781
    777782template< typename pass_type >
    778783void PassVisitor< pass_type >::visit( ConstructorInit * node ) {
    779         VISIT_BODY( node );
     784        VISIT_BODY( node ); 
    780785}
    781786
    782787template< typename pass_type >
    783788void PassVisitor< pass_type >::visit( Subrange * node ) {
    784         VISIT_BODY( node );
     789        VISIT_BODY( node ); 
    785790}
    786791
    787792template< typename pass_type >
    788793void PassVisitor< pass_type >::visit( Constant * node ) {
    789         VISIT_BODY( node );
     794        VISIT_BODY( node ); 
    790795}
    791796
     
    983988
    984989template< typename pass_type >
     990Expression * PassVisitor< pass_type >::mutate( UntypedValofExpr * node ) {
     991        MUTATE_BODY( Expression, node );
     992}
     993
     994template< typename pass_type >
    985995Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) {
    986996        MUTATE_BODY( Expression, node );
  • src/InitTweak/FixInit.cc

    re9a3b20b rd56e5bc  
    5656                typedef std::unordered_map< int, int > UnqCount;
    5757
    58                 class InsertImplicitCalls : public WithTypeSubstitution {
     58                class InsertImplicitCalls {
    5959                public:
    6060                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     
    6969                        // collects environments for relevant nodes
    7070                        EnvMap & envMap;
     71                        TypeSubstitution * env; //Magically populated by the PassVisitor
    7172                };
    7273
     
    191192                };
    192193
    193                 class FixInit : public WithStmtsToAdd {
     194                class FixInit {
    194195                  public:
    195196                        /// expand each object declaration to use its constructor after it is declared.
     
    199200
    200201                        std::list< Declaration * > staticDtorDecls;
     202                        std::list< Statement * > stmtsToAddAfter; // found by PassVisitor
    201203                };
    202204
  • src/Parser/ExpressionNode.cc

    re9a3b20b rd56e5bc  
    348348
    349349Expression *build_valexpr( StatementNode *s ) {
    350         return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
     350        return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr );
    351351}
    352352Expression *build_typevalue( DeclarationNode *decl ) {
  • src/Parser/ParseNode.h

    re9a3b20b rd56e5bc  
    415415                                result->location = cur->location;
    416416                                * out++ = result;
    417                         } else {
    418                                 assertf(false, "buildList unknown type");
    419417                        } // if
    420418                } catch( SemanticError &e ) {
  • src/Parser/StatementNode.cc

    re9a3b20b rd56e5bc  
    175175
    176176Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
    177         std::list< CatchStmt * > branches;
    178         buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches );
     177        std::list< Statement * > branches;
     178        buildMoveList< Statement, StatementNode >( catch_stmt, branches );
    179179        CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    180180        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
  • src/SymTab/Indexer.cc

    re9a3b20b rd56e5bc  
    493493                acceptNewScope( compLitExpr->get_result(), *this );
    494494                maybeAccept( compLitExpr->get_initializer(), *this );
     495        }
     496
     497        void Indexer::visit( UntypedValofExpr *valofExpr ) {
     498                acceptNewScope( valofExpr->get_result(), *this );
     499                maybeAccept( valofExpr->get_body(), *this );
    495500        }
    496501
  • src/SymTab/Indexer.h

    re9a3b20b rd56e5bc  
    6969                virtual void visit( ConstructorExpr * ctorExpr );
    7070                virtual void visit( CompoundLiteralExpr *compLitExpr );
     71                virtual void visit( UntypedValofExpr *valofExpr );
    7172                virtual void visit( RangeExpr *rangeExpr );
    7273                virtual void visit( UntypedTupleExpr *tupleExpr );
  • src/SymTab/Validate.cc

    re9a3b20b rd56e5bc  
    115115
    116116        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    117         class EnumAndPointerDecay {
    118         public:
    119                 void previsit( EnumDecl *aggregateDecl );
    120                 void previsit( FunctionType *func );
     117        class EnumAndPointerDecayPass final : public Visitor {
     118                typedef Visitor Parent;
     119                virtual void visit( EnumDecl *aggregateDecl );
     120                virtual void visit( FunctionType *func );
    121121        };
    122122
     
    126126          public:
    127127                LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
     128          private:
    128129                using Parent::visit;
    129130                void visit( EnumInstType *enumInst ) final;
     
    135136                void visit( UnionDecl *unionDecl ) final;
    136137                void visit( TypeInstType *typeInst ) final;
    137           private:
     138
    138139                const Indexer *indexer;
    139140
     
    146147        };
    147148
    148         /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
    149         class ForallPointerDecay final : public Indexer {
     149        /// Replaces array and function types in forall lists by appropriate pointer type
     150        class Pass3 final : public Indexer {
    150151                typedef Indexer Parent;
    151152          public:
    152153                using Parent::visit;
    153                 ForallPointerDecay( const Indexer *indexer );
    154 
     154                Pass3( const Indexer *indexer );
     155          private:
    155156                virtual void visit( ObjectDecl *object ) override;
    156157                virtual void visit( FunctionDecl *func ) override;
     
    159160        };
    160161
    161         class ReturnChecker : public WithScopes {
     162        class ReturnChecker {
    162163          public:
    163164                /// Checks that return statements return nothing if their return type is void
     
    166167          private:
    167168                void previsit( FunctionDecl * functionDecl );
     169                void postvisit( FunctionDecl * functionDecl );
    168170                void previsit( ReturnStmt * returnStmt );
    169171
    170172                typedef std::list< DeclarationWithType * > ReturnVals;
    171173                ReturnVals returnVals;
     174                std::stack< ReturnVals > returnValsStack;
    172175        };
    173176
     
    245248
    246249        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    247                 PassVisitor<EnumAndPointerDecay> epc;
     250                EnumAndPointerDecayPass epc;
    248251                LinkReferenceToTypes lrt( doDebug, 0 );
    249                 ForallPointerDecay fpd( 0 );
     252                Pass3 pass3( 0 );
    250253                CompoundLiteral compoundliteral;
    251254                PassVisitor<ValidateGenericParameters> genericParams;
     
    259262                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    260263                Concurrency::applyKeywords( translationUnit );
    261                 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
     264                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
    262265                Concurrency::implementMutexFuncs( translationUnit );
    263266                Concurrency::implementThreadStarter( translationUnit );
    264267                ReturnChecker::checkFunctionReturns( translationUnit );
    265268                compoundliteral.mutateDeclarationList( translationUnit );
    266                 acceptAll( translationUnit, fpd );
     269                acceptAll( translationUnit, pass3 );
    267270                ArrayLength::computeLength( translationUnit );
    268271        }
    269272
    270273        void validateType( Type *type, const Indexer *indexer ) {
    271                 PassVisitor<EnumAndPointerDecay> epc;
     274                EnumAndPointerDecayPass epc;
    272275                LinkReferenceToTypes lrt( false, indexer );
    273                 ForallPointerDecay fpd( indexer );
     276                Pass3 pass3( indexer );
    274277                type->accept( epc );
    275278                type->accept( lrt );
    276                 type->accept( fpd );
     279                type->accept( pass3 );
    277280        }
    278281
     
    353356        }
    354357
    355         void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) {
     358        void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) {
    356359                // Set the type of each member of the enumeration to be EnumConstant
    357360                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     
    360363                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
    361364                } // for
     365                Parent::visit( enumDecl );
    362366        }
    363367
     
    366370                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
    367371                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
    368                         // entirely. other fix ups are handled by the FixFunction class
     372                        // entirely other fix ups are handled by the FixFunction class
    369373                        typedef typename DWTList::iterator DWTIterator;
    370374                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
     
    385389                                for ( ; i != end; ++i ) {
    386390                                        FixFunction fixer;
    387                                         *i = (*i)->acceptMutator( fixer );
     391                                        *i = (*i )->acceptMutator( fixer );
    388392                                        if ( fixer.get_isVoid() ) {
    389393                                                throw SemanticError( "invalid type void in function type ", func );
     
    394398        }
    395399
    396         void EnumAndPointerDecay::previsit( FunctionType *func ) {
     400        void EnumAndPointerDecayPass::visit( FunctionType *func ) {
    397401                // Fix up parameters and return types
    398402                fixFunctionList( func->get_parameters(), func );
    399403                fixFunctionList( func->get_returnVals(), func );
     404                Visitor::visit( func );
    400405        }
    401406
     
    544549        }
    545550
    546         ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) :  Indexer( false ) {
     551        Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
    547552                if ( other_indexer ) {
    548553                        indexer = other_indexer;
     
    582587        }
    583588
    584         void ForallPointerDecay::visit( ObjectDecl *object ) {
     589        void Pass3::visit( ObjectDecl *object ) {
    585590                forallFixer( object->get_type() );
    586591                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     
    591596        }
    592597
    593         void ForallPointerDecay::visit( FunctionDecl *func ) {
     598        void Pass3::visit( FunctionDecl *func ) {
    594599                forallFixer( func->get_type() );
    595600                Parent::visit( func );
     
    603608
    604609        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
    605                 GuardValue( returnVals );
     610                returnValsStack.push( returnVals );
    606611                returnVals = functionDecl->get_functionType()->get_returnVals();
     612        }
     613        void ReturnChecker::postvisit( __attribute__((unused)) FunctionDecl * functionDecl ) {
     614                returnVals = returnValsStack.top();
     615                returnValsStack.pop();
    607616        }
    608617
  • src/SynTree/BaseSyntaxNode.h

    re9a3b20b rd56e5bc  
    2424        CodeLocation location;
    2525
    26         virtual ~BaseSyntaxNode() {}
    27 
    28         virtual void accept( Visitor & v ) = 0;
     26        virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast
    2927};
    3028
  • src/SynTree/Expression.cc

    re9a3b20b rd56e5bc  
    288288}
    289289
     290// CastExpr *CastExpr::clone() const { return 0; }
     291
    290292void CastExpr::print( std::ostream &os, int indent ) const {
    291293        os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
     
    353355}
    354356
     357//// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
    355358MemberExpr::MemberExpr( const MemberExpr &other ) :
    356359                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
     
    358361
    359362MemberExpr::~MemberExpr() {
    360         // don't delete the member declaration, since it points somewhere else in the tree
     363        // delete member;
    361364        delete aggregate;
    362365}
     
    588591}
    589592
     593UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
     594
     595UntypedValofExpr::~UntypedValofExpr() { delete body; }
     596
     597void UntypedValofExpr::print( std::ostream &os, int indent ) const {
     598        os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
     599        if ( get_body() != 0 )
     600                get_body()->print( os, indent + 2 );
     601}
     602
    590603RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
    591604RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
  • src/SynTree/Expression.h

    re9a3b20b rd56e5bc  
    226226};
    227227
    228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer.
    229 /// Does not take ownership of member.
     228/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
    230229class MemberExpr : public Expression {
    231230  public:
     
    248247};
    249248
    250 /// VariableExpr represents an expression that simply refers to the value of a named variable.
    251 /// Does not take ownership of var.
     249/// VariableExpr represents an expression that simply refers to the value of a named variable
    252250class VariableExpr : public Expression {
    253251  public:
     
    600598};
    601599
     600/// ValofExpr represents a GCC 'lambda expression'
     601class UntypedValofExpr : public Expression {
     602  public:
     603        UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}
     604        UntypedValofExpr( const UntypedValofExpr & other );
     605        virtual ~UntypedValofExpr();
     606
     607        Expression * get_value();
     608        Statement * get_body() const { return body; }
     609
     610        virtual UntypedValofExpr * clone() const { return new UntypedValofExpr( * this ); }
     611        virtual void accept( Visitor & v ) { v.visit( this ); }
     612        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     613        virtual void print( std::ostream & os, int indent = 0 ) const;
     614  private:
     615        Statement * body;
     616};
     617
    602618/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
    603619class RangeExpr : public Expression {
  • src/SynTree/Mutator.cc

    re9a3b20b rd56e5bc  
    380380}
    381381
     382Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
     383        valofExpr->set_env( maybeMutate( valofExpr->get_env(), *this ) );
     384        valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) );
     385        return valofExpr;
     386}
     387
    382388Expression *Mutator::mutate( RangeExpr *rangeExpr ) {
    383389        rangeExpr->set_env( maybeMutate( rangeExpr->get_env(), *this ) );
  • src/SynTree/Mutator.h

    re9a3b20b rd56e5bc  
    7878        virtual Expression* mutate( ConstructorExpr *ctorExpr );
    7979        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );
     80        virtual Expression* mutate( UntypedValofExpr *valofExpr );
    8081        virtual Expression* mutate( RangeExpr *rangeExpr );
    8182        virtual Expression* mutate( UntypedTupleExpr *tupleExpr );
  • src/SynTree/ObjectDecl.cc

    re9a3b20b rd56e5bc  
    5656
    5757        if ( init ) {
    58                 os << " with initializer " << std::endl;
    59                 init->print( os, indent+2 );
    60                 os << std::endl << std::string(indent+2, ' ');
     58                os << " with initializer ";
     59                init->print( os, indent );
     60                os << std::endl << std::string(indent, ' ');
    6161                os << "maybeConstructed? " << init->get_maybeConstructed();
    6262        } // if
  • src/SynTree/Statement.cc

    re9a3b20b rd56e5bc  
    313313}
    314314
    315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
     315TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) :
    316316        Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) {
    317317}
     
    334334        // handlers
    335335        os << string( indent + 2, ' ' ) << "and handlers: " << endl;
    336         for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++)
     336        for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++)
    337337                (*i )->print( os, indent + 4 );
    338338
  • src/SynTree/Statement.h

    re9a3b20b rd56e5bc  
    315315class TryStmt : public Statement {
    316316  public:
    317         TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
     317        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 );
    318318        TryStmt( const TryStmt &other );
    319319        virtual ~TryStmt();
     
    321321        CompoundStmt *get_block() const { return block; }
    322322        void set_block( CompoundStmt *newValue ) { block = newValue; }
    323         std::list<CatchStmt *>& get_catchers() { return handlers; }
     323        std::list<Statement *>& get_catchers() { return handlers; }
    324324
    325325        FinallyStmt *get_finally() const { return finallyBlock; }
     
    333333  private:
    334334        CompoundStmt *block;
    335         std::list<CatchStmt *> handlers;
     335        std::list<Statement *> handlers;
    336336        FinallyStmt *finallyBlock;
    337337};
  • src/SynTree/Visitor.cc

    re9a3b20b rd56e5bc  
    301301}
    302302
     303void Visitor::visit( UntypedValofExpr *valofExpr ) {
     304        maybeAccept( valofExpr->get_result(), *this );
     305        maybeAccept( valofExpr->get_body(), *this );
     306}
     307
    303308void Visitor::visit( RangeExpr *rangeExpr ) {
    304309        maybeAccept( rangeExpr->get_low(), *this );
  • src/SynTree/Visitor.h

    re9a3b20b rd56e5bc  
    8181        virtual void visit( ConstructorExpr * ctorExpr );
    8282        virtual void visit( CompoundLiteralExpr *compLitExpr );
     83        virtual void visit( UntypedValofExpr *valofExpr );
    8384        virtual void visit( RangeExpr *rangeExpr );
    8485        virtual void visit( UntypedTupleExpr *tupleExpr );
     
    162163                        } // if
    163164                } catch( SemanticError &e ) {
    164                         e.set_location( (*i)->location );
     165                        e.set_location( (*i)->location );                       
    165166                        errors.append( e );
    166167                } // try
Note: See TracChangeset for help on using the changeset viewer.