1 //===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H
10 #define LLVM_CLANG_INDEX_INDEXSYMBOL_H
12 #include "clang/Basic/LLVM.h"
13 #include "clang/Lex/MacroInfo.h"
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/Support/DataTypes.h"
23 enum class SymbolKind : uint8_t {
62 enum class SymbolLanguage : uint8_t {
69 /// Language specific sub-kinds.
70 enum class SymbolSubKind : uint8_t {
80 typedef uint16_t SymbolPropertySet;
81 /// Set of properties that provide additional info about a symbol.
82 enum class SymbolProperty : SymbolPropertySet {
84 TemplatePartialSpecialization = 1 << 1,
85 TemplateSpecialization = 1 << 2,
88 IBOutletCollection = 1 << 5,
89 GKInspectable = 1 << 6,
91 /// Symbol is part of a protocol interface.
92 ProtocolInterface = 1 << 8,
94 static const unsigned SymbolPropertyBitNum = 9;
96 /// Set of roles that are attributed to symbol occurrences.
98 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
99 enum class SymbolRole : uint32_t {
100 Declaration = 1 << 0,
109 // FIXME: this is not mirrored in CXSymbolRole.
110 // Note that macro occurrences aren't currently supported in libclang.
111 Undefinition = 1 << 9, // macro #undef
114 RelationChildOf = 1 << 10,
115 RelationBaseOf = 1 << 11,
116 RelationOverrideOf = 1 << 12,
117 RelationReceivedBy = 1 << 13,
118 RelationCalledBy = 1 << 14,
119 RelationExtendedBy = 1 << 15,
120 RelationAccessorOf = 1 << 16,
121 RelationContainedBy = 1 << 17,
122 RelationIBTypeOf = 1 << 18,
123 RelationSpecializationOf = 1 << 19,
125 // Symbol only references the name of the object as written. For example, a
126 // constructor references the class declaration using that role.
127 NameReference = 1 << 20,
129 static const unsigned SymbolRoleBitNum = 21;
130 typedef unsigned SymbolRoleSet;
132 /// Represents a relation to another symbol for a symbol occurrence.
133 struct SymbolRelation {
135 const Decl *RelatedSymbol;
137 SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
138 : Roles(Roles), RelatedSymbol(Sym) {}
143 SymbolSubKind SubKind;
145 SymbolPropertySet Properties;
148 SymbolInfo getSymbolInfo(const Decl *D);
150 SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
152 bool isFunctionLocalSymbol(const Decl *D);
154 void applyForEachSymbolRole(SymbolRoleSet Roles,
155 llvm::function_ref<void(SymbolRole)> Fn);
156 bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
157 llvm::function_ref<bool(SymbolRole)> Fn);
158 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
160 /// \returns true if no name was printed, false otherwise.
161 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
163 StringRef getSymbolKindString(SymbolKind K);
164 StringRef getSymbolSubKindString(SymbolSubKind K);
165 StringRef getSymbolLanguageString(SymbolLanguage K);
167 void applyForEachSymbolProperty(SymbolPropertySet Props,
168 llvm::function_ref<void(SymbolProperty)> Fn);
169 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);