TypeOrdering.h revision 06159e878569e5f39bf0e8f11b84ac3ad0970597
1//===-------------- TypeOrdering.h - Total ordering for types -------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 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. 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_CLANG_TYPE_ORDERING_H 17#define LLVM_CLANG_TYPE_ORDERING_H 18 19#include "clang/AST/Type.h" 20#include <functional> 21 22namespace clang { 23 24/// QualTypeOrdering - Function object that provides a total ordering 25/// on QualType values. 26struct QualTypeOrdering : std::binary_function<QualType, QualType, bool> { 27 bool operator()(QualType T1, QualType T2) const { 28 return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr()); 29 } 30}; 31 32} 33 34namespace llvm { 35 template<class> struct DenseMapInfo; 36 37 template<> struct DenseMapInfo<clang::QualType> { 38 static inline clang::QualType getEmptyKey() { return clang::QualType(); } 39 40 static inline clang::QualType getTombstoneKey() { 41 using clang::QualType; 42 return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); 43 } 44 45 static unsigned getHashValue(clang::QualType Val) { 46 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ 47 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); 48 } 49 50 static bool isEqual(clang::QualType LHS, clang::QualType RHS) { 51 return LHS == RHS; 52 } 53 }; 54 55 // FIXME: Move to Type.h 56 template <> 57 struct isPodLike<clang::QualType> { static const bool value = true; }; 58} 59 60#endif 61