1 //===-------------- TypeOrdering.h - Total ordering for types ---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Allows QualTypes to be sorted and hence used in maps and sets.
12 /// Defines clang::QualTypeOrdering, a total ordering on clang::QualType,
13 /// and hence enables QualType values to be sorted and to be used in
14 /// std::maps, std::sets, llvm::DenseMaps, and llvm::DenseSets.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CLANG_AST_TYPEORDERING_H
19 #define LLVM_CLANG_AST_TYPEORDERING_H
21 #include "clang/AST/CanonicalType.h"
22 #include "clang/AST/Type.h"
27 /// Function object that provides a total ordering on QualType values.
28 struct QualTypeOrdering {
29 bool operator()(QualType T1, QualType T2) const {
30 return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
37 template<class> struct DenseMapInfo;
39 template<> struct DenseMapInfo<clang::QualType> {
40 static inline clang::QualType getEmptyKey() { return clang::QualType(); }
42 static inline clang::QualType getTombstoneKey() {
43 using clang::QualType;
44 return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
47 static unsigned getHashValue(clang::QualType Val) {
48 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
49 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
52 static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
57 template<> struct DenseMapInfo<clang::CanQualType> {
58 static inline clang::CanQualType getEmptyKey() {
59 return clang::CanQualType();
62 static inline clang::CanQualType getTombstoneKey() {
63 using clang::CanQualType;
64 return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
67 static unsigned getHashValue(clang::CanQualType Val) {
68 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
69 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
72 static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {