Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r1db21619 r59db689  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 16 16:20:24 2015
    13 // Update Count     : 30
     12// Last Modified On : Sat Jun  6 23:25:41 2015
     13// Update Count     : 19
    1414//
    1515
     
    7272        delete control;
    7373        delete block;
     74        delete labels;
    7475        delete target;
    7576        delete decl;
     
    102103}
    103104
     105void StatementNode::set_control( ExpressionNode *c ) {
     106        control = c;
     107}
     108
     109StatementNode * StatementNode::set_block( StatementNode *b ) {
     110        block = b;
     111
     112        return this;
     113}
     114
     115ExpressionNode *StatementNode::get_control() const {
     116        return control;
     117}
     118
     119StatementNode *StatementNode::get_block() const {
     120        return block;
     121}
     122
     123StatementNode::Type StatementNode::get_type() const {
     124        return type;
     125}
     126
    104127StatementNode *StatementNode::add_label( const std::string *l ) {
    105128        if ( l != 0 ) {
    106                 labels.push_front( *l );
     129                if ( labels == 0 )
     130                        labels = new std::list<std::string>();
     131
     132                labels->push_front(*l );
    107133                delete l;
    108134        } // if
    109135        return this;
    110136}
     137
     138std::list<std::string> *StatementNode::get_labels() const { return labels; }
    111139
    112140StatementNode *StatementNode::add_controlexp( ExpressionNode *e ) {
     
    142170
    143171void StatementNode::print( std::ostream &os, int indent ) const {
    144         if ( ! labels.empty()) {
    145                 std::list<std::string>::const_iterator i;
    146 
    147                 os << string( indent, ' ' );
    148                 for ( i = labels.begin(); i != labels.end(); i++ )
    149                         os << *i << ":";
    150                 os << endl;
     172        if ( labels != 0 ) {
     173                if ( ! labels->empty()) {
     174                        std::list<std::string>::const_iterator i;
     175
     176                        os << string( indent, ' ' );
     177                        for ( i = labels->begin(); i != labels->end(); i++ )
     178                                os << *i << ":";
     179                        os << endl;
     180                } // if
    151181        } // if
    152182
     
    195225        std::list<Label> labs;
    196226
    197         if ( ! labels.empty() ) {
     227        if ( labels != 0 ) {
    198228                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    199                 copy( labels.begin(), labels.end(), lab_it );
     229                copy( labels->begin(), labels->end(), lab_it );
    200230        } // if
    201231
     
    241271                        assert( ctl != 0 );
    242272
    243                         std::list<Statement *> init;
    244                         if ( ctl->get_init() != 0 ) {
    245                                 buildList( ctl->get_init(), init );
    246                         } // if
     273                        Statement *stmt = 0;
     274                        if ( ctl->get_init() != 0 )
     275                                stmt = ctl->get_init()->build();
    247276
    248277                        Expression *cond = 0;
     
    254283                                incr = ctl->get_change()->build();
    255284
    256                         return new ForStmt( labs, init, cond, incr, branches.front() );
     285                        return new ForStmt( labs, stmt, cond, incr, branches.front() );
    257286                }
    258287          case Switch:
     
    348377Statement *CompoundStmtNode::build() const {
    349378        std::list<Label> labs;
    350         const std::list<std::string> &labels = get_labels();
    351 
    352         if ( ! labels.empty() ) {
     379        std::list<std::string> *labels = get_labels();
     380
     381        if ( labels != 0 ) {
    353382                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    354                 copy( labels.begin(), labels.end(), lab_it );
     383                copy( labels->begin(), labels->end(), lab_it );
    355384        } // if
    356385
Note: See TracChangeset for help on using the changeset viewer.