This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH for demangler
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH for demangler
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Tue, 19 Oct 1999 10:59:16 -0700
- Organization: CodeSourcery, LLC
This is the demangler patch required to handle the minor change just
made to the G++ mangling scheme.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-10-19 Mark Mitchell <mark@codesourcery.com>
* cplus-dem.c (INTBUF_SIZE): New macro.
(string_append_template_idx): New function.
(demangle_expression): Likewise.
(demangle_integral_value): Use it.
(demangle_real_value): New function, split out from ...
(demangle_template_value_parm): ... here. Use
string_append_template_idx. Use demangle_real_value.
(demangle_template): Use string_append_template_idx.
(demangle_qualified): Use consume_count_with_underscores.
(get_count): Tweak formatting.
(do_type): Use string_append_template_idx.
Index: testsuite/demangle-expected
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/testsuite/demangle-expected,v
retrieving revision 1.3
diff -c -p -r1.3 demangle-expected
*** demangle-expected 1999/10/11 08:32:10 1.3
--- demangle-expected 1999/10/19 17:50:49
*************** C<Test, Test::output> call<Test>(Test &)
*** 2474,2476 ****
--- 2474,2488 ----
--format=gnu
fn__FPQ21n1cPMQ21n1cFPQ21n1c_i
fn(n::c *, int (n::c::*)(n::c *))
+ #
+ --format=gnu
+ f__FGt3Bar1i21i
+ f(Bar<2>, i)
+ #
+ --format=gnu
+ f__FGt3Bar1i_21_i
+ f(Bar<21>, int)
+ #
+ --format=gnu
+ f__FGt3Bar1i24XY_t
+ f(Bar<2>, XY_t)
Index: cplus-dem.c
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/cplus-dem.c,v
retrieving revision 1.50
diff -c -p -r1.50 cplus-dem.c
*** cplus-dem.c 1999/10/11 08:32:10 1.50
--- cplus-dem.c 1999/10/19 17:50:48
*************** char * realloc ();
*** 53,58 ****
--- 53,62 ----
#define min(X,Y) (((X) < (Y)) ? (X) : (Y))
+ /* A value at least one greater than the maximum number of characters
+ that will be output when using the `%d' format with `printf'. */
+ #define INTBUF_SIZE 32
+
extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;
static const char *mystrstr PARAMS ((const char *, const char *));
*************** string_prepend PARAMS ((string *, const
*** 347,352 ****
--- 351,359 ----
static void
string_prependn PARAMS ((string *, const char *, int));
+ static void
+ string_append_template_idx PARAMS ((string *, int));
+
static int
get_count PARAMS ((const char **, int *));
*************** static const char*
*** 425,433 ****
--- 432,447 ----
demangle_qualifier PARAMS ((int));
static int
+ demangle_expression PARAMS ((struct work_stuff *, const char **, string *,
+ type_kind_t));
+
+ static int
demangle_integral_value PARAMS ((struct work_stuff *, const char **,
string *));
+ static int
+ demangle_real_value PARAMS ((struct work_stuff *, const char **, string *));
+
static void
demangle_arm_hp_template PARAMS ((struct work_stuff *, const char **, int,
string *));
*************** demangle_template_template_parm (work, m
*** 1348,1434 ****
}
static int
! demangle_integral_value (work, mangled, s)
struct work_stuff *work;
const char** mangled;
string* s;
{
int success;
! if (**mangled == 'E')
{
! int need_operator = 0;
!
! success = 1;
! string_appendn (s, "(", 1);
! (*mangled)++;
! while (success && **mangled != 'W' && **mangled != '\0')
{
! if (need_operator)
! {
! size_t i;
! size_t len;
! success = 0;
! len = strlen (*mangled);
! for (i = 0;
! i < sizeof (optable) / sizeof (optable [0]);
! ++i)
! {
! size_t l = strlen (optable[i].in);
! if (l <= len
! && memcmp (optable[i].in, *mangled, l) == 0)
! {
! string_appendn (s, " ", 1);
! string_append (s, optable[i].out);
! string_appendn (s, " ", 1);
! success = 1;
! (*mangled) += l;
! break;
! }
}
-
- if (!success)
- break;
}
- else
- need_operator = 1;
! success = demangle_template_value_parm (work, mangled, s,
! tk_integral);
}
-
- if (**mangled != 'W')
- success = 0;
else
! {
! string_appendn (s, ")", 1);
! (*mangled)++;
! }
}
else if (**mangled == 'Q' || **mangled == 'K')
success = demangle_qualified (work, mangled, s, 0, 1);
else
{
success = 0;
if (**mangled == 'm')
{
string_appendn (s, "-", 1);
(*mangled)++;
}
while (isdigit ((unsigned char)**mangled))
{
string_appendn (s, *mangled, 1);
(*mangled)++;
- success = 1;
}
}
! return success;
}
static int
--- 1362,1516 ----
}
static int
! demangle_expression (work, mangled, s, tk)
struct work_stuff *work;
const char** mangled;
string* s;
+ type_kind_t tk;
{
+ int need_operator = 0;
int success;
! success = 1;
! string_appendn (s, "(", 1);
! (*mangled)++;
! while (success && **mangled != 'W' && **mangled != '\0')
{
! if (need_operator)
{
! size_t i;
! size_t len;
! success = 0;
! len = strlen (*mangled);
! for (i = 0;
! i < sizeof (optable) / sizeof (optable [0]);
! ++i)
! {
! size_t l = strlen (optable[i].in);
! if (l <= len
! && memcmp (optable[i].in, *mangled, l) == 0)
! {
! string_appendn (s, " ", 1);
! string_append (s, optable[i].out);
! string_appendn (s, " ", 1);
! success = 1;
! (*mangled) += l;
! break;
}
}
! if (!success)
! break;
}
else
! need_operator = 1;
!
! success = demangle_template_value_parm (work, mangled, s, tk);
! }
!
! if (**mangled != 'W')
! success = 0;
! else
! {
! string_appendn (s, ")", 1);
! (*mangled)++;
}
+
+ return success;
+ }
+
+ static int
+ demangle_integral_value (work, mangled, s)
+ struct work_stuff *work;
+ const char** mangled;
+ string* s;
+ {
+ int success;
+
+ if (**mangled == 'E')
+ success = demangle_expression (work, mangled, s, tk_integral);
else if (**mangled == 'Q' || **mangled == 'K')
success = demangle_qualified (work, mangled, s, 0, 1);
else
{
+ int value;
+
success = 0;
+ /* Negative numbers are indicated with a leading `m'. */
if (**mangled == 'm')
{
string_appendn (s, "-", 1);
(*mangled)++;
}
+
+ /* Read the rest of the number. */
+ value = consume_count_with_underscores (mangled);
+ if (value != -1)
+ {
+ char buf[INTBUF_SIZE];
+ sprintf (buf, "%d", value);
+ string_append (s, buf);
+
+ /* If the next character is an underscore, skip it. */
+ if (**mangled == '_')
+ (*mangled)++;
+
+ /* All is well. */
+ success = 1;
+ }
+ }
+
+ return success;
+ }
+
+ /* Demangle the real value in MANGLED. */
+
+ static int
+ demangle_real_value (work, mangled, s)
+ struct work_stuff *work;
+ const char **mangled;
+ string* s;
+ {
+ if (**mangled == 'E')
+ return demangle_expression (work, mangled, s, tk_real);
+
+ if (**mangled == 'm')
+ {
+ string_appendn (s, "-", 1);
+ (*mangled)++;
+ }
+ while (isdigit ((unsigned char)**mangled))
+ {
+ string_appendn (s, *mangled, 1);
+ (*mangled)++;
+ }
+ if (**mangled == '.') /* fraction */
+ {
+ string_appendn (s, ".", 1);
+ (*mangled)++;
+ while (isdigit ((unsigned char)**mangled))
+ {
+ string_appendn (s, *mangled, 1);
+ (*mangled)++;
+ }
+ }
+ if (**mangled == 'e') /* exponent */
+ {
+ string_appendn (s, "e", 1);
+ (*mangled)++;
while (isdigit ((unsigned char)**mangled))
{
string_appendn (s, *mangled, 1);
(*mangled)++;
}
}
! return 1;
}
static int
*************** demangle_template_value_parm (work, mang
*** 1454,1464 ****
if (work->tmpl_argvec)
string_append (s, work->tmpl_argvec[idx]);
else
! {
! char buf[10];
! sprintf(buf, "T%d", idx);
! string_append (s, buf);
! }
}
else if (tk == tk_integral)
success = demangle_integral_value (work, mangled, s);
--- 1536,1542 ----
if (work->tmpl_argvec)
string_append (s, work->tmpl_argvec[idx]);
else
! string_append_template_idx (s, idx);
}
else if (tk == tk_integral)
success = demangle_integral_value (work, mangled, s);
*************** demangle_template_value_parm (work, mang
*** 1494,1531 ****
success = 0;
}
else if (tk == tk_real)
! {
! if (**mangled == 'm')
! {
! string_appendn (s, "-", 1);
! (*mangled)++;
! }
! while (isdigit ((unsigned char)**mangled))
! {
! string_appendn (s, *mangled, 1);
! (*mangled)++;
! }
! if (**mangled == '.') /* fraction */
! {
! string_appendn (s, ".", 1);
! (*mangled)++;
! while (isdigit ((unsigned char)**mangled))
! {
! string_appendn (s, *mangled, 1);
! (*mangled)++;
! }
! }
! if (**mangled == 'e') /* exponent */
! {
! string_appendn (s, "e", 1);
! (*mangled)++;
! while (isdigit ((unsigned char)**mangled))
! {
! string_appendn (s, *mangled, 1);
! (*mangled)++;
! }
! }
! }
else if (tk == tk_pointer || tk == tk_reference)
{
if (**mangled == 'Q')
--- 1572,1578 ----
success = 0;
}
else if (tk == tk_real)
! success = demangle_real_value (work, mangled, s);
else if (tk == tk_pointer || tk == tk_reference)
{
if (**mangled == 'Q')
*************** demangle_template (work, mangled, tname,
*** 1623,1633 ****
}
else
{
! char buf[10];
! sprintf(buf, "T%d", idx);
! string_append (tname, buf);
if (trawname)
! string_append (trawname, buf);
}
}
else
--- 1670,1678 ----
}
else
{
! string_append_template_idx (tname, idx);
if (trawname)
! string_append_template_idx (trawname, idx);
}
}
else
*************** demangle_qualified (work, mangled, resul
*** 2696,2702 ****
{
int qualifiers = 0;
int success = 1;
- const char *p;
char num[2];
string temp;
string last_name;
--- 2741,2746 ----
*************** demangle_qualified (work, mangled, resul
*** 2728,2746 ****
/* GNU mangled name with more than 9 classes. The count is preceded
by an underscore (to distinguish it from the <= 9 case) and followed
by an underscore. */
! p = *mangled + 2;
! qualifiers = atoi (p);
! if (!isdigit ((unsigned char)*p) || *p == '0')
! success = 0;
!
! /* Skip the digits. */
! while (isdigit ((unsigned char)*p))
! ++p;
!
! if (*p != '_')
success = 0;
-
- *mangled = p + 1;
break;
case '1':
--- 2772,2781 ----
/* GNU mangled name with more than 9 classes. The count is preceded
by an underscore (to distinguish it from the <= 9 case) and followed
by an underscore. */
! (*mangled)++;
! qualifiers = consume_count_with_underscores (mangled);
! if (qualifiers == -1)
success = 0;
break;
case '1':
*************** get_count (type, count)
*** 2931,2939 ****
int n;
if (!isdigit ((unsigned char)**type))
! {
! return (0);
! }
else
{
*count = **type - '0';
--- 2966,2972 ----
int n;
if (!isdigit ((unsigned char)**type))
! return (0);
else
{
*count = **type - '0';
*************** do_type (work, mangled, result)
*** 3230,3240 ****
if (work->tmpl_argvec)
string_append (result, work->tmpl_argvec[idx]);
else
! {
! char buf[10];
! sprintf(buf, "T%d", idx);
! string_append (result, buf);
! }
success = 1;
}
--- 3263,3269 ----
if (work->tmpl_argvec)
string_append (result, work->tmpl_argvec[idx]);
else
! string_append_template_idx (result, idx);
success = 1;
}
*************** string_prependn (p, s, n)
*** 4351,4356 ****
--- 4380,4395 ----
memcpy (p->b, s, n);
p->p += n;
}
+ }
+
+ static void
+ string_append_template_idx (s, idx)
+ string *s;
+ int idx;
+ {
+ char buf[INTBUF_SIZE + 1 /* 'T' */];
+ sprintf(buf, "T%d", idx);
+ string_append (s, buf);
}
/* To generate a standalone demangler program for testing purposes,