clang 20.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,
30
31 Enum,
32 Struct,
33 Class,
36 Union,
38
41 Field,
43
50
54
56 Using,
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,
81};
82
83typedef uint16_t SymbolPropertySet;
84/// Set of properties that provide additional info about a symbol.
86 Generic = 1 << 0,
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.
139
141 : Roles(Roles), RelatedSymbol(Sym) {}
142};
143
149};
150
152
154
155bool isFunctionLocalSymbol(const Decl *D);
156
158 llvm::function_ref<void(SymbolRole)> Fn);
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
169
171 llvm::function_ref<void(SymbolProperty)> Fn);
172void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
173
174} // namespace index
175} // namespace clang
176
177#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:476
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
void applyForEachSymbolProperty(SymbolPropertySet Props, llvm::function_ref< void(SymbolProperty)> Fn)
SymbolRole
Set of roles that are attributed to symbol occurrences.
Definition: IndexSymbol.h:102
StringRef getSymbolSubKindString(SymbolSubKind K)
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:97
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:132
unsigned SymbolRoleSet
Definition: IndexSymbol.h:133
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
SymbolProperty
Set of properties that provide additional info about a symbol.
Definition: IndexSymbol.h:85
@ ProtocolInterface
Symbol is part of a protocol interface.
uint16_t SymbolPropertySet
Definition: IndexSymbol.h:83
StringRef getSymbolLanguageString(SymbolLanguage K)
SymbolSubKind
Language specific sub-kinds.
Definition: IndexSymbol.h:72
The JSON file list parser is used to communicate input to InstallAPI.
SymbolPropertySet Properties
Definition: IndexSymbol.h:148
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:136
SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
Definition: IndexSymbol.h:140