Patch for demangling Java identifiers which are C++ keywords
Ian Lance Taylor
ian@wasabisystems.com
Sat Dec 20 17:42:00 GMT 2003
When the current Java compiler mangles a name which happens to be a
C++ keyword, it adds a '$' after the identifier. However, that '$' is
not counted in the identifier length in the mangled name. So the
demangler needs to handle it specially. This patch permits the
demangler to demangle this sort of name.
As a side note, my guess is that adding the '$' is intended to make it
possible for Java routines to be implemented in C++. The C++ code
would simply append a '$' to the keyword, in order to be able to use
it in C++. Unfortunately, this won't work, because the C++ mangler
will count the '$' in the identifier length, unlike the Java mangler.
So if my guess about the intention is correct, then this is actually a
bug in the Java mangler. If the Java mangler is fixed to count the
'$' in the identifier length, then the patch below will only be needed
for older code. It will do no harm for newer code, except that in
extremely unusual situations it will demangle a symbol name which is
not actually a mangled name.
I am about to check in this patch.
Ian
2003-12-20 Ian Lance Taylor <ian@wasabisystems.com>
* cp-demangle.c (d_identifier): In Java mode, skip an optional '$'
after the identifier.
* testsuite/demangle-expected: Add test case.
Index: cp-demangle.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/cp-demangle.c,v
retrieving revision 1.61
diff -u -p -r1.61 cp-demangle.c
--- cp-demangle.c 19 Dec 2003 21:14:34 -0000 1.61
+++ cp-demangle.c 20 Dec 2003 15:46:07 -0000
@@ -1341,6 +1341,13 @@ d_identifier (di, len)
name = d_str (di);
d_advance (di, len);
+ /* A Java mangled name may have a trailing '$' if it is a C++
+ keyword. This '$' is not included in the length count. We just
+ ignore the '$'. */
+ if ((di->options & DMGL_JAVA) != 0
+ && d_peek_char (di) == '$')
+ d_advance (di, 1);
+
/* Look for something which looks like a gcc encoding of an
anonymous namespace, and replace it with a more user friendly
name. */
Index: testsuite/demangle-expected
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/testsuite/demangle-expected,v
retrieving revision 1.25
diff -u -p -r1.25 demangle-expected
--- testsuite/demangle-expected 19 Dec 2003 21:14:35 -0000 1.25
+++ testsuite/demangle-expected 20 Dec 2003 15:46:07 -0000
@@ -2591,6 +2591,10 @@ Prim.i(int, boolean, byte, double, float
_ZN4java4util14Map__U24_Entry11class__U24_E
java.util.Map$Entry.class$
#
+--format=java
+_ZN3org7eclipse3cdt5debug8internal4core5model9CVariable6sizeof$Ev
+org.eclipse.cdt.debug.internal.core.model.CVariable.sizeof()
+#
--format=hp
_Utf58_0_1__1_2147483647__2147483648
_Utf58_0_1__1_2147483647__2147483648
More information about the Gcc-patches
mailing list