Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r843054c2 rde62360d  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 10:55:19 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue Jun 23 11:42:09 2015
     13// Update Count     : 21
    1414//
    1515
     
    3030Statement::Statement( std::list<Label> _labels ) : labels(_labels ) {}
    3131
    32 void Statement::print( std::ostream &, int indent ) {}
     32void Statement::print( std::ostream &, int indent ) const {}
    3333
    3434Statement::~Statement() {}
     
    3838ExprStmt::~ExprStmt() {}
    3939
    40 void ExprStmt::print( std::ostream &os, int indent ) {
    41         os << "\r" << string(indent, ' ') << "Expression Statement:" << endl;
     40void ExprStmt::print( std::ostream &os, int indent ) const {
     41        os << string( indent, ' ' ) << "Expression Statement:" << endl;
    4242        expr->print( os, indent + 2 );
    4343}
     
    4646
    4747BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) :
    48         Statement( labels ), target(_target ), type(_type ) {
     48        Statement( labels ), originalTarget(_target ), target(_target ), type(_type ) {
    4949        //actually this is a syntactic error signaled by the parser
    5050        if ( type == BranchStmt::Goto && target.size() == 0 )
     
    5858}
    5959
    60 void BranchStmt::print( std::ostream &os, int indent ) {
    61         os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ;
     60void BranchStmt::print( std::ostream &os, int indent ) const {
     61        os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ;
    6262}
    6363
     
    6868}
    6969
    70 void ReturnStmt::print( std::ostream &os, int indent ) {
    71         os << "\r" << std::string( indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
     70void ReturnStmt::print( std::ostream &os, int indent ) const {
     71        os << std::string( indent, ' ' ) << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
    7272        if ( expr != 0 ) expr->print( os );
    7373        os << endl;
     
    7979IfStmt::~IfStmt() {}
    8080
    81 void IfStmt::print( std::ostream &os, int indent ) {
    82         os << "\r" << string( indent, ' ') << "If on condition: " << endl ;
     81void IfStmt::print( std::ostream &os, int indent ) const {
     82        os << string( indent, ' ' ) << "If on condition: " << endl ;
    8383        condition->print( os, indent + 4 );
    8484
    85         os << string( indent, ' ') << ".... and branches: " << endl;
     85        os << string( indent, ' ' ) << ".... and branches: " << endl;
    8686
    8787        thenPart->print( os, indent + 4 );
     
    103103void SwitchStmt::add_case( CaseStmt *c ) {}
    104104
    105 void SwitchStmt::print( std::ostream &os, int indent ) {
    106         os << "\r" << string( indent, ' ') << "Switch on condition: ";
     105void SwitchStmt::print( std::ostream &os, int indent ) const {
     106        os << string( indent, ' ' ) << "Switch on condition: ";
    107107        condition->print( os );
    108108        os << endl;
    109109
    110110        // branches
    111         std::list<Statement *>::iterator i;
     111        std::list<Statement *>::const_iterator i;
    112112        for ( i = branches.begin(); i != branches.end(); i++)
    113                 (*i )->print( os, indent + 4 );
     113                (*i)->print( os, indent + 4 );
    114114
    115115        //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));
     
    126126}
    127127
    128 void CaseStmt::print( std::ostream &os, int indent ) {
    129         os << "\r" << string( indent, ' ');
    130 
    131         if ( isDefault())
     128CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) {
     129        return new CaseStmt( labels, 0, branches, true );
     130}
     131
     132void CaseStmt::print( std::ostream &os, int indent ) const {
     133        os << string( indent, ' ' );
     134
     135        if ( isDefault() )
    132136                os << "Default ";
    133137        else {
     
    138142        os << endl;
    139143
    140         std::list<Statement *>::iterator i;
     144        std::list<Statement *>::const_iterator i;
    141145        for ( i = stmts.begin(); i != stmts.end(); i++)
    142146                (*i )->print( os, indent + 4 );
     
    154158void ChooseStmt::add_case( CaseStmt *c ) {}
    155159
    156 void ChooseStmt::print( std::ostream &os, int indent ) {
    157         os << "\r" << string( indent, ' ') << "Choose on condition: ";
     160void ChooseStmt::print( std::ostream &os, int indent ) const {
     161        os << string( indent, ' ' ) << "Choose on condition: ";
    158162        condition->print( os );
    159163        os << endl;
    160164
    161165        // branches
    162         std::list<Statement *>::iterator i;
     166        std::list<Statement *>::const_iterator i;
    163167        for ( i = branches.begin(); i != branches.end(); i++)
    164168                (*i )->print( os, indent + 4 );
     
    167171}
    168172
    169 void FallthruStmt::print( std::ostream &os, int indent ) {
    170         os << "\r" << string( indent, ' ') << "Fall-through statement" << endl;
     173void FallthruStmt::print( std::ostream &os, int indent ) const {
     174        os << string( indent, ' ' ) << "Fall-through statement" << endl;
    171175}
    172176
     
    179183}
    180184
    181 void WhileStmt::print( std::ostream &os, int indent ) {
    182         os << "\r" << string( indent, ' ') << "While on condition: " << endl ;
     185void WhileStmt::print( std::ostream &os, int indent ) const {
     186        os << string( indent, ' ' ) << "While on condition: " << endl ;
    183187        condition->print( os, indent + 4 );
    184188
    185         os << string( indent, ' ') << ".... with body: " << endl;
     189        os << string( indent, ' ' ) << ".... with body: " << endl;
    186190
    187191        if ( body != 0 ) body->print( os, indent + 4 );
     
    199203}
    200204
    201 void ForStmt::print( std::ostream &os, int indent ) {
    202         os << "\r" << string( indent, ' ') << "For Statement" << endl ;
    203 
    204         os << "\r" << string( indent + 2, ' ') << "initialization: \n";
     205void ForStmt::print( std::ostream &os, int indent ) const {
     206        os << string( indent, ' ' ) << "Labels: {";
     207        for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
     208                os << *it << ",";
     209        }
     210        os << "}" << endl;
     211
     212        os << string( indent, ' ' ) << "For Statement" << endl ;
     213
     214        os << string( indent + 2, ' ' ) << "initialization: \n";
    205215        if ( initialization != 0 )
    206216                initialization->print( os, indent + 4 );
    207217
    208         os << "\n\r" << string( indent + 2, ' ') << "condition: \n";
     218        os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
    209219        if ( condition != 0 )
    210220                condition->print( os, indent + 4 );
    211221
    212         os << "\n\r" << string( indent + 2, ' ') << "increment: \n";
     222        os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
    213223        if ( increment != 0 )
    214224                increment->print( os, indent + 4 );
    215225
    216         os << "\n\r" << string( indent + 2, ' ') << "statement block: \n";
     226        os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
    217227        if ( body != 0 )
    218228                body->print( os, indent + 4 );
     
    235245}
    236246
    237 void TryStmt::print( std::ostream &os, int indent ) {
    238         os << "\r" << string( indent, ' ') << "Try Statement" << endl;
    239         os << string( indent + 2, ' ') << "with block: " << endl;
     247void TryStmt::print( std::ostream &os, int indent ) const {
     248        os << string( indent, ' ' ) << "Try Statement" << endl;
     249        os << string( indent + 2, ' ' ) << "with block: " << endl;
    240250        block->print( os, indent + 4 );
    241251
    242252        // handlers
    243         os << string( indent + 2, ' ') << "and handlers: " << endl;
    244         std::list<Statement *>::iterator i;
    245         for ( i = handlers.begin(); i != handlers.end(); i++)
     253        os << string( indent + 2, ' ' ) << "and handlers: " << endl;
     254        for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++)
    246255                (*i )->print( os, indent + 4 );
    247256
    248257        // finally block
    249258        if ( finallyBlock != 0 ) {
    250                 os << string( indent + 2, ' ') << "Finally block: " << endl;
     259                os << string( indent + 2, ' ' ) << "Finally block: " << endl;
    251260                finallyBlock->print( os, indent + 4 );
    252261        } // if
     
    262271}
    263272
    264 void CatchStmt::print( std::ostream &os, int indent ) {
    265         os << "\r" << string( indent, ' ') << "Catch Statement" << endl;
    266 
    267         os << "\r" << string( indent, ' ') << "... catching" << endl;
     273void CatchStmt::print( std::ostream &os, int indent ) const {
     274        os << string( indent, ' ' ) << "Catch Statement" << endl;
     275
     276        os << string( indent, ' ' ) << "... catching" << endl;
    268277        if ( decl ) {
    269278                decl->printShort( os, indent + 4 );
    270279                os << endl;
    271280        } else if ( catchRest )
    272                 os << "\r" << string( indent + 4 , ' ') << "the rest" << endl;
     281                os << string( indent + 4 , ' ' ) << "the rest" << endl;
    273282        else
    274                 os << "\r" << string( indent + 4 , ' ') << ">>> Error:  this catch clause must have a declaration <<<" << endl;
     283                os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl;
    275284}
    276285
     
    284293}
    285294
    286 void FinallyStmt::print( std::ostream &os, int indent ) {
    287         os << "\r" << string( indent, ' ') << "Finally Statement" << endl;
    288         os << string( indent + 2, ' ') << "with block: " << endl;
     295void FinallyStmt::print( std::ostream &os, int indent ) const {
     296        os << string( indent, ' ' ) << "Finally Statement" << endl;
     297        os << string( indent + 2, ' ' ) << "with block: " << endl;
    289298        block->print( os, indent + 4 );
    290299}
     
    294303NullStmt::~NullStmt() {}
    295304
    296 void NullStmt::print( std::ostream &os, int indent ) {
    297         os << "\r" << string( indent, ' ') << "Null Statement" << endl ;
     305void NullStmt::print( std::ostream &os, int indent ) const {
     306        os << string( indent, ' ' ) << "Null Statement" << endl ;
    298307}
    299308
Note: See TracChangeset for help on using the changeset viewer.