1 | //===--- MultiplexExternalSemaSource.cpp ---------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file implements the event dispatching to the subscribed clients. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | #include "clang/Sema/MultiplexExternalSemaSource.h" |
13 | #include "clang/Sema/Lookup.h" |
14 | |
15 | using namespace clang; |
16 | |
17 | char MultiplexExternalSemaSource::ID; |
18 | |
19 | /// Constructs a new multiplexing external sema source and appends the |
20 | /// given element to it. |
21 | /// |
22 | MultiplexExternalSemaSource::MultiplexExternalSemaSource( |
23 | ExternalSemaSource *S1, ExternalSemaSource *S2) { |
24 | S1->Retain(); |
25 | S2->Retain(); |
26 | Sources.push_back(Elt: S1); |
27 | Sources.push_back(Elt: S2); |
28 | } |
29 | |
30 | // pin the vtable here. |
31 | MultiplexExternalSemaSource::~MultiplexExternalSemaSource() { |
32 | for (auto *S : Sources) |
33 | S->Release(); |
34 | } |
35 | |
36 | /// Appends new source to the source list. |
37 | /// |
38 | ///\param[in] source - An ExternalSemaSource. |
39 | /// |
40 | void MultiplexExternalSemaSource::AddSource(ExternalSemaSource *Source) { |
41 | Source->Retain(); |
42 | Sources.push_back(Elt: Source); |
43 | } |
44 | |
45 | //===----------------------------------------------------------------------===// |
46 | // ExternalASTSource. |
47 | //===----------------------------------------------------------------------===// |
48 | |
49 | Decl *MultiplexExternalSemaSource::GetExternalDecl(GlobalDeclID ID) { |
50 | for(size_t i = 0; i < Sources.size(); ++i) |
51 | if (Decl *Result = Sources[i]->GetExternalDecl(ID)) |
52 | return Result; |
53 | return nullptr; |
54 | } |
55 | |
56 | void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) { |
57 | for (size_t i = 0; i < Sources.size(); ++i) |
58 | Sources[i]->CompleteRedeclChain(D); |
59 | } |
60 | |
61 | Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) { |
62 | Selector Sel; |
63 | for(size_t i = 0; i < Sources.size(); ++i) { |
64 | Sel = Sources[i]->GetExternalSelector(ID); |
65 | if (!Sel.isNull()) |
66 | return Sel; |
67 | } |
68 | return Sel; |
69 | } |
70 | |
71 | uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() { |
72 | uint32_t total = 0; |
73 | for(size_t i = 0; i < Sources.size(); ++i) |
74 | total += Sources[i]->GetNumExternalSelectors(); |
75 | return total; |
76 | } |
77 | |
78 | Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) { |
79 | for(size_t i = 0; i < Sources.size(); ++i) |
80 | if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset)) |
81 | return Result; |
82 | return nullptr; |
83 | } |
84 | |
85 | CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers( |
86 | uint64_t Offset){ |
87 | for(size_t i = 0; i < Sources.size(); ++i) |
88 | if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset)) |
89 | return R; |
90 | return nullptr; |
91 | } |
92 | |
93 | CXXCtorInitializer ** |
94 | MultiplexExternalSemaSource::GetExternalCXXCtorInitializers(uint64_t Offset) { |
95 | for (auto *S : Sources) |
96 | if (auto *R = S->GetExternalCXXCtorInitializers(Offset)) |
97 | return R; |
98 | return nullptr; |
99 | } |
100 | |
101 | ExternalASTSource::ExtKind |
102 | MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) { |
103 | for (const auto &S : Sources) |
104 | if (auto EK = S->hasExternalDefinitions(D)) |
105 | if (EK != EK_ReplyHazy) |
106 | return EK; |
107 | return EK_ReplyHazy; |
108 | } |
109 | |
110 | bool MultiplexExternalSemaSource::wasThisDeclarationADefinition( |
111 | const FunctionDecl *FD) { |
112 | for (const auto &S : Sources) |
113 | if (S->wasThisDeclarationADefinition(FD)) |
114 | return true; |
115 | return false; |
116 | } |
117 | |
118 | bool MultiplexExternalSemaSource::FindExternalVisibleDeclsByName( |
119 | const DeclContext *DC, DeclarationName Name, |
120 | const DeclContext *OriginalDC) { |
121 | bool AnyDeclsFound = false; |
122 | for (size_t i = 0; i < Sources.size(); ++i) |
123 | AnyDeclsFound |= |
124 | Sources[i]->FindExternalVisibleDeclsByName(DC, Name, OriginalDC); |
125 | return AnyDeclsFound; |
126 | } |
127 | |
128 | bool MultiplexExternalSemaSource::LoadExternalSpecializations( |
129 | const Decl *D, bool OnlyPartial) { |
130 | bool Loaded = false; |
131 | for (size_t i = 0; i < Sources.size(); ++i) |
132 | Loaded |= Sources[i]->LoadExternalSpecializations(D, OnlyPartial); |
133 | return Loaded; |
134 | } |
135 | |
136 | bool MultiplexExternalSemaSource::LoadExternalSpecializations( |
137 | const Decl *D, ArrayRef<TemplateArgument> TemplateArgs) { |
138 | bool AnyNewSpecsLoaded = false; |
139 | for (size_t i = 0; i < Sources.size(); ++i) |
140 | AnyNewSpecsLoaded |= |
141 | Sources[i]->LoadExternalSpecializations(D, TemplateArgs); |
142 | return AnyNewSpecsLoaded; |
143 | } |
144 | |
145 | void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){ |
146 | for(size_t i = 0; i < Sources.size(); ++i) |
147 | Sources[i]->completeVisibleDeclsMap(DC); |
148 | } |
149 | |
150 | void MultiplexExternalSemaSource::FindExternalLexicalDecls( |
151 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
152 | SmallVectorImpl<Decl *> &Result) { |
153 | for(size_t i = 0; i < Sources.size(); ++i) |
154 | Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result); |
155 | } |
156 | |
157 | void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File, |
158 | unsigned Offset, |
159 | unsigned Length, |
160 | SmallVectorImpl<Decl *> &Decls){ |
161 | for(size_t i = 0; i < Sources.size(); ++i) |
162 | Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls); |
163 | } |
164 | |
165 | void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) { |
166 | for(size_t i = 0; i < Sources.size(); ++i) |
167 | Sources[i]->CompleteType(Tag); |
168 | } |
169 | |
170 | void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) { |
171 | for(size_t i = 0; i < Sources.size(); ++i) |
172 | Sources[i]->CompleteType(Class); |
173 | } |
174 | |
175 | void MultiplexExternalSemaSource::ReadComments() { |
176 | for(size_t i = 0; i < Sources.size(); ++i) |
177 | Sources[i]->ReadComments(); |
178 | } |
179 | |
180 | void MultiplexExternalSemaSource::StartedDeserializing() { |
181 | for(size_t i = 0; i < Sources.size(); ++i) |
182 | Sources[i]->StartedDeserializing(); |
183 | } |
184 | |
185 | void MultiplexExternalSemaSource::FinishedDeserializing() { |
186 | for(size_t i = 0; i < Sources.size(); ++i) |
187 | Sources[i]->FinishedDeserializing(); |
188 | } |
189 | |
190 | void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) { |
191 | for(size_t i = 0; i < Sources.size(); ++i) |
192 | Sources[i]->StartTranslationUnit(Consumer); |
193 | } |
194 | |
195 | void MultiplexExternalSemaSource::PrintStats() { |
196 | for(size_t i = 0; i < Sources.size(); ++i) |
197 | Sources[i]->PrintStats(); |
198 | } |
199 | |
200 | Module *MultiplexExternalSemaSource::getModule(unsigned ID) { |
201 | for (size_t i = 0; i < Sources.size(); ++i) |
202 | if (auto M = Sources[i]->getModule(ID)) |
203 | return M; |
204 | return nullptr; |
205 | } |
206 | |
207 | bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record, |
208 | uint64_t &Size, |
209 | uint64_t &Alignment, |
210 | llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, |
211 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, |
212 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){ |
213 | for(size_t i = 0; i < Sources.size(); ++i) |
214 | if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets, |
215 | BaseOffsets, VirtualBaseOffsets)) |
216 | return true; |
217 | return false; |
218 | } |
219 | |
220 | void MultiplexExternalSemaSource:: |
221 | getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
222 | for(size_t i = 0; i < Sources.size(); ++i) |
223 | Sources[i]->getMemoryBufferSizes(sizes); |
224 | |
225 | } |
226 | |
227 | //===----------------------------------------------------------------------===// |
228 | // ExternalSemaSource. |
229 | //===----------------------------------------------------------------------===// |
230 | |
231 | |
232 | void MultiplexExternalSemaSource::InitializeSema(Sema &S) { |
233 | for(size_t i = 0; i < Sources.size(); ++i) |
234 | Sources[i]->InitializeSema(S); |
235 | } |
236 | |
237 | void MultiplexExternalSemaSource::ForgetSema() { |
238 | for(size_t i = 0; i < Sources.size(); ++i) |
239 | Sources[i]->ForgetSema(); |
240 | } |
241 | |
242 | void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) { |
243 | for(size_t i = 0; i < Sources.size(); ++i) |
244 | Sources[i]->ReadMethodPool(Sel); |
245 | } |
246 | |
247 | void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) { |
248 | for(size_t i = 0; i < Sources.size(); ++i) |
249 | Sources[i]->updateOutOfDateSelector(Sel); |
250 | } |
251 | |
252 | void MultiplexExternalSemaSource::ReadKnownNamespaces( |
253 | SmallVectorImpl<NamespaceDecl*> &Namespaces){ |
254 | for(size_t i = 0; i < Sources.size(); ++i) |
255 | Sources[i]->ReadKnownNamespaces(Namespaces); |
256 | } |
257 | |
258 | void MultiplexExternalSemaSource::ReadUndefinedButUsed( |
259 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
260 | for(size_t i = 0; i < Sources.size(); ++i) |
261 | Sources[i]->ReadUndefinedButUsed(Undefined); |
262 | } |
263 | |
264 | void MultiplexExternalSemaSource::ReadMismatchingDeleteExpressions( |
265 | llvm::MapVector<FieldDecl *, |
266 | llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
267 | Exprs) { |
268 | for (auto &Source : Sources) |
269 | Source->ReadMismatchingDeleteExpressions(Exprs); |
270 | } |
271 | |
272 | bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ |
273 | for(size_t i = 0; i < Sources.size(); ++i) |
274 | Sources[i]->LookupUnqualified(R, S); |
275 | |
276 | return !R.empty(); |
277 | } |
278 | |
279 | void MultiplexExternalSemaSource::ReadTentativeDefinitions( |
280 | SmallVectorImpl<VarDecl*> &TentativeDefs) { |
281 | for(size_t i = 0; i < Sources.size(); ++i) |
282 | Sources[i]->ReadTentativeDefinitions(TentativeDefs); |
283 | } |
284 | |
285 | void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls( |
286 | SmallVectorImpl<const DeclaratorDecl*> &Decls) { |
287 | for(size_t i = 0; i < Sources.size(); ++i) |
288 | Sources[i]->ReadUnusedFileScopedDecls(Decls); |
289 | } |
290 | |
291 | void MultiplexExternalSemaSource::ReadDelegatingConstructors( |
292 | SmallVectorImpl<CXXConstructorDecl*> &Decls) { |
293 | for(size_t i = 0; i < Sources.size(); ++i) |
294 | Sources[i]->ReadDelegatingConstructors(Decls); |
295 | } |
296 | |
297 | void MultiplexExternalSemaSource::ReadExtVectorDecls( |
298 | SmallVectorImpl<TypedefNameDecl*> &Decls) { |
299 | for(size_t i = 0; i < Sources.size(); ++i) |
300 | Sources[i]->ReadExtVectorDecls(Decls); |
301 | } |
302 | |
303 | void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags( |
304 | llvm::SmallSetVector<Decl *, 4> &Decls) { |
305 | for(size_t i = 0; i < Sources.size(); ++i) |
306 | Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls); |
307 | } |
308 | |
309 | void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates( |
310 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
311 | for(size_t i = 0; i < Sources.size(); ++i) |
312 | Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls); |
313 | } |
314 | |
315 | void MultiplexExternalSemaSource::ReadReferencedSelectors( |
316 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
317 | for(size_t i = 0; i < Sources.size(); ++i) |
318 | Sources[i]->ReadReferencedSelectors(Sels); |
319 | } |
320 | |
321 | void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers( |
322 | SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) { |
323 | for(size_t i = 0; i < Sources.size(); ++i) |
324 | Sources[i]->ReadWeakUndeclaredIdentifiers(WI); |
325 | } |
326 | |
327 | void MultiplexExternalSemaSource::ReadUsedVTables( |
328 | SmallVectorImpl<ExternalVTableUse> &VTables) { |
329 | for(size_t i = 0; i < Sources.size(); ++i) |
330 | Sources[i]->ReadUsedVTables(VTables); |
331 | } |
332 | |
333 | void MultiplexExternalSemaSource::ReadPendingInstantiations( |
334 | SmallVectorImpl<std::pair<ValueDecl*, |
335 | SourceLocation> > &Pending) { |
336 | for(size_t i = 0; i < Sources.size(); ++i) |
337 | Sources[i]->ReadPendingInstantiations(Pending); |
338 | } |
339 | |
340 | void MultiplexExternalSemaSource::ReadLateParsedTemplates( |
341 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
342 | &LPTMap) { |
343 | for (size_t i = 0; i < Sources.size(); ++i) |
344 | Sources[i]->ReadLateParsedTemplates(LPTMap); |
345 | } |
346 | |
347 | TypoCorrection MultiplexExternalSemaSource::CorrectTypo( |
348 | const DeclarationNameInfo &Typo, |
349 | int LookupKind, Scope *S, CXXScopeSpec *SS, |
350 | CorrectionCandidateCallback &CCC, |
351 | DeclContext *MemberContext, |
352 | bool EnteringContext, |
353 | const ObjCObjectPointerType *OPT) { |
354 | for (size_t I = 0, E = Sources.size(); I < E; ++I) { |
355 | if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC, |
356 | MemberContext, |
357 | EnteringContext, OPT)) |
358 | return C; |
359 | } |
360 | return TypoCorrection(); |
361 | } |
362 | |
363 | bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType( |
364 | SourceLocation Loc, QualType T) { |
365 | for (size_t I = 0, E = Sources.size(); I < E; ++I) { |
366 | if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T)) |
367 | return true; |
368 | } |
369 | return false; |
370 | } |
371 | |
372 | void MultiplexExternalSemaSource::AssignedLambdaNumbering( |
373 | CXXRecordDecl *Lambda) { |
374 | for (auto *Source : Sources) |
375 | Source->AssignedLambdaNumbering(Lambda); |
376 | } |
377 |
Definitions
- ID
- MultiplexExternalSemaSource
- ~MultiplexExternalSemaSource
- AddSource
- GetExternalDecl
- CompleteRedeclChain
- GetExternalSelector
- GetNumExternalSelectors
- GetExternalDeclStmt
- GetExternalCXXBaseSpecifiers
- GetExternalCXXCtorInitializers
- hasExternalDefinitions
- wasThisDeclarationADefinition
- FindExternalVisibleDeclsByName
- LoadExternalSpecializations
- LoadExternalSpecializations
- completeVisibleDeclsMap
- FindExternalLexicalDecls
- FindFileRegionDecls
- CompleteType
- CompleteType
- ReadComments
- StartedDeserializing
- FinishedDeserializing
- StartTranslationUnit
- PrintStats
- getModule
- layoutRecordType
- getMemoryBufferSizes
- InitializeSema
- ForgetSema
- ReadMethodPool
- updateOutOfDateSelector
- ReadKnownNamespaces
- ReadUndefinedButUsed
- ReadMismatchingDeleteExpressions
- LookupUnqualified
- ReadTentativeDefinitions
- ReadUnusedFileScopedDecls
- ReadDelegatingConstructors
- ReadExtVectorDecls
- ReadDeclsToCheckForDeferredDiags
- ReadUnusedLocalTypedefNameCandidates
- ReadReferencedSelectors
- ReadWeakUndeclaredIdentifiers
- ReadUsedVTables
- ReadPendingInstantiations
- ReadLateParsedTemplates
- CorrectTypo
- MaybeDiagnoseMissingCompleteType
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more