Ignore:
Timestamp:
Aug 12, 2019, 1:47:37 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
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:
14388c1, e0bd0f9
Parents:
4f5a8a2
Message:

lvalue is now read through the expression.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cc

    r4f5a8a2 r7d01cf44  
    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        }
Note: See TracChangeset for help on using the changeset viewer.