| 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 | //
|
|---|
| 7 | // Statement.cc --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Richard C. Bilson
|
|---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
|---|
| 11 | // Last Modified By : Andrew Beach
|
|---|
| 12 | // Last Modified On : Mon Aug 14 12:26:00 2017
|
|---|
| 13 | // Update Count : 65
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include "SynTree/Statement.h"
|
|---|
| 17 |
|
|---|
| 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<<
|
|---|
| 30 |
|
|---|
| 31 | using std::string;
|
|---|
| 32 | using std::endl;
|
|---|
| 33 |
|
|---|
| 34 | Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {}
|
|---|
| 35 |
|
|---|
| 36 | void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {}
|
|---|
| 37 |
|
|---|
| 38 | Statement::~Statement() {}
|
|---|
| 39 |
|
|---|
| 40 | ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
|
|---|
| 41 |
|
|---|
| 42 | ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
|
|---|
| 43 |
|
|---|
| 44 | ExprStmt::~ExprStmt() {
|
|---|
| 45 | delete expr;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void ExprStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 49 | os << "Expression Statement:" << endl << std::string( indent + 2, ' ' );
|
|---|
| 50 | expr->print( os, indent + 2 );
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 );
|
|---|
| 76 | } // if
|
|---|
| 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
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
|
|---|
| 89 |
|
|---|
| 90 | BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) :
|
|---|
| 91 | Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) {
|
|---|
| 92 | //actually this is a syntactic error signaled by the parser
|
|---|
| 93 | if ( type == BranchStmt::Goto && target.empty() )
|
|---|
| 94 | throw SemanticError("goto without target");
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) :
|
|---|
| 98 | Statement( labels ), computedTarget( _computedTarget ), type( _type ) {
|
|---|
| 99 | if ( type != BranchStmt::Goto || computedTarget == 0 )
|
|---|
| 100 | throw SemanticError("Computed target not valid in branch statement");
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | void BranchStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 104 | os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {}
|
|---|
| 108 |
|
|---|
| 109 | ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
|
|---|
| 110 |
|
|---|
| 111 | ReturnStmt::~ReturnStmt() {
|
|---|
| 112 | delete expr;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void ReturnStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 116 | os << "Return Statement, returning: ";
|
|---|
| 117 | if ( expr != 0 ) {
|
|---|
| 118 | os << endl << string( indent+2, ' ' );
|
|---|
| 119 | expr->print( os, indent + 2 );
|
|---|
| 120 | }
|
|---|
| 121 | os << endl;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
|
|---|
| 125 | Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
|
|---|
| 126 |
|
|---|
| 127 | IfStmt::IfStmt( const IfStmt & other ) :
|
|---|
| 128 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
|
|---|
| 129 |
|
|---|
| 130 | IfStmt::~IfStmt() {
|
|---|
| 131 | delete condition;
|
|---|
| 132 | delete thenPart;
|
|---|
| 133 | delete elsePart;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | void IfStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 137 | os << "If on condition: " << endl ;
|
|---|
| 138 | os << string( indent+4, ' ' );
|
|---|
| 139 | condition->print( os, indent + 4 );
|
|---|
| 140 |
|
|---|
| 141 | os << string( indent+2, ' ' ) << "... then: " << endl;
|
|---|
| 142 |
|
|---|
| 143 | os << string( indent+4, ' ' );
|
|---|
| 144 | thenPart->print( os, indent + 4 );
|
|---|
| 145 |
|
|---|
| 146 | if ( elsePart != 0 ) {
|
|---|
| 147 | os << string( indent+2, ' ' ) << "... else: " << endl;
|
|---|
| 148 | os << string( indent+4, ' ' );
|
|---|
| 149 | elsePart->print( os, indent + 4 );
|
|---|
| 150 | } // if
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
|
|---|
| 154 | Statement( _labels ), condition( _condition ), statements( _statements ) {
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | SwitchStmt::SwitchStmt( const SwitchStmt & other ):
|
|---|
| 158 | Statement( other ), condition( maybeClone( other.condition ) ) {
|
|---|
| 159 | cloneAll( other.statements, statements );
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | SwitchStmt::~SwitchStmt() {
|
|---|
| 163 | delete condition;
|
|---|
| 164 | // destroy statements
|
|---|
| 165 | deleteAll( statements );
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | void SwitchStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 169 | os << "Switch on condition: ";
|
|---|
| 170 | condition->print( os );
|
|---|
| 171 | os << endl;
|
|---|
| 172 |
|
|---|
| 173 | // statements
|
|---|
| 174 | std::list<Statement *>::const_iterator i;
|
|---|
| 175 | for ( i = statements.begin(); i != statements.end(); i++)
|
|---|
| 176 | (*i)->print( os, indent + 4 );
|
|---|
| 177 |
|
|---|
| 178 | //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os ));
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
|
|---|
| 182 | Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
|
|---|
| 183 | if ( isDefault() && condition != 0 )
|
|---|
| 184 | throw SemanticError("default with conditions");
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | CaseStmt::CaseStmt( const CaseStmt & other ) :
|
|---|
| 188 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {
|
|---|
| 189 | cloneAll( other.stmts, stmts );
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | CaseStmt::~CaseStmt() {
|
|---|
| 193 | delete condition;
|
|---|
| 194 | deleteAll( stmts );
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) {
|
|---|
| 198 | return new CaseStmt( labels, 0, stmts, true );
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | void CaseStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 202 | os << string( indent, ' ' );
|
|---|
| 203 |
|
|---|
| 204 | if ( isDefault() )
|
|---|
| 205 | os << "Default ";
|
|---|
| 206 | else {
|
|---|
| 207 | os << "Case ";
|
|---|
| 208 | condition->print( os );
|
|---|
| 209 | } // if
|
|---|
| 210 |
|
|---|
| 211 | os << endl;
|
|---|
| 212 |
|
|---|
| 213 | std::list<Statement *>::const_iterator i;
|
|---|
| 214 | for ( i = stmts.begin(); i != stmts.end(); i++)
|
|---|
| 215 | (*i )->print( os, indent + 4 );
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
|
|---|
| 219 | Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | WhileStmt::WhileStmt( const WhileStmt & other ):
|
|---|
| 223 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | WhileStmt::~WhileStmt() {
|
|---|
| 227 | delete body;
|
|---|
| 228 | delete condition;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | void WhileStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 232 | os << "While on condition: " << endl ;
|
|---|
| 233 | condition->print( os, indent + 4 );
|
|---|
| 234 |
|
|---|
| 235 | os << string( indent, ' ' ) << ".... with body: " << endl;
|
|---|
| 236 |
|
|---|
| 237 | if ( body != 0 ) body->print( os, indent + 4 );
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
|
|---|
| 241 | Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 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 |
|
|---|
| 250 | ForStmt::~ForStmt() {
|
|---|
| 251 | deleteAll( initialization );
|
|---|
| 252 | delete condition;
|
|---|
| 253 | delete increment;
|
|---|
| 254 | delete body;
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | void ForStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 258 | os << "Labels: {";
|
|---|
| 259 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) {
|
|---|
| 260 | os << *it << ",";
|
|---|
| 261 | }
|
|---|
| 262 | os << "}" << endl;
|
|---|
| 263 |
|
|---|
| 264 | os << string( indent, ' ' ) << "For Statement" << endl ;
|
|---|
| 265 |
|
|---|
| 266 | os << string( indent + 2, ' ' ) << "initialization: \n";
|
|---|
| 267 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
|
|---|
| 268 | os << string( indent + 4, ' ' );
|
|---|
| 269 | (*it)->print( os, indent + 4 );
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
|
|---|
| 273 | if ( condition != 0 ) {
|
|---|
| 274 | os << string( indent + 4, ' ' );
|
|---|
| 275 | condition->print( os, indent + 4 );
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
|
|---|
| 279 | if ( increment != 0 ) {
|
|---|
| 280 | os << string( indent + 4, ' ' );
|
|---|
| 281 | increment->print( os, indent + 4 );
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
|
|---|
| 285 | if ( body != 0 ) {
|
|---|
| 286 | os << string( indent + 4, ' ' );
|
|---|
| 287 | body->print( os, indent + 4 );
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | os << endl;
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 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 |
|
|---|
| 319 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
|
|---|
| 320 | Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) {
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
|
|---|
| 324 | cloneAll( other.handlers, handlers );
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | TryStmt::~TryStmt() {
|
|---|
| 328 | delete block;
|
|---|
| 329 | deleteAll( handlers );
|
|---|
| 330 | delete finallyBlock;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | void TryStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 334 | os << "Try Statement" << endl;
|
|---|
| 335 | os << string( indent + 2, ' ' ) << "with block:" << endl;
|
|---|
| 336 | os << string( indent + 4, ' ' );
|
|---|
| 337 | block->print( os, indent + 4 );
|
|---|
| 338 |
|
|---|
| 339 | // handlers
|
|---|
| 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, ' ' );
|
|---|
| 343 | (*i )->print( os, indent + 4 );
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | // finally block
|
|---|
| 347 | if ( finallyBlock != 0 ) {
|
|---|
| 348 | os << string( indent + 2, ' ' ) << "and finally:" << endl;
|
|---|
| 349 | finallyBlock->print( os, indent + 4 );
|
|---|
| 350 | } // if
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 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 ) {
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | CatchStmt::CatchStmt( const CatchStmt & other ) :
|
|---|
| 358 | Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) {
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | CatchStmt::~CatchStmt() {
|
|---|
| 362 | delete decl;
|
|---|
| 363 | delete body;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | void CatchStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 367 | os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
|
|---|
| 368 |
|
|---|
| 369 | os << string( indent + 2, ' ' ) << "... catching: ";
|
|---|
| 370 | if ( decl ) {
|
|---|
| 371 | decl->printShort( os, indent + 4 );
|
|---|
| 372 | os << endl;
|
|---|
| 373 | }
|
|---|
| 374 | else
|
|---|
| 375 | os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl;
|
|---|
| 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 );
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
|
|---|
| 392 | assert( labels.empty() ); // finally statement cannot be labeled
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | FinallyStmt::~FinallyStmt() {
|
|---|
| 399 | delete block;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | void FinallyStmt::print( std::ostream &os, int indent ) const {
|
|---|
| 403 | os << "Finally Statement" << endl;
|
|---|
| 404 | os << string( indent + 2, ' ' ) << "with block:" << endl;
|
|---|
| 405 | os << string( indent + 4, ' ' );
|
|---|
| 406 | block->print( os, indent + 4 );
|
|---|
| 407 | }
|
|---|
| 408 |
|
|---|
| 409 | NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {}
|
|---|
| 410 | NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {}
|
|---|
| 411 |
|
|---|
| 412 | void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const {
|
|---|
| 413 | os << "Null Statement" << endl ;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {
|
|---|
| 417 | assert( callStmt );
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) {
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
|
|---|
| 424 | delete callStmt;
|
|---|
| 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 |
|
|---|
| 434 | std::ostream & operator<<( std::ostream & out, const Statement * statement ) {
|
|---|
| 435 | if ( statement ) {
|
|---|
| 436 | statement->print( out );
|
|---|
| 437 | } else {
|
|---|
| 438 | out << "nullptr";
|
|---|
| 439 | }
|
|---|
| 440 | return out;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | // Local Variables: //
|
|---|
| 444 | // tab-width: 4 //
|
|---|
| 445 | // mode: c++ //
|
|---|
| 446 | // compile-command: "make install" //
|
|---|
| 447 | // End: //
|
|---|