IndexingContext.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 = None);
  55. bool handleDecl(const Decl *D, SourceLocation Loc,
  56. SymbolRoleSet Roles = SymbolRoleSet(),
  57. ArrayRef<SymbolRelation> Relations = None,
  58. const DeclContext *DC = nullptr);
  59. bool handleReference(const NamedDecl *D, SourceLocation Loc,
  60. const NamedDecl *Parent,
  61. const DeclContext *DC,
  62. SymbolRoleSet Roles = SymbolRoleSet(),
  63. ArrayRef<SymbolRelation> Relations = None,
  64. const Expr *RefE = nullptr,
  65. const Decl *RefD = nullptr);
  66. void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
  67. const MacroInfo &MI);
  68. void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc,
  69. const MacroInfo &MI);
  70. void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc,
  71. const MacroInfo &MD);
  72. bool importedModule(const ImportDecl *ImportD);
  73. bool indexDecl(const Decl *D);
  74. void indexTagDecl(const TagDecl *D,
  75. ArrayRef<SymbolRelation> Relations = None);
  76. void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
  77. const DeclContext *DC = nullptr,
  78. bool isBase = false,
  79. bool isIBType = false);
  80. void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
  81. const DeclContext *DC = nullptr,
  82. bool isBase = false,
  83. bool isIBType = false);
  84. void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
  85. const NamedDecl *Parent,
  86. const DeclContext *DC = nullptr);
  87. bool indexDeclContext(const DeclContext *DC);
  88. void indexBody(const Stmt *S, const NamedDecl *Parent,
  89. const DeclContext *DC = nullptr);
  90. bool indexTopLevelDecl(const Decl *D);
  91. bool indexDeclGroupRef(DeclGroupRef DG);
  92. private:
  93. bool shouldIgnoreIfImplicit(const Decl *D);
  94. bool shouldIndexMacroOccurrence(bool IsRef, SourceLocation Loc);
  95. bool handleDeclOccurrence(const Decl *D, SourceLocation Loc,
  96. bool IsRef, const Decl *Parent,
  97. SymbolRoleSet Roles,
  98. ArrayRef<SymbolRelation> Relations,
  99. const Expr *RefE,
  100. const Decl *RefD,
  101. const DeclContext *ContainerDC);
  102. };
  103. } // end namespace index
  104. } // end namespace clang
  105. #endif