Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r03e5d14 rc2ce2350  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 15:40:35 2016
    13 // Update Count     : 243
     12// Last Modified On : Wed Apr 27 11:59:36 2016
     13// Update Count     : 255
    1414//
    1515
     
    6767        string mangleName( DeclarationWithType *decl ) {
    6868                if ( decl->get_mangleName() != "" ) {
    69                         return decl->get_mangleName();
     69                        // need to incorporate scope level in order to differentiate names for destructors
     70                        return decl->get_scopedMangleName();
    7071                } else {
    7172                        return decl->get_name();
     
    7576        //*** Declarations
    7677        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
    77                 // generalize this
    78                 FunctionDecl::Attribute attr = functionDecl->get_attribute();
    79                 switch ( attr.type ) {
    80                         case FunctionDecl::Attribute::Constructor:
    81                                 output << "__attribute__ ((constructor";
    82                                 if ( attr.priority != FunctionDecl::Attribute::Default ) {
    83                                         output << "(" << attr.priority << ")";
    84                                 }
    85                                 output << ")) ";
    86                                 break;
    87                         case FunctionDecl::Attribute::Destructor:
    88                                 output << "__attribute__ ((destructor";
    89                                 if ( attr.priority != FunctionDecl::Attribute::Default ) {
    90                                         output << "(" << attr.priority << ")";
    91                                 }
    92                                 output << ")) ";
    93                                 break;
    94                         default:
    95                                 break;
    96                 }
    9778                handleStorageClass( functionDecl );
    9879                if ( functionDecl->get_isInline() ) {
     
    233214                printDesignators( init->get_designators() );
    234215                output << "{ ";
    235                 genCommaList( init->begin_initializers(), init->end_initializers() );
     216                if ( init->begin_initializers() == init->end_initializers() ) {
     217                        // illegal to leave initializer list empty for scalar initializers,
     218                        // but always legal to have 0
     219                        output << "0";
     220                } else {
     221                        genCommaList( init->begin_initializers(), init->end_initializers() );
     222                }
    236223                output << " }";
    237224        }
     
    251238                                  case OT_POSTFIXASSIGN:
    252239                                  case OT_INFIXASSIGN:
     240                                  case OT_CTOR:
     241                                  case OT_DTOR:
    253242                                        {
    254243                                                assert( arg != applicationExpr->get_args().end() );
    255244                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    256 
     245                                                        // remove & from first assignment/ctor argument
    257246                                                        *arg = addrExpr->get_arg();
    258247                                                } else {
     248                                                        // no address-of operator, so must be a pointer - add dereference
    259249                                                        UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    260250                                                        newExpr->get_args().push_back( *arg );
     
    283273                                        break;
    284274
     275                                  case OT_CTOR:
     276                                  case OT_DTOR:
     277                                        if ( applicationExpr->get_args().size() == 1 ) {
     278                                                // the expression fed into a single parameter constructor or destructor
     279                                                // may contain side effects - output as a void expression
     280                                                output << "((void)(";
     281                                                (*arg++)->accept( *this );
     282                                                output << ")) /* " << opInfo.inputName << " */";
     283                                        } else if ( applicationExpr->get_args().size() == 2 ) {
     284                                                // intrinsic two parameter constructors are essentially bitwise assignment
     285                                                output << "(";
     286                                                (*arg++)->accept( *this );
     287                                                output << opInfo.symbol;
     288                                                (*arg)->accept( *this );
     289                                                output << ") /* " << opInfo.inputName << " */";
     290                                        } else {
     291                                                // no constructors with 0 or more than 2 parameters
     292                                                assert( false );
     293                                        }
     294                                        break;
     295
    285296                                  case OT_PREFIX:
    286297                                  case OT_PREFIXASSIGN:
     
    298309                                        output << opInfo.symbol;
    299310                                        break;
     311
    300312
    301313                                  case OT_INFIX:
     
    344356                                  case OT_CALL:
    345357                                        assert( false );
     358
     359
     360                                  case OT_CTOR:
     361                                  case OT_DTOR:
     362                                        if ( untypedExpr->get_args().size() == 1 ) {
     363                                                // the expression fed into a single parameter constructor or destructor
     364                                                // may contain side effects - output as a void expression
     365                                                output << "((void)(";
     366                                                (*arg++)->accept( *this );
     367                                                output << ")) /* " << opInfo.inputName << " */";
     368                                        } else if ( untypedExpr->get_args().size() == 2 ) {
     369                                                // intrinsic two parameter constructors are essentially bitwise assignment
     370                                                output << "(";
     371                                                (*arg++)->accept( *this );
     372                                                output << opInfo.symbol;
     373                                                (*arg)->accept( *this );
     374                                                output << ") /* " << opInfo.inputName << " */";
     375                                        } else {
     376                                                // no constructors with 0 or more than 2 parameters
     377                                                assert( false );
     378                                        }
    346379                                        break;
    347380
Note: See TracChangeset for help on using the changeset viewer.