summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/libiberty/cplus-dem.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/binutils/libiberty/cplus-dem.c')
-rw-r--r--contrib/binutils/libiberty/cplus-dem.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/contrib/binutils/libiberty/cplus-dem.c b/contrib/binutils/libiberty/cplus-dem.c
index a42f45e..5af8826 100644
--- a/contrib/binutils/libiberty/cplus-dem.c
+++ b/contrib/binutils/libiberty/cplus-dem.c
@@ -1,6 +1,6 @@
/* Demangler for GNU C++
Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000 Free Software Foundation, Inc.
+ 2000, 2001 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.uucp)
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
@@ -63,25 +63,6 @@ static char *ada_demangle PARAMS ((const char *, int));
extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;
-static const char *mystrstr PARAMS ((const char *, const char *));
-
-static const char *
-mystrstr (s1, s2)
- const char *s1, *s2;
-{
- register const char *p = s1;
- register int len = strlen (s2);
-
- for (; (p = strchr (p, *s2)) != 0; p++)
- {
- if (strncmp (p, s2, len) == 0)
- {
- return (p);
- }
- }
- return (0);
-}
-
/* In order to allow a single demangler executable to demangle strings
using various common values of CPLUS_MARKER, as well as any specific
one set at compile time, we maintain a string containing all the
@@ -157,9 +138,9 @@ struct work_stuff
static const struct optable
{
- const char *in;
- const char *out;
- int flags;
+ const char *const in;
+ const char *const out;
+ const int flags;
} optable[] = {
{"nw", " new", DMGL_ANSI}, /* new (1.92, ansi) */
{"dl", " delete", DMGL_ANSI}, /* new (1.92, ansi) */
@@ -256,9 +237,15 @@ typedef enum type_kind_t
tk_real
} type_kind_t;
-struct demangler_engine libiberty_demanglers[] =
+const struct demangler_engine libiberty_demanglers[] =
{
{
+ NO_DEMANGLING_STYLE_STRING,
+ no_demangling,
+ "Demangling disabled"
+ }
+ ,
+ {
AUTO_DEMANGLING_STYLE_STRING,
auto_demangling,
"Automatic selection based on executable"
@@ -568,6 +555,9 @@ consume_count (type)
(*type)++;
}
+ if (count < 0)
+ count = -1;
+
return (count);
}
@@ -847,7 +837,7 @@ enum demangling_styles
cplus_demangle_set_style (style)
enum demangling_styles style;
{
- struct demangler_engine *demangler = libiberty_demanglers;
+ const struct demangler_engine *demangler = libiberty_demanglers;
for (; demangler->demangling_style != unknown_demangling; ++demangler)
if (style == demangler->demangling_style)
@@ -865,7 +855,7 @@ enum demangling_styles
cplus_demangle_name_to_style (name)
const char *name;
{
- struct demangler_engine *demangler = libiberty_demanglers;
+ const struct demangler_engine *demangler = libiberty_demanglers;
for (; demangler->demangling_style != unknown_demangling; ++demangler)
if (strcmp (name, demangler->demangling_style_name) == 0)
@@ -877,7 +867,7 @@ cplus_demangle_name_to_style (name)
/* char *cplus_demangle (const char *mangled, int options)
If MANGLED is a mangled function name produced by GNU C++, then
- a pointer to a malloced string giving a C++ representation
+ a pointer to a @code{malloc}ed string giving a C++ representation
of the name will be returned; otherwise NULL will be returned.
It is the caller's responsibility to free the string which
is returned.
@@ -909,6 +899,10 @@ cplus_demangle (mangled, options)
{
char *ret;
struct work_stuff work[1];
+
+ if (current_demangling_style == no_demangling)
+ return xstrdup (mangled);
+
memset ((char *) work, 0, sizeof (work));
work->options = options;
if ((work->options & DMGL_STYLE_MASK) == 0)
@@ -922,6 +916,13 @@ cplus_demangle (mangled, options)
return ret;
}
+ if (JAVA_DEMANGLING)
+ {
+ ret = java_demangle_v3 (mangled);
+ if (ret)
+ return ret;
+ }
+
if (GNAT_DEMANGLING)
return ada_demangle(mangled,options);
@@ -2233,7 +2234,7 @@ arm_pt (work, mangled, n, anchor, args)
{
/* Check if ARM template with "__pt__" in it ("parameterized type") */
/* Allow HP also here, because HP's cfront compiler follows ARM to some extent */
- if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = mystrstr (mangled, "__pt__")))
+ if ((ARM_DEMANGLING || HP_DEMANGLING) && (*anchor = strstr (mangled, "__pt__")))
{
int len;
*args = *anchor + 6;
@@ -2248,9 +2249,9 @@ arm_pt (work, mangled, n, anchor, args)
}
if (AUTO_DEMANGLING || EDG_DEMANGLING)
{
- if ((*anchor = mystrstr (mangled, "__tm__"))
- || (*anchor = mystrstr (mangled, "__ps__"))
- || (*anchor = mystrstr (mangled, "__pt__")))
+ if ((*anchor = strstr (mangled, "__tm__"))
+ || (*anchor = strstr (mangled, "__ps__"))
+ || (*anchor = strstr (mangled, "__pt__")))
{
int len;
*args = *anchor + 6;
@@ -2263,7 +2264,7 @@ arm_pt (work, mangled, n, anchor, args)
return 1;
}
}
- else if ((*anchor = mystrstr (mangled, "__S")))
+ else if ((*anchor = strstr (mangled, "__S")))
{
int len;
*args = *anchor + 3;
@@ -2564,7 +2565,7 @@ iterate_demangle_function (work, mangled, declp, scan)
/* 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)
+ || strstr (scan + 2, "__") == NULL)
{
demangle_function_name (work, mangled, declp, scan);
return 1;
@@ -2707,7 +2708,7 @@ demangle_prefix (work, mangled, declp)
/* This block of code is a reduction in strength time optimization
of:
- scan = mystrstr (*mangled, "__"); */
+ scan = strstr (*mangled, "__"); */
{
scan = *mangled;
@@ -2799,7 +2800,7 @@ demangle_prefix (work, mangled, declp)
{
scan++;
}
- if ((scan = mystrstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))
+ if ((scan = strstr (scan, "__")) == NULL || (*(scan + 2) == '\0'))
{
/* No separator (I.E. "__not_mangled"), or empty signature
(I.E. "__not_mangled_either__") */
@@ -4902,7 +4903,7 @@ static void
print_demangler_list (stream)
FILE *stream;
{
- struct demangler_engine *demangler;
+ const struct demangler_engine *demangler;
fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);
@@ -4946,11 +4947,10 @@ extern int prepends_underscore;
int strip_underscore = 0;
-static struct option long_options[] = {
+static const struct option long_options[] = {
{"strip-underscores", no_argument, 0, '_'},
{"format", required_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
- {"java", no_argument, 0, 'j'},
{"no-strip-underscores", no_argument, 0, 'n'},
{"version", no_argument, 0, 'v'},
{0, no_argument, 0, 0}
@@ -5044,12 +5044,13 @@ main (argc, argv)
char *result;
int c;
const char *valid_symbols;
+ enum demangling_styles style = auto_demangling;
program_name = argv[0];
strip_underscore = prepends_underscore;
- while ((c = getopt_long (argc, argv, "_ns:j", long_options, (int *) 0)) != EOF)
+ while ((c = getopt_long (argc, argv, "_ns:", long_options, (int *) 0)) != EOF)
{
switch (c)
{
@@ -5067,13 +5068,8 @@ main (argc, argv)
case '_':
strip_underscore = 1;
break;
- case 'j':
- flags |= DMGL_JAVA;
- break;
case 's':
{
- enum demangling_styles style;
-
style = cplus_demangle_name_to_style (optarg);
if (style == unknown_demangling)
{
@@ -5137,7 +5133,7 @@ main (argc, argv)
{
int skip_first = 0;
- if (mbuffer[0] == '.')
+ if (mbuffer[0] == '.' || mbuffer[0] == '$')
++skip_first;
if (strip_underscore && mbuffer[skip_first] == '_')
++skip_first;
@@ -5146,7 +5142,7 @@ main (argc, argv)
skip_first = i;
mbuffer[i] = 0;
-
+ flags |= (int) style;
result = cplus_demangle (mbuffer + skip_first, flags);
if (result)
{
OpenPOWER on IntegriCloud