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