Changes in src/SynTree/Statement.cc [70d826cd:50377a4]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Statement.cc
r70d826cd r50377a4 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:17:20201713 // Update Count : 6 712 // Last Modified On : Sun Sep 3 20:46:44 2017 13 // Update Count : 68 14 14 // 15 15 … … 34 34 Statement::Statement( std::list<Label> labels ) : labels( labels ) {} 35 35 36 void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {} 36 void Statement::print( std::ostream & os, Indenter ) const { 37 if ( ! labels.empty() ) { 38 os << "Labels: {"; 39 for ( const Label & l : labels ) { 40 os << l << ","; 41 } 42 os << "}" << endl; 43 } 44 } 37 45 38 46 Statement::~Statement() {} … … 46 54 } 47 55 48 void ExprStmt::print( std::ostream &os, intindent ) const {49 os << "Expression Statement:" << endl << std::string( indent + 2, ' ' );50 expr->print( os, indent + 2);51 } 52 53 54 AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr*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 ) {}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( 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 ) {} 55 63 56 64 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { … … 67 75 } 68 76 69 void AsmStmt::print( std::ostream &os, intindent ) const {77 void AsmStmt::print( std::ostream &os, Indenter indent ) const { 70 78 os << "Assembler Statement:" << endl; 71 os << std::string( indent, ' ' ) << "instruction: " << endl << std::string( indent, ' ' );72 instruction->print( os, indent + 2);79 os << indent+1 << "instruction: " << endl << indent; 80 instruction->print( os, indent+1 ); 73 81 if ( ! output.empty() ) { 74 os << endl << std::string( indent, ' ' )<< "output: " << endl;75 printAll( output, os, indent + 2);82 os << endl << indent+1 << "output: " << endl; 83 printAll( output, os, indent+1 ); 76 84 } // if 77 85 if ( ! input.empty() ) { 78 os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );79 printAll( input, os, indent + 2);86 os << indent+1 << "input: " << endl; 87 printAll( input, os, indent+1 ); 80 88 } // if 81 89 if ( ! clobber.empty() ) { 82 os << std::string( indent, ' ' )<< "clobber: " << endl;83 printAll( clobber, os, indent + 2);90 os << indent+1 << "clobber: " << endl; 91 printAll( clobber, os, indent+1 ); 84 92 } // if 85 93 } … … 103 111 } 104 112 105 void BranchStmt::print( std::ostream &os, intindent ) const {106 os << string( indent, ' ' ) <<"Branch (" << brType[type] << ")" << endl ;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;113 void BranchStmt::print( std::ostream &os, Indenter indent ) const { 114 os << "Branch (" << brType[type] << ")" << endl ; 115 if ( target != "" ) os << indent+1 << "with target: " << target << endl; 116 if ( originalTarget != "" ) os << indent+1 << "with original target: " << originalTarget << endl; 117 if ( computedTarget != nullptr ) os << indent+1 << "with computed target: " << computedTarget << endl; 110 118 } 111 119 … … 118 126 } 119 127 120 void ReturnStmt::print( std::ostream &os, intindent ) const {121 os << 122 if ( expr != 0) {123 os << endl << string( indent+2, ' ' );124 expr->print( os, indent + 2);128 void ReturnStmt::print( std::ostream &os, Indenter indent ) const { 129 os << "Return Statement, returning: "; 130 if ( expr != nullptr ) { 131 os << endl << indent+1; 132 expr->print( os, indent+1 ); 125 133 } 126 134 os << endl; … … 142 150 } 143 151 144 void IfStmt::print( std::ostream &os, intindent ) const {145 os << "If on condition: " << endl 146 os << string( indent+4, ' ' );147 condition->print( os, indent + 4);152 void IfStmt::print( std::ostream &os, Indenter indent ) const { 153 os << "If on condition: " << endl; 154 os << indent+1; 155 condition->print( os, indent+1 ); 148 156 149 157 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);158 os << indent << "... with initialization: \n"; 159 for ( const Statement * stmt : initialization ) { 160 os << indent+1; 161 stmt->print( os, indent+1 ); 154 162 } 155 163 os << endl; 156 164 } 157 165 158 os << string( indent+2, ' ' )<< "... then: " << endl;159 160 os << string( indent+4, ' ' );161 thenPart->print( os, indent + 4);166 os << indent << "... then: " << endl; 167 168 os << indent+1; 169 thenPart->print( os, indent+1 ); 162 170 163 171 if ( elsePart != 0 ) { 164 os << string( indent+2, ' ' )<< "... else: " << endl;165 os << string( indent+4, ' ' );166 elsePart->print( os, indent + 4);167 } // if 168 } 169 170 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):172 os << indent << "... else: " << endl; 173 os << indent+1; 174 elsePart->print( os, indent+1 ); 175 } // if 176 } 177 178 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, const std::list<Statement *> &statements ): 171 179 Statement( labels ), condition( condition ), statements( statements ) { 172 180 } … … 183 191 } 184 192 185 void SwitchStmt::print( std::ostream &os, intindent ) const {193 void SwitchStmt::print( std::ostream &os, Indenter indent ) const { 186 194 os << "Switch on condition: "; 187 195 condition->print( os ); 188 196 os << endl; 189 197 190 // statements 191 std::list<Statement *>::const_iterator i; 192 for ( i = statements.begin(); i != statements.end(); i++) 193 (*i)->print( os, indent + 4 ); 194 195 //for_each( statements.begin(), statements.end(), mem_fun( bind1st(&Statement::print ), os )); 196 } 197 198 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) : 198 for ( const Statement * stmt : statements ) { 199 stmt->print( os, indent+1 ); 200 } 201 } 202 203 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) : 199 204 Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) { 200 if ( isDefault() && condition != 0 ) 201 throw SemanticError("default with conditions"); 205 if ( isDefault() && condition != 0 ) throw SemanticError("default case with condition: ", condition); 202 206 } 203 207 … … 216 220 } 217 221 218 void CaseStmt::print( std::ostream &os, int indent ) const { 219 os << string( indent, ' ' ); 220 221 if ( isDefault() ) 222 os << "Default "; 222 void CaseStmt::print( std::ostream &os, Indenter indent ) const { 223 if ( isDefault() ) os << "Default "; 223 224 else { 224 225 os << "Case "; 225 condition->print( os ); 226 } // if 227 228 os << endl; 229 230 std::list<Statement *>::const_iterator i; 231 for ( i = stmts.begin(); i != stmts.end(); i++) 232 (*i )->print( os, indent + 4 ); 226 condition->print( os, indent ); 227 } // if 228 os << endl; 229 230 for ( Statement * stmt : stmts ) { 231 stmt->print( os, indent+1 ); 232 } 233 233 } 234 234 … … 246 246 } 247 247 248 void WhileStmt::print( std::ostream &os, intindent ) const {248 void WhileStmt::print( std::ostream &os, Indenter indent ) const { 249 249 os << "While on condition: " << endl ; 250 condition->print( os, indent + 4);251 252 os << string( indent, ' ' ) << ".... with body: " << endl;253 254 if ( body != 0 ) body->print( os, indent + 4);250 condition->print( os, indent+1 ); 251 252 os << indent << "... with body: " << endl; 253 254 if ( body != 0 ) body->print( os, indent+1 ); 255 255 } 256 256 … … 272 272 } 273 273 274 void ForStmt::print( std::ostream &os, int indent ) const { 275 os << "Labels: {"; 276 for ( std::list<Label>::const_iterator it = get_labels().begin(); it != get_labels().end(); ++it) { 277 os << *it << ","; 278 } 279 os << "}" << endl; 280 281 os << string( indent, ' ' ) << "For Statement" << endl ; 282 283 os << string( indent + 2, ' ' ) << "initialization: \n"; 284 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { 285 os << string( indent + 4, ' ' ); 286 (*it)->print( os, indent + 4 ); 287 } 288 289 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 290 if ( condition != 0 ) { 291 os << string( indent + 4, ' ' ); 292 condition->print( os, indent + 4 ); 293 } 294 295 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 296 if ( increment != 0 ) { 297 os << string( indent + 4, ' ' ); 298 increment->print( os, indent + 4 ); 299 } 300 301 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 274 void ForStmt::print( std::ostream &os, Indenter indent ) const { 275 Statement::print( os, indent ); // print labels 276 277 os << "For Statement" << endl; 278 279 if ( ! initialization.empty() ) { 280 os << indent << "... initialization: \n"; 281 for ( Statement * stmt : initialization ) { 282 os << indent+1; 283 stmt->print( os, indent+1 ); 284 } 285 } 286 287 if ( condition != nullptr ) { 288 os << indent << "... condition: \n" << indent+1; 289 condition->print( os, indent+1 ); 290 } 291 292 if ( increment != nullptr ) { 293 os << "\n" << indent << "... increment: \n" << indent+1; 294 increment->print( os, indent+1 ); 295 } 296 302 297 if ( body != 0 ) { 303 os << string( indent + 4, ' ' ); 304 body->print( os, indent + 4 ); 305 } 306 298 os << "\n" << indent << "... with body: \n" << indent+1; 299 body->print( os, indent+1 ); 300 } 307 301 os << endl; 308 302 } … … 322 316 } 323 317 324 void ThrowStmt::print( std::ostream &os, int indent) const { 318 void ThrowStmt::print( std::ostream &os, Indenter indent) const { 319 if ( target ) os << "Non-Local "; 320 os << "Throw Statement, raising: "; 321 expr->print(os, indent+1); 325 322 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); 323 os << "... at: "; 324 target->print(os, indent+1); 333 325 } 334 326 } … … 348 340 } 349 341 350 void TryStmt::print( std::ostream &os, intindent ) const {342 void TryStmt::print( std::ostream &os, Indenter indent ) const { 351 343 os << "Try Statement" << endl; 352 os << string( indent + 2, ' ' ) << "with block:" << endl; 353 os << string( indent + 4, ' ' ); 354 block->print( os, indent + 4 ); 344 os << indent << "... with block:" << endl << indent+1; 345 block->print( os, indent+1 ); 355 346 356 347 // handlers 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, ' ' );360 (*i )->print( os, indent + 4);348 os << indent << "... and handlers:" << endl; 349 for ( const CatchStmt * stmt : handlers ) { 350 os << indent+1; 351 stmt->print( os, indent+1 ); 361 352 } 362 353 363 354 // finally block 364 355 if ( finallyBlock != 0 ) { 365 os << string( indent + 2, ' ' ) << "and finally:" << endl;366 finallyBlock->print( os, indent + 4);356 os << indent << "... and finally:" << endl << indent+1; 357 finallyBlock->print( os, indent+1 ); 367 358 } // if 368 359 } … … 370 361 CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) : 371 362 Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { 363 assertf( decl, "Catch clause must have a declaration." ); 372 364 } 373 365 … … 381 373 } 382 374 383 void CatchStmt::print( std::ostream &os, intindent ) const {375 void CatchStmt::print( std::ostream &os, Indenter indent ) const { 384 376 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; 385 377 386 os << string( indent + 2, ' ' ) << "... catching: "; 387 if ( decl ) { 388 decl->printShort( os, indent + 4 ); 389 os << endl; 390 } 391 else 392 os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl; 378 os << indent << "... catching: "; 379 decl->printShort( os, indent+1 ); 380 os << endl; 393 381 394 382 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 ); 383 os << indent << "... with conditional:" << endl << indent+1; 384 cond->print( os, indent+1 ); 385 } 386 387 os << indent << "... with block:" << endl; 388 os << indent+1; 389 body->print( os, indent+1 ); 405 390 } 406 391 … … 417 402 } 418 403 419 void FinallyStmt::print( std::ostream &os, intindent ) const {404 void FinallyStmt::print( std::ostream &os, Indenter indent ) const { 420 405 os << "Finally Statement" << endl; 421 os << string( indent + 2, ' ' ) << "with block:" << endl; 422 os << string( indent + 4, ' ' ); 423 block->print( os, indent + 4 ); 406 os << indent << "... with block:" << endl << indent+1; 407 block->print( os, indent+1 ); 424 408 } 425 409 … … 465 449 } 466 450 467 void WaitForStmt::print( std::ostream &os, intindent ) const {451 void WaitForStmt::print( std::ostream &os, Indenter indent ) const { 468 452 os << "Waitfor Statement" << endl; 469 os << string( indent + 2, ' ' ) << "with block:" << endl; 470 os << string( indent + 4, ' ' ); 453 os << indent << "... with block:" << endl << indent+1; 471 454 // block->print( os, indent + 4 ); 472 455 } … … 475 458 NullStmt::NullStmt() : Statement( std::list<Label>() ) {} 476 459 477 void NullStmt::print( std::ostream &os, __attribute__((unused)) int indent) const {478 os << "Null Statement" << endl 460 void NullStmt::print( std::ostream &os, Indenter ) const { 461 os << "Null Statement" << endl; 479 462 } 480 463 … … 490 473 } 491 474 492 void ImplicitCtorDtorStmt::print( std::ostream &os, intindent ) const {475 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const { 493 476 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 499 std::ostream & operator<<( std::ostream & out, const Statement * statement ) { 500 if ( statement ) { 501 statement->print( out ); 502 } else { 503 out << "nullptr"; 504 } 505 return out; 477 os << indent << "... with Ctor/Dtor: "; 478 callStmt->print( os, indent+1); 479 os << endl; 506 480 } 507 481
Note:
See TracChangeset
for help on using the changeset viewer.