Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r68f9c43 rcc32d83  
    3434Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}
    3535
    36 void Statement::print( std::ostream & os, Indenter ) const {
     36void Statement::print( std::ostream & os, Indenter indent ) const {
    3737        if ( ! labels.empty() ) {
    38                 os << "Labels: {";
     38                os << indent << "... Labels: {";
    3939                for ( const Label & l : labels ) {
    4040                        os << l << ",";
     
    4444}
    4545
     46Statement::~Statement() {}
     47
    4648ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}
    4749
    4850ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     51
     52ExprStmt::~ExprStmt() {
     53        delete expr;
     54}
    4955
    5056void ExprStmt::print( std::ostream &os, Indenter indent ) const {
     
    6066  cloneAll( other.input, input );
    6167  cloneAll( other.clobber, clobber );
     68}
     69
     70AsmStmt::~AsmStmt() {
     71        delete instruction;
     72        deleteAll( output );
     73        deleteAll( input );
     74        deleteAll( clobber );
    6275}
    6376
     
    8194
    8295
     96DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {}
     97
     98void DirectiveStmt::print( std::ostream &os, Indenter ) const {
     99        os << "GCC Directive:" << directive << endl;
     100}
     101
     102
    83103const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    84104
     
    109129ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    110130
     131ReturnStmt::~ReturnStmt() {
     132        delete expr;
     133}
     134
    111135void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
    112136        os << "Return Statement, returning: ";
     
    124148        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
    125149        cloneAll( other.initialization, initialization );
     150}
     151
     152IfStmt::~IfStmt() {
     153        deleteAll( initialization );
     154        delete condition;
     155        delete thenPart;
     156        delete elsePart;
    126157}
    127158
     
    161192}
    162193
     194SwitchStmt::~SwitchStmt() {
     195        delete condition;
     196        // destroy statements
     197        deleteAll( statements );
     198}
     199
    163200void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
    164201        os << "Switch on condition: ";
     
    181218}
    182219
     220CaseStmt::~CaseStmt() {
     221        delete condition;
     222        deleteAll( stmts );
     223}
     224
    183225CaseStmt * CaseStmt::makeDefault( const std::list<Label> & labels, std::list<Statement *> stmts ) {
    184226        CaseStmt * stmt = new CaseStmt( nullptr, stmts, true );
     
    188230
    189231void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    190         if ( isDefault() ) os << "Default ";
     232        if ( isDefault() ) os << indent << "Default ";
    191233        else {
    192                 os << "Case ";
     234                os << indent << "Case ";
    193235                condition->print( os, indent );
    194236        } // if
     
    196238
    197239        for ( Statement * stmt : stmts ) {
     240                os << indent+1;
    198241                stmt->print( os, indent+1 );
    199242        }
     
    206249WhileStmt::WhileStmt( const WhileStmt & other ):
    207250        Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
     251}
     252
     253WhileStmt::~WhileStmt() {
     254        delete body;
     255        delete condition;
    208256}
    209257
     
    225273                cloneAll( other.initialization, initialization );
    226274
     275}
     276
     277ForStmt::~ForStmt() {
     278        deleteAll( initialization );
     279        delete condition;
     280        delete increment;
     281        delete body;
    227282}
    228283
     
    264319ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
    265320        Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
     321}
     322
     323ThrowStmt::~ThrowStmt() {
     324        delete expr;
     325        delete target;
    266326}
    267327
     
    284344}
    285345
     346TryStmt::~TryStmt() {
     347        delete block;
     348        deleteAll( handlers );
     349        delete finallyBlock;
     350}
     351
    286352void TryStmt::print( std::ostream &os, Indenter indent ) const {
    287353        os << "Try Statement" << endl;
     
    312378}
    313379
     380CatchStmt::~CatchStmt() {
     381        delete decl;
     382        delete body;
     383}
     384
    314385void CatchStmt::print( std::ostream &os, Indenter indent ) const {
    315386        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
     
    334405
    335406FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
     407}
     408
     409FinallyStmt::~FinallyStmt() {
     410        delete block;
    336411}
    337412
     
    367442}
    368443
     444WaitForStmt::~WaitForStmt() {
     445        for( auto & clause : clauses ) {
     446                delete clause.target.function;
     447                deleteAll( clause.target.arguments );
     448                delete clause.statement;
     449                delete clause.condition;
     450        }
     451
     452        delete timeout.time;
     453        delete timeout.statement;
     454        delete timeout.condition;
     455
     456        delete orelse.statement;
     457        delete orelse.condition;
     458}
     459
    369460void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
    370461        os << "Waitfor Statement" << endl;
    371         os << indent << "... with block:" << endl << indent+1;
    372         // block->print( os, indent + 4 );
     462        indent += 1;
     463        for( auto & clause : clauses ) {
     464                os << indent << "target function :";
     465                if(clause.target.function) { clause.target.function->print(os, indent + 1); }
     466                os << endl << indent << "with arguments :" << endl;
     467                for( auto & thing : clause.target.arguments) {
     468                        if(thing) { thing->print(os, indent + 1); }
     469                }
     470                os << indent << " with statment :" << endl;
     471                if(clause.statement) { clause.statement->print(os, indent + 1); }
     472
     473                os << indent << " with condition :" << endl;
     474                if(clause.condition) { clause.condition->print(os, indent + 1); }
     475        }
     476
     477        os << indent << " timeout of :" << endl;
     478        if(timeout.time) { timeout.time->print(os, indent + 1); }
     479
     480        os << indent << " with statment :" << endl;
     481        if(timeout.statement) { timeout.statement->print(os, indent + 1); }
     482
     483        os << indent << " with condition :" << endl;
     484        if(timeout.condition) { timeout.condition->print(os, indent + 1); }
     485
     486
     487        os << indent << " else :" << endl;
     488        if(orelse.statement) { orelse.statement->print(os, indent + 1); }
     489
     490        os << indent << " with condition :" << endl;
     491        if(orelse.condition) { orelse.condition->print(os, indent + 1); }
    373492}
    374493
     
    377496WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {
    378497        cloneAll( other.exprs, exprs );
     498}
     499WithStmt::~WithStmt() {
     500        deleteAll( exprs );
     501        delete stmt;
    379502}
    380503
     
    391514}
    392515
    393 void NullStmt::print( std::ostream &os, Indenter ) const {
     516void NullStmt::print( std::ostream &os, Indenter indent ) const {
    394517        os << "Null Statement" << endl;
     518        Statement::print( os, indent );
    395519}
    396520
     
    400524
    401525ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) {
     526}
     527
     528ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
     529        delete callStmt;
    402530}
    403531
Note: See TracChangeset for help on using the changeset viewer.