Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    rc92bdcc racb33f15  
    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.hpp"       // for conversionCast
    30 #include "Cost.hpp"
     29#include "ConversionCost.h"       // for conversionCast
     30#include "Cost.h"
    3131#include "ExplodedArg.hpp"
    3232#include "PolyCost.hpp"
    33 #include "RenameVars.hpp"           // for renameTyVars
    34 #include "Resolver.hpp"
    35 #include "ResolveTypeof.hpp"
     33#include "RenameVars.h"           // for renameTyVars
     34#include "Resolver.h"
     35#include "ResolveTypeof.h"
    3636#include "SatisfyAssertions.hpp"
    3737#include "SpecCost.hpp"
    38 #include "Typeops.hpp"              // for combos
    39 #include "Unify.hpp"
    40 #include "WidenMode.hpp"
     38#include "typeops.h"              // for combos
     39#include "Unify.h"
     40#include "WidenMode.h"
    4141#include "AST/Expr.hpp"
    4242#include "AST/Node.hpp"
     
    4545#include "AST/SymbolTable.hpp"
    4646#include "AST/Type.hpp"
    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"
     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"
    5353
    5454#include "AST/Inspect.hpp"             // for getFunctionName
     
    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.