clang  14.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 
62 enum class SymbolLanguage : uint8_t {
63  C,
64  ObjC,
65  CXX,
66  Swift,
67 };
68 
69 /// Language specific sub-kinds.
70 enum class SymbolSubKind : uint8_t {
71  None,
77  UsingValue,
78  UsingEnum,
79 };
80 
81 typedef uint16_t SymbolPropertySet;
82 /// Set of properties that provide additional info about a symbol.
84  Generic = 1 << 0,
86  TemplateSpecialization = 1 << 2,
87  UnitTest = 1 << 3,
88  IBAnnotated = 1 << 4,
89  IBOutletCollection = 1 << 5,
90  GKInspectable = 1 << 6,
91  Local = 1 << 7,
92  /// Symbol is part of a protocol interface.
93  ProtocolInterface = 1 << 8,
94 };
95 static const unsigned SymbolPropertyBitNum = 9;
96 
97 /// Set of roles that are attributed to symbol occurrences.
98 ///
99 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
100 enum class SymbolRole : uint32_t {
101  Declaration = 1 << 0,
102  Definition = 1 << 1,
103  Reference = 1 << 2,
104  Read = 1 << 3,
105  Write = 1 << 4,
106  Call = 1 << 5,
107  Dynamic = 1 << 6,
108  AddressOf = 1 << 7,
109  Implicit = 1 << 8,
110  // FIXME: this is not mirrored in CXSymbolRole.
111  // Note that macro occurrences aren't currently supported in libclang.
112  Undefinition = 1 << 9, // macro #undef
113 
114  // Relation roles.
115  RelationChildOf = 1 << 10,
116  RelationBaseOf = 1 << 11,
117  RelationOverrideOf = 1 << 12,
118  RelationReceivedBy = 1 << 13,
119  RelationCalledBy = 1 << 14,
120  RelationExtendedBy = 1 << 15,
121  RelationAccessorOf = 1 << 16,
122  RelationContainedBy = 1 << 17,
123  RelationIBTypeOf = 1 << 18,
124  RelationSpecializationOf = 1 << 19,
125 
126  // Symbol only references the name of the object as written. For example, a
127  // constructor references the class declaration using that role.
128  NameReference = 1 << 20,
129 };
130 static const unsigned SymbolRoleBitNum = 21;
131 typedef unsigned SymbolRoleSet;
132 
133 /// Represents a relation to another symbol for a symbol occurrence.
137 
139  : Roles(Roles), RelatedSymbol(Sym) {}
140 };
141 
142 struct SymbolInfo {
147 };
148 
149 SymbolInfo getSymbolInfo(const Decl *D);
150 
152 
153 bool isFunctionLocalSymbol(const Decl *D);
154 
156  llvm::function_ref<void(SymbolRole)> Fn);
158  llvm::function_ref<bool(SymbolRole)> Fn);
159 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
160 
161 /// \returns true if no name was printed, false otherwise.
162 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
163 
164 StringRef getSymbolKindString(SymbolKind K);
167 
169  llvm::function_ref<void(SymbolProperty)> Fn);
170 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
171 
172 } // namespace index
173 } // namespace clang
174 
175 #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:412
clang::index::SymbolProperty
SymbolProperty
Set of properties that provide additional info about a symbol.
Definition: IndexSymbol.h:83
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:138
clang::index::printSymbolProperties
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)
Definition: IndexSymbol.cpp:585
clang::index::getSymbolSubKindString
StringRef getSymbolSubKindString(SymbolSubKind K)
Definition: IndexSymbol.cpp:541
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:130
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:70
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:454
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:145
clang::index::SymbolInfo::Kind
SymbolKind Kind
Definition: IndexSymbol.h:143
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:144
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:566
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:136
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:446
clang::index::SymbolRole::RelationCalledBy
@ RelationCalledBy
clang::index::SymbolLanguage
SymbolLanguage
Definition: IndexSymbol.h:62
clang::index::SymbolKind::ClassMethod
@ ClassMethod
clang::index::SymbolKind::Extension
@ Extension
clang::index::SymbolProperty::IBAnnotated
@ IBAnnotated
clang::index::SymbolInfo
Definition: IndexSymbol.h:142
clang::index::SymbolRole
SymbolRole
Set of roles that are attributed to symbol occurrences.
Definition: IndexSymbol.h:100
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:89
clang::index::getSymbolKindString
StringRef getSymbolKindString(SymbolKind K)
Definition: IndexSymbol.cpp:505
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:403
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:556
clang::index::SymbolRole::NameReference
@ NameReference
clang::index::SymbolPropertyBitNum
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:95
clang::index::SymbolRoleSet
unsigned SymbolRoleSet
Definition: IndexSymbol.h:131
clang::index::printSymbolName
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)
Definition: IndexSymbol.cpp:487
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:58
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:135
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:146
clang::index::SymbolPropertySet
uint16_t SymbolPropertySet
Definition: IndexSymbol.h:81
clang::index::SymbolRole::RelationContainedBy
@ RelationContainedBy
clang::index::SymbolRelation
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:134
clang::index::SymbolRole::RelationBaseOf
@ RelationBaseOf
clang::index::SymbolSubKind::CXXMoveConstructor
@ CXXMoveConstructor