1 //===--- GlobalSelector.h - Cross-translation-unit "token" for selectors --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // GlobalSelector is a ASTContext-independent way to refer to selectors.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_INDEX_GLOBALSELECTOR_H
15 #define LLVM_CLANG_INDEX_GLOBALSELECTOR_H
17 #include "llvm/ADT/DenseMap.h"
27 /// \brief A ASTContext-independent way to refer to selectors.
28 class GlobalSelector {
31 explicit GlobalSelector(void *val) : Val(val) { }
34 GlobalSelector() : Val(0) { }
36 /// \brief Get the ASTContext-specific selector.
37 Selector getSelector(ASTContext &AST) const;
39 bool isValid() const { return Val != 0; }
40 bool isInvalid() const { return !isValid(); }
42 /// \brief Get a printable name for debugging purpose.
43 std::string getPrintableName() const;
45 /// \brief Get a GlobalSelector for the ASTContext-specific selector.
46 static GlobalSelector get(Selector Sel, Program &Prog);
48 void *getAsOpaquePtr() const { return Val; }
50 static GlobalSelector getFromOpaquePtr(void *Ptr) {
51 return GlobalSelector(Ptr);
54 friend bool operator==(const GlobalSelector &LHS, const GlobalSelector &RHS) {
55 return LHS.getAsOpaquePtr() == RHS.getAsOpaquePtr();
58 // For use in a std::map.
59 friend bool operator< (const GlobalSelector &LHS, const GlobalSelector &RHS) {
60 return LHS.getAsOpaquePtr() < RHS.getAsOpaquePtr();
63 // For use in DenseMap/DenseSet.
64 static GlobalSelector getEmptyMarker() { return GlobalSelector((void*)-1); }
65 static GlobalSelector getTombstoneMarker() {
66 return GlobalSelector((void*)-2);
75 /// Define DenseMapInfo so that GlobalSelectors can be used as keys in DenseMap
78 struct DenseMapInfo<clang::idx::GlobalSelector> {
79 static inline clang::idx::GlobalSelector getEmptyKey() {
80 return clang::idx::GlobalSelector::getEmptyMarker();
83 static inline clang::idx::GlobalSelector getTombstoneKey() {
84 return clang::idx::GlobalSelector::getTombstoneMarker();
87 static unsigned getHashValue(clang::idx::GlobalSelector);
90 isEqual(clang::idx::GlobalSelector LHS, clang::idx::GlobalSelector RHS) {
96 struct isPodLike<clang::idx::GlobalSelector> { static const bool value = true;};
98 } // end namespace llvm