Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r401e61f rcc32d83  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun  5 08:58:34 2018
    13 // Update Count     : 362
     12// Last Modified On : Mon Apr 30 09:21:16 2018
     13// Update Count     : 354
    1414//
    1515
     
    6969        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    7070        return this;
    71 } // StatementNode::append_last_case
     71}
    7272
    7373Statement * build_expr( ExpressionNode * ctl ) {
    7474        Expression * e = maybeMoveBuild< Expression >( ctl );
    7575
    76         if ( e ) return new ExprStmt( e );
    77         else return new NullStmt();
    78 } // build_expr
    79 
    80 Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) {
     76        if ( e )
     77                return new ExprStmt( e );
     78        else
     79                return new NullStmt();
     80}
     81
     82Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
     83        Statement * thenb, * elseb = 0;
     84        std::list< Statement * > branches;
     85        buildMoveList< Statement, StatementNode >( then_stmt, branches );
     86        assert( branches.size() == 1 );
     87        thenb = branches.front();
     88
     89        if ( else_stmt ) {
     90                std::list< Statement * > branches;
     91                buildMoveList< Statement, StatementNode >( else_stmt, branches );
     92                assert( branches.size() == 1 );
     93                elseb = branches.front();
     94        } // if
     95
     96        std::list< Statement * > init;
    8197        if ( ctl->init != 0 ) {
    8298                buildMoveList( ctl->init, init );
     
    86102        if ( ctl->condition ) {
    87103                // compare the provided condition against 0
    88                 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
     104                cond =  notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
    89105        } else {
    90106                for ( Statement * stmt : init ) {
     
    97113        }
    98114        delete ctl;
    99         return cond;
    100 } // build_if_control
    101 
    102 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
    103         Statement * thenb, * elseb = nullptr;
    104         std::list< Statement * > branches;
    105         buildMoveList< Statement, StatementNode >( then_stmt, branches );
    106         assert( branches.size() == 1 );
    107         thenb = branches.front();
    108 
    109         if ( else_stmt ) {
    110                 std::list< Statement * > branches;
    111                 buildMoveList< Statement, StatementNode >( else_stmt, branches );
    112                 assert( branches.size() == 1 );
    113                 elseb = branches.front();
    114         } // if
    115 
    116         std::list< Statement * > init;
    117         Expression * cond = build_if_control( ctl, init );
    118115        return new IfStmt( cond, thenb, elseb, init );
    119 } // build_if
     116}
    120117
    121118Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) {
     
    133130        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    134131        return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
    135 } // build_switch
    136 
     132}
    137133Statement * build_case( ExpressionNode * ctl ) {
    138134        std::list< Statement * > branches;
    139135        return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );
    140 } // build_case
    141 
     136}
    142137Statement * build_default() {
    143138        std::list< Statement * > branches;
    144139        return new CaseStmt( nullptr, branches, true );
    145 } // build_default
    146 
    147 Statement * build_while( IfCtl * ctl, StatementNode * stmt ) {
     140}
     141
     142Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) {
    148143        std::list< Statement * > branches;
    149144        buildMoveList< Statement, StatementNode >( stmt, branches );
    150145        assert( branches.size() == 1 );
    151 
    152         std::list< Statement * > init;
    153         Expression * cond = build_if_control( ctl, init );
    154         return new WhileStmt( cond, branches.front(), init, false );
    155 } // build_while
    156 
    157 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) {
    158         std::list< Statement * > branches;
    159         buildMoveList< Statement, StatementNode >( stmt, branches );
    160         assert( branches.size() == 1 );
    161 
    162         std::list< Statement * > init;
    163         return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true );
    164 } // build_do_while
     146        return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );
     147}
    165148
    166149Statement * build_for( ForCtl * forctl, StatementNode * stmt ) {
     
    184167        delete forctl;
    185168        return new ForStmt( init, cond, incr, branches.front() );
    186 } // build_for
     169}
    187170
    188171Statement * build_branch( BranchStmt::Type kind ) {
    189172        Statement * ret = new BranchStmt( "", kind );
    190173        return ret;
    191 } // build_branch
    192 
     174}
    193175Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) {
    194176        Statement * ret = new BranchStmt( * identifier, kind );
    195177        delete identifier;                                                                      // allocated by lexer
    196178        return ret;
    197 } // build_branch
    198 
     179}
    199180Statement * build_computedgoto( ExpressionNode * ctl ) {
    200181        return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    201 } // build_computedgoto
     182}
    202183
    203184Statement * build_return( ExpressionNode * ctl ) {
     
    205186        buildMoveList( ctl, exps );
    206187        return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr );
    207 } // build_return
     188}
    208189
    209190Statement * build_throw( ExpressionNode * ctl ) {
     
    212193        assertf( exps.size() < 2, "This means we are leaking memory");
    213194        return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
    214 } // build_throw
     195}
    215196
    216197Statement * build_resume( ExpressionNode * ctl ) {
     
    219200        assertf( exps.size() < 2, "This means we are leaking memory");
    220201        return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
    221 } // build_resume
     202}
    222203
    223204Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) {
     
    225206        (void)target;
    226207        assertf( false, "resume at (non-local throw) is not yet supported," );
    227 } // build_resume_at
     208}
    228209
    229210Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) {
     
    233214        FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    234215        return new TryStmt( tryBlock, branches, finallyBlock );
    235 } // build_try
    236 
     216}
    237217Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) {
    238218        std::list< Statement * > branches;
     
    240220        assert( branches.size() == 1 );
    241221        return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    242 } // build_catch
    243 
     222}
    244223Statement * build_finally( StatementNode * stmt ) {
    245224        std::list< Statement * > branches;
     
    247226        assert( branches.size() == 1 );
    248227        return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );
    249 } // build_finally
     228}
    250229
    251230WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) {
     
    268247
    269248        return node;
    270 } // build_waitfor
     249}
    271250
    272251WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
     
    287266
    288267        return node;
    289 } // build_waitfor
     268}
    290269
    291270WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) {
     
    296275                node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
    297276                node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    298         } else {
     277        }
     278        else {
    299279                node->orelse.statement  = maybeMoveBuild<Statement >( stmt );
    300280                node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    301         } // if
     281        }
    302282
    303283        return node;
    304 } // build_waitfor_timeout
     284}
    305285
    306286WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when,  StatementNode * else_stmt, ExpressionNode * else_when ) {
     
    315295
    316296        return node;
    317 } // build_waitfor_timeout
     297}
    318298
    319299WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
     
    322302        Statement * s = maybeMoveBuild<Statement>( stmt );
    323303        return new WithStmt( e, s );
    324 } // build_with
     304}
    325305
    326306Statement * build_compound( StatementNode * first ) {
     
    328308        buildMoveList( first, cs->get_kids() );
    329309        return cs;
    330 } // build_compound
     310}
    331311
    332312Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
     
    338318        buildMoveList( clobber, clob );
    339319        return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    340 } // build_asm
     320}
    341321
    342322Statement * build_directive( string * directive ) {
    343323        return new DirectiveStmt( *directive );
    344 } // build_directive
     324}
    345325
    346326// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.