From db64692796590cab2c7344c86d4abfd67bbc87de Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 May 2024 11:29:34 +0200 Subject: [PATCH] enable __PRETTY_FUNCTION__ trimming for testing --- entity/name-of.hpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/entity/name-of.hpp b/entity/name-of.hpp index 42674a19..207beb0f 100644 --- a/entity/name-of.hpp +++ b/entity/name-of.hpp @@ -1,4 +1,5 @@ #pragma once +//#include "compat/assert.hpp" #include #if defined _MSC_VER @@ -7,8 +8,7 @@ #define FM_PRETTY_FUNCTION __PRETTY_FUNCTION__ #endif -template -static constexpr auto mangled_name() { // NOLINT(bugprone-reserved-identifier) +template static constexpr auto mangled_name() { using namespace Corrade::Containers; using SVF = StringViewFlag; constexpr auto my_strlen = [](const char* str) constexpr -> size_t { @@ -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 constexpr inline auto name_of = mangled_name();