blob: 5f717891032e4ad6bc5dc101001faf671e6ff85f [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//===----------------------------------------------------------------------===//
Stephen Hines176edba2014-12-01 14:53:08 -080013#ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
14#define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
Axel Naumann0ec56b72012-10-18 19:05:02 +000015
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.
Stephen Hines651f13c2014-04-23 16:59:28 -070068 Decl *GetExternalDecl(uint32_t ID) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +000069
Stephen Hines6bcf27b2014-05-29 04:14:42 -070070 /// \brief Complete the redeclaration chain if it's been extended since the
71 /// previous generation of the AST source.
72 void CompleteRedeclChain(const Decl *D) override;
73
Axel Naumann0ec56b72012-10-18 19:05:02 +000074 /// \brief Resolve a selector ID into a selector.
Stephen Hines651f13c2014-04-23 16:59:28 -070075 Selector GetExternalSelector(uint32_t ID) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +000076
77 /// \brief Returns the number of selectors known to the external AST
78 /// source.
Stephen Hines651f13c2014-04-23 16:59:28 -070079 uint32_t GetNumExternalSelectors() override;
Axel Naumann0ec56b72012-10-18 19:05:02 +000080
81 /// \brief Resolve the offset of a statement in the decl stream into
82 /// a statement.
Stephen Hines651f13c2014-04-23 16:59:28 -070083 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +000084
85 /// \brief Resolve the offset of a set of C++ base specifiers in the decl
86 /// stream into an array of specifiers.
Stephen Hines651f13c2014-04-23 16:59:28 -070087 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +000088
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070089 /// \brief Resolve a handle to a list of ctor initializers into the list of
90 /// initializers themselves.
91 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
92
Richard Smith3646c682013-02-07 03:30:24 +000093 /// \brief Find all declarations with the given name in the
Axel Naumann0ec56b72012-10-18 19:05:02 +000094 /// given context.
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070095 bool FindExternalVisibleDeclsByName(const DeclContext *DC,
96 DeclarationName Name) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +000097
98 /// \brief Ensures that the table of all visible declarations inside this
99 /// context is up to date.
Stephen Hines651f13c2014-04-23 16:59:28 -0700100 void completeVisibleDeclsMap(const DeclContext *DC) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000101
102 /// \brief Finds all declarations lexically contained within the given
103 /// DeclContext, after applying an optional filter predicate.
104 ///
105 /// \param isKindWeWant a predicate function that returns true if the passed
106 /// declaration kind is one we are looking for. If NULL, all declarations
107 /// are returned.
108 ///
109 /// \return an indication of whether the load succeeded or failed.
Stephen Hines651f13c2014-04-23 16:59:28 -0700110 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
111 bool (*isKindWeWant)(Decl::Kind),
112 SmallVectorImpl<Decl*> &Result) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000113
114 /// \brief Finds all declarations lexically contained within the given
115 /// DeclContext.
116 ///
117 /// \return true if an error occurred
118 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
119 SmallVectorImpl<Decl*> &Result) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700120 return FindExternalLexicalDecls(DC, nullptr, Result);
Axel Naumann0ec56b72012-10-18 19:05:02 +0000121 }
122
123 template <typename DeclTy>
124 ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
125 SmallVectorImpl<Decl*> &Result) {
126 return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
127 }
128
129 /// \brief Get the decls that are contained in a file in the Offset/Length
130 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
131 /// a range.
Stephen Hines651f13c2014-04-23 16:59:28 -0700132 void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
133 SmallVectorImpl<Decl *> &Decls) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000134
135 /// \brief Gives the external AST source an opportunity to complete
136 /// an incomplete type.
Stephen Hines651f13c2014-04-23 16:59:28 -0700137 void CompleteType(TagDecl *Tag) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000138
139 /// \brief Gives the external AST source an opportunity to complete an
140 /// incomplete Objective-C class.
141 ///
142 /// This routine will only be invoked if the "externally completed" bit is
143 /// set on the ObjCInterfaceDecl via the function
144 /// \c ObjCInterfaceDecl::setExternallyCompleted().
Stephen Hines651f13c2014-04-23 16:59:28 -0700145 void CompleteType(ObjCInterfaceDecl *Class) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000146
147 /// \brief Loads comment ranges.
Stephen Hines651f13c2014-04-23 16:59:28 -0700148 void ReadComments() override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000149
150 /// \brief Notify ExternalASTSource that we started deserialization of
151 /// a decl or type so until FinishedDeserializing is called there may be
152 /// decls that are initializing. Must be paired with FinishedDeserializing.
Stephen Hines651f13c2014-04-23 16:59:28 -0700153 void StartedDeserializing() override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000154
155 /// \brief Notify ExternalASTSource that we finished the deserialization of
156 /// a decl or type. Must be paired with StartedDeserializing.
Stephen Hines651f13c2014-04-23 16:59:28 -0700157 void FinishedDeserializing() override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000158
159 /// \brief Function that will be invoked when we begin parsing a new
160 /// translation unit involving this external AST source.
Stephen Hines651f13c2014-04-23 16:59:28 -0700161 void StartTranslationUnit(ASTConsumer *Consumer) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000162
163 /// \brief Print any statistics that have been gathered regarding
164 /// the external AST source.
Stephen Hines651f13c2014-04-23 16:59:28 -0700165 void PrintStats() override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000166
167
168 /// \brief Perform layout on the given record.
169 ///
170 /// This routine allows the external AST source to provide an specific
171 /// layout for a record, overriding the layout that would normally be
172 /// constructed. It is intended for clients who receive specific layout
173 /// details rather than source code (such as LLDB). The client is expected
174 /// to fill in the field offsets, base offsets, virtual base offsets, and
175 /// complete object size.
176 ///
177 /// \param Record The record whose layout is being requested.
178 ///
179 /// \param Size The final size of the record, in bits.
180 ///
181 /// \param Alignment The final alignment of the record, in bits.
182 ///
183 /// \param FieldOffsets The offset of each of the fields within the record,
184 /// expressed in bits. All of the fields must be provided with offsets.
185 ///
186 /// \param BaseOffsets The offset of each of the direct, non-virtual base
187 /// classes. If any bases are not given offsets, the bases will be laid
188 /// out according to the ABI.
189 ///
190 /// \param VirtualBaseOffsets The offset of each of the virtual base classes
191 /// (either direct or not). If any bases are not given offsets, the bases will
192 /// be laid out according to the ABI.
193 ///
194 /// \returns true if the record layout was provided, false otherwise.
Stephen Hines651f13c2014-04-23 16:59:28 -0700195 bool
Axel Naumann0ec56b72012-10-18 19:05:02 +0000196 layoutRecordType(const RecordDecl *Record,
197 uint64_t &Size, uint64_t &Alignment,
198 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
199 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
Stephen Hines651f13c2014-04-23 16:59:28 -0700200 llvm::DenseMap<const CXXRecordDecl *,
201 CharUnits> &VirtualBaseOffsets) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000202
203 /// Return the amount of memory used by memory buffers, breaking down
204 /// by heap-backed versus mmap'ed memory.
Stephen Hines651f13c2014-04-23 16:59:28 -0700205 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000206
207 //===--------------------------------------------------------------------===//
208 // ExternalSemaSource.
209 //===--------------------------------------------------------------------===//
210
211 /// \brief Initialize the semantic source with the Sema instance
212 /// being used to perform semantic analysis on the abstract syntax
213 /// tree.
Stephen Hines651f13c2014-04-23 16:59:28 -0700214 void InitializeSema(Sema &S) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000215
216 /// \brief Inform the semantic consumer that Sema is no longer available.
Stephen Hines651f13c2014-04-23 16:59:28 -0700217 void ForgetSema() override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000218
219 /// \brief Load the contents of the global method pool for a given
220 /// selector.
Stephen Hines651f13c2014-04-23 16:59:28 -0700221 void ReadMethodPool(Selector Sel) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000222
223 /// \brief Load the set of namespaces that are known to the external source,
224 /// which will be used during typo correction.
Stephen Hines651f13c2014-04-23 16:59:28 -0700225 void
226 ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override;
Nick Lewycky01a41142013-01-26 00:35:08 +0000227
Nick Lewyckycd0655b2013-02-01 08:13:20 +0000228 /// \brief Load the set of used but not defined functions or variables with
229 /// internal linkage, or used but not defined inline functions.
Stephen Hines651f13c2014-04-23 16:59:28 -0700230 void ReadUndefinedButUsed(
231 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined) override;
232
Axel Naumann0ec56b72012-10-18 19:05:02 +0000233 /// \brief Do last resort, unqualified lookup on a LookupResult that
234 /// Sema cannot find.
235 ///
236 /// \param R a LookupResult that is being recovered.
237 ///
238 /// \param S the Scope of the identifier occurrence.
239 ///
240 /// \return true to tell Sema to recover using the LookupResult.
Stephen Hines651f13c2014-04-23 16:59:28 -0700241 bool LookupUnqualified(LookupResult &R, Scope *S) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000242
243 /// \brief Read the set of tentative definitions known to the external Sema
244 /// source.
245 ///
246 /// The external source should append its own tentative definitions to the
247 /// given vector of tentative definitions. Note that this routine may be
248 /// invoked multiple times; the external source should take care not to
249 /// introduce the same declarations repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700250 void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override;
251
Axel Naumann0ec56b72012-10-18 19:05:02 +0000252 /// \brief Read the set of unused file-scope declarations known to the
253 /// external Sema source.
254 ///
255 /// The external source should append its own unused, filed-scope 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.
Stephen Hines651f13c2014-04-23 16:59:28 -0700259 void ReadUnusedFileScopedDecls(
260 SmallVectorImpl<const DeclaratorDecl*> &Decls) override;
261
Axel Naumann0ec56b72012-10-18 19:05:02 +0000262 /// \brief Read the set of delegating constructors known to the
263 /// external Sema source.
264 ///
265 /// The external source should append its own delegating constructors to the
266 /// 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.
Stephen Hines651f13c2014-04-23 16:59:28 -0700269 void ReadDelegatingConstructors(
270 SmallVectorImpl<CXXConstructorDecl*> &Decls) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000271
272 /// \brief Read the set of ext_vector type declarations known to the
273 /// external Sema source.
274 ///
275 /// The external source should append its own ext_vector type declarations to
276 /// the given vector of declarations. Note that this routine may be
277 /// invoked multiple times; the external source should take care not to
278 /// introduce the same declarations repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700279 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000280
Stephen Hines176edba2014-12-01 14:53:08 -0800281 /// \brief Read the set of potentially unused typedefs known to the source.
282 ///
283 /// The external source should append its own potentially unused local
284 /// typedefs to the given vector of declarations. Note that this routine may
285 /// be invoked multiple times; the external source should take care not to
286 /// introduce the same declarations repeatedly.
287 void ReadUnusedLocalTypedefNameCandidates(
288 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
289
Axel Naumann0ec56b72012-10-18 19:05:02 +0000290 /// \brief Read the set of referenced selectors known to the
291 /// external Sema source.
292 ///
293 /// The external source should append its own referenced selectors to the
294 /// given vector of selectors. Note that this routine
295 /// may be invoked multiple times; the external source should take care not
296 /// to introduce the same selectors repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700297 void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
298 SourceLocation> > &Sels) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000299
300 /// \brief Read the set of weak, undeclared identifiers known to the
301 /// external Sema source.
302 ///
303 /// The external source should append its own weak, undeclared identifiers to
304 /// the given vector. Note that this routine may be invoked multiple times;
305 /// the external source should take care not to introduce the same identifiers
306 /// repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700307 void ReadWeakUndeclaredIdentifiers(
308 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000309
310 /// \brief Read the set of used vtables known to the external Sema source.
311 ///
312 /// The external source should append its own used vtables to the given
313 /// vector. Note that this routine may be invoked multiple times; the external
314 /// source should take care not to introduce the same vtables repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700315 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000316
317 /// \brief Read the set of pending instantiations known to the external
318 /// Sema source.
319 ///
320 /// The external source should append its own pending instantiations to the
321 /// given vector. Note that this routine may be invoked multiple times; the
322 /// external source should take care not to introduce the same instantiations
323 /// repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700324 void ReadPendingInstantiations(
325 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
Axel Naumann0ec56b72012-10-18 19:05:02 +0000326
Richard Smithac32d902013-08-07 21:41:30 +0000327 /// \brief Read the set of late parsed template functions for this source.
328 ///
329 /// The external source should insert its own late parsed template functions
330 /// into the map. Note that this routine may be invoked multiple times; the
331 /// external source should take care not to introduce the same map entries
332 /// repeatedly.
Stephen Hines651f13c2014-04-23 16:59:28 -0700333 void ReadLateParsedTemplates(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700334 llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap)
335 override;
Richard Smithac32d902013-08-07 21:41:30 +0000336
Kaelyn Uhrain70571f42013-08-12 19:54:38 +0000337 /// \copydoc ExternalSemaSource::CorrectTypo
338 /// \note Returns the first nonempty correction.
Stephen Hines651f13c2014-04-23 16:59:28 -0700339 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
340 int LookupKind, Scope *S, CXXScopeSpec *SS,
341 CorrectionCandidateCallback &CCC,
342 DeclContext *MemberContext,
343 bool EnteringContext,
344 const ObjCObjectPointerType *OPT) override;
Kaelyn Uhrain70571f42013-08-12 19:54:38 +0000345
Kaelyn Uhrain5d937b32013-08-12 22:11:14 +0000346 /// \brief Produces a diagnostic note if one of the attached sources
347 /// contains a complete definition for \p T. Queries the sources in list
348 /// order until the first one claims that a diagnostic was produced.
349 ///
350 /// \param Loc the location at which a complete type was required but not
351 /// provided
352 ///
353 /// \param T the \c QualType that should have been complete at \p Loc
354 ///
355 /// \return true if a diagnostic was produced, false otherwise.
Stephen Hines651f13c2014-04-23 16:59:28 -0700356 bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
357 QualType T) override;
Kaelyn Uhrain5d937b32013-08-12 22:11:14 +0000358
Axel Naumann0ec56b72012-10-18 19:05:02 +0000359 // isa/cast/dyn_cast support
360 static bool classof(const MultiplexExternalSemaSource*) { return true; }
361 //static bool classof(const ExternalSemaSource*) { return true; }
362};
363
364} // end namespace clang
365
Stephen Hines176edba2014-12-01 14:53:08 -0800366#endif