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