Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r843054c2 r59db689  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:10:45 2015
    13 // Update Count     : 7
     12// Last Modified On : Sat Jun  6 23:25:41 2015
     13// Update Count     : 19
    1414//
    1515
     
    3636StatementNode::StatementNode() : ParseNode(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    3737
    38 StatementNode::StatementNode( string name_) : ParseNode( name_), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
     38StatementNode::StatementNode( const string *name_ ) : ParseNode( name_ ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    3939
    4040StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), isCatchRest ( false ) {
     
    4949                                next->set_next( new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ) );
    5050                                decl->set_next( 0 );
    51                         }
     51                        } // if
    5252                } else {
    5353                        if ( decl->get_link() ) {
    5454                                next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) );
    5555                                decl->set_next( 0 );
    56                         }
     56                        } // if
    5757                        this->decl = decl;
    58                 }
    59         }
     58                } // if
     59        } // if
    6060}
    6161
     
    6767
    6868StatementNode::StatementNode( Type t, string *_target ) :
    69                 type( t ), control( 0 ), block( 0 ),   labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {}
     69                type( t ), control( 0 ), block( 0 ), labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {}
    7070
    7171StatementNode::~StatementNode() {
     
    9898        } else {
    9999                newnode->target = 0;
    100         }
     100        } // if
    101101        newnode->decl = maybeClone( decl );
    102102        return newnode;
     
    125125}
    126126
    127 StatementNode *StatementNode::add_label( std::string *l ) {
     127StatementNode *StatementNode::add_label( const std::string *l ) {
    128128        if ( l != 0 ) {
    129129                if ( labels == 0 )
     
    132132                labels->push_front(*l );
    133133                delete l;
    134         }
     134        } // if
    135135        return this;
    136136}
     
    151151                else
    152152                        block->set_link( stmt );
    153         }
     153        } // if
    154154        return this;
    155155}
     
    165165                        else
    166166                                block->set_link( stmt );
    167         }
     167        } // if
    168168        return this;
    169169}
    170170
    171171void StatementNode::print( std::ostream &os, int indent ) const {
    172         if ( labels != 0 )
     172        if ( labels != 0 ) {
    173173                if ( ! labels->empty()) {
    174174                        std::list<std::string>::const_iterator i;
    175175
    176                         os << '\r' << string( indent, ' ');
     176                        os << string( indent, ' ' );
    177177                        for ( i = labels->begin(); i != labels->end(); i++ )
    178178                                os << *i << ":";
    179179                        os << endl;
    180                 }
     180                } // if
     181        } // if
    181182
    182183        switch ( type ) {
     
    193194                break;
    194195          default:
    195                 os << '\r' << string( indent, ' ') << StatementNode::StType[type] << endl;
     196                os << string( indent, ' ' ) << StatementNode::StType[type] << endl;
    196197                if ( type == Catch ) {
    197198                        if ( decl ) {
    198                                 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
     199                                os << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
    199200                                decl->print( os, indent + 2*ParseNode::indent_by );
    200201                        } else if ( isCatchRest ) {
    201                                 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
     202                                os << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
    202203                        } else {
    203204                                ; // should never reach here
    204                         }
    205                 }
     205                        } // if
     206                } // if
    206207                if ( control ) {
    207                         os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;
     208                        os << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;
    208209                        control->printList( os, indent + 2*ParseNode::indent_by );
    209                 }
     210                } // if
    210211                if ( block ) {
    211                         os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
     212                        os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
    212213                        block->printList( os, indent + 2*ParseNode::indent_by ); 
    213                 }
     214                } // if
    214215                if ( target ) {
    215                         os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
    216                 }
     216                        os << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
     217                } // if
    217218                break;
    218         }
     219        } // switch
    219220}
    220221
     
    227228                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    228229                copy( labels->begin(), labels->end(), lab_it );
    229         }
     230        } // if
    230231
    231232        // try {
     
    254255                                elseb = branches.front();
    255256                                branches.pop_front();
    256                         }
     257                        } // if
    257258                        return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb );
    258259                }
     
    299300                                assert( get_control() != 0 );
    300301                                return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto );
    301                         }
     302                        } // if
    302303
    303304                        return new BranchStmt( labs, get_target(), BranchStmt::Goto );
     
    322323                        if ( ( finallyBlock = dynamic_cast<FinallyStmt *>( branches.back())) ) {
    323324                                branches.pop_back();
    324                         }
     325                        } // if
    325326                        return new TryStmt( labs, tryBlock, branches, finallyBlock );
    326327                }
     
    342343                // shouldn't be here
    343344                return 0;
    344         }
    345 }
    346 
    347 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {
    348 }
    349 
    350 CompoundStmtNode::CompoundStmtNode( string *name_) : StatementNode(*name_), first( 0 ), last( 0 ) {
    351 }
    352 
    353 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ): first( stmt ) {
     345        } // switch
     346}
     347
     348CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {}
     349
     350CompoundStmtNode::CompoundStmtNode( const string *name_ ) : StatementNode( name_ ), first( 0 ), last( 0 ) {}
     351
     352CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ) : first( stmt ) {
    354353        if ( first ) {
    355354                last = ( StatementNode *)( stmt->get_last());
    356355        } else {
    357356                last = 0;
    358         }
     357        } // if
    359358}
    360359
     
    367366                last->set_link( stmt );
    368367                last = ( StatementNode *)( stmt->get_link());
    369         }
     368        } // if
    370369}
    371370
     
    373372        if ( first ) {
    374373                first->printList( os, indent+2 );
    375         }
     374        } // if
    376375}
    377376
     
    383382                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    384383                copy( labels->begin(), labels->end(), lab_it );
    385         }
     384        } // if
    386385
    387386        CompoundStmt *cs = new CompoundStmt( labs );
     
    391390
    392391void NullStmtNode::print( ostream &os, int indent ) const {
    393         os << "\r" << string( indent, ' ') << "Null Statement:" << endl;
     392        os << string( indent, ' ' ) << "Null Statement:" << endl;
    394393}
    395394
Note: See TracChangeset for help on using the changeset viewer.