]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/Sema/ExternalSemaSource.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / clang / include / clang / Sema / ExternalSemaSource.h
1 //===--- ExternalSemaSource.h - External Sema Interface ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the ExternalSemaSource interface.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H
14 #define LLVM_CLANG_SEMA_EXTERNAL_SEMA_SOURCE_H
15
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"
21 #include <utility>
22
23 namespace clang {
24
25 class CXXConstructorDecl;
26 class CXXRecordDecl;
27 class DeclaratorDecl;
28 class LookupResult;
29 struct ObjCMethodList;
30 class Scope;
31 class Sema;
32 class TypedefNameDecl;
33 class ValueDecl;
34 class VarDecl;
35 struct LateParsedTemplate;
36
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;
43 };
44   
45 /// \brief An abstract interface that should be implemented by
46 /// external AST sources that also provide information for semantic
47 /// analysis.
48 class ExternalSemaSource : public ExternalASTSource {
49 public:
50   ExternalSemaSource() {
51     ExternalASTSource::SemaSource = true;
52   }
53
54   ~ExternalSemaSource();
55
56   /// \brief Initialize the semantic source with the Sema instance
57   /// being used to perform semantic analysis on the abstract syntax
58   /// tree.
59   virtual void InitializeSema(Sema &S) {}
60
61   /// \brief Inform the semantic consumer that Sema is no longer available.
62   virtual void ForgetSema() {}
63
64   /// \brief Load the contents of the global method pool for a given
65   /// selector.
66   virtual void ReadMethodPool(Selector Sel);
67
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);
72
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);
77
78   /// \brief Do last resort, unqualified lookup on a LookupResult that
79   /// Sema cannot find.
80   ///
81   /// \param R a LookupResult that is being recovered.
82   ///
83   /// \param S the Scope of the identifier occurrence.
84   ///
85   /// \return true to tell Sema to recover using the LookupResult.
86   virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
87
88   /// \brief Read the set of tentative definitions known to the external Sema
89   /// source.
90   ///
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) {}
97   
98   /// \brief Read the set of unused file-scope declarations known to the
99   /// external Sema source.
100   ///
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) {}
107   
108   /// \brief Read the set of delegating constructors known to the
109   /// external Sema source.
110   ///
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) {}
117
118   /// \brief Read the set of ext_vector type declarations known to the
119   /// external Sema source.
120   ///
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) {}
126
127   /// \brief Read the set of dynamic classes known to the external Sema source.
128   ///
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) {}
134
135   /// \brief Read the set of locally-scoped external declarations known to the
136   /// external Sema source.
137   ///
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) {}
144
145   /// \brief Read the set of referenced selectors known to the
146   /// external Sema source.
147   ///
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) {}
154
155   /// \brief Read the set of weak, undeclared identifiers known to the
156   /// external Sema source.
157   ///
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
161   /// repeatedly.
162   virtual void ReadWeakUndeclaredIdentifiers(
163                  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
164
165   /// \brief Read the set of used vtables known to the external Sema source.
166   ///
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) {}
171
172   /// \brief Read the set of pending instantiations known to the external
173   /// Sema source.
174   ///
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
178   /// repeatedly.
179   virtual void ReadPendingInstantiations(
180                  SmallVectorImpl<std::pair<ValueDecl *, 
181                                            SourceLocation> > &Pending) {}
182
183   /// \brief Read the set of late parsed template functions for this source.
184   ///
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
188   /// repeatedly.
189   virtual void ReadLateParsedTemplates(
190       llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {}
191
192   /// \copydoc Sema::CorrectTypo
193   /// \note LookupKind must correspond to a valid Sema::LookupNameKind
194   ///
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();
206   }
207
208   /// \brief Produces a diagnostic note if the external source contains a
209   /// complete definition for \p T.
210   ///
211   /// \param Loc the location at which a complete type was required but not
212   /// provided
213   ///
214   /// \param T the \c QualType that should have been complete at \p Loc
215   ///
216   /// \return true if a diagnostic was produced, false otherwise.
217   virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
218                                                 QualType T) {
219     return false;
220   }
221
222   // isa/cast/dyn_cast support
223   static bool classof(const ExternalASTSource *Source) {
224     return Source->SemaSource;
225   }
226 }; 
227
228 } // end namespace clang
229
230 #endif