IndexSymbol.h revision 321369
1//===--- IndexSymbol.h - Types and functions for indexing symbols ---------===//
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 "llvm/ADT/STLExtras.h"
15#include "llvm/Support/DataTypes.h"
16
17namespace clang {
18  class Decl;
19  class LangOptions;
20
21namespace index {
22
23enum class SymbolKind : uint8_t {
24  Unknown,
25
26  Module,
27  Namespace,
28  NamespaceAlias,
29  Macro,
30
31  Enum,
32  Struct,
33  Class,
34  Protocol,
35  Extension,
36  Union,
37  TypeAlias,
38
39  Function,
40  Variable,
41  Field,
42  EnumConstant,
43
44  InstanceMethod,
45  ClassMethod,
46  StaticMethod,
47  InstanceProperty,
48  ClassProperty,
49  StaticProperty,
50
51  Constructor,
52  Destructor,
53  ConversionFunction,
54
55  Parameter,
56};
57
58enum class SymbolLanguage {
59  C,
60  ObjC,
61  CXX,
62  Swift,
63};
64
65/// Language specific sub-kinds.
66enum class SymbolSubKind {
67  None,
68  CXXCopyConstructor,
69  CXXMoveConstructor,
70  AccessorGetter,
71  AccessorSetter,
72};
73
74/// Set of properties that provide additional info about a symbol.
75enum class SymbolProperty : uint8_t {
76  Generic                       = 1 << 0,
77  TemplatePartialSpecialization = 1 << 1,
78  TemplateSpecialization        = 1 << 2,
79  UnitTest                      = 1 << 3,
80  IBAnnotated                   = 1 << 4,
81  IBOutletCollection            = 1 << 5,
82  GKInspectable                 = 1 << 6,
83  Local                         = 1 << 7,
84};
85static const unsigned SymbolPropertyBitNum = 8;
86typedef unsigned SymbolPropertySet;
87
88/// Set of roles that are attributed to symbol occurrences.
89enum class SymbolRole : uint32_t {
90  Declaration = 1 << 0,
91  Definition  = 1 << 1,
92  Reference   = 1 << 2,
93  Read        = 1 << 3,
94  Write       = 1 << 4,
95  Call        = 1 << 5,
96  Dynamic     = 1 << 6,
97  AddressOf   = 1 << 7,
98  Implicit    = 1 << 8,
99
100  // Relation roles.
101  RelationChildOf     = 1 << 9,
102  RelationBaseOf      = 1 << 10,
103  RelationOverrideOf  = 1 << 11,
104  RelationReceivedBy  = 1 << 12,
105  RelationCalledBy    = 1 << 13,
106  RelationExtendedBy  = 1 << 14,
107  RelationAccessorOf  = 1 << 15,
108  RelationContainedBy = 1 << 16,
109  RelationIBTypeOf    = 1 << 17,
110  RelationSpecializationOf = 1 << 18,
111};
112static const unsigned SymbolRoleBitNum = 19;
113typedef unsigned SymbolRoleSet;
114
115/// Represents a relation to another symbol for a symbol occurrence.
116struct SymbolRelation {
117  SymbolRoleSet Roles;
118  const Decl *RelatedSymbol;
119
120  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
121    : Roles(Roles), RelatedSymbol(Sym) {}
122};
123
124struct SymbolInfo {
125  SymbolKind Kind;
126  SymbolSubKind SubKind;
127  SymbolPropertySet Properties;
128  SymbolLanguage Lang;
129};
130
131SymbolInfo getSymbolInfo(const Decl *D);
132
133bool isFunctionLocalSymbol(const Decl *D);
134
135void applyForEachSymbolRole(SymbolRoleSet Roles,
136                            llvm::function_ref<void(SymbolRole)> Fn);
137bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
138                            llvm::function_ref<bool(SymbolRole)> Fn);
139void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
140
141/// \returns true if no name was printed, false otherwise.
142bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
143
144StringRef getSymbolKindString(SymbolKind K);
145StringRef getSymbolSubKindString(SymbolSubKind K);
146StringRef getSymbolLanguageString(SymbolLanguage K);
147
148void applyForEachSymbolProperty(SymbolPropertySet Props,
149                            llvm::function_ref<void(SymbolProperty)> Fn);
150void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
151
152} // namespace index
153} // namespace clang
154
155#endif
156