Ignore:
Timestamp:
Aug 16, 2016, 8:59:49 AM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0da3e2c, 13e3b50, 7527e63
Parents:
b1848a0
Message:

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    rb1848a0 r7880579  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 15 14:40:05 2016
    13 // Update Count     : 317
     12// Last Modified On : Mon Aug 15 20:47:11 2016
     13// Update Count     : 322
    1414//
    1515
     
    3232                if ( agg ) {
    3333                        StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) );
    34                         next = nextStmt;
     34                        set_next( nextStmt );
    3535                        if ( decl->get_next() ) {
    36                                 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>(decl->get_next()) ) );
     36                                get_next()->set_next( new StatementNode( dynamic_cast< DeclarationNode * >(decl->get_next()) ) );
    3737                                decl->set_next( 0 );
    3838                        } // if
    3939                } else {
    4040                        if ( decl->get_next() ) {
    41                                 next = new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next() ) );
     41                                set_next(new StatementNode( dynamic_cast< DeclarationNode * >( decl->get_next() ) ) );
    4242                                decl->set_next( 0 );
    4343                        } // if
    4444                        agg = decl;
    4545                } // if
    46                 stmt = new DeclStmt( noLabels, maybeBuild<Declaration>(agg) );
     46                stmt = new DeclStmt( noLabels, maybeBuild< Declaration >(agg) );
    4747        } else {
    4848                assert( false );
     
    5454        // find end of list and maintain previous pointer
    5555        for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) {
    56                 StatementNode *node = dynamic_cast<StatementNode *>(curr);
     56                StatementNode *node = dynamic_cast< StatementNode * >(curr);
    5757                assert( node );
    58                 assert( dynamic_cast<CaseStmt *>(node->stmt) );
     58                assert( dynamic_cast< CaseStmt * >(node->stmt) );
    5959                prev = curr;
    6060        } // for
    6161        // convert from StatementNode list to Statement list
    62         StatementNode *node = dynamic_cast<StatementNode *>(prev);
    63         std::list<Statement *> stmts;
     62        StatementNode *node = dynamic_cast< StatementNode * >(prev);
     63        std::list< Statement * > stmts;
    6464        buildList( stmt, stmts );
    6565        // splice any new Statements to end of current Statements
    66         CaseStmt * caseStmt = dynamic_cast<CaseStmt *>(node->stmt);
     66        CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt);
    6767        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    6868        return this;
     
    8080Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
    8181        Statement *thenb, *elseb = 0;
    82         std::list<Statement *> branches;
    83         buildList<Statement, StatementNode>( then_stmt, branches );
     82        std::list< Statement * > branches;
     83        buildList< Statement, StatementNode >( then_stmt, branches );
    8484        assert( branches.size() == 1 );
    8585        thenb = branches.front();
    8686
    8787        if ( else_stmt ) {
    88                 std::list<Statement *> branches;
    89                 buildList<Statement, StatementNode>( else_stmt, branches );
     88                std::list< Statement * > branches;
     89                buildList< Statement, StatementNode >( else_stmt, branches );
    9090                assert( branches.size() == 1 );
    9191                elseb = branches.front();
    9292        } // if
    93         return new IfStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), thenb, elseb );
     93        return new IfStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), thenb, elseb );
    9494}
    9595
    9696Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
    97         std::list<Statement *> branches;
    98         buildList<Statement, StatementNode>( stmt, branches );
     97        std::list< Statement * > branches;
     98        buildList< Statement, StatementNode >( stmt, branches );
    9999        assert( branches.size() >= 0 );                                         // size == 0 for switch (...) {}, i.e., no declaration or statements
    100         return new SwitchStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     100        return new SwitchStmt( noLabels, maybeBuild< Expression >(ctl), branches );
    101101}
    102102Statement *build_case( ExpressionNode *ctl ) {
    103         std::list<Statement *> branches;
    104         return new CaseStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     103        std::list< Statement * > branches;
     104        return new CaseStmt( noLabels, maybeBuild< Expression >(ctl), branches );
    105105}
    106106Statement *build_default() {
    107         std::list<Statement *> branches;
     107        std::list< Statement * > branches;
    108108        return new CaseStmt( noLabels, nullptr, branches, true );
    109109}
    110110
    111111Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {
    112         std::list<Statement *> branches;
    113         buildList<Statement, StatementNode>( stmt, branches );
     112        std::list< Statement * > branches;
     113        buildList< Statement, StatementNode >( stmt, branches );
    114114        assert( branches.size() == 1 );
    115         return new WhileStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), branches.front(), kind );
     115        return new WhileStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), branches.front(), kind );
    116116}
    117117
    118118Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {
    119         std::list<Statement *> branches;
    120         buildList<Statement, StatementNode>( stmt, branches );
     119        std::list< Statement * > branches;
     120        buildList< Statement, StatementNode >( stmt, branches );
    121121        assert( branches.size() == 1 );
    122122
    123         std::list<Statement *> init;
     123        std::list< Statement * > init;
    124124        if ( forctl->init != 0 ) {
    125125                buildList( forctl->init, init );
     
    128128        Expression *cond = 0;
    129129        if ( forctl->condition != 0 )
    130                 cond = notZeroExpr( maybeBuild<Expression>(forctl->condition) );
     130                cond = notZeroExpr( maybeBuild< Expression >(forctl->condition) );
    131131
    132132        Expression *incr = 0;
    133133        if ( forctl->change != 0 )
    134                 incr = maybeBuild<Expression>(forctl->change);
     134                incr = maybeBuild< Expression >(forctl->change);
    135135
    136136        delete forctl;
     
    142142}
    143143Statement *build_computedgoto( ExpressionNode *ctl ) {
    144         return new BranchStmt( noLabels, maybeBuild<Expression>(ctl), BranchStmt::Goto );
     144        return new BranchStmt( noLabels, maybeBuild< Expression >(ctl), BranchStmt::Goto );
    145145}
    146146
    147147Statement *build_return( ExpressionNode *ctl ) {
    148         std::list<Expression *> exps;
     148        std::list< Expression * > exps;
    149149        buildList( ctl, exps );
    150150        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );
    151151}
    152152Statement *build_throw( ExpressionNode *ctl ) {
    153         std::list<Expression *> exps;
     153        std::list< Expression * > exps;
    154154        buildList( ctl, exps );
    155155        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true );
     
    157157
    158158Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
    159         std::list<Statement *> branches;
    160         buildList<Statement, StatementNode>( catch_stmt, branches );
    161         CompoundStmt *tryBlock = dynamic_cast<CompoundStmt *>(maybeBuild<Statement>(try_stmt));
     159        std::list< Statement * > branches;
     160        buildList< Statement, StatementNode >( catch_stmt, branches );
     161        CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeBuild< Statement >(try_stmt));
    162162        assert( tryBlock );
    163         FinallyStmt *finallyBlock = dynamic_cast<FinallyStmt *>(maybeBuild<Statement>(finally_stmt) );
     163        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeBuild< Statement >(finally_stmt) );
    164164        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
    165165}
    166166Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) {
    167         std::list<Statement *> branches;
    168         buildList<Statement, StatementNode>( stmt, branches );
     167        std::list< Statement * > branches;
     168        buildList< Statement, StatementNode >( stmt, branches );
    169169        assert( branches.size() == 1 );
    170         return new CatchStmt( noLabels, maybeBuild<Declaration>(decl), branches.front(), catchAny );
     170        return new CatchStmt( noLabels, maybeBuild< Declaration >(decl), branches.front(), catchAny );
    171171}
    172172Statement *build_finally( StatementNode *stmt ) {
    173         std::list<Statement *> branches;
    174         buildList<Statement, StatementNode>( stmt, branches );
     173        std::list< Statement * > branches;
     174        buildList< Statement, StatementNode >( stmt, branches );
    175175        assert( branches.size() == 1 );
    176         return new FinallyStmt( noLabels, dynamic_cast<CompoundStmt *>( branches.front() ) );
     176        return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) );
    177177}
    178178
Note: See TracChangeset for help on using the changeset viewer.