WPILibC++  unspecified
PointerLikeTypeTraits.h
1 //===- llvm/Support/PointerLikeTypeTraits.h - Pointer Traits ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the PointerLikeTypeTraits class. This allows data
11 // structures to reason about pointers and other things that are pointer sized.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
16 #define LLVM_SUPPORT_POINTERLIKETYPETRAITS_H
17 
18 #include "llvm/AlignOf.h"
19 #include <cstdint>
20 
21 namespace llvm {
22 
25 template <typename T> class PointerLikeTypeTraits {
26  // getAsVoidPointer
27  // getFromVoidPointer
28  // getNumLowBitsAvailable
29 };
30 
31 namespace detail {
33 template <size_t N>
35  : std::integral_constant<size_t, ConstantLog2<N / 2>::value + 1> {};
36 template <> struct ConstantLog2<1> : std::integral_constant<size_t, 0> {};
37 }
38 
39 // Provide PointerLikeTypeTraits for non-cvr pointers.
40 template <typename T> class PointerLikeTypeTraits<T *> {
41 public:
42  static inline void *getAsVoidPointer(T *P) { return P; }
43  static inline T *getFromVoidPointer(void *P) { return static_cast<T *>(P); }
44 
45  enum {
46  NumLowBitsAvailable = detail::ConstantLog2<AlignOf<T>::Alignment>::value
47  };
48 };
49 
50 template <> class PointerLikeTypeTraits<void *> {
51 public:
52  static inline void *getAsVoidPointer(void *P) { return P; }
53  static inline void *getFromVoidPointer(void *P) { return P; }
54 
62  enum { NumLowBitsAvailable = 2 };
63 };
64 
65 // Provide PointerLikeTypeTraits for const pointers.
66 template <typename T> class PointerLikeTypeTraits<const T *> {
68 
69 public:
70  static inline const void *getAsVoidPointer(const T *P) {
71  return NonConst::getAsVoidPointer(const_cast<T *>(P));
72  }
73  static inline const T *getFromVoidPointer(const void *P) {
74  return NonConst::getFromVoidPointer(const_cast<void *>(P));
75  }
76  enum { NumLowBitsAvailable = NonConst::NumLowBitsAvailable };
77 };
78 
79 // Provide PointerLikeTypeTraits for uintptr_t.
80 template <> class PointerLikeTypeTraits<uintptr_t> {
81 public:
82  static inline void *getAsVoidPointer(uintptr_t P) {
83  return reinterpret_cast<void *>(P);
84  }
85  static inline uintptr_t getFromVoidPointer(void *P) {
86  return reinterpret_cast<uintptr_t>(P);
87  }
88  // No bits are available!
89  enum { NumLowBitsAvailable = 0 };
90 };
91 
92 } // end namespace llvm
93 
94 #endif
Definition: Path.inc:27
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
Definition: PointerLikeTypeTraits.h:25
A tiny meta function to compute the log2 of a compile time constant.
Definition: PointerLikeTypeTraits.h:34
Definition: PointerLikeTypeTraits.h:40