LLDB mainline
DemangledNameInfo.cpp
Go to the documentation of this file.
1//===-- DemangledNameInfo.cpp ---------------------------------------------===//
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
10
11using namespace llvm::itanium_demangle;
12
13namespace lldb_private {
14
17 return false;
18
19 if (isGtInsideTemplateArgs())
20 return false;
21
22 if (NameInfo.ArgumentsRange.first > 0)
23 return false;
24
25 return true;
26}
27
30 return false;
31
32 if (isGtInsideTemplateArgs())
33 return false;
34
35 if (NameInfo.ArgumentsRange.first == 0)
36 return false;
37
38 return true;
39}
40
42 if (!shouldTrack())
43 return;
44
45 NameInfo.BasenameRange.second = getCurrentPosition();
46}
47
49 if (!shouldTrack())
50 return;
51
52 NameInfo.ScopeRange.first = getCurrentPosition();
53}
54
56 if (!shouldTrack())
57 return;
58
59 NameInfo.ScopeRange.second = getCurrentPosition();
60}
61
63 if (!canFinalize())
64 return;
65
66 NameInfo.ArgumentsRange.second = getCurrentPosition();
67}
68
70 if (!canFinalize())
71 return;
72
73 NameInfo.QualifiersRange.first = getCurrentPosition();
74}
75
77 if (!canFinalize())
78 return;
79
80 NameInfo.QualifiersRange.second = getCurrentPosition();
81}
82
84 if (!shouldTrack())
85 return;
86
87 NameInfo.ArgumentsRange.first = getCurrentPosition();
88
89 // If nothing has set the end of the basename yet (for example when
90 // printing templates), then the beginning of the arguments is the end of
91 // the basename.
92 if (NameInfo.BasenameRange.second == 0)
93 NameInfo.BasenameRange.second = getCurrentPosition();
94
95 // There is something between the basename and the start of the function
96 // arguments. Assume those are template arguments (which *should* be true for
97 // C++ demangled names, but this assumption may change in the future, in
98 // which case this needs to be adjusted).
99 if (NameInfo.BasenameRange.second != NameInfo.ArgumentsRange.first)
100 NameInfo.TemplateArgumentsRange = {NameInfo.BasenameRange.second,
101 NameInfo.ArgumentsRange.first};
102
103 assert(!shouldTrack());
104 assert(canFinalize());
105}
106
108 if (!canFinalize())
109 return;
110
111 if (NameInfo.ScopeRange.first > NameInfo.ScopeRange.second)
112 NameInfo.ScopeRange.second = NameInfo.ScopeRange.first;
113 NameInfo.BasenameRange.first = NameInfo.ScopeRange.second;
114
115 // We call anything past the FunctionEncoding the "suffix".
116 // In practice this would be nodes like `DotSuffix` that wrap
117 // a FunctionEncoding.
118 NameInfo.SuffixRange.first = getCurrentPosition();
119}
120
124
128
130 switch (N.getKind()) {
131 case Node::KFunctionType:
132 printLeftImpl(static_cast<const FunctionType &>(N));
133 break;
134 case Node::KFunctionEncoding:
135 printLeftImpl(static_cast<const FunctionEncoding &>(N));
136 break;
137 case Node::KNestedName:
138 printLeftImpl(static_cast<const NestedName &>(N));
139 break;
140 case Node::KNameWithTemplateArgs:
141 printLeftImpl(static_cast<const NameWithTemplateArgs &>(N));
142 break;
143 default:
144 OutputBuffer::printLeft(N);
145 }
146
147 // Keep updating suffix until we reach the end.
148 NameInfo.SuffixRange.second = getCurrentPosition();
149}
150
152 switch (N.getKind()) {
153 case Node::KFunctionType:
154 printRightImpl(static_cast<const FunctionType &>(N));
155 break;
156 case Node::KFunctionEncoding:
157 printRightImpl(static_cast<const FunctionEncoding &>(N));
158 break;
159 default:
160 OutputBuffer::printRight(N);
161 }
162
163 // Keep updating suffix until we reach the end.
164 NameInfo.SuffixRange.second = getCurrentPosition();
165}
166
167void TrackingOutputBuffer::printLeftImpl(const FunctionType &N) {
168 auto Scoped = enterFunctionTypePrinting();
169 OutputBuffer::printLeft(N);
170}
171
172void TrackingOutputBuffer::printRightImpl(const FunctionType &N) {
173 auto Scoped = enterFunctionTypePrinting();
174 OutputBuffer::printRight(N);
175}
176
177void TrackingOutputBuffer::printLeftImpl(const FunctionEncoding &N) {
178 auto Scoped = enterFunctionTypePrinting();
179
180 const Node *Ret = N.getReturnType();
181 if (Ret) {
182 printLeft(*Ret);
183 if (!Ret->hasRHSComponent(*this))
184 *this += " ";
185 }
186
188
189 N.getName()->print(*this);
190}
191
192void TrackingOutputBuffer::printRightImpl(const FunctionEncoding &N) {
193 auto Scoped = enterFunctionTypePrinting();
195
196 printOpen();
197 N.getParams().printWithComma(*this);
198 printClose();
199
201
202 const Node *Ret = N.getReturnType();
203
204 if (Ret)
205 printRight(*Ret);
206
208
209 auto CVQuals = N.getCVQuals();
210 auto RefQual = N.getRefQual();
211 auto *Attrs = N.getAttrs();
212 auto *Requires = N.getRequires();
213
214 if (CVQuals & QualConst)
215 *this += " const";
216 if (CVQuals & QualVolatile)
217 *this += " volatile";
218 if (CVQuals & QualRestrict)
219 *this += " restrict";
220 if (RefQual == FrefQualLValue)
221 *this += " &";
222 else if (RefQual == FrefQualRValue)
223 *this += " &&";
224 if (Attrs != nullptr)
225 Attrs->print(*this);
226 if (Requires != nullptr) {
227 *this += " requires ";
228 Requires->print(*this);
229 }
230
232 finalizeEnd();
233}
234
235void TrackingOutputBuffer::printLeftImpl(const NestedName &N) {
236 N.Qual->print(*this);
237 *this += "::";
239 N.Name->print(*this);
241}
242
243void TrackingOutputBuffer::printLeftImpl(const NameWithTemplateArgs &N) {
244 N.Name->print(*this);
246 N.TemplateArgs->print(*this);
247}
248
249} // namespace lldb_private
A class that represents a running process on the host machine.
void updateScopeStart()
If this object shouldTrack, then update the beginning of the scope range to the current OB position.
bool canFinalize() const
Helper used in the finalize APIs.
void printRightImpl(const llvm::itanium_demangle::FunctionType &N)
void printLeftImpl(const llvm::itanium_demangle::FunctionType &N)
bool isPrintingTopLevelFunctionType() const
Returns true if we're not printing any nested function types, just a FunctionEncoding in the Itanium ...
llvm::itanium_demangle::ScopedOverride< unsigned > enterFunctionTypePrinting()
Called whenever we start printing a function type in the Itanium mangling scheme.
void updateBasenameEnd()
If this object shouldTrack, then update the end of the basename range to the current OB position.
unsigned FunctionPrintingDepth
Incremented each time we start printing a function type node in the Itanium mangling scheme (e....
void printLeft(const llvm::itanium_demangle::Node &N) override
void finalizeArgumentEnd()
Helpers called to track beginning and end of the function arguments.
void updateScopeEnd()
If this object shouldTrack, then update the end of the scope range to the current OB position.
void printRight(const llvm::itanium_demangle::Node &N) override
bool shouldTrack() const
Returns true if the members of this object can be updated.
DemangledNameInfo NameInfo
Holds information about the demangled name that is being printed into this buffer.