ExternalSemaSource.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- ExternalSemaSource.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 the ExternalSemaSource interface.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
  18. #define LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
  19. #include "clang/AST/ExternalASTSource.h"
  20. #include "clang/AST/Type.h"
  21. #include "clang/Sema/TypoCorrection.h"
  22. #include "clang/Sema/Weak.h"
  23. #include "llvm/ADT/MapVector.h"
  24. #include <utility>
  25. namespace llvm {
  26. template <class T, unsigned n> class SmallSetVector;
  27. }
  28. namespace clang {
  29. class CXXConstructorDecl;
  30. class CXXRecordDecl;
  31. class DeclaratorDecl;
  32. class LookupResult;
  33. class Scope;
  34. class Sema;
  35. class TypedefNameDecl;
  36. class ValueDecl;
  37. class VarDecl;
  38. struct LateParsedTemplate;
  39. /// A simple structure that captures a vtable use for the purposes of
  40. /// the \c ExternalSemaSource.
  41. struct ExternalVTableUse {
  42. CXXRecordDecl *Record;
  43. SourceLocation Location;
  44. bool DefinitionRequired;
  45. };
  46. /// An abstract interface that should be implemented by
  47. /// external AST sources that also provide information for semantic
  48. /// analysis.
  49. class ExternalSemaSource : public ExternalASTSource {
  50. /// LLVM-style RTTI.
  51. static char ID;
  52. public:
  53. ExternalSemaSource() = default;
  54. ~ExternalSemaSource() override;
  55. /// Initialize the semantic source with the Sema instance
  56. /// being used to perform semantic analysis on the abstract syntax
  57. /// tree.
  58. virtual void InitializeSema(Sema &S) {}
  59. /// Inform the semantic consumer that Sema is no longer available.
  60. virtual void ForgetSema() {}
  61. /// Load the contents of the global method pool for a given
  62. /// selector.
  63. virtual void ReadMethodPool(Selector Sel);
  64. /// Load the contents of the global method pool for a given
  65. /// selector if necessary.
  66. virtual void updateOutOfDateSelector(Selector Sel);
  67. /// Load the set of namespaces that are known to the external source,
  68. /// which will be used during typo correction.
  69. virtual void ReadKnownNamespaces(
  70. SmallVectorImpl<NamespaceDecl *> &Namespaces);
  71. /// Load the set of used but not defined functions or variables with
  72. /// internal linkage, or used but not defined internal functions.
  73. virtual void
  74. ReadUndefinedButUsed(llvm::MapVector<NamedDecl *, SourceLocation> &Undefined);
  75. virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
  76. FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &);
  77. /// Do last resort, unqualified lookup on a LookupResult that
  78. /// Sema cannot find.
  79. ///
  80. /// \param R a LookupResult that is being recovered.
  81. ///
  82. /// \param S the Scope of the identifier occurrence.
  83. ///
  84. /// \return true to tell Sema to recover using the LookupResult.
  85. virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
  86. /// Read the set of tentative definitions known to the external Sema
  87. /// source.
  88. ///
  89. /// The external source should append its own tentative definitions to the
  90. /// given vector of tentative definitions. Note that this routine may be
  91. /// invoked multiple times; the external source should take care not to
  92. /// introduce the same declarations repeatedly.
  93. virtual void ReadTentativeDefinitions(
  94. SmallVectorImpl<VarDecl *> &TentativeDefs) {}
  95. /// Read the set of unused file-scope declarations known to the
  96. /// external Sema source.
  97. ///
  98. /// The external source should append its own unused, filed-scope to the
  99. /// given vector of declarations. Note that this routine may be
  100. /// invoked multiple times; the external source should take care not to
  101. /// introduce the same declarations repeatedly.
  102. virtual void ReadUnusedFileScopedDecls(
  103. SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
  104. /// Read the set of delegating constructors known to the
  105. /// external Sema source.
  106. ///
  107. /// The external source should append its own delegating constructors to the
  108. /// given vector of declarations. Note that this routine may be
  109. /// invoked multiple times; the external source should take care not to
  110. /// introduce the same declarations repeatedly.
  111. virtual void ReadDelegatingConstructors(
  112. SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
  113. /// Read the set of ext_vector type declarations known to the
  114. /// external Sema source.
  115. ///
  116. /// The external source should append its own ext_vector type declarations to
  117. /// the given vector of declarations. Note that this routine may be
  118. /// invoked multiple times; the external source should take care not to
  119. /// introduce the same declarations repeatedly.
  120. virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
  121. /// Read the set of potentially unused typedefs known to the source.
  122. ///
  123. /// The external source should append its own potentially unused local
  124. /// typedefs to the given vector of declarations. Note that this routine may
  125. /// be invoked multiple times; the external source should take care not to
  126. /// introduce the same declarations repeatedly.
  127. virtual void ReadUnusedLocalTypedefNameCandidates(
  128. llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {}
  129. /// Read the set of referenced selectors known to the
  130. /// external Sema source.
  131. ///
  132. /// The external source should append its own referenced selectors to the
  133. /// given vector of selectors. Note that this routine
  134. /// may be invoked multiple times; the external source should take care not
  135. /// to introduce the same selectors repeatedly.
  136. virtual void ReadReferencedSelectors(
  137. SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
  138. /// Read the set of weak, undeclared identifiers known to the
  139. /// external Sema source.
  140. ///
  141. /// The external source should append its own weak, undeclared identifiers to
  142. /// the given vector. Note that this routine may be invoked multiple times;
  143. /// the external source should take care not to introduce the same identifiers
  144. /// repeatedly.
  145. virtual void ReadWeakUndeclaredIdentifiers(
  146. SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
  147. /// Read the set of used vtables known to the external Sema source.
  148. ///
  149. /// The external source should append its own used vtables to the given
  150. /// vector. Note that this routine may be invoked multiple times; the external
  151. /// source should take care not to introduce the same vtables repeatedly.
  152. virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
  153. /// Read the set of pending instantiations known to the external
  154. /// Sema source.
  155. ///
  156. /// The external source should append its own pending instantiations to the
  157. /// given vector. Note that this routine may be invoked multiple times; the
  158. /// external source should take care not to introduce the same instantiations
  159. /// repeatedly.
  160. virtual void ReadPendingInstantiations(
  161. SmallVectorImpl<std::pair<ValueDecl *,
  162. SourceLocation> > &Pending) {}
  163. /// Read the set of late parsed template functions for this source.
  164. ///
  165. /// The external source should insert its own late parsed template functions
  166. /// into the map. Note that this routine may be invoked multiple times; the
  167. /// external source should take care not to introduce the same map entries
  168. /// repeatedly.
  169. virtual void ReadLateParsedTemplates(
  170. llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
  171. &LPTMap) {}
  172. /// Read the set of decls to be checked for deferred diags.
  173. ///
  174. /// The external source should append its own potentially emitted function
  175. /// and variable decls which may cause deferred diags. Note that this routine
  176. /// may be invoked multiple times; the external source should take care not to
  177. /// introduce the same declarations repeatedly.
  178. virtual void
  179. ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector<Decl *, 4> &Decls) {}
  180. /// \copydoc Sema::CorrectTypo
  181. /// \note LookupKind must correspond to a valid Sema::LookupNameKind
  182. ///
  183. /// ExternalSemaSource::CorrectTypo is always given the first chance to
  184. /// correct a typo (really, to offer suggestions to repair a failed lookup).
  185. /// It will even be called when SpellChecking is turned off or after a
  186. /// fatal error has already been detected.
  187. virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
  188. int LookupKind, Scope *S, CXXScopeSpec *SS,
  189. CorrectionCandidateCallback &CCC,
  190. DeclContext *MemberContext,
  191. bool EnteringContext,
  192. const ObjCObjectPointerType *OPT) {
  193. return TypoCorrection();
  194. }
  195. /// Produces a diagnostic note if the external source contains a
  196. /// complete definition for \p T.
  197. ///
  198. /// \param Loc the location at which a complete type was required but not
  199. /// provided
  200. ///
  201. /// \param T the \c QualType that should have been complete at \p Loc
  202. ///
  203. /// \return true if a diagnostic was produced, false otherwise.
  204. virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
  205. QualType T) {
  206. return false;
  207. }
  208. /// LLVM-style RTTI.
  209. /// \{
  210. bool isA(const void *ClassID) const override {
  211. return ClassID == &ID || ExternalASTSource::isA(ClassID);
  212. }
  213. static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
  214. /// \}
  215. };
  216. } // end namespace clang
  217. #endif
  218. #ifdef __GNUC__
  219. #pragma GCC diagnostic pop
  220. #endif