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