1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===-- UnresolvedSet.h - Unresolved sets of declarations ------*- C++ -*-===// 2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// The LLVM Compiler Infrastructure 4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source 6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details. 7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file defines the UnresolvedSet class, which is used to store 11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// collections of declarations in the AST. 12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_CLANG_AST_UNRESOLVEDSET_H 16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_CLANG_AST_UNRESOLVEDSET_H 17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/AST/DeclAccessPair.h" 19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/LLVM.h" 20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/SmallVector.h" 21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/iterator.h" 22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace clang { 24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// The iterator over UnresolvedSets. Serves as both the const and 26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// non-const iterator. 27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass UnresolvedSetIterator : public llvm::iterator_adaptor_base< 28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetIterator, DeclAccessPair *, 29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::random_access_iterator_tag, NamedDecl *, 30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot std::ptrdiff_t, NamedDecl *, NamedDecl *> { 31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class UnresolvedSetImpl; 32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class ASTUnresolvedSet; 33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend class OverloadExpr; 34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot explicit UnresolvedSetIterator(DeclAccessPair *Iter) 36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : iterator_adaptor_base(Iter) {} 37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot explicit UnresolvedSetIterator(const DeclAccessPair *Iter) 38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : iterator_adaptor_base(const_cast<DeclAccessPair *>(Iter)) {} 39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Work around a bug in MSVC 2013 where explicitly default constructed 42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // temporaries with defaulted ctors are not zero initialized. 43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetIterator() : iterator_adaptor_base(nullptr) {} 44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot NamedDecl *getDecl() const { return I->getDecl(); } 46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setDecl(NamedDecl *ND) const { return I->setDecl(ND); } 47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot AccessSpecifier getAccess() const { return I->getAccess(); } 48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setAccess(AccessSpecifier AS) { I->setAccess(AS); } 49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const DeclAccessPair &getPair() const { return *I; } 50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot NamedDecl *operator*() const { return getDecl(); } 52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot NamedDecl *operator->() const { return **this; } 53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief A set of unresolved declarations. 56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass UnresolvedSetImpl { 57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef SmallVectorImpl<DeclAccessPair> DeclsTy; 58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Don't allow direct construction, and only permit subclassing by 60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // UnresolvedSet. 61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate: 62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot template <unsigned N> friend class UnresolvedSet; 63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetImpl() = default; 64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetImpl(const UnresolvedSetImpl &) = default; 65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetImpl &operator=(const UnresolvedSetImpl &) = default; 66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // FIXME: Switch these to "= default" once MSVC supports generating move ops 68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetImpl(UnresolvedSetImpl &&) {} 69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) { return *this; } 70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // We don't currently support assignment through this iterator, so we might 73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // as well use the same implementation twice. 74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef UnresolvedSetIterator iterator; 75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef UnresolvedSetIterator const_iterator; 76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot iterator begin() { return iterator(decls().begin()); } 78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot iterator end() { return iterator(decls().end()); } 79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const_iterator begin() const { return const_iterator(decls().begin()); } 81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const_iterator end() const { return const_iterator(decls().end()); } 82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void addDecl(NamedDecl *D) { 84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot addDecl(D, AS_none); 85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void addDecl(NamedDecl *D, AccessSpecifier AS) { 88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot decls().push_back(DeclAccessPair::make(D, AS)); 89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Replaces the given declaration with the new one, once. 92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \return true if the set changed 94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool replace(const NamedDecl* Old, NamedDecl *New) { 95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot for (DeclsTy::iterator I = decls().begin(), E = decls().end(); I != E; ++I) 96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot if (I->getDecl() == Old) 97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return (I->setDecl(New), true); 98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return false; 99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Replaces the declaration at the given iterator with the new one, 102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// preserving the original access bits. 103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void replace(iterator I, NamedDecl *New) { I.I->setDecl(New); } 104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void replace(iterator I, NamedDecl *New, AccessSpecifier AS) { 106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot I.I->set(New, AS); 107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void erase(unsigned I) { decls()[I] = decls().pop_back_val(); } 110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void erase(iterator I) { *I.I = decls().pop_back_val(); } 112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); } 114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void clear() { decls().clear(); } 116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void set_size(unsigned N) { decls().set_size(N); } 117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool empty() const { return decls().empty(); } 119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned size() const { return decls().size(); } 120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void append(iterator I, iterator E) { decls().append(I.I, E.I); } 122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DeclAccessPair &operator[](unsigned I) { return decls()[I]; } 124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const DeclAccessPair &operator[](unsigned I) const { return decls()[I]; } 125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate: 127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // These work because the only permitted subclass is UnresolvedSetImpl 128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DeclsTy &decls() { 130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *reinterpret_cast<DeclsTy*>(this); 131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const DeclsTy &decls() const { 133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *reinterpret_cast<const DeclsTy*>(this); 134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief A set of unresolved declarations. 138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottemplate <unsigned InlineCapacity> class UnresolvedSet : 139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot public UnresolvedSetImpl { 140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallVector<DeclAccessPair, InlineCapacity> Decls; 141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // namespace clang 145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif 147