Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r10a7775 r03e5d14  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 16:01:00 2016
    13 // Update Count     : 255
     12// Last Modified On : Fri May 06 15:40:35 2016
     13// Update Count     : 243
    1414//
    1515
     
    3434#include "GenType.h"
    3535
    36 #include "InitTweak/InitTweak.h"
    37 
    3836using namespace std;
    3937
     
    6967        string mangleName( DeclarationWithType *decl ) {
    7068                if ( decl->get_mangleName() != "" ) {
    71                         // need to incorporate scope level in order to differentiate names for destructors
    72                         return decl->get_scopedMangleName();
     69                        return decl->get_mangleName();
    7370                } else {
    7471                        return decl->get_name();
     
    236233                printDesignators( init->get_designators() );
    237234                output << "{ ";
    238                 if ( init->begin_initializers() == init->end_initializers() ) {
    239                         // illegal to leave initializer list empty for scalar initializers,
    240                         // but always legal to have 0
    241                         output << "0";
    242                 } else {
    243                         genCommaList( init->begin_initializers(), init->end_initializers() );
    244                 }
     235                genCommaList( init->begin_initializers(), init->end_initializers() );
    245236                output << " }";
    246237        }
     
    257248                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    258249                                switch ( opInfo.type ) {
    259                                   case OT_CTOR:
    260                                   case OT_DTOR:
    261                                         {
    262                                                 // if the first argument's type is const then GCC complains. In this
    263                                                 // case, output an explicit ctor/dtor call and exit, rather than following
    264                                                 // the normal path
    265                                                 assert( arg != applicationExpr->get_args().end() );
    266                                                 assert( (*arg)->get_results().size() >= 1 );
    267                                                 Type * baseType = InitTweak::getPointerBase( (*arg)->get_results().front() );
    268                                                 if ( baseType->get_isConst() ) {
    269                                                         // cast away the qualifiers, to eliminate warnings
    270                                                         Type * newType = baseType->clone();
    271                                                         newType->get_qualifiers() = Type::Qualifiers();
    272                                                         *arg = new CastExpr( *arg, new PointerType( Type::Qualifiers(), newType ) );
    273                                                         varExpr->accept( *this );
    274                                                         output << "(";
    275                                                         genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
    276                                                         output << ")";
    277                                                         return;
    278                                                 }
    279                                         }
    280                                         // intentional fallthrough - instrinsic ctor/dtor for non-const objects should
    281                                         // be handled the same way as assignment
    282250                                  case OT_PREFIXASSIGN:
    283251                                  case OT_POSTFIXASSIGN:
     
    286254                                                assert( arg != applicationExpr->get_args().end() );
    287255                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    288                                                         // remove & from first assignment/ctor argument
     256
    289257                                                        *arg = addrExpr->get_arg();
    290258                                                } else {
    291                                                         // no address-of operator, so must be a pointer - add dereference
    292259                                                        UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    293260                                                        newExpr->get_args().push_back( *arg );
    294                                                         assert( (*arg)->get_results().size() == 1 );
    295                                                         Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() );
    296                                                         assert( type );
    297                                                         newExpr->get_results().push_back( type );
    298261                                                        *arg = newExpr;
    299262                                                } // if
     
    320283                                        break;
    321284
    322                                   case OT_CTOR:
    323                                   case OT_DTOR:
    324                                         if ( applicationExpr->get_args().size() == 1 ) {
    325                                                 // the expression fed into a single parameter constructor or destructor
    326                                                 // may contain side effects - output as a void expression
    327                                                 output << "((void)(";
    328                                                 (*arg++)->accept( *this );
    329                                                 output << ")) /* " << opInfo.inputName << " */";
    330                                         } else if ( applicationExpr->get_args().size() == 2 ) {
    331                                                 // intrinsic two parameter constructors are essentially bitwise assignment
    332                                                 output << "(";
    333                                                 (*arg++)->accept( *this );
    334                                                 output << opInfo.symbol;
    335                                                 (*arg)->accept( *this );
    336                                                 output << ") /* " << opInfo.inputName << " */";
    337                                         } else {
    338                                                 // no constructors with 0 or more than 2 parameters
    339                                                 assert( false );
    340                                         }
    341                                         break;
    342 
    343285                                  case OT_PREFIX:
    344286                                  case OT_PREFIXASSIGN:
     
    356298                                        output << opInfo.symbol;
    357299                                        break;
    358 
    359300
    360301                                  case OT_INFIX:
     
    403344                                  case OT_CALL:
    404345                                        assert( false );
    405 
    406 
    407                                   case OT_CTOR:
    408                                   case OT_DTOR:
    409                                         if ( untypedExpr->get_args().size() == 1 ) {
    410                                                 // the expression fed into a single parameter constructor or destructor
    411                                                 // may contain side effects - output as a void expression
    412                                                 output << "((void)(";
    413                                                 (*arg++)->accept( *this );
    414                                                 output << ")) /* " << opInfo.inputName << " */";
    415                                         } else if ( untypedExpr->get_args().size() == 2 ) {
    416                                                 // intrinsic two parameter constructors are essentially bitwise assignment
    417                                                 output << "(";
    418                                                 (*arg++)->accept( *this );
    419                                                 output << opInfo.symbol;
    420                                                 (*arg)->accept( *this );
    421                                                 output << ") /* " << opInfo.inputName << " */";
    422                                         } else {
    423                                                 // no constructors with 0 or more than 2 parameters
    424                                                 assert( false );
    425                                         }
    426346                                        break;
    427347
Note: See TracChangeset for help on using the changeset viewer.