clang  3.9.0
UnresolvedSet.h
Go to the documentation of this file.
1 //===-- UnresolvedSet.h - Unresolved sets of declarations ------*- C++ -*-===//
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 // This file defines the UnresolvedSet class, which is used to store
11 // collections of declarations in the AST.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_UNRESOLVEDSET_H
16 #define LLVM_CLANG_AST_UNRESOLVEDSET_H
17 
19 #include "clang/Basic/LLVM.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/iterator.h"
23 
24 namespace clang {
25 
26 /// The iterator over UnresolvedSets. Serves as both the const and
27 /// non-const iterator.
28 class UnresolvedSetIterator : public llvm::iterator_adaptor_base<
29  UnresolvedSetIterator, DeclAccessPair *,
30  std::random_access_iterator_tag, NamedDecl *,
31  std::ptrdiff_t, NamedDecl *, NamedDecl *> {
32  friend class UnresolvedSetImpl;
33  friend class ASTUnresolvedSet;
34  friend class OverloadExpr;
35 
37  : iterator_adaptor_base(Iter) {}
38  explicit UnresolvedSetIterator(const DeclAccessPair *Iter)
39  : iterator_adaptor_base(const_cast<DeclAccessPair *>(Iter)) {}
40 
41 public:
43 
44  NamedDecl *getDecl() const { return I->getDecl(); }
45  void setDecl(NamedDecl *ND) const { return I->setDecl(ND); }
46  AccessSpecifier getAccess() const { return I->getAccess(); }
47  void setAccess(AccessSpecifier AS) { I->setAccess(AS); }
48  const DeclAccessPair &getPair() const { return *I; }
49 
50  NamedDecl *operator*() const { return getDecl(); }
51  NamedDecl *operator->() const { return **this; }
52 };
53 
54 /// \brief A set of unresolved declarations.
57 
58  // Don't allow direct construction, and only permit subclassing by
59  // UnresolvedSet.
60 private:
61  template <unsigned N> friend class UnresolvedSet;
62  UnresolvedSetImpl() = default;
63  UnresolvedSetImpl(const UnresolvedSetImpl &) = default;
64  UnresolvedSetImpl &operator=(const UnresolvedSetImpl &) = default;
65 
66  // FIXME: Switch these to "= default" once MSVC supports generating move ops
68  UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) { return *this; }
69 
70 public:
71  // We don't currently support assignment through this iterator, so we might
72  // as well use the same implementation twice.
75 
76  iterator begin() { return iterator(decls().begin()); }
77  iterator end() { return iterator(decls().end()); }
78 
79  const_iterator begin() const { return const_iterator(decls().begin()); }
80  const_iterator end() const { return const_iterator(decls().end()); }
81 
82  void addDecl(NamedDecl *D) {
83  addDecl(D, AS_none);
84  }
85 
87  decls().push_back(DeclAccessPair::make(D, AS));
88  }
89 
90  /// Replaces the given declaration with the new one, once.
91  ///
92  /// \return true if the set changed
93  bool replace(const NamedDecl* Old, NamedDecl *New) {
94  for (DeclsTy::iterator I = decls().begin(), E = decls().end(); I != E; ++I)
95  if (I->getDecl() == Old)
96  return (I->setDecl(New), true);
97  return false;
98  }
99 
100  /// Replaces the declaration at the given iterator with the new one,
101  /// preserving the original access bits.
102  void replace(iterator I, NamedDecl *New) { I.I->setDecl(New); }
103 
105  I.I->set(New, AS);
106  }
107 
108  void erase(unsigned I) { decls()[I] = decls().pop_back_val(); }
109 
110  void erase(iterator I) { *I.I = decls().pop_back_val(); }
111 
112  void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); }
113 
114  void clear() { decls().clear(); }
115  void set_size(unsigned N) { decls().set_size(N); }
116 
117  bool empty() const { return decls().empty(); }
118  unsigned size() const { return decls().size(); }
119 
120  void append(iterator I, iterator E) { decls().append(I.I, E.I); }
121 
122  DeclAccessPair &operator[](unsigned I) { return decls()[I]; }
123  const DeclAccessPair &operator[](unsigned I) const { return decls()[I]; }
124 
125 private:
126  // These work because the only permitted subclass is UnresolvedSetImpl
127 
128  DeclsTy &decls() {
129  return *reinterpret_cast<DeclsTy*>(this);
130  }
131  const DeclsTy &decls() const {
132  return *reinterpret_cast<const DeclsTy*>(this);
133  }
134 };
135 
136 /// \brief A set of unresolved declarations.
137 template <unsigned InlineCapacity> class UnresolvedSet :
138  public UnresolvedSetImpl {
140 };
141 
142 
143 } // namespace clang
144 
145 #endif
void replace(iterator I, NamedDecl *New)
Replaces the declaration at the given iterator with the new one, preserving the original access bits...
void setDecl(NamedDecl *ND) const
Definition: UnresolvedSet.h:45
void setAccess(iterator I, AccessSpecifier AS)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:93
void setAccess(AccessSpecifier AS)
Definition: UnresolvedSet.h:47
UnresolvedSetIterator const_iterator
Definition: UnresolvedSet.h:74
unsigned size() const
const_iterator begin() const
Definition: UnresolvedSet.h:79
const DeclAccessPair & operator[](unsigned I) const
void addDecl(NamedDecl *D, AccessSpecifier AS)
Definition: UnresolvedSet.h:86
NamedDecl * operator->() const
Definition: UnresolvedSet.h:51
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:28
void replace(iterator I, NamedDecl *New, AccessSpecifier AS)
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
void set_size(unsigned N)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
A set of unresolved declarations.
Definition: UnresolvedSet.h:55
void append(iterator I, iterator E)
detail::InMemoryDirectory::const_iterator I
NamedDecl * getDecl() const
Definition: UnresolvedSet.h:44
void erase(unsigned I)
bool replace(const NamedDecl *Old, NamedDecl *New)
Replaces the given declaration with the new one, once.
Definition: UnresolvedSet.h:93
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
Definition: ExprCXX.h:2483
const TemplateArgument * iterator
Definition: Type.h:4233
const_iterator end() const
Definition: UnresolvedSet.h:80
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:82
const DeclAccessPair & getPair() const
Definition: UnresolvedSet.h:48
A POD class for pairing a NamedDecl* with an access specifier.
AccessSpecifier getAccess() const
Definition: UnresolvedSet.h:46
A set of unresolved declarations.
detail::InMemoryDirectory::const_iterator E
An UnresolvedSet-like class which uses the ASTContext's allocator.
NamedDecl * operator*() const
Definition: UnresolvedSet.h:50
void erase(iterator I)
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
DeclAccessPair & operator[](unsigned I)
UnresolvedSetIterator iterator
Definition: UnresolvedSet.h:73