blob: 32b7276c83a1f42f3491260f6df2d6e280ef40d4 [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.
68 ///
69 /// This method only needs to be implemented if the AST source ever
70 /// passes back decl sets as VisibleDeclaration objects.
71 ///
72 /// The default implementation of this method is a no-op.
73 virtual Decl *GetExternalDecl(uint32_t ID);
74
75 /// \brief Resolve a selector ID into a selector.
76 ///
77 /// This operation only needs to be implemented if the AST source
78 /// returns non-zero for GetNumKnownSelectors().
79 ///
80 /// The default implementation of this method is a no-op.
81 virtual Selector GetExternalSelector(uint32_t ID);
82
83 /// \brief Returns the number of selectors known to the external AST
84 /// source.
85 ///
86 /// The default implementation of this method is a no-op.
87 virtual uint32_t GetNumExternalSelectors();
88
89 /// \brief Resolve the offset of a statement in the decl stream into
90 /// a statement.
91 ///
92 /// This operation is meant to be used via a LazyOffsetPtr. It only
93 /// needs to be implemented if the AST source uses methods like
94 /// FunctionDecl::setLazyBody when building decls.
95 ///
96 /// The default implementation of this method is a no-op.
97 virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
98
99 /// \brief Resolve the offset of a set of C++ base specifiers in the decl
100 /// stream into an array of specifiers.
101 ///
102 /// The default implementation of this method is a no-op.
103 virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
104
105 /// \brief Finds all declarations with the given name in the
106 /// given context.
107 ///
108 /// Generally the final step of this method is either to call
109 /// SetExternalVisibleDeclsForName or to recursively call lookup on
110 /// the DeclContext after calling SetExternalVisibleDecls.
111 ///
112 /// The default implementation of this method is a no-op.
113 virtual DeclContextLookupResult
114 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
115
116 /// \brief Ensures that the table of all visible declarations inside this
117 /// context is up to date.
118 ///
119 /// The default implementation of this functino is a no-op.
120 virtual void completeVisibleDeclsMap(const DeclContext *DC);
121
122 /// \brief Finds all declarations lexically contained within the given
123 /// DeclContext, after applying an optional filter predicate.
124 ///
125 /// \param isKindWeWant a predicate function that returns true if the passed
126 /// declaration kind is one we are looking for. If NULL, all declarations
127 /// are returned.
128 ///
129 /// \return an indication of whether the load succeeded or failed.
130 ///
131 /// The default implementation of this method is a no-op.
132 virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
133 bool (*isKindWeWant)(Decl::Kind),
134 SmallVectorImpl<Decl*> &Result);
135
136 /// \brief Finds all declarations lexically contained within the given
137 /// DeclContext.
138 ///
139 /// \return true if an error occurred
140 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
141 SmallVectorImpl<Decl*> &Result) {
142 return FindExternalLexicalDecls(DC, 0, Result);
143 }
144
145 template <typename DeclTy>
146 ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
147 SmallVectorImpl<Decl*> &Result) {
148 return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
149 }
150
151 /// \brief Get the decls that are contained in a file in the Offset/Length
152 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
153 /// a range.
154 virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
155 SmallVectorImpl<Decl *> &Decls);
156
157 /// \brief Gives the external AST source an opportunity to complete
158 /// an incomplete type.
159 virtual void CompleteType(TagDecl *Tag);
160
161 /// \brief Gives the external AST source an opportunity to complete an
162 /// incomplete Objective-C class.
163 ///
164 /// This routine will only be invoked if the "externally completed" bit is
165 /// set on the ObjCInterfaceDecl via the function
166 /// \c ObjCInterfaceDecl::setExternallyCompleted().
167 virtual void CompleteType(ObjCInterfaceDecl *Class);
168
169 /// \brief Loads comment ranges.
170 virtual void ReadComments();
171
172 /// \brief Notify ExternalASTSource that we started deserialization of
173 /// a decl or type so until FinishedDeserializing is called there may be
174 /// decls that are initializing. Must be paired with FinishedDeserializing.
175 ///
176 /// The default implementation of this method is a no-op.
177 virtual void StartedDeserializing();
178
179 /// \brief Notify ExternalASTSource that we finished the deserialization of
180 /// a decl or type. Must be paired with StartedDeserializing.
181 ///
182 /// The default implementation of this method is a no-op.
183 virtual void FinishedDeserializing();
184
185 /// \brief Function that will be invoked when we begin parsing a new
186 /// translation unit involving this external AST source.
187 ///
188 /// The default implementation of this method is a no-op.
189 virtual void StartTranslationUnit(ASTConsumer *Consumer);
190
191 /// \brief Print any statistics that have been gathered regarding
192 /// the external AST source.
193 ///
194 /// The default implementation of this method is a no-op.
195 virtual void PrintStats();
196
197
198 /// \brief Perform layout on the given record.
199 ///
200 /// This routine allows the external AST source to provide an specific
201 /// layout for a record, overriding the layout that would normally be
202 /// constructed. It is intended for clients who receive specific layout
203 /// details rather than source code (such as LLDB). The client is expected
204 /// to fill in the field offsets, base offsets, virtual base offsets, and
205 /// complete object size.
206 ///
207 /// \param Record The record whose layout is being requested.
208 ///
209 /// \param Size The final size of the record, in bits.
210 ///
211 /// \param Alignment The final alignment of the record, in bits.
212 ///
213 /// \param FieldOffsets The offset of each of the fields within the record,
214 /// expressed in bits. All of the fields must be provided with offsets.
215 ///
216 /// \param BaseOffsets The offset of each of the direct, non-virtual base
217 /// classes. If any bases are not given offsets, the bases will be laid
218 /// out according to the ABI.
219 ///
220 /// \param VirtualBaseOffsets The offset of each of the virtual base classes
221 /// (either direct or not). If any bases are not given offsets, the bases will
222 /// be laid out according to the ABI.
223 ///
224 /// \returns true if the record layout was provided, false otherwise.
225 virtual bool
226 layoutRecordType(const RecordDecl *Record,
227 uint64_t &Size, uint64_t &Alignment,
228 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
229 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
230 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
231
232 /// Return the amount of memory used by memory buffers, breaking down
233 /// by heap-backed versus mmap'ed memory.
234 virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
235
236 //===--------------------------------------------------------------------===//
237 // ExternalSemaSource.
238 //===--------------------------------------------------------------------===//
239
240 /// \brief Initialize the semantic source with the Sema instance
241 /// being used to perform semantic analysis on the abstract syntax
242 /// tree.
243 virtual void InitializeSema(Sema &S);
244
245 /// \brief Inform the semantic consumer that Sema is no longer available.
246 virtual void ForgetSema();
247
248 /// \brief Load the contents of the global method pool for a given
249 /// selector.
250 virtual void ReadMethodPool(Selector Sel);
251
252 /// \brief Load the set of namespaces that are known to the external source,
253 /// which will be used during typo correction.
254 virtual void ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces);
Nick Lewycky01a41142013-01-26 00:35:08 +0000255
Nick Lewyckycd0655b2013-02-01 08:13:20 +0000256 /// \brief Load the set of used but not defined functions or variables with
257 /// internal linkage, or used but not defined inline functions.
258 virtual void ReadUndefinedButUsed(
Nick Lewycky995e26b2013-01-31 03:23:57 +0000259 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
Axel Naumann0ec56b72012-10-18 19:05:02 +0000260
261 /// \brief Do last resort, unqualified lookup on a LookupResult that
262 /// Sema cannot find.
263 ///
264 /// \param R a LookupResult that is being recovered.
265 ///
266 /// \param S the Scope of the identifier occurrence.
267 ///
268 /// \return true to tell Sema to recover using the LookupResult.
269 virtual bool LookupUnqualified(LookupResult &R, Scope *S);
270
271 /// \brief Read the set of tentative definitions known to the external Sema
272 /// source.
273 ///
274 /// The external source should append its own tentative definitions to the
275 /// given vector of tentative definitions. Note that this routine may be
276 /// invoked multiple times; the external source should take care not to
277 /// introduce the same declarations repeatedly.
278 virtual void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs);
279
280 /// \brief Read the set of unused file-scope declarations known to the
281 /// external Sema source.
282 ///
283 /// The external source should append its own unused, filed-scope to the
284 /// given vector of declarations. Note that this routine may be
285 /// invoked multiple times; the external source should take care not to
286 /// introduce the same declarations repeatedly.
287 virtual void ReadUnusedFileScopedDecls(
288 SmallVectorImpl<const DeclaratorDecl*> &Decls);
289
290 /// \brief Read the set of delegating constructors known to the
291 /// external Sema source.
292 ///
293 /// The external source should append its own delegating constructors to the
294 /// given vector of declarations. Note that this routine may be
295 /// invoked multiple times; the external source should take care not to
296 /// introduce the same declarations repeatedly.
297 virtual void ReadDelegatingConstructors(
298 SmallVectorImpl<CXXConstructorDecl*> &Decls);
299
300 /// \brief Read the set of ext_vector type declarations known to the
301 /// external Sema source.
302 ///
303 /// The external source should append its own ext_vector type declarations to
304 /// the given vector of declarations. Note that this routine may be
305 /// invoked multiple times; the external source should take care not to
306 /// introduce the same declarations repeatedly.
307 virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls);
308
309 /// \brief Read the set of dynamic classes known to the external Sema source.
310 ///
311 /// The external source should append its own dynamic classes to
312 /// the given vector of declarations. Note that this routine may be
313 /// invoked multiple times; the external source should take care not to
314 /// introduce the same declarations repeatedly.
315 virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl*> &Decls);
316
Richard Smith5ea6ef42013-01-10 23:43:47 +0000317 /// \brief Read the set of locally-scoped extern "C" declarations known to the
Axel Naumann0ec56b72012-10-18 19:05:02 +0000318 /// external Sema source.
319 ///
320 /// The external source should append its own locally-scoped external
Richard Smith5ea6ef42013-01-10 23:43:47 +0000321 /// declarations to the given vector of declarations. Note that this routine
322 /// may be invoked multiple times; the external source should take care not
Axel Naumann0ec56b72012-10-18 19:05:02 +0000323 /// to introduce the same declarations repeatedly.
Richard Smith5ea6ef42013-01-10 23:43:47 +0000324 virtual void ReadLocallyScopedExternCDecls(SmallVectorImpl<NamedDecl*>&Decls);
Axel Naumann0ec56b72012-10-18 19:05:02 +0000325
326 /// \brief Read the set of referenced selectors known to the
327 /// external Sema source.
328 ///
329 /// The external source should append its own referenced selectors to the
330 /// given vector of selectors. Note that this routine
331 /// may be invoked multiple times; the external source should take care not
332 /// to introduce the same selectors repeatedly.
333 virtual void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
334 SourceLocation> > &Sels);
335
336 /// \brief Read the set of weak, undeclared identifiers known to the
337 /// external Sema source.
338 ///
339 /// The external source should append its own weak, undeclared identifiers to
340 /// the given vector. Note that this routine may be invoked multiple times;
341 /// the external source should take care not to introduce the same identifiers
342 /// repeatedly.
343 virtual void ReadWeakUndeclaredIdentifiers(
344 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI);
345
346 /// \brief Read the set of used vtables known to the external Sema source.
347 ///
348 /// The external source should append its own used vtables to the given
349 /// vector. Note that this routine may be invoked multiple times; the external
350 /// source should take care not to introduce the same vtables repeatedly.
351 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
352
353 /// \brief Read the set of pending instantiations known to the external
354 /// Sema source.
355 ///
356 /// The external source should append its own pending instantiations to the
357 /// given vector. Note that this routine may be invoked multiple times; the
358 /// external source should take care not to introduce the same instantiations
359 /// repeatedly.
360 virtual void ReadPendingInstantiations(
361 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending);
362
363 // isa/cast/dyn_cast support
364 static bool classof(const MultiplexExternalSemaSource*) { return true; }
365 //static bool classof(const ExternalSemaSource*) { return true; }
366};
367
368} // end namespace clang
369
370#endif // LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H