| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_AST_UNRESOLVEDSET_H |
| 15 | #define LLVM_CLANG_AST_UNRESOLVEDSET_H |
| 16 | |
| 17 | #include "clang/AST/DeclAccessPair.h" |
| 18 | #include "clang/Basic/LLVM.h" |
| 19 | #include "clang/Basic/Specifiers.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include "llvm/ADT/iterator.h" |
| 22 | #include <cstddef> |
| 23 | #include <iterator> |
| 24 | |
| 25 | namespace clang { |
| 26 | |
| 27 | class NamedDecl; |
| 28 | |
| 29 | |
| 30 | |
| 31 | class UnresolvedSetIterator : public llvm::iterator_adaptor_base< |
| 32 | UnresolvedSetIterator, DeclAccessPair *, |
| 33 | std::random_access_iterator_tag, NamedDecl *, |
| 34 | std::ptrdiff_t, NamedDecl *, NamedDecl *> { |
| 35 | friend class ASTUnresolvedSet; |
| 36 | friend class OverloadExpr; |
| 37 | friend class UnresolvedSetImpl; |
| 38 | |
| 39 | explicit UnresolvedSetIterator(DeclAccessPair *Iter) |
| 40 | : iterator_adaptor_base(Iter) {} |
| 41 | explicit UnresolvedSetIterator(const DeclAccessPair *Iter) |
| 42 | : iterator_adaptor_base(const_cast<DeclAccessPair *>(Iter)) {} |
| 43 | |
| 44 | public: |
| 45 | |
| 46 | |
| 47 | UnresolvedSetIterator() : iterator_adaptor_base(nullptr) {} |
| 48 | |
| 49 | NamedDecl *getDecl() const { return I->getDecl(); } |
| 50 | void setDecl(NamedDecl *ND) const { return I->setDecl(ND); } |
| 51 | AccessSpecifier getAccess() const { return I->getAccess(); } |
| 52 | void setAccess(AccessSpecifier AS) { I->setAccess(AS); } |
| 53 | const DeclAccessPair &getPair() const { return *I; } |
| 54 | |
| 55 | NamedDecl *operator*() const { return getDecl(); } |
| 56 | NamedDecl *operator->() const { return **this; } |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | class UnresolvedSetImpl { |
| 61 | using DeclsTy = SmallVectorImpl<DeclAccessPair>; |
| 62 | |
| 63 | |
| 64 | |
| 65 | private: |
| 66 | template <unsigned N> friend class UnresolvedSet; |
| 67 | |
| 68 | UnresolvedSetImpl() = default; |
| 69 | UnresolvedSetImpl(const UnresolvedSetImpl &) = default; |
| 70 | UnresolvedSetImpl &operator=(const UnresolvedSetImpl &) = default; |
| 71 | |
| 72 | |
| 73 | UnresolvedSetImpl(UnresolvedSetImpl &&) {} |
| 74 | UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) { return *this; } |
| 75 | |
| 76 | public: |
| 77 | |
| 78 | |
| 79 | using iterator = UnresolvedSetIterator; |
| 80 | using const_iterator = UnresolvedSetIterator; |
| 81 | |
| 82 | iterator begin() { return iterator(decls().begin()); } |
| 83 | iterator end() { return iterator(decls().end()); } |
| 84 | |
| 85 | const_iterator begin() const { return const_iterator(decls().begin()); } |
| 86 | const_iterator end() const { return const_iterator(decls().end()); } |
| 87 | |
| 88 | void addDecl(NamedDecl *D) { |
| 89 | addDecl(D, AS_none); |
| 90 | } |
| 91 | |
| 92 | void addDecl(NamedDecl *D, AccessSpecifier AS) { |
| 93 | decls().push_back(DeclAccessPair::make(D, AS)); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | bool replace(const NamedDecl* Old, NamedDecl *New) { |
| 100 | for (DeclsTy::iterator I = decls().begin(), E = decls().end(); I != E; ++I) |
| 101 | if (I->getDecl() == Old) |
| 102 | return (I->setDecl(New), true); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | |
| 108 | void replace(iterator I, NamedDecl *New) { I.I->setDecl(New); } |
| 109 | |
| 110 | void replace(iterator I, NamedDecl *New, AccessSpecifier AS) { |
| 111 | I.I->set(New, AS); |
| 112 | } |
| 113 | |
| 114 | void erase(unsigned I) { decls()[I] = decls().pop_back_val(); } |
| 115 | |
| 116 | void erase(iterator I) { *I.I = decls().pop_back_val(); } |
| 117 | |
| 118 | void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); } |
| 119 | |
| 120 | void clear() { decls().clear(); } |
| 121 | void set_size(unsigned N) { decls().set_size(N); } |
| 122 | |
| 123 | bool empty() const { return decls().empty(); } |
| 124 | unsigned size() const { return decls().size(); } |
| 125 | |
| 126 | void append(iterator I, iterator E) { decls().append(I.I, E.I); } |
| 127 | |
| 128 | DeclAccessPair &operator[](unsigned I) { return decls()[I]; } |
| 129 | const DeclAccessPair &operator[](unsigned I) const { return decls()[I]; } |
| 130 | |
| 131 | private: |
| 132 | |
| 133 | |
| 134 | DeclsTy &decls() { |
| 135 | return *reinterpret_cast<DeclsTy*>(this); |
| 136 | } |
| 137 | const DeclsTy &decls() const { |
| 138 | return *reinterpret_cast<const DeclsTy*>(this); |
| 139 | } |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | template <unsigned InlineCapacity> class UnresolvedSet : |
| 144 | public UnresolvedSetImpl { |
| 145 | SmallVector<DeclAccessPair, InlineCapacity> Decls; |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | } |
| 150 | |
| 151 | #endif |
| 152 | |