* libiberty/cplus-dem.c

(libiberty_demanglers): new table for demangle styles
        (cplus_demangle_set_style): New function for setting style
        (cplus_demangle_name_to_style): New function to translate name
        * include/demangle.h
        (libiberty_demanglers): new table for different styles
        (cplus_demangle_set_style): New function for setting style
        (cplus_demangle_name_to_style): New function to translate name

Co-Authored-By: Jason Merrill <jason@casey.cygnus.com>

From-SVN: r33525
This commit is contained in:
Kenneth Block 2000-04-28 22:22:22 +00:00 committed by Jason Merrill
parent 34332678da
commit 24eaa47a46
4 changed files with 150 additions and 29 deletions

View File

@ -1,3 +1,10 @@
2000-04-28 Kenneth Block <block@zk3.dec.com>
Jason Merrill <jason@casey.cygnus.com>
* demangle.h (libiberty_demanglers): new table for different styles.
(cplus_demangle_set_style): New function for setting style.
(cplus_demangle_name_to_style): New function to translate name.
2000-04-24 Mark Mitchell <mark@codesourcery.com>
* hashtab.h (hash_pointer): Declare.

View File

@ -78,6 +78,16 @@ extern enum demangling_styles
#define HP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_HP)
#define EDG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_EDG)
/* Provide information about the available demangle styles. This code is
pulled from gdb into libiberty because it is useful to binutils also. */
extern struct demangler_engine
{
char *demangling_style_name;
enum demangling_styles demangling_style;
char *demangling_style_doc;
} libiberty_demanglers[];
extern char *
cplus_demangle PARAMS ((const char *mangled, int options));
@ -92,4 +102,9 @@ cplus_mangle_opname PARAMS ((const char *opname, int options));
extern void
set_cplus_marker_for_demangling PARAMS ((int ch));
extern enum demangling_styles
cplus_demangle_set_style PARAMS ((enum demangling_styles style));
extern enum demangling_styles
cplus_demangle_name_to_style PARAMS ((const char *name));
#endif /* DEMANGLE_H */

View File

@ -1,3 +1,10 @@
2000-04-28 Kenneth Block <block@zk3.dec.com>
Jason Merrill <jason@casey.cygnus.com>
* cplus-dem.c (libiberty_demanglers): New table for demangle styles.
(cplus_demangle_set_style): New function for setting style.
(cplus_demangle_name_to_style): New function to translate name.
2000-04-27 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* aclocal.m4: New file with new test libiberty_AC_FUNC_STRNCMP.

View File

@ -252,6 +252,49 @@ typedef enum type_kind_t
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"
}
,
{
NULL, unknown_demangling, NULL
}
};
#define STRING_EMPTY(str) ((str) -> b == (str) -> p)
#define PREPEND_BLANK(str) {if (!STRING_EMPTY(str)) \
string_prepend(str, " ");}
@ -733,6 +776,7 @@ cplus_demangle_opname (opname, result, options)
return ret;
}
/* Takes operator name as e.g. "++" and returns mangled
operator name (e.g. "postincrement_expr"), or NULL if not found.
@ -758,6 +802,40 @@ cplus_mangle_opname (opname, options)
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
@ -4421,16 +4499,43 @@ 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);
}
@ -4553,32 +4658,19 @@ main (argc, argv)
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);
return (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;
}
}