| [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 | 
|---|
| [3b0bc16] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [6180274] | 12 | // Last Modified On : Wed Feb  2 20:19:33 2022 | 
|---|
|  | 13 | // Update Count     : 90 | 
|---|
| [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 |  | 
|---|
| [6180274] | 31 | using namespace std; | 
|---|
| [51b73452] | 32 |  | 
|---|
|  | 33 |  | 
|---|
| [6180274] | 34 | Statement::Statement( const list<Label> & labels ) : labels( labels ) {} | 
|---|
|  | 35 |  | 
|---|
|  | 36 | void Statement::print( ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 37 | if ( ! labels.empty() ) { | 
|---|
| [6a276a0] | 38 | os << indent << "... Labels: {"; | 
|---|
| [50377a4] | 39 | for ( const Label & l : labels ) { | 
|---|
|  | 40 | os << l << ","; | 
|---|
|  | 41 | } | 
|---|
|  | 42 | os << "}" << endl; | 
|---|
|  | 43 | } | 
|---|
|  | 44 | } | 
|---|
| [51b73452] | 45 |  | 
|---|
|  | 46 | Statement::~Statement() {} | 
|---|
|  | 47 |  | 
|---|
| [0608e007] | 48 | ExprStmt::ExprStmt( Expression * expr ) : Statement(), expr( expr ) {} | 
|---|
| [51b73452] | 49 |  | 
|---|
| [0608e007] | 50 | ExprStmt::ExprStmt( const ExprStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} | 
|---|
| [3be261a] | 51 |  | 
|---|
|  | 52 | ExprStmt::~ExprStmt() { | 
|---|
|  | 53 | delete expr; | 
|---|
|  | 54 | } | 
|---|
| [51b73452] | 55 |  | 
|---|
| [6180274] | 56 | void ExprStmt::print( ostream & os, Indenter indent ) const { | 
|---|
|  | 57 | os << "Expression Statement:" << endl << indent + 1; | 
|---|
|  | 58 | expr->print( os, indent + 1 ); | 
|---|
| [3be261a] | 59 | } | 
|---|
| [51b73452] | 60 |  | 
|---|
| [7f5566b] | 61 |  | 
|---|
| [6180274] | 62 | AsmStmt::AsmStmt( bool voltile, Expression * instruction, const list<Expression *> output, const list<Expression *> input, const list<ConstantExpr *> clobber, const list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {} | 
|---|
| [7f5566b] | 63 |  | 
|---|
| [3be261a] | 64 | AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { | 
|---|
|  | 65 | cloneAll( other.output, output ); | 
|---|
|  | 66 | cloneAll( other.input, input ); | 
|---|
|  | 67 | cloneAll( other.clobber, clobber ); | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [7f5566b] | 70 | AsmStmt::~AsmStmt() { | 
|---|
|  | 71 | delete instruction; | 
|---|
|  | 72 | deleteAll( output ); | 
|---|
|  | 73 | deleteAll( input ); | 
|---|
|  | 74 | deleteAll( clobber ); | 
|---|
|  | 75 | } | 
|---|
|  | 76 |  | 
|---|
| [6180274] | 77 | void AsmStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [7f5566b] | 78 | os << "Assembler Statement:" << endl; | 
|---|
| [6180274] | 79 | os << indent + 1 << "instruction: " << endl << indent; | 
|---|
|  | 80 | instruction->print( os, indent + 1 ); | 
|---|
| [7f5566b] | 81 | if ( ! output.empty() ) { | 
|---|
| [6180274] | 82 | os << endl << indent + 1 << "output: " << endl; | 
|---|
|  | 83 | printAll( output, os, indent + 1 ); | 
|---|
| [3be261a] | 84 | } // if | 
|---|
| [7f5566b] | 85 | if ( ! input.empty() ) { | 
|---|
| [6180274] | 86 | os << indent + 1 << "input: " << endl; | 
|---|
|  | 87 | printAll( input, os, indent + 1 ); | 
|---|
| [7f5566b] | 88 | } // if | 
|---|
|  | 89 | if ( ! clobber.empty() ) { | 
|---|
| [6180274] | 90 | os << indent + 1 << "clobber: " << endl; | 
|---|
|  | 91 | printAll( clobber, os, indent + 1 ); | 
|---|
| [7f5566b] | 92 | } // if | 
|---|
| [3be261a] | 93 | } | 
|---|
| [7f5566b] | 94 |  | 
|---|
|  | 95 |  | 
|---|
| [6180274] | 96 | DirectiveStmt::DirectiveStmt( const string & directive ) : Statement(), directive( directive ) {} | 
|---|
| [cc32d83] | 97 |  | 
|---|
| [6180274] | 98 | void DirectiveStmt::print( ostream & os, Indenter ) const { | 
|---|
| [cc32d83] | 99 | os << "GCC Directive:" << directive << endl; | 
|---|
|  | 100 | } | 
|---|
|  | 101 |  | 
|---|
|  | 102 |  | 
|---|
| [5ee7d36] | 103 | const char * BranchStmt::brType[] = { | 
|---|
|  | 104 | "Goto", "Break", "Continue", "Fall Through", "Fall Through Default", | 
|---|
|  | 105 | }; | 
|---|
| [51b73452] | 106 |  | 
|---|
| [f8965f4] | 107 | BranchStmt::BranchStmt( Label target, Type type ) : | 
|---|
| [ba3706f] | 108 | Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) { | 
|---|
| [0dd3a2f] | 109 | //actually this is a syntactic error signaled by the parser | 
|---|
| [b0dfbc4] | 110 | if ( type == BranchStmt::Goto && target.empty() ) { | 
|---|
| [a16764a6] | 111 | SemanticError( target.get_statement()->location, "goto without target"); | 
|---|
| [b0dfbc4] | 112 | } | 
|---|
| [51b73452] | 113 | } | 
|---|
|  | 114 |  | 
|---|
| [f8965f4] | 115 | BranchStmt::BranchStmt( Expression * computedTarget, Type type ) : | 
|---|
| [ba3706f] | 116 | Statement(), computedTarget( computedTarget ), type( type ) { | 
|---|
| [b0dfbc4] | 117 | if ( type != BranchStmt::Goto || computedTarget == nullptr ) { | 
|---|
| [a16764a6] | 118 | SemanticError( computedTarget->location, "Computed target not valid in branch statement"); | 
|---|
| [b0dfbc4] | 119 | } | 
|---|
| [51b73452] | 120 | } | 
|---|
|  | 121 |  | 
|---|
| [6180274] | 122 | void BranchStmt::print( ostream & os, Indenter indent ) const { | 
|---|
|  | 123 | assertf(type < BranchStmts, "CFA internal error: invalid branch statement" ); | 
|---|
| [50377a4] | 124 | os << "Branch (" << brType[type] << ")" << endl ; | 
|---|
| [6180274] | 125 | if ( target != "" ) os << indent + 1 << "with target: " << target << endl; | 
|---|
|  | 126 | if ( originalTarget != "" ) os << indent + 1 << "with original target: " << originalTarget << endl; | 
|---|
|  | 127 | if ( computedTarget != nullptr ) os << indent + 1 << "with computed target: " << computedTarget << endl; | 
|---|
| [51b73452] | 128 | } | 
|---|
|  | 129 |  | 
|---|
| [0608e007] | 130 | ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {} | 
|---|
| [51b73452] | 131 |  | 
|---|
| [daf1af8] | 132 | ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} | 
|---|
| [3be261a] | 133 |  | 
|---|
| [51b73452] | 134 | ReturnStmt::~ReturnStmt() { | 
|---|
| [0dd3a2f] | 135 | delete expr; | 
|---|
| [51b73452] | 136 | } | 
|---|
|  | 137 |  | 
|---|
| [6180274] | 138 | void ReturnStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 139 | os << "Return Statement, returning: "; | 
|---|
|  | 140 | if ( expr != nullptr ) { | 
|---|
| [6180274] | 141 | os << endl << indent + 1; | 
|---|
|  | 142 | expr->print( os, indent + 1 ); | 
|---|
| [89231bc] | 143 | } | 
|---|
| [0dd3a2f] | 144 | os << endl; | 
|---|
| [51b73452] | 145 | } | 
|---|
|  | 146 |  | 
|---|
| [6180274] | 147 | IfStmt::IfStmt( Expression * condition, Statement * then, Statement * else_, const list<Statement *> initialization ): | 
|---|
| [3b0bc16] | 148 | Statement(), condition( condition ), then( then ), else_( else_ ), initialization( initialization ) {} | 
|---|
| [51b73452] | 149 |  | 
|---|
| [3be261a] | 150 | IfStmt::IfStmt( const IfStmt & other ) : | 
|---|
| [3b0bc16] | 151 | Statement( other ), condition( maybeClone( other.condition ) ), then( maybeClone( other.then ) ), else_( maybeClone( other.else_ ) ) { | 
|---|
| [6d49ea3] | 152 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 153 | } | 
|---|
| [3be261a] | 154 |  | 
|---|
| [ac71a86] | 155 | IfStmt::~IfStmt() { | 
|---|
| [6d49ea3] | 156 | deleteAll( initialization ); | 
|---|
| [ac71a86] | 157 | delete condition; | 
|---|
| [3b0bc16] | 158 | delete then; | 
|---|
|  | 159 | delete else_; | 
|---|
| [ac71a86] | 160 | } | 
|---|
| [51b73452] | 161 |  | 
|---|
| [6180274] | 162 | void IfStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 163 | os << "If on condition: " << endl; | 
|---|
| [6180274] | 164 | os << indent + 1; | 
|---|
|  | 165 | condition->print( os, indent + 1 ); | 
|---|
| [51b73452] | 166 |  | 
|---|
| [6d49ea3] | 167 | if ( !initialization.empty() ) { | 
|---|
| [50377a4] | 168 | os << indent << "... with initialization: \n"; | 
|---|
|  | 169 | for ( const Statement * stmt : initialization ) { | 
|---|
| [6180274] | 170 | os << indent + 1; | 
|---|
|  | 171 | stmt->print( os, indent + 1 ); | 
|---|
| [6d49ea3] | 172 | } | 
|---|
|  | 173 | os << endl; | 
|---|
|  | 174 | } | 
|---|
|  | 175 |  | 
|---|
| [50377a4] | 176 | os << indent << "... then: " << endl; | 
|---|
| [51b73452] | 177 |  | 
|---|
| [6180274] | 178 | os << indent + 1; | 
|---|
|  | 179 | then->print( os, indent + 1 ); | 
|---|
| [51b73452] | 180 |  | 
|---|
| [3b0bc16] | 181 | if ( else_ != nullptr ) { | 
|---|
| [50377a4] | 182 | os << indent << "... else: " << endl; | 
|---|
| [6180274] | 183 | os << indent + 1; | 
|---|
|  | 184 | else_->print( os, indent + 1 ); | 
|---|
| [0dd3a2f] | 185 | } // if | 
|---|
| [51b73452] | 186 | } | 
|---|
|  | 187 |  | 
|---|
| [6180274] | 188 | SwitchStmt::SwitchStmt( Expression * condition, const list<Statement *> & statements ): | 
|---|
| [ba3706f] | 189 | Statement(), condition( condition ), statements( statements ) { | 
|---|
| [0dd3a2f] | 190 | } | 
|---|
| [51b73452] | 191 |  | 
|---|
| [3be261a] | 192 | SwitchStmt::SwitchStmt( const SwitchStmt & other ): | 
|---|
|  | 193 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
| [8688ce1] | 194 | cloneAll( other.statements, statements ); | 
|---|
| [3be261a] | 195 | } | 
|---|
|  | 196 |  | 
|---|
| [51b73452] | 197 | SwitchStmt::~SwitchStmt() { | 
|---|
| [0dd3a2f] | 198 | delete condition; | 
|---|
| [8688ce1] | 199 | // destroy statements | 
|---|
| [2037f82] | 200 | deleteAll( statements ); | 
|---|
| [51b73452] | 201 | } | 
|---|
|  | 202 |  | 
|---|
| [6180274] | 203 | void SwitchStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [89231bc] | 204 | os << "Switch on condition: "; | 
|---|
| [0dd3a2f] | 205 | condition->print( os ); | 
|---|
|  | 206 | os << endl; | 
|---|
| [51b73452] | 207 |  | 
|---|
| [50377a4] | 208 | for ( const Statement * stmt : statements ) { | 
|---|
| [6180274] | 209 | stmt->print( os, indent + 1 ); | 
|---|
| [50377a4] | 210 | } | 
|---|
| [51b73452] | 211 | } | 
|---|
|  | 212 |  | 
|---|
| [f8965f4] | 213 | CaseStmt::CaseStmt( Expression * condition, const list<Statement *> & statements, bool deflt ) : | 
|---|
| [6180274] | 214 | Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) { | 
|---|
| [0608e007] | 215 | if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " ); | 
|---|
| [51b73452] | 216 | } | 
|---|
|  | 217 |  | 
|---|
| [3be261a] | 218 | CaseStmt::CaseStmt( const CaseStmt & other ) : | 
|---|
| [6180274] | 219 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { | 
|---|
| [3be261a] | 220 | cloneAll( other.stmts, stmts ); | 
|---|
|  | 221 | } | 
|---|
|  | 222 |  | 
|---|
| [51b73452] | 223 | CaseStmt::~CaseStmt() { | 
|---|
| [0dd3a2f] | 224 | delete condition; | 
|---|
| [2037f82] | 225 | deleteAll( stmts ); | 
|---|
| [51b73452] | 226 | } | 
|---|
|  | 227 |  | 
|---|
| [6180274] | 228 | CaseStmt * CaseStmt::makeDefault( const list<Label> & labels, list<Statement *> stmts ) { | 
|---|
| [ba3706f] | 229 | CaseStmt * stmt = new CaseStmt( nullptr, stmts, true ); | 
|---|
|  | 230 | stmt->labels = labels; | 
|---|
|  | 231 | return stmt; | 
|---|
| [b2152e7a] | 232 | } | 
|---|
|  | 233 |  | 
|---|
| [6180274] | 234 | void CaseStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [6a276a0] | 235 | if ( isDefault() ) os << indent << "Default "; | 
|---|
| [0dd3a2f] | 236 | else { | 
|---|
| [6a276a0] | 237 | os << indent << "Case "; | 
|---|
| [50377a4] | 238 | condition->print( os, indent ); | 
|---|
| [0dd3a2f] | 239 | } // if | 
|---|
|  | 240 | os << endl; | 
|---|
| [51b73452] | 241 |  | 
|---|
| [50377a4] | 242 | for ( Statement * stmt : stmts ) { | 
|---|
| [6180274] | 243 | os << indent + 1; | 
|---|
|  | 244 | stmt->print( os, indent + 1 ); | 
|---|
| [50377a4] | 245 | } | 
|---|
| [51b73452] | 246 | } | 
|---|
|  | 247 |  | 
|---|
| [6180274] | 248 | WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, const list< Statement * > & initialization, bool isDoWhile ): | 
|---|
| [3b0bc16] | 249 | Statement(), condition( condition ), body( body ), else_( nullptr ), initialization( initialization ), isDoWhile( isDoWhile) { | 
|---|
| [0dd3a2f] | 250 | } | 
|---|
| [51b73452] | 251 |  | 
|---|
| [6180274] | 252 | WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, Statement * else_, const list< Statement * > & initialization, bool isDoWhile ): | 
|---|
| [3b0bc16] | 253 | Statement(), condition( condition), body( body ), else_( else_ ), initialization( initialization ), isDoWhile( isDoWhile) { | 
|---|
|  | 254 | } | 
|---|
|  | 255 |  | 
|---|
|  | 256 | WhileDoStmt::WhileDoStmt( const WhileDoStmt & other ): | 
|---|
| [3be261a] | 257 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { | 
|---|
|  | 258 | } | 
|---|
|  | 259 |  | 
|---|
| [3b0bc16] | 260 | WhileDoStmt::~WhileDoStmt() { | 
|---|
| [0dd3a2f] | 261 | delete body; | 
|---|
| [2037f82] | 262 | delete condition; | 
|---|
| [51b73452] | 263 | } | 
|---|
|  | 264 |  | 
|---|
| [6180274] | 265 | void WhileDoStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [89231bc] | 266 | os << "While on condition: " << endl ; | 
|---|
| [6180274] | 267 | condition->print( os, indent + 1 ); | 
|---|
| [51b73452] | 268 |  | 
|---|
| [50377a4] | 269 | os << indent << "... with body: " << endl; | 
|---|
| [51b73452] | 270 |  | 
|---|
| [6180274] | 271 | if ( body != nullptr ) body->print( os, indent + 1 ); | 
|---|
| [51b73452] | 272 | } | 
|---|
|  | 273 |  | 
|---|
| [6180274] | 274 | ForStmt::ForStmt( const list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body, Statement * else_ ): | 
|---|
| [3b0bc16] | 275 | Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ), else_( else_ ) { | 
|---|
| [0dd3a2f] | 276 | } | 
|---|
| [51b73452] | 277 |  | 
|---|
| [3be261a] | 278 | ForStmt::ForStmt( const ForStmt & other ): | 
|---|
| [3b0bc16] | 279 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ), else_( maybeClone( other.else_ ) ) { | 
|---|
| [3be261a] | 280 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 281 |  | 
|---|
|  | 282 | } | 
|---|
|  | 283 |  | 
|---|
| [51b73452] | 284 | ForStmt::~ForStmt() { | 
|---|
| [145f1fc] | 285 | deleteAll( initialization ); | 
|---|
| [0dd3a2f] | 286 | delete condition; | 
|---|
|  | 287 | delete increment; | 
|---|
|  | 288 | delete body; | 
|---|
| [3b0bc16] | 289 | delete else_; | 
|---|
| [51b73452] | 290 | } | 
|---|
|  | 291 |  | 
|---|
| [6180274] | 292 | void ForStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 293 | Statement::print( os, indent ); // print labels | 
|---|
| [be5aa1b] | 294 |  | 
|---|
| [50377a4] | 295 | os << "For Statement" << endl; | 
|---|
| [51b73452] | 296 |  | 
|---|
| [50377a4] | 297 | if ( ! initialization.empty() ) { | 
|---|
|  | 298 | os << indent << "... initialization: \n"; | 
|---|
|  | 299 | for ( Statement * stmt : initialization ) { | 
|---|
| [6180274] | 300 | os << indent + 1; | 
|---|
|  | 301 | stmt->print( os, indent + 1 ); | 
|---|
| [50377a4] | 302 | } | 
|---|
| [145f1fc] | 303 | } | 
|---|
| [51b73452] | 304 |  | 
|---|
| [50377a4] | 305 | if ( condition != nullptr ) { | 
|---|
| [6180274] | 306 | os << indent << "... condition: \n" << indent + 1; | 
|---|
|  | 307 | condition->print( os, indent + 1 ); | 
|---|
| [bb8ea30] | 308 | } | 
|---|
| [51b73452] | 309 |  | 
|---|
| [50377a4] | 310 | if ( increment != nullptr ) { | 
|---|
| [6180274] | 311 | os << "\n" << indent << "... increment: \n" << indent + 1; | 
|---|
|  | 312 | increment->print( os, indent + 1 ); | 
|---|
| [bb8ea30] | 313 | } | 
|---|
| [51b73452] | 314 |  | 
|---|
| [0608e007] | 315 | if ( body != nullptr ) { | 
|---|
| [6180274] | 316 | os << "\n" << indent << "... with body: \n" << indent + 1; | 
|---|
|  | 317 | body->print( os, indent + 1 ); | 
|---|
| [bb8ea30] | 318 | } | 
|---|
| [3b0bc16] | 319 |  | 
|---|
|  | 320 | if ( else_ != nullptr ) { | 
|---|
| [6180274] | 321 | os << "\n" << indent << "... with body: \n" << indent + 1; | 
|---|
|  | 322 | else_->print( os, indent + 1 ); | 
|---|
| [3b0bc16] | 323 | } | 
|---|
| [0dd3a2f] | 324 | os << endl; | 
|---|
| [51b73452] | 325 | } | 
|---|
|  | 326 |  | 
|---|
| [ba3706f] | 327 | ThrowStmt::ThrowStmt( Kind kind, Expression * expr, Expression * target ) : | 
|---|
|  | 328 | Statement(), kind(kind), expr(expr), target(target)     { | 
|---|
| [daf1af8] | 329 | assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." ); | 
|---|
|  | 330 | } | 
|---|
|  | 331 |  | 
|---|
| [0608e007] | 332 | ThrowStmt::ThrowStmt( const ThrowStmt & other ) : | 
|---|
| [daf1af8] | 333 | Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { | 
|---|
|  | 334 | } | 
|---|
|  | 335 |  | 
|---|
|  | 336 | ThrowStmt::~ThrowStmt() { | 
|---|
|  | 337 | delete expr; | 
|---|
|  | 338 | delete target; | 
|---|
|  | 339 | } | 
|---|
|  | 340 |  | 
|---|
| [6180274] | 341 | void ThrowStmt::print( ostream & os, Indenter indent) const { | 
|---|
| [50377a4] | 342 | if ( target ) os << "Non-Local "; | 
|---|
| [daf1af8] | 343 | os << "Throw Statement, raising: "; | 
|---|
| [6180274] | 344 | expr->print(os, indent + 1); | 
|---|
| [daf1af8] | 345 | if ( target ) { | 
|---|
| [50377a4] | 346 | os << "... at: "; | 
|---|
| [6180274] | 347 | target->print(os, indent + 1); | 
|---|
| [daf1af8] | 348 | } | 
|---|
|  | 349 | } | 
|---|
|  | 350 |  | 
|---|
| [6180274] | 351 | TryStmt::TryStmt( CompoundStmt * tryBlock, const list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) : | 
|---|
| [ba3706f] | 352 | Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) { | 
|---|
| [0dd3a2f] | 353 | } | 
|---|
| [51b73452] | 354 |  | 
|---|
| [0608e007] | 355 | TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { | 
|---|
| [3be261a] | 356 | cloneAll( other.handlers, handlers ); | 
|---|
| [51b73452] | 357 | } | 
|---|
|  | 358 |  | 
|---|
| [a08ba92] | 359 | TryStmt::~TryStmt() { | 
|---|
| [0dd3a2f] | 360 | delete block; | 
|---|
| [2037f82] | 361 | deleteAll( handlers ); | 
|---|
|  | 362 | delete finallyBlock; | 
|---|
| [51b73452] | 363 | } | 
|---|
|  | 364 |  | 
|---|
| [6180274] | 365 | void TryStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [89231bc] | 366 | os << "Try Statement" << endl; | 
|---|
| [6180274] | 367 | os << indent << "... with block:" << endl << indent + 1; | 
|---|
|  | 368 | block->print( os, indent + 1 ); | 
|---|
| [0dd3a2f] | 369 |  | 
|---|
|  | 370 | // handlers | 
|---|
| [50377a4] | 371 | os << indent << "... and handlers:" << endl; | 
|---|
|  | 372 | for ( const CatchStmt * stmt : handlers ) { | 
|---|
| [6180274] | 373 | os << indent + 1; | 
|---|
|  | 374 | stmt->print( os, indent + 1 ); | 
|---|
| [406a6e6] | 375 | } | 
|---|
| [0dd3a2f] | 376 |  | 
|---|
|  | 377 | // finally block | 
|---|
| [0608e007] | 378 | if ( finallyBlock != nullptr ) { | 
|---|
| [6180274] | 379 | os << indent << "... and finally:" << endl << indent + 1; | 
|---|
|  | 380 | finallyBlock->print( os, indent + 1 ); | 
|---|
| [0dd3a2f] | 381 | } // if | 
|---|
| [51b73452] | 382 | } | 
|---|
|  | 383 |  | 
|---|
| [0608e007] | 384 | CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) : | 
|---|
| [ba3706f] | 385 | Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { | 
|---|
| [50377a4] | 386 | assertf( decl, "Catch clause must have a declaration." ); | 
|---|
| [0dd3a2f] | 387 | } | 
|---|
| [51b73452] | 388 |  | 
|---|
| [3be261a] | 389 | CatchStmt::CatchStmt( const CatchStmt & other ) : | 
|---|
| [ca78437] | 390 | Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) { | 
|---|
| [3be261a] | 391 | } | 
|---|
|  | 392 |  | 
|---|
| [a08ba92] | 393 | CatchStmt::~CatchStmt() { | 
|---|
| [0dd3a2f] | 394 | delete decl; | 
|---|
|  | 395 | delete body; | 
|---|
| [51b73452] | 396 | } | 
|---|
|  | 397 |  | 
|---|
| [6180274] | 398 | void CatchStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [ca78437] | 399 | os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; | 
|---|
| [0dd3a2f] | 400 |  | 
|---|
| [50377a4] | 401 | os << indent << "... catching: "; | 
|---|
| [6180274] | 402 | decl->printShort( os, indent + 1 ); | 
|---|
| [50377a4] | 403 | os << endl; | 
|---|
| [406a6e6] | 404 |  | 
|---|
|  | 405 | if ( cond ) { | 
|---|
| [6180274] | 406 | os << indent << "... with conditional:" << endl << indent + 1; | 
|---|
|  | 407 | cond->print( os, indent + 1 ); | 
|---|
| [406a6e6] | 408 | } | 
|---|
|  | 409 |  | 
|---|
| [50377a4] | 410 | os << indent << "... with block:" << endl; | 
|---|
| [6180274] | 411 | os << indent + 1; | 
|---|
|  | 412 | body->print( os, indent + 1 ); | 
|---|
| [51b73452] | 413 | } | 
|---|
|  | 414 |  | 
|---|
|  | 415 |  | 
|---|
| [0608e007] | 416 | FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) { | 
|---|
| [51b73452] | 417 | } | 
|---|
|  | 418 |  | 
|---|
| [3be261a] | 419 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { | 
|---|
|  | 420 | } | 
|---|
|  | 421 |  | 
|---|
| [0dd3a2f] | 422 | FinallyStmt::~FinallyStmt() { | 
|---|
|  | 423 | delete block; | 
|---|
| [51b73452] | 424 | } | 
|---|
|  | 425 |  | 
|---|
| [6180274] | 426 | void FinallyStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [f1b1e4c] | 427 | os << "Finally Statement" << endl; | 
|---|
| [6180274] | 428 | os << indent << "... with block:" << endl << indent + 1; | 
|---|
|  | 429 | block->print( os, indent + 1 ); | 
|---|
| [51b73452] | 430 | } | 
|---|
|  | 431 |  | 
|---|
| [37cdd97] | 432 | SuspendStmt::SuspendStmt( const SuspendStmt & other ) | 
|---|
|  | 433 | : Statement( other ) | 
|---|
|  | 434 | , then( maybeClone(other.then) ) | 
|---|
|  | 435 | {} | 
|---|
|  | 436 |  | 
|---|
|  | 437 | SuspendStmt::~SuspendStmt() { | 
|---|
|  | 438 | delete then; | 
|---|
|  | 439 | } | 
|---|
|  | 440 |  | 
|---|
| [6180274] | 441 | void SuspendStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [37cdd97] | 442 | os << "Suspend Statement"; | 
|---|
|  | 443 | switch (type) { | 
|---|
|  | 444 | case None     : os << " with implicit target"; break; | 
|---|
|  | 445 | case Generator: os << " for generator"       ; break; | 
|---|
|  | 446 | case Coroutine: os << " for coroutine"       ; break; | 
|---|
|  | 447 | } | 
|---|
|  | 448 | os << endl; | 
|---|
|  | 449 | indent += 1; | 
|---|
|  | 450 |  | 
|---|
|  | 451 | if(then) { | 
|---|
|  | 452 | os << indent << " with post statement :" << endl; | 
|---|
|  | 453 | then->print( os, indent + 1); | 
|---|
|  | 454 | } | 
|---|
|  | 455 | } | 
|---|
|  | 456 |  | 
|---|
| [ba3706f] | 457 | WaitForStmt::WaitForStmt() : Statement() { | 
|---|
| [135b431] | 458 | timeout.time      = nullptr; | 
|---|
|  | 459 | timeout.statement = nullptr; | 
|---|
|  | 460 | timeout.condition = nullptr; | 
|---|
|  | 461 | orelse .statement = nullptr; | 
|---|
|  | 462 | orelse .condition = nullptr; | 
|---|
|  | 463 | } | 
|---|
|  | 464 |  | 
|---|
|  | 465 | WaitForStmt::WaitForStmt( const WaitForStmt & other ) : Statement( other ) { | 
|---|
|  | 466 | clauses.reserve( other.clauses.size() ); | 
|---|
|  | 467 | for( auto & ocl : other.clauses ) { | 
|---|
|  | 468 | clauses.emplace_back(); | 
|---|
|  | 469 | clauses.back().target.function = ocl.target.function->clone(); | 
|---|
|  | 470 | cloneAll( ocl.target.arguments, clauses.back().target.arguments ); | 
|---|
|  | 471 | clauses.back().statement = ocl.statement->clone(); | 
|---|
|  | 472 | clauses.back().condition = ocl.condition->clone(); | 
|---|
|  | 473 | } | 
|---|
|  | 474 |  | 
|---|
|  | 475 | timeout.time      = other.timeout.time     ->clone(); | 
|---|
|  | 476 | timeout.statement = other.timeout.statement->clone(); | 
|---|
|  | 477 | timeout.condition = other.timeout.condition->clone(); | 
|---|
|  | 478 | orelse .statement = other.orelse .statement->clone(); | 
|---|
|  | 479 | orelse .condition = other.orelse .condition->clone(); | 
|---|
|  | 480 | } | 
|---|
|  | 481 |  | 
|---|
|  | 482 | WaitForStmt::~WaitForStmt() { | 
|---|
|  | 483 | for( auto & clause : clauses ) { | 
|---|
|  | 484 | delete clause.target.function; | 
|---|
|  | 485 | deleteAll( clause.target.arguments ); | 
|---|
|  | 486 | delete clause.statement; | 
|---|
|  | 487 | delete clause.condition; | 
|---|
|  | 488 | } | 
|---|
|  | 489 |  | 
|---|
|  | 490 | delete timeout.time; | 
|---|
|  | 491 | delete timeout.statement; | 
|---|
|  | 492 | delete timeout.condition; | 
|---|
|  | 493 |  | 
|---|
|  | 494 | delete orelse.statement; | 
|---|
|  | 495 | delete orelse.condition; | 
|---|
|  | 496 | } | 
|---|
|  | 497 |  | 
|---|
| [6180274] | 498 | void WaitForStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [135b431] | 499 | os << "Waitfor Statement" << endl; | 
|---|
| [b9f383f] | 500 | indent += 1; | 
|---|
|  | 501 | for( auto & clause : clauses ) { | 
|---|
|  | 502 | os << indent << "target function :"; | 
|---|
|  | 503 | if(clause.target.function) { clause.target.function->print(os, indent + 1); } | 
|---|
|  | 504 | os << endl << indent << "with arguments :" << endl; | 
|---|
|  | 505 | for( auto & thing : clause.target.arguments) { | 
|---|
|  | 506 | if(thing) { thing->print(os, indent + 1); } | 
|---|
|  | 507 | } | 
|---|
|  | 508 | os << indent << " with statment :" << endl; | 
|---|
|  | 509 | if(clause.statement) { clause.statement->print(os, indent + 1); } | 
|---|
|  | 510 |  | 
|---|
|  | 511 | os << indent << " with condition :" << endl; | 
|---|
|  | 512 | if(clause.condition) { clause.condition->print(os, indent + 1); } | 
|---|
|  | 513 | } | 
|---|
|  | 514 |  | 
|---|
|  | 515 | os << indent << " timeout of :" << endl; | 
|---|
|  | 516 | if(timeout.time) { timeout.time->print(os, indent + 1); } | 
|---|
|  | 517 |  | 
|---|
|  | 518 | os << indent << " with statment :" << endl; | 
|---|
|  | 519 | if(timeout.statement) { timeout.statement->print(os, indent + 1); } | 
|---|
|  | 520 |  | 
|---|
|  | 521 | os << indent << " with condition :" << endl; | 
|---|
|  | 522 | if(timeout.condition) { timeout.condition->print(os, indent + 1); } | 
|---|
|  | 523 |  | 
|---|
|  | 524 |  | 
|---|
|  | 525 | os << indent << " else :" << endl; | 
|---|
|  | 526 | if(orelse.statement) { orelse.statement->print(os, indent + 1); } | 
|---|
|  | 527 |  | 
|---|
|  | 528 | os << indent << " with condition :" << endl; | 
|---|
|  | 529 | if(orelse.condition) { orelse.condition->print(os, indent + 1); } | 
|---|
| [135b431] | 530 | } | 
|---|
|  | 531 |  | 
|---|
| [61255ad] | 532 |  | 
|---|
| [6180274] | 533 | WithStmt::WithStmt( const list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {} | 
|---|
| [e67991f] | 534 | WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { | 
|---|
| [61255ad] | 535 | cloneAll( other.exprs, exprs ); | 
|---|
|  | 536 | } | 
|---|
|  | 537 | WithStmt::~WithStmt() { | 
|---|
|  | 538 | deleteAll( exprs ); | 
|---|
|  | 539 | delete stmt; | 
|---|
|  | 540 | } | 
|---|
|  | 541 |  | 
|---|
| [6180274] | 542 | void WithStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [61255ad] | 543 | os << "With statement" << endl; | 
|---|
| [44b4114] | 544 | os << indent << "... with expressions: " << endl; | 
|---|
| [6180274] | 545 | printAll( exprs, os, indent + 1 ); | 
|---|
|  | 546 | os << indent << "... with statement:" << endl << indent + 1; | 
|---|
|  | 547 | stmt->print( os, indent + 1 ); | 
|---|
| [61255ad] | 548 | } | 
|---|
|  | 549 |  | 
|---|
|  | 550 |  | 
|---|
| [6180274] | 551 | NullStmt::NullStmt( const list<Label> & labels ) : Statement( labels ) { | 
|---|
| [ba3706f] | 552 | } | 
|---|
| [51b73452] | 553 |  | 
|---|
| [6180274] | 554 | void NullStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 555 | os << "Null Statement" << endl; | 
|---|
| [6a276a0] | 556 | Statement::print( os, indent ); | 
|---|
| [51b73452] | 557 | } | 
|---|
|  | 558 |  | 
|---|
| [ba3706f] | 559 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement(), callStmt( callStmt ) { | 
|---|
| [f1b1e4c] | 560 | assert( callStmt ); | 
|---|
|  | 561 | } | 
|---|
|  | 562 |  | 
|---|
| [74d1804] | 563 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { | 
|---|
| [f1b1e4c] | 564 | } | 
|---|
|  | 565 |  | 
|---|
|  | 566 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { | 
|---|
| [74d1804] | 567 | delete callStmt; | 
|---|
| [f1b1e4c] | 568 | } | 
|---|
|  | 569 |  | 
|---|
| [6180274] | 570 | void ImplicitCtorDtorStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [f1b1e4c] | 571 | os << "Implicit Ctor Dtor Statement" << endl; | 
|---|
| [50377a4] | 572 | os << indent << "... with Ctor/Dtor: "; | 
|---|
| [6180274] | 573 | callStmt->print( os, indent + 1); | 
|---|
| [f1b1e4c] | 574 | os << endl; | 
|---|
|  | 575 | } | 
|---|
|  | 576 |  | 
|---|
| [f8965f4] | 577 | MutexStmt::MutexStmt( Statement * stmt, const list<Expression *> mutexObjs ) | 
|---|
| [6cebfef] | 578 | : Statement(), stmt( stmt ), mutexObjs( mutexObjs ) { } | 
|---|
|  | 579 |  | 
|---|
|  | 580 | MutexStmt::MutexStmt( const MutexStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) { | 
|---|
|  | 581 | cloneAll( other.mutexObjs, mutexObjs ); | 
|---|
|  | 582 | } | 
|---|
|  | 583 |  | 
|---|
|  | 584 | MutexStmt::~MutexStmt() { | 
|---|
|  | 585 | deleteAll( mutexObjs ); | 
|---|
|  | 586 | delete stmt; | 
|---|
|  | 587 | } | 
|---|
|  | 588 |  | 
|---|
| [6180274] | 589 | void MutexStmt::print( ostream & os, Indenter indent ) const { | 
|---|
| [6cebfef] | 590 | os << "Mutex Statement" << endl; | 
|---|
|  | 591 | os << indent << "... with Expressions: " << endl; | 
|---|
|  | 592 | for (auto * obj : mutexObjs) { | 
|---|
| [6180274] | 593 | os << indent + 1; | 
|---|
|  | 594 | obj->print( os, indent + 1); | 
|---|
| [6cebfef] | 595 | os << endl; | 
|---|
|  | 596 | } | 
|---|
| [6180274] | 597 | os << indent << "... with Statement: " << endl << indent + 1; | 
|---|
|  | 598 | stmt->print( os, indent + 1 ); | 
|---|
| [6cebfef] | 599 | } | 
|---|
|  | 600 |  | 
|---|
| [0dd3a2f] | 601 | // Local Variables: // | 
|---|
|  | 602 | // tab-width: 4 // | 
|---|
|  | 603 | // mode: c++ // | 
|---|
|  | 604 | // compile-command: "make install" // | 
|---|
|  | 605 | // End: // | 
|---|