Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cc

    r748c751 r76fe046  
    278278        if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) {
    279279                conversionCostFromBasicToBasic( basicType, dstAsBasic );
    280         } else if ( dynamic_cast< const ast::EnumAttrType *>(dst) ) {
     280        }
     281        else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
     282                auto enumDecl = enumInst->base;
     283                if ( enumDecl->base.get() ) {
     284                        // cost = costCalc( basicType, baseType, srcIsLvalue, symtab, env );
     285                        // cost.incUnsafe();
     286                        cost = Cost::infinity;
     287                } else {
     288            cost = Cost::unsafe;
     289                }
     290        } else if ( dynamic_cast< const ast::EnumPosType *>(dst) ) {
    281291                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    282292                cost = costCalc( basicType, integer, srcIsLvalue, symtab, env );
    283         } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    284                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    285                         cost = Cost::zero;
    286                         cost.incUnsafe();
    287                 }
    288293        }
    289294}
     
    361366}
    362367
    363 void ConversionCost::postvisit( const ast::EnumInstType * inst ) {
    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;
    369                         }
    370                 }
    371         }
     368void ConversionCost::postvisit( const ast::EnumInstType * ) {
    372369        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    373370        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     
    377374}
    378375
    379 void ConversionCost::postvisit( const ast::EnumAttrType * src ) {
    380     auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst);
    381         assert( src->attr != ast::EnumAttribute::Label );
    382     if ( src->attr == ast::EnumAttribute::Value ) {
    383         if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {
    384             cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
    385         } else {
    386             auto baseType = src->instance->base->base;
    387             cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );
    388                         if ( cost < Cost::infinity ) {
    389                                 cost.incUnsafe();
    390                         }
    391         }
    392     } else { // ast::EnumAttribute::Posn
    393         if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    394                     cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env );
    395                     if ( cost < Cost::unsafe ) cost.incSafe();
    396             } else {
    397                     static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    398                     cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    399                     if ( cost < Cost::unsafe ) {
    400                             cost.incSafe();
    401                     }
    402             }
    403     }
     376void ConversionCost::postvisit( const ast::EnumPosType * src ) {
     377        if ( dynamic_cast<const ast::EnumPosType *>( dst ) ) {
     378                // cost = costCalc( src->instance, dstBase->instance, srcIsLvalue, symtab, env );
     379                // if ( cost < Cost::unsafe ) cost.incSafe();
     380                cost = Cost::zero;
     381        } else if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
     382                cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env );
     383                if ( cost < Cost::unsafe ) cost.incSafe();
     384        } else {
     385                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
     386                cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     387                if ( cost < Cost::unsafe ) {
     388                        cost.incSafe();
     389                }
     390        }
     391
    404392}
    405393
     
    478466                cost.incSafe( maxIntCost + 2 );
    479467                // assuming 0p is supposed to be used for pointers?
    480         } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    481                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    482                         cost = Cost::zero;
    483                         cost.incUnsafe();
    484                 }
    485468        }
    486469}
     
    500483                        cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
    501484                }
    502         } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    503                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    504                         cost = Cost::zero;
    505                         cost.incUnsafe();
    506                 }
    507485        }
    508486}
Note: See TracChangeset for help on using the changeset viewer.