clang  12.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 //===----------------------------------------------------------------------===//
14 #include "clang/Sema/Lookup.h"
15 
16 using namespace clang;
17 
18 char MultiplexExternalSemaSource::ID;
19 
20 ///Constructs a new multiplexing external sema source and appends the
21 /// given element to it.
22 ///
24  ExternalSemaSource &s2){
25  Sources.push_back(&s1);
26  Sources.push_back(&s2);
27 }
28 
29 // pin the vtable here.
31 
32 ///Appends new source to the source list.
33 ///
34 ///\param[in] source - An ExternalSemaSource.
35 ///
37  Sources.push_back(&source);
38 }
39 
40 //===----------------------------------------------------------------------===//
41 // ExternalASTSource.
42 //===----------------------------------------------------------------------===//
43 
45  for(size_t i = 0; i < Sources.size(); ++i)
46  if (Decl *Result = Sources[i]->GetExternalDecl(ID))
47  return Result;
48  return nullptr;
49 }
50 
52  for (size_t i = 0; i < Sources.size(); ++i)
53  Sources[i]->CompleteRedeclChain(D);
54 }
55 
57  Selector Sel;
58  for(size_t i = 0; i < Sources.size(); ++i) {
59  Sel = Sources[i]->GetExternalSelector(ID);
60  if (!Sel.isNull())
61  return Sel;
62  }
63  return Sel;
64 }
65 
67  uint32_t total = 0;
68  for(size_t i = 0; i < Sources.size(); ++i)
69  total += Sources[i]->GetNumExternalSelectors();
70  return total;
71 }
72 
74  for(size_t i = 0; i < Sources.size(); ++i)
75  if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset))
76  return Result;
77  return nullptr;
78 }
79 
81  uint64_t Offset){
82  for(size_t i = 0; i < Sources.size(); ++i)
83  if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset))
84  return R;
85  return nullptr;
86 }
87 
90  for (auto *S : Sources)
91  if (auto *R = S->GetExternalCXXCtorInitializers(Offset))
92  return R;
93  return nullptr;
94 }
95 
98  for (const auto &S : Sources)
99  if (auto EK = S->hasExternalDefinitions(D))
100  if (EK != EK_ReplyHazy)
101  return EK;
102  return EK_ReplyHazy;
103 }
104 
107  bool AnyDeclsFound = false;
108  for (size_t i = 0; i < Sources.size(); ++i)
109  AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
110  return AnyDeclsFound;
111 }
112 
114  for(size_t i = 0; i < Sources.size(); ++i)
115  Sources[i]->completeVisibleDeclsMap(DC);
116 }
117 
119  const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
121  for(size_t i = 0; i < Sources.size(); ++i)
122  Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
123 }
124 
126  unsigned Offset,
127  unsigned Length,
128  SmallVectorImpl<Decl *> &Decls){
129  for(size_t i = 0; i < Sources.size(); ++i)
130  Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
131 }
132 
134  for(size_t i = 0; i < Sources.size(); ++i)
135  Sources[i]->CompleteType(Tag);
136 }
137 
139  for(size_t i = 0; i < Sources.size(); ++i)
140  Sources[i]->CompleteType(Class);
141 }
142 
144  for(size_t i = 0; i < Sources.size(); ++i)
145  Sources[i]->ReadComments();
146 }
147 
149  for(size_t i = 0; i < Sources.size(); ++i)
150  Sources[i]->StartedDeserializing();
151 }
152 
154  for(size_t i = 0; i < Sources.size(); ++i)
155  Sources[i]->FinishedDeserializing();
156 }
157 
159  for(size_t i = 0; i < Sources.size(); ++i)
160  Sources[i]->StartTranslationUnit(Consumer);
161 }
162 
164  for(size_t i = 0; i < Sources.size(); ++i)
165  Sources[i]->PrintStats();
166 }
167 
169  for (size_t i = 0; i < Sources.size(); ++i)
170  if (auto M = Sources[i]->getModule(ID))
171  return M;
172  return nullptr;
173 }
174 
176  for (auto *S : Sources)
177  if (S->DeclIsFromPCHWithObjectFile(D))
178  return true;
179  return false;
180 }
181 
183  uint64_t &Size,
184  uint64_t &Alignment,
185  llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
186  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
187  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){
188  for(size_t i = 0; i < Sources.size(); ++i)
189  if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets,
190  BaseOffsets, VirtualBaseOffsets))
191  return true;
192  return false;
193 }
194 
197  for(size_t i = 0; i < Sources.size(); ++i)
198  Sources[i]->getMemoryBufferSizes(sizes);
199 
200 }
201 
202 //===----------------------------------------------------------------------===//
203 // ExternalSemaSource.
204 //===----------------------------------------------------------------------===//
205 
206 
208  for(size_t i = 0; i < Sources.size(); ++i)
209  Sources[i]->InitializeSema(S);
210 }
211 
213  for(size_t i = 0; i < Sources.size(); ++i)
214  Sources[i]->ForgetSema();
215 }
216 
218  for(size_t i = 0; i < Sources.size(); ++i)
219  Sources[i]->ReadMethodPool(Sel);
220 }
221 
223  for(size_t i = 0; i < Sources.size(); ++i)
224  Sources[i]->updateOutOfDateSelector(Sel);
225 }
226 
228  SmallVectorImpl<NamespaceDecl*> &Namespaces){
229  for(size_t i = 0; i < Sources.size(); ++i)
230  Sources[i]->ReadKnownNamespaces(Namespaces);
231 }
232 
234  llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
235  for(size_t i = 0; i < Sources.size(); ++i)
236  Sources[i]->ReadUndefinedButUsed(Undefined);
237 }
238 
240  llvm::MapVector<FieldDecl *,
241  llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
242  Exprs) {
243  for (auto &Source : Sources)
244  Source->ReadMismatchingDeleteExpressions(Exprs);
245 }
246 
248  for(size_t i = 0; i < Sources.size(); ++i)
249  Sources[i]->LookupUnqualified(R, S);
250 
251  return !R.empty();
252 }
253 
255  SmallVectorImpl<VarDecl*> &TentativeDefs) {
256  for(size_t i = 0; i < Sources.size(); ++i)
257  Sources[i]->ReadTentativeDefinitions(TentativeDefs);
258 }
259 
262  for(size_t i = 0; i < Sources.size(); ++i)
263  Sources[i]->ReadUnusedFileScopedDecls(Decls);
264 }
265 
268  for(size_t i = 0; i < Sources.size(); ++i)
269  Sources[i]->ReadDelegatingConstructors(Decls);
270 }
271 
274  for(size_t i = 0; i < Sources.size(); ++i)
275  Sources[i]->ReadExtVectorDecls(Decls);
276 }
277 
280  for(size_t i = 0; i < Sources.size(); ++i)
281  Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
282 }
283 
286  for(size_t i = 0; i < Sources.size(); ++i)
287  Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls);
288 }
289 
291  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
292  for(size_t i = 0; i < Sources.size(); ++i)
293  Sources[i]->ReadReferencedSelectors(Sels);
294 }
295 
297  SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
298  for(size_t i = 0; i < Sources.size(); ++i)
299  Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
300 }
301 
304  for(size_t i = 0; i < Sources.size(); ++i)
305  Sources[i]->ReadUsedVTables(VTables);
306 }
307 
309  SmallVectorImpl<std::pair<ValueDecl*,
310  SourceLocation> > &Pending) {
311  for(size_t i = 0; i < Sources.size(); ++i)
312  Sources[i]->ReadPendingInstantiations(Pending);
313 }
314 
316  llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
317  &LPTMap) {
318  for (size_t i = 0; i < Sources.size(); ++i)
319  Sources[i]->ReadLateParsedTemplates(LPTMap);
320 }
321 
323  const DeclarationNameInfo &Typo,
324  int LookupKind, Scope *S, CXXScopeSpec *SS,
327  bool EnteringContext,
328  const ObjCObjectPointerType *OPT) {
329  for (size_t I = 0, E = Sources.size(); I < E; ++I) {
330  if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC,
331  MemberContext,
332  EnteringContext, OPT))
333  return C;
334  }
335  return TypoCorrection();
336 }
337 
339  SourceLocation Loc, QualType T) {
340  for (size_t I = 0, E = Sources.size(); I < E; ++I) {
341  if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T))
342  return true;
343  }
344  return false;
345 }
Represents a function declaration or definition.
Definition: Decl.h:1783
bool DeclIsFromPCHWithObjectFile(const Decl *D) override
Determine whether D comes from a PCH which was built with a corresponding object file.
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:655
Simple class containing the result of Sema::CorrectTypo.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
void completeVisibleDeclsMap(const DeclContext *DC) override
Ensures that the table of all visible declarations inside this context is up to date.
Stmt - This represents one statement.
Definition: Stmt.h:68
void StartTranslationUnit(ASTConsumer *Consumer) override
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
void StartedDeserializing() override
Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...
void ReadMethodPool(Selector Sel) override
Load the contents of the global method pool for a given selector.
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...
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
Module * getModule(unsigned ID) override
Retrieve the module that corresponds to the given module ID.
void CompleteRedeclChain(const Decl *D) override
Complete the redeclaration chain if it&#39;s been extended since the previous generation of the AST sourc...
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Find all declarations with the given name in the given context.
Represents a struct/union/class.
Definition: Decl.h:3770
bool LookupUnqualified(LookupResult &R, Scope *S) override
Do last resort, unqualified lookup on a LookupResult that Sema cannot find.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Represents a member of a struct/union/class.
Definition: Decl.h:2746
Describes a module or submodule.
Definition: Module.h:87
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...
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI) override
Read the set of weak, undeclared identifiers known to the external Sema source.
Represents the results of name lookup.
Definition: Lookup.h:46
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement in the decl stream into a statement.
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.
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
Decl * GetExternalDecl(uint32_t ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
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...
Represents an ObjC class declaration.
Definition: DeclObjC.h:1163
ExtKind hasExternalDefinitions(const Decl *D) override
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.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:340
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl *> &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
unsigned Offset
Definition: Format.cpp:2020
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:619
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
void FinishedDeserializing() override
Notify ExternalASTSource that we finished the deserialization of a decl or type.
void CompleteType(TagDecl *Tag) override
Gives the external AST source an opportunity to complete an incomplete type.
void PrintStats() override
Print any statistics that have been gathered regarding the external AST source.
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Resolve a handle to a list of ctor initializers into the list of initializers themselves.
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl *> &Defs) override
Read the set of tentative definitions known to the external Sema source.
The result type of a method or function.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap&#39;ed memor...
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending) override
Read the set of pending instantiations known to the external Sema source.
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 >> &Exprs) override
An abstract interface that should be implemented by external AST sources that also provide informatio...
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
Encodes a location in the source.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3239
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl *> &Decls) override
Read the set of delegating constructors known to the external Sema source.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl *> &Decls) override
Read the set of unused file-scope declarations known to the external Sema source. ...
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...
MultiplexExternalSemaSource(ExternalSemaSource &s1, ExternalSemaSource &s2)
Constructs a new multiplexing external sema source and appends the given element to it...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1303
The name of a declaration.
void ReadDeclsToCheckForDeferredDiags(llvm::SmallVector< Decl *, 4 > &Decls) override
Read the set of decls to be checked for deferred diags.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined) override
Load the set of used but not defined functions or variables with internal linkage, or used but not defined inline functions.
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate >> &LPTMap) override
Read the set of late parsed template functions for this source.
Represents a pointer to an Objective C object.
Definition: Type.h:6050
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2185
void addSource(ExternalSemaSource &source)
Appends new source to the source list.
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
void ReadComments() override
Loads comment ranges.
bool isNull() const
Determine whether this is the empty selector.
Selector GetExternalSelector(uint32_t ID) override
Resolve a selector ID into a selector.
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:92
bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T) override
Produces a diagnostic note if one of the attached sources contains a complete definition for T...
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339