[llvm] 6e08abd - [Demangle] Add support for multiple identifiers in D qualified names

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 29 16:06:29 PST 2021


Author: David Blaikie
Date: 2021-11-29T16:05:33-08:00
New Revision: 6e08abdc256bb9c2158ab5dbfa082a78faa3543a

URL: https://github.com/llvm/llvm-project/commit/6e08abdc256bb9c2158ab5dbfa082a78faa3543a
DIFF: https://github.com/llvm/llvm-project/commit/6e08abdc256bb9c2158ab5dbfa082a78faa3543a.diff

LOG: [Demangle] Add support for multiple identifiers in D qualified names

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D114305

Added: 
    

Modified: 
    llvm/lib/Demangle/DLangDemangle.cpp
    llvm/unittests/Demangle/DLangDemangleTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Demangle/DLangDemangle.cpp b/llvm/lib/Demangle/DLangDemangle.cpp
index 73d5ce1907e94..a877174f95207 100644
--- a/llvm/lib/Demangle/DLangDemangle.cpp
+++ b/llvm/lib/Demangle/DLangDemangle.cpp
@@ -69,6 +69,15 @@ struct Demangler {
   /// \see https://dlang.org/spec/abi.html#Number .
   const char *decodeNumber(const char *Mangled, unsigned long *Ret);
 
+  /// Check whether it is the beginning of a symbol name.
+  ///
+  /// \param Mangled string to extract the symbol name.
+  ///
+  /// \return true on success, false otherwise.
+  ///
+  /// \see https://dlang.org/spec/abi.html#SymbolName .
+  bool isSymbolName(const char *Mangled);
+
   /// Extract and demangle an identifier from a given mangled symbol append it
   /// to the output string.
   ///
@@ -136,6 +145,14 @@ const char *Demangler::decodeNumber(const char *Mangled, unsigned long *Ret) {
   return Mangled;
 }
 
+bool Demangler::isSymbolName(const char *Mangled) {
+  if (std::isdigit(*Mangled))
+    return true;
+
+  // TODO: Handle symbol back references and template instances.
+  return false;
+}
+
 const char *Demangler::parseMangle(OutputBuffer *Demangled,
                                    const char *Mangled) {
   // A D mangled symbol is comprised of both scope and type information.
@@ -180,9 +197,18 @@ const char *Demangler::parseQualified(OutputBuffer *Demangled,
   //        SymbolName M TypeModifiers TypeFunctionNoReturn
   // The start pointer should be at the above location.
 
-  // TODO: Parse multiple identifiers
+  // Whether it has more than one symbol
+  size_t NotFirst = false;
+  do {
+    if (NotFirst)
+      *Demangled << '.';
+    NotFirst = true;
+
+    Mangled = parseIdentifier(Demangled, Mangled);
+
+  } while (Mangled && isSymbolName(Mangled));
 
-  return parseIdentifier(Demangled, Mangled);
+  return Mangled;
 }
 
 const char *Demangler::parseIdentifier(OutputBuffer *Demangled,

diff  --git a/llvm/unittests/Demangle/DLangDemangleTest.cpp b/llvm/unittests/Demangle/DLangDemangleTest.cpp
index ad814cb404ec1..750ce88424825 100644
--- a/llvm/unittests/Demangle/DLangDemangleTest.cpp
+++ b/llvm/unittests/Demangle/DLangDemangleTest.cpp
@@ -26,11 +26,12 @@ TEST_P(DLangDemangleTestFixture, DLangDemangleTest) {
   EXPECT_STREQ(Demangled, GetParam().second);
 }
 
-INSTANTIATE_TEST_SUITE_P(DLangDemangleTest, DLangDemangleTestFixture,
-                         testing::Values(std::make_pair("_Dmain", "D main"),
-                                         std::make_pair(nullptr, nullptr),
-                                         std::make_pair("_Z", nullptr),
-                                         std::make_pair("_DDD", nullptr),
-                                         std::make_pair("_D88", nullptr),
-                                         std::make_pair("_D8demangleZ",
-                                                        "demangle")));
+INSTANTIATE_TEST_SUITE_P(
+    DLangDemangleTest, DLangDemangleTestFixture,
+    testing::Values(
+        std::make_pair("_Dmain", "D main"), std::make_pair(nullptr, nullptr),
+        std::make_pair("_Z", nullptr), std::make_pair("_DDD", nullptr),
+        std::make_pair("_D88", nullptr),
+        std::make_pair("_D8demangleZ", "demangle"),
+        std::make_pair("_D8demangle4testZ", "demangle.test"),
+        std::make_pair("_D8demangle4test5test2Z", "demangle.test.test2")));


        


More information about the llvm-commits mailing list