Changes in src/CodeGen/CodeGenerator.cc [cda48b6:68cd1ce]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rcda48b6 r68cd1ce 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jun 11 13:22:39201513 // Update Count : 1 3711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 13 07:12:27 2015 13 // Update Count : 129 14 14 // 15 15 … … 19 19 #include <list> 20 20 21 #include "Parser/ParseNode.h" 22 21 23 #include "SynTree/Type.h" 22 #include "SynTree/Declaration.h"23 #include "SynTree/Statement.h"24 24 #include "SynTree/Expression.h" 25 25 #include "SynTree/Initializer.h" 26 #include "SynTree/Statement.h" 26 27 27 28 #include "utility.h" … … 43 44 } 44 45 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 ) { 46 CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { } 47 48 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indent, bool infunp ) 49 : cur_indent( indent ), insideFunction( infunp ), output( os ) { 57 50 //output << std::string( init ); 58 51 } 59 52 60 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent ation, bool infunp )61 : indent(*this), cur_indent( indentation), insideFunction( infunp ), output( os ) {53 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent, bool infunp ) 54 : cur_indent( indent ), insideFunction( infunp ), output( os ) { 62 55 //output << std::string( init ); 63 56 } … … 70 63 } // if 71 64 } 72 65 73 66 //*** Declarations 74 67 void CodeGenerator::visit( FunctionDecl *functionDecl ) { … … 112 105 113 106 if ( ! memb.empty() ) { 114 output << endl << indent<< "{" << endl;107 output << endl << string( cur_indent, ' ' ) << "{" << endl; 115 108 116 109 cur_indent += CodeGenerator::tabsize; 117 110 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 118 output << indent;111 output << string( cur_indent, ' ' ); 119 112 (*i)->accept(*this ); 120 113 output << ";" << endl; … … 123 116 cur_indent -= CodeGenerator::tabsize; 124 117 125 output << indent<< "}";118 output << string( cur_indent, ' ' ) << "}"; 126 119 } // if 127 120 } … … 146 139 147 140 if ( ! memb.empty() ) { 148 output << "{" << endl;141 output << endl << "{" << endl; 149 142 150 143 cur_indent += CodeGenerator::tabsize; … … 152 145 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 153 146 assert( obj ); 154 output << indent<< mangleName( obj );147 output << string( cur_indent, ' ' ) << mangleName( obj ); 155 148 if ( obj->get_init() ) { 156 149 output << " = "; … … 162 155 cur_indent -= CodeGenerator::tabsize; 163 156 164 output << indent << "}";157 output << "}" << endl; 165 158 } // if 166 159 } … … 452 445 453 446 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++) { 454 output << indent<< printLabels( (*i)->get_labels() );447 output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() ); 455 448 (*i)->accept(*this ); 456 449 … … 462 455 cur_indent -= CodeGenerator::tabsize; 463 456 464 output << indent<< "}";457 output << string( cur_indent, ' ' ) << "}"; 465 458 } 466 459 … … 502 495 cur_indent -= CodeGenerator::tabsize; 503 496 504 output << indent<< "}";497 output << string( cur_indent, ' ' ) << "}"; 505 498 } 506 499 507 500 void CodeGenerator::visit( CaseStmt *caseStmt ) { 508 output << indent;501 output << string( cur_indent, ' ' ); 509 502 if ( caseStmt->isDefault()) { 510 503 output << "default"; … … 519 512 cur_indent += CodeGenerator::tabsize; 520 513 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 521 output << indent<< printLabels( (*i)->get_labels() ) ;514 output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() ) ; 522 515 (*i)->accept(*this ); 523 516 output << endl; … … 572 565 whileStmt->get_body()->accept( *this ); 573 566 574 output << indent;567 output << string( cur_indent, ' ' ); 575 568 576 569 if ( whileStmt->get_isDoWhile() ) { … … 604 597 605 598 void CodeGenerator::visit( NullStmt *nullStmt ) { 606 //output << indent<< CodeGenerator::printLabels( nullStmt->get_labels() );599 //output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( nullStmt->get_labels() ); 607 600 output << "/* null statement */ ;"; 608 601 } … … 628 621 void CodeGenerator::handleStorageClass( Declaration *decl ) { 629 622 switch ( decl->get_storageClass() ) { 630 case Declaration::NoStorageClass: 631 break; 632 case Declaration::Extern: 623 case DeclarationNode::Extern: 633 624 output << "extern "; 634 625 break; 635 case Declaration ::Static:626 case DeclarationNode::Static: 636 627 output << "static "; 637 628 break; 638 case Declaration ::Auto:629 case DeclarationNode::Auto: 639 630 // silently drop storage class 640 631 break; 641 case Declaration ::Register:632 case DeclarationNode::Register: 642 633 output << "register "; 643 634 break; 644 case Declaration ::Inline:635 case DeclarationNode::Inline: 645 636 // handled as special via isInline flag (FIX) 646 637 break; 647 case Declaration ::Fortran:638 case DeclarationNode::Fortran: 648 639 // not handled 640 output << "fortran "; 641 break; 642 case DeclarationNode::Noreturn: 643 // not handled 644 output << "_Noreturn "; 645 break; 646 case DeclarationNode::Threadlocal: 647 // not handled 648 output << "_Thread_local "; 649 break; 650 case DeclarationNode::NoStorageClass: 649 651 break; 650 652 } // switch
Note:
See TracChangeset
for help on using the changeset viewer.