Changeset 6180274 for src/SynTree/Statement.cc
- Timestamp:
- Feb 2, 2022, 9:25:37 PM (23 months ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 9dc0836
- Parents:
- 4e7171f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Statement.cc
r4e7171f r6180274 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 11:55:19202213 // Update Count : 8012 // Last Modified On : Wed Feb 2 20:19:33 2022 13 // Update Count : 90 14 14 // 15 15 … … 29 29 #include "SynTree/Label.h" // for Label, operator<< 30 30 31 using std::string;32 using std::endl; 33 34 Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}35 36 void Statement::print( std::ostream & os, Indenter indent ) const {31 using namespace std; 32 33 34 Statement::Statement( const list<Label> & labels ) : labels( labels ) {} 35 36 void Statement::print( ostream & os, Indenter indent ) const { 37 37 if ( ! labels.empty() ) { 38 38 os << indent << "... Labels: {"; … … 54 54 } 55 55 56 void ExprStmt::print( std::ostream & os, Indenter indent ) const {57 os << "Expression Statement:" << endl << indent +1;58 expr->print( os, indent +1 );59 } 60 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 ) {}56 void ExprStmt::print( ostream & os, Indenter indent ) const { 57 os << "Expression Statement:" << endl << indent + 1; 58 expr->print( os, indent + 1 ); 59 } 60 61 62 AsmStmt::AsmStmt( bool voltile, Expression * instruction, const list<Expression *> output, const list<Expression *> input, const list<ConstantExpr *> clobber, const 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( ostream & os, Indenter indent ) const { 78 78 os << "Assembler Statement:" << endl; 79 os << indent +1 << "instruction: " << endl << indent;80 instruction->print( os, indent +1 );79 os << indent + 1 << "instruction: " << endl << indent; 80 instruction->print( os, indent + 1 ); 81 81 if ( ! output.empty() ) { 82 os << endl << indent +1 << "output: " << endl;83 printAll( output, os, indent +1 );82 os << endl << indent + 1 << "output: " << endl; 83 printAll( output, os, indent + 1 ); 84 84 } // if 85 85 if ( ! input.empty() ) { 86 os << indent +1 << "input: " << endl;87 printAll( input, os, indent +1 );86 os << indent + 1 << "input: " << endl; 87 printAll( input, os, indent + 1 ); 88 88 } // if 89 89 if ( ! clobber.empty() ) { 90 os << indent +1 << "clobber: " << endl;91 printAll( clobber, os, indent +1 );90 os << indent + 1 << "clobber: " << endl; 91 printAll( clobber, os, indent + 1 ); 92 92 } // if 93 93 } 94 94 95 95 96 DirectiveStmt::DirectiveStmt( const st d::string & directive ) : Statement(), directive( directive ) {}97 98 void DirectiveStmt::print( std::ostream & os, Indenter ) const {96 DirectiveStmt::DirectiveStmt( const string & directive ) : Statement(), directive( directive ) {} 97 98 void DirectiveStmt::print( ostream & os, Indenter ) const { 99 99 os << "GCC Directive:" << directive << endl; 100 100 } … … 120 120 } 121 121 122 void BranchStmt::print( std::ostream & os, Indenter indent ) const {123 assert (type < 5);122 void BranchStmt::print( ostream & os, Indenter indent ) const { 123 assertf(type < BranchStmts, "CFA internal error: invalid branch statement" ); 124 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;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; 128 128 } 129 129 … … 136 136 } 137 137 138 void ReturnStmt::print( std::ostream & os, Indenter indent ) const {138 void ReturnStmt::print( ostream & os, Indenter indent ) const { 139 139 os << "Return Statement, returning: "; 140 140 if ( expr != nullptr ) { 141 os << endl << indent +1;142 expr->print( os, indent +1 );141 os << endl << indent + 1; 142 expr->print( os, indent + 1 ); 143 143 } 144 144 os << endl; 145 145 } 146 146 147 IfStmt::IfStmt( Expression * condition, Statement * then, Statement * else_, std::list<Statement *> initialization ):147 IfStmt::IfStmt( Expression * condition, Statement * then, Statement * else_, const list<Statement *> initialization ): 148 148 Statement(), condition( condition ), then( then ), else_( else_ ), initialization( initialization ) {} 149 149 … … 160 160 } 161 161 162 void IfStmt::print( std::ostream & os, Indenter indent ) const {162 void IfStmt::print( ostream & os, Indenter indent ) const { 163 163 os << "If on condition: " << endl; 164 os << indent +1;165 condition->print( os, indent +1 );164 os << indent + 1; 165 condition->print( os, indent + 1 ); 166 166 167 167 if ( !initialization.empty() ) { 168 168 os << indent << "... with initialization: \n"; 169 169 for ( const Statement * stmt : initialization ) { 170 os << indent +1;171 stmt->print( os, indent +1 );170 os << indent + 1; 171 stmt->print( os, indent + 1 ); 172 172 } 173 173 os << endl; … … 176 176 os << indent << "... then: " << endl; 177 177 178 os << indent +1;179 then->print( os, indent +1 );178 os << indent + 1; 179 then->print( os, indent + 1 ); 180 180 181 181 if ( else_ != nullptr ) { 182 182 os << indent << "... else: " << endl; 183 os << indent +1;184 else_->print( os, indent +1 );183 os << indent + 1; 184 else_->print( os, indent + 1 ); 185 185 } // if 186 186 } 187 187 188 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ):188 SwitchStmt::SwitchStmt( Expression * condition, const list<Statement *> & statements ): 189 189 Statement(), condition( condition ), statements( statements ) { 190 190 } … … 201 201 } 202 202 203 void SwitchStmt::print( std::ostream & os, Indenter indent ) const {203 void SwitchStmt::print( ostream & os, Indenter indent ) const { 204 204 os << "Switch on condition: "; 205 205 condition->print( os ); … … 207 207 208 208 for ( const Statement * stmt : statements ) { 209 stmt->print( os, indent +1 );210 } 211 } 212 213 CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) :214 Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {209 stmt->print( os, indent + 1 ); 210 } 211 } 212 213 CaseStmt::CaseStmt( Expression * condition, const list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) : 214 Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) { 215 215 if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " ); 216 216 } 217 217 218 218 CaseStmt::CaseStmt( const CaseStmt & other ) : 219 Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {219 Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { 220 220 cloneAll( other.stmts, stmts ); 221 221 } … … 226 226 } 227 227 228 CaseStmt * CaseStmt::makeDefault( const std::list<Label> & labels, std::list<Statement *> stmts ) {228 CaseStmt * CaseStmt::makeDefault( const list<Label> & labels, list<Statement *> stmts ) { 229 229 CaseStmt * stmt = new CaseStmt( nullptr, stmts, true ); 230 230 stmt->labels = labels; … … 232 232 } 233 233 234 void CaseStmt::print( std::ostream & os, Indenter indent ) const {234 void CaseStmt::print( ostream & os, Indenter indent ) const { 235 235 if ( isDefault() ) os << indent << "Default "; 236 236 else { … … 241 241 242 242 for ( Statement * stmt : stmts ) { 243 os << indent +1;244 stmt->print( os, indent +1 );245 } 246 } 247 248 WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, const std::list< Statement * > & initialization, bool isDoWhile ):243 os << indent + 1; 244 stmt->print( os, indent + 1 ); 245 } 246 } 247 248 WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, const list< Statement * > & initialization, bool isDoWhile ): 249 249 Statement(), condition( condition ), body( body ), else_( nullptr ), initialization( initialization ), isDoWhile( isDoWhile) { 250 250 } 251 251 252 WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, Statement * else_, const std::list< Statement * > & initialization, bool isDoWhile ):252 WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, Statement * else_, const list< Statement * > & initialization, bool isDoWhile ): 253 253 Statement(), condition( condition), body( body ), else_( else_ ), initialization( initialization ), isDoWhile( isDoWhile) { 254 254 } … … 263 263 } 264 264 265 void WhileDoStmt::print( std::ostream & os, Indenter indent ) const {265 void WhileDoStmt::print( ostream & os, Indenter indent ) const { 266 266 os << "While on condition: " << endl ; 267 condition->print( os, indent +1 );267 condition->print( os, indent + 1 ); 268 268 269 269 os << indent << "... with body: " << endl; 270 270 271 if ( body != nullptr ) body->print( os, indent +1 );272 } 273 274 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body, Statement * else_ ):271 if ( body != nullptr ) body->print( os, indent + 1 ); 272 } 273 274 ForStmt::ForStmt( const list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body, Statement * else_ ): 275 275 Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ), else_( else_ ) { 276 276 } … … 290 290 } 291 291 292 void ForStmt::print( std::ostream & os, Indenter indent ) const {292 void ForStmt::print( ostream & os, Indenter indent ) const { 293 293 Statement::print( os, indent ); // print labels 294 294 … … 298 298 os << indent << "... initialization: \n"; 299 299 for ( Statement * stmt : initialization ) { 300 os << indent +1;301 stmt->print( os, indent +1 );300 os << indent + 1; 301 stmt->print( os, indent + 1 ); 302 302 } 303 303 } 304 304 305 305 if ( condition != nullptr ) { 306 os << indent << "... condition: \n" << indent +1;307 condition->print( os, indent +1 );306 os << indent << "... condition: \n" << indent + 1; 307 condition->print( os, indent + 1 ); 308 308 } 309 309 310 310 if ( increment != nullptr ) { 311 os << "\n" << indent << "... increment: \n" << indent +1;312 increment->print( os, indent +1 );311 os << "\n" << indent << "... increment: \n" << indent + 1; 312 increment->print( os, indent + 1 ); 313 313 } 314 314 315 315 if ( body != nullptr ) { 316 os << "\n" << indent << "... with body: \n" << indent +1;317 body->print( os, indent +1 );316 os << "\n" << indent << "... with body: \n" << indent + 1; 317 body->print( os, indent + 1 ); 318 318 } 319 319 320 320 if ( else_ != nullptr ) { 321 os << "\n" << indent << "... with body: \n" << indent +1;322 else_->print( os, indent +1 );321 os << "\n" << indent << "... with body: \n" << indent + 1; 322 else_->print( os, indent + 1 ); 323 323 } 324 324 os << endl; … … 339 339 } 340 340 341 void ThrowStmt::print( std::ostream & os, Indenter indent) const {341 void ThrowStmt::print( ostream & os, Indenter indent) const { 342 342 if ( target ) os << "Non-Local "; 343 343 os << "Throw Statement, raising: "; 344 expr->print(os, indent +1);344 expr->print(os, indent + 1); 345 345 if ( target ) { 346 346 os << "... at: "; 347 target->print(os, indent +1);348 } 349 } 350 351 TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) :347 target->print(os, indent + 1); 348 } 349 } 350 351 TryStmt::TryStmt( CompoundStmt * tryBlock, const list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) : 352 352 Statement(), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) { 353 353 } … … 363 363 } 364 364 365 void TryStmt::print( std::ostream & os, Indenter indent ) const {365 void TryStmt::print( ostream & os, Indenter indent ) const { 366 366 os << "Try Statement" << endl; 367 os << indent << "... with block:" << endl << indent +1;368 block->print( os, indent +1 );367 os << indent << "... with block:" << endl << indent + 1; 368 block->print( os, indent + 1 ); 369 369 370 370 // handlers 371 371 os << indent << "... and handlers:" << endl; 372 372 for ( const CatchStmt * stmt : handlers ) { 373 os << indent +1;374 stmt->print( os, indent +1 );373 os << indent + 1; 374 stmt->print( os, indent + 1 ); 375 375 } 376 376 377 377 // finally block 378 378 if ( finallyBlock != nullptr ) { 379 os << indent << "... and finally:" << endl << indent +1;380 finallyBlock->print( os, indent +1 );379 os << indent << "... and finally:" << endl << indent + 1; 380 finallyBlock->print( os, indent + 1 ); 381 381 } // if 382 382 } … … 396 396 } 397 397 398 void CatchStmt::print( std::ostream & os, Indenter indent ) const {398 void CatchStmt::print( ostream & os, Indenter indent ) const { 399 399 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; 400 400 401 401 os << indent << "... catching: "; 402 decl->printShort( os, indent +1 );402 decl->printShort( os, indent + 1 ); 403 403 os << endl; 404 404 405 405 if ( cond ) { 406 os << indent << "... with conditional:" << endl << indent +1;407 cond->print( os, indent +1 );406 os << indent << "... with conditional:" << endl << indent + 1; 407 cond->print( os, indent + 1 ); 408 408 } 409 409 410 410 os << indent << "... with block:" << endl; 411 os << indent +1;412 body->print( os, indent +1 );411 os << indent + 1; 412 body->print( os, indent + 1 ); 413 413 } 414 414 … … 424 424 } 425 425 426 void FinallyStmt::print( std::ostream & os, Indenter indent ) const {426 void FinallyStmt::print( ostream & os, Indenter indent ) const { 427 427 os << "Finally Statement" << endl; 428 os << indent << "... with block:" << endl << indent +1;429 block->print( os, indent +1 );428 os << indent << "... with block:" << endl << indent + 1; 429 block->print( os, indent + 1 ); 430 430 } 431 431 … … 439 439 } 440 440 441 void SuspendStmt::print( std::ostream & os, Indenter indent ) const {441 void SuspendStmt::print( ostream & os, Indenter indent ) const { 442 442 os << "Suspend Statement"; 443 443 switch (type) { … … 496 496 } 497 497 498 void WaitForStmt::print( std::ostream & os, Indenter indent ) const {498 void WaitForStmt::print( ostream & os, Indenter indent ) const { 499 499 os << "Waitfor Statement" << endl; 500 500 indent += 1; … … 531 531 532 532 533 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {}533 WithStmt::WithStmt( const list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {} 534 534 WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { 535 535 cloneAll( other.exprs, exprs ); … … 540 540 } 541 541 542 void WithStmt::print( std::ostream & os, Indenter indent ) const {542 void WithStmt::print( ostream & os, Indenter indent ) const { 543 543 os << "With statement" << endl; 544 544 os << indent << "... with expressions: " << endl; 545 printAll( exprs, os, indent +1 );546 os << indent << "... with statement:" << endl << indent +1;547 stmt->print( os, indent +1 );548 } 549 550 551 NullStmt::NullStmt( const std::list<Label> & labels ) : Statement( labels ) {552 } 553 554 void NullStmt::print( std::ostream & os, Indenter indent ) const {545 printAll( exprs, os, indent + 1 ); 546 os << indent << "... with statement:" << endl << indent + 1; 547 stmt->print( os, indent + 1 ); 548 } 549 550 551 NullStmt::NullStmt( const list<Label> & labels ) : Statement( labels ) { 552 } 553 554 void NullStmt::print( ostream & os, Indenter indent ) const { 555 555 os << "Null Statement" << endl; 556 556 Statement::print( os, indent ); … … 568 568 } 569 569 570 void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const {570 void ImplicitCtorDtorStmt::print( ostream & os, Indenter indent ) const { 571 571 os << "Implicit Ctor Dtor Statement" << endl; 572 572 os << indent << "... with Ctor/Dtor: "; 573 callStmt->print( os, indent +1);573 callStmt->print( os, indent + 1); 574 574 os << endl; 575 575 } 576 576 577 MutexStmt::MutexStmt( Statement * stmt, std::list<Expression *> mutexObjs )577 MutexStmt::MutexStmt( Statement * stmt, const list<Expression *> mutexObjs ) 578 578 : Statement(), stmt( stmt ), mutexObjs( mutexObjs ) { } 579 579 … … 587 587 } 588 588 589 void MutexStmt::print( std::ostream & os, Indenter indent ) const {589 void MutexStmt::print( ostream & os, Indenter indent ) const { 590 590 os << "Mutex Statement" << endl; 591 591 os << indent << "... with Expressions: " << endl; 592 592 for (auto * obj : mutexObjs) { 593 os << indent +1;594 obj->print( os, indent +1);593 os << indent + 1; 594 obj->print( os, indent + 1); 595 595 os << endl; 596 596 } 597 os << indent << "... with Statement: " << endl << indent +1;598 stmt->print( os, indent +1 );597 os << indent << "... with Statement: " << endl << indent + 1; 598 stmt->print( os, indent + 1 ); 599 599 } 600 600
Note: See TracChangeset
for help on using the changeset viewer.