Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    ra8404d9 r17fa94f  
    21502150}
    21512151
    2152 const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src,
    2153                 const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {
     2152const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src, 
     2153        const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {
    21542154        auto srcDecl = src->base;
    21552155        auto dstDecl = dst->base;
    21562156
    2157         if ( srcDecl->name == dstDecl->name ) return expr;
    2158 
    2159         for ( auto& dstChild : dstDecl->inlinedDecl ) {
     2157        if (srcDecl->name == dstDecl->name) return expr;
     2158
     2159        for (auto& dstChild: dstDecl->inlinedDecl) {
    21602160                Cost c = castCost(src, dstChild, false, context.symtab, env);
    2161                 if ( minCost <= c ) continue;
    2162                 unsigned offset = findChildOffset( dstDecl, dstChild.get()->base );
    2163                 if ( offset <= 0 ) return new ast::CastExpr( expr, dst );
    2164 
    2165                 auto untyped = ast::UntypedExpr::createCall(
    2166                         expr->location,
    2167                         "?+?",
    2168                         { new ast::CastExpr( expr->location,
    2169                                 expr,
    2170                                 new ast::BasicType( ast::BasicKind::SignedInt ),
    2171                                 ast::GeneratedFlag::ExplicitCast ),
    2172                                 ast::ConstantExpr::from_int( expr->location, offset ) } );
    2173                 CandidateFinder finder(context, env);
    2174                 finder.find( untyped );
    2175                 CandidateList winners = findMinCost( finder.candidates );
    2176                 CandidateRef & choice = winners.front();
    2177                 choice->expr = new ast::CastExpr( expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast );
    2178                 if ( auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost ) ) {
    2179                         return new ast::CastExpr( destExpr, dst );
     2161                ast::CastExpr * castToDst;
     2162                if (c<minCost) {
     2163                        unsigned offset = findChildOffset( dstDecl, dstChild.get()->base );
     2164                        if (offset > 0) {
     2165                                auto untyped = ast::UntypedExpr::createCall(
     2166                                        expr->location,
     2167                                        "?+?",
     2168                                        { new ast::CastExpr( expr->location,
     2169                                                expr,
     2170                                                new ast::BasicType(ast::BasicKind::SignedInt),
     2171                                                ast::GeneratedFlag::ExplicitCast ),
     2172                                                ast::ConstantExpr::from_int(expr->location, offset)} );
     2173                                CandidateFinder finder(context, env);
     2174                                finder.find( untyped );
     2175                                CandidateList winners = findMinCost( finder.candidates );
     2176                                CandidateRef & choice = winners.front();
     2177                                choice->expr = new ast::CastExpr(expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast);
     2178                                auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost );
     2179                                if ( !destExpr ) continue;
     2180                                castToDst = new ast::CastExpr( destExpr, dst );
     2181                        } else {
     2182                                castToDst = new ast::CastExpr( expr, dst );
     2183                        }
     2184                        return castToDst;
    21802185                }
    21812186        }
Note: See TracChangeset for help on using the changeset viewer.