-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
909 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//****************************************************************************** | ||
// Includes | ||
//****************************************************************************** | ||
|
||
#include "Utilities/Demangle.hpp" | ||
|
||
/// \cond | ||
// #define DEMANGLE_USE_BOOST | ||
/// \endcond | ||
|
||
#if defined(DEMANGLE_USE_BOOST) | ||
#include <boost/core/demangle.hpp> | ||
#elif defined(__clang__) || defined(__GNUG__) | ||
#include <cxxabi.h> | ||
#endif | ||
|
||
#if defined(DEMANGLE_USE_BOOST) | ||
std::string demangle(char const* name) { return boost::core::demangle(name); } | ||
#elif defined(__clang__) || defined(__GNUG__) | ||
// else we inline some logic of boost::core::demangle | ||
std::string demangle(char const* name) { | ||
int status(-1); | ||
char* demangled_name = abi::__cxa_demangle(name, nullptr, nullptr, &status); | ||
// status == 0 is good | ||
std::string class_name(status ? name : demangled_name); | ||
// Be a good boy and free | ||
std::free(demangled_name); // NOLINT | ||
return class_name; | ||
} | ||
#else | ||
std::string demangle(char const* name) { return name; } | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
//****************************************************************************** | ||
// Includes | ||
//****************************************************************************** | ||
|
||
#include <string> | ||
|
||
//****************************************************************************** | ||
/*!\brief Returns the demangled name of a compilation symbol | ||
// \ingroup UtilitiesGroup | ||
// | ||
// \usage | ||
\code | ||
auto demangled_name = demangle(typeid(int).name()); | ||
\endcode | ||
*/ | ||
std::string demangle(char const* name); | ||
//****************************************************************************** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Reused from SpECTRE : https://spectre-code.org/ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include "Utilities/PrettyType.hpp" | ||
|
||
#include <cstddef> | ||
#include <regex> | ||
|
||
namespace pretty_type { | ||
|
||
namespace detail { | ||
|
||
std::string extract_short_name(std::string name) { | ||
// Remove all template arguments | ||
const std::regex template_pattern("<[^<>]*>"); | ||
size_t previous_size = 0; | ||
while (name.size() != previous_size) { | ||
previous_size = name.size(); | ||
name = std::regex_replace(name, template_pattern, ""); | ||
} | ||
|
||
// Remove namespaces, etc. | ||
const size_t last_colon = name.rfind(':'); | ||
if (last_colon != std::string::npos) { | ||
name.replace(0, last_colon + 1, ""); | ||
} | ||
|
||
return name; | ||
} | ||
|
||
} // namespace detail | ||
|
||
} // namespace pretty_type |
Oops, something went wrong.