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>
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
20namespace librepr {
22#if USING(LIBREPR_PLATFORM_WINDOWS)
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
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
T free(T... args)
Definition ctvi/ctvi.h:9
std::string code_for()
Definition repr:39
std::string demangle(std::string_view mangled)
Definition demangle.h:21