From: Richard Smith Date: Mon, 9 Sep 2019 22:26:04 +0000 (+0000) Subject: Simplify demangler rule for lambda-expressions to match discussion on X-Git-Tag: llvmorg-11-init~9614 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ca7370183a104b7769202032e9d5a41c04ed070;p=platform%2Fupstream%2Fllvm.git Simplify demangler rule for lambda-expressions to match discussion on cxx-abi list. llvm-svn: 371462 --- diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index c1efd7e..edba17d 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -2063,8 +2063,6 @@ public: class LambdaExpr : public Node { const Node *Type; - void printLambdaDeclarator(OutputStream &S) const; - public: LambdaExpr(const Node *Type_) : Node(KLambdaExpr), Type(Type_) {} @@ -2072,7 +2070,8 @@ public: void printLeft(OutputStream &S) const override { S += "[]"; - printLambdaDeclarator(S); + if (Type->getKind() == KClosureTypeName) + static_cast(Type)->printDeclarator(S); S += "{...}"; } }; @@ -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 PODSmallVector { static_assert(std::is_pod::value, @@ -4324,20 +4290,26 @@ Node *AbstractManglingParser::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(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(T, N); - } - if (consumeIf('E')) - return make(T); - return nullptr; + if (N.empty()) + return nullptr; + if (!consumeIf('E')) + return nullptr; + return make(T, N); } } } diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp index 9f7f167..c84447f 100644 --- a/libcxxabi/test/test_demangle.pass.cpp +++ b/libcxxabi/test/test_demangle.pass.cpp @@ -29784,7 +29784,9 @@ const char* cases[][2] = {"_ZNK1xMUlTyT_E_clIiEEDaS_", "auto x::'lambda'($T)::operator()(x) const"}, {"_ZNK1xMUlTnPA3_ivE_clILS0_0EEEDav", "auto x::'lambda'()::operator()<(int [3])0>() const"}, {"_ZNK1xMUlTyTtTyTnT_TpTnPA3_TL0__ETpTyvE_clIi1XJfEEEDav", "auto x::'lambda' typename $TT, typename ...$T1>()::operator()() const"}, - {"_ZN1AIiE1fIfEEvDTLZ1AIiEEUlTyTtTyTnTL1__ETL0_1_T_TL0__E_EE", "void A::f(decltype([] typename $TT>($TT, int, $T){...}))"}, + {"_ZN1AIiE1fIfEEvDTLUlTyTtTyTnTL1__ETL0_1_T_TL0__E_EE", "void A::f(decltype([] typename $TT>($TT, float, $T){...}))"}, + {"_ZN1S1fILb1EEEv1XILUlvE_EE", "void S::f(X<[](){...}>)"}, + {"_ZN1S1fILb1EEEv1XILUlvE0_EE", "void S::f(X<[](){...}>)"}, }; const unsigned N = sizeof(cases) / sizeof(cases[0]); diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index c1efd7e..edba17d 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -2063,8 +2063,6 @@ public: class LambdaExpr : public Node { const Node *Type; - void printLambdaDeclarator(OutputStream &S) const; - public: LambdaExpr(const Node *Type_) : Node(KLambdaExpr), Type(Type_) {} @@ -2072,7 +2070,8 @@ public: void printLeft(OutputStream &S) const override { S += "[]"; - printLambdaDeclarator(S); + if (Type->getKind() == KClosureTypeName) + static_cast(Type)->printDeclarator(S); S += "{...}"; } }; @@ -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 PODSmallVector { static_assert(std::is_pod::value, @@ -4324,20 +4290,26 @@ Node *AbstractManglingParser::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(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(T, N); - } - if (consumeIf('E')) - return make(T); - return nullptr; + if (N.empty()) + return nullptr; + if (!consumeIf('E')) + return nullptr; + return make(T, N); } } }