Commit c3325cb5 authored by Dominik Charousset's avatar Dominik Charousset

Support GCC and MSVC anonymous namespace encodings

parent e0aaa1db
...@@ -63,7 +63,12 @@ constexpr string_view fun_prefixes[] = { ...@@ -63,7 +63,12 @@ constexpr string_view fun_prefixes[] = {
"unsigned ", "unsigned ",
}; };
constexpr string_view anon_ns = "(anonymous namespace)"; // Various spellings of the anonymous namespace as reported by CAF_PRETTY_FUN.
constexpr string_view anon_ns[] = {
"(anonymous namespace)", // Clang
"{anonymous}", // GCC
"`anonymous-namespace'", // MSVC
};
/// Reduces symbol by printing all prefixes to `out` and returning the /// Reduces symbol by printing all prefixes to `out` and returning the
/// remainder. For example, "ns::foo::bar" prints "ns.foo" to `out` and returns /// remainder. For example, "ns::foo::bar" prints "ns.foo" to `out` and returns
...@@ -107,13 +112,17 @@ string_view reduce_symbol(std::ostream& out, string_view symbol) { ...@@ -107,13 +112,17 @@ string_view reduce_symbol(std::ostream& out, string_view symbol) {
case ':': case ':':
advance(2); advance(2);
break; break;
// This either marks the beginning of the argument list *or* on GCC // These characters are invalid in function names, unless they indicate
// is part of "(anonymous namespace)". // an anonymous namespace or the beginning of the argument list.
case '(': case '`':
if (starts_with(symbol, anon_ns)) { case '{':
case '(': {
auto pred = [&](string_view x) { return starts_with(symbol, x); };
auto i = std::find_if(std::begin(anon_ns), std::end(anon_ns), pred);
if (i != std::end(anon_ns)) {
set_last("$"); set_last("$");
// The anonymous namespace is always followed by "::". // The anonymous namespace is always followed by "::".
symbol.remove_prefix(anon_ns.size() + 2); symbol.remove_prefix(i->size() + 2);
pos = 0; pos = 0;
break; break;
} }
...@@ -123,6 +132,7 @@ string_view reduce_symbol(std::ostream& out, string_view symbol) { ...@@ -123,6 +132,7 @@ string_view reduce_symbol(std::ostream& out, string_view symbol) {
if (!printed) if (!printed)
out << "GLOBAL"; out << "GLOBAL";
return symbol; return symbol;
}
case '<': case '<':
flush(); flush();
out << '<'; out << '<';
...@@ -437,6 +447,8 @@ void logger::render_fun_prefix(std::ostream& out, const event& x) { ...@@ -437,6 +447,8 @@ void logger::render_fun_prefix(std::ostream& out, const event& x) {
break; break;
} }
} }
// MSVC puts '__cdecl' between the return type and the function name.
skip("__cdecl ");
reduced.remove_prefix(pos); reduced.remove_prefix(pos);
}; };
skip_return_type(); skip_return_type();
......
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