LLVM: include/llvm/Demangle/Utility.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef DEMANGLE_UTILITY_H
17#define DEMANGLE_UTILITY_H
18
20
21#include
22#include
23#include
24#include
25#include
26#include <string_view>
27
29
31
32
33
35 char *Buffer = nullptr;
36 size_t CurrentPosition = 0;
37 size_t BufferCapacity = 0;
38
39
40 void grow(size_t N) {
41 size_t Need = N + CurrentPosition;
42 if (Need > BufferCapacity) {
43
44
45
46 Need += 1024 - 32;
47 BufferCapacity *= 2;
48 if (BufferCapacity < Need)
49 BufferCapacity = Need;
50 Buffer = static_cast<char *>(std::realloc(Buffer, BufferCapacity));
51 if (Buffer == nullptr)
52 std::abort();
53 }
54 }
55
57 std::array<char, 21> Temp;
58 char *TempPtr = Temp.data() + Temp.size();
59
60
61 do {
62 *--TempPtr = char('0' + N % 10);
63 N /= 10;
64 } while (N);
65
66
68 *--TempPtr = '-';
69
71 std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
72 }
73
74public:
76 : Buffer(StartBuf), BufferCapacity(Size) {}
80
83
85
86 operator std::string_view() const {
87 return std::string_view(Buffer, CurrentPosition);
88 }
89
90
91
92
95
96
97 virtual void notifyInsertion(size_t , size_t ) {}
98
99
100 virtual void notifyDeletion(size_t , size_t ) {}
101
102
103
106
107 struct {
108
109
111
112
115
116
117
121
122
124
133 *this += Close;
134 }
135
137 if (size_t Size = R.size()) {
139 std::memcpy(Buffer + CurrentPosition, &*R.begin(), Size);
140 CurrentPosition += Size;
141 }
142 return *this;
143 }
144
146 grow(1);
147 Buffer[CurrentPosition++] = C;
148 return *this;
149 }
150
152 size_t Size = R.size();
154 return *this;
155
157 std::memmove(Buffer + Size, Buffer, CurrentPosition);
158 std::memcpy(Buffer, &*R.begin(), Size);
159 CurrentPosition += Size;
160
162
163 return *this;
164 }
165
167
169
171 return writeUnsigned(static_cast<unsigned long long>(std::abs(N)), N < 0);
172 }
173
175 return writeUnsigned(N, false);
176 }
177
179 return this->operator<<(static_cast(N));
180 }
181
183 return this->operator<<(static_cast(N));
184 }
185
187 return this->operator<<(static_cast(N));
188 }
189
191 return this->operator<<(static_cast(N));
192 }
193
194 void insert(size_t Pos, const char *S, size_t N) {
196 if (N == 0)
197 return;
198
199 grow(N);
200 std::memmove(Buffer + Pos + N, Buffer + Pos, CurrentPosition - Pos);
201 std::memcpy(Buffer + Pos, S, N);
202 CurrentPosition += N;
203
205 }
206
210 CurrentPosition = NewPos;
211 }
212
215 return Buffer[CurrentPosition - 1];
216 }
217
218 bool empty() const { return CurrentPosition == 0; }
219
221 char *getBufferEnd() { return Buffer + CurrentPosition - 1; }
223};
224
226 T &Loc;
227 T Original;
228
229public:
231
233 Loc_ = std::move(NewVal);
234 }
236
239};
240
242
243#endif
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool isNeg(Value *V)
Returns true if the operation is a negation of V, and it works for both integers and floats.
#define DEMANGLE_NAMESPACE_END
#define DEMANGLE_ASSERT(__expr, __msg)
#define DEMANGLE_NAMESPACE_BEGIN
char * getBufferEnd()
Definition Utility.h:221
OutputBuffer & operator<<(unsigned long long N)
Definition Utility.h:174
OutputBuffer(const OutputBuffer &)=delete
size_t getBufferCapacity() const
Definition Utility.h:222
OutputBuffer & operator+=(std::string_view R)
Definition Utility.h:136
bool empty() const
Definition Utility.h:218
virtual ~OutputBuffer()=default
virtual void printRight(const Node &N)
OutputBuffer(char *StartBuf, size_t Size)
Definition Utility.h:75
virtual void printLeft(const Node &N)
Called by the demangler when printing the demangle tree.
OutputBuffer(char *StartBuf, size_t *SizePtr)
Definition Utility.h:77
OutputBuffer & operator<<(char C)
Definition Utility.h:168
struct OutputBuffer::@022130012352050223320041212153342131303002064135 TemplateTracker
char back() const
Definition Utility.h:213
OutputBuffer & operator=(const OutputBuffer &)=delete
virtual void notifyInsertion(size_t, size_t)
Called when we write to this object anywhere other than the end.
Definition Utility.h:97
OutputBuffer & prepend(std::string_view R)
Definition Utility.h:151
char * getBuffer()
Definition Utility.h:220
unsigned CurrentPackMax
Definition Utility.h:105
OutputBuffer & operator<<(std::string_view R)
Definition Utility.h:166
unsigned CurrentPackIndex
If a ParameterPackExpansion (or similar type) is encountered, the offset into the pack that we're cur...
Definition Utility.h:104
bool InsideTemplate
True if we're currently printing a template argument.
Definition Utility.h:113
OutputBuffer & operator<<(long N)
Definition Utility.h:178
OutputBuffer & operator<<(int N)
Definition Utility.h:186
OutputBuffer & operator<<(long long N)
Definition Utility.h:170
virtual void notifyDeletion(size_t, size_t)
Called when we make the CurrentPosition of this object smaller.
Definition Utility.h:100
void printClose(char Close=')')
Definition Utility.h:130
void setCurrentPosition(size_t NewPos)
Definition Utility.h:208
OutputBuffer & operator+=(char C)
Definition Utility.h:145
size_t getCurrentPosition() const
Definition Utility.h:207
void printOpen(char Open='(')
Definition Utility.h:125
bool isInParensInTemplateArgs() const
Returns true if we're currently between a '(' and ')' when printing template args.
Definition Utility.h:118
void insert(size_t Pos, const char *S, size_t N)
Definition Utility.h:194
OutputBuffer & operator<<(unsigned long N)
Definition Utility.h:182
bool isInsideTemplateArgs() const
Returns true if we're printing template args.
Definition Utility.h:123
OutputBuffer & operator<<(unsigned int N)
Definition Utility.h:190
unsigned ParenDepth
The depth of '(' and ')' inside the currently printed template arguments.
Definition Utility.h:110
ScopedOverride(T &Loc_, T NewVal)
Definition Utility.h:232
ScopedOverride(T &Loc_)
Definition Utility.h:230
ScopedOverride & operator=(const ScopedOverride &)=delete
~ScopedOverride()
Definition Utility.h:235
ScopedOverride(const ScopedOverride &)=delete