clang  16.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 
17 namespace clang {
18  class Decl;
19  class LangOptions;
20 
21 namespace index {
22 
23 enum class SymbolKind : uint8_t {
24  Unknown,
25 
26  Module,
27  Namespace,
29  Macro,
30 
31  Enum,
32  Struct,
33  Class,
34  Protocol,
35  Extension,
36  Union,
37  TypeAlias,
38 
39  Function,
40  Variable,
41  Field,
43 
50 
52  Destructor,
54 
55  Parameter,
56  Using,
60 
61  Concept, /// C++20 concept.
62 };
63 
64 enum class SymbolLanguage : uint8_t {
65  C,
66  ObjC,
67  CXX,
68  Swift,
69 };
70 
71 /// Language specific sub-kinds.
72 enum class SymbolSubKind : uint8_t {
73  None,
79  UsingValue,
80  UsingEnum,
81 };
82 
83 typedef uint16_t SymbolPropertySet;
84 /// Set of properties that provide additional info about a symbol.
86  Generic = 1 << 0,
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 };
97 static 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.
102 enum 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 };
132 static const unsigned SymbolRoleBitNum = 21;
133 typedef unsigned SymbolRoleSet;
134 
135 /// Represents a relation to another symbol for a symbol occurrence.
139 
141  : Roles(Roles), RelatedSymbol(Sym) {}
142 };
143 
144 struct SymbolInfo {
149 };
150 
151 SymbolInfo getSymbolInfo(const Decl *D);
152 
154 
155 bool isFunctionLocalSymbol(const Decl *D);
156 
158  llvm::function_ref<void(SymbolRole)> Fn);
160  llvm::function_ref<bool(SymbolRole)> Fn);
161 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
162 
163 /// \returns true if no name was printed, false otherwise.
164 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
165 
166 StringRef getSymbolKindString(SymbolKind K);
169 
171  llvm::function_ref<void(SymbolProperty)> Fn);
172 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
173 
174 } // namespace index
175 } // namespace clang
176 
177 #endif
clang::index::SymbolRole::AddressOf
@ AddressOf
clang::index::SymbolKind::ClassProperty
@ ClassProperty
clang::index::applyForEachSymbolRoleInterruptible
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
Definition: IndexSymbol.cpp:415
clang::index::SymbolProperty
SymbolProperty
Set of properties that provide additional info about a symbol.
Definition: IndexSymbol.h:85
clang::index::SymbolRole::RelationExtendedBy
@ RelationExtendedBy
clang::index::SymbolKind::Protocol
@ Protocol
clang::index::SymbolKind::Class
@ Class
clang::index::SymbolRelation::SymbolRelation
SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
Definition: IndexSymbol.h:140
clang::index::printSymbolProperties
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)
Definition: IndexSymbol.cpp:590
clang::index::getSymbolSubKindString
StringRef getSymbolSubKindString(SymbolSubKind K)
Definition: IndexSymbol.cpp:546
clang::index::SymbolLanguage::Swift
@ Swift
clang::index::SymbolLanguage::CXX
@ CXX
clang::index::SymbolKind::EnumConstant
@ EnumConstant
clang::index::SymbolRoleBitNum
static const unsigned SymbolRoleBitNum
Definition: IndexSymbol.h:132
clang::index::SymbolKind::StaticMethod
@ StaticMethod
clang::index::SymbolRole::RelationChildOf
@ RelationChildOf
clang::index::SymbolKind::Unknown
@ Unknown
clang::index::SymbolKind::Struct
@ Struct
clang::index::SymbolKind::NamespaceAlias
@ NamespaceAlias
clang::index::SymbolRole::Definition
@ Definition
clang::index::SymbolSubKind
SymbolSubKind
Language specific sub-kinds.
Definition: IndexSymbol.h:72
clang::index::SymbolKind::Parameter
@ Parameter
clang::index::SymbolKind::TypeAlias
@ TypeAlias
clang::index::SymbolKind::Using
@ Using
clang::index::SymbolSubKind::UsingTypename
@ UsingTypename
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
clang::index::SymbolProperty::Generic
@ Generic
clang::index::SymbolRole::Reference
@ Reference
clang::index::SymbolKind::Macro
@ Macro
clang::index::SymbolRole::Call
@ Call
clang::index::SymbolKind::NonTypeTemplateParm
@ NonTypeTemplateParm
clang::index::printSymbolRoles
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS)
Definition: IndexSymbol.cpp:457
clang::index::SymbolKind::Constructor
@ Constructor
clang::index::SymbolSubKind::None
@ None
clang::index::SymbolKind::TemplateTypeParm
@ TemplateTypeParm
clang::index::SymbolKind::Variable
@ Variable
clang::index::SymbolProperty::Local
@ Local
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::index::SymbolKind::Namespace
@ Namespace
clang::index::SymbolInfo::Lang
SymbolLanguage Lang
Definition: IndexSymbol.h:147
clang::index::SymbolInfo::Kind
SymbolKind Kind
Definition: IndexSymbol.h:145
clang::index::SymbolRole::RelationOverrideOf
@ RelationOverrideOf
clang::index::SymbolSubKind::AccessorSetter
@ AccessorSetter
clang::index::SymbolSubKind::CXXCopyConstructor
@ CXXCopyConstructor
clang::index::SymbolRole::Declaration
@ Declaration
clang::index::SymbolProperty::GKInspectable
@ GKInspectable
clang::index::SymbolKind::InstanceProperty
@ InstanceProperty
clang::index::SymbolSubKind::UsingEnum
@ UsingEnum
clang::index::SymbolKind::Module
@ Module
clang::index::SymbolRole::Implicit
@ Implicit
clang::index::SymbolProperty::IBOutletCollection
@ IBOutletCollection
clang::index::SymbolRole::RelationReceivedBy
@ RelationReceivedBy
clang::index::SymbolInfo::SubKind
SymbolSubKind SubKind
Definition: IndexSymbol.h:146
clang::index::SymbolKind::Destructor
@ Destructor
clang::index::SymbolKind::Field
@ Field
clang::index::applyForEachSymbolProperty
void applyForEachSymbolProperty(SymbolPropertySet Props, llvm::function_ref< void(SymbolProperty)> Fn)
Definition: IndexSymbol.cpp:571
clang::index::SymbolLanguage::C
@ C
clang::index::SymbolProperty::ProtocolInterface
@ ProtocolInterface
Symbol is part of a protocol interface.
clang::index::SymbolRole::RelationIBTypeOf
@ RelationIBTypeOf
clang::index::SymbolKind::ConversionFunction
@ ConversionFunction
clang::index::isFunctionLocalSymbol
bool isFunctionLocalSymbol(const Decl *D)
Definition: IndexSymbol.cpp:53
clang::index::SymbolKind::TemplateTemplateParm
@ TemplateTemplateParm
clang::index::SymbolRole::Dynamic
@ Dynamic
clang::index::SymbolRelation::RelatedSymbol
const Decl * RelatedSymbol
Definition: IndexSymbol.h:138
clang::index::SymbolRole::Undefinition
@ Undefinition
clang::index::SymbolRole::RelationAccessorOf
@ RelationAccessorOf
clang::index::applyForEachSymbolRole
void applyForEachSymbolRole(SymbolRoleSet Roles, llvm::function_ref< void(SymbolRole)> Fn)
Definition: IndexSymbol.cpp:449
clang::index::SymbolRole::RelationCalledBy
@ RelationCalledBy
clang::index::SymbolLanguage
SymbolLanguage
Definition: IndexSymbol.h:64
clang::index::SymbolKind::ClassMethod
@ ClassMethod
clang::index::SymbolKind::Extension
@ Extension
clang::index::SymbolProperty::IBAnnotated
@ IBAnnotated
clang::index::SymbolInfo
Definition: IndexSymbol.h:144
clang::index::SymbolRole
SymbolRole
Set of roles that are attributed to symbol occurrences.
Definition: IndexSymbol.h:102
clang::index::getSymbolInfo
SymbolInfo getSymbolInfo(const Decl *D)
Definition: IndexSymbol.cpp:85
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::index::getSymbolKindString
StringRef getSymbolKindString(SymbolKind K)
Definition: IndexSymbol.cpp:508
clang::index::SymbolKind
SymbolKind
Definition: IndexSymbol.h:23
clang::index::SymbolLanguage::ObjC
@ ObjC
clang::index::SymbolRole::Read
@ Read
clang::index::SymbolRole::RelationSpecializationOf
@ RelationSpecializationOf
LLVM.h
clang::index::getSymbolInfoForMacro
SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI)
Definition: IndexSymbol.cpp:406
clang::index::SymbolSubKind::AccessorGetter
@ AccessorGetter
clang::index::SymbolProperty::TemplatePartialSpecialization
@ TemplatePartialSpecialization
clang::index::SymbolProperty::UnitTest
@ UnitTest
clang::index::SymbolSubKind::UsingValue
@ UsingValue
clang::index::getSymbolLanguageString
StringRef getSymbolLanguageString(SymbolLanguage K)
Definition: IndexSymbol.cpp:561
clang::index::SymbolRole::NameReference
@ NameReference
clang::index::SymbolPropertyBitNum
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:97
clang::index::SymbolRoleSet
unsigned SymbolRoleSet
Definition: IndexSymbol.h:133
clang::index::printSymbolName
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)
Definition: IndexSymbol.cpp:490
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:78
clang::index::SymbolKind::Union
@ Union
clang
Definition: CalledOnceCheck.h:17
MacroInfo.h
clang::index::SymbolProperty::TemplateSpecialization
@ TemplateSpecialization
unsigned
clang::index::SymbolRelation::Roles
SymbolRoleSet Roles
Definition: IndexSymbol.h:137
clang::index::SymbolRole::Write
@ Write
clang::index::SymbolKind::InstanceMethod
@ InstanceMethod
clang::index::SymbolKind::StaticProperty
@ StaticProperty
clang::index::SymbolKind::Function
@ Function
clang::index::SymbolKind::Enum
@ Enum
clang::index::SymbolInfo::Properties
SymbolPropertySet Properties
Definition: IndexSymbol.h:148
clang::index::SymbolPropertySet
uint16_t SymbolPropertySet
Definition: IndexSymbol.h:83
clang::index::SymbolRole::RelationContainedBy
@ RelationContainedBy
clang::index::SymbolKind::Concept
@ Concept
clang::index::SymbolRelation
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:136
clang::index::SymbolRole::RelationBaseOf
@ RelationBaseOf
clang::index::SymbolSubKind::CXXMoveConstructor
@ CXXMoveConstructor