Commit 6ec17dc6 by Chris Mihelich Committed by Copybara-Service

Demangle &-qualified function types.

PiperOrigin-RevId: 637972935
Change-Id: Ia684f7761b2a98a0d9d5ae096daba34e9140aa22
parent 4a861bb1
...@@ -1386,19 +1386,30 @@ static bool ParseExceptionSpec(State *state) { ...@@ -1386,19 +1386,30 @@ static bool ParseExceptionSpec(State *state) {
return false; return false;
} }
// <function-type> ::= [exception-spec] F [Y] <bare-function-type> [O] E // <function-type> ::=
// [exception-spec] F [Y] <bare-function-type> [<ref-qualifier>] E
//
// <ref-qualifier> ::= R | O
static bool ParseFunctionType(State *state) { static bool ParseFunctionType(State *state) {
ComplexityGuard guard(state); ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false; if (guard.IsTooComplex()) return false;
ParseState copy = state->parse_state; ParseState copy = state->parse_state;
if (Optional(ParseExceptionSpec(state)) && ParseOneCharToken(state, 'F') && Optional(ParseExceptionSpec(state));
Optional(ParseOneCharToken(state, 'Y')) && ParseBareFunctionType(state) && if (!ParseOneCharToken(state, 'F')) {
Optional(ParseOneCharToken(state, 'O')) && state->parse_state = copy;
ParseOneCharToken(state, 'E')) { return false;
return true;
} }
state->parse_state = copy; Optional(ParseOneCharToken(state, 'Y'));
return false; if (!ParseBareFunctionType(state)) {
state->parse_state = copy;
return false;
}
Optional(ParseCharClass(state, "RO"));
if (!ParseOneCharToken(state, 'E')) {
state->parse_state = copy;
return false;
}
return true;
} }
// <bare-function-type> ::= <(signature) type>+ // <bare-function-type> ::= <(signature) type>+
......
...@@ -569,6 +569,26 @@ TEST(Demangle, DirectListInitialization) { ...@@ -569,6 +569,26 @@ TEST(Demangle, DirectListInitialization) {
EXPECT_STREQ("j<>()", tmp); EXPECT_STREQ("j<>()", tmp);
} }
TEST(Demangle, ReferenceQualifiedFunctionTypes) {
char tmp[80];
// void f(void (*)() const &, int)
EXPECT_TRUE(Demangle("_Z1fPKFvvREi", tmp, sizeof(tmp)));
EXPECT_STREQ("f()", tmp);
// void f(void (*)() &&, int)
EXPECT_TRUE(Demangle("_Z1fPFvvOEi", tmp, sizeof(tmp)));
EXPECT_STREQ("f()", tmp);
// void f(void (*)(int&) &, int)
EXPECT_TRUE(Demangle("_Z1fPFvRiREi", tmp, sizeof(tmp)));
EXPECT_STREQ("f()", tmp);
// void f(void (*)(S&&) &&, int)
EXPECT_TRUE(Demangle("_Z1fPFvO1SOEi", tmp, sizeof(tmp)));
EXPECT_STREQ("f()", tmp);
}
// Test one Rust symbol to exercise Demangle's delegation path. Rust demangling // Test one Rust symbol to exercise Demangle's delegation path. Rust demangling
// itself is more thoroughly tested in demangle_rust_test.cc. // itself is more thoroughly tested in demangle_rust_test.cc.
TEST(Demangle, DelegatesToDemangleRustSymbolEncoding) { TEST(Demangle, DelegatesToDemangleRustSymbolEncoding) {
......
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