Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r7a780ad rfc1a3e2  
    513513                                        // add new result
    514514                                        assert( common );
    515                                         // auto attrType = common.as<ast::EnumAttrType>();
    516                                         // if ( attrType && ( attrType->attr == ast::EnumAttribute::Value ) ) {
    517                                         //      auto callExpr = new ast::UntypedExpr(
    518                                         //              expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
    519                                         //      CandidateFinder finder( context, env );
    520                                         //      finder.find( callExpr );
    521                                         //      CandidateList winners = findMinCost( finder.candidates );
    522                                         //      if (winners.size() != 1) {
    523                                         //              SemanticError( callExpr, "Ambiguous expression in valueE" );
    524                                         //      }
    525                                         //      CandidateRef & choice = winners.front();
    526                                         //      choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );
    527 
    528                                         //      results.emplace_back(
    529                                         //              i, choice->expr,
    530                                         //              std::move( env ), std::move( need ), std::move( have ), std::move( open ),
    531                                         //              nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    532                                         // } else {
    533515                                                results.emplace_back(
    534516                                                        i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ),
     
    921903                                CandidateList winners = findMinCost( finder.candidates );
    922904                                if (winners.size() != 1) {
    923                                         SemanticError( callExpr, "Ambiguous expression in valueE" );
     905                                        SemanticError( callExpr, "Ambiguous expression in valueE..." );
    924906                                }
    925907                                CandidateRef & choice = winners.front();
    926                                 // choice->cost.incSafe();
     908                                choice->cost.incVar();
    927909                                candidates.emplace_back( std::move(choice) );
    928910                        }
     
    14301412        }
    14311413
    1432     void Finder::postvisit(const ast::VariableExpr *variableExpr) {
    1433         // not sufficient to just pass `variableExpr` here, type might have changed
    1434 
    1435         auto cand = new Candidate(variableExpr, tenv);
    1436         candidates.emplace_back(cand);
    1437     }
     1414        void Finder::postvisit(const ast::VariableExpr *variableExpr) {
     1415                // not sufficient to just pass `variableExpr` here, type might have changed
     1416
     1417                auto cand = new Candidate(variableExpr, tenv);
     1418                candidates.emplace_back(cand);
     1419        }
    14381420
    14391421        void Finder::postvisit( const ast::ConstantExpr * constantExpr ) {
     
    18001782                                                        CandidateList winners = findMinCost( finder.candidates );
    18011783                                                        if (winners.size() != 1) {
    1802                                                                 SemanticError( callExpr, "Ambiguous expression in valueE" );
     1784                                                                SemanticError( callExpr, "Ambiguous expression in valueE..." );
    18031785                                                        }
    18041786                                                        CandidateRef & choice = winners.front();
     
    21502132}
    21512133
    2152 const ast::Expr * getValueEnumCall( const ast::Expr * expr,
    2153                 const ResolveContext & context, const ast::TypeEnvironment & env ) {
    2154         auto callExpr = new ast::UntypedExpr(
    2155                 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
    2156         CandidateFinder finder( context, env );
    2157         finder.find( callExpr );
    2158         CandidateList winners = findMinCost( finder.candidates );
    2159         if (winners.size() != 1) {
    2160                 SemanticError( callExpr, "Ambiguous expression in valueE" );
    2161         }
    2162         CandidateRef & choice = winners.front();
    2163         return choice->expr;
     2134// get the valueE(...) ApplicationExpr that returns the enum value
     2135const ast::Expr * getValueEnumCall(
     2136        const ast::Expr * expr,
     2137        const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) {
     2138                auto callExpr = new ast::UntypedExpr(
     2139                        expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
     2140                CandidateFinder finder( context, env );
     2141                finder.find( callExpr );
     2142                CandidateList winners = findMinCost( finder.candidates );
     2143                if (winners.size() != 1) {
     2144                        SemanticError( callExpr, "Ambiguous expression in valueE..." );
     2145                }
     2146                CandidateRef & choice = winners.front();
     2147                return choice->expr;
    21642148}
    21652149
Note: See TracChangeset for help on using the changeset viewer.