Home | History | Annotate | Download | only in Index
      1 //===--- GlobalSelector.h - Cross-translation-unit "token" for selectors --===//
      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 //  GlobalSelector is a ASTContext-independent way to refer to selectors.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_INDEX_GLOBALSELECTOR_H
     15 #define LLVM_CLANG_INDEX_GLOBALSELECTOR_H
     16 
     17 #include "llvm/ADT/DenseMap.h"
     18 #include <string>
     19 
     20 namespace clang {
     21   class ASTContext;
     22   class Selector;
     23 
     24 namespace idx {
     25   class Program;
     26 
     27 /// \brief A ASTContext-independent way to refer to selectors.
     28 class GlobalSelector {
     29   void *Val;
     30 
     31   explicit GlobalSelector(void *val) : Val(val) { }
     32 
     33 public:
     34   GlobalSelector() : Val(0) { }
     35 
     36   /// \brief Get the ASTContext-specific selector.
     37   Selector getSelector(ASTContext &AST) const;
     38 
     39   bool isValid() const { return Val != 0; }
     40   bool isInvalid() const { return !isValid(); }
     41 
     42   /// \brief Get a printable name for debugging purpose.
     43   std::string getPrintableName() const;
     44 
     45   /// \brief Get a GlobalSelector for the ASTContext-specific selector.
     46   static GlobalSelector get(Selector Sel, Program &Prog);
     47 
     48   void *getAsOpaquePtr() const { return Val; }
     49 
     50   static GlobalSelector getFromOpaquePtr(void *Ptr) {
     51     return GlobalSelector(Ptr);
     52   }
     53 
     54   friend bool operator==(const GlobalSelector &LHS, const GlobalSelector &RHS) {
     55     return LHS.getAsOpaquePtr() == RHS.getAsOpaquePtr();
     56   }
     57 
     58   // For use in a std::map.
     59   friend bool operator< (const GlobalSelector &LHS, const GlobalSelector &RHS) {
     60     return LHS.getAsOpaquePtr() < RHS.getAsOpaquePtr();
     61   }
     62 
     63   // For use in DenseMap/DenseSet.
     64   static GlobalSelector getEmptyMarker() { return GlobalSelector((void*)-1); }
     65   static GlobalSelector getTombstoneMarker() {
     66     return GlobalSelector((void*)-2);
     67   }
     68 };
     69 
     70 } // namespace idx
     71 
     72 } // namespace clang
     73 
     74 namespace llvm {
     75 /// Define DenseMapInfo so that GlobalSelectors can be used as keys in DenseMap
     76 /// and DenseSets.
     77 template<>
     78 struct DenseMapInfo<clang::idx::GlobalSelector> {
     79   static inline clang::idx::GlobalSelector getEmptyKey() {
     80     return clang::idx::GlobalSelector::getEmptyMarker();
     81   }
     82 
     83   static inline clang::idx::GlobalSelector getTombstoneKey() {
     84     return clang::idx::GlobalSelector::getTombstoneMarker();
     85   }
     86 
     87   static unsigned getHashValue(clang::idx::GlobalSelector);
     88 
     89   static inline bool
     90   isEqual(clang::idx::GlobalSelector LHS, clang::idx::GlobalSelector RHS) {
     91     return LHS == RHS;
     92   }
     93 };
     94 
     95 template <>
     96 struct isPodLike<clang::idx::GlobalSelector> { static const bool value = true;};
     97 
     98 }  // end namespace llvm
     99 
    100 #endif
    101