Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cc

    raf746cc 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 ( 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();
    382                         }
    383                 }
    384                 return;
    385         }
     368void ConversionCost::postvisit( const ast::EnumInstType * ) {
    386369        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    387370        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     
    391374}
    392375
    393 void ConversionCost::postvisit( const ast::EnumAttrType * src ) {
    394     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 ) {
    401         if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {
    402             cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
    403         } else {
    404             auto baseType = src->instance->base->base;
    405             cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );
    406                         if ( cost < Cost::infinity ) {
    407                                 cost.incUnsafe();
    408                         }
    409         }
    410     } else { // ast::EnumAttribute::Posn
    411         if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    412                     cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env );
    413                     if ( cost < Cost::unsafe ) cost.incSafe();
    414             } else {
    415                     static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    416                     cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    417                     if ( cost < Cost::unsafe ) {
    418                             cost.incSafe();
    419                     }
    420             }
    421     }
     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
    422392}
    423393
     
    496466                cost.incSafe( maxIntCost + 2 );
    497467                // assuming 0p is supposed to be used for pointers?
    498         } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    499                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    500                         cost = Cost::zero;
    501                         cost.incUnsafe();
    502                 }
    503468        }
    504469}
     
    518483                        cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
    519484                }
    520         } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    521                 if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    522                         cost = Cost::zero;
    523                         cost.incUnsafe();
    524                 }
    525485        }
    526486}
Note: See TracChangeset for help on using the changeset viewer.