Commit 4b9a55fd by Chris Mihelich Committed by Copybara-Service

Decode Rust Punycode when it's not too long.

PiperOrigin-RevId: 647340145
Change-Id: I4b0076595dbda1f81ffdc32adad2dc1e35cb9e04
parent 0ccc51f9
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/debugging/internal/decode_rust_punycode.h"
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
...@@ -710,13 +711,19 @@ class RustSymbolParser { ...@@ -710,13 +711,19 @@ class RustSymbolParser {
int num_bytes = 0; int num_bytes = 0;
if (!ParseDecimalNumber(num_bytes)) return false; if (!ParseDecimalNumber(num_bytes)) return false;
(void)Eat('_'); // optional separator, needed if a digit follows (void)Eat('_'); // optional separator, needed if a digit follows
if (is_punycoded) {
DecodeRustPunycodeOptions options;
options.punycode_begin = &encoding_[pos_];
options.punycode_end = &encoding_[pos_] + num_bytes;
options.out_begin = out_;
options.out_end = out_end_;
out_ = DecodeRustPunycode(options);
if (out_ == nullptr) return false;
pos_ += static_cast<size_t>(num_bytes);
}
// Emit the beginnings of braced forms like {shim:vtable#0}. // Emit the beginnings of braced forms like {shim:vtable#0}.
if (uppercase_namespace == '\0') { if (uppercase_namespace != '\0') {
// Decoding of Punycode is not yet implemented. For now we emit
// "{Punycode ...}" with the raw encoding inside.
if (is_punycoded && !Emit("{Punycode ")) return false;
} else {
switch (uppercase_namespace) { switch (uppercase_namespace) {
case 'C': case 'C':
if (!Emit("{closure")) return false; if (!Emit("{closure")) return false;
...@@ -732,24 +739,24 @@ class RustSymbolParser { ...@@ -732,24 +739,24 @@ class RustSymbolParser {
} }
// Emit the name itself. // Emit the name itself.
if (!is_punycoded) {
for (int i = 0; i < num_bytes; ++i) { for (int i = 0; i < num_bytes; ++i) {
const char c = Take(); const char c = Take();
if (!IsIdentifierChar(c) && if (!IsIdentifierChar(c) &&
// The spec gives toolchains the choice of Punycode or raw UTF-8 for // The spec gives toolchains the choice of Punycode or raw UTF-8 for
// identifiers containing code points above 0x7f, so accept bytes with // identifiers containing code points above 0x7f, so accept bytes
// the high bit set if this is not a u... encoding. // with the high bit set.
(is_punycoded || (c & 0x80) == 0)) { (c & 0x80) == 0) {
return false; return false;
} }
if (!EmitChar(c)) return false; if (!EmitChar(c)) return false;
} }
}
// Emit the endings of braced forms: "#42}" or "}". // Emit the endings of braced forms, e.g., "#42}".
if (uppercase_namespace != '\0') { if (uppercase_namespace != '\0') {
if (!EmitChar('#')) return false; if (!EmitChar('#')) return false;
if (!EmitDisambiguator(disambiguator)) return false; if (!EmitDisambiguator(disambiguator)) return false;
}
if (uppercase_namespace != '\0' || is_punycoded) {
if (!EmitChar('}')) return false; if (!EmitChar('}')) return false;
} }
......
...@@ -117,7 +117,7 @@ TEST(DemangleRust, UnicodeIdentifiers) { ...@@ -117,7 +117,7 @@ TEST(DemangleRust, UnicodeIdentifiers) {
EXPECT_DEMANGLING("_RNvC7ice_cap17Eyjafjallajökull", EXPECT_DEMANGLING("_RNvC7ice_cap17Eyjafjallajökull",
"ice_cap::Eyjafjallajökull"); "ice_cap::Eyjafjallajökull");
EXPECT_DEMANGLING("_RNvC7ice_caps_u19Eyjafjallajkull_jtb", EXPECT_DEMANGLING("_RNvC7ice_caps_u19Eyjafjallajkull_jtb",
"ice_cap::{Punycode Eyjafjallajkull_jtb}"); "ice_cap::Eyjafjallajökull");
} }
TEST(DemangleRust, FunctionInModule) { TEST(DemangleRust, FunctionInModule) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment