1 //===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H
11 #define LLVM_CLANG_INDEX_INDEXSYMBOL_H
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Lex/MacroInfo.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/Support/DataTypes.h"
24 enum class SymbolKind : uint8_t {
60 enum class SymbolLanguage : uint8_t {
67 /// Language specific sub-kinds.
68 enum class SymbolSubKind : uint8_t {
78 typedef uint8_t SymbolPropertySet;
79 /// Set of properties that provide additional info about a symbol.
80 enum class SymbolProperty : SymbolPropertySet {
82 TemplatePartialSpecialization = 1 << 1,
83 TemplateSpecialization = 1 << 2,
86 IBOutletCollection = 1 << 5,
87 GKInspectable = 1 << 6,
90 static const unsigned SymbolPropertyBitNum = 8;
92 /// Set of roles that are attributed to symbol occurrences.
94 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
95 enum class SymbolRole : uint32_t {
105 // FIXME: this is not mirrored in CXSymbolRole.
106 // Note that macro occurrences aren't currently supported in libclang.
107 Undefinition = 1 << 9, // macro #undef
110 RelationChildOf = 1 << 10,
111 RelationBaseOf = 1 << 11,
112 RelationOverrideOf = 1 << 12,
113 RelationReceivedBy = 1 << 13,
114 RelationCalledBy = 1 << 14,
115 RelationExtendedBy = 1 << 15,
116 RelationAccessorOf = 1 << 16,
117 RelationContainedBy = 1 << 17,
118 RelationIBTypeOf = 1 << 18,
119 RelationSpecializationOf = 1 << 19,
121 static const unsigned SymbolRoleBitNum = 20;
122 typedef unsigned SymbolRoleSet;
124 /// Represents a relation to another symbol for a symbol occurrence.
125 struct SymbolRelation {
127 const Decl *RelatedSymbol;
129 SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
130 : Roles(Roles), RelatedSymbol(Sym) {}
135 SymbolSubKind SubKind;
137 SymbolPropertySet Properties;
140 SymbolInfo getSymbolInfo(const Decl *D);
142 SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
144 bool isFunctionLocalSymbol(const Decl *D);
146 void applyForEachSymbolRole(SymbolRoleSet Roles,
147 llvm::function_ref<void(SymbolRole)> Fn);
148 bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
149 llvm::function_ref<bool(SymbolRole)> Fn);
150 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
152 /// \returns true if no name was printed, false otherwise.
153 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
155 StringRef getSymbolKindString(SymbolKind K);
156 StringRef getSymbolSubKindString(SymbolSubKind K);
157 StringRef getSymbolLanguageString(SymbolLanguage K);
159 void applyForEachSymbolProperty(SymbolPropertySet Props,
160 llvm::function_ref<void(SymbolProperty)> Fn);
161 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);