5#ifndef INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
6#define INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
18#if CPPGC_SUPPORTS_OBJECT_NAMES && defined(__clang__)
19#define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 1
25 char name[Size + 1]{};
27 static constexpr NameBuffer FromCString(
const char* str) {
29 for (
size_t i = 0; i < Size; ++i) result.name[i] = str[i];
30 result.name[Size] = 0;
36const char* GetTypename() {
37 static constexpr char kSelfPrefix[] =
38 "const char *cppgc::internal::GetTypename() [T =";
39 static_assert(__builtin_strncmp(__PRETTY_FUNCTION__, kSelfPrefix,
40 sizeof(kSelfPrefix) - 1) == 0,
41 "The prefix must match");
42 static constexpr const char* kTypenameStart =
43 __PRETTY_FUNCTION__ +
sizeof(kSelfPrefix);
44 static constexpr size_t kTypenameSize =
45 __builtin_strlen(__PRETTY_FUNCTION__) -
sizeof(kSelfPrefix) - 1;
48 static constexpr auto buffer =
49 NameBuffer<kTypenameSize>::FromCString(kTypenameStart);
54#define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 0
78#if CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
80#elif CPPGC_SUPPORTS_OBJECT_NAMES
83 return std::is_base_of<NameProvider, T>::value;
89 return GetNameFor(
static_cast<const T*
>(obj), name_retrieval_mode);
100 static HeapObjectName GetNameFor(
105#if CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
106 return {GetTypename<T>(),
false};
107#elif CPPGC_SUPPORTS_OBJECT_NAMES
109#if defined(V8_CC_GNU)
110#define PRETTY_FUNCTION_VALUE __PRETTY_FUNCTION__
111#elif defined(V8_CC_MSVC)
112#define PRETTY_FUNCTION_VALUE __FUNCSIG__
114#define PRETTY_FUNCTION_VALUE nullptr
117 static const HeapObjectName leaky_name =
121#undef PRETTY_FUNCTION_VALUE
135#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, HeapObjectNameForUnnamedObject name_retrieval_mode)
static constexpr bool HasNonHiddenName()
HeapObjectNameForUnnamedObject
@ kUseClassNameIfSupported
HeapObjectName(*)(const void *, HeapObjectNameForUnnamedObject) NameCallback