Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cc

    rf9feab8 r90152a4  
    3131
    3232namespace ResolvExpr {
    33         class CastCost : public ConversionCost {
     33        struct CastCost : public ConversionCost {
    3434          public:
    35                 CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
     35                CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
    3636
    37                 virtual void visit( BasicType *basicType );
    38                 virtual void visit( PointerType *pointerType );
     37                using ConversionCost::previsit;
     38                using ConversionCost::postvisit;
     39                void postvisit( BasicType * basicType );
     40                void postvisit( PointerType * pointerType );
    3941        };
    4042
    4143        Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    4244                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    43                         EqvClass eqvClass;
    44                         NamedTypeDecl *namedType;
    45                         if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
    46                                 if ( eqvClass.type ) {
    47                                         return castCost( src, eqvClass.type, indexer, env );
     45                        if ( const EqvClass* eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
     46                                if ( eqvClass->type ) {
     47                                        return castCost( src, eqvClass->type, indexer, env );
    4848                                } else {
    4949                                        return Cost::infinity;
    5050                                }
    51                         } else if ( ( namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) ) {
     51                        } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) {
    5252                                // all typedefs should be gone by this point
    5353                                TypeDecl *type = strict_dynamic_cast< TypeDecl* >( namedType );
    54                                 if ( type->get_base() ) {
    55                                         return castCost( src, type->get_base(), indexer, env ) + Cost::safe;
     54                                if ( type->base ) {
     55                                        return castCost( src, type->base, indexer, env ) + Cost::safe;
    5656                                } // if
    5757                        } // if
     
    7474                } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
    7575                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    76                         return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer & indexer) {
     76                        return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
    7777                                return ptrsCastable( t1, t2, env, indexer );
    7878                        });
    7979                } else {
    80                         CastCost converter( dest, indexer, env );
     80                        PassVisitor<CastCost> converter( dest, indexer, env, castCost );
    8181                        src->accept( converter );
    82                         if ( converter.get_cost() == Cost::infinity ) {
     82                        if ( converter.pass.get_cost() == Cost::infinity ) {
    8383                                return Cost::infinity;
    8484                        } else {
    8585                                // xxx - why are we adding cost 0 here?
    86                                 return converter.get_cost() + Cost::zero;
     86                                return converter.pass.get_cost() + Cost::zero;
    8787                        } // if
    8888                } // if
    8989        }
    9090
    91         CastCost::CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env )
    92                 : ConversionCost( dest, indexer, env ) {
     91        CastCost::CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
     92                : ConversionCost( dest, indexer, env, costFunc ) {
    9393        }
    9494
    95         void CastCost::visit( BasicType *basicType ) {
     95        void CastCost::postvisit( BasicType *basicType ) {
    9696                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    9797                if ( destAsPointer && basicType->isInteger() ) {
     
    103103        }
    104104
    105         void CastCost::visit( PointerType *pointerType ) {
     105        void CastCost::postvisit( PointerType *pointerType ) {
    106106                if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
    107                         if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->get_base(), destAsPtr->get_base(), indexer, env ) ) {
     107                        if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {
    108108                                cost = Cost::safe;
    109109                        } else {
    110110                                TypeEnvironment newEnv( env );
    111                                 newEnv.add( pointerType->get_forall() );
    112                                 newEnv.add( pointerType->get_base()->get_forall() );
    113                                 int castResult = ptrsCastable( pointerType->get_base(), destAsPtr->get_base(), newEnv, indexer );
     111                                newEnv.add( pointerType->forall );
     112                                newEnv.add( pointerType->base->forall );
     113                                int castResult = ptrsCastable( pointerType->base, destAsPtr->base, newEnv, indexer );
    114114                                if ( castResult > 0 ) {
    115115                                        cost = Cost::safe;
Note: See TracChangeset for help on using the changeset viewer.