1 //===--- ExternalSemaSource.h - External Sema Interface ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ExternalSemaSource interface.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
14 #define LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
16 #include "clang/AST/ExternalASTSource.h"
17 #include "clang/AST/Type.h"
18 #include "clang/Sema/TypoCorrection.h"
19 #include "clang/Sema/Weak.h"
20 #include "llvm/ADT/MapVector.h"
24 template <class T, unsigned n> class SmallSetVector;
29 class CXXConstructorDecl;
34 struct ObjCMethodList;
37 class TypedefNameDecl;
40 struct LateParsedTemplate;
42 /// \brief A simple structure that captures a vtable use for the purposes of
43 /// the \c ExternalSemaSource.
44 struct ExternalVTableUse {
45 CXXRecordDecl *Record;
46 SourceLocation Location;
47 bool DefinitionRequired;
50 /// \brief An abstract interface that should be implemented by
51 /// external AST sources that also provide information for semantic
53 class ExternalSemaSource : public ExternalASTSource {
55 ExternalSemaSource() {
56 ExternalASTSource::SemaSource = true;
59 ~ExternalSemaSource() override;
61 /// \brief Initialize the semantic source with the Sema instance
62 /// being used to perform semantic analysis on the abstract syntax
64 virtual void InitializeSema(Sema &S) {}
66 /// \brief Inform the semantic consumer that Sema is no longer available.
67 virtual void ForgetSema() {}
69 /// \brief Load the contents of the global method pool for a given
71 virtual void ReadMethodPool(Selector Sel);
73 /// \brief Load the set of namespaces that are known to the external source,
74 /// which will be used during typo correction.
75 virtual void ReadKnownNamespaces(
76 SmallVectorImpl<NamespaceDecl *> &Namespaces);
78 /// \brief Load the set of used but not defined functions or variables with
79 /// internal linkage, or used but not defined internal functions.
80 virtual void ReadUndefinedButUsed(
81 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
83 virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
84 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &);
86 /// \brief Do last resort, unqualified lookup on a LookupResult that
89 /// \param R a LookupResult that is being recovered.
91 /// \param S the Scope of the identifier occurrence.
93 /// \return true to tell Sema to recover using the LookupResult.
94 virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
96 /// \brief Read the set of tentative definitions known to the external Sema
99 /// The external source should append its own tentative definitions to the
100 /// given vector of tentative definitions. Note that this routine may be
101 /// invoked multiple times; the external source should take care not to
102 /// introduce the same declarations repeatedly.
103 virtual void ReadTentativeDefinitions(
104 SmallVectorImpl<VarDecl *> &TentativeDefs) {}
106 /// \brief Read the set of unused file-scope declarations known to the
107 /// external Sema source.
109 /// The external source should append its own unused, filed-scope to the
110 /// given vector of declarations. Note that this routine may be
111 /// invoked multiple times; the external source should take care not to
112 /// introduce the same declarations repeatedly.
113 virtual void ReadUnusedFileScopedDecls(
114 SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
116 /// \brief Read the set of delegating constructors known to the
117 /// external Sema source.
119 /// The external source should append its own delegating constructors to the
120 /// given vector of declarations. Note that this routine may be
121 /// invoked multiple times; the external source should take care not to
122 /// introduce the same declarations repeatedly.
123 virtual void ReadDelegatingConstructors(
124 SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
126 /// \brief Read the set of ext_vector type declarations known to the
127 /// external Sema source.
129 /// The external source should append its own ext_vector type declarations to
130 /// the given vector of declarations. Note that this routine may be
131 /// invoked multiple times; the external source should take care not to
132 /// introduce the same declarations repeatedly.
133 virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
135 /// \brief Read the set of potentially unused typedefs known to the source.
137 /// The external source should append its own potentially unused local
138 /// typedefs to the given vector of declarations. Note that this routine may
139 /// be invoked multiple times; the external source should take care not to
140 /// introduce the same declarations repeatedly.
141 virtual void ReadUnusedLocalTypedefNameCandidates(
142 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {}
144 /// \brief Read the set of referenced selectors known to the
145 /// external Sema source.
147 /// The external source should append its own referenced selectors to the
148 /// given vector of selectors. Note that this routine
149 /// may be invoked multiple times; the external source should take care not
150 /// to introduce the same selectors repeatedly.
151 virtual void ReadReferencedSelectors(
152 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
154 /// \brief Read the set of weak, undeclared identifiers known to the
155 /// external Sema source.
157 /// The external source should append its own weak, undeclared identifiers to
158 /// the given vector. Note that this routine may be invoked multiple times;
159 /// the external source should take care not to introduce the same identifiers
161 virtual void ReadWeakUndeclaredIdentifiers(
162 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
164 /// \brief Read the set of used vtables known to the external Sema source.
166 /// The external source should append its own used vtables to the given
167 /// vector. Note that this routine may be invoked multiple times; the external
168 /// source should take care not to introduce the same vtables repeatedly.
169 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
171 /// \brief Read the set of pending instantiations known to the external
174 /// The external source should append its own pending instantiations to the
175 /// given vector. Note that this routine may be invoked multiple times; the
176 /// external source should take care not to introduce the same instantiations
178 virtual void ReadPendingInstantiations(
179 SmallVectorImpl<std::pair<ValueDecl *,
180 SourceLocation> > &Pending) {}
182 /// \brief Read the set of late parsed template functions for this source.
184 /// The external source should insert its own late parsed template functions
185 /// into the map. Note that this routine may be invoked multiple times; the
186 /// external source should take care not to introduce the same map entries
188 virtual void ReadLateParsedTemplates(
189 llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {}
191 /// \copydoc Sema::CorrectTypo
192 /// \note LookupKind must correspond to a valid Sema::LookupNameKind
194 /// ExternalSemaSource::CorrectTypo is always given the first chance to
195 /// correct a typo (really, to offer suggestions to repair a failed lookup).
196 /// It will even be called when SpellChecking is turned off or after a
197 /// fatal error has already been detected.
198 virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
199 int LookupKind, Scope *S, CXXScopeSpec *SS,
200 CorrectionCandidateCallback &CCC,
201 DeclContext *MemberContext,
202 bool EnteringContext,
203 const ObjCObjectPointerType *OPT) {
204 return TypoCorrection();
207 /// \brief Produces a diagnostic note if the external source contains a
208 /// complete definition for \p T.
210 /// \param Loc the location at which a complete type was required but not
213 /// \param T the \c QualType that should have been complete at \p Loc
215 /// \return true if a diagnostic was produced, false otherwise.
216 virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
221 // isa/cast/dyn_cast support
222 static bool classof(const ExternalASTSource *Source) {
223 return Source->SemaSource;
227 } // end namespace clang