clang 20.0.0git
MultiplexExternalSemaSource.h
Go to the documentation of this file.
1//===--- MultiplexExternalSemaSource.h - External Sema Interface-*- C++ -*-===//
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 defines ExternalSemaSource interface, dispatching to all clients
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
13#define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
14
16#include "clang/Sema/Weak.h"
17#include "llvm/ADT/SmallVector.h"
18#include <utility>
19
20namespace clang {
21
22 class CXXConstructorDecl;
23 class CXXRecordDecl;
24 class DeclaratorDecl;
25 struct ExternalVTableUse;
26 class LookupResult;
27 class NamespaceDecl;
28 class Scope;
29 class Sema;
30 class TypedefNameDecl;
31 class ValueDecl;
32 class VarDecl;
33
34
35/// An abstract interface that should be implemented by
36/// external AST sources that also provide information for semantic
37/// analysis.
39 /// LLVM-style RTTI.
40 static char ID;
41
42private:
44
45public:
46 /// 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 /// 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 /// Resolve a declaration ID into a declaration, potentially
67 /// building a new declaration.
68 Decl *GetExternalDecl(GlobalDeclID ID) override;
69
70 /// 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 /// Resolve a selector ID into a selector.
75 Selector GetExternalSelector(uint32_t ID) override;
76
77 /// Returns the number of selectors known to the external AST
78 /// source.
79 uint32_t GetNumExternalSelectors() override;
80
81 /// Resolve the offset of a statement in the decl stream into
82 /// a statement.
83 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
84
85 /// 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 /// 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 ExtKind hasExternalDefinitions(const Decl *D) override;
94
95 /// Find all declarations with the given name in the
96 /// given context.
98 DeclarationName Name) override;
99
100 bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
101
102 bool
104 ArrayRef<TemplateArgument> TemplateArgs) override;
105
106 /// Ensures that the table of all visible declarations inside this
107 /// context is up to date.
108 void completeVisibleDeclsMap(const DeclContext *DC) override;
109
110 /// Finds all declarations lexically contained within the given
111 /// DeclContext, after applying an optional filter predicate.
112 ///
113 /// \param IsKindWeWant a predicate function that returns true if the passed
114 /// declaration kind is one we are looking for.
115 void
117 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
119
120 /// Get the decls that are contained in a file in the Offset/Length
121 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
122 /// a range.
123 void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
124 SmallVectorImpl<Decl *> &Decls) override;
125
126 /// Gives the external AST source an opportunity to complete
127 /// an incomplete type.
128 void CompleteType(TagDecl *Tag) override;
129
130 /// Gives the external AST source an opportunity to complete an
131 /// incomplete Objective-C class.
132 ///
133 /// This routine will only be invoked if the "externally completed" bit is
134 /// set on the ObjCInterfaceDecl via the function
135 /// \c ObjCInterfaceDecl::setExternallyCompleted().
136 void CompleteType(ObjCInterfaceDecl *Class) override;
137
138 /// Loads comment ranges.
139 void ReadComments() override;
140
141 /// Notify ExternalASTSource that we started deserialization of
142 /// a decl or type so until FinishedDeserializing is called there may be
143 /// decls that are initializing. Must be paired with FinishedDeserializing.
144 void StartedDeserializing() override;
145
146 /// Notify ExternalASTSource that we finished the deserialization of
147 /// a decl or type. Must be paired with StartedDeserializing.
148 void FinishedDeserializing() override;
149
150 /// Function that will be invoked when we begin parsing a new
151 /// translation unit involving this external AST source.
152 void StartTranslationUnit(ASTConsumer *Consumer) override;
153
154 /// Print any statistics that have been gathered regarding
155 /// the external AST source.
156 void PrintStats() override;
157
158 /// Retrieve the module that corresponds to the given module ID.
159 Module *getModule(unsigned ID) override;
160
161 /// Perform layout on the given record.
162 ///
163 /// This routine allows the external AST source to provide an specific
164 /// layout for a record, overriding the layout that would normally be
165 /// constructed. It is intended for clients who receive specific layout
166 /// details rather than source code (such as LLDB). The client is expected
167 /// to fill in the field offsets, base offsets, virtual base offsets, and
168 /// complete object size.
169 ///
170 /// \param Record The record whose layout is being requested.
171 ///
172 /// \param Size The final size of the record, in bits.
173 ///
174 /// \param Alignment The final alignment of the record, in bits.
175 ///
176 /// \param FieldOffsets The offset of each of the fields within the record,
177 /// expressed in bits. All of the fields must be provided with offsets.
178 ///
179 /// \param BaseOffsets The offset of each of the direct, non-virtual base
180 /// classes. If any bases are not given offsets, the bases will be laid
181 /// out according to the ABI.
182 ///
183 /// \param VirtualBaseOffsets The offset of each of the virtual base classes
184 /// (either direct or not). If any bases are not given offsets, the bases will
185 /// be laid out according to the ABI.
186 ///
187 /// \returns true if the record layout was provided, false otherwise.
188 bool
190 uint64_t &Size, uint64_t &Alignment,
191 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
192 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
193 llvm::DenseMap<const CXXRecordDecl *,
194 CharUnits> &VirtualBaseOffsets) override;
195
196 /// Return the amount of memory used by memory buffers, breaking down
197 /// by heap-backed versus mmap'ed memory.
198 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
199
200 //===--------------------------------------------------------------------===//
201 // ExternalSemaSource.
202 //===--------------------------------------------------------------------===//
203
204 /// Initialize the semantic source with the Sema instance
205 /// being used to perform semantic analysis on the abstract syntax
206 /// tree.
207 void InitializeSema(Sema &S) override;
208
209 /// Inform the semantic consumer that Sema is no longer available.
210 void ForgetSema() override;
211
212 /// Load the contents of the global method pool for a given
213 /// selector.
214 void ReadMethodPool(Selector Sel) override;
215
216 /// Load the contents of the global method pool for a given
217 /// selector if necessary.
218 void updateOutOfDateSelector(Selector Sel) override;
219
220 /// Load the set of namespaces that are known to the external source,
221 /// which will be used during typo correction.
222 void
224
225 /// Load the set of used but not defined functions or variables with
226 /// internal linkage, or used but not defined inline functions.
228 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
229
230 void ReadMismatchingDeleteExpressions(llvm::MapVector<
231 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
232 Exprs) override;
233
234 /// Do last resort, unqualified lookup on a LookupResult that
235 /// Sema cannot find.
236 ///
237 /// \param R a LookupResult that is being recovered.
238 ///
239 /// \param S the Scope of the identifier occurrence.
240 ///
241 /// \return true to tell Sema to recover using the LookupResult.
242 bool LookupUnqualified(LookupResult &R, Scope *S) override;
243
244 /// Read the set of tentative definitions known to the external Sema
245 /// source.
246 ///
247 /// The external source should append its own tentative definitions to the
248 /// given vector of tentative definitions. Note that this routine may be
249 /// invoked multiple times; the external source should take care not to
250 /// introduce the same declarations repeatedly.
252
253 /// Read the set of unused file-scope declarations known to the
254 /// external Sema source.
255 ///
256 /// The external source should append its own unused, filed-scope to the
257 /// given vector of declarations. Note that this routine may be
258 /// invoked multiple times; the external source should take care not to
259 /// introduce the same declarations repeatedly.
262
263 /// Read the set of delegating constructors known to the
264 /// external Sema source.
265 ///
266 /// The external source should append its own delegating constructors to the
267 /// given vector of declarations. Note that this routine may be
268 /// invoked multiple times; the external source should take care not to
269 /// introduce the same declarations repeatedly.
272
273 /// Read the set of ext_vector type declarations known to the
274 /// external Sema source.
275 ///
276 /// The external source should append its own ext_vector type declarations to
277 /// the given vector of declarations. Note that this routine may be
278 /// invoked multiple times; the external source should take care not to
279 /// introduce the same declarations repeatedly.
281
282 /// Read the set of potentially unused typedefs known to the source.
283 ///
284 /// The external source should append its own potentially unused local
285 /// typedefs to the given vector of declarations. Note that this routine may
286 /// be invoked multiple times; the external source should take care not to
287 /// introduce the same declarations repeatedly.
290
291 /// Read the set of referenced selectors known to the
292 /// external Sema source.
293 ///
294 /// The external source should append its own referenced selectors to the
295 /// given vector of selectors. Note that this routine
296 /// may be invoked multiple times; the external source should take care not
297 /// to introduce the same selectors repeatedly.
299 SourceLocation> > &Sels) override;
300
301 /// Read the set of weak, undeclared identifiers known to the
302 /// external Sema source.
303 ///
304 /// The external source should append its own weak, undeclared identifiers to
305 /// the given vector. Note that this routine may be invoked multiple times;
306 /// the external source should take care not to introduce the same identifiers
307 /// repeatedly.
309 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
310
311 /// Read the set of used vtables known to the external Sema source.
312 ///
313 /// The external source should append its own used vtables to the given
314 /// vector. Note that this routine may be invoked multiple times; the external
315 /// source should take care not to introduce the same vtables repeatedly.
317
318 /// Read the set of pending instantiations known to the external
319 /// Sema source.
320 ///
321 /// The external source should append its own pending instantiations to the
322 /// given vector. Note that this routine may be invoked multiple times; the
323 /// external source should take care not to introduce the same instantiations
324 /// repeatedly.
326 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
327
328 /// Read the set of late parsed template functions for this source.
329 ///
330 /// The external source should insert its own late parsed template functions
331 /// into the map. Note that this routine may be invoked multiple times; the
332 /// external source should take care not to introduce the same map entries
333 /// repeatedly.
335 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
336 &LPTMap) override;
337
338 /// Read the set of decls to be checked for deferred diags.
339 ///
340 /// The external source should append its own potentially emitted function
341 /// and variable decls which may cause deferred diags. Note that this routine
342 /// may be invoked multiple times; the external source should take care not to
343 /// introduce the same declarations repeatedly.
345 llvm::SmallSetVector<Decl *, 4> &Decls) override;
346
347 /// \copydoc ExternalSemaSource::CorrectTypo
348 /// \note Returns the first nonempty correction.
350 int LookupKind, Scope *S, CXXScopeSpec *SS,
352 DeclContext *MemberContext,
353 bool EnteringContext,
354 const ObjCObjectPointerType *OPT) override;
355
356 /// Produces a diagnostic note if one of the attached sources
357 /// contains a complete definition for \p T. Queries the sources in list
358 /// order until the first one claims that a diagnostic was produced.
359 ///
360 /// \param Loc the location at which a complete type was required but not
361 /// provided
362 ///
363 /// \param T the \c QualType that should have been complete at \p Loc
364 ///
365 /// \return true if a diagnostic was produced, false otherwise.
367 QualType T) override;
368
369 // Inform all attached sources that a mangling number was assigned.
370 void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override;
371
372 /// LLVM-style RTTI.
373 /// \{
374 bool isA(const void *ClassID) const override {
375 return ClassID == &ID || ExternalSemaSource::isA(ClassID);
376 }
377 static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
378 /// \}
379};
380
381} // end namespace clang
382
383#endif
const Decl * D
llvm::MachO::Record Record
Definition: MachO.h:31
SourceLocation Loc
Definition: SemaObjC.cpp:759
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:34
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2318
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
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:1435
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.
Abstract interface for external sources of AST nodes.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
An abstract interface that should be implemented by external AST sources that also provide informatio...
bool isA(const void *ClassID) const override
LLVM-style RTTI.
Represents a member of a struct/union/class.
Definition: Decl.h:3033
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:1935
Represents the results of name lookup.
Definition: Lookup.h:46
Describes a module or submodule.
Definition: Module.h:115
An abstract interface that should be implemented by external AST sources that also provide informatio...
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > &LPTMap) override
Read the set of late parsed template functions for this 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.
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.
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.
static bool classof(const ExternalASTSource *S)
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI) override
Read the set of weak, undeclared identifiers known to the 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.
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override
Find all declarations with the given name in the given context.
bool isA(const void *ClassID) const override
LLVM-style RTTI.
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.
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 AddSource(ExternalSemaSource *Source)
Appends new source to the source list.
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
Represents a pointer to an Objective C object.
Definition: Type.h:7580
A (possibly-)qualified type.
Definition: Type.h:929
Represents a struct/union/class.
Definition: Decl.h:4148
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.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:463
Encodes a location in the source.
Stmt - This represents one statement.
Definition: Stmt.h:84
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3564
Simple class containing the result of Sema::CorrectTypo.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...