summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/include/clang/Index/GlobalSelector.h
blob: 9cd83a8595b97dd7172e71e98c394aaa4ff0779e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//===--- GlobalSelector.h - Cross-translation-unit "token" for selectors --===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  GlobalSelector is a ASTContext-independent way to refer to selectors.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_INDEX_GLOBALSELECTOR_H
#define LLVM_CLANG_INDEX_GLOBALSELECTOR_H

#include "llvm/ADT/DenseMap.h"
#include <string>

namespace clang {
  class ASTContext;
  class Selector;

namespace idx {
  class Program;

/// \brief A ASTContext-independent way to refer to selectors.
class GlobalSelector {
  void *Val;

  explicit GlobalSelector(void *val) : Val(val) { }

public:
  GlobalSelector() : Val(0) { }

  /// \brief Get the ASTContext-specific selector.
  Selector getSelector(ASTContext &AST) const;

  bool isValid() const { return Val != 0; }
  bool isInvalid() const { return !isValid(); }

  /// \brief Get a printable name for debugging purpose.
  std::string getPrintableName() const;

  /// \brief Get a GlobalSelector for the ASTContext-specific selector.
  static GlobalSelector get(Selector Sel, Program &Prog);

  void *getAsOpaquePtr() const { return Val; }

  static GlobalSelector getFromOpaquePtr(void *Ptr) {
    return GlobalSelector(Ptr);
  }

  friend bool operator==(const GlobalSelector &LHS, const GlobalSelector &RHS) {
    return LHS.getAsOpaquePtr() == RHS.getAsOpaquePtr();
  }

  // For use in a std::map.
  friend bool operator< (const GlobalSelector &LHS, const GlobalSelector &RHS) {
    return LHS.getAsOpaquePtr() < RHS.getAsOpaquePtr();
  }

  // For use in DenseMap/DenseSet.
  static GlobalSelector getEmptyMarker() { return GlobalSelector((void*)-1); }
  static GlobalSelector getTombstoneMarker() {
    return GlobalSelector((void*)-2);
  }
};

} // namespace idx

} // namespace clang

namespace llvm {
/// Define DenseMapInfo so that GlobalSelectors can be used as keys in DenseMap
/// and DenseSets.
template<>
struct DenseMapInfo<clang::idx::GlobalSelector> {
  static inline clang::idx::GlobalSelector getEmptyKey() {
    return clang::idx::GlobalSelector::getEmptyMarker();
  }

  static inline clang::idx::GlobalSelector getTombstoneKey() {
    return clang::idx::GlobalSelector::getTombstoneMarker();
  }

  static unsigned getHashValue(clang::idx::GlobalSelector);

  static inline bool
  isEqual(clang::idx::GlobalSelector LHS, clang::idx::GlobalSelector RHS) {
    return LHS == RHS;
  }
};
  
template <>
struct isPodLike<clang::idx::GlobalSelector> { static const bool value = true;};

}  // end namespace llvm

#endif
OpenPOWER on IntegriCloud