2003-11-21 18:42:45 +01:00
|
|
|
/* Demangler for g++ V3 ABI.
|
2005-04-02 19:18:43 +02:00
|
|
|
Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
|
2003-11-21 18:42:45 +01:00
|
|
|
Written by Ian Lance Taylor <ian@wasabisystems.com>.
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-08-12 14:23:42 +02:00
|
|
|
This file is part of the libiberty library, which is part of GCC.
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-08-12 14:23:42 +02:00
|
|
|
This file is free software; you can redistribute it and/or modify
|
2000-06-15 22:56:25 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2002-03-12 22:11:11 +01:00
|
|
|
In addition to the permissions in the GNU 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 General 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.)
|
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-10 17:33:34 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-06-15 22:56:25 +02:00
|
|
|
*/
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
/* This code implements a demangler for the g++ V3 ABI. The ABI is
|
|
|
|
described on this web page:
|
|
|
|
http://www.codesourcery.com/cxx-abi/abi.html#mangling
|
|
|
|
|
|
|
|
This code was written while looking at the demangler written by
|
|
|
|
Alex Samuel <samuel@codesourcery.com>.
|
|
|
|
|
|
|
|
This code first pulls the mangled name apart into a list of
|
|
|
|
components, and then walks the list generating the demangled
|
|
|
|
name.
|
|
|
|
|
|
|
|
This file will normally define the following functions, q.v.:
|
|
|
|
char *cplus_demangle_v3(const char *mangled, int options)
|
|
|
|
char *java_demangle_v3(const char *mangled)
|
|
|
|
enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
|
|
|
|
enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
Also, the interface to the component list is public, and defined in
|
|
|
|
demangle.h. The interface consists of these types, which are
|
|
|
|
defined in demangle.h:
|
|
|
|
enum demangle_component_type
|
|
|
|
struct demangle_component
|
|
|
|
and these functions defined in this file:
|
|
|
|
cplus_demangle_fill_name
|
|
|
|
cplus_demangle_fill_extended_operator
|
|
|
|
cplus_demangle_fill_ctor
|
|
|
|
cplus_demangle_fill_dtor
|
|
|
|
cplus_demangle_print
|
|
|
|
and other functions defined in the file cp-demint.c.
|
|
|
|
|
|
|
|
This file also defines some other functions and variables which are
|
|
|
|
only to be used by the file cp-demint.c.
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
Preprocessor macros you can define while compiling this file:
|
|
|
|
|
|
|
|
IN_LIBGCC2
|
|
|
|
If defined, this file defines the following function, q.v.:
|
|
|
|
char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
|
|
|
|
int *status)
|
|
|
|
instead of cplus_demangle_v3() and java_demangle_v3().
|
|
|
|
|
|
|
|
IN_GLIBCPP_V3
|
2004-01-12 22:24:38 +01:00
|
|
|
If defined, this file defines only __cxa_demangle(), and no other
|
|
|
|
publically visible functions or variables.
|
2003-12-04 21:03:39 +01:00
|
|
|
|
|
|
|
STANDALONE_DEMANGLER
|
|
|
|
If defined, this file defines a main() function which demangles
|
|
|
|
any arguments, or, if none, demangles stdin.
|
|
|
|
|
|
|
|
CP_DEMANGLE_DEBUG
|
|
|
|
If defined, turns on debugging mode, which prints information on
|
|
|
|
stdout about the mangled string. This is not generally useful.
|
|
|
|
*/
|
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#include <stdio.h>
|
2000-07-23 17:58:11 +02:00
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ansidecl.h"
|
|
|
|
#include "libiberty.h"
|
|
|
|
#include "demangle.h"
|
2004-01-12 22:24:38 +01:00
|
|
|
#include "cp-demangle.h"
|
|
|
|
|
|
|
|
/* If IN_GLIBCPP_V3 is defined, some functions are made static. We
|
|
|
|
also rename them via #define to avoid compiler errors when the
|
|
|
|
static definition conflicts with the extern declaration in a header
|
|
|
|
file. */
|
|
|
|
#ifdef IN_GLIBCPP_V3
|
|
|
|
|
|
|
|
#define CP_STATIC_IF_GLIBCPP_V3 static
|
|
|
|
|
|
|
|
#define cplus_demangle_fill_name d_fill_name
|
2005-03-27 07:28:42 +02:00
|
|
|
static int d_fill_name (struct demangle_component *, const char *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_fill_extended_operator d_fill_extended_operator
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_fill_extended_operator (struct demangle_component *, int,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_fill_ctor d_fill_ctor
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_fill_ctor (struct demangle_component *, enum gnu_v3_ctor_kinds,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_fill_dtor d_fill_dtor
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_fill_dtor (struct demangle_component *, enum gnu_v3_dtor_kinds,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_mangled_name d_mangled_name
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_mangled_name (struct d_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_type d_type
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_type (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_print d_print
|
2005-03-27 07:28:42 +02:00
|
|
|
static char *d_print (int, const struct demangle_component *, int, size_t *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#define cplus_demangle_init_info d_init_info
|
2005-03-27 07:28:42 +02:00
|
|
|
static void d_init_info (const char *, int, size_t, struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
#else /* ! defined(IN_GLIBCPP_V3) */
|
|
|
|
#define CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
#endif /* ! defined(IN_GLIBCPP_V3) */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* See if the compiler supports dynamic arrays. */
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define CP_DYNAMIC_ARRAYS
|
|
|
|
#else
|
|
|
|
#ifdef __STDC__
|
|
|
|
#ifdef __STDC_VERSION__
|
|
|
|
#if __STDC_VERSION__ >= 199901L
|
|
|
|
#define CP_DYNAMIC_ARRAYS
|
|
|
|
#endif /* __STDC__VERSION >= 199901L */
|
|
|
|
#endif /* defined (__STDC_VERSION__) */
|
|
|
|
#endif /* defined (__STDC__) */
|
|
|
|
#endif /* ! defined (__GNUC__) */
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
/* We avoid pulling in the ctype tables, to prevent pulling in
|
|
|
|
additional unresolved symbols when this code is used in a library.
|
|
|
|
FIXME: Is this really a valid reason? This comes from the original
|
|
|
|
V3 demangler code.
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
As of this writing this file has the following undefined references
|
|
|
|
when compiled with -DIN_GLIBCPP_V3: malloc, realloc, free, memcpy,
|
|
|
|
strcpy, strcat, strlen. */
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
|
2003-12-04 21:03:39 +01:00
|
|
|
#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
|
|
|
|
#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2000-10-12 04:16:48 +02:00
|
|
|
/* The prefix prepended by GCC to an identifier represnting the
|
|
|
|
anonymous namespace. */
|
|
|
|
#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
|
2003-11-21 18:42:45 +01:00
|
|
|
#define ANONYMOUS_NAMESPACE_PREFIX_LEN \
|
|
|
|
(sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-12-15 18:45:42 +01:00
|
|
|
/* Information we keep for the standard substitutions. */
|
|
|
|
|
|
|
|
struct d_standard_sub_info
|
|
|
|
{
|
|
|
|
/* The code for this substitution. */
|
|
|
|
char code;
|
|
|
|
/* The simple string it expands to. */
|
|
|
|
const char *simple_expansion;
|
2003-12-22 17:03:32 +01:00
|
|
|
/* The length of the simple expansion. */
|
|
|
|
int simple_len;
|
2003-12-15 18:45:42 +01:00
|
|
|
/* The results of a full, verbose, expansion. This is used when
|
|
|
|
qualifying a constructor/destructor, or when in verbose mode. */
|
|
|
|
const char *full_expansion;
|
2003-12-22 17:03:32 +01:00
|
|
|
/* The length of the full expansion. */
|
|
|
|
int full_len;
|
2003-12-15 18:45:42 +01:00
|
|
|
/* What to set the last_name field of d_info to; NULL if we should
|
|
|
|
not set it. This is only relevant when qualifying a
|
|
|
|
constructor/destructor. */
|
|
|
|
const char *set_last_name;
|
2003-12-22 17:03:32 +01:00
|
|
|
/* The length of set_last_name. */
|
|
|
|
int set_last_name_len;
|
2003-12-15 18:45:42 +01:00
|
|
|
};
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
/* Accessors for subtrees of struct demangle_component. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#define d_left(dc) ((dc)->u.s_binary.left)
|
|
|
|
#define d_right(dc) ((dc)->u.s_binary.right)
|
|
|
|
|
|
|
|
/* A list of templates. This is used while printing. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
struct d_print_template
|
|
|
|
{
|
|
|
|
/* Next template on the list. */
|
|
|
|
struct d_print_template *next;
|
|
|
|
/* This template. */
|
2005-05-24 23:01:33 +02:00
|
|
|
const struct demangle_component *template_decl;
|
2003-11-21 18:42:45 +01:00
|
|
|
};
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* A list of type modifiers. This is used while printing. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
struct d_print_mod
|
|
|
|
{
|
|
|
|
/* Next modifier on the list. These are in the reverse of the order
|
|
|
|
in which they appeared in the mangled string. */
|
|
|
|
struct d_print_mod *next;
|
|
|
|
/* The modifier. */
|
2004-01-12 22:24:38 +01:00
|
|
|
const struct demangle_component *mod;
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Whether this modifier was printed. */
|
|
|
|
int printed;
|
2003-11-27 02:17:34 +01:00
|
|
|
/* The list of templates which applies to this modifier. */
|
|
|
|
struct d_print_template *templates;
|
2003-11-21 18:42:45 +01:00
|
|
|
};
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* We use this structure to hold information during printing. */
|
|
|
|
|
|
|
|
struct d_print_info
|
|
|
|
{
|
|
|
|
/* The options passed to the demangler. */
|
|
|
|
int options;
|
|
|
|
/* Buffer holding the result. */
|
|
|
|
char *buf;
|
|
|
|
/* Current length of data in buffer. */
|
|
|
|
size_t len;
|
|
|
|
/* Allocated size of buffer. */
|
|
|
|
size_t alc;
|
|
|
|
/* The current list of templates, if any. */
|
|
|
|
struct d_print_template *templates;
|
|
|
|
/* The current list of modifiers (e.g., pointer, reference, etc.),
|
|
|
|
if any. */
|
|
|
|
struct d_print_mod *modifiers;
|
|
|
|
/* Set to 1 if we had a memory allocation failure. */
|
|
|
|
int allocation_failure;
|
|
|
|
};
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#define d_print_saw_error(dpi) ((dpi)->buf == NULL)
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#define d_append_char(dpi, c) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if ((dpi)->buf != NULL && (dpi)->len < (dpi)->alc) \
|
|
|
|
(dpi)->buf[(dpi)->len++] = (c); \
|
|
|
|
else \
|
|
|
|
d_print_append_char ((dpi), (c)); \
|
|
|
|
} \
|
|
|
|
while (0)
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#define d_append_buffer(dpi, s, l) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if ((dpi)->buf != NULL && (dpi)->len + (l) <= (dpi)->alc) \
|
|
|
|
{ \
|
|
|
|
memcpy ((dpi)->buf + (dpi)->len, (s), (l)); \
|
|
|
|
(dpi)->len += l; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
d_print_append_buffer ((dpi), (s), (l)); \
|
|
|
|
} \
|
|
|
|
while (0)
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
#define d_append_string_constant(dpi, s) \
|
|
|
|
d_append_buffer (dpi, (s), sizeof (s) - 1)
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
#define d_last_char(dpi) \
|
|
|
|
((dpi)->buf == NULL || (dpi)->len == 0 ? '\0' : (dpi)->buf[(dpi)->len - 1])
|
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
#ifdef CP_DEMANGLE_DEBUG
|
2005-03-27 07:28:42 +02:00
|
|
|
static void d_dump (struct demangle_component *, int);
|
2000-06-15 22:56:25 +02:00
|
|
|
#endif
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_empty (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_comp (struct d_info *, enum demangle_component_type,
|
|
|
|
struct demangle_component *,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_name (struct d_info *, const char *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_builtin_type (struct d_info *,
|
|
|
|
const struct demangle_builtin_type_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_operator (struct d_info *,
|
|
|
|
const struct demangle_operator_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_extended_operator (struct d_info *, int,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_ctor (struct d_info *, enum gnu_v3_ctor_kinds,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_dtor (struct d_info *, enum gnu_v3_dtor_kinds,
|
|
|
|
struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_template_param (struct d_info *, long);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_sub (struct d_info *, const char *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
has_return_type (struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
is_ctor_dtor_or_conversion (struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_encoding (struct d_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_nested_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_prefix (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_unqualified_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_source_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static long d_number (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_identifier (struct d_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_operator_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_special_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static int d_call_offset (struct d_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_ctor_dtor_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component **
|
2005-03-27 07:28:42 +02:00
|
|
|
d_cv_qualifiers (struct d_info *, struct demangle_component **, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_function_type (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_bare_function_type (struct d_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_class_enum_type (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_array_type (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_pointer_to_member_type (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_template_param (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_template_args (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_template_arg (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_expression (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_expr_primary (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_local_name (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static int d_discriminator (struct d_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_add_substitution (struct d_info *, struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static struct demangle_component *d_substitution (struct d_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static void d_print_resize (struct d_print_info *, size_t);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static void d_print_append_char (struct d_print_info *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_append_buffer (struct d_print_info *, const char *, size_t);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static void d_print_error (struct d_print_info *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_comp (struct d_print_info *, const struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_java_identifier (struct d_print_info *, const char *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_mod_list (struct d_print_info *, struct d_print_mod *, int);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_mod (struct d_print_info *, const struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_function_type (struct d_print_info *,
|
|
|
|
const struct demangle_component *,
|
|
|
|
struct d_print_mod *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_array_type (struct d_print_info *,
|
|
|
|
const struct demangle_component *,
|
|
|
|
struct d_print_mod *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_expr_op (struct d_print_info *, const struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_cast (struct d_print_info *, const struct demangle_component *);
|
2004-01-12 22:24:38 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
static char *d_demangle (const char *, int, size_t *);
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
#ifdef CP_DEMANGLE_DEBUG
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_dump (struct demangle_component *dc, int indent)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dc == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < indent; ++i)
|
|
|
|
putchar (' ');
|
|
|
|
|
|
|
|
switch (dc->type)
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("template parameter %ld\n", dc->u.s_number.number);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CTOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("constructor %d\n", (int) dc->u.s_ctor.kind);
|
|
|
|
d_dump (dc->u.s_ctor.name, indent + 2);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_DTOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("destructor %d\n", (int) dc->u.s_dtor.kind);
|
|
|
|
d_dump (dc->u.s_dtor.name, indent + 2);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_SUB_STD:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("standard substitution %s\n", dc->u.s_string.string);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_BUILTIN_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("builtin type %s\n", dc->u.s_builtin.type->name);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_OPERATOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("operator %s\n", dc->u.s_operator.op->name);
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("extended operator with %d args\n",
|
|
|
|
dc->u.s_extended_operator.args);
|
|
|
|
d_dump (dc->u.s_extended_operator.name, indent + 2);
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_QUAL_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("qualified name\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_LOCAL_NAME:
|
2003-12-19 23:03:41 +01:00
|
|
|
printf ("local name\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPED_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("typed name\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("template\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VTABLE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("vtable\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VTT:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("VTT\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("construction vtable\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("typeinfo\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("typeinfo name\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO_FN:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("typeinfo function\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_THUNK:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("thunk\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("virtual thunk\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("covariant thunk\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_JAVA_CLASS:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("java class\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_GUARD:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("guard\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_REFTEMP:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("reference temporary\n");
|
|
|
|
break;
|
2005-05-26 01:32:36 +02:00
|
|
|
case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
|
|
|
|
printf ("hidden alias\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("restrict\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VOLATILE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("volatile\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CONST:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("const\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
2003-12-04 21:03:39 +01:00
|
|
|
printf ("restrict this\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
2003-12-04 21:03:39 +01:00
|
|
|
printf ("volatile this\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
2003-12-04 21:03:39 +01:00
|
|
|
printf ("const this\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("vendor type qualifier\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_POINTER:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("pointer\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_REFERENCE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("reference\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_COMPLEX:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("complex\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_IMAGINARY:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("imaginary\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("vendor type\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("function type\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_ARRAY_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("array type\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("pointer to member type\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_ARGLIST:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("argument list\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("template argument list\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CAST:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("cast\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_UNARY:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("unary operator\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_BINARY:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("binary operator\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_BINARY_ARGS:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("binary operator arguments\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TRINARY:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("trinary operator\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TRINARY_ARG1:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("trinary operator arguments 1\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TRINARY_ARG2:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("trinary operator arguments 1\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_LITERAL:
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("literal\n");
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_LITERAL_NEG:
|
2003-12-15 18:45:42 +01:00
|
|
|
printf ("negative literal\n");
|
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_dump (d_left (dc), indent + 2);
|
|
|
|
d_dump (d_right (dc), indent + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CP_DEMANGLE_DEBUG */
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
/* Fill in a DEMANGLE_COMPONENT_NAME. */
|
|
|
|
|
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
int
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
if (p == NULL || s == NULL || len == 0)
|
|
|
|
return 0;
|
|
|
|
p->type = DEMANGLE_COMPONENT_NAME;
|
|
|
|
p->u.s_name.s = s;
|
|
|
|
p->u.s_name.len = len;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
|
|
|
|
|
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
int
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_fill_extended_operator (struct demangle_component *p, int args,
|
|
|
|
struct demangle_component *name)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
if (p == NULL || args < 0 || name == NULL)
|
|
|
|
return 0;
|
|
|
|
p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
|
|
|
|
p->u.s_extended_operator.args = args;
|
|
|
|
p->u.s_extended_operator.name = name;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in a DEMANGLE_COMPONENT_CTOR. */
|
|
|
|
|
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
int
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_fill_ctor (struct demangle_component *p,
|
|
|
|
enum gnu_v3_ctor_kinds kind,
|
|
|
|
struct demangle_component *name)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
if (p == NULL
|
|
|
|
|| name == NULL
|
|
|
|
|| (kind < gnu_v3_complete_object_ctor
|
|
|
|
&& kind > gnu_v3_complete_object_allocating_ctor))
|
|
|
|
return 0;
|
|
|
|
p->type = DEMANGLE_COMPONENT_CTOR;
|
|
|
|
p->u.s_ctor.kind = kind;
|
|
|
|
p->u.s_ctor.name = name;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in a DEMANGLE_COMPONENT_DTOR. */
|
|
|
|
|
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
int
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_fill_dtor (struct demangle_component *p,
|
|
|
|
enum gnu_v3_dtor_kinds kind,
|
|
|
|
struct demangle_component *name)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
if (p == NULL
|
|
|
|
|| name == NULL
|
|
|
|
|| (kind < gnu_v3_deleting_dtor
|
|
|
|
&& kind > gnu_v3_base_object_dtor))
|
|
|
|
return 0;
|
|
|
|
p->type = DEMANGLE_COMPONENT_DTOR;
|
|
|
|
p->u.s_dtor.kind = kind;
|
|
|
|
p->u.s_dtor.name = name;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new component. */
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_empty (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
if (di->next_comp >= di->num_comps)
|
|
|
|
return NULL;
|
|
|
|
p = &di->comps[di->next_comp];
|
|
|
|
++di->next_comp;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a new generic component. */
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_comp (struct d_info *di, enum demangle_component_type type,
|
|
|
|
struct demangle_component *left,
|
|
|
|
struct demangle_component *right)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
/* We check for errors here. A typical error would be a NULL return
|
2003-11-27 02:17:34 +01:00
|
|
|
from a subroutine. We catch those here, and return NULL
|
|
|
|
upward. */
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
/* These types require two parameters. */
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_QUAL_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_LOCAL_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_TYPED_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE:
|
2004-01-13 22:34:31 +01:00
|
|
|
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
|
|
|
|
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
|
|
|
|
case DEMANGLE_COMPONENT_UNARY:
|
|
|
|
case DEMANGLE_COMPONENT_BINARY:
|
|
|
|
case DEMANGLE_COMPONENT_BINARY_ARGS:
|
|
|
|
case DEMANGLE_COMPONENT_TRINARY:
|
|
|
|
case DEMANGLE_COMPONENT_TRINARY_ARG1:
|
|
|
|
case DEMANGLE_COMPONENT_TRINARY_ARG2:
|
|
|
|
case DEMANGLE_COMPONENT_LITERAL:
|
|
|
|
case DEMANGLE_COMPONENT_LITERAL_NEG:
|
2003-11-21 18:42:45 +01:00
|
|
|
if (left == NULL || right == NULL)
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* These types only require one parameter. */
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VTABLE:
|
|
|
|
case DEMANGLE_COMPONENT_VTT:
|
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO:
|
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO_FN:
|
|
|
|
case DEMANGLE_COMPONENT_THUNK:
|
|
|
|
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
|
|
|
|
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
|
|
|
|
case DEMANGLE_COMPONENT_JAVA_CLASS:
|
|
|
|
case DEMANGLE_COMPONENT_GUARD:
|
|
|
|
case DEMANGLE_COMPONENT_REFTEMP:
|
2005-05-26 01:32:36 +02:00
|
|
|
case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_POINTER:
|
|
|
|
case DEMANGLE_COMPONENT_REFERENCE:
|
|
|
|
case DEMANGLE_COMPONENT_COMPLEX:
|
|
|
|
case DEMANGLE_COMPONENT_IMAGINARY:
|
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE:
|
|
|
|
case DEMANGLE_COMPONENT_ARGLIST:
|
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
|
|
|
|
case DEMANGLE_COMPONENT_CAST:
|
2003-11-21 18:42:45 +01:00
|
|
|
if (left == NULL)
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* This needs a right parameter, but the left parameter can be
|
|
|
|
empty. */
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_ARRAY_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
if (right == NULL)
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* These are allowed to have no parameters--in some cases they
|
|
|
|
will be filled in later. */
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
|
|
|
|
case DEMANGLE_COMPONENT_RESTRICT:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE:
|
|
|
|
case DEMANGLE_COMPONENT_CONST:
|
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Other types should not be seen here. */
|
|
|
|
default:
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (p != NULL)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
p->type = type;
|
2003-11-21 18:42:45 +01:00
|
|
|
p->u.s_binary.left = left;
|
|
|
|
p->u.s_binary.right = right;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new name component. */
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_name (struct d_info *di, const char *s, int len)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
|
|
|
if (! cplus_demangle_fill_name (p, s, len))
|
2003-12-04 21:03:39 +01:00
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new builtin type component. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_builtin_type (struct d_info *di,
|
|
|
|
const struct demangle_builtin_type_info *type)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
if (type == NULL)
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (p != NULL)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
|
|
|
|
p->u.s_builtin.type = type;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new operator component. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_operator (struct d_info *di, const struct demangle_operator_info *op)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (p != NULL)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
p->type = DEMANGLE_COMPONENT_OPERATOR;
|
|
|
|
p->u.s_operator.op = op;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new extended operator component. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_extended_operator (struct d_info *di, int args,
|
|
|
|
struct demangle_component *name)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
|
|
|
if (! cplus_demangle_fill_extended_operator (p, args, name))
|
2003-11-27 02:17:34 +01:00
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new constructor component. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_ctor (struct d_info *di, enum gnu_v3_ctor_kinds kind,
|
|
|
|
struct demangle_component *name)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
|
|
|
if (! cplus_demangle_fill_ctor (p, kind, name))
|
2003-11-27 02:17:34 +01:00
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new destructor component. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_dtor (struct d_info *di, enum gnu_v3_dtor_kinds kind,
|
|
|
|
struct demangle_component *name)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
|
|
|
if (! cplus_demangle_fill_dtor (p, kind, name))
|
2003-11-27 02:17:34 +01:00
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new template parameter. */
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_template_param (struct d_info *di, long i)
|
2000-10-23 17:30:54 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (p != NULL)
|
2004-01-12 22:24:38 +01:00
|
|
|
{
|
|
|
|
p->type = DEMANGLE_COMPONENT_TEMPLATE_PARAM;
|
|
|
|
p->u.s_number.number = i;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-10-23 17:30:54 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new standard substitution component. */
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_make_sub (struct d_info *di, const char *name, int len)
|
2000-10-23 17:30:54 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *p;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
p = d_make_empty (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (p != NULL)
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
p->type = DEMANGLE_COMPONENT_SUB_STD;
|
2003-12-22 17:03:32 +01:00
|
|
|
p->u.s_string.string = name;
|
|
|
|
p->u.s_string.len = len;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return p;
|
2000-10-23 17:30:54 +02:00
|
|
|
}
|
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
/* <mangled-name> ::= _Z <encoding>
|
|
|
|
|
|
|
|
TOP_LEVEL is non-zero when called at the top level. */
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_mangled_name (struct d_info *di, int top_level)
|
2000-10-23 17:30:54 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != '_')
|
|
|
|
return NULL;
|
|
|
|
if (d_next_char (di) != 'Z')
|
|
|
|
return NULL;
|
2003-11-27 02:17:34 +01:00
|
|
|
return d_encoding (di, top_level);
|
2000-10-23 17:30:54 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Return whether a function should have a return type. The argument
|
|
|
|
is the function name, which may be qualified in various ways. The
|
|
|
|
rules are that template functions have return types with some
|
|
|
|
exceptions, function types which are not part of a function name
|
|
|
|
mangling have return types with some exceptions, and non-template
|
|
|
|
function names do not have return types. The exceptions are that
|
|
|
|
constructors, destructors, and conversion operators do not have
|
|
|
|
return types. */
|
2000-10-23 17:30:54 +02:00
|
|
|
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
has_return_type (struct demangle_component *dc)
|
2000-10-23 17:30:54 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dc == NULL)
|
|
|
|
return 0;
|
|
|
|
switch (dc->type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return 0;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE:
|
2003-11-21 18:42:45 +01:00
|
|
|
return ! is_ctor_dtor_or_conversion (d_left (dc));
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
2003-11-21 23:01:27 +01:00
|
|
|
return has_return_type (d_left (dc));
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-10-23 17:30:54 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Return whether a name is a constructor, a destructor, or a
|
|
|
|
conversion operator. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
is_ctor_dtor_or_conversion (struct demangle_component *dc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dc == NULL)
|
|
|
|
return 0;
|
|
|
|
switch (dc->type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return 0;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_QUAL_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_LOCAL_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
return is_ctor_dtor_or_conversion (d_right (dc));
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CTOR:
|
|
|
|
case DEMANGLE_COMPONENT_DTOR:
|
|
|
|
case DEMANGLE_COMPONENT_CAST:
|
2003-11-21 18:42:45 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <encoding> ::= <(function) name> <bare-function-type>
|
|
|
|
::= <(data) name>
|
2003-11-24 20:33:33 +01:00
|
|
|
::= <special-name>
|
|
|
|
|
|
|
|
TOP_LEVEL is non-zero when called at the top level, in which case
|
|
|
|
if DMGL_PARAMS is not set we do not demangle the function
|
|
|
|
parameters. We only set this at the top level, because otherwise
|
|
|
|
we would not correctly demangle names in local scopes. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_encoding (struct d_info *di, int top_level)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char peek = d_peek_char (di);
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (peek == 'G' || peek == 'T')
|
|
|
|
return d_special_name (di);
|
|
|
|
else
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dc;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
dc = d_name (di);
|
2003-11-27 02:17:34 +01:00
|
|
|
|
|
|
|
if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)
|
|
|
|
{
|
|
|
|
/* Strip off any initial CV-qualifiers, as they really apply
|
|
|
|
to the `this' parameter, and they were not output by the
|
|
|
|
v2 demangler without DMGL_PARAMS. */
|
2004-01-12 22:24:38 +01:00
|
|
|
while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
|| dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
|| dc->type == DEMANGLE_COMPONENT_CONST_THIS)
|
2003-11-27 02:17:34 +01:00
|
|
|
dc = d_left (dc);
|
2004-01-02 22:11:34 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
/* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
|
|
|
|
there may be CV-qualifiers on its right argument which
|
|
|
|
really apply here; this happens when parsing a class
|
|
|
|
which is local to a function. */
|
|
|
|
if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
|
2004-01-02 22:11:34 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dcr;
|
2004-01-02 22:11:34 +01:00
|
|
|
|
|
|
|
dcr = d_right (dc);
|
2004-01-12 22:24:38 +01:00
|
|
|
while (dcr->type == DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
|| dcr->type == DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
|| dcr->type == DEMANGLE_COMPONENT_CONST_THIS)
|
2004-01-02 22:11:34 +01:00
|
|
|
dcr = d_left (dcr);
|
|
|
|
dc->u.s_binary.right = dcr;
|
|
|
|
}
|
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
return dc;
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
peek = d_peek_char (di);
|
2003-11-27 02:17:34 +01:00
|
|
|
if (peek == '\0' || peek == 'E')
|
2003-11-21 18:42:45 +01:00
|
|
|
return dc;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc,
|
2003-11-21 18:42:45 +01:00
|
|
|
d_bare_function_type (di, has_return_type (dc)));
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* <name> ::= <nested-name>
|
|
|
|
::= <unscoped-name>
|
|
|
|
::= <unscoped-template-name> <template-args>
|
|
|
|
::= <local-name>
|
|
|
|
|
|
|
|
<unscoped-name> ::= <unqualified-name>
|
|
|
|
::= St <unqualified-name>
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
<unscoped-template-name> ::= <unscoped-name>
|
|
|
|
::= <substitution>
|
|
|
|
*/
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_name (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
char peek = d_peek_char (di);
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dc;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
switch (peek)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'N':
|
|
|
|
return d_nested_name (di);
|
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
return d_local_name (di);
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
{
|
|
|
|
int subst;
|
|
|
|
|
|
|
|
if (d_peek_next_char (di) != 't')
|
|
|
|
{
|
2003-12-15 18:45:42 +01:00
|
|
|
dc = d_substitution (di, 0);
|
2003-11-21 18:42:45 +01:00
|
|
|
subst = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d_advance (di, 2);
|
2004-01-12 22:24:38 +01:00
|
|
|
dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,
|
|
|
|
d_make_name (di, "std", 3),
|
2003-11-21 18:42:45 +01:00
|
|
|
d_unqualified_name (di));
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += 3;
|
2003-11-21 18:42:45 +01:00
|
|
|
subst = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d_peek_char (di) != 'I')
|
|
|
|
{
|
|
|
|
/* The grammar does not permit this case to occur if we
|
|
|
|
called d_substitution() above (i.e., subst == 1). We
|
|
|
|
don't bother to check. */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is <template-args>, which means that we just saw
|
|
|
|
<unscoped-template-name>, which is a substitution
|
|
|
|
candidate if we didn't just get it from a
|
|
|
|
substitution. */
|
|
|
|
if (! subst)
|
|
|
|
{
|
|
|
|
if (! d_add_substitution (di, dc))
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-01-12 22:24:38 +01:00
|
|
|
dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
|
|
|
|
d_template_args (di));
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
dc = d_unqualified_name (di);
|
|
|
|
if (d_peek_char (di) == 'I')
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
/* This is <template-args>, which means that we just saw
|
|
|
|
<unscoped-template-name>, which is a substitution
|
|
|
|
candidate. */
|
|
|
|
if (! d_add_substitution (di, dc))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
|
|
|
|
d_template_args (di));
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return dc;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
|
|
|
|
::= N [<CV-qualifiers>] <template-prefix> <template-args> E
|
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_nested_name (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
|
|
|
struct demangle_component **pret;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'N')
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
pret = d_cv_qualifiers (di, &ret, 1);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (pret == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*pret = d_prefix (di);
|
|
|
|
if (*pret == NULL)
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'E')
|
2000-06-15 22:56:25 +02:00
|
|
|
return NULL;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return ret;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <prefix> ::= <prefix> <unqualified-name>
|
|
|
|
::= <template-prefix> <template-args>
|
|
|
|
::= <template-param>
|
|
|
|
::=
|
|
|
|
::= <substitution>
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
<template-prefix> ::= <prefix> <(template) unqualified-name>
|
|
|
|
::= <template-param>
|
|
|
|
::= <substitution>
|
|
|
|
*/
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_prefix (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret = NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
while (1)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char peek;
|
2004-01-12 22:24:38 +01:00
|
|
|
enum demangle_component_type comb_type;
|
|
|
|
struct demangle_component *dc;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == '\0')
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* The older code accepts a <local-name> here, but I don't see
|
|
|
|
that in the grammar. The older code does not accept a
|
|
|
|
<template-param> here. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
comb_type = DEMANGLE_COMPONENT_QUAL_NAME;
|
2003-11-21 18:42:45 +01:00
|
|
|
if (IS_DIGIT (peek)
|
2003-12-04 21:03:39 +01:00
|
|
|
|| IS_LOWER (peek)
|
2003-11-21 18:42:45 +01:00
|
|
|
|| peek == 'C'
|
|
|
|
|| peek == 'D')
|
|
|
|
dc = d_unqualified_name (di);
|
|
|
|
else if (peek == 'S')
|
2003-12-15 18:45:42 +01:00
|
|
|
dc = d_substitution (di, 1);
|
2003-11-21 18:42:45 +01:00
|
|
|
else if (peek == 'I')
|
|
|
|
{
|
|
|
|
if (ret == NULL)
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
comb_type = DEMANGLE_COMPONENT_TEMPLATE;
|
2003-11-21 18:42:45 +01:00
|
|
|
dc = d_template_args (di);
|
|
|
|
}
|
|
|
|
else if (peek == 'T')
|
|
|
|
dc = d_template_param (di);
|
|
|
|
else if (peek == 'E')
|
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (ret == NULL)
|
|
|
|
ret = dc;
|
2000-06-15 22:56:25 +02:00
|
|
|
else
|
2003-11-21 18:42:45 +01:00
|
|
|
ret = d_make_comp (di, comb_type, ret, dc);
|
|
|
|
|
|
|
|
if (peek != 'S' && d_peek_char (di) != 'E')
|
|
|
|
{
|
|
|
|
if (! d_add_substitution (di, ret))
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <unqualified-name> ::= <operator-name>
|
|
|
|
::= <ctor-dtor-name>
|
|
|
|
::= <source-name>
|
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_unqualified_name (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char peek;
|
|
|
|
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (IS_DIGIT (peek))
|
|
|
|
return d_source_name (di);
|
2003-12-04 21:03:39 +01:00
|
|
|
else if (IS_LOWER (peek))
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
2003-12-22 17:03:32 +01:00
|
|
|
|
|
|
|
ret = d_operator_name (di);
|
2004-01-12 22:24:38 +01:00
|
|
|
if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
|
|
|
|
return ret;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else if (peek == 'C' || peek == 'D')
|
|
|
|
return d_ctor_dtor_name (di);
|
|
|
|
else
|
2000-07-20 20:56:16 +02:00
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <source-name> ::= <(positive length) number> <identifier> */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_source_name (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
long len;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
len = d_number (di);
|
|
|
|
if (len <= 0)
|
|
|
|
return NULL;
|
|
|
|
ret = d_identifier (di, len);
|
|
|
|
di->last_name = ret;
|
|
|
|
return ret;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* number ::= [n] <(non-negative decimal integer)> */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static long
|
2005-03-27 07:28:42 +02:00
|
|
|
d_number (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
int negative;
|
2003-11-21 18:42:45 +01:00
|
|
|
char peek;
|
|
|
|
long ret;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
negative = 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == 'n')
|
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
negative = 1;
|
2003-11-21 18:42:45 +01:00
|
|
|
d_advance (di, 1);
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
ret = 0;
|
|
|
|
while (1)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (! IS_DIGIT (peek))
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
if (negative)
|
|
|
|
ret = - ret;
|
|
|
|
return ret;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
ret = ret * 10 + peek - '0';
|
|
|
|
d_advance (di, 1);
|
|
|
|
peek = d_peek_char (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* identifier ::= <(unqualified source code identifier)> */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_identifier (struct d_info *di, int len)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
const char *name;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
name = d_str (di);
|
2003-12-22 17:03:32 +01:00
|
|
|
|
|
|
|
if (di->send - name < len)
|
|
|
|
return NULL;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_advance (di, len);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-20 17:06:10 +01:00
|
|
|
/* A Java mangled name may have a trailing '$' if it is a C++
|
|
|
|
keyword. This '$' is not included in the length count. We just
|
|
|
|
ignore the '$'. */
|
|
|
|
if ((di->options & DMGL_JAVA) != 0
|
|
|
|
&& d_peek_char (di) == '$')
|
|
|
|
d_advance (di, 1);
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Look for something which looks like a gcc encoding of an
|
|
|
|
anonymous namespace, and replace it with a more user friendly
|
|
|
|
name. */
|
|
|
|
if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2
|
|
|
|
&& memcmp (name, ANONYMOUS_NAMESPACE_PREFIX,
|
|
|
|
ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
const char *s;
|
|
|
|
|
|
|
|
s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN;
|
|
|
|
if ((*s == '.' || *s == '_' || *s == '$')
|
|
|
|
&& s[1] == 'N')
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
di->expansion -= len - sizeof "(anonymous namespace)";
|
|
|
|
return d_make_name (di, "(anonymous namespace)",
|
|
|
|
sizeof "(anonymous namespace)" - 1);
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
return d_make_name (di, name, len);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* operator_name ::= many different two character encodings.
|
|
|
|
::= cv <type>
|
|
|
|
::= v <digit> <source-name>
|
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
#define NL(s) s, (sizeof s) - 1
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
const struct demangle_operator_info cplus_demangle_operators[] =
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
{ "aN", NL ("&="), 2 },
|
|
|
|
{ "aS", NL ("="), 2 },
|
|
|
|
{ "aa", NL ("&&"), 2 },
|
|
|
|
{ "ad", NL ("&"), 1 },
|
|
|
|
{ "an", NL ("&"), 2 },
|
|
|
|
{ "cl", NL ("()"), 0 },
|
|
|
|
{ "cm", NL (","), 2 },
|
|
|
|
{ "co", NL ("~"), 1 },
|
|
|
|
{ "dV", NL ("/="), 2 },
|
|
|
|
{ "da", NL ("delete[]"), 1 },
|
|
|
|
{ "de", NL ("*"), 1 },
|
|
|
|
{ "dl", NL ("delete"), 1 },
|
|
|
|
{ "dv", NL ("/"), 2 },
|
|
|
|
{ "eO", NL ("^="), 2 },
|
|
|
|
{ "eo", NL ("^"), 2 },
|
|
|
|
{ "eq", NL ("=="), 2 },
|
|
|
|
{ "ge", NL (">="), 2 },
|
|
|
|
{ "gt", NL (">"), 2 },
|
|
|
|
{ "ix", NL ("[]"), 2 },
|
|
|
|
{ "lS", NL ("<<="), 2 },
|
|
|
|
{ "le", NL ("<="), 2 },
|
|
|
|
{ "ls", NL ("<<"), 2 },
|
|
|
|
{ "lt", NL ("<"), 2 },
|
|
|
|
{ "mI", NL ("-="), 2 },
|
|
|
|
{ "mL", NL ("*="), 2 },
|
|
|
|
{ "mi", NL ("-"), 2 },
|
|
|
|
{ "ml", NL ("*"), 2 },
|
|
|
|
{ "mm", NL ("--"), 1 },
|
|
|
|
{ "na", NL ("new[]"), 1 },
|
|
|
|
{ "ne", NL ("!="), 2 },
|
|
|
|
{ "ng", NL ("-"), 1 },
|
|
|
|
{ "nt", NL ("!"), 1 },
|
|
|
|
{ "nw", NL ("new"), 1 },
|
|
|
|
{ "oR", NL ("|="), 2 },
|
|
|
|
{ "oo", NL ("||"), 2 },
|
|
|
|
{ "or", NL ("|"), 2 },
|
|
|
|
{ "pL", NL ("+="), 2 },
|
|
|
|
{ "pl", NL ("+"), 2 },
|
|
|
|
{ "pm", NL ("->*"), 2 },
|
|
|
|
{ "pp", NL ("++"), 1 },
|
|
|
|
{ "ps", NL ("+"), 1 },
|
|
|
|
{ "pt", NL ("->"), 2 },
|
|
|
|
{ "qu", NL ("?"), 3 },
|
|
|
|
{ "rM", NL ("%="), 2 },
|
|
|
|
{ "rS", NL (">>="), 2 },
|
|
|
|
{ "rm", NL ("%"), 2 },
|
|
|
|
{ "rs", NL (">>"), 2 },
|
|
|
|
{ "st", NL ("sizeof "), 1 },
|
2004-01-12 22:24:38 +01:00
|
|
|
{ "sz", NL ("sizeof "), 1 },
|
|
|
|
{ NULL, NULL, 0, 0 }
|
2003-11-21 18:42:45 +01:00
|
|
|
};
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_operator_name (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char c1;
|
|
|
|
char c2;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
c1 = d_next_char (di);
|
|
|
|
c2 = d_next_char (di);
|
|
|
|
if (c1 == 'v' && IS_DIGIT (c2))
|
|
|
|
return d_make_extended_operator (di, c2 - '0', d_source_name (di));
|
|
|
|
else if (c1 == 'c' && c2 == 'v')
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_CAST,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
/* LOW is the inclusive lower bound. */
|
2003-11-21 18:42:45 +01:00
|
|
|
int low = 0;
|
2004-01-12 22:24:38 +01:00
|
|
|
/* HIGH is the exclusive upper bound. We subtract one to ignore
|
|
|
|
the sentinel at the end of the array. */
|
|
|
|
int high = ((sizeof (cplus_demangle_operators)
|
|
|
|
/ sizeof (cplus_demangle_operators[0]))
|
|
|
|
- 1);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int i;
|
2004-01-12 22:24:38 +01:00
|
|
|
const struct demangle_operator_info *p;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
i = low + (high - low) / 2;
|
2004-01-12 22:24:38 +01:00
|
|
|
p = cplus_demangle_operators + i;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (c1 == p->code[0] && c2 == p->code[1])
|
|
|
|
return d_make_operator (di, p);
|
|
|
|
|
|
|
|
if (c1 < p->code[0] || (c1 == p->code[0] && c2 < p->code[1]))
|
|
|
|
high = i;
|
|
|
|
else
|
|
|
|
low = i + 1;
|
|
|
|
if (low == high)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <special-name> ::= TV <type>
|
|
|
|
::= TT <type>
|
|
|
|
::= TI <type>
|
|
|
|
::= TS <type>
|
|
|
|
::= GV <(object) name>
|
|
|
|
::= T <call-offset> <(base) encoding>
|
|
|
|
::= Tc <call-offset> <call-offset> <(base) encoding>
|
|
|
|
Also g++ extensions:
|
|
|
|
::= TC <type> <(offset) number> _ <(base) type>
|
|
|
|
::= TF <type>
|
|
|
|
::= TJ <type>
|
|
|
|
::= GR <name>
|
2005-05-26 01:32:36 +02:00
|
|
|
::= GA <encoding>
|
2003-11-21 18:42:45 +01:00
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_special_name (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char c;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += 20;
|
2003-11-21 18:42:45 +01:00
|
|
|
c = d_next_char (di);
|
|
|
|
if (c == 'T')
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (d_next_char (di))
|
|
|
|
{
|
|
|
|
case 'V':
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion -= 5;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_VTABLE,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'T':
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion -= 10;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_VTT,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'I':
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'S':
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_NAME,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'h':
|
|
|
|
if (! d_call_offset (di, 'h'))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_THUNK,
|
|
|
|
d_encoding (di, 0), NULL);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'v':
|
|
|
|
if (! d_call_offset (di, 'v'))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_VIRTUAL_THUNK,
|
|
|
|
d_encoding (di, 0), NULL);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'c':
|
|
|
|
if (! d_call_offset (di, '\0'))
|
|
|
|
return NULL;
|
|
|
|
if (! d_call_offset (di, '\0'))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_COVARIANT_THUNK,
|
|
|
|
d_encoding (di, 0), NULL);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'C':
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *derived_type;
|
2003-11-21 18:42:45 +01:00
|
|
|
long offset;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *base_type;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
derived_type = cplus_demangle_type (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
offset = d_number (di);
|
|
|
|
if (offset < 0)
|
|
|
|
return NULL;
|
|
|
|
if (d_next_char (di) != '_')
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
base_type = cplus_demangle_type (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
/* We don't display the offset. FIXME: We should display
|
|
|
|
it in verbose mode. */
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += 5;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
|
|
|
|
base_type, derived_type);
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'F':
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_FN,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'J':
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_JAVA_CLASS,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else if (c == 'G')
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (d_next_char (di))
|
|
|
|
{
|
|
|
|
case 'V':
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
case 'R':
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, d_name (di),
|
|
|
|
NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2005-05-26 01:32:36 +02:00
|
|
|
case 'A':
|
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
|
|
|
|
d_encoding (di, 0), NULL);
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <call-offset> ::= h <nv-offset> _
|
|
|
|
::= v <v-offset> _
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
<nv-offset> ::= <(offset) number>
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
<v-offset> ::= <(offset) number> _ <(virtual offset) number>
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
The C parameter, if not '\0', is a character we just read which is
|
|
|
|
the start of the <call-offset>.
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
We don't display the offset information anywhere. FIXME: We should
|
|
|
|
display it in verbose mode. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_call_offset (struct d_info *di, int c)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (c == '\0')
|
|
|
|
c = d_next_char (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (c == 'h')
|
2004-11-24 04:00:34 +01:00
|
|
|
d_number (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
else if (c == 'v')
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-11-24 04:00:34 +01:00
|
|
|
d_number (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != '_')
|
|
|
|
return 0;
|
2004-11-24 04:00:34 +01:00
|
|
|
d_number (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
|
|
|
return 0;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != '_')
|
|
|
|
return 0;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return 1;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <ctor-dtor-name> ::= C1
|
|
|
|
::= C2
|
|
|
|
::= C3
|
|
|
|
::= D0
|
|
|
|
::= D1
|
|
|
|
::= D2
|
|
|
|
*/
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_ctor_dtor_name (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
if (di->last_name != NULL)
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
if (di->last_name->type == DEMANGLE_COMPONENT_NAME)
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += di->last_name->u.s_name.len;
|
2004-01-12 22:24:38 +01:00
|
|
|
else if (di->last_name->type == DEMANGLE_COMPONENT_SUB_STD)
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += di->last_name->u.s_string.len;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (d_next_char (di))
|
|
|
|
{
|
|
|
|
case 'C':
|
|
|
|
{
|
|
|
|
enum gnu_v3_ctor_kinds kind;
|
|
|
|
|
|
|
|
switch (d_next_char (di))
|
|
|
|
{
|
|
|
|
case '1':
|
|
|
|
kind = gnu_v3_complete_object_ctor;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
kind = gnu_v3_base_object_ctor;
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
kind = gnu_v3_complete_object_allocating_ctor;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return d_make_ctor (di, kind, di->last_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
{
|
|
|
|
enum gnu_v3_dtor_kinds kind;
|
|
|
|
|
|
|
|
switch (d_next_char (di))
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
kind = gnu_v3_deleting_dtor;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
kind = gnu_v3_complete_object_dtor;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
kind = gnu_v3_base_object_dtor;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return d_make_dtor (di, kind, di->last_name);
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <type> ::= <builtin-type>
|
|
|
|
::= <function-type>
|
|
|
|
::= <class-enum-type>
|
|
|
|
::= <array-type>
|
|
|
|
::= <pointer-to-member-type>
|
|
|
|
::= <template-param>
|
|
|
|
::= <template-template-param> <template-args>
|
|
|
|
::= <substitution>
|
|
|
|
::= <CV-qualifiers> <type>
|
|
|
|
::= P <type>
|
|
|
|
::= R <type>
|
|
|
|
::= C <type>
|
|
|
|
::= G <type>
|
|
|
|
::= U <source-name> <type>
|
|
|
|
|
|
|
|
<builtin-type> ::= various one letter codes
|
|
|
|
::= u <source-name>
|
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
const struct demangle_builtin_type_info
|
|
|
|
cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-02-25 06:40:03 +01:00
|
|
|
/* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL },
|
2004-02-25 06:40:03 +01:00
|
|
|
/* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT },
|
|
|
|
/* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT },
|
|
|
|
/* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT },
|
|
|
|
/* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT },
|
|
|
|
/* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT },
|
|
|
|
/* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* i */ { NL ("int"), NL ("int"), D_PRINT_INT },
|
2004-02-25 06:40:03 +01:00
|
|
|
/* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* k */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
|
|
|
|
/* l */ { NL ("long"), NL ("long"), D_PRINT_LONG },
|
2004-02-25 06:40:03 +01:00
|
|
|
/* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT },
|
2004-02-25 06:40:03 +01:00
|
|
|
/* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
|
|
|
|
D_PRINT_DEFAULT },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* p */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
|
|
|
|
/* q */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
|
|
|
|
/* r */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
|
2004-02-25 06:40:03 +01:00
|
|
|
/* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT },
|
|
|
|
/* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* u */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
|
|
|
|
/* v */ { NL ("void"), NL ("void"), D_PRINT_VOID },
|
2004-02-25 06:40:03 +01:00
|
|
|
/* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT },
|
|
|
|
/* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG },
|
|
|
|
/* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
|
|
|
|
D_PRINT_UNSIGNED_LONG_LONG },
|
2003-12-22 17:03:32 +01:00
|
|
|
/* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT },
|
2003-11-21 18:42:45 +01:00
|
|
|
};
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_type (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char peek;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
2003-11-21 18:42:45 +01:00
|
|
|
int can_subst;
|
|
|
|
|
|
|
|
/* The ABI specifies that when CV-qualifiers are used, the base type
|
|
|
|
is substitutable, and the fully qualified type is substitutable,
|
|
|
|
but the base type with a strict subset of the CV-qualifiers is
|
|
|
|
not substitutable. The natural recursive implementation of the
|
|
|
|
CV-qualifiers would cause subsets to be substitutable, so instead
|
|
|
|
we pull them all off now.
|
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
FIXME: The ABI says that order-insensitive vendor qualifiers
|
|
|
|
should be handled in the same way, but we have no way to tell
|
|
|
|
which vendor qualifiers are order-insensitive and which are
|
|
|
|
order-sensitive. So we just assume that they are all
|
|
|
|
order-sensitive. g++ 3.4 supports only one vendor qualifier,
|
|
|
|
__vector, and it treats it as order-sensitive when mangling
|
|
|
|
names. */
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == 'r' || peek == 'V' || peek == 'K')
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component **pret;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
pret = d_cv_qualifiers (di, &ret, 0);
|
2003-11-27 02:17:34 +01:00
|
|
|
if (pret == NULL)
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
*pret = cplus_demangle_type (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (! d_add_substitution (di, ret))
|
|
|
|
return NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
can_subst = 1;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2000-10-12 04:16:48 +02:00
|
|
|
switch (peek)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
|
|
|
|
case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
|
|
|
|
case 'o': case 's': case 't':
|
|
|
|
case 'v': case 'w': case 'x': case 'y': case 'z':
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_builtin_type (di,
|
|
|
|
&cplus_demangle_builtin_types[peek - 'a']);
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += ret->u.s_builtin.type->len;
|
2003-11-21 18:42:45 +01:00
|
|
|
can_subst = 0;
|
|
|
|
d_advance (di, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
d_advance (di, 1);
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE,
|
|
|
|
d_source_name (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
ret = d_function_type (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
break;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
case 'N':
|
2000-06-15 22:56:25 +02:00
|
|
|
case 'Z':
|
2003-11-21 18:42:45 +01:00
|
|
|
ret = d_class_enum_type (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
break;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'A':
|
|
|
|
ret = d_array_type (di);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
ret = d_pointer_to_member_type (di);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
ret = d_template_param (di);
|
|
|
|
if (d_peek_char (di) == 'I')
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
/* This is <template-template-param> <template-args>. The
|
|
|
|
<template-template-param> part is a substitution
|
|
|
|
candidate. */
|
|
|
|
if (! d_add_substitution (di, ret))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
|
|
|
|
d_template_args (di));
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
/* If this is a special substitution, then it is the start of
|
|
|
|
<class-enum-type>. */
|
|
|
|
{
|
|
|
|
char peek_next;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
peek_next = d_peek_next_char (di);
|
|
|
|
if (IS_DIGIT (peek_next)
|
|
|
|
|| peek_next == '_'
|
2003-12-04 21:03:39 +01:00
|
|
|
|| IS_UPPER (peek_next))
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-12-15 18:45:42 +01:00
|
|
|
ret = d_substitution (di, 0);
|
2003-11-21 18:42:45 +01:00
|
|
|
/* The substituted name may have been a template name and
|
|
|
|
may be followed by tepmlate args. */
|
|
|
|
if (d_peek_char (di) == 'I')
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
|
2003-11-21 18:42:45 +01:00
|
|
|
d_template_args (di));
|
|
|
|
else
|
|
|
|
can_subst = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = d_class_enum_type (di);
|
|
|
|
/* If the substitution was a complete type, then it is not
|
|
|
|
a new substitution candidate. However, if the
|
|
|
|
substitution was followed by template arguments, then
|
|
|
|
the whole thing is a substitution candidate. */
|
2004-01-12 22:24:38 +01:00
|
|
|
if (ret != NULL && ret->type == DEMANGLE_COMPONENT_SUB_STD)
|
2003-11-21 18:42:45 +01:00
|
|
|
can_subst = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
break;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'P':
|
|
|
|
d_advance (di, 1);
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_POINTER,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'R':
|
|
|
|
d_advance (di, 1);
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_REFERENCE,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'C':
|
|
|
|
d_advance (di, 1);
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_COMPLEX,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
d_advance (di, 1);
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_IMAGINARY,
|
|
|
|
cplus_demangle_type (di), NULL);
|
2003-11-21 18:42:45 +01:00
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'U':
|
|
|
|
d_advance (di, 1);
|
|
|
|
ret = d_source_name (di);
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
|
|
|
|
cplus_demangle_type (di), ret);
|
2000-06-15 22:56:25 +02:00
|
|
|
break;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (can_subst)
|
|
|
|
{
|
|
|
|
if (! d_add_substitution (di, ret))
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <CV-qualifiers> ::= [r] [V] [K] */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component **
|
2005-03-27 07:28:42 +02:00
|
|
|
d_cv_qualifiers (struct d_info *di,
|
|
|
|
struct demangle_component **pret, int member_fn)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
|
|
|
char peek;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
peek = d_peek_char (di);
|
|
|
|
while (peek == 'r' || peek == 'V' || peek == 'K')
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
enum demangle_component_type t;
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_advance (di, 1);
|
|
|
|
if (peek == 'r')
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
t = (member_fn
|
|
|
|
? DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
: DEMANGLE_COMPONENT_RESTRICT);
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += sizeof "restrict";
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else if (peek == 'V')
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
t = (member_fn
|
|
|
|
? DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
: DEMANGLE_COMPONENT_VOLATILE);
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += sizeof "volatile";
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
t = (member_fn
|
|
|
|
? DEMANGLE_COMPONENT_CONST_THIS
|
|
|
|
: DEMANGLE_COMPONENT_CONST);
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += sizeof "const";
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
*pret = d_make_comp (di, t, NULL, NULL);
|
|
|
|
if (*pret == NULL)
|
|
|
|
return NULL;
|
|
|
|
pret = &d_left (*pret);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
peek = d_peek_char (di);
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return pret;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <function-type> ::= F [Y] <bare-function-type> E */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_function_type (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'F')
|
|
|
|
return NULL;
|
|
|
|
if (d_peek_char (di) == 'Y')
|
|
|
|
{
|
|
|
|
/* Function has C linkage. We don't print this information.
|
|
|
|
FIXME: We should print it in verbose mode. */
|
|
|
|
d_advance (di, 1);
|
|
|
|
}
|
|
|
|
ret = d_bare_function_type (di, 1);
|
|
|
|
if (d_next_char (di) != 'E')
|
|
|
|
return NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2005-12-11 03:16:09 +01:00
|
|
|
/* <bare-function-type> ::= [J]<type>+ */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_bare_function_type (struct d_info *di, int has_return_type)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *return_type;
|
|
|
|
struct demangle_component *tl;
|
|
|
|
struct demangle_component **ptl;
|
2005-12-11 03:16:09 +01:00
|
|
|
char peek;
|
|
|
|
|
|
|
|
/* Detect special qualifier indicating that the first argument
|
|
|
|
is the return type. */
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == 'J')
|
|
|
|
{
|
|
|
|
d_advance (di, 1);
|
|
|
|
has_return_type = 1;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return_type = NULL;
|
|
|
|
tl = NULL;
|
|
|
|
ptl = &tl;
|
2000-06-15 22:56:25 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *type;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == '\0' || peek == 'E')
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
type = cplus_demangle_type (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (type == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (has_return_type)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
return_type = type;
|
|
|
|
has_return_type = 0;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
*ptl = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, type, NULL);
|
2003-11-27 02:17:34 +01:00
|
|
|
if (*ptl == NULL)
|
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
ptl = &d_right (*ptl);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* There should be at least one parameter type besides the optional
|
|
|
|
return type. A function which takes no arguments will have a
|
|
|
|
single parameter type void. */
|
|
|
|
if (tl == NULL)
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* If we have a single parameter type void, omit it. */
|
|
|
|
if (d_right (tl) == NULL
|
2004-01-12 22:24:38 +01:00
|
|
|
&& d_left (tl)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
|
2003-11-21 18:42:45 +01:00
|
|
|
&& d_left (tl)->u.s_builtin.type->print == D_PRINT_VOID)
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
di->expansion -= d_left (tl)->u.s_builtin.type->len;
|
|
|
|
tl = NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_FUNCTION_TYPE, return_type, tl);
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <class-enum-type> ::= <name> */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_class_enum_type (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
return d_name (di);
|
|
|
|
}
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <array-type> ::= A <(positive dimension) number> _ <(element) type>
|
|
|
|
::= A [<(dimension) expression>] _ <(element) type>
|
|
|
|
*/
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_array_type (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
char peek;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dim;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'A')
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == '_')
|
|
|
|
dim = NULL;
|
|
|
|
else if (IS_DIGIT (peek))
|
2000-10-12 04:16:48 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
const char *s;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
s = d_str (di);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
d_advance (di, 1);
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
}
|
|
|
|
while (IS_DIGIT (peek));
|
|
|
|
dim = d_make_name (di, s, d_str (di) - s);
|
2003-11-27 02:17:34 +01:00
|
|
|
if (dim == NULL)
|
|
|
|
return NULL;
|
2000-10-12 04:16:48 +02:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
else
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
dim = d_expression (di);
|
|
|
|
if (dim == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != '_')
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_ARRAY_TYPE, dim,
|
|
|
|
cplus_demangle_type (di));
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_pointer_to_member_type (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *cl;
|
|
|
|
struct demangle_component *mem;
|
|
|
|
struct demangle_component **pmem;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'M')
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
cl = cplus_demangle_type (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* The ABI specifies that any type can be a substitution source, and
|
|
|
|
that M is followed by two types, and that when a CV-qualified
|
|
|
|
type is seen both the base type and the CV-qualified types are
|
|
|
|
substitution sources. The ABI also specifies that for a pointer
|
|
|
|
to a CV-qualified member function, the qualifiers are attached to
|
|
|
|
the second type. Given the grammar, a plain reading of the ABI
|
|
|
|
suggests that both the CV-qualified member function and the
|
|
|
|
non-qualified member function are substitution sources. However,
|
|
|
|
g++ does not work that way. g++ treats only the CV-qualified
|
|
|
|
member function as a substitution source. FIXME. So to work
|
|
|
|
with g++, we need to pull off the CV-qualifiers here, in order to
|
2004-01-12 22:24:38 +01:00
|
|
|
avoid calling add_substitution() in cplus_demangle_type(). */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
pmem = d_cv_qualifiers (di, &mem, 1);
|
2003-11-27 02:17:34 +01:00
|
|
|
if (pmem == NULL)
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
*pmem = cplus_demangle_type (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_PTRMEM_TYPE, cl, mem);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <template-param> ::= T_
|
|
|
|
::= T <(parameter-2 non-negative) number> _
|
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_template_param (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
long param;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'T')
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_peek_char (di) == '_')
|
|
|
|
param = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
param = d_number (di);
|
|
|
|
if (param < 0)
|
|
|
|
return NULL;
|
|
|
|
param += 1;
|
|
|
|
}
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != '_')
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
++di->did_subs;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return d_make_template_param (di, param);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <template-args> ::= I <template-arg>+ E */
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_template_args (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *hold_last_name;
|
|
|
|
struct demangle_component *al;
|
|
|
|
struct demangle_component **pal;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Preserve the last name we saw--don't let the template arguments
|
|
|
|
clobber it, as that would give us the wrong name for a subsequent
|
|
|
|
constructor or destructor. */
|
|
|
|
hold_last_name = di->last_name;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'I')
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
al = NULL;
|
|
|
|
pal = &al;
|
2000-06-15 22:56:25 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *a;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
a = d_template_arg (di);
|
|
|
|
if (a == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
*pal = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, a, NULL);
|
2003-11-27 02:17:34 +01:00
|
|
|
if (*pal == NULL)
|
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
pal = &d_right (*pal);
|
|
|
|
|
|
|
|
if (d_peek_char (di) == 'E')
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
d_advance (di, 1);
|
|
|
|
break;
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
di->last_name = hold_last_name;
|
|
|
|
|
|
|
|
return al;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <template-arg> ::= <type>
|
|
|
|
::= X <expression> E
|
|
|
|
::= <expr-primary>
|
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_template_arg (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (d_peek_char (di))
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'X':
|
|
|
|
d_advance (di, 1);
|
|
|
|
ret = d_expression (di);
|
|
|
|
if (d_next_char (di) != 'E')
|
|
|
|
return NULL;
|
|
|
|
return ret;
|
2002-07-10 02:01:58 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
case 'L':
|
|
|
|
return d_expr_primary (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
default:
|
2004-01-12 22:24:38 +01:00
|
|
|
return cplus_demangle_type (di);
|
2000-10-12 04:16:48 +02:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <expression> ::= <(unary) operator-name> <expression>
|
|
|
|
::= <(binary) operator-name> <expression> <expression>
|
|
|
|
::= <(trinary) operator-name> <expression> <expression> <expression>
|
|
|
|
::= st <type>
|
|
|
|
::= <template-param>
|
|
|
|
::= sr <type> <unqualified-name>
|
|
|
|
::= sr <type> <unqualified-name> <template-args>
|
|
|
|
::= <expr-primary>
|
|
|
|
*/
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_expression (struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char peek;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == 'L')
|
|
|
|
return d_expr_primary (di);
|
|
|
|
else if (peek == 'T')
|
|
|
|
return d_template_param (di);
|
|
|
|
else if (peek == 's' && d_peek_next_char (di) == 'r')
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *type;
|
|
|
|
struct demangle_component *name;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_advance (di, 2);
|
2004-01-12 22:24:38 +01:00
|
|
|
type = cplus_demangle_type (di);
|
2003-11-21 18:42:45 +01:00
|
|
|
name = d_unqualified_name (di);
|
|
|
|
if (d_peek_char (di) != 'I')
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name);
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type,
|
|
|
|
d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
|
2003-11-21 18:42:45 +01:00
|
|
|
d_template_args (di)));
|
2002-07-02 06:09:35 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *op;
|
2003-11-21 18:42:45 +01:00
|
|
|
int args;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
op = d_operator_name (di);
|
|
|
|
if (op == NULL)
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
if (op->type == DEMANGLE_COMPONENT_OPERATOR)
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion += op->u.s_operator.op->len - 2;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
if (op->type == DEMANGLE_COMPONENT_OPERATOR
|
2003-11-21 18:42:45 +01:00
|
|
|
&& strcmp (op->u.s_operator.op->code, "st") == 0)
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
|
|
|
|
cplus_demangle_type (di));
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (op->type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_OPERATOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
args = op->u.s_operator.op->args;
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
args = op->u.s_extended_operator.args;
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CAST:
|
2003-11-21 18:42:45 +01:00
|
|
|
args = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args)
|
|
|
|
{
|
|
|
|
case 1:
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
|
|
|
|
d_expression (di));
|
2003-11-21 18:42:45 +01:00
|
|
|
case 2:
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *left;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
left = d_expression (di);
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_BINARY, op,
|
|
|
|
d_make_comp (di,
|
|
|
|
DEMANGLE_COMPONENT_BINARY_ARGS,
|
|
|
|
left,
|
2003-11-21 18:42:45 +01:00
|
|
|
d_expression (di)));
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *first;
|
|
|
|
struct demangle_component *second;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
first = d_expression (di);
|
|
|
|
second = d_expression (di);
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_TRINARY, op,
|
|
|
|
d_make_comp (di,
|
|
|
|
DEMANGLE_COMPONENT_TRINARY_ARG1,
|
|
|
|
first,
|
2003-11-21 18:42:45 +01:00
|
|
|
d_make_comp (di,
|
2004-01-12 22:24:38 +01:00
|
|
|
DEMANGLE_COMPONENT_TRINARY_ARG2,
|
2003-11-21 18:42:45 +01:00
|
|
|
second,
|
|
|
|
d_expression (di))));
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <expr-primary> ::= L <type> <(value) number> E
|
|
|
|
::= L <type> <(value) float> E
|
|
|
|
::= L <mangled-name> E
|
|
|
|
*/
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_expr_primary (struct d_info *di)
|
2000-10-12 04:16:48 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *ret;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'L')
|
|
|
|
return NULL;
|
|
|
|
if (d_peek_char (di) == '_')
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = cplus_demangle_mangled_name (di, 0);
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2000-10-12 04:16:48 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *type;
|
|
|
|
enum demangle_component_type t;
|
2003-11-21 18:42:45 +01:00
|
|
|
const char *s;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
type = cplus_demangle_type (di);
|
2004-06-28 20:01:46 +02:00
|
|
|
if (type == NULL)
|
|
|
|
return NULL;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* If we have a type we know how to print, we aren't going to
|
|
|
|
print the type name itself. */
|
2004-01-12 22:24:38 +01:00
|
|
|
if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
|
2003-12-22 17:03:32 +01:00
|
|
|
&& type->u.s_builtin.type->print != D_PRINT_DEFAULT)
|
|
|
|
di->expansion -= type->u.s_builtin.type->len;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Rather than try to interpret the literal value, we just
|
|
|
|
collect it as a string. Note that it's possible to have a
|
|
|
|
floating point literal here. The ABI specifies that the
|
|
|
|
format of such literals is machine independent. That's fine,
|
|
|
|
but what's not fine is that versions of g++ up to 3.2 with
|
|
|
|
-fabi-version=1 used upper case letters in the hex constant,
|
|
|
|
and dumped out gcc's internal representation. That makes it
|
|
|
|
hard to tell where the constant ends, and hard to dump the
|
|
|
|
constant in any readable form anyhow. We don't attempt to
|
|
|
|
handle these cases. */
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
t = DEMANGLE_COMPONENT_LITERAL;
|
2003-12-15 18:45:42 +01:00
|
|
|
if (d_peek_char (di) == 'n')
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
t = DEMANGLE_COMPONENT_LITERAL_NEG;
|
2003-12-15 18:45:42 +01:00
|
|
|
d_advance (di, 1);
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
s = d_str (di);
|
|
|
|
while (d_peek_char (di) != 'E')
|
2005-07-03 21:16:20 +02:00
|
|
|
{
|
|
|
|
if (d_peek_char (di) == '\0')
|
|
|
|
return NULL;
|
|
|
|
d_advance (di, 1);
|
|
|
|
}
|
2003-12-15 18:45:42 +01:00
|
|
|
ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s));
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
|
|
|
if (d_next_char (di) != 'E')
|
|
|
|
return NULL;
|
|
|
|
return ret;
|
2000-10-12 04:16:48 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
|
|
|
|
::= Z <(function) encoding> E s [<discriminator>]
|
|
|
|
*/
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_local_name (struct d_info *di)
|
2000-10-12 04:16:48 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *function;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'Z')
|
|
|
|
return NULL;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-24 20:33:33 +01:00
|
|
|
function = d_encoding (di, 0);
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'E')
|
|
|
|
return NULL;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_peek_char (di) == 's')
|
2000-10-12 04:16:48 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
d_advance (di, 1);
|
|
|
|
if (! d_discriminator (di))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function,
|
2003-11-21 18:42:45 +01:00
|
|
|
d_make_name (di, "string literal",
|
|
|
|
sizeof "string literal" - 1));
|
2000-10-12 04:16:48 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2000-10-12 04:16:48 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *name;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
name = d_name (di);
|
|
|
|
if (! d_discriminator (di))
|
|
|
|
return NULL;
|
2004-01-12 22:24:38 +01:00
|
|
|
return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name);
|
2000-10-12 04:16:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* <discriminator> ::= _ <(non-negative) number>
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
We demangle the discriminator, but we don't print it out. FIXME:
|
|
|
|
We should print it out in verbose mode. */
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_discriminator (struct d_info *di)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
long discrim;
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_peek_char (di) != '_')
|
|
|
|
return 1;
|
|
|
|
d_advance (di, 1);
|
|
|
|
discrim = d_number (di);
|
|
|
|
if (discrim < 0)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Add a new substitution. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
d_add_substitution (struct d_info *di, struct demangle_component *dc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-27 02:17:34 +01:00
|
|
|
if (dc == NULL)
|
|
|
|
return 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
if (di->next_sub >= di->num_subs)
|
|
|
|
return 0;
|
|
|
|
di->subs[di->next_sub] = dc;
|
|
|
|
++di->next_sub;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <substitution> ::= S <seq-id> _
|
|
|
|
::= S_
|
|
|
|
::= St
|
|
|
|
::= Sa
|
|
|
|
::= Sb
|
|
|
|
::= Ss
|
|
|
|
::= Si
|
|
|
|
::= So
|
|
|
|
::= Sd
|
2003-12-15 18:45:42 +01:00
|
|
|
|
|
|
|
If PREFIX is non-zero, then this type is being used as a prefix in
|
|
|
|
a qualified name. In this case, for the standard substitutions, we
|
|
|
|
need to check whether we are being used as a prefix for a
|
|
|
|
constructor or destructor, and return a full template name.
|
|
|
|
Otherwise we will get something like std::iostream::~iostream()
|
|
|
|
which does not correspond particularly well to any function which
|
|
|
|
actually appears in the source.
|
2003-11-21 18:42:45 +01:00
|
|
|
*/
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-15 18:45:42 +01:00
|
|
|
static const struct d_standard_sub_info standard_subs[] =
|
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
{ 't', NL ("std"),
|
|
|
|
NL ("std"),
|
|
|
|
NULL, 0 },
|
|
|
|
{ 'a', NL ("std::allocator"),
|
|
|
|
NL ("std::allocator"),
|
|
|
|
NL ("allocator") },
|
|
|
|
{ 'b', NL ("std::basic_string"),
|
|
|
|
NL ("std::basic_string"),
|
|
|
|
NL ("basic_string") },
|
|
|
|
{ 's', NL ("std::string"),
|
|
|
|
NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
|
|
|
|
NL ("basic_string") },
|
|
|
|
{ 'i', NL ("std::istream"),
|
|
|
|
NL ("std::basic_istream<char, std::char_traits<char> >"),
|
|
|
|
NL ("basic_istream") },
|
|
|
|
{ 'o', NL ("std::ostream"),
|
|
|
|
NL ("std::basic_ostream<char, std::char_traits<char> >"),
|
|
|
|
NL ("basic_ostream") },
|
|
|
|
{ 'd', NL ("std::iostream"),
|
|
|
|
NL ("std::basic_iostream<char, std::char_traits<char> >"),
|
|
|
|
NL ("basic_iostream") }
|
2003-12-15 18:45:42 +01:00
|
|
|
};
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
static struct demangle_component *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_substitution (struct d_info *di, int prefix)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
char c;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_next_char (di) != 'S')
|
|
|
|
return NULL;
|
2001-08-09 02:05:37 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
c = d_next_char (di);
|
2003-12-04 21:03:39 +01:00
|
|
|
if (c == '_' || IS_DIGIT (c) || IS_UPPER (c))
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
int id;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
id = 0;
|
|
|
|
if (c != '_')
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
do
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (IS_DIGIT (c))
|
|
|
|
id = id * 36 + c - '0';
|
2003-12-04 21:03:39 +01:00
|
|
|
else if (IS_UPPER (c))
|
2003-11-21 18:42:45 +01:00
|
|
|
id = id * 36 + c - 'A' + 10;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
c = d_next_char (di);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
while (c != '_');
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
++id;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (id >= di->next_sub)
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
++di->did_subs;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return di->subs[id];
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-12-15 18:45:42 +01:00
|
|
|
int verbose;
|
|
|
|
const struct d_standard_sub_info *p;
|
|
|
|
const struct d_standard_sub_info *pend;
|
|
|
|
|
|
|
|
verbose = (di->options & DMGL_VERBOSE) != 0;
|
|
|
|
if (! verbose && prefix)
|
2001-03-20 19:22:38 +01:00
|
|
|
{
|
2003-12-15 18:45:42 +01:00
|
|
|
char peek;
|
|
|
|
|
|
|
|
peek = d_peek_char (di);
|
|
|
|
if (peek == 'C' || peek == 'D')
|
|
|
|
verbose = 1;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-12-15 18:45:42 +01:00
|
|
|
|
|
|
|
pend = (&standard_subs[0]
|
|
|
|
+ sizeof standard_subs / sizeof standard_subs[0]);
|
|
|
|
for (p = &standard_subs[0]; p < pend; ++p)
|
|
|
|
{
|
|
|
|
if (c == p->code)
|
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
const char *s;
|
|
|
|
int len;
|
|
|
|
|
2003-12-15 18:45:42 +01:00
|
|
|
if (p->set_last_name != NULL)
|
2003-12-22 17:03:32 +01:00
|
|
|
di->last_name = d_make_sub (di, p->set_last_name,
|
|
|
|
p->set_last_name_len);
|
2003-12-15 18:45:42 +01:00
|
|
|
if (verbose)
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
s = p->full_expansion;
|
|
|
|
len = p->full_len;
|
|
|
|
}
|
2003-12-15 18:45:42 +01:00
|
|
|
else
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
s = p->simple_expansion;
|
|
|
|
len = p->simple_len;
|
|
|
|
}
|
|
|
|
di->expansion += len;
|
|
|
|
return d_make_sub (di, s, len);
|
2003-12-15 18:45:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Resize the print buffer. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_resize (struct d_print_info *dpi, size_t add)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
size_t need;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
if (dpi->buf == NULL)
|
|
|
|
return;
|
2003-11-21 18:42:45 +01:00
|
|
|
need = dpi->len + add;
|
|
|
|
while (need > dpi->alc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
size_t newalc;
|
|
|
|
char *newbuf;
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
newalc = dpi->alc * 2;
|
2005-05-24 23:01:33 +02:00
|
|
|
newbuf = (char *) realloc (dpi->buf, newalc);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (newbuf == NULL)
|
2003-11-19 17:19:14 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
free (dpi->buf);
|
|
|
|
dpi->buf = NULL;
|
|
|
|
dpi->allocation_failure = 1;
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->buf = newbuf;
|
|
|
|
dpi->alc = newalc;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2003-11-19 17:19:14 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Append a character to the print buffer. */
|
2003-11-19 17:19:14 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_append_char (struct d_print_info *dpi, int c)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
if (dpi->buf != NULL)
|
|
|
|
{
|
|
|
|
if (dpi->len >= dpi->alc)
|
|
|
|
{
|
|
|
|
d_print_resize (dpi, 1);
|
|
|
|
if (dpi->buf == NULL)
|
|
|
|
return;
|
|
|
|
}
|
2003-11-19 17:19:14 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->buf[dpi->len] = c;
|
|
|
|
++dpi->len;
|
2000-10-12 04:16:48 +02:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Append a buffer to the print buffer. */
|
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_append_buffer (struct d_print_info *dpi, const char *s, size_t l)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dpi->buf != NULL)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dpi->len + l > dpi->alc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_resize (dpi, l);
|
|
|
|
if (dpi->buf == NULL)
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
memcpy (dpi->buf + dpi->len, s, l);
|
|
|
|
dpi->len += l;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Indicate that an error occurred during printing. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_error (struct d_print_info *dpi)
|
2001-02-02 19:58:51 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
free (dpi->buf);
|
|
|
|
dpi->buf = NULL;
|
|
|
|
}
|
2001-02-02 19:58:51 +01:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* Turn components into a human readable string. OPTIONS is the
|
|
|
|
options bits passed to the demangler. DC is the tree to print.
|
|
|
|
ESTIMATE is a guess at the length of the result. This returns a
|
|
|
|
string allocated by malloc, or NULL on error. On success, this
|
|
|
|
sets *PALC to the size of the allocated buffer. On failure, this
|
|
|
|
sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
|
|
|
|
failure. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
char *
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_print (int options, const struct demangle_component *dc,
|
|
|
|
int estimate, size_t *palc)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
struct d_print_info dpi;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi.options = options;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
dpi.alc = estimate + 1;
|
2005-05-24 23:01:33 +02:00
|
|
|
dpi.buf = (char *) malloc (dpi.alc);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dpi.buf == NULL)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
*palc = 1;
|
|
|
|
return NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi.len = 0;
|
|
|
|
dpi.templates = NULL;
|
|
|
|
dpi.modifiers = NULL;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi.allocation_failure = 0;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (&dpi, dc);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (&dpi, '\0');
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dpi.buf != NULL)
|
|
|
|
*palc = dpi.alc;
|
|
|
|
else
|
|
|
|
*palc = dpi.allocation_failure;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return dpi.buf;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Subroutine to handle components. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_comp (struct d_print_info *dpi,
|
|
|
|
const struct demangle_component *dc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dc == NULL)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_print_saw_error (dpi))
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
switch (dc->type)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_NAME:
|
2003-12-22 17:03:32 +01:00
|
|
|
if ((dpi->options & DMGL_JAVA) == 0)
|
|
|
|
d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len);
|
|
|
|
else
|
|
|
|
d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len);
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_QUAL_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_LOCAL_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
2003-12-22 17:03:32 +01:00
|
|
|
if ((dpi->options & DMGL_JAVA) == 0)
|
|
|
|
d_append_string_constant (dpi, "::");
|
|
|
|
else
|
|
|
|
d_append_char (dpi, '.');
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPED_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-12-04 21:03:39 +01:00
|
|
|
struct d_print_mod *hold_modifiers;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *typed_name;
|
2003-12-04 21:03:39 +01:00
|
|
|
struct d_print_mod adpm[4];
|
|
|
|
unsigned int i;
|
2003-11-21 18:42:45 +01:00
|
|
|
struct d_print_template dpt;
|
|
|
|
|
|
|
|
/* Pass the name down to the type so that it can be printed in
|
2003-12-04 21:03:39 +01:00
|
|
|
the right place for the type. We also have to pass down
|
|
|
|
any CV-qualifiers, which apply to the this parameter. */
|
|
|
|
hold_modifiers = dpi->modifiers;
|
|
|
|
i = 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
typed_name = d_left (dc);
|
2003-12-04 21:03:39 +01:00
|
|
|
while (typed_name != NULL)
|
|
|
|
{
|
|
|
|
if (i >= sizeof adpm / sizeof adpm[0])
|
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
adpm[i].next = dpi->modifiers;
|
|
|
|
dpi->modifiers = &adpm[i];
|
|
|
|
adpm[i].mod = typed_name;
|
|
|
|
adpm[i].printed = 0;
|
|
|
|
adpm[i].templates = dpi->templates;
|
|
|
|
++i;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
if (typed_name->type != DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
&& typed_name->type != DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
&& typed_name->type != DEMANGLE_COMPONENT_CONST_THIS)
|
2003-12-04 21:03:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
typed_name = d_left (typed_name);
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
/* If typed_name is a template, then it applies to the
|
|
|
|
function type as well. */
|
2004-01-12 22:24:38 +01:00
|
|
|
if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
dpt.next = dpi->templates;
|
|
|
|
dpi->templates = &dpt;
|
2005-05-24 23:01:33 +02:00
|
|
|
dpt.template_decl = typed_name;
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
/* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
|
|
|
|
there may be CV-qualifiers on its right argument which
|
|
|
|
really apply here; this happens when parsing a class which
|
|
|
|
is local to a function. */
|
|
|
|
if (typed_name->type == DEMANGLE_COMPONENT_LOCAL_NAME)
|
2003-12-19 23:03:41 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *local_name;
|
2003-12-19 23:03:41 +01:00
|
|
|
|
|
|
|
local_name = d_right (typed_name);
|
2004-01-12 22:24:38 +01:00
|
|
|
while (local_name->type == DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
|| local_name->type == DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
|| local_name->type == DEMANGLE_COMPONENT_CONST_THIS)
|
2003-12-19 23:03:41 +01:00
|
|
|
{
|
|
|
|
if (i >= sizeof adpm / sizeof adpm[0])
|
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
adpm[i] = adpm[i - 1];
|
|
|
|
adpm[i].next = &adpm[i - 1];
|
|
|
|
dpi->modifiers = &adpm[i];
|
|
|
|
|
|
|
|
adpm[i - 1].mod = local_name;
|
|
|
|
adpm[i - 1].printed = 0;
|
|
|
|
adpm[i - 1].templates = dpi->templates;
|
|
|
|
++i;
|
|
|
|
|
|
|
|
local_name = d_left (local_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
2000-10-12 04:16:48 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->templates = dpt.next;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
/* If the modifiers didn't get printed by the type, print them
|
2003-11-21 18:42:45 +01:00
|
|
|
now. */
|
2003-12-04 21:03:39 +01:00
|
|
|
while (i > 0)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-12-04 21:03:39 +01:00
|
|
|
--i;
|
|
|
|
if (! adpm[i].printed)
|
|
|
|
{
|
|
|
|
d_append_char (dpi, ' ');
|
|
|
|
d_print_mod (dpi, adpm[i].mod);
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
dpi->modifiers = hold_modifiers;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE:
|
2003-11-27 02:17:34 +01:00
|
|
|
{
|
|
|
|
struct d_print_mod *hold_dpm;
|
|
|
|
|
|
|
|
/* Don't push modifiers into a template definition. Doing so
|
|
|
|
could give the wrong definition for a template argument.
|
|
|
|
Instead, treat the template essentially as a name. */
|
|
|
|
|
|
|
|
hold_dpm = dpi->modifiers;
|
|
|
|
dpi->modifiers = NULL;
|
|
|
|
|
|
|
|
d_print_comp (dpi, d_left (dc));
|
2003-12-04 21:03:39 +01:00
|
|
|
if (d_last_char (dpi) == '<')
|
|
|
|
d_append_char (dpi, ' ');
|
2003-11-27 02:17:34 +01:00
|
|
|
d_append_char (dpi, '<');
|
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
/* Avoid generating two consecutive '>' characters, to avoid
|
|
|
|
the C++ syntactic ambiguity. */
|
2003-12-04 21:03:39 +01:00
|
|
|
if (d_last_char (dpi) == '>')
|
2003-11-27 02:17:34 +01:00
|
|
|
d_append_char (dpi, ' ');
|
|
|
|
d_append_char (dpi, '>');
|
|
|
|
|
|
|
|
dpi->modifiers = hold_dpm;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
long i;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *a;
|
2003-11-21 18:42:45 +01:00
|
|
|
struct d_print_template *hold_dpt;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dpi->templates == NULL)
|
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i = dc->u.s_number.number;
|
2005-05-24 23:01:33 +02:00
|
|
|
for (a = d_right (dpi->templates->template_decl);
|
2003-11-21 18:42:45 +01:00
|
|
|
a != NULL;
|
|
|
|
a = d_right (a))
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (i <= 0)
|
|
|
|
break;
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
if (i != 0 || a == NULL)
|
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* While processing this parameter, we need to pop the list of
|
|
|
|
templates. This is because the template parameter may
|
|
|
|
itself be a reference to a parameter of an outer
|
|
|
|
template. */
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
hold_dpt = dpi->templates;
|
|
|
|
dpi->templates = hold_dpt->next;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (a));
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->templates = hold_dpt;
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CTOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, dc->u.s_ctor.name);
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_DTOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '~');
|
|
|
|
d_print_comp (dpi, dc->u.s_dtor.name);
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VTABLE:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "vtable for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VTT:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "VTT for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "construction vtable for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "-in-");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "typeinfo for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "typeinfo name for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPEINFO_FN:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "typeinfo fn for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_THUNK:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "non-virtual thunk to ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "virtual thunk to ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "covariant return thunk to ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_JAVA_CLASS:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "java Class for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_GUARD:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "guard variable for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_REFTEMP:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "reference temporary for ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2005-05-26 01:32:36 +02:00
|
|
|
case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
|
|
|
|
d_append_string_constant (dpi, "hidden alias for ");
|
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_SUB_STD:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len);
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE:
|
|
|
|
case DEMANGLE_COMPONENT_CONST:
|
2004-02-24 17:30:50 +01:00
|
|
|
{
|
|
|
|
struct d_print_mod *pdpm;
|
|
|
|
|
|
|
|
/* When printing arrays, it's possible to have cases where the
|
|
|
|
same CV-qualifier gets pushed on the stack multiple times.
|
|
|
|
We only need to print it once. */
|
|
|
|
|
|
|
|
for (pdpm = dpi->modifiers; pdpm != NULL; pdpm = pdpm->next)
|
|
|
|
{
|
|
|
|
if (! pdpm->printed)
|
|
|
|
{
|
|
|
|
if (pdpm->mod->type != DEMANGLE_COMPONENT_RESTRICT
|
|
|
|
&& pdpm->mod->type != DEMANGLE_COMPONENT_VOLATILE
|
|
|
|
&& pdpm->mod->type != DEMANGLE_COMPONENT_CONST)
|
|
|
|
break;
|
|
|
|
if (pdpm->mod->type == dc->type)
|
|
|
|
{
|
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Fall through. */
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
|
|
|
|
case DEMANGLE_COMPONENT_POINTER:
|
|
|
|
case DEMANGLE_COMPONENT_REFERENCE:
|
|
|
|
case DEMANGLE_COMPONENT_COMPLEX:
|
|
|
|
case DEMANGLE_COMPONENT_IMAGINARY:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
/* We keep a list of modifiers on the stack. */
|
|
|
|
struct d_print_mod dpm;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpm.next = dpi->modifiers;
|
|
|
|
dpi->modifiers = &dpm;
|
|
|
|
dpm.mod = dc;
|
|
|
|
dpm.printed = 0;
|
2003-11-27 02:17:34 +01:00
|
|
|
dpm.templates = dpi->templates;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
2000-10-23 17:30:54 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* If the modifier didn't get printed by the type, print it
|
|
|
|
now. */
|
|
|
|
if (! dpm.printed)
|
|
|
|
d_print_mod (dpi, dc);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->modifiers = dpm.next;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_BUILTIN_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
if ((dpi->options & DMGL_JAVA) == 0)
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_buffer (dpi, dc->u.s_builtin.type->name,
|
|
|
|
dc->u.s_builtin.type->len);
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_buffer (dpi, dc->u.s_builtin.type->java_name,
|
|
|
|
dc->u.s_builtin.type->java_len);
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2005-12-11 03:16:09 +01:00
|
|
|
if ((dpi->options & DMGL_RET_POSTFIX) != 0)
|
|
|
|
d_print_function_type (dpi, dc, dpi->modifiers);
|
|
|
|
|
|
|
|
/* Print return type if present */
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_left (dc) != NULL)
|
|
|
|
{
|
|
|
|
struct d_print_mod dpm;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* We must pass this type down as a modifier in order to
|
|
|
|
print it in the right location. */
|
|
|
|
dpm.next = dpi->modifiers;
|
|
|
|
dpi->modifiers = &dpm;
|
|
|
|
dpm.mod = dc;
|
|
|
|
dpm.printed = 0;
|
2003-11-27 02:17:34 +01:00
|
|
|
dpm.templates = dpi->templates;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->modifiers = dpm.next;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dpm.printed)
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2005-12-11 03:16:09 +01:00
|
|
|
/* In standard prefix notation, there is a space between the
|
|
|
|
return type and the function signature. */
|
|
|
|
if ((dpi->options & DMGL_RET_POSTFIX) == 0)
|
|
|
|
d_append_char (dpi, ' ');
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2005-12-11 03:16:09 +01:00
|
|
|
if ((dpi->options & DMGL_RET_POSTFIX) == 0)
|
|
|
|
d_print_function_type (dpi, dc, dpi->modifiers);
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_ARRAY_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
struct d_print_mod *hold_modifiers;
|
|
|
|
struct d_print_mod adpm[4];
|
|
|
|
unsigned int i;
|
|
|
|
struct d_print_mod *pdpm;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* We must pass this type down as a modifier in order to print
|
2004-02-24 17:30:50 +01:00
|
|
|
multi-dimensional arrays correctly. If the array itself is
|
|
|
|
CV-qualified, we act as though the element type were
|
|
|
|
CV-qualified. We do this by copying the modifiers down
|
|
|
|
rather than fiddling pointers, so that we don't wind up
|
|
|
|
with a d_print_mod higher on the stack pointing into our
|
|
|
|
stack frame after we return. */
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2004-02-24 17:30:50 +01:00
|
|
|
hold_modifiers = dpi->modifiers;
|
|
|
|
|
|
|
|
adpm[0].next = hold_modifiers;
|
|
|
|
dpi->modifiers = &adpm[0];
|
|
|
|
adpm[0].mod = dc;
|
|
|
|
adpm[0].printed = 0;
|
|
|
|
adpm[0].templates = dpi->templates;
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
pdpm = hold_modifiers;
|
|
|
|
while (pdpm != NULL
|
|
|
|
&& (pdpm->mod->type == DEMANGLE_COMPONENT_RESTRICT
|
|
|
|
|| pdpm->mod->type == DEMANGLE_COMPONENT_VOLATILE
|
|
|
|
|| pdpm->mod->type == DEMANGLE_COMPONENT_CONST))
|
|
|
|
{
|
|
|
|
if (! pdpm->printed)
|
|
|
|
{
|
|
|
|
if (i >= sizeof adpm / sizeof adpm[0])
|
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
adpm[i] = *pdpm;
|
|
|
|
adpm[i].next = dpi->modifiers;
|
|
|
|
dpi->modifiers = &adpm[i];
|
|
|
|
pdpm->printed = 1;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdpm = pdpm->next;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-02-24 17:30:50 +01:00
|
|
|
dpi->modifiers = hold_modifiers;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-02-24 17:30:50 +01:00
|
|
|
if (adpm[0].printed)
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-02-24 17:30:50 +01:00
|
|
|
while (i > 1)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
d_print_mod (dpi, adpm[i].mod);
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_array_type (dpi, dc, dpi->modifiers);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
struct d_print_mod dpm;
|
|
|
|
|
|
|
|
dpm.next = dpi->modifiers;
|
|
|
|
dpi->modifiers = &dpm;
|
|
|
|
dpm.mod = dc;
|
|
|
|
dpm.printed = 0;
|
2003-11-27 02:17:34 +01:00
|
|
|
dpm.templates = dpi->templates;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
/* If the modifier didn't get printed by the type, print it
|
|
|
|
now. */
|
|
|
|
if (! dpm.printed)
|
|
|
|
{
|
|
|
|
d_append_char (dpi, ' ');
|
|
|
|
d_print_comp (dpi, d_left (dc));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "::*");
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->modifiers = dpm.next;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_ARGLIST:
|
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
if (d_right (dc) != NULL)
|
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, ", ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
}
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_OPERATOR:
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "operator");
|
2003-11-21 18:42:45 +01:00
|
|
|
c = dc->u.s_operator.op->name[0];
|
2003-12-04 21:03:39 +01:00
|
|
|
if (IS_LOWER (c))
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, ' ');
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_buffer (dpi, dc->u.s_operator.op->name,
|
|
|
|
dc->u.s_operator.op->len);
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "operator ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, dc->u.s_extended_operator.name);
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CAST:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "operator ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_cast (dpi, dc);
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_UNARY:
|
|
|
|
if (d_left (dc)->type != DEMANGLE_COMPONENT_CAST)
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_expr_op (dpi, d_left (dc));
|
|
|
|
else
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-02-25 03:04:37 +01:00
|
|
|
d_append_char (dpi, '(');
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_cast (dpi, d_left (dc));
|
|
|
|
d_append_char (dpi, ')');
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '(');
|
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
d_append_char (dpi, ')');
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_BINARY:
|
|
|
|
if (d_right (dc)->type != DEMANGLE_COMPONENT_BINARY_ARGS)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-12-04 21:03:39 +01:00
|
|
|
|
|
|
|
/* We wrap an expression which uses the greater-than operator in
|
|
|
|
an extra layer of parens so that it does not get confused
|
|
|
|
with the '>' which ends the template parameters. */
|
2004-01-12 22:24:38 +01:00
|
|
|
if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
|
2003-12-22 17:03:32 +01:00
|
|
|
&& d_left (dc)->u.s_operator.op->len == 1
|
|
|
|
&& d_left (dc)->u.s_operator.op->name[0] == '>')
|
2003-12-04 21:03:39 +01:00
|
|
|
d_append_char (dpi, '(');
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '(');
|
|
|
|
d_print_comp (dpi, d_left (d_right (dc)));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, ") ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_expr_op (dpi, d_left (dc));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, " (");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (d_right (dc)));
|
|
|
|
d_append_char (dpi, ')');
|
2003-12-04 21:03:39 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
|
2003-12-22 17:03:32 +01:00
|
|
|
&& d_left (dc)->u.s_operator.op->len == 1
|
|
|
|
&& d_left (dc)->u.s_operator.op->name[0] == '>')
|
2003-12-04 21:03:39 +01:00
|
|
|
d_append_char (dpi, ')');
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_BINARY_ARGS:
|
|
|
|
/* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TRINARY:
|
|
|
|
if (d_right (dc)->type != DEMANGLE_COMPONENT_TRINARY_ARG1
|
|
|
|
|| d_right (d_right (dc))->type != DEMANGLE_COMPONENT_TRINARY_ARG2)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d_append_char (dpi, '(');
|
|
|
|
d_print_comp (dpi, d_left (d_right (dc)));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, ") ");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_expr_op (dpi, d_left (dc));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, " (");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (d_right (d_right (dc))));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, ") : (");
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_right (d_right (d_right (dc))));
|
|
|
|
d_append_char (dpi, ')');
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TRINARY_ARG1:
|
|
|
|
case DEMANGLE_COMPONENT_TRINARY_ARG2:
|
|
|
|
/* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_LITERAL:
|
|
|
|
case DEMANGLE_COMPONENT_LITERAL_NEG:
|
2004-02-25 06:40:03 +01:00
|
|
|
{
|
|
|
|
enum d_builtin_type_print tp;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-02-25 06:40:03 +01:00
|
|
|
/* For some builtin types, produce simpler output. */
|
|
|
|
tp = D_PRINT_DEFAULT;
|
|
|
|
if (d_left (dc)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE)
|
|
|
|
{
|
|
|
|
tp = d_left (dc)->u.s_builtin.type->print;
|
|
|
|
switch (tp)
|
|
|
|
{
|
|
|
|
case D_PRINT_INT:
|
|
|
|
case D_PRINT_UNSIGNED:
|
|
|
|
case D_PRINT_LONG:
|
|
|
|
case D_PRINT_UNSIGNED_LONG:
|
|
|
|
case D_PRINT_LONG_LONG:
|
|
|
|
case D_PRINT_UNSIGNED_LONG_LONG:
|
|
|
|
if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME)
|
|
|
|
{
|
|
|
|
if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
|
|
|
|
d_append_char (dpi, '-');
|
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
switch (tp)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case D_PRINT_UNSIGNED:
|
|
|
|
d_append_char (dpi, 'u');
|
|
|
|
break;
|
|
|
|
case D_PRINT_LONG:
|
|
|
|
d_append_char (dpi, 'l');
|
|
|
|
break;
|
|
|
|
case D_PRINT_UNSIGNED_LONG:
|
|
|
|
d_append_string_constant (dpi, "ul");
|
|
|
|
break;
|
|
|
|
case D_PRINT_LONG_LONG:
|
|
|
|
d_append_string_constant (dpi, "ll");
|
|
|
|
break;
|
|
|
|
case D_PRINT_UNSIGNED_LONG_LONG:
|
|
|
|
d_append_string_constant (dpi, "ull");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-02-25 06:40:03 +01:00
|
|
|
case D_PRINT_BOOL:
|
|
|
|
if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME
|
|
|
|
&& d_right (dc)->u.s_name.len == 1
|
|
|
|
&& dc->type == DEMANGLE_COMPONENT_LITERAL)
|
|
|
|
{
|
|
|
|
switch (d_right (dc)->u.s_name.s[0])
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
d_append_string_constant (dpi, "false");
|
|
|
|
return;
|
|
|
|
case '1':
|
|
|
|
d_append_string_constant (dpi, "true");
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2004-02-25 06:40:03 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2004-02-25 06:40:03 +01:00
|
|
|
d_append_char (dpi, '(');
|
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
d_append_char (dpi, ')');
|
|
|
|
if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
|
|
|
|
d_append_char (dpi, '-');
|
|
|
|
if (tp == D_PRINT_FLOAT)
|
|
|
|
d_append_char (dpi, '[');
|
|
|
|
d_print_comp (dpi, d_right (dc));
|
|
|
|
if (tp == D_PRINT_FLOAT)
|
|
|
|
d_append_char (dpi, ']');
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
default:
|
|
|
|
d_print_error (dpi);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* Print a Java dentifier. For Java we try to handle encoded extended
|
|
|
|
Unicode characters. The C++ ABI doesn't mention Unicode encoding,
|
|
|
|
so we don't it for C++. Characters are encoded as
|
|
|
|
__U<hex-char>+_. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_java_identifier (struct d_print_info *dpi, const char *name, int len)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
const char *p;
|
|
|
|
const char *end;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
end = name + len;
|
|
|
|
for (p = name; p < end; ++p)
|
|
|
|
{
|
|
|
|
if (end - p > 3
|
|
|
|
&& p[0] == '_'
|
|
|
|
&& p[1] == '_'
|
|
|
|
&& p[2] == 'U')
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
unsigned long c;
|
|
|
|
const char *q;
|
|
|
|
|
|
|
|
c = 0;
|
|
|
|
for (q = p + 3; q < end; ++q)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-12-22 17:03:32 +01:00
|
|
|
int dig;
|
|
|
|
|
|
|
|
if (IS_DIGIT (*q))
|
|
|
|
dig = *q - '0';
|
|
|
|
else if (*q >= 'A' && *q <= 'F')
|
|
|
|
dig = *q - 'A' + 10;
|
|
|
|
else if (*q >= 'a' && *q <= 'f')
|
|
|
|
dig = *q - 'a' + 10;
|
|
|
|
else
|
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
c = c * 16 + dig;
|
|
|
|
}
|
|
|
|
/* If the Unicode character is larger than 256, we don't try
|
|
|
|
to deal with it here. FIXME. */
|
|
|
|
if (q < end && *q == '_' && c < 256)
|
|
|
|
{
|
|
|
|
d_append_char (dpi, c);
|
|
|
|
p = q;
|
|
|
|
continue;
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
|
|
|
}
|
2003-12-22 17:03:32 +01:00
|
|
|
|
|
|
|
d_append_char (dpi, *p);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
/* Print a list of modifiers. SUFFIX is 1 if we are printing
|
|
|
|
qualifiers on this after printing a function. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_mod_list (struct d_print_info *dpi,
|
|
|
|
struct d_print_mod *mods, int suffix)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-27 02:17:34 +01:00
|
|
|
struct d_print_template *hold_dpt;
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
if (mods == NULL || d_print_saw_error (dpi))
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
if (mods->printed
|
|
|
|
|| (! suffix
|
2004-01-12 22:24:38 +01:00
|
|
|
&& (mods->mod->type == DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
|| mods->mod->type == DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
|| mods->mod->type == DEMANGLE_COMPONENT_CONST_THIS)))
|
2003-12-04 21:03:39 +01:00
|
|
|
{
|
|
|
|
d_print_mod_list (dpi, mods->next, suffix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
mods->printed = 1;
|
|
|
|
|
|
|
|
hold_dpt = dpi->templates;
|
|
|
|
dpi->templates = mods->templates;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_function_type (dpi, mods->mod, mods->next);
|
2003-11-27 02:17:34 +01:00
|
|
|
dpi->templates = hold_dpt;
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-01-12 22:24:38 +01:00
|
|
|
else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
d_print_array_type (dpi, mods->mod, mods->next);
|
2003-11-27 02:17:34 +01:00
|
|
|
dpi->templates = hold_dpt;
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2004-01-12 22:24:38 +01:00
|
|
|
else if (mods->mod->type == DEMANGLE_COMPONENT_LOCAL_NAME)
|
2003-12-19 23:03:41 +01:00
|
|
|
{
|
|
|
|
struct d_print_mod *hold_modifiers;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dc;
|
2003-12-19 23:03:41 +01:00
|
|
|
|
|
|
|
/* When this is on the modifier stack, we have pulled any
|
|
|
|
qualifiers off the right argument already. Otherwise, we
|
|
|
|
print it as usual, but don't let the left argument see any
|
|
|
|
modifiers. */
|
|
|
|
|
|
|
|
hold_modifiers = dpi->modifiers;
|
|
|
|
dpi->modifiers = NULL;
|
|
|
|
d_print_comp (dpi, d_left (mods->mod));
|
|
|
|
dpi->modifiers = hold_modifiers;
|
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
if ((dpi->options & DMGL_JAVA) == 0)
|
|
|
|
d_append_string_constant (dpi, "::");
|
|
|
|
else
|
|
|
|
d_append_char (dpi, '.');
|
2003-12-19 23:03:41 +01:00
|
|
|
|
|
|
|
dc = d_right (mods->mod);
|
2004-01-12 22:24:38 +01:00
|
|
|
while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
|
|
|
|
|| dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
|
|
|
|
|| dc->type == DEMANGLE_COMPONENT_CONST_THIS)
|
2003-12-19 23:03:41 +01:00
|
|
|
dc = d_left (dc);
|
|
|
|
|
|
|
|
d_print_comp (dpi, dc);
|
|
|
|
|
|
|
|
dpi->templates = hold_dpt;
|
|
|
|
return;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_mod (dpi, mods->mod);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
dpi->templates = hold_dpt;
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
d_print_mod_list (dpi, mods->next, suffix);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-27 02:17:34 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Print a modifier. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_mod (struct d_print_info *dpi,
|
|
|
|
const struct demangle_component *mod)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
switch (mod->type)
|
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT:
|
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, " restrict");
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VOLATILE:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, " volatile");
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CONST:
|
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, " const");
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, ' ');
|
|
|
|
d_print_comp (dpi, d_right (mod));
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_POINTER:
|
2003-11-21 18:42:45 +01:00
|
|
|
/* There is no pointer symbol in Java. */
|
|
|
|
if ((dpi->options & DMGL_JAVA) == 0)
|
|
|
|
d_append_char (dpi, '*');
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_REFERENCE:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '&');
|
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_COMPLEX:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "complex ");
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_IMAGINARY:
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "imaginary ");
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
|
2003-12-04 21:03:39 +01:00
|
|
|
if (d_last_char (dpi) != '(')
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, ' ');
|
|
|
|
d_print_comp (dpi, d_left (mod));
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, "::*");
|
2003-11-21 18:42:45 +01:00
|
|
|
return;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPED_NAME:
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (mod));
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
/* Otherwise, we have something that won't go back on the
|
|
|
|
modifier stack, so we can just print it. */
|
|
|
|
d_print_comp (dpi, mod);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Print a function type, except for the return type. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_function_type (struct d_print_info *dpi,
|
|
|
|
const struct demangle_component *dc,
|
|
|
|
struct d_print_mod *mods)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-27 02:17:34 +01:00
|
|
|
int need_paren;
|
|
|
|
int saw_mod;
|
2004-02-25 06:40:03 +01:00
|
|
|
int need_space;
|
2003-11-27 02:17:34 +01:00
|
|
|
struct d_print_mod *p;
|
2003-12-19 23:03:41 +01:00
|
|
|
struct d_print_mod *hold_modifiers;
|
2003-11-27 02:17:34 +01:00
|
|
|
|
|
|
|
need_paren = 0;
|
|
|
|
saw_mod = 0;
|
2004-02-25 06:40:03 +01:00
|
|
|
need_space = 0;
|
2003-11-27 02:17:34 +01:00
|
|
|
for (p = mods; p != NULL; p = p->next)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2003-11-27 02:17:34 +01:00
|
|
|
if (p->printed)
|
|
|
|
break;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
saw_mod = 1;
|
|
|
|
switch (p->mod->type)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-02-25 06:40:03 +01:00
|
|
|
case DEMANGLE_COMPONENT_POINTER:
|
|
|
|
case DEMANGLE_COMPONENT_REFERENCE:
|
|
|
|
need_paren = 1;
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE:
|
|
|
|
case DEMANGLE_COMPONENT_CONST:
|
|
|
|
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
|
|
|
|
case DEMANGLE_COMPONENT_COMPLEX:
|
|
|
|
case DEMANGLE_COMPONENT_IMAGINARY:
|
|
|
|
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
|
2004-02-25 06:40:03 +01:00
|
|
|
need_space = 1;
|
2003-11-27 02:17:34 +01:00
|
|
|
need_paren = 1;
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
2003-12-04 21:03:39 +01:00
|
|
|
break;
|
2003-11-27 02:17:34 +01:00
|
|
|
default:
|
|
|
|
break;
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2003-11-27 02:17:34 +01:00
|
|
|
if (need_paren)
|
|
|
|
break;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
if (d_left (dc) != NULL && ! saw_mod)
|
|
|
|
need_paren = 1;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
if (need_paren)
|
2003-12-04 21:03:39 +01:00
|
|
|
{
|
2004-02-25 06:40:03 +01:00
|
|
|
if (! need_space)
|
2003-12-04 21:03:39 +01:00
|
|
|
{
|
2004-02-25 06:40:03 +01:00
|
|
|
if (d_last_char (dpi) != '('
|
|
|
|
&& d_last_char (dpi) != '*')
|
|
|
|
need_space = 1;
|
2003-12-04 21:03:39 +01:00
|
|
|
}
|
2004-02-25 06:40:03 +01:00
|
|
|
if (need_space && d_last_char (dpi) != ' ')
|
|
|
|
d_append_char (dpi, ' ');
|
2003-12-04 21:03:39 +01:00
|
|
|
d_append_char (dpi, '(');
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-19 23:03:41 +01:00
|
|
|
hold_modifiers = dpi->modifiers;
|
|
|
|
dpi->modifiers = NULL;
|
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
d_print_mod_list (dpi, mods, 0);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
if (need_paren)
|
|
|
|
d_append_char (dpi, ')');
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '(');
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_right (dc) != NULL)
|
2003-12-19 23:03:41 +01:00
|
|
|
d_print_comp (dpi, d_right (dc));
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, ')');
|
2003-12-04 21:03:39 +01:00
|
|
|
|
|
|
|
d_print_mod_list (dpi, mods, 1);
|
2003-12-19 23:03:41 +01:00
|
|
|
|
|
|
|
dpi->modifiers = hold_modifiers;
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Print an array type, except for the element type. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_array_type (struct d_print_info *dpi,
|
|
|
|
const struct demangle_component *dc,
|
|
|
|
struct d_print_mod *mods)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
|
|
|
int need_space;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
need_space = 1;
|
|
|
|
if (mods != NULL)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
int need_paren;
|
|
|
|
struct d_print_mod *p;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
need_paren = 0;
|
|
|
|
for (p = mods; p != NULL; p = p->next)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
if (! p->printed)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
if (p->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
|
|
|
|
{
|
|
|
|
need_space = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
need_paren = 1;
|
|
|
|
need_space = 1;
|
|
|
|
break;
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (need_paren)
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_string_constant (dpi, " (");
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
d_print_mod_list (dpi, mods, 0);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (need_paren)
|
|
|
|
d_append_char (dpi, ')');
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (need_space)
|
|
|
|
d_append_char (dpi, ' ');
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '[');
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (d_left (dc) != NULL)
|
|
|
|
d_print_comp (dpi, d_left (dc));
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, ']');
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Print an operator in an expression. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_expr_op (struct d_print_info *dpi,
|
|
|
|
const struct demangle_component *dc)
|
2003-11-21 18:42:45 +01:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
if (dc->type == DEMANGLE_COMPONENT_OPERATOR)
|
2003-12-22 17:03:32 +01:00
|
|
|
d_append_buffer (dpi, dc->u.s_operator.op->name,
|
|
|
|
dc->u.s_operator.op->len);
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
|
|
|
d_print_comp (dpi, dc);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Print a cast. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
d_print_cast (struct d_print_info *dpi,
|
|
|
|
const struct demangle_component *dc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2004-01-12 22:24:38 +01:00
|
|
|
if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (dc));
|
|
|
|
else
|
|
|
|
{
|
2003-11-27 02:17:34 +01:00
|
|
|
struct d_print_mod *hold_dpm;
|
2003-11-21 18:42:45 +01:00
|
|
|
struct d_print_template dpt;
|
2003-11-19 17:19:14 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* It appears that for a templated cast operator, we need to put
|
|
|
|
the template parameters in scope for the operator name, but
|
|
|
|
not for the parameters. The effect is that we need to handle
|
2003-12-02 00:54:49 +01:00
|
|
|
the template printing here. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-27 02:17:34 +01:00
|
|
|
hold_dpm = dpi->modifiers;
|
|
|
|
dpi->modifiers = NULL;
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpt.next = dpi->templates;
|
|
|
|
dpi->templates = &dpt;
|
2005-05-24 23:01:33 +02:00
|
|
|
dpt.template_decl = d_left (dc);
|
2003-11-19 17:19:14 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
d_print_comp (dpi, d_left (d_left (dc)));
|
2003-11-19 17:19:14 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
dpi->templates = dpt.next;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-12-04 21:03:39 +01:00
|
|
|
if (d_last_char (dpi) == '<')
|
|
|
|
d_append_char (dpi, ' ');
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, '<');
|
|
|
|
d_print_comp (dpi, d_right (d_left (dc)));
|
|
|
|
/* Avoid generating two consecutive '>' characters, to avoid
|
|
|
|
the C++ syntactic ambiguity. */
|
2003-12-04 21:03:39 +01:00
|
|
|
if (d_last_char (dpi) == '>')
|
2003-11-21 18:42:45 +01:00
|
|
|
d_append_char (dpi, ' ');
|
|
|
|
d_append_char (dpi, '>');
|
2003-11-27 02:17:34 +01:00
|
|
|
|
|
|
|
dpi->modifiers = hold_dpm;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the information structure we use to pass around
|
|
|
|
information. */
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
CP_STATIC_IF_GLIBCPP_V3
|
|
|
|
void
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_init_info (const char *mangled, int options, size_t len,
|
|
|
|
struct d_info *di)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
di->s = mangled;
|
2003-12-22 17:03:32 +01:00
|
|
|
di->send = mangled + len;
|
2003-11-21 18:42:45 +01:00
|
|
|
di->options = options;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
di->n = mangled;
|
|
|
|
|
|
|
|
/* We can not need more components than twice the number of chars in
|
|
|
|
the mangled string. Most components correspond directly to
|
|
|
|
chars, but the ARGLIST types are exceptions. */
|
|
|
|
di->num_comps = 2 * len;
|
|
|
|
di->next_comp = 0;
|
|
|
|
|
|
|
|
/* Similarly, we can not need more substitutions than there are
|
2003-11-27 02:17:34 +01:00
|
|
|
chars in the mangled string. */
|
|
|
|
di->num_subs = len;
|
2003-11-21 18:42:45 +01:00
|
|
|
di->next_sub = 0;
|
2003-12-22 17:03:32 +01:00
|
|
|
di->did_subs = 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
di->last_name = NULL;
|
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
di->expansion = 0;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
|
|
|
|
name, return a buffer allocated with malloc holding the demangled
|
|
|
|
name. OPTIONS is the usual libiberty demangler options. On
|
|
|
|
success, this sets *PALC to the allocated size of the returned
|
|
|
|
buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
|
|
|
|
a memory allocation failure. On failure, this returns NULL. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
static char *
|
2005-03-27 07:28:42 +02:00
|
|
|
d_demangle (const char* mangled, int options, size_t *palc)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
size_t len;
|
|
|
|
int type;
|
|
|
|
struct d_info di;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dc;
|
2003-12-22 17:03:32 +01:00
|
|
|
int estimate;
|
2003-11-21 18:42:45 +01:00
|
|
|
char *ret;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
*palc = 0;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
len = strlen (mangled);
|
|
|
|
|
|
|
|
if (mangled[0] == '_' && mangled[1] == 'Z')
|
|
|
|
type = 0;
|
|
|
|
else if (strncmp (mangled, "_GLOBAL_", 8) == 0
|
|
|
|
&& (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
|
|
|
|
&& (mangled[9] == 'D' || mangled[9] == 'I')
|
|
|
|
&& mangled[10] == '_')
|
|
|
|
{
|
|
|
|
char *r;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2005-05-24 23:01:33 +02:00
|
|
|
r = (char *) malloc (40 + len - 11);
|
2003-11-21 18:42:45 +01:00
|
|
|
if (r == NULL)
|
|
|
|
*palc = 1;
|
|
|
|
else
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (mangled[9] == 'I')
|
|
|
|
strcpy (r, "global constructors keyed to ");
|
|
|
|
else
|
|
|
|
strcpy (r, "global destructors keyed to ");
|
|
|
|
strcat (r, mangled + 11);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
return r;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if ((options & DMGL_TYPES) == 0)
|
|
|
|
return NULL;
|
|
|
|
type = 1;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
cplus_demangle_init_info (mangled, options, len, &di);
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
#ifdef CP_DYNAMIC_ARRAYS
|
2004-01-12 22:24:38 +01:00
|
|
|
__extension__ struct demangle_component comps[di.num_comps];
|
|
|
|
__extension__ struct demangle_component *subs[di.num_subs];
|
2003-12-22 17:03:32 +01:00
|
|
|
|
|
|
|
di.comps = &comps[0];
|
|
|
|
di.subs = &subs[0];
|
|
|
|
#else
|
2004-01-12 22:24:38 +01:00
|
|
|
di.comps = ((struct demangle_component *)
|
|
|
|
malloc (di.num_comps * sizeof (struct demangle_component)));
|
|
|
|
di.subs = ((struct demangle_component **)
|
|
|
|
malloc (di.num_subs * sizeof (struct demangle_component *)));
|
2003-12-22 17:03:32 +01:00
|
|
|
if (di.comps == NULL || di.subs == NULL)
|
|
|
|
{
|
|
|
|
if (di.comps != NULL)
|
|
|
|
free (di.comps);
|
|
|
|
if (di.subs != NULL)
|
|
|
|
free (di.subs);
|
|
|
|
*palc = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (! type)
|
2004-01-12 22:24:38 +01:00
|
|
|
dc = cplus_demangle_mangled_name (&di, 1);
|
2003-12-22 17:03:32 +01:00
|
|
|
else
|
2004-01-12 22:24:38 +01:00
|
|
|
dc = cplus_demangle_type (&di);
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* If DMGL_PARAMS is set, then if we didn't consume the entire
|
|
|
|
mangled string, then we didn't successfully demangle it. If
|
|
|
|
DMGL_PARAMS is not set, we didn't look at the trailing
|
|
|
|
parameters. */
|
|
|
|
if (((options & DMGL_PARAMS) != 0) && d_peek_char (&di) != '\0')
|
|
|
|
dc = NULL;
|
2003-12-02 00:54:49 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#ifdef CP_DEMANGLE_DEBUG
|
2003-12-22 17:03:32 +01:00
|
|
|
if (dc == NULL)
|
|
|
|
printf ("failed demangling\n");
|
|
|
|
else
|
|
|
|
d_dump (dc, 0);
|
2003-11-21 18:42:45 +01:00
|
|
|
#endif
|
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* We try to guess the length of the demangled string, to minimize
|
|
|
|
calls to realloc during demangling. */
|
|
|
|
estimate = len + di.expansion + 10 * di.did_subs;
|
|
|
|
estimate += estimate / 8;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
ret = NULL;
|
|
|
|
if (dc != NULL)
|
2004-01-12 22:24:38 +01:00
|
|
|
ret = cplus_demangle_print (options, dc, estimate, palc);
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
#ifndef CP_DYNAMIC_ARRAYS
|
|
|
|
free (di.comps);
|
|
|
|
free (di.subs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CP_DEMANGLE_DEBUG
|
|
|
|
if (ret != NULL)
|
|
|
|
{
|
|
|
|
int rlen;
|
|
|
|
|
|
|
|
rlen = strlen (ret);
|
|
|
|
if (rlen > 2 * estimate)
|
|
|
|
printf ("*** Length %d much greater than estimate %d\n",
|
|
|
|
rlen, estimate);
|
|
|
|
else if (rlen > estimate)
|
|
|
|
printf ("*** Length %d greater than estimate %d\n",
|
|
|
|
rlen, estimate);
|
|
|
|
else if (rlen < estimate / 2)
|
|
|
|
printf ("*** Length %d much less than estimate %d\n",
|
|
|
|
rlen, estimate);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return ret;
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2002-04-02 00:01:20 +02:00
|
|
|
#if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2005-03-27 07:28:42 +02:00
|
|
|
extern char *__cxa_demangle (const char *, char *, size_t *, int *);
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* ia64 ABI-mandated entry point in the C++ runtime library for
|
|
|
|
performing demangling. MANGLED_NAME is a NUL-terminated character
|
|
|
|
string containing the name to be demangled.
|
2000-07-20 20:56:16 +02:00
|
|
|
|
|
|
|
OUTPUT_BUFFER is a region of memory, allocated with malloc, of
|
|
|
|
*LENGTH bytes, into which the demangled name is stored. If
|
|
|
|
OUTPUT_BUFFER is not long enough, it is expanded using realloc.
|
|
|
|
OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
|
2003-11-21 18:42:45 +01:00
|
|
|
is placed in a region of memory allocated with malloc.
|
2000-07-20 20:56:16 +02:00
|
|
|
|
|
|
|
If LENGTH is non-NULL, the length of the buffer conaining the
|
2003-11-21 18:42:45 +01:00
|
|
|
demangled name, is placed in *LENGTH.
|
2000-07-20 20:56:16 +02:00
|
|
|
|
|
|
|
The return value is a pointer to the start of the NUL-terminated
|
|
|
|
demangled name, or NULL if the demangling fails. The caller is
|
2003-11-21 18:42:45 +01:00
|
|
|
responsible for deallocating this memory using free.
|
2000-07-20 20:56:16 +02:00
|
|
|
|
|
|
|
*STATUS is set to one of the following values:
|
|
|
|
0: The demangling operation succeeded.
|
2003-11-21 18:42:45 +01:00
|
|
|
-1: A memory allocation failure occurred.
|
2000-07-20 20:56:16 +02:00
|
|
|
-2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
|
|
|
|
-3: One of the arguments is invalid.
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
The demangling is performed using the C++ ABI mangling rules, with
|
2000-07-20 20:56:16 +02:00
|
|
|
GNU extensions. */
|
|
|
|
|
|
|
|
char *
|
2005-03-27 07:28:42 +02:00
|
|
|
__cxa_demangle (const char *mangled_name, char *output_buffer,
|
|
|
|
size_t *length, int *status)
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char *demangled;
|
|
|
|
size_t alc;
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (mangled_name == NULL)
|
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
if (status != NULL)
|
|
|
|
*status = -3;
|
2000-07-20 20:56:16 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (output_buffer != NULL && length == NULL)
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
if (status != NULL)
|
|
|
|
*status = -3;
|
2003-11-21 18:42:45 +01:00
|
|
|
return NULL;
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-02-24 17:30:50 +01:00
|
|
|
demangled = d_demangle (mangled_name, DMGL_PARAMS | DMGL_TYPES, &alc);
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
if (demangled == NULL)
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
if (status != NULL)
|
|
|
|
{
|
|
|
|
if (alc == 1)
|
|
|
|
*status = -1;
|
|
|
|
else
|
|
|
|
*status = -2;
|
|
|
|
}
|
2000-07-20 20:56:16 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
if (output_buffer == NULL)
|
|
|
|
{
|
|
|
|
if (length != NULL)
|
|
|
|
*length = alc;
|
|
|
|
}
|
2000-07-20 20:56:16 +02:00
|
|
|
else
|
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (strlen (demangled) < *length)
|
|
|
|
{
|
|
|
|
strcpy (output_buffer, demangled);
|
|
|
|
free (demangled);
|
|
|
|
demangled = output_buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free (output_buffer);
|
|
|
|
*length = alc;
|
|
|
|
}
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-02-24 17:30:50 +01:00
|
|
|
if (status != NULL)
|
|
|
|
*status = 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
return demangled;
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
|
|
|
|
2002-04-02 00:01:20 +02:00
|
|
|
#else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
|
|
|
|
mangled name, return a buffer allocated with malloc holding the
|
|
|
|
demangled name. Otherwise, return NULL. */
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
char *
|
2005-03-27 07:28:42 +02:00
|
|
|
cplus_demangle_v3 (const char* mangled, int options)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
size_t alc;
|
2000-12-05 20:08:13 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return d_demangle (mangled, options, &alc);
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
|
2001-02-02 19:58:51 +01:00
|
|
|
/* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
|
|
|
|
conventions, but the output formatting is a little different.
|
|
|
|
This instructs the C++ demangler not to emit pointer characters ("*"), and
|
|
|
|
to use Java's namespace separator symbol ("." instead of "::"). It then
|
|
|
|
does an additional pass over the demangled output to replace instances
|
|
|
|
of JArray<TYPE> with TYPE[]. */
|
|
|
|
|
|
|
|
char *
|
2005-03-27 07:28:42 +02:00
|
|
|
java_demangle_v3 (const char* mangled)
|
2001-02-02 19:58:51 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
size_t alc;
|
|
|
|
char *demangled;
|
|
|
|
int nesting;
|
|
|
|
char *from;
|
|
|
|
char *to;
|
|
|
|
|
2005-12-11 03:16:09 +01:00
|
|
|
demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX,
|
|
|
|
&alc);
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
if (demangled == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nesting = 0;
|
|
|
|
from = demangled;
|
|
|
|
to = from;
|
|
|
|
while (*from != '\0')
|
2001-02-02 19:58:51 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
if (strncmp (from, "JArray<", 7) == 0)
|
|
|
|
{
|
|
|
|
from += 7;
|
2001-02-02 19:58:51 +01:00
|
|
|
++nesting;
|
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else if (nesting > 0 && *from == '>')
|
|
|
|
{
|
|
|
|
while (to > demangled && to[-1] == ' ')
|
|
|
|
--to;
|
|
|
|
*to++ = '[';
|
|
|
|
*to++ = ']';
|
2001-02-02 19:58:51 +01:00
|
|
|
--nesting;
|
2003-11-21 18:42:45 +01:00
|
|
|
++from;
|
2001-02-02 19:58:51 +01:00
|
|
|
}
|
|
|
|
else
|
2003-11-21 18:42:45 +01:00
|
|
|
*to++ = *from++;
|
2001-02-02 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
*to = '\0';
|
2002-03-30 07:17:57 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
return demangled;
|
2001-02-02 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
2002-04-02 00:01:20 +02:00
|
|
|
#endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
|
2000-07-20 20:56:16 +02:00
|
|
|
|
2002-07-09 03:01:18 +02:00
|
|
|
#ifndef IN_GLIBCPP_V3
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
/* Demangle a string in order to find out whether it is a constructor
|
|
|
|
or destructor. Return non-zero on success. Set *CTOR_KIND and
|
|
|
|
*DTOR_KIND appropriately. */
|
|
|
|
|
|
|
|
static int
|
2005-03-27 07:28:42 +02:00
|
|
|
is_ctor_or_dtor (const char *mangled,
|
|
|
|
enum gnu_v3_ctor_kinds *ctor_kind,
|
|
|
|
enum gnu_v3_dtor_kinds *dtor_kind)
|
2001-03-20 19:22:38 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
struct d_info di;
|
2004-01-12 22:24:38 +01:00
|
|
|
struct demangle_component *dc;
|
2003-12-04 21:03:39 +01:00
|
|
|
int ret;
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
*ctor_kind = (enum gnu_v3_ctor_kinds) 0;
|
|
|
|
*dtor_kind = (enum gnu_v3_dtor_kinds) 0;
|
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
cplus_demangle_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di);
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
{
|
|
|
|
#ifdef CP_DYNAMIC_ARRAYS
|
2004-01-12 22:24:38 +01:00
|
|
|
__extension__ struct demangle_component comps[di.num_comps];
|
|
|
|
__extension__ struct demangle_component *subs[di.num_subs];
|
2003-12-22 17:03:32 +01:00
|
|
|
|
|
|
|
di.comps = &comps[0];
|
|
|
|
di.subs = &subs[0];
|
|
|
|
#else
|
2004-01-12 22:24:38 +01:00
|
|
|
di.comps = ((struct demangle_component *)
|
|
|
|
malloc (di.num_comps * sizeof (struct demangle_component)));
|
|
|
|
di.subs = ((struct demangle_component **)
|
|
|
|
malloc (di.num_subs * sizeof (struct demangle_component *)));
|
2003-12-22 17:03:32 +01:00
|
|
|
if (di.comps == NULL || di.subs == NULL)
|
|
|
|
{
|
|
|
|
if (di.comps != NULL)
|
|
|
|
free (di.comps);
|
|
|
|
if (di.subs != NULL)
|
|
|
|
free (di.subs);
|
2003-12-26 17:27:37 +01:00
|
|
|
return 0;
|
2003-12-22 17:03:32 +01:00
|
|
|
}
|
|
|
|
#endif
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2004-01-12 22:24:38 +01:00
|
|
|
dc = cplus_demangle_mangled_name (&di, 1);
|
2003-12-16 01:58:45 +01:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
/* Note that because we did not pass DMGL_PARAMS, we don't expect
|
|
|
|
to demangle the entire string. */
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-12-22 17:03:32 +01:00
|
|
|
ret = 0;
|
|
|
|
while (dc != NULL)
|
|
|
|
{
|
|
|
|
switch (dc->type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
dc = NULL;
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_TYPED_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_TEMPLATE:
|
|
|
|
case DEMANGLE_COMPONENT_RESTRICT_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_VOLATILE_THIS:
|
|
|
|
case DEMANGLE_COMPONENT_CONST_THIS:
|
2003-12-22 17:03:32 +01:00
|
|
|
dc = d_left (dc);
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_QUAL_NAME:
|
|
|
|
case DEMANGLE_COMPONENT_LOCAL_NAME:
|
2003-12-22 17:03:32 +01:00
|
|
|
dc = d_right (dc);
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_CTOR:
|
2003-12-22 17:03:32 +01:00
|
|
|
*ctor_kind = dc->u.s_ctor.kind;
|
|
|
|
ret = 1;
|
|
|
|
dc = NULL;
|
|
|
|
break;
|
2004-01-12 22:24:38 +01:00
|
|
|
case DEMANGLE_COMPONENT_DTOR:
|
2003-12-22 17:03:32 +01:00
|
|
|
*dtor_kind = dc->u.s_dtor.kind;
|
|
|
|
ret = 1;
|
|
|
|
dc = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CP_DYNAMIC_ARRAYS
|
|
|
|
free (di.subs);
|
|
|
|
free (di.comps);
|
|
|
|
#endif
|
|
|
|
}
|
2003-12-04 21:03:39 +01:00
|
|
|
|
|
|
|
return ret;
|
2001-03-20 19:22:38 +01:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Return whether NAME is the mangled form of a g++ V3 ABI constructor
|
|
|
|
name. A non-zero return indicates the type of constructor. */
|
2001-03-20 19:22:38 +01:00
|
|
|
|
|
|
|
enum gnu_v3_ctor_kinds
|
2005-03-27 07:28:42 +02:00
|
|
|
is_gnu_v3_mangled_ctor (const char *name)
|
2001-03-20 19:22:38 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
enum gnu_v3_ctor_kinds ctor_kind;
|
|
|
|
enum gnu_v3_dtor_kinds dtor_kind;
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
|
2002-09-20 15:45:20 +02:00
|
|
|
return (enum gnu_v3_ctor_kinds) 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
return ctor_kind;
|
2001-03-20 19:22:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
/* Return whether NAME is the mangled form of a g++ V3 ABI destructor
|
|
|
|
name. A non-zero return indicates the type of destructor. */
|
|
|
|
|
2001-03-20 19:22:38 +01:00
|
|
|
enum gnu_v3_dtor_kinds
|
2005-03-27 07:28:42 +02:00
|
|
|
is_gnu_v3_mangled_dtor (const char *name)
|
2001-03-20 19:22:38 +01:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
enum gnu_v3_ctor_kinds ctor_kind;
|
|
|
|
enum gnu_v3_dtor_kinds dtor_kind;
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
|
2002-09-20 15:45:20 +02:00
|
|
|
return (enum gnu_v3_dtor_kinds) 0;
|
2003-11-21 18:42:45 +01:00
|
|
|
return dtor_kind;
|
2001-03-20 19:22:38 +01:00
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#endif /* IN_GLIBCPP_V3 */
|
2001-03-20 19:22:38 +01:00
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
#ifdef STANDALONE_DEMANGLER
|
|
|
|
|
|
|
|
#include "getopt.h"
|
2003-11-21 18:42:45 +01:00
|
|
|
#include "dyn-string.h"
|
|
|
|
|
2005-03-28 19:14:34 +02:00
|
|
|
static void print_usage (FILE* fp, int exit_value);
|
2000-06-15 22:56:25 +02:00
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
#define IS_ALPHA(CHAR) \
|
|
|
|
(((CHAR) >= 'a' && (CHAR) <= 'z') \
|
|
|
|
|| ((CHAR) >= 'A' && (CHAR) <= 'Z'))
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* Non-zero if CHAR is a character than can occur in a mangled name. */
|
|
|
|
#define is_mangled_char(CHAR) \
|
2000-10-12 04:16:48 +02:00
|
|
|
(IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
|
|
|
|
|| (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* The name of this program, as invoked. */
|
|
|
|
const char* program_name;
|
|
|
|
|
|
|
|
/* Prints usage summary to FP and then exits with EXIT_VALUE. */
|
|
|
|
|
|
|
|
static void
|
2005-03-27 07:28:42 +02:00
|
|
|
print_usage (FILE* fp, int exit_value)
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
|
|
|
fprintf (fp, "Usage: %s [options] [names ...]\n", program_name);
|
2000-10-12 04:16:48 +02:00
|
|
|
fprintf (fp, "Options:\n");
|
2000-06-15 22:56:25 +02:00
|
|
|
fprintf (fp, " -h,--help Display this message.\n");
|
2003-11-24 20:33:33 +01:00
|
|
|
fprintf (fp, " -p,--no-params Don't display function parameters\n");
|
2000-06-15 22:56:25 +02:00
|
|
|
fprintf (fp, " -v,--verbose Produce verbose demanglings.\n");
|
|
|
|
fprintf (fp, "If names are provided, they are demangled. Otherwise filters standard input.\n");
|
|
|
|
|
|
|
|
exit (exit_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Option specification for getopt_long. */
|
2002-01-03 01:25:57 +01:00
|
|
|
static const struct option long_options[] =
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
2003-11-24 20:33:33 +01:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "no-params", no_argument, NULL, 'p' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ NULL, no_argument, NULL, 0 },
|
2000-06-15 22:56:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Main entry for a demangling filter executable. It will demangle
|
|
|
|
its command line arguments, if any. If none are provided, it will
|
|
|
|
filter stdin to stdout, replacing any recognized mangled C++ names
|
|
|
|
with their demangled equivalents. */
|
|
|
|
|
|
|
|
int
|
2005-03-27 07:28:42 +02:00
|
|
|
main (int argc, char *argv[])
|
2000-06-15 22:56:25 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int opt_char;
|
2003-11-21 18:42:45 +01:00
|
|
|
int options = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* Use the program name of this program, as invoked. */
|
|
|
|
program_name = argv[0];
|
|
|
|
|
|
|
|
/* Parse options. */
|
|
|
|
do
|
|
|
|
{
|
2003-11-24 20:33:33 +01:00
|
|
|
opt_char = getopt_long (argc, argv, "hpv", long_options, NULL);
|
2000-06-15 22:56:25 +02:00
|
|
|
switch (opt_char)
|
|
|
|
{
|
|
|
|
case '?': /* Unrecognized option. */
|
|
|
|
print_usage (stderr, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
print_usage (stdout, 0);
|
|
|
|
break;
|
|
|
|
|
2003-11-24 20:33:33 +01:00
|
|
|
case 'p':
|
|
|
|
options &= ~ DMGL_PARAMS;
|
|
|
|
break;
|
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
case 'v':
|
2003-11-21 18:42:45 +01:00
|
|
|
options |= DMGL_VERBOSE;
|
2000-06-15 22:56:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (opt_char != -1);
|
|
|
|
|
|
|
|
if (optind == argc)
|
|
|
|
/* No command line arguments were provided. Filter stdin. */
|
|
|
|
{
|
|
|
|
dyn_string_t mangled = dyn_string_new (3);
|
2003-11-21 18:42:45 +01:00
|
|
|
char *s;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* Read all of input. */
|
|
|
|
while (!feof (stdin))
|
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char c;
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* Pile characters into mangled until we hit one that can't
|
|
|
|
occur in a mangled name. */
|
|
|
|
c = getchar ();
|
|
|
|
while (!feof (stdin) && is_mangled_char (c))
|
|
|
|
{
|
|
|
|
dyn_string_append_char (mangled, c);
|
|
|
|
if (feof (stdin))
|
|
|
|
break;
|
|
|
|
c = getchar ();
|
|
|
|
}
|
|
|
|
|
2003-11-21 18:42:45 +01:00
|
|
|
if (dyn_string_length (mangled) > 0)
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2004-02-24 17:30:50 +01:00
|
|
|
#ifdef IN_GLIBCPP_V3
|
|
|
|
s = __cxa_demangle (dyn_string_buf (mangled), NULL, NULL, NULL);
|
|
|
|
#else
|
2003-11-21 18:42:45 +01:00
|
|
|
s = cplus_demangle_v3 (dyn_string_buf (mangled), options);
|
2004-02-24 17:30:50 +01:00
|
|
|
#endif
|
2003-11-21 18:42:45 +01:00
|
|
|
|
|
|
|
if (s != NULL)
|
|
|
|
{
|
|
|
|
fputs (s, stdout);
|
|
|
|
free (s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It might not have been a mangled name. Print the
|
|
|
|
original text. */
|
|
|
|
fputs (dyn_string_buf (mangled), stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
dyn_string_clear (mangled);
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* If we haven't hit EOF yet, we've read one character that
|
|
|
|
can't occur in a mangled name, so print it out. */
|
|
|
|
if (!feof (stdin))
|
|
|
|
putchar (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
dyn_string_delete (mangled);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Demangle command line arguments. */
|
|
|
|
{
|
|
|
|
/* Loop over command line arguments. */
|
|
|
|
for (i = optind; i < argc; ++i)
|
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
char *s;
|
2004-02-24 17:30:50 +01:00
|
|
|
#ifdef IN_GLIBCPP_V3
|
|
|
|
int status;
|
|
|
|
#endif
|
2003-11-21 18:42:45 +01:00
|
|
|
|
2000-06-15 22:56:25 +02:00
|
|
|
/* Attempt to demangle. */
|
2004-02-24 17:30:50 +01:00
|
|
|
#ifdef IN_GLIBCPP_V3
|
|
|
|
s = __cxa_demangle (argv[i], NULL, NULL, &status);
|
|
|
|
#else
|
2003-11-21 18:42:45 +01:00
|
|
|
s = cplus_demangle_v3 (argv[i], options);
|
2004-02-24 17:30:50 +01:00
|
|
|
#endif
|
2000-06-15 22:56:25 +02:00
|
|
|
|
|
|
|
/* If it worked, print the demangled name. */
|
2003-11-21 18:42:45 +01:00
|
|
|
if (s != NULL)
|
2000-07-20 20:56:16 +02:00
|
|
|
{
|
2003-11-21 18:42:45 +01:00
|
|
|
printf ("%s\n", s);
|
|
|
|
free (s);
|
2000-07-20 20:56:16 +02:00
|
|
|
}
|
2003-11-21 18:42:45 +01:00
|
|
|
else
|
2004-02-24 17:30:50 +01:00
|
|
|
{
|
|
|
|
#ifdef IN_GLIBCPP_V3
|
|
|
|
fprintf (stderr, "Failed: %s (status %d)\n", argv[i], status);
|
|
|
|
#else
|
|
|
|
fprintf (stderr, "Failed: %s\n", argv[i]);
|
|
|
|
#endif
|
|
|
|
}
|
2000-06-15 22:56:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* STANDALONE_DEMANGLER */
|