Changeset 10a7775 for src/CodeGen


Ignore:
Timestamp:
Jun 3, 2016, 2:02:29 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, with_gc
Children:
e365cb5
Parents:
e01bfbc
Message:

can use intrinsic constructors on const objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/CodeGen/CodeGenerator.cc

    re01bfbc r10a7775  
    3333#include "OperatorTable.h"
    3434#include "GenType.h"
     35
     36#include "InitTweak/InitTweak.h"
    3537
    3638using namespace std;
     
    255257                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    256258                                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
    257282                                  case OT_PREFIXASSIGN:
    258283                                  case OT_POSTFIXASSIGN:
    259284                                  case OT_INFIXASSIGN:
    260                                   case OT_CTOR:
    261                                   case OT_DTOR:
    262285                                        {
    263286                                                assert( arg != applicationExpr->get_args().end() );
     
    269292                                                        UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    270293                                                        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 );
    271298                                                        *arg = newExpr;
    272299                                                } // if
Note: See TracChangeset for help on using the changeset viewer.