Ignore:
Timestamp:
Sep 15, 2015, 1:58:27 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
18387ef, c8fcda2
Parents:
32a1e5fd
Message:

drop cast when the result type is an lvalue type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r32a1e5fd r76b48f1  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Sep 11 12:59:09 2015
    13 // Update Count     : 223
     12// Last Modified On : Tue Sep 15 13:55:27 2015
     13// Update Count     : 230
    1414//
    1515
     
    322322             
    323323                                  case OT_CALL:
     324                                  case OT_CTOR:
     325                                  case OT_DTOR:
    324326                                        assert( false );
    325327                                        break;
     
    392394
    393395        void CodeGenerator::visit( CastExpr *castExpr ) {
    394                 output << "((";
    395                 if ( castExpr->get_results().empty() ) {
    396                         output << "void" ;
    397                 } else {
    398                         output << genType( castExpr->get_results().front(), "" );
    399                 } // if
    400                 output << ")";
    401                 castExpr->get_arg()->accept( *this );
    402                 output << ")";
     396                // if the cast is to an lvalue type, then the cast
     397                // should be dropped, since the result of a cast is
     398                // never an lvalue in C
     399                if ( castExpr->get_results().front()->get_isLvalue() ) {
     400                        castExpr->get_arg()->accept( *this );
     401                } else {
     402                        output << "((";
     403                        if ( castExpr->get_results().empty() ) {
     404                                output << "void" ;
     405                        } else {
     406                                output << genType( castExpr->get_results().front(), "" );
     407                        } // if
     408                        output << ")";
     409                        castExpr->get_arg()->accept( *this );
     410                        output << ")";                 
     411                }
    403412        }
    404413 
Note: See TracChangeset for help on using the changeset viewer.