Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cc

    rbd0b6b62 r150ec33  
    3131
    3232namespace ResolvExpr {
    33         struct CastCost : public ConversionCost {
     33        class CastCost : public ConversionCost {
    3434          public:
    35                 CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
     35                CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    3636
    37                 using ConversionCost::previsit;
    38                 using ConversionCost::postvisit;
    39                 void postvisit( BasicType * basicType );
    40                 void postvisit( PointerType * pointerType );
     37                virtual void visit( BasicType *basicType );
     38                virtual void visit( PointerType *pointerType );
    4139        };
    4240
     
    5452                                // all typedefs should be gone by this point
    5553                                TypeDecl *type = strict_dynamic_cast< TypeDecl* >( namedType );
    56                                 if ( type->base ) {
    57                                         return castCost( src, type->base, indexer, env ) + Cost::safe;
     54                                if ( type->get_base() ) {
     55                                        return castCost( src, type->get_base(), indexer, env ) + Cost::safe;
    5856                                } // if
    5957                        } // if
     
    7674                } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
    7775                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
    78                         return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
     76                        return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer & indexer) {
    7977                                return ptrsCastable( t1, t2, env, indexer );
    8078                        });
    8179                } else {
    82                         PassVisitor<CastCost> converter( dest, indexer, env, castCost );
     80                        CastCost converter( dest, indexer, env );
    8381                        src->accept( converter );
    84                         if ( converter.pass.get_cost() == Cost::infinity ) {
     82                        if ( converter.get_cost() == Cost::infinity ) {
    8583                                return Cost::infinity;
    8684                        } else {
    8785                                // xxx - why are we adding cost 0 here?
    88                                 return converter.pass.get_cost() + Cost::zero;
     86                                return converter.get_cost() + Cost::zero;
    8987                        } // if
    9088                } // if
    9189        }
    9290
    93         CastCost::CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
    94                 : ConversionCost( dest, indexer, env, costFunc ) {
     91        CastCost::CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env )
     92                : ConversionCost( dest, indexer, env ) {
    9593        }
    9694
    97         void CastCost::postvisit( BasicType *basicType ) {
     95        void CastCost::visit( BasicType *basicType ) {
    9896                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    9997                if ( destAsPointer && basicType->isInteger() ) {
     
    105103        }
    106104
    107         void CastCost::postvisit( PointerType *pointerType ) {
     105        void CastCost::visit( PointerType *pointerType ) {
    108106                if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
    109                         if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {
     107                        if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->get_base(), destAsPtr->get_base(), indexer, env ) ) {
    110108                                cost = Cost::safe;
    111109                        } else {
    112110                                TypeEnvironment newEnv( env );
    113                                 newEnv.add( pointerType->forall );
    114                                 newEnv.add( pointerType->base->forall );
    115                                 int castResult = ptrsCastable( pointerType->base, destAsPtr->base, newEnv, indexer );
     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 );
    116114                                if ( castResult > 0 ) {
    117115                                        cost = Cost::safe;
Note: See TracChangeset for help on using the changeset viewer.