| [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 | 
|---|
| [6d49ea3] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [e612146c] | 12 | // Last Modified On : Sun Sep  3 20:46:44 2017 | 
|---|
|  | 13 | // Update Count     : 68 | 
|---|
| [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 |  | 
|---|
| [6d49ea3] | 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 |  | 
|---|
| [6d49ea3] | 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 |  | 
|---|
| [e612146c] | 54 | AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, Expression *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 ) {} | 
|---|
| [7f5566b] | 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 |  | 
|---|
| [6d49ea3] | 90 | BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) : | 
|---|
| [b0dfbc4] | 91 | Statement( labels ), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) { | 
|---|
| [0dd3a2f] | 92 | //actually this is a syntactic error signaled by the parser | 
|---|
| [b0dfbc4] | 93 | if ( type == BranchStmt::Goto && target.empty() ) { | 
|---|
| [0dd3a2f] | 94 | throw SemanticError("goto without target"); | 
|---|
| [b0dfbc4] | 95 | } | 
|---|
| [51b73452] | 96 | } | 
|---|
|  | 97 |  | 
|---|
| [6d49ea3] | 98 | BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) : | 
|---|
|  | 99 | Statement( labels ), computedTarget( computedTarget ), type( type ) { | 
|---|
| [b0dfbc4] | 100 | if ( type != BranchStmt::Goto || computedTarget == nullptr ) { | 
|---|
| [0dd3a2f] | 101 | throw SemanticError("Computed target not valid in branch statement"); | 
|---|
| [b0dfbc4] | 102 | } | 
|---|
| [51b73452] | 103 | } | 
|---|
|  | 104 |  | 
|---|
| [de62360d] | 105 | void BranchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 106 | os << string( indent, ' ' ) << "Branch (" << brType[type] << ")" << endl ; | 
|---|
| [b0dfbc4] | 107 | if ( target != "" ) os << string( indent+2, ' ' ) << "with target: " << target << endl; | 
|---|
|  | 108 | if ( originalTarget != "" ) os << string( indent+2, ' ' ) << "with original target: " << originalTarget << endl; | 
|---|
|  | 109 | if ( computedTarget != nullptr ) os << string( indent+2, ' ' ) << "with computed target: " << computedTarget << endl; | 
|---|
| [51b73452] | 110 | } | 
|---|
|  | 111 |  | 
|---|
| [6d49ea3] | 112 | ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {} | 
|---|
| [51b73452] | 113 |  | 
|---|
| [daf1af8] | 114 | ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} | 
|---|
| [3be261a] | 115 |  | 
|---|
| [51b73452] | 116 | ReturnStmt::~ReturnStmt() { | 
|---|
| [0dd3a2f] | 117 | delete expr; | 
|---|
| [51b73452] | 118 | } | 
|---|
|  | 119 |  | 
|---|
| [de62360d] | 120 | void ReturnStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [daf1af8] | 121 | os <<  "Return Statement, returning: "; | 
|---|
| [89231bc] | 122 | if ( expr != 0 ) { | 
|---|
|  | 123 | os << endl << string( indent+2, ' ' ); | 
|---|
|  | 124 | expr->print( os, indent + 2 ); | 
|---|
|  | 125 | } | 
|---|
| [0dd3a2f] | 126 | os << endl; | 
|---|
| [51b73452] | 127 | } | 
|---|
|  | 128 |  | 
|---|
| [6d49ea3] | 129 | IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ): | 
|---|
|  | 130 | Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {} | 
|---|
| [51b73452] | 131 |  | 
|---|
| [3be261a] | 132 | IfStmt::IfStmt( const IfStmt & other ) : | 
|---|
| [6d49ea3] | 133 | Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { | 
|---|
|  | 134 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 135 | } | 
|---|
| [3be261a] | 136 |  | 
|---|
| [ac71a86] | 137 | IfStmt::~IfStmt() { | 
|---|
| [6d49ea3] | 138 | deleteAll( initialization ); | 
|---|
| [ac71a86] | 139 | delete condition; | 
|---|
|  | 140 | delete thenPart; | 
|---|
|  | 141 | delete elsePart; | 
|---|
|  | 142 | } | 
|---|
| [51b73452] | 143 |  | 
|---|
| [de62360d] | 144 | void IfStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 145 | os << "If on condition: " << endl ; | 
|---|
| [60089f4] | 146 | os << string( indent+4, ' ' ); | 
|---|
| [0dd3a2f] | 147 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 148 |  | 
|---|
| [6d49ea3] | 149 | if ( !initialization.empty() ) { | 
|---|
|  | 150 | os << string( indent + 2, ' ' ) << "initialization: \n"; | 
|---|
|  | 151 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { | 
|---|
|  | 152 | os << string( indent + 4, ' ' ); | 
|---|
|  | 153 | (*it)->print( os, indent + 4 ); | 
|---|
|  | 154 | } | 
|---|
|  | 155 | os << endl; | 
|---|
|  | 156 | } | 
|---|
|  | 157 |  | 
|---|
| [60089f4] | 158 | os << string( indent+2, ' ' ) << "... then: " << endl; | 
|---|
| [51b73452] | 159 |  | 
|---|
| [60089f4] | 160 | os << string( indent+4, ' ' ); | 
|---|
| [0dd3a2f] | 161 | thenPart->print( os, indent + 4 ); | 
|---|
| [51b73452] | 162 |  | 
|---|
| [0dd3a2f] | 163 | if ( elsePart != 0 ) { | 
|---|
| [60089f4] | 164 | os << string( indent+2, ' ' ) << "... else: " << endl; | 
|---|
|  | 165 | os << string( indent+4, ' ' ); | 
|---|
| [0dd3a2f] | 166 | elsePart->print( os, indent + 4 ); | 
|---|
|  | 167 | } // if | 
|---|
| [51b73452] | 168 | } | 
|---|
|  | 169 |  | 
|---|
| [1dcd9554] | 170 | SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, const std::list<Statement *> &statements ): | 
|---|
| [6d49ea3] | 171 | Statement( labels ), condition( condition ), statements( statements ) { | 
|---|
| [0dd3a2f] | 172 | } | 
|---|
| [51b73452] | 173 |  | 
|---|
| [3be261a] | 174 | SwitchStmt::SwitchStmt( const SwitchStmt & other ): | 
|---|
|  | 175 | Statement( other ), condition( maybeClone( other.condition ) ) { | 
|---|
| [8688ce1] | 176 | cloneAll( other.statements, statements ); | 
|---|
| [3be261a] | 177 | } | 
|---|
|  | 178 |  | 
|---|
| [51b73452] | 179 | SwitchStmt::~SwitchStmt() { | 
|---|
| [0dd3a2f] | 180 | delete condition; | 
|---|
| [8688ce1] | 181 | // destroy statements | 
|---|
| [2037f82] | 182 | deleteAll( statements ); | 
|---|
| [51b73452] | 183 | } | 
|---|
|  | 184 |  | 
|---|
| [de62360d] | 185 | void SwitchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 186 | os << "Switch on condition: "; | 
|---|
| [0dd3a2f] | 187 | condition->print( os ); | 
|---|
|  | 188 | os << endl; | 
|---|
| [51b73452] | 189 |  | 
|---|
| [8688ce1] | 190 | // statements | 
|---|
| [de62360d] | 191 | std::list<Statement *>::const_iterator i; | 
|---|
| [8688ce1] | 192 | for ( i = statements.begin(); i != statements.end(); i++) | 
|---|
| [de62360d] | 193 | (*i)->print( os, indent + 4 ); | 
|---|
| [51b73452] | 194 |  | 
|---|
| [8688ce1] | 195 | //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os )); | 
|---|
| [51b73452] | 196 | } | 
|---|
|  | 197 |  | 
|---|
| [1dcd9554] | 198 | CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) : | 
|---|
| [6d49ea3] | 199 | Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) { | 
|---|
| [0dd3a2f] | 200 | if ( isDefault() && condition != 0 ) | 
|---|
|  | 201 | throw SemanticError("default with conditions"); | 
|---|
| [51b73452] | 202 | } | 
|---|
|  | 203 |  | 
|---|
| [3be261a] | 204 | CaseStmt::CaseStmt( const CaseStmt & other ) : | 
|---|
|  | 205 | Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { | 
|---|
|  | 206 | cloneAll( other.stmts, stmts ); | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
| [51b73452] | 209 | CaseStmt::~CaseStmt() { | 
|---|
| [0dd3a2f] | 210 | delete condition; | 
|---|
| [2037f82] | 211 | deleteAll( stmts ); | 
|---|
| [51b73452] | 212 | } | 
|---|
|  | 213 |  | 
|---|
| [8688ce1] | 214 | CaseStmt * CaseStmt::makeDefault( std::list<Label> labels, std::list<Statement *> stmts ) { | 
|---|
|  | 215 | return new CaseStmt( labels, 0, stmts, true ); | 
|---|
| [b2152e7a] | 216 | } | 
|---|
|  | 217 |  | 
|---|
| [de62360d] | 218 | void CaseStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [44b5ca0] | 219 | os << string( indent, ' ' ); | 
|---|
| [51b73452] | 220 |  | 
|---|
| [de62360d] | 221 | if ( isDefault() ) | 
|---|
| [0dd3a2f] | 222 | os << "Default "; | 
|---|
|  | 223 | else { | 
|---|
|  | 224 | os << "Case "; | 
|---|
|  | 225 | condition->print( os ); | 
|---|
|  | 226 | } // if | 
|---|
| [51b73452] | 227 |  | 
|---|
| [0dd3a2f] | 228 | os << endl; | 
|---|
| [51b73452] | 229 |  | 
|---|
| [de62360d] | 230 | std::list<Statement *>::const_iterator i; | 
|---|
| [0dd3a2f] | 231 | for ( i = stmts.begin(); i != stmts.end(); i++) | 
|---|
|  | 232 | (*i )->print( os, indent + 4 ); | 
|---|
| [51b73452] | 233 | } | 
|---|
|  | 234 |  | 
|---|
| [6d49ea3] | 235 | WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ): | 
|---|
|  | 236 | Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) { | 
|---|
| [0dd3a2f] | 237 | } | 
|---|
| [51b73452] | 238 |  | 
|---|
| [3be261a] | 239 | WhileStmt::WhileStmt( const WhileStmt & other ): | 
|---|
|  | 240 | Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) { | 
|---|
|  | 241 | } | 
|---|
|  | 242 |  | 
|---|
| [a08ba92] | 243 | WhileStmt::~WhileStmt() { | 
|---|
| [0dd3a2f] | 244 | delete body; | 
|---|
| [2037f82] | 245 | delete condition; | 
|---|
| [51b73452] | 246 | } | 
|---|
|  | 247 |  | 
|---|
| [de62360d] | 248 | void WhileStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 249 | os << "While on condition: " << endl ; | 
|---|
| [0dd3a2f] | 250 | condition->print( os, indent + 4 ); | 
|---|
| [51b73452] | 251 |  | 
|---|
| [44b5ca0] | 252 | os << string( indent, ' ' ) << ".... with body: " << endl; | 
|---|
| [51b73452] | 253 |  | 
|---|
| [0dd3a2f] | 254 | if ( body != 0 ) body->print( os, indent + 4 ); | 
|---|
| [51b73452] | 255 | } | 
|---|
|  | 256 |  | 
|---|
| [6d49ea3] | 257 | ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ): | 
|---|
|  | 258 | Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) { | 
|---|
| [0dd3a2f] | 259 | } | 
|---|
| [51b73452] | 260 |  | 
|---|
| [3be261a] | 261 | ForStmt::ForStmt( const ForStmt & other ): | 
|---|
|  | 262 | Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) { | 
|---|
|  | 263 | cloneAll( other.initialization, initialization ); | 
|---|
|  | 264 |  | 
|---|
|  | 265 | } | 
|---|
|  | 266 |  | 
|---|
| [51b73452] | 267 | ForStmt::~ForStmt() { | 
|---|
| [145f1fc] | 268 | deleteAll( initialization ); | 
|---|
| [0dd3a2f] | 269 | delete condition; | 
|---|
|  | 270 | delete increment; | 
|---|
|  | 271 | delete body; | 
|---|
| [51b73452] | 272 | } | 
|---|
|  | 273 |  | 
|---|
| [de62360d] | 274 | void ForStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 275 | os << "Labels: {"; | 
|---|
| [de62360d] | 276 | for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { | 
|---|
| [be5aa1b] | 277 | os << *it << ","; | 
|---|
|  | 278 | } | 
|---|
|  | 279 | os << "}" << endl; | 
|---|
|  | 280 |  | 
|---|
| [44b5ca0] | 281 | os << string( indent, ' ' ) << "For Statement" << endl ; | 
|---|
| [51b73452] | 282 |  | 
|---|
| [3be261a] | 283 | os << string( indent + 2, ' ' ) << "initialization: \n"; | 
|---|
| [145f1fc] | 284 | for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { | 
|---|
| [bb8ea30] | 285 | os << string( indent + 4, ' ' ); | 
|---|
| [145f1fc] | 286 | (*it)->print( os, indent + 4 ); | 
|---|
|  | 287 | } | 
|---|
| [51b73452] | 288 |  | 
|---|
| [3be261a] | 289 | os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; | 
|---|
| [bb8ea30] | 290 | if ( condition != 0 ) { | 
|---|
|  | 291 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 292 | condition->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 293 | } | 
|---|
| [51b73452] | 294 |  | 
|---|
| [3be261a] | 295 | os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; | 
|---|
| [bb8ea30] | 296 | if ( increment != 0 ) { | 
|---|
|  | 297 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 298 | increment->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 299 | } | 
|---|
| [51b73452] | 300 |  | 
|---|
| [3be261a] | 301 | os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; | 
|---|
| [bb8ea30] | 302 | if ( body != 0 ) { | 
|---|
|  | 303 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 304 | body->print( os, indent + 4 ); | 
|---|
| [bb8ea30] | 305 | } | 
|---|
| [51b73452] | 306 |  | 
|---|
| [0dd3a2f] | 307 | os << endl; | 
|---|
| [51b73452] | 308 | } | 
|---|
|  | 309 |  | 
|---|
| [daf1af8] | 310 | ThrowStmt::ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target ) : | 
|---|
|  | 311 | Statement( labels ), kind(kind), expr(expr), target(target)     { | 
|---|
|  | 312 | assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." ); | 
|---|
|  | 313 | } | 
|---|
|  | 314 |  | 
|---|
|  | 315 | ThrowStmt::ThrowStmt( const ThrowStmt &other ) : | 
|---|
|  | 316 | Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { | 
|---|
|  | 317 | } | 
|---|
|  | 318 |  | 
|---|
|  | 319 | ThrowStmt::~ThrowStmt() { | 
|---|
|  | 320 | delete expr; | 
|---|
|  | 321 | delete target; | 
|---|
|  | 322 | } | 
|---|
|  | 323 |  | 
|---|
|  | 324 | void ThrowStmt::print( std::ostream &os, int indent) const { | 
|---|
|  | 325 | if ( target ) { | 
|---|
|  | 326 | os << "Non-Local "; | 
|---|
|  | 327 | } | 
|---|
|  | 328 | os << "Throw Statement, raising: "; | 
|---|
|  | 329 | expr->print(os, indent + 4); | 
|---|
|  | 330 | if ( target ) { | 
|---|
|  | 331 | os << "At: "; | 
|---|
|  | 332 | target->print(os, indent + 4); | 
|---|
|  | 333 | } | 
|---|
|  | 334 | } | 
|---|
|  | 335 |  | 
|---|
| [6d49ea3] | 336 | TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) : | 
|---|
|  | 337 | Statement( labels ), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) { | 
|---|
| [0dd3a2f] | 338 | } | 
|---|
| [51b73452] | 339 |  | 
|---|
| [3be261a] | 340 | TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { | 
|---|
|  | 341 | cloneAll( other.handlers, handlers ); | 
|---|
| [51b73452] | 342 | } | 
|---|
|  | 343 |  | 
|---|
| [a08ba92] | 344 | TryStmt::~TryStmt() { | 
|---|
| [0dd3a2f] | 345 | delete block; | 
|---|
| [2037f82] | 346 | deleteAll( handlers ); | 
|---|
|  | 347 | delete finallyBlock; | 
|---|
| [51b73452] | 348 | } | 
|---|
|  | 349 |  | 
|---|
| [de62360d] | 350 | void TryStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [89231bc] | 351 | os << "Try Statement" << endl; | 
|---|
| [406a6e6] | 352 | os << string( indent + 2, ' ' ) << "with block:" << endl; | 
|---|
|  | 353 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 354 | block->print( os, indent + 4 ); | 
|---|
|  | 355 |  | 
|---|
|  | 356 | // handlers | 
|---|
| [406a6e6] | 357 | os << string( indent + 2, ' ' ) << "and handlers:" << endl; | 
|---|
|  | 358 | for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) { | 
|---|
|  | 359 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 360 | (*i )->print( os, indent + 4 ); | 
|---|
| [406a6e6] | 361 | } | 
|---|
| [0dd3a2f] | 362 |  | 
|---|
|  | 363 | // finally block | 
|---|
|  | 364 | if ( finallyBlock != 0 ) { | 
|---|
| [406a6e6] | 365 | os << string( indent + 2, ' ' ) << "and finally:" << endl; | 
|---|
| [0dd3a2f] | 366 | finallyBlock->print( os, indent + 4 ); | 
|---|
|  | 367 | } // if | 
|---|
| [51b73452] | 368 | } | 
|---|
|  | 369 |  | 
|---|
| [6d49ea3] | 370 | CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) : | 
|---|
|  | 371 | Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { | 
|---|
| [0dd3a2f] | 372 | } | 
|---|
| [51b73452] | 373 |  | 
|---|
| [3be261a] | 374 | CatchStmt::CatchStmt( const CatchStmt & other ) : | 
|---|
| [ca78437] | 375 | Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) { | 
|---|
| [3be261a] | 376 | } | 
|---|
|  | 377 |  | 
|---|
| [a08ba92] | 378 | CatchStmt::~CatchStmt() { | 
|---|
| [0dd3a2f] | 379 | delete decl; | 
|---|
|  | 380 | delete body; | 
|---|
| [51b73452] | 381 | } | 
|---|
|  | 382 |  | 
|---|
| [de62360d] | 383 | void CatchStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [ca78437] | 384 | os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; | 
|---|
| [0dd3a2f] | 385 |  | 
|---|
| [406a6e6] | 386 | os << string( indent + 2, ' ' ) << "... catching: "; | 
|---|
| [0dd3a2f] | 387 | if ( decl ) { | 
|---|
|  | 388 | decl->printShort( os, indent + 4 ); | 
|---|
|  | 389 | os << endl; | 
|---|
| [ca78437] | 390 | } | 
|---|
| [0dd3a2f] | 391 | else | 
|---|
| [44b5ca0] | 392 | os << string( indent + 4 , ' ' ) << ">>> Error:  this catch clause must have a declaration <<<" << endl; | 
|---|
| [406a6e6] | 393 |  | 
|---|
|  | 394 | if ( cond ) { | 
|---|
|  | 395 | os << string( indent + 2, ' ' ) << "with conditional:" << endl; | 
|---|
|  | 396 | os << string( indent + 4, ' ' ); | 
|---|
|  | 397 | cond->print( os, indent + 4 ); | 
|---|
|  | 398 | } | 
|---|
|  | 399 | else | 
|---|
|  | 400 | os << string( indent + 2, ' ' ) << "with no conditional" << endl; | 
|---|
|  | 401 |  | 
|---|
|  | 402 | os << string( indent + 2, ' ' ) << "with block:" << endl; | 
|---|
|  | 403 | os << string( indent + 4, ' ' ); | 
|---|
|  | 404 | body->print( os, indent + 4 ); | 
|---|
| [51b73452] | 405 | } | 
|---|
|  | 406 |  | 
|---|
|  | 407 |  | 
|---|
| [6d49ea3] | 408 | FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) { | 
|---|
| [0dd3a2f] | 409 | assert( labels.empty() ); // finally statement cannot be labeled | 
|---|
| [51b73452] | 410 | } | 
|---|
|  | 411 |  | 
|---|
| [3be261a] | 412 | FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { | 
|---|
|  | 413 | } | 
|---|
|  | 414 |  | 
|---|
| [0dd3a2f] | 415 | FinallyStmt::~FinallyStmt() { | 
|---|
|  | 416 | delete block; | 
|---|
| [51b73452] | 417 | } | 
|---|
|  | 418 |  | 
|---|
| [de62360d] | 419 | void FinallyStmt::print( std::ostream &os, int indent ) const { | 
|---|
| [f1b1e4c] | 420 | os << "Finally Statement" << endl; | 
|---|
| [406a6e6] | 421 | os << string( indent + 2, ' ' ) << "with block:" << endl; | 
|---|
|  | 422 | os << string( indent + 4, ' ' ); | 
|---|
| [0dd3a2f] | 423 | block->print( os, indent + 4 ); | 
|---|
| [51b73452] | 424 | } | 
|---|
|  | 425 |  | 
|---|
| [135b431] | 426 | WaitForStmt::WaitForStmt( std::list<Label> labels ) : Statement( labels ) { | 
|---|
|  | 427 | timeout.time      = nullptr; | 
|---|
|  | 428 | timeout.statement = nullptr; | 
|---|
|  | 429 | timeout.condition = nullptr; | 
|---|
|  | 430 | orelse .statement = nullptr; | 
|---|
|  | 431 | orelse .condition = nullptr; | 
|---|
|  | 432 | } | 
|---|
|  | 433 |  | 
|---|
|  | 434 | WaitForStmt::WaitForStmt( const WaitForStmt & other ) : Statement( other ) { | 
|---|
|  | 435 | clauses.reserve( other.clauses.size() ); | 
|---|
|  | 436 | for( auto & ocl : other.clauses ) { | 
|---|
|  | 437 | clauses.emplace_back(); | 
|---|
|  | 438 | clauses.back().target.function = ocl.target.function->clone(); | 
|---|
|  | 439 | cloneAll( ocl.target.arguments, clauses.back().target.arguments ); | 
|---|
|  | 440 | clauses.back().statement = ocl.statement->clone(); | 
|---|
|  | 441 | clauses.back().condition = ocl.condition->clone(); | 
|---|
|  | 442 | } | 
|---|
|  | 443 |  | 
|---|
|  | 444 | timeout.time      = other.timeout.time     ->clone(); | 
|---|
|  | 445 | timeout.statement = other.timeout.statement->clone(); | 
|---|
|  | 446 | timeout.condition = other.timeout.condition->clone(); | 
|---|
|  | 447 | orelse .statement = other.orelse .statement->clone(); | 
|---|
|  | 448 | orelse .condition = other.orelse .condition->clone(); | 
|---|
|  | 449 | } | 
|---|
|  | 450 |  | 
|---|
|  | 451 | WaitForStmt::~WaitForStmt() { | 
|---|
|  | 452 | for( auto & clause : clauses ) { | 
|---|
|  | 453 | delete clause.target.function; | 
|---|
|  | 454 | deleteAll( clause.target.arguments ); | 
|---|
|  | 455 | delete clause.statement; | 
|---|
|  | 456 | delete clause.condition; | 
|---|
|  | 457 | } | 
|---|
|  | 458 |  | 
|---|
|  | 459 | delete timeout.time; | 
|---|
|  | 460 | delete timeout.statement; | 
|---|
|  | 461 | delete timeout.condition; | 
|---|
|  | 462 |  | 
|---|
|  | 463 | delete orelse.statement; | 
|---|
|  | 464 | delete orelse.condition; | 
|---|
|  | 465 | } | 
|---|
|  | 466 |  | 
|---|
|  | 467 | void WaitForStmt::print( std::ostream &os, int indent ) const { | 
|---|
|  | 468 | os << "Waitfor Statement" << endl; | 
|---|
|  | 469 | os << string( indent + 2, ' ' ) << "with block:" << endl; | 
|---|
|  | 470 | os << string( indent + 4, ' ' ); | 
|---|
|  | 471 | // block->print( os, indent + 4 ); | 
|---|
|  | 472 | } | 
|---|
|  | 473 |  | 
|---|
| [70d826cd] | 474 | NullStmt::NullStmt( std::list<Label> labels ) : Statement( labels ) {} | 
|---|
|  | 475 | NullStmt::NullStmt() : Statement( std::list<Label>() ) {} | 
|---|
| [51b73452] | 476 |  | 
|---|
| [b3c36f4] | 477 | void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent ) const { | 
|---|
| [89231bc] | 478 | os << "Null Statement" << endl ; | 
|---|
| [51b73452] | 479 | } | 
|---|
|  | 480 |  | 
|---|
| [f1b1e4c] | 481 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { | 
|---|
|  | 482 | assert( callStmt ); | 
|---|
|  | 483 | } | 
|---|
|  | 484 |  | 
|---|
| [74d1804] | 485 | ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( maybeClone( other.callStmt ) ) { | 
|---|
| [f1b1e4c] | 486 | } | 
|---|
|  | 487 |  | 
|---|
|  | 488 | ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { | 
|---|
| [74d1804] | 489 | delete callStmt; | 
|---|
| [f1b1e4c] | 490 | } | 
|---|
|  | 491 |  | 
|---|
|  | 492 | void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const { | 
|---|
|  | 493 | os << "Implicit Ctor Dtor Statement" << endl; | 
|---|
|  | 494 | os << string( indent + 2, ' ' ) << "with Ctor/Dtor: "; | 
|---|
|  | 495 | callStmt->print( os, indent + 2); | 
|---|
|  | 496 | os << endl; | 
|---|
|  | 497 | } | 
|---|
|  | 498 |  | 
|---|
| [0dd3a2f] | 499 | // Local Variables: // | 
|---|
|  | 500 | // tab-width: 4 // | 
|---|
|  | 501 | // mode: c++ // | 
|---|
|  | 502 | // compile-command: "make install" // | 
|---|
|  | 503 | // End: // | 
|---|