1999-01-14 12:09:01 +00:00
|
|
|
/* Demangler for GNU C++
|
2024-01-03 11:19:35 +00:00
|
|
|
Copyright (C) 1989-2024 Free Software Foundation, Inc.
|
1997-08-21 22:57:35 +00:00
|
|
|
Written by James Clark (jjc@jclark.uucp)
|
|
|
|
Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
|
1998-12-07 22:21:45 +00:00
|
|
|
Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
|
1999-01-14 12:09:01 +00:00
|
|
|
|
1997-08-21 22:57:35 +00:00
|
|
|
This file is part of the libiberty library.
|
|
|
|
Libiberty is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
2003-03-04 02:57:16 +00:00
|
|
|
In addition to the permissions in the GNU Library General Public
|
|
|
|
License, the Free Software Foundation gives you unlimited permission
|
|
|
|
to link the compiled version of this file into combinations with other
|
|
|
|
programs, and to distribute those combinations without any restriction
|
|
|
|
coming from the use of this file. (The Library Public License
|
|
|
|
restrictions do apply in other respects; for example, they cover
|
|
|
|
modification of the file, and distribution when not linked into a
|
|
|
|
combined executable.)
|
|
|
|
|
1997-08-21 22:57:35 +00:00
|
|
|
Libiberty is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with libiberty; see the file COPYING.LIB. If
|
2005-05-10 15:33:18 +00:00
|
|
|
not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA. */
|
1997-08-21 22:57:35 +00:00
|
|
|
|
|
|
|
/* This file lives in both GCC and libiberty. When making changes, please
|
|
|
|
try not to break either. */
|
|
|
|
|
1998-08-17 11:42:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
safe-ctype.h: New file.
include:
* safe-ctype.h: New file.
libiberty:
* safe-ctype.c: New file.
* Makefile.in (CFILES): Add safe-ctype.c.
(REQUIRED_OFILES): Add safe-ctype.o.
* argv.c: Define ISBLANK and use it, not isspace.
* basename.c, cplus-dem.c, fnmatch.c, pexecute.c, strtod.c,
strtol.c, strtoul.c: Include safe-ctype.h, not ctype.h. Use
uppercase ctype macros. Don't test ISUPPER(c)/ISLOWER(c)
before calling TOLOWER(c)/TOUPPER(c).
gcc:
* Makefile.in (HOST_RTL): Add safe-ctype.o.
(safe-ctype.o): New rule.
* system.h: Include safe-ctype.h, not ctype.h. No need to
wrap ctype macros.
* cpphash.h: Zap IStable and related macros. Define is_* in
terms of safe-ctype.h macros.
* cppinit.c: Delete the IStable and all related code.
* tradcpp.c: Delete is_idchar, is_idstart, is_hor_space, and
is_space arrays. Delete initialize_char_syntax. Change all
references to the above arrays to use macros instead.
* tradcpp.h: Define is_idchar, is_idstart, is_space, and
is_nvspace in terms of safe_ctype.h's macros.
* tradcif.y: is_idchar, is_idstart are macros not arrays.
* config/i370/i370.c, config/winnt/dirent.c,
config/winnt/fixinc-nt.c, config/winnt/ld.c:
Use uppercase ctype macros. If we included ctype.h,
include safe-ctype.h instead.
* fixinc/fixfixes.c: Use uppercase ctype macros. Don't test
ISLOWER(c) before calling TOUPPER(c).
* fixinc/fixincl.c (extract_quoted_files): Simplify out some gunk.
* fixinc/gnu-regex.c: Include safe-ctype.h, not ctype.h. No need to
wrap ctype macros. Don't test ISUPPER(x) before calling TOLOWER(x).
gcc/ch:
* lex.c: Don't bother checking whether ISUPPER(c) before
calling TOLOWER(c). Don't bother checking whether isascii(c)
before testing ISSPACE(c); ISSPACE(c) includes '\n'.
gcc/f:
* Make-lang.in: Link f/fini with safe-ctype.o.
* bad.c: Don't test ISUPPER(c) || ISLOWER(c) before calling TOUPPER(c).
* com.c: Use TOUPPER, not ffesrc_toupper.
* fini.c: Don't test ISALPHA(c) before calling TOUPPER(c)/TOLOWER(c).
* intrin.c: Don't test IN_CTYPE_DOMAIN(c).
* src.c: Delete ffesrc_toupper_ and ffesrc_tolower_ and their
initializing code; use TOUPPER and TOLOWER instead of
ffesrc_toupper and ffesrc_tolower.
* src.h: Don't declare ffesrc_toupper_ or ffesrc_tolower_.
Don't define ffesrc_toupper or ffesrc_tolower.
gcc/java:
* jvgenmain.c: Use ISPRINT not isascii.
From-SVN: r38124
2000-12-08 03:00:26 +00:00
|
|
|
#include "safe-ctype.h"
|
|
|
|
|
1997-08-21 22:57:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
1998-04-10 00:45:43 +00:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
1998-08-17 11:42:54 +00:00
|
|
|
#else
|
2008-03-13 18:49:45 +00:00
|
|
|
void * malloc ();
|
|
|
|
void * realloc ();
|
1998-04-10 00:45:43 +00:00
|
|
|
#endif
|
|
|
|
|
1997-08-21 22:57:35 +00:00
|
|
|
#include <demangle.h>
|
|
|
|
#undef CURRENT_DEMANGLING_STYLE
|
Remove support for demangling GCC 2.x era mangling schemes.
libiberty/
* cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname,
internal_cplus_demangle, and all subroutines.
(libiberty_demanglers): Remove entries for ancient GNU (pre-3.0),
Lucid, ARM, HP, and EDG demangling styles.
(cplus_demangle): Remove 'work' variable. Don't call
internal_cplus_demangle.
include/
* demangle.h: Remove support for ancient GNU (pre-3.0), Lucid,
ARM, HP, and EDG demangling styles.
From-SVN: r267363
2018-12-23 00:06:34 +00:00
|
|
|
#define CURRENT_DEMANGLING_STYLE options
|
1997-08-21 22:57:35 +00:00
|
|
|
|
1998-11-27 10:28:57 +00:00
|
|
|
#include "libiberty.h"
|
1997-08-21 22:57:35 +00:00
|
|
|
|
2000-12-04 17:11:17 +00:00
|
|
|
enum demangling_styles current_demangling_style = auto_demangling;
|
1997-08-21 22:57:35 +00:00
|
|
|
|
2001-10-07 14:45:04 +00:00
|
|
|
const struct demangler_engine libiberty_demanglers[] =
|
2000-04-28 22:22:22 +00:00
|
|
|
{
|
2001-12-06 21:56:15 +00:00
|
|
|
{
|
|
|
|
NO_DEMANGLING_STYLE_STRING,
|
|
|
|
no_demangling,
|
|
|
|
"Demangling disabled"
|
|
|
|
}
|
|
|
|
,
|
2000-04-28 22:22:22 +00:00
|
|
|
{
|
|
|
|
AUTO_DEMANGLING_STYLE_STRING,
|
|
|
|
auto_demangling,
|
|
|
|
"Automatic selection based on executable"
|
|
|
|
}
|
|
|
|
,
|
2000-06-05 02:28:41 +00:00
|
|
|
{
|
2000-12-04 17:11:17 +00:00
|
|
|
GNU_V3_DEMANGLING_STYLE_STRING,
|
|
|
|
gnu_v3_demangling,
|
Remove support for demangling GCC 2.x era mangling schemes.
libiberty/
* cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname,
internal_cplus_demangle, and all subroutines.
(libiberty_demanglers): Remove entries for ancient GNU (pre-3.0),
Lucid, ARM, HP, and EDG demangling styles.
(cplus_demangle): Remove 'work' variable. Don't call
internal_cplus_demangle.
include/
* demangle.h: Remove support for ancient GNU (pre-3.0), Lucid,
ARM, HP, and EDG demangling styles.
From-SVN: r267363
2018-12-23 00:06:34 +00:00
|
|
|
"GNU (g++) V3 (Itanium C++ ABI) style demangling"
|
2000-06-05 02:28:41 +00:00
|
|
|
}
|
|
|
|
,
|
2000-11-15 11:54:53 +00:00
|
|
|
{
|
|
|
|
JAVA_DEMANGLING_STYLE_STRING,
|
|
|
|
java_demangling,
|
|
|
|
"Java style demangling"
|
|
|
|
}
|
|
|
|
,
|
|
|
|
{
|
|
|
|
GNAT_DEMANGLING_STYLE_STRING,
|
|
|
|
gnat_demangling,
|
|
|
|
"GNAT style demangling"
|
|
|
|
}
|
|
|
|
,
|
2014-09-23 18:36:14 +00:00
|
|
|
{
|
|
|
|
DLANG_DEMANGLING_STYLE_STRING,
|
|
|
|
dlang_demangling,
|
|
|
|
"DLANG style demangling"
|
|
|
|
}
|
|
|
|
,
|
2016-11-16 23:09:27 +00:00
|
|
|
{
|
|
|
|
RUST_DEMANGLING_STYLE_STRING,
|
|
|
|
rust_demangling,
|
|
|
|
"Rust style demangling"
|
|
|
|
}
|
|
|
|
,
|
2000-04-28 22:22:22 +00:00
|
|
|
{
|
|
|
|
NULL, unknown_demangling, NULL
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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
|
Convert libiberty to use ISO C prototype style 3/n.
* cplus-dem.c (set_cplus_marker_for_demangling, consume_count,
consume_count_with_underscores, code_for_qualifier,
qualifier_string, demangle_qualifier, cplus_demangle_opname,
cplus_mangle_opname, cplus_demangle_set_style,
cplus_demangle_name_to_style, cplus_demangle, grow_vect,
ada_demangle, internal_cplus_demangle, squangle_mop_up,
work_stuff_copy_to_from, delete_non_B_K_work_stuff,
delete_work_stuff, mop_up, demangle_signature,
demangle_method_args, demangle_template_template_parm,
demangle_expression, demangle_integral_value,
demangle_real_value, demangle_template_value_parm,
demangle_template, arm_pt, demangle_arm_hp_template,
demangle_class_name, demangle_class,
iterate_demangle_function,
demangle_prefix, gnu_special, recursively_demangle,
arm_special,
demangle_qualified, get_count, do_type, demangle_fund_type,
do_hpacc_template_const_value, do_hpacc_template_literal,
snarf_numeric_literal, do_arg, remember_type, remember_Ktype,
register_Btype, remember_Btype, forget_B_and_K_types,
forget_types, demangle_args, demangle_nested_args,
demangle_function_name, string_need, string_delete,
string_init,
string_clear, string_empty, string_append, string_appends,
string_appendn, string_prepend, string_prepends,
string_prependn,
string_append_template_idx): Use ISO C prootype style.
* cp-demint.c (cplus_demangle_fill_component,
cplus_demangle_fill_builtin_type,
cplus_demangle_fill_operator,
cplus_demangle_v3_components): Likewise.
From-SVN: r97109
2005-03-27 05:00:12 +00:00
|
|
|
cplus_demangle_set_style (enum demangling_styles style)
|
2000-04-28 22:22:22 +00:00
|
|
|
{
|
2001-10-07 14:45:04 +00:00
|
|
|
const struct demangler_engine *demangler = libiberty_demanglers;
|
2000-04-28 22:22:22 +00:00
|
|
|
|
|
|
|
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
|
Convert libiberty to use ISO C prototype style 3/n.
* cplus-dem.c (set_cplus_marker_for_demangling, consume_count,
consume_count_with_underscores, code_for_qualifier,
qualifier_string, demangle_qualifier, cplus_demangle_opname,
cplus_mangle_opname, cplus_demangle_set_style,
cplus_demangle_name_to_style, cplus_demangle, grow_vect,
ada_demangle, internal_cplus_demangle, squangle_mop_up,
work_stuff_copy_to_from, delete_non_B_K_work_stuff,
delete_work_stuff, mop_up, demangle_signature,
demangle_method_args, demangle_template_template_parm,
demangle_expression, demangle_integral_value,
demangle_real_value, demangle_template_value_parm,
demangle_template, arm_pt, demangle_arm_hp_template,
demangle_class_name, demangle_class,
iterate_demangle_function,
demangle_prefix, gnu_special, recursively_demangle,
arm_special,
demangle_qualified, get_count, do_type, demangle_fund_type,
do_hpacc_template_const_value, do_hpacc_template_literal,
snarf_numeric_literal, do_arg, remember_type, remember_Ktype,
register_Btype, remember_Btype, forget_B_and_K_types,
forget_types, demangle_args, demangle_nested_args,
demangle_function_name, string_need, string_delete,
string_init,
string_clear, string_empty, string_append, string_appends,
string_appendn, string_prepend, string_prepends,
string_prependn,
string_append_template_idx): Use ISO C prootype style.
* cp-demint.c (cplus_demangle_fill_component,
cplus_demangle_fill_builtin_type,
cplus_demangle_fill_operator,
cplus_demangle_v3_components): Likewise.
From-SVN: r97109
2005-03-27 05:00:12 +00:00
|
|
|
cplus_demangle_name_to_style (const char *name)
|
2000-04-28 22:22:22 +00:00
|
|
|
{
|
2001-10-07 14:45:04 +00:00
|
|
|
const struct demangler_engine *demangler = libiberty_demanglers;
|
2000-04-28 22:22:22 +00:00
|
|
|
|
|
|
|
for (; demangler->demangling_style != unknown_demangling; ++demangler)
|
|
|
|
if (strcmp (name, demangler->demangling_style_name) == 0)
|
|
|
|
return demangler->demangling_style;
|
|
|
|
|
|
|
|
return unknown_demangling;
|
|
|
|
}
|
|
|
|
|
1997-08-21 22:57:35 +00:00
|
|
|
/* char *cplus_demangle (const char *mangled, int options)
|
|
|
|
|
|
|
|
If MANGLED is a mangled function name produced by GNU C++, then
|
argv.c, [...]: Improve manual formatting.
* argv.c, asprintf.c, choose-temp.c, concat.c, cplus-dem.c,
ffs.c, fnmatch.txh, getruntime.c, make-temp-file.c,
mkstemps.c, pexecute.c, random.c, strsitnal.c, vasprintf.c:
Improve manual formatting.
* functions.texi: Regenerate.
From-SVN: r46323
2001-10-17 21:15:41 +00:00
|
|
|
a pointer to a @code{malloc}ed string giving a C++ representation
|
1997-08-21 22:57:35 +00:00
|
|
|
of the name will be returned; otherwise NULL will be returned.
|
|
|
|
It is the caller's responsibility to free the string which
|
|
|
|
is returned.
|
|
|
|
|
|
|
|
Note that any leading underscores, or other such characters prepended by
|
|
|
|
the compilation system, are presumed to have already been stripped from
|
|
|
|
MANGLED. */
|
|
|
|
|
|
|
|
char *
|
Convert libiberty to use ISO C prototype style 3/n.
* cplus-dem.c (set_cplus_marker_for_demangling, consume_count,
consume_count_with_underscores, code_for_qualifier,
qualifier_string, demangle_qualifier, cplus_demangle_opname,
cplus_mangle_opname, cplus_demangle_set_style,
cplus_demangle_name_to_style, cplus_demangle, grow_vect,
ada_demangle, internal_cplus_demangle, squangle_mop_up,
work_stuff_copy_to_from, delete_non_B_K_work_stuff,
delete_work_stuff, mop_up, demangle_signature,
demangle_method_args, demangle_template_template_parm,
demangle_expression, demangle_integral_value,
demangle_real_value, demangle_template_value_parm,
demangle_template, arm_pt, demangle_arm_hp_template,
demangle_class_name, demangle_class,
iterate_demangle_function,
demangle_prefix, gnu_special, recursively_demangle,
arm_special,
demangle_qualified, get_count, do_type, demangle_fund_type,
do_hpacc_template_const_value, do_hpacc_template_literal,
snarf_numeric_literal, do_arg, remember_type, remember_Ktype,
register_Btype, remember_Btype, forget_B_and_K_types,
forget_types, demangle_args, demangle_nested_args,
demangle_function_name, string_need, string_delete,
string_init,
string_clear, string_empty, string_append, string_appends,
string_appendn, string_prepend, string_prepends,
string_prependn,
string_append_template_idx): Use ISO C prootype style.
* cp-demint.c (cplus_demangle_fill_component,
cplus_demangle_fill_builtin_type,
cplus_demangle_fill_operator,
cplus_demangle_v3_components): Likewise.
From-SVN: r97109
2005-03-27 05:00:12 +00:00
|
|
|
cplus_demangle (const char *mangled, int options)
|
1997-08-21 22:57:35 +00:00
|
|
|
{
|
1998-04-22 08:04:13 +00:00
|
|
|
char *ret;
|
2001-12-06 21:56:15 +00:00
|
|
|
|
|
|
|
if (current_demangling_style == no_demangling)
|
|
|
|
return xstrdup (mangled);
|
|
|
|
|
Remove support for demangling GCC 2.x era mangling schemes.
libiberty/
* cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname,
internal_cplus_demangle, and all subroutines.
(libiberty_demanglers): Remove entries for ancient GNU (pre-3.0),
Lucid, ARM, HP, and EDG demangling styles.
(cplus_demangle): Remove 'work' variable. Don't call
internal_cplus_demangle.
include/
* demangle.h: Remove support for ancient GNU (pre-3.0), Lucid,
ARM, HP, and EDG demangling styles.
From-SVN: r267363
2018-12-23 00:06:34 +00:00
|
|
|
if ((options & DMGL_STYLE_MASK) == 0)
|
|
|
|
options |= (int) current_demangling_style & DMGL_STYLE_MASK;
|
1998-04-22 08:04:13 +00:00
|
|
|
|
2019-11-16 15:32:50 +00:00
|
|
|
/* The Rust demangling is implemented elsewhere.
|
|
|
|
Legacy Rust symbols overlap with GNU_V3, so try Rust first. */
|
|
|
|
if (RUST_DEMANGLING || AUTO_DEMANGLING)
|
|
|
|
{
|
|
|
|
ret = rust_demangle (mangled, options);
|
|
|
|
if (ret || RUST_DEMANGLING)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-12-04 17:11:17 +00:00
|
|
|
/* The V3 ABI demangling is implemented elsewhere. */
|
2019-11-16 15:32:50 +00:00
|
|
|
if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
|
2000-12-04 17:11:17 +00:00
|
|
|
{
|
Remove support for demangling GCC 2.x era mangling schemes.
libiberty/
* cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname,
internal_cplus_demangle, and all subroutines.
(libiberty_demanglers): Remove entries for ancient GNU (pre-3.0),
Lucid, ARM, HP, and EDG demangling styles.
(cplus_demangle): Remove 'work' variable. Don't call
internal_cplus_demangle.
include/
* demangle.h: Remove support for ancient GNU (pre-3.0), Lucid,
ARM, HP, and EDG demangling styles.
From-SVN: r267363
2018-12-23 00:06:34 +00:00
|
|
|
ret = cplus_demangle_v3 (mangled, options);
|
2019-11-16 15:32:50 +00:00
|
|
|
if (ret || GNU_V3_DEMANGLING)
|
2000-12-04 17:11:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2000-06-05 02:28:41 +00:00
|
|
|
|
2001-02-02 00:27:39 +00:00
|
|
|
if (JAVA_DEMANGLING)
|
|
|
|
{
|
|
|
|
ret = java_demangle_v3 (mangled);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-11-15 11:54:53 +00:00
|
|
|
if (GNAT_DEMANGLING)
|
2010-01-11 11:38:35 +00:00
|
|
|
return ada_demangle (mangled, options);
|
2000-11-15 11:54:53 +00:00
|
|
|
|
2024-03-30 19:48:30 +00:00
|
|
|
if (DLANG_DEMANGLING || AUTO_DEMANGLING)
|
2014-09-23 18:36:14 +00:00
|
|
|
{
|
|
|
|
ret = dlang_demangle (mangled, options);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1998-04-22 08:04:13 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
/* Demangle ada names. The encoding is documented in gcc/ada/exp_dbug.ads. */
|
1999-01-14 12:09:01 +00:00
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
char *
|
Convert libiberty to use ISO C prototype style 3/n.
* cplus-dem.c (set_cplus_marker_for_demangling, consume_count,
consume_count_with_underscores, code_for_qualifier,
qualifier_string, demangle_qualifier, cplus_demangle_opname,
cplus_mangle_opname, cplus_demangle_set_style,
cplus_demangle_name_to_style, cplus_demangle, grow_vect,
ada_demangle, internal_cplus_demangle, squangle_mop_up,
work_stuff_copy_to_from, delete_non_B_K_work_stuff,
delete_work_stuff, mop_up, demangle_signature,
demangle_method_args, demangle_template_template_parm,
demangle_expression, demangle_integral_value,
demangle_real_value, demangle_template_value_parm,
demangle_template, arm_pt, demangle_arm_hp_template,
demangle_class_name, demangle_class,
iterate_demangle_function,
demangle_prefix, gnu_special, recursively_demangle,
arm_special,
demangle_qualified, get_count, do_type, demangle_fund_type,
do_hpacc_template_const_value, do_hpacc_template_literal,
snarf_numeric_literal, do_arg, remember_type, remember_Ktype,
register_Btype, remember_Btype, forget_B_and_K_types,
forget_types, demangle_args, demangle_nested_args,
demangle_function_name, string_need, string_delete,
string_init,
string_clear, string_empty, string_append, string_appends,
string_appendn, string_prepend, string_prepends,
string_prependn,
string_append_template_idx): Use ISO C prootype style.
* cp-demint.c (cplus_demangle_fill_component,
cplus_demangle_fill_builtin_type,
cplus_demangle_fill_operator,
cplus_demangle_v3_components): Likewise.
From-SVN: r97109
2005-03-27 05:00:12 +00:00
|
|
|
ada_demangle (const char *mangled, int option ATTRIBUTE_UNUSED)
|
2000-11-15 11:54:53 +00:00
|
|
|
{
|
|
|
|
int len0;
|
|
|
|
const char* p;
|
2010-01-11 11:38:35 +00:00
|
|
|
char *d;
|
2016-11-01 23:13:10 +00:00
|
|
|
char *demangled = NULL;
|
2000-11-15 11:54:53 +00:00
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
/* Discard leading _ada_, which is used for library level subprograms. */
|
2000-11-15 11:54:53 +00:00
|
|
|
if (strncmp (mangled, "_ada_", 5) == 0)
|
2010-01-11 11:38:35 +00:00
|
|
|
mangled += 5;
|
|
|
|
|
|
|
|
/* All ada unit names are lower-case. */
|
|
|
|
if (!ISLOWER (mangled[0]))
|
|
|
|
goto unknown;
|
|
|
|
|
|
|
|
/* Most of the demangling will trivially remove chars. Operator names
|
2024-10-31 16:57:45 +00:00
|
|
|
may add one char but because they are always preceded by '__' which is
|
2010-09-22 09:26:03 +00:00
|
|
|
replaced by '.', they eventually never expand the size.
|
|
|
|
A few special names such as '___elabs' add a few chars (at most 7), but
|
|
|
|
they occur only once. */
|
|
|
|
len0 = strlen (mangled) + 7 + 1;
|
2010-01-11 11:38:35 +00:00
|
|
|
demangled = XNEWVEC (char, len0);
|
2000-11-15 11:54:53 +00:00
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
d = demangled;
|
|
|
|
p = mangled;
|
|
|
|
while (1)
|
2000-11-15 11:54:53 +00:00
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
/* An entity names is expected. */
|
2010-01-11 11:38:35 +00:00
|
|
|
if (ISLOWER (*p))
|
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
/* An identifier, which is always lower case. */
|
2010-01-11 11:38:35 +00:00
|
|
|
do
|
|
|
|
*d++ = *p++;
|
|
|
|
while (ISLOWER(*p) || ISDIGIT (*p)
|
|
|
|
|| (p[0] == '_' && (ISLOWER (p[1]) || ISDIGIT (p[1]))));
|
|
|
|
}
|
|
|
|
else if (p[0] == 'O')
|
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
/* An operator name. */
|
2010-01-11 11:38:35 +00:00
|
|
|
static const char * const operators[][2] =
|
|
|
|
{{"Oabs", "abs"}, {"Oand", "and"}, {"Omod", "mod"},
|
|
|
|
{"Onot", "not"}, {"Oor", "or"}, {"Orem", "rem"},
|
|
|
|
{"Oxor", "xor"}, {"Oeq", "="}, {"One", "/="},
|
|
|
|
{"Olt", "<"}, {"Ole", "<="}, {"Ogt", ">"},
|
|
|
|
{"Oge", ">="}, {"Oadd", "+"}, {"Osubtract", "-"},
|
|
|
|
{"Oconcat", "&"}, {"Omultiply", "*"}, {"Odivide", "/"},
|
|
|
|
{"Oexpon", "**"}, {NULL, NULL}};
|
|
|
|
int k;
|
|
|
|
|
2010-09-22 09:26:03 +00:00
|
|
|
for (k = 0; operators[k][0] != NULL; k++)
|
2010-01-11 11:38:35 +00:00
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
size_t slen = strlen (operators[k][0]);
|
|
|
|
if (strncmp (p, operators[k][0], slen) == 0)
|
2010-01-11 11:38:35 +00:00
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
p += slen;
|
|
|
|
slen = strlen (operators[k][1]);
|
2010-01-11 11:38:35 +00:00
|
|
|
*d++ = '"';
|
2010-09-22 09:26:03 +00:00
|
|
|
memcpy (d, operators[k][1], slen);
|
|
|
|
d += slen;
|
2010-01-11 11:38:35 +00:00
|
|
|
*d++ = '"';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Operator not found. */
|
2010-09-22 09:26:03 +00:00
|
|
|
if (operators[k][0] == NULL)
|
2010-01-11 11:38:35 +00:00
|
|
|
goto unknown;
|
|
|
|
}
|
2000-11-15 11:54:53 +00:00
|
|
|
else
|
2010-01-11 11:38:35 +00:00
|
|
|
{
|
|
|
|
/* Not a GNAT encoding. */
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
|
2010-09-22 09:26:03 +00:00
|
|
|
/* The name can be directly followed by some uppercase letters. */
|
|
|
|
if (p[0] == 'T' && p[1] == 'K')
|
|
|
|
{
|
|
|
|
/* Task stuff. */
|
|
|
|
if (p[2] == 'B' && p[3] == 0)
|
|
|
|
{
|
|
|
|
/* Subprogram for task body. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (p[2] == '_' && p[3] == '_')
|
|
|
|
{
|
|
|
|
/* Inner declarations in a task. */
|
|
|
|
p += 4;
|
|
|
|
*d++ = '.';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (p[0] == 'E' && p[1] == 0)
|
|
|
|
{
|
|
|
|
/* Exception name. */
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if ((p[0] == 'P' || p[0] == 'N') && p[1] == 0)
|
|
|
|
{
|
|
|
|
/* Protected type subprogram. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((*p == 'N' || *p == 'S') && p[1] == 0)
|
|
|
|
{
|
|
|
|
/* Enumerated type name table. */
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (p[0] == 'X')
|
|
|
|
{
|
|
|
|
/* Body nested. */
|
|
|
|
p++;
|
|
|
|
while (p[0] == 'n' || p[0] == 'b')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (p[0] == 'S' && p[1] != 0 && (p[2] == '_' || p[2] == 0))
|
|
|
|
{
|
|
|
|
/* Stream operations. */
|
|
|
|
const char *name;
|
|
|
|
switch (p[1])
|
|
|
|
{
|
|
|
|
case 'R':
|
|
|
|
name = "'Read";
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
name = "'Write";
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
name = "'Input";
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
name = "'Output";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
p += 2;
|
|
|
|
strcpy (d, name);
|
|
|
|
d += strlen (name);
|
|
|
|
}
|
|
|
|
else if (p[0] == 'D')
|
|
|
|
{
|
|
|
|
/* Controlled type operation. */
|
|
|
|
const char *name;
|
|
|
|
switch (p[1])
|
|
|
|
{
|
|
|
|
case 'F':
|
|
|
|
name = ".Finalize";
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
name = ".Adjust";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
strcpy (d, name);
|
|
|
|
d += strlen (name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
if (p[0] == '_')
|
|
|
|
{
|
|
|
|
/* Separator. */
|
|
|
|
if (p[1] == '_')
|
|
|
|
{
|
|
|
|
/* Standard separator. Handled first. */
|
|
|
|
p += 2;
|
2010-09-22 09:26:03 +00:00
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
if (ISDIGIT (*p))
|
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
/* Overloading number. */
|
2010-01-11 11:38:35 +00:00
|
|
|
do
|
|
|
|
p++;
|
|
|
|
while (ISDIGIT (*p) || (p[0] == '_' && ISDIGIT (p[1])));
|
2010-09-22 09:26:03 +00:00
|
|
|
if (*p == 'X')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
while (p[0] == 'n' || p[0] == 'b')
|
|
|
|
p++;
|
|
|
|
}
|
2010-01-11 11:38:35 +00:00
|
|
|
}
|
2010-09-22 09:26:03 +00:00
|
|
|
else if (p[0] == '_' && p[1] != '_')
|
2010-01-11 11:38:35 +00:00
|
|
|
{
|
2010-09-22 09:26:03 +00:00
|
|
|
/* Special names. */
|
|
|
|
static const char * const special[][2] = {
|
|
|
|
{ "_elabb", "'Elab_Body" },
|
|
|
|
{ "_elabs", "'Elab_Spec" },
|
|
|
|
{ "_size", "'Size" },
|
|
|
|
{ "_alignment", "'Alignment" },
|
|
|
|
{ "_assign", ".\":=\"" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for (k = 0; special[k][0] != NULL; k++)
|
|
|
|
{
|
|
|
|
size_t slen = strlen (special[k][0]);
|
|
|
|
if (strncmp (p, special[k][0], slen) == 0)
|
|
|
|
{
|
|
|
|
p += slen;
|
|
|
|
slen = strlen (special[k][1]);
|
|
|
|
memcpy (d, special[k][1], slen);
|
|
|
|
d += slen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (special[k][0] != NULL)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
goto unknown;
|
2010-01-11 11:38:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*d++ = '.';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (p[1] == 'B' || p[1] == 'E')
|
|
|
|
{
|
|
|
|
/* Entry Body or barrier Evaluation. */
|
|
|
|
p += 2;
|
|
|
|
while (ISDIGIT (*p))
|
|
|
|
p++;
|
|
|
|
if (p[0] == 's' && p[1] == 0)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p[0] == '.' && ISDIGIT (p[1]))
|
|
|
|
{
|
|
|
|
/* Nested subprogram. */
|
|
|
|
p += 2;
|
|
|
|
while (ISDIGIT (*p))
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (*p == 0)
|
|
|
|
{
|
|
|
|
/* End of mangled name. */
|
|
|
|
break;
|
|
|
|
}
|
2000-11-15 11:54:53 +00:00
|
|
|
else
|
2010-01-11 11:38:35 +00:00
|
|
|
goto unknown;
|
2000-11-15 11:54:53 +00:00
|
|
|
}
|
2010-01-11 11:38:35 +00:00
|
|
|
*d = 0;
|
|
|
|
return demangled;
|
2000-11-15 11:54:53 +00:00
|
|
|
|
2010-01-11 11:38:35 +00:00
|
|
|
unknown:
|
2016-11-01 23:13:10 +00:00
|
|
|
XDELETEVEC (demangled);
|
2010-01-11 11:38:35 +00:00
|
|
|
len0 = strlen (mangled);
|
|
|
|
demangled = XNEWVEC (char, len0 + 3);
|
2002-10-06 19:29:24 +00:00
|
|
|
|
2000-11-15 11:54:53 +00:00
|
|
|
if (mangled[0] == '<')
|
|
|
|
strcpy (demangled, mangled);
|
|
|
|
else
|
|
|
|
sprintf (demangled, "<%s>", mangled);
|
|
|
|
|
|
|
|
return demangled;
|
|
|
|
}
|