clang 23.0.0git
MultiplexExternalSemaSource.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
13#include "clang/Sema/Lookup.h"
14
15using namespace clang;
16
17char MultiplexExternalSemaSource::ID;
18
19/// Constructs an empty multiplexing external sema source.
21
22/// Constructs a new multiplexing external sema source and appends the
23/// given element to it.
24///
28 Sources.push_back(std::move(S1));
29 Sources.push_back(std::move(S2));
30}
31
32/// Appends new source to the source list.
33///
34///\param[in] source - An ExternalSemaSource.
35///
38 Sources.push_back(std::move(Source));
39}
40
41//===----------------------------------------------------------------------===//
42// ExternalASTSource.
43//===----------------------------------------------------------------------===//
44
46 for(size_t i = 0; i < Sources.size(); ++i)
47 if (Decl *Result = Sources[i]->GetExternalDecl(ID))
48 return Result;
49 return nullptr;
50}
51
53 for (size_t i = 0; i < Sources.size(); ++i)
54 Sources[i]->CompleteRedeclChain(D);
55}
56
58 Selector Sel;
59 for(size_t i = 0; i < Sources.size(); ++i) {
60 Sel = Sources[i]->GetExternalSelector(ID);
61 if (!Sel.isNull())
62 return Sel;
63 }
64 return Sel;
65}
66
68 uint32_t total = 0;
69 for(size_t i = 0; i < Sources.size(); ++i)
70 total += Sources[i]->GetNumExternalSelectors();
71 return total;
72}
73
75 for(size_t i = 0; i < Sources.size(); ++i)
76 if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset))
77 return Result;
78 return nullptr;
79}
80
82 uint64_t Offset){
83 for(size_t i = 0; i < Sources.size(); ++i)
84 if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset))
85 return R;
86 return nullptr;
87}
88
91 for (auto &S : Sources)
92 if (auto *R = S->GetExternalCXXCtorInitializers(Offset))
93 return R;
94 return nullptr;
95}
96
99 for (const auto &S : Sources)
100 if (auto EK = S->hasExternalDefinitions(D))
101 if (EK != EK_ReplyHazy)
102 return EK;
103 return EK_ReplyHazy;
104}
105
107 const FunctionDecl *FD) {
108 for (const auto &S : Sources)
109 if (S->wasThisDeclarationADefinition(FD))
110 return true;
111 return false;
112}
113
115 const DeclContext *DC, DeclarationName Name,
116 const DeclContext *OriginalDC) {
117 bool AnyDeclsFound = false;
118 for (size_t i = 0; i < Sources.size(); ++i)
119 AnyDeclsFound |=
120 Sources[i]->FindExternalVisibleDeclsByName(DC, Name, OriginalDC);
121 return AnyDeclsFound;
122}
123
125 const Decl *D, bool OnlyPartial) {
126 bool Loaded = false;
127 for (size_t i = 0; i < Sources.size(); ++i)
128 Loaded |= Sources[i]->LoadExternalSpecializations(D, OnlyPartial);
129 return Loaded;
130}
131
133 const Decl *D, ArrayRef<TemplateArgument> TemplateArgs) {
134 bool AnyNewSpecsLoaded = false;
135 for (size_t i = 0; i < Sources.size(); ++i)
136 AnyNewSpecsLoaded |=
137 Sources[i]->LoadExternalSpecializations(D, TemplateArgs);
138 return AnyNewSpecsLoaded;
139}
140
142 for(size_t i = 0; i < Sources.size(); ++i)
143 Sources[i]->completeVisibleDeclsMap(DC);
144}
145
147 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
149 for(size_t i = 0; i < Sources.size(); ++i)
150 Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
151}
152
154 unsigned Offset,
155 unsigned Length,
157 for(size_t i = 0; i < Sources.size(); ++i)
158 Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
159}
160
162 for(size_t i = 0; i < Sources.size(); ++i)
163 Sources[i]->CompleteType(Tag);
164}
165
167 for(size_t i = 0; i < Sources.size(); ++i)
168 Sources[i]->CompleteType(Class);
169}
170
172 for(size_t i = 0; i < Sources.size(); ++i)
173 Sources[i]->ReadComments();
174}
175
177 for(size_t i = 0; i < Sources.size(); ++i)
178 Sources[i]->StartedDeserializing();
179}
180
182 for(size_t i = 0; i < Sources.size(); ++i)
183 Sources[i]->FinishedDeserializing();
184}
185
187 for(size_t i = 0; i < Sources.size(); ++i)
188 Sources[i]->StartTranslationUnit(Consumer);
189}
190
192 for(size_t i = 0; i < Sources.size(); ++i)
193 Sources[i]->PrintStats();
194}
195
197 for (size_t i = 0; i < Sources.size(); ++i)
198 if (auto M = Sources[i]->getModule(ID))
199 return M;
200 return nullptr;
201}
202
204 uint64_t &Size,
205 uint64_t &Alignment,
206 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
207 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
208 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){
209 for(size_t i = 0; i < Sources.size(); ++i)
210 if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets,
211 BaseOffsets, VirtualBaseOffsets))
212 return true;
213 return false;
214}
215
218 for(size_t i = 0; i < Sources.size(); ++i)
219 Sources[i]->getMemoryBufferSizes(sizes);
220
221}
222
223//===----------------------------------------------------------------------===//
224// ExternalSemaSource.
225//===----------------------------------------------------------------------===//
226
227
229 for(size_t i = 0; i < Sources.size(); ++i)
230 Sources[i]->InitializeSema(S);
231}
232
234 for(size_t i = 0; i < Sources.size(); ++i)
235 Sources[i]->ForgetSema();
236}
237
239 for(size_t i = 0; i < Sources.size(); ++i)
240 Sources[i]->ReadMethodPool(Sel);
241}
242
244 for(size_t i = 0; i < Sources.size(); ++i)
245 Sources[i]->updateOutOfDateSelector(Sel);
246}
247
250 for(size_t i = 0; i < Sources.size(); ++i)
251 Sources[i]->ReadKnownNamespaces(Namespaces);
252}
253
255 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
256 for(size_t i = 0; i < Sources.size(); ++i)
257 Sources[i]->ReadUndefinedButUsed(Undefined);
258}
259
261 llvm::MapVector<FieldDecl *,
262 llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
263 Exprs) {
264 for (auto &Source : Sources)
265 Source->ReadMismatchingDeleteExpressions(Exprs);
266}
267
269 for(size_t i = 0; i < Sources.size(); ++i)
270 Sources[i]->LookupUnqualified(R, S);
271
272 return !R.empty();
273}
274
276 SmallVectorImpl<VarDecl*> &TentativeDefs) {
277 for(size_t i = 0; i < Sources.size(); ++i)
278 Sources[i]->ReadTentativeDefinitions(TentativeDefs);
279}
280
283 for(size_t i = 0; i < Sources.size(); ++i)
284 Sources[i]->ReadUnusedFileScopedDecls(Decls);
285}
286
289 for(size_t i = 0; i < Sources.size(); ++i)
290 Sources[i]->ReadDelegatingConstructors(Decls);
291}
292
295 for(size_t i = 0; i < Sources.size(); ++i)
296 Sources[i]->ReadExtVectorDecls(Decls);
297}
298
301 for(size_t i = 0; i < Sources.size(); ++i)
302 Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
303}
304
310
312 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
313 for(size_t i = 0; i < Sources.size(); ++i)
314 Sources[i]->ReadReferencedSelectors(Sels);
315}
316
318 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
319 for(size_t i = 0; i < Sources.size(); ++i)
320 Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
321}
322
324 SmallVectorImpl<std::pair<IdentifierInfo *, AsmLabelAttr *>> &EI) {
325 for (size_t i = 0; i < Sources.size(); ++i)
326 Sources[i]->ReadExtnameUndeclaredIdentifiers(EI);
327}
328
331 for(size_t i = 0; i < Sources.size(); ++i)
332 Sources[i]->ReadUsedVTables(VTables);
333}
334
336 SmallVectorImpl<std::pair<ValueDecl*,
337 SourceLocation> > &Pending) {
338 for(size_t i = 0; i < Sources.size(); ++i)
339 Sources[i]->ReadPendingInstantiations(Pending);
340}
341
343 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
344 &LPTMap) {
345 for (size_t i = 0; i < Sources.size(); ++i)
346 Sources[i]->ReadLateParsedTemplates(LPTMap);
347}
348
350 const DeclarationNameInfo &Typo,
351 int LookupKind, Scope *S, CXXScopeSpec *SS,
353 DeclContext *MemberContext,
354 bool EnteringContext,
355 const ObjCObjectPointerType *OPT) {
356 for (size_t I = 0, E = Sources.size(); I < E; ++I) {
357 if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC,
358 MemberContext,
359 EnteringContext, OPT))
360 return C;
361 }
362 return TypoCorrection();
363}
364
366 SourceLocation Loc, QualType T) {
367 for (size_t I = 0, E = Sources.size(); I < E; ++I) {
368 if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T))
369 return true;
370 }
371 return false;
372}
373
375 CXXRecordDecl *Lambda) {
376 for (auto &Source : Sources)
377 Source->AssignedLambdaNumbering(Lambda);
378}
llvm::MachO::Record Record
Definition MachO.h:31
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition ASTConsumer.h:35
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a C++ base or member initializer.
Definition DeclCXX.h:2398
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:76
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Kind
Lists the kind of concrete classes of Decl.
Definition DeclBase.h:89
The name of a declaration.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
Represents a member of a struct/union/class.
Definition Decl.h:3191
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
Definition Decl.h:2027
Represents the results of name lookup.
Definition Lookup.h:147
Describes a module or submodule.
Definition Module.h:340
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > &LPTMap) override
Read the set of late parsed template functions for this source.
void ReadExtnameUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, AsmLabelAttr * > > &EI) override
Read the set of pragma redefine_extname'd, undeclared identifiers known to the external Sema source.
void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls) override
Get the decls that are contained in a file in the Offset/Length range.
bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override
Load all the external specializations for the Decl.
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement in the decl stream into a statement.
bool wasThisDeclarationADefinition(const FunctionDecl *FD) override
True if this function declaration was a definition before in its own module.
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, int LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, DeclContext *MemberContext, bool EnteringContext, const ObjCObjectPointerType *OPT) override
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
bool LookupUnqualified(LookupResult &R, Scope *S) override
Do last resort, unqualified lookup on a LookupResult that Sema cannot find.
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls) override
Read the set of delegating constructors known to the external Sema source.
void AddSource(llvm::IntrusiveRefCntPtr< ExternalSemaSource > Source)
Appends new source to the source list.
ExtKind hasExternalDefinitions(const Decl *D) override
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &Exprs) override
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls) override
Read the set of unused file-scope declarations known to the external Sema source.
void ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector< Decl *, 4 > &Decls) override
Read the set of decls to be checked for deferred diags.
Selector GetExternalSelector(uint32_t ID) override
Resolve a selector ID into a selector.
CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset) override
Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers.
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &Defs) override
Read the set of tentative definitions known to the external Sema source.
void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined) override
Load the set of used but not defined functions or variables with internal linkage,...
void ReadComments() override
Loads comment ranges.
void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result) override
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
void PrintStats() override
Print any statistics that have been gathered regarding the external AST source.
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI) override
Read the set of weak, undeclared identifiers known to the external Sema source.
MultiplexExternalSemaSource()
Constructs an empty multiplexing external sema source.
void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override
Notify the external source that a lambda was assigned a mangling number.
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Resolve a handle to a list of ctor initializers into the list of initializers themselves.
void CompleteType(TagDecl *Tag) override
Gives the external AST source an opportunity to complete an incomplete type.
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
void StartedDeserializing() override
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...
void FinishedDeserializing() override
Notify ExternalASTSource that we finished the deserialization of a decl or type.
bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T) override
Produces a diagnostic note if one of the attached sources contains a complete definition for T.
void ReadMethodPool(Selector Sel) override
Load the contents of the global method pool for a given selector.
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
void CompleteRedeclChain(const Decl *D) override
Complete the redeclaration chain if it's been extended since the previous generation of the AST sourc...
Decl * GetExternalDecl(GlobalDeclID ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
void completeVisibleDeclsMap(const DeclContext *DC) override
Ensures that the table of all visible declarations inside this context is up to date.
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC) override
Find all declarations with the given name in the given context.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
void StartTranslationUnit(ASTConsumer *Consumer) override
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
bool layoutRecordType(const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &BaseOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &VirtualBaseOffsets) override
Perform layout on the given record.
void ReadKnownNamespaces(SmallVectorImpl< NamespaceDecl * > &Namespaces) override
Load the set of namespaces that are known to the external source, which will be used during typo corr...
Module * getModule(unsigned ID) override
Retrieve the module that corresponds to the given module ID.
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending) override
Read the set of pending instantiations known to the external Sema source.
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
Represents a pointer to an Objective C object.
Definition TypeBase.h:8065
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4356
Scope - A scope is a transient data structure that is used while parsing the program.
Definition Scope.h:41
Smart pointer class that efficiently represents Objective-C method names.
bool isNull() const
Determine whether this is the empty selector.
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:86
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3748
Simple class containing the result of Sema::CorrectTypo.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
The JSON file list parser is used to communicate input to InstallAPI.
@ Undefined
Keep undefined.
@ Result
The result type of a method or function.
Definition TypeBase.h:905
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5981
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...