1 //===-------------- TypeOrdering.h - Total ordering for types -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides a function objects and specializations that
11 // allow QualType values to be sorted, used in std::maps, std::sets,
12 // llvm::DenseMaps, and llvm::DenseSets.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_TYPE_ORDERING_H
17 #define LLVM_CLANG_TYPE_ORDERING_H
19 #include "clang/AST/Type.h"
20 #include "clang/AST/CanonicalType.h"
25 /// QualTypeOrdering - Function object that provides a total ordering
26 /// on QualType values.
27 struct QualTypeOrdering : std::binary_function<QualType, QualType, bool> {
28 bool operator()(QualType T1, QualType T2) const {
29 return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
36 template<class> struct DenseMapInfo;
38 template<> struct DenseMapInfo<clang::QualType> {
39 static inline clang::QualType getEmptyKey() { return clang::QualType(); }
41 static inline clang::QualType getTombstoneKey() {
42 using clang::QualType;
43 return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
46 static unsigned getHashValue(clang::QualType Val) {
47 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
48 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
51 static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
56 template<> struct DenseMapInfo<clang::CanQualType> {
57 static inline clang::CanQualType getEmptyKey() {
58 return clang::CanQualType();
61 static inline clang::CanQualType getTombstoneKey() {
62 using clang::CanQualType;
63 return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
66 static unsigned getHashValue(clang::CanQualType Val) {
67 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
68 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
71 static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {