clang  9.0.0svn
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,
57 };
58 
59 enum class SymbolLanguage : uint8_t {
60  C,
61  ObjC,
62  CXX,
63  Swift,
64 };
65 
66 /// Language specific sub-kinds.
67 enum class SymbolSubKind : uint8_t {
68  None,
74  UsingValue,
75 };
76 
77 typedef uint16_t SymbolPropertySet;
78 /// Set of properties that provide additional info about a symbol.
79 enum class SymbolProperty : SymbolPropertySet {
80  Generic = 1 << 0,
82  TemplateSpecialization = 1 << 2,
83  UnitTest = 1 << 3,
84  IBAnnotated = 1 << 4,
85  IBOutletCollection = 1 << 5,
86  GKInspectable = 1 << 6,
87  Local = 1 << 7,
88  /// Symbol is part of a protocol interface.
89  ProtocolInterface = 1 << 8,
90 };
91 static const unsigned SymbolPropertyBitNum = 9;
92 
93 /// Set of roles that are attributed to symbol occurrences.
94 ///
95 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
96 enum class SymbolRole : uint32_t {
97  Declaration = 1 << 0,
98  Definition = 1 << 1,
99  Reference = 1 << 2,
100  Read = 1 << 3,
101  Write = 1 << 4,
102  Call = 1 << 5,
103  Dynamic = 1 << 6,
104  AddressOf = 1 << 7,
105  Implicit = 1 << 8,
106  // FIXME: this is not mirrored in CXSymbolRole.
107  // Note that macro occurrences aren't currently supported in libclang.
108  Undefinition = 1 << 9, // macro #undef
109 
110  // Relation roles.
111  RelationChildOf = 1 << 10,
112  RelationBaseOf = 1 << 11,
113  RelationOverrideOf = 1 << 12,
114  RelationReceivedBy = 1 << 13,
115  RelationCalledBy = 1 << 14,
116  RelationExtendedBy = 1 << 15,
117  RelationAccessorOf = 1 << 16,
118  RelationContainedBy = 1 << 17,
119  RelationIBTypeOf = 1 << 18,
120  RelationSpecializationOf = 1 << 19,
121 };
122 static const unsigned SymbolRoleBitNum = 20;
123 typedef unsigned SymbolRoleSet;
124 
125 /// Represents a relation to another symbol for a symbol occurrence.
127  SymbolRoleSet Roles;
129 
130  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
131  : Roles(Roles), RelatedSymbol(Sym) {}
132 };
133 
134 struct SymbolInfo {
138  SymbolPropertySet Properties;
139 };
140 
141 SymbolInfo getSymbolInfo(const Decl *D);
142 
144 
145 bool isFunctionLocalSymbol(const Decl *D);
146 
147 void applyForEachSymbolRole(SymbolRoleSet Roles,
148  llvm::function_ref<void(SymbolRole)> Fn);
149 bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
150  llvm::function_ref<bool(SymbolRole)> Fn);
151 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
152 
153 /// \returns true if no name was printed, false otherwise.
154 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
155 
156 StringRef getSymbolKindString(SymbolKind K);
159 
160 void applyForEachSymbolProperty(SymbolPropertySet Props,
161  llvm::function_ref<void(SymbolProperty)> Fn);
162 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
163 
164 } // namespace index
165 } // namespace clang
166 
167 #endif
StringRef getSymbolLanguageString(SymbolLanguage K)
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:126
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
uint16_t SymbolPropertySet
Definition: IndexSymbol.h:77
Defines the clang::MacroInfo and clang::MacroDirective classes.
Symbol is part of a protocol interface.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
SymbolSubKind
Language specific sub-kinds.
Definition: IndexSymbol.h:67
void applyForEachSymbolProperty(SymbolPropertySet Props, llvm::function_ref< void(SymbolProperty)> Fn)
SymbolRole
Set of roles that are attributed to symbol occurrences.
Definition: IndexSymbol.h:96
bool isFunctionLocalSymbol(const Decl *D)
Definition: IndexSymbol.cpp:52
StringRef getSymbolKindString(SymbolKind K)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
static const unsigned SymbolRoleBitNum
Definition: IndexSymbol.h:122
StringRef getSymbolSubKindString(SymbolSubKind K)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
unsigned SymbolRoleSet
Definition: IndexSymbol.h:123
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:91
void applyForEachSymbolRole(SymbolRoleSet Roles, llvm::function_ref< void(SymbolRole)> Fn)
Dataflow Directional Tag Classes.
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
Definition: IndexSymbol.h:130
SymbolProperty
Set of properties that provide additional info about a symbol.
Definition: IndexSymbol.h:79
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS)
SymbolInfo getSymbolInfo(const Decl *D)
Definition: IndexSymbol.cpp:87
SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI)
SymbolPropertySet Properties
Definition: IndexSymbol.h:138