- File:
-
- 1 edited
-
src/ResolvExpr/AlternativeFinder.cc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
ra181494 r93401f8 204 204 } // namespace 205 205 206 void referenceToRvalueConversion( Expression *& expr , Cost & cost) {206 void referenceToRvalueConversion( Expression *& expr ) { 207 207 if ( dynamic_cast< ReferenceType * >( expr->get_result() ) ) { 208 208 // cast away reference from expr 209 209 expr = new CastExpr( expr, expr->get_result()->stripReferences()->clone() ); 210 cost.incReference();211 210 } 212 211 } … … 436 435 PRINT( std::cerr << "end of formals with varargs function: inc unsafe: " << convCost << std::endl; ; ) 437 436 // convert reference-typed expressions to value-typed expressions 438 referenceToRvalueConversion( *actualExpr , convCost);437 referenceToRvalueConversion( *actualExpr ); 439 438 continue; 440 439 } else { … … 566 565 // DOESN'T WORK: grandchild nodes conflict with their cousins 567 566 //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue; 568 569 Expression *varExpr = data.combine( newerAlt.cost ); 567 Expression *varExpr = data.combine(); 570 568 delete varExpr->get_result(); 571 569 varExpr->set_result( adjType->clone() ); … … 1123 1121 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 1124 1122 Alternative newFunc( *func ); 1125 referenceToRvalueConversion( newFunc.expr , newFunc.cost);1123 referenceToRvalueConversion( newFunc.expr ); 1126 1124 makeFunctionAlternatives( newFunc, function, argExpansions, 1127 1125 std::back_inserter( candidates ) ); … … 1132 1130 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 1133 1131 Alternative newFunc( *func ); 1134 referenceToRvalueConversion( newFunc.expr , newFunc.cost);1132 referenceToRvalueConversion( newFunc.expr ); 1135 1133 makeFunctionAlternatives( newFunc, function, argExpansions, 1136 1134 std::back_inserter( candidates ) ); … … 1162 1160 dynamic_cast<FunctionType*>( pointer->get_base() ) ) { 1163 1161 Alternative newFunc( *funcOp ); 1164 referenceToRvalueConversion( newFunc.expr , newFunc.cost);1162 referenceToRvalueConversion( newFunc.expr ); 1165 1163 makeFunctionAlternatives( newFunc, function, argExpansions, 1166 1164 std::back_inserter( candidates ) ); … … 1346 1344 for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) { 1347 1345 // 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 } 1353 1352 // find member of the given type 1354 1353 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() ); 1356 1355 } 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() ); 1358 1357 } 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() ); 1360 1359 } // if 1361 1360 } // for … … 1371 1370 PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; ) 1372 1371 for ( auto & data : declList ) { 1373 Cost cost = Cost::zero;1374 Expression * newExpr = data.combine( cost );1375 alternatives.push_back( Alternative( newExpr, env, Cost::zero ) ); // xxx1372 Expression * newExpr = data.combine(); 1373 // xxx - add in extra cost for with-statement exprs? 1374 alternatives.push_back( Alternative( newExpr, env, Cost::zero ) ); 1376 1375 PRINT( 1377 1376 std::cerr << "decl is "; … … 1413 1412 // return the lowest cost alternative for the argument 1414 1413 Alternative &choice = winners.front(); 1415 referenceToRvalueConversion( choice.expr , choice.cost);1414 referenceToRvalueConversion( choice.expr ); 1416 1415 alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) ); 1417 1416 } // if … … 1434 1433 // return the lowest cost alternative for the argument 1435 1434 Alternative &choice = winners.front(); 1436 referenceToRvalueConversion( choice.expr , choice.cost);1435 referenceToRvalueConversion( choice.expr ); 1437 1436 alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) ); 1438 1437 } // if … … 1486 1485 AltList & alternatives = finder.get_alternatives(); 1487 1486 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 ) ); 1491 1488 for ( DeclarationWithType * retVal : function->returnVals ) { 1492 1489 alternatives.back().expr->result = retVal->get_type()->clone(); … … 1525 1522 } else { 1526 1523 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 ) ); 1530 1525 renameTypes( alternatives.back().expr ); 1531 1526 } // for
Note:
See TracChangeset
for help on using the changeset viewer.