Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    ra181494 r93401f8  
    204204        } // namespace
    205205
    206         void referenceToRvalueConversion( Expression *& expr, Cost & cost ) {
     206        void referenceToRvalueConversion( Expression *& expr ) {
    207207                if ( dynamic_cast< ReferenceType * >( expr->get_result() ) ) {
    208208                        // cast away reference from expr
    209209                        expr = new CastExpr( expr, expr->get_result()->stripReferences()->clone() );
    210                         cost.incReference();
    211210                }
    212211        }
     
    436435                                        PRINT( std::cerr << "end of formals with varargs function: inc unsafe: " << convCost << std::endl; ; )
    437436                                        // convert reference-typed expressions to value-typed expressions
    438                                         referenceToRvalueConversion( *actualExpr, convCost );
     437                                        referenceToRvalueConversion( *actualExpr );
    439438                                        continue;
    440439                                } else {
     
    566565                                // DOESN'T WORK: grandchild nodes conflict with their cousins
    567566                                //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;
    568 
    569                                 Expression *varExpr = data.combine( newerAlt.cost );
     567                                Expression *varExpr = data.combine();
    570568                                delete varExpr->get_result();
    571569                                varExpr->set_result( adjType->clone() );
     
    11231121                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    11241122                                                Alternative newFunc( *func );
    1125                                                 referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     1123                                                referenceToRvalueConversion( newFunc.expr );
    11261124                                                makeFunctionAlternatives( newFunc, function, argExpansions,
    11271125                                                        std::back_inserter( candidates ) );
     
    11321130                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    11331131                                                        Alternative newFunc( *func );
    1134                                                         referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     1132                                                        referenceToRvalueConversion( newFunc.expr );
    11351133                                                        makeFunctionAlternatives( newFunc, function, argExpansions,
    11361134                                                                std::back_inserter( candidates ) );
     
    11621160                                                                dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
    11631161                                                        Alternative newFunc( *funcOp );
    1164                                                         referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     1162                                                        referenceToRvalueConversion( newFunc.expr );
    11651163                                                        makeFunctionAlternatives( newFunc, function, argExpansions,
    11661164                                                                std::back_inserter( candidates ) );
     
    13461344                for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) {
    13471345                        // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value
    1348                         Cost cost = agg->cost;
    1349                         Expression * aggrExpr = agg->expr->clone();
    1350                         referenceToRvalueConversion( aggrExpr, cost );
    1351                         std::unique_ptr<Expression> guard( aggrExpr );
    1352 
     1346                        std::unique_ptr<Expression> aggrExpr( agg->expr->clone() );
     1347                        Type * aggrType = aggrExpr->get_result();
     1348                        if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
     1349                                aggrType = aggrType->stripReferences();
     1350                                aggrExpr.reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );
     1351                        }
    13531352                        // find member of the given type
    13541353                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    1355                                 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1354                                addAggMembers( structInst, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
    13561355                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    1357                                 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1356                                addAggMembers( unionInst, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
    13581357                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) {
    1359                                 addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1358                                addTupleMembers( tupleType, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
    13601359                        } // if
    13611360                } // for
     
    13711370                PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; )
    13721371                for ( auto & data : declList ) {
    1373                         Cost cost = Cost::zero;
    1374                         Expression * newExpr = data.combine( cost );
    1375                         alternatives.push_back( Alternative( newExpr, env, Cost::zero ) ); // xxx
     1372                        Expression * newExpr = data.combine();
     1373                        // xxx - add in extra cost for with-statement exprs?
     1374                        alternatives.push_back( Alternative( newExpr, env, Cost::zero ) );
    13761375                        PRINT(
    13771376                                std::cerr << "decl is ";
     
    14131412                        // return the lowest cost alternative for the argument
    14141413                        Alternative &choice = winners.front();
    1415                         referenceToRvalueConversion( choice.expr, choice.cost );
     1414                        referenceToRvalueConversion( choice.expr );
    14161415                        alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
    14171416                } // if
     
    14341433                        // return the lowest cost alternative for the argument
    14351434                        Alternative &choice = winners.front();
    1436                         referenceToRvalueConversion( choice.expr, choice.cost );
     1435                        referenceToRvalueConversion( choice.expr );
    14371436                        alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
    14381437                } // if
     
    14861485                        AltList & alternatives = finder.get_alternatives();
    14871486                        if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) {
    1488                                 Cost cost = Cost::zero;
    1489                                 Expression * newExpr = data.combine( cost );
    1490                                 alternatives.push_back( Alternative( new AttrExpr( newExpr, argType->clone() ), env, cost ) );
     1487                                alternatives.push_back( Alternative( new AttrExpr( data.combine(), argType->clone() ), env, Cost::zero ) );
    14911488                                for ( DeclarationWithType * retVal : function->returnVals ) {
    14921489                                        alternatives.back().expr->result = retVal->get_type()->clone();
     
    15251522                } else {
    15261523                        for ( auto & data : attrList ) {
    1527                                 Cost cost = Cost::zero;
    1528                                 Expression * newExpr = data.combine( cost );
    1529                                 alternatives.push_back( Alternative( newExpr, env, cost ) );
     1524                                alternatives.push_back( Alternative( data.combine(), env, Cost::zero ) );
    15301525                                renameTypes( alternatives.back().expr );
    15311526                        } // for
Note: See TracChangeset for help on using the changeset viewer.