| [0dd3a2f] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [3be261a] | 7 | // Statement.cc -- | 
|---|
| [0dd3a2f] | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Mon May 18 07:44:20 2015 | 
|---|
| [baf7fee] | 11 | // Last Modified By : Rob Schluntz | 
|---|
| [bb8ea30] | 12 | // Last Modified On : Thu May 12 13:33:18 2016 | 
|---|
| [baf7fee] | 13 | // Update Count     : 54 | 
|---|
| [0dd3a2f] | 14 | // | 
|---|
|  | 15 |  | 
|---|
| [51b73452] | 16 | #include <functional> | 
|---|
|  | 17 | #include <algorithm> | 
|---|
|  | 18 | #include <iostream> | 
|---|
|  | 19 | #include <list> | 
|---|
|  | 20 | #include <cassert> | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include "Statement.h" | 
|---|
|  | 23 | #include "Expression.h" | 
|---|
|  | 24 | #include "Declaration.h" | 
|---|
|  | 25 | #include "Common/SemanticError.h" | 
|---|
|  | 26 |  | 
|---|
|  | 27 | using std::string; | 
|---|
|  | 28 | using std::endl; | 
|---|
|  | 29 |  | 
|---|
| [2871210] | 30 | Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {} | 
|---|
| [51b73452] | 31 |  | 
|---|
| [de62360d] | 32 | void Statement::print( std::ostream &, int indent ) const {} | 
|---|
| [51b73452] | 33 |  | 
|---|
|  | 34 | Statement::~Statement() {} | 
|---|
|  | 35 |  | 
|---|
| [2871210] | 36 | ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {} | 
|---|
| [51b73452] | 37 |  | 
|---|
| [3be261a] | 38 | ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} | 
|---|
|  | 39 |  | 
|---|
|  | 40 | ExprStmt::~ExprStmt() { | 
|---|
|  | 41 | delete expr; | 
|---|
|  | 42 | } | 
|---|
| [51b73452] | 43 |  | 
|---|
| [de62360d] | 44 | void ExprStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [bb8ea30] | 45 | os << "Expression Statement:" << endl << std::string( indent + 2, ' ' ); | 
|---|
| [0dd3a2f] | 46 | expr->print( os, indent + 2 ); | 
|---|
| [3be261a] | 47 | } | 
|---|
| [51b73452] | 48 |  | 
|---|
| [7f5566b] | 49 |  | 
|---|
|  | 50 | AsmStmt::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 |  | 
|---|
| [3be261a] | 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 | } | 
|---|
|  | 57 |  | 
|---|
| [7f5566b] | 58 | AsmStmt::~AsmStmt() { | 
|---|
|  | 59 | delete instruction; | 
|---|
|  | 60 | deleteAll( output ); | 
|---|
|  | 61 | deleteAll( input ); | 
|---|
|  | 62 | deleteAll( clobber ); | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 | void AsmStmt::print( std::ostream &os, int indent ) const { | 
|---|
|  | 66 | os << "Assembler Statement:" << endl; | 
|---|
|  | 67 | os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' ); | 
|---|
|  | 68 | instruction->print( os, indent + 2 ); | 
|---|
|  | 69 | if ( ! output.empty() ) { | 
|---|
|  | 70 | os << endl << std::string( indent, ' ' ) << "output: " << endl; | 
|---|
|  | 71 | printAll( output, os, indent + 2 ); | 
|---|
| [3be261a] | 72 | } // if | 
|---|
| [7f5566b] | 73 | if ( ! input.empty() ) { | 
|---|
|  | 74 | os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' ); | 
|---|
|  | 75 | printAll( input, os, indent + 2 ); | 
|---|
|  | 76 | } // if | 
|---|
|  | 77 | if ( ! clobber.empty() ) { | 
|---|
|  | 78 | os << std::string( indent, ' ' ) << "clobber: " << endl; | 
|---|
|  | 79 | printAll( clobber, os, indent + 2 ); | 
|---|
|  | 80 | } // if | 
|---|
| [3be261a] | 81 | } | 
|---|
| [7f5566b] | 82 |  | 
|---|
|  | 83 |  | 
|---|
| [51b73452] | 84 | const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; | 
|---|
|  | 85 |  | 
|---|
| [0dd3a2f] | 86 | BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) : | 
|---|
| [2871210] | 87 | Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) { | 
|---|
| [0dd3a2f] | 88 | //actually this is a syntactic error signaled by the parser | 
|---|
| [0f8e4ac] | 89 | if ( type == BranchStmt::Goto && target.empty() ) | 
|---|
| [0dd3a2f] | 90 | throw SemanticError("goto without target"); | 
|---|
| [51b73452] | 91 | } | 
|---|
|  | 92 |  | 
|---|
| [0dd3a2f] | 93 | BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) : | 
|---|
| [2871210] | 94 | Statement( labels ), computedTarget( _computedTarget ), type( _type ) { | 
|---|
| [0dd3a2f] | 95 | if ( type != BranchStmt::Goto || computedTarget == 0 ) | 
|---|
|  | 96 | throw SemanticError("Computed target not valid in branch statement"); | 
|---|
| [51b73452] | 97 | } | 
|---|
|  | 98 |  | 
|---|
| [de62360d] | 99 | void BranchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 100 | os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ; | 
|---|
| [51b73452] | 101 | } | 
|---|
|  | 102 |  | 
|---|
| [0dd3a2f] | 103 | ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {} | 
|---|
| [51b73452] | 104 |  | 
|---|
| [3be261a] | 105 | ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ), isThrow( other.isThrow ) {} | 
|---|
|  | 106 |  | 
|---|
| [51b73452] | 107 | ReturnStmt::~ReturnStmt() { | 
|---|
| [0dd3a2f] | 108 | delete expr; | 
|---|
| [51b73452] | 109 | } | 
|---|
|  | 110 |  | 
|---|
| [de62360d] | 111 | void ReturnStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 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 | } | 
|---|
| [0dd3a2f] | 117 | os << endl; | 
|---|
| [51b73452] | 118 | } | 
|---|
|  | 119 |  | 
|---|
|  | 120 | IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ): | 
|---|
| [2871210] | 121 | Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {} | 
|---|
| [51b73452] | 122 |  | 
|---|
| [3be261a] | 123 | IfStmt::IfStmt( const IfStmt & other ) : | 
|---|
|  | 124 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {} | 
|---|
|  | 125 |  | 
|---|
| [51b73452] | 126 | IfStmt::~IfStmt() {} | 
|---|
|  | 127 |  | 
|---|
| [de62360d] | 128 | void IfStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 129 | os << "If on condition: " << endl ; | 
|---|
| [60089f4] | 130 | os << string( indent+4, ' ' ); | 
|---|
| [0dd3a2f] | 131 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 132 |  | 
|---|
| [60089f4] | 133 | os << string( indent+2, ' ' ) << "... then: " << endl; | 
|---|
| [51b73452] | 134 |  | 
|---|
| [60089f4] | 135 | os << string( indent+4, ' ' ); | 
|---|
| [0dd3a2f] | 136 | thenPart->print( os, indent + 4 ); | 
|---|
| [51b73452] | 137 |  | 
|---|
| [0dd3a2f] | 138 | if ( elsePart != 0 ) { | 
|---|
| [60089f4] | 139 | os << string( indent+2, ' ' ) << "... else: " << endl; | 
|---|
|  | 140 | os << string( indent+4, ' ' ); | 
|---|
| [0dd3a2f] | 141 | elsePart->print( os, indent + 4 ); | 
|---|
|  | 142 | } // if | 
|---|
| [51b73452] | 143 | } | 
|---|
|  | 144 |  | 
|---|
| [0dd3a2f] | 145 | SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): | 
|---|
| [2871210] | 146 | Statement( _labels ), condition( _condition ), branches( _branches ) { | 
|---|
| [0dd3a2f] | 147 | } | 
|---|
| [51b73452] | 148 |  | 
|---|
| [3be261a] | 149 | SwitchStmt::SwitchStmt( const SwitchStmt & other ): | 
|---|
|  | 150 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
|  | 151 | cloneAll( other.branches, branches ); | 
|---|
|  | 152 | } | 
|---|
|  | 153 |  | 
|---|
| [51b73452] | 154 | SwitchStmt::~SwitchStmt() { | 
|---|
| [0dd3a2f] | 155 | delete condition; | 
|---|
|  | 156 | // destroy branches | 
|---|
| [51b73452] | 157 | } | 
|---|
|  | 158 |  | 
|---|
| [0dd3a2f] | 159 | void SwitchStmt::add_case( CaseStmt *c ) {} | 
|---|
| [51b73452] | 160 |  | 
|---|
| [de62360d] | 161 | void SwitchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 162 | os << "Switch on condition: "; | 
|---|
| [0dd3a2f] | 163 | condition->print( os ); | 
|---|
|  | 164 | os << endl; | 
|---|
| [51b73452] | 165 |  | 
|---|
| [0dd3a2f] | 166 | // branches | 
|---|
| [de62360d] | 167 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 168 | for ( i = branches.begin(); i != branches.end(); i++) | 
|---|
| [de62360d] | 169 | (*i)->print( os, indent + 4 ); | 
|---|
| [51b73452] | 170 |  | 
|---|
| [0dd3a2f] | 171 | //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); | 
|---|
| [51b73452] | 172 | } | 
|---|
|  | 173 |  | 
|---|
| [3be261a] | 174 | CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : | 
|---|
| [2871210] | 175 | Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) { | 
|---|
| [0dd3a2f] | 176 | if ( isDefault() && condition != 0 ) | 
|---|
|  | 177 | throw SemanticError("default with conditions"); | 
|---|
| [51b73452] | 178 | } | 
|---|
|  | 179 |  | 
|---|
| [3be261a] | 180 | CaseStmt::CaseStmt( const CaseStmt & other ) : | 
|---|
|  | 181 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { | 
|---|
|  | 182 | cloneAll( other.stmts, stmts ); | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
| [51b73452] | 185 | CaseStmt::~CaseStmt() { | 
|---|
| [0dd3a2f] | 186 | delete condition; | 
|---|
| [51b73452] | 187 | } | 
|---|
|  | 188 |  | 
|---|
| [b2152e7a] | 189 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) { | 
|---|
|  | 190 | return new CaseStmt( labels, 0, branches, true ); | 
|---|
|  | 191 | } | 
|---|
|  | 192 |  | 
|---|
| [de62360d] | 193 | void CaseStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 194 | os << string( indent, ' ' ); | 
|---|
| [51b73452] | 195 |  | 
|---|
| [de62360d] | 196 | if ( isDefault() ) | 
|---|
| [0dd3a2f] | 197 | os << "Default "; | 
|---|
|  | 198 | else { | 
|---|
|  | 199 | os << "Case "; | 
|---|
|  | 200 | condition->print( os ); | 
|---|
|  | 201 | } // if | 
|---|
| [51b73452] | 202 |  | 
|---|
| [0dd3a2f] | 203 | os << endl; | 
|---|
| [51b73452] | 204 |  | 
|---|
| [de62360d] | 205 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 206 | for ( i = stmts.begin(); i != stmts.end(); i++) | 
|---|
|  | 207 | (*i )->print( os, indent + 4 ); | 
|---|
| [51b73452] | 208 | } | 
|---|
|  | 209 |  | 
|---|
|  | 210 | //ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {} | 
|---|
| [0dd3a2f] | 211 | ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): | 
|---|
| [2871210] | 212 | Statement( _labels ), condition( _condition ), branches( _branches ) { | 
|---|
| [0dd3a2f] | 213 | } | 
|---|
| [51b73452] | 214 |  | 
|---|
| [3be261a] | 215 | ChooseStmt::ChooseStmt( const ChooseStmt & other ): | 
|---|
|  | 216 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
|  | 217 | cloneAll( other.branches, branches ); | 
|---|
|  | 218 | } | 
|---|
|  | 219 |  | 
|---|
| [51b73452] | 220 | ChooseStmt::~ChooseStmt() { | 
|---|
| [0dd3a2f] | 221 | delete condition; | 
|---|
| [51b73452] | 222 | } | 
|---|
|  | 223 |  | 
|---|
| [0dd3a2f] | 224 | void ChooseStmt::add_case( CaseStmt *c ) {} | 
|---|
| [51b73452] | 225 |  | 
|---|
| [de62360d] | 226 | void ChooseStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 227 | os << "Choose on condition: "; | 
|---|
| [0dd3a2f] | 228 | condition->print( os ); | 
|---|
|  | 229 | os << endl; | 
|---|
| [51b73452] | 230 |  | 
|---|
| [0dd3a2f] | 231 | // branches | 
|---|
| [de62360d] | 232 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 233 | for ( i = branches.begin(); i != branches.end(); i++) | 
|---|
|  | 234 | (*i )->print( os, indent + 4 ); | 
|---|
| [51b73452] | 235 |  | 
|---|
| [0dd3a2f] | 236 | //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); | 
|---|
| [51b73452] | 237 | } | 
|---|
|  | 238 |  | 
|---|
| [de62360d] | 239 | void FallthruStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 240 | os << string( indent, ' ' ) << "Fall-through statement" << endl; | 
|---|
| [51b73452] | 241 | } | 
|---|
|  | 242 |  | 
|---|
| [0dd3a2f] | 243 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): | 
|---|
|  | 244 | Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { | 
|---|
|  | 245 | } | 
|---|
| [51b73452] | 246 |  | 
|---|
| [3be261a] | 247 | WhileStmt::WhileStmt( const WhileStmt & other ): | 
|---|
|  | 248 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { | 
|---|
|  | 249 | } | 
|---|
|  | 250 |  | 
|---|
| [a08ba92] | 251 | WhileStmt::~WhileStmt() { | 
|---|
| [0dd3a2f] | 252 | delete body; | 
|---|
| [51b73452] | 253 | } | 
|---|
|  | 254 |  | 
|---|
| [de62360d] | 255 | void WhileStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 256 | os << "While on condition: " << endl ; | 
|---|
| [0dd3a2f] | 257 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 258 |  | 
|---|
| [44b5ca0] | 259 | os << string( indent, ' ' ) << ".... with body: " << endl; | 
|---|
| [51b73452] | 260 |  | 
|---|
| [0dd3a2f] | 261 | if ( body != 0 ) body->print( os, indent + 4 ); | 
|---|
| [51b73452] | 262 | } | 
|---|
|  | 263 |  | 
|---|
| [145f1fc] | 264 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): | 
|---|
| [0dd3a2f] | 265 | Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { | 
|---|
|  | 266 | } | 
|---|
| [51b73452] | 267 |  | 
|---|
| [3be261a] | 268 | ForStmt::ForStmt( const ForStmt & other ): | 
|---|
|  | 269 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) { | 
|---|
|  | 270 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 271 |  | 
|---|
|  | 272 | } | 
|---|
|  | 273 |  | 
|---|
| [51b73452] | 274 | ForStmt::~ForStmt() { | 
|---|
| [145f1fc] | 275 | deleteAll( initialization ); | 
|---|
| [0dd3a2f] | 276 | delete condition; | 
|---|
|  | 277 | delete increment; | 
|---|
|  | 278 | delete body; | 
|---|
| [51b73452] | 279 | } | 
|---|
|  | 280 |  | 
|---|
| [de62360d] | 281 | void ForStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 282 | os << "Labels: {"; | 
|---|
| [de62360d] | 283 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { | 
|---|
| [be5aa1b] | 284 | os << *it << ","; | 
|---|
|  | 285 | } | 
|---|
|  | 286 | os << "}" << endl; | 
|---|
|  | 287 |  | 
|---|
| [44b5ca0] | 288 | os << string( indent, ' ' ) << "For Statement" << endl ; | 
|---|
| [51b73452] | 289 |  | 
|---|
| [3be261a] | 290 | os << string( indent + 2, ' ' ) << "initialization: \n"; | 
|---|
| [145f1fc] | 291 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { | 
|---|
| [bb8ea30] | 292 | os << string( indent + 4, ' ' ); | 
|---|
| [145f1fc] | 293 | (*it)->print( os, indent + 4 ); | 
|---|
|  | 294 | } | 
|---|
| [51b73452] | 295 |  | 
|---|
| [3be261a] | 296 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; | 
|---|
| [bb8ea30] | 297 | if ( condition != 0 ) { | 
|---|
|  | 298 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 299 | condition->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 300 | } | 
|---|
| [51b73452] | 301 |  | 
|---|
| [3be261a] | 302 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; | 
|---|
| [bb8ea30] | 303 | if ( increment != 0 ) { | 
|---|
|  | 304 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 305 | increment->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 306 | } | 
|---|
| [51b73452] | 307 |  | 
|---|
| [3be261a] | 308 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; | 
|---|
| [bb8ea30] | 309 | if ( body != 0 ) { | 
|---|
|  | 310 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 311 | body->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 312 | } | 
|---|
| [51b73452] | 313 |  | 
|---|
| [0dd3a2f] | 314 | os << endl; | 
|---|
| [51b73452] | 315 | } | 
|---|
|  | 316 |  | 
|---|
|  | 317 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) : | 
|---|
| [0dd3a2f] | 318 | Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) { | 
|---|
|  | 319 | } | 
|---|
| [51b73452] | 320 |  | 
|---|
| [3be261a] | 321 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { | 
|---|
|  | 322 | cloneAll( other.handlers, handlers ); | 
|---|
| [51b73452] | 323 | } | 
|---|
|  | 324 |  | 
|---|
| [a08ba92] | 325 | TryStmt::~TryStmt() { | 
|---|
| [0dd3a2f] | 326 | delete block; | 
|---|
| [51b73452] | 327 | } | 
|---|
|  | 328 |  | 
|---|
| [de62360d] | 329 | void TryStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 330 | os << "Try Statement" << endl; | 
|---|
| [44b5ca0] | 331 | os << string( indent + 2, ' ' ) << "with block: " << endl; | 
|---|
| [0dd3a2f] | 332 | block->print( os, indent + 4 ); | 
|---|
|  | 333 |  | 
|---|
|  | 334 | // handlers | 
|---|
| [44b5ca0] | 335 | os << string( indent + 2, ' ' ) << "and handlers: " << endl; | 
|---|
| [de62360d] | 336 | for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) | 
|---|
| [0dd3a2f] | 337 | (*i )->print( os, indent + 4 ); | 
|---|
|  | 338 |  | 
|---|
|  | 339 | // finally block | 
|---|
|  | 340 | if ( finallyBlock != 0 ) { | 
|---|
| [44b5ca0] | 341 | os << string( indent + 2, ' ' ) << "Finally block: " << endl; | 
|---|
| [0dd3a2f] | 342 | finallyBlock->print( os, indent + 4 ); | 
|---|
|  | 343 | } // if | 
|---|
| [51b73452] | 344 | } | 
|---|
|  | 345 |  | 
|---|
|  | 346 | CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) : | 
|---|
| [0dd3a2f] | 347 | Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) { | 
|---|
|  | 348 | } | 
|---|
| [51b73452] | 349 |  | 
|---|
| [3be261a] | 350 | CatchStmt::CatchStmt( const CatchStmt & other ) : | 
|---|
|  | 351 | Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) { | 
|---|
|  | 352 | } | 
|---|
|  | 353 |  | 
|---|
| [a08ba92] | 354 | CatchStmt::~CatchStmt() { | 
|---|
| [0dd3a2f] | 355 | delete decl; | 
|---|
|  | 356 | delete body; | 
|---|
| [51b73452] | 357 | } | 
|---|
|  | 358 |  | 
|---|
| [de62360d] | 359 | void CatchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [f1b1e4c] | 360 | os << "Catch Statement" << endl; | 
|---|
| [0dd3a2f] | 361 |  | 
|---|
| [44b5ca0] | 362 | os << string( indent, ' ' ) << "... catching" << endl; | 
|---|
| [0dd3a2f] | 363 | if ( decl ) { | 
|---|
|  | 364 | decl->printShort( os, indent + 4 ); | 
|---|
|  | 365 | os << endl; | 
|---|
|  | 366 | } else if ( catchRest ) | 
|---|
| [44b5ca0] | 367 | os << string( indent + 4 , ' ' ) << "the rest" << endl; | 
|---|
| [0dd3a2f] | 368 | else | 
|---|
| [44b5ca0] | 369 | os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl; | 
|---|
| [51b73452] | 370 | } | 
|---|
|  | 371 |  | 
|---|
|  | 372 |  | 
|---|
| [0dd3a2f] | 373 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { | 
|---|
|  | 374 | assert( labels.empty() ); // finally statement cannot be labeled | 
|---|
| [51b73452] | 375 | } | 
|---|
|  | 376 |  | 
|---|
| [3be261a] | 377 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { | 
|---|
|  | 378 | } | 
|---|
|  | 379 |  | 
|---|
| [0dd3a2f] | 380 | FinallyStmt::~FinallyStmt() { | 
|---|
|  | 381 | delete block; | 
|---|
| [51b73452] | 382 | } | 
|---|
|  | 383 |  | 
|---|
| [de62360d] | 384 | void FinallyStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [f1b1e4c] | 385 | os << "Finally Statement" << endl; | 
|---|
| [44b5ca0] | 386 | os << string( indent + 2, ' ' ) << "with block: " << endl; | 
|---|
| [0dd3a2f] | 387 | block->print( os, indent + 4 ); | 
|---|
| [51b73452] | 388 | } | 
|---|
|  | 389 |  | 
|---|
|  | 390 | NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {} | 
|---|
|  | 391 | NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {} | 
|---|
|  | 392 |  | 
|---|
| [de62360d] | 393 | void NullStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 394 | os << "Null Statement" << endl ; | 
|---|
| [51b73452] | 395 | } | 
|---|
|  | 396 |  | 
|---|
| [f1b1e4c] | 397 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { | 
|---|
|  | 398 | assert( callStmt ); | 
|---|
|  | 399 | } | 
|---|
|  | 400 |  | 
|---|
| [74d1804] | 401 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { | 
|---|
| [f1b1e4c] | 402 | } | 
|---|
|  | 403 |  | 
|---|
|  | 404 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { | 
|---|
| [74d1804] | 405 | delete callStmt; | 
|---|
| [f1b1e4c] | 406 | } | 
|---|
|  | 407 |  | 
|---|
|  | 408 | void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const { | 
|---|
|  | 409 | os << "Implicit Ctor Dtor Statement" << endl; | 
|---|
|  | 410 | os << string( indent + 2, ' ' ) << "with Ctor/Dtor: "; | 
|---|
|  | 411 | callStmt->print( os, indent + 2); | 
|---|
|  | 412 | os << endl; | 
|---|
|  | 413 | } | 
|---|
|  | 414 |  | 
|---|
| [baf7fee] | 415 | std::ostream & operator<<( std::ostream & out, Statement * statement ) { | 
|---|
|  | 416 | statement->print( out ); | 
|---|
|  | 417 | return out; | 
|---|
|  | 418 | } | 
|---|
|  | 419 |  | 
|---|
| [0dd3a2f] | 420 | // Local Variables: // | 
|---|
|  | 421 | // tab-width: 4 // | 
|---|
|  | 422 | // mode: c++ // | 
|---|
|  | 423 | // compile-command: "make install" // | 
|---|
|  | 424 | // End: // | 
|---|