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) { 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