TypeOrdering.h revision f5586f6b311c98e1022a8fe0609053849b70d323
10218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor//===-------------- TypeOrdering.h - Total ordering for types -------------===// 20218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// 30218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// The LLVM Compiler Infrastructure 40218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// 50218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// This file is distributed under the University of Illinois Open Source 60218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// License. See LICENSE.TXT for details. 70218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// 80218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor//===----------------------------------------------------------------------===// 90218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// 10eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor// This file provides a function objects and specializations that 11eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor// allow QualType values to be sorted, used in std::maps, std::sets, 12eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor// llvm::DenseMaps, and llvm::DenseSets. 130218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor// 140218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor//===----------------------------------------------------------------------===// 150218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor 160218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor#ifndef LLVM_CLANG_TYPE_ORDERING_H 170218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor#define LLVM_CLANG_TYPE_ORDERING_H 180218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor 190218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor#include "clang/AST/Type.h" 20f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor#include "clang/AST/CanonicalType.h" 210218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor#include <functional> 220218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor 230218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregornamespace clang { 240218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor 250218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor/// QualTypeOrdering - Function object that provides a total ordering 260218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor/// on QualType values. 270218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregorstruct QualTypeOrdering : std::binary_function<QualType, QualType, bool> { 282b9d973eb749aee6becbcf5e51ab5d49b828c978Douglas Gregor bool operator()(QualType T1, QualType T2) const { 290218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr()); 300218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor } 310218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor}; 320218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor 330218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor} 340218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor 35eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregornamespace llvm { 36bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor template<class> struct DenseMapInfo; 37bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor 38eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor template<> struct DenseMapInfo<clang::QualType> { 39eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor static inline clang::QualType getEmptyKey() { return clang::QualType(); } 40eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static inline clang::QualType getTombstoneKey() { 42eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor using clang::QualType; 43eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); 44eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor } 45eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 46eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor static unsigned getHashValue(clang::QualType Val) { 47b7c3ca8af0a1a3b66fb220562c72dd3102153d5bDouglas Gregor return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ 48b7c3ca8af0a1a3b66fb220562c72dd3102153d5bDouglas Gregor ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); 49eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor } 50eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 51eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor static bool isEqual(clang::QualType LHS, clang::QualType RHS) { 52eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor return LHS == RHS; 53eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor } 54eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor }; 55f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 56f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor template<> struct DenseMapInfo<clang::CanQualType> { 57f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static inline clang::CanQualType getEmptyKey() { 58f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor return clang::CanQualType(); 59f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor } 60f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 61f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static inline clang::CanQualType getTombstoneKey() { 62f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor using clang::CanQualType; 63f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); 64f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor } 65f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 66f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static unsigned getHashValue(clang::CanQualType Val) { 67f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ 68f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); 69f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor } 70f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor 71f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) { 72f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor return LHS == RHS; 73f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor } 74f5586f6b311c98e1022a8fe0609053849b70d323Douglas Gregor }; 75eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor} 76eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 770218936235b137bbdcd29a6c36d61d9215bb4eddDouglas Gregor#endif 78