diff options
Diffstat (limited to 'include/clang/AST/TypeOrdering.h')
-rw-r--r-- | include/clang/AST/TypeOrdering.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/include/clang/AST/TypeOrdering.h b/include/clang/AST/TypeOrdering.h new file mode 100644 index 0000000..4f60273 --- /dev/null +++ b/include/clang/AST/TypeOrdering.h @@ -0,0 +1,63 @@ +//===-------------- TypeOrdering.h - Total ordering for types -------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides a function objects and specializations that +// allow QualType values to be sorted, used in std::maps, std::sets, +// llvm::DenseMaps, and llvm::DenseSets. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TYPE_ORDERING_H +#define LLVM_CLANG_TYPE_ORDERING_H + +#include "clang/AST/Type.h" +#include <functional> + +namespace clang { + +/// QualTypeOrdering - Function object that provides a total ordering +/// on QualType values. +struct QualTypeOrdering : std::binary_function<QualType, QualType, bool> { + bool operator()(QualType T1, QualType T2) const { + return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr()); + } +}; + +} + +namespace llvm { + template<class> struct DenseMapInfo; + + template<> struct DenseMapInfo<clang::QualType> { + static inline clang::QualType getEmptyKey() { return clang::QualType(); } + + static inline clang::QualType getTombstoneKey() { + using clang::QualType; + return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); + } + + static unsigned getHashValue(clang::QualType Val) { + return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ + ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); + } + + static bool isEqual(clang::QualType LHS, clang::QualType RHS) { + return LHS == RHS; + } + + static bool isPod() { + // QualType isn't *technically* a POD type. However, we can get + // away with calling it a POD type since its copy constructor, + // copy assignment operator, and destructor are all trivial. + return true; + } + }; +} + +#endif |