Changeset cf32116 for src


Ignore:
Timestamp:
Oct 4, 2019, 3:07:07 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
3f3bfe5a
Parents:
90ce35aa
Message:

Implemented expression based lvalue resolution on new ast.

Location:
src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r90ce35aa rcf32116  
    1010// Created On       : Wed May 15 17:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Created On       : Thr Jun 13 13:38:00 2019
    13 // Update Count     : 2
     12// Created On       : Thr Jun 26 12:12:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    2323#include "Eval.hpp"                // for call
    2424#include "GenericSubstitution.hpp"
     25#include "LinkageSpec.hpp"
    2526#include "Stmt.hpp"
    2627#include "Type.hpp"
     
    2930#include "Common/SemanticError.h"
    3031#include "GenPoly/Lvalue.h"        // for referencesPermissable
    31 #include "InitTweak/InitTweak.h"   // for getPointerBase
     32#include "InitTweak/InitTweak.h"   // for getFunction, getPointerBase
    3233#include "ResolvExpr/typeops.h"    // for extractResultType
    3334#include "Tuples/Tuples.h"         // for makeTupleType
    3435
    3536namespace ast {
     37
     38namespace {
     39        std::set<std::string> const lvalueFunctionNames = {"*?", "?[?]"};
     40}
     41
     42// --- Expr
     43bool Expr::get_lvalue() const {
     44        return false;
     45}
    3646
    3747// --- ApplicationExpr
     
    4656        result = ResolvExpr::extractResultType( fn );
    4757        assert( result );
     58}
     59
     60bool ApplicationExpr::get_lvalue() const {
     61        if ( const DeclWithType * func = InitTweak::getFunction( this ) ) {
     62                return func->linkage == Linkage::Intrinsic && lvalueFunctionNames.count( func->name );
     63        }
     64        return false;
    4865}
    4966
     
    7188}
    7289
     90bool UntypedExpr::get_lvalue() const {
     91        std::string fname = InitTweak::getFunctionName( this );
     92        return lvalueFunctionNames.count( fname );
     93}
     94
    7395UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ) {
    7496        assert( lhs && rhs );
     
    106128AddressExpr::AddressExpr( const CodeLocation & loc, const Expr * a ) : Expr( loc ), arg( a ) {
    107129        if ( arg->result ) {
    108                 if ( arg->result->is_lvalue() ) {
     130                if ( arg->get_lvalue() ) {
    109131                        // lvalue, retains all levels of reference, and gains a pointer inside the references
    110132                        Type * res = addrType( arg->result );
     
    137159: Expr( loc, new VoidType{} ), arg( a ), isGenerated( g ) {}
    138160
     161bool CastExpr::get_lvalue() const {
     162        // This is actually wrong by C, but it works with our current set-up.
     163        return arg->get_lvalue();
     164}
     165
    139166// --- KeywordCastExpr
    140167
     
    150177}
    151178
     179// --- UntypedMemberExpr
     180
     181bool UntypedMemberExpr::get_lvalue() const {
     182        return aggregate->get_lvalue();
     183}
     184
    152185// --- MemberExpr
    153186
     
    210243}
    211244
     245bool MemberExpr::get_lvalue() const {
     246        // This is actually wrong by C, but it works with our current set-up.
     247        return true;
     248}
     249
    212250// --- VariableExpr
    213251
     
    222260        r->qualifiers |= CV::Lvalue;
    223261        result = r;
     262}
     263
     264bool VariableExpr::get_lvalue() const {
     265        // It isn't always an lvalue, but it is never an rvalue.
     266        return true;
    224267}
    225268
     
    308351: Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
    309352
     353// --- CommaExpr
     354bool CommaExpr::get_lvalue() const {
     355        // This is wrong by C, but the current implementation uses it.
     356        // (ex: Specialize, Lvalue and Box)
     357        return arg2->get_lvalue();
     358}
     359
    310360// --- ConstructorExpr
    311361
     
    329379}
    330380
     381bool CompoundLiteralExpr::get_lvalue() const {
     382        return true;
     383}
     384
    331385// --- TupleExpr
    332386
     
    344398        result = type->types[ index ];
    345399        add_qualifiers( result, CV::Lvalue );
     400}
     401
     402bool TupleIndexExpr::get_lvalue() const {
     403        return tuple->get_lvalue();
    346404}
    347405
  • src/AST/Expr.hpp

    r90ce35aa rcf32116  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri May 10 10:30:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Created On       : Fri May 10 10:30:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Created On       : Thr Sep 26 12:51:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    187187
    188188        Expr * set_extension( bool ex ) { extension = ex; return this; }
     189        virtual bool get_lvalue() const;
    189190
    190191        virtual const Expr * accept( Visitor & v ) const override = 0;
     
    203204        ApplicationExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} );
    204205
     206        bool get_lvalue() const final;
     207
    205208        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    206209private:
     
    217220        UntypedExpr( const CodeLocation & loc, const Expr * f, std::vector<ptr<Expr>> && as = {} )
    218221        : Expr( loc ), func( f ), args( std::move(as) ) {}
     222
     223        bool get_lvalue() const final;
    219224
    220225        /// Creates a new dereference expression
     
    293298        CastExpr( const Expr * a ) : CastExpr( a->location, a, GeneratedCast ) {}
    294299
     300        bool get_lvalue() const final;
     301
    295302        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    296303private:
     
    340347        : Expr( loc ), member( mem ), aggregate( agg ) { assert( aggregate ); }
    341348
     349        bool get_lvalue() const final;
     350
    342351        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    343352private:
     
    353362
    354363        MemberExpr( const CodeLocation & loc, const DeclWithType * mem, const Expr * agg );
     364
     365        bool get_lvalue() const final;
    355366
    356367        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    374385        VariableExpr( const CodeLocation & loc );
    375386        VariableExpr( const CodeLocation & loc, const DeclWithType * v );
     387
     388        bool get_lvalue() const final;
    376389
    377390        /// generates a function pointer for a given function
     
    545558        }
    546559
     560        bool get_lvalue() const final;
     561
    547562        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    548563private:
     
    616631        CompoundLiteralExpr( const CodeLocation & loc, const Type * t, const Init * i );
    617632
     633        bool get_lvalue() const final;
     634
    618635        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    619636private:
     
    671688
    672689        TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i );
     690
     691        bool get_lvalue() const final;
    673692
    674693        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/ResolvExpr/CandidateFinder.cpp

    r90ce35aa rcf32116  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed Jun 5 14:30:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed Jun 5 14:30:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Oct  1 14:55:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    6262
    6363Cost computeConversionCost(
    64         const ast::Type * argType, const ast::Type * paramType, const ast::SymbolTable & symtab,
    65         const ast::TypeEnvironment & env
     64        const ast::Type * argType, const ast::Type * paramType, bool argIsLvalue,
     65        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
    6666) {
    6767        PRINT(
     
    7474                std::cerr << std::endl;
    7575        )
    76         Cost convCost = conversionCost( argType, paramType, symtab, env );
     76        Cost convCost = conversionCost( argType, paramType, argIsLvalue, symtab, env );
    7777        PRINT(
    7878                std::cerr << std::endl << "cost is " << convCost << std::endl;
     
    110110                const ast::Expr * arg, const ast::Type * paramType, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, Cost & outCost
    111111        ) {
    112                 Cost convCost = computeConversionCost( arg->result, paramType, symtab, env );
     112                Cost convCost = computeConversionCost(
     113                                arg->result, paramType, arg->get_lvalue(), symtab, env );
    113114                outCost += convCost;
    114115
     
    982983                /// true if expression is an lvalue
    983984                static bool isLvalue( const ast::Expr * x ) {
    984                         return x->result && ( x->result->is_lvalue() || x->result.as< ast::ReferenceType >() );
     985                        return x->result && ( x->get_lvalue() || x->result.as< ast::ReferenceType >() );
    985986                }
    986987
     
    10241025                                // unification run for side-effects
    10251026                                unify( toType, cand->expr->result, cand->env, need, have, open, symtab );
    1026                                 Cost thisCost = castCost( cand->expr->result, toType, symtab, cand->env );
     1027                                Cost thisCost = castCost( cand->expr->result, toType, cand->expr->get_lvalue(),
     1028                                                symtab, cand->env );
    10271029                                PRINT(
    10281030                                        std::cerr << "working on cast with result: " << toType << std::endl;
     
    14341436                                        // unification run for side-effects
    14351437                                        unify( toType, cand->expr->result, env, need, have, open, symtab );
    1436                                         Cost thisCost = castCost( cand->expr->result, toType, symtab, env );
     1438                                        Cost thisCost = castCost( cand->expr->result, toType, cand->expr->get_lvalue(),
     1439                                                        symtab, env );
    14371440
    14381441                                        if ( thisCost != Cost::infinity ) {
  • src/ResolvExpr/CandidateFinder.hpp

    r90ce35aa rcf32116  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed Jun 5 14:30:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed Jun 5 14:30:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Oct  1  9:51:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    3232        ast::ptr< ast::Type > targetType;  ///< Target type for resolution
    3333
    34         CandidateFinder( 
    35                 const ast::SymbolTable & syms, const ast::TypeEnvironment & env, 
     34        CandidateFinder(
     35                const ast::SymbolTable & syms, const ast::TypeEnvironment & env,
    3636                const ast::Type * tt = nullptr )
    3737        : candidates(), localSyms( syms ), env( env ), targetType( tt ) {}
     
    4949        iterator begin() { return candidates.begin(); }
    5050        const_iterator begin() const { return candidates.begin(); }
    51        
     51
    5252        iterator end() { return candidates.end(); }
    5353        const_iterator end() const { return candidates.end(); }
     
    5555
    5656/// Computes conversion cost between two types
    57 Cost computeConversionCost( 
    58         const ast::Type * argType, const ast::Type * paramType, const ast::SymbolTable & symtab,
    59         const ast::TypeEnvironment & env );
     57Cost computeConversionCost(
     58        const ast::Type * argType, const ast::Type * paramType, bool argIsLvalue,
     59        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    6060
    6161} // namespace ResolvExpr
  • src/ResolvExpr/CastCost.cc

    r90ce35aa rcf32116  
    1010// Created On       : Sun May 17 06:57:43 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Aug  8 16:12:00 2019
    13 // Update Count     : 8
     12// Last Modified On : Tue Oct  4 15:00:00 2019
     13// Update Count     : 9
    1414//
    1515
     
    142142
    143143                CastCost_new(
    144                         const ast::Type * dst, const ast::SymbolTable & symtab,
     144                        const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,
    145145                        const ast::TypeEnvironment & env, CostCalculation costFunc )
    146                 : ConversionCost_new( dst, symtab, env, costFunc ) {}
     146                : ConversionCost_new( dst, srcIsLvalue, symtab, env, costFunc ) {}
    147147
    148148                void postvisit( const ast::BasicType * basicType ) {
     
    152152                                cost = Cost::unsafe;
    153153                        } else {
    154                                 cost = conversionCost( basicType, dst, symtab, env );
     154                                cost = conversionCost( basicType, dst, srcIsLvalue, symtab, env );
    155155                        }
    156156                }
     
    183183                }
    184184        };
     185
     186        #warning For overload resolution between the two versions.
     187        int localPtrsCastable(const ast::Type * t1, const ast::Type * t2,
     188                        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) {
     189                return ptrsCastable( t1, t2, symtab, env );
     190        }
     191        Cost localCastCost(
     192                const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     193                const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
     194        ) { return castCost( src, dst, srcIsLvalue, symtab, env ); }
    185195} // anonymous namespace
    186196
     197
     198
    187199Cost castCost(
    188         const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    189         const ast::TypeEnvironment & env
     200        const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     201        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
    190202) {
    191203        if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
     
    193205                        // check cast cost against bound type, if present
    194206                        if ( eqvClass->bound ) {
    195                                 return castCost( src, eqvClass->bound, symtab, env );
     207                                return castCost( src, eqvClass->bound, srcIsLvalue, symtab, env );
    196208                        } else {
    197209                                return Cost::infinity;
     
    201213                        auto type = strict_dynamic_cast< const ast::TypeDecl * >( named );
    202214                        if ( type->base ) {
    203                                 return castCost( src, type->base, symtab, env ) + Cost::safe;
     215                                return castCost( src, type->base, srcIsLvalue, symtab, env ) + Cost::safe;
    204216                        }
    205217                }
     
    224236                #warning cast on ptrsCastable artifact of having two functions, remove when port done
    225237                return convertToReferenceCost(
    226                         src, refType, symtab, env,
    227                         ( int (*)(
    228                                 const ast::Type *, const ast::Type *, const ast::SymbolTable &,
    229                                 const ast::TypeEnvironment & )
    230                         ) ptrsCastable );
     238                        src, refType, srcIsLvalue, symtab, env, localPtrsCastable );
    231239        } else {
    232240                #warning cast on castCost artifact of having two functions, remove when port done
    233                 ast::Pass< CastCost_new > converter{
    234                         dst, symtab, env,
    235                         ( Cost (*)(
    236                                 const ast::Type *, const ast::Type *, const ast::SymbolTable &,
    237                                 const ast::TypeEnvironment & )
    238                         ) castCost };
     241                ast::Pass< CastCost_new > converter(
     242                        dst, srcIsLvalue, symtab, env, localCastCost );
    239243                src->accept( converter );
    240244                return converter.pass.cost;
  • src/ResolvExpr/ConversionCost.cc

    r90ce35aa rcf32116  
    1010// Created On       : Sun May 17 07:06:19 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Jul  4 10:56:00 2019
    13 // Update Count     : 27
     12// Last Modified On : Fri Oct  4 14:45:00 2019
     13// Update Count     : 28
    1414//
    1515
     
    497497        }
    498498
    499 static 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.
    506 static 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 ); }
     499namespace {
     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}
    510510
    511511Cost conversionCost(
    512         const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    513         const ast::TypeEnvironment & env
     512        const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     513        const ast::SymbolTable & symtab, 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, symtab, env );
     518                                return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env );
    519519                        } else {
    520520                                return Cost::infinity;
     
    524524                        assertf( type, "Unexpected typedef." );
    525525                        if ( type->base ) {
    526                                 return conversionCost( src, type->base, symtab, env ) + Cost::safe;
     526                                return conversionCost( src, type->base, srcIsLvalue, 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, symtab, env, localPtrsAssignable );
     536                return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable );
    537537        } else {
    538                 ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost );
     538                ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, 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,
     544static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
    545545                int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
    546                 NumCostCalculation func ) {
     546                PtrsCalculation func ) {
    547547        if ( 0 < diff ) {
    548548                Cost cost = convertToReferenceCost(
    549                         strict_dynamic_cast< const ast::ReferenceType * >( src )->base,
    550                         dst, (diff - 1), symtab, env, func );
     549                        strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst,
     550                        srcIsLvalue, (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                         (diff + 1), symtab, env, func );
     556                        srcIsLvalue, (diff + 1), symtab, env, func );
    557557                cost.incReference();
    558558                return cost;
     
    579579                        }
    580580                } else {
    581                         ast::Pass<ConversionCost_new> converter( dst, symtab, env, localConversionCost );
     581                        ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, 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 ( src->is_lvalue() ) {
     590                        if ( srcIsLvalue ) {
    591591                                if ( src->qualifiers == dstAsRef->base->qualifiers ) {
    592592                                        return Cost::reference;
     
    607607
    608608Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst,
    609             const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
    610                 NumCostCalculation func ) {
     609                bool srcIsLvalue, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env,
     610                PtrsCalculation func ) {
    611611        int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth();
    612         return convertToReferenceCost( src, dst, sdepth - ddepth, symtab, env, func );
     612        return convertToReferenceCost( src, dst, srcIsLvalue, sdepth - ddepth, symtab, env, func );
    613613}
    614614
     
    667667        assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) );
    668668
    669         cost = costCalc( refType->base, dst, symtab, env );
     669        cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env );
    670670        if ( refType->base->qualifiers == dst->qualifiers ) {
    671671                cost.incReference();
     
    702702        (void)enumInstType;
    703703        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    704         cost = costCalc( integer, dst, symtab, env );
     704        cost = costCalc( integer, dst, srcIsLvalue, 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, symtab, env );
     716                cost = costCalc( eqv->bound, dst, srcIsLvalue, 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, symtab, env ) + Cost::safe;
     726                        cost = costCalc( type->base, dst, srcIsLvalue, symtab, env ) + Cost::safe;
    727727                }
    728728        }
     
    737737                auto dstEnd = dstAsTuple->types.end();
    738738                while ( srcIt != srcEnd && dstIt != dstEnd ) {
    739                         Cost newCost = costCalc( * srcIt++, * dstIt++, symtab, env );
     739                        Cost newCost = costCalc( * srcIt++, * dstIt++, srcIsLvalue, symtab, env );
    740740                        if ( newCost == Cost::infinity ) {
    741741                                return;
  • src/ResolvExpr/ConversionCost.h

    r90ce35aa rcf32116  
    1010// Created On       : Sun May 17 09:37:28 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Aug  8 16:13:00 2019
    13 // Update Count     : 6
     12// Last Modified On : Tue Oct  4 14:59:00 2019
     13// Update Count     : 7
    1414//
    1515
     
    7474
    7575// Some function pointer types, differ in return type.
    76 using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *,
     76using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *, bool,
    7777        const ast::SymbolTable &, const ast::TypeEnvironment &)>;
    78 using NumCostCalculation = std::function<int(const ast::Type *, const ast::Type *,
     78using PtrsCalculation = std::function<int(const ast::Type *, const ast::Type *,
    7979        const ast::SymbolTable &, const ast::TypeEnvironment &)>;
    8080
     
    8383protected:
    8484        const ast::Type * dst;
     85        bool srcIsLvalue;
    8586        const ast::SymbolTable & symtab;
    8687        const ast::TypeEnvironment & env;
     
    8990        Cost cost;
    9091
    91         ConversionCost_new( const ast::Type * dst, const ast::SymbolTable & symtab,
     92        ConversionCost_new( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,
    9293                        const ast::TypeEnvironment & env, CostCalculation costCalc ) :
    93                 dst( dst ), symtab( symtab ), env( env ), costCalc( costCalc ), cost( Cost::infinity )
     94                dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ),
     95                costCalc( costCalc ), cost( Cost::infinity )
    9496        {}
    9597
     
    114116
    115117Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest,
    116         const ast::SymbolTable & indexer, const ast::TypeEnvironment & env, NumCostCalculation func );
     118        bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env,
     119        PtrsCalculation func );
    117120
    118121} // namespace ResolvExpr
  • src/ResolvExpr/SatisfyAssertions.cpp

    r90ce35aa rcf32116  
    99// Author           : Aaron B. Moss
    1010// Created On       : Mon Jun 10 17:45:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Mon Jun 10 17:45:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Oct  1 13:56:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    299299                        Cost cost;
    300300
    301                         OutType( 
    302                                 const ast::TypeEnvironment & e, const ast::OpenVarSet & o, 
     301                        OutType(
     302                                const ast::TypeEnvironment & e, const ast::OpenVarSet & o,
    303303                                const std::vector< DeferRef > & as, const ast::SymbolTable & symtab )
    304304                        : env( e ), open( o ), assns( as ), cost( Cost::zero ) {
     
    306306                                for ( const DeferRef & assn : assns ) {
    307307                                        // compute conversion cost from satisfying decl to assertion
    308                                         cost += computeConversionCost( 
    309                                                 assn.match.adjType, assn.decl->get_type(), symtab, env );
    310                                        
     308                                        cost += computeConversionCost(
     309                                                assn.match.adjType, assn.decl->get_type(), false, symtab, env );
     310
    311311                                        // mark vars+specialization on function-type assertions
    312                                         const ast::FunctionType * func = 
     312                                        const ast::FunctionType * func =
    313313                                                GenPoly::getFunctionType( assn.match.cdata.id->get_type() );
    314314                                        if ( ! func ) continue;
     
    317317                                                cost.decSpec( specCost( param->get_type() ) );
    318318                                        }
    319                                        
     319
    320320                                        cost.incVar( func->forall.size() );
    321                                        
     321
    322322                                        for ( const ast::TypeDecl * td : func->forall ) {
    323323                                                cost.decSpec( td->assertions.size() );
     
    329329                };
    330330
    331                 CandidateEnvMerger( 
    332                         const ast::TypeEnvironment & env, const ast::OpenVarSet & open, 
     331                CandidateEnvMerger(
     332                        const ast::TypeEnvironment & env, const ast::OpenVarSet & open,
    333333                        const ast::SymbolTable & syms )
    334334                : crnt(), envs{ env }, opens{ open }, symtab( syms ) {}
  • src/ResolvExpr/SatisfyAssertions.hpp

    r90ce35aa rcf32116  
    2828
    2929/// Recursively satisfies all assertions provided in a candidate; returns true if succeeds
    30 void satisfyAssertions( 
    31         CandidateRef & cand, const ast::SymbolTable & symtab, CandidateList & out, 
     30void satisfyAssertions(
     31        CandidateRef & cand, const ast::SymbolTable & symtab, CandidateList & out,
    3232        std::vector<std::string> & errors );
    3333
  • src/ResolvExpr/typeops.h

    r90ce35aa rcf32116  
    1010// Created On       : Sun May 17 07:28:22 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Aug  8 16:36:00 2019
    13 // Update Count     : 5
     12// Last Modified On : Tue Oct  1 09:45:00 2019
     13// Update Count     : 6
    1414//
    1515
     
    8383                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    8484        Cost castCost(
    85                 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    86                 const ast::TypeEnvironment & env );
     85                const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     86                const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    8787
    8888        // in ConversionCost.cc
     
    9090                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    9191        Cost conversionCost(
    92                 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
    93                 const ast::TypeEnvironment & env );
     92                const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
     93                const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
    9494
    9595        // in AlternativeFinder.cc
Note: See TracChangeset for help on using the changeset viewer.