forked from OSchip/llvm-project
[lldb/StringPrinter] Simplify StringPrinterBufferPointer, NFC
Remove its template arguments and delete its copy/assign methods.
This commit is contained in:
parent
bb6646ce0a
commit
63e6508221
|
@ -147,21 +147,20 @@ public:
|
|||
// pointers I don't need to free - which is what this class essentially is
|
||||
// It's very specialized to the needs of this file, and not suggested for
|
||||
// general use
|
||||
template <typename T = uint8_t, typename U = char, typename S = size_t>
|
||||
struct StringPrinterBufferPointer {
|
||||
public:
|
||||
typedef std::function<void(const T *)> Deleter;
|
||||
typedef std::function<void(const uint8_t *)> Deleter;
|
||||
|
||||
StringPrinterBufferPointer(std::nullptr_t ptr)
|
||||
: m_data(nullptr), m_size(0), m_deleter() {}
|
||||
|
||||
StringPrinterBufferPointer(const T *bytes, S size,
|
||||
StringPrinterBufferPointer(const uint8_t *bytes, size_t size,
|
||||
Deleter deleter = nullptr)
|
||||
: m_data(bytes), m_size(size), m_deleter(deleter) {}
|
||||
|
||||
StringPrinterBufferPointer(const U *bytes, S size,
|
||||
StringPrinterBufferPointer(const char *bytes, size_t size,
|
||||
Deleter deleter = nullptr)
|
||||
: m_data(reinterpret_cast<const T *>(bytes)), m_size(size),
|
||||
: m_data(reinterpret_cast<const uint8_t *>(bytes)), m_size(size),
|
||||
m_deleter(deleter) {}
|
||||
|
||||
StringPrinterBufferPointer(StringPrinterBufferPointer &&rhs)
|
||||
|
@ -169,23 +168,18 @@ public:
|
|||
rhs.m_data = nullptr;
|
||||
}
|
||||
|
||||
StringPrinterBufferPointer(const StringPrinterBufferPointer &rhs)
|
||||
: m_data(rhs.m_data), m_size(rhs.m_size), m_deleter(rhs.m_deleter) {
|
||||
rhs.m_data = nullptr; // this is why m_data has to be mutable
|
||||
}
|
||||
|
||||
~StringPrinterBufferPointer() {
|
||||
if (m_data && m_deleter)
|
||||
m_deleter(m_data);
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
||||
const T *GetBytes() const { return m_data; }
|
||||
const uint8_t *GetBytes() const { return m_data; }
|
||||
|
||||
const S GetSize() const { return m_size; }
|
||||
size_t GetSize() const { return m_size; }
|
||||
|
||||
StringPrinterBufferPointer &
|
||||
operator=(const StringPrinterBufferPointer &rhs) {
|
||||
operator=(StringPrinterBufferPointer &&rhs) {
|
||||
if (m_data && m_deleter)
|
||||
m_deleter(m_data);
|
||||
m_data = rhs.m_data;
|
||||
|
@ -196,13 +190,15 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
mutable const T *m_data;
|
||||
DISALLOW_COPY_AND_ASSIGN(StringPrinterBufferPointer);
|
||||
|
||||
const uint8_t *m_data;
|
||||
size_t m_size;
|
||||
Deleter m_deleter;
|
||||
};
|
||||
|
||||
typedef std::function<StringPrinter::StringPrinterBufferPointer<
|
||||
uint8_t, char, size_t>(uint8_t *, uint8_t *, uint8_t *&)>
|
||||
typedef std::function<StringPrinter::StringPrinterBufferPointer(
|
||||
uint8_t *, uint8_t *, uint8_t *&)>
|
||||
EscapingHelper;
|
||||
typedef std::function<EscapingHelper(GetPrintableElementType)>
|
||||
EscapingHelperGenerator;
|
||||
|
|
|
@ -28,7 +28,7 @@ using namespace lldb_private::formatters;
|
|||
// we define this for all values of type but only implement it for those we
|
||||
// care about that's good because we get linker errors for any unsupported type
|
||||
template <lldb_private::formatters::StringPrinter::StringElementType type>
|
||||
static StringPrinter::StringPrinterBufferPointer<>
|
||||
static StringPrinter::StringPrinterBufferPointer
|
||||
GetPrintableImpl(uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next);
|
||||
|
||||
// mimic isprint() for Unicode codepoints
|
||||
|
@ -60,11 +60,11 @@ static bool isprint(char32_t codepoint) {
|
|||
}
|
||||
|
||||
template <>
|
||||
StringPrinter::StringPrinterBufferPointer<>
|
||||
StringPrinter::StringPrinterBufferPointer
|
||||
GetPrintableImpl<StringPrinter::StringElementType::ASCII>(uint8_t *buffer,
|
||||
uint8_t *buffer_end,
|
||||
uint8_t *&next) {
|
||||
StringPrinter::StringPrinterBufferPointer<> retval = {nullptr};
|
||||
StringPrinter::StringPrinterBufferPointer retval = {nullptr};
|
||||
|
||||
switch (*buffer) {
|
||||
case 0:
|
||||
|
@ -125,11 +125,11 @@ static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1,
|
|||
}
|
||||
|
||||
template <>
|
||||
StringPrinter::StringPrinterBufferPointer<>
|
||||
StringPrinter::StringPrinterBufferPointer
|
||||
GetPrintableImpl<StringPrinter::StringElementType::UTF8>(uint8_t *buffer,
|
||||
uint8_t *buffer_end,
|
||||
uint8_t *&next) {
|
||||
StringPrinter::StringPrinterBufferPointer<> retval{nullptr};
|
||||
StringPrinter::StringPrinterBufferPointer retval{nullptr};
|
||||
|
||||
unsigned utf8_encoded_len = llvm::getNumBytesForUTF8(*buffer);
|
||||
|
||||
|
@ -224,7 +224,7 @@ GetPrintableImpl<StringPrinter::StringElementType::UTF8>(uint8_t *buffer,
|
|||
// Given a sequence of bytes, this function returns: a sequence of bytes to
|
||||
// actually print out + a length the following unscanned position of the buffer
|
||||
// is in next
|
||||
static StringPrinter::StringPrinterBufferPointer<>
|
||||
static StringPrinter::StringPrinterBufferPointer
|
||||
GetPrintable(StringPrinter::StringElementType type, uint8_t *buffer,
|
||||
uint8_t *buffer_end, uint8_t *&next) {
|
||||
if (!buffer)
|
||||
|
@ -247,13 +247,13 @@ StringPrinter::GetDefaultEscapingHelper(GetPrintableElementType elem_type) {
|
|||
switch (elem_type) {
|
||||
case GetPrintableElementType::UTF8:
|
||||
return [](uint8_t *buffer, uint8_t *buffer_end,
|
||||
uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> {
|
||||
uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer {
|
||||
return GetPrintable(StringPrinter::StringElementType::UTF8, buffer,
|
||||
buffer_end, next);
|
||||
};
|
||||
case GetPrintableElementType::ASCII:
|
||||
return [](uint8_t *buffer, uint8_t *buffer_end,
|
||||
uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> {
|
||||
uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer {
|
||||
return GetPrintable(StringPrinter::StringElementType::ASCII, buffer,
|
||||
buffer_end, next);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue