Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r94b4364 rde62360d  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Jun 15 12:47:16 2015
    13 // Update Count     : 142
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Jun 23 16:16:57 2015
     13// Update Count     : 133
    1414//
    1515
     
    4444        }
    4545
    46         ostream & CodeGenerator::Indenter::operator()( ostream & output ) {
    47           return output << string( cg.cur_indent, ' ' );
    48         }
    49 
    50         ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) {
    51                 return indent( output );
    52         }
    53 
    54         CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { }
    55 
    56         CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
    57                         : 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 ) {
    5850                //output << std::string( init );
    5951        }
    6052
    61         CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
    62                         : 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 ) {
    6355                //output << std::string( init );
    6456        }
     
    7163                } // if
    7264        }
    73 
     65 
    7466        //*** Declarations
    7567        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     
    7769                if ( functionDecl->get_isInline() ) {
    7870                        output << "inline ";
     71                } // if
     72                if ( functionDecl->get_isNoreturn() ) {
     73                        output << "_Noreturn ";
    7974                } // if
    8075                output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );
     
    113108
    114109                if ( ! memb.empty() ) {
    115                         output << " {" << endl;
     110                        output << endl << string( cur_indent, ' ' ) << "{" << endl;
    116111
    117112                        cur_indent += CodeGenerator::tabsize;
    118113                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    119                                 output << indent;
     114                                output << string( cur_indent, ' ' );
    120115                                (*i)->accept(*this );
    121116                                output << ";" << endl;
     
    124119                        cur_indent -= CodeGenerator::tabsize;
    125120
    126                         output << indent << "}";
     121                        output << string( cur_indent, ' ' ) << "}";
    127122                } // if
    128123        }
     
    147142
    148143                if ( ! memb.empty() ) {
    149                         output << " {" << endl;
     144                        output << endl << "{" << endl;
    150145
    151146                        cur_indent += CodeGenerator::tabsize;
     
    153148                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    154149                                assert( obj );
    155                                 output << indent << mangleName( obj );
     150                                output << string( cur_indent, ' ' ) << mangleName( obj );
    156151                                if ( obj->get_init() ) {
    157152                                        output << " = ";
     
    163158                        cur_indent -= CodeGenerator::tabsize;
    164159
    165                         output << indent << "}";
     160                        output << "}" << endl;
    166161                } // if
    167162        }
     
    303298                                  case OT_PREFIX:
    304299                                  case OT_PREFIXASSIGN:
     300                                  case OT_LABELADDRESS:
    305301                                        assert( untypedExpr->get_args().size() == 1 );
    306302                                        output << "(";
     
    326322                                        output << ")";
    327323                                        break;
    328              
     324                                       
    329325                                  case OT_CONSTANT:
    330326                                        // there are no intrinsic definitions of 0 or 1 as functions
     
    453449
    454450                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    455                         output << indent << printLabels( (*i)->get_labels() );
     451                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() );
    456452                        (*i)->accept(*this );
    457453
     
    463459                cur_indent -= CodeGenerator::tabsize;
    464460
    465                 output << indent << "}";
     461                output << string( cur_indent, ' ' ) << "}";
    466462        }
    467463
     
    503499                cur_indent -= CodeGenerator::tabsize;
    504500
    505                 output << indent << "}";
     501                output << string( cur_indent, ' ' ) << "}";
    506502        }
    507503
    508504        void CodeGenerator::visit( CaseStmt *caseStmt ) {
    509                 output << indent;
     505                output << string( cur_indent, ' ' );
    510506                if ( caseStmt->isDefault()) {
    511507                        output << "default";
     
    520516                cur_indent += CodeGenerator::tabsize;
    521517                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    522                         output << indent << printLabels( (*i)->get_labels() )  ;
     518                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
    523519                        (*i)->accept(*this );
    524520                        output << endl;
     
    573569                whileStmt->get_body()->accept( *this );
    574570
    575                 output << indent;
     571                output << string( cur_indent, ' ' );
    576572
    577573                if ( whileStmt->get_isDoWhile() ) {
     
    605601
    606602        void CodeGenerator::visit( NullStmt *nullStmt ) {
    607                 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
     603                //output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( nullStmt->get_labels() );
    608604                output << "/* null statement */ ;";
    609605        }
     
    642638                        break;
    643639                  case DeclarationNode::Inline:
    644                         // handled as special via isInline flag (FIX)
     640                        output << "inline ";
    645641                        break;
    646642                  case DeclarationNode::Fortran:
    647                         // not handled
    648643                        output << "fortran ";
    649644                        break;
    650645                  case DeclarationNode::Noreturn:
    651                         // not handled
    652646                        output << "_Noreturn ";
    653647                        break;
    654648                  case DeclarationNode::Threadlocal:
    655                         // not handled
    656649                        output << "_Thread_local ";
    657650                        break;
Note: See TracChangeset for help on using the changeset viewer.