IndexSymbol.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IndexSymbol.h - Types and functions for indexing symbols -*- 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. #ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H
  14. #define LLVM_CLANG_INDEX_INDEXSYMBOL_H
  15. #include "clang/Basic/LLVM.h"
  16. #include "clang/Lex/MacroInfo.h"
  17. #include "llvm/ADT/STLExtras.h"
  18. #include "llvm/Support/DataTypes.h"
  19. namespace clang {
  20. class Decl;
  21. class LangOptions;
  22. namespace index {
  23. enum class SymbolKind : uint8_t {
  24. Unknown,
  25. Module,
  26. Namespace,
  27. NamespaceAlias,
  28. Macro,
  29. Enum,
  30. Struct,
  31. Class,
  32. Protocol,
  33. Extension,
  34. Union,
  35. TypeAlias,
  36. Function,
  37. Variable,
  38. Field,
  39. EnumConstant,
  40. InstanceMethod,
  41. ClassMethod,
  42. StaticMethod,
  43. InstanceProperty,
  44. ClassProperty,
  45. StaticProperty,
  46. Constructor,
  47. Destructor,
  48. ConversionFunction,
  49. Parameter,
  50. Using,
  51. TemplateTypeParm,
  52. TemplateTemplateParm,
  53. NonTypeTemplateParm,
  54. Concept, /// C++20 concept.
  55. };
  56. enum class SymbolLanguage : uint8_t {
  57. C,
  58. ObjC,
  59. CXX,
  60. Swift,
  61. };
  62. /// Language specific sub-kinds.
  63. enum class SymbolSubKind : uint8_t {
  64. None,
  65. CXXCopyConstructor,
  66. CXXMoveConstructor,
  67. AccessorGetter,
  68. AccessorSetter,
  69. UsingTypename,
  70. UsingValue,
  71. UsingEnum,
  72. };
  73. typedef uint16_t SymbolPropertySet;
  74. /// Set of properties that provide additional info about a symbol.
  75. enum class SymbolProperty : SymbolPropertySet {
  76. Generic = 1 << 0,
  77. TemplatePartialSpecialization = 1 << 1,
  78. TemplateSpecialization = 1 << 2,
  79. UnitTest = 1 << 3,
  80. IBAnnotated = 1 << 4,
  81. IBOutletCollection = 1 << 5,
  82. GKInspectable = 1 << 6,
  83. Local = 1 << 7,
  84. /// Symbol is part of a protocol interface.
  85. ProtocolInterface = 1 << 8,
  86. };
  87. static const unsigned SymbolPropertyBitNum = 9;
  88. /// Set of roles that are attributed to symbol occurrences.
  89. ///
  90. /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
  91. enum class SymbolRole : uint32_t {
  92. Declaration = 1 << 0,
  93. Definition = 1 << 1,
  94. Reference = 1 << 2,
  95. Read = 1 << 3,
  96. Write = 1 << 4,
  97. Call = 1 << 5,
  98. Dynamic = 1 << 6,
  99. AddressOf = 1 << 7,
  100. Implicit = 1 << 8,
  101. // FIXME: this is not mirrored in CXSymbolRole.
  102. // Note that macro occurrences aren't currently supported in libclang.
  103. Undefinition = 1 << 9, // macro #undef
  104. // Relation roles.
  105. RelationChildOf = 1 << 10,
  106. RelationBaseOf = 1 << 11,
  107. RelationOverrideOf = 1 << 12,
  108. RelationReceivedBy = 1 << 13,
  109. RelationCalledBy = 1 << 14,
  110. RelationExtendedBy = 1 << 15,
  111. RelationAccessorOf = 1 << 16,
  112. RelationContainedBy = 1 << 17,
  113. RelationIBTypeOf = 1 << 18,
  114. RelationSpecializationOf = 1 << 19,
  115. // Symbol only references the name of the object as written. For example, a
  116. // constructor references the class declaration using that role.
  117. NameReference = 1 << 20,
  118. };
  119. static const unsigned SymbolRoleBitNum = 21;
  120. typedef unsigned SymbolRoleSet;
  121. /// Represents a relation to another symbol for a symbol occurrence.
  122. struct SymbolRelation {
  123. SymbolRoleSet Roles;
  124. const Decl *RelatedSymbol;
  125. SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
  126. : Roles(Roles), RelatedSymbol(Sym) {}
  127. };
  128. struct SymbolInfo {
  129. SymbolKind Kind;
  130. SymbolSubKind SubKind;
  131. SymbolLanguage Lang;
  132. SymbolPropertySet Properties;
  133. };
  134. SymbolInfo getSymbolInfo(const Decl *D);
  135. SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
  136. bool isFunctionLocalSymbol(const Decl *D);
  137. void applyForEachSymbolRole(SymbolRoleSet Roles,
  138. llvm::function_ref<void(SymbolRole)> Fn);
  139. bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
  140. llvm::function_ref<bool(SymbolRole)> Fn);
  141. void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
  142. /// \returns true if no name was printed, false otherwise.
  143. bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
  144. StringRef getSymbolKindString(SymbolKind K);
  145. StringRef getSymbolSubKindString(SymbolSubKind K);
  146. StringRef getSymbolLanguageString(SymbolLanguage K);
  147. void applyForEachSymbolProperty(SymbolPropertySet Props,
  148. llvm::function_ref<void(SymbolProperty)> Fn);
  149. void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
  150. } // namespace index
  151. } // namespace clang
  152. #endif
  153. #ifdef __GNUC__
  154. #pragma GCC diagnostic pop
  155. #endif