File indexing completed on 2026-05-10 08:36:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
0015 #define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
0016
0017 #include "clang/AST/ASTVector.h"
0018 #include "clang/AST/DeclAccessPair.h"
0019 #include "clang/AST/DeclID.h"
0020 #include "clang/AST/UnresolvedSet.h"
0021 #include "clang/Basic/Specifiers.h"
0022 #include <cassert>
0023 #include <cstdint>
0024
0025 namespace clang {
0026
0027 class NamedDecl;
0028
0029
0030 class ASTUnresolvedSet {
0031 friend class LazyASTUnresolvedSet;
0032
0033 struct DeclsTy : ASTVector<DeclAccessPair> {
0034 DeclsTy() = default;
0035 DeclsTy(ASTContext &C, unsigned N) : ASTVector<DeclAccessPair>(C, N) {}
0036
0037 bool isLazy() const { return getTag(); }
0038 void setLazy(bool Lazy) { setTag(Lazy); }
0039 };
0040
0041 DeclsTy Decls;
0042
0043 public:
0044 ASTUnresolvedSet() = default;
0045 ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
0046
0047 using iterator = UnresolvedSetIterator;
0048 using const_iterator = UnresolvedSetIterator;
0049
0050 iterator begin() { return iterator(Decls.begin()); }
0051 iterator end() { return iterator(Decls.end()); }
0052
0053 const_iterator begin() const { return const_iterator(Decls.begin()); }
0054 const_iterator end() const { return const_iterator(Decls.end()); }
0055
0056 void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) {
0057 Decls.push_back(DeclAccessPair::make(D, AS), C);
0058 }
0059
0060 void addLazyDecl(ASTContext &C, GlobalDeclID ID, AccessSpecifier AS) {
0061 Decls.push_back(DeclAccessPair::makeLazy(ID.getRawValue(), AS), C);
0062 }
0063
0064
0065
0066
0067 bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS) {
0068 for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) {
0069 if (I->getDecl() == Old) {
0070 I->set(New, AS);
0071 return true;
0072 }
0073 }
0074 return false;
0075 }
0076
0077 void erase(unsigned I) {
0078 if (I == Decls.size() - 1)
0079 Decls.pop_back();
0080 else
0081 Decls[I] = Decls.pop_back_val();
0082 }
0083
0084 void clear() { Decls.clear(); }
0085
0086 bool empty() const { return Decls.empty(); }
0087 unsigned size() const { return Decls.size(); }
0088
0089 void reserve(ASTContext &C, unsigned N) {
0090 Decls.reserve(C, N);
0091 }
0092
0093 void append(ASTContext &C, iterator I, iterator E) {
0094 Decls.append(C, I.I, E.I);
0095 }
0096
0097 DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
0098 const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }
0099 };
0100
0101
0102
0103 class LazyASTUnresolvedSet {
0104 mutable ASTUnresolvedSet Impl;
0105
0106 void getFromExternalSource(ASTContext &C) const;
0107
0108 public:
0109 ASTUnresolvedSet &get(ASTContext &C) const {
0110 if (Impl.Decls.isLazy())
0111 getFromExternalSource(C);
0112 return Impl;
0113 }
0114
0115 void reserve(ASTContext &C, unsigned N) { Impl.reserve(C, N); }
0116
0117 void addLazyDecl(ASTContext &C, GlobalDeclID ID, AccessSpecifier AS) {
0118 assert(Impl.empty() || Impl.Decls.isLazy());
0119 Impl.Decls.setLazy(true);
0120 Impl.addLazyDecl(C, ID, AS);
0121 }
0122 };
0123
0124 }
0125
0126 #endif