Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cc

    rcf32116 r849720f  
    1010// Created On       : Sun May 17 07:06:19 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  4 14:45:00 2019
    13 // Update Count     : 28
     12// Last Modified On : Mon Aug 12 10:21:00 2019
     13// Update Count     : 27
    1414//
    1515
     
    497497        }
    498498
    499 namespace {
    500         # warning For overload resolution between the two versions.
    501         int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2,
    502                         const ast::SymbolTable &, const ast::TypeEnvironment & env ) {
    503                 return ptrsAssignable( t1, t2, env );
    504         }
    505         Cost localConversionCost(
    506                 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
    507                 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
    508         ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); }
    509 }
     499static int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2,
     500                const ast::SymbolTable &, const ast::TypeEnvironment & env ) {
     501        return ptrsAssignable( t1, t2, env );
     502}
     503
     504// TODO: This is used for overload resolution. It might be able to be dropped once the old system
     505// is removed.
     506static Cost localConversionCost(
     507        const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     508        const ast::TypeEnvironment & env
     509) { return conversionCost( src, dst, symtab, env ); }
    510510
    511511Cost conversionCost(
    512         const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
    513         const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
     512        const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     513        const ast::TypeEnvironment & env
    514514) {
    515515        if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
    516516                if ( const ast::EqvClass * eqv = env.lookup( inst->name ) ) {
    517517                        if ( eqv->bound ) {
    518                                 return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env );
     518                                return conversionCost(src, eqv->bound, symtab, env );
    519519                        } else {
    520520                                return Cost::infinity;
     
    524524                        assertf( type, "Unexpected typedef." );
    525525                        if ( type->base ) {
    526                                 return conversionCost( src, type->base, srcIsLvalue, symtab, env ) + Cost::safe;
     526                                return conversionCost( src, type->base, symtab, env ) + Cost::safe;
    527527                        }
    528528                }
     
    534534        } else if ( const ast::ReferenceType * refType =
    535535                         dynamic_cast< const ast::ReferenceType * >( dst ) ) {
    536                 return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable );
     536                return convertToReferenceCost( src, refType, symtab, env, localPtrsAssignable );
    537537        } else {
    538                 ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost );
     538                ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost );
    539539                src->accept( converter );
    540540                return converter.pass.cost;
     
    542542}
    543543
    544 static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     544static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst,
    545545                int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
    546                 PtrsCalculation func ) {
     546                NumCostCalculation func ) {
    547547        if ( 0 < diff ) {
    548548                Cost cost = convertToReferenceCost(
    549                         strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst,
    550                         srcIsLvalue, (diff - 1), symtab, env, func );
     549                        strict_dynamic_cast< const ast::ReferenceType * >( src )->base,
     550                        dst, (diff - 1), symtab, env, func );
    551551                cost.incReference();
    552552                return cost;
     
    554554                Cost cost = convertToReferenceCost(
    555555                        src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base,
    556                         srcIsLvalue, (diff + 1), symtab, env, func );
     556                        (diff + 1), symtab, env, func );
    557557                cost.incReference();
    558558                return cost;
     
    579579                        }
    580580                } else {
    581                         ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost );
     581                        ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost );
    582582                        src->accept( converter );
    583583                        return converter.pass.cost;
     
    588588                assert( dstAsRef );
    589589                if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, symtab, env ) ) {
    590                         if ( srcIsLvalue ) {
     590                        if ( src->is_lvalue() ) {
    591591                                if ( src->qualifiers == dstAsRef->base->qualifiers ) {
    592592                                        return Cost::reference;
     
    607607
    608608Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst,
    609                 bool srcIsLvalue, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
    610                 PtrsCalculation func ) {
     609            const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
     610                NumCostCalculation func ) {
    611611        int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth();
    612         return convertToReferenceCost( src, dst, srcIsLvalue, sdepth - ddepth, symtab, env, func );
     612        return convertToReferenceCost( src, dst, sdepth - ddepth, symtab, env, func );
    613613}
    614614
     
    667667        assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) );
    668668
    669         cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env );
     669        cost = costCalc( refType->base, dst, symtab, env );
    670670        if ( refType->base->qualifiers == dst->qualifiers ) {
    671671                cost.incReference();
     
    701701void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) {
    702702        (void)enumInstType;
    703         static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    704         cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     703        static const ast::BasicType integer( ast::BasicType::SignedInt );
     704        cost = costCalc( &integer, dst, symtab, env );
    705705        if ( cost < Cost::unsafe ) {
    706706                cost.incSafe();
     
    714714void ConversionCost_new::postvisit( const ast::TypeInstType * typeInstType ) {
    715715        if ( const ast::EqvClass * eqv = env.lookup( typeInstType->name ) ) {
    716                 cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env );
     716                cost = costCalc( eqv->bound, dst, symtab, env );
    717717        } else if ( const ast::TypeInstType * dstAsInst =
    718718                        dynamic_cast< const ast::TypeInstType * >( dst ) ) {
     
    724724                assertf( type, "Unexpected typedef.");
    725725                if ( type->base ) {
    726                         cost = costCalc( type->base, dst, srcIsLvalue, symtab, env ) + Cost::safe;
     726                        cost = costCalc( type->base, dst, symtab, env ) + Cost::safe;
    727727                }
    728728        }
     
    737737                auto dstEnd = dstAsTuple->types.end();
    738738                while ( srcIt != srcEnd && dstIt != dstEnd ) {
    739                         Cost newCost = costCalc( * srcIt++, * dstIt++, srcIsLvalue, symtab, env );
     739                        Cost newCost = costCalc( * srcIt++, * dstIt++, symtab, env );
    740740                        if ( newCost == Cost::infinity ) {
    741741                                return;
     
    772772                        cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
    773773                }
    774         } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) {
    775                 cost = Cost::zero;
    776                 // +1 for zero_t ->, +1 for disambiguation
    777                 cost.incSafe( maxIntCost + 2 );
    778774        }
    779775}
     
    793789                        cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
    794790                }
     791        } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) {
     792                cost = Cost::zero;
     793                cost.incSafe( maxIntCost + 2 );
    795794        }
    796795}
Note: See TracChangeset for help on using the changeset viewer.