Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r401e61f ree3c93d  
    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
     76        if ( e )
     77                return new ExprStmt( e );
     78        else
     79                return new NullStmt();
     80}
    7981
    8082Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) {
     
    98100        delete ctl;
    99101        return cond;
    100 } // build_if_control
     102}
    101103
    102104Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
    103         Statement * thenb, * elseb = nullptr;
     105        Statement * thenb, * elseb = 0;
    104106        std::list< Statement * > branches;
    105107        buildMoveList< Statement, StatementNode >( then_stmt, branches );
     
    117119        Expression * cond = build_if_control( ctl, init );
    118120        return new IfStmt( cond, thenb, elseb, init );
    119 } // build_if
     121}
    120122
    121123Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) {
     
    133135        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    134136        return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
    135 } // build_switch
    136 
     137}
    137138Statement * build_case( ExpressionNode * ctl ) {
    138139        std::list< Statement * > branches;
    139140        return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );
    140 } // build_case
    141 
     141}
    142142Statement * build_default() {
    143143        std::list< Statement * > branches;
    144144        return new CaseStmt( nullptr, branches, true );
    145 } // build_default
    146 
    147 Statement * build_while( IfCtl * ctl, StatementNode * stmt ) {
     145}
     146
     147Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) {
    148148        std::list< Statement * > branches;
    149149        buildMoveList< Statement, StatementNode >( stmt, branches );
     
    151151
    152152        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
     153        return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, kind );
     154}
    165155
    166156Statement * build_for( ForCtl * forctl, StatementNode * stmt ) {
     
    184174        delete forctl;
    185175        return new ForStmt( init, cond, incr, branches.front() );
    186 } // build_for
     176}
    187177
    188178Statement * build_branch( BranchStmt::Type kind ) {
    189179        Statement * ret = new BranchStmt( "", kind );
    190180        return ret;
    191 } // build_branch
    192 
     181}
    193182Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) {
    194183        Statement * ret = new BranchStmt( * identifier, kind );
    195184        delete identifier;                                                                      // allocated by lexer
    196185        return ret;
    197 } // build_branch
    198 
     186}
    199187Statement * build_computedgoto( ExpressionNode * ctl ) {
    200188        return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    201 } // build_computedgoto
     189}
    202190
    203191Statement * build_return( ExpressionNode * ctl ) {
     
    205193        buildMoveList( ctl, exps );
    206194        return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr );
    207 } // build_return
     195}
    208196
    209197Statement * build_throw( ExpressionNode * ctl ) {
     
    212200        assertf( exps.size() < 2, "This means we are leaking memory");
    213201        return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
    214 } // build_throw
     202}
    215203
    216204Statement * build_resume( ExpressionNode * ctl ) {
     
    219207        assertf( exps.size() < 2, "This means we are leaking memory");
    220208        return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
    221 } // build_resume
     209}
    222210
    223211Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) {
     
    225213        (void)target;
    226214        assertf( false, "resume at (non-local throw) is not yet supported," );
    227 } // build_resume_at
     215}
    228216
    229217Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) {
     
    233221        FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    234222        return new TryStmt( tryBlock, branches, finallyBlock );
    235 } // build_try
    236 
     223}
    237224Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) {
    238225        std::list< Statement * > branches;
     
    240227        assert( branches.size() == 1 );
    241228        return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    242 } // build_catch
    243 
     229}
    244230Statement * build_finally( StatementNode * stmt ) {
    245231        std::list< Statement * > branches;
     
    247233        assert( branches.size() == 1 );
    248234        return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );
    249 } // build_finally
     235}
    250236
    251237WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) {
     
    268254
    269255        return node;
    270 } // build_waitfor
     256}
    271257
    272258WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
     
    287273
    288274        return node;
    289 } // build_waitfor
     275}
    290276
    291277WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) {
     
    296282                node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
    297283                node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    298         } else {
     284        }
     285        else {
    299286                node->orelse.statement  = maybeMoveBuild<Statement >( stmt );
    300287                node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    301         } // if
     288        }
    302289
    303290        return node;
    304 } // build_waitfor_timeout
     291}
    305292
    306293WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when,  StatementNode * else_stmt, ExpressionNode * else_when ) {
     
    315302
    316303        return node;
    317 } // build_waitfor_timeout
     304}
    318305
    319306WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
     
    322309        Statement * s = maybeMoveBuild<Statement>( stmt );
    323310        return new WithStmt( e, s );
    324 } // build_with
     311}
    325312
    326313Statement * build_compound( StatementNode * first ) {
     
    328315        buildMoveList( first, cs->get_kids() );
    329316        return cs;
    330 } // build_compound
     317}
    331318
    332319Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
     
    338325        buildMoveList( clobber, clob );
    339326        return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    340 } // build_asm
     327}
    341328
    342329Statement * build_directive( string * directive ) {
    343330        return new DirectiveStmt( *directive );
    344 } // build_directive
     331}
    345332
    346333// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.