Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r7f5566b r8688ce1  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Statement.cc -- 
     7// Statement.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 25 12:19:50 2015
    13 // Update Count     : 53
     12// Last Modified On : Thu Aug  4 11:25:20 2016
     13// Update Count     : 61
    1414//
    1515
     
    3636ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
    3737
    38 ExprStmt::~ExprStmt() {}
     38ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     39
     40ExprStmt::~ExprStmt() {
     41        delete expr;
     42}
    3943
    4044void ExprStmt::print( std::ostream &os, int indent ) const {
    41         os << string( indent, ' ' ) << "Expression Statement:" << endl;
     45        os << "Expression Statement:" << endl << std::string( indent + 2, ' ' );
    4246        expr->print( os, indent + 2 );
    43 } 
     47}
    4448
    4549
    4650AsmStmt::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 ) {}
     51
     52AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
     53  cloneAll( other.output, output );
     54  cloneAll( other.input, input );
     55  cloneAll( other.clobber, clobber );
     56}
    4757
    4858AsmStmt::~AsmStmt() {
     
    6070                os << endl << std::string( indent, ' ' ) << "output: " << endl;
    6171                printAll( output, os, indent + 2 );
    62         } // if 
     72        } // if
    6373        if ( ! input.empty() ) {
    6474                os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );
     
    6979                printAll( clobber, os, indent + 2 );
    7080        } // if
    71 } 
     81}
    7282
    7383
     
    7787        Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) {
    7888        //actually this is a syntactic error signaled by the parser
    79         if ( type == BranchStmt::Goto && target.size() == 0 )
     89        if ( type == BranchStmt::Goto && target.empty() )
    8090                throw SemanticError("goto without target");
    8191}
     
    93103ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {}
    94104
     105ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ), isThrow( other.isThrow ) {}
     106
    95107ReturnStmt::~ReturnStmt() {
    96108        delete expr;
     
    98110
    99111void ReturnStmt::print( std::ostream &os, int indent ) const {
    100         os << std::string( indent, ' ' ) << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
    101         if ( expr != 0 ) expr->print( os );
     112        os << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
     113        if ( expr != 0 ) {
     114                os << endl << string( indent+2, ' ' );
     115                expr->print( os, indent + 2 );
     116        }
    102117        os << endl;
    103118}
     
    106121        Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
    107122
     123IfStmt::IfStmt( const IfStmt & other ) :
     124        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
     125
    108126IfStmt::~IfStmt() {}
    109127
    110128void IfStmt::print( std::ostream &os, int indent ) const {
    111         os << string( indent, ' ' ) << "If on condition: " << endl ;
     129        os << "If on condition: " << endl ;
     130        os << string( indent+4, ' ' );
    112131        condition->print( os, indent + 4 );
    113132
    114         os << string( indent, ' ' ) << ".... and branches: " << endl;
    115 
     133        os << string( indent+2, ' ' ) << "... then: " << endl;
     134
     135        os << string( indent+4, ' ' );
    116136        thenPart->print( os, indent + 4 );
    117137
    118138        if ( elsePart != 0 ) {
     139                os << string( indent+2, ' ' ) << "... else: " << endl;
     140                os << string( indent+4, ' ' );
    119141                elsePart->print( os, indent + 4 );
    120142        } // if
    121143}
    122144
    123 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
    124         Statement( _labels ), condition( _condition ), branches( _branches ) {
     145SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
     146        Statement( _labels ), condition( _condition ), statements( _statements ) {
     147}
     148
     149SwitchStmt::SwitchStmt( const SwitchStmt & other ):
     150        Statement( other ), condition( maybeClone( other.condition ) ) {
     151        cloneAll( other.statements, statements );
    125152}
    126153
    127154SwitchStmt::~SwitchStmt() {
    128155        delete condition;
    129         // destroy branches
    130 }
    131 
    132 void SwitchStmt::add_case( CaseStmt *c ) {}
     156        // destroy statements
     157}
    133158
    134159void SwitchStmt::print( std::ostream &os, int indent ) const {
    135         os << string( indent, ' ' ) << "Switch on condition: ";
     160        os << "Switch on condition: ";
    136161        condition->print( os );
    137162        os << endl;
    138163
    139         // branches
     164        // statements
    140165        std::list<Statement *>::const_iterator i;
    141         for ( i = branches.begin(); i != branches.end(); i++)
     166        for ( i = statements.begin(); i != statements.end(); i++)
    142167                (*i)->print( os, indent + 4 );
    143168
    144         //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));
    145 }
    146 
    147 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 
     169        //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os ));
     170}
     171
     172CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
    148173        Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
    149174        if ( isDefault() && condition != 0 )
     
    151176}
    152177
     178CaseStmt::CaseStmt( const CaseStmt & other ) :
     179        Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {
     180        cloneAll( other.stmts, stmts );
     181}
     182
    153183CaseStmt::~CaseStmt() {
    154184        delete condition;
    155185}
    156186
    157 CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) {
    158         return new CaseStmt( labels, 0, branches, true );
     187CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) {
     188        return new CaseStmt( labels, 0, stmts, true );
    159189}
    160190
     
    176206}
    177207
    178 //ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {}
    179 ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
    180         Statement( _labels ), condition( _condition ), branches( _branches ) {
    181 }
    182 
    183 ChooseStmt::~ChooseStmt() {
    184         delete condition;
    185 }
    186 
    187 void ChooseStmt::add_case( CaseStmt *c ) {}
    188 
    189 void ChooseStmt::print( std::ostream &os, int indent ) const {
    190         os << string( indent, ' ' ) << "Choose on condition: ";
    191         condition->print( os );
    192         os << endl;
    193 
    194         // branches
    195         std::list<Statement *>::const_iterator i;
    196         for ( i = branches.begin(); i != branches.end(); i++)
    197                 (*i )->print( os, indent + 4 );
    198 
    199         //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));
    200 }
    201 
    202 void FallthruStmt::print( std::ostream &os, int indent ) const {
    203         os << string( indent, ' ' ) << "Fall-through statement" << endl;
    204 }
    205 
    206208WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
    207209        Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
    208210}
    209211
     212WhileStmt::WhileStmt( const WhileStmt & other ):
     213        Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
     214}
     215
    210216WhileStmt::~WhileStmt() {
    211217        delete body;
     
    213219
    214220void WhileStmt::print( std::ostream &os, int indent ) const {
    215         os << string( indent, ' ' ) << "While on condition: " << endl ;
     221        os << "While on condition: " << endl ;
    216222        condition->print( os, indent + 4 );
    217223
     
    223229ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    224230        Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
     231}
     232
     233ForStmt::ForStmt( const ForStmt & other ):
     234        Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) {
     235                cloneAll( other.initialization, initialization );
     236
    225237}
    226238
     
    233245
    234246void ForStmt::print( std::ostream &os, int indent ) const {
    235         os << string( indent, ' ' ) << "Labels: {";
     247        os << "Labels: {";
    236248        for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
    237249                os << *it << ",";
     
    241253        os << string( indent, ' ' ) << "For Statement" << endl ;
    242254
    243         os << string( indent + 2, ' ' ) << "initialization: \n"; 
     255        os << string( indent + 2, ' ' ) << "initialization: \n";
    244256        for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     257                os << string( indent + 4, ' ' );
    245258                (*it)->print( os, indent + 4 );
    246259        }
    247260
    248         os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
    249         if ( condition != 0 )
     261        os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
     262        if ( condition != 0 ) {
     263                os << string( indent + 4, ' ' );
    250264                condition->print( os, indent + 4 );
    251 
    252         os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
    253         if ( increment != 0 )
     265        }
     266
     267        os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
     268        if ( increment != 0 ) {
     269                os << string( indent + 4, ' ' );
    254270                increment->print( os, indent + 4 );
    255 
    256         os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
    257         if ( body != 0 )
     271        }
     272
     273        os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
     274        if ( body != 0 ) {
     275                os << string( indent + 4, ' ' );
    258276                body->print( os, indent + 4 );
     277        }
    259278
    260279        os << endl;
     
    265284}
    266285
    267 TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) {
    268         block = other.block;
    269         std::copy( other.handlers.begin(), other.handlers.end(), back_inserter( handlers ) );
    270         finallyBlock = other.finallyBlock;
     286TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
     287        cloneAll( other.handlers, handlers );
    271288}
    272289
     
    276293
    277294void TryStmt::print( std::ostream &os, int indent ) const {
    278         os << string( indent, ' ' ) << "Try Statement" << endl;
     295        os << "Try Statement" << endl;
    279296        os << string( indent + 2, ' ' ) << "with block: " << endl;
    280297        block->print( os, indent + 4 );
     
    296313}
    297314
     315CatchStmt::CatchStmt( const CatchStmt & other ) :
     316        Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) {
     317}
     318
    298319CatchStmt::~CatchStmt() {
    299320        delete decl;
     
    302323
    303324void CatchStmt::print( std::ostream &os, int indent ) const {
    304         os << string( indent, ' ' ) << "Catch Statement" << endl;
     325        os << "Catch Statement" << endl;
    305326
    306327        os << string( indent, ' ' ) << "... catching" << endl;
     
    319340}
    320341
     342FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
     343}
     344
    321345FinallyStmt::~FinallyStmt() {
    322346        delete block;
     
    324348
    325349void FinallyStmt::print( std::ostream &os, int indent ) const {
    326         os << string( indent, ' ' ) << "Finally Statement" << endl;
     350        os << "Finally Statement" << endl;
    327351        os << string( indent + 2, ' ' ) << "with block: " << endl;
    328352        block->print( os, indent + 4 );
     
    331355NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {}
    332356NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {}
    333 NullStmt::~NullStmt() {}
    334357
    335358void NullStmt::print( std::ostream &os, int indent ) const {
    336         os << string( indent, ' ' ) << "Null Statement" << endl ;
     359        os << "Null Statement" << endl ;
     360}
     361
     362ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {
     363        assert( callStmt );
     364}
     365
     366ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) {
     367}
     368
     369ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
     370        delete callStmt;
     371}
     372
     373void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const {
     374        os << "Implicit Ctor Dtor Statement" << endl;
     375        os << string( indent + 2, ' ' ) << "with Ctor/Dtor: ";
     376        callStmt->print( os, indent + 2);
     377        os << endl;
     378}
     379
     380std::ostream & operator<<( std::ostream & out, Statement * statement ) {
     381        statement->print( out );
     382        return out;
    337383}
    338384
Note: See TracChangeset for help on using the changeset viewer.