1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[Demangle][Rust] Parse inherent implementations

Part of https://reviews.llvm.org/D102549
This commit is contained in:
Tomasz Miąsko 2021-05-15 23:24:16 +02:00
parent ee05e77f81
commit 160e922bf8
3 changed files with 32 additions and 3 deletions

View File

@ -63,6 +63,10 @@ class Demangler {
// Position in the input string.
size_t Position;
// When true, print methods append the output to the stream.
// When false, the output is suppressed.
bool Print;
// True if an error occurred.
bool Error;
@ -76,6 +80,7 @@ public:
private:
void demanglePath();
void demangleImplPath();
void demangleGenericArg();
void demangleType();
void demangleConst();
@ -90,21 +95,21 @@ private:
uint64_t parseHexNumber(StringView &HexDigits);
void print(char C) {
if (Error)
if (Error || !Print)
return;
Output += C;
}
void print(StringView S) {
if (Error)
if (Error || !Print)
return;
Output += S;
}
void printDecimalNumber(uint64_t N) {
if (Error)
if (Error || !Print)
return;
Output << N;

View File

@ -101,6 +101,7 @@ static inline bool isValid(const char C) {
bool Demangler::demangle(StringView Mangled) {
Position = 0;
Error = false;
Print = true;
RecursionLevel = 0;
if (!Mangled.consumeFront("_R")) {
@ -145,6 +146,13 @@ void Demangler::demanglePath() {
print(Ident.Name);
break;
}
case 'M': {
demangleImplPath();
print("<");
demangleType();
print(">");
break;
}
case 'N': {
char NS = consume();
if (!isLower(NS) && !isUpper(NS)) {
@ -199,6 +207,14 @@ void Demangler::demanglePath() {
}
}
// <impl-path> = [<disambiguator>] <path>
// <disambiguator> = "s" <base-62-number>
void Demangler::demangleImplPath() {
SwapAndRestore<bool> SavePrint(Print, false);
parseOptionalBase62Number('s');
demanglePath();
}
// <generic-arg> = <lifetime>
// | <type>
// | "K" <const>

View File

@ -33,6 +33,14 @@ CHECK: crate::{shim:reify#0}
CHECK: crate::{Z:ident#10}
_RNZC5crates8_5ident
; Inherent impl
CHECK: <_>
_RMC5cratep
CHECK: <_>
_RMs_C5cratep
; Generic type arguments
CHECK: generic::<_>