| [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 | 
|---|
| [5ee7d36] | 11 | // Last Modified By : Andrew Beach | 
|---|
|  | 12 | // Last Modified On : Mon Jan 20 16:03:00 2020 | 
|---|
|  | 13 | // Update Count     : 71 | 
|---|
| [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 |  | 
|---|
| [ba3706f] | 34 | Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {} | 
|---|
| [51b73452] | 35 |  | 
|---|
| [6a276a0] | 36 | void Statement::print( std::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 |  | 
|---|
| [0608e007] | 56 | void ExprStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 57 | os << "Expression Statement:" << endl << indent+1; | 
|---|
|  | 58 | expr->print( os, indent+1 ); | 
|---|
| [3be261a] | 59 | } | 
|---|
| [51b73452] | 60 |  | 
|---|
| [7f5566b] | 61 |  | 
|---|
| [0608e007] | 62 | AsmStmt::AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::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 |  | 
|---|
| [0608e007] | 77 | void AsmStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [7f5566b] | 78 | os << "Assembler Statement:" << endl; | 
|---|
| [50377a4] | 79 | os << indent+1 << "instruction: " << endl << indent; | 
|---|
|  | 80 | instruction->print( os, indent+1 ); | 
|---|
| [7f5566b] | 81 | if ( ! output.empty() ) { | 
|---|
| [50377a4] | 82 | os << endl << indent+1 << "output: " << endl; | 
|---|
|  | 83 | printAll( output, os, indent+1 ); | 
|---|
| [3be261a] | 84 | } // if | 
|---|
| [7f5566b] | 85 | if ( ! input.empty() ) { | 
|---|
| [50377a4] | 86 | os << indent+1 << "input: " << endl; | 
|---|
|  | 87 | printAll( input, os, indent+1 ); | 
|---|
| [7f5566b] | 88 | } // if | 
|---|
|  | 89 | if ( ! clobber.empty() ) { | 
|---|
| [50377a4] | 90 | os << indent+1 << "clobber: " << endl; | 
|---|
|  | 91 | printAll( clobber, os, indent+1 ); | 
|---|
| [7f5566b] | 92 | } // if | 
|---|
| [3be261a] | 93 | } | 
|---|
| [7f5566b] | 94 |  | 
|---|
|  | 95 |  | 
|---|
| [cc32d83] | 96 | DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {} | 
|---|
|  | 97 |  | 
|---|
| [0608e007] | 98 | void DirectiveStmt::print( std::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 |  | 
|---|
| [a16764a6] | 107 | BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) : | 
|---|
| [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 |  | 
|---|
| [0608e007] | 115 | BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) : | 
|---|
| [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 |  | 
|---|
| [0608e007] | 122 | void BranchStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [5ee7d36] | 123 | assert(type < 5); | 
|---|
| [50377a4] | 124 | os << "Branch (" << brType[type] << ")" << endl ; | 
|---|
|  | 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 |  | 
|---|
| [0608e007] | 138 | void ReturnStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 139 | os << "Return Statement, returning: "; | 
|---|
|  | 140 | if ( expr != nullptr ) { | 
|---|
|  | 141 | os << endl << indent+1; | 
|---|
|  | 142 | expr->print( os, indent+1 ); | 
|---|
| [89231bc] | 143 | } | 
|---|
| [0dd3a2f] | 144 | os << endl; | 
|---|
| [51b73452] | 145 | } | 
|---|
|  | 146 |  | 
|---|
| [0608e007] | 147 | IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ): | 
|---|
| [ba3706f] | 148 | Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {} | 
|---|
| [51b73452] | 149 |  | 
|---|
| [3be261a] | 150 | IfStmt::IfStmt( const IfStmt & other ) : | 
|---|
| [6d49ea3] | 151 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { | 
|---|
|  | 152 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 153 | } | 
|---|
| [3be261a] | 154 |  | 
|---|
| [ac71a86] | 155 | IfStmt::~IfStmt() { | 
|---|
| [6d49ea3] | 156 | deleteAll( initialization ); | 
|---|
| [ac71a86] | 157 | delete condition; | 
|---|
|  | 158 | delete thenPart; | 
|---|
|  | 159 | delete elsePart; | 
|---|
|  | 160 | } | 
|---|
| [51b73452] | 161 |  | 
|---|
| [0608e007] | 162 | void IfStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 163 | os << "If on condition: " << endl; | 
|---|
|  | 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 ) { | 
|---|
|  | 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 |  | 
|---|
| [50377a4] | 178 | os << indent+1; | 
|---|
|  | 179 | thenPart->print( os, indent+1 ); | 
|---|
| [51b73452] | 180 |  | 
|---|
| [0608e007] | 181 | if ( elsePart != nullptr ) { | 
|---|
| [50377a4] | 182 | os << indent << "... else: " << endl; | 
|---|
|  | 183 | os << indent+1; | 
|---|
|  | 184 | elsePart->print( os, indent+1 ); | 
|---|
| [0dd3a2f] | 185 | } // if | 
|---|
| [51b73452] | 186 | } | 
|---|
|  | 187 |  | 
|---|
| [0608e007] | 188 | SwitchStmt::SwitchStmt( Expression * condition, const std::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 |  | 
|---|
| [0608e007] | 203 | void SwitchStmt::print( std::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 ) { | 
|---|
|  | 209 | stmt->print( os, indent+1 ); | 
|---|
|  | 210 | } | 
|---|
| [51b73452] | 211 | } | 
|---|
|  | 212 |  | 
|---|
| [0608e007] | 213 | CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) : | 
|---|
| [ba3706f] | 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 ) : | 
|---|
|  | 219 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { | 
|---|
|  | 220 | cloneAll( other.stmts, stmts ); | 
|---|
|  | 221 | } | 
|---|
|  | 222 |  | 
|---|
| [51b73452] | 223 | CaseStmt::~CaseStmt() { | 
|---|
| [0dd3a2f] | 224 | delete condition; | 
|---|
| [2037f82] | 225 | deleteAll( stmts ); | 
|---|
| [51b73452] | 226 | } | 
|---|
|  | 227 |  | 
|---|
| [ba3706f] | 228 | CaseStmt * CaseStmt::makeDefault( const std::list<Label> & labels, std::list<Statement *> stmts ) { | 
|---|
|  | 229 | CaseStmt * stmt = new CaseStmt( nullptr, stmts, true ); | 
|---|
|  | 230 | stmt->labels = labels; | 
|---|
|  | 231 | return stmt; | 
|---|
| [b2152e7a] | 232 | } | 
|---|
|  | 233 |  | 
|---|
| [0608e007] | 234 | void CaseStmt::print( std::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 ) { | 
|---|
| [6a276a0] | 243 | os << indent+1; | 
|---|
| [50377a4] | 244 | stmt->print( os, indent+1 ); | 
|---|
|  | 245 | } | 
|---|
| [51b73452] | 246 | } | 
|---|
|  | 247 |  | 
|---|
| [0608e007] | 248 | WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ): | 
|---|
| [ee3c93d] | 249 | Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) { | 
|---|
| [0dd3a2f] | 250 | } | 
|---|
| [51b73452] | 251 |  | 
|---|
| [3be261a] | 252 | WhileStmt::WhileStmt( const WhileStmt & other ): | 
|---|
|  | 253 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { | 
|---|
|  | 254 | } | 
|---|
|  | 255 |  | 
|---|
| [a08ba92] | 256 | WhileStmt::~WhileStmt() { | 
|---|
| [0dd3a2f] | 257 | delete body; | 
|---|
| [2037f82] | 258 | delete condition; | 
|---|
| [51b73452] | 259 | } | 
|---|
|  | 260 |  | 
|---|
| [0608e007] | 261 | void WhileStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [89231bc] | 262 | os << "While on condition: " << endl ; | 
|---|
| [50377a4] | 263 | condition->print( os, indent+1 ); | 
|---|
| [51b73452] | 264 |  | 
|---|
| [50377a4] | 265 | os << indent << "... with body: " << endl; | 
|---|
| [51b73452] | 266 |  | 
|---|
| [0608e007] | 267 | if ( body != nullptr ) body->print( os, indent+1 ); | 
|---|
| [51b73452] | 268 | } | 
|---|
|  | 269 |  | 
|---|
| [0608e007] | 270 | ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ): | 
|---|
| [ba3706f] | 271 | Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) { | 
|---|
| [0dd3a2f] | 272 | } | 
|---|
| [51b73452] | 273 |  | 
|---|
| [3be261a] | 274 | ForStmt::ForStmt( const ForStmt & other ): | 
|---|
|  | 275 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) { | 
|---|
|  | 276 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 277 |  | 
|---|
|  | 278 | } | 
|---|
|  | 279 |  | 
|---|
| [51b73452] | 280 | ForStmt::~ForStmt() { | 
|---|
| [145f1fc] | 281 | deleteAll( initialization ); | 
|---|
| [0dd3a2f] | 282 | delete condition; | 
|---|
|  | 283 | delete increment; | 
|---|
|  | 284 | delete body; | 
|---|
| [51b73452] | 285 | } | 
|---|
|  | 286 |  | 
|---|
| [0608e007] | 287 | void ForStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 288 | Statement::print( os, indent ); // print labels | 
|---|
| [be5aa1b] | 289 |  | 
|---|
| [50377a4] | 290 | os << "For Statement" << endl; | 
|---|
| [51b73452] | 291 |  | 
|---|
| [50377a4] | 292 | if ( ! initialization.empty() ) { | 
|---|
|  | 293 | os << indent << "... initialization: \n"; | 
|---|
|  | 294 | for ( Statement * stmt : initialization ) { | 
|---|
|  | 295 | os << indent+1; | 
|---|
|  | 296 | stmt->print( os, indent+1 ); | 
|---|
|  | 297 | } | 
|---|
| [145f1fc] | 298 | } | 
|---|
| [51b73452] | 299 |  | 
|---|
| [50377a4] | 300 | if ( condition != nullptr ) { | 
|---|
|  | 301 | os << indent << "... condition: \n" << indent+1; | 
|---|
|  | 302 | condition->print( os, indent+1 ); | 
|---|
| [bb8ea30] | 303 | } | 
|---|
| [51b73452] | 304 |  | 
|---|
| [50377a4] | 305 | if ( increment != nullptr ) { | 
|---|
|  | 306 | os << "\n" << indent << "... increment: \n" << indent+1; | 
|---|
|  | 307 | increment->print( os, indent+1 ); | 
|---|
| [bb8ea30] | 308 | } | 
|---|
| [51b73452] | 309 |  | 
|---|
| [0608e007] | 310 | if ( body != nullptr ) { | 
|---|
| [50377a4] | 311 | os << "\n" << indent << "... with body: \n" << indent+1; | 
|---|
|  | 312 | body->print( os, indent+1 ); | 
|---|
| [bb8ea30] | 313 | } | 
|---|
| [0dd3a2f] | 314 | os << endl; | 
|---|
| [51b73452] | 315 | } | 
|---|
|  | 316 |  | 
|---|
| [ba3706f] | 317 | ThrowStmt::ThrowStmt( Kind kind, Expression * expr, Expression * target ) : | 
|---|
|  | 318 | Statement(), kind(kind), expr(expr), target(target)     { | 
|---|
| [daf1af8] | 319 | assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." ); | 
|---|
|  | 320 | } | 
|---|
|  | 321 |  | 
|---|
| [0608e007] | 322 | ThrowStmt::ThrowStmt( const ThrowStmt & other ) : | 
|---|
| [daf1af8] | 323 | Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { | 
|---|
|  | 324 | } | 
|---|
|  | 325 |  | 
|---|
|  | 326 | ThrowStmt::~ThrowStmt() { | 
|---|
|  | 327 | delete expr; | 
|---|
|  | 328 | delete target; | 
|---|
|  | 329 | } | 
|---|
|  | 330 |  | 
|---|
| [0608e007] | 331 | void ThrowStmt::print( std::ostream & os, Indenter indent) const { | 
|---|
| [50377a4] | 332 | if ( target ) os << "Non-Local "; | 
|---|
| [daf1af8] | 333 | os << "Throw Statement, raising: "; | 
|---|
| [50377a4] | 334 | expr->print(os, indent+1); | 
|---|
| [daf1af8] | 335 | if ( target ) { | 
|---|
| [50377a4] | 336 | os << "... at: "; | 
|---|
|  | 337 | target->print(os, indent+1); | 
|---|
| [daf1af8] | 338 | } | 
|---|
|  | 339 | } | 
|---|
|  | 340 |  | 
|---|
| [0608e007] | 341 | TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) : | 
|---|
| [ba3706f] | 342 | Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) { | 
|---|
| [0dd3a2f] | 343 | } | 
|---|
| [51b73452] | 344 |  | 
|---|
| [0608e007] | 345 | TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { | 
|---|
| [3be261a] | 346 | cloneAll( other.handlers, handlers ); | 
|---|
| [51b73452] | 347 | } | 
|---|
|  | 348 |  | 
|---|
| [a08ba92] | 349 | TryStmt::~TryStmt() { | 
|---|
| [0dd3a2f] | 350 | delete block; | 
|---|
| [2037f82] | 351 | deleteAll( handlers ); | 
|---|
|  | 352 | delete finallyBlock; | 
|---|
| [51b73452] | 353 | } | 
|---|
|  | 354 |  | 
|---|
| [0608e007] | 355 | void TryStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [89231bc] | 356 | os << "Try Statement" << endl; | 
|---|
| [50377a4] | 357 | os << indent << "... with block:" << endl << indent+1; | 
|---|
|  | 358 | block->print( os, indent+1 ); | 
|---|
| [0dd3a2f] | 359 |  | 
|---|
|  | 360 | // handlers | 
|---|
| [50377a4] | 361 | os << indent << "... and handlers:" << endl; | 
|---|
|  | 362 | for ( const CatchStmt * stmt : handlers ) { | 
|---|
|  | 363 | os << indent+1; | 
|---|
|  | 364 | stmt->print( os, indent+1 ); | 
|---|
| [406a6e6] | 365 | } | 
|---|
| [0dd3a2f] | 366 |  | 
|---|
|  | 367 | // finally block | 
|---|
| [0608e007] | 368 | if ( finallyBlock != nullptr ) { | 
|---|
| [50377a4] | 369 | os << indent << "... and finally:" << endl << indent+1; | 
|---|
|  | 370 | finallyBlock->print( os, indent+1 ); | 
|---|
| [0dd3a2f] | 371 | } // if | 
|---|
| [51b73452] | 372 | } | 
|---|
|  | 373 |  | 
|---|
| [0608e007] | 374 | CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) : | 
|---|
| [ba3706f] | 375 | Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { | 
|---|
| [50377a4] | 376 | assertf( decl, "Catch clause must have a declaration." ); | 
|---|
| [0dd3a2f] | 377 | } | 
|---|
| [51b73452] | 378 |  | 
|---|
| [3be261a] | 379 | CatchStmt::CatchStmt( const CatchStmt & other ) : | 
|---|
| [ca78437] | 380 | Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) { | 
|---|
| [3be261a] | 381 | } | 
|---|
|  | 382 |  | 
|---|
| [a08ba92] | 383 | CatchStmt::~CatchStmt() { | 
|---|
| [0dd3a2f] | 384 | delete decl; | 
|---|
|  | 385 | delete body; | 
|---|
| [51b73452] | 386 | } | 
|---|
|  | 387 |  | 
|---|
| [0608e007] | 388 | void CatchStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [ca78437] | 389 | os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; | 
|---|
| [0dd3a2f] | 390 |  | 
|---|
| [50377a4] | 391 | os << indent << "... catching: "; | 
|---|
|  | 392 | decl->printShort( os, indent+1 ); | 
|---|
|  | 393 | os << endl; | 
|---|
| [406a6e6] | 394 |  | 
|---|
|  | 395 | if ( cond ) { | 
|---|
| [50377a4] | 396 | os << indent << "... with conditional:" << endl << indent+1; | 
|---|
|  | 397 | cond->print( os, indent+1 ); | 
|---|
| [406a6e6] | 398 | } | 
|---|
|  | 399 |  | 
|---|
| [50377a4] | 400 | os << indent << "... with block:" << endl; | 
|---|
|  | 401 | os << indent+1; | 
|---|
|  | 402 | body->print( os, indent+1 ); | 
|---|
| [51b73452] | 403 | } | 
|---|
|  | 404 |  | 
|---|
|  | 405 |  | 
|---|
| [0608e007] | 406 | FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) { | 
|---|
| [51b73452] | 407 | } | 
|---|
|  | 408 |  | 
|---|
| [3be261a] | 409 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { | 
|---|
|  | 410 | } | 
|---|
|  | 411 |  | 
|---|
| [0dd3a2f] | 412 | FinallyStmt::~FinallyStmt() { | 
|---|
|  | 413 | delete block; | 
|---|
| [51b73452] | 414 | } | 
|---|
|  | 415 |  | 
|---|
| [0608e007] | 416 | void FinallyStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [f1b1e4c] | 417 | os << "Finally Statement" << endl; | 
|---|
| [50377a4] | 418 | os << indent << "... with block:" << endl << indent+1; | 
|---|
|  | 419 | block->print( os, indent+1 ); | 
|---|
| [51b73452] | 420 | } | 
|---|
|  | 421 |  | 
|---|
| [37cdd97] | 422 | SuspendStmt::SuspendStmt( const SuspendStmt & other ) | 
|---|
|  | 423 | : Statement( other ) | 
|---|
|  | 424 | , then( maybeClone(other.then) ) | 
|---|
|  | 425 | {} | 
|---|
|  | 426 |  | 
|---|
|  | 427 | SuspendStmt::~SuspendStmt() { | 
|---|
|  | 428 | delete then; | 
|---|
|  | 429 | } | 
|---|
|  | 430 |  | 
|---|
|  | 431 | void SuspendStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
|  | 432 | os << "Suspend Statement"; | 
|---|
|  | 433 | switch (type) { | 
|---|
|  | 434 | case None     : os << " with implicit target"; break; | 
|---|
|  | 435 | case Generator: os << " for generator"       ; break; | 
|---|
|  | 436 | case Coroutine: os << " for coroutine"       ; break; | 
|---|
|  | 437 | } | 
|---|
|  | 438 | os << endl; | 
|---|
|  | 439 | indent += 1; | 
|---|
|  | 440 |  | 
|---|
|  | 441 | if(then) { | 
|---|
|  | 442 | os << indent << " with post statement :" << endl; | 
|---|
|  | 443 | then->print( os, indent + 1); | 
|---|
|  | 444 | } | 
|---|
|  | 445 | } | 
|---|
|  | 446 |  | 
|---|
| [ba3706f] | 447 | WaitForStmt::WaitForStmt() : Statement() { | 
|---|
| [135b431] | 448 | timeout.time      = nullptr; | 
|---|
|  | 449 | timeout.statement = nullptr; | 
|---|
|  | 450 | timeout.condition = nullptr; | 
|---|
|  | 451 | orelse .statement = nullptr; | 
|---|
|  | 452 | orelse .condition = nullptr; | 
|---|
|  | 453 | } | 
|---|
|  | 454 |  | 
|---|
|  | 455 | WaitForStmt::WaitForStmt( const WaitForStmt & other ) : Statement( other ) { | 
|---|
|  | 456 | clauses.reserve( other.clauses.size() ); | 
|---|
|  | 457 | for( auto & ocl : other.clauses ) { | 
|---|
|  | 458 | clauses.emplace_back(); | 
|---|
|  | 459 | clauses.back().target.function = ocl.target.function->clone(); | 
|---|
|  | 460 | cloneAll( ocl.target.arguments, clauses.back().target.arguments ); | 
|---|
|  | 461 | clauses.back().statement = ocl.statement->clone(); | 
|---|
|  | 462 | clauses.back().condition = ocl.condition->clone(); | 
|---|
|  | 463 | } | 
|---|
|  | 464 |  | 
|---|
|  | 465 | timeout.time      = other.timeout.time     ->clone(); | 
|---|
|  | 466 | timeout.statement = other.timeout.statement->clone(); | 
|---|
|  | 467 | timeout.condition = other.timeout.condition->clone(); | 
|---|
|  | 468 | orelse .statement = other.orelse .statement->clone(); | 
|---|
|  | 469 | orelse .condition = other.orelse .condition->clone(); | 
|---|
|  | 470 | } | 
|---|
|  | 471 |  | 
|---|
|  | 472 | WaitForStmt::~WaitForStmt() { | 
|---|
|  | 473 | for( auto & clause : clauses ) { | 
|---|
|  | 474 | delete clause.target.function; | 
|---|
|  | 475 | deleteAll( clause.target.arguments ); | 
|---|
|  | 476 | delete clause.statement; | 
|---|
|  | 477 | delete clause.condition; | 
|---|
|  | 478 | } | 
|---|
|  | 479 |  | 
|---|
|  | 480 | delete timeout.time; | 
|---|
|  | 481 | delete timeout.statement; | 
|---|
|  | 482 | delete timeout.condition; | 
|---|
|  | 483 |  | 
|---|
|  | 484 | delete orelse.statement; | 
|---|
|  | 485 | delete orelse.condition; | 
|---|
|  | 486 | } | 
|---|
|  | 487 |  | 
|---|
| [0608e007] | 488 | void WaitForStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [135b431] | 489 | os << "Waitfor Statement" << endl; | 
|---|
| [b9f383f] | 490 | indent += 1; | 
|---|
|  | 491 | for( auto & clause : clauses ) { | 
|---|
|  | 492 | os << indent << "target function :"; | 
|---|
|  | 493 | if(clause.target.function) { clause.target.function->print(os, indent + 1); } | 
|---|
|  | 494 | os << endl << indent << "with arguments :" << endl; | 
|---|
|  | 495 | for( auto & thing : clause.target.arguments) { | 
|---|
|  | 496 | if(thing) { thing->print(os, indent + 1); } | 
|---|
|  | 497 | } | 
|---|
|  | 498 | os << indent << " with statment :" << endl; | 
|---|
|  | 499 | if(clause.statement) { clause.statement->print(os, indent + 1); } | 
|---|
|  | 500 |  | 
|---|
|  | 501 | os << indent << " with condition :" << endl; | 
|---|
|  | 502 | if(clause.condition) { clause.condition->print(os, indent + 1); } | 
|---|
|  | 503 | } | 
|---|
|  | 504 |  | 
|---|
|  | 505 | os << indent << " timeout of :" << endl; | 
|---|
|  | 506 | if(timeout.time) { timeout.time->print(os, indent + 1); } | 
|---|
|  | 507 |  | 
|---|
|  | 508 | os << indent << " with statment :" << endl; | 
|---|
|  | 509 | if(timeout.statement) { timeout.statement->print(os, indent + 1); } | 
|---|
|  | 510 |  | 
|---|
|  | 511 | os << indent << " with condition :" << endl; | 
|---|
|  | 512 | if(timeout.condition) { timeout.condition->print(os, indent + 1); } | 
|---|
|  | 513 |  | 
|---|
|  | 514 |  | 
|---|
|  | 515 | os << indent << " else :" << endl; | 
|---|
|  | 516 | if(orelse.statement) { orelse.statement->print(os, indent + 1); } | 
|---|
|  | 517 |  | 
|---|
|  | 518 | os << indent << " with condition :" << endl; | 
|---|
|  | 519 | if(orelse.condition) { orelse.condition->print(os, indent + 1); } | 
|---|
| [135b431] | 520 | } | 
|---|
|  | 521 |  | 
|---|
| [61255ad] | 522 |  | 
|---|
| [e67991f] | 523 | WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {} | 
|---|
|  | 524 | WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { | 
|---|
| [61255ad] | 525 | cloneAll( other.exprs, exprs ); | 
|---|
|  | 526 | } | 
|---|
|  | 527 | WithStmt::~WithStmt() { | 
|---|
|  | 528 | deleteAll( exprs ); | 
|---|
|  | 529 | delete stmt; | 
|---|
|  | 530 | } | 
|---|
|  | 531 |  | 
|---|
|  | 532 | void WithStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
|  | 533 | os << "With statement" << endl; | 
|---|
| [44b4114] | 534 | os << indent << "... with expressions: " << endl; | 
|---|
|  | 535 | printAll( exprs, os, indent+1 ); | 
|---|
| [61255ad] | 536 | os << indent << "... with statement:" << endl << indent+1; | 
|---|
|  | 537 | stmt->print( os, indent+1 ); | 
|---|
|  | 538 | } | 
|---|
|  | 539 |  | 
|---|
|  | 540 |  | 
|---|
| [ba3706f] | 541 | NullStmt::NullStmt( const std::list<Label> & labels ) : Statement( labels ) { | 
|---|
|  | 542 | } | 
|---|
| [51b73452] | 543 |  | 
|---|
| [0608e007] | 544 | void NullStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [50377a4] | 545 | os << "Null Statement" << endl; | 
|---|
| [6a276a0] | 546 | Statement::print( os, indent ); | 
|---|
| [51b73452] | 547 | } | 
|---|
|  | 548 |  | 
|---|
| [ba3706f] | 549 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement(), callStmt( callStmt ) { | 
|---|
| [f1b1e4c] | 550 | assert( callStmt ); | 
|---|
|  | 551 | } | 
|---|
|  | 552 |  | 
|---|
| [74d1804] | 553 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { | 
|---|
| [f1b1e4c] | 554 | } | 
|---|
|  | 555 |  | 
|---|
|  | 556 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { | 
|---|
| [74d1804] | 557 | delete callStmt; | 
|---|
| [f1b1e4c] | 558 | } | 
|---|
|  | 559 |  | 
|---|
| [0608e007] | 560 | void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const { | 
|---|
| [f1b1e4c] | 561 | os << "Implicit Ctor Dtor Statement" << endl; | 
|---|
| [50377a4] | 562 | os << indent << "... with Ctor/Dtor: "; | 
|---|
|  | 563 | callStmt->print( os, indent+1); | 
|---|
| [f1b1e4c] | 564 | os << endl; | 
|---|
|  | 565 | } | 
|---|
|  | 566 |  | 
|---|
| [0dd3a2f] | 567 | // Local Variables: // | 
|---|
|  | 568 | // tab-width: 4 // | 
|---|
|  | 569 | // mode: c++ // | 
|---|
|  | 570 | // compile-command: "make install" // | 
|---|
|  | 571 | // End: // | 
|---|