clang  3.9.0
MultiplexExternalSemaSource.cpp
Go to the documentation of this file.
1 //===--- MultiplexExternalSemaSource.cpp ---------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the event dispatching to the subscribed clients.
11 //
12 //===----------------------------------------------------------------------===//
15 #include "clang/Sema/Lookup.h"
16 
17 using namespace clang;
18 
19 ///\brief Constructs a new multiplexing external sema source and appends the
20 /// given element to it.
21 ///
22 ///\param[in] source - An ExternalSemaSource.
23 ///
25  ExternalSemaSource &s2){
26  Sources.push_back(&s1);
27  Sources.push_back(&s2);
28 }
29 
30 // pin the vtable here.
32 
33 ///\brief Appends new source to the source list.
34 ///
35 ///\param[in] source - An ExternalSemaSource.
36 ///
38  Sources.push_back(&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  bool AnyDeclsFound = false;
100  for (size_t i = 0; i < Sources.size(); ++i)
101  AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
102  return AnyDeclsFound;
103 }
104 
106  for(size_t i = 0; i < Sources.size(); ++i)
107  Sources[i]->completeVisibleDeclsMap(DC);
108 }
109 
111  const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
112  SmallVectorImpl<Decl *> &Result) {
113  for(size_t i = 0; i < Sources.size(); ++i)
114  Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
115 }
116 
118  unsigned Offset,
119  unsigned Length,
120  SmallVectorImpl<Decl *> &Decls){
121  for(size_t i = 0; i < Sources.size(); ++i)
122  Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
123 }
124 
126  for(size_t i = 0; i < Sources.size(); ++i)
127  Sources[i]->CompleteType(Tag);
128 }
129 
131  for(size_t i = 0; i < Sources.size(); ++i)
132  Sources[i]->CompleteType(Class);
133 }
134 
136  for(size_t i = 0; i < Sources.size(); ++i)
137  Sources[i]->ReadComments();
138 }
139 
141  for(size_t i = 0; i < Sources.size(); ++i)
142  Sources[i]->StartedDeserializing();
143 }
144 
146  for(size_t i = 0; i < Sources.size(); ++i)
147  Sources[i]->FinishedDeserializing();
148 }
149 
151  for(size_t i = 0; i < Sources.size(); ++i)
152  Sources[i]->StartTranslationUnit(Consumer);
153 }
154 
156  for(size_t i = 0; i < Sources.size(); ++i)
157  Sources[i]->PrintStats();
158 }
159 
161  uint64_t &Size,
162  uint64_t &Alignment,
163  llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
164  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
165  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){
166  for(size_t i = 0; i < Sources.size(); ++i)
167  if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets,
168  BaseOffsets, VirtualBaseOffsets))
169  return true;
170  return false;
171 }
172 
175  for(size_t i = 0; i < Sources.size(); ++i)
176  Sources[i]->getMemoryBufferSizes(sizes);
177 
178 }
179 
180 //===----------------------------------------------------------------------===//
181 // ExternalSemaSource.
182 //===----------------------------------------------------------------------===//
183 
184 
186  for(size_t i = 0; i < Sources.size(); ++i)
187  Sources[i]->InitializeSema(S);
188 }
189 
191  for(size_t i = 0; i < Sources.size(); ++i)
192  Sources[i]->ForgetSema();
193 }
194 
196  for(size_t i = 0; i < Sources.size(); ++i)
197  Sources[i]->ReadMethodPool(Sel);
198 }
199 
201  for(size_t i = 0; i < Sources.size(); ++i)
202  Sources[i]->updateOutOfDateSelector(Sel);
203 }
204 
206  SmallVectorImpl<NamespaceDecl*> &Namespaces){
207  for(size_t i = 0; i < Sources.size(); ++i)
208  Sources[i]->ReadKnownNamespaces(Namespaces);
209 }
210 
212  llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
213  for(size_t i = 0; i < Sources.size(); ++i)
214  Sources[i]->ReadUndefinedButUsed(Undefined);
215 }
216 
218  llvm::MapVector<FieldDecl *,
219  llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
220  Exprs) {
221  for (auto &Source : Sources)
222  Source->ReadMismatchingDeleteExpressions(Exprs);
223 }
224 
226  for(size_t i = 0; i < Sources.size(); ++i)
227  Sources[i]->LookupUnqualified(R, S);
228 
229  return !R.empty();
230 }
231 
233  SmallVectorImpl<VarDecl*> &TentativeDefs) {
234  for(size_t i = 0; i < Sources.size(); ++i)
235  Sources[i]->ReadTentativeDefinitions(TentativeDefs);
236 }
237 
240  for(size_t i = 0; i < Sources.size(); ++i)
241  Sources[i]->ReadUnusedFileScopedDecls(Decls);
242 }
243 
246  for(size_t i = 0; i < Sources.size(); ++i)
247  Sources[i]->ReadDelegatingConstructors(Decls);
248 }
249 
252  for(size_t i = 0; i < Sources.size(); ++i)
253  Sources[i]->ReadExtVectorDecls(Decls);
254 }
255 
258  for(size_t i = 0; i < Sources.size(); ++i)
259  Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls);
260 }
261 
263  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
264  for(size_t i = 0; i < Sources.size(); ++i)
265  Sources[i]->ReadReferencedSelectors(Sels);
266 }
267 
269  SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
270  for(size_t i = 0; i < Sources.size(); ++i)
271  Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
272 }
273 
276  for(size_t i = 0; i < Sources.size(); ++i)
277  Sources[i]->ReadUsedVTables(VTables);
278 }
279 
281  SmallVectorImpl<std::pair<ValueDecl*,
282  SourceLocation> > &Pending) {
283  for(size_t i = 0; i < Sources.size(); ++i)
284  Sources[i]->ReadPendingInstantiations(Pending);
285 }
286 
288  llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {
289  for (size_t i = 0; i < Sources.size(); ++i)
290  Sources[i]->ReadLateParsedTemplates(LPTMap);
291 }
292 
294  const DeclarationNameInfo &Typo,
295  int LookupKind, Scope *S, CXXScopeSpec *SS,
297  DeclContext *MemberContext,
298  bool EnteringContext,
299  const ObjCObjectPointerType *OPT) {
300  for (size_t I = 0, E = Sources.size(); I < E; ++I) {
301  if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC,
302  MemberContext,
303  EnteringContext, OPT))
304  return C;
305  }
306  return TypoCorrection();
307 }
308 
310  SourceLocation Loc, QualType T) {
311  for (size_t I = 0, E = Sources.size(); I < E; ++I) {
312  if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T))
313  return true;
314  }
315  return false;
316 }
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...
Smart pointer class that efficiently represents Objective-C method names.
unsigned Length
A (possibly-)qualified type.
Definition: Type.h:598
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:36
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 completeVisibleDeclsMap(const DeclContext *DC) override
Ensures that the table of all visible declarations inside this context is up to date.
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 CompleteRedeclChain(const Decl *D) override
Complete the redeclaration chain if it'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.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3253
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
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 ...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2293
bool isNull() const
Determine whether this is the empty selector.
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: Sema/Lookup.h:30
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement in the decl stream into a statement.
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &Defs) override
Read the set of tentative definitions known to the external Sema source.
uint32_t Offset
Definition: CacheTokens.cpp:44
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:39
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:63
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:1091
detail::InMemoryDirectory::const_iterator I
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:590
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
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.
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.
The result type of a method or function.
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.
Kind
Encodes a location in the source.
const std::string ID
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2727
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls) override
Read the set of delegating constructors 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...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
DeclarationName - The name of a declaration.
detail::InMemoryDirectory::const_iterator E
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
StringRef Typo
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.
Represents a pointer to an Objective C object.
Definition: Type.h:4991
bool empty() const
Return true if no decls were found.
Definition: Sema/Lookup.h:323
Represents a C++ base or member initializer.
Definition: DeclCXX.h:1922
void addSource(ExternalSemaSource &source)
Appends new source to the source list.
Represents a base class of a C++ class.
Definition: DeclCXX.h:159
void ReadComments() override
Loads comment ranges.
Selector GetExternalSelector(uint32_t ID) override
Resolve a selector ID into a selector.
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T) override
Produces a diagnostic note if one of the attached sources contains a complete definition for T...
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls) override
Read the set of unused file-scope declarations known to the external Sema source. ...
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, LateParsedTemplate * > &LPTMap) override
Read the set of late parsed template functions for this source.