1 //===--- MultiplexExternalSemaSource.h - External Sema Interface-*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines ExternalSemaSource interface, dispatching to all clients
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
14 #define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
16 #include "clang/Sema/ExternalSemaSource.h"
17 #include "clang/Sema/Weak.h"
18 #include "llvm/ADT/SmallVector.h"
23 class CXXConstructorDecl;
26 struct ExternalVTableUse;
31 class TypedefNameDecl;
36 /// \brief An abstract interface that should be implemented by
37 /// external AST sources that also provide information for semantic
39 class MultiplexExternalSemaSource : public ExternalSemaSource {
42 SmallVector<ExternalSemaSource *, 2> Sources; // doesn't own them.
46 ///\brief Constructs a new multiplexing external sema source and appends the
47 /// given element to it.
49 ///\param[in] s1 - A non-null (old) ExternalSemaSource.
50 ///\param[in] s2 - A non-null (new) ExternalSemaSource.
52 MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2);
54 ~MultiplexExternalSemaSource() override;
56 ///\brief Appends new source to the source list.
58 ///\param[in] source - An ExternalSemaSource.
60 void addSource(ExternalSemaSource &source);
62 //===--------------------------------------------------------------------===//
64 //===--------------------------------------------------------------------===//
66 /// \brief Resolve a declaration ID into a declaration, potentially
67 /// building a new declaration.
68 Decl *GetExternalDecl(uint32_t ID) override;
70 /// \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;
74 /// \brief Resolve a selector ID into a selector.
75 Selector GetExternalSelector(uint32_t ID) override;
77 /// \brief Returns the number of selectors known to the external AST
79 uint32_t GetNumExternalSelectors() override;
81 /// \brief Resolve the offset of a statement in the decl stream into
83 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
85 /// \brief Resolve the offset of a set of C++ base specifiers in the decl
86 /// stream into an array of specifiers.
87 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
89 /// \brief Resolve a handle to a list of ctor initializers into the list of
90 /// initializers themselves.
91 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
93 ExtKind hasExternalDefinitions(const Decl *D) override;
95 /// \brief Find all declarations with the given name in the
97 bool FindExternalVisibleDeclsByName(const DeclContext *DC,
98 DeclarationName Name) override;
100 /// \brief Ensures that the table of all visible declarations inside this
101 /// context is up to date.
102 void completeVisibleDeclsMap(const DeclContext *DC) override;
104 /// \brief Finds all declarations lexically contained within the given
105 /// DeclContext, after applying an optional filter predicate.
107 /// \param IsKindWeWant a predicate function that returns true if the passed
108 /// declaration kind is one we are looking for.
110 FindExternalLexicalDecls(const DeclContext *DC,
111 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
112 SmallVectorImpl<Decl *> &Result) override;
114 /// \brief Get the decls that are contained in a file in the Offset/Length
115 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
117 void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
118 SmallVectorImpl<Decl *> &Decls) override;
120 /// \brief Gives the external AST source an opportunity to complete
121 /// an incomplete type.
122 void CompleteType(TagDecl *Tag) override;
124 /// \brief Gives the external AST source an opportunity to complete an
125 /// incomplete Objective-C class.
127 /// This routine will only be invoked if the "externally completed" bit is
128 /// set on the ObjCInterfaceDecl via the function
129 /// \c ObjCInterfaceDecl::setExternallyCompleted().
130 void CompleteType(ObjCInterfaceDecl *Class) override;
132 /// \brief Loads comment ranges.
133 void ReadComments() override;
135 /// \brief Notify ExternalASTSource that we started deserialization of
136 /// a decl or type so until FinishedDeserializing is called there may be
137 /// decls that are initializing. Must be paired with FinishedDeserializing.
138 void StartedDeserializing() override;
140 /// \brief Notify ExternalASTSource that we finished the deserialization of
141 /// a decl or type. Must be paired with StartedDeserializing.
142 void FinishedDeserializing() override;
144 /// \brief Function that will be invoked when we begin parsing a new
145 /// translation unit involving this external AST source.
146 void StartTranslationUnit(ASTConsumer *Consumer) override;
148 /// \brief Print any statistics that have been gathered regarding
149 /// the external AST source.
150 void PrintStats() override;
153 /// \brief Perform layout on the given record.
155 /// This routine allows the external AST source to provide an specific
156 /// layout for a record, overriding the layout that would normally be
157 /// constructed. It is intended for clients who receive specific layout
158 /// details rather than source code (such as LLDB). The client is expected
159 /// to fill in the field offsets, base offsets, virtual base offsets, and
160 /// complete object size.
162 /// \param Record The record whose layout is being requested.
164 /// \param Size The final size of the record, in bits.
166 /// \param Alignment The final alignment of the record, in bits.
168 /// \param FieldOffsets The offset of each of the fields within the record,
169 /// expressed in bits. All of the fields must be provided with offsets.
171 /// \param BaseOffsets The offset of each of the direct, non-virtual base
172 /// classes. If any bases are not given offsets, the bases will be laid
173 /// out according to the ABI.
175 /// \param VirtualBaseOffsets The offset of each of the virtual base classes
176 /// (either direct or not). If any bases are not given offsets, the bases will
177 /// be laid out according to the ABI.
179 /// \returns true if the record layout was provided, false otherwise.
181 layoutRecordType(const RecordDecl *Record,
182 uint64_t &Size, uint64_t &Alignment,
183 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
184 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
185 llvm::DenseMap<const CXXRecordDecl *,
186 CharUnits> &VirtualBaseOffsets) override;
188 /// Return the amount of memory used by memory buffers, breaking down
189 /// by heap-backed versus mmap'ed memory.
190 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
192 //===--------------------------------------------------------------------===//
193 // ExternalSemaSource.
194 //===--------------------------------------------------------------------===//
196 /// \brief Initialize the semantic source with the Sema instance
197 /// being used to perform semantic analysis on the abstract syntax
199 void InitializeSema(Sema &S) override;
201 /// \brief Inform the semantic consumer that Sema is no longer available.
202 void ForgetSema() override;
204 /// \brief Load the contents of the global method pool for a given
206 void ReadMethodPool(Selector Sel) override;
208 /// Load the contents of the global method pool for a given
209 /// selector if necessary.
210 void updateOutOfDateSelector(Selector Sel) override;
212 /// \brief Load the set of namespaces that are known to the external source,
213 /// which will be used during typo correction.
215 ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override;
217 /// \brief Load the set of used but not defined functions or variables with
218 /// internal linkage, or used but not defined inline functions.
219 void ReadUndefinedButUsed(
220 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
222 void ReadMismatchingDeleteExpressions(llvm::MapVector<
223 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
226 /// \brief Do last resort, unqualified lookup on a LookupResult that
227 /// Sema cannot find.
229 /// \param R a LookupResult that is being recovered.
231 /// \param S the Scope of the identifier occurrence.
233 /// \return true to tell Sema to recover using the LookupResult.
234 bool LookupUnqualified(LookupResult &R, Scope *S) override;
236 /// \brief Read the set of tentative definitions known to the external Sema
239 /// The external source should append its own tentative definitions to the
240 /// given vector of tentative definitions. Note that this routine may be
241 /// invoked multiple times; the external source should take care not to
242 /// introduce the same declarations repeatedly.
243 void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override;
245 /// \brief Read the set of unused file-scope declarations known to the
246 /// external Sema source.
248 /// The external source should append its own unused, filed-scope to the
249 /// given vector of declarations. Note that this routine may be
250 /// invoked multiple times; the external source should take care not to
251 /// introduce the same declarations repeatedly.
252 void ReadUnusedFileScopedDecls(
253 SmallVectorImpl<const DeclaratorDecl*> &Decls) override;
255 /// \brief Read the set of delegating constructors known to the
256 /// external Sema source.
258 /// The external source should append its own delegating constructors to the
259 /// given vector of declarations. Note that this routine may be
260 /// invoked multiple times; the external source should take care not to
261 /// introduce the same declarations repeatedly.
262 void ReadDelegatingConstructors(
263 SmallVectorImpl<CXXConstructorDecl*> &Decls) override;
265 /// \brief Read the set of ext_vector type declarations known to the
266 /// external Sema source.
268 /// The external source should append its own ext_vector type declarations to
269 /// the given vector of declarations. Note that this routine may be
270 /// invoked multiple times; the external source should take care not to
271 /// introduce the same declarations repeatedly.
272 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override;
274 /// \brief Read the set of potentially unused typedefs known to the source.
276 /// The external source should append its own potentially unused local
277 /// typedefs to the given vector of declarations. Note that this routine may
278 /// be invoked multiple times; the external source should take care not to
279 /// introduce the same declarations repeatedly.
280 void ReadUnusedLocalTypedefNameCandidates(
281 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
283 /// \brief Read the set of referenced selectors known to the
284 /// external Sema source.
286 /// The external source should append its own referenced selectors to the
287 /// given vector of selectors. Note that this routine
288 /// may be invoked multiple times; the external source should take care not
289 /// to introduce the same selectors repeatedly.
290 void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
291 SourceLocation> > &Sels) override;
293 /// \brief Read the set of weak, undeclared identifiers known to the
294 /// external Sema source.
296 /// The external source should append its own weak, undeclared identifiers to
297 /// the given vector. Note that this routine may be invoked multiple times;
298 /// the external source should take care not to introduce the same identifiers
300 void ReadWeakUndeclaredIdentifiers(
301 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
303 /// \brief Read the set of used vtables known to the external Sema source.
305 /// The external source should append its own used vtables to the given
306 /// vector. Note that this routine may be invoked multiple times; the external
307 /// source should take care not to introduce the same vtables repeatedly.
308 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
310 /// \brief Read the set of pending instantiations known to the external
313 /// The external source should append its own pending instantiations to the
314 /// given vector. Note that this routine may be invoked multiple times; the
315 /// external source should take care not to introduce the same instantiations
317 void ReadPendingInstantiations(
318 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
320 /// \brief Read the set of late parsed template functions for this source.
322 /// The external source should insert its own late parsed template functions
323 /// into the map. Note that this routine may be invoked multiple times; the
324 /// external source should take care not to introduce the same map entries
326 void ReadLateParsedTemplates(
327 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
330 /// \copydoc ExternalSemaSource::CorrectTypo
331 /// \note Returns the first nonempty correction.
332 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
333 int LookupKind, Scope *S, CXXScopeSpec *SS,
334 CorrectionCandidateCallback &CCC,
335 DeclContext *MemberContext,
336 bool EnteringContext,
337 const ObjCObjectPointerType *OPT) override;
339 /// \brief Produces a diagnostic note if one of the attached sources
340 /// contains a complete definition for \p T. Queries the sources in list
341 /// order until the first one claims that a diagnostic was produced.
343 /// \param Loc the location at which a complete type was required but not
346 /// \param T the \c QualType that should have been complete at \p Loc
348 /// \return true if a diagnostic was produced, false otherwise.
349 bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
350 QualType T) override;
352 // isa/cast/dyn_cast support
353 static bool classof(const MultiplexExternalSemaSource*) { return true; }
354 //static bool classof(const ExternalSemaSource*) { return true; }
357 } // end namespace clang