[PATCH] D111416: [Demangle] Add minimal support for D simple basic types

Luís Ferreira via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 11 18:16:27 PST 2022


ljmf00 updated this revision to Diff 399156.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111416/new/

https://reviews.llvm.org/D111416

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


Index: llvm/unittests/Demangle/DLangDemangleTest.cpp
===================================================================
--- llvm/unittests/Demangle/DLangDemangleTest.cpp
+++ llvm/unittests/Demangle/DLangDemangleTest.cpp
@@ -47,4 +47,9 @@
         std::make_pair("_D8demangle4test12__ModuleInfoZ",
                        "ModuleInfo for demangle.test"),
         std::make_pair("_D8demangle4__S14testZ", "demangle.test"),
-        std::make_pair("_D8demangle4__Sd4testZ", "demangle.__Sd.test")));
+        std::make_pair("_D8demangle4__Sd4testZ", "demangle.__Sd.test"),
+        std::make_pair("_D8demangle3fooi", "demangle.foo"),
+        std::make_pair("_D8demangle3foo",
+                       nullptr), // symbol without a type sequence
+        std::make_pair("_D8demangle3fooinvalidtypeseq",
+                       nullptr))); // invalid type sequence
Index: llvm/lib/Demangle/DLangDemangle.cpp
===================================================================
--- llvm/lib/Demangle/DLangDemangle.cpp
+++ llvm/lib/Demangle/DLangDemangle.cpp
@@ -115,6 +115,16 @@
   /// \see https://dlang.org/spec/abi.html#QualifiedName .
   const char *parseQualified(OutputBuffer *Demangled, const char *Mangled);
 
+  /// Extract and demangle a type from a given mangled symbol append it to
+  /// the output string.
+  ///
+  /// \param Mangled mangled symbol to be demangled.
+  ///
+  /// \return the remaining string on success or nullptr on failure.
+  ///
+  /// \see https://dlang.org/spec/abi.html#Type .
+  const char *parseType(const char *Mangled);
+
   /// The string we are demangling.
   const char *Str;
 };
@@ -174,8 +184,7 @@
     if (*Mangled == 'Z')
       ++Mangled;
     else {
-      // TODO: Implement symbols with types.
-      return nullptr;
+      Mangled = parseType(Mangled);
     }
   }
 
@@ -262,6 +271,31 @@
   return parseLName(Demangled, Mangled, Len);
 }
 
+const char *Demangler::parseType(const char *Mangled) {
+  if (*Mangled == '\0')
+    return nullptr;
+
+  switch (*Mangled) {
+  // TODO: Parse type qualifiers.
+  // TODO: Parse function types.
+  // TODO: Parse compound types.
+  // TODO: Parse delegate types.
+  // TODO: Parse tuple types.
+
+  // Basic types.
+  case 'i':
+    ++Mangled;
+    // TODO: Add type name dumping
+    return Mangled;
+
+    // TODO: Add support for the rest of the basic types.
+    // TODO: Parse back referenced types.
+
+  default: // unhandled.
+    return nullptr;
+  }
+}
+
 const char *Demangler::parseLName(OutputBuffer *Demangled, const char *Mangled,
                                   unsigned long Len) {
   switch (Len) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111416.399156.patch
Type: text/x-patch
Size: 2610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220112/6a7856db/attachment.bin>


More information about the llvm-commits mailing list