Coverage Report

Created: 2020-09-22 08:39

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Index/IndexSymbol.h
Line
Count
Source
1
//===- IndexSymbol.h - Types and functions for indexing symbols -*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_INDEX_INDEXSYMBOL_H
10
#define LLVM_CLANG_INDEX_INDEXSYMBOL_H
11
12
#include "clang/Basic/LLVM.h"
13
#include "clang/Lex/MacroInfo.h"
14
#include "llvm/ADT/STLExtras.h"
15
#include "llvm/Support/DataTypes.h"
16
17
namespace clang {
18
  class Decl;
19
  class LangOptions;
20
21
namespace index {
22
23
enum 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
  Using,
57
  TemplateTypeParm,
58
  TemplateTemplateParm,
59
  NonTypeTemplateParm,
60
};
61
62
enum class SymbolLanguage : uint8_t {
63
  C,
64
  ObjC,
65
  CXX,
66
  Swift,
67
};
68
69
/// Language specific sub-kinds.
70
enum class SymbolSubKind : uint8_t {
71
  None,
72
  CXXCopyConstructor,
73
  CXXMoveConstructor,
74
  AccessorGetter,
75
  AccessorSetter,
76
  UsingTypename,
77
  UsingValue,
78
};
79
80
typedef uint16_t SymbolPropertySet;
81
/// Set of properties that provide additional info about a symbol.
82
enum class SymbolProperty : SymbolPropertySet {
83
  Generic                       = 1 << 0,
84
  TemplatePartialSpecialization = 1 << 1,
85
  TemplateSpecialization        = 1 << 2,
86
  UnitTest                      = 1 << 3,
87
  IBAnnotated                   = 1 << 4,
88
  IBOutletCollection            = 1 << 5,
89
  GKInspectable                 = 1 << 6,
90
  Local                         = 1 << 7,
91
  /// Symbol is part of a protocol interface.
92
  ProtocolInterface             = 1 << 8,
93
};
94
static const unsigned SymbolPropertyBitNum = 9;
95
96
/// Set of roles that are attributed to symbol occurrences.
97
///
98
/// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
99
enum class SymbolRole : uint32_t {
100
  Declaration = 1 << 0,
101
  Definition = 1 << 1,
102
  Reference = 1 << 2,
103
  Read = 1 << 3,
104
  Write = 1 << 4,
105
  Call = 1 << 5,
106
  Dynamic = 1 << 6,
107
  AddressOf = 1 << 7,
108
  Implicit = 1 << 8,
109
  // FIXME: this is not mirrored in CXSymbolRole.
110
  // Note that macro occurrences aren't currently supported in libclang.
111
  Undefinition = 1 << 9, // macro #undef
112
113
  // Relation roles.
114
  RelationChildOf = 1 << 10,
115
  RelationBaseOf = 1 << 11,
116
  RelationOverrideOf = 1 << 12,
117
  RelationReceivedBy = 1 << 13,
118
  RelationCalledBy = 1 << 14,
119
  RelationExtendedBy = 1 << 15,
120
  RelationAccessorOf = 1 << 16,
121
  RelationContainedBy = 1 << 17,
122
  RelationIBTypeOf = 1 << 18,
123
  RelationSpecializationOf = 1 << 19,
124
125
  // Symbol only references the name of the object as written. For example, a
126
  // constructor references the class declaration using that role.
127
  NameReference = 1 << 20,
128
};
129
static const unsigned SymbolRoleBitNum = 21;
130
typedef unsigned SymbolRoleSet;
131
132
/// Represents a relation to another symbol for a symbol occurrence.
133
struct SymbolRelation {
134
  SymbolRoleSet Roles;
135
  const Decl *RelatedSymbol;
136
137
  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
138
7.30k
    : Roles(Roles), RelatedSymbol(Sym) {}
139
};
140
141
struct SymbolInfo {
142
  SymbolKind Kind;
143
  SymbolSubKind SubKind;
144
  SymbolLanguage Lang;
145
  SymbolPropertySet Properties;
146
};
147
148
SymbolInfo getSymbolInfo(const Decl *D);
149
150
SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
151
152
bool isFunctionLocalSymbol(const Decl *D);
153
154
void applyForEachSymbolRole(SymbolRoleSet Roles,
155
                            llvm::function_ref<void(SymbolRole)> Fn);
156
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
157
                            llvm::function_ref<bool(SymbolRole)> Fn);
158
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
159
160
/// \returns true if no name was printed, false otherwise.
161
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
162
163
StringRef getSymbolKindString(SymbolKind K);
164
StringRef getSymbolSubKindString(SymbolSubKind K);
165
StringRef getSymbolLanguageString(SymbolLanguage K);
166
167
void applyForEachSymbolProperty(SymbolPropertySet Props,
168
                            llvm::function_ref<void(SymbolProperty)> Fn);
169
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
170
171
} // namespace index
172
} // namespace clang
173
174
#endif