ASTUnresolvedSet.h revision 2a82ca255b0f99f6201a75ed52b91fc024f6e9cf
1//===-- ASTUnresolvedSet.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 provides an UnresolvedSet-like class, whose contents are
11//  allocated using the allocator associated with an ASTContext.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
16#define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
17
18#include "clang/AST/UnresolvedSet.h"
19#include "clang/AST/ASTVector.h"
20
21namespace clang {
22
23/// \brief An UnresolvedSet-like class which uses the ASTContext's allocator.
24class ASTUnresolvedSet {
25  typedef ASTVector<DeclAccessPair> DeclsTy;
26  DeclsTy Decls;
27
28  ASTUnresolvedSet(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
29  void operator=(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
30
31public:
32  ASTUnresolvedSet() {}
33  ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
34
35  typedef UnresolvedSetIterator iterator;
36  typedef UnresolvedSetIterator const_iterator;
37
38  iterator begin() { return iterator(Decls.begin()); }
39  iterator end() { return iterator(Decls.end()); }
40
41  const_iterator begin() const { return const_iterator(Decls.begin()); }
42  const_iterator end() const { return const_iterator(Decls.end()); }
43
44  void addDecl(ASTContext &C, NamedDecl *D) {
45    addDecl(C, D, AS_none);
46  }
47
48  void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) {
49    Decls.push_back(DeclAccessPair::make(D, AS), C);
50  }
51
52  /// Replaces the given declaration with the new one, once.
53  ///
54  /// \return true if the set changed
55  bool replace(const NamedDecl* Old, NamedDecl *New) {
56    for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I)
57      if (I->getDecl() == Old)
58        return (I->setDecl(New), true);
59    return false;
60  }
61
62  void erase(unsigned I) {
63    Decls[I] = Decls.back();
64    Decls.pop_back();
65  }
66
67  void clear() { Decls.clear(); }
68
69  bool empty() const { return Decls.empty(); }
70  unsigned size() const { return Decls.size(); }
71
72  void reserve(ASTContext &C, unsigned N) {
73    Decls.reserve(C, N);
74  }
75
76  void append(ASTContext &C, iterator I, iterator E) {
77    Decls.append(C, I.ir, E.ir);
78  }
79
80  DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
81  const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }
82};
83
84} // namespace clang
85
86#endif
87