]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Index/IndexSymbol.h
Merge clang trunk r338150, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Index / IndexSymbol.h
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,
29   NamespaceAlias,
30   Macro,
31
32   Enum,
33   Struct,
34   Class,
35   Protocol,
36   Extension,
37   Union,
38   TypeAlias,
39
40   Function,
41   Variable,
42   Field,
43   EnumConstant,
44
45   InstanceMethod,
46   ClassMethod,
47   StaticMethod,
48   InstanceProperty,
49   ClassProperty,
50   StaticProperty,
51
52   Constructor,
53   Destructor,
54   ConversionFunction,
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,
70   CXXCopyConstructor,
71   CXXMoveConstructor,
72   AccessorGetter,
73   AccessorSetter,
74   UsingTypename,
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,
82   TemplatePartialSpecialization = 1 << 1,
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.
125 struct SymbolRelation {
126   SymbolRoleSet Roles;
127   const Decl *RelatedSymbol;
128
129   SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
130     : Roles(Roles), RelatedSymbol(Sym) {}
131 };
132
133 struct SymbolInfo {
134   SymbolKind Kind;
135   SymbolSubKind SubKind;
136   SymbolLanguage Lang;
137   SymbolPropertySet Properties;
138 };
139
140 SymbolInfo getSymbolInfo(const Decl *D);
141
142 SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
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);
156 StringRef getSymbolSubKindString(SymbolSubKind K);
157 StringRef getSymbolLanguageString(SymbolLanguage 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