Ignore:
Timestamp:
May 13, 2024, 10:26:52 AM (5 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
31f4837
Parents:
41c8312
Message:

Change enum conversion steps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r41c8312 racb33f15  
    906906                                }
    907907                                CandidateRef & choice = winners.front();
    908                                 choice->cost.incSafe();
     908                                choice->cost = Cost::unsafe;
    909909                                candidates.emplace_back( std::move(choice) );
    910910                        }
     
    955955
    956956                CandidateFinder funcFinder( context, tenv );
     957                std::string funcName;
    957958                if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) {
     959                        funcName = nameExpr->name;
    958960                        auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name);
    959961                        if (kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS) {
     
    10191021                CandidateList found;
    10201022                SemanticErrorException errors;
     1023               
    10211024                for ( CandidateRef & func : funcFinder ) {
    10221025                        try {
     
    10931096                        Cost cvtCost = computeApplicationConversionCost( withFunc, symtab );
    10941097
     1098                        if (funcName == "?|?") {
    10951099                        PRINT(
    10961100                                auto appExpr = withFunc->expr.strict_as< ast::ApplicationExpr >();
     
    11081112                                std::cerr << "cost of conversion is:" << cvtCost << std::endl;
    11091113                        )
    1110 
     1114                        }
    11111115                        if ( cvtCost != Cost::infinity ) {
    11121116                                withFunc->cvtCost = cvtCost;
     
    17741778                                                matches.clear();
    17751779                                        }
    1776                                         // ambiguous case, still output candidates to print in error message
    1777                                         if ( cand->cost == minExprCost && thisCost == minCastCost ) {
    1778                                                 auto commonAsEnumAttr = common.as<ast::EnumAttrType>();
    1779                                                 if ( commonAsEnumAttr && commonAsEnumAttr->attr == ast::EnumAttribute::Value ) {
    1780                                                         auto callExpr = new ast::UntypedExpr(
    1781                                                                 cand->expr->location, new ast::NameExpr( cand->expr->location, "valueE"), {cand->expr} );
    1782                                                         CandidateFinder finder( context, env );
    1783                                                         finder.find( callExpr );
    1784                                                         CandidateList winners = findMinCost( finder.candidates );
    1785                                                         if (winners.size() != 1) {
    1786                                                                 SemanticError( callExpr, "Ambiguous expression in valueE..." );
    1787                                                         }
    1788                                                         CandidateRef & choice = winners.front();
    1789                                                         // assert( valueCall->result );
    1790                                                         CandidateRef newCand = std::make_shared<Candidate>(
    1791                                                                 new ast::InitExpr{
    1792                                                                         initExpr->location,
    1793                                                                         // restructureCast( cand->expr, toType ),
    1794                                                                         choice->expr,
    1795                                                                         initAlt.designation },
    1796                                                                 std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost );
    1797                                                                 inferParameters( newCand, matches );
    1798                                                 } else {
    1799                                                         CandidateRef newCand = std::make_shared<Candidate>(
    1800                                                                 new ast::InitExpr{
    1801                                                                         initExpr->location,
    1802                                                                         restructureCast( cand->expr, toType ),
    1803                                                                         initAlt.designation },
    1804                                                                 std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost );
    1805                                                         // currently assertions are always resolved immediately so this should have no effect.
    1806                                                         // if this somehow changes in the future (e.g. delayed by indeterminate return type)
    1807                                                         // we may need to revisit the logic.
    1808                                                         inferParameters( newCand, matches );
    1809                                                 }
    1810                                         }
     1780                                        CandidateRef newCand = std::make_shared<Candidate>(
     1781                                                new ast::InitExpr{
     1782                                                        initExpr->location,
     1783                                                        restructureCast( cand->expr, toType ),
     1784                                                        initAlt.designation },
     1785                                                std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost );
     1786                                        // currently assertions are always resolved immediately so this should have no effect.
     1787                                        // if this somehow changes in the future (e.g. delayed by indeterminate return type)
     1788                                        // we may need to revisit the logic.
     1789                                        inferParameters( newCand, matches );
    18111790                                }
    18121791                        }
Note: See TracChangeset for help on using the changeset viewer.