LLDB mainline
DemangledNameInfo.h
Go to the documentation of this file.
1//===-- DemangledNameInfo.h -------------------------------------*- 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 LLDB_CORE_DEMANGLEDNAMEINFO_H
10#define LLDB_CORE_DEMANGLEDNAMEINFO_H
11
12#include "llvm/Demangle/ItaniumDemangle.h"
13#include "llvm/Demangle/Utility.h"
14
15#include <cstddef>
16#include <utility>
17
18namespace lldb_private {
19
20/// Stores information about where certain portions of a demangled
21/// function name begin and end.
23 /// A [start, end) pair for the function basename.
24 /// The basename is the name without scope qualifiers
25 /// and without template parameters.
26 ///
27 /// E.g.,
28 /// \code{.cpp}
29 /// void foo::bar<int>::someFunc<float>(int) const &&
30 /// ^ ^
31 /// start end
32 /// \endcode
33 std::pair<size_t, size_t> BasenameRange;
34
35 /// A [start, end) pair for the function template arguments.
36 ///
37 /// E.g.,
38 /// \code{.cpp}
39 /// void foo::bar<int>::someFunc<float>(int) const &&
40 /// ^ ^
41 /// start end
42 /// \endcode
43 std::pair<size_t, size_t> TemplateArgumentsRange;
44
45 /// A [start, end) pair for the function scope qualifiers.
46 ///
47 /// E.g.,
48 /// \code{.cpp}
49 /// void foo::bar<int>::qux<float>(int) const &&
50 /// ^ ^
51 /// start end
52 /// \endcode
53 std::pair<size_t, size_t> ScopeRange;
54
55 /// Indicates the [start, end) of the function argument list.
56 ///
57 /// E.g.,
58 /// \code{.cpp}
59 /// int (*getFunc<float>(float, double))(int, int)
60 /// ^ ^
61 /// start end
62 /// \endcode
63 std::pair<size_t, size_t> ArgumentsRange;
64
65 /// Indicates the [start, end) of the function qualifiers
66 /// (e.g., CV-qualifiers, reference qualifiers, requires clauses).
67 ///
68 /// E.g.,
69 /// \code{.cpp}
70 /// void foo::bar<int>::qux<float>(int) const &&
71 /// ^ ^
72 /// start end
73 /// \endcode
74 std::pair<size_t, size_t> QualifiersRange;
75
76 /// Indicates the [start, end) of the function's name qualifiers. This is a
77 /// catch-all range for anything in between the basename and the function's
78 /// arguments or template arguments, that is not tracked by the rest of the
79 /// pairs.
80 ///
81 /// E.g.,
82 /// \code{.swift}
83 /// closure #1 in A.foo<Int>()
84 /// ^ ^
85 /// start end
86 /// \endcode
87 std::pair<size_t, size_t> NameQualifiersRange;
88
89 /// Indicates the [start, end) of the function's prefix. This is a
90 /// catch-all range for anything that is not tracked by the rest of
91 /// the pairs.
92 std::pair<size_t, size_t> PrefixRange;
93
94 /// Indicates the [start, end) of the function's suffix. This is a
95 /// catch-all range for anything that is not tracked by the rest of
96 /// the pairs.
97 std::pair<size_t, size_t> SuffixRange;
98
99 /// Returns \c true if this object holds a valid basename range.
100 bool hasBasename() const {
101 // A function always has a name.
102 return BasenameRange.second > BasenameRange.first;
103 }
104
105 /// Returns \c true if this object holds a valid template arguments range.
106 bool hasTemplateArguments() const {
107 return TemplateArgumentsRange.second >= TemplateArgumentsRange.first;
108 }
109
110 /// Returns \c true if this object holds a valid scope range.
111 bool hasScope() const { return ScopeRange.second >= ScopeRange.first; }
112
113 /// Returns \c true if this object holds a valid arguments range.
114 bool hasArguments() const {
115 return ArgumentsRange.second >= ArgumentsRange.first;
116 }
117
118 /// Returns \c true if this object holds a valid qualifiers range.
119 bool hasQualifiers() const {
120 return QualifiersRange.second >= QualifiersRange.first;
121 }
122
123 /// Returns \c true if this object holds a valid name qualifiers range.
124 bool hasNameQualifiers() const {
125 return NameQualifiersRange.second >= NameQualifiersRange.first;
126 }
127
128 /// Returns \c true if this object holds a valid prefix range.
129 bool hasPrefix() const { return PrefixRange.second >= PrefixRange.first; }
130
131 /// Returns \c true if this object holds a valid suffix range.
132 bool hasSuffix() const { return SuffixRange.second >= SuffixRange.first; }
133};
134
135/// An OutputBuffer which keeps a record of where certain parts of a
136/// demangled name begin/end (e.g., basename, scope, argument list, etc.).
137/// The tracking occurs during printing of the Itanium demangle tree.
138///
139/// Usage:
140/// \code{.cpp}
141///
142/// Node *N = mangling_parser.parseType();
143///
144/// TrackingOutputBuffer buffer;
145/// N->printLeft(OB);
146///
147/// assert (buffer.NameInfo.hasBasename());
148///
149/// \endcode
151 using OutputBuffer::OutputBuffer;
152
153 /// Holds information about the demangled name that is
154 /// being printed into this buffer.
156
157 void printLeft(const llvm::itanium_demangle::Node &N) override;
158 void printRight(const llvm::itanium_demangle::Node &N) override;
159
160private:
161 void printLeftImpl(const llvm::itanium_demangle::FunctionType &N);
162 void printRightImpl(const llvm::itanium_demangle::FunctionType &N);
163
164 void printLeftImpl(const llvm::itanium_demangle::FunctionEncoding &N);
165 void printRightImpl(const llvm::itanium_demangle::FunctionEncoding &N);
166
167 void printLeftImpl(const llvm::itanium_demangle::NestedName &N);
168 void printLeftImpl(const llvm::itanium_demangle::NameWithTemplateArgs &N);
169
170 /// Called whenever we start printing a function type in the Itanium
171 /// mangling scheme. Examples include \ref FunctionEncoding, \ref
172 /// FunctionType, etc.
173 ///
174 /// \returns A ScopedOverride which will update the nesting depth of
175 /// currently printed function types on destruction.
176 [[nodiscard]] llvm::itanium_demangle::ScopedOverride<unsigned>
178
179 /// Returns \c true if we're not printing any nested function types,
180 /// just a \ref FunctionEncoding in the Itanium mangling scheme.
182
183 /// If this object \ref shouldTrack, then update the end of
184 /// the basename range to the current \c OB position.
185 void updateBasenameEnd();
186
187 /// If this object \ref shouldTrack, then update the beginning
188 /// of the scope range to the current \c OB position.
189 void updateScopeStart();
190
191 /// If this object \ref shouldTrack, then update the end of
192 /// the scope range to the current \c OB position.
193 void updateScopeEnd();
194
195 /// Returns \c true if the members of this object can be
196 /// updated. E.g., when we're printing nested template
197 /// arguments, we don't need to be tracking basename
198 /// locations.
199 bool shouldTrack() const;
200
201 /// Helpers called to track beginning and end of the function
202 /// arguments.
203 void finalizeArgumentEnd();
204 void finalizeStart();
205 void finalizeEnd();
208
209 /// Helper used in the finalize APIs.
210 bool canFinalize() const;
211
212 /// Incremented each time we start printing a function type node
213 /// in the Itanium mangling scheme (e.g., \ref FunctionEncoding
214 /// or \ref FunctionType).
216};
217} // namespace lldb_private
218
219#endif // LLDB_CORE_DEMANGLEDNAMEINFO_H
A class that represents a running process on the host machine.
Stores information about where certain portions of a demangled function name begin and end.
bool hasSuffix() const
Returns true if this object holds a valid suffix range.
bool hasBasename() const
Returns true if this object holds a valid basename range.
std::pair< size_t, size_t > TemplateArgumentsRange
A [start, end) pair for the function template arguments.
std::pair< size_t, size_t > NameQualifiersRange
Indicates the [start, end) of the function's name qualifiers.
std::pair< size_t, size_t > ArgumentsRange
Indicates the [start, end) of the function argument list.
bool hasPrefix() const
Returns true if this object holds a valid prefix range.
std::pair< size_t, size_t > SuffixRange
Indicates the [start, end) of the function's suffix.
std::pair< size_t, size_t > PrefixRange
Indicates the [start, end) of the function's prefix.
std::pair< size_t, size_t > BasenameRange
A [start, end) pair for the function basename.
bool hasTemplateArguments() const
Returns true if this object holds a valid template arguments range.
bool hasScope() const
Returns true if this object holds a valid scope range.
bool hasNameQualifiers() const
Returns true if this object holds a valid name qualifiers range.
bool hasQualifiers() const
Returns true if this object holds a valid qualifiers range.
bool hasArguments() const
Returns true if this object holds a valid arguments range.
std::pair< size_t, size_t > ScopeRange
A [start, end) pair for the function scope qualifiers.
std::pair< size_t, size_t > QualifiersRange
Indicates the [start, end) of the function qualifiers (e.g., CV-qualifiers, reference qualifiers,...
An OutputBuffer which keeps a record of where certain parts of a demangled name begin/end (e....
void updateScopeStart()
If this object shouldTrack, then update the beginning of the scope range to the current OB position.
void printLeftImpl(const llvm::itanium_demangle::NameWithTemplateArgs &N)
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 printLeftImpl(const llvm::itanium_demangle::FunctionEncoding &N)
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 printRightImpl(const llvm::itanium_demangle::FunctionEncoding &N)
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 printLeftImpl(const llvm::itanium_demangle::NestedName &N)
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.