MultiplexExternalSemaSource.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- MultiplexExternalSemaSource.h - External Sema Interface-*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines ExternalSemaSource interface, dispatching to all clients
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
  18. #define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H
  19. #include "clang/Sema/ExternalSemaSource.h"
  20. #include "clang/Sema/Weak.h"
  21. #include "llvm/ADT/SmallVector.h"
  22. #include <utility>
  23. namespace clang {
  24. class CXXConstructorDecl;
  25. class CXXRecordDecl;
  26. class DeclaratorDecl;
  27. struct ExternalVTableUse;
  28. class LookupResult;
  29. class NamespaceDecl;
  30. class Scope;
  31. class Sema;
  32. class TypedefNameDecl;
  33. class ValueDecl;
  34. class VarDecl;
  35. /// An abstract interface that should be implemented by
  36. /// external AST sources that also provide information for semantic
  37. /// analysis.
  38. class MultiplexExternalSemaSource : public ExternalSemaSource {
  39. /// LLVM-style RTTI.
  40. static char ID;
  41. private:
  42. SmallVector<ExternalSemaSource *, 2> Sources;
  43. public:
  44. /// Constructs a new multiplexing external sema source and appends the
  45. /// given element to it.
  46. ///
  47. ///\param[in] S1 - A non-null (old) ExternalSemaSource.
  48. ///\param[in] S2 - A non-null (new) ExternalSemaSource.
  49. ///
  50. MultiplexExternalSemaSource(ExternalSemaSource *S1, ExternalSemaSource *S2);
  51. ~MultiplexExternalSemaSource() override;
  52. /// Appends new source to the source list.
  53. ///
  54. ///\param[in] Source - An ExternalSemaSource.
  55. ///
  56. void AddSource(ExternalSemaSource *Source);
  57. //===--------------------------------------------------------------------===//
  58. // ExternalASTSource.
  59. //===--------------------------------------------------------------------===//
  60. /// Resolve a declaration ID into a declaration, potentially
  61. /// building a new declaration.
  62. Decl *GetExternalDecl(uint32_t ID) override;
  63. /// Complete the redeclaration chain if it's been extended since the
  64. /// previous generation of the AST source.
  65. void CompleteRedeclChain(const Decl *D) override;
  66. /// Resolve a selector ID into a selector.
  67. Selector GetExternalSelector(uint32_t ID) override;
  68. /// Returns the number of selectors known to the external AST
  69. /// source.
  70. uint32_t GetNumExternalSelectors() override;
  71. /// Resolve the offset of a statement in the decl stream into
  72. /// a statement.
  73. Stmt *GetExternalDeclStmt(uint64_t Offset) override;
  74. /// Resolve the offset of a set of C++ base specifiers in the decl
  75. /// stream into an array of specifiers.
  76. CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
  77. /// Resolve a handle to a list of ctor initializers into the list of
  78. /// initializers themselves.
  79. CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
  80. ExtKind hasExternalDefinitions(const Decl *D) override;
  81. /// Find all declarations with the given name in the
  82. /// given context.
  83. bool FindExternalVisibleDeclsByName(const DeclContext *DC,
  84. DeclarationName Name) override;
  85. /// Ensures that the table of all visible declarations inside this
  86. /// context is up to date.
  87. void completeVisibleDeclsMap(const DeclContext *DC) override;
  88. /// Finds all declarations lexically contained within the given
  89. /// DeclContext, after applying an optional filter predicate.
  90. ///
  91. /// \param IsKindWeWant a predicate function that returns true if the passed
  92. /// declaration kind is one we are looking for.
  93. void
  94. FindExternalLexicalDecls(const DeclContext *DC,
  95. llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
  96. SmallVectorImpl<Decl *> &Result) override;
  97. /// Get the decls that are contained in a file in the Offset/Length
  98. /// range. \p Length can be 0 to indicate a point at \p Offset instead of
  99. /// a range.
  100. void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
  101. SmallVectorImpl<Decl *> &Decls) override;
  102. /// Gives the external AST source an opportunity to complete
  103. /// an incomplete type.
  104. void CompleteType(TagDecl *Tag) override;
  105. /// Gives the external AST source an opportunity to complete an
  106. /// incomplete Objective-C class.
  107. ///
  108. /// This routine will only be invoked if the "externally completed" bit is
  109. /// set on the ObjCInterfaceDecl via the function
  110. /// \c ObjCInterfaceDecl::setExternallyCompleted().
  111. void CompleteType(ObjCInterfaceDecl *Class) override;
  112. /// Loads comment ranges.
  113. void ReadComments() override;
  114. /// Notify ExternalASTSource that we started deserialization of
  115. /// a decl or type so until FinishedDeserializing is called there may be
  116. /// decls that are initializing. Must be paired with FinishedDeserializing.
  117. void StartedDeserializing() override;
  118. /// Notify ExternalASTSource that we finished the deserialization of
  119. /// a decl or type. Must be paired with StartedDeserializing.
  120. void FinishedDeserializing() override;
  121. /// Function that will be invoked when we begin parsing a new
  122. /// translation unit involving this external AST source.
  123. void StartTranslationUnit(ASTConsumer *Consumer) override;
  124. /// Print any statistics that have been gathered regarding
  125. /// the external AST source.
  126. void PrintStats() override;
  127. /// Retrieve the module that corresponds to the given module ID.
  128. Module *getModule(unsigned ID) override;
  129. /// Perform layout on the given record.
  130. ///
  131. /// This routine allows the external AST source to provide an specific
  132. /// layout for a record, overriding the layout that would normally be
  133. /// constructed. It is intended for clients who receive specific layout
  134. /// details rather than source code (such as LLDB). The client is expected
  135. /// to fill in the field offsets, base offsets, virtual base offsets, and
  136. /// complete object size.
  137. ///
  138. /// \param Record The record whose layout is being requested.
  139. ///
  140. /// \param Size The final size of the record, in bits.
  141. ///
  142. /// \param Alignment The final alignment of the record, in bits.
  143. ///
  144. /// \param FieldOffsets The offset of each of the fields within the record,
  145. /// expressed in bits. All of the fields must be provided with offsets.
  146. ///
  147. /// \param BaseOffsets The offset of each of the direct, non-virtual base
  148. /// classes. If any bases are not given offsets, the bases will be laid
  149. /// out according to the ABI.
  150. ///
  151. /// \param VirtualBaseOffsets The offset of each of the virtual base classes
  152. /// (either direct or not). If any bases are not given offsets, the bases will
  153. /// be laid out according to the ABI.
  154. ///
  155. /// \returns true if the record layout was provided, false otherwise.
  156. bool
  157. layoutRecordType(const RecordDecl *Record,
  158. uint64_t &Size, uint64_t &Alignment,
  159. llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
  160. llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
  161. llvm::DenseMap<const CXXRecordDecl *,
  162. CharUnits> &VirtualBaseOffsets) override;
  163. /// Return the amount of memory used by memory buffers, breaking down
  164. /// by heap-backed versus mmap'ed memory.
  165. void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
  166. //===--------------------------------------------------------------------===//
  167. // ExternalSemaSource.
  168. //===--------------------------------------------------------------------===//
  169. /// Initialize the semantic source with the Sema instance
  170. /// being used to perform semantic analysis on the abstract syntax
  171. /// tree.
  172. void InitializeSema(Sema &S) override;
  173. /// Inform the semantic consumer that Sema is no longer available.
  174. void ForgetSema() override;
  175. /// Load the contents of the global method pool for a given
  176. /// selector.
  177. void ReadMethodPool(Selector Sel) override;
  178. /// Load the contents of the global method pool for a given
  179. /// selector if necessary.
  180. void updateOutOfDateSelector(Selector Sel) override;
  181. /// Load the set of namespaces that are known to the external source,
  182. /// which will be used during typo correction.
  183. void
  184. ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override;
  185. /// Load the set of used but not defined functions or variables with
  186. /// internal linkage, or used but not defined inline functions.
  187. void ReadUndefinedButUsed(
  188. llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
  189. void ReadMismatchingDeleteExpressions(llvm::MapVector<
  190. FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
  191. Exprs) override;
  192. /// Do last resort, unqualified lookup on a LookupResult that
  193. /// Sema cannot find.
  194. ///
  195. /// \param R a LookupResult that is being recovered.
  196. ///
  197. /// \param S the Scope of the identifier occurrence.
  198. ///
  199. /// \return true to tell Sema to recover using the LookupResult.
  200. bool LookupUnqualified(LookupResult &R, Scope *S) override;
  201. /// Read the set of tentative definitions known to the external Sema
  202. /// source.
  203. ///
  204. /// The external source should append its own tentative definitions to the
  205. /// given vector of tentative definitions. Note that this routine may be
  206. /// invoked multiple times; the external source should take care not to
  207. /// introduce the same declarations repeatedly.
  208. void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override;
  209. /// Read the set of unused file-scope declarations known to the
  210. /// external Sema source.
  211. ///
  212. /// The external source should append its own unused, filed-scope to the
  213. /// given vector of declarations. Note that this routine may be
  214. /// invoked multiple times; the external source should take care not to
  215. /// introduce the same declarations repeatedly.
  216. void ReadUnusedFileScopedDecls(
  217. SmallVectorImpl<const DeclaratorDecl*> &Decls) override;
  218. /// Read the set of delegating constructors known to the
  219. /// external Sema source.
  220. ///
  221. /// The external source should append its own delegating constructors to the
  222. /// given vector of declarations. Note that this routine may be
  223. /// invoked multiple times; the external source should take care not to
  224. /// introduce the same declarations repeatedly.
  225. void ReadDelegatingConstructors(
  226. SmallVectorImpl<CXXConstructorDecl*> &Decls) override;
  227. /// Read the set of ext_vector type declarations known to the
  228. /// external Sema source.
  229. ///
  230. /// The external source should append its own ext_vector type declarations to
  231. /// the given vector of declarations. Note that this routine may be
  232. /// invoked multiple times; the external source should take care not to
  233. /// introduce the same declarations repeatedly.
  234. void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override;
  235. /// Read the set of potentially unused typedefs known to the source.
  236. ///
  237. /// The external source should append its own potentially unused local
  238. /// typedefs to the given vector of declarations. Note that this routine may
  239. /// be invoked multiple times; the external source should take care not to
  240. /// introduce the same declarations repeatedly.
  241. void ReadUnusedLocalTypedefNameCandidates(
  242. llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
  243. /// Read the set of referenced selectors known to the
  244. /// external Sema source.
  245. ///
  246. /// The external source should append its own referenced selectors to the
  247. /// given vector of selectors. Note that this routine
  248. /// may be invoked multiple times; the external source should take care not
  249. /// to introduce the same selectors repeatedly.
  250. void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,
  251. SourceLocation> > &Sels) override;
  252. /// Read the set of weak, undeclared identifiers known to the
  253. /// external Sema source.
  254. ///
  255. /// The external source should append its own weak, undeclared identifiers to
  256. /// the given vector. Note that this routine may be invoked multiple times;
  257. /// the external source should take care not to introduce the same identifiers
  258. /// repeatedly.
  259. void ReadWeakUndeclaredIdentifiers(
  260. SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override;
  261. /// Read the set of used vtables known to the external Sema source.
  262. ///
  263. /// The external source should append its own used vtables to the given
  264. /// vector. Note that this routine may be invoked multiple times; the external
  265. /// source should take care not to introduce the same vtables repeatedly.
  266. void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
  267. /// Read the set of pending instantiations known to the external
  268. /// Sema source.
  269. ///
  270. /// The external source should append its own pending instantiations to the
  271. /// given vector. Note that this routine may be invoked multiple times; the
  272. /// external source should take care not to introduce the same instantiations
  273. /// repeatedly.
  274. void ReadPendingInstantiations(
  275. SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
  276. /// Read the set of late parsed template functions for this source.
  277. ///
  278. /// The external source should insert its own late parsed template functions
  279. /// into the map. Note that this routine may be invoked multiple times; the
  280. /// external source should take care not to introduce the same map entries
  281. /// repeatedly.
  282. void ReadLateParsedTemplates(
  283. llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
  284. &LPTMap) override;
  285. /// Read the set of decls to be checked for deferred diags.
  286. ///
  287. /// The external source should append its own potentially emitted function
  288. /// and variable decls which may cause deferred diags. Note that this routine
  289. /// may be invoked multiple times; the external source should take care not to
  290. /// introduce the same declarations repeatedly.
  291. void ReadDeclsToCheckForDeferredDiags(
  292. llvm::SmallSetVector<Decl *, 4> &Decls) override;
  293. /// \copydoc ExternalSemaSource::CorrectTypo
  294. /// \note Returns the first nonempty correction.
  295. TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
  296. int LookupKind, Scope *S, CXXScopeSpec *SS,
  297. CorrectionCandidateCallback &CCC,
  298. DeclContext *MemberContext,
  299. bool EnteringContext,
  300. const ObjCObjectPointerType *OPT) override;
  301. /// Produces a diagnostic note if one of the attached sources
  302. /// contains a complete definition for \p T. Queries the sources in list
  303. /// order until the first one claims that a diagnostic was produced.
  304. ///
  305. /// \param Loc the location at which a complete type was required but not
  306. /// provided
  307. ///
  308. /// \param T the \c QualType that should have been complete at \p Loc
  309. ///
  310. /// \return true if a diagnostic was produced, false otherwise.
  311. bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
  312. QualType T) override;
  313. /// LLVM-style RTTI.
  314. /// \{
  315. bool isA(const void *ClassID) const override {
  316. return ClassID == &ID || ExternalSemaSource::isA(ClassID);
  317. }
  318. static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
  319. /// \}
  320. };
  321. } // end namespace clang
  322. #endif
  323. #ifdef __GNUC__
  324. #pragma GCC diagnostic pop
  325. #endif