[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 |
---|
[6d49ea3] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Thu Aug 17 16:17:20 2017 |
---|
| 13 | // Update Count : 67 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[ea6332d] | 16 | #include "SynTree/Statement.h" |
---|
[51b7345] | 17 | |
---|
[ea6332d] | 18 | #include <stddef.h> // for NULL |
---|
| 19 | #include <cassert> // for assert, assertf |
---|
| 20 | #include <iostream> // for operator<<, basic_ostream, endl |
---|
| 21 | #include <list> // for list, list<>::const_iterator, _Lis... |
---|
| 22 | #include <string> // for operator<<, string, char_traits |
---|
| 23 | |
---|
| 24 | #include "Common/SemanticError.h" // for SemanticError |
---|
| 25 | #include "Common/utility.h" // for maybeClone, cloneAll, deleteAll |
---|
| 26 | #include "Declaration.h" // for Declaration |
---|
| 27 | #include "Expression.h" // for Expression, ConstantExpr |
---|
| 28 | #include "Statement.h" // for Statement, ForStmt, AsmStmt, Catch... |
---|
| 29 | #include "SynTree/Label.h" // for Label, operator<< |
---|
[51b7345] | 30 | |
---|
| 31 | using std::string; |
---|
| 32 | using std::endl; |
---|
| 33 | |
---|
[6d49ea3] | 34 | Statement::Statement( std::list<Label> labels ) : labels( labels ) {} |
---|
[51b7345] | 35 | |
---|
[b3c36f4] | 36 | void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {} |
---|
[51b7345] | 37 | |
---|
| 38 | Statement::~Statement() {} |
---|
| 39 | |
---|
[6d49ea3] | 40 | ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {} |
---|
[51b7345] | 41 | |
---|
[3be261a] | 42 | ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} |
---|
| 43 | |
---|
| 44 | ExprStmt::~ExprStmt() { |
---|
| 45 | delete expr; |
---|
| 46 | } |
---|
[51b7345] | 47 | |
---|
[de62360d] | 48 | void ExprStmt::print( std::ostream &os, int indent ) const { |
---|
[bb8ea30] | 49 | os << "Expression Statement:" << endl << std::string( indent + 2, ' ' ); |
---|
[0dd3a2f] | 50 | expr->print( os, indent + 2 ); |
---|
[3be261a] | 51 | } |
---|
[51b7345] | 52 | |
---|
[7f5566b] | 53 | |
---|
| 54 | 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 ) {} |
---|
| 55 | |
---|
[3be261a] | 56 | AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { |
---|
| 57 | cloneAll( other.output, output ); |
---|
| 58 | cloneAll( other.input, input ); |
---|
| 59 | cloneAll( other.clobber, clobber ); |
---|
| 60 | } |
---|
| 61 | |
---|
[7f5566b] | 62 | AsmStmt::~AsmStmt() { |
---|
| 63 | delete instruction; |
---|
| 64 | deleteAll( output ); |
---|
| 65 | deleteAll( input ); |
---|
| 66 | deleteAll( clobber ); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | void AsmStmt::print( std::ostream &os, int indent ) const { |
---|
| 70 | os << "Assembler Statement:" << endl; |
---|
| 71 | os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' ); |
---|
| 72 | instruction->print( os, indent + 2 ); |
---|
| 73 | if ( ! output.empty() ) { |
---|
| 74 | os << endl << std::string( indent, ' ' ) << "output: " << endl; |
---|
| 75 | printAll( output, os, indent + 2 ); |
---|
[3be261a] | 76 | } // if |
---|
[7f5566b] | 77 | if ( ! input.empty() ) { |
---|
| 78 | os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' ); |
---|
| 79 | printAll( input, os, indent + 2 ); |
---|
| 80 | } // if |
---|
| 81 | if ( ! clobber.empty() ) { |
---|
| 82 | os << std::string( indent, ' ' ) << "clobber: " << endl; |
---|
| 83 | printAll( clobber, os, indent + 2 ); |
---|
| 84 | } // if |
---|
[3be261a] | 85 | } |
---|
[7f5566b] | 86 | |
---|
| 87 | |
---|
[51b7345] | 88 | const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; |
---|
| 89 | |
---|
[6d49ea3] | 90 | BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) : |
---|
| 91 | Statement( labels ), originalTarget( target ), target( target ), computedTarget( NULL ), type( type ) { |
---|
[0dd3a2f] | 92 | //actually this is a syntactic error signaled by the parser |
---|
[0f8e4ac] | 93 | if ( type == BranchStmt::Goto && target.empty() ) |
---|
[0dd3a2f] | 94 | throw SemanticError("goto without target"); |
---|
[51b7345] | 95 | } |
---|
| 96 | |
---|
[6d49ea3] | 97 | BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) : |
---|
| 98 | Statement( labels ), computedTarget( computedTarget ), type( type ) { |
---|
[0dd3a2f] | 99 | if ( type != BranchStmt::Goto || computedTarget == 0 ) |
---|
| 100 | throw SemanticError("Computed target not valid in branch statement"); |
---|
[51b7345] | 101 | } |
---|
| 102 | |
---|
[de62360d] | 103 | void BranchStmt::print( std::ostream &os, int indent ) const { |
---|
[44b5ca0] | 104 | os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ; |
---|
[51b7345] | 105 | } |
---|
| 106 | |
---|
[6d49ea3] | 107 | ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {} |
---|
[51b7345] | 108 | |
---|
[daf1af8] | 109 | ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} |
---|
[3be261a] | 110 | |
---|
[51b7345] | 111 | ReturnStmt::~ReturnStmt() { |
---|
[0dd3a2f] | 112 | delete expr; |
---|
[51b7345] | 113 | } |
---|
| 114 | |
---|
[de62360d] | 115 | void ReturnStmt::print( std::ostream &os, int indent ) const { |
---|
[daf1af8] | 116 | os << "Return Statement, returning: "; |
---|
[89231bc] | 117 | if ( expr != 0 ) { |
---|
| 118 | os << endl << string( indent+2, ' ' ); |
---|
| 119 | expr->print( os, indent + 2 ); |
---|
| 120 | } |
---|
[0dd3a2f] | 121 | os << endl; |
---|
[51b7345] | 122 | } |
---|
| 123 | |
---|
[6d49ea3] | 124 | IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ): |
---|
| 125 | Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {} |
---|
[51b7345] | 126 | |
---|
[3be261a] | 127 | IfStmt::IfStmt( const IfStmt & other ) : |
---|
[6d49ea3] | 128 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { |
---|
| 129 | cloneAll( other.initialization, initialization ); |
---|
| 130 | } |
---|
[3be261a] | 131 | |
---|
[ac71a86] | 132 | IfStmt::~IfStmt() { |
---|
[6d49ea3] | 133 | deleteAll( initialization ); |
---|
[ac71a86] | 134 | delete condition; |
---|
| 135 | delete thenPart; |
---|
| 136 | delete elsePart; |
---|
| 137 | } |
---|
[51b7345] | 138 | |
---|
[de62360d] | 139 | void IfStmt::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 140 | os << "If on condition: " << endl ; |
---|
[60089f4] | 141 | os << string( indent+4, ' ' ); |
---|
[0dd3a2f] | 142 | condition->print( os, indent + 4 ); |
---|
[51b7345] | 143 | |
---|
[6d49ea3] | 144 | if ( !initialization.empty() ) { |
---|
| 145 | os << string( indent + 2, ' ' ) << "initialization: \n"; |
---|
| 146 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { |
---|
| 147 | os << string( indent + 4, ' ' ); |
---|
| 148 | (*it)->print( os, indent + 4 ); |
---|
| 149 | } |
---|
| 150 | os << endl; |
---|
| 151 | } |
---|
| 152 | |
---|
[60089f4] | 153 | os << string( indent+2, ' ' ) << "... then: " << endl; |
---|
[51b7345] | 154 | |
---|
[60089f4] | 155 | os << string( indent+4, ' ' ); |
---|
[0dd3a2f] | 156 | thenPart->print( os, indent + 4 ); |
---|
[51b7345] | 157 | |
---|
[0dd3a2f] | 158 | if ( elsePart != 0 ) { |
---|
[60089f4] | 159 | os << string( indent+2, ' ' ) << "... else: " << endl; |
---|
| 160 | os << string( indent+4, ' ' ); |
---|
[0dd3a2f] | 161 | elsePart->print( os, indent + 4 ); |
---|
| 162 | } // if |
---|
[51b7345] | 163 | } |
---|
| 164 | |
---|
[6d49ea3] | 165 | SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ): |
---|
| 166 | Statement( labels ), condition( condition ), statements( statements ) { |
---|
[0dd3a2f] | 167 | } |
---|
[51b7345] | 168 | |
---|
[3be261a] | 169 | SwitchStmt::SwitchStmt( const SwitchStmt & other ): |
---|
| 170 | Statement( other ), condition( maybeClone( other.condition ) ) { |
---|
[8688ce1] | 171 | cloneAll( other.statements, statements ); |
---|
[3be261a] | 172 | } |
---|
| 173 | |
---|
[51b7345] | 174 | SwitchStmt::~SwitchStmt() { |
---|
[0dd3a2f] | 175 | delete condition; |
---|
[8688ce1] | 176 | // destroy statements |
---|
[2037f82] | 177 | deleteAll( statements ); |
---|
[51b7345] | 178 | } |
---|
| 179 | |
---|
[de62360d] | 180 | void SwitchStmt::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 181 | os << "Switch on condition: "; |
---|
[0dd3a2f] | 182 | condition->print( os ); |
---|
| 183 | os << endl; |
---|
[51b7345] | 184 | |
---|
[8688ce1] | 185 | // statements |
---|
[de62360d] | 186 | std::list<Statement *>::const_iterator i; |
---|
[8688ce1] | 187 | for ( i = statements.begin(); i != statements.end(); i++) |
---|
[de62360d] | 188 | (*i)->print( os, indent + 4 ); |
---|
[51b7345] | 189 | |
---|
[8688ce1] | 190 | //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os )); |
---|
[51b7345] | 191 | } |
---|
| 192 | |
---|
[6d49ea3] | 193 | CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) : |
---|
| 194 | Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) { |
---|
[0dd3a2f] | 195 | if ( isDefault() && condition != 0 ) |
---|
| 196 | throw SemanticError("default with conditions"); |
---|
[51b7345] | 197 | } |
---|
| 198 | |
---|
[3be261a] | 199 | CaseStmt::CaseStmt( const CaseStmt & other ) : |
---|
| 200 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { |
---|
| 201 | cloneAll( other.stmts, stmts ); |
---|
| 202 | } |
---|
| 203 | |
---|
[51b7345] | 204 | CaseStmt::~CaseStmt() { |
---|
[0dd3a2f] | 205 | delete condition; |
---|
[2037f82] | 206 | deleteAll( stmts ); |
---|
[51b7345] | 207 | } |
---|
| 208 | |
---|
[8688ce1] | 209 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) { |
---|
| 210 | return new CaseStmt( labels, 0, stmts, true ); |
---|
[b2152e7a] | 211 | } |
---|
| 212 | |
---|
[de62360d] | 213 | void CaseStmt::print( std::ostream &os, int indent ) const { |
---|
[44b5ca0] | 214 | os << string( indent, ' ' ); |
---|
[51b7345] | 215 | |
---|
[de62360d] | 216 | if ( isDefault() ) |
---|
[0dd3a2f] | 217 | os << "Default "; |
---|
| 218 | else { |
---|
| 219 | os << "Case "; |
---|
| 220 | condition->print( os ); |
---|
| 221 | } // if |
---|
[51b7345] | 222 | |
---|
[0dd3a2f] | 223 | os << endl; |
---|
[51b7345] | 224 | |
---|
[de62360d] | 225 | std::list<Statement *>::const_iterator i; |
---|
[0dd3a2f] | 226 | for ( i = stmts.begin(); i != stmts.end(); i++) |
---|
| 227 | (*i )->print( os, indent + 4 ); |
---|
[51b7345] | 228 | } |
---|
| 229 | |
---|
[6d49ea3] | 230 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ): |
---|
| 231 | Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) { |
---|
[0dd3a2f] | 232 | } |
---|
[51b7345] | 233 | |
---|
[3be261a] | 234 | WhileStmt::WhileStmt( const WhileStmt & other ): |
---|
| 235 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { |
---|
| 236 | } |
---|
| 237 | |
---|
[a08ba92] | 238 | WhileStmt::~WhileStmt() { |
---|
[0dd3a2f] | 239 | delete body; |
---|
[2037f82] | 240 | delete condition; |
---|
[51b7345] | 241 | } |
---|
| 242 | |
---|
[de62360d] | 243 | void WhileStmt::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 244 | os << "While on condition: " << endl ; |
---|
[0dd3a2f] | 245 | condition->print( os, indent + 4 ); |
---|
[51b7345] | 246 | |
---|
[44b5ca0] | 247 | os << string( indent, ' ' ) << ".... with body: " << endl; |
---|
[51b7345] | 248 | |
---|
[0dd3a2f] | 249 | if ( body != 0 ) body->print( os, indent + 4 ); |
---|
[51b7345] | 250 | } |
---|
| 251 | |
---|
[6d49ea3] | 252 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ): |
---|
| 253 | Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) { |
---|
[0dd3a2f] | 254 | } |
---|
[51b7345] | 255 | |
---|
[3be261a] | 256 | ForStmt::ForStmt( const ForStmt & other ): |
---|
| 257 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) { |
---|
| 258 | cloneAll( other.initialization, initialization ); |
---|
| 259 | |
---|
| 260 | } |
---|
| 261 | |
---|
[51b7345] | 262 | ForStmt::~ForStmt() { |
---|
[145f1fc] | 263 | deleteAll( initialization ); |
---|
[0dd3a2f] | 264 | delete condition; |
---|
| 265 | delete increment; |
---|
| 266 | delete body; |
---|
[51b7345] | 267 | } |
---|
| 268 | |
---|
[de62360d] | 269 | void ForStmt::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 270 | os << "Labels: {"; |
---|
[de62360d] | 271 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { |
---|
[be5aa1b] | 272 | os << *it << ","; |
---|
| 273 | } |
---|
| 274 | os << "}" << endl; |
---|
| 275 | |
---|
[44b5ca0] | 276 | os << string( indent, ' ' ) << "For Statement" << endl ; |
---|
[51b7345] | 277 | |
---|
[3be261a] | 278 | os << string( indent + 2, ' ' ) << "initialization: \n"; |
---|
[145f1fc] | 279 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { |
---|
[bb8ea30] | 280 | os << string( indent + 4, ' ' ); |
---|
[145f1fc] | 281 | (*it)->print( os, indent + 4 ); |
---|
| 282 | } |
---|
[51b7345] | 283 | |
---|
[3be261a] | 284 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; |
---|
[bb8ea30] | 285 | if ( condition != 0 ) { |
---|
| 286 | os << string( indent + 4, ' ' ); |
---|
[0dd3a2f] | 287 | condition->print( os, indent + 4 ); |
---|
[bb8ea30] | 288 | } |
---|
[51b7345] | 289 | |
---|
[3be261a] | 290 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; |
---|
[bb8ea30] | 291 | if ( increment != 0 ) { |
---|
| 292 | os << string( indent + 4, ' ' ); |
---|
[0dd3a2f] | 293 | increment->print( os, indent + 4 ); |
---|
[bb8ea30] | 294 | } |
---|
[51b7345] | 295 | |
---|
[3be261a] | 296 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; |
---|
[bb8ea30] | 297 | if ( body != 0 ) { |
---|
| 298 | os << string( indent + 4, ' ' ); |
---|
[0dd3a2f] | 299 | body->print( os, indent + 4 ); |
---|
[bb8ea30] | 300 | } |
---|
[51b7345] | 301 | |
---|
[0dd3a2f] | 302 | os << endl; |
---|
[51b7345] | 303 | } |
---|
| 304 | |
---|
[daf1af8] | 305 | ThrowStmt::ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target ) : |
---|
| 306 | Statement( labels ), kind(kind), expr(expr), target(target) { |
---|
| 307 | assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." ); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | ThrowStmt::ThrowStmt( const ThrowStmt &other ) : |
---|
| 311 | Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | ThrowStmt::~ThrowStmt() { |
---|
| 315 | delete expr; |
---|
| 316 | delete target; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | void ThrowStmt::print( std::ostream &os, int indent) const { |
---|
| 320 | if ( target ) { |
---|
| 321 | os << "Non-Local "; |
---|
| 322 | } |
---|
| 323 | os << "Throw Statement, raising: "; |
---|
| 324 | expr->print(os, indent + 4); |
---|
| 325 | if ( target ) { |
---|
| 326 | os << "At: "; |
---|
| 327 | target->print(os, indent + 4); |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
[6d49ea3] | 331 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) : |
---|
| 332 | Statement( labels ), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) { |
---|
[0dd3a2f] | 333 | } |
---|
[51b7345] | 334 | |
---|
[3be261a] | 335 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { |
---|
| 336 | cloneAll( other.handlers, handlers ); |
---|
[51b7345] | 337 | } |
---|
| 338 | |
---|
[a08ba92] | 339 | TryStmt::~TryStmt() { |
---|
[0dd3a2f] | 340 | delete block; |
---|
[2037f82] | 341 | deleteAll( handlers ); |
---|
| 342 | delete finallyBlock; |
---|
[51b7345] | 343 | } |
---|
| 344 | |
---|
[de62360d] | 345 | void TryStmt::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 346 | os << "Try Statement" << endl; |
---|
[406a6e6] | 347 | os << string( indent + 2, ' ' ) << "with block:" << endl; |
---|
| 348 | os << string( indent + 4, ' ' ); |
---|
[0dd3a2f] | 349 | block->print( os, indent + 4 ); |
---|
| 350 | |
---|
| 351 | // handlers |
---|
[406a6e6] | 352 | os << string( indent + 2, ' ' ) << "and handlers:" << endl; |
---|
| 353 | for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) { |
---|
| 354 | os << string( indent + 4, ' ' ); |
---|
[0dd3a2f] | 355 | (*i )->print( os, indent + 4 ); |
---|
[406a6e6] | 356 | } |
---|
[0dd3a2f] | 357 | |
---|
| 358 | // finally block |
---|
| 359 | if ( finallyBlock != 0 ) { |
---|
[406a6e6] | 360 | os << string( indent + 2, ' ' ) << "and finally:" << endl; |
---|
[0dd3a2f] | 361 | finallyBlock->print( os, indent + 4 ); |
---|
| 362 | } // if |
---|
[51b7345] | 363 | } |
---|
| 364 | |
---|
[6d49ea3] | 365 | CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) : |
---|
| 366 | Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { |
---|
[0dd3a2f] | 367 | } |
---|
[51b7345] | 368 | |
---|
[3be261a] | 369 | CatchStmt::CatchStmt( const CatchStmt & other ) : |
---|
[ca78437] | 370 | Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) { |
---|
[3be261a] | 371 | } |
---|
| 372 | |
---|
[a08ba92] | 373 | CatchStmt::~CatchStmt() { |
---|
[0dd3a2f] | 374 | delete decl; |
---|
| 375 | delete body; |
---|
[51b7345] | 376 | } |
---|
| 377 | |
---|
[de62360d] | 378 | void CatchStmt::print( std::ostream &os, int indent ) const { |
---|
[ca78437] | 379 | os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; |
---|
[0dd3a2f] | 380 | |
---|
[406a6e6] | 381 | os << string( indent + 2, ' ' ) << "... catching: "; |
---|
[0dd3a2f] | 382 | if ( decl ) { |
---|
| 383 | decl->printShort( os, indent + 4 ); |
---|
| 384 | os << endl; |
---|
[ca78437] | 385 | } |
---|
[0dd3a2f] | 386 | else |
---|
[44b5ca0] | 387 | os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl; |
---|
[406a6e6] | 388 | |
---|
| 389 | if ( cond ) { |
---|
| 390 | os << string( indent + 2, ' ' ) << "with conditional:" << endl; |
---|
| 391 | os << string( indent + 4, ' ' ); |
---|
| 392 | cond->print( os, indent + 4 ); |
---|
| 393 | } |
---|
| 394 | else |
---|
| 395 | os << string( indent + 2, ' ' ) << "with no conditional" << endl; |
---|
| 396 | |
---|
| 397 | os << string( indent + 2, ' ' ) << "with block:" << endl; |
---|
| 398 | os << string( indent + 4, ' ' ); |
---|
| 399 | body->print( os, indent + 4 ); |
---|
[51b7345] | 400 | } |
---|
| 401 | |
---|
| 402 | |
---|
[6d49ea3] | 403 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) { |
---|
[0dd3a2f] | 404 | assert( labels.empty() ); // finally statement cannot be labeled |
---|
[51b7345] | 405 | } |
---|
| 406 | |
---|
[3be261a] | 407 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { |
---|
| 408 | } |
---|
| 409 | |
---|
[0dd3a2f] | 410 | FinallyStmt::~FinallyStmt() { |
---|
| 411 | delete block; |
---|
[51b7345] | 412 | } |
---|
| 413 | |
---|
[de62360d] | 414 | void FinallyStmt::print( std::ostream &os, int indent ) const { |
---|
[f1b1e4c] | 415 | os << "Finally Statement" << endl; |
---|
[406a6e6] | 416 | os << string( indent + 2, ' ' ) << "with block:" << endl; |
---|
| 417 | os << string( indent + 4, ' ' ); |
---|
[0dd3a2f] | 418 | block->print( os, indent + 4 ); |
---|
[51b7345] | 419 | } |
---|
| 420 | |
---|
[135b431] | 421 | WaitForStmt::WaitForStmt( std::list<Label> labels ) : Statement( labels ) { |
---|
| 422 | timeout.time = nullptr; |
---|
| 423 | timeout.statement = nullptr; |
---|
| 424 | timeout.condition = nullptr; |
---|
| 425 | orelse .statement = nullptr; |
---|
| 426 | orelse .condition = nullptr; |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | WaitForStmt::WaitForStmt( const WaitForStmt & other ) : Statement( other ) { |
---|
| 430 | clauses.reserve( other.clauses.size() ); |
---|
| 431 | for( auto & ocl : other.clauses ) { |
---|
| 432 | clauses.emplace_back(); |
---|
| 433 | clauses.back().target.function = ocl.target.function->clone(); |
---|
| 434 | cloneAll( ocl.target.arguments, clauses.back().target.arguments ); |
---|
| 435 | clauses.back().statement = ocl.statement->clone(); |
---|
| 436 | clauses.back().condition = ocl.condition->clone(); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | timeout.time = other.timeout.time ->clone(); |
---|
| 440 | timeout.statement = other.timeout.statement->clone(); |
---|
| 441 | timeout.condition = other.timeout.condition->clone(); |
---|
| 442 | orelse .statement = other.orelse .statement->clone(); |
---|
| 443 | orelse .condition = other.orelse .condition->clone(); |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | WaitForStmt::~WaitForStmt() { |
---|
| 447 | for( auto & clause : clauses ) { |
---|
| 448 | delete clause.target.function; |
---|
| 449 | deleteAll( clause.target.arguments ); |
---|
| 450 | delete clause.statement; |
---|
| 451 | delete clause.condition; |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | delete timeout.time; |
---|
| 455 | delete timeout.statement; |
---|
| 456 | delete timeout.condition; |
---|
| 457 | |
---|
| 458 | delete orelse.statement; |
---|
| 459 | delete orelse.condition; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | void WaitForStmt::print( std::ostream &os, int indent ) const { |
---|
| 463 | os << "Waitfor Statement" << endl; |
---|
| 464 | os << string( indent + 2, ' ' ) << "with block:" << endl; |
---|
| 465 | os << string( indent + 4, ' ' ); |
---|
| 466 | // block->print( os, indent + 4 ); |
---|
| 467 | } |
---|
| 468 | |
---|
[51b7345] | 469 | NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {} |
---|
| 470 | NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {} |
---|
| 471 | |
---|
[b3c36f4] | 472 | void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const { |
---|
[89231bc] | 473 | os << "Null Statement" << endl ; |
---|
[51b7345] | 474 | } |
---|
| 475 | |
---|
[f1b1e4c] | 476 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { |
---|
| 477 | assert( callStmt ); |
---|
| 478 | } |
---|
| 479 | |
---|
[74d1804] | 480 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { |
---|
[f1b1e4c] | 481 | } |
---|
| 482 | |
---|
| 483 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { |
---|
[74d1804] | 484 | delete callStmt; |
---|
[f1b1e4c] | 485 | } |
---|
| 486 | |
---|
| 487 | void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const { |
---|
| 488 | os << "Implicit Ctor Dtor Statement" << endl; |
---|
| 489 | os << string( indent + 2, ' ' ) << "with Ctor/Dtor: "; |
---|
| 490 | callStmt->print( os, indent + 2); |
---|
| 491 | os << endl; |
---|
| 492 | } |
---|
| 493 | |
---|
[3906301] | 494 | std::ostream & operator<<( std::ostream & out, const Statement * statement ) { |
---|
[8bf784a] | 495 | if ( statement ) { |
---|
| 496 | statement->print( out ); |
---|
| 497 | } else { |
---|
| 498 | out << "nullptr"; |
---|
| 499 | } |
---|
[baf7fee] | 500 | return out; |
---|
| 501 | } |
---|
| 502 | |
---|
[0dd3a2f] | 503 | // Local Variables: // |
---|
| 504 | // tab-width: 4 // |
---|
| 505 | // mode: c++ // |
---|
| 506 | // compile-command: "make install" // |
---|
| 507 | // End: // |
---|