16#ifndef DEMANGLE_UTILITY_H
17#define DEMANGLE_UTILITY_H
35 char *Buffer =
nullptr;
36 size_t CurrentPosition = 0;
37 size_t BufferCapacity = 0;
41 size_t Need =
N + CurrentPosition;
42 if (Need > BufferCapacity) {
48 if (BufferCapacity < Need)
49 BufferCapacity = Need;
50 Buffer =
static_cast<char *
>(std::realloc(Buffer, BufferCapacity));
51 if (Buffer ==
nullptr)
57 std::array<char, 21> Temp;
58 char *TempPtr = Temp.data() + Temp.size();
62 *--TempPtr =
char(
'0' +
N % 10);
71 std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
76 : Buffer(StartBuf), BufferCapacity(
Size) {}
86 operator std::string_view()
const {
87 return std::string_view(Buffer, CurrentPosition);
123 if (
size_t Size = R.size()) {
125 std::memcpy(Buffer + CurrentPosition, &*R.begin(),
Size);
126 CurrentPosition +=
Size;
133 Buffer[CurrentPosition++] =
C;
138 size_t Size = R.size();
143 std::memmove(Buffer +
Size, Buffer, CurrentPosition);
144 std::memcpy(Buffer, &*R.begin(),
Size);
145 CurrentPosition +=
Size;
157 return writeUnsigned(
static_cast<unsigned long long>(std::abs(
N)),
N < 0);
161 return writeUnsigned(
N,
false);
165 return this->operator<<(static_cast<long long>(
N));
169 return this->operator<<(static_cast<unsigned long long>(
N));
173 return this->operator<<(static_cast<long long>(
N));
177 return this->operator<<(static_cast<unsigned long long>(
N));
180 void insert(
size_t Pos,
const char *S,
size_t N) {
186 std::memmove(Buffer + Pos +
N, Buffer + Pos, CurrentPosition - Pos);
187 std::memcpy(Buffer + Pos, S,
N);
188 CurrentPosition +=
N;
196 CurrentPosition = NewPos;
201 return Buffer[CurrentPosition - 1];
204 bool empty()
const {
return CurrentPosition == 0; }
219 Loc_ = std::move(NewVal);
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
OutputBuffer & operator<<(unsigned long long N)
OutputBuffer(const OutputBuffer &)=delete
size_t getBufferCapacity() const
OutputBuffer & operator+=(std::string_view R)
virtual void printRight(const Node &N)
OutputBuffer(char *StartBuf, size_t Size)
unsigned GtIsGt
When zero, we're printing template args and '>' needs to be parenthesized.
virtual void printLeft(const Node &N)
Called by the demangler when printing the demangle tree.
OutputBuffer(char *StartBuf, size_t *SizePtr)
OutputBuffer & operator<<(char C)
OutputBuffer & operator=(const OutputBuffer &)=delete
virtual void notifyInsertion(size_t, size_t)
Called when we write to this object anywhere other than the end.
OutputBuffer & prepend(std::string_view R)
OutputBuffer & operator<<(std::string_view R)
unsigned CurrentPackIndex
If a ParameterPackExpansion (or similar type) is encountered, the offset into the pack that we're cur...
OutputBuffer & operator<<(long N)
OutputBuffer & operator<<(int N)
OutputBuffer & operator<<(long long N)
virtual void notifyDeletion(size_t, size_t)
Called when we make the CurrentPosition of this object smaller.
void printClose(char Close=')')
void setCurrentPosition(size_t NewPos)
bool isGtInsideTemplateArgs() const
OutputBuffer & operator+=(char C)
size_t getCurrentPosition() const
void printOpen(char Open='(')
void insert(size_t Pos, const char *S, size_t N)
OutputBuffer & operator<<(unsigned long N)
OutputBuffer & operator<<(unsigned int N)
ScopedOverride(T &Loc_, T NewVal)
ScopedOverride & operator=(const ScopedOverride &)=delete
ScopedOverride(const ScopedOverride &)=delete