Changeset 2b6c1e0 for src/CodeGen
- Timestamp:
- Jun 2, 2015, 1:26:42 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- b2152e7a
- Parents:
- 6c4ff37
- Location:
- src/CodeGen
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r6c4ff37 r2b6c1e0 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jun 02 1 1:45:06201513 // Update Count : 6512 // Last Modified On : Tue Jun 02 13:25:22 2015 13 // Update Count : 118 14 14 // 15 15 … … 36 36 namespace CodeGen { 37 37 int CodeGenerator::tabsize = 4; 38 39 // the kinds of statements that would ideally be separated by more whitespace 40 bool wantSpacing( Statement * stmt) { 41 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || 42 dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt ); 43 } 38 44 39 45 CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { } … … 429 435 430 436 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 431 432 437 433 438 //*** Statements 434 439 void CodeGenerator::visit( CompoundStmt *compoundStmt ) { 435 440 std::list<Statement*> ks = compoundStmt->get_kids(); 436 437 output << endl << string( cur_indent, ' ' ) << "{" << endl; 438 439 cur_indent += CodeGenerator::tabsize; 441 output << "{" << endl; 442 443 cur_indent += CodeGenerator::tabsize; 440 444 441 445 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++) { 442 output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() ) 446 output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() ); 443 447 (*i)->accept(*this ); 448 444 449 output << endl; 450 if ( wantSpacing( *i ) ) { 451 output << endl; 452 } 445 453 } 446 454 cur_indent -= CodeGenerator::tabsize; 447 455 448 output << string( cur_indent, ' ' ) << "}" << endl;456 output << string( cur_indent, ' ' ) << "}"; 449 457 } 450 458 … … 464 472 output << "if ("; 465 473 ifStmt->get_condition()->accept(*this ); 466 output << ")\n"; 467 468 cur_indent += CodeGenerator::tabsize; 469 output << string( cur_indent, ' ' ); 474 output << ") "; 475 470 476 ifStmt->get_thenPart()->accept(*this ); 471 cur_indent -= CodeGenerator::tabsize;472 output << endl;473 477 474 478 if ( ifStmt->get_elsePart() != 0) { 475 output << string( cur_indent, ' ' ) << " else " << endl ; 476 477 cur_indent += CodeGenerator::tabsize; 479 output << " else "; 478 480 ifStmt->get_elsePart()->accept(*this ); 479 cur_indent -= CodeGenerator::tabsize;480 481 } // if 481 482 } … … 485 486 output << "switch (" ; 486 487 switchStmt->get_condition()->accept(*this ); 487 output << ") \n";488 output << ") "; 488 489 489 output << string( cur_indent, ' ' ) <<"{" << std::endl;490 output << "{" << std::endl; 490 491 cur_indent += CodeGenerator::tabsize; 491 492 … … 494 495 cur_indent -= CodeGenerator::tabsize; 495 496 496 output << /* "\r" << */ string( cur_indent, ' ' ) << "}" << endl;497 output << string( cur_indent, ' ' ) << "}"; 497 498 } 498 499 … … 500 501 output << string( cur_indent, ' ' ); 501 502 if ( caseStmt->isDefault()) 502 output << "default" 503 output << "default"; 503 504 else { 504 output << "case " 505 output << "case "; 505 506 caseStmt->get_condition()->accept(*this ); 506 507 } // if … … 540 541 break; 541 542 } 542 output << ";" << endl;543 output << ";"; 543 544 } 544 545 … … 562 563 output << ")"; 563 564 } // if 564 output << " \n";565 566 output << string( cur_indent, ' ' ) <<CodeGenerator::printLabels( whileStmt->get_body()->get_labels() );565 output << " "; 566 567 output << CodeGenerator::printLabels( whileStmt->get_body()->get_labels() ); 567 568 whileStmt->get_body()->accept( *this ); 568 569 … … 574 575 output << ");"; 575 576 } // if 576 577 output << "\n";578 577 } 579 578 … … 592 591 if ( forStmt->get_increment() != 0 ) 593 592 forStmt->get_increment()->accept( *this ); 594 output << ") " << endl;593 output << ") "; 595 594 596 595 if ( forStmt->get_body() != 0 ) { 597 output << string( cur_indent, ' ' ) <<CodeGenerator::printLabels( forStmt->get_body()->get_labels() );596 output << CodeGenerator::printLabels( forStmt->get_body()->get_labels() ); 598 597 forStmt->get_body()->accept( *this ); 599 598 } // if -
src/CodeGen/CodeGenerator.h
r6c4ff37 r2b6c1e0 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jun 02 1 1:45:20201513 // Update Count : 912 // Last Modified On : Tue Jun 02 13:25:09 2015 13 // Update Count : 12 14 14 // 15 15 … … 32 32 CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false ); 33 33 CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false ); 34 35 CodeGenerator( CodeGenerator & );36 34 37 35 //*** Declaration
Note: See TracChangeset
for help on using the changeset viewer.