1 //===-------------- TypeOrdering.h - Total ordering for types ---*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
11 /// Allows QualTypes to be sorted and hence used in maps and sets.
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.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CLANG_AST_TYPEORDERING_H
20 #define LLVM_CLANG_AST_TYPEORDERING_H
22 #include "clang/AST/CanonicalType.h"
23 #include "clang/AST/Type.h"
28 /// Function object that provides a total ordering on QualType values.
29 struct QualTypeOrdering {
30 bool operator()(QualType T1, QualType T2) const {
31 return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
38 template<class> struct DenseMapInfo;
40 template<> struct DenseMapInfo<clang::QualType> {
41 static inline clang::QualType getEmptyKey() { return clang::QualType(); }
43 static inline clang::QualType getTombstoneKey() {
44 using clang::QualType;
45 return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
48 static unsigned getHashValue(clang::QualType Val) {
49 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
50 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
53 static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
58 template<> struct DenseMapInfo<clang::CanQualType> {
59 static inline clang::CanQualType getEmptyKey() {
60 return clang::CanQualType();
63 static inline clang::CanQualType getTombstoneKey() {
64 using clang::CanQualType;
65 return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
68 static unsigned getHashValue(clang::CanQualType Val) {
69 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
70 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
73 static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {