Commit 1f5a9cdc by Chris Mihelich Committed by Copybara-Service

Demangle static_cast and friends.

PiperOrigin-RevId: 638232699
Change-Id: I134905927ba72eaa5eaf821bb5535942746a3672
parent 457fdbf9
...@@ -1877,6 +1877,10 @@ static bool ParseBracedExpression(State *state) { ...@@ -1877,6 +1877,10 @@ static bool ParseBracedExpression(State *state) {
// ::= cv <type> <expression> # type (expression) // ::= cv <type> <expression> # type (expression)
// ::= cv <type> _ <expression>* E # type (expr-list) // ::= cv <type> _ <expression>* E # type (expr-list)
// ::= tl <type> <braced-expression>* E // ::= tl <type> <braced-expression>* E
// ::= dc <type> <expression>
// ::= sc <type> <expression>
// ::= cc <type> <expression>
// ::= rc <type> <expression>
// ::= st <type> // ::= st <type>
// ::= <template-param> // ::= <template-param>
// ::= <function-param> // ::= <function-param>
...@@ -1942,6 +1946,15 @@ static bool ParseExpression(State *state) { ...@@ -1942,6 +1946,15 @@ static bool ParseExpression(State *state) {
} }
state->parse_state = copy; state->parse_state = copy;
// dynamic_cast, static_cast, const_cast, reinterpret_cast.
//
// <expression> ::= (dc | sc | cc | rc) <type> <expression>
if (ParseCharClass(state, "dscr") && ParseOneCharToken(state, 'c') &&
ParseType(state) && ParseExpression(state)) {
return true;
}
state->parse_state = copy;
// Parse the conversion expressions jointly to avoid re-parsing the <type> in // Parse the conversion expressions jointly to avoid re-parsing the <type> in
// their common prefix. Parsed as: // their common prefix. Parsed as:
// <expression> ::= cv <type> <conversion-args> // <expression> ::= cv <type> <conversion-args>
......
...@@ -706,6 +706,76 @@ TEST(Demangle, ReferenceQualifiedFunctionTypes) { ...@@ -706,6 +706,76 @@ TEST(Demangle, ReferenceQualifiedFunctionTypes) {
EXPECT_STREQ("f()", tmp); EXPECT_STREQ("f()", tmp);
} }
TEST(Demangle, DynamicCast) {
char tmp[80];
// Source:
//
// template <class T> auto f(T* p) -> decltype(dynamic_cast<const T*>(p)) {
// return p;
// }
// struct S {};
// void g(S* p) { f(p); }
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(dynamic_cast<S const*>(fp)) f<S>(S*)
EXPECT_TRUE(Demangle("_Z1fI1SEDTdcPKT_fp_EPS1_", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, StaticCast) {
char tmp[80];
// Source:
//
// template <class T> auto f(T* p) -> decltype(static_cast<const T*>(p)) {
// return p;
// }
// void g(int* p) { f(p); }
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(static_cast<int const*>(fp)) f<int>(int*)
EXPECT_TRUE(Demangle("_Z1fIiEDTscPKT_fp_EPS0_", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, ConstCast) {
char tmp[80];
// Source:
//
// template <class T> auto f(T* p) -> decltype(const_cast<const T*>(p)) {
// return p;
// }
// void g(int* p) { f(p); }
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(const_cast<int const*>(fp)) f<int>(int*)
EXPECT_TRUE(Demangle("_Z1fIiEDTccPKT_fp_EPS0_", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, ReinterpretCast) {
char tmp[80];
// Source:
//
// template <class T> auto f(T* p)
// -> decltype(reinterpret_cast<const T*>(p)) {
// return p;
// }
// void g(int* p) { f(p); }
//
// Full LLVM demangling of the instantiation of f:
//
// decltype(reinterpret_cast<int const*>(fp)) f<int>(int*)
EXPECT_TRUE(Demangle("_Z1fIiEDTrcPKT_fp_EPS0_", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, ThreadLocalWrappers) { TEST(Demangle, ThreadLocalWrappers) {
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