clang API Documentation
00001 //===--- GlobalSelector.h - Cross-translation-unit "token" for selectors --===// 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 // GlobalSelector is a ASTContext-independent way to refer to selectors. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_INDEX_GLOBALSELECTOR_H 00015 #define LLVM_CLANG_INDEX_GLOBALSELECTOR_H 00016 00017 #include "llvm/ADT/DenseMap.h" 00018 #include <string> 00019 00020 namespace clang { 00021 class ASTContext; 00022 class Selector; 00023 00024 namespace idx { 00025 class Program; 00026 00027 /// \brief A ASTContext-independent way to refer to selectors. 00028 class GlobalSelector { 00029 void *Val; 00030 00031 explicit GlobalSelector(void *val) : Val(val) { } 00032 00033 public: 00034 GlobalSelector() : Val(0) { } 00035 00036 /// \brief Get the ASTContext-specific selector. 00037 Selector getSelector(ASTContext &AST) const; 00038 00039 bool isValid() const { return Val != 0; } 00040 bool isInvalid() const { return !isValid(); } 00041 00042 /// \brief Get a printable name for debugging purpose. 00043 std::string getPrintableName() const; 00044 00045 /// \brief Get a GlobalSelector for the ASTContext-specific selector. 00046 static GlobalSelector get(Selector Sel, Program &Prog); 00047 00048 void *getAsOpaquePtr() const { return Val; } 00049 00050 static GlobalSelector getFromOpaquePtr(void *Ptr) { 00051 return GlobalSelector(Ptr); 00052 } 00053 00054 friend bool operator==(const GlobalSelector &LHS, const GlobalSelector &RHS) { 00055 return LHS.getAsOpaquePtr() == RHS.getAsOpaquePtr(); 00056 } 00057 00058 // For use in a std::map. 00059 friend bool operator< (const GlobalSelector &LHS, const GlobalSelector &RHS) { 00060 return LHS.getAsOpaquePtr() < RHS.getAsOpaquePtr(); 00061 } 00062 00063 // For use in DenseMap/DenseSet. 00064 static GlobalSelector getEmptyMarker() { return GlobalSelector((void*)-1); } 00065 static GlobalSelector getTombstoneMarker() { 00066 return GlobalSelector((void*)-2); 00067 } 00068 }; 00069 00070 } // namespace idx 00071 00072 } // namespace clang 00073 00074 namespace llvm { 00075 /// Define DenseMapInfo so that GlobalSelectors can be used as keys in DenseMap 00076 /// and DenseSets. 00077 template<> 00078 struct DenseMapInfo<clang::idx::GlobalSelector> { 00079 static inline clang::idx::GlobalSelector getEmptyKey() { 00080 return clang::idx::GlobalSelector::getEmptyMarker(); 00081 } 00082 00083 static inline clang::idx::GlobalSelector getTombstoneKey() { 00084 return clang::idx::GlobalSelector::getTombstoneMarker(); 00085 } 00086 00087 static unsigned getHashValue(clang::idx::GlobalSelector); 00088 00089 static inline bool 00090 isEqual(clang::idx::GlobalSelector LHS, clang::idx::GlobalSelector RHS) { 00091 return LHS == RHS; 00092 } 00093 }; 00094 00095 template <> 00096 struct isPodLike<clang::idx::GlobalSelector> { static const bool value = true;}; 00097 00098 } // end namespace llvm 00099 00100 #endif