Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r721f17a rde62360d  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 26 16:52:58 2015
    13 // Update Count     : 144
     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 ) {
     
    116108
    117109                if ( ! memb.empty() ) {
    118                         output << " {" << endl;
     110                        output << endl << string( cur_indent, ' ' ) << "{" << endl;
    119111
    120112                        cur_indent += CodeGenerator::tabsize;
    121113                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    122                                 output << indent;
     114                                output << string( cur_indent, ' ' );
    123115                                (*i)->accept(*this );
    124116                                output << ";" << endl;
     
    127119                        cur_indent -= CodeGenerator::tabsize;
    128120
    129                         output << indent << "}";
     121                        output << string( cur_indent, ' ' ) << "}";
    130122                } // if
    131123        }
     
    150142
    151143                if ( ! memb.empty() ) {
    152                         output << " {" << endl;
     144                        output << endl << "{" << endl;
    153145
    154146                        cur_indent += CodeGenerator::tabsize;
     
    156148                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    157149                                assert( obj );
    158                                 output << indent << mangleName( obj );
     150                                output << string( cur_indent, ' ' ) << mangleName( obj );
    159151                                if ( obj->get_init() ) {
    160152                                        output << " = ";
     
    166158                        cur_indent -= CodeGenerator::tabsize;
    167159
    168                         output << indent << "}";
     160                        output << "}" << endl;
    169161                } // if
    170162        }
     
    269261             
    270262                                  case OT_CONSTANT:
    271                                   case OT_LABELADDRESS:
    272                                         // there are no intrinsic definitions of 0/1 or label addresses as functions
     263                                        // there are no intrinsic definitions of 0 or 1 as functions
    273264                                        assert( false );
    274265                                }
     
    458449
    459450                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    460                         output << indent << printLabels( (*i)->get_labels() );
     451                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() );
    461452                        (*i)->accept(*this );
    462453
     
    468459                cur_indent -= CodeGenerator::tabsize;
    469460
    470                 output << indent << "}";
     461                output << string( cur_indent, ' ' ) << "}";
    471462        }
    472463
     
    508499                cur_indent -= CodeGenerator::tabsize;
    509500
    510                 output << indent << "}";
     501                output << string( cur_indent, ' ' ) << "}";
    511502        }
    512503
    513504        void CodeGenerator::visit( CaseStmt *caseStmt ) {
    514                 output << indent;
     505                output << string( cur_indent, ' ' );
    515506                if ( caseStmt->isDefault()) {
    516507                        output << "default";
     
    525516                cur_indent += CodeGenerator::tabsize;
    526517                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    527                         output << indent << printLabels( (*i)->get_labels() )  ;
     518                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
    528519                        (*i)->accept(*this );
    529520                        output << endl;
     
    578569                whileStmt->get_body()->accept( *this );
    579570
    580                 output << indent;
     571                output << string( cur_indent, ' ' );
    581572
    582573                if ( whileStmt->get_isDoWhile() ) {
     
    610601
    611602        void CodeGenerator::visit( NullStmt *nullStmt ) {
    612                 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
     603                //output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( nullStmt->get_labels() );
    613604                output << "/* null statement */ ;";
    614605        }
Note: See TracChangeset for help on using the changeset viewer.