Commit 61e721f4 by Chris Mihelich Committed by Copybara-Service

Demangle fully general vendor extended types (any <template-args>).

PiperOrigin-RevId: 641271471
Change-Id: Ibeedb4dea3b961955d073f048d293b19aa917792
parent 59d0a7d1
...@@ -1444,8 +1444,6 @@ static bool ParseCVQualifiers(State *state) { ...@@ -1444,8 +1444,6 @@ static bool ParseCVQualifiers(State *state) {
// //
// Not supported: // Not supported:
// ::= DF <number> _ # _FloatN (N bits) // ::= DF <number> _ # _FloatN (N bits)
//
// NOTE: [I <type> E] is a vendor extension (http://shortn/_FrINpH1XC5).
static bool ParseBuiltinType(State *state) { static bool ParseBuiltinType(State *state) {
ComplexityGuard guard(state); ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false; if (guard.IsTooComplex()) return false;
...@@ -1466,22 +1464,15 @@ static bool ParseBuiltinType(State *state) { ...@@ -1466,22 +1464,15 @@ static bool ParseBuiltinType(State *state) {
return ParseVendorExtendedType(state); return ParseVendorExtendedType(state);
} }
// <vendor-extended-type> ::= u <source-name> [I <type> E] // <vendor-extended-type> ::= u <source-name> [<template-args>]
//
// NOTE: [I <type> E] is a vendor extension (http://shortn/_FrINpH1XC5).
static bool ParseVendorExtendedType(State *state) { static bool ParseVendorExtendedType(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 (ParseOneCharToken(state, 'u') && ParseSourceName(state)) { if (ParseOneCharToken(state, 'u') && ParseSourceName(state) &&
copy = state->parse_state; Optional(ParseTemplateArgs(state))) {
if (ParseOneCharToken(state, 'I') && ParseType(state) && return true;
ParseOneCharToken(state, 'E')) {
return true; // ::= u <source-name> I <type> E
}
state->parse_state = copy;
return true; // ::= u <source-name>
} }
state->parse_state = copy; state->parse_state = copy;
return false; return false;
......
...@@ -209,15 +209,16 @@ TEST(Demangle, SingleArgTemplateBuiltinType) { ...@@ -209,15 +209,16 @@ TEST(Demangle, SingleArgTemplateBuiltinType) {
EXPECT_STREQ(tmp, "foo<>()"); EXPECT_STREQ(tmp, "foo<>()");
} }
TEST(Demangle, FailsOnTwoArgTemplateBuiltinType) { TEST(Demangle, TwoArgTemplateBuiltinType) {
char tmp[100]; char tmp[100];
// template <typename T, typename U> // template <typename T, typename U>
// __my_builtin_type<T, U> foo(); // __my_builtin_type<T, U> foo();
// //
// foo<int, char>(); // foo<int, char>();
ASSERT_FALSE( ASSERT_TRUE(
Demangle("_Z3fooIicEu17__my_builtin_typeIT_T0_Ev", tmp, sizeof(tmp))); Demangle("_Z3fooIicEu17__my_builtin_typeIT_T0_Ev", tmp, sizeof(tmp)));
EXPECT_STREQ(tmp, "foo<>()");
} }
TEST(Demangle, TypeNestedUnderTemplatedBuiltinType) { TEST(Demangle, TypeNestedUnderTemplatedBuiltinType) {
......
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