Changes in / [7a780ad:38093ae]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r7a780ad r38093ae  
    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                        }
     
    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
  • src/ResolvExpr/ConversionCost.cc

    r7a780ad r38093ae  
    362362
    363363void ConversionCost::postvisit( const ast::EnumInstType * inst ) {
    364         if ( inst->base && inst->base->base ) {
    365                 if ( auto dstAsAttr = dynamic_cast<const ast::EnumAttrType *>( dst ) ) {
    366                         auto instAsAttr = ast::EnumAttrType( inst, dstAsAttr->attr );
    367                         if ( instAsAttr.match(dstAsAttr) ) {
    368                                 cost.incUnsafe();
    369                         }
    370 
    371                 } else if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    372                         if (inst->base && dstAsInst->base) {
    373                                 if (inst->base == dstAsInst->base) {
    374                                         cost.incUnsafe();
    375                                 }
    376                         }
    377                 } else {
    378                         auto instAsVal = ast::EnumAttrType( inst, ast::EnumAttribute::Value );
    379                         cost = costCalc( &instAsVal, dst, srcIsLvalue, symtab, env );
    380                         if ( cost < Cost::infinity ) {
    381                                 cost.incUnsafe();
     364        if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
     365                if (inst->base && dstAsInst->base) {
     366                        if (inst->base->name == dstAsInst->base->name) {
     367                                cost = Cost::zero;
     368                                return;
    382369                        }
    383370                }
     
    393380void ConversionCost::postvisit( const ast::EnumAttrType * src ) {
    394381    auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst);
    395     if ( src->attr == ast::EnumAttribute::Label ) {
    396         if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Label ) {
    397             cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
    398         }
    399         // Add Conversion To String
    400     } else if ( src->attr == ast::EnumAttribute::Value ) {
     382        assert( src->attr != ast::EnumAttribute::Label );
     383    if ( src->attr == ast::EnumAttribute::Value ) {
    401384        if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {
    402385            cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
  • src/Validate/ImplementEnumFunc.cpp

    r7a780ad r38093ae  
    156156                                         const ast::ObjectDecl* dstParam,
    157157                                         const ast::ObjectDecl* srcParam) {
    158         // const CodeLocation& location = func->location;
    159         // auto& params = func->params;
    160         // assert(2 == params.size());
    161         // auto dstParam = params.front().strict_as<ast::ObjectDecl>();
    162         // auto srcParam = params.back().strict_as<ast::ObjectDecl>();
    163158        return new ast::CompoundStmt(
    164159            location,
     
    301296        {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},
    302297        {new ast::ObjectDecl(getLocation(), "_ret",
    303                              new ast::EnumAttrType(new ast::EnumInstType(decl),
    304                                                    ast::EnumAttribute::Posn))});
     298            new ast::BasicType(ast::BasicType::UnsignedInt))});
    305299}
    306300
     
    440434
    441435    auto addOneExpr = ast::UntypedExpr::createCall( location,
    442         "?+?",
     436        succ? "?+?": "?-?",
    443437        {new ast::VariableExpr(location, param),
    444438        ast::ConstantExpr::from_int(location, 1)}
  • src/main.cc

    r7a780ad r38093ae  
    382382                DUMP( exprp, std::move( transUnit ) );
    383383                PASS( "Replace Pseudo Func", Validate::replacePseudoFunc, transUnit );
    384                 DUMP( reppseu, std::move( transUnit ) );
    385384                PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); // Here
    386385                PASS( "Erase With", ResolvExpr::eraseWith, transUnit );
     
    534533        { "instgen", genericsp, true, "print AST after instantiate generics" },
    535534        { "bbox", bboxp, true, "print AST before box pass" },
    536         { "bcodegen", bcodegenp, true, "print AST before code generation" },
    537         { "reppseu", reppseu, true, "print AST after replacing pseudo functions" }
     535        { "bcodegen", bcodegenp, true, "print AST before code generation" }
    538536};
    539537enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) };
Note: See TracChangeset for help on using the changeset viewer.