1193326Sed//===--- ExternalSemaSource.h - External Sema Interface ---------*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10193326Sed//  This file defines the ExternalSemaSource interface.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed#ifndef LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H
14193326Sed#define LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H
15193326Sed
16193326Sed#include "clang/AST/ExternalASTSource.h"
17263509Sdim#include "clang/AST/Type.h"
18263509Sdim#include "clang/Sema/TypoCorrection.h"
19226890Sdim#include "clang/Sema/Weak.h"
20252723Sdim#include "llvm/ADT/MapVector.h"
21218893Sdim#include <utility>
22193326Sed
23193326Sednamespace clang {
24193326Sed
25226890Sdimclass CXXConstructorDecl;
26226890Sdimclass CXXRecordDecl;
27226890Sdimclass DeclaratorDecl;
28226890Sdimclass LookupResult;
29218893Sdimstruct ObjCMethodList;
30226890Sdimclass Scope;
31193326Sedclass Sema;
32226890Sdimclass TypedefNameDecl;
33226890Sdimclass ValueDecl;
34226890Sdimclass VarDecl;
35263509Sdimstruct LateParsedTemplate;
36263509Sdim
37226890Sdim/// \brief A simple structure that captures a vtable use for the purposes of
38226890Sdim/// the \c ExternalSemaSource.
39226890Sdimstruct ExternalVTableUse {
40226890Sdim  CXXRecordDecl *Record;
41226890Sdim  SourceLocation Location;
42226890Sdim  bool DefinitionRequired;
43226890Sdim};
44226890Sdim
45193326Sed/// \brief An abstract interface that should be implemented by
46193326Sed/// external AST sources that also provide information for semantic
47193326Sed/// analysis.
48193326Sedclass ExternalSemaSource : public ExternalASTSource {
49193326Sedpublic:
50193326Sed  ExternalSemaSource() {
51193326Sed    ExternalASTSource::SemaSource = true;
52193326Sed  }
53193326Sed
54210299Sed  ~ExternalSemaSource();
55210299Sed
56193326Sed  /// \brief Initialize the semantic source with the Sema instance
57193326Sed  /// being used to perform semantic analysis on the abstract syntax
58193326Sed  /// tree.
59193326Sed  virtual void InitializeSema(Sema &S) {}
60193326Sed
61200583Srdivacky  /// \brief Inform the semantic consumer that Sema is no longer available.
62200583Srdivacky  virtual void ForgetSema() {}
63200583Srdivacky
64193326Sed  /// \brief Load the contents of the global method pool for a given
65193326Sed  /// selector.
66235633Sdim  virtual void ReadMethodPool(Selector Sel);
67198092Srdivacky
68224145Sdim  /// \brief Load the set of namespaces that are known to the external source,
69224145Sdim  /// which will be used during typo correction.
70224145Sdim  virtual void ReadKnownNamespaces(
71226890Sdim                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
72252723Sdim
73252723Sdim  /// \brief Load the set of used but not defined functions or variables with
74252723Sdim  /// internal linkage, or used but not defined internal functions.
75252723Sdim  virtual void ReadUndefinedButUsed(
76252723Sdim                         llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
77252723Sdim
78219077Sdim  /// \brief Do last resort, unqualified lookup on a LookupResult that
79219077Sdim  /// Sema cannot find.
80219077Sdim  ///
81219077Sdim  /// \param R a LookupResult that is being recovered.
82219077Sdim  ///
83219077Sdim  /// \param S the Scope of the identifier occurrence.
84219077Sdim  ///
85219077Sdim  /// \return true to tell Sema to recover using the LookupResult.
86219077Sdim  virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
87219077Sdim
88226890Sdim  /// \brief Read the set of tentative definitions known to the external Sema
89226890Sdim  /// source.
90226890Sdim  ///
91226890Sdim  /// The external source should append its own tentative definitions to the
92226890Sdim  /// given vector of tentative definitions. Note that this routine may be
93226890Sdim  /// invoked multiple times; the external source should take care not to
94226890Sdim  /// introduce the same declarations repeatedly.
95226890Sdim  virtual void ReadTentativeDefinitions(
96226890Sdim                                  SmallVectorImpl<VarDecl *> &TentativeDefs) {}
97226890Sdim
98226890Sdim  /// \brief Read the set of unused file-scope declarations known to the
99226890Sdim  /// external Sema source.
100226890Sdim  ///
101226890Sdim  /// The external source should append its own unused, filed-scope to the
102226890Sdim  /// given vector of declarations. Note that this routine may be
103226890Sdim  /// invoked multiple times; the external source should take care not to
104226890Sdim  /// introduce the same declarations repeatedly.
105226890Sdim  virtual void ReadUnusedFileScopedDecls(
106226890Sdim                 SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
107226890Sdim
108226890Sdim  /// \brief Read the set of delegating constructors known to the
109226890Sdim  /// external Sema source.
110226890Sdim  ///
111226890Sdim  /// The external source should append its own delegating constructors to the
112226890Sdim  /// given vector of declarations. Note that this routine may be
113226890Sdim  /// invoked multiple times; the external source should take care not to
114226890Sdim  /// introduce the same declarations repeatedly.
115226890Sdim  virtual void ReadDelegatingConstructors(
116226890Sdim                 SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
117226890Sdim
118226890Sdim  /// \brief Read the set of ext_vector type declarations known to the
119226890Sdim  /// external Sema source.
120226890Sdim  ///
121226890Sdim  /// The external source should append its own ext_vector type declarations to
122226890Sdim  /// the given vector of declarations. Note that this routine may be
123226890Sdim  /// invoked multiple times; the external source should take care not to
124226890Sdim  /// introduce the same declarations repeatedly.
125226890Sdim  virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
126226890Sdim
127226890Sdim  /// \brief Read the set of dynamic classes known to the external Sema source.
128226890Sdim  ///
129226890Sdim  /// The external source should append its own dynamic classes to
130226890Sdim  /// the given vector of declarations. Note that this routine may be
131226890Sdim  /// invoked multiple times; the external source should take care not to
132226890Sdim  /// introduce the same declarations repeatedly.
133226890Sdim  virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {}
134226890Sdim
135226890Sdim  /// \brief Read the set of locally-scoped external declarations known to the
136226890Sdim  /// external Sema source.
137226890Sdim  ///
138226890Sdim  /// The external source should append its own locally-scoped external
139226890Sdim  /// declarations to the given vector of declarations. Note that this routine
140226890Sdim  /// may be invoked multiple times; the external source should take care not
141226890Sdim  /// to introduce the same declarations repeatedly.
142252723Sdim  virtual void ReadLocallyScopedExternCDecls(
143226890Sdim                 SmallVectorImpl<NamedDecl *> &Decls) {}
144226890Sdim
145226890Sdim  /// \brief Read the set of referenced selectors known to the
146226890Sdim  /// external Sema source.
147226890Sdim  ///
148226890Sdim  /// The external source should append its own referenced selectors to the
149226890Sdim  /// given vector of selectors. Note that this routine
150226890Sdim  /// may be invoked multiple times; the external source should take care not
151226890Sdim  /// to introduce the same selectors repeatedly.
152226890Sdim  virtual void ReadReferencedSelectors(
153226890Sdim                 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
154226890Sdim
155226890Sdim  /// \brief Read the set of weak, undeclared identifiers known to the
156226890Sdim  /// external Sema source.
157226890Sdim  ///
158226890Sdim  /// The external source should append its own weak, undeclared identifiers to
159226890Sdim  /// the given vector. Note that this routine may be invoked multiple times;
160226890Sdim  /// the external source should take care not to introduce the same identifiers
161226890Sdim  /// repeatedly.
162226890Sdim  virtual void ReadWeakUndeclaredIdentifiers(
163226890Sdim                 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
164226890Sdim
165226890Sdim  /// \brief Read the set of used vtables known to the external Sema source.
166226890Sdim  ///
167226890Sdim  /// The external source should append its own used vtables to the given
168226890Sdim  /// vector. Note that this routine may be invoked multiple times; the external
169226890Sdim  /// source should take care not to introduce the same vtables repeatedly.
170226890Sdim  virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
171226890Sdim
172226890Sdim  /// \brief Read the set of pending instantiations known to the external
173226890Sdim  /// Sema source.
174226890Sdim  ///
175226890Sdim  /// The external source should append its own pending instantiations to the
176226890Sdim  /// given vector. Note that this routine may be invoked multiple times; the
177226890Sdim  /// external source should take care not to introduce the same instantiations
178226890Sdim  /// repeatedly.
179226890Sdim  virtual void ReadPendingInstantiations(
180226890Sdim                 SmallVectorImpl<std::pair<ValueDecl *,
181226890Sdim                                           SourceLocation> > &Pending) {}
182226890Sdim
183263509Sdim  /// \brief Read the set of late parsed template functions for this source.
184263509Sdim  ///
185263509Sdim  /// The external source should insert its own late parsed template functions
186263509Sdim  /// into the map. Note that this routine may be invoked multiple times; the
187263509Sdim  /// external source should take care not to introduce the same map entries
188263509Sdim  /// repeatedly.
189263509Sdim  virtual void ReadLateParsedTemplates(
190263509Sdim      llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {}
191263509Sdim
192263509Sdim  /// \copydoc Sema::CorrectTypo
193263509Sdim  /// \note LookupKind must correspond to a valid Sema::LookupNameKind
194263509Sdim  ///
195263509Sdim  /// ExternalSemaSource::CorrectTypo is always given the first chance to
196263509Sdim  /// correct a typo (really, to offer suggestions to repair a failed lookup).
197263509Sdim  /// It will even be called when SpellChecking is turned off or after a
198263509Sdim  /// fatal error has already been detected.
199263509Sdim  virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
200263509Sdim                                     int LookupKind, Scope *S, CXXScopeSpec *SS,
201263509Sdim                                     CorrectionCandidateCallback &CCC,
202263509Sdim                                     DeclContext *MemberContext,
203263509Sdim                                     bool EnteringContext,
204263509Sdim                                     const ObjCObjectPointerType *OPT) {
205263509Sdim    return TypoCorrection();
206263509Sdim  }
207263509Sdim
208263509Sdim  /// \brief Produces a diagnostic note if the external source contains a
209263509Sdim  /// complete definition for \p T.
210263509Sdim  ///
211263509Sdim  /// \param Loc the location at which a complete type was required but not
212263509Sdim  /// provided
213263509Sdim  ///
214263509Sdim  /// \param T the \c QualType that should have been complete at \p Loc
215263509Sdim  ///
216263509Sdim  /// \return true if a diagnostic was produced, false otherwise.
217263509Sdim  virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
218263509Sdim                                                QualType T) {
219263509Sdim    return false;
220263509Sdim  }
221263509Sdim
222193326Sed  // isa/cast/dyn_cast support
223198092Srdivacky  static bool classof(const ExternalASTSource *Source) {
224193326Sed    return Source->SemaSource;
225193326Sed  }
226226890Sdim};
227193326Sed
228193326Sed} // end namespace clang
229193326Sed
230193326Sed#endif
231