Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    re67991f r37cdd97  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:46:44 2017
    13 // Update Count     : 68
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jan 20 16:03:00 2020
     13// Update Count     : 71
    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[] = { "Goto", "Break", "Continue" };
     103const char * BranchStmt::brType[] = {
     104        "Goto", "Break", "Continue", "Fall Through", "Fall Through Default",
     105};
    104106
    105107BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
     
    111113}
    112114
    113 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) :
     115BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) :
    114116        Statement(), computedTarget( computedTarget ), type( type ) {
    115117        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
     
    118120}
    119121
    120 void BranchStmt::print( std::ostream &os, Indenter indent ) const {
     122void BranchStmt::print( std::ostream & os, Indenter indent ) const {
     123        assert(type < 5);
    121124        os << "Branch (" << brType[type] << ")" << endl ;
    122125        if ( target != "" ) os << indent+1 << "with target: " << target << endl;
     
    125128}
    126129
    127 ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {}
     130ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {}
    128131
    129132ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    133136}
    134137
    135 void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
     138void ReturnStmt::print( std::ostream & os, Indenter indent ) const {
    136139        os << "Return Statement, returning: ";
    137140        if ( expr != nullptr ) {
     
    142145}
    143146
    144 IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
     147IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ):
    145148        Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    146149
     
    157160}
    158161
    159 void IfStmt::print( std::ostream &os, Indenter indent ) const {
     162void IfStmt::print( std::ostream & os, Indenter indent ) const {
    160163        os << "If on condition: " << endl;
    161164        os << indent+1;
     
    176179        thenPart->print( os, indent+1 );
    177180
    178         if ( elsePart != 0 ) {
     181        if ( elsePart != nullptr ) {
    179182                os << indent << "... else: " << endl;
    180183                os << indent+1;
     
    183186}
    184187
    185 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ):
     188SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ):
    186189        Statement(), condition( condition ), statements( statements ) {
    187190}
     
    198201}
    199202
    200 void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
     203void SwitchStmt::print( std::ostream & os, Indenter indent ) const {
    201204        os << "Switch on condition: ";
    202205        condition->print( os );
     
    208211}
    209212
    210 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :
     213CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) :
    211214        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    212         if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " );
     215        if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " );
    213216}
    214217
     
    229232}
    230233
    231 void CaseStmt::print( std::ostream &os, Indenter indent ) const {
     234void CaseStmt::print( std::ostream & os, Indenter indent ) const {
    232235        if ( isDefault() ) os << indent << "Default ";
    233236        else {
     
    243246}
    244247
    245 WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):
     248WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ):
    246249        Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) {
    247250}
     
    256259}
    257260
    258 void WhileStmt::print( std::ostream &os, Indenter indent ) const {
     261void WhileStmt::print( std::ostream & os, Indenter indent ) const {
    259262        os << "While on condition: " << endl ;
    260263        condition->print( os, indent+1 );
     
    262265        os << indent << "... with body: " << endl;
    263266
    264         if ( body != 0 ) body->print( os, indent+1 );
    265 }
    266 
    267 ForStmt::ForStmt( std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
     267        if ( body != nullptr ) body->print( os, indent+1 );
     268}
     269
     270ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ):
    268271        Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    269272}
     
    282285}
    283286
    284 void ForStmt::print( std::ostream &os, Indenter indent ) const {
     287void ForStmt::print( std::ostream & os, Indenter indent ) const {
    285288        Statement::print( os, indent ); // print labels
    286289
     
    305308        }
    306309
    307         if ( body != 0 ) {
     310        if ( body != nullptr ) {
    308311                os << "\n" << indent << "... with body: \n" << indent+1;
    309312                body->print( os, indent+1 );
     
    317320}
    318321
    319 ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
     322ThrowStmt::ThrowStmt( const ThrowStmt & other ) :
    320323        Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
    321324}
     
    326329}
    327330
    328 void ThrowStmt::print( std::ostream &os, Indenter indent) const {
     331void ThrowStmt::print( std::ostream & os, Indenter indent) const {
    329332        if ( target ) os << "Non-Local ";
    330333        os << "Throw Statement, raising: ";
     
    336339}
    337340
    338 TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
     341TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) :
    339342        Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    340343}
    341344
    342 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
     345TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
    343346        cloneAll( other.handlers, handlers );
    344347}
     
    350353}
    351354
    352 void TryStmt::print( std::ostream &os, Indenter indent ) const {
     355void TryStmt::print( std::ostream & os, Indenter indent ) const {
    353356        os << "Try Statement" << endl;
    354357        os << indent << "... with block:" << endl << indent+1;
     
    363366
    364367        // finally block
    365         if ( finallyBlock != 0 ) {
     368        if ( finallyBlock != nullptr ) {
    366369                os << indent << "... and finally:" << endl << indent+1;
    367370                finallyBlock->print( os, indent+1 );
     
    369372}
    370373
    371 CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
     374CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) :
    372375        Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    373376                assertf( decl, "Catch clause must have a declaration." );
     
    383386}
    384387
    385 void CatchStmt::print( std::ostream &os, Indenter indent ) const {
     388void CatchStmt::print( std::ostream & os, Indenter indent ) const {
    386389        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
    387390
     
    401404
    402405
    403 FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) {
     406FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) {
    404407}
    405408
     
    411414}
    412415
    413 void FinallyStmt::print( std::ostream &os, Indenter indent ) const {
     416void FinallyStmt::print( std::ostream & os, Indenter indent ) const {
    414417        os << "Finally Statement" << endl;
    415418        os << indent << "... with block:" << endl << indent+1;
    416419        block->print( os, indent+1 );
     420}
     421
     422SuspendStmt::SuspendStmt( const SuspendStmt & other )
     423        : Statement( other )
     424        , then( maybeClone(other.then) )
     425{}
     426
     427SuspendStmt::~SuspendStmt() {
     428        delete then;
     429}
     430
     431void 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        }
    417445}
    418446
     
    458486}
    459487
    460 void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
     488void WaitForStmt::print( std::ostream & os, Indenter indent ) const {
    461489        os << "Waitfor Statement" << endl;
    462490        indent += 1;
     
    514542}
    515543
    516 void NullStmt::print( std::ostream &os, Indenter indent ) const {
     544void NullStmt::print( std::ostream & os, Indenter indent ) const {
    517545        os << "Null Statement" << endl;
    518546        Statement::print( os, indent );
     
    530558}
    531559
    532 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
     560void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const {
    533561        os << "Implicit Ctor Dtor Statement" << endl;
    534562        os << indent << "... with Ctor/Dtor: ";
Note: See TracChangeset for help on using the changeset viewer.