From b1a7f3c741a260df1c0e9e9f62518601f72ac2a7 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Sat, 10 Mar 2018 21:31:15 +0000 Subject: [PATCH] [demangler] Support for structured bindings. llvm-svn: 327226 --- libcxxabi/src/cxa_demangle.cpp | 29 ++++++++++++++++++++++++++--- libcxxabi/test/test_demangle.pass.cpp | 5 ++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/libcxxabi/src/cxa_demangle.cpp b/libcxxabi/src/cxa_demangle.cpp index ffd887a..5c313cb 100644 --- a/libcxxabi/src/cxa_demangle.cpp +++ b/libcxxabi/src/cxa_demangle.cpp @@ -197,6 +197,7 @@ public: KDtorName, KUnnamedTypeName, KClosureTypeName, + KStructuredBindingName, KExpr, KBracedExpr, KBracedRangeExpr, @@ -1337,6 +1338,19 @@ public: } }; +class StructuredBindingName : public Node { + NodeArray Bindings; +public: + StructuredBindingName(NodeArray Bindings_) + : Node(KStructuredBindingName), Bindings(Bindings_) {} + + void printLeft(OutputStream &S) const override { + S += "'structured-binding'["; + Bindings.printWithComma(S); + S += ']'; + } +}; + // -- Expression Nodes -- struct Expr : public Node { @@ -2217,7 +2231,7 @@ Node *Db::parseUnscopedName(NameState *State) { // ::= // ::= // ::= -// FIXME: ::= DC + E # structured binding declaration +// ::= DC + E # structured binding declaration Node *Db::parseUnqualifiedName(NameState *State) { // s are special-cased in parseNestedName(). Node *Result; @@ -2225,7 +2239,16 @@ Node *Db::parseUnqualifiedName(NameState *State) { Result = parseUnnamedTypeName(State); else if (look() >= '1' && look() <= '9') Result = parseSourceName(State); - else + else if (consumeIf("DC")) { + size_t BindingsBegin = Names.size(); + do { + Node *Binding = parseSourceName(State); + if (Binding == nullptr) + return nullptr; + Names.push_back(Binding); + } while (!consumeIf('E')); + Result = make(popTrailingNodeArray(BindingsBegin)); + } else Result = parseOperatorName(State); if (Result != nullptr) Result = parseAbiTags(Result); @@ -2689,7 +2712,7 @@ Node *Db::parseNestedName(NameState *State) { } // Parse an thats actually a . - if (look() == 'C' || look() == 'D') { + if (look() == 'C' || (look() == 'D' && look(1) != 'C')) { if (SoFar == nullptr) return nullptr; Node *CtorDtor = parseCtorDtorName(SoFar, State); diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp index ef2821c..8e97a7f 100644 --- a/libcxxabi/test/test_demangle.pass.cpp +++ b/libcxxabi/test/test_demangle.pass.cpp @@ -29718,6 +29718,10 @@ const char* cases[][2] = {"_Z1fSsB1XS_", "f(std::string[abi:X], std::string[abi:X])"}, {"___Z10blocksNRVOv_block_invoke", "invocation function for block in blocksNRVO()"}, + + // Structured bindings: + {"_ZDC2a12a2E", "'structured-binding'[a1, a2]"}, + {"_ZN2NSDC1x1yEE", "NS::'structured-binding'[x, y]"}, }; const unsigned N = sizeof(cases) / sizeof(cases[0]); @@ -29848,7 +29852,6 @@ void test_invalid_cases() const char *xfail_cases[] = { "_Z1fUa9enable_ifIXLi1EEEv", // enable_if attribute - "_ZDC2a12a2E", // decomposition decl "_ZW6FooBarE2f3v", // C++ modules TS // FIXME: Why does clang generate the "cp" expr? -- 2.7.4