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
17namespace clang {
18 class Decl;
19 class LangOptions;
20
21namespace index {
22
23enum 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
64enum class SymbolLanguage : uint8_t {
65 C,
66 ObjC,
67 CXX,
68 Swift,
69};
70
71/// Language specific sub-kinds.
72enum class SymbolSubKind : uint8_t {
73 None,
74 CXXCopyConstructor,
75 CXXMoveConstructor,
76 AccessorGetter,
77 AccessorSetter,
78 UsingTypename,
79 UsingValue,
80 UsingEnum,
81};
82
83typedef uint16_t SymbolPropertySet;
84/// Set of properties that provide additional info about a symbol.
85enum 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};
97static 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.
102enum 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};
132static const unsigned SymbolRoleBitNum = 21;
133typedef unsigned SymbolRoleSet;
134
135/// Represents a relation to another symbol for a symbol occurrence.
136struct SymbolRelation {
137 SymbolRoleSet Roles;
138 const Decl *RelatedSymbol;
139
140 SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
141 : Roles(Roles), RelatedSymbol(Sym) {}
142};
143
144struct SymbolInfo {
145 SymbolKind Kind;
146 SymbolSubKind SubKind;
147 SymbolLanguage Lang;
148 SymbolPropertySet Properties;
149};
150
151SymbolInfo getSymbolInfo(const Decl *D);
152
153SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
154
155bool isFunctionLocalSymbol(const Decl *D);
156
157void applyForEachSymbolRole(SymbolRoleSet Roles,
158 llvm::function_ref<void(SymbolRole)> Fn);
159bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
160 llvm::function_ref<bool(SymbolRole)> Fn);
161void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
162
163/// \returns true if no name was printed, false otherwise.
164bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
165
166StringRef getSymbolKindString(SymbolKind K);
167StringRef getSymbolSubKindString(SymbolSubKind K);
168StringRef getSymbolLanguageString(SymbolLanguage K);
169
170void applyForEachSymbolProperty(SymbolPropertySet Props,
171 llvm::function_ref<void(SymbolProperty)> Fn);
172void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
173
174} // namespace index
175} // namespace clang
176
177#endif
178

source code of clang/include/clang/Index/IndexSymbol.h