Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r658fafe4 r2f22cc4  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 17:21:02 2016
    13 // Update Count     : 133
     12// Last Modified On : Wed Aug 10 13:54:21 2016
     13// Update Count     : 170
    1414//
    1515
     
    106106        return this;
    107107}
    108 
    109 // StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) {
    110 //      if ( control && e )
    111 //              control->add_to_list( e ); // xxx - check this
    112 //      return this;
    113 // }
    114108
    115109StatementNode *StatementNode::append_block( StatementNode *stmt ) {
     
    176170                } // if
    177171                if ( block ) {
    178                         os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
     172                        os << string( indent + ParseNode::indent_by, ' ' ) << "Cases: " << endl;
    179173                        block->printList( os, indent + 2 * ParseNode::indent_by );
    180174                } // if
     
    212206                }
    213207          case If:
    214                 {
    215                         Statement *thenb = 0, *elseb = 0;
    216                         assert( branches.size() >= 1 );
    217 
    218                         thenb = branches.front();
    219                         branches.pop_front();
    220                         if ( ! branches.empty() ) {
    221                                 elseb = branches.front();
    222                                 branches.pop_front();
    223                         } // if
    224                         return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb );
    225                 }
    226           case While:
    227                 assert( branches.size() == 1 );
    228                 return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() );
    229           case Do:
    230                 assert( branches.size() == 1 );
    231                 return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true );
    232           case For:
    233                 {
    234                         assert( branches.size() == 1 );
    235 
    236                         ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>( get_control() );
    237                         assert( ctl != 0 );
    238 
    239                         std::list<Statement *> init;
    240                         if ( ctl->get_init() != 0 ) {
    241                                 buildList( ctl->get_init(), init );
    242                         } // if
    243 
    244                         Expression *cond = 0;
    245                         if ( ctl->get_condition() != 0 )
    246                                 cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) );
    247 
    248                         Expression *incr = 0;
    249                         if ( ctl->get_change() != 0 )
    250                                 incr = maybeBuild<Expression>(ctl->get_change());
    251 
    252                         return new ForStmt( labs, init, cond, incr, branches.front() );
    253                 }
     208                // {
     209                //      Statement *thenb = 0, *elseb = 0;
     210                //      assert( branches.size() >= 1 );
     211
     212                //      thenb = branches.front();
     213                //      branches.pop_front();
     214                //      if ( ! branches.empty() ) {
     215                //              elseb = branches.front();
     216                //              branches.pop_front();
     217                //      } // if
     218                //      return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb );
     219                // }
     220                assert( false );
    254221          case Switch:
    255                 return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches );
     222                //return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches );
     223                assert( false );
    256224          case Case:
    257                 return new CaseStmt( labs, maybeBuild<Expression>(get_control()), branches );
     225                return new CaseStmt( labs, maybeBuild<Expression>(get_control() ), branches );
    258226          case Default:
    259227                return new CaseStmt( labs, 0, branches, true );
     228          case While:
     229                // assert( branches.size() == 1 );
     230                // return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() );
     231                assert( false );
     232          case Do:
     233                // assert( branches.size() == 1 );
     234                // return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true );
     235                assert( false );
     236          case For:
     237                // {
     238                //      assert( branches.size() == 1 );
     239
     240                //      ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>( get_control() );
     241                //      assert( ctl != 0 );
     242
     243                //      std::list<Statement *> init;
     244                //      if ( ctl->get_init() != 0 ) {
     245                //              buildList( ctl->get_init(), init );
     246                //      } // if
     247
     248                //      Expression *cond = 0;
     249                //      if ( ctl->get_condition() != 0 )
     250                //              cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) );
     251
     252                //      Expression *incr = 0;
     253                //      if ( ctl->get_change() != 0 )
     254                //              incr = maybeBuild<Expression>(ctl->get_change());
     255
     256                //      return new ForStmt( labs, init, cond, incr, branches.front() );
     257                // }
     258                assert( false );
    260259          case Goto:
    261260                {
     
    311310}
    312311
     312Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
     313        Statement *thenb, *elseb = 0;
     314        std::list<Statement *> branches;
     315        buildList<Statement, StatementNode>( then_stmt, branches );
     316        assert( branches.size() >= 1 );
     317        thenb = branches.front();
     318
     319        if ( else_stmt ) {
     320                std::list<Statement *> branches;
     321                buildList<Statement, StatementNode>( else_stmt, branches );
     322                assert( branches.size() >= 1 );
     323                elseb = branches.front();
     324        } // if
     325        return new IfStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), thenb, elseb );
     326}
     327
     328Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
     329        std::list<Statement *> branches;
     330        buildList<Statement, StatementNode>( stmt, branches );
     331        assert( branches.size() >= 1 );
     332        return new SwitchStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     333}
     334
     335Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {
     336        std::list<Statement *> branches;
     337        buildList<Statement, StatementNode>( stmt, branches );
     338        assert( branches.size() == 1 );
     339        return new WhileStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), branches.front(), kind );
     340}
     341
     342Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {
     343        std::list<Statement *> branches;
     344        buildList<Statement, StatementNode>( stmt, branches );
     345        assert( branches.size() == 1 );
     346
     347        std::list<Statement *> init;
     348        if ( forctl->init != 0 ) {
     349                buildList( forctl->init, init );
     350        } // if
     351
     352        Expression *cond = 0;
     353        if ( forctl->condition != 0 )
     354                cond = notZeroExpr( maybeBuild<Expression>(forctl->condition) );
     355
     356        Expression *incr = 0;
     357        if ( forctl->change != 0 )
     358                incr = maybeBuild<Expression>(forctl->change);
     359
     360        delete forctl;
     361        return new ForStmt( noLabels, init, cond, incr, branches.front() );
     362}
     363
    313364
    314365CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {}
     
    356407
    357408
    358 AsmStmtNode::AsmStmtNode( Type t, bool voltile, ConstantNode *instruction, ExpressionNode *output, ExpressionNode *input, ConstantNode *clobber, LabelNode *gotolabels ) :
     409AsmStmtNode::AsmStmtNode( Type t, bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) :
    359410        StatementNode( t ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ) {
    360411        if ( gotolabels ) {
     
    365416
    366417AsmStmtNode::~AsmStmtNode() {
    367         delete instruction; delete output; delete input; delete clobber;
     418        delete output; delete input; delete clobber;
    368419}
    369420
     
    373424        if ( instruction ) {
    374425                os << string( indent + ParseNode::indent_by, ' ' ) << "Instruction:" << endl;
    375                 instruction->printList( os, indent + 2 * ParseNode::indent_by );
     426//              instruction->printList( os, indent + 2 * ParseNode::indent_by );
    376427        } // if
    377428        if ( output ) {
     
    385436        if ( clobber ) {
    386437                os << string( indent + ParseNode::indent_by, ' ' ) << "Clobber:" << endl;
    387                 clobber->printList( os, indent + 2 * ParseNode::indent_by );
     438//              clobber->printList( os, indent + 2 * ParseNode::indent_by );
    388439        } // if
    389440        if ( ! gotolabels.empty() ) {
     
    414465        buildList( clobber, clob );
    415466        std::list< Label > gotolabs = gotolabels;
    416         return new AsmStmt( labs, voltile, (ConstantExpr *)maybeBuild< Expression >( instruction ), out, in, clob, gotolabs );
     467        return new AsmStmt( labs, voltile, instruction, out, in, clob, gotolabs );
    417468}
    418469
Note: See TracChangeset for help on using the changeset viewer.