Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r8688ce1 r7f5566b  
    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 : Thu Aug  4 11:25:20 2016
    13 // Update Count     : 61
     12// Last Modified On : Sat Jul 25 12:19:50 2015
     13// Update Count     : 53
    1414//
    1515
     
    3636ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
    3737
    38 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    39 
    40 ExprStmt::~ExprStmt() {
    41         delete expr;
    42 }
     38ExprStmt::~ExprStmt() {}
    4339
    4440void ExprStmt::print( std::ostream &os, int indent ) const {
    45         os << "Expression Statement:" << endl << std::string( indent + 2, ' ' );
     41        os << string( indent, ' ' ) << "Expression Statement:" << endl;
    4642        expr->print( os, indent + 2 );
    47 }
     43} 
    4844
    4945
    5046AsmStmt::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 
    52 AsmStmt::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 }
    5747
    5848AsmStmt::~AsmStmt() {
     
    7060                os << endl << std::string( indent, ' ' ) << "output: " << endl;
    7161                printAll( output, os, indent + 2 );
    72         } // if
     62        } // if 
    7363        if ( ! input.empty() ) {
    7464                os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );
     
    7969                printAll( clobber, os, indent + 2 );
    8070        } // if
    81 }
     71} 
    8272
    8373
     
    8777        Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) {
    8878        //actually this is a syntactic error signaled by the parser
    89         if ( type == BranchStmt::Goto && target.empty() )
     79        if ( type == BranchStmt::Goto && target.size() == 0 )
    9080                throw SemanticError("goto without target");
    9181}
     
    10393ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {}
    10494
    105 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ), isThrow( other.isThrow ) {}
    106 
    10795ReturnStmt::~ReturnStmt() {
    10896        delete expr;
     
    11098
    11199void ReturnStmt::print( std::ostream &os, int indent ) const {
    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         }
     100        os << std::string( indent, ' ' ) << string ( isThrow? "Throw":"Return" ) << " Statement, returning: ";
     101        if ( expr != 0 ) expr->print( os );
    117102        os << endl;
    118103}
     
    121106        Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
    122107
    123 IfStmt::IfStmt( const IfStmt & other ) :
    124         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
    125 
    126108IfStmt::~IfStmt() {}
    127109
    128110void IfStmt::print( std::ostream &os, int indent ) const {
    129         os << "If on condition: " << endl ;
    130         os << string( indent+4, ' ' );
     111        os << string( indent, ' ' ) << "If on condition: " << endl ;
    131112        condition->print( os, indent + 4 );
    132113
    133         os << string( indent+2, ' ' ) << "... then: " << endl;
    134 
    135         os << string( indent+4, ' ' );
     114        os << string( indent, ' ' ) << ".... and branches: " << endl;
     115
    136116        thenPart->print( os, indent + 4 );
    137117
    138118        if ( elsePart != 0 ) {
    139                 os << string( indent+2, ' ' ) << "... else: " << endl;
    140                 os << string( indent+4, ' ' );
    141119                elsePart->print( os, indent + 4 );
    142120        } // if
    143121}
    144122
    145 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
    146         Statement( _labels ), condition( _condition ), statements( _statements ) {
    147 }
    148 
    149 SwitchStmt::SwitchStmt( const SwitchStmt & other ):
    150         Statement( other ), condition( maybeClone( other.condition ) ) {
    151         cloneAll( other.statements, statements );
     123SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
     124        Statement( _labels ), condition( _condition ), branches( _branches ) {
    152125}
    153126
    154127SwitchStmt::~SwitchStmt() {
    155128        delete condition;
    156         // destroy statements
    157 }
     129        // destroy branches
     130}
     131
     132void SwitchStmt::add_case( CaseStmt *c ) {}
    158133
    159134void SwitchStmt::print( std::ostream &os, int indent ) const {
    160         os << "Switch on condition: ";
     135        os << string( indent, ' ' ) << "Switch on condition: ";
    161136        condition->print( os );
    162137        os << endl;
    163138
    164         // statements
     139        // branches
    165140        std::list<Statement *>::const_iterator i;
    166         for ( i = statements.begin(); i != statements.end(); i++)
     141        for ( i = branches.begin(); i != branches.end(); i++)
    167142                (*i)->print( os, indent + 4 );
    168143
    169         //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os ));
    170 }
    171 
    172 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
     144        //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os ));
     145}
     146
     147CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 
    173148        Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
    174149        if ( isDefault() && condition != 0 )
     
    176151}
    177152
    178 CaseStmt::CaseStmt( const CaseStmt & other ) :
    179         Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {
    180         cloneAll( other.stmts, stmts );
    181 }
    182 
    183153CaseStmt::~CaseStmt() {
    184154        delete condition;
    185155}
    186156
    187 CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) {
    188         return new CaseStmt( labels, 0, stmts, true );
     157CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) {
     158        return new CaseStmt( labels, 0, branches, true );
    189159}
    190160
     
    206176}
    207177
     178//ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {}
     179ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
     180        Statement( _labels ), condition( _condition ), branches( _branches ) {
     181}
     182
     183ChooseStmt::~ChooseStmt() {
     184        delete condition;
     185}
     186
     187void ChooseStmt::add_case( CaseStmt *c ) {}
     188
     189void 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
     202void FallthruStmt::print( std::ostream &os, int indent ) const {
     203        os << string( indent, ' ' ) << "Fall-through statement" << endl;
     204}
     205
    208206WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
    209207        Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
    210208}
    211209
    212 WhileStmt::WhileStmt( const WhileStmt & other ):
    213         Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
    214 }
    215 
    216210WhileStmt::~WhileStmt() {
    217211        delete body;
     
    219213
    220214void WhileStmt::print( std::ostream &os, int indent ) const {
    221         os << "While on condition: " << endl ;
     215        os << string( indent, ' ' ) << "While on condition: " << endl ;
    222216        condition->print( os, indent + 4 );
    223217
     
    229223ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    230224        Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
    231 }
    232 
    233 ForStmt::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 
    237225}
    238226
     
    245233
    246234void ForStmt::print( std::ostream &os, int indent ) const {
    247         os << "Labels: {";
     235        os << string( indent, ' ' ) << "Labels: {";
    248236        for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
    249237                os << *it << ",";
     
    253241        os << string( indent, ' ' ) << "For Statement" << endl ;
    254242
    255         os << string( indent + 2, ' ' ) << "initialization: \n";
     243        os << string( indent + 2, ' ' ) << "initialization: \n"; 
    256244        for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
    257                 os << string( indent + 4, ' ' );
    258245                (*it)->print( os, indent + 4 );
    259246        }
    260247
    261         os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
    262         if ( condition != 0 ) {
    263                 os << string( indent + 4, ' ' );
     248        os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
     249        if ( condition != 0 )
    264250                condition->print( os, indent + 4 );
    265         }
    266 
    267         os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
    268         if ( increment != 0 ) {
    269                 os << string( indent + 4, ' ' );
     251
     252        os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
     253        if ( increment != 0 )
    270254                increment->print( os, indent + 4 );
    271         }
    272 
    273         os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
    274         if ( body != 0 ) {
    275                 os << string( indent + 4, ' ' );
     255
     256        os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
     257        if ( body != 0 )
    276258                body->print( os, indent + 4 );
    277         }
    278259
    279260        os << endl;
     
    284265}
    285266
    286 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
    287         cloneAll( other.handlers, handlers );
     267TryStmt::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;
    288271}
    289272
     
    293276
    294277void TryStmt::print( std::ostream &os, int indent ) const {
    295         os << "Try Statement" << endl;
     278        os << string( indent, ' ' ) << "Try Statement" << endl;
    296279        os << string( indent + 2, ' ' ) << "with block: " << endl;
    297280        block->print( os, indent + 4 );
     
    313296}
    314297
    315 CatchStmt::CatchStmt( const CatchStmt & other ) :
    316         Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) {
    317 }
    318 
    319298CatchStmt::~CatchStmt() {
    320299        delete decl;
     
    323302
    324303void CatchStmt::print( std::ostream &os, int indent ) const {
    325         os << "Catch Statement" << endl;
     304        os << string( indent, ' ' ) << "Catch Statement" << endl;
    326305
    327306        os << string( indent, ' ' ) << "... catching" << endl;
     
    340319}
    341320
    342 FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
    343 }
    344 
    345321FinallyStmt::~FinallyStmt() {
    346322        delete block;
     
    348324
    349325void FinallyStmt::print( std::ostream &os, int indent ) const {
    350         os << "Finally Statement" << endl;
     326        os << string( indent, ' ' ) << "Finally Statement" << endl;
    351327        os << string( indent + 2, ' ' ) << "with block: " << endl;
    352328        block->print( os, indent + 4 );
     
    355331NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {}
    356332NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {}
     333NullStmt::~NullStmt() {}
    357334
    358335void NullStmt::print( std::ostream &os, int indent ) const {
    359         os << "Null Statement" << endl ;
    360 }
    361 
    362 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {
    363         assert( callStmt );
    364 }
    365 
    366 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) {
    367 }
    368 
    369 ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
    370         delete callStmt;
    371 }
    372 
    373 void 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 
    380 std::ostream & operator<<( std::ostream & out, Statement * statement ) {
    381         statement->print( out );
    382         return out;
     336        os << string( indent, ' ' ) << "Null Statement" << endl ;
    383337}
    384338
Note: See TracChangeset for help on using the changeset viewer.