Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/StatementNode.cc

    r59db689 r843054c2  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  6 23:25:41 2015
    13 // Update Count     : 19
     12// Last Modified On : Sat May 16 15:10:45 2015
     13// Update Count     : 7
    1414//
    1515
     
    3636StatementNode::StatementNode() : ParseNode(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    3737
    38 StatementNode::StatementNode( const string *name_ ) : ParseNode( name_ ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
     38StatementNode::StatementNode( 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                         } // if
     51                        }
    5252                } else {
    5353                        if ( decl->get_link() ) {
    5454                                next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) );
    5555                                decl->set_next( 0 );
    56                         } // if
     56                        }
    5757                        this->decl = decl;
    58                 } // if
    59         } // if
     58                }
     59        }
    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         } // if
     100        }
    101101        newnode->decl = maybeClone( decl );
    102102        return newnode;
     
    125125}
    126126
    127 StatementNode *StatementNode::add_label( const std::string *l ) {
     127StatementNode *StatementNode::add_label( std::string *l ) {
    128128        if ( l != 0 ) {
    129129                if ( labels == 0 )
     
    132132                labels->push_front(*l );
    133133                delete l;
    134         } // if
     134        }
    135135        return this;
    136136}
     
    151151                else
    152152                        block->set_link( stmt );
    153         } // if
     153        }
    154154        return this;
    155155}
     
    165165                        else
    166166                                block->set_link( stmt );
    167         } // if
     167        }
    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 << string( indent, ' ' );
     176                        os << '\r' << string( indent, ' ');
    177177                        for ( i = labels->begin(); i != labels->end(); i++ )
    178178                                os << *i << ":";
    179179                        os << endl;
    180                 } // if
    181         } // if
     180                }
    182181
    183182        switch ( type ) {
     
    194193                break;
    195194          default:
    196                 os << string( indent, ' ' ) << StatementNode::StType[type] << endl;
     195                os << '\r' << string( indent, ' ') << StatementNode::StType[type] << endl;
    197196                if ( type == Catch ) {
    198197                        if ( decl ) {
    199                                 os << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
     198                                os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
    200199                                decl->print( os, indent + 2*ParseNode::indent_by );
    201200                        } else if ( isCatchRest ) {
    202                                 os << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
     201                                os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
    203202                        } else {
    204203                                ; // should never reach here
    205                         } // if
    206                 } // if
     204                        }
     205                }
    207206                if ( control ) {
    208                         os << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;
     207                        os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;
    209208                        control->printList( os, indent + 2*ParseNode::indent_by );
    210                 } // if
     209                }
    211210                if ( block ) {
    212                         os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
     211                        os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
    213212                        block->printList( os, indent + 2*ParseNode::indent_by ); 
    214                 } // if
     213                }
    215214                if ( target ) {
    216                         os << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
    217                 } // if
     215                        os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
     216                }
    218217                break;
    219         } // switch
     218        }
    220219}
    221220
     
    228227                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    229228                copy( labels->begin(), labels->end(), lab_it );
    230         } // if
     229        }
    231230
    232231        // try {
     
    255254                                elseb = branches.front();
    256255                                branches.pop_front();
    257                         } // if
     256                        }
    258257                        return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb );
    259258                }
     
    300299                                assert( get_control() != 0 );
    301300                                return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto );
    302                         } // if
     301                        }
    303302
    304303                        return new BranchStmt( labs, get_target(), BranchStmt::Goto );
     
    323322                        if ( ( finallyBlock = dynamic_cast<FinallyStmt *>( branches.back())) ) {
    324323                                branches.pop_back();
    325                         } // if
     324                        }
    326325                        return new TryStmt( labs, tryBlock, branches, finallyBlock );
    327326                }
     
    343342                // shouldn't be here
    344343                return 0;
    345         } // switch
    346 }
    347 
    348 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {}
    349 
    350 CompoundStmtNode::CompoundStmtNode( const string *name_ ) : StatementNode( name_ ), first( 0 ), last( 0 ) {}
    351 
    352 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ) : first( stmt ) {
     344        }
     345}
     346
     347CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {
     348}
     349
     350CompoundStmtNode::CompoundStmtNode( string *name_) : StatementNode(*name_), first( 0 ), last( 0 ) {
     351}
     352
     353CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ): first( stmt ) {
    353354        if ( first ) {
    354355                last = ( StatementNode *)( stmt->get_last());
    355356        } else {
    356357                last = 0;
    357         } // if
     358        }
    358359}
    359360
     
    366367                last->set_link( stmt );
    367368                last = ( StatementNode *)( stmt->get_link());
    368         } // if
     369        }
    369370}
    370371
     
    372373        if ( first ) {
    373374                first->printList( os, indent+2 );
    374         } // if
     375        }
    375376}
    376377
     
    382383                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    383384                copy( labels->begin(), labels->end(), lab_it );
    384         } // if
     385        }
    385386
    386387        CompoundStmt *cs = new CompoundStmt( labs );
     
    390391
    391392void NullStmtNode::print( ostream &os, int indent ) const {
    392         os << string( indent, ' ' ) << "Null Statement:" << endl;
     393        os << "\r" << string( indent, ' ') << "Null Statement:" << endl;
    393394}
    394395
Note: See TracChangeset for help on using the changeset viewer.