IndexingContext.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //===- IndexingContext.h - Indexing context data ----------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
  9. #define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
  10. #include "clang/Basic/IdentifierTable.h"
  11. #include "clang/Basic/LLVM.h"
  12. #include "clang/Index/IndexSymbol.h"
  13. #include "clang/Index/IndexingAction.h"
  14. #include "clang/Lex/MacroInfo.h"
  15. #include "llvm/ADT/ArrayRef.h"
  16. namespace clang {
  17. class ASTContext;
  18. class Decl;
  19. class DeclGroupRef;
  20. class ImportDecl;
  21. class TagDecl;
  22. class TypeSourceInfo;
  23. class NamedDecl;
  24. class ObjCMethodDecl;
  25. class DeclContext;
  26. class NestedNameSpecifierLoc;
  27. class Stmt;
  28. class Expr;
  29. class TypeLoc;
  30. class SourceLocation;
  31. namespace index {
  32. class IndexDataConsumer;
  33. class IndexingContext {
  34. IndexingOptions IndexOpts;
  35. IndexDataConsumer &DataConsumer;
  36. ASTContext *Ctx = nullptr;
  37. public:
  38. IndexingContext(IndexingOptions IndexOpts, IndexDataConsumer &DataConsumer)
  39. : IndexOpts(IndexOpts), DataConsumer(DataConsumer) {}
  40. const IndexingOptions &getIndexOpts() const { return IndexOpts; }
  41. IndexDataConsumer &getDataConsumer() { return DataConsumer; }
  42. void setASTContext(ASTContext &ctx) { Ctx = &ctx; }
  43. bool shouldIndex(const Decl *D);
  44. const LangOptions &getLangOpts() const;
  45. bool shouldSuppressRefs() const {
  46. return false;
  47. }
  48. bool shouldIndexFunctionLocalSymbols() const;
  49. bool shouldIndexImplicitInstantiation() const;
  50. bool shouldIndexParametersInDeclarations() const;
  51. bool shouldIndexTemplateParameters() const;
  52. static bool isTemplateImplicitInstantiation(const Decl *D);
  53. bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),
  54. ArrayRef<SymbolRelation> Relations = std::nullopt);
  55. bool handleDecl(const Decl *D, SourceLocation Loc,
  56. SymbolRoleSet Roles = SymbolRoleSet(),
  57. ArrayRef<SymbolRelation> Relations = std::nullopt,
  58. const DeclContext *DC = nullptr);
  59. bool handleReference(const NamedDecl *D, SourceLocation Loc,
  60. const NamedDecl *Parent, const DeclContext *DC,
  61. SymbolRoleSet Roles = SymbolRoleSet(),
  62. ArrayRef<SymbolRelation> Relations = std::nullopt,
  63. const Expr *RefE = nullptr, const Decl *RefD = nullptr);
  64. void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
  65. const MacroInfo &MI);
  66. void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc,
  67. const MacroInfo &MI);
  68. void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc,
  69. const MacroInfo &MD);
  70. bool importedModule(const ImportDecl *ImportD);
  71. bool indexDecl(const Decl *D);
  72. void indexTagDecl(const TagDecl *D,
  73. ArrayRef<SymbolRelation> Relations = std::nullopt);
  74. void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
  75. const DeclContext *DC = nullptr,
  76. bool isBase = false,
  77. bool isIBType = false);
  78. void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
  79. const DeclContext *DC = nullptr,
  80. bool isBase = false,
  81. bool isIBType = false);
  82. void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
  83. const NamedDecl *Parent,
  84. const DeclContext *DC = nullptr);
  85. bool indexDeclContext(const DeclContext *DC);
  86. void indexBody(const Stmt *S, const NamedDecl *Parent,
  87. const DeclContext *DC = nullptr);
  88. bool indexTopLevelDecl(const Decl *D);
  89. bool indexDeclGroupRef(DeclGroupRef DG);
  90. private:
  91. bool shouldIgnoreIfImplicit(const Decl *D);
  92. bool shouldIndexMacroOccurrence(bool IsRef, SourceLocation Loc);
  93. bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
  94. bool IsRef, const Decl *Parent,
  95. SymbolRoleSet Roles,
  96. ArrayRef<SymbolRelation> Relations,
  97. const Expr *RefE,
  98. const Decl *RefD,
  99. const DeclContext *ContainerDC);
  100. };
  101. } // end namespace index
  102. } // end namespace clang
  103. #endif