repr 0.1
Reconstructable string representations and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
demangle.h
Go to the documentation of this file.
#pragma once
#include <string>
#include <string_view>
#include <librepr/feature.h>
#if USING(LIBREPR_PLATFORM_WINDOWS)
#include "detail/denoise.h"
#elif __has_include(<cxxabi.h>)
#include <cxxabi.h>
#include <memory>
#else
#error No available demangling method!
#endif
namespace librepr {
#if USING(LIBREPR_PLATFORM_WINDOWS)
auto count = detail::undecorate_name(mangled.data(), buffer);
if (count == 0) [[unlikely]] {
// Demangling failed...
return mangled.data();
}
if constexpr(!detail::msvc::has_rawname) {
// Check if the symbol was obtained with __FUNCDNAME__
if(mangled.starts_with("??$get_mangled_name")) [[likely]] {
using namespace detail;
std::string_view snip { buffer.data(), count };
snip.remove_prefix(strsize("char const * librepr::get_mangled_name<"));
snip.remove_suffix(strsize(">(void)"));
return denoise_name(snip);
}
}
return std::string(buffer.data(), count);
#else
struct FreeDeleter {
void operator()(void* ptr) const { std::free(ptr); }
};
abi::__cxa_demangle(mangled.data(), nullptr, nullptr, nullptr)
};
#endif
}
} // namespace librepr