Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    rcc32d83 r8d7bef2  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 30 09:21:16 2018
    13 // Update Count     : 354
     12// Last Modified On : Fri Sep  1 23:25:23 2017
     13// Update Count     : 346
    1414//
    1515
    1616#include <cassert>                 // for assert, strict_dynamic_cast, assertf
    1717#include <list>                    // for list
    18 #include <memory>                  // for unique_ptr
    1918#include <string>                  // for string
    2019
     
    3332
    3433
    35 StatementNode::StatementNode( DeclarationNode * decl ) {
     34StatementNode::StatementNode( DeclarationNode *decl ) {
    3635        assert( decl );
    37         DeclarationNode * agg = decl->extractAggregate();
     36        DeclarationNode *agg = decl->extractAggregate();
    3837        if ( agg ) {
    39                 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );
     38                StatementNode *nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );
    4039                set_next( nextStmt );
    4140                if ( decl->get_next() ) {
     
    5049                agg = decl;
    5150        } // if
    52         stmt.reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );
     51        stmt = new DeclStmt{ maybeMoveBuild< Declaration >(agg) };
    5352} // StatementNode::StatementNode
    5453
    55 StatementNode * StatementNode::append_last_case( StatementNode * stmt ) {
    56         StatementNode * prev = this;
     54StatementNode *StatementNode::append_last_case( StatementNode *stmt ) {
     55        StatementNode *prev = this;
    5756        // find end of list and maintain previous pointer
    5857        for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) {
    59                 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr);
    60                 assert( dynamic_cast< CaseStmt * >(node->stmt.get()) );
     58                StatementNode *node = strict_dynamic_cast< StatementNode * >(curr);
     59                assert( dynamic_cast< CaseStmt * >(node->stmt) );
    6160                prev = curr;
    6261        } // for
    6362        // convert from StatementNode list to Statement list
    64         StatementNode * node = dynamic_cast< StatementNode * >(prev);
     63        StatementNode *node = dynamic_cast< StatementNode * >(prev);
    6564        std::list< Statement * > stmts;
    6665        buildMoveList( stmt, stmts );
    6766        // splice any new Statements to end of current Statements
    68         CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt.get());
     67        CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt);
    6968        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    7069        return this;
    7170}
    7271
    73 Statement * build_expr( ExpressionNode * ctl ) {
    74         Expression * e = maybeMoveBuild< Expression >( ctl );
     72Statement *build_expr( ExpressionNode *ctl ) {
     73        Expression *e = maybeMoveBuild< Expression >( ctl );
    7574
    7675        if ( e )
     
    8079}
    8180
    82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
    83         Statement * thenb, * elseb = 0;
     81Statement *build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
     82        Statement *thenb, *elseb = 0;
    8483        std::list< Statement * > branches;
    8584        buildMoveList< Statement, StatementNode >( then_stmt, branches );
     
    116115}
    117116
    118 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) {
     117Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
    119118        std::list< Statement * > branches;
    120119        buildMoveList< Statement, StatementNode >( stmt, branches );
    121         if ( ! isSwitch ) {                                                                             // choose statement
    122                 for ( Statement * stmt : branches ) {
    123                         CaseStmt * caseStmt = strict_dynamic_cast< CaseStmt * >( stmt );
    124                         if ( ! caseStmt->stmts.empty() ) {                      // code after "case" => end of case list
    125                                 CompoundStmt * block = strict_dynamic_cast< CompoundStmt * >( caseStmt->stmts.front() );
    126                                 block->kids.push_back( new BranchStmt( "", BranchStmt::Break ) );
    127                         } // if
    128                 } // for
    129         } // if
    130120        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    131121        return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
    132122}
    133 Statement * build_case( ExpressionNode * ctl ) {
     123Statement *build_case( ExpressionNode *ctl ) {
    134124        std::list< Statement * > branches;
    135125        return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );
    136126}
    137 Statement * build_default() {
     127Statement *build_default() {
    138128        std::list< Statement * > branches;
    139129        return new CaseStmt( nullptr, branches, true );
    140130}
    141131
    142 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) {
     132Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {
    143133        std::list< Statement * > branches;
    144134        buildMoveList< Statement, StatementNode >( stmt, branches );
     
    147137}
    148138
    149 Statement * build_for( ForCtl * forctl, StatementNode * stmt ) {
     139Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {
    150140        std::list< Statement * > branches;
    151141        buildMoveList< Statement, StatementNode >( stmt, branches );
     
    157147        } // if
    158148
    159         Expression * cond = 0;
     149        Expression *cond = 0;
    160150        if ( forctl->condition != 0 )
    161151                cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) );
    162152
    163         Expression * incr = 0;
     153        Expression *incr = 0;
    164154        if ( forctl->change != 0 )
    165155                incr = maybeMoveBuild< Expression >(forctl->change);
     
    169159}
    170160
    171 Statement * build_branch( BranchStmt::Type kind ) {
     161Statement *build_branch( BranchStmt::Type kind ) {
    172162        Statement * ret = new BranchStmt( "", kind );
    173163        return ret;
    174164}
    175 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) {
    176         Statement * ret = new BranchStmt( * identifier, kind );
     165Statement *build_branch( std::string *identifier, BranchStmt::Type kind ) {
     166        Statement * ret = new BranchStmt( *identifier, kind );
    177167        delete identifier;                                                                      // allocated by lexer
    178168        return ret;
    179169}
    180 Statement * build_computedgoto( ExpressionNode * ctl ) {
     170Statement *build_computedgoto( ExpressionNode *ctl ) {
    181171        return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    182172}
    183173
    184 Statement * build_return( ExpressionNode * ctl ) {
     174Statement *build_return( ExpressionNode *ctl ) {
    185175        std::list< Expression * > exps;
    186176        buildMoveList( ctl, exps );
     
    188178}
    189179
    190 Statement * build_throw( ExpressionNode * ctl ) {
     180Statement *build_throw( ExpressionNode *ctl ) {
    191181        std::list< Expression * > exps;
    192182        buildMoveList( ctl, exps );
     
    195185}
    196186
    197 Statement * build_resume( ExpressionNode * ctl ) {
     187Statement *build_resume( ExpressionNode *ctl ) {
    198188        std::list< Expression * > exps;
    199189        buildMoveList( ctl, exps );
     
    202192}
    203193
    204 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) {
     194Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) {
    205195        (void)ctl;
    206196        (void)target;
     
    208198}
    209199
    210 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) {
     200Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
    211201        std::list< CatchStmt * > branches;
    212202        buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches );
    213         CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    214         FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
     203        CompoundStmt *tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
     204        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    215205        return new TryStmt( tryBlock, branches, finallyBlock );
    216206}
    217 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) {
     207Statement *build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) {
    218208        std::list< Statement * > branches;
    219209        buildMoveList< Statement, StatementNode >( body, branches );
     
    221211        return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    222212}
    223 Statement * build_finally( StatementNode * stmt ) {
     213Statement *build_finally( StatementNode *stmt ) {
    224214        std::list< Statement * > branches;
    225215        buildMoveList< Statement, StatementNode >( stmt, branches );
     
    304294}
    305295
    306 Statement * build_compound( StatementNode * first ) {
    307         CompoundStmt * cs = new CompoundStmt();
     296Statement *build_compound( StatementNode *first ) {
     297        CompoundStmt *cs = new CompoundStmt();
    308298        buildMoveList( first, cs->get_kids() );
    309299        return cs;
    310300}
    311301
    312 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
     302Statement *build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {
    313303        std::list< Expression * > out, in;
    314304        std::list< ConstantExpr * > clob;
     
    318308        buildMoveList( clobber, clob );
    319309        return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    320 }
    321 
    322 Statement * build_directive( string * directive ) {
    323         return new DirectiveStmt( *directive );
    324310}
    325311
Note: See TracChangeset for help on using the changeset viewer.