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