Changeset 0a81c3f


Ignore:
Timestamp:
Jul 13, 2017, 1:44:58 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
2463d0e
Parents:
c6976ba
Message:

Remove several missing-reference related hacks

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rc6976ba r0a81c3f  
    338338                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
    339339                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    340                                 switch ( opInfo.type ) {
    341                                   case OT_PREFIXASSIGN:
    342                                   case OT_POSTFIXASSIGN:
    343                                   case OT_INFIXASSIGN:
    344                                   case OT_CTOR:
    345                                   case OT_DTOR:
    346                                         {
    347                                                 assert( arg != applicationExpr->get_args().end() );
    348                                                 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    349                                                         // remove & from first assignment/ctor argument
    350                                                         *arg = addrExpr->get_arg();
    351                                                 } else {
    352                                                         // no address-of operator, so must be a pointer - add dereference
    353                                                         // NOTE: if the assertion starts to trigger, check that the application expr isn't being shared.
    354                                                         // Since its arguments are modified here, this assertion most commonly triggers when the application
    355                                                         // is visited multiple times.
    356                                                         UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    357                                                         newExpr->get_args().push_back( *arg );
    358                                                         Type * type = InitTweak::getPointerBase( (*arg)->get_result() );
    359                                                         assertf( type, "First argument to a derefence must be a pointer. Ensure that expressions are not being shared." );
    360                                                         newExpr->set_result( type->clone() );
    361                                                         *arg = newExpr;
    362                                                 } // if
    363                                                 break;
    364                                         }
    365 
    366                                   default:
    367                                         // do nothing
    368                                         ;
    369                                 } // switch
    370 
    371340                                switch ( opInfo.type ) {
    372341                                  case OT_INDEX:
  • src/GenPoly/Box.cc

    rc6976ba r0a81c3f  
    758758                                        // if the argument's type is polymorphic, we don't need to box again!
    759759                                        return;
    760                                 } else if ( arg->get_result()->get_lvalue() ) {
     760                                } else if ( arg->get_result()->get_lvalue() ) {  // xxx - is this still right??
     761                                // xxx - dynamic_cast<ReferenceType *>( arg->get_result() )??
    761762                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
    762763                                        // xxx - need to test that this code is still reachable
     
    10361037                                                assert( appExpr->has_result() );
    10371038                                                assert( ! appExpr->get_args().empty() );
    1038                                                 if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) {
     1039                                                if ( isPolyPtr( appExpr->get_result(), scopeTyVars, env ) ) { // dereference returns a reference type
     1040                                                        // remove dereference from polymorphic types since they are boxed.
    10391041                                                        Expression *ret = appExpr->get_args().front();
    10401042                                                        delete ret->get_result();
  • src/InitTweak/FixInit.cc

    rc6976ba r0a81c3f  
    364364                                        assert( ftype );
    365365                                        if ( isConstructor( funcDecl->get_name() ) && ftype->get_parameters().size() == 2 ) {
    366                                                 Type * t1 = ftype->get_parameters().front()->get_type();
     366                                                Type * t1 = getPointerBase( ftype->get_parameters().front()->get_type() );
    367367                                                Type * t2 = ftype->get_parameters().back()->get_type();
    368                                                 PointerType * ptrType = safe_dynamic_cast< PointerType * > ( t1 );
    369 
    370                                                 if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) {
     368                                                assert( t1 );
     369
     370                                                if ( ResolvExpr::typesCompatible( t1, t2, SymTab::Indexer() ) ) {
    371371                                                        // optimization: don't need to copy construct in order to call a copy constructor
    372372                                                        return appExpr;
     
    489489                                impCpCtorExpr->get_returnDecls().push_back( ret );
    490490                                CP_CTOR_PRINT( std::cerr << "makeCtorDtor for a return" << std::endl; )
    491                                 if ( ! result->get_lvalue() ) {
     491                                if ( ! dynamic_cast< ReferenceType * >( result ) ) {
    492492                                        // destructing lvalue returns is bad because it can cause multiple destructor calls to the same object - the returned object is not a temporary
    493493                                        destructRet( ret, impCpCtorExpr );
     
    997997                                assert( ! type->get_parameters().empty() );
    998998                                thisParam = safe_dynamic_cast< ObjectDecl * >( type->get_parameters().front() );
    999                                 PointerType * ptrType = safe_dynamic_cast< PointerType * > ( thisParam->get_type() );
    1000                                 StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() );
     999                                Type * thisType = getPointerBase( thisParam->get_type() );
     1000                                StructInstType * structType = dynamic_cast< StructInstType * >( thisType );
    10011001                                if ( structType ) {
    10021002                                        structDecl = structType->get_baseStruct();
     
    10461046                                        // insert and resolve default/copy constructor call for each field that's unhandled
    10471047                                        std::list< Statement * > stmt;
    1048                                         UntypedExpr * deref = UntypedExpr::createDeref( new VariableExpr( thisParam ) );
    1049 
    10501048                                        Expression * arg2 = 0;
    10511049                                        if ( isCopyConstructor( function ) ) {
     
    10561054                                        }
    10571055                                        InitExpander srcParam( arg2 );
    1058                                         SymTab::genImplicitCall( srcParam, new MemberExpr( field, deref ), function->get_name(), back_inserter( stmt ), field, isCtor );
     1056                                        SymTab::genImplicitCall( srcParam, new MemberExpr( field, new VariableExpr( thisParam ) ), function->get_name(), back_inserter( stmt ), field, isCtor );
    10591057
    10601058                                        assert( stmt.size() <= 1 );
Note: See TracChangeset for help on using the changeset viewer.