aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/RustDemangle.cpp
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2021-05-22 11:36:59 +0200
committerTomasz Miąsko <tomasz.miasko@gmail.com>2021-05-22 11:49:08 +0200
commit75cc1cf0181a78d1e79c96b5d318f58a72050939 (patch)
tree566c6ed620e7c77bef3805373002686d4341f824 /llvm/lib/Demangle/RustDemangle.cpp
parente4fa6c95aca1555167f867a0205cbc99caa2ce09 (diff)
downloadllvm-75cc1cf0181a78d1e79c96b5d318f58a72050939.zip
llvm-75cc1cf0181a78d1e79c96b5d318f58a72050939.tar.gz
llvm-75cc1cf0181a78d1e79c96b5d318f58a72050939.tar.bz2
[Demangle][Rust] Parse function signatures
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102581
Diffstat (limited to 'llvm/lib/Demangle/RustDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/RustDemangle.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp
index 8d43b6e..d81ee33 100644
--- a/llvm/lib/Demangle/RustDemangle.cpp
+++ b/llvm/lib/Demangle/RustDemangle.cpp
@@ -472,6 +472,9 @@ void Demangler::demangleType() {
print("*mut ");
demangleType();
break;
+ case 'F':
+ demangleFnSig();
+ break;
default:
Position = Start;
demanglePath(rust_demangle::InType::Yes);
@@ -479,6 +482,47 @@ void Demangler::demangleType() {
}
}
+// <fn-sig> := [<binder>] ["U"] ["K" <abi>] {<type>} "E" <type>
+// <abi> = "C"
+// | <undisambiguated-identifier>
+void Demangler::demangleFnSig() {
+ // FIXME demangle binder.
+
+ if (consumeIf('U'))
+ print("unsafe ");
+
+ if (consumeIf('K')) {
+ print("extern \"");
+ if (consumeIf('C')) {
+ print("C");
+ } else {
+ Identifier Ident = parseIdentifier();
+ for (char C : Ident.Name) {
+ // When mangling ABI string, the "-" is replaced with "_".
+ if (C == '_')
+ C = '-';
+ print(C);
+ }
+ }
+ print("\" ");
+ }
+
+ print("fn(");
+ for (size_t I = 0; !Error && !consumeIf('E'); ++I) {
+ if (I > 0)
+ print(", ");
+ demangleType();
+ }
+ print(")");
+
+ if (consumeIf('u')) {
+ // Skip the unit type from the output.
+ } else {
+ print(" -> ");
+ demangleType();
+ }
+}
+
// <const> = <basic-type> <const-data>
// | "p" // placeholder
// | <backref>