14#ifndef WPIUTIL_WPI_POINTERINTPAIR_H 
   15#define WPIUTIL_WPI_POINTERINTPAIR_H 
   29  static_assert(
sizeof(Ptr) == 
sizeof(intptr_t), 
"");
 
   33  static_assert(std::is_trivially_destructible<Ptr>::value, 
"");
 
   34  static_assert(std::is_trivially_copy_constructible<Ptr>::value, 
"");
 
   35  static_assert(std::is_trivially_move_constructible<Ptr>::value, 
"");
 
   39  constexpr intptr_t 
asInt()
 const {
 
   41    std::memcpy(&R, Data, 
sizeof(R));
 
 
   45  constexpr operator intptr_t()
 const { 
return asInt(); }
 
   48    std::memcpy(Data, &V, 
sizeof(Data));
 
 
   56  alignas(Ptr) 
unsigned char Data[
sizeof(Ptr)];
 
 
 
   60template <
typename T, 
typename Enable> 
struct DenseMapInfo;
 
   61template <
typename Po
interT, 
unsigned IntBits, 
typename PtrTraits>
 
   62struct PointerIntPairInfo;
 
   77template <
typename PointerTy, 
unsigned IntBits, 
typename IntType = unsigned,
 
   78          typename PtrTraits = PointerLikeTypeTraits<PointerTy>,
 
   79          typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>>
 
   94  PointerTy 
getPointer()
 const { 
return Info::getPointer(Value); }
 
   96  IntType 
getInt()
 const { 
return (IntType)Info::getInt(Value); }
 
   99    Value = Info::updatePointer(Value, PtrVal);
 
 
  103    Value = Info::updateInt(Value, 
static_cast<intptr_t
>(IntVal));
 
 
  107    Value = Info::updatePointer(0, PtrVal);
 
 
  111    Value = Info::updateInt(Info::updatePointer(0, PtrVal),
 
  112                            static_cast<intptr_t
>(IntVal));
 
 
  120    assert(Value == 
reinterpret_cast<intptr_t
>(
getPointer()) &&
 
  121           "Can only return the address if IntBits is cleared and " 
  122           "PtrTraits doesn't change the pointer");
 
 
  127    return reinterpret_cast<void *
>(Value.
asInt());
 
 
  131    Value = 
reinterpret_cast<intptr_t
>(Val);
 
 
  143    (void)PtrTraits::getFromVoidPointer(V);
 
 
  148    return Value == RHS.Value;
 
 
  152    return Value != RHS.Value;
 
 
  159    return Value <= RHS.Value;
 
 
  163    return Value >= RHS.Value;
 
 
 
  167template <
typename Po
interT, 
unsigned IntBits, 
typename PtrTraits>
 
  169  static_assert(PtrTraits::NumLowBitsAvailable <
 
  170                    std::numeric_limits<uintptr_t>::digits,
 
  171                "cannot use a pointer type that has all bits free");
 
  172  static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
 
  173                "PointerIntPair with integer size too large for pointer");
 
  177        ~(uintptr_t)(((intptr_t)1 << PtrTraits::NumLowBitsAvailable) - 1),
 
  181    IntShift = (uintptr_t)PtrTraits::NumLowBitsAvailable - IntBits,
 
  184    IntMask = (uintptr_t)(((intptr_t)1 << IntBits) - 1),
 
 
  191    return PtrTraits::getFromVoidPointer(
 
 
  201        reinterpret_cast<intptr_t
>(PtrTraits::getAsVoidPointer(Ptr));
 
  203           "Pointer is not sufficiently aligned");
 
  205    return PtrWord | (OrigValue & ~PointerBitMask);
 
 
  208  static intptr_t 
