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);
137 if (
size_t Size = R.size()) {
139 std::memcpy(Buffer + CurrentPosition, &*R.begin(),
Size);
140 CurrentPosition +=
Size;
147 Buffer[CurrentPosition++] =
C;
152 size_t Size = R.size();
157 std::memmove(Buffer +
Size, Buffer, CurrentPosition);
158 std::memcpy(Buffer, &*R.begin(),
Size);
159 CurrentPosition +=
Size;
171 return writeUnsigned(
static_cast<unsigned long long>(std::abs(
N)),
N < 0);
175 return writeUnsigned(
N,
false);
179 return this->operator<<(static_cast<long long>(
N));
183 return this->operator<<(static_cast<unsigned long long>(
N));
187 return this->operator<<(static_cast<long long>(
N));
191 return this->operator<<(static_cast<unsigned long long>(
N));
194 void insert(
size_t Pos,
const char *S,
size_t N) {
200 std::memmove(Buffer + Pos +
N, Buffer + Pos, CurrentPosition - Pos);
201 std::memcpy(Buffer + Pos, S,
N);
202 CurrentPosition +=
N;
210 CurrentPosition = NewPos;
215 return Buffer[CurrentPosition - 1];
218 bool empty()
const {
return CurrentPosition == 0; }
233 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 ~OutputBuffer()=default
virtual void printRight(const Node &N)
OutputBuffer(char *StartBuf, size_t Size)
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)
struct OutputBuffer::@022130012352050223320041212153342131303002064135 TemplateTracker
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...
bool InsideTemplate
True if we're currently printing a template argument.
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)
OutputBuffer & operator+=(char C)
size_t getCurrentPosition() const
void printOpen(char Open='(')
bool isInParensInTemplateArgs() const
Returns true if we're currently between a '(' and ')' when printing template args.
void insert(size_t Pos, const char *S, size_t N)
OutputBuffer & operator<<(unsigned long N)
bool isInsideTemplateArgs() const
Returns true if we're printing template args.
OutputBuffer & operator<<(unsigned int N)
unsigned ParenDepth
The depth of '(' and ')' inside the currently printed template arguments.
ScopedOverride(T &Loc_, T NewVal)
ScopedOverride & operator=(const ScopedOverride &)=delete
ScopedOverride(const ScopedOverride &)=delete