[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
Wed Jan 5 17:30:25 PST 2022
ljmf00 updated this revision to Diff 397752.
ljmf00 added a comment.
Added comment on nullptr testcases.
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,7 @@
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("_D8demangle1ii", "demangle.i"),
+ std::make_pair("_D8demangle1vv", "demangle.v"),
+ std::make_pair("_D8demangle1iinvalidtypeseq", nullptr))); // invalid type sequence
Index: llvm/lib/Demangle/DLangDemangle.cpp
===================================================================
--- llvm/lib/Demangle/DLangDemangle.cpp
+++ llvm/lib/Demangle/DLangDemangle.cpp
@@ -115,6 +115,17 @@
/// \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 Demangled output buffer to write the demangled name.
+ /// \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(OutputBuffer *Demangled, const char *Mangled);
+
/// The string we are demangling.
const char *Str;
};
@@ -174,8 +185,13 @@
if (*Mangled == 'Z')
++Mangled;
else {
- // TODO: Implement symbols with types.
- return nullptr;
+ // Discard the declaration or return type.
+ OutputBuffer Type;
+ if (!initializeOutputBuffer(nullptr, nullptr, Type, 32))
+ return nullptr;
+
+ Mangled = parseType(&Type, Mangled);
+ std::free(Type.getBuffer());
}
}
@@ -262,6 +278,36 @@
return parseLName(Demangled, Mangled, Len);
}
+const char *Demangler::parseType(OutputBuffer *Demangled, const char *Mangled) {
+ if (Mangled == nullptr || *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 'v':
+ ++Mangled;
+ *Demangled << "void";
+ return Mangled;
+
+ case 'i':
+ ++Mangled;
+ *Demangled << "int";
+ 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.397752.patch
Type: text/x-patch
Size: 2945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220106/c0a10862/attachment.bin>
More information about the llvm-commits
mailing list