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