Skip to content

Commit

Permalink
Simplify demangler rule for lambda-expressions to match discussion on
Browse files Browse the repository at this point in the history
cxx-abi list.

git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@371462 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
zygoloid committed Sep 9, 2019
1 parent 950f33f commit 2daf732
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 45 deletions.
60 changes: 16 additions & 44 deletions src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2063,16 +2063,15 @@ class StringLiteral : public Node {
class LambdaExpr : public Node {
const Node *Type;

void printLambdaDeclarator(OutputStream &S) const;

public:
LambdaExpr(const Node *Type_) : Node(KLambdaExpr), Type(Type_) {}

template<typename Fn> void match(Fn F) const { F(Type); }

void printLeft(OutputStream &S) const override {
S += "[]";
printLambdaDeclarator(S);
if (Type->getKind() == KClosureTypeName)
static_cast<const ClosureTypeName *>(Type)->printDeclarator(S);
S += "{...}";
}
};
Expand Down Expand Up @@ -2209,39 +2208,6 @@ FOR_EACH_NODE_KIND(SPECIALIZATION)

#undef FOR_EACH_NODE_KIND

inline void LambdaExpr::printLambdaDeclarator(OutputStream &S) const {
struct LambdaDeclaratorPrinter {
OutputStream &S;
void operator()(const ClosureTypeName *LambdaType) {
LambdaType->printDeclarator(S);
}

// Walk through any qualifiers to find the lambda-expression.
void operator()(const SpecialName *Name) {
Name->match([&](StringView, const Node *Name) { Name->visit(*this); });
}
void operator()(const NestedName *Name) {
Name->match([&](const Node *, const Node *Name) { Name->visit(*this); });
}
void operator()(const LocalName *Name) {
Name->match([&](const Node *, const Node *Name) { Name->visit(*this); });
}
void operator()(const QualifiedName *Name) {
Name->match([&](const Node *, const Node *Name) { Name->visit(*this); });
}
void operator()(const GlobalQualifiedName *Name) {
Name->match([&](const Node *Child) { Child->visit(*this); });
}
void operator()(const StdQualifiedName *Name) {
Name->match([&](const Node *Child) { Child->visit(*this); });
}
void operator()(const Node *) {
// If we can't find the lambda type, just print '[]{...}'.
}
};
return Type->visit(LambdaDeclaratorPrinter{S});
}

template <class T, size_t N>
class PODSmallVector {
static_assert(std::is_pod<T>::value,
Expand Down Expand Up @@ -4324,20 +4290,26 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
// Invalid mangled name per
// http://sourcerytools.com/pipermail/cxx-abi-dev/2011-August/002422.html
return nullptr;
case 'U': {
// FIXME: Should we support LUb... for block literals?
if (look(1) != 'l')
return nullptr;
Node *T = parseUnnamedTypeName(nullptr);
if (!T || !consumeIf('E'))
return nullptr;
return make<LambdaExpr>(T);
}
default: {
// might be named type
Node *T = getDerived().parseType();
if (T == nullptr)
return nullptr;
StringView N = parseNumber();
if (!N.empty()) {
if (!consumeIf('E'))
return nullptr;
return make<IntegerCastExpr>(T, N);
}
if (consumeIf('E'))
return make<LambdaExpr>(T);
return nullptr;
if (N.empty())
return nullptr;
if (!consumeIf('E'))
return nullptr;
return make<IntegerCastExpr>(T, N);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/test_demangle.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29784,7 +29784,9 @@ const char* cases[][2] =
{"_ZNK1xMUlTyT_E_clIiEEDaS_", "auto x::'lambda'<typename $T>($T)::operator()<int>(x) const"},
{"_ZNK1xMUlTnPA3_ivE_clILS0_0EEEDav", "auto x::'lambda'<int (*$N) [3]>()::operator()<(int [3])0>() const"},
{"_ZNK1xMUlTyTtTyTnT_TpTnPA3_TL0__ETpTyvE_clIi1XJfEEEDav", "auto x::'lambda'<typename $T, template<typename $T0, $T $N, $T0 (*...$N0) [3]> typename $TT, typename ...$T1>()::operator()<int, X, float>() const"},
{"_ZN1AIiE1fIfEEvDTLZ1AIiEEUlTyTtTyTnTL1__ETL0_1_T_TL0__E_EE", "void A<int>::f<float>(decltype([]<typename $T, template<typename $T0, $T0 $N> typename $TT>($TT, int, $T){...}))"},
{"_ZN1AIiE1fIfEEvDTLUlTyTtTyTnTL1__ETL0_1_T_TL0__E_EE", "void A<int>::f<float>(decltype([]<typename $T, template<typename $T0, $T0 $N> typename $TT>($TT, float, $T){...}))"},
{"_ZN1S1fILb1EEEv1XILUlvE_EE", "void S::f<true>(X<[](){...}>)"},
{"_ZN1S1fILb1EEEv1XILUlvE0_EE", "void S::f<true>(X<[](){...}>)"},
};

const unsigned N = sizeof(cases) / sizeof(cases[0]);
Expand Down

0 comments on commit 2daf732

Please sign in to comment.