Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r8cc5cb0 r837a17c  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 11 16:19:45 2016
    13 // Update Count     : 210
     12// Last Modified On : Sun Aug 21 11:59:37 2016
     13// Update Count     : 325
    1414//
    1515
     
    2626using namespace std;
    2727
    28 const char *StatementNode::StType[] = {
    29         "Exp",   "If",       "Switch", "Case",    "Default",  "Choose",   "Fallthru",
    30         "While", "Do",       "For",
    31         "Goto",  "Continue", "Break",  "Return",  "Throw",
    32         "Try",   "Catch",    "Finally", "Asm",
    33         "Decl"
    34 };
    35 
    36 StatementNode::StatementNode() : ParseNode(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    37 
    38 StatementNode::StatementNode( const string *name ) : ParseNode( name ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    39 
    40 StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), isCatchRest ( false ) {
     28
     29StatementNode::StatementNode( DeclarationNode *decl ) {
    4130        if ( decl ) {
    42                 if ( DeclarationNode *agg = decl->extractAggregate() ) {
    43                         this->decl = agg;
    44                         StatementNode *nextStmt = new StatementNode;
    45                         nextStmt->type = Decl;
    46                         nextStmt->decl = decl;
    47                         next = nextStmt;
    48                         if ( decl->get_link() ) {
    49                                 next->set_next( new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ) );
     31                DeclarationNode *agg = decl->extractAggregate();
     32                if ( agg ) {
     33                        StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) );
     34                        set_next( nextStmt );
     35                        if ( decl->get_next() ) {
     36                                get_next()->set_next( new StatementNode( dynamic_cast< DeclarationNode * >(decl->get_next()) ) );
    5037                                decl->set_next( 0 );
    5138                        } // if
    5239                } else {
    53                         if ( decl->get_link() ) {
    54                                 next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) );
     40                        if ( decl->get_next() ) {
     41                                set_next(new StatementNode( dynamic_cast< DeclarationNode * >( decl->get_next() ) ) );
    5542                                decl->set_next( 0 );
    5643                        } // if
    57                         this->decl = decl;
     44                        agg = decl;
    5845                } // if
     46                stmt.reset( new DeclStmt( noLabels, maybeMoveBuild< Declaration >(agg) ) );
     47        } else {
     48                assert( false );
    5949        } // if
    6050}
    6151
    62 StatementNode::StatementNode( Type t, ExpressionNode *ctrl_label, StatementNode *block ) : type( t ), control( ctrl_label ), block( block ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {
    63         this->control = ( t == Default ) ? 0 : control;
    64 }
    65 
    66 StatementNode::StatementNode( Type t, string *target ) : type( t ), control( 0 ), block( 0 ), labels( 0 ), target( target ), decl( 0 ), isCatchRest ( false ) {}
    67 
    68 StatementNode::~StatementNode() {
    69         delete control;
    70         delete block;
    71         delete target;
    72         delete decl;
    73 }
    74 
    75 StatementNode * StatementNode::newCatchStmt( DeclarationNode *d, StatementNode *s, bool catchRestP ) {
    76         StatementNode *ret = new StatementNode( StatementNode::Catch, 0, s );
    77         ret->addDeclaration( d );
    78         ret->setCatchRest( catchRestP );
    79 
    80         return ret;
    81 }
    82 
    83 std::string StatementNode::get_target() const{
    84         if ( target )
    85                 return *target;
    86 
    87         return string("");
    88 }
    89 
    90 StatementNode * StatementNode::clone() const {
    91         StatementNode *newnode = new StatementNode( type, maybeClone( control ), maybeClone( block ) );
    92         if ( target ) {
    93                 newnode->target = new string( *target );
    94         } else {
    95                 newnode->target = 0;
    96         } // if
    97         newnode->decl = maybeClone( decl );
    98         return newnode;
    99 }
    100 
    101 StatementNode *StatementNode::add_label( const std::string *l ) {
    102         if ( l != 0 ) {
    103                 labels.push_front( *l );
    104                 delete l;
    105         } // if
    106         return this;
    107 }
    108 
    109 StatementNode *StatementNode::append_block( StatementNode *stmt ) {
    110         if ( stmt != 0 ) {
    111                 if ( block == 0 )
    112                         block = stmt;
    113                 else
    114                         block->set_link( stmt );
    115         } // if
    116         return this;
    117 }
    118 
    11952StatementNode *StatementNode::append_last_case( StatementNode *stmt ) {
    120         assert( false );
    121         if ( stmt != 0 ) {
    122                 StatementNode *next = ( StatementNode *)get_link();
    123                 if ( next && ( next->get_type() == StatementNode::Case || next->get_type() == StatementNode::Default ) )
    124                         next->append_last_case( stmt );
    125                 else
    126                         if ( block == 0 )
    127                                 block = stmt;
    128                         else
    129                                 block->set_link( stmt );
    130         } // if
    131         return this;
    132 }
    133 
    134 StatementNode *StatementNode2::append_last_case( StatementNode *stmt ) {
    13553        StatementNode *prev = this;
    136         for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_link() ) {
    137                 StatementNode2 *node = dynamic_cast<StatementNode2 *>(curr);
    138                 assert( node );
    139                 assert( dynamic_cast<CaseStmt *>(node->stmt) );
     54        // find end of list and maintain previous pointer
     55        for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) {
     56                StatementNode *node = safe_dynamic_cast< StatementNode * >(curr);
     57                assert( dynamic_cast< CaseStmt * >(node->stmt.get()) );
    14058                prev = curr;
    14159        } // for
    142         StatementNode2 *node = dynamic_cast<StatementNode2 *>(prev);
    143         std::list<Statement *> stmts;
    144         buildList( stmt, stmts );
    145         CaseStmt * caseStmt;
    146         caseStmt = dynamic_cast<CaseStmt *>(node->stmt);
     60        // convert from StatementNode list to Statement list
     61        StatementNode *node = dynamic_cast< StatementNode * >(prev);
     62        std::list< Statement * > stmts;
     63        buildMoveList( stmt, stmts );
     64        // splice any new Statements to end of current Statements
     65        CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt.get());
    14766        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    14867        return this;
    14968}
    15069
    151 void StatementNode::print( std::ostream &os, int indent ) const {
    152         if ( ! labels.empty() ) {
    153                 std::list<std::string>::const_iterator i;
    154 
    155                 os << string( indent, ' ' );
    156                 for ( i = labels.begin(); i != labels.end(); i++ )
    157                         os << *i << ":";
    158                 os << endl;
    159         } // if
    160 
    161         switch ( type ) {
    162           case Decl:
    163                 decl->print( os, indent );
    164                 break;
    165           case Exp:
    166                 if ( control ) {
    167                         os << string( indent, ' ' );
    168                         control->print( os, indent );
    169                         os << endl;
    170                 } else
    171                         os << string( indent, ' ' ) << "Null Statement" << endl;
    172                 break;
    173           default:
    174                 os << string( indent, ' ' ) << StatementNode::StType[type] << endl;
    175                 if ( type == Catch ) {
    176                         if ( decl ) {
    177                                 os << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
    178                                 decl->print( os, indent + 2 * ParseNode::indent_by );
    179                         } else if ( isCatchRest ) {
    180                                 os << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
    181                         } else {
    182                                 ; // should never reach here
    183                         } // if
    184                 } // if
    185                 if ( control ) {
    186                         os << string( indent + ParseNode::indent_by, ' ' ) << "Control: " << endl;
    187                         control->printList( os, indent + 2 * ParseNode::indent_by );
    188                 } // if
    189                 if ( block ) {
    190                         os << string( indent + ParseNode::indent_by, ' ' ) << "Cases: " << endl;
    191                         block->printList( os, indent + 2 * ParseNode::indent_by );
    192                 } // if
    193                 if ( target ) {
    194                         os << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
    195                 } // if
    196                 break;
    197         } // switch
    198 }
    199 
    200 Statement *StatementNode::build() const {
    201         std::list<Statement *> branches;
    202         std::list<Expression *> exps;
    203         std::list<Label> labs;
    204 
    205         if ( ! labels.empty() ) {
    206                 std::back_insert_iterator< std::list<Label> > lab_it( labs );
    207                 copy( labels.begin(), labels.end(), lab_it );
    208         } // if
    209 
    210         // try {
    211         buildList<Statement, StatementNode>( get_block(), branches );
    212 
    213         switch ( type ) {
    214           case Decl:
    215                 return new DeclStmt( labs, maybeBuild< Declaration >( decl ) );
    216           case Exp:
    217                 {
    218                         Expression *e = maybeBuild< Expression >( get_control() );
    219 
    220                         if ( e )
    221                                 return new ExprStmt( labs, e );
    222                         else
    223                                 return new NullStmt( labs );
    224                 }
    225                 assert( false );
    226           case If:
    227                 // {
    228                 //      Statement *thenb = 0, *elseb = 0;
    229                 //      assert( branches.size() >= 1 );
    230 
    231                 //      thenb = branches.front();
    232                 //      branches.pop_front();
    233                 //      if ( ! branches.empty() ) {
    234                 //              elseb = branches.front();
    235                 //              branches.pop_front();
    236                 //      } // if
    237                 //      return new IfStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), thenb, elseb );
    238                 // }
    239                 assert( false );
    240           case Switch:
    241                 // return new SwitchStmt( labs, maybeBuild<Expression>(get_control()), branches );
    242                 assert( false );
    243           case Case:
    244                 //return new CaseStmt( labs, maybeBuild<Expression>(get_control() ), branches );
    245                 assert( false );
    246           case Default:
    247                 //return new CaseStmt( labs, 0, branches, true );
    248                 assert( false );
    249           case While:
    250                 // assert( branches.size() == 1 );
    251                 // return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front() );
    252                 assert( false );
    253           case Do:
    254                 // assert( branches.size() == 1 );
    255                 // return new WhileStmt( labs, notZeroExpr( maybeBuild<Expression>(get_control()) ), branches.front(), true );
    256                 assert( false );
    257           case For:
    258                 // {
    259                 //      assert( branches.size() == 1 );
    260 
    261                 //      ForCtlExprNode *ctl = dynamic_cast<ForCtlExprNode *>( get_control() );
    262                 //      assert( ctl != 0 );
    263 
    264                 //      std::list<Statement *> init;
    265                 //      if ( ctl->get_init() != 0 ) {
    266                 //              buildList( ctl->get_init(), init );
    267                 //      } // if
    268 
    269                 //      Expression *cond = 0;
    270                 //      if ( ctl->get_condition() != 0 )
    271                 //              cond = notZeroExpr( maybeBuild<Expression>(ctl->get_condition()) );
    272 
    273                 //      Expression *incr = 0;
    274                 //      if ( ctl->get_change() != 0 )
    275                 //              incr = maybeBuild<Expression>(ctl->get_change());
    276 
    277                 //      return new ForStmt( labs, init, cond, incr, branches.front() );
    278                 // }
    279                 assert( false );
    280           case Goto:
    281                 // {
    282                 //      if ( get_target() == "" ) {                                     // computed goto
    283                 //              assert( get_control() != 0 );
    284                 //              return new BranchStmt( labs, maybeBuild<Expression>(get_control()), BranchStmt::Goto );
    285                 //      } // if
    286 
    287                 //      return new BranchStmt( labs, get_target(), BranchStmt::Goto );
    288                 // }
    289                 assert( false );
    290           case Break:
    291                 // return new BranchStmt( labs, get_target(), BranchStmt::Break );
    292                 assert( false );
    293           case Continue:
    294                 // return new BranchStmt( labs, get_target(), BranchStmt::Continue );
    295                 assert( false );
    296           case Return:
    297           case Throw :
    298                 // buildList( get_control(), exps );
    299                 // if ( exps.size() ==0 )
    300                 //      return new ReturnStmt( labs, 0, type == Throw );
    301                 // if ( exps.size() > 0 )
    302                 //      return new ReturnStmt( labs, exps.back(), type == Throw );
    303                 assert( false );
    304           case Try:
    305                 {
    306                         assert( branches.size() >= 0 );
    307                         CompoundStmt *tryBlock = dynamic_cast<CompoundStmt *>( branches.front());
    308                         branches.pop_front();
    309                         FinallyStmt *finallyBlock = 0;
    310                         if ( ( finallyBlock = dynamic_cast<FinallyStmt *>( branches.back())) ) {
    311                                 branches.pop_back();
    312                         } // if
    313                         return new TryStmt( labs, tryBlock, branches, finallyBlock );
    314                 }
    315           case Catch:
    316                 {
    317                         assert( branches.size() == 1 );
    318 
    319                         return new CatchStmt( labs, maybeBuild< Declaration >( decl ), branches.front(), isCatchRest );
    320                 }
    321           case Finally:
    322                 {
    323                         assert( branches.size() == 1 );
    324                         CompoundStmt *block = dynamic_cast<CompoundStmt *>( branches.front() );
    325                         assert( block != 0 );
    326 
    327                         return new FinallyStmt( labs, block );
    328                 }
    329           case Asm:
    330                 assert( false );
    331           default:
    332                 // shouldn't be here
    333                 return 0;
    334         } // switch
    335 }
    336 
    33770Statement *build_expr( ExpressionNode *ctl ) {
    338         Expression *e = maybeBuild< Expression >( ctl );
     71        Expression *e = maybeMoveBuild< Expression >( ctl );
    33972
    34073        if ( e )
     
    34679Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {
    34780        Statement *thenb, *elseb = 0;
    348         std::list<Statement *> branches;
    349         buildList<Statement, StatementNode>( then_stmt, branches );
     81        std::list< Statement * > branches;
     82        buildMoveList< Statement, StatementNode >( then_stmt, branches );
    35083        assert( branches.size() == 1 );
    35184        thenb = branches.front();
    35285
    35386        if ( else_stmt ) {
    354                 std::list<Statement *> branches;
    355                 buildList<Statement, StatementNode>( else_stmt, branches );
     87                std::list< Statement * > branches;
     88                buildMoveList< Statement, StatementNode >( else_stmt, branches );
    35689                assert( branches.size() == 1 );
    35790                elseb = branches.front();
    35891        } // if
    359         return new IfStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), thenb, elseb );
     92        return new IfStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), thenb, elseb );
    36093}
    36194
    36295Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
    363         std::list<Statement *> branches;
    364         buildList<Statement, StatementNode>( stmt, branches );
     96        std::list< Statement * > branches;
     97        buildMoveList< Statement, StatementNode >( stmt, branches );
    36598        assert( branches.size() >= 0 );                                         // size == 0 for switch (...) {}, i.e., no declaration or statements
    366         return new SwitchStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     99        return new SwitchStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    367100}
    368101Statement *build_case( ExpressionNode *ctl ) {
    369         std::list<Statement *> branches;
    370         return new CaseStmt( noLabels, maybeBuild<Expression>(ctl), branches );
     102        std::list< Statement * > branches;
     103        return new CaseStmt( noLabels, maybeMoveBuild< Expression >(ctl), branches );
    371104}
    372105Statement *build_default() {
    373         std::list<Statement *> branches;
     106        std::list< Statement * > branches;
    374107        return new CaseStmt( noLabels, nullptr, branches, true );
    375108}
    376109
    377110Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {
    378         std::list<Statement *> branches;
    379         buildList<Statement, StatementNode>( stmt, branches );
    380         assert( branches.size() == 1 );
    381         return new WhileStmt( noLabels, notZeroExpr( maybeBuild<Expression>(ctl) ), branches.front(), kind );
     111        std::list< Statement * > branches;
     112        buildMoveList< Statement, StatementNode >( stmt, branches );
     113        assert( branches.size() == 1 );
     114        return new WhileStmt( noLabels, notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );
    382115}
    383116
    384117Statement *build_for( ForCtl *forctl, StatementNode *stmt ) {
    385         std::list<Statement *> branches;
    386         buildList<Statement, StatementNode>( stmt, branches );
    387         assert( branches.size() == 1 );
    388 
    389         std::list<Statement *> init;
     118        std::list< Statement * > branches;
     119        buildMoveList< Statement, StatementNode >( stmt, branches );
     120        assert( branches.size() == 1 );
     121
     122        std::list< Statement * > init;
    390123        if ( forctl->init != 0 ) {
    391                 buildList( forctl->init, init );
     124                buildMoveList( forctl->init, init );
    392125        } // if
    393126
    394127        Expression *cond = 0;
    395128        if ( forctl->condition != 0 )
    396                 cond = notZeroExpr( maybeBuild<Expression>(forctl->condition) );
     129                cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) );
    397130
    398131        Expression *incr = 0;
    399132        if ( forctl->change != 0 )
    400                 incr = maybeBuild<Expression>(forctl->change);
     133                incr = maybeMoveBuild< Expression >(forctl->change);
    401134
    402135        delete forctl;
     
    404137}
    405138
    406 Statement *build_branch( std::string identifier, BranchStmt::Type kind ) {
    407         return new BranchStmt( noLabels, identifier, kind );
     139Statement *build_branch( BranchStmt::Type kind ) {
     140        Statement * ret = new BranchStmt( noLabels, "", kind );
     141        return ret;
     142}
     143Statement *build_branch( std::string *identifier, BranchStmt::Type kind ) {
     144        Statement * ret = new BranchStmt( noLabels, *identifier, kind );
     145        delete identifier;                                                                      // allocated by lexer
     146        return ret;
    408147}
    409148Statement *build_computedgoto( ExpressionNode *ctl ) {
    410         return new BranchStmt( noLabels, maybeBuild<Expression>(ctl), BranchStmt::Goto );
     149        return new BranchStmt( noLabels, maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    411150}
    412151
    413152Statement *build_return( ExpressionNode *ctl ) {
    414         std::list<Expression *> exps;
    415         buildList( ctl, exps );
     153        std::list< Expression * > exps;
     154        buildMoveList( ctl, exps );
    416155        return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr );
    417156}
    418157Statement *build_throw( ExpressionNode *ctl ) {
    419         std::list<Expression *> exps;
    420         buildList( ctl, exps );
    421         return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true );
    422 }
    423 
    424 
    425 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {}
    426 
    427 CompoundStmtNode::CompoundStmtNode( const string *name_ ) : StatementNode( name_ ), first( 0 ), last( 0 ) {}
    428 
    429 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ) : first( stmt ) {
    430         if ( first ) {
    431                 last = ( StatementNode *)( stmt->get_last());
    432         } else {
    433                 last = 0;
    434         } // if
    435 }
    436 
    437 CompoundStmtNode::~CompoundStmtNode() {
    438         delete first;
    439 }
    440 
    441 void CompoundStmtNode::add_statement( StatementNode *stmt ) {
    442         if ( stmt != 0 ) {
    443                 last->set_link( stmt );
    444                 last = ( StatementNode *)( stmt->get_link());
    445         } // if
    446 }
    447 
    448 void CompoundStmtNode::print( ostream &os, int indent ) const {
    449         if ( first ) {
    450                 first->printList( os, indent+2 );
    451         } // if
    452 }
    453 
    454 Statement *CompoundStmtNode::build() const {
    455         std::list<Label> labs;
    456         const std::list<std::string> &labels = get_labels();
    457 
    458         if ( ! labels.empty() ) {
    459                 std::back_insert_iterator< std::list<Label> > lab_it( labs );
    460                 copy( labels.begin(), labels.end(), lab_it );
    461         } // if
    462 
    463         CompoundStmt *cs = new CompoundStmt( labs );
    464         buildList( first, cs->get_kids() );
     158        std::list< Expression * > exps;
     159        buildMoveList( ctl, exps );
     160        assertf( exps.size() < 2, "This means we are leaking memory");
     161        return new ReturnStmt( noLabels, !exps.empty() ? exps.back() : nullptr, true );
     162}
     163
     164Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {
     165        std::list< Statement * > branches;
     166        buildMoveList< Statement, StatementNode >( catch_stmt, branches );
     167        CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
     168        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
     169        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
     170}
     171Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) {
     172        std::list< Statement * > branches;
     173        buildMoveList< Statement, StatementNode >( stmt, branches );
     174        assert( branches.size() == 1 );
     175        return new CatchStmt( noLabels, maybeMoveBuild< Declaration >(decl), branches.front(), catchAny );
     176}
     177Statement *build_finally( StatementNode *stmt ) {
     178        std::list< Statement * > branches;
     179        buildMoveList< Statement, StatementNode >( stmt, branches );
     180        assert( branches.size() == 1 );
     181        return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) );
     182}
     183
     184Statement *build_compound( StatementNode *first ) {
     185        CompoundStmt *cs = new CompoundStmt( noLabels );
     186        buildMoveList( first, cs->get_kids() );
    465187        return cs;
    466188}
    467189
    468 
    469 AsmStmtNode::AsmStmtNode( Type t, bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) :
    470         StatementNode( t ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ) {
    471         if ( gotolabels ) {
    472                 this->gotolabels = gotolabels->get_labels();
    473                 delete gotolabels;
    474         } // if
    475 }
    476 
    477 AsmStmtNode::~AsmStmtNode() {
    478         delete output; delete input; delete clobber;
    479 }
    480 
    481 void AsmStmtNode::print( std::ostream &os, int indent ) const {
    482         StatementNode::print( os, indent );                                     // print statement labels
    483         os << string( indent + ParseNode::indent_by, ' ' ) << "volatile:" << voltile << endl;
    484         if ( instruction ) {
    485                 os << string( indent + ParseNode::indent_by, ' ' ) << "Instruction:" << endl;
    486 //              instruction->printList( os, indent + 2 * ParseNode::indent_by );
    487         } // if
    488         if ( output ) {
    489                 os << string( indent + ParseNode::indent_by, ' ' ) << "Output:" << endl;
    490                 output->printList( os, indent + 2 * ParseNode::indent_by );
    491         } // if
    492         if ( input ) {
    493                 os << string( indent + ParseNode::indent_by, ' ' ) << "Input:" << endl;
    494                 input->printList( os, indent + 2 * ParseNode::indent_by );
    495         } // if
    496         if ( clobber ) {
    497                 os << string( indent + ParseNode::indent_by, ' ' ) << "Clobber:" << endl;
    498 //              clobber->printList( os, indent + 2 * ParseNode::indent_by );
    499         } // if
    500         if ( ! gotolabels.empty() ) {
    501                 os << string( indent + ParseNode::indent_by, ' ' ) << "Goto Labels:" << endl;
    502                 os << string( indent + 2 * ParseNode::indent_by, ' ' );
    503                 for ( std::list<Label>::const_iterator i = gotolabels.begin();; ) {
    504                         os << *i;
    505                         i++;
    506                   if ( i == gotolabels.end() ) break;
    507                         os << ", ";
    508                 }
    509                 os << endl;
    510         } // if
    511 }
    512 
    513 Statement *AsmStmtNode::build() const {
    514         std::list<Label> labs;
    515 
    516         if ( ! get_labels().empty() ) {
    517                 std::back_insert_iterator< std::list<Label> > lab_it( labs );
    518                 copy( get_labels().begin(), get_labels().end(), lab_it );
    519         } // if
    520 
     190Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {
    521191        std::list< Expression * > out, in;
    522192        std::list< ConstantExpr * > clob;
    523         buildList( output, out );
    524         buildList( input, in );
    525         buildList( clobber, clob );
    526         std::list< Label > gotolabs = gotolabels;
    527         return new AsmStmt( labs, voltile, instruction, out, in, clob, gotolabs );
     193
     194        buildMoveList( output, out );
     195        buildMoveList( input, in );
     196        buildMoveList( clobber, clob );
     197        return new AsmStmt( noLabels, voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    528198}
    529199
Note: See TracChangeset for help on using the changeset viewer.