Commit 3941dc41 by Chris Mihelich Committed by Copybara-Service

Demangle _BitInt types DB..., DU....

PiperOrigin-RevId: 641360162
Change-Id: Iabce55eb61feaa4dc099093a6496e26ab66906fa
parent 9140cc7b
...@@ -1453,12 +1453,43 @@ static bool ParseExtendedQualifier(State *state) { ...@@ -1453,12 +1453,43 @@ static bool ParseExtendedQualifier(State *state) {
// <builtin-type> ::= v, etc. # single-character builtin types // <builtin-type> ::= v, etc. # single-character builtin types
// ::= <vendor-extended-type> // ::= <vendor-extended-type>
// ::= Dd, etc. # two-character builtin types // ::= Dd, etc. # two-character builtin types
// ::= DB (<number> | <expression>) _ # _BitInt(N)
// ::= DU (<number> | <expression>) _ # unsigned _BitInt(N)
// //
// Not supported: // Not supported:
// ::= DF <number> _ # _FloatN (N bits) // ::= DF <number> _ # _FloatN (N bits)
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;
ParseState copy = state->parse_state;
// DB (<number> | <expression>) _ # _BitInt(N)
// DU (<number> | <expression>) _ # unsigned _BitInt(N)
if (ParseTwoCharToken(state, "DB") ||
(ParseTwoCharToken(state, "DU") && MaybeAppend(state, "unsigned "))) {
bool append = state->parse_state.append;
DisableAppend(state);
int number = -1;
if (!ParseNumber(state, &number) && !ParseExpression(state)) {
state->parse_state = copy;
return false;
}
RestoreAppend(state, append);
if (!ParseOneCharToken(state, '_')) {
state->parse_state = copy;
return false;
}
MaybeAppend(state, "_BitInt(");
if (number >= 0) {
MaybeAppendDecimal(state, number);
} else {
MaybeAppend(state, "?"); // the best we can do for dependent sizes
}
MaybeAppend(state, ")");
return true;
}
for (const AbbrevPair *p = kBuiltinTypeList; p->abbrev != nullptr; ++p) { for (const AbbrevPair *p = kBuiltinTypeList; p->abbrev != nullptr; ++p) {
// Guaranteed only 1- or 2-character strings in kBuiltinTypeList. // Guaranteed only 1- or 2-character strings in kBuiltinTypeList.
......
...@@ -660,6 +660,30 @@ TEST(Demangle, ComplexFloatingPointLiterals) { ...@@ -660,6 +660,30 @@ TEST(Demangle, ComplexFloatingPointLiterals) {
EXPECT_STREQ("f<>()", tmp); EXPECT_STREQ("f<>()", tmp);
} }
TEST(Demangle, SimpleSignedBitInt) {
char tmp[80];
// S::operator _BitInt(256)() const
EXPECT_TRUE(Demangle("_ZNK1ScvDB256_Ev", tmp, sizeof(tmp)));
EXPECT_STREQ("S::operator _BitInt(256)()", tmp);
}
TEST(Demangle, SimpleUnsignedBitInt) {
char tmp[80];
// S::operator unsigned _BitInt(256)() const
EXPECT_TRUE(Demangle("_ZNK1ScvDU256_Ev", tmp, sizeof(tmp)));
EXPECT_STREQ("S::operator unsigned _BitInt(256)()", tmp);
}
TEST(Demangle, DependentBitInt) {
char tmp[80];
// S::operator _BitInt(256)<256>() const
EXPECT_TRUE(Demangle("_ZNK1ScvDBT__ILi256EEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("S::operator _BitInt(?)<>()", tmp);
}
TEST(Demangle, GlobalInitializers) { TEST(Demangle, GlobalInitializers) {
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