Ignore:
Timestamp:
Jun 11, 2015, 1:27:16 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
a8541d9
Parents:
7bcf74e
Message:

more codegen reformatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r7bcf74e rcda48b6  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jun 04 15:00:00 2015
    13 // Update Count     : 125
     12// Last Modified On : Thu Jun 11 13:22:39 2015
     13// Update Count     : 137
    1414//
    1515
     
    4343        }
    4444
    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 ) {
     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 ) {
    4957                //output << std::string( init );
    5058        }
    5159
    52         CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent, bool infunp )
    53                         : 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 ) {
    5462                //output << std::string( init );
    5563        }
     
    6270                } // if
    6371        }
    64   
     72 
    6573        //*** Declarations
    6674        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
     
    104112
    105113                if ( ! memb.empty() ) {
    106                         output << endl << string( cur_indent, ' ' ) << "{" << endl;
     114                        output << endl << indent << "{" << endl;
    107115
    108116                        cur_indent += CodeGenerator::tabsize;
    109117                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    110                                 output << string( cur_indent, ' ' );
     118                                output << indent;
    111119                                (*i)->accept(*this );
    112120                                output << ";" << endl;
     
    115123                        cur_indent -= CodeGenerator::tabsize;
    116124
    117                         output << string( cur_indent, ' ' ) << "}";
     125                        output << indent << "}";
    118126                } // if
    119127        }
     
    138146
    139147                if ( ! memb.empty() ) {
    140                         output << endl << "{" << endl;
     148                        output << " {" << endl;
    141149
    142150                        cur_indent += CodeGenerator::tabsize;
     
    144152                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    145153                                assert( obj );
    146                                 output << string( cur_indent, ' ' ) << mangleName( obj );
     154                                output << indent << mangleName( obj );
    147155                                if ( obj->get_init() ) {
    148156                                        output << " = ";
     
    154162                        cur_indent -= CodeGenerator::tabsize;
    155163
    156                         output << "}" << endl;
     164                        output << indent << "}";
    157165                } // if
    158166        }
     
    444452
    445453                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    446                         output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() );
     454                        output << indent << printLabels( (*i)->get_labels() );
    447455                        (*i)->accept(*this );
    448456
     
    454462                cur_indent -= CodeGenerator::tabsize;
    455463
    456                 output << string( cur_indent, ' ' ) << "}";
     464                output << indent << "}";
    457465        }
    458466
     
    494502                cur_indent -= CodeGenerator::tabsize;
    495503
    496                 output << string( cur_indent, ' ' ) << "}";
     504                output << indent << "}";
    497505        }
    498506
    499507        void CodeGenerator::visit( CaseStmt *caseStmt ) {
    500                 output << string( cur_indent, ' ' );
     508                output << indent;
    501509                if ( caseStmt->isDefault()) {
    502510                        output << "default";
     
    511519                cur_indent += CodeGenerator::tabsize;
    512520                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    513                         output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
     521                        output << indent << printLabels( (*i)->get_labels() )  ;
    514522                        (*i)->accept(*this );
    515523                        output << endl;
     
    564572                whileStmt->get_body()->accept( *this );
    565573
    566                 output << string( cur_indent, ' ' );
     574                output << indent;
    567575
    568576                if ( whileStmt->get_isDoWhile() ) {
     
    596604
    597605        void CodeGenerator::visit( NullStmt *nullStmt ) {
    598                 //output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( nullStmt->get_labels() );
     606                //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
    599607                output << "/* null statement */ ;";
    600608        }
Note: See TracChangeset for help on using the changeset viewer.