Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r29cf9c8 r5f642e38  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tus May  9 16:50:00 2017
    13 // Update Count     : 484
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Mar 30 16:38:01 2017
     13// Update Count     : 482
    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         }
    5643
    5744        // the kinds of statements that would ideally be followed by whitespace
     
    141128
    142129
    143         // *** Declarations
     130        //*** Declarations
    144131        void CodeGenerator::visit( FunctionDecl * functionDecl ) {
    145                 output << lineDirective( functionDecl );
    146 
    147132                extension( functionDecl );
    148133                genAttributes( functionDecl->get_attributes() );
     
    168153                }
    169154
    170                 output << lineDirective( objectDecl );
    171 
    172155                extension( objectDecl );
    173156                genAttributes( objectDecl->get_attributes() );
     
    209192                        cur_indent += CodeGenerator::tabsize;
    210193                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    211                                 output << lineDirective( *i ) << indent;
     194                                output << indent;
    212195                                (*i)->accept( *this );
    213196                                output << ";" << endl;
     
    221204
    222205        void CodeGenerator::visit( StructDecl * structDecl ) {
    223                 output << lineDirective( structDecl );
    224 
    225206                extension( structDecl );
    226207                handleAggregate( structDecl, "struct " );
     
    228209
    229210        void CodeGenerator::visit( UnionDecl * unionDecl ) {
    230                 output << lineDirective( unionDecl );
    231 
    232211                extension( unionDecl );
    233212                handleAggregate( unionDecl, "union " );
     
    236215        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    237216                extension( enumDecl );
    238                 output << lineDirective ( enumDecl );
    239217                output << "enum ";
    240218                genAttributes( enumDecl->get_attributes() );
     
    252230                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    253231                                assert( obj );
    254                                 output << lineDirective( obj ) << indent << mangleName( obj );
     232                                output << indent << mangleName( obj );
    255233                                if ( obj->get_init() ) {
    256234                                        output << " = ";
     
    270248        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    271249                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
    272                 output << lineDirective( typeDecl );
    273250                output << "typedef ";
    274251                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    285262                        } // if
    286263                } else {
    287                         output << typeDecl->genTypeString() << " " << typeDecl->get_name();
    288                         if ( typeDecl->get_kind() != TypeDecl::Any && typeDecl->get_sized() ) {
    289                                 output << " | sized(" << typeDecl->get_name() << ")";
    290                         }
     264                        output << typeDecl->typeString() << " " << typeDecl->get_name();
    291265                        if ( ! typeDecl->get_assertions().empty() ) {
    292266                                output << " | { ";
     
    342316        }
    343317
    344         // *** Expressions
     318        //*** Expressions
    345319        void CodeGenerator::visit( ApplicationExpr * applicationExpr ) {
    346320                extension( applicationExpr );
     
    745719        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    746720                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    747                 output << lineDirective( stmtExpr) << "({" << std::endl;
     721                output << "({" << std::endl;
    748722                cur_indent += CodeGenerator::tabsize;
    749723                unsigned int numStmts = stmts.size();
    750724                unsigned int i = 0;
    751725                for ( Statement * stmt : stmts ) {
    752                         output << lineDirective( stmt ) << indent;
    753             output << printLabels( stmt->get_labels() );
     726                        output << indent << printLabels( stmt->get_labels() );
    754727                        if ( i+1 == numStmts ) {
    755728                                // last statement in a statement expression needs to be handled specially -
     
    773746        }
    774747
    775         // *** Statements
     748        //*** Statements
    776749        void CodeGenerator::visit( CompoundStmt * compoundStmt ) {
    777750                std::list<Statement*> ks = compoundStmt->get_kids();
     
    796769        void CodeGenerator::visit( ExprStmt * exprStmt ) {
    797770                assert( exprStmt );
    798                 Expression * expr = exprStmt->get_expr();
    799                 if ( genC ) {
    800                         // cast the top-level expression to void to reduce gcc warnings.
    801                         expr = new CastExpr( expr );
    802                 }
     771                // cast the top-level expression to void to reduce gcc warnings.
     772                Expression * expr = new CastExpr( exprStmt->get_expr() );
    803773                expr->accept( *this );
    804774                output << ";";
     
    837807
    838808        void CodeGenerator::visit( IfStmt * ifStmt ) {
    839                 output << lineDirective( ifStmt );
    840809                output << "if ( ";
    841810                ifStmt->get_condition()->accept( *this );
     
    851820
    852821        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
    853                 output << lineDirective( switchStmt );
    854822                output << "switch ( " ;
    855823                switchStmt->get_condition()->accept( *this );
     
    864832
    865833        void CodeGenerator::visit( CaseStmt * caseStmt ) {
    866                 output << lineDirective( caseStmt );
    867834                output << indent;
    868835                if ( caseStmt->isDefault()) {
Note: See TracChangeset for help on using the changeset viewer.