5#ifndef INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
6#define INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
17#if CPPGC_SUPPORTS_OBJECT_NAMES && defined(__clang__)
18#define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 1
24 char name[Size + 1]{};
26 static constexpr NameBuffer FromCString(
const char* str) {
28 for (
size_t i = 0; i < Size; ++i) result.name[i] = str[i];
29 result.name[Size] = 0;
35const char* GetTypename() {
36 static constexpr char kSelfPrefix[] =
37 "const char *cppgc::internal::GetTypename() [T =";
38 static_assert(__builtin_strncmp(__PRETTY_FUNCTION__, kSelfPrefix,
39 sizeof(kSelfPrefix) - 1) == 0,
40 "The prefix must match");
41 static constexpr const char* kTypenameStart =
42 __PRETTY_FUNCTION__ +
sizeof(kSelfPrefix);
43 static constexpr size_t kTypenameSize =
44 __builtin_strlen(__PRETTY_FUNCTION__) -
sizeof(kSelfPrefix) - 1;
47 static constexpr auto buffer =
48 NameBuffer<kTypenameSize>::FromCString(kTypenameStart);
53#define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 0
72#if CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
74#elif CPPGC_SUPPORTS_OBJECT_NAMES
77 return std::is_base_of<NameProvider, T>::value;
82 return GetNameFor(
static_cast<const T*
>(obj));
90 static HeapObjectName GetNameFor(...) {
91#if CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
92 return {GetTypename<T>(),
false};
93#elif CPPGC_SUPPORTS_OBJECT_NAMES
96#define PRETTY_FUNCTION_VALUE __PRETTY_FUNCTION__
97#elif defined(V8_CC_MSVC)
98#define PRETTY_FUNCTION_VALUE __FUNCSIG__
100#define PRETTY_FUNCTION_VALUE nullptr
103 static const HeapObjectName leaky_name =
105 return {leaky_name,
false};
107#undef PRETTY_FUNCTION_VALUE
120#undef CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
virtual const char * GetHumanReadableName() const =0
static constexpr const char kHiddenName[]
static HeapObjectName GetNameFromTypeSignature(const char *)
static HeapObjectName GetName(const void *obj)
static constexpr bool HasNonHiddenName()
HeapObjectName(*)(const void *) NameCallback