return false;
}
+static bool isCustomType(StringView S) { return S[0] == '?'; }
+
static bool isPointerType(StringView S) {
if (S.startsWith("$$Q")) // foo &&
return true;
// Parser functions. This is a recursive-descent parser.
TypeNode *demangleType(StringView &MangledName, QualifierMangleMode QMM);
PrimitiveTypeNode *demanglePrimitiveType(StringView &MangledName);
+ CustomTypeNode *demangleCustomType(StringView &MangledName);
TagTypeNode *demangleClassType(StringView &MangledName);
PointerTypeNode *demanglePointerType(StringView &MangledName);
PointerTypeNode *demangleMemberPointerType(StringView &MangledName);
int64_t demangleSigned(StringView &MangledName);
void memorizeString(StringView s);
+ void memorizeIdentifier(IdentifierNode *Identifier);
/// Allocate a copy of \p Borrowed into memory that we own.
StringView copyString(StringView Borrowed);
return Backrefs.Names[I];
}
+void Demangler::memorizeIdentifier(IdentifierNode *Identifier) {
+ // Render this class template name into a string buffer so that we can
+ // memorize it for the purpose of back-referencing.
+ OutputStream OS = OutputStream::create(nullptr, nullptr, 1024);
+ Identifier->output(OS, OF_Default);
+ OS << '\0';
+ char *Name = OS.getBuffer();
+
+ StringView Owned = copyString(Name);
+ memorizeString(Owned);
+ std::free(Name);
+}
+
IdentifierNode *
Demangler::demangleTemplateInstantiationName(StringView &MangledName,
NameBackrefBehavior NBB) {
if (Error)
return nullptr;
- if (NBB & NBB_Template) {
- // Render this class template name into a string buffer so that we can
- // memorize it for the purpose of back-referencing.
- OutputStream OS = OutputStream::create(nullptr, nullptr, 1024);
- Identifier->output(OS, OF_Default);
- OS << '\0';
- char *Name = OS.getBuffer();
-
- StringView Owned = copyString(Name);
- memorizeString(Owned);
- std::free(Name);
- }
+ if (NBB & NBB_Template)
+ memorizeIdentifier(Identifier);
return Identifier;
}
MangledName.consumeFront("$$A6");
Ty = demangleFunctionType(MangledName, false);
}
+ } else if (isCustomType(MangledName)) {
+ Ty = demangleCustomType(MangledName);
} else {
Ty = demanglePrimitiveType(MangledName);
assert(Ty && !Error);
return Symbol;
}
+CustomTypeNode *Demangler::demangleCustomType(StringView &MangledName) {
+ assert(MangledName.startsWith('?'));
+ MangledName.popFront();
+
+ CustomTypeNode *CTN = Arena.alloc<CustomTypeNode>();
+ CTN->Identifier = demangleUnqualifiedTypeName(MangledName, true);
+ if (!MangledName.consumeFront('@'))
+ Error = true;
+ if (Error)
+ return nullptr;
+ return CTN;
+}
+
// Reads a primitive type.
PrimitiveTypeNode *Demangler::demanglePrimitiveType(StringView &MangledName) {
if (MangledName.consumeFront("$$T"))
// I - virtual inheritance <name> <number> <number> <number>
// J - unspecified inheritance <name> <number> <number> <number>
char InheritanceSpecifier = MangledName.popFront();
- SymbolNode *S =
- MangledName.startsWith('?') ? parse(MangledName) : nullptr;
+ SymbolNode *S = nullptr;
+ if (MangledName.startsWith('?')) {
+ S = parse(MangledName);
+ memorizeIdentifier(S->Name->getUnqualifiedIdentifier());
+ }
+
switch (InheritanceSpecifier) {
case 'J':
TPRN->ThunkOffsets[TPRN->ThunkOffsetCount++] =
enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
-enum OutputFlags { OF_Default = 0, OF_NoCallingConvention = 1 };
+enum OutputFlags {
+ OF_Default = 0,
+ OF_NoCallingConvention = 1,
+};
// Types
enum class PrimitiveKind {
explicit FunctionSignatureNode(NodeKind K) : TypeNode(K) {}
FunctionSignatureNode() : TypeNode(NodeKind::FunctionSignature) {}
- virtual void outputPre(OutputStream &OS, OutputFlags Flags) const;
- virtual void outputPost(OutputStream &OS, OutputFlags Flags) const;
+ void outputPre(OutputStream &OS, OutputFlags Flags) const override;
+ void outputPost(OutputStream &OS, OutputFlags Flags) const override;
// Valid if this FunctionTypeNode is the Pointee of a PointerType or
// MemberPointerType.
void output(OutputStream &OS, OutputFlags Flags) const override {}
};
-struct CustomNode : public Node {
- CustomNode() : Node(NodeKind::Custom) {}
+struct CustomTypeNode : public TypeNode {
+ CustomTypeNode() : TypeNode(NodeKind::Custom) {}
- void output(OutputStream &OS, OutputFlags Flags) const override;
+ void outputPre(OutputStream &OS, OutputFlags Flags) const override;
+ void outputPost(OutputStream &OS, OutputFlags Flags) const override;
- // The string to print.
- StringView Name;
+ IdentifierNode *Identifier;
};
struct NodeArrayNode : public Node {
--- /dev/null
+; These tests are based on clang/test/CodeGenCXX/mangle-ms-arg-qualifiers.cpp
+; RUN: llvm-undname < %s | FileCheck %s
+
+; CHECK-NOT: Invalid mangled name
+
+??$x@X@@3HA
+; CHECK: int x<void>
+
+?FunctionWithLocalType@@YA?A?<auto>@@XZ
+; CHECK: <auto> __cdecl FunctionWithLocalType(void)
+
+?ValueFromFunctionWithLocalType@@3ULocalType@?1??FunctionWithLocalType@@YA?A?<auto>@@XZ@A
+; CHECK: struct `<auto> __cdecl FunctionWithLocalType(void)'::`2'::LocalType ValueFromFunctionWithLocalType
+
+??R<lambda_0>@@QBE?A?<auto>@@XZ
+; CHECK: <auto> __thiscall <lambda_0>::operator()(void) const
+
+?ValueFromLambdaWithLocalType@@3ULocalType@?1???R<lambda_0>@@QBE?A?<auto>@@XZ@A
+; CHECK: struct `<auto> __thiscall <lambda_0>::operator()(void) const'::`2'::LocalType ValueFromLambdaWithLocalType
+
+?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?2???R<lambda_1>@?0???$TemplateFuncionWithLocalLambda@H@@YA?A?<auto>@@H@Z@QBE?A?3@XZ@A
+; CHECK: struct `<auto> __thiscall `<auto> __cdecl TemplateFuncionWithLocalLambda<int>(int)'::`1'::<lambda_1>::operator()(void) const'::`3'::LocalType ValueFromTemplateFuncionWithLocalLambda
+
+??$TemplateFuncionWithLocalLambda@H@@YA?A?<auto>@@H@Z
+; CHECK: <auto> __cdecl TemplateFuncionWithLocalLambda<int>(int)
+
+??R<lambda_1>@?0???$TemplateFuncionWithLocalLambda@H@@YA?A?<auto>@@H@Z@QBE?A?1@XZ
+; CHECK: <auto> __thiscall `<auto> __cdecl TemplateFuncionWithLocalLambda<int>(int)'::`1'::<lambda_1>::operator()(void) const
+
+??$WithPMD@$GA@A@?0@@3HA
+; CHECK: int WithPMD<{0, 0, -1}>
+
+?Zoo@@3U?$Foo@$1??$x@H@@3HA$1?1@3HA@@A
+; CHECK: struct Foo<&int x<int>, &int x<int>> Zoo
+
+??$unaligned_x@PFAH@@3PFAHA
+; CHECK: int __unaligned *unaligned_x<int __unaligned *>