Changeset 2b6c1e0


Ignore:
Timestamp:
Jun 2, 2015, 1:26:42 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:
b2152e7a
Parents:
6c4ff37
Message:

more output code formatting

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r6c4ff37 r2b6c1e0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jun 02 11:45:06 2015
    13 // Update Count     : 65
     12// Last Modified On : Tue Jun 02 13:25:22 2015
     13// Update Count     : 118
    1414//
    1515
     
    3636namespace CodeGen {
    3737        int CodeGenerator::tabsize = 4;
     38
     39        // the kinds of statements that would ideally be separated by more whitespace
     40        bool wantSpacing( Statement * stmt) {
     41                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
     42                        dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt );
     43        }
    3844
    3945        CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { }
     
    429435 
    430436        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
    431  
    432  
     437
    433438        //*** Statements
    434439        void CodeGenerator::visit( CompoundStmt *compoundStmt ) {
    435440                std::list<Statement*> ks = compoundStmt->get_kids();
    436 
    437                 output << endl << string( cur_indent, ' ' ) << "{" << endl;
    438 
    439                 cur_indent += CodeGenerator::tabsize;
     441                output << "{" << endl;
     442
     443                cur_indent += CodeGenerator::tabsize;
    440444
    441445                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    442                         output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
     446                        output << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() );
    443447                        (*i)->accept(*this );
     448
    444449                        output << endl;
     450                        if ( wantSpacing( *i ) ) {
     451                                output << endl;
     452                        }
    445453                }
    446454                cur_indent -= CodeGenerator::tabsize;
    447455
    448                 output << string( cur_indent, ' ' ) << "}" << endl;
     456                output << string( cur_indent, ' ' ) << "}";
    449457        }
    450458
     
    464472                output << "if (";
    465473                ifStmt->get_condition()->accept(*this );
    466                 output << ")\n";
    467 
    468                 cur_indent += CodeGenerator::tabsize;
    469                 output << string( cur_indent, ' ' );
     474                output << ") ";
     475
    470476                ifStmt->get_thenPart()->accept(*this );
    471                 cur_indent -= CodeGenerator::tabsize;
    472                 output << endl;
    473477
    474478                if ( ifStmt->get_elsePart() != 0) {
    475                         output << string( cur_indent, ' ' ) << " else " << endl ;
    476 
    477                         cur_indent += CodeGenerator::tabsize;
     479                        output << " else ";
    478480                        ifStmt->get_elsePart()->accept(*this );
    479                         cur_indent -= CodeGenerator::tabsize;
    480481                } // if
    481482        }
     
    485486                output << "switch (" ;
    486487                switchStmt->get_condition()->accept(*this );
    487                 output << ")\n";
     488                output << ") ";
    488489               
    489                 output << string( cur_indent, ' ' ) << "{" << std::endl;
     490                output << "{" << std::endl;
    490491                cur_indent += CodeGenerator::tabsize;
    491492
     
    494495                cur_indent -= CodeGenerator::tabsize;
    495496
    496                 output << /* "\r" << */ string( cur_indent, ' ' ) << "}" << endl;
     497                output << string( cur_indent, ' ' ) << "}";
    497498        }
    498499
     
    500501                output << string( cur_indent, ' ' );
    501502                if ( caseStmt->isDefault())
    502                         output << "default"  ;
     503                        output << "default";
    503504                else {
    504                         output << "case "  ;
     505                        output << "case ";
    505506                        caseStmt->get_condition()->accept(*this );
    506507                } // if
     
    540541                        break;
    541542                }
    542                 output << ";" << endl;
     543                output << ";";
    543544        }
    544545
     
    562563                        output << ")";
    563564                } // if
    564                 output << "\n";
    565 
    566                 output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( whileStmt->get_body()->get_labels() );
     565                output << " ";
     566
     567                output << CodeGenerator::printLabels( whileStmt->get_body()->get_labels() );
    567568                whileStmt->get_body()->accept( *this );
    568569
     
    574575                        output << ");";
    575576                } // if
    576 
    577                 output << "\n";
    578577        }
    579578
     
    592591                if ( forStmt->get_increment() != 0 )
    593592                        forStmt->get_increment()->accept( *this );
    594                 output << ")" << endl;
     593                output << ") ";
    595594
    596595                if ( forStmt->get_body() != 0 ) {
    597                         output << string( cur_indent, ' ' ) << CodeGenerator::printLabels( forStmt->get_body()->get_labels() );
     596                        output << CodeGenerator::printLabels( forStmt->get_body()->get_labels() );
    598597                        forStmt->get_body()->accept( *this );
    599598                } // if
  • src/CodeGen/CodeGenerator.h

    r6c4ff37 r2b6c1e0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jun 02 11:45:20 2015
    13 // Update Count     : 9
     12// Last Modified On : Tue Jun 02 13:25:09 2015
     13// Update Count     : 12
    1414//
    1515
     
    3232                CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
    3333                CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
    34 
    35                 CodeGenerator( CodeGenerator & );
    3634
    3735                //*** Declaration
Note: See TracChangeset for help on using the changeset viewer.