llvm/llvm/lib/Demangle/MicrosoftDemangle.cpp

//===- MicrosoftDemangle.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines a demangler for MSVC-style mangled symbols.
//
// This file has no dependencies on the rest of LLVM so that it can be
// easily reused in other programs such as libcxxabi.
//
//===----------------------------------------------------------------------===//

#include "llvm/Demangle/MicrosoftDemangle.h"

#include "llvm/Demangle/Demangle.h"
#include "llvm/Demangle/DemangleConfig.h"
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
#include "llvm/Demangle/StringViewExtras.h"
#include "llvm/Demangle/Utility.h"

#include <array>
#include <cctype>
#include <cstdio>
#include <string_view>
#include <tuple>

usingnamespacellvm;
usingnamespacems_demangle;

static bool startsWithDigit(std::string_view S) {}

struct NodeList {};

static bool consumeFront(std::string_view &S, char C) {}

static bool consumeFront(std::string_view &S, std::string_view C) {}

static bool consumeFront(std::string_view &S, std::string_view PrefixA,
                         std::string_view PrefixB, bool A) {}

static bool startsWith(std::string_view S, std::string_view PrefixA,
                       std::string_view PrefixB, bool A) {}

static bool isMemberPointer(std::string_view MangledName, bool &Error) {}

static SpecialIntrinsicKind
consumeSpecialIntrinsicKind(std::string_view &MangledName) {}

static bool startsWithLocalScopePattern(std::string_view S) {}

static bool isTagType(std::string_view S) {}

static bool isCustomType(std::string_view S) {}

static bool isPointerType(std::string_view S) {}

static bool isArrayType(std::string_view S) {}

static bool isFunctionType(std::string_view S) {}

static FunctionRefQualifier
demangleFunctionRefQualifier(std::string_view &MangledName) {}

static std::pair<Qualifiers, PointerAffinity>
demanglePointerCVQualifiers(std::string_view &MangledName) {}

std::string_view Demangler::copyString(std::string_view Borrowed) {}

SpecialTableSymbolNode *
Demangler::demangleSpecialTableSymbolNode(std::string_view &MangledName,
                                          SpecialIntrinsicKind K) {}

LocalStaticGuardVariableNode *
Demangler::demangleLocalStaticGuard(std::string_view &MangledName,
                                    bool IsThread) {}

static NamedIdentifierNode *synthesizeNamedIdentifier(ArenaAllocator &Arena,
                                                      std::string_view Name) {}

static QualifiedNameNode *synthesizeQualifiedName(ArenaAllocator &Arena,
                                                  IdentifierNode *Identifier) {}

static QualifiedNameNode *synthesizeQualifiedName(ArenaAllocator &Arena,
                                                  std::string_view Name) {}

static VariableSymbolNode *synthesizeVariable(ArenaAllocator &Arena,
                                              TypeNode *Type,
                                              std::string_view VariableName) {}

VariableSymbolNode *
Demangler::demangleUntypedVariable(ArenaAllocator &Arena,
                                   std::string_view &MangledName,
                                   std::string_view VariableName) {}

VariableSymbolNode *
Demangler::demangleRttiBaseClassDescriptorNode(ArenaAllocator &Arena,
                                               std::string_view &MangledName) {}

FunctionSymbolNode *
Demangler::demangleInitFiniStub(std::string_view &MangledName,
                                bool IsDestructor) {}

SymbolNode *Demangler::demangleSpecialIntrinsic(std::string_view &MangledName) {}

IdentifierNode *
Demangler::demangleFunctionIdentifierCode(std::string_view &MangledName) {}

StructorIdentifierNode *
Demangler::demangleStructorIdentifier(std::string_view &MangledName,
                                      bool IsDestructor) {}

ConversionOperatorIdentifierNode *
Demangler::demangleConversionOperatorIdentifier(std::string_view &MangledName) {}

LiteralOperatorIdentifierNode *
Demangler::demangleLiteralOperatorIdentifier(std::string_view &MangledName) {}

