[PATCH] D103459: [Demangle][Rust] Parse path backreferences

Tomasz Miąsko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 7 15:00:39 PDT 2021


tmiasko updated this revision to Diff 350425.
tmiasko retitled this revision from "[Demangle][Rust] Parse backreferences" to "[Demangle][Rust] Parse path backreferences".
tmiasko added a comment.

Parse path backreferences


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103459/new/

https://reviews.llvm.org/D103459

Files:
  llvm/include/llvm/Demangle/RustDemangle.h
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/test/Demangle/rust.test


Index: llvm/test/Demangle/rust.test
===================================================================
--- llvm/test/Demangle/rust.test
+++ llvm/test/Demangle/rust.test
@@ -420,6 +420,22 @@
 CHECK: _RIC4charKc1234567_E
        _RIC4charKc1234567_E
 
+; Backreferences
+
+CHECK: backref::<backref::ident>
+       _RIC7backrefNvB0_5identE
+
+; Invalid backreferences
+
+CHECK: _RB_
+       _RB_
+
+CHECK: _RB5_
+       _RB5_
+
+CHECK: _RNvB_1a
+       _RNvB_1a
+
 ; Invalid mangled characters
 
 CHECK: _RNvC2a.1c
Index: llvm/lib/Demangle/RustDemangle.cpp
===================================================================
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -232,8 +232,12 @@
       print(">");
     break;
   }
+  case 'B': {
+    bool IsOpen = false;
+    demangleBackref([&] { IsOpen = demanglePath(InType, LeaveOpen); });
+    return IsOpen;
+  }
   default:
-    // FIXME parse remaining productions.
     Error = true;
     break;
   }
Index: llvm/include/llvm/Demangle/RustDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/RustDemangle.h
+++ llvm/include/llvm/Demangle/RustDemangle.h
@@ -102,6 +102,21 @@
   void demangleConstBool();
   void demangleConstChar();
 
+  template <typename Callable> void demangleBackref(Callable Demangler) {
+    uint64_t Backref = parseBase62Number();
+    if (Error || Backref >= Position) {
+      Error = true;
+      return;
+    }
+
+    if (!Print)
+      return;
+
+    SwapAndRestore<size_t> SavePosition(Position, Position);
+    Position = Backref;
+    Demangler();
+  }
+
   Identifier parseIdentifier();
   uint64_t parseOptionalBase62Number(char Tag);
   uint64_t parseBase62Number();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103459.350425.patch
Type: text/x-patch
Size: 1745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210607/2dc443e0/attachment.bin>


More information about the llvm-commits mailing list