clang  14.0.0git
TypeOrdering.h
Go to the documentation of this file.
1 //===-------------- TypeOrdering.h - Total ordering for types ---*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Allows QualTypes to be sorted and hence used in maps and sets.
11 ///
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.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_CLANG_AST_TYPEORDERING_H
19 #define LLVM_CLANG_AST_TYPEORDERING_H
20 
22 #include "clang/AST/Type.h"
23 #include <functional>
24 
25 namespace clang {
26 
27 /// Function object that provides a total ordering on QualType values.
29  bool operator()(QualType T1, QualType T2) const {
30  return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
31  }
32 };
33 
34 }
35 
36 namespace llvm {
37  template<class> struct DenseMapInfo;
38 
39  template<> struct DenseMapInfo<clang::QualType> {
40  static inline clang::QualType getEmptyKey() { return clang::QualType(); }
41 
42  static inline clang::QualType getTombstoneKey() {
43  using clang::QualType;
44  return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
45  }
46 
47  static unsigned getHashValue(clang::QualType Val) {
48  return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
49  ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
50  }
51 
52  static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
53  return LHS == RHS;
54  }
55  };
56 
57  template<> struct DenseMapInfo<clang::CanQualType> {
58  static inline clang::CanQualType getEmptyKey() {
59  return clang::CanQualType();
60  }
61 
63  using clang::CanQualType;
64  return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
65  }
66 
67  static unsigned getHashValue(clang::CanQualType Val) {
68  return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
69  ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
70  }
71 
73  return LHS == RHS;
74  }
75  };
76 }
77 
78 #endif
llvm
Definition: Dominators.h:30
llvm::DenseMapInfo< clang::CanQualType >::getHashValue
static unsigned getHashValue(clang::CanQualType Val)
Definition: TypeOrdering.h:67
llvm::DenseMapInfo< clang::QualType >::isEqual
static bool isEqual(clang::QualType LHS, clang::QualType RHS)
Definition: TypeOrdering.h:52
llvm::DenseMapInfo< clang::QualType >::getTombstoneKey
static clang::QualType getTombstoneKey()
Definition: TypeOrdering.h:42
llvm::DenseMapInfo< clang::CanQualType >::isEqual
static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS)
Definition: TypeOrdering.h:72
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
llvm::DenseMapInfo< clang::CanQualType >::getEmptyKey
static clang::CanQualType getEmptyKey()
Definition: TypeOrdering.h:58
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
llvm::DenseMapInfo
Definition: TypeOrdering.h:37
clang::CanQual::getAsOpaquePtr
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
Definition: CanonicalType.h:182
llvm::DenseMapInfo< clang::QualType >::getHashValue
static unsigned getHashValue(clang::QualType Val)
Definition: TypeOrdering.h:47
clang::CanQualType
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:212
uintptr_t
__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-base.h:124
Type.h
llvm::DenseMapInfo< clang::CanQualType >::getTombstoneKey
static clang::CanQualType getTombstoneKey()
Definition: TypeOrdering.h:62
clang::CanQual< Type >
llvm::DenseMapInfo< clang::QualType >::getEmptyKey
static clang::QualType getEmptyKey()
Definition: TypeOrdering.h:40
clang
Definition: CalledOnceCheck.h:17
CanonicalType.h
clang::QualType::getAsOpaquePtr
void * getAsOpaquePtr() const
Definition: Type.h:718
clang::QualTypeOrdering
Function object that provides a total ordering on QualType values.
Definition: TypeOrdering.h:28
clang::QualTypeOrdering::operator()
bool operator()(QualType T1, QualType T2) const
Definition: TypeOrdering.h:29