File indexing completed on 2026-05-10 08:36:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_AST_UNRESOLVEDSET_H
0015 #define LLVM_CLANG_AST_UNRESOLVEDSET_H
0016
0017 #include "clang/AST/DeclAccessPair.h"
0018 #include "clang/Basic/LLVM.h"
0019 #include "clang/Basic/Specifiers.h"
0020 #include "llvm/ADT/ArrayRef.h"
0021 #include "llvm/ADT/SmallVector.h"
0022 #include "llvm/ADT/iterator.h"
0023 #include <cstddef>
0024 #include <iterator>
0025
0026 namespace clang {
0027
0028 class NamedDecl;
0029
0030
0031
0032 class UnresolvedSetIterator : public llvm::iterator_adaptor_base<
0033 UnresolvedSetIterator, DeclAccessPair *,
0034 std::random_access_iterator_tag, NamedDecl *,
0035 std::ptrdiff_t, NamedDecl *, NamedDecl *> {
0036 friend class ASTUnresolvedSet;
0037 friend class OverloadExpr;
0038 friend class UnresolvedSetImpl;
0039
0040 explicit UnresolvedSetIterator(DeclAccessPair *Iter)
0041 : iterator_adaptor_base(Iter) {}
0042 explicit UnresolvedSetIterator(const DeclAccessPair *Iter)
0043 : iterator_adaptor_base(const_cast<DeclAccessPair *>(Iter)) {}
0044
0045 public:
0046
0047
0048 UnresolvedSetIterator() : iterator_adaptor_base(nullptr) {}
0049
0050 uint64_t getDeclID() const { return I->getDeclID(); }
0051 NamedDecl *getDecl() const { return I->getDecl(); }
0052 void setDecl(NamedDecl *ND) const { return I->setDecl(ND); }
0053 AccessSpecifier getAccess() const { return I->getAccess(); }
0054 void setAccess(AccessSpecifier AS) { I->setAccess(AS); }
0055 const DeclAccessPair &getPair() const { return *I; }
0056
0057 NamedDecl *operator*() const { return getDecl(); }
0058 NamedDecl *operator->() const { return **this; }
0059 };
0060
0061
0062 class UnresolvedSetImpl {
0063 using DeclsTy = SmallVectorImpl<DeclAccessPair>;
0064
0065
0066
0067 private:
0068 template <unsigned N> friend class UnresolvedSet;
0069
0070 UnresolvedSetImpl() = default;
0071 UnresolvedSetImpl(const UnresolvedSetImpl &) = default;
0072 UnresolvedSetImpl &operator=(const UnresolvedSetImpl &) = default;
0073
0074 UnresolvedSetImpl(UnresolvedSetImpl &&) = default;
0075 UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) = default;
0076
0077 public:
0078
0079
0080 using iterator = UnresolvedSetIterator;
0081 using const_iterator = UnresolvedSetIterator;
0082
0083 iterator begin() { return iterator(decls().begin()); }
0084 iterator end() { return iterator(decls().end()); }
0085
0086 const_iterator begin() const { return const_iterator(decls().begin()); }
0087 const_iterator end() const { return const_iterator(decls().end()); }
0088
0089 ArrayRef<DeclAccessPair> pairs() const { return decls(); }
0090
0091 void addDecl(NamedDecl *D) {
0092 addDecl(D, AS_none);
0093 }
0094
0095 void addDecl(NamedDecl *D, AccessSpecifier AS) {
0096 decls().push_back(DeclAccessPair::make(D, AS));
0097 }
0098
0099
0100
0101
0102 bool replace(const NamedDecl* Old, NamedDecl *New) {
0103 for (DeclsTy::iterator I = decls().begin(), E = decls().end(); I != E; ++I)
0104 if (I->getDecl() == Old)
0105 return (I->setDecl(New), true);
0106 return false;
0107 }
0108
0109
0110
0111 void replace(iterator I, NamedDecl *New) { I.I->setDecl(New); }
0112
0113 void replace(iterator I, NamedDecl *New, AccessSpecifier AS) {
0114 I.I->set(New, AS);
0115 }
0116
0117 void erase(unsigned I) {
0118 auto val = decls().pop_back_val();
0119 if (I < size())
0120 decls()[I] = val;
0121 }
0122
0123 void erase(iterator I) {
0124 auto val = decls().pop_back_val();
0125 if (I != end())
0126 *I.I = val;
0127 }
0128
0129 void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); }
0130
0131 void clear() { decls().clear(); }
0132 void truncate(unsigned N) { decls().truncate(N); }
0133
0134 bool empty() const { return decls().empty(); }
0135 unsigned size() const { return decls().size(); }
0136
0137 void append(iterator I, iterator E) { decls().append(I.I, E.I); }
0138
0139 template<typename Iter> void assign(Iter I, Iter E) { decls().assign(I, E); }
0140
0141 DeclAccessPair &operator[](unsigned I) { return decls()[I]; }
0142 const DeclAccessPair &operator[](unsigned I) const { return decls()[I]; }
0143
0144 private:
0145
0146
0147 DeclsTy &decls() {
0148 return *reinterpret_cast<DeclsTy*>(this);
0149 }
0150 const DeclsTy &decls() const {
0151 return *reinterpret_cast<const DeclsTy*>(this);
0152 }
0153 };
0154
0155
0156 template <unsigned InlineCapacity> class UnresolvedSet :
0157 public UnresolvedSetImpl {
0158 SmallVector<DeclAccessPair, InlineCapacity> Decls;
0159 };
0160
0161
0162 }
0163
0164 #endif