clang  3.7.0
MultiplexExternalSemaSource.h
Go to the documentation of this file.
1 //===--- MultiplexExternalSemaSource.h - External Sema Interface-*- C++ -*-===//
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 defines ExternalSemaSource interface, dispatching to all clients
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
14 #define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
15 
17 #include "clang/Sema/Weak.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include <utility>
20 
21 namespace clang {
22 
23  class CXXConstructorDecl;
24  class CXXRecordDecl;
25  class DeclaratorDecl;
26  struct ExternalVTableUse;
27  class LookupResult;
28  class NamespaceDecl;
29  class Scope;
30  class Sema;
31  class TypedefNameDecl;
32  class ValueDecl;
33  class VarDecl;
34 
35 
36 /// \brief An abstract interface that should be implemented by
37 /// external AST sources that also provide information for semantic
38 /// analysis.
40 
41 private:
42  SmallVector<ExternalSemaSource *, 2> Sources; // doesn't own them.
43 
44 public:
45 
46  ///\brief Constructs a new multiplexing external sema source and appends the
47  /// given element to it.
48  ///
49  ///\param[in] s1 - A non-null (old) ExternalSemaSource.
50  ///\param[in] s2 - A non-null (new) ExternalSemaSource.
51  ///
53 
55 
56  ///\brief Appends new source to the source list.
57  ///
58  ///\param[in] source - An ExternalSemaSource.
59  ///
60  void addSource(ExternalSemaSource &source);
61 
62  //===--------------------------------------------------------------------===//
63  // ExternalASTSource.
64  //===--------------------------------------------------------------------===//
65 
66  /// \brief Resolve a declaration ID into a declaration, potentially
67  /// building a new declaration.
68  Decl *GetExternalDecl(uint32_t ID) override;
69 
70  /// \brief Complete the redeclaration chain if it's been extended since the
71  /// previous generation of the AST source.
72  void CompleteRedeclChain(const Decl *D) override;
73 
74  /// \brief Resolve a selector ID into a selector.
75  Selector GetExternalSelector(uint32_t ID) override;
76 
77  /// \brief Returns the number of selectors known to the external AST
78  /// source.
79  uint32_t GetNumExternalSelectors() override;
80 
81  /// \brief Resolve the offset of a statement in the decl stream into
82  /// a statement.
83  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
84 
85  /// \brief Resolve the offset of a set of C++ base specifiers in the decl
86  /// stream into an array of specifiers.
87  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
88 
89  /// \brief Resolve a handle to a list of ctor initializers into the list of
90  /// initializers themselves.
91  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
92 
93  /// \brief Find all declarations with the given name in the
94  /// given context.
96  DeclarationName Name) override;
97 
98  /// \brief Ensures that the table of all visible declarations inside this
99  /// context is up to date.
100  void completeVisibleDeclsMap(const DeclContext *DC) override;
101 
102  /// \brief Finds all declarations lexically contained within the given
103  /// DeclContext, after applying an optional filter predicate.
104  ///
105  /// \param isKindWeWant a predicate function that returns true if the passed
106  /// declaration kind is one we are looking for. If NULL, all declarations
107  /// are returned.
108  ///
109  /// \return an indication of whether the load succeeded or failed.
111  bool (*isKindWeWant)(Decl::Kind),
112  SmallVectorImpl<Decl*> &Result) override;
113 
114  /// \brief Finds all declarations lexically contained within the given
115  /// DeclContext.
116  ///
117  /// \return true if an error occurred
119  SmallVectorImpl<Decl*> &Result) {
120  return FindExternalLexicalDecls(DC, nullptr, Result);
121  }
122 
123  template <typename DeclTy>
125  SmallVectorImpl<Decl*> &Result) {
126  return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
127  }
128 
129  /// \brief Get the decls that are contained in a file in the Offset/Length
130  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
131  /// a range.
132  void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
133  SmallVectorImpl<Decl *> &Decls) override;
134 
135  /// \brief Gives the external AST source an opportunity to complete
136  /// an incomplete type.
137  void CompleteType(TagDecl *Tag) override;
138 
139  /// \brief Gives the external AST source an opportunity to complete an
140  /// incomplete Objective-C class.
141  ///
142  /// This routine will only be invoked if the "externally completed" bit is
143  /// set on the ObjCInterfaceDecl via the function
144  /// \c ObjCInterfaceDecl::setExternallyCompleted().
145  void CompleteType(ObjCInterfaceDecl *Class) override;
146 
147  /// \brief Loads comment ranges.
148  void ReadComments() override;
149 
150  /// \brief Notify ExternalASTSource that we started deserialization of
151  /// a decl or type so until FinishedDeserializing is called there may be
152  /// decls that are initializing. Must be paired with FinishedDeserializing.
153  void StartedDeserializing() override;
154 
155  /// \brief Notify ExternalASTSource that we finished the deserialization of
156  /// a decl or type. Must be paired with StartedDeserializing.
157  void FinishedDeserializing() override;
158 
159  /// \brief Function that will be invoked when we begin parsing a new
160  /// translation unit involving this external AST source.
161  void StartTranslationUnit(ASTConsumer *Consumer) override;
162 
163  /// \brief Print any statistics that have been gathered regarding
164  /// the external AST source.
165  void PrintStats() override;
166 
167 
168  /// \brief Perform layout on the given record.
169  ///
170  /// This routine allows the external AST source to provide an specific
171  /// layout for a record, overriding the layout that would normally be
172  /// constructed. It is intended for clients who receive specific layout
173  /// details rather than source code (such as LLDB). The client is expected
174  /// to fill in the field offsets, base offsets, virtual base offsets, and
175  /// complete object size.
176  ///
177  /// \param Record The record whose layout is being requested.
178  ///
179  /// \param Size The final size of the record, in bits.
180  ///
181  /// \param Alignment The final alignment of the record, in bits.
182  ///
183  /// \param FieldOffsets The offset of each of the fields within the record,
184  /// expressed in bits. All of the fields must be provided with offsets.
185  ///
186  /// \param BaseOffsets The offset of each of the direct, non-virtual base
187  /// classes. If any bases are not given offsets, the bases will be laid
188  /// out according to the ABI.
189  ///
190  /// \param VirtualBaseOffsets The offset of each of the virtual base classes
191  /// (either direct or not). If any bases are not given offsets, the bases will
192  /// be laid out according to the ABI.
193  ///
194  /// \returns true if the record layout was provided, false otherwise.
195  bool
196  layoutRecordType(const RecordDecl *Record,
197  uint64_t &Size, uint64_t &Alignment,
198  llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
199  llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
200  llvm::DenseMap<const CXXRecordDecl *,
201  CharUnits> &VirtualBaseOffsets) override;
202 
203  /// Return the amount of memory used by memory buffers, breaking down
204  /// by heap-backed versus mmap'ed memory.
205  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
206 
207  //===--------------------------------------------------------------------===//
208  // ExternalSemaSource.
209  //===--------------------------------------------------------------------===//
210 
211  /// \brief Initialize the semantic source with the Sema instance
212  /// being used to perform semantic analysis on the abstract syntax
213  /// tree.
214  void InitializeSema(Sema &S) override;
215 
216  /// \brief Inform the semantic consumer that Sema is no longer available.
217  void ForgetSema() override;
218 
219  /// \brief Load the contents of the global method pool for a given
220  /// selector.
221  void ReadMethodPool(Selector Sel) override;
222 
223  /// \brief Load the set of namespaces that are known to the external source,
224  /// which will be used during typo correction.
225  void
227 
228  /// \brief Load the set of used but not defined functions or variables with
229  /// internal linkage, or used but not defined inline functions.
231  llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined) override;
232 
233  void ReadMismatchingDeleteExpressions(llvm::MapVector<
234  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
235  Exprs) override;
236 
237  /// \brief Do last resort, unqualified lookup on a LookupResult that
238  /// Sema cannot find.
239  ///
240  /// \param R a LookupResult that is being recovered.
241  ///
242  /// \param S the Scope of the identifier occurrence.
243  ///
244  /// \return true to tell Sema to recover using the LookupResult.
245  bool LookupUnqualified(LookupResult &R, Scope *S) override;
246 
247  /// \brief Read the set of tentative definitions known to the external Sema
248  /// source.
249  ///
250  /// The external source should append its own tentative definitions to the
251  /// given vector of tentative definitions. Note that this routine may be
252  /// invoked multiple times; the external source should take care not to
253  /// introduce the same declarations repeatedly.
255 
256  /// \brief Read the set of unused file-scope declarations known to the
257  /// external Sema source.
258  ///
259  /// The external source should append its own unused, filed-scope to the
260  /// given vector of declarations. Note that this routine may be
261  /// invoked multiple times; the external source should take care not to
262  /// introduce the same declarations repeatedly.
265 
266  /// \brief Read the set of delegating constructors known to the
267  /// external Sema source.
268  ///
269  /// The external source should append its own delegating constructors to the
270  /// given vector of declarations. Note that this routine may be
271  /// invoked multiple times; the external source should take care not to
272  /// introduce the same declarations repeatedly.
274  SmallVectorImpl<CXXConstructorDecl*> &Decls) override;
275 
276  /// \brief Read the set of ext_vector type declarations known to the
277  /// external Sema source.
278  ///
279  /// The external source should append its own ext_vector type declarations to
280  /// the given vector of declarations. Note that this routine may be
281  /// invoked multiple times; the external source should take care not to
282  /// introduce the same declarations repeatedly.
284 
285  /// \brief Read the set of potentially unused typedefs known to the source.
286  ///
287  /// The external source should append its own potentially unused local
288  /// typedefs to the given vector of declarations. Note that this routine may
289  /// be invoked multiple times; the external source should take care not to
290  /// introduce the same declarations repeatedly.
293 
294  /// \brief Read the set of referenced selectors known to the
295  /// external Sema source.
296  ///
297  /// The external source should append its own referenced selectors to the
298  /// given vector of selectors. Note that this routine
299  /// may be invoked multiple times; the external source should take care not
300  /// to introduce the same selectors repeatedly.
302  SourceLocation> > &Sels) override;
303 
304  /// \brief Read the set of weak, undeclared identifiers known to the
305  /// external Sema source.
306  ///
307  /// The external source should append its own weak, undeclared identifiers to
308  /// the given vector. Note that this routine may be invoked multiple times;
309  /// the external source should take care not to introduce the same identifiers
310  /// repeatedly.
312  SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
313 
314  /// \brief Read the set of used vtables known to the external Sema source.
315  ///
316  /// The external source should append its own used vtables to the given
317  /// vector. Note that this routine may be invoked multiple times; the external
318  /// source should take care not to introduce the same vtables repeatedly.
319  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
320 
321  /// \brief Read the set of pending instantiations known to the external
322  /// Sema source.
323  ///
324  /// The external source should append its own pending instantiations to the
325  /// given vector. Note that this routine may be invoked multiple times; the
326  /// external source should take care not to introduce the same instantiations
327  /// repeatedly.
329  SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
330 
331  /// \brief Read the set of late parsed template functions for this source.
332  ///
333  /// The external source should insert its own late parsed template functions
334  /// into the map. Note that this routine may be invoked multiple times; the
335  /// external source should take care not to introduce the same map entries
336  /// repeatedly.
338  llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap)
339  override;
340 
341  /// \copydoc ExternalSemaSource::CorrectTypo
342  /// \note Returns the first nonempty correction.
344  int LookupKind, Scope *S, CXXScopeSpec *SS,
346  DeclContext *MemberContext,
347  bool EnteringContext,
348  const ObjCObjectPointerType *OPT) override;
349 
350  /// \brief Produces a diagnostic note if one of the attached sources
351  /// contains a complete definition for \p T. Queries the sources in list
352  /// order until the first one claims that a diagnostic was produced.
353  ///
354  /// \param Loc the location at which a complete type was required but not
355  /// provided
356  ///
357  /// \param T the \c QualType that should have been complete at \p Loc
358  ///
359  /// \return true if a diagnostic was produced, false otherwise.
361  QualType T) override;
362 
363  // isa/cast/dyn_cast support
364  static bool classof(const MultiplexExternalSemaSource*) { return true; }
365  //static bool classof(const ExternalSemaSource*) { return true; }
366 };
367 
368 } // end namespace clang
369 
370 #endif
Smart pointer class that efficiently represents Objective-C method names.
Simple class containing the result of Sema::CorrectTypo.
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
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 ...
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: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:43
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.
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:68
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:851
ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
An abstract interface that should be implemented by external AST sources that also provide informatio...
ExternalLoadResult
Enumeration describing the result of loading information from an external 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. Length can be 0 to indicate a ...
void FinishedDeserializing() override
Notify ExternalASTSource that we finished the deserialization of a decl or type. Must be paired with ...
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.
static bool classof(const MultiplexExternalSemaSource *)
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.
ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, bool(*isKindWeWant)(Decl::Kind), SmallVectorImpl< Decl * > &Result) override
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2694
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)
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...
StringRef Typo
void ReadUndefinedButUsed(llvm::DenseMap< 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 C++ base or member initializer.
Definition: DeclCXX.h:1901
void addSource(ExternalSemaSource &source)
Appends new source to the source list.
Represents a base class of a C++ class.
Definition: DeclCXX.h:157
void ReadComments() override
Loads comment ranges.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
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:76
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.