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_EXTERNAL_SEMA_SOURCE_H
14 #define LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_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"
25 class CXXConstructorDecl;
29 struct ObjCMethodList;
32 class TypedefNameDecl;
35 struct LateParsedTemplate;
37 /// \brief A simple structure that captures a vtable use for the purposes of
38 /// the \c ExternalSemaSource.
39 struct ExternalVTableUse {
40 CXXRecordDecl *Record;
41 SourceLocation Location;
42 bool DefinitionRequired;
45 /// \brief An abstract interface that should be implemented by
46 /// external AST sources that also provide information for semantic
48 class ExternalSemaSource : public ExternalASTSource {
50 ExternalSemaSource() {
51 ExternalASTSource::SemaSource = true;
54 ~ExternalSemaSource();
56 /// \brief Initialize the semantic source with the Sema instance
57 /// being used to perform semantic analysis on the abstract syntax
59 virtual void InitializeSema(Sema &S) {}
61 /// \brief Inform the semantic consumer that Sema is no longer available.
62 virtual void ForgetSema() {}
64 /// \brief Load the contents of the global method pool for a given
66 virtual void ReadMethodPool(Selector Sel);
68 /// \brief Load the set of namespaces that are known to the external source,
69 /// which will be used during typo correction.
70 virtual void ReadKnownNamespaces(
71 SmallVectorImpl<NamespaceDecl *> &Namespaces);
73 /// \brief Load the set of used but not defined functions or variables with
74 /// internal linkage, or used but not defined internal functions.
75 virtual void ReadUndefinedButUsed(
76 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
78 /// \brief Do last resort, unqualified lookup on a LookupResult that
81 /// \param R a LookupResult that is being recovered.
83 /// \param S the Scope of the identifier occurrence.
85 /// \return true to tell Sema to recover using the LookupResult.
86 virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
88 /// \brief Read the set of tentative definitions known to the external Sema
91 /// The external source should append its own tentative definitions to the
92 /// given vector of tentative definitions. Note that this routine may be
93 /// invoked multiple times; the external source should take care not to
94 /// introduce the same declarations repeatedly.
95 virtual void ReadTentativeDefinitions(
96 SmallVectorImpl<VarDecl *> &TentativeDefs) {}
98 /// \brief Read the set of unused file-scope declarations known to the
99 /// external Sema source.
101 /// The external source should append its own unused, filed-scope to the
102 /// given vector of declarations. Note that this routine may be
103 /// invoked multiple times; the external source should take care not to
104 /// introduce the same declarations repeatedly.
105 virtual void ReadUnusedFileScopedDecls(
106 SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
108 /// \brief Read the set of delegating constructors known to the
109 /// external Sema source.
111 /// The external source should append its own delegating constructors 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.
115 virtual void ReadDelegatingConstructors(
116 SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
118 /// \brief Read the set of ext_vector type declarations known to the
119 /// external Sema source.
121 /// The external source should append its own ext_vector type declarations to
122 /// the 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.
125 virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
127 /// \brief Read the set of dynamic classes known to the external Sema source.
129 /// The external source should append its own dynamic classes 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 ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {}
135 /// \brief Read the set of locally-scoped external declarations known to the
136 /// external Sema source.
138 /// The external source should append its own locally-scoped external
139 /// declarations to the given vector of declarations. Note that this routine
140 /// may be invoked multiple times; the external source should take care not
141 /// to introduce the same declarations repeatedly.
142 virtual void ReadLocallyScopedExternCDecls(
143 SmallVectorImpl<NamedDecl *> &Decls) {}
145 /// \brief Read the set of referenced selectors known to the
146 /// external Sema source.
148 /// The external source should append its own referenced selectors to the
149 /// given vector of selectors. Note that this routine
150 /// may be invoked multiple times; the external source should take care not
151 /// to introduce the same selectors repeatedly.
152 virtual void ReadReferencedSelectors(
153 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
155 /// \brief Read the set of weak, undeclared identifiers known to the
156 /// external Sema source.
158 /// The external source should append its own weak, undeclared identifiers to
159 /// the given vector. Note that this routine may be invoked multiple times;
160 /// the external source should take care not to introduce the same identifiers
162 virtual void ReadWeakUndeclaredIdentifiers(
163 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
165 /// \brief Read the set of used vtables known to the external Sema source.
167 /// The external source should append its own used vtables to the given
168 /// vector. Note that this routine may be invoked multiple times; the external
169 /// source should take care not to introduce the same vtables repeatedly.
170 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
172 /// \brief Read the set of pending instantiations known to the external
175 /// The external source should append its own pending instantiations to the
176 /// given vector. Note that this routine may be invoked multiple times; the
177 /// external source should take care not to introduce the same instantiations
179 virtual void ReadPendingInstantiations(
180 SmallVectorImpl<std::pair<ValueDecl *,
181 SourceLocation> > &Pending) {}
183 /// \brief Read the set of late parsed template functions for this source.
185 /// The external source should insert its own late parsed template functions
186 /// into the map. Note that this routine may be invoked multiple times; the
187 /// external source should take care not to introduce the same map entries
189 virtual void ReadLateParsedTemplates(
190 llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {}
192 /// \copydoc Sema::CorrectTypo
193 /// \note LookupKind must correspond to a valid Sema::LookupNameKind
195 /// ExternalSemaSource::CorrectTypo is always given the first chance to
196 /// correct a typo (really, to offer suggestions to repair a failed lookup).
197 /// It will even be called when SpellChecking is turned off or after a
198 /// fatal error has already been detected.
199 virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
200 int LookupKind, Scope *S, CXXScopeSpec *SS,
201 CorrectionCandidateCallback &CCC,
202 DeclContext *MemberContext,
203 bool EnteringContext,
204 const ObjCObjectPointerType *OPT) {
205 return TypoCorrection();
208 /// \brief Produces a diagnostic note if the external source contains a
209 /// complete definition for \p T.
211 /// \param Loc the location at which a complete type was required but not
214 /// \param T the \c QualType that should have been complete at \p Loc
216 /// \return true if a diagnostic was produced, false otherwise.
217 virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
222 // isa/cast/dyn_cast support
223 static bool classof(const ExternalASTSource *Source) {
224 return Source->SemaSource;
228 } // end namespace clang