| [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 | 
|---|
| [4e06c1e] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [8688ce1] | 12 | // Last Modified On : Thu Aug  4 11:25:20 2016 | 
|---|
|  | 13 | // Update Count     : 61 | 
|---|
| [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 |  | 
|---|
| [8688ce1] | 145 | SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ): | 
|---|
|  | 146 | Statement( _labels ), condition( _condition ), statements( _statements ) { | 
|---|
| [0dd3a2f] | 147 | } | 
|---|
| [51b73452] | 148 |  | 
|---|
| [3be261a] | 149 | SwitchStmt::SwitchStmt( const SwitchStmt & other ): | 
|---|
|  | 150 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
| [8688ce1] | 151 | cloneAll( other.statements, statements ); | 
|---|
| [3be261a] | 152 | } | 
|---|
|  | 153 |  | 
|---|
| [51b73452] | 154 | SwitchStmt::~SwitchStmt() { | 
|---|
| [0dd3a2f] | 155 | delete condition; | 
|---|
| [8688ce1] | 156 | // destroy statements | 
|---|
| [51b73452] | 157 | } | 
|---|
|  | 158 |  | 
|---|
| [de62360d] | 159 | void SwitchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 160 | os << "Switch on condition: "; | 
|---|
| [0dd3a2f] | 161 | condition->print( os ); | 
|---|
|  | 162 | os << endl; | 
|---|
| [51b73452] | 163 |  | 
|---|
| [8688ce1] | 164 | // statements | 
|---|
| [de62360d] | 165 | std::list<Statement *>::const_iterator i; | 
|---|
| [8688ce1] | 166 | for ( i = statements.begin(); i != statements.end(); i++) | 
|---|
| [de62360d] | 167 | (*i)->print( os, indent + 4 ); | 
|---|
| [51b73452] | 168 |  | 
|---|
| [8688ce1] | 169 | //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os )); | 
|---|
| [51b73452] | 170 | } | 
|---|
|  | 171 |  | 
|---|
| [3be261a] | 172 | CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : | 
|---|
| [2871210] | 173 | Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) { | 
|---|
| [0dd3a2f] | 174 | if ( isDefault() && condition != 0 ) | 
|---|
|  | 175 | throw SemanticError("default with conditions"); | 
|---|
| [51b73452] | 176 | } | 
|---|
|  | 177 |  | 
|---|
| [3be261a] | 178 | CaseStmt::CaseStmt( const CaseStmt & other ) : | 
|---|
|  | 179 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { | 
|---|
|  | 180 | cloneAll( other.stmts, stmts ); | 
|---|
|  | 181 | } | 
|---|
|  | 182 |  | 
|---|
| [51b73452] | 183 | CaseStmt::~CaseStmt() { | 
|---|
| [0dd3a2f] | 184 | delete condition; | 
|---|
| [51b73452] | 185 | } | 
|---|
|  | 186 |  | 
|---|
| [8688ce1] | 187 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) { | 
|---|
|  | 188 | return new CaseStmt( labels, 0, stmts, true ); | 
|---|
| [b2152e7a] | 189 | } | 
|---|
|  | 190 |  | 
|---|
| [de62360d] | 191 | void CaseStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 192 | os << string( indent, ' ' ); | 
|---|
| [51b73452] | 193 |  | 
|---|
| [de62360d] | 194 | if ( isDefault() ) | 
|---|
| [0dd3a2f] | 195 | os << "Default "; | 
|---|
|  | 196 | else { | 
|---|
|  | 197 | os << "Case "; | 
|---|
|  | 198 | condition->print( os ); | 
|---|
|  | 199 | } // if | 
|---|
| [51b73452] | 200 |  | 
|---|
| [0dd3a2f] | 201 | os << endl; | 
|---|
| [51b73452] | 202 |  | 
|---|
| [de62360d] | 203 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 204 | for ( i = stmts.begin(); i != stmts.end(); i++) | 
|---|
|  | 205 | (*i )->print( os, indent + 4 ); | 
|---|
| [51b73452] | 206 | } | 
|---|
|  | 207 |  | 
|---|
| [0dd3a2f] | 208 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): | 
|---|
|  | 209 | Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { | 
|---|
|  | 210 | } | 
|---|
| [51b73452] | 211 |  | 
|---|
| [3be261a] | 212 | WhileStmt::WhileStmt( const WhileStmt & other ): | 
|---|
|  | 213 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { | 
|---|
|  | 214 | } | 
|---|
|  | 215 |  | 
|---|
| [a08ba92] | 216 | WhileStmt::~WhileStmt() { | 
|---|
| [0dd3a2f] | 217 | delete body; | 
|---|
| [51b73452] | 218 | } | 
|---|
|  | 219 |  | 
|---|
| [de62360d] | 220 | void WhileStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 221 | os << "While on condition: " << endl ; | 
|---|
| [0dd3a2f] | 222 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 223 |  | 
|---|
| [44b5ca0] | 224 | os << string( indent, ' ' ) << ".... with body: " << endl; | 
|---|
| [51b73452] | 225 |  | 
|---|
| [0dd3a2f] | 226 | if ( body != 0 ) body->print( os, indent + 4 ); | 
|---|
| [51b73452] | 227 | } | 
|---|
|  | 228 |  | 
|---|
| [145f1fc] | 229 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): | 
|---|
| [0dd3a2f] | 230 | Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { | 
|---|
|  | 231 | } | 
|---|
| [51b73452] | 232 |  | 
|---|
| [3be261a] | 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 |  | 
|---|
|  | 237 | } | 
|---|
|  | 238 |  | 
|---|
| [51b73452] | 239 | ForStmt::~ForStmt() { | 
|---|
| [145f1fc] | 240 | deleteAll( initialization ); | 
|---|
| [0dd3a2f] | 241 | delete condition; | 
|---|
|  | 242 | delete increment; | 
|---|
|  | 243 | delete body; | 
|---|
| [51b73452] | 244 | } | 
|---|
|  | 245 |  | 
|---|
| [de62360d] | 246 | void ForStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 247 | os << "Labels: {"; | 
|---|
| [de62360d] | 248 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { | 
|---|
| [be5aa1b] | 249 | os << *it << ","; | 
|---|
|  | 250 | } | 
|---|
|  | 251 | os << "}" << endl; | 
|---|
|  | 252 |  | 
|---|
| [44b5ca0] | 253 | os << string( indent, ' ' ) << "For Statement" << endl ; | 
|---|
| [51b73452] | 254 |  | 
|---|
| [3be261a] | 255 | os << string( indent + 2, ' ' ) << "initialization: \n"; | 
|---|
| [145f1fc] | 256 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { | 
|---|
| [bb8ea30] | 257 | os << string( indent + 4, ' ' ); | 
|---|
| [145f1fc] | 258 | (*it)->print( os, indent + 4 ); | 
|---|
|  | 259 | } | 
|---|
| [51b73452] | 260 |  | 
|---|
| [3be261a] | 261 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; | 
|---|
| [bb8ea30] | 262 | if ( condition != 0 ) { | 
|---|
|  | 263 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 264 | condition->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 265 | } | 
|---|
| [51b73452] | 266 |  | 
|---|
| [3be261a] | 267 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; | 
|---|
| [bb8ea30] | 268 | if ( increment != 0 ) { | 
|---|
|  | 269 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 270 | increment->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 271 | } | 
|---|
| [51b73452] | 272 |  | 
|---|
| [3be261a] | 273 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; | 
|---|
| [bb8ea30] | 274 | if ( body != 0 ) { | 
|---|
|  | 275 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 276 | body->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 277 | } | 
|---|
| [51b73452] | 278 |  | 
|---|
| [0dd3a2f] | 279 | os << endl; | 
|---|
| [51b73452] | 280 | } | 
|---|
|  | 281 |  | 
|---|
|  | 282 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) : | 
|---|
| [0dd3a2f] | 283 | Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) { | 
|---|
|  | 284 | } | 
|---|
| [51b73452] | 285 |  | 
|---|
| [3be261a] | 286 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { | 
|---|
|  | 287 | cloneAll( other.handlers, handlers ); | 
|---|
| [51b73452] | 288 | } | 
|---|
|  | 289 |  | 
|---|
| [a08ba92] | 290 | TryStmt::~TryStmt() { | 
|---|
| [0dd3a2f] | 291 | delete block; | 
|---|
| [51b73452] | 292 | } | 
|---|
|  | 293 |  | 
|---|
| [de62360d] | 294 | void TryStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 295 | os << "Try Statement" << endl; | 
|---|
| [44b5ca0] | 296 | os << string( indent + 2, ' ' ) << "with block: " << endl; | 
|---|
| [0dd3a2f] | 297 | block->print( os, indent + 4 ); | 
|---|
|  | 298 |  | 
|---|
|  | 299 | // handlers | 
|---|
| [44b5ca0] | 300 | os << string( indent + 2, ' ' ) << "and handlers: " << endl; | 
|---|
| [de62360d] | 301 | for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) | 
|---|
| [0dd3a2f] | 302 | (*i )->print( os, indent + 4 ); | 
|---|
|  | 303 |  | 
|---|
|  | 304 | // finally block | 
|---|
|  | 305 | if ( finallyBlock != 0 ) { | 
|---|
| [44b5ca0] | 306 | os << string( indent + 2, ' ' ) << "Finally block: " << endl; | 
|---|
| [0dd3a2f] | 307 | finallyBlock->print( os, indent + 4 ); | 
|---|
|  | 308 | } // if | 
|---|
| [51b73452] | 309 | } | 
|---|
|  | 310 |  | 
|---|
|  | 311 | CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) : | 
|---|
| [0dd3a2f] | 312 | Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) { | 
|---|
|  | 313 | } | 
|---|
| [51b73452] | 314 |  | 
|---|
| [3be261a] | 315 | CatchStmt::CatchStmt( const CatchStmt & other ) : | 
|---|
|  | 316 | Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) { | 
|---|
|  | 317 | } | 
|---|
|  | 318 |  | 
|---|
| [a08ba92] | 319 | CatchStmt::~CatchStmt() { | 
|---|
| [0dd3a2f] | 320 | delete decl; | 
|---|
|  | 321 | delete body; | 
|---|
| [51b73452] | 322 | } | 
|---|
|  | 323 |  | 
|---|
| [de62360d] | 324 | void CatchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [f1b1e4c] | 325 | os << "Catch Statement" << endl; | 
|---|
| [0dd3a2f] | 326 |  | 
|---|
| [44b5ca0] | 327 | os << string( indent, ' ' ) << "... catching" << endl; | 
|---|
| [0dd3a2f] | 328 | if ( decl ) { | 
|---|
|  | 329 | decl->printShort( os, indent + 4 ); | 
|---|
|  | 330 | os << endl; | 
|---|
|  | 331 | } else if ( catchRest ) | 
|---|
| [44b5ca0] | 332 | os << string( indent + 4 , ' ' ) << "the rest" << endl; | 
|---|
| [0dd3a2f] | 333 | else | 
|---|
| [44b5ca0] | 334 | os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl; | 
|---|
| [51b73452] | 335 | } | 
|---|
|  | 336 |  | 
|---|
|  | 337 |  | 
|---|
| [0dd3a2f] | 338 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { | 
|---|
|  | 339 | assert( labels.empty() ); // finally statement cannot be labeled | 
|---|
| [51b73452] | 340 | } | 
|---|
|  | 341 |  | 
|---|
| [3be261a] | 342 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { | 
|---|
|  | 343 | } | 
|---|
|  | 344 |  | 
|---|
| [0dd3a2f] | 345 | FinallyStmt::~FinallyStmt() { | 
|---|
|  | 346 | delete block; | 
|---|
| [51b73452] | 347 | } | 
|---|
|  | 348 |  | 
|---|
| [de62360d] | 349 | void FinallyStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [f1b1e4c] | 350 | os << "Finally Statement" << endl; | 
|---|
| [44b5ca0] | 351 | os << string( indent + 2, ' ' ) << "with block: " << endl; | 
|---|
| [0dd3a2f] | 352 | block->print( os, indent + 4 ); | 
|---|
| [51b73452] | 353 | } | 
|---|
|  | 354 |  | 
|---|
|  | 355 | NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {} | 
|---|
|  | 356 | NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {} | 
|---|
|  | 357 |  | 
|---|
| [de62360d] | 358 | void NullStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 359 | os << "Null Statement" << endl ; | 
|---|
| [51b73452] | 360 | } | 
|---|
|  | 361 |  | 
|---|
| [f1b1e4c] | 362 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { | 
|---|
|  | 363 | assert( callStmt ); | 
|---|
|  | 364 | } | 
|---|
|  | 365 |  | 
|---|
| [74d1804] | 366 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { | 
|---|
| [f1b1e4c] | 367 | } | 
|---|
|  | 368 |  | 
|---|
|  | 369 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { | 
|---|
| [74d1804] | 370 | delete callStmt; | 
|---|
| [f1b1e4c] | 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 |  | 
|---|
| [baf7fee] | 380 | std::ostream & operator<<( std::ostream & out, Statement * statement ) { | 
|---|
|  | 381 | statement->print( out ); | 
|---|
|  | 382 | return out; | 
|---|
|  | 383 | } | 
|---|
|  | 384 |  | 
|---|
| [0dd3a2f] | 385 | // Local Variables: // | 
|---|
|  | 386 | // tab-width: 4 // | 
|---|
|  | 387 | // mode: c++ // | 
|---|
|  | 388 | // compile-command: "make install" // | 
|---|
|  | 389 | // End: // | 
|---|