clang  12.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 CXXDeleteExpr;
30 class CXXRecordDecl;
31 class DeclaratorDecl;
32 class LookupResult;
33 struct ObjCMethodList;
34 class Scope;
35 class Sema;
36 class TypedefNameDecl;
37 class ValueDecl;
38 class VarDecl;
39 struct LateParsedTemplate;
40 
41 /// A simple structure that captures a vtable use for the purposes of
42 /// the \c ExternalSemaSource.
47 };
48 
49 /// An abstract interface that should be implemented by
50 /// external AST sources that also provide information for semantic
51 /// analysis.
53  /// LLVM-style RTTI.
54  static char ID;
55 
56 public:
57  ExternalSemaSource() = default;
58 
59  ~ExternalSemaSource() override;
60 
61  /// Initialize the semantic source with the Sema instance
62  /// being used to perform semantic analysis on the abstract syntax
63  /// tree.
64  virtual void InitializeSema(Sema &S) {}
65 
66  /// Inform the semantic consumer that Sema is no longer available.
67  virtual void ForgetSema() {}
68 
69  /// Load the contents of the global method pool for a given
70  /// selector.
71  virtual void ReadMethodPool(Selector Sel);
72 
73  /// Load the contents of the global method pool for a given
74  /// selector if necessary.
75  virtual void updateOutOfDateSelector(Selector Sel);
76 
77  /// Load the set of namespaces that are known to the external source,
78  /// which will be used during typo correction.
79  virtual void ReadKnownNamespaces(
81 
82  /// Load the set of used but not defined functions or variables with
83  /// internal linkage, or used but not defined internal functions.
84  virtual void
85  ReadUndefinedButUsed(llvm::MapVector<NamedDecl *, SourceLocation> &Undefined);
86 
87  virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
88  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &);
89 
90  /// Do last resort, unqualified lookup on a LookupResult that
91  /// Sema cannot find.
92  ///
93  /// \param R a LookupResult that is being recovered.
94  ///
95  /// \param S the Scope of the identifier occurrence.
96  ///
97  /// \return true to tell Sema to recover using the LookupResult.
98  virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
99 
100  /// Read the set of tentative definitions known to the external Sema
101  /// source.
102  ///
103  /// The external source should append its own tentative definitions to the
104  /// given vector of tentative definitions. Note that this routine may be
105  /// invoked multiple times; the external source should take care not to
106  /// introduce the same declarations repeatedly.
108  SmallVectorImpl<VarDecl *> &TentativeDefs) {}
109 
110  /// Read the set of unused file-scope declarations known to the
111  /// external Sema source.
112  ///
113  /// The external source should append its own unused, filed-scope to the
114  /// given vector of declarations. Note that this routine may be
115  /// invoked multiple times; the external source should take care not to
116  /// introduce the same declarations repeatedly.
119 
120  /// Read the set of delegating constructors known to the
121  /// external Sema source.
122  ///
123  /// The external source should append its own delegating constructors to the
124  /// given vector of declarations. Note that this routine may be
125  /// invoked multiple times; the external source should take care not to
126  /// introduce the same declarations repeatedly.
129 
130  /// Read the set of ext_vector type declarations known to the
131  /// external Sema source.
132  ///
133  /// The external source should append its own ext_vector type declarations to
134  /// the given vector of declarations. Note that this routine may be
135  /// invoked multiple times; the external source should take care not to
136  /// introduce the same declarations repeatedly.
138 
139  /// Read the set of potentially unused typedefs known to the source.
140  ///
141  /// The external source should append its own potentially unused local
142  /// typedefs to the given vector of declarations. Note that this routine may
143  /// be invoked multiple times; the external source should take care not to
144  /// introduce the same declarations repeatedly.
147 
148  /// Read the set of referenced selectors known to the
149  /// external Sema source.
150  ///
151  /// The external source should append its own referenced selectors to the
152  /// given vector of selectors. Note that this routine
153  /// may be invoked multiple times; the external source should take care not
154  /// to introduce the same selectors repeatedly.
156  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
157 
158  /// Read the set of weak, undeclared identifiers known to the
159  /// external Sema source.
160  ///
161  /// The external source should append its own weak, undeclared identifiers to
162  /// the given vector. Note that this routine may be invoked multiple times;
163  /// the external source should take care not to introduce the same identifiers
164  /// repeatedly.
166  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
167 
168  /// Read the set of used vtables known to the external Sema source.
169  ///
170  /// The external source should append its own used vtables to the given
171  /// vector. Note that this routine may be invoked multiple times; the external
172  /// source should take care not to introduce the same vtables repeatedly.
174 
175  /// Read the set of pending instantiations known to the external
176  /// Sema source.
177  ///
178  /// The external source should append its own pending instantiations to the
179  /// given vector. Note that this routine may be invoked multiple times; the
180  /// external source should take care not to introduce the same instantiations
181  /// repeatedly.
183  SmallVectorImpl<std::pair<ValueDecl *,
184  SourceLocation> > &Pending) {}
185 
186  /// Read the set of late parsed template functions for this source.
187  ///
188  /// The external source should insert its own late parsed template functions
189  /// into the map. Note that this routine may be invoked multiple times; the
190  /// external source should take care not to introduce the same map entries
191  /// repeatedly.
193  llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
194  &LPTMap) {}
195 
196  /// Read the set of decls to be checked for deferred diags.
197  ///
198  /// The external source should append its own potentially emitted function
199  /// and variable decls which may cause deferred diags. Note that this routine
200  /// may be invoked multiple times; the external source should take care not to
201  /// introduce the same declarations repeatedly.
204 
205  /// \copydoc Sema::CorrectTypo
206  /// \note LookupKind must correspond to a valid Sema::LookupNameKind
207  ///
208  /// ExternalSemaSource::CorrectTypo is always given the first chance to
209  /// correct a typo (really, to offer suggestions to repair a failed lookup).
210  /// It will even be called when SpellChecking is turned off or after a
211  /// fatal error has already been detected.
213  int LookupKind, Scope *S, CXXScopeSpec *SS,
215  DeclContext *MemberContext,
216  bool EnteringContext,
217  const ObjCObjectPointerType *OPT) {
218  return TypoCorrection();
219  }
220 
221  /// Produces a diagnostic note if the external source contains a
222  /// complete definition for \p T.
223  ///
224  /// \param Loc the location at which a complete type was required but not
225  /// provided
226  ///
227  /// \param T the \c QualType that should have been complete at \p Loc
228  ///
229  /// \return true if a diagnostic was produced, false otherwise.
231  QualType T) {
232  return false;
233  }
234 
235  /// LLVM-style RTTI.
236  /// \{
237  bool isA(const void *ClassID) const override {
238  return ClassID == &ID || ExternalASTSource::isA(ClassID);
239  }
240  static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
241  /// \}
242 };
243 
244 } // end namespace clang
245 
246 #endif
Represents a function declaration or definition.
Definition: Decl.h:1783
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:655
Simple class containing the result of Sema::CorrectTypo.
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
virtual bool LookupUnqualified(LookupResult &R, Scope *S)
Do last resort, unqualified lookup on a LookupResult that Sema cannot find.
C Language Family Type Representation.
virtual void ForgetSema()
Inform the semantic consumer that Sema is no longer available.
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 ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WI)
Read the set of weak, undeclared identifiers known to the external Sema source.
static bool classof(const ExternalASTSource *S)
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 ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls)
Read the set of potentially unused typedefs known to the source.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
Represents a member of a struct/union/class.
Definition: Decl.h:2746
virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T)
Produces a diagnostic note if the external source contains a complete definition for T...
Represents the results of name lookup.
Definition: Lookup.h:46
virtual void InitializeSema(Sema &S)
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
virtual void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels)
Read the set of referenced selectors known to the external Sema source.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:340
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:619
An abstract interface that should be implemented by external AST sources that also provide informatio...
Abstract interface for external sources of AST nodes.
Encodes a location in the source.
bool isA(const void *ClassID) const override
LLVM-style RTTI.
virtual void ReadTentativeDefinitions(SmallVectorImpl< VarDecl *> &TentativeDefs)
Read the set of tentative definitions known to the external Sema source.
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1303
virtual void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl *> &Decls)
Read the set of delegating constructors known to the external Sema source.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Represents a pointer to an Objective C object.
Definition: Type.h:6050
virtual void ReadDeclsToCheckForDeferredDiags(llvm::SmallVector< Decl *, 4 > &Decls)
Read the set of decls to be checked for deferred diags.
virtual bool isA(const void *ClassID) const
LLVM-style RTTI.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
virtual void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl *> &Decls)
Read the set of unused file-scope declarations known to the external Sema source. ...
virtual void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending)
Read the set of pending instantiations known to the external Sema source.
virtual void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables)
Read the set of used vtables known to the external Sema source.