Changeset 0c6596f
- Timestamp:
- Aug 27, 2017, 11:25:00 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:
- 1cb758f2
- Parents:
- 2ae171d8
- git-author:
- Rob Schluntz <rschlunt@…> (08/27/17 11:24:53)
- git-committer:
- Rob Schluntz <rschlunt@…> (08/27/17 11:25:00)
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CastCost.cc
r2ae171d8 r0c6596f 58 58 return Cost::safe; 59 59 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) { 60 return convertToReferenceCost( src, refType, indexer, env ); 60 return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer & indexer) { 61 return ptrsCastable( t1, t2, env, indexer ); 62 }); 61 63 } else { 62 64 CastCost converter( dest, indexer, env ); -
src/ResolvExpr/ConversionCost.cc
r2ae171d8 r0c6596f 40 40 #define PRINT(x) 41 41 #endif 42 43 42 Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 44 43 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { … … 78 77 } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) { 79 78 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 80 return convertToReferenceCost( src, refType, indexer, env ); 79 return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer &){ 80 return ptrsAssignable( t1, t2, env ); 81 }); 81 82 } else { 82 83 ConversionCost converter( dest, indexer, env ); … … 90 91 } 91 92 92 Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {93 Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) { 93 94 PRINT( std::cerr << "convert to reference cost..." << std::endl; ) 94 95 if ( diff > 0 ) { 95 96 // TODO: document this 96 Cost cost = convertToReferenceCost( safe_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env );97 Cost cost = convertToReferenceCost( safe_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env, func ); 97 98 cost.incReference(); 98 99 return cost; 99 100 } else if ( diff < -1 ) { 100 101 // TODO: document this 101 Cost cost = convertToReferenceCost( src, safe_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env );102 Cost cost = convertToReferenceCost( src, safe_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env, func ); 102 103 cost.incReference(); 103 104 return cost; … … 110 111 return Cost::safe; 111 112 } else { // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right? 112 int assignResult = ptrsAssignable( srcAsRef->get_base(), destAsRef->get_base(), env);113 int assignResult = func( srcAsRef->get_base(), destAsRef->get_base(), env, indexer ); 113 114 PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; ) 114 115 if ( assignResult < 0 ) { … … 157 158 } 158 159 159 Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {160 Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) { 160 161 int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth(); 161 return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env );162 return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func ); 162 163 } 163 164 -
src/ResolvExpr/ConversionCost.h
r2ae171d8 r0c6596f 16 16 #pragma once 17 17 18 #include <functional> // for function 19 18 20 #include "Cost.h" // for Cost 19 21 #include "SynTree/Visitor.h" // for Visitor … … 21 23 22 24 namespace SymTab { 23 class Indexer;25 class Indexer; 24 26 } // namespace SymTab 25 27 26 28 namespace ResolvExpr { 27 class TypeEnvironment;29 class TypeEnvironment; 28 30 29 31 class ConversionCost : public Visitor { … … 55 57 }; 56 58 57 Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env ); 59 typedef std::function<int(Type *, Type *, const TypeEnvironment &, const SymTab::Indexer &)> PtrsFunction; 60 Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ); 58 61 } // namespace ResolvExpr 59 62
Note: See TracChangeset
for help on using the changeset viewer.