| [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 | 
|---|
|  | 12 | // Last Modified On : Wed Dec 09 14:09:34 2015 | 
|---|
|  | 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 { | 
|---|
| [44b5ca0] | 45 | os << string( indent, ' ' ) << "Expression Statement:" << endl; | 
|---|
| [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 | 
|---|
|  | 89 | if ( type == BranchStmt::Goto && target.size() == 0 ) | 
|---|
|  | 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 { | 
|---|
| [44b5ca0] | 112 | os << std::string( indent, ' ' ) << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; | 
|---|
| [0dd3a2f] | 113 | if ( expr != 0 ) expr->print( os ); | 
|---|
|  | 114 | os << endl; | 
|---|
| [51b73452] | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 | IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ): | 
|---|
| [2871210] | 118 | Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {} | 
|---|
| [51b73452] | 119 |  | 
|---|
| [3be261a] | 120 | IfStmt::IfStmt( const IfStmt & other ) : | 
|---|
|  | 121 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {} | 
|---|
|  | 122 |  | 
|---|
| [51b73452] | 123 | IfStmt::~IfStmt() {} | 
|---|
|  | 124 |  | 
|---|
| [de62360d] | 125 | void IfStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 126 | os << string( indent, ' ' ) << "If on condition: " << endl ; | 
|---|
| [0dd3a2f] | 127 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 128 |  | 
|---|
| [44b5ca0] | 129 | os << string( indent, ' ' ) << ".... and branches: " << endl; | 
|---|
| [51b73452] | 130 |  | 
|---|
| [0dd3a2f] | 131 | thenPart->print( os, indent + 4 ); | 
|---|
| [51b73452] | 132 |  | 
|---|
| [0dd3a2f] | 133 | if ( elsePart != 0 ) { | 
|---|
|  | 134 | elsePart->print( os, indent + 4 ); | 
|---|
|  | 135 | } // if | 
|---|
| [51b73452] | 136 | } | 
|---|
|  | 137 |  | 
|---|
| [0dd3a2f] | 138 | SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): | 
|---|
| [2871210] | 139 | Statement( _labels ), condition( _condition ), branches( _branches ) { | 
|---|
| [0dd3a2f] | 140 | } | 
|---|
| [51b73452] | 141 |  | 
|---|
| [3be261a] | 142 | SwitchStmt::SwitchStmt( const SwitchStmt & other ): | 
|---|
|  | 143 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
|  | 144 | cloneAll( other.branches, branches ); | 
|---|
|  | 145 | } | 
|---|
|  | 146 |  | 
|---|
| [51b73452] | 147 | SwitchStmt::~SwitchStmt() { | 
|---|
| [0dd3a2f] | 148 | delete condition; | 
|---|
|  | 149 | // destroy branches | 
|---|
| [51b73452] | 150 | } | 
|---|
|  | 151 |  | 
|---|
| [0dd3a2f] | 152 | void SwitchStmt::add_case( CaseStmt *c ) {} | 
|---|
| [51b73452] | 153 |  | 
|---|
| [de62360d] | 154 | void SwitchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 155 | os << string( indent, ' ' ) << "Switch on condition: "; | 
|---|
| [0dd3a2f] | 156 | condition->print( os ); | 
|---|
|  | 157 | os << endl; | 
|---|
| [51b73452] | 158 |  | 
|---|
| [0dd3a2f] | 159 | // branches | 
|---|
| [de62360d] | 160 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 161 | for ( i = branches.begin(); i != branches.end(); i++) | 
|---|
| [de62360d] | 162 | (*i)->print( os, indent + 4 ); | 
|---|
| [51b73452] | 163 |  | 
|---|
| [0dd3a2f] | 164 | //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); | 
|---|
| [51b73452] | 165 | } | 
|---|
|  | 166 |  | 
|---|
| [3be261a] | 167 | CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : | 
|---|
| [2871210] | 168 | Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) { | 
|---|
| [0dd3a2f] | 169 | if ( isDefault() && condition != 0 ) | 
|---|
|  | 170 | throw SemanticError("default with conditions"); | 
|---|
| [51b73452] | 171 | } | 
|---|
|  | 172 |  | 
|---|
| [3be261a] | 173 | CaseStmt::CaseStmt( const CaseStmt & other ) : | 
|---|
|  | 174 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { | 
|---|
|  | 175 | cloneAll( other.stmts, stmts ); | 
|---|
|  | 176 | } | 
|---|
|  | 177 |  | 
|---|
| [51b73452] | 178 | CaseStmt::~CaseStmt() { | 
|---|
| [0dd3a2f] | 179 | delete condition; | 
|---|
| [51b73452] | 180 | } | 
|---|
|  | 181 |  | 
|---|
| [b2152e7a] | 182 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> branches ) { | 
|---|
|  | 183 | return new CaseStmt( labels, 0, branches, true ); | 
|---|
|  | 184 | } | 
|---|
|  | 185 |  | 
|---|
| [de62360d] | 186 | void CaseStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 187 | os << string( indent, ' ' ); | 
|---|
| [51b73452] | 188 |  | 
|---|
| [de62360d] | 189 | if ( isDefault() ) | 
|---|
| [0dd3a2f] | 190 | os << "Default "; | 
|---|
|  | 191 | else { | 
|---|
|  | 192 | os << "Case "; | 
|---|
|  | 193 | condition->print( os ); | 
|---|
|  | 194 | } // if | 
|---|
| [51b73452] | 195 |  | 
|---|
| [0dd3a2f] | 196 | os << endl; | 
|---|
| [51b73452] | 197 |  | 
|---|
| [de62360d] | 198 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 199 | for ( i = stmts.begin(); i != stmts.end(); i++) | 
|---|
|  | 200 | (*i )->print( os, indent + 4 ); | 
|---|
| [51b73452] | 201 | } | 
|---|
|  | 202 |  | 
|---|
|  | 203 | //ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {} | 
|---|
| [0dd3a2f] | 204 | ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): | 
|---|
| [2871210] | 205 | Statement( _labels ), condition( _condition ), branches( _branches ) { | 
|---|
| [0dd3a2f] | 206 | } | 
|---|
| [51b73452] | 207 |  | 
|---|
| [3be261a] | 208 | ChooseStmt::ChooseStmt( const ChooseStmt & other ): | 
|---|
|  | 209 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
|  | 210 | cloneAll( other.branches, branches ); | 
|---|
|  | 211 | } | 
|---|
|  | 212 |  | 
|---|
| [51b73452] | 213 | ChooseStmt::~ChooseStmt() { | 
|---|
| [0dd3a2f] | 214 | delete condition; | 
|---|
| [51b73452] | 215 | } | 
|---|
|  | 216 |  | 
|---|
| [0dd3a2f] | 217 | void ChooseStmt::add_case( CaseStmt *c ) {} | 
|---|
| [51b73452] | 218 |  | 
|---|
| [de62360d] | 219 | void ChooseStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 220 | os << string( indent, ' ' ) << "Choose on condition: "; | 
|---|
| [0dd3a2f] | 221 | condition->print( os ); | 
|---|
|  | 222 | os << endl; | 
|---|
| [51b73452] | 223 |  | 
|---|
| [0dd3a2f] | 224 | // branches | 
|---|
| [de62360d] | 225 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 226 | for ( i = branches.begin(); i != branches.end(); i++) | 
|---|
|  | 227 | (*i )->print( os, indent + 4 ); | 
|---|
| [51b73452] | 228 |  | 
|---|
| [0dd3a2f] | 229 | //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); | 
|---|
| [51b73452] | 230 | } | 
|---|
|  | 231 |  | 
|---|
| [de62360d] | 232 | void FallthruStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 233 | os << string( indent, ' ' ) << "Fall-through statement" << endl; | 
|---|
| [51b73452] | 234 | } | 
|---|
|  | 235 |  | 
|---|
| [0dd3a2f] | 236 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): | 
|---|
|  | 237 | Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { | 
|---|
|  | 238 | } | 
|---|
| [51b73452] | 239 |  | 
|---|
| [3be261a] | 240 | WhileStmt::WhileStmt( const WhileStmt & other ): | 
|---|
|  | 241 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { | 
|---|
|  | 242 | } | 
|---|
|  | 243 |  | 
|---|
| [a08ba92] | 244 | WhileStmt::~WhileStmt() { | 
|---|
| [0dd3a2f] | 245 | delete body; | 
|---|
| [51b73452] | 246 | } | 
|---|
|  | 247 |  | 
|---|
| [de62360d] | 248 | void WhileStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 249 | os << string( indent, ' ' ) << "While on condition: " << endl ; | 
|---|
| [0dd3a2f] | 250 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 251 |  | 
|---|
| [44b5ca0] | 252 | os << string( indent, ' ' ) << ".... with body: " << endl; | 
|---|
| [51b73452] | 253 |  | 
|---|
| [0dd3a2f] | 254 | if ( body != 0 ) body->print( os, indent + 4 ); | 
|---|
| [51b73452] | 255 | } | 
|---|
|  | 256 |  | 
|---|
| [145f1fc] | 257 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): | 
|---|
| [0dd3a2f] | 258 | Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { | 
|---|
|  | 259 | } | 
|---|
| [51b73452] | 260 |  | 
|---|
| [3be261a] | 261 | ForStmt::ForStmt( const ForStmt & other ): | 
|---|
|  | 262 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) { | 
|---|
|  | 263 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 264 |  | 
|---|
|  | 265 | } | 
|---|
|  | 266 |  | 
|---|
| [51b73452] | 267 | ForStmt::~ForStmt() { | 
|---|
| [145f1fc] | 268 | deleteAll( initialization ); | 
|---|
| [0dd3a2f] | 269 | delete condition; | 
|---|
|  | 270 | delete increment; | 
|---|
|  | 271 | delete body; | 
|---|
| [51b73452] | 272 | } | 
|---|
|  | 273 |  | 
|---|
| [de62360d] | 274 | void ForStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 275 | os << string( indent, ' ' ) << "Labels: {"; | 
|---|
| [de62360d] | 276 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { | 
|---|
| [be5aa1b] | 277 | os << *it << ","; | 
|---|
|  | 278 | } | 
|---|
|  | 279 | os << "}" << endl; | 
|---|
|  | 280 |  | 
|---|
| [44b5ca0] | 281 | os << string( indent, ' ' ) << "For Statement" << endl ; | 
|---|
| [51b73452] | 282 |  | 
|---|
| [3be261a] | 283 | os << string( indent + 2, ' ' ) << "initialization: \n"; | 
|---|
| [145f1fc] | 284 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { | 
|---|
|  | 285 | (*it)->print( os, indent + 4 ); | 
|---|
|  | 286 | } | 
|---|
| [51b73452] | 287 |  | 
|---|
| [3be261a] | 288 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; | 
|---|
| [0dd3a2f] | 289 | if ( condition != 0 ) | 
|---|
|  | 290 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 291 |  | 
|---|
| [3be261a] | 292 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; | 
|---|
| [0dd3a2f] | 293 | if ( increment != 0 ) | 
|---|
|  | 294 | increment->print( os, indent + 4 ); | 
|---|
| [51b73452] | 295 |  | 
|---|
| [3be261a] | 296 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; | 
|---|
| [0dd3a2f] | 297 | if ( body != 0 ) | 
|---|
|  | 298 | body->print( os, indent + 4 ); | 
|---|
| [51b73452] | 299 |  | 
|---|
| [0dd3a2f] | 300 | os << endl; | 
|---|
| [51b73452] | 301 | } | 
|---|
|  | 302 |  | 
|---|
|  | 303 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) : | 
|---|
| [0dd3a2f] | 304 | Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) { | 
|---|
|  | 305 | } | 
|---|
| [51b73452] | 306 |  | 
|---|
| [3be261a] | 307 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { | 
|---|
|  | 308 | cloneAll( other.handlers, handlers ); | 
|---|
| [51b73452] | 309 | } | 
|---|
|  | 310 |  | 
|---|
| [a08ba92] | 311 | TryStmt::~TryStmt() { | 
|---|
| [0dd3a2f] | 312 | delete block; | 
|---|
| [51b73452] | 313 | } | 
|---|
|  | 314 |  | 
|---|
| [de62360d] | 315 | void TryStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 316 | os << string( indent, ' ' ) << "Try Statement" << endl; | 
|---|
|  | 317 | os << string( indent + 2, ' ' ) << "with block: " << endl; | 
|---|
| [0dd3a2f] | 318 | block->print( os, indent + 4 ); | 
|---|
|  | 319 |  | 
|---|
|  | 320 | // handlers | 
|---|
| [44b5ca0] | 321 | os << string( indent + 2, ' ' ) << "and handlers: " << endl; | 
|---|
| [de62360d] | 322 | for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) | 
|---|
| [0dd3a2f] | 323 | (*i )->print( os, indent + 4 ); | 
|---|
|  | 324 |  | 
|---|
|  | 325 | // finally block | 
|---|
|  | 326 | if ( finallyBlock != 0 ) { | 
|---|
| [44b5ca0] | 327 | os << string( indent + 2, ' ' ) << "Finally block: " << endl; | 
|---|
| [0dd3a2f] | 328 | finallyBlock->print( os, indent + 4 ); | 
|---|
|  | 329 | } // if | 
|---|
| [51b73452] | 330 | } | 
|---|
|  | 331 |  | 
|---|
|  | 332 | CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) : | 
|---|
| [0dd3a2f] | 333 | Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) { | 
|---|
|  | 334 | } | 
|---|
| [51b73452] | 335 |  | 
|---|
| [3be261a] | 336 | CatchStmt::CatchStmt( const CatchStmt & other ) : | 
|---|
|  | 337 | Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) { | 
|---|
|  | 338 | } | 
|---|
|  | 339 |  | 
|---|
| [a08ba92] | 340 | CatchStmt::~CatchStmt() { | 
|---|
| [0dd3a2f] | 341 | delete decl; | 
|---|
|  | 342 | delete body; | 
|---|
| [51b73452] | 343 | } | 
|---|
|  | 344 |  | 
|---|
| [de62360d] | 345 | void CatchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 346 | os << string( indent, ' ' ) << "Catch Statement" << endl; | 
|---|
| [0dd3a2f] | 347 |  | 
|---|
| [44b5ca0] | 348 | os << string( indent, ' ' ) << "... catching" << endl; | 
|---|
| [0dd3a2f] | 349 | if ( decl ) { | 
|---|
|  | 350 | decl->printShort( os, indent + 4 ); | 
|---|
|  | 351 | os << endl; | 
|---|
|  | 352 | } else if ( catchRest ) | 
|---|
| [44b5ca0] | 353 | os << string( indent + 4 , ' ' ) << "the rest" << endl; | 
|---|
| [0dd3a2f] | 354 | else | 
|---|
| [44b5ca0] | 355 | os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl; | 
|---|
| [51b73452] | 356 | } | 
|---|
|  | 357 |  | 
|---|
|  | 358 |  | 
|---|
| [0dd3a2f] | 359 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { | 
|---|
|  | 360 | assert( labels.empty() ); // finally statement cannot be labeled | 
|---|
| [51b73452] | 361 | } | 
|---|
|  | 362 |  | 
|---|
| [3be261a] | 363 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { | 
|---|
|  | 364 | } | 
|---|
|  | 365 |  | 
|---|
| [0dd3a2f] | 366 | FinallyStmt::~FinallyStmt() { | 
|---|
|  | 367 | delete block; | 
|---|
| [51b73452] | 368 | } | 
|---|
|  | 369 |  | 
|---|
| [de62360d] | 370 | void FinallyStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 371 | os << string( indent, ' ' ) << "Finally Statement" << endl; | 
|---|
|  | 372 | os << string( indent + 2, ' ' ) << "with block: " << endl; | 
|---|
| [0dd3a2f] | 373 | block->print( os, indent + 4 ); | 
|---|
| [51b73452] | 374 | } | 
|---|
|  | 375 |  | 
|---|
|  | 376 | NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {} | 
|---|
|  | 377 | NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {} | 
|---|
|  | 378 |  | 
|---|
| [de62360d] | 379 | void NullStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 380 | os << string( indent, ' ' ) << "Null Statement" << endl ; | 
|---|
| [51b73452] | 381 | } | 
|---|
|  | 382 |  | 
|---|
| [baf7fee] | 383 | std::ostream & operator<<( std::ostream & out, Statement * statement ) { | 
|---|
|  | 384 | statement->print( out ); | 
|---|
|  | 385 | return out; | 
|---|
|  | 386 | } | 
|---|
|  | 387 |  | 
|---|
| [0dd3a2f] | 388 | // Local Variables: // | 
|---|
|  | 389 | // tab-width: 4 // | 
|---|
|  | 390 | // mode: c++ // | 
|---|
|  | 391 | // compile-command: "make install" // | 
|---|
|  | 392 | // End: // | 
|---|