Changeset 1118b8b for src/ResolvExpr


Ignore:
Timestamp:
Aug 13, 2019, 2:36:06 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
dcfedca
Parents:
dee1f89 (diff), 14388c1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/ResolvExpr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rdee1f89 r1118b8b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sat May 16 23:52:08 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:37:46 2019
    13 // Update Count     : 37
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Aug  8 16:35:00 2019
     13// Update Count     : 38
    1414//
    1515
     
    377377        }
    378378
    379         Cost computeConversionCost( Type * actualType, Type * formalType, const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
     379        Cost computeConversionCost( Type * actualType, Type * formalType, bool actualIsLvalue,
     380                        const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
    380381                PRINT(
    381382                        std::cerr << std::endl << "converting ";
     
    387388                        std::cerr << std::endl;
    388389                )
    389                 Cost convCost = conversionCost( actualType, formalType, indexer, env );
     390                Cost convCost = conversionCost( actualType, formalType, actualIsLvalue, indexer, env );
    390391                PRINT(
    391392                        std::cerr << std::endl << "cost is " << convCost << std::endl;
     
    402403
    403404        Cost computeExpressionConversionCost( Expression *& actualExpr, Type * formalType, const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
    404                 Cost convCost = computeConversionCost( actualExpr->result, formalType, indexer, env );
     405                Cost convCost = computeConversionCost(
     406                        actualExpr->result, formalType, actualExpr->get_lvalue(), indexer, env );
    405407
    406408                // if there is a non-zero conversion cost, ignoring poly cost, then the expression requires conversion.
     
    12131215                        unify( castExpr->result, alt.expr->result, alt.env, needAssertions,
    12141216                                haveAssertions, openVars, indexer );
    1215                         Cost thisCost = castCost( alt.expr->result, castExpr->result, indexer,
    1216                                 alt.env );
     1217                        Cost thisCost = castCost( alt.expr->result, castExpr->result, alt.expr->get_lvalue(),
     1218                                indexer, alt.env );
    12171219                        PRINT(
    12181220                                std::cerr << "working on cast with result: " << castExpr->result << std::endl;
     
    16411643                                // xxx - do some inspecting on this line... why isn't result bound to initAlt.type?
    16421644
    1643                                 Cost thisCost = castCost( alt.expr->result, toType, indexer, newEnv );
     1645                                Cost thisCost = castCost( alt.expr->result, toType, alt.expr->get_lvalue(),
     1646                                        indexer, newEnv );
    16441647                                if ( thisCost != Cost::infinity ) {
    16451648                                        // count one safe conversion for each value that is thrown away
  • src/ResolvExpr/CastCost.cc

    rdee1f89 r1118b8b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 06:57:43 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  2 15:34:36 2016
    13 // Update Count     : 7
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Aug  8 16:12:00 2019
     13// Update Count     : 8
    1414//
    1515
     
    3737        struct CastCost_old : public ConversionCost {
    3838          public:
    39                 CastCost_old( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
     39                CastCost_old( const Type * dest, bool srcIsLvalue,
     40                        const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
    4041
    4142                using ConversionCost::previsit;
     
    4546        };
    4647
    47         Cost castCost( const Type * src, const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
     48        Cost castCost( const Type * src, const Type * dest, bool srcIsLvalue,
     49                        const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    4850                if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType * >( dest ) ) {
    4951                        if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->name ) ) {
    5052                                if ( eqvClass->type ) {
    51                                         return castCost( src, eqvClass->type, indexer, env );
     53                                        return castCost( src, eqvClass->type, srcIsLvalue, indexer, env );
    5254                                } else {
    5355                                        return Cost::infinity;
     
    5759                                const TypeDecl * type = strict_dynamic_cast< const TypeDecl * >( namedType );
    5860                                if ( type->base ) {
    59                                         return castCost( src, type->base, indexer, env ) + Cost::safe;
     61                                        return castCost( src, type->base, srcIsLvalue, indexer, env ) + Cost::safe;
    6062                                } // if
    6163                        } // if
     
    7880                } else if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * > ( dest ) ) {
    7981                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    80                         return convertToReferenceCost( src, refType, indexer, env, [](const Type * t1, const Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     82                        return convertToReferenceCost( src, refType, srcIsLvalue, indexer, env, [](const Type * t1, const Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
    8183                                return ptrsCastable( t1, t2, env, indexer );
    8284                        });
    8385                } else {
    8486                        PassVisitor<CastCost_old> converter(
    85                                 dest, indexer, env,
    86                                 (Cost (*)( const Type *, const Type *, const SymTab::Indexer &, const TypeEnvironment & ))
     87                                dest, srcIsLvalue, indexer, env,
     88                                (Cost (*)( const Type *, const Type *, bool, const SymTab::Indexer &, const TypeEnvironment & ))
    8789                                        castCost );
    8890                        src->accept( converter );
     
    9698        }
    9799
    98         CastCost_old::CastCost_old( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
    99                 : ConversionCost( dest, indexer, env, costFunc ) {
     100        CastCost_old::CastCost_old( const Type * dest, bool srcIsLvalue,
     101                        const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
     102                : ConversionCost( dest, srcIsLvalue, indexer, env, costFunc ) {
    100103        }
    101104
     
    106109                        cost = Cost::unsafe;
    107110                } else {
    108                         cost = conversionCost( basicType, dest, indexer, env );
     111                        cost = conversionCost( basicType, dest, srcIsLvalue, indexer, env );
    109112                } // if
    110113        }
  • src/ResolvExpr/ConversionCost.cc

    rdee1f89 r1118b8b  
    1010// Created On       : Sun May 17 07:06:19 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jun 24 13:33:00 2019
    13 // Update Count     : 26
     12// Last Modified On : Mon Aug 12 10:21:00 2019
     13// Update Count     : 27
    1414//
    1515
     
    4646#endif
    4747
    48         Cost conversionCost( const Type * src, const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
     48        Cost conversionCost( const Type * src, const Type * dest, bool srcIsLvalue,
     49                        const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    4950                if ( const TypeInstType * destAsTypeInst = dynamic_cast< const TypeInstType * >( dest ) ) {
    5051                        PRINT( std::cerr << "type inst " << destAsTypeInst->name; )
    5152                        if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->name ) ) {
    5253                                if ( eqvClass->type ) {
    53                                         return conversionCost( src, eqvClass->type, indexer, env );
     54                                        return conversionCost( src, eqvClass->type, srcIsLvalue, indexer, env );
    5455                                } else {
    5556                                        return Cost::infinity;
     
    6162                                assert( type );
    6263                                if ( type->base ) {
    63                                         return conversionCost( src, type->base, indexer, env ) + Cost::safe;
     64                                        return conversionCost( src, type->base, srcIsLvalue, indexer, env )
     65                                                + Cost::safe;
    6466                                } // if
    6567                        } // if
     
    8183                } else if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * > ( dest ) ) {
    8284                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    83                         return convertToReferenceCost( src, refType, indexer, env, [](const Type * const t1, const Type * t2, const SymTab::Indexer &, const TypeEnvironment & env ){
     85                        return convertToReferenceCost( src, refType, srcIsLvalue, indexer, env, [](const Type * const t1, const Type * t2, const SymTab::Indexer &, const TypeEnvironment & env ){
    8486                                return ptrsAssignable( t1, t2, env );
    8587                        });
    8688                } else {
    8789                        PassVisitor<ConversionCost> converter(
    88                                 dest, indexer, env,
    89                                 (Cost (*)(const Type *, const Type *, const SymTab::Indexer&, const TypeEnvironment&))
     90                                dest, srcIsLvalue, indexer, env,
     91                                (Cost (*)(const Type *, const Type *, bool, const SymTab::Indexer&, const TypeEnvironment&))
    9092                                        conversionCost );
    9193                        src->accept( converter );
     
    98100        }
    99101
    100         static Cost convertToReferenceCost( const Type * src, const Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
     102        static Cost convertToReferenceCost( const Type * src, const Type * dest, bool srcIsLvalue,
     103                        int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    101104                PRINT( std::cerr << "convert to reference cost... diff " << diff << " " << src << " / " << dest << std::endl; )
    102105                if ( diff > 0 ) {
    103106                        // TODO: document this
    104                         Cost cost = convertToReferenceCost( strict_dynamic_cast< const ReferenceType * >( src )->base, dest, diff-1, indexer, env, func );
     107                        Cost cost = convertToReferenceCost(
     108                                strict_dynamic_cast< const ReferenceType * >( src )->base, dest, srcIsLvalue,
     109                                diff-1, indexer, env, func );
    105110                        cost.incReference();
    106111                        return cost;
    107112                } else if ( diff < -1 ) {
    108113                        // TODO: document this
    109                         Cost cost = convertToReferenceCost( src, strict_dynamic_cast< const ReferenceType * >( dest )->base, diff+1, indexer, env, func );
     114                        Cost cost = convertToReferenceCost(
     115                                src, strict_dynamic_cast< const ReferenceType * >( dest )->base, srcIsLvalue,
     116                                diff+1, indexer, env, func );
    110117                        cost.incReference();
    111118                        return cost;
     
    138145                                PRINT( std::cerr << "reference to rvalue conversion" << std::endl; )
    139146                                PassVisitor<ConversionCost> converter(
    140                                         dest, indexer, env,
    141                                         (Cost (*)(const Type *, const Type *, const SymTab::Indexer&, const TypeEnvironment&))
     147                                        dest, srcIsLvalue, indexer, env,
     148                                        (Cost (*)(const Type *, const Type *, bool, const SymTab::Indexer&, const TypeEnvironment&))
    142149                                                conversionCost );
    143150                                src->accept( converter );
     
    150157                        if ( typesCompatibleIgnoreQualifiers( src, destAsRef->base, indexer, env ) ) {
    151158                                PRINT( std::cerr << "converting compatible base type" << std::endl; )
    152                                 if ( src->get_lvalue() ) {
     159                                assert( src->get_lvalue() == srcIsLvalue );
     160                                if ( srcIsLvalue ) {
    153161                                        PRINT(
    154162                                                std::cerr << "lvalue to reference conversion" << std::endl;
     
    178186        }
    179187
    180         Cost convertToReferenceCost( const Type * src, const ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
     188        Cost convertToReferenceCost( const Type * src, const ReferenceType * dest, bool srcIsLvalue,
     189                        const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
    181190                int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth();
    182                 Cost cost = convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func );
     191                Cost cost = convertToReferenceCost( src, dest, srcIsLvalue, sdepth-ddepth, indexer, env, func );
    183192                PRINT( std::cerr << "convertToReferenceCost result: " << cost << std::endl; )
    184193                return cost;
    185194        }
    186195
    187         ConversionCost::ConversionCost( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
    188                 : dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ), costFunc( costFunc ) {
     196        ConversionCost::ConversionCost( const Type * dest, bool srcIsLvalue, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
     197                : dest( dest ), srcIsLvalue( srcIsLvalue ), indexer( indexer ), cost( Cost::infinity ), env( env ), costFunc( costFunc ) {
    189198        }
    190199
     
    371380                // recursively compute conversion cost from T1 to T2.
    372381                // cv can be safely dropped because of 'implicit dereference' behavior.
    373                 cost = costFunc( refType->base, dest, indexer, env );
     382                cost = costFunc( refType->base, dest, srcIsLvalue, indexer, env );
    374383                if ( refType->base->tq == dest->tq ) {
    375384                        cost.incReference();  // prefer exact qualifiers
     
    403412                static Type::Qualifiers q;
    404413                static BasicType integer( q, BasicType::SignedInt );
    405                 cost = costFunc( &integer, dest, indexer, env );  // safe if dest >= int
     414                cost = costFunc( &integer, dest, srcIsLvalue, indexer, env );  // safe if dest >= int
    406415                if ( cost < Cost::unsafe ) {
    407416                        cost.incSafe();
     
    413422        void ConversionCost::postvisit( const TypeInstType * inst ) {
    414423                if ( const EqvClass * eqvClass = env.lookup( inst->name ) ) {
    415                         cost = costFunc( eqvClass->type, dest, indexer, env );
     424                        cost = costFunc( eqvClass->type, dest, srcIsLvalue, indexer, env );
    416425                } else if ( const TypeInstType * destAsInst = dynamic_cast< const TypeInstType * >( dest ) ) {
    417426                        if ( inst->name == destAsInst->name ) {
     
    423432                        assert( type );
    424433                        if ( type->base ) {
    425                                 cost = costFunc( type->base, dest, indexer, env ) + Cost::safe;
     434                                cost = costFunc( type->base, dest, srcIsLvalue, indexer, env ) + Cost::safe;
    426435                        } // if
    427436                } // if
     
    434443                        std::list< Type * >::const_iterator destIt = destAsTuple->types.begin();
    435444                        while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) {
    436                                 Cost newCost = costFunc( * srcIt++, * destIt++, indexer, env );
     445                                Cost newCost = costFunc( * srcIt++, * destIt++, srcIsLvalue, indexer, env );
    437446                                if ( newCost == Cost::infinity ) {
    438447                                        return;
  • src/ResolvExpr/ConversionCost.h

    rdee1f89 r1118b8b  
    1010// Created On       : Sun May 17 09:37:28 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jun 24 10:00:00 2019
    13 // Update Count     : 5
     12// Last Modified On : Thu Aug  8 16:13:00 2019
     13// Update Count     : 6
    1414//
    1515
     
    3333        class TypeEnvironment;
    3434
    35         typedef std::function<Cost(const Type *, const Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
     35        typedef std::function<Cost(const Type *, const Type *, bool,
     36                const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
     37
    3638        struct ConversionCost : public WithShortCircuiting {
    3739          public:
    38                 ConversionCost( const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
     40                ConversionCost( const Type * dest, bool srcIsLvalue,
     41                        const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
    3942
    4043                Cost get_cost() const { return cost; }
     
    5962          protected:
    6063                const Type * dest;
     64                bool srcIsLvalue;
    6165                const SymTab::Indexer &indexer;
    6266                Cost cost;
     
    6670
    6771        typedef std::function<int(const Type *, const Type *, const SymTab::Indexer &, const TypeEnvironment &)> PtrsFunction;
    68         Cost convertToReferenceCost( const Type * src, const ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
     72        Cost convertToReferenceCost( const Type * src, const ReferenceType * dest, bool srcIsLvalue,
     73                const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
    6974
    7075// Some function pointer types, differ in return type.
  • src/ResolvExpr/ResolveAssertions.cc

    rdee1f89 r1118b8b  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri Oct 05 13:46:00 2018
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 10 16:10:37 2019
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Aug  8 16:47:00 2019
     13// Update Count     : 3
    1414//
    1515
     
    156156                        for ( const auto& assn : x.assns ) {
    157157                                // compute conversion cost from satisfying decl to assertion
     158                                assert( !assn.match.adjType->get_lvalue() );
    158159                                k += computeConversionCost(
    159                                         assn.match.adjType, assn.decl->get_type(), indexer, x.env );
     160                                        assn.match.adjType, assn.decl->get_type(), false, indexer, x.env );
    160161
    161162                                // mark vars+specialization cost on function-type assertions
  • src/ResolvExpr/typeops.h

    rdee1f89 r1118b8b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 07:28:22 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  8 09:30:34 2019
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Aug  8 16:36:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    8080
    8181        // in CastCost.cc
    82         Cost castCost( const Type * src, const Type * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     82        Cost castCost( const Type * src, const Type * dest, bool srcIsLvalue,
     83                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    8384        Cost castCost(
    8485                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     
    8687
    8788        // in ConversionCost.cc
    88         Cost conversionCost( const Type * src, const Type * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     89        Cost conversionCost( const Type * src, const Type * dest, bool srcIsLvalue,
     90                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    8991        Cost conversionCost(
    9092                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     
    9294
    9395        // in AlternativeFinder.cc
    94         Cost computeConversionCost( Type * actualType, Type * formalType,
     96        Cost computeConversionCost( Type * actualType, Type * formalType, bool actualIsLvalue,
    9597                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    9698
Note: See TracChangeset for help on using the changeset viewer.