clang  8.0.0svn
IndexSymbol.h
Go to the documentation of this file.
1 //===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H
11 #define LLVM_CLANG_INDEX_INDEXSYMBOL_H
12 
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Lex/MacroInfo.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/Support/DataTypes.h"
17 
18 namespace clang {
19  class Decl;
20  class LangOptions;
21 
22 namespace index {
23 
24 enum class SymbolKind : uint8_t {
25  Unknown,
26 
27  Module,
28  Namespace,
30  Macro,
31 
32  Enum,
33  Struct,
34  Class,
35  Protocol,
36  Extension,
37  Union,
38  TypeAlias,
39 
40  Function,
41  Variable,
42  Field,
44 
51 
53  Destructor,
55 
56  Parameter,
57  Using,
58 };
59 
60 enum class SymbolLanguage : uint8_t {
61  C,
62  ObjC,
63  CXX,
64  Swift,
65 };
66 
67 /// Language specific sub-kinds.
68 enum class SymbolSubKind : uint8_t {
69  None,
75  UsingValue,
76 };
77 
78 typedef uint16_t SymbolPropertySet;
79 /// Set of properties that provide additional info about a symbol.
80 enum class SymbolProperty : SymbolPropertySet {
81  Generic = 1 << 0,
83  TemplateSpecialization = 1 << 2,
84  UnitTest = 1 << 3,
85  IBAnnotated = 1 << 4,
86  IBOutletCollection = 1 << 5,
87  GKInspectable = 1 << 6,
88  Local = 1 << 7,
89  /// Symbol is part of a protocol interface.
90  ProtocolInterface = 1 << 8,
91 };
92 static const unsigned SymbolPropertyBitNum = 9;
93 
94 /// Set of roles that are attributed to symbol occurrences.
95 ///
96 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
97 enum class SymbolRole : uint32_t {
98  Declaration = 1 << 0,
99  Definition = 1 << 1,
100  Reference = 1 << 2,
101  Read = 1 << 3,
102  Write = 1 << 4,
103  Call = 1 << 5,
104  Dynamic = 1 << 6,
105  AddressOf = 1 << 7,
106  Implicit = 1 << 8,
107  // FIXME: this is not mirrored in CXSymbolRole.
108  // Note that macro occurrences aren't currently supported in libclang.
109  Undefinition = 1 << 9, // macro #undef
110 
111  // Relation roles.
112  RelationChildOf = 1 << 10,
113  RelationBaseOf = 1 << 11,
114  RelationOverrideOf = 1 << 12,
115  RelationReceivedBy = 1 << 13,
116  RelationCalledBy = 1 << 14,
117  RelationExtendedBy = 1 << 15,
118  RelationAccessorOf = 1 << 16,
119  RelationContainedBy = 1 << 17,
120  RelationIBTypeOf = 1 << 18,
121  RelationSpecializationOf = 1 << 19,
122 };
123 static const unsigned SymbolRoleBitNum = 20;
124 typedef unsigned SymbolRoleSet;
125 
126 /// Represents a relation to another symbol for a symbol occurrence.
128  SymbolRoleSet Roles;
130 
131  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
132  : Roles(Roles), RelatedSymbol(Sym) {}
133 };
134 
135 struct SymbolInfo {
139  SymbolPropertySet Properties;
140 };
141 
142 SymbolInfo getSymbolInfo(const Decl *D);
143 
145 
146 bool isFunctionLocalSymbol(const Decl *D);
147 
148 void applyForEachSymbolRole(SymbolRoleSet Roles,
149  llvm::function_ref<void(SymbolRole)> Fn);
150 bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
151  llvm::function_ref<bool(SymbolRole)> Fn);
152 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
153 
154 /// \returns true if no name was printed, false otherwise.
155 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
156 
157 StringRef getSymbolKindString(SymbolKind K);
160 
161 void applyForEachSymbolProperty(SymbolPropertySet Props,
162  llvm::function_ref<void(SymbolProperty)> Fn);
163 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
164 
165 } // namespace index
166 } // namespace clang
167 
168 #endif
StringRef getSymbolLanguageString(SymbolLanguage K)
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:127
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
uint16_t SymbolPropertySet
Definition: IndexSymbol.h:78
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:68
void applyForEachSymbolProperty(SymbolPropertySet Props, llvm::function_ref< void(SymbolProperty)> Fn)
SymbolRole
Set of roles that are attributed to symbol occurrences.
Definition: IndexSymbol.h:97
bool isFunctionLocalSymbol(const Decl *D)
Definition: IndexSymbol.cpp:53
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:50
static const unsigned SymbolRoleBitNum
Definition: IndexSymbol.h:123
StringRef getSymbolSubKindString(SymbolSubKind K)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
unsigned SymbolRoleSet
Definition: IndexSymbol.h:124
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:92
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:40
SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
Definition: IndexSymbol.h:131
SymbolProperty
Set of properties that provide additional info about a symbol.
Definition: IndexSymbol.h:80
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS)
SymbolInfo getSymbolInfo(const Decl *D)
Definition: IndexSymbol.cpp:88
SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI)
SymbolPropertySet Properties
Definition: IndexSymbol.h:139