Changes in src/SynTree/Statement.cc [37cdd97:e67991f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Statement.cc
r37cdd97 re67991f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jan 20 16:03:00 202013 // Update Count : 7111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 20:46:44 2017 13 // Update Count : 68 14 14 // 15 15 … … 46 46 Statement::~Statement() {} 47 47 48 ExprStmt::ExprStmt( Expression * 49 50 ExprStmt::ExprStmt( const ExprStmt & 48 ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {} 49 50 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 51 51 52 52 ExprStmt::~ExprStmt() { … … 54 54 } 55 55 56 void ExprStmt::print( std::ostream & 56 void ExprStmt::print( std::ostream &os, Indenter indent ) const { 57 57 os << "Expression Statement:" << endl << indent+1; 58 58 expr->print( os, indent+1 ); … … 60 60 61 61 62 AsmStmt::AsmStmt( bool voltile, Expression * 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 ) {} 63 63 64 64 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { … … 75 75 } 76 76 77 void AsmStmt::print( std::ostream & 77 void AsmStmt::print( std::ostream &os, Indenter indent ) const { 78 78 os << "Assembler Statement:" << endl; 79 79 os << indent+1 << "instruction: " << endl << indent; … … 96 96 DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {} 97 97 98 void DirectiveStmt::print( std::ostream & 98 void DirectiveStmt::print( std::ostream &os, Indenter ) const { 99 99 os << "GCC Directive:" << directive << endl; 100 100 } 101 101 102 102 103 const char * BranchStmt::brType[] = { 104 "Goto", "Break", "Continue", "Fall Through", "Fall Through Default", 105 }; 103 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 106 104 107 105 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) : … … 113 111 } 114 112 115 BranchStmt::BranchStmt( Expression * 113 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) : 116 114 Statement(), computedTarget( computedTarget ), type( type ) { 117 115 if ( type != BranchStmt::Goto || computedTarget == nullptr ) { … … 120 118 } 121 119 122 void BranchStmt::print( std::ostream & os, Indenter indent ) const { 123 assert(type < 5); 120 void BranchStmt::print( std::ostream &os, Indenter indent ) const { 124 121 os << "Branch (" << brType[type] << ")" << endl ; 125 122 if ( target != "" ) os << indent+1 << "with target: " << target << endl; … … 128 125 } 129 126 130 ReturnStmt::ReturnStmt( Expression * 127 ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {} 131 128 132 129 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 136 133 } 137 134 138 void ReturnStmt::print( std::ostream & 135 void ReturnStmt::print( std::ostream &os, Indenter indent ) const { 139 136 os << "Return Statement, returning: "; 140 137 if ( expr != nullptr ) { … … 145 142 } 146 143 147 IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement *elsePart, std::list<Statement *> initialization ):144 IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ): 148 145 Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {} 149 146 … … 160 157 } 161 158 162 void IfStmt::print( std::ostream & 159 void IfStmt::print( std::ostream &os, Indenter indent ) const { 163 160 os << "If on condition: " << endl; 164 161 os << indent+1; … … 179 176 thenPart->print( os, indent+1 ); 180 177 181 if ( elsePart != nullptr) {178 if ( elsePart != 0 ) { 182 179 os << indent << "... else: " << endl; 183 180 os << indent+1; … … 186 183 } 187 184 188 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & 185 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ): 189 186 Statement(), condition( condition ), statements( statements ) { 190 187 } … … 201 198 } 202 199 203 void SwitchStmt::print( std::ostream & 200 void SwitchStmt::print( std::ostream &os, Indenter indent ) const { 204 201 os << "Switch on condition: "; 205 202 condition->print( os ); … … 211 208 } 212 209 213 CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :210 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) : 214 211 Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) { 215 if ( isDefault() && condition != nullptr) SemanticError( condition, "default case with condition: " );212 if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " ); 216 213 } 217 214 … … 232 229 } 233 230 234 void CaseStmt::print( std::ostream & 231 void CaseStmt::print( std::ostream &os, Indenter indent ) const { 235 232 if ( isDefault() ) os << indent << "Default "; 236 233 else { … … 246 243 } 247 244 248 WhileStmt::WhileStmt( Expression * condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):245 WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ): 249 246 Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) { 250 247 } … … 259 256 } 260 257 261 void WhileStmt::print( std::ostream & 258 void WhileStmt::print( std::ostream &os, Indenter indent ) const { 262 259 os << "While on condition: " << endl ; 263 260 condition->print( os, indent+1 ); … … 265 262 os << indent << "... with body: " << endl; 266 263 267 if ( body != nullptr) body->print( os, indent+1 );268 } 269 270 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement *body ):264 if ( body != 0 ) body->print( os, indent+1 ); 265 } 266 267 ForStmt::ForStmt( std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ): 271 268 Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) { 272 269 } … … 285 282 } 286 283 287 void ForStmt::print( std::ostream & 284 void ForStmt::print( std::ostream &os, Indenter indent ) const { 288 285 Statement::print( os, indent ); // print labels 289 286 … … 308 305 } 309 306 310 if ( body != nullptr) {307 if ( body != 0 ) { 311 308 os << "\n" << indent << "... with body: \n" << indent+1; 312 309 body->print( os, indent+1 ); … … 320 317 } 321 318 322 ThrowStmt::ThrowStmt( const ThrowStmt & 319 ThrowStmt::ThrowStmt( const ThrowStmt &other ) : 323 320 Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { 324 321 } … … 329 326 } 330 327 331 void ThrowStmt::print( std::ostream & 328 void ThrowStmt::print( std::ostream &os, Indenter indent) const { 332 329 if ( target ) os << "Non-Local "; 333 330 os << "Throw Statement, raising: "; … … 339 336 } 340 337 341 TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt *finallyBlock ) :338 TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) : 342 339 Statement(), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) { 343 340 } 344 341 345 TryStmt::TryStmt( const TryStmt & 342 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { 346 343 cloneAll( other.handlers, handlers ); 347 344 } … … 353 350 } 354 351 355 void TryStmt::print( std::ostream & 352 void TryStmt::print( std::ostream &os, Indenter indent ) const { 356 353 os << "Try Statement" << endl; 357 354 os << indent << "... with block:" << endl << indent+1; … … 366 363 367 364 // finally block 368 if ( finallyBlock != nullptr) {365 if ( finallyBlock != 0 ) { 369 366 os << indent << "... and finally:" << endl << indent+1; 370 367 finallyBlock->print( os, indent+1 ); … … 372 369 } 373 370 374 CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement *body ) :371 CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) : 375 372 Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { 376 373 assertf( decl, "Catch clause must have a declaration." ); … … 386 383 } 387 384 388 void CatchStmt::print( std::ostream & 385 void CatchStmt::print( std::ostream &os, Indenter indent ) const { 389 386 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; 390 387 … … 404 401 405 402 406 FinallyStmt::FinallyStmt( CompoundStmt * 403 FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) { 407 404 } 408 405 … … 414 411 } 415 412 416 void FinallyStmt::print( std::ostream & 413 void FinallyStmt::print( std::ostream &os, Indenter indent ) const { 417 414 os << "Finally Statement" << endl; 418 415 os << indent << "... with block:" << endl << indent+1; 419 416 block->print( os, indent+1 ); 420 }421 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 417 } 446 418 … … 486 458 } 487 459 488 void WaitForStmt::print( std::ostream & 460 void WaitForStmt::print( std::ostream &os, Indenter indent ) const { 489 461 os << "Waitfor Statement" << endl; 490 462 indent += 1; … … 542 514 } 543 515 544 void NullStmt::print( std::ostream & 516 void NullStmt::print( std::ostream &os, Indenter indent ) const { 545 517 os << "Null Statement" << endl; 546 518 Statement::print( os, indent ); … … 558 530 } 559 531 560 void ImplicitCtorDtorStmt::print( std::ostream & 532 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const { 561 533 os << "Implicit Ctor Dtor Statement" << endl; 562 534 os << indent << "... with Ctor/Dtor: ";
Note:
See TracChangeset
for help on using the changeset viewer.