mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 17:26:55 +08:00
add support for demangling c++ type names (libstdc++)
This commit is contained in:
parent
6411aa7498
commit
4929c5ab14
@ -384,6 +384,7 @@ namespace chaiscript::bootstrap {
|
||||
m.add(fun(&Type_Info::is_arithmetic), "is_type_arithmetic");
|
||||
m.add(fun(&Type_Info::name), "cpp_name");
|
||||
m.add(fun(&Type_Info::bare_name), "cpp_bare_name");
|
||||
m.add(fun(&Type_Info::demangled_name), "cpp_demangled_name");
|
||||
m.add(fun(&Type_Info::bare_equal), "bare_equal");
|
||||
|
||||
basic_constructors<bool>("bool", m);
|
||||
|
||||
@ -15,6 +15,10 @@
|
||||
#include <type_traits>
|
||||
#include <typeinfo>
|
||||
|
||||
#if __has_include(<cxxabi.h>)
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
namespace chaiscript {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
@ -83,6 +87,24 @@ namespace chaiscript {
|
||||
}
|
||||
}
|
||||
|
||||
std::string demangled_name() const noexcept {
|
||||
#if __has_include(<cxxabi.h>)
|
||||
if (is_undef())
|
||||
return "";
|
||||
|
||||
int status{};
|
||||
char *ret = abi::__cxa_demangle(m_bare_type_info->name(), nullptr, nullptr, &status);
|
||||
if (ret) {
|
||||
std::string value{ret};
|
||||
free(ret);
|
||||
return value;
|
||||
}
|
||||
return m_bare_type_info->name();
|
||||
#else
|
||||
return bare_name();
|
||||
#endif
|
||||
}
|
||||
|
||||
constexpr const std::type_info *bare_type_info() const noexcept { return m_bare_type_info; }
|
||||
|
||||
private:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user