clang  6.0.0svn
TypeOrdering.h
Go to the documentation of this file.
1 //===-------------- TypeOrdering.h - Total ordering for types -------------===//
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 /// \file
11 /// \brief Allows QualTypes to be sorted and hence used in maps and sets.
12 ///
13 /// Defines clang::QualTypeOrdering, a total ordering on clang::QualType,
14 /// and hence enables QualType values to be sorted and to be used in
15 /// std::maps, std::sets, llvm::DenseMaps, and llvm::DenseSets.
16 ///
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef LLVM_CLANG_AST_TYPEORDERING_H
20 #define LLVM_CLANG_AST_TYPEORDERING_H
21 
23 #include "clang/AST/Type.h"
24 #include <functional>
25 
26 namespace clang {
27 
28 /// \brief Function object that provides a total ordering on QualType values.
30  bool operator()(QualType T1, QualType T2) const {
31  return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
32  }
33 };
34 
35 }
36 
37 namespace llvm {
38  template<class> struct DenseMapInfo;
39 
40  template<> struct DenseMapInfo<clang::QualType> {
41  static inline clang::QualType getEmptyKey() { return clang::QualType(); }
42 
43  static inline clang::QualType getTombstoneKey() {
44  using clang::QualType;
45  return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
46  }
47 
48  static unsigned getHashValue(clang::QualType Val) {
49  return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
50  ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
51  }
52 
53  static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
54  return LHS == RHS;
55  }
56  };
57 
58  template<> struct DenseMapInfo<clang::CanQualType> {
59  static inline clang::CanQualType getEmptyKey() {
60  return clang::CanQualType();
61  }
62 
64  using clang::CanQualType;
65  return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
66  }
67 
68  static unsigned getHashValue(clang::CanQualType Val) {
69  return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
70  ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
71  }
72 
74  return LHS == RHS;
75  }
76  };
77 }
78 
79 #endif
A (possibly-)qualified type.
Definition: Type.h:614
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
C Language Family Type Representation.
static clang::CanQualType getEmptyKey()
Definition: TypeOrdering.h:59
static clang::CanQualType getTombstoneKey()
Definition: TypeOrdering.h:63
static unsigned getHashValue(clang::QualType Val)
Definition: TypeOrdering.h:48
static clang::QualType getEmptyKey()
Definition: TypeOrdering.h:41
void * getAsOpaquePtr() const
Definition: Type.h:662
static clang::QualType getTombstoneKey()
Definition: TypeOrdering.h:43
static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS)
Definition: TypeOrdering.h:73
static unsigned getHashValue(clang::CanQualType Val)
Definition: TypeOrdering.h:68
Function object that provides a total ordering on QualType values.
Definition: TypeOrdering.h:29
static bool isEqual(clang::QualType LHS, clang::QualType RHS)
Definition: TypeOrdering.h:53
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:82
bool operator()(QualType T1, QualType T2) const
Definition: TypeOrdering.h:30
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:663
Dataflow Directional Tag Classes.
static CanQual< Type > getFromOpaquePtr(void *Ptr)
Construct a canonical type from its internal representation.
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.