Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rc2ce2350 r03e5d14  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Apr 27 11:59:36 2016
    13 // Update Count     : 255
     12// Last Modified On : Fri May 06 15:40:35 2016
     13// Update Count     : 243
    1414//
    1515
     
    6767        string mangleName( DeclarationWithType *decl ) {
    6868                if ( decl->get_mangleName() != "" ) {
    69                         // need to incorporate scope level in order to differentiate names for destructors
    70                         return decl->get_scopedMangleName();
     69                        return decl->get_mangleName();
    7170                } else {
    7271                        return decl->get_name();
     
    7675        //*** Declarations
    7776        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                }
    7897                handleStorageClass( functionDecl );
    7998                if ( functionDecl->get_isInline() ) {
     
    214233                printDesignators( init->get_designators() );
    215234                output << "{ ";
    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                 }
     235                genCommaList( init->begin_initializers(), init->end_initializers() );
    223236                output << " }";
    224237        }
     
    238251                                  case OT_POSTFIXASSIGN:
    239252                                  case OT_INFIXASSIGN:
    240                                   case OT_CTOR:
    241                                   case OT_DTOR:
    242253                                        {
    243254                                                assert( arg != applicationExpr->get_args().end() );
    244255                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    245                                                         // remove & from first assignment/ctor argument
     256
    246257                                                        *arg = addrExpr->get_arg();
    247258                                                } else {
    248                                                         // no address-of operator, so must be a pointer - add dereference
    249259                                                        UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    250260                                                        newExpr->get_args().push_back( *arg );
     
    273283                                        break;
    274284
    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 
    296285                                  case OT_PREFIX:
    297286                                  case OT_PREFIXASSIGN:
     
    309298                                        output << opInfo.symbol;
    310299                                        break;
    311 
    312300
    313301                                  case OT_INFIX:
     
    356344                                  case OT_CALL:
    357345                                        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                                         }
    379346                                        break;
    380347
Note: See TracChangeset for help on using the changeset viewer.