clang API Documentation
00001 //===-------------- TypeOrdering.h - Total ordering for types -------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file provides a function objects and specializations that 00011 // allow QualType values to be sorted, used in std::maps, std::sets, 00012 // llvm::DenseMaps, and llvm::DenseSets. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_CLANG_TYPE_ORDERING_H 00017 #define LLVM_CLANG_TYPE_ORDERING_H 00018 00019 #include "clang/AST/Type.h" 00020 #include "clang/AST/CanonicalType.h" 00021 #include <functional> 00022 00023 namespace clang { 00024 00025 /// QualTypeOrdering - Function object that provides a total ordering 00026 /// on QualType values. 00027 struct QualTypeOrdering : std::binary_function<QualType, QualType, bool> { 00028 bool operator()(QualType T1, QualType T2) const { 00029 return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr()); 00030 } 00031 }; 00032 00033 } 00034 00035 namespace llvm { 00036 template<class> struct DenseMapInfo; 00037 00038 template<> struct DenseMapInfo<clang::QualType> { 00039 static inline clang::QualType getEmptyKey() { return clang::QualType(); } 00040 00041 static inline clang::QualType getTombstoneKey() { 00042 using clang::QualType; 00043 return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); 00044 } 00045 00046 static unsigned getHashValue(clang::QualType Val) { 00047 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ 00048 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); 00049 } 00050 00051 static bool isEqual(clang::QualType LHS, clang::QualType RHS) { 00052 return LHS == RHS; 00053 } 00054 }; 00055 00056 template<> struct DenseMapInfo<clang::CanQualType> { 00057 static inline clang::CanQualType getEmptyKey() { 00058 return clang::CanQualType(); 00059 } 00060 00061 static inline clang::CanQualType getTombstoneKey() { 00062 using clang::CanQualType; 00063 return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1)); 00064 } 00065 00066 static unsigned getHashValue(clang::CanQualType Val) { 00067 return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^ 00068 ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9)); 00069 } 00070 00071 static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) { 00072 return LHS == RHS; 00073 } 00074 }; 00075 } 00076 00077 #endif