Changeset cda48b6
- Timestamp:
- Jun 11, 2015, 1:27:16 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:
- a8541d9
- Parents:
- 7bcf74e
- Location:
- src/CodeGen
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r7bcf74e rcda48b6 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jun 04 15:00:00201513 // Update Count : 1 2512 // Last Modified On : Thu Jun 11 13:22:39 2015 13 // Update Count : 137 14 14 // 15 15 … … 43 43 } 44 44 45 CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { } 46 47 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indent, bool infunp ) 48 : cur_indent( indent ), insideFunction( infunp ), output( os ) { 45 ostream & CodeGenerator::Indenter::operator()( ostream & output ) { 46 return output << string( cg.cur_indent, ' ' ); 47 } 48 49 ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) { 50 return indent( output ); 51 } 52 53 CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { } 54 55 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp ) 56 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 49 57 //output << std::string( init ); 50 58 } 51 59 52 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent , bool infunp )53 : cur_indent( indent), insideFunction( infunp ), output( os ) {60 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp ) 61 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 54 62 //output << std::string( init ); 55 63 } … … 62 70 } // if 63 71 } 64 72 65 73 //*** Declarations 66 74 void CodeGenerator::visit( FunctionDecl *functionDecl ) { … … 104 112 105 113 if ( ! memb.empty() ) { 106 output << endl << string( cur_indent, ' ' )<< "{" << endl;114 output << endl << indent << "{" << endl; 107 115 108 116 cur_indent += CodeGenerator::tabsize; 109 117 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 110 output << string( cur_indent, ' ' );118 output << indent; 111 119 (*i)->accept(*this ); 112 120 output << ";" << endl; … … 115 123 cur_indent -= CodeGenerator::tabsize; 116 124 117 output << string( cur_indent, ' ' )<< "}";125 output << indent << "}"; 118 126 } // if 119 127 } … … 138 146 139 147 if ( ! memb.empty() ) { 140 output << endl << "{" << endl;148 output << " {" << endl; 141 149 142 150 cur_indent += CodeGenerator::tabsize; … … 144 152 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 145 153 assert( obj ); 146 output << string( cur_indent, ' ' )<< mangleName( obj );154 output << indent << mangleName( obj ); 147 155 if ( obj->get_init() ) { 148 156 output << " = "; … … 154 162 cur_indent -= CodeGenerator::tabsize; 155 163 156 output << "}" << endl;164 output << indent << "}"; 157 165 } // if 158 166 } … … 444 452 445 453 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++) { 446 output << string( cur_indent, ' ' )<< printLabels( (*i)->get_labels() );454 output << indent << printLabels( (*i)->get_labels() ); 447 455 (*i)->accept(*this ); 448 456 … … 454 462 cur_indent -= CodeGenerator::tabsize; 455 463 456 output << string( cur_indent, ' ' )<< "}";464 output << indent << "}"; 457 465 } 458 466 … … 494 502 cur_indent -= CodeGenerator::tabsize; 495 503 496 output << string( cur_indent, ' ' )<< "}";504 output << indent << "}"; 497 505 } 498 506 499 507 void CodeGenerator::visit( CaseStmt *caseStmt ) { 500 output << string( cur_indent, ' ' );508 output << indent; 501 509 if ( caseStmt->isDefault()) { 502 510 output << "default"; … … 511 519 cur_indent += CodeGenerator::tabsize; 512 520 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 513 output << string( cur_indent, ' ' )<< printLabels( (*i)->get_labels() ) ;521 output << indent << printLabels( (*i)->get_labels() ) ; 514 522 (*i)->accept(*this ); 515 523 output << endl; … … 564 572 whileStmt->get_body()->accept( *this ); 565 573 566 output << string( cur_indent, ' ' );574 output << indent; 567 575 568 576 if ( whileStmt->get_isDoWhile() ) { … … 596 604 597 605 void CodeGenerator::visit( NullStmt *nullStmt ) { 598 //output << string( cur_indent, ' ' )<< CodeGenerator::printLabels( nullStmt->get_labels() );606 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() ); 599 607 output << "/* null statement */ ;"; 600 608 } -
src/CodeGen/CodeGenerator.h
r7bcf74e rcda48b6 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 : Mon Jun 8 14:34:43 201513 // Update Count : 1511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jun 11 13:24:23 2015 13 // Update Count : 23 14 14 // 15 15 … … 80 80 81 81 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); 82 83 struct Indenter { 84 Indenter(CodeGenerator &cg) : cg(cg) {} 85 CodeGenerator & cg; 86 std::ostream& operator()(std::ostream & os); 87 }; 82 88 private: 89 90 Indenter indent; 83 91 int cur_indent; 84 92 bool insideFunction;
Note: See TracChangeset
for help on using the changeset viewer.