blob: 54a06edc5ec1dc02affe6bbb5e480291bdde4234 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
//===-- DemangledNameInfo.cpp ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Core/DemangledNameInfo.h"
using namespace llvm::itanium_demangle;
namespace lldb_private {
bool TrackingOutputBuffer::shouldTrack() const {
if (!isPrintingTopLevelFunctionType())
return false;
if (isGtInsideTemplateArgs())
return false;
if (NameInfo.ArgumentsRange.first > 0)
return false;
return true;
}
bool TrackingOutputBuffer::canFinalize() const {
if (!isPrintingTopLevelFunctionType())
return false;
if (isGtInsideTemplateArgs())
return false;
if (NameInfo.ArgumentsRange.first == 0)
return false;
return true;
}
void TrackingOutputBuffer::updateBasenameEnd() {
if (!shouldTrack())
return;
NameInfo.BasenameRange.second = getCurrentPosition();
}
void TrackingOutputBuffer::updateScopeStart() {
if (!shouldTrack())
return;
NameInfo.ScopeRange.first = getCurrentPosition();
}
void TrackingOutputBuffer::updateScopeEnd() {
if (!shouldTrack())
return;
NameInfo.ScopeRange.second = getCurrentPosition();
}
void TrackingOutputBuffer::finalizeArgumentEnd() {
if (!canFinalize())
return;
NameInfo.ArgumentsRange.second = getCurrentPosition();
}
void TrackingOutputBuffer::finalizeQualifiersStart() {
if (!canFinalize())
return;
NameInfo.QualifiersRange.first = getCurrentPosition();
}
void TrackingOutputBuffer::finalizeQualifiersEnd() {
if (!canFinalize())
return;
NameInfo.QualifiersRange.second = getCurrentPosition();
}
void TrackingOutputBuffer::finalizeStart() {
if (!shouldTrack())
return;
NameInfo.ArgumentsRange.first = getCurrentPosition();
// If nothing has set the end of the basename yet (for example when
// printing templates), then the beginning of the arguments is the end of
// the basename.
if (NameInfo.BasenameRange.second == 0)
NameInfo.BasenameRange.second = getCurrentPosition();
assert(!shouldTrack());
assert(canFinalize());
}
void TrackingOutputBuffer::finalizeEnd() {
if (!canFinalize())
return;
if (NameInfo.ScopeRange.first > NameInfo.ScopeRange.second)
NameInfo.ScopeRange.second = NameInfo.ScopeRange.first;
NameInfo.BasenameRange.first = NameInfo.ScopeRange.second;
}
ScopedOverride<unsigned> TrackingOutputBuffer::enterFunctionTypePrinting() {
return {FunctionPrintingDepth, FunctionPrintingDepth + 1};
}
bool TrackingOutputBuffer::isPrintingTopLevelFunctionType() const {
return FunctionPrintingDepth == 1;
}
void TrackingOutputBuffer::printLeft(const Node &N) {
switch (N.getKind()) {
case Node::KFunctionType:
printLeftImpl(static_cast<const FunctionType &>(N));
break;
case Node::KFunctionEncoding:
printLeftImpl(static_cast<const FunctionEncoding &>(N));
break;
case Node::KNestedName:
printLeftImpl(static_cast<const NestedName &>(N));
break;
case Node::KNameWithTemplateArgs:
printLeftImpl(static_cast<const NameWithTemplateArgs &>(N));
break;
default:
OutputBuffer::printLeft(N);
}
}
void TrackingOutputBuffer::printRight(const Node &N) {
switch (N.getKind()) {
case Node::KFunctionType:
printRightImpl(static_cast<const FunctionType &>(N));
break;
case Node::KFunctionEncoding:
printRightImpl(static_cast<const FunctionEncoding &>(N));
break;
default:
OutputBuffer::printRight(N);
}
}
void TrackingOutputBuffer::printLeftImpl(const FunctionType &N) {
auto Scoped = enterFunctionTypePrinting();
OutputBuffer::printLeft(N);
}
void TrackingOutputBuffer::printRightImpl(const FunctionType &N) {
auto Scoped = enterFunctionTypePrinting();
OutputBuffer::printRight(N);
}
void TrackingOutputBuffer::printLeftImpl(const FunctionEncoding &N) {
auto Scoped = enterFunctionTypePrinting();
const Node *Ret = N.getReturnType();
if (Ret) {
printLeft(*Ret);
if (!Ret->hasRHSComponent(*this))
*this += " ";
}
updateScopeStart();
N.getName()->print(*this);
}
void TrackingOutputBuffer::printRightImpl(const FunctionEncoding &N) {
auto Scoped = enterFunctionTypePrinting();
finalizeStart();
printOpen();
N.getParams().printWithComma(*this);
printClose();
finalizeArgumentEnd();
const Node *Ret = N.getReturnType();
if (Ret)
printRight(*Ret);
finalizeQualifiersStart();
auto CVQuals = N.getCVQuals();
auto RefQual = N.getRefQual();
auto *Attrs = N.getAttrs();
auto *Requires = N.getRequires();
if (CVQuals & QualConst)
*this += " const";
if (CVQuals & QualVolatile)
*this += " volatile";
if (CVQuals & QualRestrict)
*this += " restrict";
if (RefQual == FrefQualLValue)
*this += " &";
else if (RefQual == FrefQualRValue)
*this += " &&";
if (Attrs != nullptr)
Attrs->print(*this);
if (Requires != nullptr) {
*this += " requires ";
Requires->print(*this);
}
finalizeQualifiersEnd();
finalizeEnd();
}
void TrackingOutputBuffer::printLeftImpl(const NestedName &N) {
N.Qual->print(*this);
*this += "::";
updateScopeEnd();
N.Name->print(*this);
updateBasenameEnd();
}
void TrackingOutputBuffer::printLeftImpl(const NameWithTemplateArgs &N) {
N.Name->print(*this);
updateBasenameEnd();
N.TemplateArgs->print(*this);
}
} // namespace lldb_private
|