1 //===-- ASTUnresolvedSet.h - Unresolved sets of declarations ---*- C++ -*-===//
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 // This file provides an UnresolvedSet-like class, whose contents are
11 // allocated using the allocator associated with an ASTContext.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
16 #define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
18 #include "clang/AST/ASTVector.h"
19 #include "clang/AST/UnresolvedSet.h"
23 /// \brief An UnresolvedSet-like class which uses the ASTContext's allocator.
24 class ASTUnresolvedSet {
25 typedef ASTVector<DeclAccessPair> DeclsTy;
28 ASTUnresolvedSet(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
29 void operator=(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
33 ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
35 typedef UnresolvedSetIterator iterator;
36 typedef UnresolvedSetIterator const_iterator;
38 iterator begin() { return iterator(Decls.begin()); }
39 iterator end() { return iterator(Decls.end()); }
41 const_iterator begin() const { return const_iterator(Decls.begin()); }
42 const_iterator end() const { return const_iterator(Decls.end()); }
44 void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) {
45 Decls.push_back(DeclAccessPair::make(D, AS), C);
48 /// Replaces the given declaration with the new one, once.
50 /// \return true if the set changed
51 bool replace(const NamedDecl* Old, NamedDecl *New, AccessSpecifier AS) {
52 for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
53 if (I->getDecl() == Old) {
61 void erase(unsigned I) {
62 Decls[I] = Decls.back();
66 void clear() { Decls.clear(); }
68 bool empty() const { return Decls.empty(); }
69 unsigned size() const { return Decls.size(); }
71 void reserve(ASTContext &C, unsigned N) {
75 void append(ASTContext &C, iterator I, iterator E) {
76 Decls.append(C, I.ir, E.ir);
79 DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
80 const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }