Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cpp

    r85855b0 r5ccc733  
    5353                void postvisit( const ast::EnumInstType * enumInst ) {
    5454                        cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env );
     55
     56                        if ( !enumInst->base->isCfa ) {
     57                                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
     58                                Cost intCost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     59                                cost = intCost < cost? intCost: cost;
     60                        } else if ( enumInst->base->isTyped() ) {
     61                                auto baseConversionCost =
     62                                        castCost( enumInst->base->base, dst, srcIsLvalue, symtab, env );
     63                                cost = baseConversionCost < cost? baseConversionCost: cost;
     64                        }
    5565                }
    5666
     
    6373                                cost = conversionCost( basicType, dst, srcIsLvalue, symtab, env );
    6474                                if ( Cost::unsafe < cost ) {
    65                                         if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) {
    66                                                 // Always explict cast only for typed enum
    67                                                 if (enumInst->base->isTyped) cost = Cost::unsafe;
     75                                        if ( dynamic_cast<const ast::EnumInstType *>(dst)) {
     76                                                cost = Cost::unsafe;
    6877                                        }
    6978                                }
     
    7483                        cost = conversionCost( zero, dst, srcIsLvalue, symtab, env );
    7584                        if ( Cost::unsafe < cost ) {
    76                                 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) {
    77                                         if (enumInst->base->isTyped) cost = Cost::unsafe;
     85                                if ( dynamic_cast<const ast::EnumInstType *>(dst)) {
     86                                        cost = Cost::unsafe;
    7887                                }
    7988                        }
     
    8392                        cost = conversionCost( one, dst, srcIsLvalue, symtab, env );
    8493                        if ( Cost::unsafe < cost ) {
    85                                 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) {
    86                                         if (enumInst->base->isTyped) cost = Cost::unsafe;
     94                                if ( dynamic_cast<const ast::EnumInstType *>(dst)) {
     95                                        cost = Cost::unsafe;
    8796                                }
    8897                        }
Note: See TracChangeset for help on using the changeset viewer.