IntrinsicFunctionKind
Demangler::translateIntrinsicFunctionCode(char CH,
                                          FunctionIdentifierCodeGroup Group) {}

IdentifierNode *
Demangler::demangleFunctionIdentifierCode(std::string_view &MangledName,
                                          FunctionIdentifierCodeGroup Group) {}

SymbolNode *Demangler::demangleEncodedSymbol(std::string_view &MangledName,
                                             QualifiedNameNode *Name) {}

SymbolNode *Demangler::demangleDeclarator(std::string_view &MangledName) {}

SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) {}

SymbolNode *Demangler::demangleTypeinfoName(std::string_view &MangledName) {}

// Parser entry point.
SymbolNode *Demangler::parse(std::string_view &MangledName) {}

TagTypeNode *Demangler::parseTagUniqueName(std::string_view &MangledName) {}

// <type-encoding> ::= <storage-class> <variable-type>
// <storage-class> ::= 0  # private static member
//                 ::= 1  # protected static member
//                 ::= 2  # public static member
//                 ::= 3  # global
//                 ::= 4  # static local

VariableSymbolNode *
Demangler::demangleVariableEncoding(std::string_view &MangledName,
                                    StorageClass SC) {}

// Sometimes numbers are encoded in mangled symbols. For example,
// "int (*x)[20]" is a valid C type (x is a pointer to an array of
// length 20), so we need some way to embed numbers as part of symbols.
// This function parses it.
//
// <number>               ::= [?] <non-negative integer>
//
// <non-negative integer> ::= <decimal digit> # when 1 <= Number <= 10
//                        ::= <hex digit>+ @  # when Number == 0 or >= 10
//
// <hex-digit>            ::= [A-P]           # A = 0, B = 1, ...
std::pair<uint64_t, bool>
Demangler::demangleNumber(std::string_view &MangledName) {}

uint64_t Demangler::demangleUnsigned(std::string_view &MangledName) {}

int64_t Demangler::demangleSigned(std::string_view &MangledName) {}

// First 10 strings can be referenced by special BackReferences ?0, ?1, ..., ?9.
// Memorize it.
void Demangler::memorizeString(std::string_view S) {}

NamedIdentifierNode *
Demangler::demangleBackRefName(std::string_view &MangledName) {}

void Demangler::memorizeIdentifier(IdentifierNode *Identifier) {}

IdentifierNode *
Demangler::demangleTemplateInstantiationName(std::string_view &MangledName,
                                             NameBackrefBehavior NBB) {}

NamedIdentifierNode *
Demangler::demangleSimpleName(std::string_view &MangledName, bool Memorize) {}

static bool isRebasedHexDigit(char C) {}

static uint8_t rebasedHexDigitToNumber(char C) {}

uint8_t Demangler::demangleCharLiteral(std::string_view &MangledName) {}

wchar_t Demangler::demangleWcharLiteral(std::string_view &MangledName) {}

static void writeHexDigit(char *Buffer, uint8_t Digit) {}

static void outputHex(OutputBuffer &OB, unsigned C) {}

static void outputEscapedChar(OutputBuffer &OB, unsigned C) {}

static unsigned countTrailingNullBytes(const uint8_t *StringBytes, int Length) {}

static unsigned countEmbeddedNulls(const uint8_t *StringBytes,
                                   unsigned Length) {}

// A mangled (non-wide) string literal stores the total length of the string it
// refers to (passed in NumBytes), and it contains up to 32 bytes of actual text
// (passed in StringBytes, NumChars).
static unsigned guessCharByteSize(const uint8_t *StringBytes, unsigned NumChars,
                                  uint64_t NumBytes) {}

static unsigned decodeMultiByteChar(const uint8_t *StringBytes,
                                    unsigned CharIndex, unsigned CharBytes) {}

FunctionSymbolNode *
Demangler::demangleVcallThunkNode(std::string_view &MangledName) {}

EncodedStringLiteralNode *
Demangler::demangleStringLiteral(std::string_view &MangledName) {}

// Returns MangledName's prefix before the first '@', or an error if
// MangledName contains no '@' or the prefix has length 0.
std::string_view Demangler::demangleSimpleString(std::string_view &MangledName,
                                                 bool Memorize) {}

NamedIdentifierNode *
Demangler::demangleAnonymousNamespaceName(std::string_view &MangledName) {}

NamedIdentifierNode *
Demangler::demangleLocallyScopedNamePiece(std::string_view &MangledName) {}

// Parses a type name in the form of A@B@C@@ which represents C::B::A.
QualifiedNameNode *
Demangler::demangleFullyQualifiedTypeName(std::string_view &MangledName) {}

// Parses a symbol name in the form of A@B@C@@ which represents C::B::A.
// Symbol names have slightly different rules regarding what can appear
// so we separate out the implementations for flexibility.
QualifiedNameNode *
Demangler::demangleFullyQualifiedSymbolName(std::string_view &MangledName) {}

IdentifierNode *
Demangler::demangleUnqualifiedTypeName(std::string_view &MangledName,
                                       bool Memorize) {}

IdentifierNode *
Demangler::demangleUnqualifiedSymbolName(std::string_view &MangledName,
                                         NameBackrefBehavior NBB) {}

IdentifierNode *
Demangler::demangleNameScopePiece(std::string_view &MangledName) {}

static NodeArrayNode *nodeListToNodeArray(ArenaAllocator &Arena, NodeList *Head,
                                          size_t Count) {}

QualifiedNameNode *
Demangler::demangleNameScopeChain(std::string_view &MangledName,
                                  IdentifierNode *UnqualifiedName) {}

FuncClass Demangler::demangleFunctionClass(std::string_view &MangledName) {}

CallingConv
Demangler::demangleCallingConvention(std::string_view &MangledName) {}

StorageClass
Demangler::demangleVariableStorageClass(std::string_view &MangledName) {}

std::pair<Qualifiers, bool>
Demangler::demangleQualifiers(std::string_view &MangledName) {}

// <variable-type> ::= <type> <cvr-qualifiers>
//                 ::= <type> <pointee-cvr-qualifiers> # pointers, references
TypeNode *Demangler::demangleType(std::string_view &MangledName,
                                  QualifierMangleMode QMM) {}

bool Demangler::demangleThrowSpecification(std::string_view &MangledName) {}

FunctionSignatureNode *
Demangler::demangleFunctionType(std::string_view &MangledName,
                                bool HasThisQuals) {}

FunctionSymbolNode *
Demangler::demangleFunctionEncoding(std::string_view &MangledName) {}

CustomTypeNode *Demangler::demangleCustomType(std::string_view &MangledName) {}

// Reads a primitive type.
PrimitiveTypeNode *
Demangler::demanglePrimitiveType(std::string_view &MangledName) {}

TagTypeNode *Demangler::demangleClassType(std::string_view &MangledName) {}

// <pointer-type> ::= E? <pointer-cvr-qualifiers> <ext-qualifiers> <type>
//                       # the E is required for 64-bit non-static pointers
PointerTypeNode *Demangler::demanglePointerType(std::string_view &MangledName) {}

PointerTypeNode *
Demangler::demangleMemberPointerType(std::string_view &MangledName) {}

Qualifiers
Demangler::demanglePointerExtQualifiers(std::string_view &MangledName) {}

ArrayTypeNode *Demangler::demangleArrayType(std::string_view &MangledName) {}

// Reads a function's parameters.
NodeArrayNode *
Demangler::demangleFunctionParameterList(std::string_view &MangledName,
                                         bool &IsVariadic) {}

NodeArrayNode *
Demangler::demangleTemplateParameterList(std::string_view &MangledName) {}

void Demangler::dumpBackReferences() {}

char *llvm::microsoftDemangle(std::string_view MangledName, size_t *NMangled,
                              int *Status, MSDemangleFlags Flags) {}