Skip to content

Commit

Permalink
enable __PRETTY_FUNCTION__ trimming for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed May 3, 2024
1 parent d66c591 commit db64692
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions entity/name-of.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
//#include "compat/assert.hpp"
#include <Corrade/Containers/StringView.h>

#if defined _MSC_VER
Expand All @@ -7,8 +8,7 @@
#define FM_PRETTY_FUNCTION __PRETTY_FUNCTION__
#endif

template<typename T>
static constexpr auto mangled_name() { // NOLINT(bugprone-reserved-identifier)
template<typename T> static constexpr auto mangled_name() {
using namespace Corrade::Containers;
using SVF = StringViewFlag;
constexpr auto my_strlen = [](const char* str) constexpr -> size_t {
Expand All @@ -17,8 +17,35 @@ static constexpr auto mangled_name() { // NOLINT(bugprone-reserved-identifier)
;
return (size_t)(str - start);
};
const char* str = FM_PRETTY_FUNCTION;
return StringView { str, my_strlen(str), SVF::Global|SVF::NullTerminated };
const char* str_ = FM_PRETTY_FUNCTION;
const auto str = StringView { str_, my_strlen(str_), SVF::Global|SVF::NullTerminated };
#if 1
{
#ifdef _MSC_VER
constexpr const char prefix[] = "auto __cdecl mangled_name<";
constexpr const char suffix[] = suffix = ">(void)";
#elif defined __clang__
constexpr const char prefix[] = "auto mangled_name() [T = ";
constexpr const char suffix[] = "]";
#else
constexpr const char prefix[] = "constexpr auto mangled_name() [with T = ";
constexpr const char suffix[] = "]";
#endif

bool ok = true;
for (auto i = 0uz; i < sizeof(prefix)-1; i++)
if (!(ok &= str.data()[i] == prefix[i]))
break;
for (auto i = 0uz; i < sizeof(suffix)-1; i++)
if (!(ok &= str.data()[str.size() - 1 - i] == suffix[sizeof(suffix)-1 - 1 - i]))
break;
fm_assert(ok);
if (ok)
return StringView{ str.data() + sizeof(prefix)-1, str.size() - sizeof(prefix)-1 - sizeof(suffix)-1 };
else
return str;
}
#endif
}

template<typename T> constexpr inline auto name_of = mangled_name<T>();

0 comments on commit db64692

Please sign in to comment.