Changeset 90152a4 for src/ResolvExpr/CastCost.cc
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CastCost.cc
rf9feab8 r90152a4 31 31 32 32 namespace ResolvExpr { 33 classCastCost : public ConversionCost {33 struct CastCost : public ConversionCost { 34 34 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 ); 36 36 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 ); 39 41 }; 40 42 41 43 Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 42 44 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 ); 48 48 } else { 49 49 return Cost::infinity; 50 50 } 51 } else if ( ( namedType = indexer.lookupType( destAsTypeInst->get_name()) ) ) {51 } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) { 52 52 // all typedefs should be gone by this point 53 53 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; 56 56 } // if 57 57 } // if … … 74 74 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) { 75 75 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 ) { 77 77 return ptrsCastable( t1, t2, env, indexer ); 78 78 }); 79 79 } else { 80 CastCost converter( dest, indexer, env);80 PassVisitor<CastCost> converter( dest, indexer, env, castCost ); 81 81 src->accept( converter ); 82 if ( converter. get_cost() == Cost::infinity ) {82 if ( converter.pass.get_cost() == Cost::infinity ) { 83 83 return Cost::infinity; 84 84 } else { 85 85 // xxx - why are we adding cost 0 here? 86 return converter. get_cost() + Cost::zero;86 return converter.pass.get_cost() + Cost::zero; 87 87 } // if 88 88 } // if 89 89 } 90 90 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 ) { 93 93 } 94 94 95 void CastCost:: visit( BasicType *basicType ) {95 void CastCost::postvisit( BasicType *basicType ) { 96 96 PointerType *destAsPointer = dynamic_cast< PointerType* >( dest ); 97 97 if ( destAsPointer && basicType->isInteger() ) { … … 103 103 } 104 104 105 void CastCost:: visit( PointerType *pointerType ) {105 void CastCost::postvisit( PointerType *pointerType ) { 106 106 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 ) ) { 108 108 cost = Cost::safe; 109 109 } else { 110 110 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 ); 114 114 if ( castResult > 0 ) { 115 115 cost = Cost::safe;
Note:
See TracChangeset
for help on using the changeset viewer.