Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rcda48b6 reb3261f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jun 11 13:22:39 2015
    13 // Update Count     : 137
     12// Last Modified On : Thu Jun 04 15:00:00 2015
     13// Update Count     : 125
    1414//
    1515
     
    4343        }
    4444
    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 ) {
     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 ) {
    5749                //output << std::string( init );
    5850        }
    5951
    60         CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
    61                         : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
     52        CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent, bool infunp )
     53                        : cur_indent( indent ), insideFunction( infunp ), output( os ) {
    6254                //output << std::string( init );
    6355        }
     
    7062                } // if
    7163        }
    72  
     64  
    7365        //*** Declarations
    7466        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     
    112104
    113105                if ( ! memb.empty() ) {
    114                         output << endl << indent << "{" << endl;
     106                        output << endl << string( cur_indent, ' ' ) << "{" << endl;
    115107
    116108                        cur_indent += CodeGenerator::tabsize;
    117109                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    118                                 output << indent;
     110                                output << string( cur_indent, ' ' );
    119111                                (*i)->accept(*this );
    120112                                output << ";" << endl;
     
    123115                        cur_indent -= CodeGenerator::tabsize;
    124116
    125                         output << indent << "}";
     117                        output << string( cur_indent, ' ' ) << "}";
    126118                } // if
    127119        }
     
    146138
    147139                if ( ! memb.empty() ) {
    148                         output << " {" << endl;
     140                        output << endl << "{" << endl;
    149141
    150142                        cur_indent += CodeGenerator::tabsize;
     
    152144                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    153145                                assert( obj );
    154                                 output << indent << mangleName( obj );
     146                                output << string( cur_indent, ' ' ) << mangleName( obj );
    155147                                if ( obj->get_init() ) {
    156148                                        output << " = ";
     
    162154                        cur_indent -= CodeGenerator::tabsize;
    163155
    164                         output << indent << "}";
     156                        output << "}" << endl;
    165157                } // if
    166158        }
     
    452444
    453445                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    454                         output << indent << printLabels( (*i)->get_labels() );
     446                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() );
    455447                        (*i)->accept(*this );
    456448
     
    462454                cur_indent -= CodeGenerator::tabsize;
    463455
    464                 output << indent << "}";
     456                output << string( cur_indent, ' ' ) << "}";
    465457        }
    466458
     
    502494                cur_indent -= CodeGenerator::tabsize;
    503495
    504                 output << indent << "}";
     496                output << string( cur_indent, ' ' ) << "}";
    505497        }
    506498
    507499        void CodeGenerator::visit( CaseStmt *caseStmt ) {
    508                 output << indent;
     500                output << string( cur_indent, ' ' );
    509501                if ( caseStmt->isDefault()) {
    510502                        output << "default";
     
    519511                cur_indent += CodeGenerator::tabsize;
    520512                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    521                         output << indent << printLabels( (*i)->get_labels() )  ;
     513                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
    522514                        (*i)->accept(*this );
    523515                        output << endl;
     
    572564                whileStmt->get_body()->accept( *this );
    573565
    574                 output << indent;
     566                output << string( cur_indent, ' ' );
    575567
    576568                if ( whileStmt->get_isDoWhile() ) {
     
    604596
    605597        void CodeGenerator::visit( NullStmt *nullStmt ) {
    606                 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
     598                //output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( nullStmt->get_labels() );
    607599                output << "/* null statement */ ;";
    608600        }
Note: See TracChangeset for help on using the changeset viewer.