clang  9.0.0svn
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 public:
55  ExternalASTSource::SemaSource = true;
56  }
57 
58  ~ExternalSemaSource() override;
59 
60  /// Initialize the semantic source with the Sema instance
61  /// being used to perform semantic analysis on the abstract syntax
62  /// tree.
63  virtual void InitializeSema(Sema &S) {}
64 
65  /// Inform the semantic consumer that Sema is no longer available.
66  virtual void ForgetSema() {}
67 
68  /// Load the contents of the global method pool for a given
69  /// selector.
70  virtual void ReadMethodPool(Selector Sel);
71 
72  /// Load the contents of the global method pool for a given
73  /// selector if necessary.
74  virtual void updateOutOfDateSelector(Selector Sel);
75 
76  /// Load the set of namespaces that are known to the external source,
77  /// which will be used during typo correction.
78  virtual void ReadKnownNamespaces(
80 
81  /// Load the set of used but not defined functions or variables with
82  /// internal linkage, or used but not defined internal functions.
83  virtual void
84  ReadUndefinedButUsed(llvm::MapVector<NamedDecl *, SourceLocation> &Undefined);
85 
86  virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
87  FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &);
88 
89  /// Do last resort, unqualified lookup on a LookupResult that
90  /// Sema cannot find.
91  ///
92  /// \param R a LookupResult that is being recovered.
93  ///
94  /// \param S the Scope of the identifier occurrence.
95  ///
96  /// \return true to tell Sema to recover using the LookupResult.
97  virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
98 
99  /// Read the set of tentative definitions known to the external Sema
100  /// source.
101  ///
102  /// The external source should append its own tentative definitions to the
103  /// given vector of tentative definitions. Note that this routine may be
104  /// invoked multiple times; the external source should take care not to
105  /// introduce the same declarations repeatedly.
107  SmallVectorImpl<VarDecl *> &TentativeDefs) {}
108 
109  /// Read the set of unused file-scope declarations known to the
110  /// external Sema source.
111  ///
112  /// The external source should append its own unused, filed-scope to the
113  /// given vector of declarations. Note that this routine may be
114  /// invoked multiple times; the external source should take care not to
115  /// introduce the same declarations repeatedly.
118 
119  /// Read the set of delegating constructors known to the
120  /// external Sema source.
121  ///
122  /// The external source should append its own delegating constructors to the
123  /// given vector of declarations. Note that this routine may be
124  /// invoked multiple times; the external source should take care not to
125  /// introduce the same declarations repeatedly.
128 
129  /// Read the set of ext_vector type declarations known to the
130  /// external Sema source.
131  ///
132  /// The external source should append its own ext_vector type declarations to
133  /// the given vector of declarations. Note that this routine may be
134  /// invoked multiple times; the external source should take care not to
135  /// introduce the same declarations repeatedly.
137 
138  /// Read the set of potentially unused typedefs known to the source.
139  ///
140  /// The external source should append its own potentially unused local
141  /// typedefs to the given vector of declarations. Note that this routine may
142  /// be invoked multiple times; the external source should take care not to
143  /// introduce the same declarations repeatedly.
146 
147  /// Read the set of referenced selectors known to the
148  /// external Sema source.
149  ///
150  /// The external source should append its own referenced selectors to the
151  /// given vector of selectors. Note that this routine
152  /// may be invoked multiple times; the external source should take care not
153  /// to introduce the same selectors repeatedly.
155  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
156 
157  /// Read the set of weak, undeclared identifiers known to the
158  /// external Sema source.
159  ///
160  /// The external source should append its own weak, undeclared identifiers to
161  /// the given vector. Note that this routine may be invoked multiple times;
162  /// the external source should take care not to introduce the same identifiers
163  /// repeatedly.
165  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
166 
167  /// Read the set of used vtables known to the external Sema source.
168  ///
169  /// The external source should append its own used vtables to the given
170  /// vector. Note that this routine may be invoked multiple times; the external
171  /// source should take care not to introduce the same vtables repeatedly.
173 
174  /// Read the set of pending instantiations known to the external
175  /// Sema source.
176  ///
177  /// The external source should append its own pending instantiations to the
178  /// given vector. Note that this routine may be invoked multiple times; the
179  /// external source should take care not to introduce the same instantiations
180  /// repeatedly.
182  SmallVectorImpl<std::pair<ValueDecl *,
183  SourceLocation> > &Pending) {}
184 
185  /// Read the set of late parsed template functions for this source.
186  ///
187  /// The external source should insert its own late parsed template functions
188  /// into the map. Note that this routine may be invoked multiple times; the
189  /// external source should take care not to introduce the same map entries
190  /// repeatedly.
192  llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
193  &LPTMap) {}
194 
195  /// \copydoc Sema::CorrectTypo
196  /// \note LookupKind must correspond to a valid Sema::LookupNameKind
197  ///
198  /// ExternalSemaSource::CorrectTypo is always given the first chance to
199  /// correct a typo (really, to offer suggestions to repair a failed lookup).
200  /// It will even be called when SpellChecking is turned off or after a
201  /// fatal error has already been detected.
203  int LookupKind, Scope *S, CXXScopeSpec *SS,
205  DeclContext *MemberContext,
206  bool EnteringContext,
207  const ObjCObjectPointerType *OPT) {
208  return TypoCorrection();
209  }
210 
211  /// Produces a diagnostic note if the external source contains a
212  /// complete definition for \p T.
213  ///
214  /// \param Loc the location at which a complete type was required but not
215  /// provided
216  ///
217  /// \param T the \c QualType that should have been complete at \p Loc
218  ///
219  /// \return true if a diagnostic was produced, false otherwise.
221  QualType T) {
222  return false;
223  }
224 
225  // isa/cast/dyn_cast support
226  static bool classof(const ExternalASTSource *Source) {
227  return Source->SemaSource;
228  }
229 };
230 
231 } // end namespace clang
232 
233 #endif
Represents a function declaration or definition.
Definition: Decl.h:1737
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
Definition: Type.h:637
Simple class containing the result of Sema::CorrectTypo.
A simple structure that captures a vtable use for the purposes of the ExternalSemaSource.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:29
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.
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:2578
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:62
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:277
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
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.
static bool classof(const ExternalASTSource *Source)
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:1261
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:5796
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
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.