Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cpp

    r5ccc733 r85855b0  
    162162Cost conversionCost(
    163163        const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
    164 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
     164        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
    165165) {
    166166        if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
     
    235235                        return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost );
    236236                }
    237                 if (const ast::EnumInstType * srcAsInst = dynamic_cast< const ast::EnumInstType * >( src )) {
    238                         if (srcAsInst->base && !srcAsInst->base->isCfa) {
    239                                 static const ast::BasicType* integer = new ast::BasicType( ast::BasicKind::UnsignedInt );
    240                                 return ast::Pass<ConversionCost>::read( integer, dst, srcIsLvalue, symtab, env, conversionCost );
    241                         }
    242                 }
    243237        } else {
    244238                assert( -1 == diff );
    245239                const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst );
    246240                assert( dstAsRef );
    247                 auto dstBaseType = dstAsRef->base;
    248                 const ast::Type * newSrc = src;
    249                 if ( dynamic_cast< const ast::EnumInstType * >( src ) && dstBaseType.as<ast::BasicType>() ) {
    250                         newSrc = new ast::BasicType( ast::BasicKind::UnsignedInt );
    251                 }
    252                 if ( typesCompatibleIgnoreQualifiers( newSrc, dstAsRef->base, env ) ) {
     241                if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) {
    253242                        if ( srcIsLvalue ) {
    254243                                if ( src->qualifiers == dstAsRef->base->qualifiers ) {
     
    295284        if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) {
    296285                conversionCostFromBasicToBasic( basicType, dstAsBasic );
    297         } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    298                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
    299                         cost = Cost::safe;
     286        }       else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
     287                if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) {
     288                        cost = Cost::unsafe;
    300289                }
    301290        }
     
    377366        if ( auto dstInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    378367                cost = enumCastCost(inst, dstInst, symtab, env);
    379         } else if ( !inst->base->isCfa ) {
    380                 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    381                 cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    382         }
    383         // cost.incUnsafe();
     368                return;
     369        }
     370        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
     371        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     372        if ( !inst->base->isTyped ) {
     373                if ( cost < Cost::unsafe ) {
     374                        cost.incSafe();
     375                }
     376                return;
     377        }
     378        cost.incUnsafe();
    384379}
    385380
     
    459454                // assuming 0p is supposed to be used for pointers?
    460455        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    461                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
    462                         cost = Cost::safe;
     456                if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) {
     457                        cost = Cost::unsafe;
    463458                }
    464459        }
     
    480475                }
    481476        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    482                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa ) {
    483                         cost = Cost::safe;
     477                if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) {
     478                        cost = Cost::unsafe;
    484479                }
    485480        }
Note: See TracChangeset for help on using the changeset viewer.