clang  16.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 
22 namespace llvm {
23 template <class T, unsigned n> class SmallSetVector;
24 }
25 
26 namespace clang {
27 
28 class CXXConstructorDecl;
29 class CXXRecordDecl;
30 class DeclaratorDecl;
31 class LookupResult;
32 class Scope;
33 class Sema;
34 class TypedefNameDecl;
35 class ValueDecl;
36 class VarDecl;
37 struct 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 
54 public:
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  /// LLVM-style RTTI.
234  /// \{
235  bool isA(const void *ClassID) const override {
236  return ClassID == &ID || ExternalASTSource::isA(ClassID);
237  }
238  static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
239  /// \}
240 };
241 
242 } // end namespace clang
243 
244 #endif
clang::ExternalSemaSource::updateOutOfDateSelector
virtual void updateOutOfDateSelector(Selector Sel)
Load the contents of the global method pool for a given selector if necessary.
Definition: Sema.cpp:2389
llvm
YAML serialization mapping.
Definition: Dominators.h:30
Weak.h
clang::ExternalSemaSource::ReadKnownNamespaces
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:2391
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1386
clang::TypoCorrection
Simple class containing the result of Sema::CorrectTypo.
Definition: TypoCorrection.h:42
clang::ExternalSemaSource::ReadDelegatingConstructors
virtual void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls)
Read the set of delegating constructors known to the external Sema source.
Definition: ExternalSemaSource.h:125
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::ExternalSemaSource::ReadUnusedLocalTypedefNameCandidates
virtual void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls)
Read the set of potentially unused typedefs known to the source.
Definition: ExternalSemaSource.h:143
clang::ExternalSemaSource::ReadMismatchingDeleteExpressions
virtual void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 >> &)
Definition: Sema.cpp:2398
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2891
clang::LookupResult
Represents the results of name lookup.
Definition: Lookup.h:46
TypoCorrection.h
clang::ExternalSemaSource::CorrectTypo
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...
Definition: ExternalSemaSource.h:210
clang::ExternalSemaSource::ReadUnusedFileScopedDecls
virtual void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls)
Read the set of unused file-scope declarations known to the external Sema source.
Definition: ExternalSemaSource.h:115
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:65
clang::ExternalVTableUse
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.
Definition: ExternalSemaSource.h:41
clang::ExternalSemaSource::ReadUsedVTables
virtual void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables)
Read the set of used vtables known to the external Sema source.
Definition: ExternalSemaSource.h:171
clang::ExternalSemaSource::~ExternalSemaSource
~ExternalSemaSource() override
Definition: Sema.cpp:2385
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::ExternalVTableUse::DefinitionRequired
bool DefinitionRequired
Definition: ExternalSemaSource.h:44
clang::ExternalSemaSource
An abstract interface that should be implemented by external AST sources that also provide informatio...
Definition: ExternalSemaSource.h:50
Type.h
clang::ExternalSemaSource::classof
static bool classof(const ExternalASTSource *S)
Definition: ExternalSemaSource.h:238
clang::ExternalSemaSource::ReadMethodPool
virtual void ReadMethodPool(Selector Sel)
Load the contents of the global method pool for a given selector.
Definition: Sema.cpp:2388
clang::ExternalASTSource::isA
virtual bool isA(const void *ClassID) const
LLVM-style RTTI.
Definition: ExternalASTSource.h:298
clang::ExternalVTableUse::Location
SourceLocation Location
Definition: ExternalSemaSource.h:43
ExternalASTSource.h
clang::ExternalSemaSource::ReadExtVectorDecls
virtual void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls)
Read the set of ext_vector type declarations known to the external Sema source.
Definition: ExternalSemaSource.h:135
clang::ExternalSemaSource::ReadUndefinedButUsed
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:2395
clang::ObjCObjectPointerType
Represents a pointer to an Objective C object.
Definition: Type.h:6268
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:674
clang::ExternalSemaSource::MaybeDiagnoseMissingCompleteType
virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T)
Produces a diagnostic note if the external source contains a complete definition for T.
Definition: ExternalSemaSource.h:228
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:358
clang::ExternalSemaSource::InitializeSema
virtual void InitializeSema(Sema &S)
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Definition: ExternalSemaSource.h:62
clang::ExternalVTableUse::Record
CXXRecordDecl * Record
Definition: ExternalSemaSource.h:42
clang::ExternalSemaSource::ReadLateParsedTemplates
virtual void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate >> &LPTMap)
Read the set of late parsed template functions for this source.
Definition: ExternalSemaSource.h:190
clang::ExternalSemaSource::ForgetSema
virtual void ForgetSema()
Inform the semantic consumer that Sema is no longer available.
Definition: ExternalSemaSource.h:65
clang
Definition: CalledOnceCheck.h:17
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:759
clang::CorrectionCandidateCallback
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
Definition: TypoCorrection.h:281
clang::ExternalSemaSource::ReadPendingInstantiations
virtual void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending)
Read the set of pending instantiations known to the external Sema source.
Definition: ExternalSemaSource.h:180
clang::ExternalSemaSource::LookupUnqualified
virtual bool LookupUnqualified(LookupResult &R, Scope *S)
Do last resort, unqualified lookup on a LookupResult that Sema cannot find.
Definition: ExternalSemaSource.h:96
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::ExternalSemaSource::isA
bool isA(const void *ClassID) const override
LLVM-style RTTI.
Definition: ExternalSemaSource.h:235
llvm::SmallSetVector
Definition: ExternalSemaSource.h:23
clang::ExternalSemaSource::ReadTentativeDefinitions
virtual void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &TentativeDefs)
Read the set of tentative definitions known to the external Sema source.
Definition: ExternalSemaSource.h:105
clang::ExternalASTSource
Abstract interface for external sources of AST nodes.
Definition: ExternalASTSource.h:60
clang::ExternalSemaSource::ReadReferencedSelectors
virtual void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels)
Read the set of referenced selectors known to the external Sema source.
Definition: ExternalSemaSource.h:153
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:767
clang::ExternalSemaSource::ExternalSemaSource
ExternalSemaSource()=default
clang::ExternalSemaSource::ReadDeclsToCheckForDeferredDiags
virtual void ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector< Decl *, 4 > &Decls)
Read the set of decls to be checked for deferred diags.
Definition: ExternalSemaSource.h:201
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1877
clang::ExternalSemaSource::ReadWeakUndeclaredIdentifiers
virtual void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI)
Read the set of weak, undeclared identifiers known to the external Sema source.
Definition: ExternalSemaSource.h:163