[llvm] f0f2a8b - [Demangle][Rust] Parse inherent implementations
Tomasz Miąsko via llvm-commits
llvm-commits at lists.llvm.org
Sat May 15 14:56:58 PDT 2021
Author: Tomasz Miąsko
Date: 2021-05-15T23:52:25+02:00
New Revision: f0f2a8b21cad8f291908ea411c7b38b8c4c8ee42
URL: https://github.com/llvm/llvm-project/commit/f0f2a8b21cad8f291908ea411c7b38b8c4c8ee42
DIFF: https://github.com/llvm/llvm-project/commit/f0f2a8b21cad8f291908ea411c7b38b8c4c8ee42.diff
LOG: [Demangle][Rust] Parse inherent implementations
Part of https://reviews.llvm.org/D102549
Added:
Modified:
llvm/include/llvm/Demangle/RustDemangle.h
llvm/lib/Demangle/RustDemangle.cpp
llvm/test/Demangle/rust.test
Removed:
################################################################################
diff --git a/llvm/include/llvm/Demangle/RustDemangle.h b/llvm/include/llvm/Demangle/RustDemangle.h
index 8797830cac69..7d575fbd6e29 100644
--- a/llvm/include/llvm/Demangle/RustDemangle.h
+++ b/llvm/include/llvm/Demangle/RustDemangle.h
@@ -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 @@ class Demangler {
private:
void demanglePath();
+ void demangleImplPath();
void demangleGenericArg();
void demangleType();
void demangleConst();
@@ -90,21 +95,21 @@ class Demangler {
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;
diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp
index ebccafcae299..223d815aa4a8 100644
--- a/llvm/lib/Demangle/RustDemangle.cpp
+++ b/llvm/lib/Demangle/RustDemangle.cpp
@@ -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>
diff --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test
index 89eda8ff1ebf..c1ba4774faa5 100644
--- a/llvm/test/Demangle/rust.test
+++ b/llvm/test/Demangle/rust.test
@@ -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::<_>
More information about the llvm-commits
mailing list