IndexSymbol.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. };
  55. enum class SymbolLanguage : uint8_t {
  56. C,
  57. ObjC,
  58. CXX,
  59. Swift,
  60. };
  61. /// Language specific sub-kinds.
  62. enum class SymbolSubKind : uint8_t {
  63. None,
  64. CXXCopyConstructor,
  65. CXXMoveConstructor,
  66. AccessorGetter,
  67. AccessorSetter,
  68. UsingTypename,
  69. UsingValue,
  70. UsingEnum,
  71. };
  72. typedef uint16_t SymbolPropertySet;
  73. /// Set of properties that provide additional info about a symbol.
  74. enum class SymbolProperty : SymbolPropertySet {
  75. Generic = 1 << 0,
  76. TemplatePartialSpecialization = 1 << 1,
  77. TemplateSpecialization = 1 << 2,
  78. UnitTest = 1 << 3,
  79. IBAnnotated = 1 << 4,
  80. IBOutletCollection = 1 << 5,
  81. GKInspectable = 1 << 6,
  82. Local = 1 << 7,
  83. /// Symbol is part of a protocol interface.
  84. ProtocolInterface = 1 << 8,
  85. };
  86. static const unsigned SymbolPropertyBitNum = 9;
  87. /// Set of roles that are attributed to symbol occurrences.
  88. ///
  89. /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
  90. enum class SymbolRole : uint32_t {
  91. Declaration = 1 << 0,
  92. Definition = 1 << 1,
  93. Reference = 1 << 2,
  94. Read = 1 << 3,
  95. Write = 1 << 4,
  96. Call = 1 << 5,
  97. Dynamic = 1 << 6,
  98. AddressOf = 1 << 7,
  99. Implicit = 1 << 8,
  100. // FIXME: this is not mirrored in CXSymbolRole.
  101. // Note that macro occurrences aren't currently supported in libclang.
  102. Undefinition = 1 << 9, // macro #undef
  103. // Relation roles.
  104. RelationChildOf = 1 << 10,
  105. RelationBaseOf = 1 << 11,
  106. RelationOverrideOf = 1 << 12,
  107. RelationReceivedBy = 1 << 13,
  108. RelationCalledBy = 1 << 14,
  109. RelationExtendedBy = 1 << 15,
  110. RelationAccessorOf = 1 << 16,
  111. RelationContainedBy = 1 << 17,
  112. RelationIBTypeOf = 1 << 18,
  113. RelationSpecializationOf = 1 << 19,
  114. // Symbol only references the name of the object as written. For example, a
  115. // constructor references the class declaration using that role.
  116. NameReference = 1 << 20,
  117. };
  118. static const unsigned SymbolRoleBitNum = 21;
  119. typedef unsigned SymbolRoleSet;
  120. /// Represents a relation to another symbol for a symbol occurrence.
  121. struct SymbolRelation {
  122. SymbolRoleSet Roles;
  123. const Decl *RelatedSymbol;
  124. SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
  125. : Roles(Roles), RelatedSymbol(Sym) {}
  126. };
  127. struct SymbolInfo {
  128. SymbolKind Kind;
  129. SymbolSubKind SubKind;
  130. SymbolLanguage Lang;
  131. SymbolPropertySet Properties;
  132. };
  133. SymbolInfo getSymbolInfo(const Decl *D);
  134. SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
  135. bool isFunctionLocalSymbol(const Decl *D);
  136. void applyForEachSymbolRole(SymbolRoleSet Roles,
  137. llvm::function_ref<void(SymbolRole)> Fn);
  138. bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
  139. llvm::function_ref<bool(SymbolRole)> Fn);
  140. void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
  141. /// \returns true if no name was printed, false otherwise.
  142. bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
  143. StringRef getSymbolKindString(SymbolKind K);
  144. StringRef getSymbolSubKindString(SymbolSubKind K);
  145. StringRef getSymbolLanguageString(SymbolLanguage K);
  146. void applyForEachSymbolProperty(SymbolPropertySet Props,
  147. llvm::function_ref<void(SymbolProperty)> Fn);
  148. void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
  149. } // namespace index
  150. } // namespace clang
  151. #endif
  152. #ifdef __GNUC__
  153. #pragma GCC diagnostic pop
  154. #endif