Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r50377a4 r70d826cd  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:46:44 2017
    13 // Update Count     : 68
     12// Last Modified On : Thu Aug 17 16:17:20 2017
     13// Update Count     : 67
    1414//
    1515
     
    3434Statement::Statement( std::list<Label> labels ) : labels( labels ) {}
    3535
    36 void Statement::print( std::ostream & os, Indenter ) const {
    37         if ( ! labels.empty() ) {
    38                 os << "Labels: {";
    39                 for ( const Label & l : labels ) {
    40                         os << l << ",";
    41                 }
    42                 os << "}" << endl;
    43         }
    44 }
     36void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {}
    4537
    4638Statement::~Statement() {}
     
    5446}
    5547
    56 void ExprStmt::print( std::ostream &os, Indenter indent ) const {
    57         os << "Expression Statement:" << endl << indent+1;
    58         expr->print( os, indent+1 );
    59 }
    60 
    61 
    62 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
     48void ExprStmt::print( std::ostream &os, int indent ) const {
     49        os << "Expression Statement:" << endl << std::string( indent + 2, ' ' );
     50        expr->print( os, indent + 2 );
     51}
     52
     53
     54AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    6355
    6456AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
     
    7567}
    7668
    77 void AsmStmt::print( std::ostream &os, Indenter indent ) const {
     69void AsmStmt::print( std::ostream &os, int indent ) const {
    7870        os << "Assembler Statement:" << endl;
    79         os << indent+1 << "instruction: " << endl << indent;
    80         instruction->print( os, indent+1 );
     71        os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' );
     72        instruction->print( os, indent + 2 );
    8173        if ( ! output.empty() ) {
    82                 os << endl << indent+1 << "output: " << endl;
    83                 printAll( output, os, indent+1 );
     74                os << endl << std::string( indent, ' ' ) << "output: " << endl;
     75                printAll( output, os, indent + 2 );
    8476        } // if
    8577        if ( ! input.empty() ) {
    86                 os << indent+1 << "input: " << endl;
    87                 printAll( input, os, indent+1 );
     78                os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );
     79                printAll( input, os, indent + 2 );
    8880        } // if
    8981        if ( ! clobber.empty() ) {
    90                 os << indent+1 << "clobber: " << endl;
    91                 printAll( clobber, os, indent+1 );
     82                os << std::string( indent, ' ' ) << "clobber: " << endl;
     83                printAll( clobber, os, indent + 2 );
    9284        } // if
    9385}
     
    111103}
    112104
    113 void BranchStmt::print( std::ostream &os, Indenter indent ) const {
    114         os << "Branch (" << brType[type] << ")" << endl ;
    115         if ( target != "" ) os << indent+1 << "with target: " << target << endl;
    116         if ( originalTarget != "" ) os << indent+1 << "with original target: " << originalTarget << endl;
    117         if ( computedTarget != nullptr ) os << indent+1 << "with computed target: " << computedTarget << endl;
     105void BranchStmt::print( std::ostream &os, int indent ) const {
     106        os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ;
     107        if ( target != "" ) os << string( indent+2, ' ' ) << "with target: " << target << endl;
     108        if ( originalTarget != "" ) os << string( indent+2, ' ' ) << "with original target: " << originalTarget << endl;
     109        if ( computedTarget != nullptr ) os << string( indent+2, ' ' ) << "with computed target: " << computedTarget << endl;
    118110}
    119111
     
    126118}
    127119
    128 void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
    129         os << "Return Statement, returning: ";
    130         if ( expr != nullptr ) {
    131                 os << endl << indent+1;
    132                 expr->print( os, indent+1 );
     120void ReturnStmt::print( std::ostream &os, int indent ) const {
     121        os <<  "Return Statement, returning: ";
     122        if ( expr != 0 ) {
     123                os << endl << string( indent+2, ' ' );
     124                expr->print( os, indent + 2 );
    133125        }
    134126        os << endl;
     
    150142}
    151143
    152 void IfStmt::print( std::ostream &os, Indenter indent ) const {
    153         os << "If on condition: " << endl;
    154         os << indent+1;
    155         condition->print( os, indent+1 );
     144void IfStmt::print( std::ostream &os, int indent ) const {
     145        os << "If on condition: " << endl ;
     146        os << string( indent+4, ' ' );
     147        condition->print( os, indent + 4 );
    156148
    157149        if ( !initialization.empty() ) {
    158                 os << indent << "... with initialization: \n";
    159                 for ( const Statement * stmt : initialization ) {
    160                         os << indent+1;
    161                         stmt->print( os, indent+1 );
     150                os << string( indent + 2, ' ' ) << "initialization: \n";
     151                for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     152                        os << string( indent + 4, ' ' );
     153                        (*it)->print( os, indent + 4 );
    162154                }
    163155                os << endl;
    164156        }
    165157
    166         os << indent << "... then: " << endl;
    167 
    168         os << indent+1;
    169         thenPart->print( os, indent+1 );
     158        os << string( indent+2, ' ' ) << "... then: " << endl;
     159
     160        os << string( indent+4, ' ' );
     161        thenPart->print( os, indent + 4 );
    170162
    171163        if ( elsePart != 0 ) {
    172                 os << indent << "... else: " << endl;
    173                 os << indent+1;
    174                 elsePart->print( os, indent+1 );
     164                os << string( indent+2, ' ' ) << "... else: " << endl;
     165                os << string( indent+4, ' ' );
     166                elsePart->print( os, indent + 4 );
    175167        } // if
    176168}
    177169
    178 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, const std::list<Statement *> &statements ):
     170SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):
    179171        Statement( labels ), condition( condition ), statements( statements ) {
    180172}
     
    191183}
    192184
    193 void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
     185void SwitchStmt::print( std::ostream &os, int indent ) const {
    194186        os << "Switch on condition: ";
    195187        condition->print( os );
    196188        os << endl;
    197189
    198         for ( const Statement * stmt : statements ) {
    199                 stmt->print( os, indent+1 );
    200         }
    201 }
    202 
    203 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
     190        // statements
     191        std::list<Statement *>::const_iterator i;
     192        for ( i = statements.begin(); i != statements.end(); i++)
     193                (*i)->print( os, indent + 4 );
     194
     195        //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os ));
     196}
     197
     198CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
    204199        Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    205         if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition);
     200        if ( isDefault() && condition != 0 )
     201                throw SemanticError("default with conditions");
    206202}
    207203
     
    220216}
    221217
    222 void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    223         if ( isDefault() ) os << "Default ";
     218void CaseStmt::print( std::ostream &os, int indent ) const {
     219        os << string( indent, ' ' );
     220
     221        if ( isDefault() )
     222                os << "Default ";
    224223        else {
    225224                os << "Case ";
    226                 condition->print( os, indent );
     225                condition->print( os );
    227226        } // if
     227
    228228        os << endl;
    229229
    230         for ( Statement * stmt : stmts ) {
    231                 stmt->print( os, indent+1 );
    232         }
     230        std::list<Statement *>::const_iterator i;
     231        for ( i = stmts.begin(); i != stmts.end(); i++)
     232                (*i )->print( os, indent + 4 );
    233233}
    234234
     
    246246}
    247247
    248 void WhileStmt::print( std::ostream &os, Indenter indent ) const {
     248void WhileStmt::print( std::ostream &os, int indent ) const {
    249249        os << "While on condition: " << endl ;
    250         condition->print( os, indent+1 );
    251 
    252         os << indent << "... with body: " << endl;
    253 
    254         if ( body != 0 ) body->print( os, indent+1 );
     250        condition->print( os, indent + 4 );
     251
     252        os << string( indent, ' ' ) << ".... with body: " << endl;
     253
     254        if ( body != 0 ) body->print( os, indent + 4 );
    255255}
    256256
     
    272272}
    273273
    274 void ForStmt::print( std::ostream &os, Indenter indent ) const {
    275         Statement::print( os, indent ); // print labels
    276 
    277         os << "For Statement" << endl;
    278 
    279         if ( ! initialization.empty() ) {
    280                 os << indent << "... initialization: \n";
    281                 for ( Statement * stmt : initialization ) {
    282                         os << indent+1;
    283                         stmt->print( os, indent+1 );
    284                 }
    285         }
    286 
    287         if ( condition != nullptr ) {
    288                 os << indent << "... condition: \n" << indent+1;
    289                 condition->print( os, indent+1 );
    290         }
    291 
    292         if ( increment != nullptr ) {
    293                 os << "\n" << indent << "... increment: \n" << indent+1;
    294                 increment->print( os, indent+1 );
    295         }
    296 
     274void ForStmt::print( std::ostream &os, int indent ) const {
     275        os << "Labels: {";
     276        for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
     277                os << *it << ",";
     278        }
     279        os << "}" << endl;
     280
     281        os << string( indent, ' ' ) << "For Statement" << endl ;
     282
     283        os << string( indent + 2, ' ' ) << "initialization: \n";
     284        for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     285                os << string( indent + 4, ' ' );
     286                (*it)->print( os, indent + 4 );
     287        }
     288
     289        os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
     290        if ( condition != 0 ) {
     291                os << string( indent + 4, ' ' );
     292                condition->print( os, indent + 4 );
     293        }
     294
     295        os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
     296        if ( increment != 0 ) {
     297                os << string( indent + 4, ' ' );
     298                increment->print( os, indent + 4 );
     299        }
     300
     301        os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
    297302        if ( body != 0 ) {
    298                 os << "\n" << indent << "... with body: \n" << indent+1;
    299                 body->print( os, indent+1 );
    300         }
     303                os << string( indent + 4, ' ' );
     304                body->print( os, indent + 4 );
     305        }
     306
    301307        os << endl;
    302308}
     
    316322}
    317323
    318 void ThrowStmt::print( std::ostream &os, Indenter indent) const {
    319         if ( target ) os << "Non-Local ";
     324void ThrowStmt::print( std::ostream &os, int indent) const {
     325        if ( target ) {
     326                os << "Non-Local ";
     327        }
    320328        os << "Throw Statement, raising: ";
    321         expr->print(os, indent+1);
     329        expr->print(os, indent + 4);
    322330        if ( target ) {
    323                 os << "... at: ";
    324                 target->print(os, indent+1);
     331                os << "At: ";
     332                target->print(os, indent + 4);
    325333        }
    326334}
     
    340348}
    341349
    342 void TryStmt::print( std::ostream &os, Indenter indent ) const {
     350void TryStmt::print( std::ostream &os, int indent ) const {
    343351        os << "Try Statement" << endl;
    344         os << indent << "... with block:" << endl << indent+1;
    345         block->print( os, indent+1 );
     352        os << string( indent + 2, ' ' ) << "with block:" << endl;
     353        os << string( indent + 4, ' ' );
     354        block->print( os, indent + 4 );
    346355
    347356        // handlers
    348         os << indent << "... and handlers:" << endl;
    349         for ( const CatchStmt * stmt : handlers ) {
    350                 os << indent+1;
    351                 stmt->print( os, indent+1 );
     357        os << string( indent + 2, ' ' ) << "and handlers:" << endl;
     358        for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) {
     359                os << string( indent + 4, ' ' );
     360                (*i )->print( os, indent + 4 );
    352361        }
    353362
    354363        // finally block
    355364        if ( finallyBlock != 0 ) {
    356                 os << indent << "... and finally:" << endl << indent+1;
    357                 finallyBlock->print( os, indent+1 );
     365                os << string( indent + 2, ' ' ) << "and finally:" << endl;
     366                finallyBlock->print( os, indent + 4 );
    358367        } // if
    359368}
     
    361370CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
    362371        Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    363                 assertf( decl, "Catch clause must have a declaration." );
    364372}
    365373
     
    373381}
    374382
    375 void CatchStmt::print( std::ostream &os, Indenter indent ) const {
     383void CatchStmt::print( std::ostream &os, int indent ) const {
    376384        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
    377385
    378         os << indent << "... catching: ";
    379         decl->printShort( os, indent+1 );
    380         os << endl;
     386        os << string( indent + 2, ' ' ) << "... catching: ";
     387        if ( decl ) {
     388                decl->printShort( os, indent + 4 );
     389                os << endl;
     390        }
     391        else
     392                os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl;
    381393
    382394        if ( cond ) {
    383                 os << indent << "... with conditional:" << endl << indent+1;
    384                 cond->print( os, indent+1 );
    385         }
    386 
    387         os << indent << "... with block:" << endl;
    388         os << indent+1;
    389         body->print( os, indent+1 );
     395                os << string( indent + 2, ' ' ) << "with conditional:" << endl;
     396                os << string( indent + 4, ' ' );
     397                cond->print( os, indent + 4 );
     398        }
     399        else
     400                os << string( indent + 2, ' ' ) << "with no conditional" << endl;
     401
     402        os << string( indent + 2, ' ' ) << "with block:" << endl;
     403        os << string( indent + 4, ' ' );
     404        body->print( os, indent + 4 );
    390405}
    391406
     
    402417}
    403418
    404 void FinallyStmt::print( std::ostream &os, Indenter indent ) const {
     419void FinallyStmt::print( std::ostream &os, int indent ) const {
    405420        os << "Finally Statement" << endl;
    406         os << indent << "... with block:" << endl << indent+1;
    407         block->print( os, indent+1 );
     421        os << string( indent + 2, ' ' ) << "with block:" << endl;
     422        os << string( indent + 4, ' ' );
     423        block->print( os, indent + 4 );
    408424}
    409425
     
    449465}
    450466
    451 void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
     467void WaitForStmt::print( std::ostream &os, int indent ) const {
    452468        os << "Waitfor Statement" << endl;
    453         os << indent << "... with block:" << endl << indent+1;
     469        os << string( indent + 2, ' ' ) << "with block:" << endl;
     470        os << string( indent + 4, ' ' );
    454471        // block->print( os, indent + 4 );
    455472}
     
    458475NullStmt::NullStmt() : Statement( std::list<Label>() ) {}
    459476
    460 void NullStmt::print( std::ostream &os, Indenter ) const {
    461         os << "Null Statement" << endl;
     477void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const {
     478        os << "Null Statement" << endl ;
    462479}
    463480
     
    473490}
    474491
    475 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
     492void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const {
    476493        os << "Implicit Ctor Dtor Statement" << endl;
    477         os << indent << "... with Ctor/Dtor: ";
    478         callStmt->print( os, indent+1);
     494        os << string( indent + 2, ' ' ) << "with Ctor/Dtor: ";
     495        callStmt->print( os, indent + 2);
    479496        os << endl;
     497}
     498
     499std::ostream & operator<<( std::ostream & out, const Statement * statement ) {
     500        if ( statement ) {
     501                statement->print( out );
     502        } else {
     503                out << "nullptr";
     504        }
     505        return out;
    480506}
    481507
Note: See TracChangeset for help on using the changeset viewer.