Commit 54e1f14c by Chris Mihelich Committed by Copybara-Service

Demangle object new-expressions, [gs] nw ....

PiperOrigin-RevId: 640688552
Change-Id: I843e5aed55f90eeb89e007389390d0aba705a3fe
parent fe43a4cb
...@@ -618,6 +618,7 @@ static bool ParseUnionSelector(State* state); ...@@ -618,6 +618,7 @@ static bool ParseUnionSelector(State* state);
static bool ParseFunctionParam(State* state); static bool ParseFunctionParam(State* state);
static bool ParseBracedExpression(State *state); static bool ParseBracedExpression(State *state);
static bool ParseExpression(State *state); static bool ParseExpression(State *state);
static bool ParseInitializer(State *state);
static bool ParseExprPrimary(State *state); static bool ParseExprPrimary(State *state);
static bool ParseExprCastValueAndTrailingE(State *state); static bool ParseExprCastValueAndTrailingE(State *state);
static bool ParseQRequiresClauseExpr(State *state); static bool ParseQRequiresClauseExpr(State *state);
...@@ -1993,6 +1994,8 @@ static bool ParseBracedExpression(State *state) { ...@@ -1993,6 +1994,8 @@ static bool ParseBracedExpression(State *state) {
// ::= cv <type> _ <expression>* E # type (expr-list) // ::= cv <type> _ <expression>* E # type (expr-list)
// ::= tl <type> <braced-expression>* E // ::= tl <type> <braced-expression>* E
// ::= il <braced-expression>* E // ::= il <braced-expression>* E
// ::= [gs] nw <expression>* _ <type> E
// ::= [gs] nw <expression>* _ <type> <initializer>
// ::= dc <type> <expression> // ::= dc <type> <expression>
// ::= sc <type> <expression> // ::= sc <type> <expression>
// ::= cc <type> <expression> // ::= cc <type> <expression>
...@@ -2088,6 +2091,17 @@ static bool ParseExpression(State *state) { ...@@ -2088,6 +2091,17 @@ static bool ParseExpression(State *state) {
} }
state->parse_state = copy; state->parse_state = copy;
// <expression> ::= [gs] nw <expression>* _ <type> E
// ::= [gs] nw <expression>* _ <type> <initializer>
if (Optional(ParseTwoCharToken(state, "gs")) &&
ParseTwoCharToken(state, "nw") &&
ZeroOrMore(ParseExpression, state) && ParseOneCharToken(state, '_') &&
ParseType(state) &&
(ParseOneCharToken(state, 'E') || ParseInitializer(state))) {
return true;
}
state->parse_state = copy;
// dynamic_cast, static_cast, const_cast, reinterpret_cast. // dynamic_cast, static_cast, const_cast, reinterpret_cast.
// //
// <expression> ::= (dc | sc | cc | rc) <type> <expression> // <expression> ::= (dc | sc | cc | rc) <type> <expression>
...@@ -2272,6 +2286,20 @@ static bool ParseExpression(State *state) { ...@@ -2272,6 +2286,20 @@ static bool ParseExpression(State *state) {
return ParseUnresolvedName(state); return ParseUnresolvedName(state);
} }
// <initializer> ::= pi <expression>* E
static bool ParseInitializer(State *state) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
ParseState copy = state->parse_state;
if (ParseTwoCharToken(state, "pi") && ZeroOrMore(ParseExpression, state) &&
ParseOneCharToken(state, 'E')) {
return true;
}
state->parse_state = copy;
return false;
}
// <expr-primary> ::= L <type> <(value) number> E // <expr-primary> ::= L <type> <(value) number> E
// ::= L <type> <(value) float> E // ::= L <type> <(value) float> E
// ::= L <mangled-name> E // ::= L <mangled-name> E
......
...@@ -1068,6 +1068,86 @@ TEST(Demangle, BracedListImplicitlyConstructingAClassObject) { ...@@ -1068,6 +1068,86 @@ TEST(Demangle, BracedListImplicitlyConstructingAClassObject) {
EXPECT_STREQ("f<>()", tmp); EXPECT_STREQ("f<>()", tmp);
} }
TEST(Demangle, SimpleNewExpression) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*new T}) f() { return T{}; }
// template decltype(int{*new int}) f<int>();
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(int{*(new int)}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_denw_S0_EEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, NewExpressionWithEmptyParentheses) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*new T()}) f() { return T{}; }
// template decltype(int{*new int()}) f<int>();
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(int{*(new int)}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_denw_S0_piEEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, NewExpressionWithNonemptyParentheses) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*new T(42)}) f() { return T{}; }
// template decltype(int{*new int(42)}) f<int>();
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(int{*(new int(42))}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_denw_S0_piLi42EEEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, PlacementNewExpression) {
char tmp[80];
// Source:
//
// #include <new>
//
// template <class T> auto f(T t) -> decltype(T{*new (&t) T(42)}) {
// return t;
// }
// template auto f<int>(int t) -> decltype(int{*new (&t) int(42)});
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(int{*(new(&fp) int(42))}) f<int>(int)
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_denwadfp__S0_piLi42EEEES0_",
tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, GlobalScopeNewExpression) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*::new T}) f() { return T{}; }
// template decltype(int{*::new int}) f<int>();
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(int{*(::new int)}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_degsnw_S0_EEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, ReferenceQualifiedFunctionTypes) { TEST(Demangle, ReferenceQualifiedFunctionTypes) {
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