#include "libiberty.h"
+#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 *));
static const char *
tk_real
} type_kind_t;
+struct demangler_engine libiberty_demanglers[] =
+{
+ {
+ AUTO_DEMANGLING_STYLE_STRING,
+ auto_demangling,
+ "Automatic selection based on executable"
+ }
+ ,
+ {
+ GNU_DEMANGLING_STYLE_STRING,
+ gnu_demangling,
+ "GNU (g++) style demangling"
+ }
+ ,
+ {
+ LUCID_DEMANGLING_STYLE_STRING,
+ lucid_demangling,
+ "Lucid (lcc) style demangling"
+ }
+ ,
+ {
+ ARM_DEMANGLING_STYLE_STRING,
+ arm_demangling,
+ "ARM style demangling"
+ }
+ ,
+ {
+ HP_DEMANGLING_STYLE_STRING,
+ hp_demangling,
+ "HP (aCC) style demangling"
+ }
+ ,
+ {
+ EDG_DEMANGLING_STYLE_STRING,
+ edg_demangling,
+ "EDG style demangling"
+ }
+ ,
+ {
+ GNU_NEW_ABI_DEMANGLING_STYLE_STRING,
+ gnu_new_abi_demangling,
+ "GNU (g++) new-ABI-style demangling"
+ }
+ ,
+ {
+ NULL, unknown_demangling, NULL
+ }
+};
+
#define STRING_EMPTY(str) ((str) -> b == (str) -> p)
#define PREPEND_BLANK(str) {if (!STRING_EMPTY(str)) \
string_prepend(str, " ");}
/* Prototypes for local functions */
+static void
+delete_work_stuff PARAMS ((struct work_stuff *));
+
+static void
+delete_non_B_K_work_stuff PARAMS ((struct work_stuff *));
+
static char *
mop_up PARAMS ((struct work_stuff *, string *, int));
static void
squangle_mop_up PARAMS ((struct work_stuff *));
+static void
+work_stuff_copy_to_from PARAMS ((struct work_stuff *, struct work_stuff *));
+
#if 0
static int
demangle_method_args PARAMS ((struct work_stuff *, const char **, string *));
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 *));
demangle_function_name PARAMS ((struct work_stuff *, const char **, string *,
const char *));
+static int
+iterate_demangle_function PARAMS ((struct work_stuff *,
+ const char **, string *, const char *));
+
static void
remember_type PARAMS ((struct work_stuff *, const char *, int));
static const char*
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 *));
+
+static void
+recursively_demangle PARAMS ((struct work_stuff *, const char **, string *,
+ int));
+
/* Translate count to integer, consuming tokens in the process.
Conversion terminates on the first non-digit character.
}
}
else if (opname[0] == '_' && opname[1] == '_'
- && opname[2] >= 'a' && opname[2] <= 'z'
- && opname[3] >= 'a' && opname[3] <= 'z')
+ && islower((unsigned char)opname[2])
+ && islower((unsigned char)opname[3]))
{
if (opname[4] == '\0')
{
return ret;
}
+
/* Takes operator name as e.g. "++" and returns mangled
operator name (e.g. "postincrement_expr"), or NULL if not found.
return (0);
}
+/* Add a routine to set the demangling style to be sure it is valid and
+ allow for any demangler initialization that maybe necessary. */
+
+enum demangling_styles
+cplus_demangle_set_style (style)
+ enum demangling_styles style;
+{
+ struct demangler_engine *demangler = libiberty_demanglers;
+
+ for (; demangler->demangling_style != unknown_demangling; ++demangler)
+ if (style == demangler->demangling_style)
+ {
+ current_demangling_style = style;
+ return current_demangling_style;
+ }
+
+ return unknown_demangling;
+}
+
+/* Do string name to style translation */
+
+enum demangling_styles
+cplus_demangle_name_to_style (name)
+ const char *name;
+{
+ struct demangler_engine *demangler = libiberty_demanglers;
+
+ for (; demangler->demangling_style != unknown_demangling; ++demangler)
+ if (strcmp (name, demangler->demangling_style_name) == 0)
+ return demangler->demangling_style;
+
+ return unknown_demangling;
+}
+
/* char *cplus_demangle (const char *mangled, int options)
If MANGLED is a mangled function name produced by GNU C++, then
if ((work -> options & DMGL_STYLE_MASK) == 0)
work -> options |= (int) current_demangling_style & DMGL_STYLE_MASK;
+ /* The new-ABI demangling is implemented elsewhere. */
+ if (GNU_NEW_ABI_DEMANGLING)
+ return cplus_demangle_new_abi (mangled);
+
ret = internal_cplus_demangle (work, mangled);
squangle_mop_up (work);
return (ret);
}
}
-/* Clear out any mangled storage */
-static char *
-mop_up (work, declp, success)
- struct work_stuff *work;
- string *declp;
- int success;
+/* Copy the work state and storage. */
+
+static void
+work_stuff_copy_to_from (to, from)
+ struct work_stuff *to;
+ struct work_stuff *from;
{
- char *demangled = NULL;
+ int i;
+ delete_work_stuff (to);
+
+ /* Shallow-copy scalars. */
+ memcpy (to, from, sizeof (*to));
+
+ /* Deep-copy dynamic storage. */
+ if (from->typevec_size)
+ to->typevec
+ = (char **) xmalloc (from->typevec_size * sizeof (to->typevec[0]));
+
+ for (i = 0; i < from->ntypes; i++)
+ {
+ int len = strlen (from->typevec[i]) + 1;
+
+ to->typevec[i] = xmalloc (len);
+ memcpy (to->typevec[i], from->typevec[i], len);
+ }
+
+ if (from->ksize)
+ to->ktypevec
+ = (char **) xmalloc (from->ksize * sizeof (to->ktypevec[0]));
+
+ for (i = 0; i < from->numk; i++)
+ {
+ int len = strlen (from->ktypevec[i]) + 1;
+
+ to->ktypevec[i] = xmalloc (len);
+ memcpy (to->ktypevec[i], from->ktypevec[i], len);
+ }
+
+ if (from->bsize)
+ to->btypevec
+ = (char **) xmalloc (from->bsize * sizeof (to->btypevec[0]));
+
+ for (i = 0; i < from->numb; i++)
+ {
+ int len = strlen (from->btypevec[i]) + 1;
+
+ to->btypevec[i] = xmalloc (len);
+ memcpy (to->btypevec[i], from->btypevec[i], len);
+ }
+
+ if (from->ntmpl_args)
+ to->tmpl_argvec
+ = xmalloc (from->ntmpl_args * sizeof (to->tmpl_argvec[0]));
+
+ for (i = 0; i < from->ntmpl_args; i++)
+ {
+ int len = strlen (from->tmpl_argvec[i]) + 1;
+
+ to->tmpl_argvec[i] = xmalloc (len);
+ memcpy (to->tmpl_argvec[i], from->tmpl_argvec[i], len);
+ }
+
+ if (from->previous_argument)
+ {
+ to->previous_argument = (string*) xmalloc (sizeof (string));
+ string_init (to->previous_argument);
+ string_appends (to->previous_argument, from->previous_argument);
+ }
+}
+
+
+/* Delete dynamic stuff in work_stuff that is not to be re-used. */
+
+static void
+delete_non_B_K_work_stuff (work)
+ struct work_stuff *work;
+{
/* Discard the remembered types, if any. */
forget_types (work);
free ((char*) work->previous_argument);
work->previous_argument = NULL;
}
+}
+
+
+/* Delete all dynamic storage in work_stuff. */
+static void
+delete_work_stuff (work)
+ struct work_stuff *work;
+{
+ delete_non_B_K_work_stuff (work);
+ squangle_mop_up (work);
+}
+
+
+/* Clear out any mangled storage */
+
+static char *
+mop_up (work, declp, success)
+ struct work_stuff *work;
+ string *declp;
+ int success;
+{
+ char *demangled = NULL;
+
+ delete_non_B_K_work_stuff (work);
/* If demangling was successful, ensure that the demangled string is null
terminated and return it. Otherwise, free the demangling decl. */
break;
case '_':
- if (GNU_DEMANGLING && expect_return_type)
+ if ((AUTO_DEMANGLING || GNU_DEMANGLING) && expect_return_type)
{
/* Read the return type. */
string return_type;
break;
case 'H':
- if (GNU_DEMANGLING)
+ if (AUTO_DEMANGLING || GNU_DEMANGLING)
{
/* A G++ template function. Read the template arguments. */
success = demangle_template (work, mangled, declp, 0, 0,
}
static int
-demangle_integral_value (work, mangled, s)
+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;
- if (**mangled == 'E')
+ success = 1;
+ string_appendn (s, "(", 1);
+ (*mangled)++;
+ while (success && **mangled != 'W' && **mangled != '\0')
{
- int need_operator = 0;
-
- success = 1;
- string_appendn (s, "(", 1);
- (*mangled)++;
- while (success && **mangled != 'W' && **mangled != '\0')
+ if (need_operator)
{
- if (need_operator)
- {
- size_t i;
- size_t len;
+ size_t i;
+ size_t len;
- success = 0;
+ success = 0;
- len = strlen (*mangled);
+ len = strlen (*mangled);
- for (i = 0;
- i < sizeof (optable) / sizeof (optable [0]);
- ++i)
- {
- size_t l = strlen (optable[i].in);
+ 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 (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 (!success)
+ break;
}
-
- if (**mangled != 'W')
- success = 0;
else
- {
- string_appendn (s, ")", 1);
- (*mangled)++;
- }
+ 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;
+
+ /* By default, we let the number decide whether we shall consume an
+ underscore. */
+ int consume_following_underscore = 0;
+ int leave_following_underscore = 0;
+
success = 0;
+ /* Negative numbers are indicated with a leading `m'. */
if (**mangled == 'm')
{
string_appendn (s, "-", 1);
(*mangled)++;
}
+ else if (mangled[0][0] == '_' && mangled[0][1] == 'm')
+ {
+ /* Since consume_count_with_underscores does not handle the
+ `m'-prefix we must do it here, using consume_count and
+ adjusting underscores: we have to consume the underscore
+ matching the prepended one. */
+ consume_following_underscore = 1;
+ string_appendn (s, "-", 1);
+ (*mangled) += 2;
+ }
+ else if (**mangled == '_')
+ {
+ /* Do not consume a following underscore;
+ consume_following_underscore will consume what should be
+ consumed. */
+ leave_following_underscore = 1;
+ }
+
+ /* We must call consume_count if we expect to remove a trailing
+ underscore, since consume_count_with_underscores expects
+ the leading underscore (that we consumed) if it is to handle
+ multi-digit numbers. */
+ if (consume_following_underscore)
+ value = consume_count (mangled);
+ else
+ value = consume_count_with_underscores (mangled);
+
+ if (value != -1)
+ {
+ char buf[INTBUF_SIZE];
+ sprintf (buf, "%d", value);
+ string_append (s, buf);
+
+ /* Numbers not otherwise delimited, might have an underscore
+ appended as a delimeter, which we should skip.
+
+ ??? This used to always remove a following underscore, which
+ is wrong. If other (arbitrary) cases are followed by an
+ underscore, we need to do something more radical. */
+
+ if ((value > 9 || consume_following_underscore)
+ && ! leave_following_underscore
+ && **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)++;
- success = 1;
}
}
- return success;
+ return 1;
}
static int
if (work->tmpl_argvec)
string_append (s, work->tmpl_argvec[idx]);
else
- {
- char buf[10];
- sprintf(buf, "T%d", idx);
- string_append (s, buf);
- }
+ string_append_template_idx (s, idx);
}
else if (tk == tk_integral)
success = demangle_integral_value (work, mangled, s);
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)++;
- }
- }
- }
+ success = demangle_real_value (work, mangled, s);
else if (tk == tk_pointer || tk == tk_reference)
{
- int symbol_len = consume_count (mangled);
- if (symbol_len == -1)
- return -1;
- if (symbol_len == 0)
- string_appendn (s, "0", 1);
+ if (**mangled == 'Q')
+ success = demangle_qualified (work, mangled, s,
+ /*isfuncname=*/0,
+ /*append=*/1);
else
{
- char *p = xmalloc (symbol_len + 1), *q;
- strncpy (p, *mangled, symbol_len);
- p [symbol_len] = '\0';
- /* We use cplus_demangle here, rather than
- internal_cplus_demangle, because the name of the entity
- mangled here does not make use of any of the squangling
- or type-code information we have built up thus far; it is
- mangled independently. */
- q = cplus_demangle (p, work->options);
- if (tk == tk_pointer)
- string_appendn (s, "&", 1);
- /* FIXME: Pointer-to-member constants should get a
- qualifying class name here. */
- if (q)
+ int symbol_len = consume_count (mangled);
+ if (symbol_len == -1)
+ return -1;
+ if (symbol_len == 0)
+ string_appendn (s, "0", 1);
+ else
{
- string_append (s, q);
- free (q);
+ char *p = xmalloc (symbol_len + 1), *q;
+ strncpy (p, *mangled, symbol_len);
+ p [symbol_len] = '\0';
+ /* We use cplus_demangle here, rather than
+ internal_cplus_demangle, because the name of the entity
+ mangled here does not make use of any of the squangling
+ or type-code information we have built up thus far; it is
+ mangled independently. */
+ q = cplus_demangle (p, work->options);
+ if (tk == tk_pointer)
+ string_appendn (s, "&", 1);
+ /* FIXME: Pointer-to-member constants should get a
+ qualifying class name here. */
+ if (q)
+ {
+ string_append (s, q);
+ free (q);
+ }
+ else
+ string_append (s, p);
+ free (p);
}
- else
- string_append (s, p);
- free (p);
+ *mangled += symbol_len;
}
- *mangled += symbol_len;
}
return success;
template parameters (e.g. S) is placed in TRAWNAME if TRAWNAME is
non-NULL. If IS_TYPE is nonzero, this template is a type template,
not a function template. If both IS_TYPE and REMEMBER are nonzero,
- the tmeplate is remembered in the list of back-referenceable
+ the template is remembered in the list of back-referenceable
types. */
static int
}
else
{
- char buf[10];
- sprintf(buf, "T%d", idx);
- string_append (tname, buf);
+ string_append_template_idx (tname, idx);
if (trawname)
- string_append (trawname, buf);
+ string_append_template_idx (trawname, idx);
}
}
else
return (success);
}
+
+/* Called when there's a "__" in the mangled name, with `scan' pointing to
+ the rightmost guess.
+
+ Find the correct "__"-sequence where the function name ends and the
+ signature starts, which is ambiguous with GNU mangling.
+ Call demangle_signature here, so we can make sure we found the right
+ one; *mangled will be consumed so caller will not make further calls to
+ demangle_signature. */
+
+static int
+iterate_demangle_function (work, mangled, declp, scan)
+ struct work_stuff *work;
+ const char **mangled;
+ string *declp;
+ const char *scan;
+{
+ const char *mangle_init = *mangled;
+ int success = 0;
+ string decl_init;
+ struct work_stuff work_init;
+
+ if (*(scan + 2) == '\0')
+ return 0;
+
+ /* Do not iterate for some demangling modes, or if there's only one
+ "__"-sequence. This is the normal case. */
+ if (ARM_DEMANGLING || LUCID_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING
+ || mystrstr (scan + 2, "__") == NULL)
+ {
+ demangle_function_name (work, mangled, declp, scan);
+ return 1;
+ }
+
+ /* Save state so we can restart if the guess at the correct "__" was
+ wrong. */
+ string_init (&decl_init);
+ string_appends (&decl_init, declp);
+ memset (&work_init, 0, sizeof work_init);
+ work_stuff_copy_to_from (&work_init, work);
+
+ /* Iterate over occurrences of __, allowing names and types to have a
+ "__" sequence in them. We must start with the first (not the last)
+ occurrence, since "__" most often occur between independent mangled
+ parts, hence starting at the last occurence inside a signature
+ might get us a "successful" demangling of the signature. */
+
+ while (scan[2])
+ {
+ demangle_function_name (work, mangled, declp, scan);
+ success = demangle_signature (work, mangled, declp);
+ if (success)
+ break;
+
+ /* Reset demangle state for the next round. */
+ *mangled = mangle_init;
+ string_clear (declp);
+ string_appends (declp, &decl_init);
+ work_stuff_copy_to_from (work, &work_init);
+
+ /* Leave this underscore-sequence. */
+ scan += 2;
+
+ /* Scan for the next "__" sequence. */
+ while (*scan && (scan[0] != '_' || scan[1] != '_'))
+ scan++;
+
+ /* Move to last "__" in this sequence. */
+ while (*scan && *scan == '_')
+ scan++;
+ scan -= 2;
+ }
+
+ /* Delete saved state. */
+ delete_work_stuff (&work_init);
+ string_delete (&decl_init);
+
+ return success;
+}
+
/*
LOCAL FUNCTION
DESCRIPTION
Consume and demangle the prefix of the mangled name.
+ While processing the function name root, arrange to call
+ demangle_signature if the root is ambiguous.
DECLP points to the string buffer into which demangled output is
placed. On entry, the buffer is empty. On exit it contains
success = 0;
}
else
- {
- const char *tmp;
-
- /* Look for the LAST occurrence of __, allowing names to
- have the '__' sequence embedded in them. */
- if (!(ARM_DEMANGLING || HP_DEMANGLING))
- {
- while ((tmp = mystrstr (scan + 2, "__")) != NULL)
- scan = tmp;
- }
- if (*(scan + 2) == '\0')
- success = 0;
- else
- demangle_function_name (work, mangled, declp, scan);
- }
+ return iterate_demangle_function (work, mangled, declp, scan);
}
}
else if (*(scan + 2) != '\0')
{
/* Mangled name does not start with "__" but does have one somewhere
in there with non empty stuff after it. Looks like a global
- function name. */
- demangle_function_name (work, mangled, declp, scan);
+ function name. Iterate over all "__":s until the right
+ one is found. */
+ return iterate_demangle_function (work, mangled, declp, scan);
}
else
{
break;
default:
n = consume_count (mangled);
- if (n < 0 || n > strlen (*mangled))
+ if (n < 0 || n > (long) strlen (*mangled))
{
success = 0;
break;
{
n = consume_count (mangled);
if (n == -1
- || n > strlen (*mangled))
+ || n > (long) strlen (*mangled))
return 0;
string_prependn (declp, *mangled, n);
(*mangled) += n;
{
int qualifiers = 0;
int success = 1;
- const char *p;
char num[2];
string temp;
string last_name;
/* 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 != '_')
+ (*mangled)++;
+ qualifiers = consume_count_with_underscores (mangled);
+ if (qualifiers == -1)
success = 0;
-
- *mangled = p + 1;
break;
case '1':
int n;
if (!isdigit ((unsigned char)**type))
- {
- return (0);
- }
+ return (0);
else
{
*count = **type - '0';
member = **mangled == 'M';
(*mangled)++;
- if (!isdigit ((unsigned char)**mangled) && **mangled != 't')
- {
- success = 0;
- break;
- }
string_append (&decl, ")");
- string_prepend (&decl, SCOPE_STRING (work));
+
+ /* We don't need to prepend `::' for a qualified name;
+ demangle_qualified will do that for us. */
+ if (**mangled != 'Q')
+ string_prepend (&decl, SCOPE_STRING (work));
+
if (isdigit ((unsigned char)**mangled))
{
n = consume_count (mangled);
string_prependn (&decl, *mangled, n);
*mangled += n;
}
- else
+ else if (**mangled == 'X' || **mangled == 'Y')
+ {
+ string temp;
+ do_type (work, mangled, &temp);
+ string_prepends (&decl, &temp);
+ }
+ else if (**mangled == 't')
{
string temp;
string_init (&temp);
else
break;
}
+ else if (**mangled == 'Q')
+ {
+ success = demangle_qualified (work, mangled, &decl,
+ /*isfuncnam=*/0,
+ /*append=*/0);
+ if (!success)
+ break;
+ }
+ else
+ {
+ success = 0;
+ break;
+ }
+
string_prepend (&decl, "(");
if (member)
{
if (work->tmpl_argvec)
string_append (result, work->tmpl_argvec[idx]);
else
- {
- char buf[10];
- sprintf(buf, "T%d", idx);
- string_append (result, buf);
- }
+ string_append_template_idx (result, idx);
success = 1;
}
int done = 0;
int success = 1;
char buf[10];
- int dec = 0;
+ unsigned int dec = 0;
string btype;
type_kind_t tk = tk_integral;
break;
}
case 'I':
- ++(*mangled);
+ (*mangled)++;
if (**mangled == '_')
{
int i;
- ++(*mangled);
+ (*mangled)++;
for (i = 0;
- (i < sizeof (buf) - 1 && **mangled && **mangled != '_');
- ++(*mangled), ++i)
+ i < (long) sizeof (buf) - 1 && **mangled && **mangled != '_';
+ (*mangled)++, i++)
buf[i] = **mangled;
if (**mangled != '_')
{
break;
}
buf[i] = '\0';
- ++(*mangled);
+ (*mangled)++;
}
else
{
strncpy (buf, *mangled, 2);
buf[2] = '\0';
- *mangled += 2;
+ *mangled += min (strlen (*mangled), 2);
}
sscanf (buf, "%x", &dec);
- sprintf (buf, "int%i_t", dec);
+ sprintf (buf, "int%u_t", dec);
APPEND_BLANK (result);
string_append (result, buf);
break;
static int
do_hpacc_template_const_value (work, mangled, result)
- struct work_stuff *work;
+ struct work_stuff *work ATTRIBUTE_UNUSED;
const char **mangled;
string *result;
{
}
}
else if (declp->b[0] == '_' && declp->b[1] == '_'
- && declp->b[2] >= 'a' && declp->b[2] <= 'z'
- && declp->b[3] >= 'a' && declp->b[3] <= 'z')
+ && islower((unsigned char)declp->b[2])
+ && islower((unsigned char)declp->b[3]))
{
if (declp->b[4] == '\0')
{
}
}
+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,
just compile and link this file with -DMAIN and libiberty.a. When
run, it demangles each command line arg, or each stdin string, and
#include "getopt.h"
-static char *program_name;
-static char *program_version = VERSION;
+static const char *program_name;
+static const char *program_version = VERSION;
static int flags = DMGL_PARAMS | DMGL_ANSI;
static void demangle_it PARAMS ((char *));
-static void usage PARAMS ((FILE *, int));
-static void fatal PARAMS ((char *));
+static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN;
+static void fatal PARAMS ((const char *)) ATTRIBUTE_NORETURN;
+static void print_demangler_list PARAMS ((FILE *));
static void
demangle_it (mangled_name)
}
}
+static void
+print_demangler_list (stream)
+ FILE *stream;
+{
+ struct demangler_engine *demangler;
+
+ fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);
+
+ for (demangler = libiberty_demanglers + 1;
+ demangler->demangling_style != unknown_demangling;
+ ++demangler)
+ fprintf (stream, ",%s", demangler->demangling_style_name);
+
+ fprintf (stream, "}");
+}
+
static void
usage (stream, status)
FILE *stream;
int status;
{
fprintf (stream, "\
-Usage: %s [-_] [-n] [-s {gnu,lucid,arm,hp,edg}] [--strip-underscores]\n\
- [--no-strip-underscores] [--format={gnu,lucid,arm,hp,edg}]\n\
- [--help] [--version] [arg...]\n",
+Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n",
program_name);
+
+ fprintf (stream, "\
+ [-s ");
+ print_demangler_list (stream);
+ fprintf (stream, "]\n");
+
+ fprintf (stream, "\
+ [--format ");
+ print_demangler_list (stream);
+ fprintf (stream, "]\n");
+
+ fprintf (stream, "\
+ [--help] [--version] [arg...]\n");
exit (status);
}
}
-/* Fill in TABLE so that TABLE[C] is true iff C (as an unsigned char)
- is a valid symbol component, in the standard assembler symbol
- syntax. */
-void
-standard_symbol_alphabet (char *table)
-{
- int c;
+static const char *
+standard_symbol_characters PARAMS ((void));
+
+static const char *
+hp_symbol_characters PARAMS ((void));
- for (c = 0; c < 256; c++)
- table[c] = isalnum(c);
+static const char *
+gnu_new_abi_symbol_characters PARAMS ((void));
+
+/* Return the string of non-alnum characters that may occur
+ as a valid symbol component, in the standard assembler symbol
+ syntax. */
- table['_'] = 1;
- table['$'] = 1;
- table['.'] = 1;
+static const char *
+standard_symbol_characters ()
+{
+ return "_$.";
}
-/* Fill in TABLE so that TABLE[C] is true iff C (as an unsigned char)
- is a valid symbol name component in an HP object file.
+/* Return the string of non-alnum characters that may occur
+ as a valid symbol name component in an HP object file.
Note that, since HP's compiler generates object code straight from
C++ source, without going through an assembler, its mangled
non-digit character.
So have fun. */
-void
-hp_symbol_alphabet (char *table)
+static const char *
+hp_symbol_characters ()
{
- char *c;
+ return "_$.<>#,*&[]:(){}";
+}
+
- standard_symbol_alphabet (table);
+/* Return the string of non-alnum characters that may occur
+ as a valid symbol component in the GNU standard C++ ABI mangling
+ scheme. */
- for (c = "<>#,*&[]:(){}"; *c; c++)
- table[(unsigned char) *c] = 1;
+static const char *
+gnu_new_abi_symbol_characters ()
+{
+ return "_";
}
+extern int main PARAMS ((int, char **));
+
int
main (argc, argv)
int argc;
{
char *result;
int c;
- char symbol_alphabet[256];
+ const char *valid_symbols;
program_name = argv[0];
break;
case 'v':
printf ("GNU %s (C++ demangler), version %s\n", program_name, program_version);
- exit (0);
+ return (0);
case '_':
strip_underscore = 1;
break;
flags |= DMGL_JAVA;
break;
case 's':
- if (strcmp (optarg, "gnu") == 0)
- {
- current_demangling_style = gnu_demangling;
- }
- else if (strcmp (optarg, "lucid") == 0)
- {
- current_demangling_style = lucid_demangling;
- }
- else if (strcmp (optarg, "arm") == 0)
- {
- current_demangling_style = arm_demangling;
- }
- else if (strcmp (optarg, "hp") == 0)
- {
- current_demangling_style = hp_demangling;
- }
- else if (strcmp (optarg, "edg") == 0)
- {
- current_demangling_style = edg_demangling;
- }
- else
- {
- fprintf (stderr, "%s: unknown demangling style `%s'\n",
- program_name, optarg);
- exit (1);
- }
+ {
+ enum demangling_styles style;
+
+ style = cplus_demangle_name_to_style (optarg);
+ if (style == unknown_demangling)
+ {
+ fprintf (stderr, "%s: unknown demangling style `%s'\n",
+ program_name, optarg);
+ return (1);
+ }
+ else
+ cplus_demangle_set_style (style);
+ }
break;
}
}
case lucid_demangling:
case arm_demangling:
case edg_demangling:
- standard_symbol_alphabet (symbol_alphabet);
+ valid_symbols = standard_symbol_characters ();
break;
case hp_demangling:
- hp_symbol_alphabet (symbol_alphabet);
+ valid_symbols = hp_symbol_characters ();
+ break;
+ case gnu_new_abi_demangling:
+ valid_symbols = gnu_new_abi_symbol_characters ();
break;
default:
/* Folks should explicitly indicate the appropriate alphabet for
int i = 0;
c = getchar ();
/* Try to read a label. */
- while (c != EOF && symbol_alphabet[c])
+ while (c != EOF && (isalnum (c) || strchr (valid_symbols, c)))
{
if (i >= MBUF_SIZE-1)
break;
if (c == EOF)
break;
putchar (c);
+ fflush (stdout);
}
}
- exit (0);
+ return (0);
}
static void
fatal (str)
- char *str;
+ const char *str;
{
fprintf (stderr, "%s: %s\n", program_name, str);
exit (1);