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_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H
14 #define LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_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();
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 virtual Decl *GetExternalDecl(uint32_t ID);
70 /// \brief Resolve a selector ID into a selector.
71 virtual Selector GetExternalSelector(uint32_t ID);
73 /// \brief Returns the number of selectors known to the external AST
75 virtual uint32_t GetNumExternalSelectors();
77 /// \brief Resolve the offset of a statement in the decl stream into
79 virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
81 /// \brief Resolve the offset of a set of C++ base specifiers in the decl
82 /// stream into an array of specifiers.
83 virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
85 /// \brief Find all declarations with the given name in the
88 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
90 /// \brief Ensures that the table of all visible declarations inside this
91 /// context is up to date.
92 virtual void completeVisibleDeclsMap(const DeclContext *DC);
94 /// \brief Finds all declarations lexically contained within the given
95 /// DeclContext, after applying an optional filter predicate.
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
101 /// \return an indication of whether the load succeeded or failed.
102 virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
103 bool (*isKindWeWant)(Decl::Kind),
104 SmallVectorImpl<Decl*> &Result);
106 /// \brief Finds all declarations lexically contained within the given
109 /// \return true if an error occurred
110 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
111 SmallVectorImpl<Decl*> &Result) {
112 return FindExternalLexicalDecls(DC, 0, Result);
115 template <typename DeclTy>
116 ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC,
117 SmallVectorImpl<Decl*> &Result) {
118 return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
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
124 virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
125 SmallVectorImpl<Decl *> &Decls);
127 /// \brief Gives the external AST source an opportunity to complete
128 /// an incomplete type.
129 virtual void CompleteType(TagDecl *Tag);
131 /// \brief Gives the external AST source an opportunity to complete an
132 /// incomplete Objective-C class.
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);
139 /// \brief Loads comment ranges.
140 virtual void ReadComments();
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.
145 virtual void StartedDeserializing();
147 /// \brief Notify ExternalASTSource that we finished the deserialization of
148 /// a decl or type. Must be paired with StartedDeserializing.
149 virtual void FinishedDeserializing();
151 /// \brief Function that will be invoked when we begin parsing a new
152 /// translation unit involving this external AST source.
153 virtual void StartTranslationUnit(ASTConsumer *Consumer);
155 /// \brief Print any statistics that have been gathered regarding
156 /// the external AST source.
157 virtual void PrintStats();
160 /// \brief Perform layout on the given record.
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.
169 /// \param Record The record whose layout is being requested.
171 /// \param Size The final size of the record, in bits.
173 /// \param Alignment The final alignment of the record, in bits.
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.
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.
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.
186 /// \returns true if the record layout was provided, false otherwise.
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);
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;
198 //===--------------------------------------------------------------------===//
199 // ExternalSemaSource.
200 //===--------------------------------------------------------------------===//
202 /// \brief Initialize the semantic source with the Sema instance
203 /// being used to perform semantic analysis on the abstract syntax
205 virtual void InitializeSema(Sema &S);
207 /// \brief Inform the semantic consumer that Sema is no longer available.
208 virtual void ForgetSema();
210 /// \brief Load the contents of the global method pool for a given
212 virtual void ReadMethodPool(Selector Sel);
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);
218 /// \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(
221 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined);
223 /// \brief Do last resort, unqualified lookup on a LookupResult that
224 /// Sema cannot find.
226 /// \param R a LookupResult that is being recovered.
228 /// \param S the Scope of the identifier occurrence.
230 /// \return true to tell Sema to recover using the LookupResult.
231 virtual bool LookupUnqualified(LookupResult &R, Scope *S);
233 /// \brief Read the set of tentative definitions known to the external Sema
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);
242 /// \brief Read the set of unused file-scope declarations known to the
243 /// external Sema source.
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);
252 /// \brief Read the set of delegating constructors known to the
253 /// external Sema source.
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);
262 /// \brief Read the set of ext_vector type declarations known to the
263 /// external Sema source.
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);
271 /// \brief Read the set of dynamic classes known to the external Sema source.
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);
279 /// \brief Read the set of locally-scoped extern "C" declarations known to the
280 /// external Sema source.
282 /// The external source should append its own locally-scoped external
283 /// declarations to the given vector of declarations. Note that this routine
284 /// may be invoked multiple times; the external source should take care not
285 /// to introduce the same declarations repeatedly.
286 virtual void ReadLocallyScopedExternCDecls(SmallVectorImpl<NamedDecl*>&Decls);
288 /// \brief Read the set of referenced selectors known to the
289 /// external Sema source.
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);
298 /// \brief Read the set of weak, undeclared identifiers known to the
299 /// external Sema source.
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
305 virtual void ReadWeakUndeclaredIdentifiers(
306 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI);
308 /// \brief Read the set of used vtables known to the external Sema source.
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);
315 /// \brief Read the set of pending instantiations known to the external
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
322 virtual void ReadPendingInstantiations(
323 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending);
325 /// \brief Read the set of late parsed template functions for this source.
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
331 virtual void ReadLateParsedTemplates(
332 llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap);
334 /// \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);
343 /// \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.
347 /// \param Loc the location at which a complete type was required but not
350 /// \param T the \c QualType that should have been complete at \p Loc
352 /// \return true if a diagnostic was produced, false otherwise.
353 virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, QualType T);
355 // isa/cast/dyn_cast support
356 static bool classof(const MultiplexExternalSemaSource*) { return true; }
357 //static bool classof(const ExternalSemaSource*) { return true; }
360 } // end namespace clang
362 #endif // LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H