Commit 1060fb28 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Handle Clang on Windows in pretty_name

Summary: [Folly] Handle Clang on Windows in `pretty_name`.

Reviewed By: Orvid

Differential Revision: D14844690

fbshipit-source-id: 1f995604d5be0cd571caa344e5b18f877188390d
parent 47b5e69f
......@@ -17,6 +17,7 @@
#pragma once
#include <cstddef>
#include <type_traits>
#include <folly/Portability.h>
......@@ -72,41 +73,54 @@ static constexpr std::size_t pretty_rfind(
return ~std::size_t(0);
}
struct pretty_tag_msc {};
struct pretty_tag_gcc {};
using pretty_default_tag = std::conditional_t< //
kMscVer && !kIsClang,
pretty_tag_msc,
pretty_tag_gcc>;
template <typename T>
static constexpr auto pretty_raw() {
static constexpr auto pretty_raw(pretty_tag_msc) {
#if _MSC_VER
return pretty_carray_from(__FUNCSIG__);
#else
#endif
}
template <typename T>
static constexpr auto pretty_raw(pretty_tag_gcc) {
#if __GNUC__ || __clang__
return pretty_carray_from(__PRETTY_FUNCTION__);
#endif
}
template <std::size_t S>
static constexpr pretty_info pretty_parse_msc(char const (&name)[S]) {
// void __cdecl folly::detail::pretty_raw<{...}>(void)
static constexpr pretty_info pretty_parse(
pretty_tag_msc,
char const (&name)[S]) {
// void __cdecl folly::detail::pretty_raw<{...}>(
// folly::detail::pretty_tag_msc)
auto const la = pretty_lfind(name, '<');
auto const rp = pretty_rfind(name, '>');
return pretty_info{la + 1, rp};
}
template <std::size_t S>
static constexpr pretty_info pretty_parse_gcc(char const (&name)[S]) {
// void folly::detail::pretty_raw() [T = {...}]
static constexpr pretty_info pretty_parse(
pretty_tag_gcc,
char const (&name)[S]) {
// void folly::detail::pretty_raw(
// folly::detail::pretty_tag_gcc) [T = {...}]
auto const eq = pretty_lfind(name, '=');
auto const br = pretty_rfind(name, ']');
return pretty_info{eq + 2, br};
}
template <std::size_t S>
static constexpr pretty_info pretty_parse(char const (&name)[S]) {
return kMscVer ? detail::pretty_parse_msc(name)
: detail::pretty_parse_gcc(name);
}
template <typename T>
template <typename T, typename Tag>
struct pretty_name_zarray {
static constexpr auto raw = pretty_raw<T>();
static constexpr auto info = pretty_parse(raw.data);
static constexpr auto raw = pretty_raw<T>(Tag{});
static constexpr auto info = pretty_parse(Tag{}, raw.data);
static constexpr auto size = info.e - info.b;
static constexpr auto zarray_() {
pretty_carray<size + 1> data{};
......@@ -119,9 +133,9 @@ struct pretty_name_zarray {
static constexpr pretty_carray<size + 1> zarray = zarray_();
};
template <typename T>
constexpr pretty_carray<pretty_name_zarray<T>::size + 1>
pretty_name_zarray<T>::zarray;
template <typename T, typename Tag>
constexpr pretty_carray<pretty_name_zarray<T, Tag>::size + 1>
pretty_name_zarray<T, Tag>::zarray;
} // namespace detail
......@@ -135,7 +149,7 @@ constexpr pretty_carray<pretty_name_zarray<T>::size + 1>
// present in the type name as it would be symbolized.
template <typename T>
constexpr char const* pretty_name() {
return detail::pretty_name_zarray<T>::zarray.data;
return detail::pretty_name_zarray<T, detail::pretty_default_tag>::zarray.data;
}
} // namespace folly
......@@ -28,14 +28,16 @@ TEST_F(PrettyTest, example) {
}
TEST_F(PrettyTest, example_msc) {
constexpr auto const tag = detail::pretty_tag_msc{};
constexpr auto const& name = "void __cdecl foo<int>(void)";
constexpr auto const info = detail::pretty_parse_msc(name);
constexpr auto const info = detail::pretty_parse(tag, name);
EXPECT_EQ("int", detail::pretty_info_to<std::string>(info, name));
}
TEST_F(PrettyTest, example_gcc) {
constexpr auto const tag = detail::pretty_tag_gcc{};
constexpr auto const& name = "void foo() [T = int]";
constexpr auto const info = detail::pretty_parse_gcc(name);
constexpr auto const info = detail::pretty_parse(tag, name);
EXPECT_EQ("int", detail::pretty_info_to<std::string>(info, name));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment