mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:29:58 +00:00
[MS Demangler] Re-write the Microsoft demangler.
This is a pretty large refactor / re-write of the Microsoft demangler. The previous one was a little hackish because it evolved as I was learning about all the various edge cases, exceptions, etc. It didn't have a proper AST and so there was lots of custom handling of things that should have been much more clean. Taking what was learned from that experience, it's now re-written with a completely redesigned and much more sensible AST. It's probably still not perfect, but at least it's comprehensible now to someone else who wants to come along and make some modifications or read the code. Incidentally, this fixed a couple of bugs, so I've enabled the tests which now pass. llvm-svn: 340710
This commit is contained in:
parent
bc7a9bd514
commit
b7710f8516
@ -1,6 +1,7 @@
|
||||
add_llvm_library(LLVMDemangle
|
||||
ItaniumDemangle.cpp
|
||||
MicrosoftDemangle.cpp
|
||||
MicrosoftDemangleNodes.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
"${LLVM_MAIN_INCLUDE_DIR}/llvm/Demangle"
|
||||
|
File diff suppressed because it is too large
Load Diff
590
lib/Demangle/MicrosoftDemangleNodes.cpp
Normal file
590
lib/Demangle/MicrosoftDemangleNodes.cpp
Normal file
@ -0,0 +1,590 @@
|
||||
//===- MicrosoftDemangle.cpp ----------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines a demangler for MSVC-style mangled symbols.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MicrosoftDemangleNodes.h"
|
||||
|
||||
#include "llvm/Demangle/Compiler.h"
|
||||
#include "llvm/Demangle/Utility.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace ms_demangle;
|
||||
|
||||
#define OUTPUT_ENUM_CLASS_VALUE(Enum, Value, Desc) \
|
||||
case Enum::Value: \
|
||||
OS << Desc; \
|
||||
break;
|
||||
|
||||
// Writes a space if the last token does not end with a punctuation.
|
||||
static void outputSpaceIfNecessary(OutputStream &OS) {
|
||||
if (OS.empty())
|
||||
return;
|
||||
|
||||
char C = OS.back();
|
||||
if (isalnum(C) || C == '>')
|
||||
OS << " ";
|
||||
}
|
||||
|
||||
static bool outputSingleQualifier(OutputStream &OS, Qualifiers Q) {
|
||||
switch (Q) {
|
||||
case Q_Const:
|
||||
OS << "const";
|
||||
return true;
|
||||
case Q_Volatile:
|
||||
OS << "volatile";
|
||||
return true;
|
||||
case Q_Restrict:
|
||||
OS << "__restrict";
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool outputQualifierIfPresent(OutputStream &OS, Qualifiers Q,
|
||||
Qualifiers Mask, bool NeedSpace) {
|
||||
if (!(Q & Mask))
|
||||
return NeedSpace;
|
||||
|
||||
if (NeedSpace)
|
||||
OS << " ";
|
||||
|
||||
outputSingleQualifier(OS, Mask);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void outputQualifiers(OutputStream &OS, Qualifiers Q, bool SpaceBefore,
|
||||
bool SpaceAfter) {
|
||||
if (Q == Q_None)
|
||||
return;
|
||||
|
||||
size_t Pos1 = OS.getCurrentPosition();
|
||||
SpaceBefore = outputQualifierIfPresent(OS, Q, Q_Const, SpaceBefore);
|
||||
SpaceBefore = outputQualifierIfPresent(OS, Q, Q_Volatile, SpaceBefore);
|
||||
SpaceBefore = outputQualifierIfPresent(OS, Q, Q_Restrict, SpaceBefore);
|
||||
size_t Pos2 = OS.getCurrentPosition();
|
||||
if (SpaceAfter && Pos2 > Pos1)
|
||||
OS << " ";
|
||||
}
|
||||
|
||||
static void outputCallingConvention(OutputStream &OS, CallingConv CC) {
|
||||
outputSpaceIfNecessary(OS);
|
||||
|
||||
switch (CC) {
|
||||
case CallingConv::Cdecl:
|
||||
OS << "__cdecl";
|
||||
break;
|
||||
case CallingConv::Fastcall:
|
||||
OS << "__fastcall";
|
||||
break;
|
||||
case CallingConv::Pascal:
|
||||
OS << "__pascal";
|
||||
break;
|
||||
case CallingConv::Regcall:
|
||||
OS << "__regcall";
|
||||
break;
|
||||
case CallingConv::Stdcall:
|
||||
OS << "__stdcall";
|
||||
break;
|
||||
case CallingConv::Thiscall:
|
||||
OS << "__thiscall";
|
||||
break;
|
||||
case CallingConv::Eabi:
|
||||
OS << "__eabi";
|
||||
break;
|
||||
case CallingConv::Vectorcall:
|
||||
OS << "__vectorcall";
|
||||
break;
|
||||
case CallingConv::Clrcall:
|
||||
OS << "__clrcall";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TypeNode::outputQuals(bool SpaceBefore, bool SpaceAfter) const {}
|
||||
|
||||
void PrimitiveTypeNode::outputPre(OutputStream &OS) const {
|
||||
switch (PrimKind) {
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Void, "void");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Bool, "bool");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char, "char");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Schar, "signed char");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Uchar, "unsigned char");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char16, "char16_t");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char32, "char32_t");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Short, "short");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ushort, "unsigned short");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Int, "int");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Uint, "unsigned int");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Long, "long");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ulong, "unsigned long");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Int64, "__int64");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Uint64, "unsigned __int64");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Wchar, "wchar_t");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Float, "float");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Double, "double");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ldouble, "long double");
|
||||
OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Nullptr, "std::nullptr_t");
|
||||
}
|
||||
outputQualifiers(OS, Quals, true, false);
|
||||
}
|
||||
|
||||
void NodeArrayNode::output(OutputStream &OS) const { output(OS, ", "); }
|
||||
|
||||
void NodeArrayNode::output(OutputStream &OS, StringView Separator) const {
|
||||
if (Count == 0)
|
||||
return;
|
||||
if (Nodes[0])
|
||||
Nodes[0]->output(OS);
|
||||
for (size_t I = 1; I < Count; ++I) {
|
||||
OS << Separator;
|
||||
Nodes[I]->output(OS);
|
||||
}
|
||||
}
|
||||
|
||||
void EncodedStringLiteralNode::output(OutputStream &OS) const {
|
||||
switch (Char) {
|
||||
case CharKind::Wchar:
|
||||
OS << "const wchar_t * {L\"";
|
||||
break;
|
||||
case CharKind::Char:
|
||||
OS << "const char * {\"";
|
||||
break;
|
||||
case CharKind::Char16:
|
||||
OS << "const char16_t * {u\"";
|
||||
break;
|
||||
case CharKind::Char32:
|
||||
OS << "const char32_t * {U\"";
|
||||
break;
|
||||
}
|
||||
OS << DecodedString << "\"";
|
||||
if (IsTruncated)
|
||||
OS << "...";
|
||||
OS << "}";
|
||||
}
|
||||
|
||||
void IntegerLiteralNode::output(OutputStream &OS) const {
|
||||
if (IsNegative)
|
||||
OS << '-';
|
||||
OS << Value;
|
||||
}
|
||||
|
||||
void TemplateParameterReferenceNode::output(OutputStream &OS) const {
|
||||
if (ThunkOffsetCount > 0)
|
||||
OS << "{";
|
||||
else if (Affinity == PointerAffinity::Pointer)
|
||||
OS << "&";
|
||||
|
||||
if (Symbol) {
|
||||
Symbol->output(OS);
|
||||
if (ThunkOffsetCount > 0)
|
||||
OS << ", ";
|
||||
}
|
||||
|
||||
if (ThunkOffsetCount > 0)
|
||||
OS << ThunkOffsets[0];
|
||||
for (int I = 1; I < ThunkOffsetCount; ++I) {
|
||||
OS << ", " << ThunkOffsets[I];
|
||||
}
|
||||
if (ThunkOffsetCount > 0)
|
||||
OS << "}";
|
||||
}
|
||||
|
||||
void IdentifierNode::outputTemplateParameters(OutputStream &OS) const {
|
||||
if (!TemplateParams)
|
||||
return;
|
||||
OS << "<";
|
||||
TemplateParams->output(OS);
|
||||
OS << ">";
|
||||
}
|
||||
|
||||
void DynamicStructorIdentifierNode::output(OutputStream &OS) const {
|
||||
if (IsDestructor)
|
||||
OS << "`dynamic atexit destructor for ";
|
||||
else
|
||||
OS << "`dynamic initializer for ";
|
||||
|
||||
OS << "'";
|
||||
Name->output(OS);
|
||||
OS << "''";
|
||||
}
|
||||
|
||||
void NamedIdentifierNode::output(OutputStream &OS) const {
|
||||
OS << Name;
|
||||
outputTemplateParameters(OS);
|
||||
}
|
||||
|
||||
void IntrinsicFunctionIdentifierNode::output(OutputStream &OS) const {
|
||||
switch (Operator) {
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, New, "operator new");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Delete, "operator delete");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Assign, "operator=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, RightShift, "operator>>");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LeftShift, "operator<<");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LogicalNot, "operator!");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Equals, "operator==");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, NotEquals, "operator!=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ArraySubscript,
|
||||
"operator[]");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Pointer, "operator->");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Increment, "operator++");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Decrement, "operator--");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Minus, "operator-");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Plus, "operator+");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Dereference, "operator*");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseAnd, "operator&");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, MemberPointer,
|
||||
"operator->*");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Divide, "operator/");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Modulus, "operator%");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LessThan, "operator<");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LessThanEqual, "operator<=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, GreaterThan, "operator>");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, GreaterThanEqual,
|
||||
"operator>=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Comma, "operator,");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Parens, "operator()");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseNot, "operator~");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseXor, "operator^");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseOr, "operator|");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LogicalAnd, "operator&&");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LogicalOr, "operator||");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, TimesEqual, "operator*=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, PlusEqual, "operator+=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, MinusEqual, "operator-=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, DivEqual, "operator/=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ModEqual, "operator%=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, RshEqual, "operator>>=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LshEqual, "operator<<=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseAndEqual,
|
||||
"operator&=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseOrEqual,
|
||||
"operator|=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseXorEqual,
|
||||
"operator^=");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VbaseDtor, "`vbase dtor'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecDelDtor,
|
||||
"`vector deleting dtor'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, DefaultCtorClosure,
|
||||
"`default ctor closure'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ScalarDelDtor,
|
||||
"`scalar deleting dtor'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecCtorIter,
|
||||
"`vector ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecDtorIter,
|
||||
"`vector dtor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecVbaseCtorIter,
|
||||
"`vector vbase ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VdispMap,
|
||||
"`virtual displacement map'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVecCtorIter,
|
||||
"`eh vector ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVecDtorIter,
|
||||
"`eh vector dtor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVecVbaseCtorIter,
|
||||
"`eh vector vbase ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, CopyCtorClosure,
|
||||
"`copy ctor closure'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LocalVftableCtorClosure,
|
||||
"`local vftable ctor closure'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ArrayNew, "operator new[]");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ArrayDelete,
|
||||
"operator delete[]");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ManVectorCtorIter,
|
||||
"`managed vector ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ManVectorDtorIter,
|
||||
"`managed vector dtor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVectorCopyCtorIter,
|
||||
"`EH vector copy ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVectorVbaseCopyCtorIter,
|
||||
"`EH vector vbase copy ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VectorCopyCtorIter,
|
||||
"`vector copy ctor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VectorVbaseCopyCtorIter,
|
||||
"`vector vbase copy constructor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ManVectorVbaseCopyCtorIter,
|
||||
"`managed vector vbase copy constructor iterator'");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, CoAwait, "co_await");
|
||||
OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Spaceship, "operator <=>");
|
||||
case IntrinsicFunctionKind::MaxIntrinsic:
|
||||
case IntrinsicFunctionKind::None:
|
||||
break;
|
||||
}
|
||||
outputTemplateParameters(OS);
|
||||
}
|
||||
|
||||
void LocalStaticGuardIdentifierNode::output(OutputStream &OS) const {
|
||||
OS << "`local static guard'";
|
||||
if (ScopeIndex > 0)
|
||||
OS << "{" << ScopeIndex << "}";
|
||||
}
|
||||
|
||||
void ConversionOperatorIdentifierNode::output(OutputStream &OS) const {
|
||||
OS << "operator";
|
||||
outputTemplateParameters(OS);
|
||||
OS << " ";
|
||||
TargetType->output(OS);
|
||||
}
|
||||
|
||||
void StructorIdentifierNode::output(OutputStream &OS) const {
|
||||
if (IsDestructor)
|
||||
OS << "~";
|
||||
Class->output(OS);
|
||||
outputTemplateParameters(OS);
|
||||
}
|
||||
|
||||
void LiteralOperatorIdentifierNode::output(OutputStream &OS) const {
|
||||
OS << "operator \"\"" << Name;
|
||||
outputTemplateParameters(OS);
|
||||
}
|
||||
|
||||
void FunctionSignatureNode::outputPre(OutputStream &OS,
|
||||
FunctionSigFlags Flags) const {
|
||||
if (!(FunctionClass & FC_Global)) {
|
||||
if (FunctionClass & FC_Static)
|
||||
OS << "static ";
|
||||
}
|
||||
if (FunctionClass & FC_ExternC)
|
||||
OS << "extern \"C\" ";
|
||||
|
||||
if (FunctionClass & FC_Virtual)
|
||||
OS << "virtual ";
|
||||
|
||||
if (ReturnType) {
|
||||
ReturnType->outputPre(OS);
|
||||
OS << " ";
|
||||
}
|
||||
|
||||
if (!(Flags & FSF_NoCallingConvention))
|
||||
outputCallingConvention(OS, CallConvention);
|
||||
}
|
||||
|
||||
void FunctionSignatureNode::outputPost(OutputStream &OS,
|
||||
FunctionSigFlags Flags) const {
|
||||
if (!(FunctionClass & FC_NoParameterList)) {
|
||||
OS << "(";
|
||||
if (Params)
|
||||
Params->output(OS);
|
||||
else
|
||||
OS << "void";
|
||||
OS << ")";
|
||||
}
|
||||
|
||||
if (Quals & Q_Const)
|
||||
OS << " const";
|
||||
if (Quals & Q_Volatile)
|
||||
OS << " volatile";
|
||||
if (Quals & Q_Restrict)
|
||||
OS << " __restrict";
|
||||
if (Quals & Q_Unaligned)
|
||||
OS << " __unaligned";
|
||||
|
||||
if (RefQualifier == FunctionRefQualifier::Reference)
|
||||
OS << " &";
|
||||
else if (RefQualifier == FunctionRefQualifier::RValueReference)
|
||||
OS << " &&";
|
||||
|
||||
if (ReturnType)
|
||||
ReturnType->outputPost(OS);
|
||||
}
|
||||
|
||||
void ThunkSignatureNode::outputPre(OutputStream &OS,
|
||||
FunctionSigFlags Flags) const {
|
||||
OS << "[thunk]: ";
|
||||
|
||||
FunctionSignatureNode::outputPre(OS, Flags);
|
||||
}
|
||||
|
||||
void ThunkSignatureNode::outputPost(OutputStream &OS,
|
||||
FunctionSigFlags Flags) const {
|
||||
if (FunctionClass & FC_StaticThisAdjust) {
|
||||
OS << "`adjustor{" << ThisAdjust.StaticOffset << "}'";
|
||||
} else if (FunctionClass & FC_VirtualThisAdjust) {
|
||||
if (FunctionClass & FC_VirtualThisAdjustEx) {
|
||||
OS << "`vtordispex{" << ThisAdjust.VBPtrOffset << ", "
|
||||
<< ThisAdjust.VBOffsetOffset << ", " << ThisAdjust.VtordispOffset
|
||||
<< ", " << ThisAdjust.StaticOffset << "}'";
|
||||
} else {
|
||||
OS << "`vtordisp{" << ThisAdjust.VtordispOffset << ", "
|
||||
<< ThisAdjust.StaticOffset << "}'";
|
||||
}
|
||||
}
|
||||
|
||||
FunctionSignatureNode::outputPost(OS, Flags);
|
||||
}
|
||||
|
||||
void PointerTypeNode::outputPre(OutputStream &OS) const {
|
||||
if (Pointee->kind() == NodeKind::FunctionSignature) {
|
||||
// If this is a pointer to a function, don't output the calling convention.
|
||||
// It needs to go inside the parentheses.
|
||||
const FunctionSignatureNode *Sig =
|
||||
static_cast<const FunctionSignatureNode *>(Pointee);
|
||||
Sig->outputPre(OS, FSF_NoCallingConvention);
|
||||
} else
|
||||
Pointee->outputPre(OS);
|
||||
|
||||
outputSpaceIfNecessary(OS);
|
||||
|
||||
if (Quals & Q_Unaligned)
|
||||
OS << "__unaligned ";
|
||||
|
||||
if (Pointee->kind() == NodeKind::ArrayType) {
|
||||
OS << "(";
|
||||
} else if (Pointee->kind() == NodeKind::FunctionSignature) {
|
||||
OS << "(";
|
||||
const FunctionSignatureNode *Sig =
|
||||
static_cast<const FunctionSignatureNode *>(Pointee);
|
||||
outputCallingConvention(OS, Sig->CallConvention);
|
||||
OS << " ";
|
||||
}
|
||||
|
||||
if (ClassParent) {
|
||||
ClassParent->output(OS);
|
||||
OS << "::";
|
||||
}
|
||||
|
||||
switch (Affinity) {
|
||||
case PointerAffinity::Pointer:
|
||||
OS << "*";
|
||||
break;
|
||||
case PointerAffinity::Reference:
|
||||
OS << "&";
|
||||
break;
|
||||
case PointerAffinity::RValueReference:
|
||||
OS << "&&";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
outputQualifiers(OS, Quals, false, false);
|
||||
}
|
||||
|
||||
void PointerTypeNode::outputPost(OutputStream &OS) const {
|
||||
if (Pointee->kind() == NodeKind::ArrayType ||
|
||||
Pointee->kind() == NodeKind::FunctionSignature)
|
||||
OS << ")";
|
||||
|
||||
Pointee->outputPost(OS);
|
||||
}
|
||||
|
||||
void TagTypeNode::outputPre(OutputStream &OS) const {
|
||||
switch (Tag) {
|
||||
OUTPUT_ENUM_CLASS_VALUE(TagKind, Class, "class");
|
||||
OUTPUT_ENUM_CLASS_VALUE(TagKind, Struct, "struct");
|
||||
OUTPUT_ENUM_CLASS_VALUE(TagKind, Union, "union");
|
||||
OUTPUT_ENUM_CLASS_VALUE(TagKind, Enum, "enum");
|
||||
}
|
||||
OS << " ";
|
||||
QualifiedName->output(OS);
|
||||
outputQualifiers(OS, Quals, true, false);
|
||||
}
|
||||
|
||||
void TagTypeNode::outputPost(OutputStream &OS) const {}
|
||||
|
||||
void ArrayTypeNode::outputPre(OutputStream &OS) const {
|
||||
ElementType->outputPre(OS);
|
||||
outputQualifiers(OS, Quals, true, false);
|
||||
}
|
||||
|
||||
void ArrayTypeNode::outputOneDimension(OutputStream &OS, Node *N) const {
|
||||
assert(N->kind() == NodeKind::IntegerLiteral);
|
||||
IntegerLiteralNode *ILN = static_cast<IntegerLiteralNode *>(N);
|
||||
if (ILN->Value != 0)
|
||||
ILN->output(OS);
|
||||
}
|
||||
|
||||
void ArrayTypeNode::outputDimensionsImpl(OutputStream &OS) const {
|
||||
if (Dimensions->Count == 0)
|
||||
return;
|
||||
|
||||
outputOneDimension(OS, Dimensions->Nodes[0]);
|
||||
for (size_t I = 1; I < Dimensions->Count; ++I) {
|
||||
OS << "][";
|
||||
outputOneDimension(OS, Dimensions->Nodes[I]);
|
||||
}
|
||||
}
|
||||
|
||||
void ArrayTypeNode::outputPost(OutputStream &OS) const {
|
||||
OS << "[";
|
||||
outputDimensionsImpl(OS);
|
||||
OS << "]";
|
||||
|
||||
ElementType->outputPost(OS);
|
||||
}
|
||||
|
||||
void SymbolNode::output(OutputStream &OS) const { Name->output(OS); }
|
||||
|
||||
void FunctionSymbolNode::output(OutputStream &OS) const {
|
||||
output(OS, FunctionSigFlags::FSF_Default);
|
||||
}
|
||||
|
||||
void FunctionSymbolNode::output(OutputStream &OS,
|
||||
FunctionSigFlags Flags) const {
|
||||
Signature->outputPre(OS, Flags);
|
||||
outputSpaceIfNecessary(OS);
|
||||
Name->output(OS);
|
||||
Signature->outputPost(OS, Flags);
|
||||
}
|
||||
|
||||
void VariableSymbolNode::output(OutputStream &OS) const {
|
||||
switch (SC) {
|
||||
case StorageClass::PrivateStatic:
|
||||
case StorageClass::PublicStatic:
|
||||
case StorageClass::ProtectedStatic:
|
||||
OS << "static ";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (Type) {
|
||||
Type->outputPre(OS);
|
||||
outputSpaceIfNecessary(OS);
|
||||
}
|
||||
Name->output(OS);
|
||||
if (Type)
|
||||
Type->outputPost(OS);
|
||||
}
|
||||
|
||||
void CustomNode::output(OutputStream &OS) const { OS << Name; }
|
||||
|
||||
void QualifiedNameNode::output(OutputStream &OS) const {
|
||||
Components->output(OS, "::");
|
||||
}
|
||||
|
||||
void RttiBaseClassDescriptorNode::output(OutputStream &OS) const {
|
||||
OS << "`RTTI Base Class Descriptor at (";
|
||||
OS << NVOffset << ", " << VBPtrOffset << ", " << VBTableOffset << ", "
|
||||
<< Flags;
|
||||
OS << ")'";
|
||||
}
|
||||
|
||||
void LocalStaticGuardVariableNode::output(OutputStream &OS) const {
|
||||
Name->output(OS);
|
||||
}
|
||||
|
||||
void VcallThunkIdentifierNode::output(OutputStream &OS) const {
|
||||
OS << "`vcall'{" << OffsetInVTable << ", {flat}}";
|
||||
}
|
||||
|
||||
void SpecialTableSymbolNode::output(OutputStream &OS) const {
|
||||
outputQualifiers(OS, Quals, false, true);
|
||||
Name->output(OS);
|
||||
if (TargetName) {
|
||||
OS << "{for `";
|
||||
TargetName->output(OS);
|
||||
OS << "'}";
|
||||
}
|
||||
return;
|
||||
}
|
705
lib/Demangle/MicrosoftDemangleNodes.h
Normal file
705
lib/Demangle/MicrosoftDemangleNodes.h
Normal file
@ -0,0 +1,705 @@
|
||||
#ifndef LLVM_SUPPORT_MICROSOFTDEMANGLENODES_H
|
||||
#define LLVM_SUPPORT_MICROSOFTDEMANGLENODES_H
|
||||
|
||||
#include "llvm/Demangle/Compiler.h"
|
||||
#include "llvm/Demangle/StringView.h"
|
||||
#include <array>
|
||||
|
||||
class OutputStream;
|
||||
|
||||
namespace llvm {
|
||||
namespace ms_demangle {
|
||||
|
||||
// This memory allocator is extremely fast, but it doesn't call dtors
|
||||
// for allocated objects. That means you can't use STL containers
|
||||
// (such as std::vector) with this allocator. But it pays off --
|
||||
// the demangler is 3x faster with this allocator compared to one with
|
||||
// STL containers.
|
||||
constexpr size_t AllocUnit = 4096;
|
||||
|
||||
class ArenaAllocator {
|
||||
struct AllocatorNode {
|
||||
uint8_t *Buf = nullptr;
|
||||
size_t Used = 0;
|
||||
size_t Capacity = 0;
|
||||
AllocatorNode *Next = nullptr;
|
||||
};
|
||||
|
||||
void addNode(size_t Capacity) {
|
||||
AllocatorNode *NewHead = new AllocatorNode;
|
||||
NewHead->Buf = new uint8_t[Capacity];
|
||||
NewHead->Next = Head;
|
||||
NewHead->Capacity = Capacity;
|
||||
Head = NewHead;
|
||||
NewHead->Used = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
ArenaAllocator() { addNode(AllocUnit); }
|
||||
|
||||
~ArenaAllocator() {
|
||||
while (Head) {
|
||||
assert(Head->Buf);
|
||||
delete[] Head->Buf;
|
||||
AllocatorNode *Next = Head->Next;
|
||||
delete Head;
|
||||
Head = Next;
|
||||
}
|
||||
}
|
||||
|
||||
char *allocUnalignedBuffer(size_t Length) {
|
||||
uint8_t *Buf = Head->Buf + Head->Used;
|
||||
|
||||
Head->Used += Length;
|
||||
if (Head->Used > Head->Capacity) {
|
||||
// It's possible we need a buffer which is larger than our default unit
|
||||
// size, so we need to be careful to add a node with capacity that is at
|
||||
// least as large as what we need.
|
||||
addNode(std::max(AllocUnit, Length));
|
||||
Head->Used = Length;
|
||||
Buf = Head->Buf;
|
||||
}
|
||||
|
||||
return reinterpret_cast<char *>(Buf);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T *allocArray(size_t Count) {
|
||||
|
||||
size_t Size = Count * sizeof(T);
|
||||
assert(Head && Head->Buf);
|
||||
|
||||
size_t P = (size_t)Head->Buf + Head->Used;
|
||||
uintptr_t AlignedP =
|
||||
(((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
|
||||
uint8_t *PP = (uint8_t *)AlignedP;
|
||||
size_t Adjustment = AlignedP - P;
|
||||
|
||||
Head->Used += Size + Adjustment;
|
||||
if (Head->Used < Head->Capacity)
|
||||
return new (PP) T[Count]();
|
||||
|
||||
addNode(AllocUnit);
|
||||
Head->Used = Size;
|
||||
return new (Head->Buf) T[Count]();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
|
||||
|
||||
size_t Size = sizeof(T);
|
||||
assert(Head && Head->Buf);
|
||||
|
||||
size_t P = (size_t)Head->Buf + Head->Used;
|
||||
uintptr_t AlignedP =
|
||||
(((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
|
||||
uint8_t *PP = (uint8_t *)AlignedP;
|
||||
size_t Adjustment = AlignedP - P;
|
||||
|
||||
Head->Used += Size + Adjustment;
|
||||
if (Head->Used < Head->Capacity)
|
||||
return new (PP) T(std::forward<Args>(ConstructorArgs)...);
|
||||
|
||||
addNode(AllocUnit);
|
||||
Head->Used = Size;
|
||||
return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
|
||||
}
|
||||
|
||||
private:
|
||||
AllocatorNode *Head = nullptr;
|
||||
};
|
||||
|
||||
// Storage classes
|
||||
enum Qualifiers : uint8_t {
|
||||
Q_None = 0,
|
||||
Q_Const = 1 << 0,
|
||||
Q_Volatile = 1 << 1,
|
||||
Q_Far = 1 << 2,
|
||||
Q_Huge = 1 << 3,
|
||||
Q_Unaligned = 1 << 4,
|
||||
Q_Restrict = 1 << 5,
|
||||
Q_Pointer64 = 1 << 6
|
||||
};
|
||||
|
||||
enum class StorageClass : uint8_t {
|
||||
None,
|
||||
PrivateStatic,
|
||||
ProtectedStatic,
|
||||
PublicStatic,
|
||||
Global,
|
||||
FunctionLocalStatic,
|
||||
};
|
||||
|
||||
enum class PointerAffinity { None, Pointer, Reference, RValueReference };
|
||||
enum class FunctionRefQualifier { None, Reference, RValueReference };
|
||||
|
||||
// Calling conventions
|
||||
enum class CallingConv : uint8_t {
|
||||
None,
|
||||
Cdecl,
|
||||
Pascal,
|
||||
Thiscall,
|
||||
Stdcall,
|
||||
Fastcall,
|
||||
Clrcall,
|
||||
Eabi,
|
||||
Vectorcall,
|
||||
Regcall,
|
||||
};
|
||||
|
||||
enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
|
||||
|
||||
enum FunctionSigFlags { FSF_Default = 0, FSF_NoCallingConvention = 1 };
|
||||
|
||||
// Types
|
||||
enum class PrimitiveKind {
|
||||
Void,
|
||||
Bool,
|
||||
Char,
|
||||
Schar,
|
||||
Uchar,
|
||||
Char16,
|
||||
Char32,
|
||||
Short,
|
||||
Ushort,
|
||||
Int,
|
||||
Uint,
|
||||
Long,
|
||||
Ulong,
|
||||
Int64,
|
||||
Uint64,
|
||||
Wchar,
|
||||
Float,
|
||||
Double,
|
||||
Ldouble,
|
||||
Nullptr,
|
||||
};
|
||||
|
||||
enum class CharKind {
|
||||
Char,
|
||||
Char16,
|
||||
Char32,
|
||||
Wchar,
|
||||
};
|
||||
|
||||
enum class IntrinsicFunctionKind : uint8_t {
|
||||
None,
|
||||
New, // ?2 # operator new
|
||||
Delete, // ?3 # operator delete
|
||||
Assign, // ?4 # operator=
|
||||
RightShift, // ?5 # operator>>
|
||||
LeftShift, // ?6 # operator<<
|
||||
LogicalNot, // ?7 # operator!
|
||||
Equals, // ?8 # operator==
|
||||
NotEquals, // ?9 # operator!=
|
||||
ArraySubscript, // ?A # operator[]
|
||||
Pointer, // ?C # operator->
|
||||
Dereference, // ?D # operator*
|
||||
Increment, // ?E # operator++
|
||||
Decrement, // ?F # operator--
|
||||
Minus, // ?G # operator-
|
||||
Plus, // ?H # operator+
|
||||
BitwiseAnd, // ?I # operator&
|
||||
MemberPointer, // ?J # operator->*
|
||||
Divide, // ?K # operator/
|
||||
Modulus, // ?L # operator%
|
||||
LessThan, // ?M operator<
|
||||
LessThanEqual, // ?N operator<=
|
||||
GreaterThan, // ?O operator>
|
||||
GreaterThanEqual, // ?P operator>=
|
||||
Comma, // ?Q operator,
|
||||
Parens, // ?R operator()
|
||||
BitwiseNot, // ?S operator~
|
||||
BitwiseXor, // ?T operator^
|
||||
BitwiseOr, // ?U operator|
|
||||
LogicalAnd, // ?V operator&&
|
||||
LogicalOr, // ?W operator||
|
||||
TimesEqual, // ?X operator*=
|
||||
PlusEqual, // ?Y operator+=
|
||||
MinusEqual, // ?Z operator-=
|
||||
DivEqual, // ?_0 operator/=
|
||||
ModEqual, // ?_1 operator%=
|
||||
RshEqual, // ?_2 operator>>=
|
||||
LshEqual, // ?_3 operator<<=
|
||||
BitwiseAndEqual, // ?_4 operator&=
|
||||
BitwiseOrEqual, // ?_5 operator|=
|
||||
BitwiseXorEqual, // ?_6 operator^=
|
||||
VbaseDtor, // ?_D # vbase destructor
|
||||
VecDelDtor, // ?_E # vector deleting destructor
|
||||
DefaultCtorClosure, // ?_F # default constructor closure
|
||||
ScalarDelDtor, // ?_G # scalar deleting destructor
|
||||
VecCtorIter, // ?_H # vector constructor iterator
|
||||
VecDtorIter, // ?_I # vector destructor iterator
|
||||
VecVbaseCtorIter, // ?_J # vector vbase constructor iterator
|
||||
VdispMap, // ?_K # virtual displacement map
|
||||
EHVecCtorIter, // ?_L # eh vector constructor iterator
|
||||
EHVecDtorIter, // ?_M # eh vector destructor iterator
|
||||
EHVecVbaseCtorIter, // ?_N # eh vector vbase constructor iterator
|
||||
CopyCtorClosure, // ?_O # copy constructor closure
|
||||
LocalVftableCtorClosure, // ?_T # local vftable constructor closure
|
||||
ArrayNew, // ?_U operator new[]
|
||||
ArrayDelete, // ?_V operator delete[]
|
||||
ManVectorCtorIter, // ?__A managed vector ctor iterator
|
||||
ManVectorDtorIter, // ?__B managed vector dtor iterator
|
||||
EHVectorCopyCtorIter, // ?__C EH vector copy ctor iterator
|
||||
EHVectorVbaseCopyCtorIter, // ?__D EH vector vbase copy ctor iterator
|
||||
VectorCopyCtorIter, // ?__G vector copy constructor iterator
|
||||
VectorVbaseCopyCtorIter, // ?__H vector vbase copy constructor iterator
|
||||
ManVectorVbaseCopyCtorIter, // ?__I managed vector vbase copy constructor
|
||||
CoAwait, // ?__L co_await
|
||||
Spaceship, // operator<=>
|
||||
MaxIntrinsic
|
||||
};
|
||||
|
||||
enum class SpecialIntrinsicKind {
|
||||
None,
|
||||
Vftable,
|
||||
Vbtable,
|
||||
Typeof,
|
||||
VcallThunk,
|
||||
LocalStaticGuard,
|
||||
StringLiteralSymbol,
|
||||
UdtReturning,
|
||||
Unknown,
|
||||
DynamicInitializer,
|
||||
DynamicAtexitDestructor,
|
||||
RttiTypeDescriptor,
|
||||
RttiBaseClassDescriptor,
|
||||
RttiBaseClassArray,
|
||||
RttiClassHierarchyDescriptor,
|
||||
RttiCompleteObjLocator,
|
||||
LocalVftable,
|
||||
LocalStaticThreadGuard,
|
||||
};
|
||||
|
||||
// Function classes
|
||||
enum FuncClass : uint16_t {
|
||||
FC_None = 0,
|
||||
FC_Public = 1 << 0,
|
||||
FC_Protected = 1 << 1,
|
||||
FC_Private = 1 << 2,
|
||||
FC_Global = 1 << 3,
|
||||
FC_Static = 1 << 4,
|
||||
FC_Virtual = 1 << 5,
|
||||
FC_Far = 1 << 6,
|
||||
FC_ExternC = 1 << 7,
|
||||
FC_NoParameterList = 1 << 8,
|
||||
FC_VirtualThisAdjust = 1 << 9,
|
||||
FC_VirtualThisAdjustEx = 1 << 10,
|
||||
FC_StaticThisAdjust = 1 << 11,
|
||||
};
|
||||
|
||||
enum class TagKind { Class, Struct, Union, Enum };
|
||||
|
||||
enum class NodeKind {
|
||||
Unknown,
|
||||
Md5Symbol,
|
||||
PrimitiveType,
|
||||
FunctionSignature,
|
||||
Identifier,
|
||||
NamedIdentifier,
|
||||
VcallThunkIdentifier,
|
||||
LocalStaticGuardIdentifier,
|
||||
IntrinsicFunctionIdentifier,
|
||||
ConversionOperatorIdentifier,
|
||||
DynamicStructorIdentifier,
|
||||
StructorIdentifier,
|
||||
LiteralOperatorIdentifier,
|
||||
ThunkSignature,
|
||||
PointerType,
|
||||
TagType,
|
||||
ArrayType,
|
||||
Custom,
|
||||
IntrinsicType,
|
||||
NodeArray,
|
||||
QualifiedName,
|
||||
TemplateParameterReference,
|
||||
EncodedStringLiteral,
|
||||
IntegerLiteral,
|
||||
RttiBaseClassDescriptor,
|
||||
LocalStaticGuardVariable,
|
||||
FunctionSymbol,
|
||||
VariableSymbol,
|
||||
SpecialTableSymbol,
|
||||
};
|
||||
|
||||
struct Node {
|
||||
explicit Node(NodeKind K) : Kind(K) {}
|
||||
|
||||
NodeKind kind() const { return Kind; }
|
||||
|
||||
virtual void output(OutputStream &OS) const = 0;
|
||||
|
||||
private:
|
||||
NodeKind Kind;
|
||||
};
|
||||
|
||||
struct TypeNode;
|
||||
struct PrimitiveTypeNode;
|
||||
struct FunctionSignatureNode;
|
||||
struct IdentifierNode;
|
||||
struct NamedIdentifierNode;
|
||||
struct VcallThunkIdentifierNode;
|
||||
struct IntrinsicFunctionIdentifierNode;
|
||||
struct LiteralOperatorIdentifierNode;
|
||||
struct ConversionOperatorIdentifierNode;
|
||||
struct StructorIdentifierNode;
|
||||
struct ThunkSignatureNode;
|
||||
struct PointerTypeNode;
|
||||
struct ArrayTypeNode;
|
||||
struct CustomNode;
|
||||
struct TagTypeNode;
|
||||
struct IntrinsicTypeNode;
|
||||
struct NodeArrayNode;
|
||||
struct QualifiedNameNode;
|
||||
struct TemplateParameterReferenceNode;
|
||||
struct EncodedStringLiteralNode;
|
||||
struct IntegerLiteralNode;
|
||||
struct RttiBaseClassDescriptorNode;
|
||||
struct LocalStaticGuardVariableNode;
|
||||
struct SymbolNode;
|
||||
struct FunctionSymbolNode;
|
||||
struct VariableSymbolNode;
|
||||
struct SpecialTableSymbolNode;
|
||||
|
||||
struct TypeNode : public Node {
|
||||
explicit TypeNode(NodeKind K) : Node(K) {}
|
||||
|
||||
virtual void outputPre(OutputStream &OS) const = 0;
|
||||
virtual void outputPost(OutputStream &OS) const = 0;
|
||||
|
||||
void output(OutputStream &OS) const {
|
||||
outputPre(OS);
|
||||
outputPost(OS);
|
||||
}
|
||||
|
||||
void outputQuals(bool SpaceBefore, bool SpaceAfter) const;
|
||||
|
||||
Qualifiers Quals = Q_None;
|
||||
};
|
||||
|
||||
struct PrimitiveTypeNode : public TypeNode {
|
||||
explicit PrimitiveTypeNode(PrimitiveKind K)
|
||||
: TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
|
||||
|
||||
void outputPre(OutputStream &OS) const;
|
||||
void outputPost(OutputStream &OS) const {}
|
||||
|
||||
PrimitiveKind PrimKind;
|
||||
};
|
||||
|
||||
struct FunctionSignatureNode : public TypeNode {
|
||||
explicit FunctionSignatureNode(NodeKind K) : TypeNode(K) {}
|
||||
FunctionSignatureNode() : TypeNode(NodeKind::FunctionSignature) {}
|
||||
|
||||
virtual void outputPre(OutputStream &OS, FunctionSigFlags Flags) const;
|
||||
virtual void outputPost(OutputStream &OS, FunctionSigFlags Flags) const;
|
||||
|
||||
void outputPre(OutputStream &OS) const override {
|
||||
outputPre(OS, FSF_Default);
|
||||
}
|
||||
void outputPost(OutputStream &OS) const override {
|
||||
outputPost(OS, FSF_Default);
|
||||
}
|
||||
|
||||
void output(OutputStream &OS) const override {
|
||||
outputPre(OS, FSF_Default);
|
||||
outputPost(OS);
|
||||
}
|
||||
|
||||
// Valid if this FunctionTypeNode is the Pointee of a PointerType or
|
||||
// MemberPointerType.
|
||||
PointerAffinity Affinity = PointerAffinity::None;
|
||||
|
||||
// The function's calling convention.
|
||||
CallingConv CallConvention = CallingConv::None;
|
||||
|
||||
// Function flags (gloabl, public, etc)
|
||||
FuncClass FunctionClass = FC_Global;
|
||||
|
||||
FunctionRefQualifier RefQualifier = FunctionRefQualifier::None;
|
||||
|
||||
// The return type of the function.
|
||||
TypeNode *ReturnType = nullptr;
|
||||
|
||||
// True if this is a C-style ... varargs function.
|
||||
bool IsVariadic = false;
|
||||
|
||||
// Function parameters
|
||||
NodeArrayNode *Params = nullptr;
|
||||
};
|
||||
|
||||
struct IdentifierNode : public Node {
|
||||
explicit IdentifierNode(NodeKind K) : Node(K) {}
|
||||
|
||||
NodeArrayNode *TemplateParams = nullptr;
|
||||
|
||||
protected:
|
||||
void outputTemplateParameters(OutputStream &OS) const;
|
||||
};
|
||||
|
||||
struct VcallThunkIdentifierNode : public IdentifierNode {
|
||||
VcallThunkIdentifierNode() : IdentifierNode(NodeKind::VcallThunkIdentifier) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
uint64_t OffsetInVTable = 0;
|
||||
};
|
||||
|
||||
struct DynamicStructorIdentifierNode : public IdentifierNode {
|
||||
DynamicStructorIdentifierNode()
|
||||
: IdentifierNode(NodeKind::DynamicStructorIdentifier) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
QualifiedNameNode *Name = nullptr;
|
||||
bool IsDestructor = false;
|
||||
};
|
||||
|
||||
struct NamedIdentifierNode : public IdentifierNode {
|
||||
NamedIdentifierNode() : IdentifierNode(NodeKind::NamedIdentifier) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
StringView Name;
|
||||
};
|
||||
|
||||
struct IntrinsicFunctionIdentifierNode : public IdentifierNode {
|
||||
explicit IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator)
|
||||
: IdentifierNode(NodeKind::IntrinsicFunctionIdentifier),
|
||||
Operator(Operator) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
IntrinsicFunctionKind Operator;
|
||||
};
|
||||
|
||||
struct LiteralOperatorIdentifierNode : public IdentifierNode {
|
||||
LiteralOperatorIdentifierNode()
|
||||
: IdentifierNode(NodeKind::LiteralOperatorIdentifier) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
StringView Name;
|
||||
};
|
||||
|
||||
struct LocalStaticGuardIdentifierNode : public IdentifierNode {
|
||||
LocalStaticGuardIdentifierNode()
|
||||
: IdentifierNode(NodeKind::LocalStaticGuardIdentifier) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
uint32_t ScopeIndex = 0;
|
||||
};
|
||||
|
||||
struct ConversionOperatorIdentifierNode : public IdentifierNode {
|
||||
ConversionOperatorIdentifierNode()
|
||||
: IdentifierNode(NodeKind::ConversionOperatorIdentifier) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
// The type that this operator converts too.
|
||||
TypeNode *TargetType = nullptr;
|
||||
};
|
||||
|
||||
struct StructorIdentifierNode : public IdentifierNode {
|
||||
StructorIdentifierNode() : IdentifierNode(NodeKind::StructorIdentifier) {}
|
||||
explicit StructorIdentifierNode(bool IsDestructor)
|
||||
: IdentifierNode(NodeKind::StructorIdentifier),
|
||||
IsDestructor(IsDestructor) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
// The name of the class that this is a structor of.
|
||||
IdentifierNode *Class = nullptr;
|
||||
bool IsDestructor = false;
|
||||
};
|
||||
|
||||
struct ThunkSignatureNode : public FunctionSignatureNode {
|
||||
ThunkSignatureNode() : FunctionSignatureNode(NodeKind::ThunkSignature) {}
|
||||
|
||||
void outputPre(OutputStream &OS, FunctionSigFlags Flags) const override;
|
||||
void outputPost(OutputStream &OS, FunctionSigFlags Flags) const override;
|
||||
|
||||
struct ThisAdjustor {
|
||||
uint32_t StaticOffset = 0;
|
||||
int32_t VBPtrOffset = 0;
|
||||
int32_t VBOffsetOffset = 0;
|
||||
int32_t VtordispOffset = 0;
|
||||
};
|
||||
|
||||
ThisAdjustor ThisAdjust;
|
||||
};
|
||||
|
||||
struct PointerTypeNode : public TypeNode {
|
||||
PointerTypeNode() : TypeNode(NodeKind::PointerType) {}
|
||||
void outputPre(OutputStream &OS) const override;
|
||||
void outputPost(OutputStream &OS) const override;
|
||||
|
||||
// Is this a pointer, reference, or rvalue-reference?
|
||||
PointerAffinity Affinity = PointerAffinity::None;
|
||||
|
||||
// If this is a member pointer, this is the class that the member is in.
|
||||
QualifiedNameNode *ClassParent = nullptr;
|
||||
|
||||
// Represents a type X in "a pointer to X", "a reference to X", or
|
||||
// "rvalue-reference to X"
|
||||
TypeNode *Pointee = nullptr;
|
||||
};
|
||||
|
||||
struct TagTypeNode : public TypeNode {
|
||||
explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}
|
||||
|
||||
void outputPre(OutputStream &OS) const;
|
||||
void outputPost(OutputStream &OS) const;
|
||||
|
||||
QualifiedNameNode *QualifiedName = nullptr;
|
||||
TagKind Tag;
|
||||
};
|
||||
|
||||
struct ArrayTypeNode : public TypeNode {
|
||||
ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {}
|
||||
|
||||
void outputPre(OutputStream &OS) const;
|
||||
void outputPost(OutputStream &OS) const;
|
||||
|
||||
void outputDimensionsImpl(OutputStream &OS) const;
|
||||
void outputOneDimension(OutputStream &OS, Node *N) const;
|
||||
|
||||
// A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]`
|
||||
NodeArrayNode *Dimensions = nullptr;
|
||||
|
||||
// The type of array element.
|
||||
TypeNode *ElementType = nullptr;
|
||||
};
|
||||
|
||||
struct IntrinsicNode : public TypeNode {
|
||||
IntrinsicNode() : TypeNode(NodeKind::IntrinsicType) {}
|
||||
void output(OutputStream &OS) const override {}
|
||||
};
|
||||
|
||||
struct CustomNode : public Node {
|
||||
CustomNode() : Node(NodeKind::Custom) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
// The string to print.
|
||||
StringView Name;
|
||||
};
|
||||
|
||||
struct NodeArrayNode : public Node {
|
||||
NodeArrayNode() : Node(NodeKind::NodeArray) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
void output(OutputStream &OS, StringView Separator) const;
|
||||
|
||||
Node **Nodes = 0;
|
||||
size_t Count = 0;
|
||||
};
|
||||
|
||||
struct QualifiedNameNode : public Node {
|
||||
QualifiedNameNode() : Node(NodeKind::QualifiedName) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
NodeArrayNode *Components = nullptr;
|
||||
|
||||
IdentifierNode *getUnqualifiedIdentifier() {
|
||||
Node *LastComponent = Components->Nodes[Components->Count - 1];
|
||||
return static_cast<IdentifierNode *>(LastComponent);
|
||||
}
|
||||
};
|
||||
|
||||
struct TemplateParameterReferenceNode : public Node {
|
||||
TemplateParameterReferenceNode()
|
||||
: Node(NodeKind::TemplateParameterReference) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
SymbolNode *Symbol = nullptr;
|
||||
|
||||
int ThunkOffsetCount = 0;
|
||||
std::array<int64_t, 3> ThunkOffsets;
|
||||
PointerAffinity Affinity = PointerAffinity::None;
|
||||
bool IsMemberPointer = false;
|
||||
};
|
||||
|
||||
struct IntegerLiteralNode : public Node {
|
||||
IntegerLiteralNode() : Node(NodeKind::IntegerLiteral) {}
|
||||
IntegerLiteralNode(uint64_t Value, bool IsNegative)
|
||||
: Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
uint64_t Value = 0;
|
||||
bool IsNegative = false;
|
||||
};
|
||||
|
||||
struct RttiBaseClassDescriptorNode : public IdentifierNode {
|
||||
RttiBaseClassDescriptorNode()
|
||||
: IdentifierNode(NodeKind::RttiBaseClassDescriptor) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
uint32_t NVOffset = 0;
|
||||
int32_t VBPtrOffset = 0;
|
||||
uint32_t VBTableOffset = 0;
|
||||
uint32_t Flags = 0;
|
||||
};
|
||||
|
||||
struct SymbolNode : public Node {
|
||||
explicit SymbolNode(NodeKind K) : Node(K) {}
|
||||
void output(OutputStream &OS) const override;
|
||||
QualifiedNameNode *Name = nullptr;
|
||||
};
|
||||
|
||||
struct SpecialTableSymbolNode : public SymbolNode {
|
||||
explicit SpecialTableSymbolNode()
|
||||
: SymbolNode(NodeKind::SpecialTableSymbol) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
QualifiedNameNode *TargetName = nullptr;
|
||||
Qualifiers Quals;
|
||||
};
|
||||
|
||||
struct LocalStaticGuardVariableNode : public SymbolNode {
|
||||
LocalStaticGuardVariableNode()
|
||||
: SymbolNode(NodeKind::LocalStaticGuardVariable) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
bool IsVisible = false;
|
||||
};
|
||||
|
||||
struct EncodedStringLiteralNode : public SymbolNode {
|
||||
EncodedStringLiteralNode() : SymbolNode(NodeKind::EncodedStringLiteral) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
StringView DecodedString;
|
||||
bool IsTruncated = false;
|
||||
CharKind Char = CharKind::Char;
|
||||
};
|
||||
|
||||
struct VariableSymbolNode : public SymbolNode {
|
||||
VariableSymbolNode() : SymbolNode(NodeKind::VariableSymbol) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
|
||||
StorageClass SC = StorageClass::None;
|
||||
TypeNode *Type = nullptr;
|
||||
};
|
||||
|
||||
struct FunctionSymbolNode : public SymbolNode {
|
||||
FunctionSymbolNode() : SymbolNode(NodeKind::FunctionSymbol) {}
|
||||
|
||||
void output(OutputStream &OS) const override;
|
||||
void output(OutputStream &OS, FunctionSigFlags Flags) const;
|
||||
|
||||
FunctionSignatureNode *Signature = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ms_demangle
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
@ -65,15 +65,12 @@
|
||||
?x@@3PEATty@@EA
|
||||
; CHECK: union ty *x
|
||||
|
||||
?x@@3PEAUty@@EA
|
||||
; CHECK: struct ty *x
|
||||
?x@@3PEAVty@@EA
|
||||
; CHECK: class ty *x
|
||||
|
||||
?x@@3PEAW4ty@@EA
|
||||
; CHECK: enum ty *x
|
||||
|
||||
?x@@3PEAVty@@EA
|
||||
; CHECK: class ty *x
|
||||
|
||||
?x@@3PEAV?$tmpl@H@@EA
|
||||
; CHECK: class tmpl<int> *x
|
||||
|
||||
|
@ -219,10 +219,10 @@
|
||||
; CHECK: const Base::`RTTI Complete Object Locator'
|
||||
|
||||
??__EFoo@@YAXXZ
|
||||
void __cdecl `dynamic initializer for 'Foo''(void)
|
||||
; CHECK: void __cdecl `dynamic initializer for 'Foo''(void)
|
||||
|
||||
??__FFoo@@YAXXZ
|
||||
void __cdecl `dynamic atexit destructor for 'Foo''(void)
|
||||
; CHECK: void __cdecl `dynamic atexit destructor for 'Foo''(void)
|
||||
|
||||
??__K_deg@@YAHO@Z
|
||||
; CHECK: int __cdecl operator ""_deg(long double)
|
||||
|
@ -10,19 +10,19 @@
|
||||
; CHECK: struct K<struct M, -1> m2
|
||||
|
||||
?n@@3U?$J@UN@@$HA@@@A
|
||||
; CHECK: struct J<struct N, nullptr> n
|
||||
; CHECK: struct J<struct N, {0}> n
|
||||
|
||||
?n2@@3U?$K@UN@@$0?0@@A
|
||||
; CHECK: struct K<struct N, -1> n2
|
||||
|
||||
?o@@3U?$J@UO@@$IA@A@@@A
|
||||
; CHECK: struct J<struct O, nullptr> o
|
||||
; CHECK: struct J<struct O, {0, 0}> o
|
||||
|
||||
?o2@@3U?$K@UO@@$FA@?0@@A
|
||||
; CHECK: struct K<struct O, {0, -1}> o2
|
||||
|
||||
?p@@3U?$J@UP@@$JA@A@?0@@A
|
||||
; CHECK: struct J<struct P, nullptr> p
|
||||
; CHECK: struct J<struct P, {0, 0, -1}> p
|
||||
|
||||
?p2@@3U?$K@UP@@$GA@A@?0@@A
|
||||
; CHECK: struct K<struct P, {0, 0, -1}> p2
|
||||
|
@ -2,21 +2,20 @@
|
||||
|
||||
; CHECK-NOT: Invalid mangled name
|
||||
|
||||
; There's a back-referencing problem here
|
||||
??$CallMethod@UC@NegativeNVOffset@@$I??_912@$BA@AEPPPPPPPM@A@@@YAXAAUC@NegativeNVOffset@@@Z
|
||||
; FIXME: void __cdecl CallMethod<struct NegativeNVOffset::C, {[thunk]: __thiscall NegativeNVOffset::C::`vcall'{0, {flat}}, 4294967292, 0}>(struct NegativeNVOffset::C &)
|
||||
; CHECK: void __cdecl CallMethod<struct NegativeNVOffset::C, {[thunk]: __thiscall NegativeNVOffset::C::`vcall'{0, {flat}}, 4294967292, 0}>(struct NegativeNVOffset::C &)
|
||||
|
||||
??$CallMethod@UM@@$0A@@@YAXAAUM@@@Z
|
||||
; CHECK: void __cdecl CallMethod<struct M, 0>(struct M &)
|
||||
|
||||
??$CallMethod@UM@@$H??_91@$BA@AEA@@@YAXAAUM@@@Z
|
||||
; FIXME: void __cdecl CallMethod<struct M, {[thunk]: __thiscall M::`vcall'{0, {flat}}', 0}>(struct M &)
|
||||
; CHECK: void __cdecl CallMethod<struct M, {[thunk]: __thiscall M::`vcall'{0, {flat}}, 0}>(struct M &)
|
||||
|
||||
??$CallMethod@UM@@$H?f@1@QAEXXZA@@@YAXAAUM@@@Z
|
||||
; FIXME: void __cdecl CallMethod<struct M, {void __thiscall M::f(void), 0}>(struct M &)
|
||||
; CHECK: void __cdecl CallMethod<struct M, {void __thiscall M::f(void), 0}>(struct M &)
|
||||
|
||||
??$CallMethod@UO@@$H??_91@$BA@AE3@@YAXAAUO@@@Z
|
||||
; FIXME: void __cdecl CallMethod<struct O, {[thunk]: __thiscall O::`vcall'{0, {flat}}, 4}>(struct O &)
|
||||
; CHECK: void __cdecl CallMethod<struct O, {[thunk]: __thiscall O::`vcall'{0, {flat}}, 4}>(struct O &)
|
||||
|
||||
??$CallMethod@US@@$0A@@@YAXAAUS@@@Z
|
||||
; CHECK: void __cdecl CallMethod<struct S, 0>(struct S &)
|
||||
|
Loading…
Reference in New Issue
Block a user