From fc1d1341ab57b5e351c1cb2eb16cc810ea657fd6 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 9 Aug 2017 18:34:21 +0000 Subject: [PATCH] PointerLikeTypeTraits: class->struct & remove the base definition This simplifies implementations and removing the base definition paves the way for detecting whether a type is 'pointer like'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310507 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/PointerEmbeddedInt.h | 5 ++--- include/llvm/ADT/PointerIntPair.h | 3 +-- include/llvm/ADT/PointerUnion.h | 9 +++------ include/llvm/Support/PointerLikeTypeTraits.h | 21 ++++++-------------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/include/llvm/ADT/PointerEmbeddedInt.h b/include/llvm/ADT/PointerEmbeddedInt.h index 34323b5b8af..ab4e1048a5b 100644 --- a/include/llvm/ADT/PointerEmbeddedInt.h +++ b/include/llvm/ADT/PointerEmbeddedInt.h @@ -52,7 +52,7 @@ class PointerEmbeddedInt { explicit RawValueTag() = default; }; - friend class PointerLikeTypeTraits; + friend struct PointerLikeTypeTraits; explicit PointerEmbeddedInt(uintptr_t Value, RawValueTag) : Value(Value) {} @@ -80,10 +80,9 @@ public: // Provide pointer like traits to support use with pointer unions and sum // types. template -class PointerLikeTypeTraits> { +struct PointerLikeTypeTraits> { using T = PointerEmbeddedInt; -public: static inline void *getAsVoidPointer(const T &P) { return reinterpret_cast(P.Value); } diff --git a/include/llvm/ADT/PointerIntPair.h b/include/llvm/ADT/PointerIntPair.h index 83fbf127e6d..f7e100bb4e1 100644 --- a/include/llvm/ADT/PointerIntPair.h +++ b/include/llvm/ADT/PointerIntPair.h @@ -201,9 +201,8 @@ struct DenseMapInfo> { // Teach SmallPtrSet that PointerIntPair is "basically a pointer". template -class PointerLikeTypeTraits< +struct PointerLikeTypeTraits< PointerIntPair> { -public: static inline void * getAsVoidPointer(const PointerIntPair &P) { return P.getOpaqueValue(); diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h index aeab641f571..d019edb57e5 100644 --- a/include/llvm/ADT/PointerUnion.h +++ b/include/llvm/ADT/PointerUnion.h @@ -207,8 +207,7 @@ bool operator<(PointerUnion lhs, PointerUnion rhs) { // Teach SmallPtrSet that PointerUnion is "basically a pointer", that has // # low bits available = min(PT1bits,PT2bits)-1. template -class PointerLikeTypeTraits> { -public: +struct PointerLikeTypeTraits> { static inline void *getAsVoidPointer(const PointerUnion &P) { return P.getOpaqueValue(); } @@ -328,8 +327,7 @@ public: // Teach SmallPtrSet that PointerUnion3 is "basically a pointer", that has // # low bits available = min(PT1bits,PT2bits,PT2bits)-2. template -class PointerLikeTypeTraits> { -public: +struct PointerLikeTypeTraits> { static inline void *getAsVoidPointer(const PointerUnion3 &P) { return P.getOpaqueValue(); } @@ -435,8 +433,7 @@ public: // Teach SmallPtrSet that PointerUnion4 is "basically a pointer", that has // # low bits available = min(PT1bits,PT2bits,PT2bits)-2. template -class PointerLikeTypeTraits> { -public: +struct PointerLikeTypeTraits> { static inline void * getAsVoidPointer(const PointerUnion4 &P) { return P.getOpaqueValue(); diff --git a/include/llvm/Support/PointerLikeTypeTraits.h b/include/llvm/Support/PointerLikeTypeTraits.h index 521a49684e4..97ce29bf6b9 100644 --- a/include/llvm/Support/PointerLikeTypeTraits.h +++ b/include/llvm/Support/PointerLikeTypeTraits.h @@ -22,11 +22,7 @@ namespace llvm { /// A traits type that is used to handle pointer types and things that are just /// wrappers for pointers as a uniform entity. -template class PointerLikeTypeTraits { - // getAsVoidPointer - // getFromVoidPointer - // getNumLowBitsAvailable -}; +template struct PointerLikeTypeTraits; namespace detail { /// A tiny meta function to compute the log2 of a compile time constant. @@ -37,16 +33,14 @@ template <> struct ConstantLog2<1> : std::integral_constant {}; } // Provide PointerLikeTypeTraits for non-cvr pointers. -template class PointerLikeTypeTraits { -public: +template struct PointerLikeTypeTraits { static inline void *getAsVoidPointer(T *P) { return P; } static inline T *getFromVoidPointer(void *P) { return static_cast(P); } enum { NumLowBitsAvailable = detail::ConstantLog2::value }; }; -template <> class PointerLikeTypeTraits { -public: +template <> struct PointerLikeTypeTraits { static inline void *getAsVoidPointer(void *P) { return P; } static inline void *getFromVoidPointer(void *P) { return P; } @@ -61,10 +55,9 @@ public: }; // Provide PointerLikeTypeTraits for const things. -template class PointerLikeTypeTraits { +template struct PointerLikeTypeTraits { typedef PointerLikeTypeTraits NonConst; -public: static inline const void *getAsVoidPointer(const T P) { return NonConst::getAsVoidPointer(P); } @@ -75,10 +68,9 @@ public: }; // Provide PointerLikeTypeTraits for const pointers. -template class PointerLikeTypeTraits { +template struct PointerLikeTypeTraits { typedef PointerLikeTypeTraits NonConst; -public: static inline const void *getAsVoidPointer(const T *P) { return NonConst::getAsVoidPointer(const_cast(P)); } @@ -89,8 +81,7 @@ public: }; // Provide PointerLikeTypeTraits for uintptr_t. -template <> class PointerLikeTypeTraits { -public: +template <> struct PointerLikeTypeTraits { static inline void *getAsVoidPointer(uintptr_t P) { return reinterpret_cast(P); } -- 2.40.0