updateInt(intptr_t OrigValue, intptr_t Int) {
 
  209    intptr_t IntWord = 
static_cast<intptr_t
>(Int);
 
  210    assert((IntWord & ~
IntMask) == 0 && 
"Integer too large for field");
 
 
 
  218template <
typename Po
interTy, 
unsigned IntBits, 
typename IntType>
 
  223    uintptr_t Val = 
static_cast<uintptr_t
>(-1);
 
  224    Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable;
 
  225    return Ty::getFromOpaqueValue(
reinterpret_cast<void *
>(Val));
 
 
  229    uintptr_t Val = 
static_cast<uintptr_t
>(-2);
 
  230    Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
 
  231    return Ty::getFromOpaqueValue(
reinterpret_cast<void *
>(Val));
 
 
  236    return unsigned(IV) ^ unsigned(IV >> 9);
 
 
  239  static bool isEqual(
const Ty &LHS, 
const Ty &RHS) { 
return LHS == RHS; }
 
 
  243template <
typename PointerTy, 
unsigned IntBits, 
typename IntType,
 
  249    return P.getOpaqueValue();
 
 
  262  static constexpr int NumLowBitsAvailable =
 
  263      PtrTraits::NumLowBitsAvailable - IntBits;
 
 
  267template <std::size_t I, 
typename PointerTy, 
unsigned IntBits, 
typename IntType,
 
  268          typename PtrTraits, 
typename Info>
 
  271  static_assert(I < 2);
 
  272  if constexpr (I == 0)
 
 
  281template <
typename PointerTy, 
unsigned IntBits, 
typename IntType,
 
  282          typename PtrTraits, 
typename Info>
 
  284    wpi::PointerIntPair<PointerTy, IntBits, IntType, PtrTraits, Info>>
 
  285    : std::integral_constant<std::size_t, 2> {};
 
 
  287template <std::size_t I, 
typename PointerTy, 
unsigned IntBits, 
typename IntType,
 
  288          typename PtrTraits, 
typename Info>
 
  290    I, 
wpi::PointerIntPair<PointerTy, IntBits, IntType, PtrTraits, Info>>
 
  291    : std::conditional<I == 0, PointerTy, IntType> {};
 
 
 
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition PointerIntPair.h:80
void setPointer(PointerTy PtrVal) &
Definition PointerIntPair.h:98
PointerIntPair(PointerTy PtrVal)
Definition PointerIntPair.h:92
void setPointerAndInt(PointerTy PtrVal, IntType IntVal) &
Definition PointerIntPair.h:110
bool operator>=(const PointerIntPair &RHS) const
Definition PointerIntPair.h:162
constexpr PointerIntPair()=default
void setInt(IntType IntVal) &
Definition PointerIntPair.h:102
void initWithPointer(PointerTy PtrVal) &
Definition PointerIntPair.h:106
bool operator<(const PointerIntPair &RHS) const
Definition PointerIntPair.h:155
PointerTy const * getAddrOfPointer() const
Definition PointerIntPair.h:115
PointerIntPair(PointerTy PtrVal, IntType IntVal)
Definition PointerIntPair.h:88
static PointerIntPair getFromOpaqueValue(void *V)
Definition PointerIntPair.h:134
static PointerIntPair getFromOpaqueValue(const void *V)
Definition PointerIntPair.h:142
bool operator>(const PointerIntPair &RHS) const
Definition PointerIntPair.h:156
bool operator==(const PointerIntPair &RHS) const
Definition PointerIntPair.h:147
void * getOpaqueValue() const
Definition PointerIntPair.h:126
IntType getInt() const
Definition PointerIntPair.h:96
PointerTy getPointer() const
Definition PointerIntPair.h:94
void setFromOpaqueValue(void *Val) &
Definition PointerIntPair.h:130
bool operator!=(const PointerIntPair &RHS) const
Definition PointerIntPair.h:151
PointerTy * getAddrOfPointer()
Definition PointerIntPair.h:119
bool operator<=(const PointerIntPair &RHS) const
Definition PointerIntPair.h:158
detail namespace with internal helper functions
Definition input_adapters.h:32
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
Foonathan namespace.
Definition ntcore_cpp.h:26
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition PointerIntPair.h:270
static Ty getTombstoneKey()
Definition PointerIntPair.h:228
static unsigned getHashValue(Ty V)
Definition PointerIntPair.h:234
static bool isEqual(const Ty &LHS, const Ty &RHS)
Definition PointerIntPair.h:239
static Ty getEmptyKey()
Definition PointerIntPair.h:222
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition Hashing.h:65
Definition PointerIntPair.h:168
static intptr_t getInt(intptr_t Value)
Definition PointerIntPair.h:195
MaskAndShiftConstants
Definition PointerIntPair.h:174
@ PointerBitMask
PointerBitMask - The bits that come from the pointer.
Definition PointerIntPair.h:176
@ IntMask
IntMask - This is the unshifted mask for valid bits of the int type.
Definition PointerIntPair.h:184
@ IntShift
IntShift - The number of low bits that we reserve for other uses, and keep zero.
Definition PointerIntPair.h:181
@ ShiftedIntMask
Definition PointerIntPair.h:187
static PointerT getPointer(intptr_t Value)
Definition PointerIntPair.h:190
static intptr_t updatePointer(intptr_t OrigValue, PointerT Ptr)
Definition PointerIntPair.h:199
static intptr_t updateInt(intptr_t OrigValue, intptr_t Int)
Definition PointerIntPair.h:208
static void * getAsVoidPointer(const PointerIntPair< PointerTy, IntBits, IntType > &P)
Definition PointerIntPair.h:248
static PointerIntPair< PointerTy, IntBits, IntType > getFromVoidPointer(const void *P)
Definition PointerIntPair.h:258
static PointerIntPair< PointerTy, IntBits, IntType > getFromVoidPointer(void *P)
Definition PointerIntPair.h:253
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition PointerLikeTypeTraits.h:25
Definition PointerIntPair.h:28
constexpr PunnedPointer(intptr_t i=0)
Definition PointerIntPair.h:37
constexpr PunnedPointer & operator=(intptr_t V)
Definition PointerIntPair.h:47
Ptr * getPointerAddress()
Definition PointerIntPair.h:52
const Ptr * getPointerAddress() const
Definition PointerIntPair.h:53
constexpr intptr_t asInt() const
Definition PointerIntPair.h:39