1// Copyright 2020 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "include/cppgc/internal/name-trait.h" 6 7#include <stdio.h> 8 9#include "src/base/logging.h" 10#include "src/base/macros.h" 11 12namespace cppgc { 13 14// static 15constexpr const char NameProvider::kHiddenName[]; 16 17// static 18constexpr const char NameProvider::kNoNameDeducible[]; 19 20namespace internal { 21 22// static 23HeapObjectName NameTraitBase::GetNameFromTypeSignature(const char* signature) { 24 // Parsing string of structure: 25 // static HeapObjectName NameTrait<int>::GetNameFor(...) [T = int] 26 if (!signature) return {NameProvider::kNoNameDeducible, true}; 27 28 const std::string raw(signature); 29 const auto start_pos = raw.rfind("T = ") + 4; 30 DCHECK_NE(std::string::npos, start_pos); 31 const auto len = raw.length() - start_pos - 1; 32 const std::string name = raw.substr(start_pos, len).c_str(); 33 char* name_buffer = new char[name.length() + 1]; 34 int written = snprintf(name_buffer, name.length() + 1, "%s", name.c_str()); 35 DCHECK_EQ(static_cast<size_t>(written), name.length()); 36 USE(written); 37 return {name_buffer, false}; 38} 39 40} // namespace internal 41} // namespace cppgc 42