Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r262f085f r6e300d9  
    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()) {
Note: See TracChangeset for help on using the changeset viewer.