Changes in / [19801aa:66ef082]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r19801aa r66ef082  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 16:38:01 2017
    13 // Update Count     : 482
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus May  9 14:32:00 2017
     13// Update Count     : 483
    1414//
    1515
     
    4141namespace CodeGen {
    4242        int CodeGenerator::tabsize = 4;
     43
     44        // Pseudo Function: output << lineDirective(*currentNode);
     45    struct lineDirective {
     46        CodeLocation const & loc;
     47                lineDirective(CodeLocation const & location) : loc(location) {}
     48                lineDirective(BaseSyntaxNode const * node) : loc(node->location) {}
     49        };
     50        std::ostream & operator<<(std::ostream & out, lineDirective const & ld) {
     51                if (ld.loc.isSet())
     52                        return out << "\n# " << ld.loc.linenumber << " \""
     53                                << ld.loc.filename << "\"\n";
     54                return out << "\n// Unset Location\n";
     55        }
    4356
    4457        // the kinds of statements that would ideally be followed by whitespace
     
    128141
    129142
    130         //*** Declarations
     143        // *** Declarations
    131144        void CodeGenerator::visit( FunctionDecl * functionDecl ) {
    132145                extension( functionDecl );
     
    182195                }
    183196
    184                 output << kind;
     197                output << lineDirective( aggDecl ) << kind;
    185198                if ( aggDecl->get_name() != "" )
    186199                        output << aggDecl->get_name();
     
    192205                        cur_indent += CodeGenerator::tabsize;
    193206                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    194                                 output << indent;
     207                                output << lineDirective( *i ) << indent;
    195208                                (*i)->accept( *this );
    196209                                output << ";" << endl;
     
    215228        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    216229                extension( enumDecl );
     230                output << lineDirective ( enumDecl );
    217231                output << "enum ";
    218232                genAttributes( enumDecl->get_attributes() );
     
    230244                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    231245                                assert( obj );
    232                                 output << indent << mangleName( obj );
     246                                output << lineDirective( obj ) << indent << mangleName( obj );
    233247                                if ( obj->get_init() ) {
    234248                                        output << " = ";
     
    248262        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    249263                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
     264                output << lineDirective( typeDecl );
    250265                output << "typedef ";
    251266                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    319334        }
    320335
    321         //*** Expressions
     336        // *** Expressions
    322337        void CodeGenerator::visit( ApplicationExpr * applicationExpr ) {
    323338                extension( applicationExpr );
     
    722737        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    723738                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    724                 output << "({" << std::endl;
     739                output << lineDirective( stmtExpr) << "({" << std::endl;
    725740                cur_indent += CodeGenerator::tabsize;
    726741                unsigned int numStmts = stmts.size();
    727742                unsigned int i = 0;
    728743                for ( Statement * stmt : stmts ) {
    729                         output << indent << printLabels( stmt->get_labels() );
     744                        output << lineDirective( stmt ) << indent;
     745            output << printLabels( stmt->get_labels() );
    730746                        if ( i+1 == numStmts ) {
    731747                                // last statement in a statement expression needs to be handled specially -
     
    749765        }
    750766
    751         //*** Statements
     767        // *** Statements
    752768        void CodeGenerator::visit( CompoundStmt * compoundStmt ) {
    753769                std::list<Statement*> ks = compoundStmt->get_kids();
     
    813829
    814830        void CodeGenerator::visit( IfStmt * ifStmt ) {
     831                output << lineDirective( ifStmt );
    815832                output << "if ( ";
    816833                ifStmt->get_condition()->accept( *this );
     
    826843
    827844        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
     845                output << lineDirective( switchStmt );
    828846                output << "switch ( " ;
    829847                switchStmt->get_condition()->accept( *this );
     
    838856
    839857        void CodeGenerator::visit( CaseStmt * caseStmt ) {
     858                output << lineDirective( caseStmt );
    840859                output << indent;
    841860                if ( caseStmt->isDefault()) {
  • src/CodeGen/LineStream.cc

    r19801aa r66ef082  
    1010// Created On       : Thr May 4 13:15:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 5 14:29:00 2017
     12// Last Modified On : Mon May 8 12:08:00 2017
    1313// Update Count     : 0
    1414//
     
    1717
    1818namespace CodeGen {
    19 
    20         LineStream::LineStream(std::ostream & baseStream, bool insertLines) :
    21                 baseStream(baseStream), insertLines(insertLines)
    22         {}
    2319
    2420        void LineStream::printLineDirective(CodeLocation const & location) {
     
    4440                actualLocation.unset();
    4541
    46                 if (addNewLine) {
     42                if (addNewline) {
    4743                        expectedLocation.linenumber += 1;
    4844                        buffer.put('\n');
     
    7975
    8076        LineStream & LineStream::operator<<(StreamFlag flag) {
    81                 static StringFlag const endlCopy = std::endl;
     77                static StreamFlag const endlCopy = std::endl;
    8278                if (!insertLines) {
    8379                        baseStream << flag;
  • src/CodeGen/LineStream.h

    r19801aa r66ef082  
    1010// Created On       : Wed May 4 09:15:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri May 5 14:29:00 2017
     12// Last Modified On : Mon May 8 14:03:00 2017
    1313// Update Count     : 1
    1414//
     
    2525namespace CodeGen {
    2626
    27         class LineStream : public std::ostream {
     27        class LineStream {
    2828                std::ostream & baseStream;
    2929                std::ostringstream buffer;
     
    4949
    5050                /// Formated output is buffered until flushed.
    51                 std::ostream & operator<<(char const *str);
    52                 std::ostream & operator<<(std::string str);
    53                 std::ostream & operator<<(StreamFlag flag);
     51                LineStream & operator<<(char const *str);
     52                LineStream & operator<<(std::string const & str);
     53                LineStream & operator<<(StreamFlag flag);
     54
     55                /// Flush all buffered output.
     56                LineStream & flush();
    5457
    5558        }; // LineStream
  • src/main.cc

    r19801aa r66ef082  
    3737#include "CodeGen/FixMain.h"
    3838#include "CodeTools/DeclStats.h"
     39#include "CodeTools/TrackLoc.h"
    3940#include "ControlStruct/Mutate.h"
    4041#include "SymTab/Validate.h"
     
    308309                } // if
    309310
     311                CodeTools::fillLocations( translationUnit );
    310312                CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true );
    311313
Note: See TracChangeset for help on using the changeset viewer.