TypeOrdering.h revision b7c3ca8af0a1a3b66fb220562c72dd3102153d5b
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 "llvm/ADT/DenseMap.h" 21#include <functional> 22 23namespace clang { 24 25/// QualTypeOrdering - Function object that provides a total ordering 26/// on QualType values. 27struct QualTypeOrdering : std::binary_function<QualType, QualType, bool> { 28 bool operator()(QualType T1, QualType T2) const { 29 return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr()); 30 } 31}; 32 33} 34 35namespace llvm { 36 template<> struct DenseMapInfo<clang::QualType> { 37 static inline clang::QualType getEmptyKey() { return clang::QualType(); } 38 39 static inline clang::QualType getTombstoneKey() { 40 using clang::QualType; 41 return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); 42 } 43 44 static unsigned getHashValue(clang::QualType Val) { 45 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ 46 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); 47 } 48 49 static bool isEqual(clang::QualType LHS, clang::QualType RHS) { 50 return LHS == RHS; 51 } 52 53 static bool isPod() { 54 // QualType isn't *technically* a POD type. However, we can get 55 // away with calling it a POD type since its copy constructor, 56 // copy assignment operator, and destructor are all trivial. 57 return true; 58 } 59 }; 60} 61 62#endif 63