clang 22.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
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 ///
54
55 /// Appends new source to the source list.
56 ///
57 ///\param[in] Source - An ExternalSemaSource.
58 ///
60
61 //===--------------------------------------------------------------------===//
62 // ExternalASTSource.
63 //===--------------------------------------------------------------------===//
64
65 /// Resolve a declaration ID into a declaration, potentially
66 /// building a new declaration.
67 Decl *GetExternalDecl(GlobalDeclID ID) override;
68
69 /// Complete the redeclaration chain if it's been extended since the
70 /// previous generation of the AST source.
71 void CompleteRedeclChain(const Decl *D) override;
72
73 /// Resolve a selector ID into a selector.
74 Selector GetExternalSelector(uint32_t ID) override;
75
76 /// Returns the number of selectors known to the external AST
77 /// source.
78 uint32_t GetNumExternalSelectors() override;
79
80 /// Resolve the offset of a statement in the decl stream into
81 /// a statement.
82 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
83
84 /// Resolve the offset of a set of C++ base specifiers in the decl
85 /// stream into an array of specifiers.
86 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
87
88 /// Resolve a handle to a list of ctor initializers into the list of
89 /// initializers themselves.
90 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
91
92 ExtKind hasExternalDefinitions(const Decl *D) override;
93
94 bool wasThisDeclarationADefinition(const FunctionDecl *FD) override;
95
96 /// Find all declarations with the given name in the
97 /// given context.
99 DeclarationName Name,
100 const DeclContext *OriginalDC) override;
101
102 bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
103
104 bool
106 ArrayRef<TemplateArgument> TemplateArgs) override;
107
108 /// Ensures that the table of all visible declarations inside this
109 /// context is up to date.
110 void completeVisibleDeclsMap(const DeclContext *DC) override;
111
112 /// Finds all declarations lexically contained within the given
113 /// DeclContext, after applying an optional filter predicate.
114 ///
115 /// \param IsKindWeWant a predicate function that returns true if the passed
116 /// declaration kind is one we are looking for.
117 void
119 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
121
122 /// Get the decls that are contained in a file in the Offset/Length
123 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
124 /// a range.
125 void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
126 SmallVectorImpl<Decl *> &Decls) override;
127
128 /// Gives the external AST source an opportunity to complete
129 /// an incomplete type.
130 void CompleteType(TagDecl *Tag) override;
131
132 /// Gives the external AST source an opportunity to complete an
133 /// incomplete Objective-C class.
134 ///
135 /// This routine will only be invoked if the "externally completed" bit is
136 /// set on the ObjCInterfaceDecl via the function
137 /// \c ObjCInterfaceDecl::setExternallyCompleted().
138 void CompleteType(ObjCInterfaceDecl *Class) override;
139
140 /// Loads comment ranges.
141 void ReadComments() override;
142
143 /// Notify ExternalASTSource that we started deserialization of
144 /// a decl or type so until FinishedDeserializing is called there may be
145 /// decls that are initializing. Must be paired with FinishedDeserializing.
146 void StartedDeserializing() override;
147
148 /// Notify ExternalASTSource that we finished the deserialization of
149 /// a decl or type. Must be paired with StartedDeserializing.
150 void FinishedDeserializing() override;
151
152 /// Function that will be invoked when we begin parsing a new
153 /// translation unit involving this external AST source.
154 void StartTranslationUnit(ASTConsumer *Consumer) override;
155
156 /// Print any statistics that have been gathered regarding
157 /// the external AST source.
158 void PrintStats() override;
159
160 /// Retrieve the module that corresponds to the given module ID.
161 Module *getModule(unsigned ID) override;
162
163 /// Perform layout on the given record.
164 ///
165 /// This routine allows the external AST source to provide an specific
166 /// layout for a record, overriding the layout that would normally be
167 /// constructed. It is intended for clients who receive specific layout
168 /// details rather than source code (such as LLDB). The client is expected
169 /// to fill in the field offsets, base offsets, virtual base offsets, and
170 /// complete object size.
171 ///
172 /// \param Record The record whose layout is being requested.
173 ///
174 /// \param Size The final size of the record, in bits.
175 ///
176 /// \param Alignment The final alignment of the record, in bits.
177 ///
178 /// \param FieldOffsets The offset of each of the fields within the record,
179 /// expressed in bits. All of the fields must be provided with offsets.
180 ///
181 /// \param BaseOffsets The offset of each of the direct, non-virtual base
182 /// classes. If any bases are not given offsets, the bases will be laid
183 /// out according to the ABI.
184 ///
185 /// \param VirtualBaseOffsets The offset of each of the virtual base classes
186 /// (either direct or not). If any bases are not given offsets, the bases will
187 /// be laid out according to the ABI.
188 ///
189 /// \returns true if the record layout was provided, false otherwise.
190 bool
192 uint64_t &Size, uint64_t &Alignment,
193 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
194 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
195 llvm::DenseMap<const CXXRecordDecl *,
196 CharUnits> &VirtualBaseOffsets) override;
197
198 /// Return the amount of memory used by memory buffers, breaking down
199 /// by heap-backed versus mmap'ed memory.
200 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
201
202 //===--------------------------------------------------------------------===//
203 // ExternalSemaSource.
204 //===--------------------------------------------------------------------===//
205
206 /// Initialize the semantic source with the Sema instance
207 /// being used to perform semantic analysis on the abstract syntax
208 /// tree.
209 void InitializeSema(Sema &S) override;
210
211 /// Inform the semantic consumer that Sema is no longer available.
212 void ForgetSema() override;
213
214 /// Load the contents of the global method pool for a given
215 /// selector.
216 void ReadMethodPool(Selector Sel) override;
217
218 /// Load the contents of the global method pool for a given
219 /// selector if necessary.
220 void updateOutOfDateSelector(Selector Sel) override;
221
222 /// Load the set of namespaces that are known to the external source,
223 /// which will be used during typo correction.
224 void
226
227 /// Load the set of used but not defined functions or variables with
228 /// internal linkage, or used but not defined inline functions.
230 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
231
232 void ReadMismatchingDeleteExpressions(llvm::MapVector<
233 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
234 Exprs) override;
235
236 /// Do last resort, unqualified lookup on a LookupResult that
237 /// Sema cannot find.
238 ///
239 /// \param R a LookupResult that is being recovered.
240 ///
241 /// \param S the Scope of the identifier occurrence.
242 ///
243 /// \return true to tell Sema to recover using the LookupResult.
244 bool LookupUnqualified(LookupResult &R, Scope *S) override;
245
246 /// Read the set of tentative definitions known to the external Sema
247 /// source.
248 ///
249 /// The external source should append its own tentative definitions to the
250 /// given vector of tentative definitions. Note that this routine may be
251 /// invoked multiple times; the external source should take care not to
252 /// introduce the same declarations repeatedly.
254
255 /// Read the set of unused file-scope declarations known to the
256 /// external Sema source.
257 ///
258 /// The external source should append its own unused, filed-scope to the
259 /// given vector of declarations. Note that this routine may be
260 /// invoked multiple times; the external source should take care not to
261 /// introduce the same declarations repeatedly.
264
265 /// Read the set of delegating constructors known to the
266 /// external Sema source.
267 ///
268 /// The external source should append its own delegating constructors to the
269 /// given vector of declarations. Note that this routine may be
270 /// invoked multiple times; the external source should take care not to
271 /// introduce the same declarations repeatedly.
274
275 /// Read the set of ext_vector type declarations known to the
276 /// external Sema source.
277 ///
278 /// The external source should append its own ext_vector type declarations to
279 /// the given vector of declarations. Note that this routine may be
280 /// invoked multiple times; the external source should take care not to
281 /// introduce the same declarations repeatedly.
283
284 /// Read the set of potentially unused typedefs known to the source.
285 ///
286 /// The external source should append its own potentially unused local
287 /// typedefs to the given vector of declarations. Note that this routine may
288 /// be invoked multiple times; the external source should take care not to
289 /// introduce the same declarations repeatedly.
292
293 /// Read the set of referenced selectors known to the
294 /// external Sema source.
295 ///
296 /// The external source should append its own referenced selectors to the
297 /// given vector of selectors. Note that this routine
298 /// may be invoked multiple times; the external source should take care not
299 /// to introduce the same selectors repeatedly.
301 SourceLocation> > &Sels) override;
302
303 /// Read the set of weak, undeclared identifiers known to the
304 /// external Sema source.
305 ///
306 /// The external source should append its own weak, undeclared identifiers to
307 /// the given vector. Note that this routine may be invoked multiple times;
308 /// the external source should take care not to introduce the same identifiers
309 /// repeatedly.
311 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
312
313 /// Read the set of used vtables known to the external Sema source.
314 ///
315 /// The external source should append its own used vtables to the given
316 /// vector. Note that this routine may be invoked multiple times; the external
317 /// source should take care not to introduce the same vtables repeatedly.
319
320 /// Read the set of pending instantiations known to the external
321 /// Sema source.
322 ///
323 /// The external source should append its own pending instantiations to the
324 /// given vector. Note that this routine may be invoked multiple times; the
325 /// external source should take care not to introduce the same instantiations
326 /// repeatedly.
328 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
329
330 /// Read the set of late parsed template functions for this source.
331 ///
332 /// The external source should insert its own late parsed template functions
333 /// into the map. Note that this routine may be invoked multiple times; the
334 /// external source should take care not to introduce the same map entries
335 /// repeatedly.
337 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
338 &LPTMap) override;
339
340 /// Read the set of decls to be checked for deferred diags.
341 ///
342 /// The external source should append its own potentially emitted function
343 /// and variable decls which may cause deferred diags. Note that this routine
344 /// may be invoked multiple times; the external source should take care not to
345 /// introduce the same declarations repeatedly.
347 llvm::SmallSetVector<Decl *, 4> &Decls) override;
348
349 /// \copydoc ExternalSemaSource::CorrectTypo
350 /// \note Returns the first nonempty correction.
352 int LookupKind, Scope *S, CXXScopeSpec *SS,
354 DeclContext *MemberContext,
355 bool EnteringContext,
356 const ObjCObjectPointerType *OPT) override;
357
358 /// Produces a diagnostic note if one of the attached sources
359 /// contains a complete definition for \p T. Queries the sources in list
360 /// order until the first one claims that a diagnostic was produced.
361 ///
362 /// \param Loc the location at which a complete type was required but not
363 /// provided
364 ///
365 /// \param T the \c QualType that should have been complete at \p Loc
366 ///
367 /// \return true if a diagnostic was produced, false otherwise.
369 QualType T) override;
370
371 // Inform all attached sources that a mangling number was assigned.
372 void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override;
373
374 /// LLVM-style RTTI.
375 /// \{
376 bool isA(const void *ClassID) const override {
377 return ClassID == &ID || ExternalSemaSource::isA(ClassID);
378 }
379 static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
380 /// \}
381};
382
383} // end namespace clang
384
385#endif
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:34
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a C++ base or member initializer.
Definition DeclCXX.h:2369
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:73
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:1449
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.
Represents a ValueDecl that came out of a declarator.
Definition Decl.h:779
Abstract interface for external sources of AST nodes.
virtual bool isA(const void *ClassID) const
LLVM-style RTTI.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
bool isA(const void *ClassID) const override
LLVM-style RTTI.
Represents a member of a struct/union/class.
Definition Decl.h:3157
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:1999
Represents the results of name lookup.
Definition Lookup.h:147
Describes a module or submodule.
Definition Module.h:144
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.
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.
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 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.
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...
MultiplexExternalSemaSource(llvm::IntrusiveRefCntPtr< ExternalSemaSource > S1, llvm::IntrusiveRefCntPtr< ExternalSemaSource > S2)
Constructs a new multiplexing external sema source and appends the given element to it.
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.
Represent a C++ namespace.
Definition Decl.h:591
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
Represents a pointer to an Objective C object.
Definition TypeBase.h:7903
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4309
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:854
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3714
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3559
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:711
Represents a variable declaration or definition.
Definition Decl.h:925
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
Definition TypeBase.h:905
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5874
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.