16#ifndef DEMANGLE_UTILITY_H
17#define DEMANGLE_UTILITY_H
33 char *Buffer =
nullptr;
34 size_t CurrentPosition = 0;
35 size_t BufferCapacity = 0;
39 size_t Need =
N + CurrentPosition;
40 if (Need > BufferCapacity) {
46 if (BufferCapacity < Need)
47 BufferCapacity = Need;
48 Buffer =
static_cast<char *
>(std::realloc(Buffer, BufferCapacity));
49 if (Buffer ==
nullptr)
55 std::array<char, 21> Temp;
56 char *TempPtr = Temp.data() + Temp.size();
60 *--TempPtr =
char(
'0' +
N % 10);
69 std::string_view(TempPtr, Temp.data() + Temp.size() - TempPtr));
74 : Buffer(StartBuf), BufferCapacity(
Size) {}
82 operator std::string_view()
const {
83 return std::string_view(Buffer, CurrentPosition);
107 if (
size_t Size = R.size()) {
109 std::memcpy(Buffer + CurrentPosition, &*R.begin(),
Size);
110 CurrentPosition +=
Size;
117 Buffer[CurrentPosition++] =
C;
122 size_t Size = R.size();
125 std::memmove(Buffer +
Size, Buffer, CurrentPosition);
126 std::memcpy(Buffer, &*R.begin(),
Size);
127 CurrentPosition +=
Size;
137 return writeUnsigned(
static_cast<unsigned long long>(std::abs(
N)),
N < 0);
141 return writeUnsigned(
N,
false);
145 return this->operator<<(static_cast<long long>(
N));
149 return this->operator<<(static_cast<unsigned long long>(
N));
153 return this->operator<<(static_cast<long long>(
N));
157 return this->operator<<(static_cast<unsigned long long>(
N));
160 void insert(
size_t Pos,
const char *S,
size_t N) {
165 std::memmove(Buffer + Pos +
N, Buffer + Pos, CurrentPosition - Pos);
166 std::memcpy(Buffer + Pos, S,
N);
167 CurrentPosition +=
N;
175 return Buffer[CurrentPosition - 1];
178 bool empty()
const {
return CurrentPosition == 0; }
193 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)
OutputBuffer(char *StartBuf, size_t Size)
unsigned GtIsGt
When zero, we're printing template args and '>' needs to be parenthesized.
OutputBuffer(char *StartBuf, size_t *SizePtr)
OutputBuffer & operator<<(char C)
OutputBuffer & operator=(const OutputBuffer &)=delete
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)
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