Changes in / [5916272:4cc585b]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r5916272 r4cc585b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:34:00 2017
    13 // Update Count     : 488
     12// Last Modified On : Tus Jul 25 15:29:00 2017
     13// Update Count     : 486
    1414//
    1515#include "CodeGenerator.h"
     
    7979        }
    8080
    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;
     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;
    110100                }
    111101        }
     
    204194                        ++indent;
    205195                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    206                                 updateLocation( *i );
     196                                output << lineDirective( *i ) << indent;
    207197                                (*i)->accept( *this );
    208198                                output << ";" << endl;
     
    227217        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    228218                extension( enumDecl );
    229                 updateLocation( enumDecl );
     219                output << lineDirective ( enumDecl );
    230220                output << "enum ";
    231221                genAttributes( enumDecl->get_attributes() );
     
    243233                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    244234                                assert( obj );
    245                                 updateLocation( obj );
    246                                 output << mangleName( obj );
     235                                output << lineDirective( obj ) << indent << mangleName( obj );
    247236                                if ( obj->get_init() ) {
    248237                                        output << " = ";
     
    262251        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    263252                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
    264                 updateLocation( typeDecl );
     253                output << lineDirective( typeDecl );
    265254                output << "typedef ";
    266255                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    763752        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    764753                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    765                 updateLocation( stmtExpr );
    766                 output << "({" << std::endl;
     754                output << lineDirective( stmtExpr) << "({" << std::endl;
    767755                ++indent;
    768756                unsigned int numStmts = stmts.size();
    769757                unsigned int i = 0;
    770758                for ( Statement * stmt : stmts ) {
    771                         updateLocation( stmt );
     759                        output << lineDirective( stmt ) << indent;
    772760            output << printLabels( stmt->get_labels() );
    773761                        if ( i+1 == numStmts ) {
     
    856844
    857845        void CodeGenerator::visit( IfStmt * ifStmt ) {
    858                 updateLocation( ifStmt );
     846                output << lineDirective( ifStmt );
    859847                output << "if ( ";
    860848                ifStmt->get_condition()->accept( *this );
     
    870858
    871859        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
    872                 updateLocation( switchStmt );
     860                output << lineDirective( switchStmt );
    873861                output << "switch ( " ;
    874862                switchStmt->get_condition()->accept( *this );
     
    883871
    884872        void CodeGenerator::visit( CaseStmt * caseStmt ) {
    885                 updateLocation( caseStmt );
     873                output << lineDirective( caseStmt );
     874                output << indent;
    886875                if ( caseStmt->isDefault()) {
    887876                        output << "default";
  • src/CodeGen/CodeGenerator.h

    r5916272 r4cc585b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:40:00 2017
    13 // Update Count     : 56
     12// Last Modified On : Tus Jul 25 25:30:00 2017
     13// Update Count     : 54
    1414//
    1515
     
    108108                };
    109109
     110                struct LineMarker {
     111                        CodeLocation const & loc;
     112                        bool toPrint;
     113
     114                        LineMarker(CodeLocation const & loc, bool toPrint);
     115                };
     116
     117                LineMarker lineDirective(BaseSyntaxNode const * node);
     118
    110119                void asmName( DeclarationWithType *decl );
    111120
    112121                void extension( Expression *expr );
    113122                void extension( Declaration *decl );
    114 
    115                 void updateLocation( BaseSyntaxNode const * to );
    116123          private:
    117124                Indenter indent;
     
    122129                bool genC = false;    // true if output has to be C code
    123130                bool lineMarks = false;
    124 
    125                 CodeLocation currentLocation;
    126                 void updateLocation( CodeLocation const & to );
    127                 void nextLine();
    128131
    129132                void handleStorageClass( DeclarationWithType *decl );
     
    152155        /// returns C-compatible name of declaration
    153156        std::string genName( DeclarationWithType * decl );
     157
     158        std::ostream & operator<<(std::ostream &,
     159                CodeGenerator::LineMarker const &);
    154160} // namespace CodeGen
    155161
  • src/CodeGen/Generate.cc

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

    r5916272 r4cc585b  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 10:22:00 2017
    13 // Update Count     : 12
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 15:32:46 2017
     13// Update Count     : 11
    1414//
    1515
     
    2121
    2222namespace ControlStruct {
    23         Statement *hoist( Statement *originalStmt, std::list<Statement *> &init ) {
    24                 // If no hoisting is needed, skip:
    25                 if ( 0 == init.size() ) {
    26                         return originalStmt;
    27                 }
     23        Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
     24                std::list<Statement *> &init = ifStmt->get_initialization();
     25                if ( init.size() == 0 ) {
     26                        return ifStmt;
     27                } // if
    2828
    29                 // Create compound statement, move initializers outside,
    30                 // the resut of the original stays as is.
     29                // create compound statement, move initializers outside, leave _for_ as-is
    3130                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    3231                std::list<Statement *> &stmts = block->get_kids();
    3332                stmts.splice( stmts.end(), init );
    3433
    35                 // Add for to the new block.
    36                 stmts.push_back( originalStmt );
     34                // add for to the new block
     35                stmts.push_back( ifStmt );
    3736                return block;
    3837        }
    3938
    40         Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
    41                 return hoist( ifStmt, ifStmt->initialization );
    42         }
    4339        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    4440                // hoist any initializer declarations to make them C89 (rather than C99)
    45                 return hoist( forStmt, forStmt->initialization );
     41                std::list<Statement *> &init = forStmt->get_initialization();
     42                if ( init.size() == 0 ) {
     43                        return forStmt;
     44                } // if
     45
     46                // create compound statement, move initializers outside, leave _for_ as-is
     47                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     48                std::list<Statement *> &stmts = block->get_kids();
     49                stmts.splice( stmts.end(), init );
     50
     51                // add for to the new block
     52                stmts.push_back( forStmt );
     53                return block;
    4654        }
    4755} // namespace ControlStruct
Note: See TracChangeset for help on using the changeset viewer.