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 3258791
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 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,18 +8,38 @@
#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 Corrade::Containers::Literals::operator ""_s;
using SVF = StringViewFlag;
constexpr auto my_strlen = [](const char* str) constexpr -> size_t {
const char* start = str;
for (; *str; str++)
;
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;
auto str = StringView { str_, my_strlen(str_), SVF::Global|SVF::NullTerminated };
#if 1
{
#ifdef _MSC_VER
constexpr StringView prefix = "auto __cdecl mangled_name<"_s, suffix = ">(void)"_s;
#elif defined __clang__
constexpr StringView prefix = "auto mangled_name() [T = "_s, suffix = "]"_s;
#else
constexpr StringView prefix = "constexpr auto mangled_name() [with T = "_s, suffix = "]"_s;
#endif

fm_assert(str.size() > prefix.size() + suffix.size());
for (auto i = 0uz; i < prefix.size(); i++)
fm_assert(str[i] == prefix[i]);
str = StringView{ str.data() + prefix.size(), str.size() - prefix.size() };
for (auto i = 0uz; i < suffix.size(); i++)
fm_assert(str[str.size() - 1 - i] == suffix[suffix.size() - 1 - i]);
str = StringView{ str.data(), str.size() - suffix.size() };
}
#endif
return str;
}

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

0 comments on commit 3258791

Please sign in to comment.