Changeset 721cd19f
- Timestamp:
- Jan 11, 2018, 10:50:03 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- bd0b6b62
- Parents:
- 80e8582
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CastCost.cc
r80e8582 r721cd19f 33 33 class 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 37 virtual void visit( BasicType *basicType ); … … 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 CastCost converter( dest, indexer, env, castCost ); 81 81 src->accept( converter ); 82 82 if ( converter.get_cost() == Cost::infinity ) { … … 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 -
src/ResolvExpr/ConversionCost.cc
r80e8582 r721cd19f 77 77 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) { 78 78 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 79 return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer &){79 return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer &, const TypeEnvironment & env ){ 80 80 return ptrsAssignable( t1, t2, env ); 81 81 }); 82 82 } else { 83 ConversionCost converter( dest, indexer, env );83 ConversionCost converter( dest, indexer, env, conversionCost ); 84 84 src->accept( converter ); 85 85 if ( converter.get_cost() == Cost::infinity ) { … … 120 120 } 121 121 } else { // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right? 122 int assignResult = func( srcAsRef->base, destAsRef->base, env, indexer);122 int assignResult = func( srcAsRef->base, destAsRef->base, indexer, env ); 123 123 PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; ) 124 124 if ( assignResult > 0 ) { … … 130 130 } else { 131 131 PRINT( std::cerr << "reference to rvalue conversion" << std::endl; ) 132 ConversionCost converter( dest, indexer, env );132 ConversionCost converter( dest, indexer, env, conversionCost ); 133 133 src->accept( converter ); 134 134 return converter.get_cost(); … … 173 173 } 174 174 175 ConversionCost::ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env )176 : dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ) {175 ConversionCost::ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc ) 176 : dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ), costFunc( costFunc ) { 177 177 } 178 178 … … 320 320 // recursively compute conversion cost from T1 to T2. 321 321 // cv can be safely dropped because of 'implicit dereference' behavior. 322 refType->base->accept( *this);322 cost = costFunc( refType->base, dest, indexer, env ); 323 323 if ( refType->base->get_qualifiers() == dest->get_qualifiers() ) { 324 324 cost.incReference(); // prefer exact qualifiers … … 352 352 static Type::Qualifiers q; 353 353 static BasicType integer( q, BasicType::SignedInt ); 354 integer.accept( *this); // safe if dest >= int354 cost = costFunc( &integer, dest, indexer, env ); // safe if dest >= int 355 355 if ( cost < Cost::unsafe ) { 356 356 cost.incSafe(); … … 364 364 NamedTypeDecl *namedType; 365 365 if ( env.lookup( inst->name, eqvClass ) ) { 366 cost = co nversionCost( eqvClass.type, dest, indexer, env );366 cost = costFunc( eqvClass.type, dest, indexer, env ); 367 367 } else if ( TypeInstType *destAsInst = dynamic_cast< TypeInstType* >( dest ) ) { 368 368 if ( inst->name == destAsInst->name ) { … … 374 374 assert( type ); 375 375 if ( type->base ) { 376 cost = co nversionCost( type->base, dest, indexer, env ) + Cost::safe;376 cost = costFunc( type->base, dest, indexer, env ) + Cost::safe; 377 377 } // if 378 378 } // if … … 385 385 std::list< Type * >::const_iterator destIt = destAsTuple->types.begin(); 386 386 while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) { 387 Cost newCost = co nversionCost( *srcIt++, *destIt++, indexer, env );387 Cost newCost = costFunc( *srcIt++, *destIt++, indexer, env ); 388 388 if ( newCost == Cost::infinity ) { 389 389 return; -
src/ResolvExpr/ConversionCost.h
r80e8582 r721cd19f 29 29 class TypeEnvironment; 30 30 31 typedef std::function<Cost(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction; 31 32 class ConversionCost : public Visitor { 32 33 public: 33 ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );34 ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction ); 34 35 35 36 Cost get_cost() const { return cost; } … … 55 56 Cost cost; 56 57 const TypeEnvironment &env; 58 CostFunction costFunc; 57 59 }; 58 60 59 typedef std::function<int(Type *, Type *, const TypeEnvironment &, const SymTab::Indexer&)> PtrsFunction;61 typedef std::function<int(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> PtrsFunction; 60 62 Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ); 61 63 } // namespace ResolvExpr
Note: See TracChangeset
for help on using the changeset viewer.