Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r37cdd97 re67991f  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jan 20 16:03:00 2020
    13 // Update Count     : 71
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 20:46:44 2017
     13// Update Count     : 68
    1414//
    1515
     
    4646Statement::~Statement() {}
    4747
    48 ExprStmt::ExprStmt( Expression * expr ) : Statement(), expr( expr ) {}
    49 
    50 ExprStmt::ExprStmt( const ExprStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     48ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}
     49
     50ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    5151
    5252ExprStmt::~ExprStmt() {
     
    5454}
    5555
    56 void ExprStmt::print( std::ostream & os, Indenter indent ) const {
     56void ExprStmt::print( std::ostream &os, Indenter indent ) const {
    5757        os << "Expression Statement:" << endl << indent+1;
    5858        expr->print( os, indent+1 );
     
    6060
    6161
    62 AsmStmt::AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
     62AsmStmt::AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    6363
    6464AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
     
    7575}
    7676
    77 void AsmStmt::print( std::ostream & os, Indenter indent ) const {
     77void AsmStmt::print( std::ostream &os, Indenter indent ) const {
    7878        os << "Assembler Statement:" << endl;
    7979        os << indent+1 << "instruction: " << endl << indent;
     
    9696DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {}
    9797
    98 void DirectiveStmt::print( std::ostream & os, Indenter ) const {
     98void DirectiveStmt::print( std::ostream &os, Indenter ) const {
    9999        os << "GCC Directive:" << directive << endl;
    100100}
    101101
    102102
    103 const char * BranchStmt::brType[] = {
    104         "Goto", "Break", "Continue", "Fall Through", "Fall Through Default",
    105 };
     103const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    106104
    107105BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
     
    113111}
    114112
    115 BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) :
     113BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) :
    116114        Statement(), computedTarget( computedTarget ), type( type ) {
    117115        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
     
    120118}
    121119
    122 void BranchStmt::print( std::ostream & os, Indenter indent ) const {
    123         assert(type < 5);
     120void BranchStmt::print( std::ostream &os, Indenter indent ) const {
    124121        os << "Branch (" << brType[type] << ")" << endl ;
    125122        if ( target != "" ) os << indent+1 << "with target: " << target << endl;
     
    128125}
    129126
    130 ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {}
     127ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {}
    131128
    132129ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    136133}
    137134
    138 void ReturnStmt::print( std::ostream & os, Indenter indent ) const {
     135void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
    139136        os << "Return Statement, returning: ";
    140137        if ( expr != nullptr ) {
     
    145142}
    146143
    147 IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ):
     144IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
    148145        Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    149146
     
    160157}
    161158
    162 void IfStmt::print( std::ostream & os, Indenter indent ) const {
     159void IfStmt::print( std::ostream &os, Indenter indent ) const {
    163160        os << "If on condition: " << endl;
    164161        os << indent+1;
     
    179176        thenPart->print( os, indent+1 );
    180177
    181         if ( elsePart != nullptr ) {
     178        if ( elsePart != 0 ) {
    182179                os << indent << "... else: " << endl;
    183180                os << indent+1;
     
    186183}
    187184
    188 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ):
     185SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ):
    189186        Statement(), condition( condition ), statements( statements ) {
    190187}
     
    201198}
    202199
    203 void SwitchStmt::print( std::ostream & os, Indenter indent ) const {
     200void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
    204201        os << "Switch on condition: ";
    205202        condition->print( os );
     
    211208}
    212209
    213 CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) :
     210CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :
    214211        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    215         if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " );
     212        if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " );
    216213}
    217214
     
    232229}
    233230
    234 void CaseStmt::print( std::ostream & os, Indenter indent ) const {
     231void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    235232        if ( isDefault() ) os << indent << "Default ";
    236233        else {
     
    246243}
    247244
    248 WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ):
     245WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):
    249246        Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) {
    250247}
     
    259256}
    260257
    261 void WhileStmt::print( std::ostream & os, Indenter indent ) const {
     258void WhileStmt::print( std::ostream &os, Indenter indent ) const {
    262259        os << "While on condition: " << endl ;
    263260        condition->print( os, indent+1 );
     
    265262        os << indent << "... with body: " << endl;
    266263
    267         if ( body != nullptr ) body->print( os, indent+1 );
    268 }
    269 
    270 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ):
     264        if ( body != 0 ) body->print( os, indent+1 );
     265}
     266
     267ForStmt::ForStmt( std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
    271268        Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    272269}
     
    285282}
    286283
    287 void ForStmt::print( std::ostream & os, Indenter indent ) const {
     284void ForStmt::print( std::ostream &os, Indenter indent ) const {
    288285        Statement::print( os, indent ); // print labels
    289286
     
    308305        }
    309306
    310         if ( body != nullptr ) {
     307        if ( body != 0 ) {
    311308                os << "\n" << indent << "... with body: \n" << indent+1;
    312309                body->print( os, indent+1 );
     
    320317}
    321318
    322 ThrowStmt::ThrowStmt( const ThrowStmt & other ) :
     319ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
    323320        Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
    324321}
     
    329326}
    330327
    331 void ThrowStmt::print( std::ostream & os, Indenter indent) const {
     328void ThrowStmt::print( std::ostream &os, Indenter indent) const {
    332329        if ( target ) os << "Non-Local ";
    333330        os << "Throw Statement, raising: ";
     
    339336}
    340337
    341 TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) :
     338TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
    342339        Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    343340}
    344341
    345 TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
     342TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
    346343        cloneAll( other.handlers, handlers );
    347344}
     
    353350}
    354351
    355 void TryStmt::print( std::ostream & os, Indenter indent ) const {
     352void TryStmt::print( std::ostream &os, Indenter indent ) const {
    356353        os << "Try Statement" << endl;
    357354        os << indent << "... with block:" << endl << indent+1;
     
    366363
    367364        // finally block
    368         if ( finallyBlock != nullptr ) {
     365        if ( finallyBlock != 0 ) {
    369366                os << indent << "... and finally:" << endl << indent+1;
    370367                finallyBlock->print( os, indent+1 );
     
    372369}
    373370
    374 CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) :
     371CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
    375372        Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    376373                assertf( decl, "Catch clause must have a declaration." );
     
    386383}
    387384
    388 void CatchStmt::print( std::ostream & os, Indenter indent ) const {
     385void CatchStmt::print( std::ostream &os, Indenter indent ) const {
    389386        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
    390387
     
    404401
    405402
    406 FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) {
     403FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) {
    407404}
    408405
     
    414411}
    415412
    416 void FinallyStmt::print( std::ostream & os, Indenter indent ) const {
     413void FinallyStmt::print( std::ostream &os, Indenter indent ) const {
    417414        os << "Finally Statement" << endl;
    418415        os << indent << "... with block:" << endl << indent+1;
    419416        block->print( os, indent+1 );
    420 }
    421 
    422 SuspendStmt::SuspendStmt( const SuspendStmt & other )
    423         : Statement( other )
    424         , then( maybeClone(other.then) )
    425 {}
    426 
    427 SuspendStmt::~SuspendStmt() {
    428         delete then;
    429 }
    430 
    431 void SuspendStmt::print( std::ostream & os, Indenter indent ) const {
    432         os << "Suspend Statement";
    433         switch (type) {
    434                 case None     : os << " with implicit target"; break;
    435                 case Generator: os << " for generator"       ; break;
    436                 case Coroutine: os << " for coroutine"       ; break;
    437         }
    438         os << endl;
    439         indent += 1;
    440 
    441         if(then) {
    442                 os << indent << " with post statement :" << endl;
    443                 then->print( os, indent + 1);
    444         }
    445417}
    446418
     
    486458}
    487459
    488 void WaitForStmt::print( std::ostream & os, Indenter indent ) const {
     460void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
    489461        os << "Waitfor Statement" << endl;
    490462        indent += 1;
     
    542514}
    543515
    544 void NullStmt::print( std::ostream & os, Indenter indent ) const {
     516void NullStmt::print( std::ostream &os, Indenter indent ) const {
    545517        os << "Null Statement" << endl;
    546518        Statement::print( os, indent );
     
    558530}
    559531
    560 void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const {
     532void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
    561533        os << "Implicit Ctor Dtor Statement" << endl;
    562534        os << indent << "... with Ctor/Dtor: ";
Note: See TracChangeset for help on using the changeset viewer.