blob: e9ba479d1255b30d31780a3ebbbd333fe1784871 [file] [log] [blame]
Axel Naumann0ec56b72012-10-18 19:05:02 +00001//===--- MultiplexExternalSemaSource.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 ExternalSemaSource interface, dispatching to all clients
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H
14#define LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H
15
16#include "clang/Sema/ExternalSemaSource.h"
17#include "clang/Sema/Weak.h"
Axel Naumann0ec56b72012-10-18 19:05:02 +000018#include "llvm/ADT/SmallVector.h"
Axel Naumann0ec56b72012-10-18 19:05:02 +000019#include <utility>
20
21namespace clang {
22
23 class CXXConstructorDecl;
24 class CXXRecordDecl;
25 class DeclaratorDecl;
26 struct ExternalVTableUse;
27 class LookupResult;
28 class NamespaceDecl;
29 class Scope;
30 class Sema;
31 class TypedefNameDecl;
32 class ValueDecl;
33 class VarDecl;
34
35
36/// \brief An abstract interface that should be implemented by
37/// external AST sources that also provide information for semantic
38/// analysis.
39class MultiplexExternalSemaSource : public ExternalSemaSource {
40
41private:
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +000042 SmallVector<ExternalSemaSource *, 2> Sources; // doesn't own them.
Axel Naumann0ec56b72012-10-18 19:05:02 +000043
44public:
45
46 ///\brief Constructs a new multiplexing external sema source and appends the
47 /// given element to it.
48 ///
49 ///\param[in] s1 - A non-null (old) ExternalSemaSource.
50 ///\param[in] s2 - A non-null (new) ExternalSemaSource.
51 ///
52 MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2);
53
54 ~MultiplexExternalSemaSource();
55
56 ///\brief Appends new source to the source list.
57 ///
58 ///\param[in] source - An ExternalSemaSource.
59 ///
60 void addSource(ExternalSemaSource &source);
61
62 //===--------------------------------------------------------------------===//
63 // ExternalASTSource.
64 //===--------------------------------------------------------------------===//
65
66 /// \brief Resolve a declaration ID into a declaration, potentially
67 /// building a new declaration.
Axel Naumann0ec56b72012-10-18 19:05:02 +000068 virtual Decl *GetExternalDecl(uint32_t ID);
69
70 /// \brief Resolve a selector ID into a selector.
Axel Naumann0ec56b72012-10-18 19:05:02 +000071 virtual Selector GetExternalSelector(uint32_t ID);
72
73 /// \brief Returns the number of selectors known to the external AST
74 /// source.
Axel Naumann0ec56b72012-10-18 19:05:02 +000075 virtual uint32_t GetNumExternalSelectors();
76
77 /// \brief Resolve the offset of a statement in the decl stream into
78 /// a statement.
Axel Naumann0ec56b72012-10-18 19:05:02 +000079 virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
80
81 /// \brief Resolve the offset of a set of C++ base specifiers in the decl
82 /// stream into an array of specifiers.
Axel Naumann0ec56b72012-10-18 19:05:02 +000083 virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
84
Richard Smith3646c682013-02-07 03:30:24 +000085 /// \brief Find all declarations with the given name in the
Axel Naumann0ec56b72012-10-18 19:05:02 +000086 /// given context.
Richard Smith3646c682013-02-07 03:30:24 +000087 virtual bool
Axel Naumann0ec56b72012-10-18 19:05:02 +000088 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
89
90 /// \brief Ensures that the table of all visible declarations inside this
91 /// context is up to date.
Axel Naumann0ec56b72012-10-18 19:05:02 +000092 virtual void completeVisibleDeclsMap(const DeclContext *DC);
93
94 /// \brief Finds all declarations lexically contained within the given
95 /// DeclContext, after applying an optional filter predicate.
96 ///
97 /// \param isKindWeWant a predicate function that returns true if the passed
98 /// declaration kind is one we are looking for. If NULL, all declarations
99 /// are returned.
100 ///
101 /// \return an indication of whether the load succeeded or failed.
Axel Naumann0ec56b72012-10-18 19:05:02 +0000102 virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
103 bool (*isKindWeWant)(Decl::Kind),
104 SmallVectorImpl<Decl*> &Result);
105
106 /// \brief Finds all declarations lexically contained within the given
107 /// DeclContext.
108 ///
109 /// \return true if an error occurred
110 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
111 SmallVectorImpl<Decl*> &Result) {
112 return FindExternalLexicalDecls(DC, 0, Result);
113 }
114
115 template <typename DeclTy>
116 ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
117 SmallVectorImpl<Decl*> &Result) {
118 return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
119 }
120
121 /// \brief Get the decls that are contained in a file in the Offset/Length
122 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
123 /// a range.
124 virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
125 SmallVectorImpl<Decl *> &Decls);
126
127 /// \brief Gives the external AST source an opportunity to complete
128 /// an incomplete type.
129 virtual void CompleteType(TagDecl *Tag);
130
131 /// \brief Gives the external AST source an opportunity to complete an
132 /// incomplete Objective-C class.
133 ///
134 /// This routine will only be invoked if the "externally completed" bit is
135 /// set on the ObjCInterfaceDecl via the function
136 /// \c ObjCInterfaceDecl::setExternallyCompleted().
137 virtual void CompleteType(ObjCInterfaceDecl *Class);
138
139 /// \brief Loads comment ranges.
140 virtual void ReadComments();
141
142 /// \brief Notify ExternalASTSource that we started deserialization of
143 /// a decl or type so until FinishedDeserializing is called there may be
144 /// decls that are initializing. Must be paired with FinishedDeserializing.
Axel Naumann0ec56b72012-10-18 19:05:02 +0000145 virtual void StartedDeserializing();
146
147 /// \brief Notify ExternalASTSource that we finished the deserialization of
148 /// a decl or type. Must be paired with StartedDeserializing.
Axel Naumann0ec56b72012-10-18 19:05:02 +0000149 virtual void FinishedDeserializing();
150
151 /// \brief Function that will be invoked when we begin parsing a new
152 /// translation unit involving this external AST source.
Axel Naumann0ec56b72012-10-18 19:05:02 +0000153 virtual void StartTranslationUnit(ASTConsumer *Consumer);
154
155 /// \brief Print any statistics that have been gathered regarding
156 /// the external AST source.
Axel Naumann0ec56b72012-10-18 19:05:02 +0000157 virtual void PrintStats();
158
159
160 /// \brief Perform layout on the given record.
161 ///
162 /// This routine allows the external AST source to provide an specific
163 /// layout for a record, overriding the layout that would normally be
164 /// constructed. It is intended for clients who receive specific layout
165 /// details rather than source code (such as LLDB). The client is expected
166 /// to fill in the field offsets, base offsets, virtual base offsets, and
167 /// complete object size.
168 ///
169 /// \param Record The record whose layout is being requested.
170 ///
171 /// \param Size The final size of the record, in bits.
172 ///
173 /// \param Alignment The final alignment of the record, in bits.
174 ///
175 /// \param FieldOffsets The offset of each of the fields within the record,
176 /// expressed in bits. All of the fields must be provided with offsets.
177 ///
178 /// \param BaseOffsets The offset of each of the direct, non-virtual base
179 /// classes. If any bases are not given offsets, the bases will be laid
180 /// out according to the ABI.
181 ///
182 /// \param VirtualBaseOffsets The offset of each of the virtual base classes
183 /// (either direct or not). If any bases are not given offsets, the bases will
184 /// be laid out according to the ABI.
185 ///
186 /// \returns true if the record layout was provided, false otherwise.
187 virtual bool
188 layoutRecordType(const RecordDecl *Record,
189 uint64_t &Size, uint64_t &Alignment,
190 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
191 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
192 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
193
194 /// Return the amount of memory used by memory buffers, breaking down
195 /// by heap-backed versus mmap'ed memory.
196 virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
197
198 //===--------------------------------------------------------------------===//
199 // ExternalSemaSource.
200 //===--------------------------------------------------------------------===//
201
202 /// \brief Initialize the semantic source with the Sema instance
203 /// being used to perform semantic analysis on the abstract syntax
204 /// tree.
205 virtual void InitializeSema(Sema &S);
206
207 /// \brief Inform the semantic consumer that Sema is no longer available.
208 virtual void ForgetSema();
209
210 /// \brief Load the contents of the global method pool for a given
211 /// selector.
212 virtual void ReadMethodPool(Selector Sel);
213
214 /// \brief Load the set of namespaces that are known to the external source,
215 /// which will be used during typo correction.
216 virtual void ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces);
Nick Lewycky01a41142013-01-26 00:35:08 +0000217
Nick Lewyckycd0655b2013-02-01 08:13:20 +0000218 /// \brief Load the set of used but not defined functions or variables with
219 /// internal linkage, or used but not defined inline functions.
220 virtual void ReadUndefinedButUsed(
Nick Lewycky995e26b2013-01-31 03:23:57 +0000221 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
Axel Naumann0ec56b72012-10-18 19:05:02 +0000222
223 /// \brief Do last resort, unqualified lookup on a LookupResult that
224 /// Sema cannot find.
225 ///
226 /// \param R a LookupResult that is being recovered.
227 ///
228 /// \param S the Scope of the identifier occurrence.
229 ///
230 /// \return true to tell Sema to recover using the LookupResult.
231 virtual bool LookupUnqualified(LookupResult &R, Scope *S);
232
233 /// \brief Read the set of tentative definitions known to the external Sema
234 /// source.
235 ///
236 /// The external source should append its own tentative definitions to the
237 /// given vector of tentative definitions. Note that this routine may be
238 /// invoked multiple times; the external source should take care not to
239 /// introduce the same declarations repeatedly.
240 virtual void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs);
241
242 /// \brief Read the set of unused file-scope declarations known to the
243 /// external Sema source.
244 ///
245 /// The external source should append its own unused, filed-scope to the
246 /// given vector of declarations. Note that this routine may be
247 /// invoked multiple times; the external source should take care not to
248 /// introduce the same declarations repeatedly.
249 virtual void ReadUnusedFileScopedDecls(
250 SmallVectorImpl<const DeclaratorDecl*> &Decls);
251
252 /// \brief Read the set of delegating constructors known to the
253 /// external Sema source.
254 ///
255 /// The external source should append its own delegating constructors to the
256 /// given vector of declarations. Note that this routine may be
257 /// invoked multiple times; the external source should take care not to
258 /// introduce the same declarations repeatedly.
259 virtual void ReadDelegatingConstructors(
260 SmallVectorImpl<CXXConstructorDecl*> &Decls);
261
262 /// \brief Read the set of ext_vector type declarations known to the
263 /// external Sema source.
264 ///
265 /// The external source should append its own ext_vector type declarations to
266 /// the given vector of declarations. Note that this routine may be
267 /// invoked multiple times; the external source should take care not to
268 /// introduce the same declarations repeatedly.
269 virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls);
270
271 /// \brief Read the set of dynamic classes known to the external Sema source.
272 ///
273 /// The external source should append its own dynamic classes to
274 /// the given vector of declarations. Note that this routine may be
275 /// invoked multiple times; the external source should take care not to
276 /// introduce the same declarations repeatedly.
277 virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl*> &Decls);
278
Richard Smith5ea6ef42013-01-10 23:43:47 +0000279 /// \brief Read the set of locally-scoped extern "C" declarations known to the
Axel Naumann0ec56b72012-10-18 19:05:02 +0000280 /// external Sema source.
281 ///
282 /// The external source should append its own locally-scoped external
Richard Smith5ea6ef42013-01-10 23:43:47 +0000283 /// declarations to the given vector of declarations. Note that this routine
284 /// may be invoked multiple times; the external source should take care not
Axel Naumann0ec56b72012-10-18 19:05:02 +0000285 /// to introduce the same declarations repeatedly.
Richard Smith5ea6ef42013-01-10 23:43:47 +0000286 virtual void ReadLocallyScopedExternCDecls(SmallVectorImpl<NamedDecl*>&Decls);
Axel Naumann0ec56b72012-10-18 19:05:02 +0000287
288 /// \brief Read the set of referenced selectors known to the
289 /// external Sema source.
290 ///
291 /// The external source should append its own referenced selectors to the
292 /// given vector of selectors. Note that this routine
293 /// may be invoked multiple times; the external source should take care not
294 /// to introduce the same selectors repeatedly.
295 virtual void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
296 SourceLocation> > &Sels);
297
298 /// \brief Read the set of weak, undeclared identifiers known to the
299 /// external Sema source.
300 ///
301 /// The external source should append its own weak, undeclared identifiers to
302 /// the given vector. Note that this routine may be invoked multiple times;
303 /// the external source should take care not to introduce the same identifiers
304 /// repeatedly.
305 virtual void ReadWeakUndeclaredIdentifiers(
306 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI);
307
308 /// \brief Read the set of used vtables known to the external Sema source.
309 ///
310 /// The external source should append its own used vtables to the given
311 /// vector. Note that this routine may be invoked multiple times; the external
312 /// source should take care not to introduce the same vtables repeatedly.
313 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
314
315 /// \brief Read the set of pending instantiations known to the external
316 /// Sema source.
317 ///
318 /// The external source should append its own pending instantiations to the
319 /// given vector. Note that this routine may be invoked multiple times; the
320 /// external source should take care not to introduce the same instantiations
321 /// repeatedly.
322 virtual void ReadPendingInstantiations(
323 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending);
324
Richard Smithac32d902013-08-07 21:41:30 +0000325 /// \brief Read the set of late parsed template functions for this source.
326 ///
327 /// The external source should insert its own late parsed template functions
328 /// into the map. Note that this routine may be invoked multiple times; the
329 /// external source should take care not to introduce the same map entries
330 /// repeatedly.
331 virtual void ReadLateParsedTemplates(
332 llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap);
333
Kaelyn Uhrain70571f42013-08-12 19:54:38 +0000334 /// \copydoc ExternalSemaSource::CorrectTypo
335 /// \note Returns the first nonempty correction.
336 virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
337 int LookupKind, Scope *S, CXXScopeSpec *SS,
338 CorrectionCandidateCallback &CCC,
339 DeclContext *MemberContext,
340 bool EnteringContext,
341 const ObjCObjectPointerType *OPT);
342
Kaelyn Uhrain5d937b32013-08-12 22:11:14 +0000343 /// \brief Produces a diagnostic note if one of the attached sources
344 /// contains a complete definition for \p T. Queries the sources in list
345 /// order until the first one claims that a diagnostic was produced.
346 ///
347 /// \param Loc the location at which a complete type was required but not
348 /// provided
349 ///
350 /// \param T the \c QualType that should have been complete at \p Loc
351 ///
352 /// \return true if a diagnostic was produced, false otherwise.
353 virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T);
354
Axel Naumann0ec56b72012-10-18 19:05:02 +0000355 // isa/cast/dyn_cast support
356 static bool classof(const MultiplexExternalSemaSource*) { return true; }
357 //static bool classof(const ExternalSemaSource*) { return true; }
358};
359
360} // end namespace clang
361
362#endif // LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H