Index: include/llvm/Demangle/Demangle.h =================================================================== --- include/llvm/Demangle/Demangle.h +++ include/llvm/Demangle/Demangle.h @@ -31,6 +31,12 @@ char *itaniumDemangle(const char *mangled_name, char *buf, size_t *n, int *status); +/// Calls the callback \c Callback with \c Ctx as an argument whenever a type is +/// encountered. Returns true if MangledName couldn't be parsed. +bool itaniumFindTypesInMangledName(const char *MangledName, void *Ctx, + void (*Callback)(void *, const char *)); + + enum MSDemangleFlags { MSDF_None = 0, MSDF_DumpBackrefs = 1 << 0 }; char *microsoftDemangle(const char *mangled_name, char *buf, size_t *n, int *status, MSDemangleFlags Flags = MSDF_None); Index: lib/Demangle/ItaniumDemangle.cpp =================================================================== --- lib/Demangle/ItaniumDemangle.cpp +++ lib/Demangle/ItaniumDemangle.cpp @@ -1965,6 +1965,9 @@ // conversion operator's type, and are resolved in the enclosing . PODSmallVector ForwardTemplateRefs; + void (*TypeCallback)(void *, const char *) = nullptr; + void *TypeCallbackContext = nullptr; + bool TryToParseTemplateArgs = true; bool PermitForwardTemplateReferences = false; bool ParsingLambdaParams = false; @@ -3207,6 +3210,9 @@ Node *Db::parseType() { Node *Result = nullptr; + if (TypeCallback != nullptr) + TypeCallback(TypeCallbackContext, First); + switch (look()) { // ::= case 'r': @@ -4986,6 +4992,15 @@ return InternalStatus == demangle_success ? Buf : nullptr; } +bool llvm::itaniumFindTypesInMangledName(const char *MangledName, void *Ctx, + void (*Callback)(void *, + const char *)) { + Db Parser(MangledName, MangledName + std::strlen(MangledName)); + Parser.TypeCallback = Callback; + Parser.TypeCallbackContext = Ctx; + return Parser.parse(); +} + namespace llvm { ItaniumPartialDemangler::ItaniumPartialDemangler() @@ -5206,5 +5221,4 @@ bool ItaniumPartialDemangler::isData() const { return !isFunction() && !isSpecialName(); } - }