clang: include/clang/AST/DeclContextInternals.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_AST_DECLCONTEXTINTERNALS_H
15#define LLVM_CLANG_AST_DECLCONTEXTINTERNALS_H
16
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/PointerIntPair.h"
24#include "llvm/ADT/PointerUnion.h"
25#include
26
28
30
31
32
35
36
37
38 using DeclsAndHasExternalTy = llvm::PointerIntPair<Decls, 1, bool>;
39
40
41
42
43 DeclsAndHasExternalTy Data;
44
46 Decls List = Data.getPointer();
47
48 if (!List)
49 return nullptr;
50
55 while (true) {
57 NewLast = NewTail;
58 *NewTail = List;
59 if (auto *Node = List.dyn_cast<DeclListNode*>()) {
60 NewTail = &Node->Rest;
61 List = Node->Rest;
62 } else {
63 break;
64 }
66 List = N->Rest;
67 C.DeallocateDeclListNode(N);
68 } else {
69
70
71
72 if (NewLast) {
74 *NewLast = Node->D;
75 C.DeallocateDeclListNode(Node);
76 }
77 break;
78 }
79 }
80 Data.setPointer(NewHead);
81
82 assert(llvm::none_of(getLookupResult(), ShouldErase) && "Still exists!");
83
84 if (!Data.getPointer())
85
86 return nullptr;
88
90 else {
91 assert(NewLast && isa<NamedDecl *>(*NewLast) && "Not the tail?");
92 return NewLast;
93 }
94 }
95
97 erase_if([ND](NamedDecl *D) { return D == ND; });
98 }
99
100public:
102
104 RHS.Data.setPointer(nullptr);
105 RHS.Data.setInt(false);
106 }
107
110 return;
111
113 Decls List = Data.getPointer();
115 List = ToDealloc->Rest;
116 C.DeallocateDeclListNode(ToDealloc);
117 }
118 }
119
123
126
127 Data = RHS.Data;
128 RHS.Data.setPointer(nullptr);
129 RHS.Data.setInt(false);
130 return *this;
131 }
132
133 bool isNull() const { return Data.getPointer().isNull(); }
134
136 assert(() && "No ASTContext.");
140 }
141
143
147
151
155
157 Data.setInt(true);
158 }
159
161 assert(() && "removing from empty list");
162 erase(D);
163 }
164
165
168
169
170 Data.setInt(false);
171 }
172
174
175
178 return true;
179
180 return llvm::any_of(Decls, [ND](NamedDecl *D) {
181
182
185 });
186 });
187
188
189 Data.setInt(false);
190
191 if (Decls.empty())
192 return;
193
194
195 ASTContext &C = Decls.front()->getASTContext();
197 for (size_t I = Decls.size() - 1; I != 0; --I) {
198 DeclListNode *Node = C.AllocateDeclListNode(Decls[I - 1]);
199 Node->Rest = DeclsAsList;
200 DeclsAsList = Node;
201 }
202
203 if (!Data.getPointer()) {
204 Data.setPointer(DeclsAsList);
205 return;
206 }
207
208
210 Node->Rest = DeclsAsList;
211 *Tail = Node;
212 }
213
214
218
219
220
222 const bool IsKnownNewer = true;
223
225 Data.setPointer(D);
226 return;
227 }
228
229
232 Data.setPointer(D);
233 return;
234 }
235
236
238 DeclListNode *Node = C.AllocateDeclListNode(OldD);
239 Node->Rest = D;
240 Data.setPointer(Node);
241 return;
242 }
243
244
245
246 assert(!llvm::is_contained(getLookupResult(), D) && "Already exists!");
247
251 N->D = D;
252 return;
253 }
254 if (auto *ND = N->Rest.dyn_cast<NamedDecl *>()) {
256 N->Rest = D;
257 return;
258 }
259
260
263 N->Rest = Node;
264 Node->Rest = D;
265 return;
266 }
267 }
268 }
269
270
273 Data.setPointer(D);
274 return;
275 }
276
279 Node->Rest = Data.getPointer();
280 Data.setPointer(Node);
281 }
282
283 LLVM_DUMP_METHOD void dump() const {
284 Decls D = Data.getPointer();
285 if (!D) {
286 llvm::errs() << "\n";
287 return;
288 }
289
290 while (true) {
291 if (auto *Node = D.dyn_cast<DeclListNode*>()) {
292 llvm::errs() << '[' << Node->D << "] -> ";
293 D = Node->Rest;
294 } else {
296 return;
297 }
298 }
299 }
300};
301
303 : public llvm::SmallDenseMap<DeclarationName, StoredDeclsList, 4> {
304 friend class ASTContext;
306
307 llvm::PointerIntPair<StoredDeclsMap*, 1> Previous;
308public:
310};
311
320
321}
322
323#endif
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DeclContextLookupResult lookup_result
A list storing NamedDecls in the lookup tables.
llvm::PointerUnion< NamedDecl *, DeclListNode * > Decls
ASTContext & getASTContext() const LLVM_READONLY
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
A dependently-generated diagnostic.
DependentStoredDeclsMap()=default
friend class DependentDiagnostic
Definition DeclContextInternals.h:314
friend class DeclContext
Definition DeclContextInternals.h:313
This represents a decl that may have a name.
bool declarationReplaces(const NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context,...
void setHasExternalDecls()
Definition DeclContextInternals.h:156
DeclsAndHasExternalTy getAsListAndHasExternal() const
Definition DeclContextInternals.h:142
DeclListNode * getAsList() const
Definition DeclContextInternals.h:148
StoredDeclsList(StoredDeclsList &&RHS)
Definition DeclContextInternals.h:103
void addOrReplaceDecl(NamedDecl *D)
If this is a redeclaration of an existing decl, replace the old one with D.
Definition DeclContextInternals.h:221
void MaybeDeallocList()
Definition DeclContextInternals.h:108
bool hasExternalDecls() const
Definition DeclContextInternals.h:152
NamedDecl * getAsDecl() const
Definition DeclContextInternals.h:144
void prependDeclNoReplace(NamedDecl *D)
Add a declaration to the list without checking if it replaces anything.
Definition DeclContextInternals.h:271
void replaceExternalDecls(ArrayRef< NamedDecl * > Decls)
Definition DeclContextInternals.h:173
void remove(NamedDecl *D)
Definition DeclContextInternals.h:160
ASTContext & getASTContext()
Definition DeclContextInternals.h:135
bool isNull() const
Definition DeclContextInternals.h:133
StoredDeclsList()=default
void removeExternalDecls()
Remove any declarations which were imported from an external AST source.
Definition DeclContextInternals.h:166
DeclContext::lookup_result getLookupResult() const
Return the list of all the decls.
Definition DeclContextInternals.h:215
LLVM_DUMP_METHOD void dump() const
Definition DeclContextInternals.h:283
StoredDeclsList & operator=(StoredDeclsList &&RHS)
Definition DeclContextInternals.h:124
~StoredDeclsList()
Definition DeclContextInternals.h:120
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
friend class ASTContext
Definition DeclContextInternals.h:304
friend class DeclContext
Definition DeclContextInternals.h:305
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
U cast(CodeGen::Address addr)