8000 add support for demangling c++ type names (libstdc++) by BerndAmend · Pull Request #578 · ChaiScript/ChaiScript · GitHub
[go: up one dir, main page]

Skip to content

add support for demangling c++ type names (libstdc++) #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/chaiscript/dispatchkit/bootstrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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), &q 10000 uot;cpp_demangled_name");
m.add(fun(&Type_Info::bare_equal), "bare_equal");

basic_constructors<bool>("bool", m);
Expand Down
4 changes: 2 additions & 2 deletions include/chaiscript/dispatchkit/dispatchkit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ namespace chaiscript {
}
}

return ti.bare_name();
return ti.demangled_name();
}

/// Return all registered types
Expand Down Expand Up @@ -932,7 +932,7 @@ namespace chaiscript {
void dump_system() const {
std::cout << "Registered Types: \n";
for (const auto &[type_name, type] : get_types()) {
std::cout << type_name << ": " << type.bare_name() << '\n';
std::cout << type_name << ": " << type.demangled_name() << '\n';
}

std::cout << '\n';
Expand Down
22 changes: 22 additions & 0 deletions include/chaiscript/dispatchkit/type_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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:
Expand Down
0