IndexSymbol.h revision 314564
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
56enum class SymbolLanguage {
57  C,
58  ObjC,
59  CXX,
60};
61
62/// Language specific sub-kinds.
63enum class SymbolSubKind {
64  None,
65  CXXCopyConstructor,
66  CXXMoveConstructor,
67  AccessorGetter,
68  AccessorSetter,
69};
70
71/// Set of properties that provide additional info about a symbol.
72enum class SymbolProperty : uint8_t {
73  Generic                       = 1 << 0,
74  TemplatePartialSpecialization = 1 << 1,
75  TemplateSpecialization        = 1 << 2,
76  UnitTest                      = 1 << 3,
77  IBAnnotated                   = 1 << 4,
78  IBOutletCollection            = 1 << 5,
79  GKInspectable                 = 1 << 6,
80};
81static const unsigned SymbolPropertyBitNum = 7;
82typedef unsigned SymbolPropertySet;
83
84/// Set of roles that are attributed to symbol occurrences.
85enum class SymbolRole : uint32_t {
86  Declaration = 1 << 0,
87  Definition  = 1 << 1,
88  Reference   = 1 << 2,
89  Read        = 1 << 3,
90  Write       = 1 << 4,
91  Call        = 1 << 5,
92  Dynamic     = 1 << 6,
93  AddressOf   = 1 << 7,
94  Implicit    = 1 << 8,
95
96  // Relation roles.
97  RelationChildOf     = 1 << 9,
98  RelationBaseOf      = 1 << 10,
99  RelationOverrideOf  = 1 << 11,
100  RelationReceivedBy  = 1 << 12,
101  RelationCalledBy    = 1 << 13,
102  RelationExtendedBy  = 1 << 14,
103  RelationAccessorOf  = 1 << 15,
104  RelationContainedBy = 1 << 16,
105  RelationIBTypeOf    = 1 << 17,
106};
107static const unsigned SymbolRoleBitNum = 18;
108typedef unsigned SymbolRoleSet;
109
110/// Represents a relation to another symbol for a symbol occurrence.
111struct SymbolRelation {
112  SymbolRoleSet Roles;
113  const Decl *RelatedSymbol;
114
115  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
116    : Roles(Roles), RelatedSymbol(Sym) {}
117};
118
119struct SymbolInfo {
120  SymbolKind Kind;
121  SymbolSubKind SubKind;
122  SymbolPropertySet Properties;
123  SymbolLanguage Lang;
124};
125
126SymbolInfo getSymbolInfo(const Decl *D);
127
128void applyForEachSymbolRole(SymbolRoleSet Roles,
129                            llvm::function_ref<void(SymbolRole)> Fn);
130void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
131
132/// \returns true if no name was printed, false otherwise.
133bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
134
135StringRef getSymbolKindString(SymbolKind K);
136StringRef getSymbolSubKindString(SymbolSubKind K);
137StringRef getSymbolLanguageString(SymbolLanguage K);
138
139void applyForEachSymbolProperty(SymbolPropertySet Props,
140                            llvm::function_ref<void(SymbolProperty)> Fn);
141void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
142
143} // namespace index
144} // namespace clang
145
146#endif
147