public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7915] gccrs: Fix legacy mangling to use Unicode escape
@ 2024-01-16 18:06 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:007940b753784aa4bd4b6bcd84b1dacb1237c055

commit r14-7915-g007940b753784aa4bd4b6bcd84b1dacb1237c055
Author: Raiki Tamura <tamaron1203@gmail.com>
Date:   Sat Aug 12 16:16:53 2023 +0900

    gccrs: Fix legacy mangling to use Unicode escape
    
    gcc/rust/ChangeLog:
    
            * backend/rust-mangle.cc (legacy_mangle_name): Use Unicode escape
    
    Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>

Diff:
---
 gcc/rust/backend/rust-mangle.cc | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc
index 8a1a73c3264..eed9c75d96e 100644
--- a/gcc/rust/backend/rust-mangle.cc
+++ b/gcc/rust/backend/rust-mangle.cc
@@ -1,6 +1,8 @@
 #include "rust-mangle.h"
 #include "fnv-hash.h"
 #include "rust-base62.h"
+#include "rust-unicode.h"
+#include "optional.h"
 
 // FIXME: Rename those to legacy_*
 static const std::string kMangledSymbolPrefix = "_ZN";
@@ -46,11 +48,15 @@ legacy_mangle_name (const std::string &name)
   // <example::Identity as example::FnLike<&T,&T>>::call
   // _ZN74_$LT$example..Identity$u20$as$u20$example..FnLike$LT$$RF$T$C$$RF$T$GT$$GT$4call17ha9ee58935895acb3E
 
+  tl::optional<Utf8String> utf8_name = Utf8String::make_utf8_string (name);
+  if (!utf8_name.has_value ())
+    rust_unreachable ();
+  std::vector<Codepoint> chars = utf8_name.value ().get_chars ();
   std::string buffer;
-  for (size_t i = 0; i < name.size (); i++)
+  for (size_t i = 0; i < chars.size (); i++)
     {
       std::string m;
-      char c = name.at (i);
+      Codepoint c = chars.at (i);
 
       if (c == ' ')
 	m = kMangledSpace;
@@ -76,14 +82,21 @@ legacy_mangle_name (const std::string &name)
 	m = kMangledComma;
       else if (c == ':')
 	{
-	  rust_assert (i + 1 < name.size ());
-	  rust_assert (name.at (i + 1) == ':');
+	  rust_assert (i + 1 < chars.size ());
+	  rust_assert (chars.at (i + 1) == ':');
 	  i++;
 	  m = "..";
 	}
+      else if (c.value < 0x80)
+	// ASCII
+	m.push_back (c.value);
       else
-	m.push_back (c);
-
+	{
+	  // Non-ASCII
+	  std::stringstream escaped;
+	  escaped << std::hex << "$u" << c.value << "$";
+	  m += escaped.str ();
+	}
       buffer += m;
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16 18:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:06 [gcc r14-7915] gccrs: Fix legacy mangling to use Unicode escape Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).