Changeset 8135d4c for src/CodeGen


Ignore:
Timestamp:
Aug 22, 2017, 7:31:52 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
9aaac6e9
Parents:
fc56cdbf (diff), b3d413b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into references

Location:
src/CodeGen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rfc56cdbf r8135d4c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 15:29:00 2017
    13 // Update Count     : 486
     12// Last Modified On : Fri Aug 18 15:34:00 2017
     13// Update Count     : 488
    1414//
    1515#include "CodeGenerator.h"
     
    7979        }
    8080
    81         CodeGenerator::LineMarker::LineMarker(
    82                         CodeLocation const & loc, bool toPrint) :
    83                 loc(loc), toPrint(toPrint)
    84         {}
    85 
    86         CodeGenerator::LineMarker CodeGenerator::lineDirective(
    87                         BaseSyntaxNode const * node) {
    88                 return LineMarker(node->location, lineMarks);
    89         }
    90 
    91         std::ostream & operator<<(std::ostream & out,
    92                         CodeGenerator::LineMarker const & marker) {
    93                 if (marker.toPrint && marker.loc.isSet()) {
    94                         return out << "\n# " << marker.loc.linenumber << " \""
    95                                 << marker.loc.filename << "\"\n";
    96                 } else if (marker.toPrint) {
    97                         return out << "\n/* Missing CodeLocation */\n";
    98                 } else {
    99                 return out;
     81        /* Using updateLocation at the beginning of a node and nextLine
     82         * within a node should become the method of formating.
     83         */
     84        void CodeGenerator::updateLocation( CodeLocation const & to ) {
     85                if ( !lineMarks ) {
     86                        return;
     87                } else if ( currentLocation.followedBy( to, 0 ) ) {
     88                        return;
     89                } else if ( currentLocation.followedBy( to, 1 ) ) {
     90                        output << "\n" << indent;
     91                        currentLocation.linenumber += 1;
     92                } else if ( currentLocation.followedBy( to, 2 ) ) {
     93                        output << "\n\n" << indent;
     94                        currentLocation.linenumber += 2;
     95                } else {
     96                        output << "\n# " << to.linenumber << " \"" << to.filename
     97                               << "\"\n" << indent;
     98                        currentLocation = to;
     99                }
     100                output << std::flush;
     101        }
     102
     103        void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) {
     104                updateLocation( to->location );
     105        }
     106
     107        void CodeGenerator::nextLine() {
     108                if ( !lineMarks ) {
     109                        output << "\n" << indent << std::flush;
    100110                }
    101111        }
     
    195205                        ++indent;
    196206                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    197                                 output << lineDirective( *i ) << indent;
     207                                updateLocation( *i );
    198208                                (*i)->accept( *this );
    199209                                output << ";" << endl;
     
    218228        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    219229                extension( enumDecl );
    220                 output << lineDirective ( enumDecl );
     230                updateLocation( enumDecl );
    221231                output << "enum ";
    222232                genAttributes( enumDecl->get_attributes() );
     
    234244                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    235245                                assert( obj );
    236                                 output << lineDirective( obj ) << indent << mangleName( obj );
     246                                updateLocation( obj );
     247                                output << mangleName( obj );
    237248                                if ( obj->get_init() ) {
    238249                                        output << " = ";
     
    252263        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    253264                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
    254                 output << lineDirective( typeDecl );
     265                updateLocation( typeDecl );
    255266                output << "typedef ";
    256267                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    741752        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    742753                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    743                 output << lineDirective( stmtExpr) << "({" << std::endl;
     754                updateLocation( stmtExpr );
     755                output << "({" << std::endl;
    744756                ++indent;
    745757                unsigned int numStmts = stmts.size();
    746758                unsigned int i = 0;
    747759                for ( Statement * stmt : stmts ) {
    748                         output << lineDirective( stmt ) << indent;
     760                        updateLocation( stmt );
    749761                        output << printLabels( stmt->get_labels() );
    750762                        if ( i+1 == numStmts ) {
     
    832844
    833845        void CodeGenerator::visit( IfStmt * ifStmt ) {
    834                 output << lineDirective( ifStmt );
     846                updateLocation( ifStmt );
    835847                output << "if ( ";
    836848                ifStmt->get_condition()->accept( *this );
     
    846858
    847859        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
    848                 output << lineDirective( switchStmt );
     860                updateLocation( switchStmt );
    849861                output << "switch ( " ;
    850862                switchStmt->get_condition()->accept( *this );
     
    859871
    860872        void CodeGenerator::visit( CaseStmt * caseStmt ) {
    861                 output << lineDirective( caseStmt );
    862                 output << indent;
     873                updateLocation( caseStmt );
    863874                if ( caseStmt->isDefault()) {
    864875                        output << "default";
  • src/CodeGen/CodeGenerator.h

    rfc56cdbf r8135d4c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 25:30:00 2017
    13 // Update Count     : 54
     12// Last Modified On : Fri Aug 18 15:40:00 2017
     13// Update Count     : 56
    1414//
    1515
     
    2121
    2222#include "Common/Indenter.h"      // for Indenter
    23 
    2423#include "SynTree/Declaration.h"  // for DeclarationWithType (ptr only), Fun...
    2524#include "SynTree/Visitor.h"      // for Visitor
    2625#include "SynTree/SynTree.h"      // for Visitor Nodes
    27 
    28 #include "Common/Indenter.h"      // for Indenter
    2926
    3027namespace CodeGen {
     
    113110                };
    114111
    115                 struct LineMarker {
    116                         CodeLocation const & loc;
    117                         bool toPrint;
    118 
    119                         LineMarker(CodeLocation const & loc, bool toPrint);
    120                 };
    121 
    122                 LineMarker lineDirective(BaseSyntaxNode const * node);
    123 
    124112                void asmName( DeclarationWithType *decl );
    125113
    126114                void extension( Expression *expr );
    127115                void extension( Declaration *decl );
     116
     117                void updateLocation( BaseSyntaxNode const * to );
    128118          private:
    129119                Indenter indent;
     
    134124                bool genC = false;    // true if output has to be C code
    135125                bool lineMarks = false;
     126
     127                CodeLocation currentLocation;
     128                void updateLocation( CodeLocation const & to );
     129                void nextLine();
    136130
    137131                void handleStorageClass( DeclarationWithType *decl );
     
    160154        /// returns C-compatible name of declaration
    161155        std::string genName( DeclarationWithType * decl );
    162 
    163         std::ostream & operator<<(std::ostream &,
    164                 CodeGenerator::LineMarker const &);
    165156} // namespace CodeGen
    166157
  • src/CodeGen/Generate.cc

    rfc56cdbf r8135d4c  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 19 13:05:00 2017
    13 // Update Count     : 6
     12// Last Modified On : Fri Aug 18 15:39:00 2017
     13// Update Count     : 7
    1414//
    1515#include "Generate.h"
     
    3333                for ( auto & dcl : translationUnit ) {
    3434                        if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
    35                                 os << cgv.lineDirective(dcl);
     35                                cgv.updateLocation( dcl );
    3636                                dcl->accept(cgv);
    3737                                if ( doSemicolon( dcl ) ) {
Note: See TracChangeset for help on using the changeset viewer.