clang 22.0.0git
IndexSymbol.h
Go to the documentation of this file.
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,
29 Macro,
31
32 Enum,
33 Struct,
34 Class,
37 Union,
39
42 Field,
44
51
55
57 Using,
61
62 Concept, /// C++20 concept.
63};
64
65enum class SymbolLanguage : uint8_t {
66 C,
67 ObjC,
68 CXX,
69 Swift,
70};
71
72/// Language specific sub-kinds.
73enum class SymbolSubKind : uint8_t {
74 None,
82};
83
84typedef uint16_t SymbolPropertySet;
85/// Set of properties that provide additional info about a symbol.
87 Generic = 1 << 0,
90 UnitTest = 1 << 3,
91 IBAnnotated = 1 << 4,
92 IBOutletCollection = 1 << 5,
93 GKInspectable = 1 << 6,
94 Local = 1 << 7,
95 /// Symbol is part of a protocol interface.
96 ProtocolInterface = 1 << 8,
97};
98static const unsigned SymbolPropertyBitNum = 9;
99
100/// Set of roles that are attributed to symbol occurrences.
101///
102/// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
103enum class SymbolRole : uint32_t {
104 Declaration = 1 << 0,
105 Definition = 1 << 1,
106 Reference = 1 << 2,
107 Read = 1 << 3,
108 Write = 1 << 4,
109 Call = 1 << 5,
110 Dynamic = 1 << 6,
111 AddressOf = 1 << 7,
112 Implicit = 1 << 8,
113 // FIXME: this is not mirrored in CXSymbolRole.
114 // Note that macro occurrences aren't currently supported in libclang.
115 Undefinition = 1 << 9, // macro #undef
116
117 // Relation roles.
118 RelationChildOf = 1 << 10,
119 RelationBaseOf = 1 << 11,
120 RelationOverrideOf = 1 << 12,
121 RelationReceivedBy = 1 << 13,
122 RelationCalledBy = 1 << 14,
123 RelationExtendedBy = 1 << 15,
124 RelationAccessorOf = 1 << 16,
125 RelationContainedBy = 1 << 17,
126 RelationIBTypeOf = 1 << 18,
127 RelationSpecializationOf = 1 << 19,
128
129 // Symbol only references the name of the object as written. For example, a
130 // constructor references the class declaration using that role.
131 NameReference = 1 << 20,
132};
133static const unsigned SymbolRoleBitNum = 21;
134typedef unsigned SymbolRoleSet;
135
136/// Represents a relation to another symbol for a symbol occurrence.
140
142 : Roles(Roles), RelatedSymbol(Sym) {}
143};
144
150};
151
153
155
156bool isFunctionLocalSymbol(const Decl *D);
157
159 llvm::function_ref<void(SymbolRole)> Fn);
161 llvm::function_ref<bool(SymbolRole)> Fn);
162void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
163
164/// \returns true if no name was printed, false otherwise.
165bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
166
170
172 llvm::function_ref<void(SymbolProperty)> Fn);
173void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
174
175} // namespace index
176} // namespace clang
177
178#endif
const Decl * D
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::MacroInfo and clang::MacroDirective classes.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
void applyForEachSymbolProperty(SymbolPropertySet Props, llvm::function_ref< void(SymbolProperty)> Fn)
SymbolRole
Set of roles that are attributed to symbol occurrences.
Definition: IndexSymbol.h:103
StringRef getSymbolSubKindString(SymbolSubKind K)
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:98
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)
SymbolInfo getSymbolInfo(const Decl *D)
Definition: IndexSymbol.cpp:86
StringRef getSymbolKindString(SymbolKind K)
bool isFunctionLocalSymbol(const Decl *D)
Definition: IndexSymbol.cpp:53
void applyForEachSymbolRole(SymbolRoleSet Roles, llvm::function_ref< void(SymbolRole)> Fn)
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS)
SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI)
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)
static const unsigned SymbolRoleBitNum
Definition: IndexSymbol.h:133
unsigned SymbolRoleSet
Definition: IndexSymbol.h:134
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
SymbolProperty
Set of properties that provide additional info about a symbol.
Definition: IndexSymbol.h:86
@ ProtocolInterface
Symbol is part of a protocol interface.
uint16_t SymbolPropertySet
Definition: IndexSymbol.h:84
StringRef getSymbolLanguageString(SymbolLanguage K)
SymbolSubKind
Language specific sub-kinds.
Definition: IndexSymbol.h:73
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Definition: ModuleMapFile.h:36
The JSON file list parser is used to communicate input to InstallAPI.
SymbolPropertySet Properties
Definition: IndexSymbol.h:149
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:137
SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
Definition: IndexSymbol.h:141