Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    racb33f15 rc92bdcc  
    1717
    1818#include <deque>
    19 #include <iterator>               // for back_inserter
     19#include <iterator>                 // for back_inserter
    2020#include <sstream>
    2121#include <string>
     
    2525#include "AdjustExprType.hpp"
    2626#include "Candidate.hpp"
    27 #include "CastCost.hpp"           // for castCost
     27#include "CastCost.hpp"             // for castCost
    2828#include "CompilationState.hpp"
    29 #include "ConversionCost.h"       // for conversionCast
    30 #include "Cost.h"
     29#include "ConversionCost.hpp"       // for conversionCast
     30#include "Cost.hpp"
    3131#include "ExplodedArg.hpp"
    3232#include "PolyCost.hpp"
    33 #include "RenameVars.h"           // for renameTyVars
    34 #include "Resolver.h"
    35 #include "ResolveTypeof.h"
     33#include "RenameVars.hpp"           // for renameTyVars
     34#include "Resolver.hpp"
     35#include "ResolveTypeof.hpp"
    3636#include "SatisfyAssertions.hpp"
    3737#include "SpecCost.hpp"
    38 #include "typeops.h"              // for combos
    39 #include "Unify.h"
    40 #include "WidenMode.h"
     38#include "Typeops.hpp"              // for combos
     39#include "Unify.hpp"
     40#include "WidenMode.hpp"
    4141#include "AST/Expr.hpp"
    4242#include "AST/Node.hpp"
     
    4545#include "AST/SymbolTable.hpp"
    4646#include "AST/Type.hpp"
    47 #include "Common/utility.h"       // for move, copy
    48 #include "SymTab/Mangler.h"
    49 #include "Tuples/Tuples.h"        // for handleTupleAssignment
    50 #include "InitTweak/InitTweak.h"  // for getPointerBase
    51 
    52 #include "Common/Stats/Counter.h"
     47#include "Common/Utility.hpp"       // for move, copy
     48#include "SymTab/Mangler.hpp"
     49#include "Tuples/Tuples.hpp"        // for handleTupleAssignment
     50#include "InitTweak/InitTweak.hpp"  // for getPointerBase
     51
     52#include "Common/Stats/Counter.hpp"
    5353
    5454#include "AST/Inspect.hpp"             // for getFunctionName
     
    906906                                }
    907907                                CandidateRef & choice = winners.front();
    908                                 choice->cost = Cost::unsafe;
     908                                choice->cost.incSafe();
    909909                                candidates.emplace_back( std::move(choice) );
    910910                        }
     
    955955
    956956                CandidateFinder funcFinder( context, tenv );
    957                 std::string funcName;
    958957                if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) {
    959                         funcName = nameExpr->name;
    960958                        auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name);
    961959                        if (kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS) {
     
    10211019                CandidateList found;
    10221020                SemanticErrorException errors;
    1023                
    10241021                for ( CandidateRef & func : funcFinder ) {
    10251022                        try {
     
    10961093                        Cost cvtCost = computeApplicationConversionCost( withFunc, symtab );
    10971094
    1098                         if (funcName == "?|?") {
    10991095                        PRINT(
    11001096                                auto appExpr = withFunc->expr.strict_as< ast::ApplicationExpr >();
     
    11121108                                std::cerr << "cost of conversion is:" << cvtCost << std::endl;
    11131109                        )
    1114                         }
     1110
    11151111                        if ( cvtCost != Cost::infinity ) {
    11161112                                withFunc->cvtCost = cvtCost;
     
    17781774                                                matches.clear();
    17791775                                        }
    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 );
     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                                        }
    17901811                                }
    17911812                        }
Note: See TracChangeset for help on using the changeset viewer.