clang 19.0.0git
ExternalSemaSource.h
Go to the documentation of this file.
1//===--- ExternalSemaSource.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 the ExternalSemaSource interface.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
13#define LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
14
16#include "clang/AST/Type.h"
18#include "clang/Sema/Weak.h"
19#include "llvm/ADT/MapVector.h"
20#include <utility>
21
22namespace llvm {
23template <class T, unsigned n> class SmallSetVector;
24}
25
26namespace clang {
27
28class CXXConstructorDecl;
29class CXXRecordDecl;
30class DeclaratorDecl;
31class LookupResult;
32class Scope;
33class Sema;
34class TypedefNameDecl;
35class ValueDecl;
36class VarDecl;
37struct LateParsedTemplate;
38
39/// A simple structure that captures a vtable use for the purposes of
40/// the \c ExternalSemaSource.
45};
46
47/// An abstract interface that should be implemented by
48/// external AST sources that also provide information for semantic
49/// analysis.
51 /// LLVM-style RTTI.
52 static char ID;
53
54public:
55 ExternalSemaSource() = default;
56
57 ~ExternalSemaSource() override;
58
59 /// Initialize the semantic source with the Sema instance
60 /// being used to perform semantic analysis on the abstract syntax
61 /// tree.
62 virtual void InitializeSema(Sema &S) {}
63
64 /// Inform the semantic consumer that Sema is no longer available.
65 virtual void ForgetSema() {}
66
67 /// Load the contents of the global method pool for a given
68 /// selector.
69 virtual void ReadMethodPool(Selector Sel);
70
71 /// Load the contents of the global method pool for a given
72 /// selector if necessary.
73 virtual void updateOutOfDateSelector(Selector Sel);
74
75 /// Load the set of namespaces that are known to the external source,
76 /// which will be used during typo correction.
77 virtual void ReadKnownNamespaces(
79
80 /// Load the set of used but not defined functions or variables with
81 /// internal linkage, or used but not defined internal functions.
82 virtual void
83 ReadUndefinedButUsed(llvm::MapVector<NamedDecl *, SourceLocation> &Undefined);
84
85 virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
86 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &);
87
88 /// Do last resort, unqualified lookup on a LookupResult that
89 /// Sema cannot find.
90 ///
91 /// \param R a LookupResult that is being recovered.
92 ///
93 /// \param S the Scope of the identifier occurrence.
94 ///
95 /// \return true to tell Sema to recover using the LookupResult.
96 virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
97
98 /// Read the set of tentative definitions known to the external Sema
99 /// source.
100 ///
101 /// The external source should append its own tentative definitions to the
102 /// given vector of tentative definitions. Note that this routine may be
103 /// invoked multiple times; the external source should take care not to
104 /// introduce the same declarations repeatedly.
106 SmallVectorImpl<VarDecl *> &TentativeDefs) {}
107
108 /// Read the set of unused file-scope declarations known to the
109 /// external Sema source.
110 ///
111 /// The external source should append its own unused, filed-scope to the
112 /// given vector of declarations. Note that this routine may be
113 /// invoked multiple times; the external source should take care not to
114 /// introduce the same declarations repeatedly.
117
118 /// Read the set of delegating constructors known to the
119 /// external Sema source.
120 ///
121 /// The external source should append its own delegating constructors to the
122 /// given vector of declarations. Note that this routine may be
123 /// invoked multiple times; the external source should take care not to
124 /// introduce the same declarations repeatedly.
127
128 /// Read the set of ext_vector type declarations known to the
129 /// external Sema source.
130 ///
131 /// The external source should append its own ext_vector type declarations to
132 /// the given vector of declarations. Note that this routine may be
133 /// invoked multiple times; the external source should take care not to
134 /// introduce the same declarations repeatedly.
136
137 /// Read the set of potentially unused typedefs known to the source.
138 ///
139 /// The external source should append its own potentially unused local
140 /// typedefs to the given vector of declarations. Note that this routine may
141 /// be invoked multiple times; the external source should take care not to
142 /// introduce the same declarations repeatedly.
145
146 /// Read the set of referenced selectors known to the
147 /// external Sema source.
148 ///
149 /// The external source should append its own referenced selectors to the
150 /// given vector of selectors. Note that this routine
151 /// may be invoked multiple times; the external source should take care not
152 /// to introduce the same selectors repeatedly.
154 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
155
156 /// Read the set of weak, undeclared identifiers known to the
157 /// external Sema source.
158 ///
159 /// The external source should append its own weak, undeclared identifiers to
160 /// the given vector. Note that this routine may be invoked multiple times;
161 /// the external source should take care not to introduce the same identifiers
162 /// repeatedly.
164 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
165
166 /// Read the set of used vtables known to the external Sema source.
167 ///
168 /// The external source should append its own used vtables to the given
169 /// vector. Note that this routine may be invoked multiple times; the external
170 /// source should take care not to introduce the same vtables repeatedly.
172
173 /// Read the set of pending instantiations known to the external
174 /// Sema source.
175 ///
176 /// The external source should append its own pending instantiations to the
177 /// given vector. Note that this routine may be invoked multiple times; the
178 /// external source should take care not to introduce the same instantiations
179 /// repeatedly.
181 SmallVectorImpl<std::pair<ValueDecl *,
182 SourceLocation> > &Pending) {}
183
184 /// Read the set of late parsed template functions for this source.
185 ///
186 /// The external source should insert its own late parsed template functions
187 /// into the map. Note that this routine may be invoked multiple times; the
188 /// external source should take care not to introduce the same map entries
189 /// repeatedly.
191 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
192 &LPTMap) {}
193
194 /// Read the set of decls to be checked for deferred diags.
195 ///
196 /// The external source should append its own potentially emitted function
197 /// and variable decls which may cause deferred diags. Note that this routine
198 /// may be invoked multiple times; the external source should take care not to
199 /// introduce the same declarations repeatedly.
200 virtual void
202
203 /// \copydoc Sema::CorrectTypo
204 /// \note LookupKind must correspond to a valid Sema::LookupNameKind
205 ///
206 /// ExternalSemaSource::CorrectTypo is always given the first chance to
207 /// correct a typo (really, to offer suggestions to repair a failed lookup).
208 /// It will even be called when SpellChecking is turned off or after a
209 /// fatal error has already been detected.
211 int LookupKind, Scope *S, CXXScopeSpec *SS,
213 DeclContext *MemberContext,
214 bool EnteringContext,
215 const ObjCObjectPointerType *OPT) {
216 return TypoCorrection();
217 }
218
219 /// Produces a diagnostic note if the external source contains a
220 /// complete definition for \p T.
221 ///
222 /// \param Loc the location at which a complete type was required but not
223 /// provided
224 ///
225 /// \param T the \c QualType that should have been complete at \p Loc
226 ///
227 /// \return true if a diagnostic was produced, false otherwise.
229 QualType T) {
230 return false;
231 }
232
233 /// Notify the external source that a lambda was assigned a mangling number.
234 /// This enables the external source to track the correspondence between
235 /// lambdas and mangling numbers if necessary.
236 virtual void AssignedLambdaNumbering(const CXXRecordDecl *Lambda) {}
237
238 /// LLVM-style RTTI.
239 /// \{
240 bool isA(const void *ClassID) const override {
241 return ClassID == &ID || ExternalASTSource::isA(ClassID);
242 }
243 static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
244 /// \}
245};
246
247} // end namespace clang
248
249#endif
C Language Family Type Representation.
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
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:1446
Abstract interface for external sources of AST nodes.
virtual bool isA(const void *ClassID) const
LLVM-style RTTI.
An abstract interface that should be implemented by external AST sources that also provide informatio...
virtual void updateOutOfDateSelector(Selector Sel)
Load the contents of the global method pool for a given selector if necessary.
Definition: Sema.cpp:2446
virtual void ReadMethodPool(Selector Sel)
Load the contents of the global method pool for a given selector.
Definition: Sema.cpp:2445
virtual void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined)
Load the set of used but not defined functions or variables with internal linkage,...
Definition: Sema.cpp:2452
virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, int LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, DeclContext *MemberContext, bool EnteringContext, const ObjCObjectPointerType *OPT)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
virtual void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &TentativeDefs)
Read the set of tentative definitions known to the external Sema source.
virtual void InitializeSema(Sema &S)
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
virtual void AssignedLambdaNumbering(const CXXRecordDecl *Lambda)
Notify the external source that a lambda was assigned a mangling number.
bool isA(const void *ClassID) const override
LLVM-style RTTI.
virtual void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables)
Read the set of used vtables known to the external Sema source.
~ExternalSemaSource() override
Definition: Sema.cpp:2442
virtual void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls)
Read the set of unused file-scope declarations known to the external Sema source.
static bool classof(const ExternalASTSource *S)
virtual bool LookupUnqualified(LookupResult &R, Scope *S)
Do last resort, unqualified lookup on a LookupResult that Sema cannot find.
virtual void ReadKnownNamespaces(SmallVectorImpl< NamespaceDecl * > &Namespaces)
Load the set of namespaces that are known to the external source, which will be used during typo corr...
Definition: Sema.cpp:2448
virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T)
Produces a diagnostic note if the external source contains a complete definition for T.
virtual void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI)
Read the set of weak, undeclared identifiers known to the external Sema source.
virtual void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > &LPTMap)
Read the set of late parsed template functions for this source.
virtual void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls)
Read the set of ext_vector type declarations known to the external Sema source.
virtual void ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector< Decl *, 4 > &Decls)
Read the set of decls to be checked for deferred diags.
virtual void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls)
Read the set of potentially unused typedefs known to the source.
virtual void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls)
Read the set of delegating constructors known to the external Sema source.
virtual void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &)
Definition: Sema.cpp:2455
virtual void ForgetSema()
Inform the semantic consumer that Sema is no longer available.
virtual void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending)
Read the set of pending instantiations known to the external Sema source.
virtual void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels)
Read the set of referenced selectors known to the external Sema source.
Represents a member of a struct/union/class.
Definition: Decl.h:3025
Represents a function declaration or definition.
Definition: Decl.h:1959
Represents the results of name lookup.
Definition: Lookup.h:46
Represents a pointer to an Objective C object.
Definition: Type.h:6768
A (possibly-)qualified type.
Definition: Type.h:738
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:426
Encodes a location in the source.
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:706
The JSON file list parser is used to communicate input to InstallAPI.
YAML serialization mapping.
Definition: Dominators.h:30
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.