Skip to content

Commit

Permalink
[PATCH] Refactor rust-demangle to be independent of C++ demangling.
Browse files Browse the repository at this point in the history
	* demangle.h (rust_demangle_callback): Add.

	* cplus-dem.c (cplus_demangle): Use rust_demangle directly.
	(rust_demangle): Remove.
	* rust-demangle.c (is_prefixed_hash): Rename to is_legacy_prefixed_hash.
	(parse_lower_hex_nibble): Rename to decode_lower_hex_nibble.
	(parse_legacy_escape): Rename to decode_legacy_escape.
	(rust_is_mangled): Remove.
	(struct rust_demangler): Add.
	(peek): Add.
	(next): Add.
	(struct rust_mangled_ident): Add.
	(parse_ident): Add.
	(rust_demangle_sym): Remove.
	(print_str): Add.
	(PRINT): Add.
	(print_ident): Add.
	(rust_demangle_callback): Add.
	(struct str_buf): Add.
	(str_buf_reserve): Add.
	(str_buf_append): Add.
	(str_buf_demangle_callback): Add.
	(rust_demangle): Add.
	* rust-demangle.h: Remove.

From-SVN: r278358
  • Loading branch information
eddyb authored and Jeff Law committed Nov 16, 2019
1 parent f73cb38 commit 32fc371
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 266 deletions.
4 changes: 4 additions & 0 deletions include/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2019-10-22 Eduard-Mihai Burtescu <eddyb@lyken.rs>

* demangle.h (rust_demangle_callback): Add.

2019-11-13 Andrew Stubbs <ams@codesourcery.com>
Kwok Cheung Yeung <kcy@codesourcery.com>
Julian Brown <julian@codesourcery.com>
Expand Down
5 changes: 5 additions & 0 deletions include/demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ ada_demangle (const char *mangled, int options);
extern char *
dlang_demangle (const char *mangled, int options);

extern int
rust_demangle_callback (const char *mangled, int options,
demangle_callbackref callback, void *opaque);


extern char *
rust_demangle (const char *mangled, int options);

Expand Down
25 changes: 25 additions & 0 deletions libiberty/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
2019-10-22 Eduard-Mihai Burtescu <eddyb@lyken.rs>

* cplus-dem.c (cplus_demangle): Use rust_demangle directly.
(rust_demangle): Remove.
* rust-demangle.c (is_prefixed_hash): Rename to is_legacy_prefixed_hash.
(parse_lower_hex_nibble): Rename to decode_lower_hex_nibble.
(parse_legacy_escape): Rename to decode_legacy_escape.
(rust_is_mangled): Remove.
(struct rust_demangler): Add.
(peek): Add.
(next): Add.
(struct rust_mangled_ident): Add.
(parse_ident): Add.
(rust_demangle_sym): Remove.
(print_str): Add.
(PRINT): Add.
(print_ident): Add.
(rust_demangle_callback): Add.
(struct str_buf): Add.
(str_buf_reserve): Add.
(str_buf_append): Add.
(str_buf_demangle_callback): Add.
(rust_demangle): Add.
* rust-demangle.h: Remove.

2019-11-15 Miguel Saldivar <saldivarcher@gmail.com>

* testsuite/demangle-expected: Fix test.
Expand Down
51 changes: 11 additions & 40 deletions libiberty/cplus-dem.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void * realloc ();
#define CURRENT_DEMANGLING_STYLE options

#include "libiberty.h"
#include "rust-demangle.h"

enum demangling_styles current_demangling_style = auto_demangling;

Expand Down Expand Up @@ -160,27 +159,20 @@ cplus_demangle (const char *mangled, int options)
if ((options & DMGL_STYLE_MASK) == 0)
options |= (int) current_demangling_style & DMGL_STYLE_MASK;

/* The Rust demangling is implemented elsewhere.
Legacy Rust symbols overlap with GNU_V3, so try Rust first. */
if (RUST_DEMANGLING || AUTO_DEMANGLING)
{
ret = rust_demangle (mangled, options);
if (ret || RUST_DEMANGLING)
return ret;
}

/* The V3 ABI demangling is implemented elsewhere. */
if (GNU_V3_DEMANGLING || RUST_DEMANGLING || AUTO_DEMANGLING)
if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
{
ret = cplus_demangle_v3 (mangled, options);
if (GNU_V3_DEMANGLING)
return ret;

if (ret)
{
/* Rust symbols are GNU_V3 mangled plus some extra subtitutions.
The subtitutions are always smaller, so do in place changes. */
if (rust_is_mangled (ret))
rust_demangle_sym (ret);
else if (RUST_DEMANGLING)
{
free (ret);
ret = NULL;
}
}

if (ret || RUST_DEMANGLING)
if (ret || GNU_V3_DEMANGLING)
return ret;
}

Expand All @@ -204,27 +196,6 @@ cplus_demangle (const char *mangled, int options)
return (ret);
}

char *
rust_demangle (const char *mangled, int options)
{
/* Rust symbols are GNU_V3 mangled plus some extra subtitutions. */
char *ret = cplus_demangle_v3 (mangled, options);

/* The Rust subtitutions are always smaller, so do in place changes. */
if (ret != NULL)
{
if (rust_is_mangled (ret))
rust_demangle_sym (ret);
else
{
free (ret);
ret = NULL;
}
}

return ret;
}

/* Demangle ada names. The encoding is documented in gcc/ada/exp_dbug.ads. */

char *
Expand Down
Loading

0 comments on commit 32fc371

Please sign in to comment.