Changeset 06ecda9
- Timestamp:
- Aug 3, 2024, 11:37:45 PM (5 months ago)
- Branches:
- master
- Children:
- bcb41f7
- Parents:
- 1571e4d
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r1571e4d r06ecda9 938 938 addAggMembers( unionInst, aggrExpr, *cand, Cost::unsafe, "" ); 939 939 } else if ( auto enumInst = aggrExpr->result.as< ast::EnumInstType >() ) { 940 addEnumValueAsCandidate( enumInst, aggrExpr, Cost::unsafe);940 addEnumValueAsCandidate( enumInst, aggrExpr, Cost::implicit ); 941 941 } 942 942 } -
src/ResolvExpr/Cost.hpp
r1571e4d r06ecda9 31 31 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 32 32 // Little-endian => first value is low priority and last is high priority. 33 unsigned char padding; ///< unused34 33 unsigned char referenceCost; ///< reference conversions 35 34 unsigned char specCost; ///< Polymorphic type specializations (type assertions), negative cost … … 38 37 unsigned char safeCost; ///< Safe (widening) conversions 39 38 unsigned char polyCost; ///< Count of parameters and return values bound to some poly type 39 unsigned char implicitCost; ///< Aggregate implicit cost 40 40 unsigned char unsafeCost; ///< Unsafe (narrowing) conversions 41 41 #else … … 46 46 }; 47 47 static const unsigned char correctb = 0xff; // byte correction for negative spec cost 48 static const uint64_t correctw = 0x00'00'00'00'00' ff'00'00; //' word correction for negative spec cost48 static const uint64_t correctw = 0x00'00'00'00'00'00'ff'00; //' word correction for negative spec cost 49 49 public: 50 50 // Compiler adjusts constants for correct endian. 51 51 enum : uint64_t { 52 zero = 0x00'00'00'00'00'ff'00'00, 53 infinity = 0xff'ff'ff'ff'ff'00'ff'ff, 54 unsafe = 0x01'00'00'00'00'ff'00'00, 55 poly = 0x00'01'00'00'00'ff'00'00, 56 safe = 0x00'00'01'00'00'ff'00'00, 57 sign = 0x00'00'00'01'00'ff'00'00, 58 var = 0x00'00'00'00'01'ff'00'00, 59 spec = 0x00'00'00'00'00'fe'00'00, 60 reference = 0x00'00'00'00'00'ff'01'00, 52 zero = 0x00'00'00'00'00'00'ff'00, 53 infinity = 0xff'ff'ff'ff'ff'ff'00'ff, 54 unsafe = 0x01'00'00'00'00'00'ff'00, 55 implicit = 0x00'01'00'00'01'00'ff'00, 56 poly = 0x00'00'01'00'00'00'ff'00, 57 safe = 0x00'00'00'01'00'00'ff'00, 58 sign = 0x00'00'00'00'01'00'ff'00, 59 var = 0x00'00'00'00'00'01'ff'00, 60 spec = 0x00'00'00'00'00'00'fe'00, 61 reference = 0x00'00'00'00'00'00'ff'01, 61 62 }; //' 62 63 63 64 Cost( uint64_t all ) { Cost::all = all; } 64 Cost( int unsafeCost, int polyCost, int safeCost, int signCost, int varCost, int specCost, int referenceCost ) {65 Cost( int unsafeCost, int polyCost, int safeCost, int signCost, int implicitCost, int varCost, int specCost, int referenceCost ) { 65 66 // Assume little-endian => first value is low priority and last is high priority. 66 67 v = { 67 68 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 68 (unsigned char)0, // padding69 69 (unsigned char)referenceCost, // low priority 70 70 (unsigned char)(specCost + correctb), // correct for signedness … … 73 73 (unsigned char)safeCost, 74 74 (unsigned char)polyCost, 75 (unsigned char)implicitCost, 75 76 (unsigned char)unsafeCost, // high priority 76 77 #else … … 81 82 82 83 int get_unsafeCost() const { return v.unsafeCost; } 84 int get_implictCost() const { return v.implicitCost; } 83 85 int get_polyCost() const { return v.polyCost; } 84 86 int get_safeCost() const { return v.safeCost; } … … 112 114 Cost incUnsafe( int inc = 1 ) { 113 115 if ( all != infinity ) { assert( v.unsafeCost + inc <= UCHAR_MAX ); v.unsafeCost += inc; } 116 return *this; 117 } 118 119 Cost incImplicit( int inc = 1 ) { 120 if ( all != infinity ) { assert( v.implicitCost + inc <= UCHAR_MAX ); v.implicitCost += inc; } 114 121 return *this; 115 122 } … … 168 175 169 176 inline std::ostream & operator<<( std::ostream & os, const Cost cost ) { 170 return os << "( " << cost.get_unsafeCost() << ", " << cost.get_ polyCost() << ", " << cost.get_safeCost()177 return os << "( " << cost.get_unsafeCost() << ", " << cost.get_implictCost() << ", " << cost.get_polyCost() << ", " << cost.get_safeCost() 171 178 << ", " << cost.get_signCost() << ", " << cost.get_varCost() << ", " << cost.get_specCost() 172 179 << ", " << cost.get_referenceCost() << " )";
Note: See TracChangeset
for help on using the changeset viewer.