ASTUnresolvedSet.h revision 251662
150826Smdodd//===-- ASTUnresolvedSet.h - Unresolved sets of declarations  ---*- C++ -*-===//
250826Smdodd//
350826Smdodd//                     The LLVM Compiler Infrastructure
450826Smdodd//
550826Smdodd// This file is distributed under the University of Illinois Open Source
650826Smdodd// License. See LICENSE.TXT for details.
750826Smdodd//
850826Smdodd//===----------------------------------------------------------------------===//
950826Smdodd//
1050826Smdodd//  This file provides an UnresolvedSet-like class, whose contents are
1150826Smdodd//  allocated using the allocator associated with an ASTContext.
1250826Smdodd//
1350826Smdodd//===----------------------------------------------------------------------===//
1450826Smdodd
1550826Smdodd#ifndef LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
1650826Smdodd#define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
1750826Smdodd
1850826Smdodd#include "clang/AST/ASTVector.h"
1950826Smdodd#include "clang/AST/UnresolvedSet.h"
2050826Smdodd
2150826Smdoddnamespace clang {
2250826Smdodd
2350826Smdodd/// \brief An UnresolvedSet-like class which uses the ASTContext's allocator.
2450826Smdoddclass ASTUnresolvedSet {
2550826Smdodd  typedef ASTVector<DeclAccessPair> DeclsTy;
2650826Smdodd  DeclsTy Decls;
2750826Smdodd
2850826Smdodd  ASTUnresolvedSet(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
2950826Smdodd  void operator=(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
3050826Smdodd
3150826Smdoddpublic:
3250826Smdodd  ASTUnresolvedSet() {}
3350826Smdodd  ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
3450826Smdodd
3550826Smdodd  typedef UnresolvedSetIterator iterator;
3650826Smdodd  typedef UnresolvedSetIterator const_iterator;
3750826Smdodd
3850826Smdodd  iterator begin() { return iterator(Decls.begin()); }
3950826Smdodd  iterator end() { return iterator(Decls.end()); }
40117126Sscottl
41117126Sscottl  const_iterator begin() const { return const_iterator(Decls.begin()); }
4250826Smdodd  const_iterator end() const { return const_iterator(Decls.end()); }
4350826Smdodd
4450826Smdodd  void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) {
4550826Smdodd    Decls.push_back(DeclAccessPair::make(D, AS), C);
4650826Smdodd  }
4750826Smdodd
4850826Smdodd  /// Replaces the given declaration with the new one, once.
4950826Smdodd  ///
5050826Smdodd  /// \return true if the set changed
5150826Smdodd  bool replace(const NamedDecl* Old, NamedDecl *New, AccessSpecifier AS) {
5250826Smdodd    for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
5350826Smdodd      if (I->getDecl() == Old) {
5450826Smdodd        I->set(New, AS);
5550826Smdodd        return true;
5650826Smdodd      }
5750826Smdodd    }
5850826Smdodd    return false;
5950826Smdodd  }
6050826Smdodd
6150826Smdodd  void erase(unsigned I) {
6250826Smdodd    Decls[I] = Decls.back();
6350826Smdodd    Decls.pop_back();
6450826Smdodd  }
6550826Smdodd
6650826Smdodd  void clear() { Decls.clear(); }
6750826Smdodd
6850826Smdodd  bool empty() const { return Decls.empty(); }
6950826Smdodd  unsigned size() const { return Decls.size(); }
7050826Smdodd
7150826Smdodd  void reserve(ASTContext &C, unsigned N) {
7250826Smdodd    Decls.reserve(C, N);
7350826Smdodd  }
7450826Smdodd
7550826Smdodd  void append(ASTContext &C, iterator I, iterator E) {
7650826Smdodd    Decls.append(C, I.ir, E.ir);
7750826Smdodd  }
7850826Smdodd
7950826Smdodd  DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
8050826Smdodd  const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }
8150826Smdodd};
8250826Smdodd
8350826Smdodd} // namespace clang
8450826Smdodd
8550826Smdodd#endif
8650826Smdodd