Coverage Report

Created: 2021-09-21 08:58

/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
  UsingEnum,
79
};
80
81
typedef uint16_t SymbolPropertySet;
82
/// Set of properties that provide additional info about a symbol.
83
enum class SymbolProperty : SymbolPropertySet {
84
  Generic                       = 1 << 0,
85
  TemplatePartialSpecialization = 1 << 1,
86
  TemplateSpecialization        = 1 << 2,
87
  UnitTest                      = 1 << 3,
88
  IBAnnotated                   = 1 << 4,
89
  IBOutletCollection            = 1 << 5,
90
  GKInspectable                 = 1 << 6,
91
  Local                         = 1 << 7,
92
  /// Symbol is part of a protocol interface.
93
  ProtocolInterface             = 1 << 8,
94
};
95
static const unsigned SymbolPropertyBitNum = 9;
96
97
/// Set of roles that are attributed to symbol occurrences.
98
///
99
/// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
100
enum class SymbolRole : uint32_t {
101
  Declaration = 1 << 0,
102
  Definition = 1 << 1,
103
  Reference = 1 << 2,
104
  Read = 1 << 3,
105
  Write = 1 << 4,
106
  Call = 1 << 5,
107
  Dynamic = 1 << 6,
108
  AddressOf = 1 << 7,
109
  Implicit = 1 << 8,
110
  // FIXME: this is not mirrored in CXSymbolRole.
111
  // Note that macro occurrences aren't currently supported in libclang.
112
  Undefinition = 1 << 9, // macro #undef
113
114
  // Relation roles.
115
  RelationChildOf = 1 << 10,
116
  RelationBaseOf = 1 << 11,
117
  RelationOverrideOf = 1 << 12,
118
  RelationReceivedBy = 1 << 13,
119
  RelationCalledBy = 1 << 14,
120
  RelationExtendedBy = 1 << 15,
121
  RelationAccessorOf = 1 << 16,
122
  RelationContainedBy = 1 << 17,
123
  RelationIBTypeOf = 1 << 18,
124
  RelationSpecializationOf = 1 << 19,
125
126
  // Symbol only references the name of the object as written. For example, a
127
  // constructor references the class declaration using that role.
128
  NameReference = 1 << 20,
129
};
130
static const unsigned SymbolRoleBitNum = 21;
131
typedef unsigned SymbolRoleSet;
132
133
/// Represents a relation to another symbol for a symbol occurrence.
134
struct SymbolRelation {
135
  SymbolRoleSet Roles;
136
  const Decl *RelatedSymbol;
137
138
  SymbolRelation(SymbolRoleSet Roles, const Decl *Sym)
139
7.31k
    : Roles(Roles), RelatedSymbol(Sym) {}
140
};
141
142
struct SymbolInfo {
143
  SymbolKind Kind;
144
  SymbolSubKind SubKind;
145
  SymbolLanguage Lang;
146
  SymbolPropertySet Properties;
147
};
148
149
SymbolInfo getSymbolInfo(const Decl *D);
150
151
SymbolInfo getSymbolInfoForMacro(const MacroInfo &MI);
152
153
bool isFunctionLocalSymbol(const Decl *D);
154
155
void applyForEachSymbolRole(SymbolRoleSet Roles,
156
                            llvm::function_ref<void(SymbolRole)> Fn);
157
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles,
158
                            llvm::function_ref<bool(SymbolRole)> Fn);
159
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
160
161
/// \returns true if no name was printed, false otherwise.
162
bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
163
164
StringRef getSymbolKindString(SymbolKind K);
165
StringRef getSymbolSubKindString(SymbolSubKind K);
166
StringRef getSymbolLanguageString(SymbolLanguage K);
167
168
void applyForEachSymbolProperty(SymbolPropertySet Props,
169
                            llvm::function_ref<void(SymbolProperty)> Fn);
170
void printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS);
171
172
} // namespace index
173
} // namespace clang
174
175
#endif