Commit 6e607350 by Chris Mihelich Committed by Copybara-Service

Demangle C++11 user-defined literal operator functions.

PiperOrigin-RevId: 641046309
Change-Id: Iaa2564a60035421969c2cd6074a457980083cbd2
parent 2a40eb60
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
// For reference check out: // For reference check out:
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
//
// Note that we only have partial C++11 support yet.
#include "absl/debugging/internal/demangle.h" #include "absl/debugging/internal/demangle.h"
...@@ -1044,6 +1042,7 @@ static bool ParseIdentifier(State *state, size_t length) { ...@@ -1044,6 +1042,7 @@ static bool ParseIdentifier(State *state, size_t length) {
// <operator-name> ::= nw, and other two letters cases // <operator-name> ::= nw, and other two letters cases
// ::= cv <type> # (cast) // ::= cv <type> # (cast)
// ::= li <source-name> # C++11 user-defined literal
// ::= v <digit> <source-name> # vendor extended operator // ::= v <digit> <source-name> # vendor extended operator
static bool ParseOperatorName(State *state, int *arity) { static bool ParseOperatorName(State *state, int *arity) {
ComplexityGuard guard(state); ComplexityGuard guard(state);
...@@ -1063,6 +1062,13 @@ static bool ParseOperatorName(State *state, int *arity) { ...@@ -1063,6 +1062,13 @@ static bool ParseOperatorName(State *state, int *arity) {
} }
state->parse_state = copy; state->parse_state = copy;
// Then user-defined literals.
if (ParseTwoCharToken(state, "li") && MaybeAppend(state, "operator\"\" ") &&
ParseSourceName(state)) {
return true;
}
state->parse_state = copy;
// Then vendor extended operators. // Then vendor extended operators.
if (ParseOneCharToken(state, 'v') && ParseDigit(state, arity) && if (ParseOneCharToken(state, 'v') && ParseDigit(state, arity) &&
ParseSourceName(state)) { ParseSourceName(state)) {
......
...@@ -1035,6 +1035,20 @@ TEST(Demangle, SizeofPackInvolvingAnAliasTemplate) { ...@@ -1035,6 +1035,20 @@ TEST(Demangle, SizeofPackInvolvingAnAliasTemplate) {
EXPECT_STREQ("f<>()", tmp); EXPECT_STREQ("f<>()", tmp);
} }
TEST(Demangle, UserDefinedLiteral) {
char tmp[80];
// Source:
//
// unsigned long long operator""_lit(unsigned long long x) { return x; }
//
// LLVM demangling:
//
// operator"" _lit(unsigned long long)
EXPECT_TRUE(Demangle("_Zli4_lity", tmp, sizeof(tmp)));
EXPECT_STREQ("operator\"\" _lit()", tmp);
}
TEST(Demangle, Spaceship) { TEST(Demangle, Spaceship) {
char tmp[80]; char tmp[80];
......
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