Download include/node/cppgc/internal/name-trait.h from Ouzhang/node-v20-11-0-linux-x64: direct link, hf CLI and curl.
- Browser
- Download file 4.18 kB
-
https://huggingface.co/datasets/Ouzhang/node-v20-11-0-linux-x64/resolve/main/include/node/cppgc/internal/name-trait.h
- Command line
-
hf download hf://datasets/Ouzhang/node-v20-11-0-linux-x64/include/node/cppgc/internal/name-trait.h
-
curl -L -o name-trait.h https://huggingface.co/datasets/Ouzhang/node-v20-11-0-linux-x64/resolve/main/include/node/cppgc/internal/name-trait.h
4.18 kB
| // Copyright 2020 the V8 project authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| namespace cppgc { | |
| namespace internal { | |
| // Provides constexpr c-string storage for a name of fixed |Size| characters. | |
| // Automatically appends terminating 0 byte. | |
| template <size_t Size> | |
| struct NameBuffer { | |
| char name[Size + 1]{}; | |
| static constexpr NameBuffer FromCString(const char* str) { | |
| NameBuffer result; | |
| for (size_t i = 0; i < Size; ++i) result.name[i] = str[i]; | |
| result.name[Size] = 0; | |
| return result; | |
| } | |
| }; | |
| template <typename T> | |
| const char* GetTypename() { | |
| static constexpr char kSelfPrefix[] = | |
| "const char *cppgc::internal::GetTypename() [T ="; | |
| static_assert(__builtin_strncmp(__PRETTY_FUNCTION__, kSelfPrefix, | |
| sizeof(kSelfPrefix) - 1) == 0, | |
| "The prefix must match"); | |
| static constexpr const char* kTypenameStart = | |
| __PRETTY_FUNCTION__ + sizeof(kSelfPrefix); | |
| static constexpr size_t kTypenameSize = | |
| __builtin_strlen(__PRETTY_FUNCTION__) - sizeof(kSelfPrefix) - 1; | |
| // NameBuffer is an indirection that is needed to make sure that only a | |
| // substring of __PRETTY_FUNCTION__ gets materialized in the binary. | |
| static constexpr auto buffer = | |
| NameBuffer<kTypenameSize>::FromCString(kTypenameStart); | |
| return buffer.name; | |
| } | |
| struct HeapObjectName { | |
| const char* value; | |
| bool name_was_hidden; | |
| }; | |
| enum class HeapObjectNameForUnnamedObject : uint8_t { | |
| kUseClassNameIfSupported, | |
| kUseHiddenName, | |
| }; | |
| class V8_EXPORT NameTraitBase { | |
| protected: | |
| static HeapObjectName GetNameFromTypeSignature(const char*); | |
| }; | |
| // Trait that specifies how the garbage collector retrieves the name for a | |
| // given object. | |
| template <typename T> | |
| class NameTrait final : public NameTraitBase { | |
| public: | |
| static constexpr bool HasNonHiddenName() { | |
| return true; | |
| return true; | |
| return std::is_base_of<NameProvider, T>::value; | |
| } | |
| static HeapObjectName GetName( | |
| const void* obj, HeapObjectNameForUnnamedObject name_retrieval_mode) { | |
| return GetNameFor(static_cast<const T*>(obj), name_retrieval_mode); | |
| } | |
| private: | |
| static HeapObjectName GetNameFor(const NameProvider* name_provider, | |
| HeapObjectNameForUnnamedObject) { | |
| // Objects inheriting from `NameProvider` are not considered unnamed as | |
| // users already provided a name for them. | |
| return {name_provider->GetHumanReadableName(), false}; | |
| } | |
| static HeapObjectName GetNameFor( | |
| const void*, HeapObjectNameForUnnamedObject name_retrieval_mode) { | |
| if (name_retrieval_mode == HeapObjectNameForUnnamedObject::kUseHiddenName) | |
| return {NameProvider::kHiddenName, true}; | |
| return {GetTypename<T>(), false}; | |
| static const HeapObjectName leaky_name = | |
| GetNameFromTypeSignature(PRETTY_FUNCTION_VALUE); | |
| return leaky_name; | |
| return {NameProvider::kHiddenName, true}; | |
| } | |
| }; | |
| using NameCallback = HeapObjectName (*)(const void*, | |
| HeapObjectNameForUnnamedObject); | |
| } // namespace internal | |
| } // namespace cppgc | |