repr
0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
demangle.h
Go to the documentation of this file.
1
#pragma once
2
#include <
string
>
3
#include <
string_view
>
4
5
#include <
librepr/feature.h
>
6
#include <
librepr/macro/util.h
>
7
#include <
librepr/macro/platform.h
>
8
#include <
librepr/util/string/util.h
>
9
10
#if USING(LIBREPR_PLATFORM_WINDOWS)
11
#include "
detail/undecorate.h
"
12
#include "
detail/denoise.h
"
13
#elif __has_include(<cxxabi.h>)
14
#include <cxxabi.h>
15
#include <
memory
>
16
#else
17
#error No available demangling method!
18
#endif
19
20
namespace
librepr
{
21
[[
nodiscard
]]
inline
std::string
demangle
(
std::string_view
mangled
) {
22
#if USING(LIBREPR_PLATFORM_WINDOWS)
23
detail::DemangleBuffer
buffer{};
24
auto
count = detail::undecorate_name(
mangled
.data(), buffer);
25
if
(count == 0) [[
unlikely
]] {
26
// Demangling failed...
27
return
mangled
.data();
28
}
29
if
constexpr
(!detail::msvc::has_rawname) {
30
// Check if the symbol was obtained with __FUNCDNAME__
31
if
(
mangled
.starts_with(
"??$get_mangled_name"
)) [[
likely
]] {
32
using namespace
detail;
33
std::string_view
snip
{ buffer.data(), count };
34
snip
.remove_prefix(strsize(
"char const * librepr::get_mangled_name<"
));
35
snip
.remove_suffix(strsize(
">(void)"
));
36
return
denoise_name(
snip
);
37
}
38
}
39
return
std::string
(buffer.data(), count);
40
#else
41
struct
FreeDeleter
{
42
void
operator()(
void
* ptr)
const
{
std::free
(ptr); }
43
};
44
45
auto
const
demangled
=
std::unique_ptr<char, FreeDeleter>
{
46
abi::__cxa_demangle(
mangled
.data(),
nullptr
,
nullptr
,
nullptr
)
47
};
48
49
return
std::string
{
demangled
?
demangled
.get() :
mangled
};
50
#endif
51
}
52
}
// namespace librepr
std::array
std::string
std::string_view
denoise.h
feature.h
std::free
T free(T... args)
util.h
memory
librepr
Definition
ctvi/ctvi.h:9
librepr::code_for
std::string code_for()
Definition
repr:39
librepr::demangle
std::string demangle(std::string_view mangled)
Definition
demangle.h:21
platform.h
string
string_view
undecorate.h
std::unique_ptr
util.h
include
librepr
name
demangle.h
Generated by
1.9.8, using the excellent
Doxygen Awesome
Theme