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 uint8_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 };
90 static const unsigned SymbolPropertyBitNum = 8;
91 
92 /// Set of roles that are attributed to symbol occurrences.
93 ///
94 /// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
95 enum class SymbolRole : uint32_t {
96  Declaration = 1 << 0,
97  Definition = 1 << 1,
98  Reference = 1 << 2,
99  Read = 1 << 3,
100  Write = 1 << 4,
101  Call = 1 << 5,
102  Dynamic = 1 << 6,
103  AddressOf = 1 << 7,
104  Implicit = 1 << 8,
105  // FIXME: this is not mirrored in CXSymbolRole.
106  // Note that macro occurrences aren't currently supported in libclang.
107  Undefinition = 1 << 9, // macro #undef
108 
109  // Relation roles.
110  RelationChildOf = 1 << 10,
111  RelationBaseOf = 1 << 11,
112  RelationOverrideOf = 1 << 12,
113  RelationReceivedBy = 1 << 13,
114  RelationCalledBy = 1 << 14,
115  RelationExtendedBy = 1 << 15,
116  RelationAccessorOf = 1 << 16,
117  RelationContainedBy = 1 << 17,
118  RelationIBTypeOf = 1 << 18,
119  RelationSpecializationOf = 1 << 19,
120 };
121 static const unsigned SymbolRoleBitNum = 20;
122 typedef unsigned SymbolRoleSet;
123 
124 /// Represents a relation to another symbol for a symbol occurrence.
126  SymbolRoleSet Roles;
128 
129  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
130  : Roles(Roles), RelatedSymbol(Sym) {}
131 };
132 
133 struct SymbolInfo {
137  SymbolPropertySet Properties;
138 };
139 
140 SymbolInfo getSymbolInfo(const Decl *D);
141 
143 
144 bool isFunctionLocalSymbol(const Decl *D);
145 
146 void applyForEachSymbolRole(SymbolRoleSet Roles,
147  llvm::function_ref<void(SymbolRole)> Fn);
148 bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
149  llvm::function_ref<bool(SymbolRole)> Fn);
150 void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
151 
152 /// \returns true if no name was printed, false otherwise.
153 bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
154 
155 StringRef getSymbolKindString(SymbolKind K);
158 
159 void applyForEachSymbolProperty(SymbolPropertySet Props,
160  llvm::function_ref<void(SymbolProperty)> Fn);
161 void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
162 
163 } // namespace index
164 } // namespace clang
165 
166 #endif
StringRef getSymbolLanguageString(SymbolLanguage K)
Represents a relation to another symbol for a symbol occurrence.
Definition: IndexSymbol.h:125
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Defines the clang::MacroInfo and clang::MacroDirective classes.
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:95
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:121
StringRef getSymbolSubKindString(SymbolSubKind K)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
unsigned SymbolRoleSet
Definition: IndexSymbol.h:122
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS)
uint8_t SymbolPropertySet
Definition: IndexSymbol.h:78
static const unsigned SymbolPropertyBitNum
Definition: IndexSymbol.h:90
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:129
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:137