[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
|
---|
[daf1af8] | 11 | // Last Modified By : Andrew Beach
|
---|
[406a6e6] | 12 | // Last Modified On : Mon Aug 14 12:26:00 2017
|
---|
| 13 | // Update Count : 65
|
---|
[0dd3a2f] | 14 | //
|
---|
| 15 |
|
---|
[ea6332d] | 16 | #include "SynTree/Statement.h"
|
---|
[51b73452] | 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<<
|
---|
[51b73452] | 30 |
|
---|
| 31 | using std::string;
|
---|
| 32 | using std::endl;
|
---|
| 33 |
|
---|
[2871210] | 34 | Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {}
|
---|
[51b73452] | 35 |
|
---|
[b3c36f4] | 36 | void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {}
|
---|
[51b73452] | 37 |
|
---|
| 38 | Statement::~Statement() {}
|
---|
| 39 |
|
---|
[2871210] | 40 | ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
|
---|
[51b73452] | 41 |
|
---|
[3be261a] | 42 | ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
|
---|
| 43 |
|
---|
| 44 | ExprStmt::~ExprStmt() {
|
---|
| 45 | delete expr;
|
---|
| 46 | }
|
---|
[51b73452] | 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 | }
|
---|
[51b73452] | 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 |
|
---|
[51b73452] | 88 | const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
|
---|
| 89 |
|
---|
[0dd3a2f] | 90 | BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) :
|
---|
[2871210] | 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");
|
---|
[51b73452] | 95 | }
|
---|
| 96 |
|
---|
[0dd3a2f] | 97 | BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) :
|
---|
[2871210] | 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");
|
---|
[51b73452] | 101 | }
|
---|
| 102 |
|
---|
[de62360d] | 103 | void BranchStmt::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 104 | os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ;
|
---|
[51b73452] | 105 | }
|
---|
| 106 |
|
---|
[daf1af8] | 107 | ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {}
|
---|
[51b73452] | 108 |
|
---|
[daf1af8] | 109 | ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
|
---|
[3be261a] | 110 |
|
---|
[51b73452] | 111 | ReturnStmt::~ReturnStmt() {
|
---|
[0dd3a2f] | 112 | delete expr;
|
---|
[51b73452] | 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;
|
---|
[51b73452] | 122 | }
|
---|
| 123 |
|
---|
| 124 | IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
|
---|
[2871210] | 125 | Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
|
---|
[51b73452] | 126 |
|
---|
[3be261a] | 127 | IfStmt::IfStmt( const IfStmt & other ) :
|
---|
| 128 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
|
---|
| 129 |
|
---|
[ac71a86] | 130 | IfStmt::~IfStmt() {
|
---|
| 131 | delete condition;
|
---|
| 132 | delete thenPart;
|
---|
| 133 | delete elsePart;
|
---|
| 134 | }
|
---|
[51b73452] | 135 |
|
---|
[de62360d] | 136 | void IfStmt::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 137 | os << "If on condition: " << endl ;
|
---|
[60089f4] | 138 | os << string( indent+4, ' ' );
|
---|
[0dd3a2f] | 139 | condition->print( os, indent + 4 );
|
---|
[51b73452] | 140 |
|
---|
[60089f4] | 141 | os << string( indent+2, ' ' ) << "... then: " << endl;
|
---|
[51b73452] | 142 |
|
---|
[60089f4] | 143 | os << string( indent+4, ' ' );
|
---|
[0dd3a2f] | 144 | thenPart->print( os, indent + 4 );
|
---|
[51b73452] | 145 |
|
---|
[0dd3a2f] | 146 | if ( elsePart != 0 ) {
|
---|
[60089f4] | 147 | os << string( indent+2, ' ' ) << "... else: " << endl;
|
---|
| 148 | os << string( indent+4, ' ' );
|
---|
[0dd3a2f] | 149 | elsePart->print( os, indent + 4 );
|
---|
| 150 | } // if
|
---|
[51b73452] | 151 | }
|
---|
| 152 |
|
---|
[8688ce1] | 153 | SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
|
---|
| 154 | Statement( _labels ), condition( _condition ), statements( _statements ) {
|
---|
[0dd3a2f] | 155 | }
|
---|
[51b73452] | 156 |
|
---|
[3be261a] | 157 | SwitchStmt::SwitchStmt( const SwitchStmt & other ):
|
---|
| 158 | Statement( other ), condition( maybeClone( other.condition ) ) {
|
---|
[8688ce1] | 159 | cloneAll( other.statements, statements );
|
---|
[3be261a] | 160 | }
|
---|
| 161 |
|
---|
[51b73452] | 162 | SwitchStmt::~SwitchStmt() {
|
---|
[0dd3a2f] | 163 | delete condition;
|
---|
[8688ce1] | 164 | // destroy statements
|
---|
[2037f82] | 165 | deleteAll( statements );
|
---|
[51b73452] | 166 | }
|
---|
| 167 |
|
---|
[de62360d] | 168 | void SwitchStmt::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 169 | os << "Switch on condition: ";
|
---|
[0dd3a2f] | 170 | condition->print( os );
|
---|
| 171 | os << endl;
|
---|
[51b73452] | 172 |
|
---|
[8688ce1] | 173 | // statements
|
---|
[de62360d] | 174 | std::list<Statement *>::const_iterator i;
|
---|
[8688ce1] | 175 | for ( i = statements.begin(); i != statements.end(); i++)
|
---|
[de62360d] | 176 | (*i)->print( os, indent + 4 );
|
---|
[51b73452] | 177 |
|
---|
[8688ce1] | 178 | //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os ));
|
---|
[51b73452] | 179 | }
|
---|
| 180 |
|
---|
[3be261a] | 181 | CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
|
---|
[2871210] | 182 | Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
|
---|
[0dd3a2f] | 183 | if ( isDefault() && condition != 0 )
|
---|
| 184 | throw SemanticError("default with conditions");
|
---|
[51b73452] | 185 | }
|
---|
| 186 |
|
---|
[3be261a] | 187 | CaseStmt::CaseStmt( const CaseStmt & other ) :
|
---|
| 188 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {
|
---|
| 189 | cloneAll( other.stmts, stmts );
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[51b73452] | 192 | CaseStmt::~CaseStmt() {
|
---|
[0dd3a2f] | 193 | delete condition;
|
---|
[2037f82] | 194 | deleteAll( stmts );
|
---|
[51b73452] | 195 | }
|
---|
| 196 |
|
---|
[8688ce1] | 197 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) {
|
---|
| 198 | return new CaseStmt( labels, 0, stmts, true );
|
---|
[b2152e7a] | 199 | }
|
---|
| 200 |
|
---|
[de62360d] | 201 | void CaseStmt::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 202 | os << string( indent, ' ' );
|
---|
[51b73452] | 203 |
|
---|
[de62360d] | 204 | if ( isDefault() )
|
---|
[0dd3a2f] | 205 | os << "Default ";
|
---|
| 206 | else {
|
---|
| 207 | os << "Case ";
|
---|
| 208 | condition->print( os );
|
---|
| 209 | } // if
|
---|
[51b73452] | 210 |
|
---|
[0dd3a2f] | 211 | os << endl;
|
---|
[51b73452] | 212 |
|
---|
[de62360d] | 213 | std::list<Statement *>::const_iterator i;
|
---|
[0dd3a2f] | 214 | for ( i = stmts.begin(); i != stmts.end(); i++)
|
---|
| 215 | (*i )->print( os, indent + 4 );
|
---|
[51b73452] | 216 | }
|
---|
| 217 |
|
---|
[0dd3a2f] | 218 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
|
---|
| 219 | Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
|
---|
| 220 | }
|
---|
[51b73452] | 221 |
|
---|
[3be261a] | 222 | WhileStmt::WhileStmt( const WhileStmt & other ):
|
---|
| 223 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[a08ba92] | 226 | WhileStmt::~WhileStmt() {
|
---|
[0dd3a2f] | 227 | delete body;
|
---|
[2037f82] | 228 | delete condition;
|
---|
[51b73452] | 229 | }
|
---|
| 230 |
|
---|
[de62360d] | 231 | void WhileStmt::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 232 | os << "While on condition: " << endl ;
|
---|
[0dd3a2f] | 233 | condition->print( os, indent + 4 );
|
---|
[51b73452] | 234 |
|
---|
[44b5ca0] | 235 | os << string( indent, ' ' ) << ".... with body: " << endl;
|
---|
[51b73452] | 236 |
|
---|
[0dd3a2f] | 237 | if ( body != 0 ) body->print( os, indent + 4 );
|
---|
[51b73452] | 238 | }
|
---|
| 239 |
|
---|
[145f1fc] | 240 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
|
---|
[0dd3a2f] | 241 | Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
|
---|
| 242 | }
|
---|
[51b73452] | 243 |
|
---|
[3be261a] | 244 | ForStmt::ForStmt( const ForStmt & other ):
|
---|
| 245 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) {
|
---|
| 246 | cloneAll( other.initialization, initialization );
|
---|
| 247 |
|
---|
| 248 | }
|
---|
| 249 |
|
---|
[51b73452] | 250 | ForStmt::~ForStmt() {
|
---|
[145f1fc] | 251 | deleteAll( initialization );
|
---|
[0dd3a2f] | 252 | delete condition;
|
---|
| 253 | delete increment;
|
---|
| 254 | delete body;
|
---|
[51b73452] | 255 | }
|
---|
| 256 |
|
---|
[de62360d] | 257 | void ForStmt::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 258 | os << "Labels: {";
|
---|
[de62360d] | 259 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
|
---|
[be5aa1b] | 260 | os << *it << ",";
|
---|
| 261 | }
|
---|
| 262 | os << "}" << endl;
|
---|
| 263 |
|
---|
[44b5ca0] | 264 | os << string( indent, ' ' ) << "For Statement" << endl ;
|
---|
[51b73452] | 265 |
|
---|
[3be261a] | 266 | os << string( indent + 2, ' ' ) << "initialization: \n";
|
---|
[145f1fc] | 267 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
|
---|
[bb8ea30] | 268 | os << string( indent + 4, ' ' );
|
---|
[145f1fc] | 269 | (*it)->print( os, indent + 4 );
|
---|
| 270 | }
|
---|
[51b73452] | 271 |
|
---|
[3be261a] | 272 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
|
---|
[bb8ea30] | 273 | if ( condition != 0 ) {
|
---|
| 274 | os << string( indent + 4, ' ' );
|
---|
[0dd3a2f] | 275 | condition->print( os, indent + 4 );
|
---|
[bb8ea30] | 276 | }
|
---|
[51b73452] | 277 |
|
---|
[3be261a] | 278 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
|
---|
[bb8ea30] | 279 | if ( increment != 0 ) {
|
---|
| 280 | os << string( indent + 4, ' ' );
|
---|
[0dd3a2f] | 281 | increment->print( os, indent + 4 );
|
---|
[bb8ea30] | 282 | }
|
---|
[51b73452] | 283 |
|
---|
[3be261a] | 284 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
|
---|
[bb8ea30] | 285 | if ( body != 0 ) {
|
---|
| 286 | os << string( indent + 4, ' ' );
|
---|
[0dd3a2f] | 287 | body->print( os, indent + 4 );
|
---|
[bb8ea30] | 288 | }
|
---|
[51b73452] | 289 |
|
---|
[0dd3a2f] | 290 | os << endl;
|
---|
[51b73452] | 291 | }
|
---|
| 292 |
|
---|
[daf1af8] | 293 | ThrowStmt::ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target ) :
|
---|
| 294 | Statement( labels ), kind(kind), expr(expr), target(target) {
|
---|
| 295 | assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." );
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
|
---|
| 299 | Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | ThrowStmt::~ThrowStmt() {
|
---|
| 303 | delete expr;
|
---|
| 304 | delete target;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | void ThrowStmt::print( std::ostream &os, int indent) const {
|
---|
| 308 | if ( target ) {
|
---|
| 309 | os << "Non-Local ";
|
---|
| 310 | }
|
---|
| 311 | os << "Throw Statement, raising: ";
|
---|
| 312 | expr->print(os, indent + 4);
|
---|
| 313 | if ( target ) {
|
---|
| 314 | os << "At: ";
|
---|
| 315 | target->print(os, indent + 4);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[046e04a] | 319 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
|
---|
[0dd3a2f] | 320 | Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) {
|
---|
| 321 | }
|
---|
[51b73452] | 322 |
|
---|
[3be261a] | 323 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
|
---|
| 324 | cloneAll( other.handlers, handlers );
|
---|
[51b73452] | 325 | }
|
---|
| 326 |
|
---|
[a08ba92] | 327 | TryStmt::~TryStmt() {
|
---|
[0dd3a2f] | 328 | delete block;
|
---|
[2037f82] | 329 | deleteAll( handlers );
|
---|
| 330 | delete finallyBlock;
|
---|
[51b73452] | 331 | }
|
---|
| 332 |
|
---|
[de62360d] | 333 | void TryStmt::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 334 | os << "Try Statement" << endl;
|
---|
[406a6e6] | 335 | os << string( indent + 2, ' ' ) << "with block:" << endl;
|
---|
| 336 | os << string( indent + 4, ' ' );
|
---|
[0dd3a2f] | 337 | block->print( os, indent + 4 );
|
---|
| 338 |
|
---|
| 339 | // handlers
|
---|
[406a6e6] | 340 | os << string( indent + 2, ' ' ) << "and handlers:" << endl;
|
---|
| 341 | for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) {
|
---|
| 342 | os << string( indent + 4, ' ' );
|
---|
[0dd3a2f] | 343 | (*i )->print( os, indent + 4 );
|
---|
[406a6e6] | 344 | }
|
---|
[0dd3a2f] | 345 |
|
---|
| 346 | // finally block
|
---|
| 347 | if ( finallyBlock != 0 ) {
|
---|
[406a6e6] | 348 | os << string( indent + 2, ' ' ) << "and finally:" << endl;
|
---|
[0dd3a2f] | 349 | finallyBlock->print( os, indent + 4 );
|
---|
| 350 | } // if
|
---|
[51b73452] | 351 | }
|
---|
| 352 |
|
---|
[ca78437] | 353 | CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) :
|
---|
| 354 | Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) {
|
---|
[0dd3a2f] | 355 | }
|
---|
[51b73452] | 356 |
|
---|
[3be261a] | 357 | CatchStmt::CatchStmt( const CatchStmt & other ) :
|
---|
[ca78437] | 358 | Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) {
|
---|
[3be261a] | 359 | }
|
---|
| 360 |
|
---|
[a08ba92] | 361 | CatchStmt::~CatchStmt() {
|
---|
[0dd3a2f] | 362 | delete decl;
|
---|
| 363 | delete body;
|
---|
[51b73452] | 364 | }
|
---|
| 365 |
|
---|
[de62360d] | 366 | void CatchStmt::print( std::ostream &os, int indent ) const {
|
---|
[ca78437] | 367 | os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
|
---|
[0dd3a2f] | 368 |
|
---|
[406a6e6] | 369 | os << string( indent + 2, ' ' ) << "... catching: ";
|
---|
[0dd3a2f] | 370 | if ( decl ) {
|
---|
| 371 | decl->printShort( os, indent + 4 );
|
---|
| 372 | os << endl;
|
---|
[ca78437] | 373 | }
|
---|
[0dd3a2f] | 374 | else
|
---|
[44b5ca0] | 375 | os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl;
|
---|
[406a6e6] | 376 |
|
---|
| 377 | if ( cond ) {
|
---|
| 378 | os << string( indent + 2, ' ' ) << "with conditional:" << endl;
|
---|
| 379 | os << string( indent + 4, ' ' );
|
---|
| 380 | cond->print( os, indent + 4 );
|
---|
| 381 | }
|
---|
| 382 | else
|
---|
| 383 | os << string( indent + 2, ' ' ) << "with no conditional" << endl;
|
---|
| 384 |
|
---|
| 385 | os << string( indent + 2, ' ' ) << "with block:" << endl;
|
---|
| 386 | os << string( indent + 4, ' ' );
|
---|
| 387 | body->print( os, indent + 4 );
|
---|
[51b73452] | 388 | }
|
---|
| 389 |
|
---|
| 390 |
|
---|
[0dd3a2f] | 391 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
|
---|
| 392 | assert( labels.empty() ); // finally statement cannot be labeled
|
---|
[51b73452] | 393 | }
|
---|
| 394 |
|
---|
[3be261a] | 395 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
|
---|
| 396 | }
|
---|
| 397 |
|
---|
[0dd3a2f] | 398 | FinallyStmt::~FinallyStmt() {
|
---|
| 399 | delete block;
|
---|
[51b73452] | 400 | }
|
---|
| 401 |
|
---|
[de62360d] | 402 | void FinallyStmt::print( std::ostream &os, int indent ) const {
|
---|
[f1b1e4c] | 403 | os << "Finally Statement" << endl;
|
---|
[406a6e6] | 404 | os << string( indent + 2, ' ' ) << "with block:" << endl;
|
---|
| 405 | os << string( indent + 4, ' ' );
|
---|
[0dd3a2f] | 406 | block->print( os, indent + 4 );
|
---|
[51b73452] | 407 | }
|
---|
| 408 |
|
---|
| 409 | NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {}
|
---|
| 410 | NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {}
|
---|
| 411 |
|
---|
[b3c36f4] | 412 | void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const {
|
---|
[89231bc] | 413 | os << "Null Statement" << endl ;
|
---|
[51b73452] | 414 | }
|
---|
| 415 |
|
---|
[f1b1e4c] | 416 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {
|
---|
| 417 | assert( callStmt );
|
---|
| 418 | }
|
---|
| 419 |
|
---|
[74d1804] | 420 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) {
|
---|
[f1b1e4c] | 421 | }
|
---|
| 422 |
|
---|
| 423 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
|
---|
[74d1804] | 424 | delete callStmt;
|
---|
[f1b1e4c] | 425 | }
|
---|
| 426 |
|
---|
| 427 | void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const {
|
---|
| 428 | os << "Implicit Ctor Dtor Statement" << endl;
|
---|
| 429 | os << string( indent + 2, ' ' ) << "with Ctor/Dtor: ";
|
---|
| 430 | callStmt->print( os, indent + 2);
|
---|
| 431 | os << endl;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[3906301] | 434 | std::ostream & operator<<( std::ostream & out, const Statement * statement ) {
|
---|
[8bf784a] | 435 | if ( statement ) {
|
---|
| 436 | statement->print( out );
|
---|
| 437 | } else {
|
---|
| 438 | out << "nullptr";
|
---|
| 439 | }
|
---|
[baf7fee] | 440 | return out;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
[0dd3a2f] | 443 | // Local Variables: //
|
---|
| 444 | // tab-width: 4 //
|
---|
| 445 | // mode: c++ //
|
---|
| 446 | // compile-command: "make install" //
|
---|
| 447 | // End: //
|
---|