Subversion Repositories Kolibri OS

Rev

Rev 5191 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5191 Rev 6324
1
/* Demangler for g++ V3 ABI.
1
/* Demangler for g++ V3 ABI.
2
   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
2
   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014
3
   Free Software Foundation, Inc.
3
   Free Software Foundation, Inc.
4
   Written by Ian Lance Taylor .
4
   Written by Ian Lance Taylor .
5
 
5
 
6
   This file is part of the libiberty library, which is part of GCC.
6
   This file is part of the libiberty library, which is part of GCC.
7
 
7
 
8
   This file is free software; you can redistribute it and/or modify
8
   This file is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 2 of the License, or
10
   the Free Software Foundation; either version 2 of the License, or
11
   (at your option) any later version.
11
   (at your option) any later version.
12
 
12
 
13
   In addition to the permissions in the GNU General Public License, the
13
   In addition to the permissions in the GNU General Public License, the
14
   Free Software Foundation gives you unlimited permission to link the
14
   Free Software Foundation gives you unlimited permission to link the
15
   compiled version of this file into combinations with other programs,
15
   compiled version of this file into combinations with other programs,
16
   and to distribute those combinations without any restriction coming
16
   and to distribute those combinations without any restriction coming
17
   from the use of this file.  (The General Public License restrictions
17
   from the use of this file.  (The General Public License restrictions
18
   do apply in other respects; for example, they cover modification of
18
   do apply in other respects; for example, they cover modification of
19
   the file, and distribution when not linked into a combined
19
   the file, and distribution when not linked into a combined
20
   executable.)
20
   executable.)
21
 
21
 
22
   This program is distributed in the hope that it will be useful,
22
   This program is distributed in the hope that it will be useful,
23
   but WITHOUT ANY WARRANTY; without even the implied warranty of
23
   but WITHOUT ANY WARRANTY; without even the implied warranty of
24
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
   GNU General Public License for more details.
25
   GNU General Public License for more details.
26
 
26
 
27
   You should have received a copy of the GNU General Public License
27
   You should have received a copy of the GNU General Public License
28
   along with this program; if not, write to the Free Software
28
   along with this program; if not, write to the Free Software
29
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 
29
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 
30
*/
30
*/
31
 
31
 
32
/* This code implements a demangler for the g++ V3 ABI.  The ABI is
32
/* This code implements a demangler for the g++ V3 ABI.  The ABI is
33
   described on this web page:
33
   described on this web page:
34
       http://www.codesourcery.com/cxx-abi/abi.html#mangling
34
       http://www.codesourcery.com/cxx-abi/abi.html#mangling
35
 
35
 
36
   This code was written while looking at the demangler written by
36
   This code was written while looking at the demangler written by
37
   Alex Samuel .
37
   Alex Samuel .
38
 
38
 
39
   This code first pulls the mangled name apart into a list of
39
   This code first pulls the mangled name apart into a list of
40
   components, and then walks the list generating the demangled
40
   components, and then walks the list generating the demangled
41
   name.
41
   name.
42
 
42
 
43
   This file will normally define the following functions, q.v.:
43
   This file will normally define the following functions, q.v.:
44
      char *cplus_demangle_v3(const char *mangled, int options)
44
      char *cplus_demangle_v3(const char *mangled, int options)
45
      char *java_demangle_v3(const char *mangled)
45
      char *java_demangle_v3(const char *mangled)
46
      int cplus_demangle_v3_callback(const char *mangled, int options,
46
      int cplus_demangle_v3_callback(const char *mangled, int options,
47
                                     demangle_callbackref callback)
47
                                     demangle_callbackref callback)
48
      int java_demangle_v3_callback(const char *mangled,
48
      int java_demangle_v3_callback(const char *mangled,
49
                                    demangle_callbackref callback)
49
                                    demangle_callbackref callback)
50
      enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
50
      enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
51
      enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
51
      enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
52
 
52
 
53
   Also, the interface to the component list is public, and defined in
53
   Also, the interface to the component list is public, and defined in
54
   demangle.h.  The interface consists of these types, which are
54
   demangle.h.  The interface consists of these types, which are
55
   defined in demangle.h:
55
   defined in demangle.h:
56
      enum demangle_component_type
56
      enum demangle_component_type
57
      struct demangle_component
57
      struct demangle_component
58
      demangle_callbackref
58
      demangle_callbackref
59
   and these functions defined in this file:
59
   and these functions defined in this file:
60
      cplus_demangle_fill_name
60
      cplus_demangle_fill_name
61
      cplus_demangle_fill_extended_operator
61
      cplus_demangle_fill_extended_operator
62
      cplus_demangle_fill_ctor
62
      cplus_demangle_fill_ctor
63
      cplus_demangle_fill_dtor
63
      cplus_demangle_fill_dtor
64
      cplus_demangle_print
64
      cplus_demangle_print
65
      cplus_demangle_print_callback
65
      cplus_demangle_print_callback
66
   and other functions defined in the file cp-demint.c.
66
   and other functions defined in the file cp-demint.c.
67
 
67
 
68
   This file also defines some other functions and variables which are
68
   This file also defines some other functions and variables which are
69
   only to be used by the file cp-demint.c.
69
   only to be used by the file cp-demint.c.
70
 
70
 
71
   Preprocessor macros you can define while compiling this file:
71
   Preprocessor macros you can define while compiling this file:
72
 
72
 
73
   IN_LIBGCC2
73
   IN_LIBGCC2
74
      If defined, this file defines the following functions, q.v.:
74
      If defined, this file defines the following functions, q.v.:
75
         char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
75
         char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
76
                               int *status)
76
                               int *status)
77
         int __gcclibcxx_demangle_callback (const char *,
77
         int __gcclibcxx_demangle_callback (const char *,
78
                                            void (*)
78
                                            void (*)
79
                                              (const char *, size_t, void *),
79
                                              (const char *, size_t, void *),
80
                                            void *)
80
                                            void *)
81
      instead of cplus_demangle_v3[_callback]() and
81
      instead of cplus_demangle_v3[_callback]() and
82
      java_demangle_v3[_callback]().
82
      java_demangle_v3[_callback]().
83
 
83
 
84
   IN_GLIBCPP_V3
84
   IN_GLIBCPP_V3
85
      If defined, this file defines only __cxa_demangle() and
85
      If defined, this file defines only __cxa_demangle() and
86
      __gcclibcxx_demangle_callback(), and no other publically visible
86
      __gcclibcxx_demangle_callback(), and no other publically visible
87
      functions or variables.
87
      functions or variables.
88
 
88
 
89
   STANDALONE_DEMANGLER
89
   STANDALONE_DEMANGLER
90
      If defined, this file defines a main() function which demangles
90
      If defined, this file defines a main() function which demangles
91
      any arguments, or, if none, demangles stdin.
91
      any arguments, or, if none, demangles stdin.
92
 
92
 
93
   CP_DEMANGLE_DEBUG
93
   CP_DEMANGLE_DEBUG
94
      If defined, turns on debugging mode, which prints information on
94
      If defined, turns on debugging mode, which prints information on
95
      stdout about the mangled string.  This is not generally useful.
95
      stdout about the mangled string.  This is not generally useful.
96
*/
96
*/
97
 
97
 
98
#if defined (_AIX) && !defined (__GNUC__)
98
#if defined (_AIX) && !defined (__GNUC__)
99
 #pragma alloca
99
 #pragma alloca
100
#endif
100
#endif
101
 
101
 
102
#ifdef HAVE_CONFIG_H
102
#ifdef HAVE_CONFIG_H
103
#include "config.h"
103
#include "config.h"
104
#endif
104
#endif
105
 
105
 
106
#include 
106
#include 
107
 
107
 
108
#ifdef HAVE_STDLIB_H
108
#ifdef HAVE_STDLIB_H
109
#include 
109
#include 
110
#endif
110
#endif
111
#ifdef HAVE_STRING_H
111
#ifdef HAVE_STRING_H
112
#include 
112
#include 
113
#endif
113
#endif
114
 
114
 
115
#ifdef HAVE_ALLOCA_H
115
#ifdef HAVE_ALLOCA_H
116
# include 
116
# include 
117
#else
117
#else
118
# ifndef alloca
118
# ifndef alloca
119
#  ifdef __GNUC__
119
#  ifdef __GNUC__
120
#   define alloca __builtin_alloca
120
#   define alloca __builtin_alloca
121
#  else
121
#  else
122
extern char *alloca ();
122
extern char *alloca ();
123
#  endif /* __GNUC__ */
123
#  endif /* __GNUC__ */
124
# endif /* alloca */
124
# endif /* alloca */
125
#endif /* HAVE_ALLOCA_H */
125
#endif /* HAVE_ALLOCA_H */
126
 
126
 
127
#include "ansidecl.h"
127
#include "ansidecl.h"
128
#include "libiberty.h"
128
#include "libiberty.h"
129
#include "demangle.h"
129
#include "demangle.h"
130
#include "cp-demangle.h"
130
#include "cp-demangle.h"
131
 
131
 
132
/* If IN_GLIBCPP_V3 is defined, some functions are made static.  We
132
/* If IN_GLIBCPP_V3 is defined, some functions are made static.  We
133
   also rename them via #define to avoid compiler errors when the
133
   also rename them via #define to avoid compiler errors when the
134
   static definition conflicts with the extern declaration in a header
134
   static definition conflicts with the extern declaration in a header
135
   file.  */
135
   file.  */
136
#ifdef IN_GLIBCPP_V3
136
#ifdef IN_GLIBCPP_V3
137
 
137
 
138
#define CP_STATIC_IF_GLIBCPP_V3 static
138
#define CP_STATIC_IF_GLIBCPP_V3 static
139
 
139
 
140
#define cplus_demangle_fill_name d_fill_name
140
#define cplus_demangle_fill_name d_fill_name
141
static int d_fill_name (struct demangle_component *, const char *, int);
141
static int d_fill_name (struct demangle_component *, const char *, int);
142
 
142
 
143
#define cplus_demangle_fill_extended_operator d_fill_extended_operator
143
#define cplus_demangle_fill_extended_operator d_fill_extended_operator
144
static int
144
static int
145
d_fill_extended_operator (struct demangle_component *, int,
145
d_fill_extended_operator (struct demangle_component *, int,
146
                          struct demangle_component *);
146
                          struct demangle_component *);
147
 
147
 
148
#define cplus_demangle_fill_ctor d_fill_ctor
148
#define cplus_demangle_fill_ctor d_fill_ctor
149
static int
149
static int
150
d_fill_ctor (struct demangle_component *, enum gnu_v3_ctor_kinds,
150
d_fill_ctor (struct demangle_component *, enum gnu_v3_ctor_kinds,
151
             struct demangle_component *);
151
             struct demangle_component *);
152
 
152
 
153
#define cplus_demangle_fill_dtor d_fill_dtor
153
#define cplus_demangle_fill_dtor d_fill_dtor
154
static int
154
static int
155
d_fill_dtor (struct demangle_component *, enum gnu_v3_dtor_kinds,
155
d_fill_dtor (struct demangle_component *, enum gnu_v3_dtor_kinds,
156
             struct demangle_component *);
156
             struct demangle_component *);
157
 
157
 
158
#define cplus_demangle_mangled_name d_mangled_name
158
#define cplus_demangle_mangled_name d_mangled_name
159
static struct demangle_component *d_mangled_name (struct d_info *, int);
159
static struct demangle_component *d_mangled_name (struct d_info *, int);
160
 
160
 
161
#define cplus_demangle_type d_type
161
#define cplus_demangle_type d_type
162
static struct demangle_component *d_type (struct d_info *);
162
static struct demangle_component *d_type (struct d_info *);
163
 
163
 
164
#define cplus_demangle_print d_print
164
#define cplus_demangle_print d_print
165
static char *d_print (int, const struct demangle_component *, int, size_t *);
165
static char *d_print (int, const struct demangle_component *, int, size_t *);
166
 
166
 
167
#define cplus_demangle_print_callback d_print_callback
167
#define cplus_demangle_print_callback d_print_callback
168
static int d_print_callback (int, const struct demangle_component *,
168
static int d_print_callback (int, const struct demangle_component *,
169
                             demangle_callbackref, void *);
169
                             demangle_callbackref, void *);
170
 
170
 
171
#define cplus_demangle_init_info d_init_info
171
#define cplus_demangle_init_info d_init_info
172
static void d_init_info (const char *, int, size_t, struct d_info *);
172
static void d_init_info (const char *, int, size_t, struct d_info *);
173
 
173
 
174
#else /* ! defined(IN_GLIBCPP_V3) */
174
#else /* ! defined(IN_GLIBCPP_V3) */
175
#define CP_STATIC_IF_GLIBCPP_V3
175
#define CP_STATIC_IF_GLIBCPP_V3
176
#endif /* ! defined(IN_GLIBCPP_V3) */
176
#endif /* ! defined(IN_GLIBCPP_V3) */
177
 
177
 
178
/* See if the compiler supports dynamic arrays.  */
178
/* See if the compiler supports dynamic arrays.  */
179
 
179
 
180
#ifdef __GNUC__
180
#ifdef __GNUC__
181
#define CP_DYNAMIC_ARRAYS
181
#define CP_DYNAMIC_ARRAYS
182
#else
182
#else
183
#ifdef __STDC__
183
#ifdef __STDC__
184
#ifdef __STDC_VERSION__
184
#ifdef __STDC_VERSION__
185
#if __STDC_VERSION__ >= 199901L
185
#if __STDC_VERSION__ >= 199901L
186
#define CP_DYNAMIC_ARRAYS
186
#define CP_DYNAMIC_ARRAYS
187
#endif /* __STDC__VERSION >= 199901L */
187
#endif /* __STDC__VERSION >= 199901L */
188
#endif /* defined (__STDC_VERSION__) */
188
#endif /* defined (__STDC_VERSION__) */
189
#endif /* defined (__STDC__) */
189
#endif /* defined (__STDC__) */
190
#endif /* ! defined (__GNUC__) */
190
#endif /* ! defined (__GNUC__) */
191
 
191
 
192
/* We avoid pulling in the ctype tables, to prevent pulling in
192
/* We avoid pulling in the ctype tables, to prevent pulling in
193
   additional unresolved symbols when this code is used in a library.
193
   additional unresolved symbols when this code is used in a library.
194
   FIXME: Is this really a valid reason?  This comes from the original
194
   FIXME: Is this really a valid reason?  This comes from the original
195
   V3 demangler code.
195
   V3 demangler code.
196
 
196
 
197
   As of this writing this file has the following undefined references
197
   As of this writing this file has the following undefined references
198
   when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
198
   when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
199
   strcat, strlen.  */
199
   strcat, strlen.  */
200
 
200
 
201
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
201
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
202
#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
202
#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
203
#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
203
#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
204
 
204
 
205
/* The prefix prepended by GCC to an identifier represnting the
205
/* The prefix prepended by GCC to an identifier represnting the
206
   anonymous namespace.  */
206
   anonymous namespace.  */
207
#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
207
#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
208
#define ANONYMOUS_NAMESPACE_PREFIX_LEN \
208
#define ANONYMOUS_NAMESPACE_PREFIX_LEN \
209
  (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
209
  (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
210
 
210
 
211
/* Information we keep for the standard substitutions.  */
211
/* Information we keep for the standard substitutions.  */
212
 
212
 
213
struct d_standard_sub_info
213
struct d_standard_sub_info
214
{
214
{
215
  /* The code for this substitution.  */
215
  /* The code for this substitution.  */
216
  char code;
216
  char code;
217
  /* The simple string it expands to.  */
217
  /* The simple string it expands to.  */
218
  const char *simple_expansion;
218
  const char *simple_expansion;
219
  /* The length of the simple expansion.  */
219
  /* The length of the simple expansion.  */
220
  int simple_len;
220
  int simple_len;
221
  /* The results of a full, verbose, expansion.  This is used when
221
  /* The results of a full, verbose, expansion.  This is used when
222
     qualifying a constructor/destructor, or when in verbose mode.  */
222
     qualifying a constructor/destructor, or when in verbose mode.  */
223
  const char *full_expansion;
223
  const char *full_expansion;
224
  /* The length of the full expansion.  */
224
  /* The length of the full expansion.  */
225
  int full_len;
225
  int full_len;
226
  /* What to set the last_name field of d_info to; NULL if we should
226
  /* What to set the last_name field of d_info to; NULL if we should
227
     not set it.  This is only relevant when qualifying a
227
     not set it.  This is only relevant when qualifying a
228
     constructor/destructor.  */
228
     constructor/destructor.  */
229
  const char *set_last_name;
229
  const char *set_last_name;
230
  /* The length of set_last_name.  */
230
  /* The length of set_last_name.  */
231
  int set_last_name_len;
231
  int set_last_name_len;
232
};
232
};
233
 
233
 
234
/* Accessors for subtrees of struct demangle_component.  */
234
/* Accessors for subtrees of struct demangle_component.  */
235
 
235
 
236
#define d_left(dc) ((dc)->u.s_binary.left)
236
#define d_left(dc) ((dc)->u.s_binary.left)
237
#define d_right(dc) ((dc)->u.s_binary.right)
237
#define d_right(dc) ((dc)->u.s_binary.right)
238
 
238
 
239
/* A list of templates.  This is used while printing.  */
239
/* A list of templates.  This is used while printing.  */
240
 
240
 
241
struct d_print_template
241
struct d_print_template
242
{
242
{
243
  /* Next template on the list.  */
243
  /* Next template on the list.  */
244
  struct d_print_template *next;
244
  struct d_print_template *next;
245
  /* This template.  */
245
  /* This template.  */
246
  const struct demangle_component *template_decl;
246
  const struct demangle_component *template_decl;
247
};
247
};
248
 
248
 
249
/* A list of type modifiers.  This is used while printing.  */
249
/* A list of type modifiers.  This is used while printing.  */
250
 
250
 
251
struct d_print_mod
251
struct d_print_mod
252
{
252
{
253
  /* Next modifier on the list.  These are in the reverse of the order
253
  /* Next modifier on the list.  These are in the reverse of the order
254
     in which they appeared in the mangled string.  */
254
     in which they appeared in the mangled string.  */
255
  struct d_print_mod *next;
255
  struct d_print_mod *next;
256
  /* The modifier.  */
256
  /* The modifier.  */
257
  const struct demangle_component *mod;
257
  const struct demangle_component *mod;
258
  /* Whether this modifier was printed.  */
258
  /* Whether this modifier was printed.  */
259
  int printed;
259
  int printed;
260
  /* The list of templates which applies to this modifier.  */
260
  /* The list of templates which applies to this modifier.  */
261
  struct d_print_template *templates;
261
  struct d_print_template *templates;
262
};
262
};
263
 
263
 
264
/* We use these structures to hold information during printing.  */
264
/* We use these structures to hold information during printing.  */
265
 
265
 
266
struct d_growable_string
266
struct d_growable_string
267
{
267
{
268
  /* Buffer holding the result.  */
268
  /* Buffer holding the result.  */
269
  char *buf;
269
  char *buf;
270
  /* Current length of data in buffer.  */
270
  /* Current length of data in buffer.  */
271
  size_t len;
271
  size_t len;
272
  /* Allocated size of buffer.  */
272
  /* Allocated size of buffer.  */
273
  size_t alc;
273
  size_t alc;
274
  /* Set to 1 if we had a memory allocation failure.  */
274
  /* Set to 1 if we had a memory allocation failure.  */
275
  int allocation_failure;
275
  int allocation_failure;
276
};
276
};
-
 
277
 
-
 
278
/* Stack of components, innermost first, used to avoid loops.  */
-
 
279
 
-
 
280
struct d_component_stack
-
 
281
{
-
 
282
  /* This component.  */
-
 
283
  const struct demangle_component *dc;
-
 
284
  /* This component's parent.  */
-
 
285
  const struct d_component_stack *parent;
-
 
286
};
-
 
287
 
-
 
288
/* A demangle component and some scope captured when it was first
-
 
289
   traversed.  */
-
 
290
 
-
 
291
struct d_saved_scope
-
 
292
{
-
 
293
  /* The component whose scope this is.  */
-
 
294
  const struct demangle_component *container;
-
 
295
  /* The list of templates, if any, that was current when this
-
 
296
     scope was captured.  */
-
 
297
  struct d_print_template *templates;
-
 
298
};
-
 
299
 
-
 
300
/* Checkpoint structure to allow backtracking.  This holds copies
-
 
301
   of the fields of struct d_info that need to be restored
-
 
302
   if a trial parse needs to be backtracked over.  */
-
 
303
 
-
 
304
struct d_info_checkpoint
-
 
305
{
-
 
306
  const char *n;
-
 
307
  int next_comp;
-
 
308
  int next_sub;
-
 
309
  int did_subs;
-
 
310
  int expansion;
-
 
311
};
277
 
312
 
278
enum { D_PRINT_BUFFER_LENGTH = 256 };
313
enum { D_PRINT_BUFFER_LENGTH = 256 };
279
struct d_print_info
314
struct d_print_info
280
{
315
{
281
  /* Fixed-length allocated buffer for demangled data, flushed to the
316
  /* Fixed-length allocated buffer for demangled data, flushed to the
282
     callback with a NUL termination once full.  */
317
     callback with a NUL termination once full.  */
283
  char buf[D_PRINT_BUFFER_LENGTH];
318
  char buf[D_PRINT_BUFFER_LENGTH];
284
  /* Current length of data in buffer.  */
319
  /* Current length of data in buffer.  */
285
  size_t len;
320
  size_t len;
286
  /* The last character printed, saved individually so that it survives
321
  /* The last character printed, saved individually so that it survives
287
     any buffer flush.  */
322
     any buffer flush.  */
288
  char last_char;
323
  char last_char;
289
  /* Callback function to handle demangled buffer flush.  */
324
  /* Callback function to handle demangled buffer flush.  */
290
  demangle_callbackref callback;
325
  demangle_callbackref callback;
291
  /* Opaque callback argument.  */
326
  /* Opaque callback argument.  */
292
  void *opaque;
327
  void *opaque;
293
  /* The current list of templates, if any.  */
328
  /* The current list of templates, if any.  */
294
  struct d_print_template *templates;
329
  struct d_print_template *templates;
295
  /* The current list of modifiers (e.g., pointer, reference, etc.),
330
  /* The current list of modifiers (e.g., pointer, reference, etc.),
296
     if any.  */
331
     if any.  */
297
  struct d_print_mod *modifiers;
332
  struct d_print_mod *modifiers;
298
  /* Set to 1 if we saw a demangling error.  */
333
  /* Set to 1 if we saw a demangling error.  */
299
  int demangle_failure;
334
  int demangle_failure;
300
  /* The current index into any template argument packs we are using
335
  /* The current index into any template argument packs we are using
301
     for printing.  */
336
     for printing.  */
302
  int pack_index;
337
  int pack_index;
303
  /* Number of d_print_flush calls so far.  */
338
  /* Number of d_print_flush calls so far.  */
304
  unsigned long int flush_count;
339
  unsigned long int flush_count;
-
 
340
  /* Stack of components, innermost first, used to avoid loops.  */
-
 
341
  const struct d_component_stack *component_stack;
-
 
342
  /* Array of saved scopes for evaluating substitutions.  */
-
 
343
  struct d_saved_scope *saved_scopes;
-
 
344
  /* Index of the next unused saved scope in the above array.  */
-
 
345
  int next_saved_scope;
-
 
346
  /* Number of saved scopes in the above array.  */
-
 
347
  int num_saved_scopes;
-
 
348
  /* Array of templates for saving into scopes.  */
-
 
349
  struct d_print_template *copy_templates;
-
 
350
  /* Index of the next unused copy template in the above array.  */
-
 
351
  int next_copy_template;
-
 
352
  /* Number of copy templates in the above array.  */
-
 
353
  int num_copy_templates;
-
 
354
  /* The nearest enclosing template, if any.  */
-
 
355
  const struct demangle_component *current_template;
305
};
356
};
306
 
357
 
307
#ifdef CP_DEMANGLE_DEBUG
358
#ifdef CP_DEMANGLE_DEBUG
308
static void d_dump (struct demangle_component *, int);
359
static void d_dump (struct demangle_component *, int);
309
#endif
360
#endif
310
 
361
 
311
static struct demangle_component *
362
static struct demangle_component *
312
d_make_empty (struct d_info *);
363
d_make_empty (struct d_info *);
313
 
364
 
314
static struct demangle_component *
365
static struct demangle_component *
315
d_make_comp (struct d_info *, enum demangle_component_type,
366
d_make_comp (struct d_info *, enum demangle_component_type,
316
             struct demangle_component *,
367
             struct demangle_component *,
317
             struct demangle_component *);
368
             struct demangle_component *);
318
 
369
 
319
static struct demangle_component *
370
static struct demangle_component *
320
d_make_name (struct d_info *, const char *, int);
371
d_make_name (struct d_info *, const char *, int);
321
 
372
 
322
static struct demangle_component *
373
static struct demangle_component *
323
d_make_demangle_mangled_name (struct d_info *, const char *);
374
d_make_demangle_mangled_name (struct d_info *, const char *);
324
 
375
 
325
static struct demangle_component *
376
static struct demangle_component *
326
d_make_builtin_type (struct d_info *,
377
d_make_builtin_type (struct d_info *,
327
                     const struct demangle_builtin_type_info *);
378
                     const struct demangle_builtin_type_info *);
328
 
379
 
329
static struct demangle_component *
380
static struct demangle_component *
330
d_make_operator (struct d_info *,
381
d_make_operator (struct d_info *,
331
                 const struct demangle_operator_info *);
382
                 const struct demangle_operator_info *);
332
 
383
 
333
static struct demangle_component *
384
static struct demangle_component *
334
d_make_extended_operator (struct d_info *, int,
385
d_make_extended_operator (struct d_info *, int,
335
                          struct demangle_component *);
386
                          struct demangle_component *);
336
 
387
 
337
static struct demangle_component *
388
static struct demangle_component *
338
d_make_ctor (struct d_info *, enum gnu_v3_ctor_kinds,
389
d_make_ctor (struct d_info *, enum gnu_v3_ctor_kinds,
339
             struct demangle_component *);
390
             struct demangle_component *);
340
 
391
 
341
static struct demangle_component *
392
static struct demangle_component *
342
d_make_dtor (struct d_info *, enum gnu_v3_dtor_kinds,
393
d_make_dtor (struct d_info *, enum gnu_v3_dtor_kinds,
343
             struct demangle_component *);
394
             struct demangle_component *);
344
 
395
 
345
static struct demangle_component *
396
static struct demangle_component *
346
d_make_template_param (struct d_info *, long);
397
d_make_template_param (struct d_info *, long);
347
 
398
 
348
static struct demangle_component *
399
static struct demangle_component *
349
d_make_sub (struct d_info *, const char *, int);
400
d_make_sub (struct d_info *, const char *, int);
350
 
401
 
351
static int
402
static int
352
has_return_type (struct demangle_component *);
403
has_return_type (struct demangle_component *);
353
 
404
 
354
static int
405
static int
355
is_ctor_dtor_or_conversion (struct demangle_component *);
406
is_ctor_dtor_or_conversion (struct demangle_component *);
356
 
407
 
357
static struct demangle_component *d_encoding (struct d_info *, int);
408
static struct demangle_component *d_encoding (struct d_info *, int);
358
 
409
 
359
static struct demangle_component *d_name (struct d_info *);
410
static struct demangle_component *d_name (struct d_info *);
360
 
411
 
361
static struct demangle_component *d_nested_name (struct d_info *);
412
static struct demangle_component *d_nested_name (struct d_info *);
362
 
413
 
363
static struct demangle_component *d_prefix (struct d_info *);
414
static struct demangle_component *d_prefix (struct d_info *);
364
 
415
 
365
static struct demangle_component *d_unqualified_name (struct d_info *);
416
static struct demangle_component *d_unqualified_name (struct d_info *);
366
 
417
 
367
static struct demangle_component *d_source_name (struct d_info *);
418
static struct demangle_component *d_source_name (struct d_info *);
368
 
419
 
369
static long d_number (struct d_info *);
420
static long d_number (struct d_info *);
370
 
421
 
371
static struct demangle_component *d_identifier (struct d_info *, int);
422
static struct demangle_component *d_identifier (struct d_info *, int);
372
 
423
 
373
static struct demangle_component *d_operator_name (struct d_info *);
424
static struct demangle_component *d_operator_name (struct d_info *);
374
 
425
 
375
static struct demangle_component *d_special_name (struct d_info *);
426
static struct demangle_component *d_special_name (struct d_info *);
376
 
427
 
377
static int d_call_offset (struct d_info *, int);
428
static int d_call_offset (struct d_info *, int);
378
 
429
 
379
static struct demangle_component *d_ctor_dtor_name (struct d_info *);
430
static struct demangle_component *d_ctor_dtor_name (struct d_info *);
380
 
431
 
381
static struct demangle_component **
432
static struct demangle_component **
382
d_cv_qualifiers (struct d_info *, struct demangle_component **, int);
433
d_cv_qualifiers (struct d_info *, struct demangle_component **, int);
383
 
434
 
384
static struct demangle_component *
435
static struct demangle_component *
385
d_ref_qualifier (struct d_info *, struct demangle_component *);
436
d_ref_qualifier (struct d_info *, struct demangle_component *);
386
 
437
 
387
static struct demangle_component *
438
static struct demangle_component *
388
d_function_type (struct d_info *);
439
d_function_type (struct d_info *);
389
 
440
 
390
static struct demangle_component *
441
static struct demangle_component *
391
d_bare_function_type (struct d_info *, int);
442
d_bare_function_type (struct d_info *, int);
392
 
443
 
393
static struct demangle_component *
444
static struct demangle_component *
394
d_class_enum_type (struct d_info *);
445
d_class_enum_type (struct d_info *);
395
 
446
 
396
static struct demangle_component *d_array_type (struct d_info *);
447
static struct demangle_component *d_array_type (struct d_info *);
397
 
448
 
398
static struct demangle_component *d_vector_type (struct d_info *);
449
static struct demangle_component *d_vector_type (struct d_info *);
399
 
450
 
400
static struct demangle_component *
451
static struct demangle_component *
401
d_pointer_to_member_type (struct d_info *);
452
d_pointer_to_member_type (struct d_info *);
402
 
453
 
403
static struct demangle_component *
454
static struct demangle_component *
404
d_template_param (struct d_info *);
455
d_template_param (struct d_info *);
405
 
456
 
406
static struct demangle_component *d_template_args (struct d_info *);
457
static struct demangle_component *d_template_args (struct d_info *);
407
 
458
 
408
static struct demangle_component *
459
static struct demangle_component *
409
d_template_arg (struct d_info *);
460
d_template_arg (struct d_info *);
410
 
461
 
411
static struct demangle_component *d_expression (struct d_info *);
462
static struct demangle_component *d_expression (struct d_info *);
412
 
463
 
413
static struct demangle_component *d_expr_primary (struct d_info *);
464
static struct demangle_component *d_expr_primary (struct d_info *);
414
 
465
 
415
static struct demangle_component *d_local_name (struct d_info *);
466
static struct demangle_component *d_local_name (struct d_info *);
416
 
467
 
417
static int d_discriminator (struct d_info *);
468
static int d_discriminator (struct d_info *);
418
 
469
 
419
static struct demangle_component *d_lambda (struct d_info *);
470
static struct demangle_component *d_lambda (struct d_info *);
420
 
471
 
421
static struct demangle_component *d_unnamed_type (struct d_info *);
472
static struct demangle_component *d_unnamed_type (struct d_info *);
422
 
473
 
423
static struct demangle_component *
474
static struct demangle_component *
424
d_clone_suffix (struct d_info *, struct demangle_component *);
475
d_clone_suffix (struct d_info *, struct demangle_component *);
425
 
476
 
426
static int
477
static int
427
d_add_substitution (struct d_info *, struct demangle_component *);
478
d_add_substitution (struct d_info *, struct demangle_component *);
428
 
479
 
429
static struct demangle_component *d_substitution (struct d_info *, int);
480
static struct demangle_component *d_substitution (struct d_info *, int);
-
 
481
 
-
 
482
static void d_checkpoint (struct d_info *, struct d_info_checkpoint *);
-
 
483
 
-
 
484
static void d_backtrack (struct d_info *, struct d_info_checkpoint *);
430
 
485
 
431
static void d_growable_string_init (struct d_growable_string *, size_t);
486
static void d_growable_string_init (struct d_growable_string *, size_t);
432
 
487
 
433
static inline void
488
static inline void
434
d_growable_string_resize (struct d_growable_string *, size_t);
489
d_growable_string_resize (struct d_growable_string *, size_t);
435
 
490
 
436
static inline void
491
static inline void
437
d_growable_string_append_buffer (struct d_growable_string *,
492
d_growable_string_append_buffer (struct d_growable_string *,
438
                                 const char *, size_t);
493
                                 const char *, size_t);
439
static void
494
static void
440
d_growable_string_callback_adapter (const char *, size_t, void *);
495
d_growable_string_callback_adapter (const char *, size_t, void *);
441
 
496
 
442
static void
497
static void
443
d_print_init (struct d_print_info *, demangle_callbackref, void *);
498
d_print_init (struct d_print_info *, demangle_callbackref, void *,
-
 
499
	      const struct demangle_component *);
444
 
500
 
445
static inline void d_print_error (struct d_print_info *);
501
static inline void d_print_error (struct d_print_info *);
446
 
502
 
447
static inline int d_print_saw_error (struct d_print_info *);
503
static inline int d_print_saw_error (struct d_print_info *);
448
 
504
 
449
static inline void d_print_flush (struct d_print_info *);
505
static inline void d_print_flush (struct d_print_info *);
450
 
506
 
451
static inline void d_append_char (struct d_print_info *, char);
507
static inline void d_append_char (struct d_print_info *, char);
452
 
508
 
453
static inline void d_append_buffer (struct d_print_info *,
509
static inline void d_append_buffer (struct d_print_info *,
454
                                    const char *, size_t);
510
                                    const char *, size_t);
455
 
511
 
456
static inline void d_append_string (struct d_print_info *, const char *);
512
static inline void d_append_string (struct d_print_info *, const char *);
457
 
513
 
458
static inline char d_last_char (struct d_print_info *);
514
static inline char d_last_char (struct d_print_info *);
459
 
515
 
460
static void
516
static void
461
d_print_comp (struct d_print_info *, int, const struct demangle_component *);
517
d_print_comp (struct d_print_info *, int, const struct demangle_component *);
462
 
518
 
463
static void
519
static void
464
d_print_java_identifier (struct d_print_info *, const char *, int);
520
d_print_java_identifier (struct d_print_info *, const char *, int);
465
 
521
 
466
static void
522
static void
467
d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int);
523
d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int);
468
 
524
 
469
static void
525
static void
470
d_print_mod (struct d_print_info *, int, const struct demangle_component *);
526
d_print_mod (struct d_print_info *, int, const struct demangle_component *);
471
 
527
 
472
static void
528
static void
473
d_print_function_type (struct d_print_info *, int,
529
d_print_function_type (struct d_print_info *, int,
474
                       const struct demangle_component *,
530
                       const struct demangle_component *,
475
                       struct d_print_mod *);
531
                       struct d_print_mod *);
476
 
532
 
477
static void
533
static void
478
d_print_array_type (struct d_print_info *, int,
534
d_print_array_type (struct d_print_info *, int,
479
                    const struct demangle_component *,
535
                    const struct demangle_component *,
480
                    struct d_print_mod *);
536
                    struct d_print_mod *);
481
 
537
 
482
static void
538
static void
483
d_print_expr_op (struct d_print_info *, int, const struct demangle_component *);
539
d_print_expr_op (struct d_print_info *, int, const struct demangle_component *);
484
 
540
 
485
static void
541
static void
486
d_print_cast (struct d_print_info *, int, const struct demangle_component *);
542
d_print_cast (struct d_print_info *, int, const struct demangle_component *);
487
 
543
 
488
static int d_demangle_callback (const char *, int,
544
static int d_demangle_callback (const char *, int,
489
                                demangle_callbackref, void *);
545
                                demangle_callbackref, void *);
490
static char *d_demangle (const char *, int, size_t *);
546
static char *d_demangle (const char *, int, size_t *);
491
 
547
 
492
#ifdef CP_DEMANGLE_DEBUG
548
#ifdef CP_DEMANGLE_DEBUG
493
 
549
 
494
static void
550
static void
495
d_dump (struct demangle_component *dc, int indent)
551
d_dump (struct demangle_component *dc, int indent)
496
{
552
{
497
  int i;
553
  int i;
498
 
554
 
499
  if (dc == NULL)
555
  if (dc == NULL)
500
    {
556
    {
501
      if (indent == 0)
557
      if (indent == 0)
502
        printf ("failed demangling\n");
558
        printf ("failed demangling\n");
503
      return;
559
      return;
504
    }
560
    }
505
 
561
 
506
  for (i = 0; i < indent; ++i)
562
  for (i = 0; i < indent; ++i)
507
    putchar (' ');
563
    putchar (' ');
508
 
564
 
509
  switch (dc->type)
565
  switch (dc->type)
510
    {
566
    {
511
    case DEMANGLE_COMPONENT_NAME:
567
    case DEMANGLE_COMPONENT_NAME:
512
      printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s);
568
      printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s);
513
      return;
569
      return;
514
    case DEMANGLE_COMPONENT_TAGGED_NAME:
570
    case DEMANGLE_COMPONENT_TAGGED_NAME:
515
      printf ("tagged name\n");
571
      printf ("tagged name\n");
516
      d_dump (dc->u.s_binary.left, indent + 2);
572
      d_dump (dc->u.s_binary.left, indent + 2);
517
      d_dump (dc->u.s_binary.right, indent + 2);
573
      d_dump (dc->u.s_binary.right, indent + 2);
518
      return;
574
      return;
519
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
575
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
520
      printf ("template parameter %ld\n", dc->u.s_number.number);
576
      printf ("template parameter %ld\n", dc->u.s_number.number);
521
      return;
577
      return;
-
 
578
    case DEMANGLE_COMPONENT_FUNCTION_PARAM:
-
 
579
      printf ("function parameter %ld\n", dc->u.s_number.number);
-
 
580
      return;
522
    case DEMANGLE_COMPONENT_CTOR:
581
    case DEMANGLE_COMPONENT_CTOR:
523
      printf ("constructor %d\n", (int) dc->u.s_ctor.kind);
582
      printf ("constructor %d\n", (int) dc->u.s_ctor.kind);
524
      d_dump (dc->u.s_ctor.name, indent + 2);
583
      d_dump (dc->u.s_ctor.name, indent + 2);
525
      return;
584
      return;
526
    case DEMANGLE_COMPONENT_DTOR:
585
    case DEMANGLE_COMPONENT_DTOR:
527
      printf ("destructor %d\n", (int) dc->u.s_dtor.kind);
586
      printf ("destructor %d\n", (int) dc->u.s_dtor.kind);
528
      d_dump (dc->u.s_dtor.name, indent + 2);
587
      d_dump (dc->u.s_dtor.name, indent + 2);
529
      return;
588
      return;
530
    case DEMANGLE_COMPONENT_SUB_STD:
589
    case DEMANGLE_COMPONENT_SUB_STD:
531
      printf ("standard substitution %s\n", dc->u.s_string.string);
590
      printf ("standard substitution %s\n", dc->u.s_string.string);
532
      return;
591
      return;
533
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
592
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
534
      printf ("builtin type %s\n", dc->u.s_builtin.type->name);
593
      printf ("builtin type %s\n", dc->u.s_builtin.type->name);
535
      return;
594
      return;
536
    case DEMANGLE_COMPONENT_OPERATOR:
595
    case DEMANGLE_COMPONENT_OPERATOR:
537
      printf ("operator %s\n", dc->u.s_operator.op->name);
596
      printf ("operator %s\n", dc->u.s_operator.op->name);
538
      return;
597
      return;
539
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
598
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
540
      printf ("extended operator with %d args\n",
599
      printf ("extended operator with %d args\n",
541
	      dc->u.s_extended_operator.args);
600
	      dc->u.s_extended_operator.args);
542
      d_dump (dc->u.s_extended_operator.name, indent + 2);
601
      d_dump (dc->u.s_extended_operator.name, indent + 2);
543
      return;
602
      return;
544
 
603
 
545
    case DEMANGLE_COMPONENT_QUAL_NAME:
604
    case DEMANGLE_COMPONENT_QUAL_NAME:
546
      printf ("qualified name\n");
605
      printf ("qualified name\n");
547
      break;
606
      break;
548
    case DEMANGLE_COMPONENT_LOCAL_NAME:
607
    case DEMANGLE_COMPONENT_LOCAL_NAME:
549
      printf ("local name\n");
608
      printf ("local name\n");
550
      break;
609
      break;
551
    case DEMANGLE_COMPONENT_TYPED_NAME:
610
    case DEMANGLE_COMPONENT_TYPED_NAME:
552
      printf ("typed name\n");
611
      printf ("typed name\n");
553
      break;
612
      break;
554
    case DEMANGLE_COMPONENT_TEMPLATE:
613
    case DEMANGLE_COMPONENT_TEMPLATE:
555
      printf ("template\n");
614
      printf ("template\n");
556
      break;
615
      break;
557
    case DEMANGLE_COMPONENT_VTABLE:
616
    case DEMANGLE_COMPONENT_VTABLE:
558
      printf ("vtable\n");
617
      printf ("vtable\n");
559
      break;
618
      break;
560
    case DEMANGLE_COMPONENT_VTT:
619
    case DEMANGLE_COMPONENT_VTT:
561
      printf ("VTT\n");
620
      printf ("VTT\n");
562
      break;
621
      break;
563
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
622
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
564
      printf ("construction vtable\n");
623
      printf ("construction vtable\n");
565
      break;
624
      break;
566
    case DEMANGLE_COMPONENT_TYPEINFO:
625
    case DEMANGLE_COMPONENT_TYPEINFO:
567
      printf ("typeinfo\n");
626
      printf ("typeinfo\n");
568
      break;
627
      break;
569
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
628
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
570
      printf ("typeinfo name\n");
629
      printf ("typeinfo name\n");
571
      break;
630
      break;
572
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
631
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
573
      printf ("typeinfo function\n");
632
      printf ("typeinfo function\n");
574
      break;
633
      break;
575
    case DEMANGLE_COMPONENT_THUNK:
634
    case DEMANGLE_COMPONENT_THUNK:
576
      printf ("thunk\n");
635
      printf ("thunk\n");
577
      break;
636
      break;
578
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
637
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
579
      printf ("virtual thunk\n");
638
      printf ("virtual thunk\n");
580
      break;
639
      break;
581
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
640
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
582
      printf ("covariant thunk\n");
641
      printf ("covariant thunk\n");
583
      break;
642
      break;
584
    case DEMANGLE_COMPONENT_JAVA_CLASS:
643
    case DEMANGLE_COMPONENT_JAVA_CLASS:
585
      printf ("java class\n");
644
      printf ("java class\n");
586
      break;
645
      break;
587
    case DEMANGLE_COMPONENT_GUARD:
646
    case DEMANGLE_COMPONENT_GUARD:
588
      printf ("guard\n");
647
      printf ("guard\n");
589
      break;
648
      break;
590
    case DEMANGLE_COMPONENT_REFTEMP:
649
    case DEMANGLE_COMPONENT_REFTEMP:
591
      printf ("reference temporary\n");
650
      printf ("reference temporary\n");
592
      break;
651
      break;
593
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
652
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
594
      printf ("hidden alias\n");
653
      printf ("hidden alias\n");
595
      break;
654
      break;
596
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
655
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
597
      printf ("transaction clone\n");
656
      printf ("transaction clone\n");
598
      break;
657
      break;
599
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
658
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
600
      printf ("non-transaction clone\n");
659
      printf ("non-transaction clone\n");
601
      break;
660
      break;
602
    case DEMANGLE_COMPONENT_RESTRICT:
661
    case DEMANGLE_COMPONENT_RESTRICT:
603
      printf ("restrict\n");
662
      printf ("restrict\n");
604
      break;
663
      break;
605
    case DEMANGLE_COMPONENT_VOLATILE:
664
    case DEMANGLE_COMPONENT_VOLATILE:
606
      printf ("volatile\n");
665
      printf ("volatile\n");
607
      break;
666
      break;
608
    case DEMANGLE_COMPONENT_CONST:
667
    case DEMANGLE_COMPONENT_CONST:
609
      printf ("const\n");
668
      printf ("const\n");
610
      break;
669
      break;
611
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
670
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
612
      printf ("restrict this\n");
671
      printf ("restrict this\n");
613
      break;
672
      break;
614
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
673
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
615
      printf ("volatile this\n");
674
      printf ("volatile this\n");
616
      break;
675
      break;
617
    case DEMANGLE_COMPONENT_CONST_THIS:
676
    case DEMANGLE_COMPONENT_CONST_THIS:
618
      printf ("const this\n");
677
      printf ("const this\n");
619
      break;
678
      break;
620
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
679
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
621
      printf ("reference this\n");
680
      printf ("reference this\n");
622
      break;
681
      break;
623
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
682
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
624
      printf ("rvalue reference this\n");
683
      printf ("rvalue reference this\n");
625
      break;
684
      break;
626
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
685
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
627
      printf ("vendor type qualifier\n");
686
      printf ("vendor type qualifier\n");
628
      break;
687
      break;
629
    case DEMANGLE_COMPONENT_POINTER:
688
    case DEMANGLE_COMPONENT_POINTER:
630
      printf ("pointer\n");
689
      printf ("pointer\n");
631
      break;
690
      break;
632
    case DEMANGLE_COMPONENT_REFERENCE:
691
    case DEMANGLE_COMPONENT_REFERENCE:
633
      printf ("reference\n");
692
      printf ("reference\n");
634
      break;
693
      break;
635
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
694
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
636
      printf ("rvalue reference\n");
695
      printf ("rvalue reference\n");
637
      break;
696
      break;
638
    case DEMANGLE_COMPONENT_COMPLEX:
697
    case DEMANGLE_COMPONENT_COMPLEX:
639
      printf ("complex\n");
698
      printf ("complex\n");
640
      break;
699
      break;
641
    case DEMANGLE_COMPONENT_IMAGINARY:
700
    case DEMANGLE_COMPONENT_IMAGINARY:
642
      printf ("imaginary\n");
701
      printf ("imaginary\n");
643
      break;
702
      break;
644
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
703
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
645
      printf ("vendor type\n");
704
      printf ("vendor type\n");
646
      break;
705
      break;
647
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
706
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
648
      printf ("function type\n");
707
      printf ("function type\n");
649
      break;
708
      break;
650
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
709
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
651
      printf ("array type\n");
710
      printf ("array type\n");
652
      break;
711
      break;
653
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
712
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
654
      printf ("pointer to member type\n");
713
      printf ("pointer to member type\n");
655
      break;
714
      break;
656
    case DEMANGLE_COMPONENT_FIXED_TYPE:
715
    case DEMANGLE_COMPONENT_FIXED_TYPE:
657
      printf ("fixed-point type\n");
716
      printf ("fixed-point type, accum? %d, sat? %d\n",
-
 
717
              dc->u.s_fixed.accum, dc->u.s_fixed.sat);
-
 
718
      d_dump (dc->u.s_fixed.length, indent + 2)
658
      break;
719
      break;
659
    case DEMANGLE_COMPONENT_ARGLIST:
720
    case DEMANGLE_COMPONENT_ARGLIST:
660
      printf ("argument list\n");
721
      printf ("argument list\n");
661
      break;
722
      break;
662
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
723
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
663
      printf ("template argument list\n");
724
      printf ("template argument list\n");
664
      break;
725
      break;
665
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
726
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
666
      printf ("initializer list\n");
727
      printf ("initializer list\n");
667
      break;
728
      break;
668
    case DEMANGLE_COMPONENT_CAST:
729
    case DEMANGLE_COMPONENT_CAST:
669
      printf ("cast\n");
730
      printf ("cast\n");
670
      break;
731
      break;
671
    case DEMANGLE_COMPONENT_NULLARY:
732
    case DEMANGLE_COMPONENT_NULLARY:
672
      printf ("nullary operator\n");
733
      printf ("nullary operator\n");
673
      break;
734
      break;
674
    case DEMANGLE_COMPONENT_UNARY:
735
    case DEMANGLE_COMPONENT_UNARY:
675
      printf ("unary operator\n");
736
      printf ("unary operator\n");
676
      break;
737
      break;
677
    case DEMANGLE_COMPONENT_BINARY:
738
    case DEMANGLE_COMPONENT_BINARY:
678
      printf ("binary operator\n");
739
      printf ("binary operator\n");
679
      break;
740
      break;
680
    case DEMANGLE_COMPONENT_BINARY_ARGS:
741
    case DEMANGLE_COMPONENT_BINARY_ARGS:
681
      printf ("binary operator arguments\n");
742
      printf ("binary operator arguments\n");
682
      break;
743
      break;
683
    case DEMANGLE_COMPONENT_TRINARY:
744
    case DEMANGLE_COMPONENT_TRINARY:
684
      printf ("trinary operator\n");
745
      printf ("trinary operator\n");
685
      break;
746
      break;
686
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
747
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
687
      printf ("trinary operator arguments 1\n");
748
      printf ("trinary operator arguments 1\n");
688
      break;
749
      break;
689
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
750
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
690
      printf ("trinary operator arguments 1\n");
751
      printf ("trinary operator arguments 1\n");
691
      break;
752
      break;
692
    case DEMANGLE_COMPONENT_LITERAL:
753
    case DEMANGLE_COMPONENT_LITERAL:
693
      printf ("literal\n");
754
      printf ("literal\n");
694
      break;
755
      break;
695
    case DEMANGLE_COMPONENT_LITERAL_NEG:
756
    case DEMANGLE_COMPONENT_LITERAL_NEG:
696
      printf ("negative literal\n");
757
      printf ("negative literal\n");
697
      break;
758
      break;
698
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
759
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
699
      printf ("java resource\n");
760
      printf ("java resource\n");
700
      break;
761
      break;
701
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
762
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
702
      printf ("compound name\n");
763
      printf ("compound name\n");
703
      break;
764
      break;
704
    case DEMANGLE_COMPONENT_CHARACTER:
765
    case DEMANGLE_COMPONENT_CHARACTER:
705
      printf ("character '%c'\n",  dc->u.s_character.character);
766
      printf ("character '%c'\n",  dc->u.s_character.character);
706
      return;
767
      return;
-
 
768
    case DEMANGLE_COMPONENT_NUMBER:
-
 
769
      printf ("number %ld\n", dc->u.s_number.number);
-
 
770
      return;
707
    case DEMANGLE_COMPONENT_DECLTYPE:
771
    case DEMANGLE_COMPONENT_DECLTYPE:
708
      printf ("decltype\n");
772
      printf ("decltype\n");
709
      break;
773
      break;
710
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
774
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
711
      printf ("pack expansion\n");
775
      printf ("pack expansion\n");
712
      break;
776
      break;
713
    case DEMANGLE_COMPONENT_TLS_INIT:
777
    case DEMANGLE_COMPONENT_TLS_INIT:
714
      printf ("tls init function\n");
778
      printf ("tls init function\n");
715
      break;
779
      break;
716
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
780
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
717
      printf ("tls wrapper function\n");
781
      printf ("tls wrapper function\n");
718
      break;
782
      break;
719
    case DEMANGLE_COMPONENT_DEFAULT_ARG:
783
    case DEMANGLE_COMPONENT_DEFAULT_ARG:
720
      printf ("default argument %d\n", dc->u.s_unary_num.num);
784
      printf ("default argument %d\n", dc->u.s_unary_num.num);
721
      d_dump (dc->u.s_unary_num.sub, indent+2);
785
      d_dump (dc->u.s_unary_num.sub, indent+2);
722
      return;
786
      return;
723
    case DEMANGLE_COMPONENT_LAMBDA:
787
    case DEMANGLE_COMPONENT_LAMBDA:
724
      printf ("lambda %d\n", dc->u.s_unary_num.num);
788
      printf ("lambda %d\n", dc->u.s_unary_num.num);
725
      d_dump (dc->u.s_unary_num.sub, indent+2);
789
      d_dump (dc->u.s_unary_num.sub, indent+2);
726
      return;
790
      return;
727
    }
791
    }
728
 
792
 
729
  d_dump (d_left (dc), indent + 2);
793
  d_dump (d_left (dc), indent + 2);
730
  d_dump (d_right (dc), indent + 2);
794
  d_dump (d_right (dc), indent + 2);
731
}
795
}
732
 
796
 
733
#endif /* CP_DEMANGLE_DEBUG */
797
#endif /* CP_DEMANGLE_DEBUG */
734
 
798
 
735
/* Fill in a DEMANGLE_COMPONENT_NAME.  */
799
/* Fill in a DEMANGLE_COMPONENT_NAME.  */
736
 
800
 
737
CP_STATIC_IF_GLIBCPP_V3
801
CP_STATIC_IF_GLIBCPP_V3
738
int
802
int
739
cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
803
cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
740
{
804
{
741
  if (p == NULL || s == NULL || len == 0)
805
  if (p == NULL || s == NULL || len == 0)
742
    return 0;
806
    return 0;
743
  p->type = DEMANGLE_COMPONENT_NAME;
807
  p->type = DEMANGLE_COMPONENT_NAME;
744
  p->u.s_name.s = s;
808
  p->u.s_name.s = s;
745
  p->u.s_name.len = len;
809
  p->u.s_name.len = len;
746
  return 1;
810
  return 1;
747
}
811
}
748
 
812
 
749
/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR.  */
813
/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR.  */
750
 
814
 
751
CP_STATIC_IF_GLIBCPP_V3
815
CP_STATIC_IF_GLIBCPP_V3
752
int
816
int
753
cplus_demangle_fill_extended_operator (struct demangle_component *p, int args,
817
cplus_demangle_fill_extended_operator (struct demangle_component *p, int args,
754
                                       struct demangle_component *name)
818
                                       struct demangle_component *name)
755
{
819
{
756
  if (p == NULL || args < 0 || name == NULL)
820
  if (p == NULL || args < 0 || name == NULL)
757
    return 0;
821
    return 0;
758
  p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
822
  p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
759
  p->u.s_extended_operator.args = args;
823
  p->u.s_extended_operator.args = args;
760
  p->u.s_extended_operator.name = name;
824
  p->u.s_extended_operator.name = name;
761
  return 1;
825
  return 1;
762
}
826
}
763
 
827
 
764
/* Fill in a DEMANGLE_COMPONENT_CTOR.  */
828
/* Fill in a DEMANGLE_COMPONENT_CTOR.  */
765
 
829
 
766
CP_STATIC_IF_GLIBCPP_V3
830
CP_STATIC_IF_GLIBCPP_V3
767
int
831
int
768
cplus_demangle_fill_ctor (struct demangle_component *p,
832
cplus_demangle_fill_ctor (struct demangle_component *p,
769
                          enum gnu_v3_ctor_kinds kind,
833
                          enum gnu_v3_ctor_kinds kind,
770
                          struct demangle_component *name)
834
                          struct demangle_component *name)
771
{
835
{
772
  if (p == NULL
836
  if (p == NULL
773
      || name == NULL
837
      || name == NULL
774
      || (int) kind < gnu_v3_complete_object_ctor
838
      || (int) kind < gnu_v3_complete_object_ctor
775
      || (int) kind > gnu_v3_object_ctor_group)
839
      || (int) kind > gnu_v3_object_ctor_group)
776
    return 0;
840
    return 0;
777
  p->type = DEMANGLE_COMPONENT_CTOR;
841
  p->type = DEMANGLE_COMPONENT_CTOR;
778
  p->u.s_ctor.kind = kind;
842
  p->u.s_ctor.kind = kind;
779
  p->u.s_ctor.name = name;
843
  p->u.s_ctor.name = name;
780
  return 1;
844
  return 1;
781
}
845
}
782
 
846
 
783
/* Fill in a DEMANGLE_COMPONENT_DTOR.  */
847
/* Fill in a DEMANGLE_COMPONENT_DTOR.  */
784
 
848
 
785
CP_STATIC_IF_GLIBCPP_V3
849
CP_STATIC_IF_GLIBCPP_V3
786
int
850
int
787
cplus_demangle_fill_dtor (struct demangle_component *p,
851
cplus_demangle_fill_dtor (struct demangle_component *p,
788
                          enum gnu_v3_dtor_kinds kind,
852
                          enum gnu_v3_dtor_kinds kind,
789
                          struct demangle_component *name)
853
                          struct demangle_component *name)
790
{
854
{
791
  if (p == NULL
855
  if (p == NULL
792
      || name == NULL
856
      || name == NULL
793
      || (int) kind < gnu_v3_deleting_dtor
857
      || (int) kind < gnu_v3_deleting_dtor
794
      || (int) kind > gnu_v3_object_dtor_group)
858
      || (int) kind > gnu_v3_object_dtor_group)
795
    return 0;
859
    return 0;
796
  p->type = DEMANGLE_COMPONENT_DTOR;
860
  p->type = DEMANGLE_COMPONENT_DTOR;
797
  p->u.s_dtor.kind = kind;
861
  p->u.s_dtor.kind = kind;
798
  p->u.s_dtor.name = name;
862
  p->u.s_dtor.name = name;
799
  return 1;
863
  return 1;
800
}
864
}
801
 
865
 
802
/* Add a new component.  */
866
/* Add a new component.  */
803
 
867
 
804
static struct demangle_component *
868
static struct demangle_component *
805
d_make_empty (struct d_info *di)
869
d_make_empty (struct d_info *di)
806
{
870
{
807
  struct demangle_component *p;
871
  struct demangle_component *p;
808
 
872
 
809
  if (di->next_comp >= di->num_comps)
873
  if (di->next_comp >= di->num_comps)
810
    return NULL;
874
    return NULL;
811
  p = &di->comps[di->next_comp];
875
  p = &di->comps[di->next_comp];
812
  ++di->next_comp;
876
  ++di->next_comp;
813
  return p;
877
  return p;
814
}
878
}
815
 
879
 
816
/* Add a new generic component.  */
880
/* Add a new generic component.  */
817
 
881
 
818
static struct demangle_component *
882
static struct demangle_component *
819
d_make_comp (struct d_info *di, enum demangle_component_type type,
883
d_make_comp (struct d_info *di, enum demangle_component_type type,
820
             struct demangle_component *left,
884
             struct demangle_component *left,
821
             struct demangle_component *right)
885
             struct demangle_component *right)
822
{
886
{
823
  struct demangle_component *p;
887
  struct demangle_component *p;
824
 
888
 
825
  /* We check for errors here.  A typical error would be a NULL return
889
  /* We check for errors here.  A typical error would be a NULL return
826
     from a subroutine.  We catch those here, and return NULL
890
     from a subroutine.  We catch those here, and return NULL
827
     upward.  */
891
     upward.  */
828
  switch (type)
892
  switch (type)
829
    {
893
    {
830
      /* These types require two parameters.  */
894
      /* These types require two parameters.  */
831
    case DEMANGLE_COMPONENT_QUAL_NAME:
895
    case DEMANGLE_COMPONENT_QUAL_NAME:
832
    case DEMANGLE_COMPONENT_LOCAL_NAME:
896
    case DEMANGLE_COMPONENT_LOCAL_NAME:
833
    case DEMANGLE_COMPONENT_TYPED_NAME:
897
    case DEMANGLE_COMPONENT_TYPED_NAME:
834
    case DEMANGLE_COMPONENT_TAGGED_NAME:
898
    case DEMANGLE_COMPONENT_TAGGED_NAME:
835
    case DEMANGLE_COMPONENT_TEMPLATE:
899
    case DEMANGLE_COMPONENT_TEMPLATE:
836
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
900
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
837
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
901
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
838
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
902
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
839
    case DEMANGLE_COMPONENT_UNARY:
903
    case DEMANGLE_COMPONENT_UNARY:
840
    case DEMANGLE_COMPONENT_BINARY:
904
    case DEMANGLE_COMPONENT_BINARY:
841
    case DEMANGLE_COMPONENT_BINARY_ARGS:
905
    case DEMANGLE_COMPONENT_BINARY_ARGS:
842
    case DEMANGLE_COMPONENT_TRINARY:
906
    case DEMANGLE_COMPONENT_TRINARY:
843
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
907
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
844
    case DEMANGLE_COMPONENT_LITERAL:
908
    case DEMANGLE_COMPONENT_LITERAL:
845
    case DEMANGLE_COMPONENT_LITERAL_NEG:
909
    case DEMANGLE_COMPONENT_LITERAL_NEG:
846
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
910
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
847
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
911
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
848
    case DEMANGLE_COMPONENT_CLONE:
912
    case DEMANGLE_COMPONENT_CLONE:
849
      if (left == NULL || right == NULL)
913
      if (left == NULL || right == NULL)
850
	return NULL;
914
	return NULL;
851
      break;
915
      break;
852
 
916
 
853
      /* These types only require one parameter.  */
917
      /* These types only require one parameter.  */
854
    case DEMANGLE_COMPONENT_VTABLE:
918
    case DEMANGLE_COMPONENT_VTABLE:
855
    case DEMANGLE_COMPONENT_VTT:
919
    case DEMANGLE_COMPONENT_VTT:
856
    case DEMANGLE_COMPONENT_TYPEINFO:
920
    case DEMANGLE_COMPONENT_TYPEINFO:
857
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
921
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
858
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
922
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
859
    case DEMANGLE_COMPONENT_THUNK:
923
    case DEMANGLE_COMPONENT_THUNK:
860
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
924
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
861
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
925
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
862
    case DEMANGLE_COMPONENT_JAVA_CLASS:
926
    case DEMANGLE_COMPONENT_JAVA_CLASS:
863
    case DEMANGLE_COMPONENT_GUARD:
927
    case DEMANGLE_COMPONENT_GUARD:
864
    case DEMANGLE_COMPONENT_TLS_INIT:
928
    case DEMANGLE_COMPONENT_TLS_INIT:
865
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
929
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
866
    case DEMANGLE_COMPONENT_REFTEMP:
930
    case DEMANGLE_COMPONENT_REFTEMP:
867
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
931
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
868
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
932
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
869
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
933
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
870
    case DEMANGLE_COMPONENT_POINTER:
934
    case DEMANGLE_COMPONENT_POINTER:
871
    case DEMANGLE_COMPONENT_REFERENCE:
935
    case DEMANGLE_COMPONENT_REFERENCE:
872
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
936
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
873
    case DEMANGLE_COMPONENT_COMPLEX:
937
    case DEMANGLE_COMPONENT_COMPLEX:
874
    case DEMANGLE_COMPONENT_IMAGINARY:
938
    case DEMANGLE_COMPONENT_IMAGINARY:
875
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
939
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
876
    case DEMANGLE_COMPONENT_CAST:
940
    case DEMANGLE_COMPONENT_CAST:
877
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
941
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
878
    case DEMANGLE_COMPONENT_DECLTYPE:
942
    case DEMANGLE_COMPONENT_DECLTYPE:
879
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
943
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
880
    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
944
    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
881
    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
945
    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
882
    case DEMANGLE_COMPONENT_NULLARY:
946
    case DEMANGLE_COMPONENT_NULLARY:
883
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
947
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
884
      if (left == NULL)
948
      if (left == NULL)
885
	return NULL;
949
	return NULL;
886
      break;
950
      break;
887
 
951
 
888
      /* This needs a right parameter, but the left parameter can be
952
      /* This needs a right parameter, but the left parameter can be
889
	 empty.  */
953
	 empty.  */
890
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
954
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
891
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
955
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
892
      if (right == NULL)
956
      if (right == NULL)
893
	return NULL;
957
	return NULL;
894
      break;
958
      break;
895
 
959
 
896
      /* These are allowed to have no parameters--in some cases they
960
      /* These are allowed to have no parameters--in some cases they
897
	 will be filled in later.  */
961
	 will be filled in later.  */
898
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
962
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
899
    case DEMANGLE_COMPONENT_RESTRICT:
963
    case DEMANGLE_COMPONENT_RESTRICT:
900
    case DEMANGLE_COMPONENT_VOLATILE:
964
    case DEMANGLE_COMPONENT_VOLATILE:
901
    case DEMANGLE_COMPONENT_CONST:
965
    case DEMANGLE_COMPONENT_CONST:
902
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
966
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
903
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
967
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
904
    case DEMANGLE_COMPONENT_CONST_THIS:
968
    case DEMANGLE_COMPONENT_CONST_THIS:
905
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
969
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
906
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
970
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
907
    case DEMANGLE_COMPONENT_ARGLIST:
971
    case DEMANGLE_COMPONENT_ARGLIST:
908
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
972
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
909
      break;
973
      break;
910
 
974
 
911
      /* Other types should not be seen here.  */
975
      /* Other types should not be seen here.  */
912
    default:
976
    default:
913
      return NULL;
977
      return NULL;
914
    }
978
    }
915
 
979
 
916
  p = d_make_empty (di);
980
  p = d_make_empty (di);
917
  if (p != NULL)
981
  if (p != NULL)
918
    {
982
    {
919
      p->type = type;
983
      p->type = type;
920
      p->u.s_binary.left = left;
984
      p->u.s_binary.left = left;
921
      p->u.s_binary.right = right;
985
      p->u.s_binary.right = right;
922
    }
986
    }
923
  return p;
987
  return p;
924
}
988
}
925
 
989
 
926
/* Add a new demangle mangled name component.  */
990
/* Add a new demangle mangled name component.  */
927
 
991
 
928
static struct demangle_component *
992
static struct demangle_component *
929
d_make_demangle_mangled_name (struct d_info *di, const char *s)
993
d_make_demangle_mangled_name (struct d_info *di, const char *s)
930
{
994
{
931
  if (d_peek_char (di) != '_' || d_peek_next_char (di) != 'Z')
995
  if (d_peek_char (di) != '_' || d_peek_next_char (di) != 'Z')
932
    return d_make_name (di, s, strlen (s));
996
    return d_make_name (di, s, strlen (s));
933
  d_advance (di, 2);
997
  d_advance (di, 2);
934
  return d_encoding (di, 0);
998
  return d_encoding (di, 0);
935
}
999
}
936
 
1000
 
937
/* Add a new name component.  */
1001
/* Add a new name component.  */
938
 
1002
 
939
static struct demangle_component *
1003
static struct demangle_component *
940
d_make_name (struct d_info *di, const char *s, int len)
1004
d_make_name (struct d_info *di, const char *s, int len)
941
{
1005
{
942
  struct demangle_component *p;
1006
  struct demangle_component *p;
943
 
1007
 
944
  p = d_make_empty (di);
1008
  p = d_make_empty (di);
945
  if (! cplus_demangle_fill_name (p, s, len))
1009
  if (! cplus_demangle_fill_name (p, s, len))
946
    return NULL;
1010
    return NULL;
947
  return p;
1011
  return p;
948
}
1012
}
949
 
1013
 
950
/* Add a new builtin type component.  */
1014
/* Add a new builtin type component.  */
951
 
1015
 
952
static struct demangle_component *
1016
static struct demangle_component *
953
d_make_builtin_type (struct d_info *di,
1017
d_make_builtin_type (struct d_info *di,
954
                     const struct demangle_builtin_type_info *type)
1018
                     const struct demangle_builtin_type_info *type)
955
{
1019
{
956
  struct demangle_component *p;
1020
  struct demangle_component *p;
957
 
1021
 
958
  if (type == NULL)
1022
  if (type == NULL)
959
    return NULL;
1023
    return NULL;
960
  p = d_make_empty (di);
1024
  p = d_make_empty (di);
961
  if (p != NULL)
1025
  if (p != NULL)
962
    {
1026
    {
963
      p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
1027
      p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
964
      p->u.s_builtin.type = type;
1028
      p->u.s_builtin.type = type;
965
    }
1029
    }
966
  return p;
1030
  return p;
967
}
1031
}
968
 
1032
 
969
/* Add a new operator component.  */
1033
/* Add a new operator component.  */
970
 
1034
 
971
static struct demangle_component *
1035
static struct demangle_component *
972
d_make_operator (struct d_info *di, const struct demangle_operator_info *op)
1036
d_make_operator (struct d_info *di, const struct demangle_operator_info *op)
973
{
1037
{
974
  struct demangle_component *p;
1038
  struct demangle_component *p;
975
 
1039
 
976
  p = d_make_empty (di);
1040
  p = d_make_empty (di);
977
  if (p != NULL)
1041
  if (p != NULL)
978
    {
1042
    {
979
      p->type = DEMANGLE_COMPONENT_OPERATOR;
1043
      p->type = DEMANGLE_COMPONENT_OPERATOR;
980
      p->u.s_operator.op = op;
1044
      p->u.s_operator.op = op;
981
    }
1045
    }
982
  return p;
1046
  return p;
983
}
1047
}
984
 
1048
 
985
/* Add a new extended operator component.  */
1049
/* Add a new extended operator component.  */
986
 
1050
 
987
static struct demangle_component *
1051
static struct demangle_component *
988
d_make_extended_operator (struct d_info *di, int args,
1052
d_make_extended_operator (struct d_info *di, int args,
989
                          struct demangle_component *name)
1053
                          struct demangle_component *name)
990
{
1054
{
991
  struct demangle_component *p;
1055
  struct demangle_component *p;
992
 
1056
 
993
  p = d_make_empty (di);
1057
  p = d_make_empty (di);
994
  if (! cplus_demangle_fill_extended_operator (p, args, name))
1058
  if (! cplus_demangle_fill_extended_operator (p, args, name))
995
    return NULL;
1059
    return NULL;
996
  return p;
1060
  return p;
997
}
1061
}
998
 
1062
 
999
static struct demangle_component *
1063
static struct demangle_component *
1000
d_make_default_arg (struct d_info *di, int num,
1064
d_make_default_arg (struct d_info *di, int num,
1001
		    struct demangle_component *sub)
1065
		    struct demangle_component *sub)
1002
{
1066
{
1003
  struct demangle_component *p = d_make_empty (di);
1067
  struct demangle_component *p = d_make_empty (di);
1004
  if (p)
1068
  if (p)
1005
    {
1069
    {
1006
      p->type = DEMANGLE_COMPONENT_DEFAULT_ARG;
1070
      p->type = DEMANGLE_COMPONENT_DEFAULT_ARG;
1007
      p->u.s_unary_num.num = num;
1071
      p->u.s_unary_num.num = num;
1008
      p->u.s_unary_num.sub = sub;
1072
      p->u.s_unary_num.sub = sub;
1009
    }
1073
    }
1010
  return p;
1074
  return p;
1011
}
1075
}
1012
 
1076
 
1013
/* Add a new constructor component.  */
1077
/* Add a new constructor component.  */
1014
 
1078
 
1015
static struct demangle_component *
1079
static struct demangle_component *
1016
d_make_ctor (struct d_info *di, enum gnu_v3_ctor_kinds kind,
1080
d_make_ctor (struct d_info *di, enum gnu_v3_ctor_kinds kind,
1017
             struct demangle_component *name)
1081
             struct demangle_component *name)
1018
{
1082
{
1019
  struct demangle_component *p;
1083
  struct demangle_component *p;
1020
 
1084
 
1021
  p = d_make_empty (di);
1085
  p = d_make_empty (di);
1022
  if (! cplus_demangle_fill_ctor (p, kind, name))
1086
  if (! cplus_demangle_fill_ctor (p, kind, name))
1023
    return NULL;
1087
    return NULL;
1024
  return p;
1088
  return p;
1025
}
1089
}
1026
 
1090
 
1027
/* Add a new destructor component.  */
1091
/* Add a new destructor component.  */
1028
 
1092
 
1029
static struct demangle_component *
1093
static struct demangle_component *
1030
d_make_dtor (struct d_info *di, enum gnu_v3_dtor_kinds kind,
1094
d_make_dtor (struct d_info *di, enum gnu_v3_dtor_kinds kind,
1031
             struct demangle_component *name)
1095
             struct demangle_component *name)
1032
{
1096
{
1033
  struct demangle_component *p;
1097
  struct demangle_component *p;
1034
 
1098
 
1035
  p = d_make_empty (di);
1099
  p = d_make_empty (di);
1036
  if (! cplus_demangle_fill_dtor (p, kind, name))
1100
  if (! cplus_demangle_fill_dtor (p, kind, name))
1037
    return NULL;
1101
    return NULL;
1038
  return p;
1102
  return p;
1039
}
1103
}
1040
 
1104
 
1041
/* Add a new template parameter.  */
1105
/* Add a new template parameter.  */
1042
 
1106
 
1043
static struct demangle_component *
1107
static struct demangle_component *
1044
d_make_template_param (struct d_info *di, long i)
1108
d_make_template_param (struct d_info *di, long i)
1045
{
1109
{
1046
  struct demangle_component *p;
1110
  struct demangle_component *p;
1047
 
1111
 
1048
  p = d_make_empty (di);
1112
  p = d_make_empty (di);
1049
  if (p != NULL)
1113
  if (p != NULL)
1050
    {
1114
    {
1051
      p->type = DEMANGLE_COMPONENT_TEMPLATE_PARAM;
1115
      p->type = DEMANGLE_COMPONENT_TEMPLATE_PARAM;
1052
      p->u.s_number.number = i;
1116
      p->u.s_number.number = i;
1053
    }
1117
    }
1054
  return p;
1118
  return p;
1055
}
1119
}
1056
 
1120
 
1057
/* Add a new function parameter.  */
1121
/* Add a new function parameter.  */
1058
 
1122
 
1059
static struct demangle_component *
1123
static struct demangle_component *
1060
d_make_function_param (struct d_info *di, long i)
1124
d_make_function_param (struct d_info *di, long i)
1061
{
1125
{
1062
  struct demangle_component *p;
1126
  struct demangle_component *p;
1063
 
1127
 
1064
  p = d_make_empty (di);
1128
  p = d_make_empty (di);
1065
  if (p != NULL)
1129
  if (p != NULL)
1066
    {
1130
    {
1067
      p->type = DEMANGLE_COMPONENT_FUNCTION_PARAM;
1131
      p->type = DEMANGLE_COMPONENT_FUNCTION_PARAM;
1068
      p->u.s_number.number = i;
1132
      p->u.s_number.number = i;
1069
    }
1133
    }
1070
  return p;
1134
  return p;
1071
}
1135
}
1072
 
1136
 
1073
/* Add a new standard substitution component.  */
1137
/* Add a new standard substitution component.  */
1074
 
1138
 
1075
static struct demangle_component *
1139
static struct demangle_component *
1076
d_make_sub (struct d_info *di, const char *name, int len)
1140
d_make_sub (struct d_info *di, const char *name, int len)
1077
{
1141
{
1078
  struct demangle_component *p;
1142
  struct demangle_component *p;
1079
 
1143
 
1080
  p = d_make_empty (di);
1144
  p = d_make_empty (di);
1081
  if (p != NULL)
1145
  if (p != NULL)
1082
    {
1146
    {
1083
      p->type = DEMANGLE_COMPONENT_SUB_STD;
1147
      p->type = DEMANGLE_COMPONENT_SUB_STD;
1084
      p->u.s_string.string = name;
1148
      p->u.s_string.string = name;
1085
      p->u.s_string.len = len;
1149
      p->u.s_string.len = len;
1086
    }
1150
    }
1087
  return p;
1151
  return p;
1088
}
1152
}
1089
 
1153
 
1090
/*  ::= _Z  []*
1154
/*  ::= _Z  []*
1091
 
1155
 
1092
   TOP_LEVEL is non-zero when called at the top level.  */
1156
   TOP_LEVEL is non-zero when called at the top level.  */
1093
 
1157
 
1094
CP_STATIC_IF_GLIBCPP_V3
1158
CP_STATIC_IF_GLIBCPP_V3
1095
struct demangle_component *
1159
struct demangle_component *
1096
cplus_demangle_mangled_name (struct d_info *di, int top_level)
1160
cplus_demangle_mangled_name (struct d_info *di, int top_level)
1097
{
1161
{
1098
  struct demangle_component *p;
1162
  struct demangle_component *p;
1099
 
1163
 
1100
  if (! d_check_char (di, '_')
1164
  if (! d_check_char (di, '_')
1101
      /* Allow missing _ if not at toplevel to work around a
1165
      /* Allow missing _ if not at toplevel to work around a
1102
	 bug in G++ abi-version=2 mangling; see the comment in
1166
	 bug in G++ abi-version=2 mangling; see the comment in
1103
	 write_template_arg.  */
1167
	 write_template_arg.  */
1104
      && top_level)
1168
      && top_level)
1105
    return NULL;
1169
    return NULL;
1106
  if (! d_check_char (di, 'Z'))
1170
  if (! d_check_char (di, 'Z'))
1107
    return NULL;
1171
    return NULL;
1108
  p = d_encoding (di, top_level);
1172
  p = d_encoding (di, top_level);
1109
 
1173
 
1110
  /* If at top level and parsing parameters, check for a clone
1174
  /* If at top level and parsing parameters, check for a clone
1111
     suffix.  */
1175
     suffix.  */
1112
  if (top_level && (di->options & DMGL_PARAMS) != 0)
1176
  if (top_level && (di->options & DMGL_PARAMS) != 0)
1113
    while (d_peek_char (di) == '.'
1177
    while (d_peek_char (di) == '.'
1114
	   && (IS_LOWER (d_peek_next_char (di))
1178
	   && (IS_LOWER (d_peek_next_char (di))
1115
	       || d_peek_next_char (di) == '_'
1179
	       || d_peek_next_char (di) == '_'
1116
	       || IS_DIGIT (d_peek_next_char (di))))
1180
	       || IS_DIGIT (d_peek_next_char (di))))
1117
      p = d_clone_suffix (di, p);
1181
      p = d_clone_suffix (di, p);
1118
 
1182
 
1119
  return p;
1183
  return p;
1120
}
1184
}
1121
 
1185
 
1122
/* Return whether a function should have a return type.  The argument
1186
/* Return whether a function should have a return type.  The argument
1123
   is the function name, which may be qualified in various ways.  The
1187
   is the function name, which may be qualified in various ways.  The
1124
   rules are that template functions have return types with some
1188
   rules are that template functions have return types with some
1125
   exceptions, function types which are not part of a function name
1189
   exceptions, function types which are not part of a function name
1126
   mangling have return types with some exceptions, and non-template
1190
   mangling have return types with some exceptions, and non-template
1127
   function names do not have return types.  The exceptions are that
1191
   function names do not have return types.  The exceptions are that
1128
   constructors, destructors, and conversion operators do not have
1192
   constructors, destructors, and conversion operators do not have
1129
   return types.  */
1193
   return types.  */
1130
 
1194
 
1131
static int
1195
static int
1132
has_return_type (struct demangle_component *dc)
1196
has_return_type (struct demangle_component *dc)
1133
{
1197
{
1134
  if (dc == NULL)
1198
  if (dc == NULL)
1135
    return 0;
1199
    return 0;
1136
  switch (dc->type)
1200
  switch (dc->type)
1137
    {
1201
    {
1138
    default:
1202
    default:
1139
      return 0;
1203
      return 0;
1140
    case DEMANGLE_COMPONENT_TEMPLATE:
1204
    case DEMANGLE_COMPONENT_TEMPLATE:
1141
      return ! is_ctor_dtor_or_conversion (d_left (dc));
1205
      return ! is_ctor_dtor_or_conversion (d_left (dc));
1142
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
1206
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
1143
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
1207
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
1144
    case DEMANGLE_COMPONENT_CONST_THIS:
1208
    case DEMANGLE_COMPONENT_CONST_THIS:
1145
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
1209
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
1146
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
1210
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
1147
      return has_return_type (d_left (dc));
1211
      return has_return_type (d_left (dc));
1148
    }
1212
    }
1149
}
1213
}
1150
 
1214
 
1151
/* Return whether a name is a constructor, a destructor, or a
1215
/* Return whether a name is a constructor, a destructor, or a
1152
   conversion operator.  */
1216
   conversion operator.  */
1153
 
1217
 
1154
static int
1218
static int
1155
is_ctor_dtor_or_conversion (struct demangle_component *dc)
1219
is_ctor_dtor_or_conversion (struct demangle_component *dc)
1156
{
1220
{
1157
  if (dc == NULL)
1221
  if (dc == NULL)
1158
    return 0;
1222
    return 0;
1159
  switch (dc->type)
1223
  switch (dc->type)
1160
    {
1224
    {
1161
    default:
1225
    default:
1162
      return 0;
1226
      return 0;
1163
    case DEMANGLE_COMPONENT_QUAL_NAME:
1227
    case DEMANGLE_COMPONENT_QUAL_NAME:
1164
    case DEMANGLE_COMPONENT_LOCAL_NAME:
1228
    case DEMANGLE_COMPONENT_LOCAL_NAME:
1165
      return is_ctor_dtor_or_conversion (d_right (dc));
1229
      return is_ctor_dtor_or_conversion (d_right (dc));
1166
    case DEMANGLE_COMPONENT_CTOR:
1230
    case DEMANGLE_COMPONENT_CTOR:
1167
    case DEMANGLE_COMPONENT_DTOR:
1231
    case DEMANGLE_COMPONENT_DTOR:
1168
    case DEMANGLE_COMPONENT_CAST:
1232
    case DEMANGLE_COMPONENT_CAST:
1169
      return 1;
1233
      return 1;
1170
    }
1234
    }
1171
}
1235
}
1172
 
1236
 
1173
/*  ::= <(function) name> 
1237
/*  ::= <(function) name> 
1174
              ::= <(data) name>
1238
              ::= <(data) name>
1175
              ::= 
1239
              ::= 
1176
 
1240
 
1177
   TOP_LEVEL is non-zero when called at the top level, in which case
1241
   TOP_LEVEL is non-zero when called at the top level, in which case
1178
   if DMGL_PARAMS is not set we do not demangle the function
1242
   if DMGL_PARAMS is not set we do not demangle the function
1179
   parameters.  We only set this at the top level, because otherwise
1243
   parameters.  We only set this at the top level, because otherwise
1180
   we would not correctly demangle names in local scopes.  */
1244
   we would not correctly demangle names in local scopes.  */
1181
 
1245
 
1182
static struct demangle_component *
1246
static struct demangle_component *
1183
d_encoding (struct d_info *di, int top_level)
1247
d_encoding (struct d_info *di, int top_level)
1184
{
1248
{
1185
  char peek = d_peek_char (di);
1249
  char peek = d_peek_char (di);
1186
 
1250
 
1187
  if (peek == 'G' || peek == 'T')
1251
  if (peek == 'G' || peek == 'T')
1188
    return d_special_name (di);
1252
    return d_special_name (di);
1189
  else
1253
  else
1190
    {
1254
    {
1191
      struct demangle_component *dc;
1255
      struct demangle_component *dc;
1192
 
1256
 
1193
      dc = d_name (di);
1257
      dc = d_name (di);
1194
 
1258
 
1195
      if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)
1259
      if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)
1196
	{
1260
	{
1197
	  /* Strip off any initial CV-qualifiers, as they really apply
1261
	  /* Strip off any initial CV-qualifiers, as they really apply
1198
	     to the `this' parameter, and they were not output by the
1262
	     to the `this' parameter, and they were not output by the
1199
	     v2 demangler without DMGL_PARAMS.  */
1263
	     v2 demangler without DMGL_PARAMS.  */
1200
	  while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
1264
	  while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
1201
		 || dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
1265
		 || dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
1202
		 || dc->type == DEMANGLE_COMPONENT_CONST_THIS
1266
		 || dc->type == DEMANGLE_COMPONENT_CONST_THIS
1203
		 || dc->type == DEMANGLE_COMPONENT_REFERENCE_THIS
1267
		 || dc->type == DEMANGLE_COMPONENT_REFERENCE_THIS
1204
		 || dc->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS)
1268
		 || dc->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS)
1205
	    dc = d_left (dc);
1269
	    dc = d_left (dc);
1206
 
1270
 
1207
	  /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1271
	  /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1208
	     there may be CV-qualifiers on its right argument which
1272
	     there may be CV-qualifiers on its right argument which
1209
	     really apply here; this happens when parsing a class
1273
	     really apply here; this happens when parsing a class
1210
	     which is local to a function.  */
1274
	     which is local to a function.  */
1211
	  if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
1275
	  if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
1212
	    {
1276
	    {
1213
	      struct demangle_component *dcr;
1277
	      struct demangle_component *dcr;
1214
 
1278
 
1215
	      dcr = d_right (dc);
1279
	      dcr = d_right (dc);
1216
	      while (dcr->type == DEMANGLE_COMPONENT_RESTRICT_THIS
1280
	      while (dcr->type == DEMANGLE_COMPONENT_RESTRICT_THIS
1217
		     || dcr->type == DEMANGLE_COMPONENT_VOLATILE_THIS
1281
		     || dcr->type == DEMANGLE_COMPONENT_VOLATILE_THIS
1218
		     || dcr->type == DEMANGLE_COMPONENT_CONST_THIS
1282
		     || dcr->type == DEMANGLE_COMPONENT_CONST_THIS
1219
		     || dcr->type == DEMANGLE_COMPONENT_REFERENCE_THIS
1283
		     || dcr->type == DEMANGLE_COMPONENT_REFERENCE_THIS
1220
		     || dcr->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS)
1284
		     || dcr->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS)
1221
		dcr = d_left (dcr);
1285
		dcr = d_left (dcr);
1222
	      dc->u.s_binary.right = dcr;
1286
	      dc->u.s_binary.right = dcr;
1223
	    }
1287
	    }
1224
 
1288
 
1225
	  return dc;
1289
	  return dc;
1226
	}
1290
	}
1227
 
1291
 
1228
      peek = d_peek_char (di);
1292
      peek = d_peek_char (di);
1229
      if (dc == NULL || peek == '\0' || peek == 'E')
1293
      if (dc == NULL || peek == '\0' || peek == 'E')
1230
	return dc;
1294
	return dc;
1231
      return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc,
1295
      return d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, dc,
1232
			  d_bare_function_type (di, has_return_type (dc)));
1296
			  d_bare_function_type (di, has_return_type (dc)));
1233
    }
1297
    }
1234
}
1298
}
1235
 
1299
 
1236
/*  ::=  B  */
1300
/*  ::=  B  */
1237
 
1301
 
1238
static struct demangle_component *
1302
static struct demangle_component *
1239
d_abi_tags (struct d_info *di, struct demangle_component *dc)
1303
d_abi_tags (struct d_info *di, struct demangle_component *dc)
1240
{
1304
{
-
 
1305
  struct demangle_component *hold_last_name;
1241
  char peek;
1306
  char peek;
-
 
1307
 
-
 
1308
  /* Preserve the last name, so the ABI tag doesn't clobber it.  */
-
 
1309
  hold_last_name = di->last_name;
-
 
1310
 
1242
  while (peek = d_peek_char (di),
1311
  while (peek = d_peek_char (di),
1243
	 peek == 'B')
1312
	 peek == 'B')
1244
    {
1313
    {
1245
      struct demangle_component *tag;
1314
      struct demangle_component *tag;
1246
      d_advance (di, 1);
1315
      d_advance (di, 1);
1247
      tag = d_source_name (di);
1316
      tag = d_source_name (di);
1248
      dc = d_make_comp (di, DEMANGLE_COMPONENT_TAGGED_NAME, dc, tag);
1317
      dc = d_make_comp (di, DEMANGLE_COMPONENT_TAGGED_NAME, dc, tag);
1249
    }
1318
    }
-
 
1319
 
-
 
1320
  di->last_name = hold_last_name;
-
 
1321
 
1250
  return dc;
1322
  return dc;
1251
}
1323
}
1252
 
1324
 
1253
/*  ::= 
1325
/*  ::= 
1254
          ::= 
1326
          ::= 
1255
          ::=  
1327
          ::=  
1256
          ::= 
1328
          ::= 
1257
 
1329
 
1258
    ::= 
1330
    ::= 
1259
                   ::= St 
1331
                   ::= St 
1260
 
1332
 
1261
    ::= 
1333
    ::= 
1262
                            ::= 
1334
                            ::= 
1263
*/
1335
*/
1264
 
1336
 
1265
static struct demangle_component *
1337
static struct demangle_component *
1266
d_name (struct d_info *di)
1338
d_name (struct d_info *di)
1267
{
1339
{
1268
  char peek = d_peek_char (di);
1340
  char peek = d_peek_char (di);
1269
  struct demangle_component *dc;
1341
  struct demangle_component *dc;
1270
 
1342
 
1271
  switch (peek)
1343
  switch (peek)
1272
    {
1344
    {
1273
    case 'N':
1345
    case 'N':
1274
      return d_nested_name (di);
1346
      return d_nested_name (di);
1275
 
1347
 
1276
    case 'Z':
1348
    case 'Z':
1277
      return d_local_name (di);
1349
      return d_local_name (di);
1278
 
-
 
1279
    case 'L':
1350
 
1280
    case 'U':
1351
    case 'U':
1281
      return d_unqualified_name (di);
1352
      return d_unqualified_name (di);
1282
 
1353
 
1283
    case 'S':
1354
    case 'S':
1284
      {
1355
      {
1285
	int subst;
1356
	int subst;
1286
 
1357
 
1287
	if (d_peek_next_char (di) != 't')
1358
	if (d_peek_next_char (di) != 't')
1288
	  {
1359
	  {
1289
	    dc = d_substitution (di, 0);
1360
	    dc = d_substitution (di, 0);
1290
	    subst = 1;
1361
	    subst = 1;
1291
	  }
1362
	  }
1292
	else
1363
	else
1293
	  {
1364
	  {
1294
	    d_advance (di, 2);
1365
	    d_advance (di, 2);
1295
	    dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,
1366
	    dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,
1296
			      d_make_name (di, "std", 3),
1367
			      d_make_name (di, "std", 3),
1297
			      d_unqualified_name (di));
1368
			      d_unqualified_name (di));
1298
	    di->expansion += 3;
1369
	    di->expansion += 3;
1299
	    subst = 0;
1370
	    subst = 0;
1300
	  }
1371
	  }
1301
 
1372
 
1302
	if (d_peek_char (di) != 'I')
1373
	if (d_peek_char (di) != 'I')
1303
	  {
1374
	  {
1304
	    /* The grammar does not permit this case to occur if we
1375
	    /* The grammar does not permit this case to occur if we
1305
	       called d_substitution() above (i.e., subst == 1).  We
1376
	       called d_substitution() above (i.e., subst == 1).  We
1306
	       don't bother to check.  */
1377
	       don't bother to check.  */
1307
	  }
1378
	  }
1308
	else
1379
	else
1309
	  {
1380
	  {
1310
	    /* This is , which means that we just saw
1381
	    /* This is , which means that we just saw
1311
	       , which is a substitution
1382
	       , which is a substitution
1312
	       candidate if we didn't just get it from a
1383
	       candidate if we didn't just get it from a
1313
	       substitution.  */
1384
	       substitution.  */
1314
	    if (! subst)
1385
	    if (! subst)
1315
	      {
1386
	      {
1316
		if (! d_add_substitution (di, dc))
1387
		if (! d_add_substitution (di, dc))
1317
		  return NULL;
1388
		  return NULL;
1318
	      }
1389
	      }
1319
	    dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1390
	    dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1320
			      d_template_args (di));
1391
			      d_template_args (di));
1321
	  }
1392
	  }
1322
 
1393
 
1323
	return dc;
1394
	return dc;
1324
      }
1395
      }
-
 
1396
 
1325
 
1397
    case 'L':
1326
    default:
1398
    default:
1327
      dc = d_unqualified_name (di);
1399
      dc = d_unqualified_name (di);
1328
      if (d_peek_char (di) == 'I')
1400
      if (d_peek_char (di) == 'I')
1329
	{
1401
	{
1330
	  /* This is , which means that we just saw
1402
	  /* This is , which means that we just saw
1331
	     , which is a substitution
1403
	     , which is a substitution
1332
	     candidate.  */
1404
	     candidate.  */
1333
	  if (! d_add_substitution (di, dc))
1405
	  if (! d_add_substitution (di, dc))
1334
	    return NULL;
1406
	    return NULL;
1335
	  dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1407
	  dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1336
			    d_template_args (di));
1408
			    d_template_args (di));
1337
	}
1409
	}
1338
      return dc;
1410
      return dc;
1339
    }
1411
    }
1340
}
1412
}
1341
 
1413
 
1342
/*  ::= N [] []   E
1414
/*  ::= N [] []   E
1343
                 ::= N [] []   E
1415
                 ::= N [] []   E
1344
*/
1416
*/
1345
 
1417
 
1346
static struct demangle_component *
1418
static struct demangle_component *
1347
d_nested_name (struct d_info *di)
1419
d_nested_name (struct d_info *di)
1348
{
1420
{
1349
  struct demangle_component *ret;
1421
  struct demangle_component *ret;
1350
  struct demangle_component **pret;
1422
  struct demangle_component **pret;
1351
  struct demangle_component *rqual;
1423
  struct demangle_component *rqual;
1352
 
1424
 
1353
  if (! d_check_char (di, 'N'))
1425
  if (! d_check_char (di, 'N'))
1354
    return NULL;
1426
    return NULL;
1355
 
1427
 
1356
  pret = d_cv_qualifiers (di, &ret, 1);
1428
  pret = d_cv_qualifiers (di, &ret, 1);
1357
  if (pret == NULL)
1429
  if (pret == NULL)
1358
    return NULL;
1430
    return NULL;
1359
 
1431
 
1360
  /* Parse the ref-qualifier now and then attach it
1432
  /* Parse the ref-qualifier now and then attach it
1361
     once we have something to attach it to.  */
1433
     once we have something to attach it to.  */
1362
  rqual = d_ref_qualifier (di, NULL);
1434
  rqual = d_ref_qualifier (di, NULL);
1363
 
1435
 
1364
  *pret = d_prefix (di);
1436
  *pret = d_prefix (di);
1365
  if (*pret == NULL)
1437
  if (*pret == NULL)
1366
    return NULL;
1438
    return NULL;
1367
 
1439
 
1368
  if (rqual)
1440
  if (rqual)
1369
    {
1441
    {
1370
      d_left (rqual) = ret;
1442
      d_left (rqual) = ret;
1371
      ret = rqual;
1443
      ret = rqual;
1372
    }
1444
    }
1373
 
1445
 
1374
  if (! d_check_char (di, 'E'))
1446
  if (! d_check_char (di, 'E'))
1375
    return NULL;
1447
    return NULL;
1376
 
1448
 
1377
  return ret;
1449
  return ret;
1378
}
1450
}
1379
 
1451
 
1380
/*  ::=  
1452
/*  ::=  
1381
            ::=  
1453
            ::=  
1382
            ::= 
1454
            ::= 
1383
            ::= 
1455
            ::= 
1384
            ::=
1456
            ::=
1385
            ::= 
1457
            ::= 
1386
 
1458
 
1387
    ::=  <(template) unqualified-name>
1459
    ::=  <(template) unqualified-name>
1388
                     ::= 
1460
                     ::= 
1389
                     ::= 
1461
                     ::= 
1390
*/
1462
*/
1391
 
1463
 
1392
static struct demangle_component *
1464
static struct demangle_component *
1393
d_prefix (struct d_info *di)
1465
d_prefix (struct d_info *di)
1394
{
1466
{
1395
  struct demangle_component *ret = NULL;
1467
  struct demangle_component *ret = NULL;
1396
 
1468
 
1397
  while (1)
1469
  while (1)
1398
    {
1470
    {
1399
      char peek;
1471
      char peek;
1400
      enum demangle_component_type comb_type;
1472
      enum demangle_component_type comb_type;
1401
      struct demangle_component *dc;
1473
      struct demangle_component *dc;
1402
 
1474
 
1403
      peek = d_peek_char (di);
1475
      peek = d_peek_char (di);
1404
      if (peek == '\0')
1476
      if (peek == '\0')
1405
	return NULL;
1477
	return NULL;
1406
 
1478
 
1407
      /* The older code accepts a  here, but I don't see
1479
      /* The older code accepts a  here, but I don't see
1408
	 that in the grammar.  The older code does not accept a
1480
	 that in the grammar.  The older code does not accept a
1409
	  here.  */
1481
	  here.  */
1410
 
1482
 
1411
      comb_type = DEMANGLE_COMPONENT_QUAL_NAME;
1483
      comb_type = DEMANGLE_COMPONENT_QUAL_NAME;
1412
      if (peek == 'D')
1484
      if (peek == 'D')
1413
	{
1485
	{
1414
	  char peek2 = d_peek_next_char (di);
1486
	  char peek2 = d_peek_next_char (di);
1415
	  if (peek2 == 'T' || peek2 == 't')
1487
	  if (peek2 == 'T' || peek2 == 't')
1416
	    /* Decltype.  */
1488
	    /* Decltype.  */
1417
	    dc = cplus_demangle_type (di);
1489
	    dc = cplus_demangle_type (di);
1418
	  else
1490
	  else
1419
	    /* Destructor name.  */
1491
	    /* Destructor name.  */
1420
	    dc = d_unqualified_name (di);
1492
	    dc = d_unqualified_name (di);
1421
	}
1493
	}
1422
      else if (IS_DIGIT (peek)
1494
      else if (IS_DIGIT (peek)
1423
	  || IS_LOWER (peek)
1495
	  || IS_LOWER (peek)
1424
	  || peek == 'C'
1496
	  || peek == 'C'
1425
	  || peek == 'U'
1497
	  || peek == 'U'
1426
	  || peek == 'L')
1498
	  || peek == 'L')
1427
	dc = d_unqualified_name (di);
1499
	dc = d_unqualified_name (di);
1428
      else if (peek == 'S')
1500
      else if (peek == 'S')
1429
	dc = d_substitution (di, 1);
1501
	dc = d_substitution (di, 1);
1430
      else if (peek == 'I')
1502
      else if (peek == 'I')
1431
	{
1503
	{
1432
	  if (ret == NULL)
1504
	  if (ret == NULL)
1433
	    return NULL;
1505
	    return NULL;
1434
	  comb_type = DEMANGLE_COMPONENT_TEMPLATE;
1506
	  comb_type = DEMANGLE_COMPONENT_TEMPLATE;
1435
	  dc = d_template_args (di);
1507
	  dc = d_template_args (di);
1436
	}
1508
	}
1437
      else if (peek == 'T')
1509
      else if (peek == 'T')
1438
	dc = d_template_param (di);
1510
	dc = d_template_param (di);
1439
      else if (peek == 'E')
1511
      else if (peek == 'E')
1440
	return ret;
1512
	return ret;
1441
      else if (peek == 'M')
1513
      else if (peek == 'M')
1442
	{
1514
	{
1443
	  /* Initializer scope for a lambda.  We don't need to represent
1515
	  /* Initializer scope for a lambda.  We don't need to represent
1444
	     this; the normal code will just treat the variable as a type
1516
	     this; the normal code will just treat the variable as a type
1445
	     scope, which gives appropriate output.  */
1517
	     scope, which gives appropriate output.  */
1446
	  if (ret == NULL)
1518
	  if (ret == NULL)
1447
	    return NULL;
1519
	    return NULL;
1448
	  d_advance (di, 1);
1520
	  d_advance (di, 1);
1449
	  continue;
1521
	  continue;
1450
	}
1522
	}
1451
      else
1523
      else
1452
	return NULL;
1524
	return NULL;
1453
 
1525
 
1454
      if (ret == NULL)
1526
      if (ret == NULL)
1455
	ret = dc;
1527
	ret = dc;
1456
      else
1528
      else
1457
	ret = d_make_comp (di, comb_type, ret, dc);
1529
	ret = d_make_comp (di, comb_type, ret, dc);
1458
 
1530
 
1459
      if (peek != 'S' && d_peek_char (di) != 'E')
1531
      if (peek != 'S' && d_peek_char (di) != 'E')
1460
	{
1532
	{
1461
	  if (! d_add_substitution (di, ret))
1533
	  if (! d_add_substitution (di, ret))
1462
	    return NULL;
1534
	    return NULL;
1463
	}
1535
	}
1464
    }
1536
    }
1465
}
1537
}
1466
 
1538
 
1467
/*  ::= 
1539
/*  ::= 
1468
                      ::= 
1540
                      ::= 
1469
                      ::= 
1541
                      ::= 
1470
		      ::=  
1542
		      ::=  
1471
 
1543
 
1472
    	::= L  
1544
    	::= L  
1473
*/
1545
*/
1474
 
1546
 
1475
static struct demangle_component *
1547
static struct demangle_component *
1476
d_unqualified_name (struct d_info *di)
1548
d_unqualified_name (struct d_info *di)
1477
{
1549
{
1478
  struct demangle_component *ret;
1550
  struct demangle_component *ret;
1479
  char peek;
1551
  char peek;
1480
 
1552
 
1481
  peek = d_peek_char (di);
1553
  peek = d_peek_char (di);
1482
  if (IS_DIGIT (peek))
1554
  if (IS_DIGIT (peek))
1483
    ret = d_source_name (di);
1555
    ret = d_source_name (di);
1484
  else if (IS_LOWER (peek))
1556
  else if (IS_LOWER (peek))
1485
    {
1557
    {
1486
      ret = d_operator_name (di);
1558
      ret = d_operator_name (di);
1487
      if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
1559
      if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
1488
	{
1560
	{
1489
	  di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
1561
	  di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
1490
	  if (!strcmp (ret->u.s_operator.op->code, "li"))
1562
	  if (!strcmp (ret->u.s_operator.op->code, "li"))
1491
	    ret = d_make_comp (di, DEMANGLE_COMPONENT_UNARY, ret,
1563
	    ret = d_make_comp (di, DEMANGLE_COMPONENT_UNARY, ret,
1492
			       d_source_name (di));
1564
			       d_source_name (di));
1493
	}
1565
	}
1494
    }
1566
    }
1495
  else if (peek == 'C' || peek == 'D')
1567
  else if (peek == 'C' || peek == 'D')
1496
    ret = d_ctor_dtor_name (di);
1568
    ret = d_ctor_dtor_name (di);
1497
  else if (peek == 'L')
1569
  else if (peek == 'L')
1498
    {
1570
    {
1499
      d_advance (di, 1);
1571
      d_advance (di, 1);
1500
 
1572
 
1501
      ret = d_source_name (di);
1573
      ret = d_source_name (di);
1502
      if (ret == NULL)
1574
      if (ret == NULL)
1503
	return NULL;
1575
	return NULL;
1504
      if (! d_discriminator (di))
1576
      if (! d_discriminator (di))
1505
	return NULL;
1577
	return NULL;
1506
    }
1578
    }
1507
  else if (peek == 'U')
1579
  else if (peek == 'U')
1508
    {
1580
    {
1509
      switch (d_peek_next_char (di))
1581
      switch (d_peek_next_char (di))
1510
	{
1582
	{
1511
	case 'l':
1583
	case 'l':
1512
	  ret = d_lambda (di);
1584
	  ret = d_lambda (di);
1513
	  break;
1585
	  break;
1514
	case 't':
1586
	case 't':
1515
	  ret = d_unnamed_type (di);
1587
	  ret = d_unnamed_type (di);
1516
	  break;
1588
	  break;
1517
	default:
1589
	default:
1518
	  return NULL;
1590
	  return NULL;
1519
	}
1591
	}
1520
    }
1592
    }
1521
  else
1593
  else
1522
    return NULL;
1594
    return NULL;
1523
 
1595
 
1524
  if (d_peek_char (di) == 'B')
1596
  if (d_peek_char (di) == 'B')
1525
    ret = d_abi_tags (di, ret);
1597
    ret = d_abi_tags (di, ret);
1526
  return ret;
1598
  return ret;
1527
}
1599
}
1528
 
1600
 
1529
/*  ::= <(positive length) number>   */
1601
/*  ::= <(positive length) number>   */
1530
 
1602
 
1531
static struct demangle_component *
1603
static struct demangle_component *
1532
d_source_name (struct d_info *di)
1604
d_source_name (struct d_info *di)
1533
{
1605
{
1534
  long len;
1606
  long len;
1535
  struct demangle_component *ret;
1607
  struct demangle_component *ret;
1536
 
1608
 
1537
  len = d_number (di);
1609
  len = d_number (di);
1538
  if (len <= 0)
1610
  if (len <= 0)
1539
    return NULL;
1611
    return NULL;
1540
  ret = d_identifier (di, len);
1612
  ret = d_identifier (di, len);
1541
  di->last_name = ret;
1613
  di->last_name = ret;
1542
  return ret;
1614
  return ret;
1543
}
1615
}
1544
 
1616
 
1545
/* number ::= [n] <(non-negative decimal integer)>  */
1617
/* number ::= [n] <(non-negative decimal integer)>  */
1546
 
1618
 
1547
static long
1619
static long
1548
d_number (struct d_info *di)
1620
d_number (struct d_info *di)
1549
{
1621
{
1550
  int negative;
1622
  int negative;
1551
  char peek;
1623
  char peek;
1552
  long ret;
1624
  long ret;
1553
 
1625
 
1554
  negative = 0;
1626
  negative = 0;
1555
  peek = d_peek_char (di);
1627
  peek = d_peek_char (di);
1556
  if (peek == 'n')
1628
  if (peek == 'n')
1557
    {
1629
    {
1558
      negative = 1;
1630
      negative = 1;
1559
      d_advance (di, 1);
1631
      d_advance (di, 1);
1560
      peek = d_peek_char (di);
1632
      peek = d_peek_char (di);
1561
    }
1633
    }
1562
 
1634
 
1563
  ret = 0;
1635
  ret = 0;
1564
  while (1)
1636
  while (1)
1565
    {
1637
    {
1566
      if (! IS_DIGIT (peek))
1638
      if (! IS_DIGIT (peek))
1567
	{
1639
	{
1568
	  if (negative)
1640
	  if (negative)
1569
	    ret = - ret;
1641
	    ret = - ret;
1570
	  return ret;
1642
	  return ret;
1571
	}
1643
	}
1572
      ret = ret * 10 + peek - '0';
1644
      ret = ret * 10 + peek - '0';
1573
      d_advance (di, 1);
1645
      d_advance (di, 1);
1574
      peek = d_peek_char (di);
1646
      peek = d_peek_char (di);
1575
    }
1647
    }
1576
}
1648
}
1577
 
1649
 
1578
/* Like d_number, but returns a demangle_component.  */
1650
/* Like d_number, but returns a demangle_component.  */
1579
 
1651
 
1580
static struct demangle_component *
1652
static struct demangle_component *
1581
d_number_component (struct d_info *di)
1653
d_number_component (struct d_info *di)
1582
{
1654
{
1583
  struct demangle_component *ret = d_make_empty (di);
1655
  struct demangle_component *ret = d_make_empty (di);
1584
  if (ret)
1656
  if (ret)
1585
    {
1657
    {
1586
      ret->type = DEMANGLE_COMPONENT_NUMBER;
1658
      ret->type = DEMANGLE_COMPONENT_NUMBER;
1587
      ret->u.s_number.number = d_number (di);
1659
      ret->u.s_number.number = d_number (di);
1588
    }
1660
    }
1589
  return ret;
1661
  return ret;
1590
}
1662
}
1591
 
1663
 
1592
/* identifier ::= <(unqualified source code identifier)>  */
1664
/* identifier ::= <(unqualified source code identifier)>  */
1593
 
1665
 
1594
static struct demangle_component *
1666
static struct demangle_component *
1595
d_identifier (struct d_info *di, int len)
1667
d_identifier (struct d_info *di, int len)
1596
{
1668
{
1597
  const char *name;
1669
  const char *name;
1598
 
1670
 
1599
  name = d_str (di);
1671
  name = d_str (di);
1600
 
1672
 
1601
  if (di->send - name < len)
1673
  if (di->send - name < len)
1602
    return NULL;
1674
    return NULL;
1603
 
1675
 
1604
  d_advance (di, len);
1676
  d_advance (di, len);
1605
 
1677
 
1606
  /* A Java mangled name may have a trailing '$' if it is a C++
1678
  /* A Java mangled name may have a trailing '$' if it is a C++
1607
     keyword.  This '$' is not included in the length count.  We just
1679
     keyword.  This '$' is not included in the length count.  We just
1608
     ignore the '$'.  */
1680
     ignore the '$'.  */
1609
  if ((di->options & DMGL_JAVA) != 0
1681
  if ((di->options & DMGL_JAVA) != 0
1610
      && d_peek_char (di) == '$')
1682
      && d_peek_char (di) == '$')
1611
    d_advance (di, 1);
1683
    d_advance (di, 1);
1612
 
1684
 
1613
  /* Look for something which looks like a gcc encoding of an
1685
  /* Look for something which looks like a gcc encoding of an
1614
     anonymous namespace, and replace it with a more user friendly
1686
     anonymous namespace, and replace it with a more user friendly
1615
     name.  */
1687
     name.  */
1616
  if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2
1688
  if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2
1617
      && memcmp (name, ANONYMOUS_NAMESPACE_PREFIX,
1689
      && memcmp (name, ANONYMOUS_NAMESPACE_PREFIX,
1618
		 ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0)
1690
		 ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0)
1619
    {
1691
    {
1620
      const char *s;
1692
      const char *s;
1621
 
1693
 
1622
      s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN;
1694
      s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN;
1623
      if ((*s == '.' || *s == '_' || *s == '$')
1695
      if ((*s == '.' || *s == '_' || *s == '$')
1624
	  && s[1] == 'N')
1696
	  && s[1] == 'N')
1625
	{
1697
	{
1626
	  di->expansion -= len - sizeof "(anonymous namespace)";
1698
	  di->expansion -= len - sizeof "(anonymous namespace)";
1627
	  return d_make_name (di, "(anonymous namespace)",
1699
	  return d_make_name (di, "(anonymous namespace)",
1628
			      sizeof "(anonymous namespace)" - 1);
1700
			      sizeof "(anonymous namespace)" - 1);
1629
	}
1701
	}
1630
    }
1702
    }
1631
 
1703
 
1632
  return d_make_name (di, name, len);
1704
  return d_make_name (di, name, len);
1633
}
1705
}
1634
 
1706
 
1635
/* operator_name ::= many different two character encodings.
1707
/* operator_name ::= many different two character encodings.
1636
                 ::= cv 
1708
                 ::= cv 
1637
                 ::= v  
1709
                 ::= v  
1638
 
1710
 
1639
   This list is sorted for binary search.  */
1711
   This list is sorted for binary search.  */
1640
 
1712
 
1641
#define NL(s) s, (sizeof s) - 1
1713
#define NL(s) s, (sizeof s) - 1
1642
 
1714
 
1643
CP_STATIC_IF_GLIBCPP_V3
1715
CP_STATIC_IF_GLIBCPP_V3
1644
const struct demangle_operator_info cplus_demangle_operators[] =
1716
const struct demangle_operator_info cplus_demangle_operators[] =
1645
{
1717
{
1646
  { "aN", NL ("&="),        2 },
1718
  { "aN", NL ("&="),        2 },
1647
  { "aS", NL ("="),         2 },
1719
  { "aS", NL ("="),         2 },
1648
  { "aa", NL ("&&"),        2 },
1720
  { "aa", NL ("&&"),        2 },
1649
  { "ad", NL ("&"),         1 },
1721
  { "ad", NL ("&"),         1 },
1650
  { "an", NL ("&"),         2 },
1722
  { "an", NL ("&"),         2 },
1651
  { "at", NL ("alignof "),   1 },
1723
  { "at", NL ("alignof "),   1 },
1652
  { "az", NL ("alignof "),   1 },
1724
  { "az", NL ("alignof "),   1 },
1653
  { "cc", NL ("const_cast"), 2 },
1725
  { "cc", NL ("const_cast"), 2 },
1654
  { "cl", NL ("()"),        2 },
1726
  { "cl", NL ("()"),        2 },
1655
  { "cm", NL (","),         2 },
1727
  { "cm", NL (","),         2 },
1656
  { "co", NL ("~"),         1 },
1728
  { "co", NL ("~"),         1 },
1657
  { "dV", NL ("/="),        2 },
1729
  { "dV", NL ("/="),        2 },
1658
  { "da", NL ("delete[] "), 1 },
1730
  { "da", NL ("delete[] "), 1 },
1659
  { "dc", NL ("dynamic_cast"), 2 },
1731
  { "dc", NL ("dynamic_cast"), 2 },
1660
  { "de", NL ("*"),         1 },
1732
  { "de", NL ("*"),         1 },
1661
  { "dl", NL ("delete "),   1 },
1733
  { "dl", NL ("delete "),   1 },
1662
  { "ds", NL (".*"),        2 },
1734
  { "ds", NL (".*"),        2 },
1663
  { "dt", NL ("."),         2 },
1735
  { "dt", NL ("."),         2 },
1664
  { "dv", NL ("/"),         2 },
1736
  { "dv", NL ("/"),         2 },
1665
  { "eO", NL ("^="),        2 },
1737
  { "eO", NL ("^="),        2 },
1666
  { "eo", NL ("^"),         2 },
1738
  { "eo", NL ("^"),         2 },
1667
  { "eq", NL ("=="),        2 },
1739
  { "eq", NL ("=="),        2 },
1668
  { "ge", NL (">="),        2 },
1740
  { "ge", NL (">="),        2 },
1669
  { "gs", NL ("::"),	    1 },
1741
  { "gs", NL ("::"),	    1 },
1670
  { "gt", NL (">"),         2 },
1742
  { "gt", NL (">"),         2 },
1671
  { "ix", NL ("[]"),        2 },
1743
  { "ix", NL ("[]"),        2 },
1672
  { "lS", NL ("<<="),       2 },
1744
  { "lS", NL ("<<="),       2 },
1673
  { "le", NL ("<="),        2 },
1745
  { "le", NL ("<="),        2 },
1674
  { "li", NL ("operator\"\" "), 1 },
1746
  { "li", NL ("operator\"\" "), 1 },
1675
  { "ls", NL ("<<"),        2 },
1747
  { "ls", NL ("<<"),        2 },
1676
  { "lt", NL ("<"),         2 },
1748
  { "lt", NL ("<"),         2 },
1677
  { "mI", NL ("-="),        2 },
1749
  { "mI", NL ("-="),        2 },
1678
  { "mL", NL ("*="),        2 },
1750
  { "mL", NL ("*="),        2 },
1679
  { "mi", NL ("-"),         2 },
1751
  { "mi", NL ("-"),         2 },
1680
  { "ml", NL ("*"),         2 },
1752
  { "ml", NL ("*"),         2 },
1681
  { "mm", NL ("--"),        1 },
1753
  { "mm", NL ("--"),        1 },
1682
  { "na", NL ("new[]"),     3 },
1754
  { "na", NL ("new[]"),     3 },
1683
  { "ne", NL ("!="),        2 },
1755
  { "ne", NL ("!="),        2 },
1684
  { "ng", NL ("-"),         1 },
1756
  { "ng", NL ("-"),         1 },
1685
  { "nt", NL ("!"),         1 },
1757
  { "nt", NL ("!"),         1 },
1686
  { "nw", NL ("new"),       3 },
1758
  { "nw", NL ("new"),       3 },
1687
  { "oR", NL ("|="),        2 },
1759
  { "oR", NL ("|="),        2 },
1688
  { "oo", NL ("||"),        2 },
1760
  { "oo", NL ("||"),        2 },
1689
  { "or", NL ("|"),         2 },
1761
  { "or", NL ("|"),         2 },
1690
  { "pL", NL ("+="),        2 },
1762
  { "pL", NL ("+="),        2 },
1691
  { "pl", NL ("+"),         2 },
1763
  { "pl", NL ("+"),         2 },
1692
  { "pm", NL ("->*"),       2 },
1764
  { "pm", NL ("->*"),       2 },
1693
  { "pp", NL ("++"),        1 },
1765
  { "pp", NL ("++"),        1 },
1694
  { "ps", NL ("+"),         1 },
1766
  { "ps", NL ("+"),         1 },
1695
  { "pt", NL ("->"),        2 },
1767
  { "pt", NL ("->"),        2 },
1696
  { "qu", NL ("?"),         3 },
1768
  { "qu", NL ("?"),         3 },
1697
  { "rM", NL ("%="),        2 },
1769
  { "rM", NL ("%="),        2 },
1698
  { "rS", NL (">>="),       2 },
1770
  { "rS", NL (">>="),       2 },
1699
  { "rc", NL ("reinterpret_cast"), 2 },
1771
  { "rc", NL ("reinterpret_cast"), 2 },
1700
  { "rm", NL ("%"),         2 },
1772
  { "rm", NL ("%"),         2 },
1701
  { "rs", NL (">>"),        2 },
1773
  { "rs", NL (">>"),        2 },
1702
  { "sc", NL ("static_cast"), 2 },
1774
  { "sc", NL ("static_cast"), 2 },
1703
  { "st", NL ("sizeof "),   1 },
1775
  { "st", NL ("sizeof "),   1 },
1704
  { "sz", NL ("sizeof "),   1 },
1776
  { "sz", NL ("sizeof "),   1 },
1705
  { "tr", NL ("throw"),     0 },
1777
  { "tr", NL ("throw"),     0 },
1706
  { "tw", NL ("throw "),    1 },
1778
  { "tw", NL ("throw "),    1 },
1707
  { NULL, NULL, 0,          0 }
1779
  { NULL, NULL, 0,          0 }
1708
};
1780
};
1709
 
1781
 
1710
static struct demangle_component *
1782
static struct demangle_component *
1711
d_operator_name (struct d_info *di)
1783
d_operator_name (struct d_info *di)
1712
{
1784
{
1713
  char c1;
1785
  char c1;
1714
  char c2;
1786
  char c2;
1715
 
1787
 
1716
  c1 = d_next_char (di);
1788
  c1 = d_next_char (di);
1717
  c2 = d_next_char (di);
1789
  c2 = d_next_char (di);
1718
  if (c1 == 'v' && IS_DIGIT (c2))
1790
  if (c1 == 'v' && IS_DIGIT (c2))
1719
    return d_make_extended_operator (di, c2 - '0', d_source_name (di));
1791
    return d_make_extended_operator (di, c2 - '0', d_source_name (di));
1720
  else if (c1 == 'c' && c2 == 'v')
1792
  else if (c1 == 'c' && c2 == 'v')
-
 
1793
    {
-
 
1794
      struct demangle_component *type;
1721
    return d_make_comp (di, DEMANGLE_COMPONENT_CAST,
1795
      int was_conversion = di->is_conversion;
-
 
1796
 
-
 
1797
      di->is_conversion = ! di->is_expression;
1722
			cplus_demangle_type (di), NULL);
1798
      type = cplus_demangle_type (di);
-
 
1799
      di->is_conversion = was_conversion;
-
 
1800
      return d_make_comp (di, DEMANGLE_COMPONENT_CAST, type, NULL);
-
 
1801
    }
1723
  else
1802
  else
1724
    {
1803
    {
1725
      /* LOW is the inclusive lower bound.  */
1804
      /* LOW is the inclusive lower bound.  */
1726
      int low = 0;
1805
      int low = 0;
1727
      /* HIGH is the exclusive upper bound.  We subtract one to ignore
1806
      /* HIGH is the exclusive upper bound.  We subtract one to ignore
1728
	 the sentinel at the end of the array.  */
1807
	 the sentinel at the end of the array.  */
1729
      int high = ((sizeof (cplus_demangle_operators)
1808
      int high = ((sizeof (cplus_demangle_operators)
1730
		   / sizeof (cplus_demangle_operators[0]))
1809
		   / sizeof (cplus_demangle_operators[0]))
1731
		  - 1);
1810
		  - 1);
1732
 
1811
 
1733
      while (1)
1812
      while (1)
1734
	{
1813
	{
1735
	  int i;
1814
	  int i;
1736
	  const struct demangle_operator_info *p;
1815
	  const struct demangle_operator_info *p;
1737
 
1816
 
1738
	  i = low + (high - low) / 2;
1817
	  i = low + (high - low) / 2;
1739
	  p = cplus_demangle_operators + i;
1818
	  p = cplus_demangle_operators + i;
1740
 
1819
 
1741
	  if (c1 == p->code[0] && c2 == p->code[1])
1820
	  if (c1 == p->code[0] && c2 == p->code[1])
1742
	    return d_make_operator (di, p);
1821
	    return d_make_operator (di, p);
1743
 
1822
 
1744
	  if (c1 < p->code[0] || (c1 == p->code[0] && c2 < p->code[1]))
1823
	  if (c1 < p->code[0] || (c1 == p->code[0] && c2 < p->code[1]))
1745
	    high = i;
1824
	    high = i;
1746
	  else
1825
	  else
1747
	    low = i + 1;
1826
	    low = i + 1;
1748
	  if (low == high)
1827
	  if (low == high)
1749
	    return NULL;
1828
	    return NULL;
1750
	}
1829
	}
1751
    }
1830
    }
1752
}
1831
}
1753
 
1832
 
1754
static struct demangle_component *
1833
static struct demangle_component *
1755
d_make_character (struct d_info *di, int c)
1834
d_make_character (struct d_info *di, int c)
1756
{
1835
{
1757
  struct demangle_component *p;
1836
  struct demangle_component *p;
1758
  p = d_make_empty (di);
1837
  p = d_make_empty (di);
1759
  if (p != NULL)
1838
  if (p != NULL)
1760
    {
1839
    {
1761
      p->type = DEMANGLE_COMPONENT_CHARACTER;
1840
      p->type = DEMANGLE_COMPONENT_CHARACTER;
1762
      p->u.s_character.character = c;
1841
      p->u.s_character.character = c;
1763
    }
1842
    }
1764
  return p;
1843
  return p;
1765
}
1844
}
1766
 
1845
 
1767
static struct demangle_component *
1846
static struct demangle_component *
1768
d_java_resource (struct d_info *di)
1847
d_java_resource (struct d_info *di)
1769
{
1848
{
1770
  struct demangle_component *p = NULL;
1849
  struct demangle_component *p = NULL;
1771
  struct demangle_component *next = NULL;
1850
  struct demangle_component *next = NULL;
1772
  long len, i;
1851
  long len, i;
1773
  char c;
1852
  char c;
1774
  const char *str;
1853
  const char *str;
1775
 
1854
 
1776
  len = d_number (di);
1855
  len = d_number (di);
1777
  if (len <= 1)
1856
  if (len <= 1)
1778
    return NULL;
1857
    return NULL;
1779
 
1858
 
1780
  /* Eat the leading '_'.  */
1859
  /* Eat the leading '_'.  */
1781
  if (d_next_char (di) != '_')
1860
  if (d_next_char (di) != '_')
1782
    return NULL;
1861
    return NULL;
1783
  len--;
1862
  len--;
1784
 
1863
 
1785
  str = d_str (di);
1864
  str = d_str (di);
1786
  i = 0;
1865
  i = 0;
1787
 
1866
 
1788
  while (len > 0)
1867
  while (len > 0)
1789
    {
1868
    {
1790
      c = str[i];
1869
      c = str[i];
1791
      if (!c)
1870
      if (!c)
1792
	return NULL;
1871
	return NULL;
1793
 
1872
 
1794
      /* Each chunk is either a '$' escape...  */
1873
      /* Each chunk is either a '$' escape...  */
1795
      if (c == '$')
1874
      if (c == '$')
1796
	{
1875
	{
1797
	  i++;
1876
	  i++;
1798
	  switch (str[i++])
1877
	  switch (str[i++])
1799
	    {
1878
	    {
1800
	    case 'S':
1879
	    case 'S':
1801
	      c = '/';
1880
	      c = '/';
1802
	      break;
1881
	      break;
1803
	    case '_':
1882
	    case '_':
1804
	      c = '.';
1883
	      c = '.';
1805
	      break;
1884
	      break;
1806
	    case '$':
1885
	    case '$':
1807
	      c = '$';
1886
	      c = '$';
1808
	      break;
1887
	      break;
1809
	    default:
1888
	    default:
1810
	      return NULL;
1889
	      return NULL;
1811
	    }
1890
	    }
1812
	  next = d_make_character (di, c);
1891
	  next = d_make_character (di, c);
1813
	  d_advance (di, i);
1892
	  d_advance (di, i);
1814
	  str = d_str (di);
1893
	  str = d_str (di);
1815
	  len -= i;
1894
	  len -= i;
1816
	  i = 0;
1895
	  i = 0;
1817
	  if (next == NULL)
1896
	  if (next == NULL)
1818
	    return NULL;
1897
	    return NULL;
1819
	}
1898
	}
1820
      /* ... or a sequence of characters.  */
1899
      /* ... or a sequence of characters.  */
1821
      else
1900
      else
1822
	{
1901
	{
1823
	  while (i < len && str[i] && str[i] != '$')
1902
	  while (i < len && str[i] && str[i] != '$')
1824
	    i++;
1903
	    i++;
1825
 
1904
 
1826
	  next = d_make_name (di, str, i);
1905
	  next = d_make_name (di, str, i);
1827
	  d_advance (di, i);
1906
	  d_advance (di, i);
1828
	  str = d_str (di);
1907
	  str = d_str (di);
1829
	  len -= i;
1908
	  len -= i;
1830
	  i = 0;
1909
	  i = 0;
1831
	  if (next == NULL)
1910
	  if (next == NULL)
1832
	    return NULL;
1911
	    return NULL;
1833
	}
1912
	}
1834
 
1913
 
1835
      if (p == NULL)
1914
      if (p == NULL)
1836
	p = next;
1915
	p = next;
1837
      else
1916
      else
1838
	{
1917
	{
1839
	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
1918
	  p = d_make_comp (di, DEMANGLE_COMPONENT_COMPOUND_NAME, p, next);
1840
	  if (p == NULL)
1919
	  if (p == NULL)
1841
	    return NULL;
1920
	    return NULL;
1842
	}
1921
	}
1843
    }
1922
    }
1844
 
1923
 
1845
  p = d_make_comp (di, DEMANGLE_COMPONENT_JAVA_RESOURCE, p, NULL);
1924
  p = d_make_comp (di, DEMANGLE_COMPONENT_JAVA_RESOURCE, p, NULL);
1846
 
1925
 
1847
  return p;
1926
  return p;
1848
}
1927
}
1849
 
1928
 
1850
/*  ::= TV 
1929
/*  ::= TV 
1851
                  ::= TT 
1930
                  ::= TT 
1852
                  ::= TI 
1931
                  ::= TI 
1853
                  ::= TS 
1932
                  ::= TS 
1854
                  ::= GV <(object) name>
1933
                  ::= GV <(object) name>
1855
                  ::= T  <(base) encoding>
1934
                  ::= T  <(base) encoding>
1856
                  ::= Tc   <(base) encoding>
1935
                  ::= Tc   <(base) encoding>
1857
   Also g++ extensions:
1936
   Also g++ extensions:
1858
                  ::= TC  <(offset) number> _ <(base) type>
1937
                  ::= TC  <(offset) number> _ <(base) type>
1859
                  ::= TF 
1938
                  ::= TF 
1860
                  ::= TJ 
1939
                  ::= TJ 
1861
                  ::= GR 
1940
                  ::= GR 
1862
		  ::= GA 
1941
		  ::= GA 
1863
		  ::= Gr 
1942
		  ::= Gr 
1864
		  ::= GTt 
1943
		  ::= GTt 
1865
		  ::= GTn 
1944
		  ::= GTn 
1866
*/
1945
*/
1867
 
1946
 
1868
static struct demangle_component *
1947
static struct demangle_component *
1869
d_special_name (struct d_info *di)
1948
d_special_name (struct d_info *di)
1870
{
1949
{
1871
  di->expansion += 20;
1950
  di->expansion += 20;
1872
  if (d_check_char (di, 'T'))
1951
  if (d_check_char (di, 'T'))
1873
    {
1952
    {
1874
      switch (d_next_char (di))
1953
      switch (d_next_char (di))
1875
	{
1954
	{
1876
	case 'V':
1955
	case 'V':
1877
	  di->expansion -= 5;
1956
	  di->expansion -= 5;
1878
	  return d_make_comp (di, DEMANGLE_COMPONENT_VTABLE,
1957
	  return d_make_comp (di, DEMANGLE_COMPONENT_VTABLE,
1879
			      cplus_demangle_type (di), NULL);
1958
			      cplus_demangle_type (di), NULL);
1880
	case 'T':
1959
	case 'T':
1881
	  di->expansion -= 10;
1960
	  di->expansion -= 10;
1882
	  return d_make_comp (di, DEMANGLE_COMPONENT_VTT,
1961
	  return d_make_comp (di, DEMANGLE_COMPONENT_VTT,
1883
			      cplus_demangle_type (di), NULL);
1962
			      cplus_demangle_type (di), NULL);
1884
	case 'I':
1963
	case 'I':
1885
	  return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO,
1964
	  return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO,
1886
			      cplus_demangle_type (di), NULL);
1965
			      cplus_demangle_type (di), NULL);
1887
	case 'S':
1966
	case 'S':
1888
	  return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_NAME,
1967
	  return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_NAME,
1889
			      cplus_demangle_type (di), NULL);
1968
			      cplus_demangle_type (di), NULL);
1890
 
1969
 
1891
	case 'h':
1970
	case 'h':
1892
	  if (! d_call_offset (di, 'h'))
1971
	  if (! d_call_offset (di, 'h'))
1893
	    return NULL;
1972
	    return NULL;
1894
	  return d_make_comp (di, DEMANGLE_COMPONENT_THUNK,
1973
	  return d_make_comp (di, DEMANGLE_COMPONENT_THUNK,
1895
			      d_encoding (di, 0), NULL);
1974
			      d_encoding (di, 0), NULL);
1896
 
1975
 
1897
	case 'v':
1976
	case 'v':
1898
	  if (! d_call_offset (di, 'v'))
1977
	  if (! d_call_offset (di, 'v'))
1899
	    return NULL;
1978
	    return NULL;
1900
	  return d_make_comp (di, DEMANGLE_COMPONENT_VIRTUAL_THUNK,
1979
	  return d_make_comp (di, DEMANGLE_COMPONENT_VIRTUAL_THUNK,
1901
			      d_encoding (di, 0), NULL);
1980
			      d_encoding (di, 0), NULL);
1902
 
1981
 
1903
	case 'c':
1982
	case 'c':
1904
	  if (! d_call_offset (di, '\0'))
1983
	  if (! d_call_offset (di, '\0'))
1905
	    return NULL;
1984
	    return NULL;
1906
	  if (! d_call_offset (di, '\0'))
1985
	  if (! d_call_offset (di, '\0'))
1907
	    return NULL;
1986
	    return NULL;
1908
	  return d_make_comp (di, DEMANGLE_COMPONENT_COVARIANT_THUNK,
1987
	  return d_make_comp (di, DEMANGLE_COMPONENT_COVARIANT_THUNK,
1909
			      d_encoding (di, 0), NULL);
1988
			      d_encoding (di, 0), NULL);
1910
 
1989
 
1911
	case 'C':
1990
	case 'C':
1912
	  {
1991
	  {
1913
	    struct demangle_component *derived_type;
1992
	    struct demangle_component *derived_type;
1914
	    long offset;
1993
	    long offset;
1915
	    struct demangle_component *base_type;
1994
	    struct demangle_component *base_type;
1916
 
1995
 
1917
	    derived_type = cplus_demangle_type (di);
1996
	    derived_type = cplus_demangle_type (di);
1918
	    offset = d_number (di);
1997
	    offset = d_number (di);
1919
	    if (offset < 0)
1998
	    if (offset < 0)
1920
	      return NULL;
1999
	      return NULL;
1921
	    if (! d_check_char (di, '_'))
2000
	    if (! d_check_char (di, '_'))
1922
	      return NULL;
2001
	      return NULL;
1923
	    base_type = cplus_demangle_type (di);
2002
	    base_type = cplus_demangle_type (di);
1924
	    /* We don't display the offset.  FIXME: We should display
2003
	    /* We don't display the offset.  FIXME: We should display
1925
	       it in verbose mode.  */
2004
	       it in verbose mode.  */
1926
	    di->expansion += 5;
2005
	    di->expansion += 5;
1927
	    return d_make_comp (di, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
2006
	    return d_make_comp (di, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE,
1928
				base_type, derived_type);
2007
				base_type, derived_type);
1929
	  }
2008
	  }
1930
 
2009
 
1931
	case 'F':
2010
	case 'F':
1932
	  return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_FN,
2011
	  return d_make_comp (di, DEMANGLE_COMPONENT_TYPEINFO_FN,
1933
			      cplus_demangle_type (di), NULL);
2012
			      cplus_demangle_type (di), NULL);
1934
	case 'J':
2013
	case 'J':
1935
	  return d_make_comp (di, DEMANGLE_COMPONENT_JAVA_CLASS,
2014
	  return d_make_comp (di, DEMANGLE_COMPONENT_JAVA_CLASS,
1936
			      cplus_demangle_type (di), NULL);
2015
			      cplus_demangle_type (di), NULL);
1937
 
2016
 
1938
	case 'H':
2017
	case 'H':
1939
	  return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT,
2018
	  return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT,
1940
			      d_name (di), NULL);
2019
			      d_name (di), NULL);
1941
 
2020
 
1942
	case 'W':
2021
	case 'W':
1943
	  return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER,
2022
	  return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER,
1944
			      d_name (di), NULL);
2023
			      d_name (di), NULL);
1945
 
2024
 
1946
	default:
2025
	default:
1947
	  return NULL;
2026
	  return NULL;
1948
	}
2027
	}
1949
    }
2028
    }
1950
  else if (d_check_char (di, 'G'))
2029
  else if (d_check_char (di, 'G'))
1951
    {
2030
    {
1952
      switch (d_next_char (di))
2031
      switch (d_next_char (di))
1953
	{
2032
	{
1954
	case 'V':
2033
	case 'V':
1955
	  return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL);
2034
	  return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL);
1956
 
2035
 
1957
	case 'R':
2036
	case 'R':
1958
	  {
2037
	  {
1959
	    struct demangle_component *name = d_name (di);
2038
	    struct demangle_component *name = d_name (di);
1960
	    return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name,
2039
	    return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name,
1961
				d_number_component (di));
2040
				d_number_component (di));
1962
	  }
2041
	  }
1963
 
2042
 
1964
	case 'A':
2043
	case 'A':
1965
	  return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
2044
	  return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
1966
			      d_encoding (di, 0), NULL);
2045
			      d_encoding (di, 0), NULL);
1967
 
2046
 
1968
	case 'T':
2047
	case 'T':
1969
	  switch (d_next_char (di))
2048
	  switch (d_next_char (di))
1970
	    {
2049
	    {
1971
	    case 'n':
2050
	    case 'n':
1972
	      return d_make_comp (di, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
2051
	      return d_make_comp (di, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE,
1973
				  d_encoding (di, 0), NULL);
2052
				  d_encoding (di, 0), NULL);
1974
	    default:
2053
	    default:
1975
	      /* ??? The proposal is that other letters (such as 'h') stand
2054
	      /* ??? The proposal is that other letters (such as 'h') stand
1976
		 for different variants of transaction cloning, such as
2055
		 for different variants of transaction cloning, such as
1977
		 compiling directly for hardware transaction support.  But
2056
		 compiling directly for hardware transaction support.  But
1978
		 they still should all be transactional clones of some sort
2057
		 they still should all be transactional clones of some sort
1979
		 so go ahead and call them that.  */
2058
		 so go ahead and call them that.  */
1980
	    case 't':
2059
	    case 't':
1981
	      return d_make_comp (di, DEMANGLE_COMPONENT_TRANSACTION_CLONE,
2060
	      return d_make_comp (di, DEMANGLE_COMPONENT_TRANSACTION_CLONE,
1982
				  d_encoding (di, 0), NULL);
2061
				  d_encoding (di, 0), NULL);
1983
	    }
2062
	    }
1984
 
2063
 
1985
	case 'r':
2064
	case 'r':
1986
	  return d_java_resource (di);
2065
	  return d_java_resource (di);
1987
 
2066
 
1988
	default:
2067
	default:
1989
	  return NULL;
2068
	  return NULL;
1990
	}
2069
	}
1991
    }
2070
    }
1992
  else
2071
  else
1993
    return NULL;
2072
    return NULL;
1994
}
2073
}
1995
 
2074
 
1996
/*  ::= h  _
2075
/*  ::= h  _
1997
                 ::= v  _
2076
                 ::= v  _
1998
 
2077
 
1999
    ::= <(offset) number>
2078
    ::= <(offset) number>
2000
 
2079
 
2001
    ::= <(offset) number> _ <(virtual offset) number>
2080
    ::= <(offset) number> _ <(virtual offset) number>
2002
 
2081
 
2003
   The C parameter, if not '\0', is a character we just read which is
2082
   The C parameter, if not '\0', is a character we just read which is
2004
   the start of the .
2083
   the start of the .
2005
 
2084
 
2006
   We don't display the offset information anywhere.  FIXME: We should
2085
   We don't display the offset information anywhere.  FIXME: We should
2007
   display it in verbose mode.  */
2086
   display it in verbose mode.  */
2008
 
2087
 
2009
static int
2088
static int
2010
d_call_offset (struct d_info *di, int c)
2089
d_call_offset (struct d_info *di, int c)
2011
{
2090
{
2012
  if (c == '\0')
2091
  if (c == '\0')
2013
    c = d_next_char (di);
2092
    c = d_next_char (di);
2014
 
2093
 
2015
  if (c == 'h')
2094
  if (c == 'h')
2016
    d_number (di);
2095
    d_number (di);
2017
  else if (c == 'v')
2096
  else if (c == 'v')
2018
    {
2097
    {
2019
      d_number (di);
2098
      d_number (di);
2020
      if (! d_check_char (di, '_'))
2099
      if (! d_check_char (di, '_'))
2021
	return 0;
2100
	return 0;
2022
      d_number (di);
2101
      d_number (di);
2023
    }
2102
    }
2024
  else
2103
  else
2025
    return 0;
2104
    return 0;
2026
 
2105
 
2027
  if (! d_check_char (di, '_'))
2106
  if (! d_check_char (di, '_'))
2028
    return 0;
2107
    return 0;
2029
 
2108
 
2030
  return 1;
2109
  return 1;
2031
}
2110
}
2032
 
2111
 
2033
/*  ::= C1
2112
/*  ::= C1
2034
                    ::= C2
2113
                    ::= C2
2035
                    ::= C3
2114
                    ::= C3
2036
                    ::= D0
2115
                    ::= D0
2037
                    ::= D1
2116
                    ::= D1
2038
                    ::= D2
2117
                    ::= D2
2039
*/
2118
*/
2040
 
2119
 
2041
static struct demangle_component *
2120
static struct demangle_component *
2042
d_ctor_dtor_name (struct d_info *di)
2121
d_ctor_dtor_name (struct d_info *di)
2043
{
2122
{
2044
  if (di->last_name != NULL)
2123
  if (di->last_name != NULL)
2045
    {
2124
    {
2046
      if (di->last_name->type == DEMANGLE_COMPONENT_NAME)
2125
      if (di->last_name->type == DEMANGLE_COMPONENT_NAME)
2047
	di->expansion += di->last_name->u.s_name.len;
2126
	di->expansion += di->last_name->u.s_name.len;
2048
      else if (di->last_name->type == DEMANGLE_COMPONENT_SUB_STD)
2127
      else if (di->last_name->type == DEMANGLE_COMPONENT_SUB_STD)
2049
	di->expansion += di->last_name->u.s_string.len;
2128
	di->expansion += di->last_name->u.s_string.len;
2050
    }
2129
    }
2051
  switch (d_peek_char (di))
2130
  switch (d_peek_char (di))
2052
    {
2131
    {
2053
    case 'C':
2132
    case 'C':
2054
      {
2133
      {
2055
	enum gnu_v3_ctor_kinds kind;
2134
	enum gnu_v3_ctor_kinds kind;
2056
 
2135
 
2057
	switch (d_peek_next_char (di))
2136
	switch (d_peek_next_char (di))
2058
	  {
2137
	  {
2059
	  case '1':
2138
	  case '1':
2060
	    kind = gnu_v3_complete_object_ctor;
2139
	    kind = gnu_v3_complete_object_ctor;
2061
	    break;
2140
	    break;
2062
	  case '2':
2141
	  case '2':
2063
	    kind = gnu_v3_base_object_ctor;
2142
	    kind = gnu_v3_base_object_ctor;
2064
	    break;
2143
	    break;
2065
	  case '3':
2144
	  case '3':
2066
	    kind = gnu_v3_complete_object_allocating_ctor;
2145
	    kind = gnu_v3_complete_object_allocating_ctor;
2067
	    break;
2146
	    break;
-
 
2147
          case '4':
-
 
2148
	    kind = gnu_v3_unified_ctor;
-
 
2149
	    break;
2068
	  case '5':
2150
	  case '5':
2069
	    kind = gnu_v3_object_ctor_group;
2151
	    kind = gnu_v3_object_ctor_group;
2070
	    break;
2152
	    break;
2071
	  default:
2153
	  default:
2072
	    return NULL;
2154
	    return NULL;
2073
	  }
2155
	  }
2074
	d_advance (di, 2);
2156
	d_advance (di, 2);
2075
	return d_make_ctor (di, kind, di->last_name);
2157
	return d_make_ctor (di, kind, di->last_name);
2076
      }
2158
      }
2077
 
2159
 
2078
    case 'D':
2160
    case 'D':
2079
      {
2161
      {
2080
	enum gnu_v3_dtor_kinds kind;
2162
	enum gnu_v3_dtor_kinds kind;
2081
 
2163
 
2082
	switch (d_peek_next_char (di))
2164
	switch (d_peek_next_char (di))
2083
	  {
2165
	  {
2084
	  case '0':
2166
	  case '0':
2085
	    kind = gnu_v3_deleting_dtor;
2167
	    kind = gnu_v3_deleting_dtor;
2086
	    break;
2168
	    break;
2087
	  case '1':
2169
	  case '1':
2088
	    kind = gnu_v3_complete_object_dtor;
2170
	    kind = gnu_v3_complete_object_dtor;
2089
	    break;
2171
	    break;
2090
	  case '2':
2172
	  case '2':
2091
	    kind = gnu_v3_base_object_dtor;
2173
	    kind = gnu_v3_base_object_dtor;
2092
	    break;
2174
	    break;
-
 
2175
          /*  digit '3' is not used */
-
 
2176
	  case '4':
-
 
2177
	    kind = gnu_v3_unified_dtor;
-
 
2178
	    break;
2093
	  case '5':
2179
	  case '5':
2094
	    kind = gnu_v3_object_dtor_group;
2180
	    kind = gnu_v3_object_dtor_group;
2095
	    break;
2181
	    break;
2096
	  default:
2182
	  default:
2097
	    return NULL;
2183
	    return NULL;
2098
	  }
2184
	  }
2099
	d_advance (di, 2);
2185
	d_advance (di, 2);
2100
	return d_make_dtor (di, kind, di->last_name);
2186
	return d_make_dtor (di, kind, di->last_name);
2101
      }
2187
      }
2102
 
2188
 
2103
    default:
2189
    default:
2104
      return NULL;
2190
      return NULL;
2105
    }
2191
    }
2106
}
2192
}
2107
 
2193
 
2108
/*  ::= 
2194
/*  ::= 
2109
          ::= 
2195
          ::= 
2110
          ::= 
2196
          ::= 
2111
          ::= 
2197
          ::= 
2112
          ::= 
2198
          ::= 
2113
          ::= 
2199
          ::= 
2114
          ::=  
2200
          ::=  
2115
          ::= 
2201
          ::= 
2116
          ::=  
2202
          ::=  
2117
          ::= P 
2203
          ::= P 
2118
          ::= R 
2204
          ::= R 
2119
          ::= O  (C++0x)
2205
          ::= O  (C++0x)
2120
          ::= C 
2206
          ::= C 
2121
          ::= G 
2207
          ::= G 
2122
          ::= U  
2208
          ::= U  
2123
 
2209
 
2124
    ::= various one letter codes
2210
    ::= various one letter codes
2125
                  ::= u 
2211
                  ::= u 
2126
*/
2212
*/
2127
 
2213
 
2128
CP_STATIC_IF_GLIBCPP_V3
2214
CP_STATIC_IF_GLIBCPP_V3
2129
const struct demangle_builtin_type_info
2215
const struct demangle_builtin_type_info
2130
cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
2216
cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
2131
{
2217
{
2132
  /* a */ { NL ("signed char"),	NL ("signed char"),	D_PRINT_DEFAULT },
2218
  /* a */ { NL ("signed char"),	NL ("signed char"),	D_PRINT_DEFAULT },
2133
  /* b */ { NL ("bool"),	NL ("boolean"),		D_PRINT_BOOL },
2219
  /* b */ { NL ("bool"),	NL ("boolean"),		D_PRINT_BOOL },
2134
  /* c */ { NL ("char"),	NL ("byte"),		D_PRINT_DEFAULT },
2220
  /* c */ { NL ("char"),	NL ("byte"),		D_PRINT_DEFAULT },
2135
  /* d */ { NL ("double"),	NL ("double"),		D_PRINT_FLOAT },
2221
  /* d */ { NL ("double"),	NL ("double"),		D_PRINT_FLOAT },
2136
  /* e */ { NL ("long double"),	NL ("long double"),	D_PRINT_FLOAT },
2222
  /* e */ { NL ("long double"),	NL ("long double"),	D_PRINT_FLOAT },
2137
  /* f */ { NL ("float"),	NL ("float"),		D_PRINT_FLOAT },
2223
  /* f */ { NL ("float"),	NL ("float"),		D_PRINT_FLOAT },
2138
  /* g */ { NL ("__float128"),	NL ("__float128"),	D_PRINT_FLOAT },
2224
  /* g */ { NL ("__float128"),	NL ("__float128"),	D_PRINT_FLOAT },
2139
  /* h */ { NL ("unsigned char"), NL ("unsigned char"),	D_PRINT_DEFAULT },
2225
  /* h */ { NL ("unsigned char"), NL ("unsigned char"),	D_PRINT_DEFAULT },
2140
  /* i */ { NL ("int"),		NL ("int"),		D_PRINT_INT },
2226
  /* i */ { NL ("int"),		NL ("int"),		D_PRINT_INT },
2141
  /* j */ { NL ("unsigned int"), NL ("unsigned"),	D_PRINT_UNSIGNED },
2227
  /* j */ { NL ("unsigned int"), NL ("unsigned"),	D_PRINT_UNSIGNED },
2142
  /* k */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2228
  /* k */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2143
  /* l */ { NL ("long"),	NL ("long"),		D_PRINT_LONG },
2229
  /* l */ { NL ("long"),	NL ("long"),		D_PRINT_LONG },
2144
  /* m */ { NL ("unsigned long"), NL ("unsigned long"),	D_PRINT_UNSIGNED_LONG },
2230
  /* m */ { NL ("unsigned long"), NL ("unsigned long"),	D_PRINT_UNSIGNED_LONG },
2145
  /* n */ { NL ("__int128"),	NL ("__int128"),	D_PRINT_DEFAULT },
2231
  /* n */ { NL ("__int128"),	NL ("__int128"),	D_PRINT_DEFAULT },
2146
  /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2232
  /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2147
	    D_PRINT_DEFAULT },
2233
	    D_PRINT_DEFAULT },
2148
  /* p */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2234
  /* p */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2149
  /* q */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2235
  /* q */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2150
  /* r */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2236
  /* r */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2151
  /* s */ { NL ("short"),	NL ("short"),		D_PRINT_DEFAULT },
2237
  /* s */ { NL ("short"),	NL ("short"),		D_PRINT_DEFAULT },
2152
  /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT },
2238
  /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT },
2153
  /* u */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2239
  /* u */ { NULL, 0,		NULL, 0,		D_PRINT_DEFAULT },
2154
  /* v */ { NL ("void"),	NL ("void"),		D_PRINT_VOID },
2240
  /* v */ { NL ("void"),	NL ("void"),		D_PRINT_VOID },
2155
  /* w */ { NL ("wchar_t"),	NL ("char"),		D_PRINT_DEFAULT },
2241
  /* w */ { NL ("wchar_t"),	NL ("char"),		D_PRINT_DEFAULT },
2156
  /* x */ { NL ("long long"),	NL ("long"),		D_PRINT_LONG_LONG },
2242
  /* x */ { NL ("long long"),	NL ("long"),		D_PRINT_LONG_LONG },
2157
  /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2243
  /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2158
	    D_PRINT_UNSIGNED_LONG_LONG },
2244
	    D_PRINT_UNSIGNED_LONG_LONG },
2159
  /* z */ { NL ("..."),		NL ("..."),		D_PRINT_DEFAULT },
2245
  /* z */ { NL ("..."),		NL ("..."),		D_PRINT_DEFAULT },
2160
  /* 26 */ { NL ("decimal32"),	NL ("decimal32"),	D_PRINT_DEFAULT },
2246
  /* 26 */ { NL ("decimal32"),	NL ("decimal32"),	D_PRINT_DEFAULT },
2161
  /* 27 */ { NL ("decimal64"),	NL ("decimal64"),	D_PRINT_DEFAULT },
2247
  /* 27 */ { NL ("decimal64"),	NL ("decimal64"),	D_PRINT_DEFAULT },
2162
  /* 28 */ { NL ("decimal128"),	NL ("decimal128"),	D_PRINT_DEFAULT },
2248
  /* 28 */ { NL ("decimal128"),	NL ("decimal128"),	D_PRINT_DEFAULT },
2163
  /* 29 */ { NL ("half"),	NL ("half"),		D_PRINT_FLOAT },
2249
  /* 29 */ { NL ("half"),	NL ("half"),		D_PRINT_FLOAT },
2164
  /* 30 */ { NL ("char16_t"),	NL ("char16_t"),	D_PRINT_DEFAULT },
2250
  /* 30 */ { NL ("char16_t"),	NL ("char16_t"),	D_PRINT_DEFAULT },
2165
  /* 31 */ { NL ("char32_t"),	NL ("char32_t"),	D_PRINT_DEFAULT },
2251
  /* 31 */ { NL ("char32_t"),	NL ("char32_t"),	D_PRINT_DEFAULT },
2166
  /* 32 */ { NL ("decltype(nullptr)"),	NL ("decltype(nullptr)"),
2252
  /* 32 */ { NL ("decltype(nullptr)"),	NL ("decltype(nullptr)"),
2167
	     D_PRINT_DEFAULT },
2253
	     D_PRINT_DEFAULT },
2168
};
2254
};
2169
 
2255
 
2170
CP_STATIC_IF_GLIBCPP_V3
2256
CP_STATIC_IF_GLIBCPP_V3
2171
struct demangle_component *
2257
struct demangle_component *
2172
cplus_demangle_type (struct d_info *di)
2258
cplus_demangle_type (struct d_info *di)
2173
{
2259
{
2174
  char peek;
2260
  char peek;
2175
  struct demangle_component *ret;
2261
  struct demangle_component *ret;
2176
  int can_subst;
2262
  int can_subst;
2177
 
2263
 
2178
  /* The ABI specifies that when CV-qualifiers are used, the base type
2264
  /* The ABI specifies that when CV-qualifiers are used, the base type
2179
     is substitutable, and the fully qualified type is substitutable,
2265
     is substitutable, and the fully qualified type is substitutable,
2180
     but the base type with a strict subset of the CV-qualifiers is
2266
     but the base type with a strict subset of the CV-qualifiers is
2181
     not substitutable.  The natural recursive implementation of the
2267
     not substitutable.  The natural recursive implementation of the
2182
     CV-qualifiers would cause subsets to be substitutable, so instead
2268
     CV-qualifiers would cause subsets to be substitutable, so instead
2183
     we pull them all off now.
2269
     we pull them all off now.
2184
 
2270
 
2185
     FIXME: The ABI says that order-insensitive vendor qualifiers
2271
     FIXME: The ABI says that order-insensitive vendor qualifiers
2186
     should be handled in the same way, but we have no way to tell
2272
     should be handled in the same way, but we have no way to tell
2187
     which vendor qualifiers are order-insensitive and which are
2273
     which vendor qualifiers are order-insensitive and which are
2188
     order-sensitive.  So we just assume that they are all
2274
     order-sensitive.  So we just assume that they are all
2189
     order-sensitive.  g++ 3.4 supports only one vendor qualifier,
2275
     order-sensitive.  g++ 3.4 supports only one vendor qualifier,
2190
     __vector, and it treats it as order-sensitive when mangling
2276
     __vector, and it treats it as order-sensitive when mangling
2191
     names.  */
2277
     names.  */
2192
 
2278
 
2193
  peek = d_peek_char (di);
2279
  peek = d_peek_char (di);
2194
  if (peek == 'r' || peek == 'V' || peek == 'K')
2280
  if (peek == 'r' || peek == 'V' || peek == 'K')
2195
    {
2281
    {
2196
      struct demangle_component **pret;
2282
      struct demangle_component **pret;
2197
 
2283
 
2198
      pret = d_cv_qualifiers (di, &ret, 0);
2284
      pret = d_cv_qualifiers (di, &ret, 0);
2199
      if (pret == NULL)
2285
      if (pret == NULL)
2200
	return NULL;
2286
	return NULL;
2201
      if (d_peek_char (di) == 'F')
2287
      if (d_peek_char (di) == 'F')
2202
	{
2288
	{
2203
	  /* cv-qualifiers before a function type apply to 'this',
2289
	  /* cv-qualifiers before a function type apply to 'this',
2204
	     so avoid adding the unqualified function type to
2290
	     so avoid adding the unqualified function type to
2205
	     the substitution list.  */
2291
	     the substitution list.  */
2206
	  *pret = d_function_type (di);
2292
	  *pret = d_function_type (di);
2207
	}
2293
	}
2208
      else
2294
      else
2209
	*pret = cplus_demangle_type (di);
2295
	*pret = cplus_demangle_type (di);
2210
      if (!*pret)
2296
      if (!*pret)
2211
	return NULL;
2297
	return NULL;
2212
      if ((*pret)->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2298
      if ((*pret)->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2213
	  || (*pret)->type == DEMANGLE_COMPONENT_REFERENCE_THIS)
2299
	  || (*pret)->type == DEMANGLE_COMPONENT_REFERENCE_THIS)
2214
	{
2300
	{
2215
	  /* Move the ref-qualifier outside the cv-qualifiers so that
2301
	  /* Move the ref-qualifier outside the cv-qualifiers so that
2216
	     they are printed in the right order.  */
2302
	     they are printed in the right order.  */
2217
	  struct demangle_component *fn = d_left (*pret);
2303
	  struct demangle_component *fn = d_left (*pret);
2218
	  d_left (*pret) = ret;
2304
	  d_left (*pret) = ret;
2219
	  ret = *pret;
2305
	  ret = *pret;
2220
	  *pret = fn;
2306
	  *pret = fn;
2221
	}
2307
	}
2222
      if (! d_add_substitution (di, ret))
2308
      if (! d_add_substitution (di, ret))
2223
	return NULL;
2309
	return NULL;
2224
      return ret;
2310
      return ret;
2225
    }
2311
    }
2226
 
2312
 
2227
  can_subst = 1;
2313
  can_subst = 1;
2228
 
2314
 
2229
  switch (peek)
2315
  switch (peek)
2230
    {
2316
    {
2231
    case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2317
    case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2232
    case 'h': case 'i': case 'j':           case 'l': case 'm': case 'n':
2318
    case 'h': case 'i': case 'j':           case 'l': case 'm': case 'n':
2233
    case 'o':                               case 's': case 't':
2319
    case 'o':                               case 's': case 't':
2234
    case 'v': case 'w': case 'x': case 'y': case 'z':
2320
    case 'v': case 'w': case 'x': case 'y': case 'z':
2235
      ret = d_make_builtin_type (di,
2321
      ret = d_make_builtin_type (di,
2236
				 &cplus_demangle_builtin_types[peek - 'a']);
2322
				 &cplus_demangle_builtin_types[peek - 'a']);
2237
      di->expansion += ret->u.s_builtin.type->len;
2323
      di->expansion += ret->u.s_builtin.type->len;
2238
      can_subst = 0;
2324
      can_subst = 0;
2239
      d_advance (di, 1);
2325
      d_advance (di, 1);
2240
      break;
2326
      break;
2241
 
2327
 
2242
    case 'u':
2328
    case 'u':
2243
      d_advance (di, 1);
2329
      d_advance (di, 1);
2244
      ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE,
2330
      ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE,
2245
			 d_source_name (di), NULL);
2331
			 d_source_name (di), NULL);
2246
      break;
2332
      break;
2247
 
2333
 
2248
    case 'F':
2334
    case 'F':
2249
      ret = d_function_type (di);
2335
      ret = d_function_type (di);
2250
      break;
2336
      break;
2251
 
2337
 
2252
    case '0': case '1': case '2': case '3': case '4':
2338
    case '0': case '1': case '2': case '3': case '4':
2253
    case '5': case '6': case '7': case '8': case '9':
2339
    case '5': case '6': case '7': case '8': case '9':
2254
    case 'N':
2340
    case 'N':
2255
    case 'Z':
2341
    case 'Z':
2256
      ret = d_class_enum_type (di);
2342
      ret = d_class_enum_type (di);
2257
      break;
2343
      break;
2258
 
2344
 
2259
    case 'A':
2345
    case 'A':
2260
      ret = d_array_type (di);
2346
      ret = d_array_type (di);
2261
      break;
2347
      break;
2262
 
2348
 
2263
    case 'M':
2349
    case 'M':
2264
      ret = d_pointer_to_member_type (di);
2350
      ret = d_pointer_to_member_type (di);
2265
      break;
2351
      break;
2266
 
2352
 
2267
    case 'T':
2353
    case 'T':
2268
      ret = d_template_param (di);
2354
      ret = d_template_param (di);
2269
      if (d_peek_char (di) == 'I')
2355
      if (d_peek_char (di) == 'I')
2270
	{
2356
	{
2271
	  /* This is  .  The
2357
	  /* This may be  .
-
 
2358
	     If this is the type for a conversion operator, we can
-
 
2359
	     have a  here only by following
-
 
2360
	     a derivation like this:
-
 
2361
 
-
 
2362
	     
-
 
2363
	     ->  
-
 
2364
	     ->   
-
 
2365
	     ->   
-
 
2366
	     ->   
-
 
2367
	     ->   
-
 
2368
	     ->  cv  
-
 
2369
	     ->  cv   
-
 
2370
 
-
 
2371
	     where the  is followed by another.
-
 
2372
	     Otherwise, we must have a derivation like this:
-
 
2373
 
-
 
2374
	     
-
 
2375
	     ->  
-
 
2376
	     ->   
-
 
2377
	     ->   
-
 
2378
	     ->   
-
 
2379
	     ->   
-
 
2380
	     ->  cv  
-
 
2381
	     ->  cv  
-
 
2382
 
-
 
2383
	     where we need to leave the  to be processed
-
 
2384
	     by d_prefix (following the ).
-
 
2385
 
2272
	      part is a substitution
2386
	     The  part is a substitution
2273
	     candidate.  */
2387
	     candidate.  */
-
 
2388
	  if (! di->is_conversion)
-
 
2389
	    {
2274
	  if (! d_add_substitution (di, ret))
2390
	  if (! d_add_substitution (di, ret))
2275
	    return NULL;
2391
	    return NULL;
2276
	  ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2392
	  ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2277
			     d_template_args (di));
2393
			     d_template_args (di));
2278
	}
2394
	}
-
 
2395
	  else
-
 
2396
	    {
-
 
2397
	      struct demangle_component *args;
-
 
2398
	      struct d_info_checkpoint checkpoint;
-
 
2399
 
-
 
2400
	      d_checkpoint (di, &checkpoint);
-
 
2401
	      args = d_template_args (di);
-
 
2402
	      if (d_peek_char (di) == 'I')
-
 
2403
		{
-
 
2404
		  if (! d_add_substitution (di, ret))
-
 
2405
		    return NULL;
-
 
2406
		  ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
-
 
2407
				     args);
-
 
2408
		}
-
 
2409
	      else
-
 
2410
		d_backtrack (di, &checkpoint);
-
 
2411
	    }
-
 
2412
	}
2279
      break;
2413
      break;
2280
 
2414
 
2281
    case 'S':
2415
    case 'S':
2282
      /* If this is a special substitution, then it is the start of
2416
      /* If this is a special substitution, then it is the start of
2283
	 .  */
2417
	 .  */
2284
      {
2418
      {
2285
	char peek_next;
2419
	char peek_next;
2286
 
2420
 
2287
	peek_next = d_peek_next_char (di);
2421
	peek_next = d_peek_next_char (di);
2288
	if (IS_DIGIT (peek_next)
2422
	if (IS_DIGIT (peek_next)
2289
	    || peek_next == '_'
2423
	    || peek_next == '_'
2290
	    || IS_UPPER (peek_next))
2424
	    || IS_UPPER (peek_next))
2291
	  {
2425
	  {
2292
	    ret = d_substitution (di, 0);
2426
	    ret = d_substitution (di, 0);
2293
	    /* The substituted name may have been a template name and
2427
	    /* The substituted name may have been a template name and
2294
	       may be followed by tepmlate args.  */
2428
	       may be followed by tepmlate args.  */
2295
	    if (d_peek_char (di) == 'I')
2429
	    if (d_peek_char (di) == 'I')
2296
	      ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2430
	      ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2297
				 d_template_args (di));
2431
				 d_template_args (di));
2298
	    else
2432
	    else
2299
	      can_subst = 0;
2433
	      can_subst = 0;
2300
	  }
2434
	  }
2301
	else
2435
	else
2302
	  {
2436
	  {
2303
	    ret = d_class_enum_type (di);
2437
	    ret = d_class_enum_type (di);
2304
	    /* If the substitution was a complete type, then it is not
2438
	    /* If the substitution was a complete type, then it is not
2305
	       a new substitution candidate.  However, if the
2439
	       a new substitution candidate.  However, if the
2306
	       substitution was followed by template arguments, then
2440
	       substitution was followed by template arguments, then
2307
	       the whole thing is a substitution candidate.  */
2441
	       the whole thing is a substitution candidate.  */
2308
	    if (ret != NULL && ret->type == DEMANGLE_COMPONENT_SUB_STD)
2442
	    if (ret != NULL && ret->type == DEMANGLE_COMPONENT_SUB_STD)
2309
	      can_subst = 0;
2443
	      can_subst = 0;
2310
	  }
2444
	  }
2311
      }
2445
      }
2312
      break;
2446
      break;
2313
 
2447
 
2314
    case 'O':
2448
    case 'O':
2315
      d_advance (di, 1);
2449
      d_advance (di, 1);
2316
      ret = d_make_comp (di, DEMANGLE_COMPONENT_RVALUE_REFERENCE,
2450
      ret = d_make_comp (di, DEMANGLE_COMPONENT_RVALUE_REFERENCE,
2317
                         cplus_demangle_type (di), NULL);
2451
                         cplus_demangle_type (di), NULL);
2318
      break;
2452
      break;
2319
 
2453
 
2320
    case 'P':
2454
    case 'P':
2321
      d_advance (di, 1);
2455
      d_advance (di, 1);
2322
      ret = d_make_comp (di, DEMANGLE_COMPONENT_POINTER,
2456
      ret = d_make_comp (di, DEMANGLE_COMPONENT_POINTER,
2323
			 cplus_demangle_type (di), NULL);
2457
			 cplus_demangle_type (di), NULL);
2324
      break;
2458
      break;
2325
 
2459
 
2326
    case 'R':
2460
    case 'R':
2327
      d_advance (di, 1);
2461
      d_advance (di, 1);
2328
      ret = d_make_comp (di, DEMANGLE_COMPONENT_REFERENCE,
2462
      ret = d_make_comp (di, DEMANGLE_COMPONENT_REFERENCE,
2329
                         cplus_demangle_type (di), NULL);
2463
                         cplus_demangle_type (di), NULL);
2330
      break;
2464
      break;
2331
 
2465
 
2332
    case 'C':
2466
    case 'C':
2333
      d_advance (di, 1);
2467
      d_advance (di, 1);
2334
      ret = d_make_comp (di, DEMANGLE_COMPONENT_COMPLEX,
2468
      ret = d_make_comp (di, DEMANGLE_COMPONENT_COMPLEX,
2335
			 cplus_demangle_type (di), NULL);
2469
			 cplus_demangle_type (di), NULL);
2336
      break;
2470
      break;
2337
 
2471
 
2338
    case 'G':
2472
    case 'G':
2339
      d_advance (di, 1);
2473
      d_advance (di, 1);
2340
      ret = d_make_comp (di, DEMANGLE_COMPONENT_IMAGINARY,
2474
      ret = d_make_comp (di, DEMANGLE_COMPONENT_IMAGINARY,
2341
			 cplus_demangle_type (di), NULL);
2475
			 cplus_demangle_type (di), NULL);
2342
      break;
2476
      break;
2343
 
2477
 
2344
    case 'U':
2478
    case 'U':
2345
      d_advance (di, 1);
2479
      d_advance (di, 1);
2346
      ret = d_source_name (di);
2480
      ret = d_source_name (di);
-
 
2481
      if (d_peek_char (di) == 'I')
-
 
2482
	ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
-
 
2483
			   d_template_args (di));
2347
      ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
2484
      ret = d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL,
2348
			 cplus_demangle_type (di), ret);
2485
			 cplus_demangle_type (di), ret);
2349
      break;
2486
      break;
2350
 
2487
 
2351
    case 'D':
2488
    case 'D':
2352
      can_subst = 0;
2489
      can_subst = 0;
2353
      d_advance (di, 1);
2490
      d_advance (di, 1);
2354
      peek = d_next_char (di);
2491
      peek = d_next_char (di);
2355
      switch (peek)
2492
      switch (peek)
2356
	{
2493
	{
2357
	case 'T':
2494
	case 'T':
2358
	case 't':
2495
	case 't':
2359
	  /* decltype (expression) */
2496
	  /* decltype (expression) */
2360
	  ret = d_make_comp (di, DEMANGLE_COMPONENT_DECLTYPE,
2497
	  ret = d_make_comp (di, DEMANGLE_COMPONENT_DECLTYPE,
2361
			     d_expression (di), NULL);
2498
			     d_expression (di), NULL);
2362
	  if (ret && d_next_char (di) != 'E')
2499
	  if (ret && d_next_char (di) != 'E')
2363
	    ret = NULL;
2500
	    ret = NULL;
2364
	  can_subst = 1;
2501
	  can_subst = 1;
2365
	  break;
2502
	  break;
2366
	  
2503
	  
2367
	case 'p':
2504
	case 'p':
2368
	  /* Pack expansion.  */
2505
	  /* Pack expansion.  */
2369
	  ret = d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION,
2506
	  ret = d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION,
2370
			     cplus_demangle_type (di), NULL);
2507
			     cplus_demangle_type (di), NULL);
2371
	  can_subst = 1;
2508
	  can_subst = 1;
2372
	  break;
2509
	  break;
2373
 
2510
 
2374
	case 'a':
2511
	case 'a':
2375
	  /* auto */
2512
	  /* auto */
2376
	  ret = d_make_name (di, "auto", 4);
2513
	  ret = d_make_name (di, "auto", 4);
2377
	  break;
2514
	  break;
2378
	  
2515
	  
2379
	case 'f':
2516
	case 'f':
2380
	  /* 32-bit decimal floating point */
2517
	  /* 32-bit decimal floating point */
2381
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[26]);
2518
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[26]);
2382
	  di->expansion += ret->u.s_builtin.type->len;
2519
	  di->expansion += ret->u.s_builtin.type->len;
2383
	  break;
2520
	  break;
2384
	case 'd':
2521
	case 'd':
2385
	  /* 64-bit DFP */
2522
	  /* 64-bit DFP */
2386
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[27]);
2523
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[27]);
2387
	  di->expansion += ret->u.s_builtin.type->len;
2524
	  di->expansion += ret->u.s_builtin.type->len;
2388
	  break;
2525
	  break;
2389
	case 'e':
2526
	case 'e':
2390
	  /* 128-bit DFP */
2527
	  /* 128-bit DFP */
2391
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[28]);
2528
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[28]);
2392
	  di->expansion += ret->u.s_builtin.type->len;
2529
	  di->expansion += ret->u.s_builtin.type->len;
2393
	  break;
2530
	  break;
2394
	case 'h':
2531
	case 'h':
2395
	  /* 16-bit half-precision FP */
2532
	  /* 16-bit half-precision FP */
2396
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[29]);
2533
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[29]);
2397
	  di->expansion += ret->u.s_builtin.type->len;
2534
	  di->expansion += ret->u.s_builtin.type->len;
2398
	  break;
2535
	  break;
2399
	case 's':
2536
	case 's':
2400
	  /* char16_t */
2537
	  /* char16_t */
2401
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[30]);
2538
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[30]);
2402
	  di->expansion += ret->u.s_builtin.type->len;
2539
	  di->expansion += ret->u.s_builtin.type->len;
2403
	  break;
2540
	  break;
2404
	case 'i':
2541
	case 'i':
2405
	  /* char32_t */
2542
	  /* char32_t */
2406
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[31]);
2543
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[31]);
2407
	  di->expansion += ret->u.s_builtin.type->len;
2544
	  di->expansion += ret->u.s_builtin.type->len;
2408
	  break;
2545
	  break;
2409
 
2546
 
2410
	case 'F':
2547
	case 'F':
2411
	  /* Fixed point types. DF  */
2548
	  /* Fixed point types. DF  */
2412
	  ret = d_make_empty (di);
2549
	  ret = d_make_empty (di);
2413
	  ret->type = DEMANGLE_COMPONENT_FIXED_TYPE;
2550
	  ret->type = DEMANGLE_COMPONENT_FIXED_TYPE;
2414
	  if ((ret->u.s_fixed.accum = IS_DIGIT (d_peek_char (di))))
2551
	  if ((ret->u.s_fixed.accum = IS_DIGIT (d_peek_char (di))))
2415
	    /* For demangling we don't care about the bits.  */
2552
	    /* For demangling we don't care about the bits.  */
2416
	    d_number (di);
2553
	    d_number (di);
2417
	  ret->u.s_fixed.length = cplus_demangle_type (di);
2554
	  ret->u.s_fixed.length = cplus_demangle_type (di);
2418
	  if (ret->u.s_fixed.length == NULL)
2555
	  if (ret->u.s_fixed.length == NULL)
2419
	    return NULL;
2556
	    return NULL;
2420
	  d_number (di);
2557
	  d_number (di);
2421
	  peek = d_next_char (di);
2558
	  peek = d_next_char (di);
2422
	  ret->u.s_fixed.sat = (peek == 's');
2559
	  ret->u.s_fixed.sat = (peek == 's');
2423
	  break;
2560
	  break;
2424
 
2561
 
2425
	case 'v':
2562
	case 'v':
2426
	  ret = d_vector_type (di);
2563
	  ret = d_vector_type (di);
2427
	  can_subst = 1;
2564
	  can_subst = 1;
2428
	  break;
2565
	  break;
2429
 
2566
 
2430
        case 'n':
2567
        case 'n':
2431
          /* decltype(nullptr) */
2568
          /* decltype(nullptr) */
2432
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]);
2569
	  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]);
2433
	  di->expansion += ret->u.s_builtin.type->len;
2570
	  di->expansion += ret->u.s_builtin.type->len;
2434
	  break;
2571
	  break;
2435
 
2572
 
2436
	default:
2573
	default:
2437
	  return NULL;
2574
	  return NULL;
2438
	}
2575
	}
2439
      break;
2576
      break;
2440
 
2577
 
2441
    default:
2578
    default:
2442
      return NULL;
2579
      return NULL;
2443
    }
2580
    }
2444
 
2581
 
2445
  if (can_subst)
2582
  if (can_subst)
2446
    {
2583
    {
2447
      if (! d_add_substitution (di, ret))
2584
      if (! d_add_substitution (di, ret))
2448
	return NULL;
2585
	return NULL;
2449
    }
2586
    }
2450
 
2587
 
2451
  return ret;
2588
  return ret;
2452
}
2589
}
2453
 
2590
 
2454
/*  ::= [r] [V] [K]  */
2591
/*  ::= [r] [V] [K]  */
2455
 
2592
 
2456
static struct demangle_component **
2593
static struct demangle_component **
2457
d_cv_qualifiers (struct d_info *di,
2594
d_cv_qualifiers (struct d_info *di,
2458
                 struct demangle_component **pret, int member_fn)
2595
                 struct demangle_component **pret, int member_fn)
2459
{
2596
{
2460
  struct demangle_component **pstart;
2597
  struct demangle_component **pstart;
2461
  char peek;
2598
  char peek;
2462
 
2599
 
2463
  pstart = pret;
2600
  pstart = pret;
2464
  peek = d_peek_char (di);
2601
  peek = d_peek_char (di);
2465
  while (peek == 'r' || peek == 'V' || peek == 'K')
2602
  while (peek == 'r' || peek == 'V' || peek == 'K')
2466
    {
2603
    {
2467
      enum demangle_component_type t;
2604
      enum demangle_component_type t;
2468
 
2605
 
2469
      d_advance (di, 1);
2606
      d_advance (di, 1);
2470
      if (peek == 'r')
2607
      if (peek == 'r')
2471
	{
2608
	{
2472
	  t = (member_fn
2609
	  t = (member_fn
2473
	       ? DEMANGLE_COMPONENT_RESTRICT_THIS
2610
	       ? DEMANGLE_COMPONENT_RESTRICT_THIS
2474
	       : DEMANGLE_COMPONENT_RESTRICT);
2611
	       : DEMANGLE_COMPONENT_RESTRICT);
2475
	  di->expansion += sizeof "restrict";
2612
	  di->expansion += sizeof "restrict";
2476
	}
2613
	}
2477
      else if (peek == 'V')
2614
      else if (peek == 'V')
2478
	{
2615
	{
2479
	  t = (member_fn
2616
	  t = (member_fn
2480
	       ? DEMANGLE_COMPONENT_VOLATILE_THIS
2617
	       ? DEMANGLE_COMPONENT_VOLATILE_THIS
2481
	       : DEMANGLE_COMPONENT_VOLATILE);
2618
	       : DEMANGLE_COMPONENT_VOLATILE);
2482
	  di->expansion += sizeof "volatile";
2619
	  di->expansion += sizeof "volatile";
2483
	}
2620
	}
2484
      else
2621
      else
2485
	{
2622
	{
2486
	  t = (member_fn
2623
	  t = (member_fn
2487
	       ? DEMANGLE_COMPONENT_CONST_THIS
2624
	       ? DEMANGLE_COMPONENT_CONST_THIS
2488
	       : DEMANGLE_COMPONENT_CONST);
2625
	       : DEMANGLE_COMPONENT_CONST);
2489
	  di->expansion += sizeof "const";
2626
	  di->expansion += sizeof "const";
2490
	}
2627
	}
2491
 
2628
 
2492
      *pret = d_make_comp (di, t, NULL, NULL);
2629
      *pret = d_make_comp (di, t, NULL, NULL);
2493
      if (*pret == NULL)
2630
      if (*pret == NULL)
2494
	return NULL;
2631
	return NULL;
2495
      pret = &d_left (*pret);
2632
      pret = &d_left (*pret);
2496
 
2633
 
2497
      peek = d_peek_char (di);
2634
      peek = d_peek_char (di);
2498
    }
2635
    }
2499
 
2636
 
2500
  if (!member_fn && peek == 'F')
2637
  if (!member_fn && peek == 'F')
2501
    {
2638
    {
2502
      while (pstart != pret)
2639
      while (pstart != pret)
2503
	{
2640
	{
2504
	  switch ((*pstart)->type)
2641
	  switch ((*pstart)->type)
2505
	    {
2642
	    {
2506
	    case DEMANGLE_COMPONENT_RESTRICT:
2643
	    case DEMANGLE_COMPONENT_RESTRICT:
2507
	      (*pstart)->type = DEMANGLE_COMPONENT_RESTRICT_THIS;
2644
	      (*pstart)->type = DEMANGLE_COMPONENT_RESTRICT_THIS;
2508
	      break;
2645
	      break;
2509
	    case DEMANGLE_COMPONENT_VOLATILE:
2646
	    case DEMANGLE_COMPONENT_VOLATILE:
2510
	      (*pstart)->type = DEMANGLE_COMPONENT_VOLATILE_THIS;
2647
	      (*pstart)->type = DEMANGLE_COMPONENT_VOLATILE_THIS;
2511
	      break;
2648
	      break;
2512
	    case DEMANGLE_COMPONENT_CONST:
2649
	    case DEMANGLE_COMPONENT_CONST:
2513
	      (*pstart)->type = DEMANGLE_COMPONENT_CONST_THIS;
2650
	      (*pstart)->type = DEMANGLE_COMPONENT_CONST_THIS;
2514
	      break;
2651
	      break;
2515
	    default:
2652
	    default:
2516
	      break;
2653
	      break;
2517
	    }
2654
	    }
2518
	  pstart = &d_left (*pstart);
2655
	  pstart = &d_left (*pstart);
2519
	}
2656
	}
2520
    }
2657
    }
2521
 
2658
 
2522
  return pret;
2659
  return pret;
2523
}
2660
}
2524
 
2661
 
2525
/*  ::= R
2662
/*  ::= R
2526
                   ::= O */
2663
                   ::= O */
2527
 
2664
 
2528
static struct demangle_component *
2665
static struct demangle_component *
2529
d_ref_qualifier (struct d_info *di, struct demangle_component *sub)
2666
d_ref_qualifier (struct d_info *di, struct demangle_component *sub)
2530
{
2667
{
2531
  struct demangle_component *ret = sub;
2668
  struct demangle_component *ret = sub;
2532
  char peek;
2669
  char peek;
2533
 
2670
 
2534
  peek = d_peek_char (di);
2671
  peek = d_peek_char (di);
2535
  if (peek == 'R' || peek == 'O')
2672
  if (peek == 'R' || peek == 'O')
2536
    {
2673
    {
2537
      enum demangle_component_type t;
2674
      enum demangle_component_type t;
2538
      if (peek == 'R')
2675
      if (peek == 'R')
2539
	{
2676
	{
2540
	  t = DEMANGLE_COMPONENT_REFERENCE_THIS;
2677
	  t = DEMANGLE_COMPONENT_REFERENCE_THIS;
2541
	  di->expansion += sizeof "&";
2678
	  di->expansion += sizeof "&";
2542
	}
2679
	}
2543
      else
2680
      else
2544
	{
2681
	{
2545
	  t = DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS;
2682
	  t = DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS;
2546
	  di->expansion += sizeof "&&";
2683
	  di->expansion += sizeof "&&";
2547
	}
2684
	}
2548
      d_advance (di, 1);
2685
      d_advance (di, 1);
2549
 
2686
 
2550
      ret = d_make_comp (di, t, ret, NULL);
2687
      ret = d_make_comp (di, t, ret, NULL);
2551
    }
2688
    }
2552
 
2689
 
2553
  return ret;
2690
  return ret;
2554
}
2691
}
2555
 
2692
 
2556
/*  ::= F [Y]  [] E  */
2693
/*  ::= F [Y]  [] E  */
2557
 
2694
 
2558
static struct demangle_component *
2695
static struct demangle_component *
2559
d_function_type (struct d_info *di)
2696
d_function_type (struct d_info *di)
2560
{
2697
{
2561
  struct demangle_component *ret;
2698
  struct demangle_component *ret;
2562
 
2699
 
2563
  if (! d_check_char (di, 'F'))
2700
  if (! d_check_char (di, 'F'))
2564
    return NULL;
2701
    return NULL;
2565
  if (d_peek_char (di) == 'Y')
2702
  if (d_peek_char (di) == 'Y')
2566
    {
2703
    {
2567
      /* Function has C linkage.  We don't print this information.
2704
      /* Function has C linkage.  We don't print this information.
2568
	 FIXME: We should print it in verbose mode.  */
2705
	 FIXME: We should print it in verbose mode.  */
2569
      d_advance (di, 1);
2706
      d_advance (di, 1);
2570
    }
2707
    }
2571
  ret = d_bare_function_type (di, 1);
2708
  ret = d_bare_function_type (di, 1);
2572
  ret = d_ref_qualifier (di, ret);
2709
  ret = d_ref_qualifier (di, ret);
2573
 
2710
 
2574
  if (! d_check_char (di, 'E'))
2711
  if (! d_check_char (di, 'E'))
2575
    return NULL;
2712
    return NULL;
2576
  return ret;
2713
  return ret;
2577
}
2714
}
2578
 
2715
 
2579
/* + */
2716
/* + */
2580
 
2717
 
2581
static struct demangle_component *
2718
static struct demangle_component *
2582
d_parmlist (struct d_info *di)
2719
d_parmlist (struct d_info *di)
2583
{
2720
{
2584
  struct demangle_component *tl;
2721
  struct demangle_component *tl;
2585
  struct demangle_component **ptl;
2722
  struct demangle_component **ptl;
2586
 
2723
 
2587
  tl = NULL;
2724
  tl = NULL;
2588
  ptl = &tl;
2725
  ptl = &tl;
2589
  while (1)
2726
  while (1)
2590
    {
2727
    {
2591
      struct demangle_component *type;
2728
      struct demangle_component *type;
2592
 
2729
 
2593
      char peek = d_peek_char (di);
2730
      char peek = d_peek_char (di);
2594
      if (peek == '\0' || peek == 'E' || peek == '.')
2731
      if (peek == '\0' || peek == 'E' || peek == '.')
2595
	break;
2732
	break;
2596
      if ((peek == 'R' || peek == 'O')
2733
      if ((peek == 'R' || peek == 'O')
2597
	  && d_peek_next_char (di) == 'E')
2734
	  && d_peek_next_char (di) == 'E')
2598
	/* Function ref-qualifier, not a ref prefix for a parameter type.  */
2735
	/* Function ref-qualifier, not a ref prefix for a parameter type.  */
2599
	break;
2736
	break;
2600
      type = cplus_demangle_type (di);
2737
      type = cplus_demangle_type (di);
2601
      if (type == NULL)
2738
      if (type == NULL)
2602
	return NULL;
2739
	return NULL;
2603
      *ptl = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, type, NULL);
2740
      *ptl = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, type, NULL);
2604
      if (*ptl == NULL)
2741
      if (*ptl == NULL)
2605
	return NULL;
2742
	return NULL;
2606
      ptl = &d_right (*ptl);
2743
      ptl = &d_right (*ptl);
2607
    }
2744
    }
2608
 
2745
 
2609
  /* There should be at least one parameter type besides the optional
2746
  /* There should be at least one parameter type besides the optional
2610
     return type.  A function which takes no arguments will have a
2747
     return type.  A function which takes no arguments will have a
2611
     single parameter type void.  */
2748
     single parameter type void.  */
2612
  if (tl == NULL)
2749
  if (tl == NULL)
2613
    return NULL;
2750
    return NULL;
2614
 
2751
 
2615
  /* If we have a single parameter type void, omit it.  */
2752
  /* If we have a single parameter type void, omit it.  */
2616
  if (d_right (tl) == NULL
2753
  if (d_right (tl) == NULL
2617
      && d_left (tl)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
2754
      && d_left (tl)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
2618
      && d_left (tl)->u.s_builtin.type->print == D_PRINT_VOID)
2755
      && d_left (tl)->u.s_builtin.type->print == D_PRINT_VOID)
2619
    {
2756
    {
2620
      di->expansion -= d_left (tl)->u.s_builtin.type->len;
2757
      di->expansion -= d_left (tl)->u.s_builtin.type->len;
2621
      d_left (tl) = NULL;
2758
      d_left (tl) = NULL;
2622
    }
2759
    }
2623
 
2760
 
2624
  return tl;
2761
  return tl;
2625
}
2762
}
2626
 
2763
 
2627
/*  ::= [J]+  */
2764
/*  ::= [J]+  */
2628
 
2765
 
2629
static struct demangle_component *
2766
static struct demangle_component *
2630
d_bare_function_type (struct d_info *di, int has_return_type)
2767
d_bare_function_type (struct d_info *di, int has_return_type)
2631
{
2768
{
2632
  struct demangle_component *return_type;
2769
  struct demangle_component *return_type;
2633
  struct demangle_component *tl;
2770
  struct demangle_component *tl;
2634
  char peek;
2771
  char peek;
2635
 
2772
 
2636
  /* Detect special qualifier indicating that the first argument
2773
  /* Detect special qualifier indicating that the first argument
2637
     is the return type.  */
2774
     is the return type.  */
2638
  peek = d_peek_char (di);
2775
  peek = d_peek_char (di);
2639
  if (peek == 'J')
2776
  if (peek == 'J')
2640
    {
2777
    {
2641
      d_advance (di, 1);
2778
      d_advance (di, 1);
2642
      has_return_type = 1;
2779
      has_return_type = 1;
2643
    }
2780
    }
2644
 
2781
 
2645
  if (has_return_type)
2782
  if (has_return_type)
2646
    {
2783
    {
2647
      return_type = cplus_demangle_type (di);
2784
      return_type = cplus_demangle_type (di);
2648
      if (return_type == NULL)
2785
      if (return_type == NULL)
2649
	return NULL;
2786
	return NULL;
2650
    }
2787
    }
2651
  else
2788
  else
2652
    return_type = NULL;
2789
    return_type = NULL;
2653
 
2790
 
2654
  tl = d_parmlist (di);
2791
  tl = d_parmlist (di);
2655
  if (tl == NULL)
2792
  if (tl == NULL)
2656
    return NULL;
2793
    return NULL;
2657
 
2794
 
2658
  return d_make_comp (di, DEMANGLE_COMPONENT_FUNCTION_TYPE,
2795
  return d_make_comp (di, DEMANGLE_COMPONENT_FUNCTION_TYPE,
2659
		      return_type, tl);
2796
		      return_type, tl);
2660
}
2797
}
2661
 
2798
 
2662
/*  ::=   */
2799
/*  ::=   */
2663
 
2800
 
2664
static struct demangle_component *
2801
static struct demangle_component *
2665
d_class_enum_type (struct d_info *di)
2802
d_class_enum_type (struct d_info *di)
2666
{
2803
{
2667
  return d_name (di);
2804
  return d_name (di);
2668
}
2805
}
2669
 
2806
 
2670
/*  ::= A <(positive dimension) number> _ <(element) type>
2807
/*  ::= A <(positive dimension) number> _ <(element) type>
2671
                ::= A [<(dimension) expression>] _ <(element) type>
2808
                ::= A [<(dimension) expression>] _ <(element) type>
2672
*/
2809
*/
2673
 
2810
 
2674
static struct demangle_component *
2811
static struct demangle_component *
2675
d_array_type (struct d_info *di)
2812
d_array_type (struct d_info *di)
2676
{
2813
{
2677
  char peek;
2814
  char peek;
2678
  struct demangle_component *dim;
2815
  struct demangle_component *dim;
2679
 
2816
 
2680
  if (! d_check_char (di, 'A'))
2817
  if (! d_check_char (di, 'A'))
2681
    return NULL;
2818
    return NULL;
2682
 
2819
 
2683
  peek = d_peek_char (di);
2820
  peek = d_peek_char (di);
2684
  if (peek == '_')
2821
  if (peek == '_')
2685
    dim = NULL;
2822
    dim = NULL;
2686
  else if (IS_DIGIT (peek))
2823
  else if (IS_DIGIT (peek))
2687
    {
2824
    {
2688
      const char *s;
2825
      const char *s;
2689
 
2826
 
2690
      s = d_str (di);
2827
      s = d_str (di);
2691
      do
2828
      do
2692
	{
2829
	{
2693
	  d_advance (di, 1);
2830
	  d_advance (di, 1);
2694
	  peek = d_peek_char (di);
2831
	  peek = d_peek_char (di);
2695
	}
2832
	}
2696
      while (IS_DIGIT (peek));
2833
      while (IS_DIGIT (peek));
2697
      dim = d_make_name (di, s, d_str (di) - s);
2834
      dim = d_make_name (di, s, d_str (di) - s);
2698
      if (dim == NULL)
2835
      if (dim == NULL)
2699
	return NULL;
2836
	return NULL;
2700
    }
2837
    }
2701
  else
2838
  else
2702
    {
2839
    {
2703
      dim = d_expression (di);
2840
      dim = d_expression (di);
2704
      if (dim == NULL)
2841
      if (dim == NULL)
2705
	return NULL;
2842
	return NULL;
2706
    }
2843
    }
2707
 
2844
 
2708
  if (! d_check_char (di, '_'))
2845
  if (! d_check_char (di, '_'))
2709
    return NULL;
2846
    return NULL;
2710
 
2847
 
2711
  return d_make_comp (di, DEMANGLE_COMPONENT_ARRAY_TYPE, dim,
2848
  return d_make_comp (di, DEMANGLE_COMPONENT_ARRAY_TYPE, dim,
2712
		      cplus_demangle_type (di));
2849
		      cplus_demangle_type (di));
2713
}
2850
}
2714
 
2851
 
2715
/*  ::= Dv  _ 
2852
/*  ::= Dv  _ 
2716
                 ::= Dv _  _  */
2853
                 ::= Dv _  _  */
2717
 
2854
 
2718
static struct demangle_component *
2855
static struct demangle_component *
2719
d_vector_type (struct d_info *di)
2856
d_vector_type (struct d_info *di)
2720
{
2857
{
2721
  char peek;
2858
  char peek;
2722
  struct demangle_component *dim;
2859
  struct demangle_component *dim;
2723
 
2860
 
2724
  peek = d_peek_char (di);
2861
  peek = d_peek_char (di);
2725
  if (peek == '_')
2862
  if (peek == '_')
2726
    {
2863
    {
2727
      d_advance (di, 1);
2864
      d_advance (di, 1);
2728
      dim = d_expression (di);
2865
      dim = d_expression (di);
2729
    }
2866
    }
2730
  else
2867
  else
2731
    dim = d_number_component (di);
2868
    dim = d_number_component (di);
2732
 
2869
 
2733
  if (dim == NULL)
2870
  if (dim == NULL)
2734
    return NULL;
2871
    return NULL;
2735
 
2872
 
2736
  if (! d_check_char (di, '_'))
2873
  if (! d_check_char (di, '_'))
2737
    return NULL;
2874
    return NULL;
2738
 
2875
 
2739
  return d_make_comp (di, DEMANGLE_COMPONENT_VECTOR_TYPE, dim,
2876
  return d_make_comp (di, DEMANGLE_COMPONENT_VECTOR_TYPE, dim,
2740
		      cplus_demangle_type (di));
2877
		      cplus_demangle_type (di));
2741
}
2878
}
2742
 
2879
 
2743
/*  ::= M <(class) type> <(member) type>  */
2880
/*  ::= M <(class) type> <(member) type>  */
2744
 
2881
 
2745
static struct demangle_component *
2882
static struct demangle_component *
2746
d_pointer_to_member_type (struct d_info *di)
2883
d_pointer_to_member_type (struct d_info *di)
2747
{
2884
{
2748
  struct demangle_component *cl;
2885
  struct demangle_component *cl;
2749
  struct demangle_component *mem;
2886
  struct demangle_component *mem;
2750
 
2887
 
2751
  if (! d_check_char (di, 'M'))
2888
  if (! d_check_char (di, 'M'))
2752
    return NULL;
2889
    return NULL;
2753
 
2890
 
2754
  cl = cplus_demangle_type (di);
2891
  cl = cplus_demangle_type (di);
2755
  if (cl == NULL)
2892
  if (cl == NULL)
2756
    return NULL;
2893
    return NULL;
2757
 
2894
 
2758
  /* The ABI says, "The type of a non-static member function is considered
2895
  /* The ABI says, "The type of a non-static member function is considered
2759
     to be different, for the purposes of substitution, from the type of a
2896
     to be different, for the purposes of substitution, from the type of a
2760
     namespace-scope or static member function whose type appears
2897
     namespace-scope or static member function whose type appears
2761
     similar. The types of two non-static member functions are considered
2898
     similar. The types of two non-static member functions are considered
2762
     to be different, for the purposes of substitution, if the functions
2899
     to be different, for the purposes of substitution, if the functions
2763
     are members of different classes. In other words, for the purposes of
2900
     are members of different classes. In other words, for the purposes of
2764
     substitution, the class of which the function is a member is
2901
     substitution, the class of which the function is a member is
2765
     considered part of the type of function."
2902
     considered part of the type of function."
2766
 
2903
 
2767
     For a pointer to member function, this call to cplus_demangle_type
2904
     For a pointer to member function, this call to cplus_demangle_type
2768
     will end up adding a (possibly qualified) non-member function type to
2905
     will end up adding a (possibly qualified) non-member function type to
2769
     the substitution table, which is not correct; however, the member
2906
     the substitution table, which is not correct; however, the member
2770
     function type will never be used in a substitution, so putting the
2907
     function type will never be used in a substitution, so putting the
2771
     wrong type in the substitution table is harmless.  */
2908
     wrong type in the substitution table is harmless.  */
2772
 
2909
 
2773
  mem = cplus_demangle_type (di);
2910
  mem = cplus_demangle_type (di);
2774
  if (mem == NULL)
2911
  if (mem == NULL)
2775
    return NULL;
2912
    return NULL;
2776
 
2913
 
2777
  return d_make_comp (di, DEMANGLE_COMPONENT_PTRMEM_TYPE, cl, mem);
2914
  return d_make_comp (di, DEMANGLE_COMPONENT_PTRMEM_TYPE, cl, mem);
2778
}
2915
}
2779
 
2916
 
2780
/*  _ */
2917
/*  _ */
2781
 
2918
 
2782
static long
2919
static long
2783
d_compact_number (struct d_info *di)
2920
d_compact_number (struct d_info *di)
2784
{
2921
{
2785
  long num;
2922
  long num;
2786
  if (d_peek_char (di) == '_')
2923
  if (d_peek_char (di) == '_')
2787
    num = 0;
2924
    num = 0;
2788
  else if (d_peek_char (di) == 'n')
2925
  else if (d_peek_char (di) == 'n')
2789
    return -1;
2926
    return -1;
2790
  else
2927
  else
2791
    num = d_number (di) + 1;
2928
    num = d_number (di) + 1;
2792
 
2929
 
2793
  if (! d_check_char (di, '_'))
2930
  if (! d_check_char (di, '_'))
2794
    return -1;
2931
    return -1;
2795
  return num;
2932
  return num;
2796
}
2933
}
2797
 
2934
 
2798
/*  ::= T_
2935
/*  ::= T_
2799
                    ::= T <(parameter-2 non-negative) number> _
2936
                    ::= T <(parameter-2 non-negative) number> _
2800
*/
2937
*/
2801
 
2938
 
2802
static struct demangle_component *
2939
static struct demangle_component *
2803
d_template_param (struct d_info *di)
2940
d_template_param (struct d_info *di)
2804
{
2941
{
2805
  long param;
2942
  long param;
2806
 
2943
 
2807
  if (! d_check_char (di, 'T'))
2944
  if (! d_check_char (di, 'T'))
2808
    return NULL;
2945
    return NULL;
2809
 
2946
 
2810
  param = d_compact_number (di);
2947
  param = d_compact_number (di);
2811
  if (param < 0)
2948
  if (param < 0)
2812
    return NULL;
2949
    return NULL;
2813
 
2950
 
2814
  ++di->did_subs;
2951
  ++di->did_subs;
2815
 
2952
 
2816
  return d_make_template_param (di, param);
2953
  return d_make_template_param (di, param);
2817
}
2954
}
2818
 
2955
 
2819
/*  ::= I + E  */
2956
/*  ::= I + E  */
2820
 
2957
 
2821
static struct demangle_component *
2958
static struct demangle_component *
2822
d_template_args (struct d_info *di)
2959
d_template_args (struct d_info *di)
2823
{
2960
{
2824
  struct demangle_component *hold_last_name;
2961
  struct demangle_component *hold_last_name;
2825
  struct demangle_component *al;
2962
  struct demangle_component *al;
2826
  struct demangle_component **pal;
2963
  struct demangle_component **pal;
2827
 
2964
 
2828
  /* Preserve the last name we saw--don't let the template arguments
2965
  /* Preserve the last name we saw--don't let the template arguments
2829
     clobber it, as that would give us the wrong name for a subsequent
2966
     clobber it, as that would give us the wrong name for a subsequent
2830
     constructor or destructor.  */
2967
     constructor or destructor.  */
2831
  hold_last_name = di->last_name;
2968
  hold_last_name = di->last_name;
2832
 
2969
 
2833
  if (d_peek_char (di) != 'I'
2970
  if (d_peek_char (di) != 'I'
2834
      && d_peek_char (di) != 'J')
2971
      && d_peek_char (di) != 'J')
2835
    return NULL;
2972
    return NULL;
2836
  d_advance (di, 1);
2973
  d_advance (di, 1);
2837
 
2974
 
2838
  if (d_peek_char (di) == 'E')
2975
  if (d_peek_char (di) == 'E')
2839
    {
2976
    {
2840
      /* An argument pack can be empty.  */
2977
      /* An argument pack can be empty.  */
2841
      d_advance (di, 1);
2978
      d_advance (di, 1);
2842
      return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, NULL, NULL);
2979
      return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, NULL, NULL);
2843
    }
2980
    }
2844
 
2981
 
2845
  al = NULL;
2982
  al = NULL;
2846
  pal = &al;
2983
  pal = &al;
2847
  while (1)
2984
  while (1)
2848
    {
2985
    {
2849
      struct demangle_component *a;
2986
      struct demangle_component *a;
2850
 
2987
 
2851
      a = d_template_arg (di);
2988
      a = d_template_arg (di);
2852
      if (a == NULL)
2989
      if (a == NULL)
2853
	return NULL;
2990
	return NULL;
2854
 
2991
 
2855
      *pal = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, a, NULL);
2992
      *pal = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, a, NULL);
2856
      if (*pal == NULL)
2993
      if (*pal == NULL)
2857
	return NULL;
2994
	return NULL;
2858
      pal = &d_right (*pal);
2995
      pal = &d_right (*pal);
2859
 
2996
 
2860
      if (d_peek_char (di) == 'E')
2997
      if (d_peek_char (di) == 'E')
2861
	{
2998
	{
2862
	  d_advance (di, 1);
2999
	  d_advance (di, 1);
2863
	  break;
3000
	  break;
2864
	}
3001
	}
2865
    }
3002
    }
2866
 
3003
 
2867
  di->last_name = hold_last_name;
3004
  di->last_name = hold_last_name;
2868
 
3005
 
2869
  return al;
3006
  return al;
2870
}
3007
}
2871
 
3008
 
2872
/*  ::= 
3009
/*  ::= 
2873
                  ::= X  E
3010
                  ::= X  E
2874
                  ::= 
3011
                  ::= 
2875
*/
3012
*/
2876
 
3013
 
2877
static struct demangle_component *
3014
static struct demangle_component *
2878
d_template_arg (struct d_info *di)
3015
d_template_arg (struct d_info *di)
2879
{
3016
{
2880
  struct demangle_component *ret;
3017
  struct demangle_component *ret;
2881
 
3018
 
2882
  switch (d_peek_char (di))
3019
  switch (d_peek_char (di))
2883
    {
3020
    {
2884
    case 'X':
3021
    case 'X':
2885
      d_advance (di, 1);
3022
      d_advance (di, 1);
2886
      ret = d_expression (di);
3023
      ret = d_expression (di);
2887
      if (! d_check_char (di, 'E'))
3024
      if (! d_check_char (di, 'E'))
2888
	return NULL;
3025
	return NULL;
2889
      return ret;
3026
      return ret;
2890
 
3027
 
2891
    case 'L':
3028
    case 'L':
2892
      return d_expr_primary (di);
3029
      return d_expr_primary (di);
2893
 
3030
 
2894
    case 'I':
3031
    case 'I':
2895
    case 'J':
3032
    case 'J':
2896
      /* An argument pack.  */
3033
      /* An argument pack.  */
2897
      return d_template_args (di);
3034
      return d_template_args (di);
2898
 
3035
 
2899
    default:
3036
    default:
2900
      return cplus_demangle_type (di);
3037
      return cplus_demangle_type (di);
2901
    }
3038
    }
2902
}
3039
}
2903
 
3040
 
2904
/* Parse a sequence of expressions until we hit the terminator
3041
/* Parse a sequence of expressions until we hit the terminator
2905
   character.  */
3042
   character.  */
2906
 
3043
 
2907
static struct demangle_component *
3044
static struct demangle_component *
2908
d_exprlist (struct d_info *di, char terminator)
3045
d_exprlist (struct d_info *di, char terminator)
2909
{
3046
{
2910
  struct demangle_component *list = NULL;
3047
  struct demangle_component *list = NULL;
2911
  struct demangle_component **p = &list;
3048
  struct demangle_component **p = &list;
2912
 
3049
 
2913
  if (d_peek_char (di) == terminator)
3050
  if (d_peek_char (di) == terminator)
2914
    {
3051
    {
2915
      d_advance (di, 1);
3052
      d_advance (di, 1);
2916
      return d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, NULL, NULL);
3053
      return d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, NULL, NULL);
2917
    }
3054
    }
2918
 
3055
 
2919
  while (1)
3056
  while (1)
2920
    {
3057
    {
2921
      struct demangle_component *arg = d_expression (di);
3058
      struct demangle_component *arg = d_expression (di);
2922
      if (arg == NULL)
3059
      if (arg == NULL)
2923
	return NULL;
3060
	return NULL;
2924
 
3061
 
2925
      *p = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, arg, NULL);
3062
      *p = d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, arg, NULL);
2926
      if (*p == NULL)
3063
      if (*p == NULL)
2927
	return NULL;
3064
	return NULL;
2928
      p = &d_right (*p);
3065
      p = &d_right (*p);
2929
 
3066
 
2930
      if (d_peek_char (di) == terminator)
3067
      if (d_peek_char (di) == terminator)
2931
	{
3068
	{
2932
	  d_advance (di, 1);
3069
	  d_advance (di, 1);
2933
	  break;
3070
	  break;
2934
	}
3071
	}
2935
    }
3072
    }
2936
 
3073
 
2937
  return list;
3074
  return list;
2938
}
3075
}
2939
 
3076
 
2940
/* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3077
/* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
2941
   dynamic_cast, static_cast or reinterpret_cast.  */
3078
   dynamic_cast, static_cast or reinterpret_cast.  */
2942
 
3079
 
2943
static int
3080
static int
2944
op_is_new_cast (struct demangle_component *op)
3081
op_is_new_cast (struct demangle_component *op)
2945
{
3082
{
2946
  const char *code = op->u.s_operator.op->code;
3083
  const char *code = op->u.s_operator.op->code;
2947
  return (code[1] == 'c'
3084
  return (code[1] == 'c'
2948
	  && (code[0] == 's' || code[0] == 'd'
3085
	  && (code[0] == 's' || code[0] == 'd'
2949
	      || code[0] == 'c' || code[0] == 'r'));
3086
	      || code[0] == 'c' || code[0] == 'r'));
2950
}
3087
}
2951
 
3088
 
2952
/*  ::= <(unary) operator-name> 
3089
/*  ::= <(unary) operator-name> 
2953
                ::= <(binary) operator-name>  
3090
                ::= <(binary) operator-name>  
2954
                ::= <(trinary) operator-name>   
3091
                ::= <(trinary) operator-name>   
2955
		::= cl + E
3092
		::= cl + E
2956
                ::= st 
3093
                ::= st 
2957
                ::= 
3094
                ::= 
2958
                ::= sr  
3095
                ::= sr  
2959
                ::= sr   
3096
                ::= sr   
2960
                ::= 
3097
                ::= 
2961
*/
3098
*/
2962
 
3099
 
2963
static struct demangle_component *
3100
static inline struct demangle_component *
2964
d_expression (struct d_info *di)
3101
d_expression_1 (struct d_info *di)
2965
{
3102
{
2966
  char peek;
3103
  char peek;
2967
 
3104
 
2968
  peek = d_peek_char (di);
3105
  peek = d_peek_char (di);
2969
  if (peek == 'L')
3106
  if (peek == 'L')
2970
    return d_expr_primary (di);
3107
    return d_expr_primary (di);
2971
  else if (peek == 'T')
3108
  else if (peek == 'T')
2972
    return d_template_param (di);
3109
    return d_template_param (di);
2973
  else if (peek == 's' && d_peek_next_char (di) == 'r')
3110
  else if (peek == 's' && d_peek_next_char (di) == 'r')
2974
    {
3111
    {
2975
      struct demangle_component *type;
3112
      struct demangle_component *type;
2976
      struct demangle_component *name;
3113
      struct demangle_component *name;
2977
 
3114
 
2978
      d_advance (di, 2);
3115
      d_advance (di, 2);
2979
      type = cplus_demangle_type (di);
3116
      type = cplus_demangle_type (di);
2980
      name = d_unqualified_name (di);
3117
      name = d_unqualified_name (di);
2981
      if (d_peek_char (di) != 'I')
3118
      if (d_peek_char (di) != 'I')
2982
	return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name);
3119
	return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name);
2983
      else
3120
      else
2984
	return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type,
3121
	return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type,
2985
			    d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3122
			    d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
2986
					 d_template_args (di)));
3123
					 d_template_args (di)));
2987
    }
3124
    }
2988
  else if (peek == 's' && d_peek_next_char (di) == 'p')
3125
  else if (peek == 's' && d_peek_next_char (di) == 'p')
2989
    {
3126
    {
2990
      d_advance (di, 2);
3127
      d_advance (di, 2);
2991
      return d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION,
3128
      return d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION,
2992
			  d_expression (di), NULL);
3129
			  d_expression_1 (di), NULL);
2993
    }
3130
    }
2994
  else if (peek == 'f' && d_peek_next_char (di) == 'p')
3131
  else if (peek == 'f' && d_peek_next_char (di) == 'p')
2995
    {
3132
    {
2996
      /* Function parameter used in a late-specified return type.  */
3133
      /* Function parameter used in a late-specified return type.  */
2997
      int index;
3134
      int index;
2998
      d_advance (di, 2);
3135
      d_advance (di, 2);
2999
      if (d_peek_char (di) == 'T')
3136
      if (d_peek_char (di) == 'T')
3000
	{
3137
	{
3001
	  /* 'this' parameter.  */
3138
	  /* 'this' parameter.  */
3002
	  d_advance (di, 1);
3139
	  d_advance (di, 1);
3003
	  index = 0;
3140
	  index = 0;
3004
	}
3141
	}
3005
      else
3142
      else
3006
	{
3143
	{
3007
	  index = d_compact_number (di) + 1;
3144
	  index = d_compact_number (di) + 1;
3008
	  if (index == 0)
3145
	  if (index == 0)
3009
	    return NULL;
3146
	    return NULL;
3010
	}
3147
	}
3011
      return d_make_function_param (di, index);
3148
      return d_make_function_param (di, index);
3012
    }
3149
    }
3013
  else if (IS_DIGIT (peek)
3150
  else if (IS_DIGIT (peek)
3014
	   || (peek == 'o' && d_peek_next_char (di) == 'n'))
3151
	   || (peek == 'o' && d_peek_next_char (di) == 'n'))
3015
    {
3152
    {
3016
      /* We can get an unqualified name as an expression in the case of
3153
      /* We can get an unqualified name as an expression in the case of
3017
         a dependent function call, i.e. decltype(f(t)).  */
3154
         a dependent function call, i.e. decltype(f(t)).  */
3018
      struct demangle_component *name;
3155
      struct demangle_component *name;
3019
 
3156
 
3020
      if (peek == 'o')
3157
      if (peek == 'o')
3021
	/* operator-function-id, i.e. operator+(t).  */
3158
	/* operator-function-id, i.e. operator+(t).  */
3022
	d_advance (di, 2);
3159
	d_advance (di, 2);
3023
 
3160
 
3024
      name = d_unqualified_name (di);
3161
      name = d_unqualified_name (di);
3025
      if (name == NULL)
3162
      if (name == NULL)
3026
	return NULL;
3163
	return NULL;
3027
      if (d_peek_char (di) == 'I')
3164
      if (d_peek_char (di) == 'I')
3028
	return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3165
	return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3029
			    d_template_args (di));
3166
			    d_template_args (di));
3030
      else
3167
      else
3031
	return name;
3168
	return name;
3032
    }
3169
    }
3033
  else if ((peek == 'i' || peek == 't')
3170
  else if ((peek == 'i' || peek == 't')
3034
	   && d_peek_next_char (di) == 'l')
3171
	   && d_peek_next_char (di) == 'l')
3035
    {
3172
    {
3036
      /* Brace-enclosed initializer list, untyped or typed.  */
3173
      /* Brace-enclosed initializer list, untyped or typed.  */
3037
      struct demangle_component *type = NULL;
3174
      struct demangle_component *type = NULL;
3038
      if (peek == 't')
3175
      if (peek == 't')
3039
	type = cplus_demangle_type (di);
3176
	type = cplus_demangle_type (di);
3040
      d_advance (di, 2);
3177
      d_advance (di, 2);
3041
      return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST,
3178
      return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST,
3042
			  type, d_exprlist (di, 'E'));
3179
			  type, d_exprlist (di, 'E'));
3043
    }
3180
    }
3044
  else
3181
  else
3045
    {
3182
    {
3046
      struct demangle_component *op;
3183
      struct demangle_component *op;
3047
      const char *code = NULL;
3184
      const char *code = NULL;
3048
      int args;
3185
      int args;
3049
 
3186
 
3050
      op = d_operator_name (di);
3187
      op = d_operator_name (di);
3051
      if (op == NULL)
3188
      if (op == NULL)
3052
	return NULL;
3189
	return NULL;
3053
 
3190
 
3054
      if (op->type == DEMANGLE_COMPONENT_OPERATOR)
3191
      if (op->type == DEMANGLE_COMPONENT_OPERATOR)
3055
	{
3192
	{
3056
	  code = op->u.s_operator.op->code;
3193
	  code = op->u.s_operator.op->code;
3057
	  di->expansion += op->u.s_operator.op->len - 2;
3194
	  di->expansion += op->u.s_operator.op->len - 2;
3058
	  if (strcmp (code, "st") == 0)
3195
	  if (strcmp (code, "st") == 0)
3059
	    return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3196
	    return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3060
				cplus_demangle_type (di));
3197
				cplus_demangle_type (di));
3061
	}
3198
	}
3062
 
3199
 
3063
      switch (op->type)
3200
      switch (op->type)
3064
	{
3201
	{
3065
	default:
3202
	default:
3066
	  return NULL;
3203
	  return NULL;
3067
	case DEMANGLE_COMPONENT_OPERATOR:
3204
	case DEMANGLE_COMPONENT_OPERATOR:
3068
	  args = op->u.s_operator.op->args;
3205
	  args = op->u.s_operator.op->args;
3069
	  break;
3206
	  break;
3070
	case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
3207
	case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
3071
	  args = op->u.s_extended_operator.args;
3208
	  args = op->u.s_extended_operator.args;
3072
	  break;
3209
	  break;
3073
	case DEMANGLE_COMPONENT_CAST:
3210
	case DEMANGLE_COMPONENT_CAST:
3074
	  args = 1;
3211
	  args = 1;
3075
	  break;
3212
	  break;
3076
	}
3213
	}
3077
 
3214
 
3078
      switch (args)
3215
      switch (args)
3079
	{
3216
	{
3080
	case 0:
3217
	case 0:
3081
	  return d_make_comp (di, DEMANGLE_COMPONENT_NULLARY, op, NULL);
3218
	  return d_make_comp (di, DEMANGLE_COMPONENT_NULLARY, op, NULL);
3082
 
3219
 
3083
	case 1:
3220
	case 1:
3084
	  {
3221
	  {
3085
	    struct demangle_component *operand;
3222
	    struct demangle_component *operand;
3086
	    int suffix = 0;
3223
	    int suffix = 0;
3087
 
3224
 
3088
	    if (code && (code[0] == 'p' || code[0] == 'm')
3225
	    if (code && (code[0] == 'p' || code[0] == 'm')
3089
		&& code[1] == code[0])
3226
		&& code[1] == code[0])
3090
	      /* pp_ and mm_ are the prefix variants.  */
3227
	      /* pp_ and mm_ are the prefix variants.  */
3091
	      suffix = !d_check_char (di, '_');
3228
	      suffix = !d_check_char (di, '_');
3092
 
3229
 
3093
	    if (op->type == DEMANGLE_COMPONENT_CAST
3230
	    if (op->type == DEMANGLE_COMPONENT_CAST
3094
		&& d_check_char (di, '_'))
3231
		&& d_check_char (di, '_'))
3095
	      operand = d_exprlist (di, 'E');
3232
	      operand = d_exprlist (di, 'E');
3096
	    else
3233
	    else
3097
	      operand = d_expression (di);
3234
	      operand = d_expression_1 (di);
3098
 
3235
 
3099
	    if (suffix)
3236
	    if (suffix)
3100
	      /* Indicate the suffix variant for d_print_comp.  */
3237
	      /* Indicate the suffix variant for d_print_comp.  */
3101
	      return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3238
	      return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3102
				  d_make_comp (di,
3239
				  d_make_comp (di,
3103
					       DEMANGLE_COMPONENT_BINARY_ARGS,
3240
					       DEMANGLE_COMPONENT_BINARY_ARGS,
3104
					       operand, operand));
3241
					       operand, operand));
3105
	    else
3242
	    else
3106
	      return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3243
	      return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op,
3107
				  operand);
3244
				  operand);
3108
	  }
3245
	  }
3109
	case 2:
3246
	case 2:
3110
	  {
3247
	  {
3111
	    struct demangle_component *left;
3248
	    struct demangle_component *left;
3112
	    struct demangle_component *right;
3249
	    struct demangle_component *right;
3113
 
3250
 
3114
	    if (op_is_new_cast (op))
3251
	    if (op_is_new_cast (op))
3115
	      left = cplus_demangle_type (di);
3252
	      left = cplus_demangle_type (di);
3116
	    else
3253
	    else
3117
	      left = d_expression (di);
3254
	      left = d_expression_1 (di);
3118
	    if (!strcmp (code, "cl"))
3255
	    if (!strcmp (code, "cl"))
3119
	      right = d_exprlist (di, 'E');
3256
	      right = d_exprlist (di, 'E');
3120
	    else if (!strcmp (code, "dt") || !strcmp (code, "pt"))
3257
	    else if (!strcmp (code, "dt") || !strcmp (code, "pt"))
3121
	      {
3258
	      {
3122
		right = d_unqualified_name (di);
3259
		right = d_unqualified_name (di);
3123
		if (d_peek_char (di) == 'I')
3260
		if (d_peek_char (di) == 'I')
3124
		  right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
3261
		  right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
3125
				       right, d_template_args (di));
3262
				       right, d_template_args (di));
3126
	      }
3263
	      }
3127
	    else
3264
	    else
3128
	      right = d_expression (di);
3265
	      right = d_expression_1 (di);
3129
 
3266
 
3130
	    return d_make_comp (di, DEMANGLE_COMPONENT_BINARY, op,
3267
	    return d_make_comp (di, DEMANGLE_COMPONENT_BINARY, op,
3131
				d_make_comp (di,
3268
				d_make_comp (di,
3132
					     DEMANGLE_COMPONENT_BINARY_ARGS,
3269
					     DEMANGLE_COMPONENT_BINARY_ARGS,
3133
					     left, right));
3270
					     left, right));
3134
	  }
3271
	  }
3135
	case 3:
3272
	case 3:
3136
	  {
3273
	  {
3137
	    struct demangle_component *first;
3274
	    struct demangle_component *first;
3138
	    struct demangle_component *second;
3275
	    struct demangle_component *second;
3139
	    struct demangle_component *third;
3276
	    struct demangle_component *third;
3140
 
3277
 
3141
	    if (!strcmp (code, "qu"))
3278
	    if (!strcmp (code, "qu"))
3142
	      {
3279
	      {
3143
		/* ?: expression.  */
3280
		/* ?: expression.  */
3144
		first = d_expression (di);
3281
		first = d_expression_1 (di);
3145
		second = d_expression (di);
3282
		second = d_expression_1 (di);
3146
		third = d_expression (di);
3283
		third = d_expression_1 (di);
3147
	      }
3284
	      }
3148
	    else if (code[0] == 'n')
3285
	    else if (code[0] == 'n')
3149
	      {
3286
	      {
3150
		/* new-expression.  */
3287
		/* new-expression.  */
3151
		if (code[1] != 'w' && code[1] != 'a')
3288
		if (code[1] != 'w' && code[1] != 'a')
3152
		  return NULL;
3289
		  return NULL;
3153
		first = d_exprlist (di, '_');
3290
		first = d_exprlist (di, '_');
3154
		second = cplus_demangle_type (di);
3291
		second = cplus_demangle_type (di);
3155
		if (d_peek_char (di) == 'E')
3292
		if (d_peek_char (di) == 'E')
3156
		  {
3293
		  {
3157
		    d_advance (di, 1);
3294
		    d_advance (di, 1);
3158
		    third = NULL;
3295
		    third = NULL;
3159
		  }
3296
		  }
3160
		else if (d_peek_char (di) == 'p'
3297
		else if (d_peek_char (di) == 'p'
3161
			 && d_peek_next_char (di) == 'i')
3298
			 && d_peek_next_char (di) == 'i')
3162
		  {
3299
		  {
3163
		    /* Parenthesized initializer.  */
3300
		    /* Parenthesized initializer.  */
3164
		    d_advance (di, 2);
3301
		    d_advance (di, 2);
3165
		    third = d_exprlist (di, 'E');
3302
		    third = d_exprlist (di, 'E');
3166
		  }
3303
		  }
3167
		else if (d_peek_char (di) == 'i'
3304
		else if (d_peek_char (di) == 'i'
3168
			 && d_peek_next_char (di) == 'l')
3305
			 && d_peek_next_char (di) == 'l')
3169
		  /* initializer-list.  */
3306
		  /* initializer-list.  */
3170
		  third = d_expression (di);
3307
		  third = d_expression_1 (di);
3171
		else
3308
		else
3172
		  return NULL;
3309
		  return NULL;
3173
	      }
3310
	      }
3174
	    else
3311
	    else
3175
	      return NULL;
3312
	      return NULL;
3176
	    return d_make_comp (di, DEMANGLE_COMPONENT_TRINARY, op,
3313
	    return d_make_comp (di, DEMANGLE_COMPONENT_TRINARY, op,
3177
				d_make_comp (di,
3314
				d_make_comp (di,
3178
					     DEMANGLE_COMPONENT_TRINARY_ARG1,
3315
					     DEMANGLE_COMPONENT_TRINARY_ARG1,
3179
					     first,
3316
					     first,
3180
					     d_make_comp (di,
3317
					     d_make_comp (di,
3181
							  DEMANGLE_COMPONENT_TRINARY_ARG2,
3318
							  DEMANGLE_COMPONENT_TRINARY_ARG2,
3182
							  second, third)));
3319
							  second, third)));
3183
	  }
3320
	  }
3184
	default:
3321
	default:
3185
	  return NULL;
3322
	  return NULL;
3186
	}
3323
	}
3187
    }
3324
    }
3188
}
3325
}
-
 
3326
 
-
 
3327
static struct demangle_component *
-
 
3328
d_expression (struct d_info *di)
-
 
3329
{
-
 
3330
  struct demangle_component *ret;
-
 
3331
  int was_expression = di->is_expression;
-
 
3332
 
-
 
3333
  di->is_expression = 1;
-
 
3334
  ret = d_expression_1 (di);
-
 
3335
  di->is_expression = was_expression;
-
 
3336
  return ret;
-
 
3337
}
3189
 
3338
 
3190
/*  ::= L  <(value) number> E
3339
/*  ::= L  <(value) number> E
3191
                  ::= L  <(value) float> E
3340
                  ::= L  <(value) float> E
3192
                  ::= L  E
3341
                  ::= L  E
3193
*/
3342
*/
3194
 
3343
 
3195
static struct demangle_component *
3344
static struct demangle_component *
3196
d_expr_primary (struct d_info *di)
3345
d_expr_primary (struct d_info *di)
3197
{
3346
{
3198
  struct demangle_component *ret;
3347
  struct demangle_component *ret;
3199
 
3348
 
3200
  if (! d_check_char (di, 'L'))
3349
  if (! d_check_char (di, 'L'))
3201
    return NULL;
3350
    return NULL;
3202
  if (d_peek_char (di) == '_'
3351
  if (d_peek_char (di) == '_'
3203
      /* Workaround for G++ bug; see comment in write_template_arg.  */
3352
      /* Workaround for G++ bug; see comment in write_template_arg.  */
3204
      || d_peek_char (di) == 'Z')
3353
      || d_peek_char (di) == 'Z')
3205
    ret = cplus_demangle_mangled_name (di, 0);
3354
    ret = cplus_demangle_mangled_name (di, 0);
3206
  else
3355
  else
3207
    {
3356
    {
3208
      struct demangle_component *type;
3357
      struct demangle_component *type;
3209
      enum demangle_component_type t;
3358
      enum demangle_component_type t;
3210
      const char *s;
3359
      const char *s;
3211
 
3360
 
3212
      type = cplus_demangle_type (di);
3361
      type = cplus_demangle_type (di);
3213
      if (type == NULL)
3362
      if (type == NULL)
3214
	return NULL;
3363
	return NULL;
3215
 
3364
 
3216
      /* If we have a type we know how to print, we aren't going to
3365
      /* If we have a type we know how to print, we aren't going to
3217
	 print the type name itself.  */
3366
	 print the type name itself.  */
3218
      if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
3367
      if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
3219
	  && type->u.s_builtin.type->print != D_PRINT_DEFAULT)
3368
	  && type->u.s_builtin.type->print != D_PRINT_DEFAULT)
3220
	di->expansion -= type->u.s_builtin.type->len;
3369
	di->expansion -= type->u.s_builtin.type->len;
3221
 
3370
 
3222
      /* Rather than try to interpret the literal value, we just
3371
      /* Rather than try to interpret the literal value, we just
3223
	 collect it as a string.  Note that it's possible to have a
3372
	 collect it as a string.  Note that it's possible to have a
3224
	 floating point literal here.  The ABI specifies that the
3373
	 floating point literal here.  The ABI specifies that the
3225
	 format of such literals is machine independent.  That's fine,
3374
	 format of such literals is machine independent.  That's fine,
3226
	 but what's not fine is that versions of g++ up to 3.2 with
3375
	 but what's not fine is that versions of g++ up to 3.2 with
3227
	 -fabi-version=1 used upper case letters in the hex constant,
3376
	 -fabi-version=1 used upper case letters in the hex constant,
3228
	 and dumped out gcc's internal representation.  That makes it
3377
	 and dumped out gcc's internal representation.  That makes it
3229
	 hard to tell where the constant ends, and hard to dump the
3378
	 hard to tell where the constant ends, and hard to dump the
3230
	 constant in any readable form anyhow.  We don't attempt to
3379
	 constant in any readable form anyhow.  We don't attempt to
3231
	 handle these cases.  */
3380
	 handle these cases.  */
3232
 
3381
 
3233
      t = DEMANGLE_COMPONENT_LITERAL;
3382
      t = DEMANGLE_COMPONENT_LITERAL;
3234
      if (d_peek_char (di) == 'n')
3383
      if (d_peek_char (di) == 'n')
3235
	{
3384
	{
3236
	  t = DEMANGLE_COMPONENT_LITERAL_NEG;
3385
	  t = DEMANGLE_COMPONENT_LITERAL_NEG;
3237
	  d_advance (di, 1);
3386
	  d_advance (di, 1);
3238
	}
3387
	}
3239
      s = d_str (di);
3388
      s = d_str (di);
3240
      while (d_peek_char (di) != 'E')
3389
      while (d_peek_char (di) != 'E')
3241
	{
3390
	{
3242
	  if (d_peek_char (di) == '\0')
3391
	  if (d_peek_char (di) == '\0')
3243
	    return NULL;
3392
	    return NULL;
3244
	  d_advance (di, 1);
3393
	  d_advance (di, 1);
3245
	}
3394
	}
3246
      ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s));
3395
      ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s));
3247
    }
3396
    }
3248
  if (! d_check_char (di, 'E'))
3397
  if (! d_check_char (di, 'E'))
3249
    return NULL;
3398
    return NULL;
3250
  return ret;
3399
  return ret;
3251
}
3400
}
3252
 
3401
 
3253
/*  ::= Z <(function) encoding> E <(entity) name> []
3402
/*  ::= Z <(function) encoding> E <(entity) name> []
3254
                ::= Z <(function) encoding> E s []
3403
                ::= Z <(function) encoding> E s []
3255
                ::= Z <(function) encoding> E d [ number>] _ 
3404
                ::= Z <(function) encoding> E d [ number>] _ 
3256
*/
3405
*/
3257
 
3406
 
3258
static struct demangle_component *
3407
static struct demangle_component *
3259
d_local_name (struct d_info *di)
3408
d_local_name (struct d_info *di)
3260
{
3409
{
3261
  struct demangle_component *function;
3410
  struct demangle_component *function;
3262
 
3411
 
3263
  if (! d_check_char (di, 'Z'))
3412
  if (! d_check_char (di, 'Z'))
3264
    return NULL;
3413
    return NULL;
3265
 
3414
 
3266
  function = d_encoding (di, 0);
3415
  function = d_encoding (di, 0);
3267
 
3416
 
3268
  if (! d_check_char (di, 'E'))
3417
  if (! d_check_char (di, 'E'))
3269
    return NULL;
3418
    return NULL;
3270
 
3419
 
3271
  if (d_peek_char (di) == 's')
3420
  if (d_peek_char (di) == 's')
3272
    {
3421
    {
3273
      d_advance (di, 1);
3422
      d_advance (di, 1);
3274
      if (! d_discriminator (di))
3423
      if (! d_discriminator (di))
3275
	return NULL;
3424
	return NULL;
3276
      return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function,
3425
      return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function,
3277
			  d_make_name (di, "string literal",
3426
			  d_make_name (di, "string literal",
3278
				       sizeof "string literal" - 1));
3427
				       sizeof "string literal" - 1));
3279
    }
3428
    }
3280
  else
3429
  else
3281
    {
3430
    {
3282
      struct demangle_component *name;
3431
      struct demangle_component *name;
3283
      int num = -1;
3432
      int num = -1;
3284
 
3433
 
3285
      if (d_peek_char (di) == 'd')
3434
      if (d_peek_char (di) == 'd')
3286
	{
3435
	{
3287
	  /* Default argument scope: d  _.  */
3436
	  /* Default argument scope: d  _.  */
3288
	  d_advance (di, 1);
3437
	  d_advance (di, 1);
3289
	  num = d_compact_number (di);
3438
	  num = d_compact_number (di);
3290
	  if (num < 0)
3439
	  if (num < 0)
3291
	    return NULL;
3440
	    return NULL;
3292
	}
3441
	}
3293
 
3442
 
3294
      name = d_name (di);
3443
      name = d_name (di);
3295
      if (name)
3444
      if (name)
3296
	switch (name->type)
3445
	switch (name->type)
3297
	  {
3446
	  {
3298
	    /* Lambdas and unnamed types have internal discriminators.  */
3447
	    /* Lambdas and unnamed types have internal discriminators.  */
3299
	  case DEMANGLE_COMPONENT_LAMBDA:
3448
	  case DEMANGLE_COMPONENT_LAMBDA:
3300
	  case DEMANGLE_COMPONENT_UNNAMED_TYPE:
3449
	  case DEMANGLE_COMPONENT_UNNAMED_TYPE:
3301
	    break;
3450
	    break;
3302
	  default:
3451
	  default:
3303
	    if (! d_discriminator (di))
3452
	    if (! d_discriminator (di))
3304
	      return NULL;
3453
	      return NULL;
3305
	  }
3454
	  }
3306
      if (num >= 0)
3455
      if (num >= 0)
3307
	name = d_make_default_arg (di, num, name);
3456
	name = d_make_default_arg (di, num, name);
3308
      return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name);
3457
      return d_make_comp (di, DEMANGLE_COMPONENT_LOCAL_NAME, function, name);
3309
    }
3458
    }
3310
}
3459
}
3311
 
3460
 
3312
/*  ::= _ <(non-negative) number>
3461
/*  ::= _ <(non-negative) number>
3313
 
3462
 
3314
   We demangle the discriminator, but we don't print it out.  FIXME:
3463
   We demangle the discriminator, but we don't print it out.  FIXME:
3315
   We should print it out in verbose mode.  */
3464
   We should print it out in verbose mode.  */
3316
 
3465
 
3317
static int
3466
static int
3318
d_discriminator (struct d_info *di)
3467
d_discriminator (struct d_info *di)
3319
{
3468
{
3320
  long discrim;
3469
  long discrim;
3321
 
3470
 
3322
  if (d_peek_char (di) != '_')
3471
  if (d_peek_char (di) != '_')
3323
    return 1;
3472
    return 1;
3324
  d_advance (di, 1);
3473
  d_advance (di, 1);
3325
  discrim = d_number (di);
3474
  discrim = d_number (di);
3326
  if (discrim < 0)
3475
  if (discrim < 0)
3327
    return 0;
3476
    return 0;
3328
  return 1;
3477
  return 1;
3329
}
3478
}
3330
 
3479
 
3331
/*  ::= Ul  E [  ] _ */
3480
/*  ::= Ul  E [  ] _ */
3332
 
3481
 
3333
static struct demangle_component *
3482
static struct demangle_component *
3334
d_lambda (struct d_info *di)
3483
d_lambda (struct d_info *di)
3335
{
3484
{
3336
  struct demangle_component *tl;
3485
  struct demangle_component *tl;
3337
  struct demangle_component *ret;
3486
  struct demangle_component *ret;
3338
  int num;
3487
  int num;
3339
 
3488
 
3340
  if (! d_check_char (di, 'U'))
3489
  if (! d_check_char (di, 'U'))
3341
    return NULL;
3490
    return NULL;
3342
  if (! d_check_char (di, 'l'))
3491
  if (! d_check_char (di, 'l'))
3343
    return NULL;
3492
    return NULL;
3344
 
3493
 
3345
  tl = d_parmlist (di);
3494
  tl = d_parmlist (di);
3346
  if (tl == NULL)
3495
  if (tl == NULL)
3347
    return NULL;
3496
    return NULL;
3348
 
3497
 
3349
  if (! d_check_char (di, 'E'))
3498
  if (! d_check_char (di, 'E'))
3350
    return NULL;
3499
    return NULL;
3351
 
3500
 
3352
  num = d_compact_number (di);
3501
  num = d_compact_number (di);
3353
  if (num < 0)
3502
  if (num < 0)
3354
    return NULL;
3503
    return NULL;
3355
 
3504
 
3356
  ret = d_make_empty (di);
3505
  ret = d_make_empty (di);
3357
  if (ret)
3506
  if (ret)
3358
    {
3507
    {
3359
      ret->type = DEMANGLE_COMPONENT_LAMBDA;
3508
      ret->type = DEMANGLE_COMPONENT_LAMBDA;
3360
      ret->u.s_unary_num.sub = tl;
3509
      ret->u.s_unary_num.sub = tl;
3361
      ret->u.s_unary_num.num = num;
3510
      ret->u.s_unary_num.num = num;
3362
    }
3511
    }
3363
 
3512
 
3364
  if (! d_add_substitution (di, ret))
3513
  if (! d_add_substitution (di, ret))
3365
    return NULL;
3514
    return NULL;
3366
 
3515
 
3367
  return ret;
3516
  return ret;
3368
}
3517
}
3369
 
3518
 
3370
/*  ::= Ut [  ] _ */
3519
/*  ::= Ut [  ] _ */
3371
 
3520
 
3372
static struct demangle_component *
3521
static struct demangle_component *
3373
d_unnamed_type (struct d_info *di)
3522
d_unnamed_type (struct d_info *di)
3374
{
3523
{
3375
  struct demangle_component *ret;
3524
  struct demangle_component *ret;
3376
  long num;
3525
  long num;
3377
 
3526
 
3378
  if (! d_check_char (di, 'U'))
3527
  if (! d_check_char (di, 'U'))
3379
    return NULL;
3528
    return NULL;
3380
  if (! d_check_char (di, 't'))
3529
  if (! d_check_char (di, 't'))
3381
    return NULL;
3530
    return NULL;
3382
 
3531
 
3383
  num = d_compact_number (di);
3532
  num = d_compact_number (di);
3384
  if (num < 0)
3533
  if (num < 0)
3385
    return NULL;
3534
    return NULL;
3386
 
3535
 
3387
  ret = d_make_empty (di);
3536
  ret = d_make_empty (di);
3388
  if (ret)
3537
  if (ret)
3389
    {
3538
    {
3390
      ret->type = DEMANGLE_COMPONENT_UNNAMED_TYPE;
3539
      ret->type = DEMANGLE_COMPONENT_UNNAMED_TYPE;
3391
      ret->u.s_number.number = num;
3540
      ret->u.s_number.number = num;
3392
    }
3541
    }
3393
 
3542
 
3394
  if (! d_add_substitution (di, ret))
3543
  if (! d_add_substitution (di, ret))
3395
    return NULL;
3544
    return NULL;
3396
 
3545
 
3397
  return ret;
3546
  return ret;
3398
}
3547
}
3399
 
3548
 
3400
/*  ::= [ .  ] [ .  ]*
3549
/*  ::= [ .  ] [ .  ]*
3401
*/
3550
*/
3402
 
3551
 
3403
static struct demangle_component *
3552
static struct demangle_component *
3404
d_clone_suffix (struct d_info *di, struct demangle_component *encoding)
3553
d_clone_suffix (struct d_info *di, struct demangle_component *encoding)
3405
{
3554
{
3406
  const char *suffix = d_str (di);
3555
  const char *suffix = d_str (di);
3407
  const char *pend = suffix;
3556
  const char *pend = suffix;
3408
  struct demangle_component *n;
3557
  struct demangle_component *n;
3409
 
3558
 
3410
  if (*pend == '.' && (IS_LOWER (pend[1]) || pend[1] == '_'))
3559
  if (*pend == '.' && (IS_LOWER (pend[1]) || pend[1] == '_'))
3411
    {
3560
    {
3412
      pend += 2;
3561
      pend += 2;
3413
      while (IS_LOWER (*pend) || *pend == '_')
3562
      while (IS_LOWER (*pend) || *pend == '_')
3414
	++pend;
3563
	++pend;
3415
    }
3564
    }
3416
  while (*pend == '.' && IS_DIGIT (pend[1]))
3565
  while (*pend == '.' && IS_DIGIT (pend[1]))
3417
    {
3566
    {
3418
      pend += 2;
3567
      pend += 2;
3419
      while (IS_DIGIT (*pend))
3568
      while (IS_DIGIT (*pend))
3420
	++pend;
3569
	++pend;
3421
    }
3570
    }
3422
  d_advance (di, pend - suffix);
3571
  d_advance (di, pend - suffix);
3423
  n = d_make_name (di, suffix, pend - suffix);
3572
  n = d_make_name (di, suffix, pend - suffix);
3424
  return d_make_comp (di, DEMANGLE_COMPONENT_CLONE, encoding, n);
3573
  return d_make_comp (di, DEMANGLE_COMPONENT_CLONE, encoding, n);
3425
}
3574
}
3426
 
3575
 
3427
/* Add a new substitution.  */
3576
/* Add a new substitution.  */
3428
 
3577
 
3429
static int
3578
static int
3430
d_add_substitution (struct d_info *di, struct demangle_component *dc)
3579
d_add_substitution (struct d_info *di, struct demangle_component *dc)
3431
{
3580
{
3432
  if (dc == NULL)
3581
  if (dc == NULL)
3433
    return 0;
3582
    return 0;
3434
  if (di->next_sub >= di->num_subs)
3583
  if (di->next_sub >= di->num_subs)
3435
    return 0;
3584
    return 0;
3436
  di->subs[di->next_sub] = dc;
3585
  di->subs[di->next_sub] = dc;
3437
  ++di->next_sub;
3586
  ++di->next_sub;
3438
  return 1;
3587
  return 1;
3439
}
3588
}
3440
 
3589
 
3441
/*  ::= S  _
3590
/*  ::= S  _
3442
                  ::= S_
3591
                  ::= S_
3443
                  ::= St
3592
                  ::= St
3444
                  ::= Sa
3593
                  ::= Sa
3445
                  ::= Sb
3594
                  ::= Sb
3446
                  ::= Ss
3595
                  ::= Ss
3447
                  ::= Si
3596
                  ::= Si
3448
                  ::= So
3597
                  ::= So
3449
                  ::= Sd
3598
                  ::= Sd
3450
 
3599
 
3451
   If PREFIX is non-zero, then this type is being used as a prefix in
3600
   If PREFIX is non-zero, then this type is being used as a prefix in
3452
   a qualified name.  In this case, for the standard substitutions, we
3601
   a qualified name.  In this case, for the standard substitutions, we
3453
   need to check whether we are being used as a prefix for a
3602
   need to check whether we are being used as a prefix for a
3454
   constructor or destructor, and return a full template name.
3603
   constructor or destructor, and return a full template name.
3455
   Otherwise we will get something like std::iostream::~iostream()
3604
   Otherwise we will get something like std::iostream::~iostream()
3456
   which does not correspond particularly well to any function which
3605
   which does not correspond particularly well to any function which
3457
   actually appears in the source.
3606
   actually appears in the source.
3458
*/
3607
*/
3459
 
3608
 
3460
static const struct d_standard_sub_info standard_subs[] =
3609
static const struct d_standard_sub_info standard_subs[] =
3461
{
3610
{
3462
  { 't', NL ("std"),
3611
  { 't', NL ("std"),
3463
    NL ("std"),
3612
    NL ("std"),
3464
    NULL, 0 },
3613
    NULL, 0 },
3465
  { 'a', NL ("std::allocator"),
3614
  { 'a', NL ("std::allocator"),
3466
    NL ("std::allocator"),
3615
    NL ("std::allocator"),
3467
    NL ("allocator") },
3616
    NL ("allocator") },
3468
  { 'b', NL ("std::basic_string"),
3617
  { 'b', NL ("std::basic_string"),
3469
    NL ("std::basic_string"),
3618
    NL ("std::basic_string"),
3470
    NL ("basic_string") },
3619
    NL ("basic_string") },
3471
  { 's', NL ("std::string"),
3620
  { 's', NL ("std::string"),
3472
    NL ("std::basic_string, std::allocator >"),
3621
    NL ("std::basic_string, std::allocator >"),
3473
    NL ("basic_string") },
3622
    NL ("basic_string") },
3474
  { 'i', NL ("std::istream"),
3623
  { 'i', NL ("std::istream"),
3475
    NL ("std::basic_istream >"),
3624
    NL ("std::basic_istream >"),
3476
    NL ("basic_istream") },
3625
    NL ("basic_istream") },
3477
  { 'o', NL ("std::ostream"),
3626
  { 'o', NL ("std::ostream"),
3478
    NL ("std::basic_ostream >"),
3627
    NL ("std::basic_ostream >"),
3479
    NL ("basic_ostream") },
3628
    NL ("basic_ostream") },
3480
  { 'd', NL ("std::iostream"),
3629
  { 'd', NL ("std::iostream"),
3481
    NL ("std::basic_iostream >"),
3630
    NL ("std::basic_iostream >"),
3482
    NL ("basic_iostream") }
3631
    NL ("basic_iostream") }
3483
};
3632
};
3484
 
3633
 
3485
static struct demangle_component *
3634
static struct demangle_component *
3486
d_substitution (struct d_info *di, int prefix)
3635
d_substitution (struct d_info *di, int prefix)
3487
{
3636
{
3488
  char c;
3637
  char c;
3489
 
3638
 
3490
  if (! d_check_char (di, 'S'))
3639
  if (! d_check_char (di, 'S'))
3491
    return NULL;
3640
    return NULL;
3492
 
3641
 
3493
  c = d_next_char (di);
3642
  c = d_next_char (di);
3494
  if (c == '_' || IS_DIGIT (c) || IS_UPPER (c))
3643
  if (c == '_' || IS_DIGIT (c) || IS_UPPER (c))
3495
    {
3644
    {
3496
      unsigned int id;
3645
      unsigned int id;
3497
 
3646
 
3498
      id = 0;
3647
      id = 0;
3499
      if (c != '_')
3648
      if (c != '_')
3500
	{
3649
	{
3501
	  do
3650
	  do
3502
	    {
3651
	    {
3503
	      unsigned int new_id;
3652
	      unsigned int new_id;
3504
 
3653
 
3505
	      if (IS_DIGIT (c))
3654
	      if (IS_DIGIT (c))
3506
		new_id = id * 36 + c - '0';
3655
		new_id = id * 36 + c - '0';
3507
	      else if (IS_UPPER (c))
3656
	      else if (IS_UPPER (c))
3508
		new_id = id * 36 + c - 'A' + 10;
3657
		new_id = id * 36 + c - 'A' + 10;
3509
	      else
3658
	      else
3510
		return NULL;
3659
		return NULL;
3511
	      if (new_id < id)
3660
	      if (new_id < id)
3512
		return NULL;
3661
		return NULL;
3513
	      id = new_id;
3662
	      id = new_id;
3514
	      c = d_next_char (di);
3663
	      c = d_next_char (di);
3515
	    }
3664
	    }
3516
	  while (c != '_');
3665
	  while (c != '_');
3517
 
3666
 
3518
	  ++id;
3667
	  ++id;
3519
	}
3668
	}
3520
 
3669
 
3521
      if (id >= (unsigned int) di->next_sub)
3670
      if (id >= (unsigned int) di->next_sub)
3522
	return NULL;
3671
	return NULL;
3523
 
3672
 
3524
      ++di->did_subs;
3673
      ++di->did_subs;
3525
 
3674
 
3526
      return di->subs[id];
3675
      return di->subs[id];
3527
    }
3676
    }
3528
  else
3677
  else
3529
    {
3678
    {
3530
      int verbose;
3679
      int verbose;
3531
      const struct d_standard_sub_info *p;
3680
      const struct d_standard_sub_info *p;
3532
      const struct d_standard_sub_info *pend;
3681
      const struct d_standard_sub_info *pend;
3533
 
3682
 
3534
      verbose = (di->options & DMGL_VERBOSE) != 0;
3683
      verbose = (di->options & DMGL_VERBOSE) != 0;
3535
      if (! verbose && prefix)
3684
      if (! verbose && prefix)
3536
	{
3685
	{
3537
	  char peek;
3686
	  char peek;
3538
 
3687
 
3539
	  peek = d_peek_char (di);
3688
	  peek = d_peek_char (di);
3540
	  if (peek == 'C' || peek == 'D')
3689
	  if (peek == 'C' || peek == 'D')
3541
	    verbose = 1;
3690
	    verbose = 1;
3542
	}
3691
	}
3543
 
3692
 
3544
      pend = (&standard_subs[0]
3693
      pend = (&standard_subs[0]
3545
	      + sizeof standard_subs / sizeof standard_subs[0]);
3694
	      + sizeof standard_subs / sizeof standard_subs[0]);
3546
      for (p = &standard_subs[0]; p < pend; ++p)
3695
      for (p = &standard_subs[0]; p < pend; ++p)
3547
	{
3696
	{
3548
	  if (c == p->code)
3697
	  if (c == p->code)
3549
	    {
3698
	    {
3550
	      const char *s;
3699
	      const char *s;
3551
	      int len;
3700
	      int len;
-
 
3701
	      struct demangle_component *c;
3552
 
3702
 
3553
	      if (p->set_last_name != NULL)
3703
	      if (p->set_last_name != NULL)
3554
		di->last_name = d_make_sub (di, p->set_last_name,
3704
		di->last_name = d_make_sub (di, p->set_last_name,
3555
					    p->set_last_name_len);
3705
					    p->set_last_name_len);
3556
	      if (verbose)
3706
	      if (verbose)
3557
		{
3707
		{
3558
		  s = p->full_expansion;
3708
		  s = p->full_expansion;
3559
		  len = p->full_len;
3709
		  len = p->full_len;
3560
		}
3710
		}
3561
	      else
3711
	      else
3562
		{
3712
		{
3563
		  s = p->simple_expansion;
3713
		  s = p->simple_expansion;
3564
		  len = p->simple_len;
3714
		  len = p->simple_len;
3565
		}
3715
		}
3566
	      di->expansion += len;
3716
	      di->expansion += len;
3567
	      return d_make_sub (di, s, len);
3717
	      c = d_make_sub (di, s, len);
-
 
3718
	      if (d_peek_char (di) == 'B')
-
 
3719
		{
-
 
3720
		  /* If there are ABI tags on the abbreviation, it becomes
-
 
3721
		     a substitution candidate.  */
-
 
3722
		  c = d_abi_tags (di, c);
-
 
3723
		  d_add_substitution (di, c);
-
 
3724
		}
-
 
3725
	      return c;
3568
	    }
3726
	    }
3569
	}
3727
	}
3570
 
3728
 
3571
      return NULL;
3729
      return NULL;
3572
    }
3730
    }
3573
}
3731
}
-
 
3732
 
-
 
3733
static void
-
 
3734
d_checkpoint (struct d_info *di, struct d_info_checkpoint *checkpoint)
-
 
3735
{
-
 
3736
  checkpoint->n = di->n;
-
 
3737
  checkpoint->next_comp = di->next_comp;
-
 
3738
  checkpoint->next_sub = di->next_sub;
-
 
3739
  checkpoint->did_subs = di->did_subs;
-
 
3740
  checkpoint->expansion = di->expansion;
-
 
3741
}
-
 
3742
 
-
 
3743
static void
-
 
3744
d_backtrack (struct d_info *di, struct d_info_checkpoint *checkpoint)
-
 
3745
{
-
 
3746
  di->n = checkpoint->n;
-
 
3747
  di->next_comp = checkpoint->next_comp;
-
 
3748
  di->next_sub = checkpoint->next_sub;
-
 
3749
  di->did_subs = checkpoint->did_subs;
-
 
3750
  di->expansion = checkpoint->expansion;
-
 
3751
}
3574
 
3752
 
3575
/* Initialize a growable string.  */
3753
/* Initialize a growable string.  */
3576
 
3754
 
3577
static void
3755
static void
3578
d_growable_string_init (struct d_growable_string *dgs, size_t estimate)
3756
d_growable_string_init (struct d_growable_string *dgs, size_t estimate)
3579
{
3757
{
3580
  dgs->buf = NULL;
3758
  dgs->buf = NULL;
3581
  dgs->len = 0;
3759
  dgs->len = 0;
3582
  dgs->alc = 0;
3760
  dgs->alc = 0;
3583
  dgs->allocation_failure = 0;
3761
  dgs->allocation_failure = 0;
3584
 
3762
 
3585
  if (estimate > 0)
3763
  if (estimate > 0)
3586
    d_growable_string_resize (dgs, estimate);
3764
    d_growable_string_resize (dgs, estimate);
3587
}
3765
}
3588
 
3766
 
3589
/* Grow a growable string to a given size.  */
3767
/* Grow a growable string to a given size.  */
3590
 
3768
 
3591
static inline void
3769
static inline void
3592
d_growable_string_resize (struct d_growable_string *dgs, size_t need)
3770
d_growable_string_resize (struct d_growable_string *dgs, size_t need)
3593
{
3771
{
3594
  size_t newalc;
3772
  size_t newalc;
3595
  char *newbuf;
3773
  char *newbuf;
3596
 
3774
 
3597
  if (dgs->allocation_failure)
3775
  if (dgs->allocation_failure)
3598
    return;
3776
    return;
3599
 
3777
 
3600
  /* Start allocation at two bytes to avoid any possibility of confusion
3778
  /* Start allocation at two bytes to avoid any possibility of confusion
3601
     with the special value of 1 used as a return in *palc to indicate
3779
     with the special value of 1 used as a return in *palc to indicate
3602
     allocation failures.  */
3780
     allocation failures.  */
3603
  newalc = dgs->alc > 0 ? dgs->alc : 2;
3781
  newalc = dgs->alc > 0 ? dgs->alc : 2;
3604
  while (newalc < need)
3782
  while (newalc < need)
3605
    newalc <<= 1;
3783
    newalc <<= 1;
3606
 
3784
 
3607
  newbuf = (char *) realloc (dgs->buf, newalc);
3785
  newbuf = (char *) realloc (dgs->buf, newalc);
3608
  if (newbuf == NULL)
3786
  if (newbuf == NULL)
3609
    {
3787
    {
3610
      free (dgs->buf);
3788
      free (dgs->buf);
3611
      dgs->buf = NULL;
3789
      dgs->buf = NULL;
3612
      dgs->len = 0;
3790
      dgs->len = 0;
3613
      dgs->alc = 0;
3791
      dgs->alc = 0;
3614
      dgs->allocation_failure = 1;
3792
      dgs->allocation_failure = 1;
3615
      return;
3793
      return;
3616
    }
3794
    }
3617
  dgs->buf = newbuf;
3795
  dgs->buf = newbuf;
3618
  dgs->alc = newalc;
3796
  dgs->alc = newalc;
3619
}
3797
}
3620
 
3798
 
3621
/* Append a buffer to a growable string.  */
3799
/* Append a buffer to a growable string.  */
3622
 
3800
 
3623
static inline void
3801
static inline void
3624
d_growable_string_append_buffer (struct d_growable_string *dgs,
3802
d_growable_string_append_buffer (struct d_growable_string *dgs,
3625
                                 const char *s, size_t l)
3803
                                 const char *s, size_t l)
3626
{
3804
{
3627
  size_t need;
3805
  size_t need;
3628
 
3806
 
3629
  need = dgs->len + l + 1;
3807
  need = dgs->len + l + 1;
3630
  if (need > dgs->alc)
3808
  if (need > dgs->alc)
3631
    d_growable_string_resize (dgs, need);
3809
    d_growable_string_resize (dgs, need);
3632
 
3810
 
3633
  if (dgs->allocation_failure)
3811
  if (dgs->allocation_failure)
3634
    return;
3812
    return;
3635
 
3813
 
3636
  memcpy (dgs->buf + dgs->len, s, l);
3814
  memcpy (dgs->buf + dgs->len, s, l);
3637
  dgs->buf[dgs->len + l] = '\0';
3815
  dgs->buf[dgs->len + l] = '\0';
3638
  dgs->len += l;
3816
  dgs->len += l;
3639
}
3817
}
3640
 
3818
 
3641
/* Bridge growable strings to the callback mechanism.  */
3819
/* Bridge growable strings to the callback mechanism.  */
3642
 
3820
 
3643
static void
3821
static void
3644
d_growable_string_callback_adapter (const char *s, size_t l, void *opaque)
3822
d_growable_string_callback_adapter (const char *s, size_t l, void *opaque)
3645
{
3823
{
3646
  struct d_growable_string *dgs = (struct d_growable_string*) opaque;
3824
  struct d_growable_string *dgs = (struct d_growable_string*) opaque;
3647
 
3825
 
3648
  d_growable_string_append_buffer (dgs, s, l);
3826
  d_growable_string_append_buffer (dgs, s, l);
3649
}
3827
}
-
 
3828
 
-
 
3829
/* Walk the tree, counting the number of templates encountered, and
-
 
3830
   the number of times a scope might be saved.  These counts will be
-
 
3831
   used to allocate data structures for d_print_comp, so the logic
-
 
3832
   here must mirror the logic d_print_comp will use.  It is not
-
 
3833
   important that the resulting numbers are exact, so long as they
-
 
3834
   are larger than the actual numbers encountered.  */
-
 
3835
 
-
 
3836
static void
-
 
3837
d_count_templates_scopes (int *num_templates, int *num_scopes,
-
 
3838
			  const struct demangle_component *dc)
-
 
3839
{
-
 
3840
  if (dc == NULL)
-
 
3841
    return;
-
 
3842
 
-
 
3843
  switch (dc->type)
-
 
3844
    {
-
 
3845
    case DEMANGLE_COMPONENT_NAME:
-
 
3846
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
-
 
3847
    case DEMANGLE_COMPONENT_FUNCTION_PARAM:
-
 
3848
    case DEMANGLE_COMPONENT_SUB_STD:
-
 
3849
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
-
 
3850
    case DEMANGLE_COMPONENT_OPERATOR:
-
 
3851
    case DEMANGLE_COMPONENT_CHARACTER:
-
 
3852
    case DEMANGLE_COMPONENT_NUMBER:
-
 
3853
    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
-
 
3854
      break;
-
 
3855
 
-
 
3856
    case DEMANGLE_COMPONENT_TEMPLATE:
-
 
3857
      (*num_templates)++;
-
 
3858
      goto recurse_left_right;
-
 
3859
 
-
 
3860
    case DEMANGLE_COMPONENT_REFERENCE:
-
 
3861
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
-
 
3862
      if (d_left (dc)->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
-
 
3863
	(*num_scopes)++;
-
 
3864
      goto recurse_left_right;
-
 
3865
 
-
 
3866
    case DEMANGLE_COMPONENT_QUAL_NAME:
-
 
3867
    case DEMANGLE_COMPONENT_LOCAL_NAME:
-
 
3868
    case DEMANGLE_COMPONENT_TYPED_NAME:
-
 
3869
    case DEMANGLE_COMPONENT_VTABLE:
-
 
3870
    case DEMANGLE_COMPONENT_VTT:
-
 
3871
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
-
 
3872
    case DEMANGLE_COMPONENT_TYPEINFO:
-
 
3873
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
-
 
3874
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
-
 
3875
    case DEMANGLE_COMPONENT_THUNK:
-
 
3876
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
-
 
3877
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
-
 
3878
    case DEMANGLE_COMPONENT_JAVA_CLASS:
-
 
3879
    case DEMANGLE_COMPONENT_GUARD:
-
 
3880
    case DEMANGLE_COMPONENT_TLS_INIT:
-
 
3881
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
-
 
3882
    case DEMANGLE_COMPONENT_REFTEMP:
-
 
3883
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
-
 
3884
    case DEMANGLE_COMPONENT_RESTRICT:
-
 
3885
    case DEMANGLE_COMPONENT_VOLATILE:
-
 
3886
    case DEMANGLE_COMPONENT_CONST:
-
 
3887
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
-
 
3888
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
-
 
3889
    case DEMANGLE_COMPONENT_CONST_THIS:
-
 
3890
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
-
 
3891
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
-
 
3892
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
-
 
3893
    case DEMANGLE_COMPONENT_POINTER:
-
 
3894
    case DEMANGLE_COMPONENT_COMPLEX:
-
 
3895
    case DEMANGLE_COMPONENT_IMAGINARY:
-
 
3896
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
-
 
3897
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
-
 
3898
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
-
 
3899
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
-
 
3900
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
-
 
3901
    case DEMANGLE_COMPONENT_ARGLIST:
-
 
3902
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
-
 
3903
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
-
 
3904
    case DEMANGLE_COMPONENT_CAST:
-
 
3905
    case DEMANGLE_COMPONENT_NULLARY:
-
 
3906
    case DEMANGLE_COMPONENT_UNARY:
-
 
3907
    case DEMANGLE_COMPONENT_BINARY:
-
 
3908
    case DEMANGLE_COMPONENT_BINARY_ARGS:
-
 
3909
    case DEMANGLE_COMPONENT_TRINARY:
-
 
3910
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
-
 
3911
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
-
 
3912
    case DEMANGLE_COMPONENT_LITERAL:
-
 
3913
    case DEMANGLE_COMPONENT_LITERAL_NEG:
-
 
3914
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
-
 
3915
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
-
 
3916
    case DEMANGLE_COMPONENT_DECLTYPE:
-
 
3917
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
-
 
3918
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
-
 
3919
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
-
 
3920
    case DEMANGLE_COMPONENT_TAGGED_NAME:
-
 
3921
    case DEMANGLE_COMPONENT_CLONE:
-
 
3922
    recurse_left_right:
-
 
3923
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3924
				d_left (dc));
-
 
3925
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3926
				d_right (dc));
-
 
3927
      break;
-
 
3928
 
-
 
3929
    case DEMANGLE_COMPONENT_CTOR:
-
 
3930
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3931
				dc->u.s_ctor.name);
-
 
3932
      break;
-
 
3933
 
-
 
3934
    case DEMANGLE_COMPONENT_DTOR:
-
 
3935
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3936
				dc->u.s_dtor.name);
-
 
3937
      break;
-
 
3938
 
-
 
3939
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
-
 
3940
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3941
				dc->u.s_extended_operator.name);
-
 
3942
      break;
-
 
3943
 
-
 
3944
    case DEMANGLE_COMPONENT_FIXED_TYPE:
-
 
3945
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3946
                                dc->u.s_fixed.length);
-
 
3947
      break;
-
 
3948
 
-
 
3949
    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
-
 
3950
    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
-
 
3951
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3952
				d_left (dc));
-
 
3953
      break;
-
 
3954
 
-
 
3955
    case DEMANGLE_COMPONENT_LAMBDA:
-
 
3956
    case DEMANGLE_COMPONENT_DEFAULT_ARG:
-
 
3957
      d_count_templates_scopes (num_templates, num_scopes,
-
 
3958
				dc->u.s_unary_num.sub);
-
 
3959
      break;
-
 
3960
    }
-
 
3961
}
3650
 
3962
 
3651
/* Initialize a print information structure.  */
3963
/* Initialize a print information structure.  */
3652
 
3964
 
3653
static void
3965
static void
3654
d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
3966
d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
3655
	      void *opaque)
3967
	      void *opaque, const struct demangle_component *dc)
3656
{
3968
{
3657
  dpi->len = 0;
3969
  dpi->len = 0;
3658
  dpi->last_char = '\0';
3970
  dpi->last_char = '\0';
3659
  dpi->templates = NULL;
3971
  dpi->templates = NULL;
3660
  dpi->modifiers = NULL;
3972
  dpi->modifiers = NULL;
3661
  dpi->pack_index = 0;
3973
  dpi->pack_index = 0;
3662
  dpi->flush_count = 0;
3974
  dpi->flush_count = 0;
3663
 
3975
 
3664
  dpi->callback = callback;
3976
  dpi->callback = callback;
3665
  dpi->opaque = opaque;
3977
  dpi->opaque = opaque;
3666
 
3978
 
3667
  dpi->demangle_failure = 0;
3979
  dpi->demangle_failure = 0;
-
 
3980
 
-
 
3981
  dpi->component_stack = NULL;
-
 
3982
 
-
 
3983
  dpi->saved_scopes = NULL;
-
 
3984
  dpi->next_saved_scope = 0;
-
 
3985
  dpi->num_saved_scopes = 0;
-
 
3986
 
-
 
3987
  dpi->copy_templates = NULL;
-
 
3988
  dpi->next_copy_template = 0;
-
 
3989
  dpi->num_copy_templates = 0;
-
 
3990
 
-
 
3991
  d_count_templates_scopes (&dpi->num_copy_templates,
-
 
3992
			    &dpi->num_saved_scopes, dc);
-
 
3993
  dpi->num_copy_templates *= dpi->num_saved_scopes;
-
 
3994
 
-
 
3995
  dpi->current_template = NULL;
3668
}
3996
}
3669
 
3997
 
3670
/* Indicate that an error occurred during printing, and test for error.  */
3998
/* Indicate that an error occurred during printing, and test for error.  */
3671
 
3999
 
3672
static inline void
4000
static inline void
3673
d_print_error (struct d_print_info *dpi)
4001
d_print_error (struct d_print_info *dpi)
3674
{
4002
{
3675
  dpi->demangle_failure = 1;
4003
  dpi->demangle_failure = 1;
3676
}
4004
}
3677
 
4005
 
3678
static inline int
4006
static inline int
3679
d_print_saw_error (struct d_print_info *dpi)
4007
d_print_saw_error (struct d_print_info *dpi)
3680
{
4008
{
3681
  return dpi->demangle_failure != 0;
4009
  return dpi->demangle_failure != 0;
3682
}
4010
}
3683
 
4011
 
3684
/* Flush buffered characters to the callback.  */
4012
/* Flush buffered characters to the callback.  */
3685
 
4013
 
3686
static inline void
4014
static inline void
3687
d_print_flush (struct d_print_info *dpi)
4015
d_print_flush (struct d_print_info *dpi)
3688
{
4016
{
3689
  dpi->buf[dpi->len] = '\0';
4017
  dpi->buf[dpi->len] = '\0';
3690
  dpi->callback (dpi->buf, dpi->len, dpi->opaque);
4018
  dpi->callback (dpi->buf, dpi->len, dpi->opaque);
3691
  dpi->len = 0;
4019
  dpi->len = 0;
3692
  dpi->flush_count++;
4020
  dpi->flush_count++;
3693
}
4021
}
3694
 
4022
 
3695
/* Append characters and buffers for printing.  */
4023
/* Append characters and buffers for printing.  */
3696
 
4024
 
3697
static inline void
4025
static inline void
3698
d_append_char (struct d_print_info *dpi, char c)
4026
d_append_char (struct d_print_info *dpi, char c)
3699
{
4027
{
3700
  if (dpi->len == sizeof (dpi->buf) - 1)
4028
  if (dpi->len == sizeof (dpi->buf) - 1)
3701
    d_print_flush (dpi);
4029
    d_print_flush (dpi);
3702
 
4030
 
3703
  dpi->buf[dpi->len++] = c;
4031
  dpi->buf[dpi->len++] = c;
3704
  dpi->last_char = c;
4032
  dpi->last_char = c;
3705
}
4033
}
3706
 
4034
 
3707
static inline void
4035
static inline void
3708
d_append_buffer (struct d_print_info *dpi, const char *s, size_t l)
4036
d_append_buffer (struct d_print_info *dpi, const char *s, size_t l)
3709
{
4037
{
3710
  size_t i;
4038
  size_t i;
3711
 
4039
 
3712
  for (i = 0; i < l; i++)
4040
  for (i = 0; i < l; i++)
3713
    d_append_char (dpi, s[i]);
4041
    d_append_char (dpi, s[i]);
3714
}
4042
}
3715
 
4043
 
3716
static inline void
4044
static inline void
3717
d_append_string (struct d_print_info *dpi, const char *s)
4045
d_append_string (struct d_print_info *dpi, const char *s)
3718
{
4046
{
3719
  d_append_buffer (dpi, s, strlen (s));
4047
  d_append_buffer (dpi, s, strlen (s));
3720
}
4048
}
3721
 
4049
 
3722
static inline void
4050
static inline void
3723
d_append_num (struct d_print_info *dpi, long l)
4051
d_append_num (struct d_print_info *dpi, long l)
3724
{
4052
{
3725
  char buf[25];
4053
  char buf[25];
3726
  sprintf (buf,"%ld", l);
4054
  sprintf (buf,"%ld", l);
3727
  d_append_string (dpi, buf);
4055
  d_append_string (dpi, buf);
3728
}
4056
}
3729
 
4057
 
3730
static inline char
4058
static inline char
3731
d_last_char (struct d_print_info *dpi)
4059
d_last_char (struct d_print_info *dpi)
3732
{
4060
{
3733
  return dpi->last_char;
4061
  return dpi->last_char;
3734
}
4062
}
3735
 
4063
 
3736
/* Turn components into a human readable string.  OPTIONS is the
4064
/* Turn components into a human readable string.  OPTIONS is the
3737
   options bits passed to the demangler.  DC is the tree to print.
4065
   options bits passed to the demangler.  DC is the tree to print.
3738
   CALLBACK is a function to call to flush demangled string segments
4066
   CALLBACK is a function to call to flush demangled string segments
3739
   as they fill the intermediate buffer, and OPAQUE is a generalized
4067
   as they fill the intermediate buffer, and OPAQUE is a generalized
3740
   callback argument.  On success, this returns 1.  On failure,
4068
   callback argument.  On success, this returns 1.  On failure,
3741
   it returns 0, indicating a bad parse.  It does not use heap
4069
   it returns 0, indicating a bad parse.  It does not use heap
3742
   memory to build an output string, so cannot encounter memory
4070
   memory to build an output string, so cannot encounter memory
3743
   allocation failure.  */
4071
   allocation failure.  */
3744
 
4072
 
3745
CP_STATIC_IF_GLIBCPP_V3
4073
CP_STATIC_IF_GLIBCPP_V3
3746
int
4074
int
3747
cplus_demangle_print_callback (int options,
4075
cplus_demangle_print_callback (int options,
3748
                               const struct demangle_component *dc,
4076
                               const struct demangle_component *dc,
3749
                               demangle_callbackref callback, void *opaque)
4077
                               demangle_callbackref callback, void *opaque)
3750
{
4078
{
3751
  struct d_print_info dpi;
4079
  struct d_print_info dpi;
3752
 
4080
 
-
 
4081
  d_print_init (&dpi, callback, opaque, dc);
-
 
4082
 
-
 
4083
  {
-
 
4084
#ifdef CP_DYNAMIC_ARRAYS
-
 
4085
    __extension__ struct d_saved_scope scopes[dpi.num_saved_scopes];
-
 
4086
    __extension__ struct d_print_template temps[dpi.num_copy_templates];
-
 
4087
 
-
 
4088
    dpi.saved_scopes = scopes;
-
 
4089
    dpi.copy_templates = temps;
-
 
4090
#else
-
 
4091
    dpi.saved_scopes = alloca (dpi.num_saved_scopes
-
 
4092
			       * sizeof (*dpi.saved_scopes));
-
 
4093
    dpi.copy_templates = alloca (dpi.num_copy_templates
-
 
4094
				 * sizeof (*dpi.copy_templates));
3753
  d_print_init (&dpi, callback, opaque);
4095
#endif
-
 
4096
 
3754
 
4097
  d_print_comp (&dpi, options, dc);
3755
  d_print_comp (&dpi, options, dc);
4098
  }
3756
 
4099
 
3757
  d_print_flush (&dpi);
4100
  d_print_flush (&dpi);
3758
 
4101
 
3759
  return ! d_print_saw_error (&dpi);
4102
  return ! d_print_saw_error (&dpi);
3760
}
4103
}
3761
 
4104
 
3762
/* Turn components into a human readable string.  OPTIONS is the
4105
/* Turn components into a human readable string.  OPTIONS is the
3763
   options bits passed to the demangler.  DC is the tree to print.
4106
   options bits passed to the demangler.  DC is the tree to print.
3764
   ESTIMATE is a guess at the length of the result.  This returns a
4107
   ESTIMATE is a guess at the length of the result.  This returns a
3765
   string allocated by malloc, or NULL on error.  On success, this
4108
   string allocated by malloc, or NULL on error.  On success, this
3766
   sets *PALC to the size of the allocated buffer.  On failure, this
4109
   sets *PALC to the size of the allocated buffer.  On failure, this
3767
   sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4110
   sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3768
   failure.  */
4111
   failure.  */
3769
 
4112
 
3770
CP_STATIC_IF_GLIBCPP_V3
4113
CP_STATIC_IF_GLIBCPP_V3
3771
char *
4114
char *
3772
cplus_demangle_print (int options, const struct demangle_component *dc,
4115
cplus_demangle_print (int options, const struct demangle_component *dc,
3773
                      int estimate, size_t *palc)
4116
                      int estimate, size_t *palc)
3774
{
4117
{
3775
  struct d_growable_string dgs;
4118
  struct d_growable_string dgs;
3776
 
4119
 
3777
  d_growable_string_init (&dgs, estimate);
4120
  d_growable_string_init (&dgs, estimate);
3778
 
4121
 
3779
  if (! cplus_demangle_print_callback (options, dc,
4122
  if (! cplus_demangle_print_callback (options, dc,
3780
                                       d_growable_string_callback_adapter,
4123
                                       d_growable_string_callback_adapter,
3781
                                       &dgs))
4124
                                       &dgs))
3782
    {
4125
    {
3783
      free (dgs.buf);
4126
      free (dgs.buf);
3784
      *palc = 0;
4127
      *palc = 0;
3785
      return NULL;
4128
      return NULL;
3786
    }
4129
    }
3787
 
4130
 
3788
  *palc = dgs.allocation_failure ? 1 : dgs.alc;
4131
  *palc = dgs.allocation_failure ? 1 : dgs.alc;
3789
  return dgs.buf;
4132
  return dgs.buf;
3790
}
4133
}
3791
 
4134
 
3792
/* Returns the I'th element of the template arglist ARGS, or NULL on
4135
/* Returns the I'th element of the template arglist ARGS, or NULL on
3793
   failure.  */
4136
   failure.  */
3794
 
4137
 
3795
static struct demangle_component *
4138
static struct demangle_component *
3796
d_index_template_argument (struct demangle_component *args, int i)
4139
d_index_template_argument (struct demangle_component *args, int i)
3797
{
4140
{
3798
  struct demangle_component *a;
4141
  struct demangle_component *a;
3799
 
4142
 
3800
  for (a = args;
4143
  for (a = args;
3801
       a != NULL;
4144
       a != NULL;
3802
       a = d_right (a))
4145
       a = d_right (a))
3803
    {
4146
    {
3804
      if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
4147
      if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
3805
	return NULL;
4148
	return NULL;
3806
      if (i <= 0)
4149
      if (i <= 0)
3807
	break;
4150
	break;
3808
      --i;
4151
      --i;
3809
    }
4152
    }
3810
  if (i != 0 || a == NULL)
4153
  if (i != 0 || a == NULL)
3811
    return NULL;
4154
    return NULL;
3812
 
4155
 
3813
  return d_left (a);
4156
  return d_left (a);
3814
}
4157
}
3815
 
4158
 
3816
/* Returns the template argument from the current context indicated by DC,
4159
/* Returns the template argument from the current context indicated by DC,
3817
   which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL.  */
4160
   which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL.  */
3818
 
4161
 
3819
static struct demangle_component *
4162
static struct demangle_component *
3820
d_lookup_template_argument (struct d_print_info *dpi,
4163
d_lookup_template_argument (struct d_print_info *dpi,
3821
			    const struct demangle_component *dc)
4164
			    const struct demangle_component *dc)
3822
{
4165
{
3823
  if (dpi->templates == NULL)
4166
  if (dpi->templates == NULL)
3824
    {
4167
    {
3825
      d_print_error (dpi);
4168
      d_print_error (dpi);
3826
      return NULL;
4169
      return NULL;
3827
    }
4170
    }
3828
	
4171
	
3829
  return d_index_template_argument
4172
  return d_index_template_argument
3830
    (d_right (dpi->templates->template_decl),
4173
    (d_right (dpi->templates->template_decl),
3831
     dc->u.s_number.number);
4174
     dc->u.s_number.number);
3832
}
4175
}
3833
 
4176
 
3834
/* Returns a template argument pack used in DC (any will do), or NULL.  */
4177
/* Returns a template argument pack used in DC (any will do), or NULL.  */
3835
 
4178
 
3836
static struct demangle_component *
4179
static struct demangle_component *
3837
d_find_pack (struct d_print_info *dpi,
4180
d_find_pack (struct d_print_info *dpi,
3838
	     const struct demangle_component *dc)
4181
	     const struct demangle_component *dc)
3839
{
4182
{
3840
  struct demangle_component *a;
4183
  struct demangle_component *a;
3841
  if (dc == NULL)
4184
  if (dc == NULL)
3842
    return NULL;
4185
    return NULL;
3843
 
4186
 
3844
  switch (dc->type)
4187
  switch (dc->type)
3845
    {
4188
    {
3846
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
4189
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
3847
      a = d_lookup_template_argument (dpi, dc);
4190
      a = d_lookup_template_argument (dpi, dc);
3848
      if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
4191
      if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
3849
	return a;
4192
	return a;
3850
      return NULL;
4193
      return NULL;
3851
 
4194
 
3852
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
4195
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
3853
      return NULL;
4196
      return NULL;
3854
      
4197
      
3855
    case DEMANGLE_COMPONENT_LAMBDA:
4198
    case DEMANGLE_COMPONENT_LAMBDA:
3856
    case DEMANGLE_COMPONENT_NAME:
4199
    case DEMANGLE_COMPONENT_NAME:
3857
    case DEMANGLE_COMPONENT_TAGGED_NAME:
4200
    case DEMANGLE_COMPONENT_TAGGED_NAME:
3858
    case DEMANGLE_COMPONENT_OPERATOR:
4201
    case DEMANGLE_COMPONENT_OPERATOR:
3859
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
4202
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
3860
    case DEMANGLE_COMPONENT_SUB_STD:
4203
    case DEMANGLE_COMPONENT_SUB_STD:
3861
    case DEMANGLE_COMPONENT_CHARACTER:
4204
    case DEMANGLE_COMPONENT_CHARACTER:
3862
    case DEMANGLE_COMPONENT_FUNCTION_PARAM:
4205
    case DEMANGLE_COMPONENT_FUNCTION_PARAM:
3863
    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
4206
    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
3864
      return NULL;
4207
      return NULL;
3865
 
4208
 
3866
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
4209
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
3867
      return d_find_pack (dpi, dc->u.s_extended_operator.name);
4210
      return d_find_pack (dpi, dc->u.s_extended_operator.name);
3868
    case DEMANGLE_COMPONENT_CTOR:
4211
    case DEMANGLE_COMPONENT_CTOR:
3869
      return d_find_pack (dpi, dc->u.s_ctor.name);
4212
      return d_find_pack (dpi, dc->u.s_ctor.name);
3870
    case DEMANGLE_COMPONENT_DTOR:
4213
    case DEMANGLE_COMPONENT_DTOR:
3871
      return d_find_pack (dpi, dc->u.s_dtor.name);
4214
      return d_find_pack (dpi, dc->u.s_dtor.name);
3872
 
4215
 
3873
    default:
4216
    default:
3874
      a = d_find_pack (dpi, d_left (dc));
4217
      a = d_find_pack (dpi, d_left (dc));
3875
      if (a)
4218
      if (a)
3876
	return a;
4219
	return a;
3877
      return d_find_pack (dpi, d_right (dc));
4220
      return d_find_pack (dpi, d_right (dc));
3878
    }
4221
    }
3879
}
4222
}
3880
 
4223
 
3881
/* Returns the length of the template argument pack DC.  */
4224
/* Returns the length of the template argument pack DC.  */
3882
 
4225
 
3883
static int
4226
static int
3884
d_pack_length (const struct demangle_component *dc)
4227
d_pack_length (const struct demangle_component *dc)
3885
{
4228
{
3886
  int count = 0;
4229
  int count = 0;
3887
  while (dc && dc->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4230
  while (dc && dc->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3888
	 && d_left (dc) != NULL)
4231
	 && d_left (dc) != NULL)
3889
    {
4232
    {
3890
      ++count;
4233
      ++count;
3891
      dc = d_right (dc);
4234
      dc = d_right (dc);
3892
    }
4235
    }
3893
  return count;
4236
  return count;
3894
}
4237
}
3895
 
4238
 
3896
/* DC is a component of a mangled expression.  Print it, wrapped in parens
4239
/* DC is a component of a mangled expression.  Print it, wrapped in parens
3897
   if needed.  */
4240
   if needed.  */
3898
 
4241
 
3899
static void
4242
static void
3900
d_print_subexpr (struct d_print_info *dpi, int options,
4243
d_print_subexpr (struct d_print_info *dpi, int options,
3901
		 const struct demangle_component *dc)
4244
		 const struct demangle_component *dc)
3902
{
4245
{
3903
  int simple = 0;
4246
  int simple = 0;
3904
  if (dc->type == DEMANGLE_COMPONENT_NAME
4247
  if (dc->type == DEMANGLE_COMPONENT_NAME
3905
      || dc->type == DEMANGLE_COMPONENT_QUAL_NAME
4248
      || dc->type == DEMANGLE_COMPONENT_QUAL_NAME
3906
      || dc->type == DEMANGLE_COMPONENT_INITIALIZER_LIST
4249
      || dc->type == DEMANGLE_COMPONENT_INITIALIZER_LIST
3907
      || dc->type == DEMANGLE_COMPONENT_FUNCTION_PARAM)
4250
      || dc->type == DEMANGLE_COMPONENT_FUNCTION_PARAM)
3908
    simple = 1;
4251
    simple = 1;
3909
  if (!simple)
4252
  if (!simple)
3910
    d_append_char (dpi, '(');
4253
    d_append_char (dpi, '(');
3911
  d_print_comp (dpi, options, dc);
4254
  d_print_comp (dpi, options, dc);
3912
  if (!simple)
4255
  if (!simple)
3913
    d_append_char (dpi, ')');
4256
    d_append_char (dpi, ')');
3914
}
4257
}
-
 
4258
 
-
 
4259
/* Save the current scope.  */
-
 
4260
 
-
 
4261
static void
-
 
4262
d_save_scope (struct d_print_info *dpi,
-
 
4263
	      const struct demangle_component *container)
-
 
4264
{
-
 
4265
  struct d_saved_scope *scope;
-
 
4266
  struct d_print_template *src, **link;
-
 
4267
 
-
 
4268
  if (dpi->next_saved_scope >= dpi->num_saved_scopes)
-
 
4269
    {
-
 
4270
      d_print_error (dpi);
-
 
4271
      return;
-
 
4272
    }
-
 
4273
  scope = &dpi->saved_scopes[dpi->next_saved_scope];
-
 
4274
  dpi->next_saved_scope++;
-
 
4275
 
-
 
4276
  scope->container = container;
-
 
4277
  link = &scope->templates;
-
 
4278
 
-
 
4279
  for (src = dpi->templates; src != NULL; src = src->next)
-
 
4280
    {
-
 
4281
      struct d_print_template *dst;
-
 
4282
 
-
 
4283
      if (dpi->next_copy_template >= dpi->num_copy_templates)
-
 
4284
	{
-
 
4285
	  d_print_error (dpi);
-
 
4286
	  return;
-
 
4287
	}
-
 
4288
      dst = &dpi->copy_templates[dpi->next_copy_template];
-
 
4289
      dpi->next_copy_template++;
-
 
4290
 
-
 
4291
      dst->template_decl = src->template_decl;
-
 
4292
      *link = dst;
-
 
4293
      link = &dst->next;
-
 
4294
    }
-
 
4295
 
-
 
4296
  *link = NULL;
-
 
4297
}
-
 
4298
 
-
 
4299
/* Attempt to locate a previously saved scope.  Returns NULL if no
-
 
4300
   corresponding saved scope was found.  */
-
 
4301
 
-
 
4302
static struct d_saved_scope *
-
 
4303
d_get_saved_scope (struct d_print_info *dpi,
-
 
4304
		   const struct demangle_component *container)
-
 
4305
{
-
 
4306
  int i;
-
 
4307
 
-
 
4308
  for (i = 0; i < dpi->next_saved_scope; i++)
-
 
4309
    if (dpi->saved_scopes[i].container == container)
-
 
4310
      return &dpi->saved_scopes[i];
-
 
4311
 
-
 
4312
  return NULL;
-
 
4313
}
3915
 
4314
 
3916
/* Subroutine to handle components.  */
4315
/* Subroutine to handle components.  */
3917
 
4316
 
3918
static void
4317
static void
3919
d_print_comp (struct d_print_info *dpi, int options,
4318
d_print_comp_inner (struct d_print_info *dpi, int options,
3920
              const struct demangle_component *dc)
4319
              const struct demangle_component *dc)
3921
{
4320
{
3922
  /* Magic variable to let reference smashing skip over the next modifier
4321
  /* Magic variable to let reference smashing skip over the next modifier
3923
     without needing to modify *dc.  */
4322
     without needing to modify *dc.  */
3924
  const struct demangle_component *mod_inner = NULL;
4323
  const struct demangle_component *mod_inner = NULL;
-
 
4324
 
-
 
4325
  /* Variable used to store the current templates while a previously
-
 
4326
     captured scope is used.  */
-
 
4327
  struct d_print_template *saved_templates;
-
 
4328
 
-
 
4329
  /* Nonzero if templates have been stored in the above variable.  */
-
 
4330
  int need_template_restore = 0;
3925
 
4331
 
3926
  if (dc == NULL)
4332
  if (dc == NULL)
3927
    {
4333
    {
3928
      d_print_error (dpi);
4334
      d_print_error (dpi);
3929
      return;
4335
      return;
3930
    }
4336
    }
3931
  if (d_print_saw_error (dpi))
4337
  if (d_print_saw_error (dpi))
3932
    return;
4338
    return;
3933
 
4339
 
3934
  switch (dc->type)
4340
  switch (dc->type)
3935
    {
4341
    {
3936
    case DEMANGLE_COMPONENT_NAME:
4342
    case DEMANGLE_COMPONENT_NAME:
3937
      if ((options & DMGL_JAVA) == 0)
4343
      if ((options & DMGL_JAVA) == 0)
3938
	d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len);
4344
	d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len);
3939
      else
4345
      else
3940
	d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len);
4346
	d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len);
3941
      return;
4347
      return;
3942
 
4348
 
3943
    case DEMANGLE_COMPONENT_TAGGED_NAME:
4349
    case DEMANGLE_COMPONENT_TAGGED_NAME:
3944
      d_print_comp (dpi, options, d_left (dc));
4350
      d_print_comp (dpi, options, d_left (dc));
3945
      d_append_string (dpi, "[abi:");
4351
      d_append_string (dpi, "[abi:");
3946
      d_print_comp (dpi, options, d_right (dc));
4352
      d_print_comp (dpi, options, d_right (dc));
3947
      d_append_char (dpi, ']');
4353
      d_append_char (dpi, ']');
3948
      return;
4354
      return;
3949
 
4355
 
3950
    case DEMANGLE_COMPONENT_QUAL_NAME:
4356
    case DEMANGLE_COMPONENT_QUAL_NAME:
3951
    case DEMANGLE_COMPONENT_LOCAL_NAME:
4357
    case DEMANGLE_COMPONENT_LOCAL_NAME:
3952
      d_print_comp (dpi, options, d_left (dc));
4358
      d_print_comp (dpi, options, d_left (dc));
3953
      if ((options & DMGL_JAVA) == 0)
4359
      if ((options & DMGL_JAVA) == 0)
3954
	d_append_string (dpi, "::");
4360
	d_append_string (dpi, "::");
3955
      else
4361
      else
3956
	d_append_char (dpi, '.');
4362
	d_append_char (dpi, '.');
3957
      {
4363
      {
3958
	struct demangle_component *local_name = d_right (dc);
4364
	struct demangle_component *local_name = d_right (dc);
3959
	if (local_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
4365
	if (local_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
3960
	  {
4366
	  {
3961
	    d_append_string (dpi, "{default arg#");
4367
	    d_append_string (dpi, "{default arg#");
3962
	    d_append_num (dpi, local_name->u.s_unary_num.num + 1);
4368
	    d_append_num (dpi, local_name->u.s_unary_num.num + 1);
3963
	    d_append_string (dpi, "}::");
4369
	    d_append_string (dpi, "}::");
3964
	    local_name = local_name->u.s_unary_num.sub;
4370
	    local_name = local_name->u.s_unary_num.sub;
3965
	  }
4371
	  }
3966
	d_print_comp (dpi, options, local_name);
4372
	d_print_comp (dpi, options, local_name);
3967
      }
4373
      }
3968
      return;
4374
      return;
3969
 
4375
 
3970
    case DEMANGLE_COMPONENT_TYPED_NAME:
4376
    case DEMANGLE_COMPONENT_TYPED_NAME:
3971
      {
4377
      {
3972
	struct d_print_mod *hold_modifiers;
4378
	struct d_print_mod *hold_modifiers;
3973
	struct demangle_component *typed_name;
4379
	struct demangle_component *typed_name;
3974
	struct d_print_mod adpm[4];
4380
	struct d_print_mod adpm[4];
3975
	unsigned int i;
4381
	unsigned int i;
3976
	struct d_print_template dpt;
4382
	struct d_print_template dpt;
3977
 
4383
 
3978
	/* Pass the name down to the type so that it can be printed in
4384
	/* Pass the name down to the type so that it can be printed in
3979
	   the right place for the type.  We also have to pass down
4385
	   the right place for the type.  We also have to pass down
3980
	   any CV-qualifiers, which apply to the this parameter.  */
4386
	   any CV-qualifiers, which apply to the this parameter.  */
3981
	hold_modifiers = dpi->modifiers;
4387
	hold_modifiers = dpi->modifiers;
3982
	dpi->modifiers = 0;
4388
	dpi->modifiers = 0;
3983
	i = 0;
4389
	i = 0;
3984
	typed_name = d_left (dc);
4390
	typed_name = d_left (dc);
3985
	while (typed_name != NULL)
4391
	while (typed_name != NULL)
3986
	  {
4392
	  {
3987
	    if (i >= sizeof adpm / sizeof adpm[0])
4393
	    if (i >= sizeof adpm / sizeof adpm[0])
3988
	      {
4394
	      {
3989
		d_print_error (dpi);
4395
		d_print_error (dpi);
3990
		return;
4396
		return;
3991
	      }
4397
	      }
3992
 
4398
 
3993
	    adpm[i].next = dpi->modifiers;
4399
	    adpm[i].next = dpi->modifiers;
3994
	    dpi->modifiers = &adpm[i];
4400
	    dpi->modifiers = &adpm[i];
3995
	    adpm[i].mod = typed_name;
4401
	    adpm[i].mod = typed_name;
3996
	    adpm[i].printed = 0;
4402
	    adpm[i].printed = 0;
3997
	    adpm[i].templates = dpi->templates;
4403
	    adpm[i].templates = dpi->templates;
3998
	    ++i;
4404
	    ++i;
3999
 
4405
 
4000
	    if (typed_name->type != DEMANGLE_COMPONENT_RESTRICT_THIS
4406
	    if (typed_name->type != DEMANGLE_COMPONENT_RESTRICT_THIS
4001
		&& typed_name->type != DEMANGLE_COMPONENT_VOLATILE_THIS
4407
		&& typed_name->type != DEMANGLE_COMPONENT_VOLATILE_THIS
4002
		&& typed_name->type != DEMANGLE_COMPONENT_CONST_THIS
4408
		&& typed_name->type != DEMANGLE_COMPONENT_CONST_THIS
4003
		&& typed_name->type != DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4409
		&& typed_name->type != DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4004
		&& typed_name->type != DEMANGLE_COMPONENT_REFERENCE_THIS)
4410
		&& typed_name->type != DEMANGLE_COMPONENT_REFERENCE_THIS)
4005
	      break;
4411
	      break;
4006
 
4412
 
4007
	    typed_name = d_left (typed_name);
4413
	    typed_name = d_left (typed_name);
4008
	  }
4414
	  }
4009
 
4415
 
4010
	if (typed_name == NULL)
4416
	if (typed_name == NULL)
4011
	  {
4417
	  {
4012
	    d_print_error (dpi);
4418
	    d_print_error (dpi);
4013
	    return;
4419
	    return;
4014
	  }
4420
	  }
4015
 
4421
 
4016
	/* If typed_name is a template, then it applies to the
4422
	/* If typed_name is a template, then it applies to the
4017
	   function type as well.  */
4423
	   function type as well.  */
4018
	if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
4424
	if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
4019
	  {
4425
	  {
4020
	    dpt.next = dpi->templates;
4426
	    dpt.next = dpi->templates;
4021
	    dpi->templates = &dpt;
4427
	    dpi->templates = &dpt;
4022
	    dpt.template_decl = typed_name;
4428
	    dpt.template_decl = typed_name;
4023
	  }
4429
	  }
4024
 
4430
 
4025
	/* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4431
	/* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4026
	   there may be CV-qualifiers on its right argument which
4432
	   there may be CV-qualifiers on its right argument which
4027
	   really apply here; this happens when parsing a class which
4433
	   really apply here; this happens when parsing a class which
4028
	   is local to a function.  */
4434
	   is local to a function.  */
4029
	if (typed_name->type == DEMANGLE_COMPONENT_LOCAL_NAME)
4435
	if (typed_name->type == DEMANGLE_COMPONENT_LOCAL_NAME)
4030
	  {
4436
	  {
4031
	    struct demangle_component *local_name;
4437
	    struct demangle_component *local_name;
4032
 
4438
 
4033
	    local_name = d_right (typed_name);
4439
	    local_name = d_right (typed_name);
4034
	    if (local_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
4440
	    if (local_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
4035
	      local_name = local_name->u.s_unary_num.sub;
4441
	      local_name = local_name->u.s_unary_num.sub;
4036
	    while (local_name->type == DEMANGLE_COMPONENT_RESTRICT_THIS
4442
	    while (local_name->type == DEMANGLE_COMPONENT_RESTRICT_THIS
4037
		   || local_name->type == DEMANGLE_COMPONENT_VOLATILE_THIS
4443
		   || local_name->type == DEMANGLE_COMPONENT_VOLATILE_THIS
4038
		   || local_name->type == DEMANGLE_COMPONENT_CONST_THIS
4444
		   || local_name->type == DEMANGLE_COMPONENT_CONST_THIS
4039
		   || local_name->type == DEMANGLE_COMPONENT_REFERENCE_THIS
4445
		   || local_name->type == DEMANGLE_COMPONENT_REFERENCE_THIS
4040
		   || (local_name->type
4446
		   || (local_name->type
4041
		       == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS))
4447
		       == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS))
4042
	      {
4448
	      {
4043
		if (i >= sizeof adpm / sizeof adpm[0])
4449
		if (i >= sizeof adpm / sizeof adpm[0])
4044
		  {
4450
		  {
4045
		    d_print_error (dpi);
4451
		    d_print_error (dpi);
4046
		    return;
4452
		    return;
4047
		  }
4453
		  }
4048
 
4454
 
4049
		adpm[i] = adpm[i - 1];
4455
		adpm[i] = adpm[i - 1];
4050
		adpm[i].next = &adpm[i - 1];
4456
		adpm[i].next = &adpm[i - 1];
4051
		dpi->modifiers = &adpm[i];
4457
		dpi->modifiers = &adpm[i];
4052
 
4458
 
4053
		adpm[i - 1].mod = local_name;
4459
		adpm[i - 1].mod = local_name;
4054
		adpm[i - 1].printed = 0;
4460
		adpm[i - 1].printed = 0;
4055
		adpm[i - 1].templates = dpi->templates;
4461
		adpm[i - 1].templates = dpi->templates;
4056
		++i;
4462
		++i;
4057
 
4463
 
4058
		local_name = d_left (local_name);
4464
		local_name = d_left (local_name);
4059
	      }
4465
	      }
4060
	  }
4466
	  }
4061
 
4467
 
4062
	d_print_comp (dpi, options, d_right (dc));
4468
	d_print_comp (dpi, options, d_right (dc));
4063
 
4469
 
4064
	if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
4470
	if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE)
4065
	  dpi->templates = dpt.next;
4471
	  dpi->templates = dpt.next;
4066
 
4472
 
4067
	/* If the modifiers didn't get printed by the type, print them
4473
	/* If the modifiers didn't get printed by the type, print them
4068
	   now.  */
4474
	   now.  */
4069
	while (i > 0)
4475
	while (i > 0)
4070
	  {
4476
	  {
4071
	    --i;
4477
	    --i;
4072
	    if (! adpm[i].printed)
4478
	    if (! adpm[i].printed)
4073
	      {
4479
	      {
4074
		d_append_char (dpi, ' ');
4480
		d_append_char (dpi, ' ');
4075
		d_print_mod (dpi, options, adpm[i].mod);
4481
		d_print_mod (dpi, options, adpm[i].mod);
4076
	      }
4482
	      }
4077
	  }
4483
	  }
4078
 
4484
 
4079
	dpi->modifiers = hold_modifiers;
4485
	dpi->modifiers = hold_modifiers;
4080
 
4486
 
4081
	return;
4487
	return;
4082
      }
4488
      }
4083
 
4489
 
4084
    case DEMANGLE_COMPONENT_TEMPLATE:
4490
    case DEMANGLE_COMPONENT_TEMPLATE:
4085
      {
4491
      {
4086
	struct d_print_mod *hold_dpm;
4492
	struct d_print_mod *hold_dpm;
4087
	struct demangle_component *dcl;
4493
	struct demangle_component *dcl;
-
 
4494
	const struct demangle_component *hold_current;
-
 
4495
 
-
 
4496
	/* This template may need to be referenced by a cast operator
-
 
4497
	   contained in its subtree.  */
-
 
4498
	hold_current = dpi->current_template;
-
 
4499
	dpi->current_template = dc;
4088
 
4500
 
4089
	/* Don't push modifiers into a template definition.  Doing so
4501
	/* Don't push modifiers into a template definition.  Doing so
4090
	   could give the wrong definition for a template argument.
4502
	   could give the wrong definition for a template argument.
4091
	   Instead, treat the template essentially as a name.  */
4503
	   Instead, treat the template essentially as a name.  */
4092
 
4504
 
4093
	hold_dpm = dpi->modifiers;
4505
	hold_dpm = dpi->modifiers;
4094
	dpi->modifiers = NULL;
4506
	dpi->modifiers = NULL;
4095
 
4507
 
4096
        dcl = d_left (dc);
4508
        dcl = d_left (dc);
4097
 
4509
 
4098
        if ((options & DMGL_JAVA) != 0
4510
        if ((options & DMGL_JAVA) != 0
4099
            && dcl->type == DEMANGLE_COMPONENT_NAME
4511
            && dcl->type == DEMANGLE_COMPONENT_NAME
4100
            && dcl->u.s_name.len == 6
4512
            && dcl->u.s_name.len == 6
4101
            && strncmp (dcl->u.s_name.s, "JArray", 6) == 0)
4513
            && strncmp (dcl->u.s_name.s, "JArray", 6) == 0)
4102
          {
4514
          {
4103
            /* Special-case Java arrays, so that JArray appears
4515
            /* Special-case Java arrays, so that JArray appears
4104
               instead as TYPE[].  */
4516
               instead as TYPE[].  */
4105
 
4517
 
4106
            d_print_comp (dpi, options, d_right (dc));
4518
            d_print_comp (dpi, options, d_right (dc));
4107
            d_append_string (dpi, "[]");
4519
            d_append_string (dpi, "[]");
4108
          }
4520
          }
4109
        else
4521
        else
4110
          {
4522
          {
4111
	    d_print_comp (dpi, options, dcl);
4523
	    d_print_comp (dpi, options, dcl);
4112
	    if (d_last_char (dpi) == '<')
4524
	    if (d_last_char (dpi) == '<')
4113
	      d_append_char (dpi, ' ');
4525
	      d_append_char (dpi, ' ');
4114
	    d_append_char (dpi, '<');
4526
	    d_append_char (dpi, '<');
4115
	    d_print_comp (dpi, options, d_right (dc));
4527
	    d_print_comp (dpi, options, d_right (dc));
4116
	    /* Avoid generating two consecutive '>' characters, to avoid
4528
	    /* Avoid generating two consecutive '>' characters, to avoid
4117
	       the C++ syntactic ambiguity.  */
4529
	       the C++ syntactic ambiguity.  */
4118
	    if (d_last_char (dpi) == '>')
4530
	    if (d_last_char (dpi) == '>')
4119
	      d_append_char (dpi, ' ');
4531
	      d_append_char (dpi, ' ');
4120
	    d_append_char (dpi, '>');
4532
	    d_append_char (dpi, '>');
4121
          }
4533
          }
4122
 
4534
 
4123
	dpi->modifiers = hold_dpm;
4535
	dpi->modifiers = hold_dpm;
-
 
4536
	dpi->current_template = hold_current;
4124
 
4537
 
4125
	return;
4538
	return;
4126
      }
4539
      }
4127
 
4540
 
4128
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
4541
    case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
4129
      {
4542
      {
4130
	struct d_print_template *hold_dpt;
4543
	struct d_print_template *hold_dpt;
4131
	struct demangle_component *a = d_lookup_template_argument (dpi, dc);
4544
	struct demangle_component *a = d_lookup_template_argument (dpi, dc);
4132
 
4545
 
4133
	if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
4546
	if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
4134
	  a = d_index_template_argument (a, dpi->pack_index);
4547
	  a = d_index_template_argument (a, dpi->pack_index);
4135
 
4548
 
4136
	if (a == NULL)
4549
	if (a == NULL)
4137
	  {
4550
	  {
4138
	    d_print_error (dpi);
4551
	    d_print_error (dpi);
4139
	    return;
4552
	    return;
4140
	  }
4553
	  }
4141
 
4554
 
4142
	/* While processing this parameter, we need to pop the list of
4555
	/* While processing this parameter, we need to pop the list of
4143
	   templates.  This is because the template parameter may
4556
	   templates.  This is because the template parameter may
4144
	   itself be a reference to a parameter of an outer
4557
	   itself be a reference to a parameter of an outer
4145
	   template.  */
4558
	   template.  */
4146
 
4559
 
4147
	hold_dpt = dpi->templates;
4560
	hold_dpt = dpi->templates;
4148
	dpi->templates = hold_dpt->next;
4561
	dpi->templates = hold_dpt->next;
4149
 
4562
 
4150
	d_print_comp (dpi, options, a);
4563
	d_print_comp (dpi, options, a);
4151
 
4564
 
4152
	dpi->templates = hold_dpt;
4565
	dpi->templates = hold_dpt;
4153
 
4566
 
4154
	return;
4567
	return;
4155
      }
4568
      }
4156
 
4569
 
4157
    case DEMANGLE_COMPONENT_CTOR:
4570
    case DEMANGLE_COMPONENT_CTOR:
4158
      d_print_comp (dpi, options, dc->u.s_ctor.name);
4571
      d_print_comp (dpi, options, dc->u.s_ctor.name);
4159
      return;
4572
      return;
4160
 
4573
 
4161
    case DEMANGLE_COMPONENT_DTOR:
4574
    case DEMANGLE_COMPONENT_DTOR:
4162
      d_append_char (dpi, '~');
4575
      d_append_char (dpi, '~');
4163
      d_print_comp (dpi, options, dc->u.s_dtor.name);
4576
      d_print_comp (dpi, options, dc->u.s_dtor.name);
4164
      return;
4577
      return;
4165
 
4578
 
4166
    case DEMANGLE_COMPONENT_VTABLE:
4579
    case DEMANGLE_COMPONENT_VTABLE:
4167
      d_append_string (dpi, "vtable for ");
4580
      d_append_string (dpi, "vtable for ");
4168
      d_print_comp (dpi, options, d_left (dc));
4581
      d_print_comp (dpi, options, d_left (dc));
4169
      return;
4582
      return;
4170
 
4583
 
4171
    case DEMANGLE_COMPONENT_VTT:
4584
    case DEMANGLE_COMPONENT_VTT:
4172
      d_append_string (dpi, "VTT for ");
4585
      d_append_string (dpi, "VTT for ");
4173
      d_print_comp (dpi, options, d_left (dc));
4586
      d_print_comp (dpi, options, d_left (dc));
4174
      return;
4587
      return;
4175
 
4588
 
4176
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
4589
    case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
4177
      d_append_string (dpi, "construction vtable for ");
4590
      d_append_string (dpi, "construction vtable for ");
4178
      d_print_comp (dpi, options, d_left (dc));
4591
      d_print_comp (dpi, options, d_left (dc));
4179
      d_append_string (dpi, "-in-");
4592
      d_append_string (dpi, "-in-");
4180
      d_print_comp (dpi, options, d_right (dc));
4593
      d_print_comp (dpi, options, d_right (dc));
4181
      return;
4594
      return;
4182
 
4595
 
4183
    case DEMANGLE_COMPONENT_TYPEINFO:
4596
    case DEMANGLE_COMPONENT_TYPEINFO:
4184
      d_append_string (dpi, "typeinfo for ");
4597
      d_append_string (dpi, "typeinfo for ");
4185
      d_print_comp (dpi, options, d_left (dc));
4598
      d_print_comp (dpi, options, d_left (dc));
4186
      return;
4599
      return;
4187
 
4600
 
4188
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
4601
    case DEMANGLE_COMPONENT_TYPEINFO_NAME:
4189
      d_append_string (dpi, "typeinfo name for ");
4602
      d_append_string (dpi, "typeinfo name for ");
4190
      d_print_comp (dpi, options, d_left (dc));
4603
      d_print_comp (dpi, options, d_left (dc));
4191
      return;
4604
      return;
4192
 
4605
 
4193
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
4606
    case DEMANGLE_COMPONENT_TYPEINFO_FN:
4194
      d_append_string (dpi, "typeinfo fn for ");
4607
      d_append_string (dpi, "typeinfo fn for ");
4195
      d_print_comp (dpi, options, d_left (dc));
4608
      d_print_comp (dpi, options, d_left (dc));
4196
      return;
4609
      return;
4197
 
4610
 
4198
    case DEMANGLE_COMPONENT_THUNK:
4611
    case DEMANGLE_COMPONENT_THUNK:
4199
      d_append_string (dpi, "non-virtual thunk to ");
4612
      d_append_string (dpi, "non-virtual thunk to ");
4200
      d_print_comp (dpi, options, d_left (dc));
4613
      d_print_comp (dpi, options, d_left (dc));
4201
      return;
4614
      return;
4202
 
4615
 
4203
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
4616
    case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
4204
      d_append_string (dpi, "virtual thunk to ");
4617
      d_append_string (dpi, "virtual thunk to ");
4205
      d_print_comp (dpi, options, d_left (dc));
4618
      d_print_comp (dpi, options, d_left (dc));
4206
      return;
4619
      return;
4207
 
4620
 
4208
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
4621
    case DEMANGLE_COMPONENT_COVARIANT_THUNK:
4209
      d_append_string (dpi, "covariant return thunk to ");
4622
      d_append_string (dpi, "covariant return thunk to ");
4210
      d_print_comp (dpi, options, d_left (dc));
4623
      d_print_comp (dpi, options, d_left (dc));
4211
      return;
4624
      return;
4212
 
4625
 
4213
    case DEMANGLE_COMPONENT_JAVA_CLASS:
4626
    case DEMANGLE_COMPONENT_JAVA_CLASS:
4214
      d_append_string (dpi, "java Class for ");
4627
      d_append_string (dpi, "java Class for ");
4215
      d_print_comp (dpi, options, d_left (dc));
4628
      d_print_comp (dpi, options, d_left (dc));
4216
      return;
4629
      return;
4217
 
4630
 
4218
    case DEMANGLE_COMPONENT_GUARD:
4631
    case DEMANGLE_COMPONENT_GUARD:
4219
      d_append_string (dpi, "guard variable for ");
4632
      d_append_string (dpi, "guard variable for ");
4220
      d_print_comp (dpi, options, d_left (dc));
4633
      d_print_comp (dpi, options, d_left (dc));
4221
      return;
4634
      return;
4222
 
4635
 
4223
    case DEMANGLE_COMPONENT_TLS_INIT:
4636
    case DEMANGLE_COMPONENT_TLS_INIT:
4224
      d_append_string (dpi, "TLS init function for ");
4637
      d_append_string (dpi, "TLS init function for ");
4225
      d_print_comp (dpi, options, d_left (dc));
4638
      d_print_comp (dpi, options, d_left (dc));
4226
      return;
4639
      return;
4227
 
4640
 
4228
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
4641
    case DEMANGLE_COMPONENT_TLS_WRAPPER:
4229
      d_append_string (dpi, "TLS wrapper function for ");
4642
      d_append_string (dpi, "TLS wrapper function for ");
4230
      d_print_comp (dpi, options, d_left (dc));
4643
      d_print_comp (dpi, options, d_left (dc));
4231
      return;
4644
      return;
4232
 
4645
 
4233
    case DEMANGLE_COMPONENT_REFTEMP:
4646
    case DEMANGLE_COMPONENT_REFTEMP:
4234
      d_append_string (dpi, "reference temporary #");
4647
      d_append_string (dpi, "reference temporary #");
4235
      d_print_comp (dpi, options, d_right (dc));
4648
      d_print_comp (dpi, options, d_right (dc));
4236
      d_append_string (dpi, " for ");
4649
      d_append_string (dpi, " for ");
4237
      d_print_comp (dpi, options, d_left (dc));
4650
      d_print_comp (dpi, options, d_left (dc));
4238
      return;
4651
      return;
4239
 
4652
 
4240
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
4653
    case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
4241
      d_append_string (dpi, "hidden alias for ");
4654
      d_append_string (dpi, "hidden alias for ");
4242
      d_print_comp (dpi, options, d_left (dc));
4655
      d_print_comp (dpi, options, d_left (dc));
4243
      return;
4656
      return;
4244
 
4657
 
4245
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
4658
    case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
4246
      d_append_string (dpi, "transaction clone for ");
4659
      d_append_string (dpi, "transaction clone for ");
4247
      d_print_comp (dpi, options, d_left (dc));
4660
      d_print_comp (dpi, options, d_left (dc));
4248
      return;
4661
      return;
4249
 
4662
 
4250
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
4663
    case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
4251
      d_append_string (dpi, "non-transaction clone for ");
4664
      d_append_string (dpi, "non-transaction clone for ");
4252
      d_print_comp (dpi, options, d_left (dc));
4665
      d_print_comp (dpi, options, d_left (dc));
4253
      return;
4666
      return;
4254
 
4667
 
4255
    case DEMANGLE_COMPONENT_SUB_STD:
4668
    case DEMANGLE_COMPONENT_SUB_STD:
4256
      d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len);
4669
      d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len);
4257
      return;
4670
      return;
4258
 
4671
 
4259
    case DEMANGLE_COMPONENT_RESTRICT:
4672
    case DEMANGLE_COMPONENT_RESTRICT:
4260
    case DEMANGLE_COMPONENT_VOLATILE:
4673
    case DEMANGLE_COMPONENT_VOLATILE:
4261
    case DEMANGLE_COMPONENT_CONST:
4674
    case DEMANGLE_COMPONENT_CONST:
4262
      {
4675
      {
4263
	struct d_print_mod *pdpm;
4676
	struct d_print_mod *pdpm;
4264
 
4677
 
4265
	/* When printing arrays, it's possible to have cases where the
4678
	/* When printing arrays, it's possible to have cases where the
4266
	   same CV-qualifier gets pushed on the stack multiple times.
4679
	   same CV-qualifier gets pushed on the stack multiple times.
4267
	   We only need to print it once.  */
4680
	   We only need to print it once.  */
4268
 
4681
 
4269
	for (pdpm = dpi->modifiers; pdpm != NULL; pdpm = pdpm->next)
4682
	for (pdpm = dpi->modifiers; pdpm != NULL; pdpm = pdpm->next)
4270
	  {
4683
	  {
4271
	    if (! pdpm->printed)
4684
	    if (! pdpm->printed)
4272
	      {
4685
	      {
4273
		if (pdpm->mod->type != DEMANGLE_COMPONENT_RESTRICT
4686
		if (pdpm->mod->type != DEMANGLE_COMPONENT_RESTRICT
4274
		    && pdpm->mod->type != DEMANGLE_COMPONENT_VOLATILE
4687
		    && pdpm->mod->type != DEMANGLE_COMPONENT_VOLATILE
4275
		    && pdpm->mod->type != DEMANGLE_COMPONENT_CONST)
4688
		    && pdpm->mod->type != DEMANGLE_COMPONENT_CONST)
4276
		  break;
4689
		  break;
4277
		if (pdpm->mod->type == dc->type)
4690
		if (pdpm->mod->type == dc->type)
4278
		  {
4691
		  {
4279
		    d_print_comp (dpi, options, d_left (dc));
4692
		    d_print_comp (dpi, options, d_left (dc));
4280
		    return;
4693
		    return;
4281
		  }
4694
		  }
4282
	      }
4695
	      }
4283
	  }
4696
	  }
4284
      }
4697
      }
4285
      goto modifier;
4698
      goto modifier;
4286
 
4699
 
4287
    case DEMANGLE_COMPONENT_REFERENCE:
4700
    case DEMANGLE_COMPONENT_REFERENCE:
4288
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
4701
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
4289
      {
4702
      {
4290
	/* Handle reference smashing: & + && = &.  */
4703
	/* Handle reference smashing: & + && = &.  */
4291
	const struct demangle_component *sub = d_left (dc);
4704
	const struct demangle_component *sub = d_left (dc);
4292
	if (sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
4705
	if (sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
4293
	  {
4706
	  {
-
 
4707
	    struct d_saved_scope *scope = d_get_saved_scope (dpi, sub);
-
 
4708
	    struct demangle_component *a;
-
 
4709
 
-
 
4710
	    if (scope == NULL)
-
 
4711
	      {
-
 
4712
		/* This is the first time SUB has been traversed.
-
 
4713
		   We need to capture the current templates so
-
 
4714
		   they can be restored if SUB is reentered as a
-
 
4715
		   substitution.  */
-
 
4716
		d_save_scope (dpi, sub);
-
 
4717
		if (d_print_saw_error (dpi))
-
 
4718
		  return;
-
 
4719
	      }
-
 
4720
	    else
-
 
4721
	      {
-
 
4722
		const struct d_component_stack *dcse;
-
 
4723
		int found_self_or_parent = 0;
-
 
4724
 
-
 
4725
		/* This traversal is reentering SUB as a substition.
-
 
4726
		   If we are not beneath SUB or DC in the tree then we
-
 
4727
		   need to restore SUB's template stack temporarily.  */
-
 
4728
		for (dcse = dpi->component_stack; dcse != NULL;
-
 
4729
		     dcse = dcse->parent)
-
 
4730
		  {
-
 
4731
		    if (dcse->dc == sub
-
 
4732
			|| (dcse->dc == dc
-
 
4733
			    && dcse != dpi->component_stack))
-
 
4734
		      {
-
 
4735
			found_self_or_parent = 1;
-
 
4736
			break;
-
 
4737
		      }
-
 
4738
		  }
-
 
4739
 
-
 
4740
		if (!found_self_or_parent)
-
 
4741
		  {
-
 
4742
		    saved_templates = dpi->templates;
-
 
4743
		    dpi->templates = scope->templates;
-
 
4744
		    need_template_restore = 1;
-
 
4745
		  }
-
 
4746
	      }
-
 
4747
 
4294
	    struct demangle_component *a = d_lookup_template_argument (dpi, sub);
4748
	    a = d_lookup_template_argument (dpi, sub);
4295
	    if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
4749
	    if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
4296
	      a = d_index_template_argument (a, dpi->pack_index);
4750
	      a = d_index_template_argument (a, dpi->pack_index);
4297
 
4751
 
4298
	    if (a == NULL)
4752
	    if (a == NULL)
4299
	      {
4753
	      {
-
 
4754
		if (need_template_restore)
-
 
4755
		  dpi->templates = saved_templates;
-
 
4756
 
4300
		d_print_error (dpi);
4757
		d_print_error (dpi);
4301
		return;
4758
		return;
4302
	      }
4759
	      }
4303
 
4760
 
4304
	    sub = a;
4761
	    sub = a;
4305
	  }
4762
	  }
4306
 
4763
 
4307
	if (sub->type == DEMANGLE_COMPONENT_REFERENCE
4764
	if (sub->type == DEMANGLE_COMPONENT_REFERENCE
4308
	    || sub->type == dc->type)
4765
	    || sub->type == dc->type)
4309
	  dc = sub;
4766
	  dc = sub;
4310
	else if (sub->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE)
4767
	else if (sub->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE)
4311
	  mod_inner = d_left (sub);
4768
	  mod_inner = d_left (sub);
4312
      }
4769
      }
4313
      /* Fall through.  */
4770
      /* Fall through.  */
4314
 
4771
 
4315
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
4772
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
4316
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
4773
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
4317
    case DEMANGLE_COMPONENT_CONST_THIS:
4774
    case DEMANGLE_COMPONENT_CONST_THIS:
4318
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
4775
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
4319
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
4776
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
4320
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
4777
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
4321
    case DEMANGLE_COMPONENT_POINTER:
4778
    case DEMANGLE_COMPONENT_POINTER:
4322
    case DEMANGLE_COMPONENT_COMPLEX:
4779
    case DEMANGLE_COMPONENT_COMPLEX:
4323
    case DEMANGLE_COMPONENT_IMAGINARY:
4780
    case DEMANGLE_COMPONENT_IMAGINARY:
4324
    modifier:
4781
    modifier:
4325
      {
4782
      {
4326
	/* We keep a list of modifiers on the stack.  */
4783
	/* We keep a list of modifiers on the stack.  */
4327
	struct d_print_mod dpm;
4784
	struct d_print_mod dpm;
4328
 
4785
 
4329
	dpm.next = dpi->modifiers;
4786
	dpm.next = dpi->modifiers;
4330
	dpi->modifiers = &dpm;
4787
	dpi->modifiers = &dpm;
4331
	dpm.mod = dc;
4788
	dpm.mod = dc;
4332
	dpm.printed = 0;
4789
	dpm.printed = 0;
4333
	dpm.templates = dpi->templates;
4790
	dpm.templates = dpi->templates;
4334
 
4791
 
4335
	if (!mod_inner)
4792
	if (!mod_inner)
4336
	  mod_inner = d_left (dc);
4793
	  mod_inner = d_left (dc);
4337
 
4794
 
4338
	d_print_comp (dpi, options, mod_inner);
4795
	d_print_comp (dpi, options, mod_inner);
4339
 
4796
 
4340
	/* If the modifier didn't get printed by the type, print it
4797
	/* If the modifier didn't get printed by the type, print it
4341
	   now.  */
4798
	   now.  */
4342
	if (! dpm.printed)
4799
	if (! dpm.printed)
4343
	  d_print_mod (dpi, options, dc);
4800
	  d_print_mod (dpi, options, dc);
4344
 
4801
 
4345
	dpi->modifiers = dpm.next;
4802
	dpi->modifiers = dpm.next;
-
 
4803
 
-
 
4804
	if (need_template_restore)
-
 
4805
	  dpi->templates = saved_templates;
4346
 
4806
 
4347
	return;
4807
	return;
4348
      }
4808
      }
4349
 
4809
 
4350
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
4810
    case DEMANGLE_COMPONENT_BUILTIN_TYPE:
4351
      if ((options & DMGL_JAVA) == 0)
4811
      if ((options & DMGL_JAVA) == 0)
4352
	d_append_buffer (dpi, dc->u.s_builtin.type->name,
4812
	d_append_buffer (dpi, dc->u.s_builtin.type->name,
4353
			 dc->u.s_builtin.type->len);
4813
			 dc->u.s_builtin.type->len);
4354
      else
4814
      else
4355
	d_append_buffer (dpi, dc->u.s_builtin.type->java_name,
4815
	d_append_buffer (dpi, dc->u.s_builtin.type->java_name,
4356
			 dc->u.s_builtin.type->java_len);
4816
			 dc->u.s_builtin.type->java_len);
4357
      return;
4817
      return;
4358
 
4818
 
4359
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
4819
    case DEMANGLE_COMPONENT_VENDOR_TYPE:
4360
      d_print_comp (dpi, options, d_left (dc));
4820
      d_print_comp (dpi, options, d_left (dc));
4361
      return;
4821
      return;
4362
 
4822
 
4363
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
4823
    case DEMANGLE_COMPONENT_FUNCTION_TYPE:
4364
      {
4824
      {
4365
	if ((options & DMGL_RET_POSTFIX) != 0)
4825
	if ((options & DMGL_RET_POSTFIX) != 0)
4366
	  d_print_function_type (dpi,
4826
	  d_print_function_type (dpi,
4367
				 options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4827
				 options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4368
				 dc, dpi->modifiers);
4828
				 dc, dpi->modifiers);
4369
 
4829
 
4370
	/* Print return type if present */
4830
	/* Print return type if present */
4371
	if (d_left (dc) != NULL && (options & DMGL_RET_POSTFIX) != 0)
4831
	if (d_left (dc) != NULL && (options & DMGL_RET_POSTFIX) != 0)
4372
	  d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4832
	  d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4373
			d_left (dc));
4833
			d_left (dc));
4374
	else if (d_left (dc) != NULL && (options & DMGL_RET_DROP) == 0)
4834
	else if (d_left (dc) != NULL && (options & DMGL_RET_DROP) == 0)
4375
	  {
4835
	  {
4376
	    struct d_print_mod dpm;
4836
	    struct d_print_mod dpm;
4377
 
4837
 
4378
	    /* We must pass this type down as a modifier in order to
4838
	    /* We must pass this type down as a modifier in order to
4379
	       print it in the right location.  */
4839
	       print it in the right location.  */
4380
	    dpm.next = dpi->modifiers;
4840
	    dpm.next = dpi->modifiers;
4381
	    dpi->modifiers = &dpm;
4841
	    dpi->modifiers = &dpm;
4382
	    dpm.mod = dc;
4842
	    dpm.mod = dc;
4383
	    dpm.printed = 0;
4843
	    dpm.printed = 0;
4384
	    dpm.templates = dpi->templates;
4844
	    dpm.templates = dpi->templates;
4385
 
4845
 
4386
	    d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4846
	    d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4387
			  d_left (dc));
4847
			  d_left (dc));
4388
 
4848
 
4389
	    dpi->modifiers = dpm.next;
4849
	    dpi->modifiers = dpm.next;
4390
 
4850
 
4391
	    if (dpm.printed)
4851
	    if (dpm.printed)
4392
	      return;
4852
	      return;
4393
 
4853
 
4394
	    /* In standard prefix notation, there is a space between the
4854
	    /* In standard prefix notation, there is a space between the
4395
	       return type and the function signature.  */
4855
	       return type and the function signature.  */
4396
	    if ((options & DMGL_RET_POSTFIX) == 0)
4856
	    if ((options & DMGL_RET_POSTFIX) == 0)
4397
	      d_append_char (dpi, ' ');
4857
	      d_append_char (dpi, ' ');
4398
	  }
4858
	  }
4399
 
4859
 
4400
	if ((options & DMGL_RET_POSTFIX) == 0)
4860
	if ((options & DMGL_RET_POSTFIX) == 0)
4401
	  d_print_function_type (dpi,
4861
	  d_print_function_type (dpi,
4402
				 options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4862
				 options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP),
4403
				 dc, dpi->modifiers);
4863
				 dc, dpi->modifiers);
4404
 
4864
 
4405
	return;
4865
	return;
4406
      }
4866
      }
4407
 
4867
 
4408
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
4868
    case DEMANGLE_COMPONENT_ARRAY_TYPE:
4409
      {
4869
      {
4410
	struct d_print_mod *hold_modifiers;
4870
	struct d_print_mod *hold_modifiers;
4411
	struct d_print_mod adpm[4];
4871
	struct d_print_mod adpm[4];
4412
	unsigned int i;
4872
	unsigned int i;
4413
	struct d_print_mod *pdpm;
4873
	struct d_print_mod *pdpm;
4414
 
4874
 
4415
	/* We must pass this type down as a modifier in order to print
4875
	/* We must pass this type down as a modifier in order to print
4416
	   multi-dimensional arrays correctly.  If the array itself is
4876
	   multi-dimensional arrays correctly.  If the array itself is
4417
	   CV-qualified, we act as though the element type were
4877
	   CV-qualified, we act as though the element type were
4418
	   CV-qualified.  We do this by copying the modifiers down
4878
	   CV-qualified.  We do this by copying the modifiers down
4419
	   rather than fiddling pointers, so that we don't wind up
4879
	   rather than fiddling pointers, so that we don't wind up
4420
	   with a d_print_mod higher on the stack pointing into our
4880
	   with a d_print_mod higher on the stack pointing into our
4421
	   stack frame after we return.  */
4881
	   stack frame after we return.  */
4422
 
4882
 
4423
	hold_modifiers = dpi->modifiers;
4883
	hold_modifiers = dpi->modifiers;
4424
 
4884
 
4425
	adpm[0].next = hold_modifiers;
4885
	adpm[0].next = hold_modifiers;
4426
	dpi->modifiers = &adpm[0];
4886
	dpi->modifiers = &adpm[0];
4427
	adpm[0].mod = dc;
4887
	adpm[0].mod = dc;
4428
	adpm[0].printed = 0;
4888
	adpm[0].printed = 0;
4429
	adpm[0].templates = dpi->templates;
4889
	adpm[0].templates = dpi->templates;
4430
 
4890
 
4431
	i = 1;
4891
	i = 1;
4432
	pdpm = hold_modifiers;
4892
	pdpm = hold_modifiers;
4433
	while (pdpm != NULL
4893
	while (pdpm != NULL
4434
	       && (pdpm->mod->type == DEMANGLE_COMPONENT_RESTRICT
4894
	       && (pdpm->mod->type == DEMANGLE_COMPONENT_RESTRICT
4435
		   || pdpm->mod->type == DEMANGLE_COMPONENT_VOLATILE
4895
		   || pdpm->mod->type == DEMANGLE_COMPONENT_VOLATILE
4436
		   || pdpm->mod->type == DEMANGLE_COMPONENT_CONST))
4896
		   || pdpm->mod->type == DEMANGLE_COMPONENT_CONST))
4437
	  {
4897
	  {
4438
	    if (! pdpm->printed)
4898
	    if (! pdpm->printed)
4439
	      {
4899
	      {
4440
		if (i >= sizeof adpm / sizeof adpm[0])
4900
		if (i >= sizeof adpm / sizeof adpm[0])
4441
		  {
4901
		  {
4442
		    d_print_error (dpi);
4902
		    d_print_error (dpi);
4443
		    return;
4903
		    return;
4444
		  }
4904
		  }
4445
 
4905
 
4446
		adpm[i] = *pdpm;
4906
		adpm[i] = *pdpm;
4447
		adpm[i].next = dpi->modifiers;
4907
		adpm[i].next = dpi->modifiers;
4448
		dpi->modifiers = &adpm[i];
4908
		dpi->modifiers = &adpm[i];
4449
		pdpm->printed = 1;
4909
		pdpm->printed = 1;
4450
		++i;
4910
		++i;
4451
	      }
4911
	      }
4452
 
4912
 
4453
	    pdpm = pdpm->next;
4913
	    pdpm = pdpm->next;
4454
	  }
4914
	  }
4455
 
4915
 
4456
	d_print_comp (dpi, options, d_right (dc));
4916
	d_print_comp (dpi, options, d_right (dc));
4457
 
4917
 
4458
	dpi->modifiers = hold_modifiers;
4918
	dpi->modifiers = hold_modifiers;
4459
 
4919
 
4460
	if (adpm[0].printed)
4920
	if (adpm[0].printed)
4461
	  return;
4921
	  return;
4462
 
4922
 
4463
	while (i > 1)
4923
	while (i > 1)
4464
	  {
4924
	  {
4465
	    --i;
4925
	    --i;
4466
	    d_print_mod (dpi, options, adpm[i].mod);
4926
	    d_print_mod (dpi, options, adpm[i].mod);
4467
	  }
4927
	  }
4468
 
4928
 
4469
	d_print_array_type (dpi, options, dc, dpi->modifiers);
4929
	d_print_array_type (dpi, options, dc, dpi->modifiers);
4470
 
4930
 
4471
	return;
4931
	return;
4472
      }
4932
      }
4473
 
4933
 
4474
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
4934
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
4475
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
4935
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
4476
      {
4936
      {
4477
	struct d_print_mod dpm;
4937
	struct d_print_mod dpm;
4478
 
4938
 
4479
	dpm.next = dpi->modifiers;
4939
	dpm.next = dpi->modifiers;
4480
	dpi->modifiers = &dpm;
4940
	dpi->modifiers = &dpm;
4481
	dpm.mod = dc;
4941
	dpm.mod = dc;
4482
	dpm.printed = 0;
4942
	dpm.printed = 0;
4483
	dpm.templates = dpi->templates;
4943
	dpm.templates = dpi->templates;
4484
 
4944
 
4485
	d_print_comp (dpi, options, d_right (dc));
4945
	d_print_comp (dpi, options, d_right (dc));
4486
 
4946
 
4487
	/* If the modifier didn't get printed by the type, print it
4947
	/* If the modifier didn't get printed by the type, print it
4488
	   now.  */
4948
	   now.  */
4489
	if (! dpm.printed)
4949
	if (! dpm.printed)
4490
	  d_print_mod (dpi, options, dc);
4950
	  d_print_mod (dpi, options, dc);
4491
 
4951
 
4492
	dpi->modifiers = dpm.next;
4952
	dpi->modifiers = dpm.next;
4493
 
4953
 
4494
	return;
4954
	return;
4495
      }
4955
      }
4496
 
4956
 
4497
    case DEMANGLE_COMPONENT_FIXED_TYPE:
4957
    case DEMANGLE_COMPONENT_FIXED_TYPE:
4498
      if (dc->u.s_fixed.sat)
4958
      if (dc->u.s_fixed.sat)
4499
	d_append_string (dpi, "_Sat ");
4959
	d_append_string (dpi, "_Sat ");
4500
      /* Don't print "int _Accum".  */
4960
      /* Don't print "int _Accum".  */
4501
      if (dc->u.s_fixed.length->u.s_builtin.type
4961
      if (dc->u.s_fixed.length->u.s_builtin.type
4502
	  != &cplus_demangle_builtin_types['i'-'a'])
4962
	  != &cplus_demangle_builtin_types['i'-'a'])
4503
	{
4963
	{
4504
	  d_print_comp (dpi, options, dc->u.s_fixed.length);
4964
	  d_print_comp (dpi, options, dc->u.s_fixed.length);
4505
	  d_append_char (dpi, ' ');
4965
	  d_append_char (dpi, ' ');
4506
	}
4966
	}
4507
      if (dc->u.s_fixed.accum)
4967
      if (dc->u.s_fixed.accum)
4508
	d_append_string (dpi, "_Accum");
4968
	d_append_string (dpi, "_Accum");
4509
      else
4969
      else
4510
	d_append_string (dpi, "_Fract");
4970
	d_append_string (dpi, "_Fract");
4511
      return;
4971
      return;
4512
 
4972
 
4513
    case DEMANGLE_COMPONENT_ARGLIST:
4973
    case DEMANGLE_COMPONENT_ARGLIST:
4514
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
4974
    case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
4515
      if (d_left (dc) != NULL)
4975
      if (d_left (dc) != NULL)
4516
	d_print_comp (dpi, options, d_left (dc));
4976
	d_print_comp (dpi, options, d_left (dc));
4517
      if (d_right (dc) != NULL)
4977
      if (d_right (dc) != NULL)
4518
	{
4978
	{
4519
	  size_t len;
4979
	  size_t len;
4520
	  unsigned long int flush_count;
4980
	  unsigned long int flush_count;
4521
	  /* Make sure ", " isn't flushed by d_append_string, otherwise
4981
	  /* Make sure ", " isn't flushed by d_append_string, otherwise
4522
	     dpi->len -= 2 wouldn't work.  */
4982
	     dpi->len -= 2 wouldn't work.  */
4523
	  if (dpi->len >= sizeof (dpi->buf) - 2)
4983
	  if (dpi->len >= sizeof (dpi->buf) - 2)
4524
	    d_print_flush (dpi);
4984
	    d_print_flush (dpi);
4525
	  d_append_string (dpi, ", ");
4985
	  d_append_string (dpi, ", ");
4526
	  len = dpi->len;
4986
	  len = dpi->len;
4527
	  flush_count = dpi->flush_count;
4987
	  flush_count = dpi->flush_count;
4528
	  d_print_comp (dpi, options, d_right (dc));
4988
	  d_print_comp (dpi, options, d_right (dc));
4529
	  /* If that didn't print anything (which can happen with empty
4989
	  /* If that didn't print anything (which can happen with empty
4530
	     template argument packs), remove the comma and space.  */
4990
	     template argument packs), remove the comma and space.  */
4531
	  if (dpi->flush_count == flush_count && dpi->len == len)
4991
	  if (dpi->flush_count == flush_count && dpi->len == len)
4532
	    dpi->len -= 2;
4992
	    dpi->len -= 2;
4533
	}
4993
	}
4534
      return;
4994
      return;
4535
 
4995
 
4536
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
4996
    case DEMANGLE_COMPONENT_INITIALIZER_LIST:
4537
      {
4997
      {
4538
	struct demangle_component *type = d_left (dc);
4998
	struct demangle_component *type = d_left (dc);
4539
	struct demangle_component *list = d_right (dc);
4999
	struct demangle_component *list = d_right (dc);
4540
 
5000
 
4541
	if (type)
5001
	if (type)
4542
	  d_print_comp (dpi, options, type);
5002
	  d_print_comp (dpi, options, type);
4543
	d_append_char (dpi, '{');
5003
	d_append_char (dpi, '{');
4544
	d_print_comp (dpi, options, list);
5004
	d_print_comp (dpi, options, list);
4545
	d_append_char (dpi, '}');
5005
	d_append_char (dpi, '}');
4546
      }
5006
      }
4547
      return;
5007
      return;
4548
 
5008
 
4549
    case DEMANGLE_COMPONENT_OPERATOR:
5009
    case DEMANGLE_COMPONENT_OPERATOR:
4550
      {
5010
      {
4551
	const struct demangle_operator_info *op = dc->u.s_operator.op;
5011
	const struct demangle_operator_info *op = dc->u.s_operator.op;
4552
	int len = op->len;
5012
	int len = op->len;
4553
 
5013
 
4554
	d_append_string (dpi, "operator");
5014
	d_append_string (dpi, "operator");
4555
	/* Add a space before new/delete.  */
5015
	/* Add a space before new/delete.  */
4556
	if (IS_LOWER (op->name[0]))
5016
	if (IS_LOWER (op->name[0]))
4557
	  d_append_char (dpi, ' ');
5017
	  d_append_char (dpi, ' ');
4558
	/* Omit a trailing space.  */
5018
	/* Omit a trailing space.  */
4559
	if (op->name[len-1] == ' ')
5019
	if (op->name[len-1] == ' ')
4560
	  --len;
5020
	  --len;
4561
	d_append_buffer (dpi, op->name, len);
5021
	d_append_buffer (dpi, op->name, len);
4562
	return;
5022
	return;
4563
      }
5023
      }
4564
 
5024
 
4565
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
5025
    case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
4566
      d_append_string (dpi, "operator ");
5026
      d_append_string (dpi, "operator ");
4567
      d_print_comp (dpi, options, dc->u.s_extended_operator.name);
5027
      d_print_comp (dpi, options, dc->u.s_extended_operator.name);
4568
      return;
5028
      return;
4569
 
5029
 
4570
    case DEMANGLE_COMPONENT_CAST:
5030
    case DEMANGLE_COMPONENT_CAST:
4571
      d_append_string (dpi, "operator ");
5031
      d_append_string (dpi, "operator ");
4572
      d_print_cast (dpi, options, dc);
5032
      d_print_cast (dpi, options, dc);
4573
      return;
5033
      return;
4574
 
5034
 
4575
    case DEMANGLE_COMPONENT_NULLARY:
5035
    case DEMANGLE_COMPONENT_NULLARY:
4576
      d_print_expr_op (dpi, options, d_left (dc));
5036
      d_print_expr_op (dpi, options, d_left (dc));
4577
      return;
5037
      return;
4578
 
5038
 
4579
    case DEMANGLE_COMPONENT_UNARY:
5039
    case DEMANGLE_COMPONENT_UNARY:
4580
      {
5040
      {
4581
	struct demangle_component *op = d_left (dc);
5041
	struct demangle_component *op = d_left (dc);
4582
	struct demangle_component *operand = d_right (dc);
5042
	struct demangle_component *operand = d_right (dc);
4583
	const char *code = NULL;
5043
	const char *code = NULL;
4584
 
5044
 
4585
	if (op->type == DEMANGLE_COMPONENT_OPERATOR)
5045
	if (op->type == DEMANGLE_COMPONENT_OPERATOR)
4586
	  {
5046
	  {
4587
	    code = op->u.s_operator.op->code;
5047
	    code = op->u.s_operator.op->code;
4588
	    if (!strcmp (code, "ad"))
5048
	    if (!strcmp (code, "ad"))
4589
	      {
5049
	      {
4590
		/* Don't print the argument list for the address of a
5050
		/* Don't print the argument list for the address of a
4591
		   function.  */
5051
		   function.  */
4592
		if (operand->type == DEMANGLE_COMPONENT_TYPED_NAME
5052
		if (operand->type == DEMANGLE_COMPONENT_TYPED_NAME
4593
		    && d_left (operand)->type == DEMANGLE_COMPONENT_QUAL_NAME
5053
		    && d_left (operand)->type == DEMANGLE_COMPONENT_QUAL_NAME
4594
		    && d_right (operand)->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
5054
		    && d_right (operand)->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
4595
		  operand = d_left (operand);
5055
		  operand = d_left (operand);
4596
	      }
5056
	      }
4597
	    if (operand->type == DEMANGLE_COMPONENT_BINARY_ARGS)
5057
	    if (operand->type == DEMANGLE_COMPONENT_BINARY_ARGS)
4598
	      {
5058
	      {
4599
		/* This indicates a suffix operator.  */
5059
		/* This indicates a suffix operator.  */
4600
		operand = d_left (operand);
5060
		operand = d_left (operand);
4601
		d_print_subexpr (dpi, options, operand);
5061
		d_print_subexpr (dpi, options, operand);
4602
		d_print_expr_op (dpi, options, op);
5062
		d_print_expr_op (dpi, options, op);
4603
		return;
5063
		return;
4604
	      }
5064
	      }
4605
	  }
5065
	  }
4606
 
5066
 
4607
	if (op->type != DEMANGLE_COMPONENT_CAST)
5067
	if (op->type != DEMANGLE_COMPONENT_CAST)
4608
	  d_print_expr_op (dpi, options, op);
5068
	  d_print_expr_op (dpi, options, op);
4609
	else
5069
	else
4610
	  {
5070
	  {
4611
	    d_append_char (dpi, '(');
5071
	    d_append_char (dpi, '(');
4612
	    d_print_cast (dpi, options, op);
5072
	    d_print_cast (dpi, options, op);
4613
	    d_append_char (dpi, ')');
5073
	    d_append_char (dpi, ')');
4614
	  }
5074
	  }
4615
	if (code && !strcmp (code, "gs"))
5075
	if (code && !strcmp (code, "gs"))
4616
	  /* Avoid parens after '::'.  */
5076
	  /* Avoid parens after '::'.  */
4617
	  d_print_comp (dpi, options, operand);
5077
	  d_print_comp (dpi, options, operand);
4618
	else if (code && !strcmp (code, "st"))
5078
	else if (code && !strcmp (code, "st"))
4619
	  /* Always print parens for sizeof (type).  */
5079
	  /* Always print parens for sizeof (type).  */
4620
	  {
5080
	  {
4621
	    d_append_char (dpi, '(');
5081
	    d_append_char (dpi, '(');
4622
	    d_print_comp (dpi, options, operand);
5082
	    d_print_comp (dpi, options, operand);
4623
	    d_append_char (dpi, ')');
5083
	    d_append_char (dpi, ')');
4624
	  }
5084
	  }
4625
	else
5085
	else
4626
	  d_print_subexpr (dpi, options, operand);
5086
	  d_print_subexpr (dpi, options, operand);
4627
      }
5087
      }
4628
      return;
5088
      return;
4629
 
5089
 
4630
    case DEMANGLE_COMPONENT_BINARY:
5090
    case DEMANGLE_COMPONENT_BINARY:
4631
      if (d_right (dc)->type != DEMANGLE_COMPONENT_BINARY_ARGS)
5091
      if (d_right (dc)->type != DEMANGLE_COMPONENT_BINARY_ARGS)
4632
	{
5092
	{
4633
	  d_print_error (dpi);
5093
	  d_print_error (dpi);
4634
	  return;
5094
	  return;
4635
	}
5095
	}
4636
 
5096
 
4637
      if (op_is_new_cast (d_left (dc)))
5097
      if (op_is_new_cast (d_left (dc)))
4638
	{
5098
	{
4639
	  d_print_expr_op (dpi, options, d_left (dc));
5099
	  d_print_expr_op (dpi, options, d_left (dc));
4640
	  d_append_char (dpi, '<');
5100
	  d_append_char (dpi, '<');
4641
	  d_print_comp (dpi, options, d_left (d_right (dc)));
5101
	  d_print_comp (dpi, options, d_left (d_right (dc)));
4642
	  d_append_string (dpi, ">(");
5102
	  d_append_string (dpi, ">(");
4643
	  d_print_comp (dpi, options, d_right (d_right (dc)));
5103
	  d_print_comp (dpi, options, d_right (d_right (dc)));
4644
	  d_append_char (dpi, ')');
5104
	  d_append_char (dpi, ')');
4645
	  return;
5105
	  return;
4646
	}
5106
	}
4647
 
5107
 
4648
      /* We wrap an expression which uses the greater-than operator in
5108
      /* We wrap an expression which uses the greater-than operator in
4649
	 an extra layer of parens so that it does not get confused
5109
	 an extra layer of parens so that it does not get confused
4650
	 with the '>' which ends the template parameters.  */
5110
	 with the '>' which ends the template parameters.  */
4651
      if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
5111
      if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
4652
	  && d_left (dc)->u.s_operator.op->len == 1
5112
	  && d_left (dc)->u.s_operator.op->len == 1
4653
	  && d_left (dc)->u.s_operator.op->name[0] == '>')
5113
	  && d_left (dc)->u.s_operator.op->name[0] == '>')
4654
	d_append_char (dpi, '(');
5114
	d_append_char (dpi, '(');
4655
 
5115
 
4656
      if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") == 0
5116
      if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") == 0
4657
          && d_left (d_right (dc))->type == DEMANGLE_COMPONENT_TYPED_NAME)
5117
          && d_left (d_right (dc))->type == DEMANGLE_COMPONENT_TYPED_NAME)
4658
	{
5118
	{
4659
	  /* Function call used in an expression should not have printed types
5119
	  /* Function call used in an expression should not have printed types
4660
	     of the function arguments.  Values of the function arguments still
5120
	     of the function arguments.  Values of the function arguments still
4661
	     get printed below.  */
5121
	     get printed below.  */
4662
 
5122
 
4663
	  const struct demangle_component *func = d_left (d_right (dc));
5123
	  const struct demangle_component *func = d_left (d_right (dc));
4664
 
5124
 
4665
	  if (d_right (func)->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
5125
	  if (d_right (func)->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
4666
	    d_print_error (dpi);
5126
	    d_print_error (dpi);
4667
	  d_print_subexpr (dpi, options, d_left (func));
5127
	  d_print_subexpr (dpi, options, d_left (func));
4668
	}
5128
	}
4669
      else
5129
      else
4670
	d_print_subexpr (dpi, options, d_left (d_right (dc)));
5130
	d_print_subexpr (dpi, options, d_left (d_right (dc)));
4671
      if (strcmp (d_left (dc)->u.s_operator.op->code, "ix") == 0)
5131
      if (strcmp (d_left (dc)->u.s_operator.op->code, "ix") == 0)
4672
	{
5132
	{
4673
	  d_append_char (dpi, '[');
5133
	  d_append_char (dpi, '[');
4674
	  d_print_comp (dpi, options, d_right (d_right (dc)));
5134
	  d_print_comp (dpi, options, d_right (d_right (dc)));
4675
	  d_append_char (dpi, ']');
5135
	  d_append_char (dpi, ']');
4676
	}
5136
	}
4677
      else
5137
      else
4678
	{
5138
	{
4679
	  if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") != 0)
5139
	  if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") != 0)
4680
	    d_print_expr_op (dpi, options, d_left (dc));
5140
	    d_print_expr_op (dpi, options, d_left (dc));
4681
	  d_print_subexpr (dpi, options, d_right (d_right (dc)));
5141
	  d_print_subexpr (dpi, options, d_right (d_right (dc)));
4682
	}
5142
	}
4683
 
5143
 
4684
      if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
5144
      if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
4685
	  && d_left (dc)->u.s_operator.op->len == 1
5145
	  && d_left (dc)->u.s_operator.op->len == 1
4686
	  && d_left (dc)->u.s_operator.op->name[0] == '>')
5146
	  && d_left (dc)->u.s_operator.op->name[0] == '>')
4687
	d_append_char (dpi, ')');
5147
	d_append_char (dpi, ')');
4688
 
5148
 
4689
      return;
5149
      return;
4690
 
5150
 
4691
    case DEMANGLE_COMPONENT_BINARY_ARGS:
5151
    case DEMANGLE_COMPONENT_BINARY_ARGS:
4692
      /* We should only see this as part of DEMANGLE_COMPONENT_BINARY.  */
5152
      /* We should only see this as part of DEMANGLE_COMPONENT_BINARY.  */
4693
      d_print_error (dpi);
5153
      d_print_error (dpi);
4694
      return;
5154
      return;
4695
 
5155
 
4696
    case DEMANGLE_COMPONENT_TRINARY:
5156
    case DEMANGLE_COMPONENT_TRINARY:
4697
      if (d_right (dc)->type != DEMANGLE_COMPONENT_TRINARY_ARG1
5157
      if (d_right (dc)->type != DEMANGLE_COMPONENT_TRINARY_ARG1
4698
	  || d_right (d_right (dc))->type != DEMANGLE_COMPONENT_TRINARY_ARG2)
5158
	  || d_right (d_right (dc))->type != DEMANGLE_COMPONENT_TRINARY_ARG2)
4699
	{
5159
	{
4700
	  d_print_error (dpi);
5160
	  d_print_error (dpi);
4701
	  return;
5161
	  return;
4702
	}
5162
	}
4703
      {
5163
      {
4704
	struct demangle_component *op = d_left (dc);
5164
	struct demangle_component *op = d_left (dc);
4705
	struct demangle_component *first = d_left (d_right (dc));
5165
	struct demangle_component *first = d_left (d_right (dc));
4706
	struct demangle_component *second = d_left (d_right (d_right (dc)));
5166
	struct demangle_component *second = d_left (d_right (d_right (dc)));
4707
	struct demangle_component *third = d_right (d_right (d_right (dc)));
5167
	struct demangle_component *third = d_right (d_right (d_right (dc)));
4708
 
5168
 
4709
	if (!strcmp (op->u.s_operator.op->code, "qu"))
5169
	if (!strcmp (op->u.s_operator.op->code, "qu"))
4710
	  {
5170
	  {
4711
	    d_print_subexpr (dpi, options, first);
5171
	    d_print_subexpr (dpi, options, first);
4712
	    d_print_expr_op (dpi, options, op);
5172
	    d_print_expr_op (dpi, options, op);
4713
	    d_print_subexpr (dpi, options, second);
5173
	    d_print_subexpr (dpi, options, second);
4714
	    d_append_string (dpi, " : ");
5174
	    d_append_string (dpi, " : ");
4715
	    d_print_subexpr (dpi, options, third);
5175
	    d_print_subexpr (dpi, options, third);
4716
	  }
5176
	  }
4717
	else
5177
	else
4718
	  {
5178
	  {
4719
	    d_append_string (dpi, "new ");
5179
	    d_append_string (dpi, "new ");
4720
	    if (d_left (first) != NULL)
5180
	    if (d_left (first) != NULL)
4721
	      {
5181
	      {
4722
		d_print_subexpr (dpi, options, first);
5182
		d_print_subexpr (dpi, options, first);
4723
		d_append_char (dpi, ' ');
5183
		d_append_char (dpi, ' ');
4724
	      }
5184
	      }
4725
	    d_print_comp (dpi, options, second);
5185
	    d_print_comp (dpi, options, second);
4726
	    if (third)
5186
	    if (third)
4727
	      d_print_subexpr (dpi, options, third);
5187
	      d_print_subexpr (dpi, options, third);
4728
	  }
5188
	  }
4729
      }
5189
      }
4730
      return;
5190
      return;
4731
 
5191
 
4732
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
5192
    case DEMANGLE_COMPONENT_TRINARY_ARG1:
4733
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
5193
    case DEMANGLE_COMPONENT_TRINARY_ARG2:
4734
      /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY.  */
5194
      /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY.  */
4735
      d_print_error (dpi);
5195
      d_print_error (dpi);
4736
      return;
5196
      return;
4737
 
5197
 
4738
    case DEMANGLE_COMPONENT_LITERAL:
5198
    case DEMANGLE_COMPONENT_LITERAL:
4739
    case DEMANGLE_COMPONENT_LITERAL_NEG:
5199
    case DEMANGLE_COMPONENT_LITERAL_NEG:
4740
      {
5200
      {
4741
	enum d_builtin_type_print tp;
5201
	enum d_builtin_type_print tp;
4742
 
5202
 
4743
	/* For some builtin types, produce simpler output.  */
5203
	/* For some builtin types, produce simpler output.  */
4744
	tp = D_PRINT_DEFAULT;
5204
	tp = D_PRINT_DEFAULT;
4745
	if (d_left (dc)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE)
5205
	if (d_left (dc)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE)
4746
	  {
5206
	  {
4747
	    tp = d_left (dc)->u.s_builtin.type->print;
5207
	    tp = d_left (dc)->u.s_builtin.type->print;
4748
	    switch (tp)
5208
	    switch (tp)
4749
	      {
5209
	      {
4750
	      case D_PRINT_INT:
5210
	      case D_PRINT_INT:
4751
	      case D_PRINT_UNSIGNED:
5211
	      case D_PRINT_UNSIGNED:
4752
	      case D_PRINT_LONG:
5212
	      case D_PRINT_LONG:
4753
	      case D_PRINT_UNSIGNED_LONG:
5213
	      case D_PRINT_UNSIGNED_LONG:
4754
	      case D_PRINT_LONG_LONG:
5214
	      case D_PRINT_LONG_LONG:
4755
	      case D_PRINT_UNSIGNED_LONG_LONG:
5215
	      case D_PRINT_UNSIGNED_LONG_LONG:
4756
		if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME)
5216
		if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME)
4757
		  {
5217
		  {
4758
		    if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
5218
		    if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
4759
		      d_append_char (dpi, '-');
5219
		      d_append_char (dpi, '-');
4760
		    d_print_comp (dpi, options, d_right (dc));
5220
		    d_print_comp (dpi, options, d_right (dc));
4761
		    switch (tp)
5221
		    switch (tp)
4762
		      {
5222
		      {
4763
		      default:
5223
		      default:
4764
			break;
5224
			break;
4765
		      case D_PRINT_UNSIGNED:
5225
		      case D_PRINT_UNSIGNED:
4766
			d_append_char (dpi, 'u');
5226
			d_append_char (dpi, 'u');
4767
			break;
5227
			break;
4768
		      case D_PRINT_LONG:
5228
		      case D_PRINT_LONG:
4769
			d_append_char (dpi, 'l');
5229
			d_append_char (dpi, 'l');
4770
			break;
5230
			break;
4771
		      case D_PRINT_UNSIGNED_LONG:
5231
		      case D_PRINT_UNSIGNED_LONG:
4772
			d_append_string (dpi, "ul");
5232
			d_append_string (dpi, "ul");
4773
			break;
5233
			break;
4774
		      case D_PRINT_LONG_LONG:
5234
		      case D_PRINT_LONG_LONG:
4775
			d_append_string (dpi, "ll");
5235
			d_append_string (dpi, "ll");
4776
			break;
5236
			break;
4777
		      case D_PRINT_UNSIGNED_LONG_LONG:
5237
		      case D_PRINT_UNSIGNED_LONG_LONG:
4778
			d_append_string (dpi, "ull");
5238
			d_append_string (dpi, "ull");
4779
			break;
5239
			break;
4780
		      }
5240
		      }
4781
		    return;
5241
		    return;
4782
		  }
5242
		  }
4783
		break;
5243
		break;
4784
 
5244
 
4785
	      case D_PRINT_BOOL:
5245
	      case D_PRINT_BOOL:
4786
		if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME
5246
		if (d_right (dc)->type == DEMANGLE_COMPONENT_NAME
4787
		    && d_right (dc)->u.s_name.len == 1
5247
		    && d_right (dc)->u.s_name.len == 1
4788
		    && dc->type == DEMANGLE_COMPONENT_LITERAL)
5248
		    && dc->type == DEMANGLE_COMPONENT_LITERAL)
4789
		  {
5249
		  {
4790
		    switch (d_right (dc)->u.s_name.s[0])
5250
		    switch (d_right (dc)->u.s_name.s[0])
4791
		      {
5251
		      {
4792
		      case '0':
5252
		      case '0':
4793
			d_append_string (dpi, "false");
5253
			d_append_string (dpi, "false");
4794
			return;
5254
			return;
4795
		      case '1':
5255
		      case '1':
4796
			d_append_string (dpi, "true");
5256
			d_append_string (dpi, "true");
4797
			return;
5257
			return;
4798
		      default:
5258
		      default:
4799
			break;
5259
			break;
4800
		      }
5260
		      }
4801
		  }
5261
		  }
4802
		break;
5262
		break;
4803
 
5263
 
4804
	      default:
5264
	      default:
4805
		break;
5265
		break;
4806
	      }
5266
	      }
4807
	  }
5267
	  }
4808
 
5268
 
4809
	d_append_char (dpi, '(');
5269
	d_append_char (dpi, '(');
4810
	d_print_comp (dpi, options, d_left (dc));
5270
	d_print_comp (dpi, options, d_left (dc));
4811
	d_append_char (dpi, ')');
5271
	d_append_char (dpi, ')');
4812
	if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
5272
	if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG)
4813
	  d_append_char (dpi, '-');
5273
	  d_append_char (dpi, '-');
4814
	if (tp == D_PRINT_FLOAT)
5274
	if (tp == D_PRINT_FLOAT)
4815
	  d_append_char (dpi, '[');
5275
	  d_append_char (dpi, '[');
4816
	d_print_comp (dpi, options, d_right (dc));
5276
	d_print_comp (dpi, options, d_right (dc));
4817
	if (tp == D_PRINT_FLOAT)
5277
	if (tp == D_PRINT_FLOAT)
4818
	  d_append_char (dpi, ']');
5278
	  d_append_char (dpi, ']');
4819
      }
5279
      }
4820
      return;
5280
      return;
4821
 
5281
 
4822
    case DEMANGLE_COMPONENT_NUMBER:
5282
    case DEMANGLE_COMPONENT_NUMBER:
4823
      d_append_num (dpi, dc->u.s_number.number);
5283
      d_append_num (dpi, dc->u.s_number.number);
4824
      return;
5284
      return;
4825
 
5285
 
4826
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
5286
    case DEMANGLE_COMPONENT_JAVA_RESOURCE:
4827
      d_append_string (dpi, "java resource ");
5287
      d_append_string (dpi, "java resource ");
4828
      d_print_comp (dpi, options, d_left (dc));
5288
      d_print_comp (dpi, options, d_left (dc));
4829
      return;
5289
      return;
4830
 
5290
 
4831
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
5291
    case DEMANGLE_COMPONENT_COMPOUND_NAME:
4832
      d_print_comp (dpi, options, d_left (dc));
5292
      d_print_comp (dpi, options, d_left (dc));
4833
      d_print_comp (dpi, options, d_right (dc));
5293
      d_print_comp (dpi, options, d_right (dc));
4834
      return;
5294
      return;
4835
 
5295
 
4836
    case DEMANGLE_COMPONENT_CHARACTER:
5296
    case DEMANGLE_COMPONENT_CHARACTER:
4837
      d_append_char (dpi, dc->u.s_character.character);
5297
      d_append_char (dpi, dc->u.s_character.character);
4838
      return;
5298
      return;
4839
 
5299
 
4840
    case DEMANGLE_COMPONENT_DECLTYPE:
5300
    case DEMANGLE_COMPONENT_DECLTYPE:
4841
      d_append_string (dpi, "decltype (");
5301
      d_append_string (dpi, "decltype (");
4842
      d_print_comp (dpi, options, d_left (dc));
5302
      d_print_comp (dpi, options, d_left (dc));
4843
      d_append_char (dpi, ')');
5303
      d_append_char (dpi, ')');
4844
      return;
5304
      return;
4845
 
5305
 
4846
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
5306
    case DEMANGLE_COMPONENT_PACK_EXPANSION:
4847
      {
5307
      {
4848
	int len;
5308
	int len;
4849
	int i;
5309
	int i;
4850
	struct demangle_component *a = d_find_pack (dpi, d_left (dc));
5310
	struct demangle_component *a = d_find_pack (dpi, d_left (dc));
4851
	if (a == NULL)
5311
	if (a == NULL)
4852
	  {
5312
	  {
4853
	    /* d_find_pack won't find anything if the only packs involved
5313
	    /* d_find_pack won't find anything if the only packs involved
4854
	       in this expansion are function parameter packs; in that
5314
	       in this expansion are function parameter packs; in that
4855
	       case, just print the pattern and "...".  */
5315
	       case, just print the pattern and "...".  */
4856
	    d_print_subexpr (dpi, options, d_left (dc));
5316
	    d_print_subexpr (dpi, options, d_left (dc));
4857
	    d_append_string (dpi, "...");
5317
	    d_append_string (dpi, "...");
4858
	    return;
5318
	    return;
4859
	  }
5319
	  }
4860
 
5320
 
4861
	len = d_pack_length (a);
5321
	len = d_pack_length (a);
4862
	dc = d_left (dc);
5322
	dc = d_left (dc);
4863
	for (i = 0; i < len; ++i)
5323
	for (i = 0; i < len; ++i)
4864
	  {
5324
	  {
4865
	    dpi->pack_index = i;
5325
	    dpi->pack_index = i;
4866
	    d_print_comp (dpi, options, dc);
5326
	    d_print_comp (dpi, options, dc);
4867
	    if (i < len-1)
5327
	    if (i < len-1)
4868
	      d_append_string (dpi, ", ");
5328
	      d_append_string (dpi, ", ");
4869
	  }
5329
	  }
4870
      }
5330
      }
4871
      return;
5331
      return;
4872
 
5332
 
4873
    case DEMANGLE_COMPONENT_FUNCTION_PARAM:
5333
    case DEMANGLE_COMPONENT_FUNCTION_PARAM:
4874
      {
5334
      {
4875
	long num = dc->u.s_number.number;
5335
	long num = dc->u.s_number.number;
4876
	if (num == 0)
5336
	if (num == 0)
4877
	  d_append_string (dpi, "this");
5337
	  d_append_string (dpi, "this");
4878
	else
5338
	else
4879
	  {
5339
	  {
4880
	    d_append_string (dpi, "{parm#");
5340
	    d_append_string (dpi, "{parm#");
4881
	    d_append_num (dpi, num);
5341
	    d_append_num (dpi, num);
4882
	    d_append_char (dpi, '}');
5342
	    d_append_char (dpi, '}');
4883
	  }
5343
	  }
4884
      }
5344
      }
4885
      return;
5345
      return;
4886
 
5346
 
4887
    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
5347
    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
4888
      d_append_string (dpi, "global constructors keyed to ");
5348
      d_append_string (dpi, "global constructors keyed to ");
4889
      d_print_comp (dpi, options, dc->u.s_binary.left);
5349
      d_print_comp (dpi, options, dc->u.s_binary.left);
4890
      return;
5350
      return;
4891
 
5351
 
4892
    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
5352
    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
4893
      d_append_string (dpi, "global destructors keyed to ");
5353
      d_append_string (dpi, "global destructors keyed to ");
4894
      d_print_comp (dpi, options, dc->u.s_binary.left);
5354
      d_print_comp (dpi, options, dc->u.s_binary.left);
4895
      return;
5355
      return;
4896
 
5356
 
4897
    case DEMANGLE_COMPONENT_LAMBDA:
5357
    case DEMANGLE_COMPONENT_LAMBDA:
4898
      d_append_string (dpi, "{lambda(");
5358
      d_append_string (dpi, "{lambda(");
4899
      d_print_comp (dpi, options, dc->u.s_unary_num.sub);
5359
      d_print_comp (dpi, options, dc->u.s_unary_num.sub);
4900
      d_append_string (dpi, ")#");
5360
      d_append_string (dpi, ")#");
4901
      d_append_num (dpi, dc->u.s_unary_num.num + 1);
5361
      d_append_num (dpi, dc->u.s_unary_num.num + 1);
4902
      d_append_char (dpi, '}');
5362
      d_append_char (dpi, '}');
4903
      return;
5363
      return;
4904
 
5364
 
4905
    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
5365
    case DEMANGLE_COMPONENT_UNNAMED_TYPE:
4906
      d_append_string (dpi, "{unnamed type#");
5366
      d_append_string (dpi, "{unnamed type#");
4907
      d_append_num (dpi, dc->u.s_number.number + 1);
5367
      d_append_num (dpi, dc->u.s_number.number + 1);
4908
      d_append_char (dpi, '}');
5368
      d_append_char (dpi, '}');
4909
      return;
5369
      return;
4910
 
5370
 
4911
    case DEMANGLE_COMPONENT_CLONE:
5371
    case DEMANGLE_COMPONENT_CLONE:
4912
      d_print_comp (dpi, options, d_left (dc));
5372
      d_print_comp (dpi, options, d_left (dc));
4913
      d_append_string (dpi, " [clone ");
5373
      d_append_string (dpi, " [clone ");
4914
      d_print_comp (dpi, options, d_right (dc));
5374
      d_print_comp (dpi, options, d_right (dc));
4915
      d_append_char (dpi, ']');
5375
      d_append_char (dpi, ']');
4916
      return;
5376
      return;
4917
 
5377
 
4918
    default:
5378
    default:
4919
      d_print_error (dpi);
5379
      d_print_error (dpi);
4920
      return;
5380
      return;
4921
    }
5381
    }
4922
}
5382
}
-
 
5383
 
-
 
5384
static void
-
 
5385
d_print_comp (struct d_print_info *dpi, int options,
-
 
5386
	      const struct demangle_component *dc)
-
 
5387
{
-
 
5388
  struct d_component_stack self;
-
 
5389
 
-
 
5390
  self.dc = dc;
-
 
5391
  self.parent = dpi->component_stack;
-
 
5392
  dpi->component_stack = &self;
-
 
5393
 
-
 
5394
  d_print_comp_inner (dpi, options, dc);
-
 
5395
 
-
 
5396
  dpi->component_stack = self.parent;
-
 
5397
}
4923
 
5398
 
4924
/* Print a Java dentifier.  For Java we try to handle encoded extended
5399
/* Print a Java dentifier.  For Java we try to handle encoded extended
4925
   Unicode characters.  The C++ ABI doesn't mention Unicode encoding,
5400
   Unicode characters.  The C++ ABI doesn't mention Unicode encoding,
4926
   so we don't it for C++.  Characters are encoded as
5401
   so we don't it for C++.  Characters are encoded as
4927
   __U+_.  */
5402
   __U+_.  */
4928
 
5403
 
4929
static void
5404
static void
4930
d_print_java_identifier (struct d_print_info *dpi, const char *name, int len)
5405
d_print_java_identifier (struct d_print_info *dpi, const char *name, int len)
4931
{
5406
{
4932
  const char *p;
5407
  const char *p;
4933
  const char *end;
5408
  const char *end;
4934
 
5409
 
4935
  end = name + len;
5410
  end = name + len;
4936
  for (p = name; p < end; ++p)
5411
  for (p = name; p < end; ++p)
4937
    {
5412
    {
4938
      if (end - p > 3
5413
      if (end - p > 3
4939
	  && p[0] == '_'
5414
	  && p[0] == '_'
4940
	  && p[1] == '_'
5415
	  && p[1] == '_'
4941
	  && p[2] == 'U')
5416
	  && p[2] == 'U')
4942
	{
5417
	{
4943
	  unsigned long c;
5418
	  unsigned long c;
4944
	  const char *q;
5419
	  const char *q;
4945
 
5420
 
4946
	  c = 0;
5421
	  c = 0;
4947
	  for (q = p + 3; q < end; ++q)
5422
	  for (q = p + 3; q < end; ++q)
4948
	    {
5423
	    {
4949
	      int dig;
5424
	      int dig;
4950
 
5425
 
4951
	      if (IS_DIGIT (*q))
5426
	      if (IS_DIGIT (*q))
4952
		dig = *q - '0';
5427
		dig = *q - '0';
4953
	      else if (*q >= 'A' && *q <= 'F')
5428
	      else if (*q >= 'A' && *q <= 'F')
4954
		dig = *q - 'A' + 10;
5429
		dig = *q - 'A' + 10;
4955
	      else if (*q >= 'a' && *q <= 'f')
5430
	      else if (*q >= 'a' && *q <= 'f')
4956
		dig = *q - 'a' + 10;
5431
		dig = *q - 'a' + 10;
4957
	      else
5432
	      else
4958
		break;
5433
		break;
4959
 
5434
 
4960
	      c = c * 16 + dig;
5435
	      c = c * 16 + dig;
4961
	    }
5436
	    }
4962
	  /* If the Unicode character is larger than 256, we don't try
5437
	  /* If the Unicode character is larger than 256, we don't try
4963
	     to deal with it here.  FIXME.  */
5438
	     to deal with it here.  FIXME.  */
4964
	  if (q < end && *q == '_' && c < 256)
5439
	  if (q < end && *q == '_' && c < 256)
4965
	    {
5440
	    {
4966
	      d_append_char (dpi, c);
5441
	      d_append_char (dpi, c);
4967
	      p = q;
5442
	      p = q;
4968
	      continue;
5443
	      continue;
4969
	    }
5444
	    }
4970
	}
5445
	}
4971
 
5446
 
4972
      d_append_char (dpi, *p);
5447
      d_append_char (dpi, *p);
4973
    }
5448
    }
4974
}
5449
}
4975
 
5450
 
4976
/* Print a list of modifiers.  SUFFIX is 1 if we are printing
5451
/* Print a list of modifiers.  SUFFIX is 1 if we are printing
4977
   qualifiers on this after printing a function.  */
5452
   qualifiers on this after printing a function.  */
4978
 
5453
 
4979
static void
5454
static void
4980
d_print_mod_list (struct d_print_info *dpi, int options,
5455
d_print_mod_list (struct d_print_info *dpi, int options,
4981
                  struct d_print_mod *mods, int suffix)
5456
                  struct d_print_mod *mods, int suffix)
4982
{
5457
{
4983
  struct d_print_template *hold_dpt;
5458
  struct d_print_template *hold_dpt;
4984
 
5459
 
4985
  if (mods == NULL || d_print_saw_error (dpi))
5460
  if (mods == NULL || d_print_saw_error (dpi))
4986
    return;
5461
    return;
4987
 
5462
 
4988
  if (mods->printed
5463
  if (mods->printed
4989
      || (! suffix
5464
      || (! suffix
4990
	  && (mods->mod->type == DEMANGLE_COMPONENT_RESTRICT_THIS
5465
	  && (mods->mod->type == DEMANGLE_COMPONENT_RESTRICT_THIS
4991
	      || mods->mod->type == DEMANGLE_COMPONENT_VOLATILE_THIS
5466
	      || mods->mod->type == DEMANGLE_COMPONENT_VOLATILE_THIS
4992
	      || mods->mod->type == DEMANGLE_COMPONENT_CONST_THIS
5467
	      || mods->mod->type == DEMANGLE_COMPONENT_CONST_THIS
4993
	      || mods->mod->type == DEMANGLE_COMPONENT_REFERENCE_THIS
5468
	      || mods->mod->type == DEMANGLE_COMPONENT_REFERENCE_THIS
4994
	      || (mods->mod->type
5469
	      || (mods->mod->type
4995
		  == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS))))
5470
		  == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS))))
4996
    {
5471
    {
4997
      d_print_mod_list (dpi, options, mods->next, suffix);
5472
      d_print_mod_list (dpi, options, mods->next, suffix);
4998
      return;
5473
      return;
4999
    }
5474
    }
5000
 
5475
 
5001
  mods->printed = 1;
5476
  mods->printed = 1;
5002
 
5477
 
5003
  hold_dpt = dpi->templates;
5478
  hold_dpt = dpi->templates;
5004
  dpi->templates = mods->templates;
5479
  dpi->templates = mods->templates;
5005
 
5480
 
5006
  if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
5481
  if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
5007
    {
5482
    {
5008
      d_print_function_type (dpi, options, mods->mod, mods->next);
5483
      d_print_function_type (dpi, options, mods->mod, mods->next);
5009
      dpi->templates = hold_dpt;
5484
      dpi->templates = hold_dpt;
5010
      return;
5485
      return;
5011
    }
5486
    }
5012
  else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
5487
  else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
5013
    {
5488
    {
5014
      d_print_array_type (dpi, options, mods->mod, mods->next);
5489
      d_print_array_type (dpi, options, mods->mod, mods->next);
5015
      dpi->templates = hold_dpt;
5490
      dpi->templates = hold_dpt;
5016
      return;
5491
      return;
5017
    }
5492
    }
5018
  else if (mods->mod->type == DEMANGLE_COMPONENT_LOCAL_NAME)
5493
  else if (mods->mod->type == DEMANGLE_COMPONENT_LOCAL_NAME)
5019
    {
5494
    {
5020
      struct d_print_mod *hold_modifiers;
5495
      struct d_print_mod *hold_modifiers;
5021
      struct demangle_component *dc;
5496
      struct demangle_component *dc;
5022
 
5497
 
5023
      /* When this is on the modifier stack, we have pulled any
5498
      /* When this is on the modifier stack, we have pulled any
5024
	 qualifiers off the right argument already.  Otherwise, we
5499
	 qualifiers off the right argument already.  Otherwise, we
5025
	 print it as usual, but don't let the left argument see any
5500
	 print it as usual, but don't let the left argument see any
5026
	 modifiers.  */
5501
	 modifiers.  */
5027
 
5502
 
5028
      hold_modifiers = dpi->modifiers;
5503
      hold_modifiers = dpi->modifiers;
5029
      dpi->modifiers = NULL;
5504
      dpi->modifiers = NULL;
5030
      d_print_comp (dpi, options, d_left (mods->mod));
5505
      d_print_comp (dpi, options, d_left (mods->mod));
5031
      dpi->modifiers = hold_modifiers;
5506
      dpi->modifiers = hold_modifiers;
5032
 
5507
 
5033
      if ((options & DMGL_JAVA) == 0)
5508
      if ((options & DMGL_JAVA) == 0)
5034
	d_append_string (dpi, "::");
5509
	d_append_string (dpi, "::");
5035
      else
5510
      else
5036
	d_append_char (dpi, '.');
5511
	d_append_char (dpi, '.');
5037
 
5512
 
5038
      dc = d_right (mods->mod);
5513
      dc = d_right (mods->mod);
5039
 
5514
 
5040
      if (dc->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
5515
      if (dc->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
5041
	{
5516
	{
5042
	  d_append_string (dpi, "{default arg#");
5517
	  d_append_string (dpi, "{default arg#");
5043
	  d_append_num (dpi, dc->u.s_unary_num.num + 1);
5518
	  d_append_num (dpi, dc->u.s_unary_num.num + 1);
5044
	  d_append_string (dpi, "}::");
5519
	  d_append_string (dpi, "}::");
5045
	  dc = dc->u.s_unary_num.sub;
5520
	  dc = dc->u.s_unary_num.sub;
5046
	}
5521
	}
5047
 
5522
 
5048
      while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
5523
      while (dc->type == DEMANGLE_COMPONENT_RESTRICT_THIS
5049
	     || dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
5524
	     || dc->type == DEMANGLE_COMPONENT_VOLATILE_THIS
5050
	     || dc->type == DEMANGLE_COMPONENT_CONST_THIS
5525
	     || dc->type == DEMANGLE_COMPONENT_CONST_THIS
5051
	     || dc->type == DEMANGLE_COMPONENT_REFERENCE_THIS
5526
	     || dc->type == DEMANGLE_COMPONENT_REFERENCE_THIS
5052
	     || dc->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS)
5527
	     || dc->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS)
5053
	dc = d_left (dc);
5528
	dc = d_left (dc);
5054
 
5529
 
5055
      d_print_comp (dpi, options, dc);
5530
      d_print_comp (dpi, options, dc);
5056
 
5531
 
5057
      dpi->templates = hold_dpt;
5532
      dpi->templates = hold_dpt;
5058
      return;
5533
      return;
5059
    }
5534
    }
5060
 
5535
 
5061
  d_print_mod (dpi, options, mods->mod);
5536
  d_print_mod (dpi, options, mods->mod);
5062
 
5537
 
5063
  dpi->templates = hold_dpt;
5538
  dpi->templates = hold_dpt;
5064
 
5539
 
5065
  d_print_mod_list (dpi, options, mods->next, suffix);
5540
  d_print_mod_list (dpi, options, mods->next, suffix);
5066
}
5541
}
5067
 
5542
 
5068
/* Print a modifier.  */
5543
/* Print a modifier.  */
5069
 
5544
 
5070
static void
5545
static void
5071
d_print_mod (struct d_print_info *dpi, int options,
5546
d_print_mod (struct d_print_info *dpi, int options,
5072
             const struct demangle_component *mod)
5547
             const struct demangle_component *mod)
5073
{
5548
{
5074
  switch (mod->type)
5549
  switch (mod->type)
5075
    {
5550
    {
5076
    case DEMANGLE_COMPONENT_RESTRICT:
5551
    case DEMANGLE_COMPONENT_RESTRICT:
5077
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
5552
    case DEMANGLE_COMPONENT_RESTRICT_THIS:
5078
      d_append_string (dpi, " restrict");
5553
      d_append_string (dpi, " restrict");
5079
      return;
5554
      return;
5080
    case DEMANGLE_COMPONENT_VOLATILE:
5555
    case DEMANGLE_COMPONENT_VOLATILE:
5081
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
5556
    case DEMANGLE_COMPONENT_VOLATILE_THIS:
5082
      d_append_string (dpi, " volatile");
5557
      d_append_string (dpi, " volatile");
5083
      return;
5558
      return;
5084
    case DEMANGLE_COMPONENT_CONST:
5559
    case DEMANGLE_COMPONENT_CONST:
5085
    case DEMANGLE_COMPONENT_CONST_THIS:
5560
    case DEMANGLE_COMPONENT_CONST_THIS:
5086
      d_append_string (dpi, " const");
5561
      d_append_string (dpi, " const");
5087
      return;
5562
      return;
5088
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5563
    case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5089
      d_append_char (dpi, ' ');
5564
      d_append_char (dpi, ' ');
5090
      d_print_comp (dpi, options, d_right (mod));
5565
      d_print_comp (dpi, options, d_right (mod));
5091
      return;
5566
      return;
5092
    case DEMANGLE_COMPONENT_POINTER:
5567
    case DEMANGLE_COMPONENT_POINTER:
5093
      /* There is no pointer symbol in Java.  */
5568
      /* There is no pointer symbol in Java.  */
5094
      if ((options & DMGL_JAVA) == 0)
5569
      if ((options & DMGL_JAVA) == 0)
5095
	d_append_char (dpi, '*');
5570
	d_append_char (dpi, '*');
5096
      return;
5571
      return;
5097
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
5572
    case DEMANGLE_COMPONENT_REFERENCE_THIS:
5098
      /* For the ref-qualifier, put a space before the &.  */
5573
      /* For the ref-qualifier, put a space before the &.  */
5099
      d_append_char (dpi, ' ');
5574
      d_append_char (dpi, ' ');
5100
    case DEMANGLE_COMPONENT_REFERENCE:
5575
    case DEMANGLE_COMPONENT_REFERENCE:
5101
      d_append_char (dpi, '&');
5576
      d_append_char (dpi, '&');
5102
      return;
5577
      return;
5103
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
5578
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
5104
      d_append_char (dpi, ' ');
5579
      d_append_char (dpi, ' ');
5105
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
5580
    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
5106
      d_append_string (dpi, "&&");
5581
      d_append_string (dpi, "&&");
5107
      return;
5582
      return;
5108
    case DEMANGLE_COMPONENT_COMPLEX:
5583
    case DEMANGLE_COMPONENT_COMPLEX:
5109
      d_append_string (dpi, "complex ");
5584
      d_append_string (dpi, "complex ");
5110
      return;
5585
      return;
5111
    case DEMANGLE_COMPONENT_IMAGINARY:
5586
    case DEMANGLE_COMPONENT_IMAGINARY:
5112
      d_append_string (dpi, "imaginary ");
5587
      d_append_string (dpi, "imaginary ");
5113
      return;
5588
      return;
5114
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5589
    case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5115
      if (d_last_char (dpi) != '(')
5590
      if (d_last_char (dpi) != '(')
5116
	d_append_char (dpi, ' ');
5591
	d_append_char (dpi, ' ');
5117
      d_print_comp (dpi, options, d_left (mod));
5592
      d_print_comp (dpi, options, d_left (mod));
5118
      d_append_string (dpi, "::*");
5593
      d_append_string (dpi, "::*");
5119
      return;
5594
      return;
5120
    case DEMANGLE_COMPONENT_TYPED_NAME:
5595
    case DEMANGLE_COMPONENT_TYPED_NAME:
5121
      d_print_comp (dpi, options, d_left (mod));
5596
      d_print_comp (dpi, options, d_left (mod));
5122
      return;
5597
      return;
5123
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
5598
    case DEMANGLE_COMPONENT_VECTOR_TYPE:
5124
      d_append_string (dpi, " __vector(");
5599
      d_append_string (dpi, " __vector(");
5125
      d_print_comp (dpi, options, d_left (mod));
5600
      d_print_comp (dpi, options, d_left (mod));
5126
      d_append_char (dpi, ')');
5601
      d_append_char (dpi, ')');
5127
      return;
5602
      return;
5128
 
5603
 
5129
    default:
5604
    default:
5130
      /* Otherwise, we have something that won't go back on the
5605
      /* Otherwise, we have something that won't go back on the
5131
	 modifier stack, so we can just print it.  */
5606
	 modifier stack, so we can just print it.  */
5132
      d_print_comp (dpi, options, mod);
5607
      d_print_comp (dpi, options, mod);
5133
      return;
5608
      return;
5134
    }
5609
    }
5135
}
5610
}
5136
 
5611
 
5137
/* Print a function type, except for the return type.  */
5612
/* Print a function type, except for the return type.  */
5138
 
5613
 
5139
static void
5614
static void
5140
d_print_function_type (struct d_print_info *dpi, int options,
5615
d_print_function_type (struct d_print_info *dpi, int options,
5141
                       const struct demangle_component *dc,
5616
                       const struct demangle_component *dc,
5142
                       struct d_print_mod *mods)
5617
                       struct d_print_mod *mods)
5143
{
5618
{
5144
  int need_paren;
5619
  int need_paren;
5145
  int need_space;
5620
  int need_space;
5146
  struct d_print_mod *p;
5621
  struct d_print_mod *p;
5147
  struct d_print_mod *hold_modifiers;
5622
  struct d_print_mod *hold_modifiers;
5148
 
5623
 
5149
  need_paren = 0;
5624
  need_paren = 0;
5150
  need_space = 0;
5625
  need_space = 0;
5151
  for (p = mods; p != NULL; p = p->next)
5626
  for (p = mods; p != NULL; p = p->next)
5152
    {
5627
    {
5153
      if (p->printed)
5628
      if (p->printed)
5154
	break;
5629
	break;
5155
 
5630
 
5156
      switch (p->mod->type)
5631
      switch (p->mod->type)
5157
	{
5632
	{
5158
	case DEMANGLE_COMPONENT_POINTER:
5633
	case DEMANGLE_COMPONENT_POINTER:
5159
	case DEMANGLE_COMPONENT_REFERENCE:
5634
	case DEMANGLE_COMPONENT_REFERENCE:
5160
	case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
5635
	case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
5161
	  need_paren = 1;
5636
	  need_paren = 1;
5162
	  break;
5637
	  break;
5163
	case DEMANGLE_COMPONENT_RESTRICT:
5638
	case DEMANGLE_COMPONENT_RESTRICT:
5164
	case DEMANGLE_COMPONENT_VOLATILE:
5639
	case DEMANGLE_COMPONENT_VOLATILE:
5165
	case DEMANGLE_COMPONENT_CONST:
5640
	case DEMANGLE_COMPONENT_CONST:
5166
	case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5641
	case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5167
	case DEMANGLE_COMPONENT_COMPLEX:
5642
	case DEMANGLE_COMPONENT_COMPLEX:
5168
	case DEMANGLE_COMPONENT_IMAGINARY:
5643
	case DEMANGLE_COMPONENT_IMAGINARY:
5169
	case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5644
	case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5170
	  need_space = 1;
5645
	  need_space = 1;
5171
	  need_paren = 1;
5646
	  need_paren = 1;
5172
	  break;
5647
	  break;
5173
	case DEMANGLE_COMPONENT_RESTRICT_THIS:
5648
	case DEMANGLE_COMPONENT_RESTRICT_THIS:
5174
	case DEMANGLE_COMPONENT_VOLATILE_THIS:
5649
	case DEMANGLE_COMPONENT_VOLATILE_THIS:
5175
	case DEMANGLE_COMPONENT_CONST_THIS:
5650
	case DEMANGLE_COMPONENT_CONST_THIS:
5176
	case DEMANGLE_COMPONENT_REFERENCE_THIS:
5651
	case DEMANGLE_COMPONENT_REFERENCE_THIS:
5177
	case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
5652
	case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
5178
	  break;
5653
	  break;
5179
	default:
5654
	default:
5180
	  break;
5655
	  break;
5181
	}
5656
	}
5182
      if (need_paren)
5657
      if (need_paren)
5183
	break;
5658
	break;
5184
    }
5659
    }
5185
 
5660
 
5186
  if (need_paren)
5661
  if (need_paren)
5187
    {
5662
    {
5188
      if (! need_space)
5663
      if (! need_space)
5189
	{
5664
	{
5190
	  if (d_last_char (dpi) != '('
5665
	  if (d_last_char (dpi) != '('
5191
	      && d_last_char (dpi) != '*')
5666
	      && d_last_char (dpi) != '*')
5192
	    need_space = 1;
5667
	    need_space = 1;
5193
	}
5668
	}
5194
      if (need_space && d_last_char (dpi) != ' ')
5669
      if (need_space && d_last_char (dpi) != ' ')
5195
	d_append_char (dpi, ' ');
5670
	d_append_char (dpi, ' ');
5196
      d_append_char (dpi, '(');
5671
      d_append_char (dpi, '(');
5197
    }
5672
    }
5198
 
5673
 
5199
  hold_modifiers = dpi->modifiers;
5674
  hold_modifiers = dpi->modifiers;
5200
  dpi->modifiers = NULL;
5675
  dpi->modifiers = NULL;
5201
 
5676
 
5202
  d_print_mod_list (dpi, options, mods, 0);
5677
  d_print_mod_list (dpi, options, mods, 0);
5203
 
5678
 
5204
  if (need_paren)
5679
  if (need_paren)
5205
    d_append_char (dpi, ')');
5680
    d_append_char (dpi, ')');
5206
 
5681
 
5207
  d_append_char (dpi, '(');
5682
  d_append_char (dpi, '(');
5208
 
5683
 
5209
  if (d_right (dc) != NULL)
5684
  if (d_right (dc) != NULL)
5210
    d_print_comp (dpi, options, d_right (dc));
5685
    d_print_comp (dpi, options, d_right (dc));
5211
 
5686
 
5212
  d_append_char (dpi, ')');
5687
  d_append_char (dpi, ')');
5213
 
5688
 
5214
  d_print_mod_list (dpi, options, mods, 1);
5689
  d_print_mod_list (dpi, options, mods, 1);
5215
 
5690
 
5216
  dpi->modifiers = hold_modifiers;
5691
  dpi->modifiers = hold_modifiers;
5217
}
5692
}
5218
 
5693
 
5219
/* Print an array type, except for the element type.  */
5694
/* Print an array type, except for the element type.  */
5220
 
5695
 
5221
static void
5696
static void
5222
d_print_array_type (struct d_print_info *dpi, int options,
5697
d_print_array_type (struct d_print_info *dpi, int options,
5223
                    const struct demangle_component *dc,
5698
                    const struct demangle_component *dc,
5224
                    struct d_print_mod *mods)
5699
                    struct d_print_mod *mods)
5225
{
5700
{
5226
  int need_space;
5701
  int need_space;
5227
 
5702
 
5228
  need_space = 1;
5703
  need_space = 1;
5229
  if (mods != NULL)
5704
  if (mods != NULL)
5230
    {
5705
    {
5231
      int need_paren;
5706
      int need_paren;
5232
      struct d_print_mod *p;
5707
      struct d_print_mod *p;
5233
 
5708
 
5234
      need_paren = 0;
5709
      need_paren = 0;
5235
      for (p = mods; p != NULL; p = p->next)
5710
      for (p = mods; p != NULL; p = p->next)
5236
	{
5711
	{
5237
	  if (! p->printed)
5712
	  if (! p->printed)
5238
	    {
5713
	    {
5239
	      if (p->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
5714
	      if (p->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE)
5240
		{
5715
		{
5241
		  need_space = 0;
5716
		  need_space = 0;
5242
		  break;
5717
		  break;
5243
		}
5718
		}
5244
	      else
5719
	      else
5245
		{
5720
		{
5246
		  need_paren = 1;
5721
		  need_paren = 1;
5247
		  need_space = 1;
5722
		  need_space = 1;
5248
		  break;
5723
		  break;
5249
		}
5724
		}
5250
	    }
5725
	    }
5251
	}
5726
	}
5252
 
5727
 
5253
      if (need_paren)
5728
      if (need_paren)
5254
	d_append_string (dpi, " (");
5729
	d_append_string (dpi, " (");
5255
 
5730
 
5256
      d_print_mod_list (dpi, options, mods, 0);
5731
      d_print_mod_list (dpi, options, mods, 0);
5257
 
5732
 
5258
      if (need_paren)
5733
      if (need_paren)
5259
	d_append_char (dpi, ')');
5734
	d_append_char (dpi, ')');
5260
    }
5735
    }
5261
 
5736
 
5262
  if (need_space)
5737
  if (need_space)
5263
    d_append_char (dpi, ' ');
5738
    d_append_char (dpi, ' ');
5264
 
5739
 
5265
  d_append_char (dpi, '[');
5740
  d_append_char (dpi, '[');
5266
 
5741
 
5267
  if (d_left (dc) != NULL)
5742
  if (d_left (dc) != NULL)
5268
    d_print_comp (dpi, options, d_left (dc));
5743
    d_print_comp (dpi, options, d_left (dc));
5269
 
5744
 
5270
  d_append_char (dpi, ']');
5745
  d_append_char (dpi, ']');
5271
}
5746
}
5272
 
5747
 
5273
/* Print an operator in an expression.  */
5748
/* Print an operator in an expression.  */
5274
 
5749
 
5275
static void
5750
static void
5276
d_print_expr_op (struct d_print_info *dpi, int options,
5751
d_print_expr_op (struct d_print_info *dpi, int options,
5277
                 const struct demangle_component *dc)
5752
                 const struct demangle_component *dc)
5278
{
5753
{
5279
  if (dc->type == DEMANGLE_COMPONENT_OPERATOR)
5754
  if (dc->type == DEMANGLE_COMPONENT_OPERATOR)
5280
    d_append_buffer (dpi, dc->u.s_operator.op->name,
5755
    d_append_buffer (dpi, dc->u.s_operator.op->name,
5281
		     dc->u.s_operator.op->len);
5756
		     dc->u.s_operator.op->len);
5282
  else
5757
  else
5283
    d_print_comp (dpi, options, dc);
5758
    d_print_comp (dpi, options, dc);
5284
}
5759
}
5285
 
5760
 
5286
/* Print a cast.  */
5761
/* Print a cast.  */
5287
 
5762
 
5288
static void
5763
static void
5289
d_print_cast (struct d_print_info *dpi, int options,
5764
d_print_cast (struct d_print_info *dpi, int options,
5290
              const struct demangle_component *dc)
5765
              const struct demangle_component *dc)
5291
{
5766
{
5292
  if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
-
 
5293
    d_print_comp (dpi, options, d_left (dc));
-
 
5294
  else
-
 
5295
    {
-
 
5296
      struct d_print_mod *hold_dpm;
-
 
5297
      struct d_print_template dpt;
5767
      struct d_print_template dpt;
5298
 
5768
 
5299
      /* It appears that for a templated cast operator, we need to put
5769
  /* For a cast operator, we need the template parameters from
5300
	 the template parameters in scope for the operator name, but
-
 
5301
	 not for the parameters.  The effect is that we need to handle
-
 
5302
	 the template printing here.  */
-
 
5303
 
-
 
5304
      hold_dpm = dpi->modifiers;
5770
     the enclosing template in scope for processing the type.  */
5305
      dpi->modifiers = NULL;
5771
  if (dpi->current_template != NULL)
5306
 
5772
    {
5307
      dpt.next = dpi->templates;
5773
      dpt.next = dpi->templates;
5308
      dpi->templates = &dpt;
5774
      dpi->templates = &dpt;
-
 
5775
      dpt.template_decl = dpi->current_template;
-
 
5776
    }
-
 
5777
 
-
 
5778
  if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
-
 
5779
    {
-
 
5780
      d_print_comp (dpi, options, d_left (dc));
-
 
5781
      if (dpi->current_template != NULL)
-
 
5782
	dpi->templates = dpt.next;
-
 
5783
    }
5309
      dpt.template_decl = d_left (dc);
5784
  else
-
 
5785
    {
-
 
5786
      d_print_comp (dpi, options, d_left (d_left (dc)));
-
 
5787
 
-
 
5788
      /* For a templated cast operator, we need to remove the template
5310
 
5789
	 parameters from scope after printing the operator name,
5311
      d_print_comp (dpi, options, d_left (d_left (dc)));
5790
	 so we need to handle the template printing here.  */
5312
 
5791
      if (dpi->current_template != NULL)
5313
      dpi->templates = dpt.next;
5792
      dpi->templates = dpt.next;
5314
 
5793
 
5315
      if (d_last_char (dpi) == '<')
5794
      if (d_last_char (dpi) == '<')
5316
	d_append_char (dpi, ' ');
5795
	d_append_char (dpi, ' ');
5317
      d_append_char (dpi, '<');
5796
      d_append_char (dpi, '<');
5318
      d_print_comp (dpi, options, d_right (d_left (dc)));
5797
      d_print_comp (dpi, options, d_right (d_left (dc)));
5319
      /* Avoid generating two consecutive '>' characters, to avoid
5798
      /* Avoid generating two consecutive '>' characters, to avoid
5320
	 the C++ syntactic ambiguity.  */
5799
	 the C++ syntactic ambiguity.  */
5321
      if (d_last_char (dpi) == '>')
5800
      if (d_last_char (dpi) == '>')
5322
	d_append_char (dpi, ' ');
5801
	d_append_char (dpi, ' ');
5323
      d_append_char (dpi, '>');
5802
      d_append_char (dpi, '>');
5324
 
-
 
5325
      dpi->modifiers = hold_dpm;
-
 
5326
    }
5803
    }
5327
}
5804
}
5328
 
5805
 
5329
/* Initialize the information structure we use to pass around
5806
/* Initialize the information structure we use to pass around
5330
   information.  */
5807
   information.  */
5331
 
5808
 
5332
CP_STATIC_IF_GLIBCPP_V3
5809
CP_STATIC_IF_GLIBCPP_V3
5333
void
5810
void
5334
cplus_demangle_init_info (const char *mangled, int options, size_t len,
5811
cplus_demangle_init_info (const char *mangled, int options, size_t len,
5335
                          struct d_info *di)
5812
                          struct d_info *di)
5336
{
5813
{
5337
  di->s = mangled;
5814
  di->s = mangled;
5338
  di->send = mangled + len;
5815
  di->send = mangled + len;
5339
  di->options = options;
5816
  di->options = options;
5340
 
5817
 
5341
  di->n = mangled;
5818
  di->n = mangled;
5342
 
5819
 
5343
  /* We can not need more components than twice the number of chars in
5820
  /* We can not need more components than twice the number of chars in
5344
     the mangled string.  Most components correspond directly to
5821
     the mangled string.  Most components correspond directly to
5345
     chars, but the ARGLIST types are exceptions.  */
5822
     chars, but the ARGLIST types are exceptions.  */
5346
  di->num_comps = 2 * len;
5823
  di->num_comps = 2 * len;
5347
  di->next_comp = 0;
5824
  di->next_comp = 0;
5348
 
5825
 
5349
  /* Similarly, we can not need more substitutions than there are
5826
  /* Similarly, we can not need more substitutions than there are
5350
     chars in the mangled string.  */
5827
     chars in the mangled string.  */
5351
  di->num_subs = len;
5828
  di->num_subs = len;
5352
  di->next_sub = 0;
5829
  di->next_sub = 0;
5353
  di->did_subs = 0;
5830
  di->did_subs = 0;
5354
 
5831
 
5355
  di->last_name = NULL;
5832
  di->last_name = NULL;
5356
 
5833
 
5357
  di->expansion = 0;
5834
  di->expansion = 0;
-
 
5835
  di->is_expression = 0;
-
 
5836
  di->is_conversion = 0;
5358
}
5837
}
5359
 
5838
 
5360
/* Internal implementation for the demangler.  If MANGLED is a g++ v3 ABI
5839
/* Internal implementation for the demangler.  If MANGLED is a g++ v3 ABI
5361
   mangled name, return strings in repeated callback giving the demangled
5840
   mangled name, return strings in repeated callback giving the demangled
5362
   name.  OPTIONS is the usual libiberty demangler options.  On success,
5841
   name.  OPTIONS is the usual libiberty demangler options.  On success,
5363
   this returns 1.  On failure, returns 0.  */
5842
   this returns 1.  On failure, returns 0.  */
5364
 
5843
 
5365
static int
5844
static int
5366
d_demangle_callback (const char *mangled, int options,
5845
d_demangle_callback (const char *mangled, int options,
5367
                     demangle_callbackref callback, void *opaque)
5846
                     demangle_callbackref callback, void *opaque)
5368
{
5847
{
5369
  enum
5848
  enum
5370
    {
5849
    {
5371
      DCT_TYPE,
5850
      DCT_TYPE,
5372
      DCT_MANGLED,
5851
      DCT_MANGLED,
5373
      DCT_GLOBAL_CTORS,
5852
      DCT_GLOBAL_CTORS,
5374
      DCT_GLOBAL_DTORS
5853
      DCT_GLOBAL_DTORS
5375
    }
5854
    }
5376
  type;
5855
  type;
5377
  struct d_info di;
5856
  struct d_info di;
5378
  struct demangle_component *dc;
5857
  struct demangle_component *dc;
5379
  int status;
5858
  int status;
5380
 
5859
 
5381
  if (mangled[0] == '_' && mangled[1] == 'Z')
5860
  if (mangled[0] == '_' && mangled[1] == 'Z')
5382
    type = DCT_MANGLED;
5861
    type = DCT_MANGLED;
5383
  else if (strncmp (mangled, "_GLOBAL_", 8) == 0
5862
  else if (strncmp (mangled, "_GLOBAL_", 8) == 0
5384
	   && (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
5863
	   && (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
5385
	   && (mangled[9] == 'D' || mangled[9] == 'I')
5864
	   && (mangled[9] == 'D' || mangled[9] == 'I')
5386
	   && mangled[10] == '_')
5865
	   && mangled[10] == '_')
5387
    type = mangled[9] == 'I' ? DCT_GLOBAL_CTORS : DCT_GLOBAL_DTORS;
5866
    type = mangled[9] == 'I' ? DCT_GLOBAL_CTORS : DCT_GLOBAL_DTORS;
5388
  else
5867
  else
5389
    {
5868
    {
5390
      if ((options & DMGL_TYPES) == 0)
5869
      if ((options & DMGL_TYPES) == 0)
5391
	return 0;
5870
	return 0;
5392
      type = DCT_TYPE;
5871
      type = DCT_TYPE;
5393
    }
5872
    }
5394
 
5873
 
5395
  cplus_demangle_init_info (mangled, options, strlen (mangled), &di);
5874
  cplus_demangle_init_info (mangled, options, strlen (mangled), &di);
5396
 
5875
 
5397
  {
5876
  {
5398
#ifdef CP_DYNAMIC_ARRAYS
5877
#ifdef CP_DYNAMIC_ARRAYS
5399
    __extension__ struct demangle_component comps[di.num_comps];
5878
    __extension__ struct demangle_component comps[di.num_comps];
5400
    __extension__ struct demangle_component *subs[di.num_subs];
5879
    __extension__ struct demangle_component *subs[di.num_subs];
5401
 
5880
 
5402
    di.comps = comps;
5881
    di.comps = comps;
5403
    di.subs = subs;
5882
    di.subs = subs;
5404
#else
5883
#else
5405
    di.comps = alloca (di.num_comps * sizeof (*di.comps));
5884
    di.comps = alloca (di.num_comps * sizeof (*di.comps));
5406
    di.subs = alloca (di.num_subs * sizeof (*di.subs));
5885
    di.subs = alloca (di.num_subs * sizeof (*di.subs));
5407
#endif
5886
#endif
5408
 
5887
 
5409
    switch (type)
5888
    switch (type)
5410
      {
5889
      {
5411
      case DCT_TYPE:
5890
      case DCT_TYPE:
5412
	dc = cplus_demangle_type (&di);
5891
	dc = cplus_demangle_type (&di);
5413
	break;
5892
	break;
5414
      case DCT_MANGLED:
5893
      case DCT_MANGLED:
5415
	dc = cplus_demangle_mangled_name (&di, 1);
5894
	dc = cplus_demangle_mangled_name (&di, 1);
5416
	break;
5895
	break;
5417
      case DCT_GLOBAL_CTORS:
5896
      case DCT_GLOBAL_CTORS:
5418
      case DCT_GLOBAL_DTORS:
5897
      case DCT_GLOBAL_DTORS:
5419
	d_advance (&di, 11);
5898
	d_advance (&di, 11);
5420
	dc = d_make_comp (&di,
5899
	dc = d_make_comp (&di,
5421
			  (type == DCT_GLOBAL_CTORS
5900
			  (type == DCT_GLOBAL_CTORS
5422
			   ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5901
			   ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5423
			   : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS),
5902
			   : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS),
5424
			  d_make_demangle_mangled_name (&di, d_str (&di)),
5903
			  d_make_demangle_mangled_name (&di, d_str (&di)),
5425
			  NULL);
5904
			  NULL);
5426
	d_advance (&di, strlen (d_str (&di)));
5905
	d_advance (&di, strlen (d_str (&di)));
5427
	break;
5906
	break;
-
 
5907
      default:
-
 
5908
	abort (); /* We have listed all the cases.  */
5428
      }
5909
      }
5429
 
5910
 
5430
    /* If DMGL_PARAMS is set, then if we didn't consume the entire
5911
    /* If DMGL_PARAMS is set, then if we didn't consume the entire
5431
       mangled string, then we didn't successfully demangle it.  If
5912
       mangled string, then we didn't successfully demangle it.  If
5432
       DMGL_PARAMS is not set, we didn't look at the trailing
5913
       DMGL_PARAMS is not set, we didn't look at the trailing
5433
       parameters.  */
5914
       parameters.  */
5434
    if (((options & DMGL_PARAMS) != 0) && d_peek_char (&di) != '\0')
5915
    if (((options & DMGL_PARAMS) != 0) && d_peek_char (&di) != '\0')
5435
      dc = NULL;
5916
      dc = NULL;
5436
 
5917
 
5437
#ifdef CP_DEMANGLE_DEBUG
5918
#ifdef CP_DEMANGLE_DEBUG
5438
    d_dump (dc, 0);
5919
    d_dump (dc, 0);
5439
#endif
5920
#endif
5440
 
5921
 
5441
    status = (dc != NULL)
5922
    status = (dc != NULL)
5442
             ? cplus_demangle_print_callback (options, dc, callback, opaque)
5923
             ? cplus_demangle_print_callback (options, dc, callback, opaque)
5443
             : 0;
5924
             : 0;
5444
  }
5925
  }
5445
 
5926
 
5446
  return status;
5927
  return status;
5447
}
5928
}
5448
 
5929
 
5449
/* Entry point for the demangler.  If MANGLED is a g++ v3 ABI mangled
5930
/* Entry point for the demangler.  If MANGLED is a g++ v3 ABI mangled
5450
   name, return a buffer allocated with malloc holding the demangled
5931
   name, return a buffer allocated with malloc holding the demangled
5451
   name.  OPTIONS is the usual libiberty demangler options.  On
5932
   name.  OPTIONS is the usual libiberty demangler options.  On
5452
   success, this sets *PALC to the allocated size of the returned
5933
   success, this sets *PALC to the allocated size of the returned
5453
   buffer.  On failure, this sets *PALC to 0 for a bad name, or 1 for
5934
   buffer.  On failure, this sets *PALC to 0 for a bad name, or 1 for
5454
   a memory allocation failure, and returns NULL.  */
5935
   a memory allocation failure, and returns NULL.  */
5455
 
5936
 
5456
static char *
5937
static char *
5457
d_demangle (const char *mangled, int options, size_t *palc)
5938
d_demangle (const char *mangled, int options, size_t *palc)
5458
{
5939
{
5459
  struct d_growable_string dgs;
5940
  struct d_growable_string dgs;
5460
  int status;
5941
  int status;
5461
 
5942
 
5462
  d_growable_string_init (&dgs, 0);
5943
  d_growable_string_init (&dgs, 0);
5463
 
5944
 
5464
  status = d_demangle_callback (mangled, options,
5945
  status = d_demangle_callback (mangled, options,
5465
                                d_growable_string_callback_adapter, &dgs);
5946
                                d_growable_string_callback_adapter, &dgs);
5466
  if (status == 0)
5947
  if (status == 0)
5467
    {
5948
    {
5468
      free (dgs.buf);
5949
      free (dgs.buf);
5469
      *palc = 0;
5950
      *palc = 0;
5470
      return NULL;
5951
      return NULL;
5471
    }
5952
    }
5472
 
5953
 
5473
  *palc = dgs.allocation_failure ? 1 : dgs.alc;
5954
  *palc = dgs.allocation_failure ? 1 : dgs.alc;
5474
  return dgs.buf;
5955
  return dgs.buf;
5475
}
5956
}
5476
 
5957
 
5477
#if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5958
#if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5478
 
5959
 
5479
extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5960
extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5480
 
5961
 
5481
/* ia64 ABI-mandated entry point in the C++ runtime library for
5962
/* ia64 ABI-mandated entry point in the C++ runtime library for
5482
   performing demangling.  MANGLED_NAME is a NUL-terminated character
5963
   performing demangling.  MANGLED_NAME is a NUL-terminated character
5483
   string containing the name to be demangled.
5964
   string containing the name to be demangled.
5484
 
5965
 
5485
   OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5966
   OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5486
   *LENGTH bytes, into which the demangled name is stored.  If
5967
   *LENGTH bytes, into which the demangled name is stored.  If
5487
   OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5968
   OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5488
   OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5969
   OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5489
   is placed in a region of memory allocated with malloc.
5970
   is placed in a region of memory allocated with malloc.
5490
 
5971
 
5491
   If LENGTH is non-NULL, the length of the buffer containing the
5972
   If LENGTH is non-NULL, the length of the buffer containing the
5492
   demangled name, is placed in *LENGTH.
5973
   demangled name, is placed in *LENGTH.
5493
 
5974
 
5494
   The return value is a pointer to the start of the NUL-terminated
5975
   The return value is a pointer to the start of the NUL-terminated
5495
   demangled name, or NULL if the demangling fails.  The caller is
5976
   demangled name, or NULL if the demangling fails.  The caller is
5496
   responsible for deallocating this memory using free.
5977
   responsible for deallocating this memory using free.
5497
 
5978
 
5498
   *STATUS is set to one of the following values:
5979
   *STATUS is set to one of the following values:
5499
      0: The demangling operation succeeded.
5980
      0: The demangling operation succeeded.
5500
     -1: A memory allocation failure occurred.
5981
     -1: A memory allocation failure occurred.
5501
     -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5982
     -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5502
     -3: One of the arguments is invalid.
5983
     -3: One of the arguments is invalid.
5503
 
5984
 
5504
   The demangling is performed using the C++ ABI mangling rules, with
5985
   The demangling is performed using the C++ ABI mangling rules, with
5505
   GNU extensions.  */
5986
   GNU extensions.  */
5506
 
5987
 
5507
char *
5988
char *
5508
__cxa_demangle (const char *mangled_name, char *output_buffer,
5989
__cxa_demangle (const char *mangled_name, char *output_buffer,
5509
                size_t *length, int *status)
5990
                size_t *length, int *status)
5510
{
5991
{
5511
  char *demangled;
5992
  char *demangled;
5512
  size_t alc;
5993
  size_t alc;
5513
 
5994
 
5514
  if (mangled_name == NULL)
5995
  if (mangled_name == NULL)
5515
    {
5996
    {
5516
      if (status != NULL)
5997
      if (status != NULL)
5517
	*status = -3;
5998
	*status = -3;
5518
      return NULL;
5999
      return NULL;
5519
    }
6000
    }
5520
 
6001
 
5521
  if (output_buffer != NULL && length == NULL)
6002
  if (output_buffer != NULL && length == NULL)
5522
    {
6003
    {
5523
      if (status != NULL)
6004
      if (status != NULL)
5524
	*status = -3;
6005
	*status = -3;
5525
      return NULL;
6006
      return NULL;
5526
    }
6007
    }
5527
 
6008
 
5528
  demangled = d_demangle (mangled_name, DMGL_PARAMS | DMGL_TYPES, &alc);
6009
  demangled = d_demangle (mangled_name, DMGL_PARAMS | DMGL_TYPES, &alc);
5529
 
6010
 
5530
  if (demangled == NULL)
6011
  if (demangled == NULL)
5531
    {
6012
    {
5532
      if (status != NULL)
6013
      if (status != NULL)
5533
	{
6014
	{
5534
	  if (alc == 1)
6015
	  if (alc == 1)
5535
	    *status = -1;
6016
	    *status = -1;
5536
	  else
6017
	  else
5537
	    *status = -2;
6018
	    *status = -2;
5538
	}
6019
	}
5539
      return NULL;
6020
      return NULL;
5540
    }
6021
    }
5541
 
6022
 
5542
  if (output_buffer == NULL)
6023
  if (output_buffer == NULL)
5543
    {
6024
    {
5544
      if (length != NULL)
6025
      if (length != NULL)
5545
	*length = alc;
6026
	*length = alc;
5546
    }
6027
    }
5547
  else
6028
  else
5548
    {
6029
    {
5549
      if (strlen (demangled) < *length)
6030
      if (strlen (demangled) < *length)
5550
	{
6031
	{
5551
	  strcpy (output_buffer, demangled);
6032
	  strcpy (output_buffer, demangled);
5552
	  free (demangled);
6033
	  free (demangled);
5553
	  demangled = output_buffer;
6034
	  demangled = output_buffer;
5554
	}
6035
	}
5555
      else
6036
      else
5556
	{
6037
	{
5557
	  free (output_buffer);
6038
	  free (output_buffer);
5558
	  *length = alc;
6039
	  *length = alc;
5559
	}
6040
	}
5560
    }
6041
    }
5561
 
6042
 
5562
  if (status != NULL)
6043
  if (status != NULL)
5563
    *status = 0;
6044
    *status = 0;
5564
 
6045
 
5565
  return demangled;
6046
  return demangled;
5566
}
6047
}
5567
 
6048
 
5568
extern int __gcclibcxx_demangle_callback (const char *,
6049
extern int __gcclibcxx_demangle_callback (const char *,
5569
                                          void (*)
6050
                                          void (*)
5570
                                            (const char *, size_t, void *),
6051
                                            (const char *, size_t, void *),
5571
                                          void *);
6052
                                          void *);
5572
 
6053
 
5573
/* Alternative, allocationless entry point in the C++ runtime library
6054
/* Alternative, allocationless entry point in the C++ runtime library
5574
   for performing demangling.  MANGLED_NAME is a NUL-terminated character
6055
   for performing demangling.  MANGLED_NAME is a NUL-terminated character
5575
   string containing the name to be demangled.
6056
   string containing the name to be demangled.
5576
 
6057
 
5577
   CALLBACK is a callback function, called with demangled string
6058
   CALLBACK is a callback function, called with demangled string
5578
   segments as demangling progresses; it is called at least once,
6059
   segments as demangling progresses; it is called at least once,
5579
   but may be called more than once.  OPAQUE is a generalized pointer
6060
   but may be called more than once.  OPAQUE is a generalized pointer
5580
   used as a callback argument.
6061
   used as a callback argument.
5581
 
6062
 
5582
   The return code is one of the following values, equivalent to
6063
   The return code is one of the following values, equivalent to
5583
   the STATUS values of __cxa_demangle() (excluding -1, since this
6064
   the STATUS values of __cxa_demangle() (excluding -1, since this
5584
   function performs no memory allocations):
6065
   function performs no memory allocations):
5585
      0: The demangling operation succeeded.
6066
      0: The demangling operation succeeded.
5586
     -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6067
     -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5587
     -3: One of the arguments is invalid.
6068
     -3: One of the arguments is invalid.
5588
 
6069
 
5589
   The demangling is performed using the C++ ABI mangling rules, with
6070
   The demangling is performed using the C++ ABI mangling rules, with
5590
   GNU extensions.  */
6071
   GNU extensions.  */
5591
 
6072
 
5592
int
6073
int
5593
__gcclibcxx_demangle_callback (const char *mangled_name,
6074
__gcclibcxx_demangle_callback (const char *mangled_name,
5594
                               void (*callback) (const char *, size_t, void *),
6075
                               void (*callback) (const char *, size_t, void *),
5595
                               void *opaque)
6076
                               void *opaque)
5596
{
6077
{
5597
  int status;
6078
  int status;
5598
 
6079
 
5599
  if (mangled_name == NULL || callback == NULL)
6080
  if (mangled_name == NULL || callback == NULL)
5600
    return -3;
6081
    return -3;
5601
 
6082
 
5602
  status = d_demangle_callback (mangled_name, DMGL_PARAMS | DMGL_TYPES,
6083
  status = d_demangle_callback (mangled_name, DMGL_PARAMS | DMGL_TYPES,
5603
                                callback, opaque);
6084
                                callback, opaque);
5604
  if (status == 0)
6085
  if (status == 0)
5605
    return -2;
6086
    return -2;
5606
 
6087
 
5607
  return 0;
6088
  return 0;
5608
}
6089
}
5609
 
6090
 
5610
#else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6091
#else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5611
 
6092
 
5612
/* Entry point for libiberty demangler.  If MANGLED is a g++ v3 ABI
6093
/* Entry point for libiberty demangler.  If MANGLED is a g++ v3 ABI
5613
   mangled name, return a buffer allocated with malloc holding the
6094
   mangled name, return a buffer allocated with malloc holding the
5614
   demangled name.  Otherwise, return NULL.  */
6095
   demangled name.  Otherwise, return NULL.  */
5615
 
6096
 
5616
char *
6097
char *
5617
cplus_demangle_v3 (const char *mangled, int options)
6098
cplus_demangle_v3 (const char *mangled, int options)
5618
{
6099
{
5619
  size_t alc;
6100
  size_t alc;
5620
 
6101
 
5621
  return d_demangle (mangled, options, &alc);
6102
  return d_demangle (mangled, options, &alc);
5622
}
6103
}
5623
 
6104
 
5624
int
6105
int
5625
cplus_demangle_v3_callback (const char *mangled, int options,
6106
cplus_demangle_v3_callback (const char *mangled, int options,
5626
                            demangle_callbackref callback, void *opaque)
6107
                            demangle_callbackref callback, void *opaque)
5627
{
6108
{
5628
  return d_demangle_callback (mangled, options, callback, opaque);
6109
  return d_demangle_callback (mangled, options, callback, opaque);
5629
}
6110
}
5630
 
6111
 
5631
/* Demangle a Java symbol.  Java uses a subset of the V3 ABI C++ mangling 
6112
/* Demangle a Java symbol.  Java uses a subset of the V3 ABI C++ mangling 
5632
   conventions, but the output formatting is a little different.
6113
   conventions, but the output formatting is a little different.
5633
   This instructs the C++ demangler not to emit pointer characters ("*"), to
6114
   This instructs the C++ demangler not to emit pointer characters ("*"), to
5634
   use Java's namespace separator symbol ("." instead of "::"), and to output
6115
   use Java's namespace separator symbol ("." instead of "::"), and to output
5635
   JArray as TYPE[].  */
6116
   JArray as TYPE[].  */
5636
 
6117
 
5637
char *
6118
char *
5638
java_demangle_v3 (const char *mangled)
6119
java_demangle_v3 (const char *mangled)
5639
{
6120
{
5640
  size_t alc;
6121
  size_t alc;
5641
 
6122
 
5642
  return d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX, &alc);
6123
  return d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX, &alc);
5643
}
6124
}
5644
 
6125
 
5645
int
6126
int
5646
java_demangle_v3_callback (const char *mangled,
6127
java_demangle_v3_callback (const char *mangled,
5647
                           demangle_callbackref callback, void *opaque)
6128
                           demangle_callbackref callback, void *opaque)
5648
{
6129
{
5649
  return d_demangle_callback (mangled,
6130
  return d_demangle_callback (mangled,
5650
                              DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX,
6131
                              DMGL_JAVA | DMGL_PARAMS | DMGL_RET_POSTFIX,
5651
                              callback, opaque);
6132
                              callback, opaque);
5652
}
6133
}
5653
 
6134
 
5654
#endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6135
#endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5655
 
6136
 
5656
#ifndef IN_GLIBCPP_V3
6137
#ifndef IN_GLIBCPP_V3
5657
 
6138
 
5658
/* Demangle a string in order to find out whether it is a constructor
6139
/* Demangle a string in order to find out whether it is a constructor
5659
   or destructor.  Return non-zero on success.  Set *CTOR_KIND and
6140
   or destructor.  Return non-zero on success.  Set *CTOR_KIND and
5660
   *DTOR_KIND appropriately.  */
6141
   *DTOR_KIND appropriately.  */
5661
 
6142
 
5662
static int
6143
static int
5663
is_ctor_or_dtor (const char *mangled,
6144
is_ctor_or_dtor (const char *mangled,
5664
                 enum gnu_v3_ctor_kinds *ctor_kind,
6145
                 enum gnu_v3_ctor_kinds *ctor_kind,
5665
                 enum gnu_v3_dtor_kinds *dtor_kind)
6146
                 enum gnu_v3_dtor_kinds *dtor_kind)
5666
{
6147
{
5667
  struct d_info di;
6148
  struct d_info di;
5668
  struct demangle_component *dc;
6149
  struct demangle_component *dc;
5669
  int ret;
6150
  int ret;
5670
 
6151
 
5671
  *ctor_kind = (enum gnu_v3_ctor_kinds) 0;
6152
  *ctor_kind = (enum gnu_v3_ctor_kinds) 0;
5672
  *dtor_kind = (enum gnu_v3_dtor_kinds) 0;
6153
  *dtor_kind = (enum gnu_v3_dtor_kinds) 0;
5673
 
6154
 
5674
  cplus_demangle_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di);
6155
  cplus_demangle_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di);
5675
 
6156
 
5676
  {
6157
  {
5677
#ifdef CP_DYNAMIC_ARRAYS
6158
#ifdef CP_DYNAMIC_ARRAYS
5678
    __extension__ struct demangle_component comps[di.num_comps];
6159
    __extension__ struct demangle_component comps[di.num_comps];
5679
    __extension__ struct demangle_component *subs[di.num_subs];
6160
    __extension__ struct demangle_component *subs[di.num_subs];
5680
 
6161
 
5681
    di.comps = comps;
6162
    di.comps = comps;
5682
    di.subs = subs;
6163
    di.subs = subs;
5683
#else
6164
#else
5684
    di.comps = alloca (di.num_comps * sizeof (*di.comps));
6165
    di.comps = alloca (di.num_comps * sizeof (*di.comps));
5685
    di.subs = alloca (di.num_subs * sizeof (*di.subs));
6166
    di.subs = alloca (di.num_subs * sizeof (*di.subs));
5686
#endif
6167
#endif
5687
 
6168
 
5688
    dc = cplus_demangle_mangled_name (&di, 1);
6169
    dc = cplus_demangle_mangled_name (&di, 1);
5689
 
6170
 
5690
    /* Note that because we did not pass DMGL_PARAMS, we don't expect
6171
    /* Note that because we did not pass DMGL_PARAMS, we don't expect
5691
       to demangle the entire string.  */
6172
       to demangle the entire string.  */
5692
 
6173
 
5693
    ret = 0;
6174
    ret = 0;
5694
    while (dc != NULL)
6175
    while (dc != NULL)
5695
      {
6176
      {
5696
	switch (dc->type)
6177
	switch (dc->type)
5697
	  {
6178
	  {
5698
	    /* These cannot appear on a constructor or destructor.  */
6179
	    /* These cannot appear on a constructor or destructor.  */
5699
	  case DEMANGLE_COMPONENT_RESTRICT_THIS:
6180
	  case DEMANGLE_COMPONENT_RESTRICT_THIS:
5700
	  case DEMANGLE_COMPONENT_VOLATILE_THIS:
6181
	  case DEMANGLE_COMPONENT_VOLATILE_THIS:
5701
	  case DEMANGLE_COMPONENT_CONST_THIS:
6182
	  case DEMANGLE_COMPONENT_CONST_THIS:
5702
	  case DEMANGLE_COMPONENT_REFERENCE_THIS:
6183
	  case DEMANGLE_COMPONENT_REFERENCE_THIS:
5703
	  case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
6184
	  case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
5704
	  default:
6185
	  default:
5705
	    dc = NULL;
6186
	    dc = NULL;
5706
	    break;
6187
	    break;
5707
	  case DEMANGLE_COMPONENT_TYPED_NAME:
6188
	  case DEMANGLE_COMPONENT_TYPED_NAME:
5708
	  case DEMANGLE_COMPONENT_TEMPLATE:
6189
	  case DEMANGLE_COMPONENT_TEMPLATE:
5709
	    dc = d_left (dc);
6190
	    dc = d_left (dc);
5710
	    break;
6191
	    break;
5711
	  case DEMANGLE_COMPONENT_QUAL_NAME:
6192
	  case DEMANGLE_COMPONENT_QUAL_NAME:
5712
	  case DEMANGLE_COMPONENT_LOCAL_NAME:
6193
	  case DEMANGLE_COMPONENT_LOCAL_NAME:
5713
	    dc = d_right (dc);
6194
	    dc = d_right (dc);
5714
	    break;
6195
	    break;
5715
	  case DEMANGLE_COMPONENT_CTOR:
6196
	  case DEMANGLE_COMPONENT_CTOR:
5716
	    *ctor_kind = dc->u.s_ctor.kind;
6197
	    *ctor_kind = dc->u.s_ctor.kind;
5717
	    ret = 1;
6198
	    ret = 1;
5718
	    dc = NULL;
6199
	    dc = NULL;
5719
	    break;
6200
	    break;
5720
	  case DEMANGLE_COMPONENT_DTOR:
6201
	  case DEMANGLE_COMPONENT_DTOR:
5721
	    *dtor_kind = dc->u.s_dtor.kind;
6202
	    *dtor_kind = dc->u.s_dtor.kind;
5722
	    ret = 1;
6203
	    ret = 1;
5723
	    dc = NULL;
6204
	    dc = NULL;
5724
	    break;
6205
	    break;
5725
	  }
6206
	  }
5726
      }
6207
      }
5727
  }
6208
  }
5728
 
6209
 
5729
  return ret;
6210
  return ret;
5730
}
6211
}
5731
 
6212
 
5732
/* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6213
/* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5733
   name.  A non-zero return indicates the type of constructor.  */
6214
   name.  A non-zero return indicates the type of constructor.  */
5734
 
6215
 
5735
enum gnu_v3_ctor_kinds
6216
enum gnu_v3_ctor_kinds
5736
is_gnu_v3_mangled_ctor (const char *name)
6217
is_gnu_v3_mangled_ctor (const char *name)
5737
{
6218
{
5738
  enum gnu_v3_ctor_kinds ctor_kind;
6219
  enum gnu_v3_ctor_kinds ctor_kind;
5739
  enum gnu_v3_dtor_kinds dtor_kind;
6220
  enum gnu_v3_dtor_kinds dtor_kind;
5740
 
6221
 
5741
  if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
6222
  if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
5742
    return (enum gnu_v3_ctor_kinds) 0;
6223
    return (enum gnu_v3_ctor_kinds) 0;
5743
  return ctor_kind;
6224
  return ctor_kind;
5744
}
6225
}
5745
 
6226
 
5746
 
6227
 
5747
/* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6228
/* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5748
   name.  A non-zero return indicates the type of destructor.  */
6229
   name.  A non-zero return indicates the type of destructor.  */
5749
 
6230
 
5750
enum gnu_v3_dtor_kinds
6231
enum gnu_v3_dtor_kinds
5751
is_gnu_v3_mangled_dtor (const char *name)
6232
is_gnu_v3_mangled_dtor (const char *name)
5752
{
6233
{
5753
  enum gnu_v3_ctor_kinds ctor_kind;
6234
  enum gnu_v3_ctor_kinds ctor_kind;
5754
  enum gnu_v3_dtor_kinds dtor_kind;
6235
  enum gnu_v3_dtor_kinds dtor_kind;
5755
 
6236
 
5756
  if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
6237
  if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
5757
    return (enum gnu_v3_dtor_kinds) 0;
6238
    return (enum gnu_v3_dtor_kinds) 0;
5758
  return dtor_kind;
6239
  return dtor_kind;
5759
}
6240
}
5760
 
6241
 
5761
#endif /* IN_GLIBCPP_V3 */
6242
#endif /* IN_GLIBCPP_V3 */
5762
 
6243
 
5763
#ifdef STANDALONE_DEMANGLER
6244
#ifdef STANDALONE_DEMANGLER
5764
 
6245
 
5765
#include "getopt.h"
6246
#include "getopt.h"
5766
#include "dyn-string.h"
6247
#include "dyn-string.h"
5767
 
6248
 
5768
static void print_usage (FILE* fp, int exit_value);
6249
static void print_usage (FILE* fp, int exit_value);
5769
 
6250
 
5770
#define IS_ALPHA(CHAR)                                                  \
6251
#define IS_ALPHA(CHAR)                                                  \
5771
  (((CHAR) >= 'a' && (CHAR) <= 'z')                                     \
6252
  (((CHAR) >= 'a' && (CHAR) <= 'z')                                     \
5772
   || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6253
   || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5773
 
6254
 
5774
/* Non-zero if CHAR is a character than can occur in a mangled name.  */
6255
/* Non-zero if CHAR is a character than can occur in a mangled name.  */
5775
#define is_mangled_char(CHAR)                                           \
6256
#define is_mangled_char(CHAR)                                           \
5776
  (IS_ALPHA (CHAR) || IS_DIGIT (CHAR)                                   \
6257
  (IS_ALPHA (CHAR) || IS_DIGIT (CHAR)                                   \
5777
   || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6258
   || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5778
 
6259
 
5779
/* The name of this program, as invoked.  */
6260
/* The name of this program, as invoked.  */
5780
const char* program_name;
6261
const char* program_name;
5781
 
6262
 
5782
/* Prints usage summary to FP and then exits with EXIT_VALUE.  */
6263
/* Prints usage summary to FP and then exits with EXIT_VALUE.  */
5783
 
6264
 
5784
static void
6265
static void
5785
print_usage (FILE* fp, int exit_value)
6266
print_usage (FILE* fp, int exit_value)
5786
{
6267
{
5787
  fprintf (fp, "Usage: %s [options] [names ...]\n", program_name);
6268
  fprintf (fp, "Usage: %s [options] [names ...]\n", program_name);
5788
  fprintf (fp, "Options:\n");
6269
  fprintf (fp, "Options:\n");
5789
  fprintf (fp, "  -h,--help       Display this message.\n");
6270
  fprintf (fp, "  -h,--help       Display this message.\n");
5790
  fprintf (fp, "  -p,--no-params  Don't display function parameters\n");
6271
  fprintf (fp, "  -p,--no-params  Don't display function parameters\n");
5791
  fprintf (fp, "  -v,--verbose    Produce verbose demanglings.\n");
6272
  fprintf (fp, "  -v,--verbose    Produce verbose demanglings.\n");
5792
  fprintf (fp, "If names are provided, they are demangled.  Otherwise filters standard input.\n");
6273
  fprintf (fp, "If names are provided, they are demangled.  Otherwise filters standard input.\n");
5793
 
6274
 
5794
  exit (exit_value);
6275
  exit (exit_value);
5795
}
6276
}
5796
 
6277
 
5797
/* Option specification for getopt_long.  */
6278
/* Option specification for getopt_long.  */
5798
static const struct option long_options[] = 
6279
static const struct option long_options[] = 
5799
{
6280
{
5800
  { "help",	 no_argument, NULL, 'h' },
6281
  { "help",	 no_argument, NULL, 'h' },
5801
  { "no-params", no_argument, NULL, 'p' },
6282
  { "no-params", no_argument, NULL, 'p' },
5802
  { "verbose",   no_argument, NULL, 'v' },
6283
  { "verbose",   no_argument, NULL, 'v' },
5803
  { NULL,        no_argument, NULL, 0   },
6284
  { NULL,        no_argument, NULL, 0   },
5804
};
6285
};
5805
 
6286
 
5806
/* Main entry for a demangling filter executable.  It will demangle
6287
/* Main entry for a demangling filter executable.  It will demangle
5807
   its command line arguments, if any.  If none are provided, it will
6288
   its command line arguments, if any.  If none are provided, it will
5808
   filter stdin to stdout, replacing any recognized mangled C++ names
6289
   filter stdin to stdout, replacing any recognized mangled C++ names
5809
   with their demangled equivalents.  */
6290
   with their demangled equivalents.  */
5810
 
6291
 
5811
int
6292
int
5812
main (int argc, char *argv[])
6293
main (int argc, char *argv[])
5813
{
6294
{
5814
  int i;
6295
  int i;
5815
  int opt_char;
6296
  int opt_char;
5816
  int options = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
6297
  int options = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
5817
 
6298
 
5818
  /* Use the program name of this program, as invoked.  */
6299
  /* Use the program name of this program, as invoked.  */
5819
  program_name = argv[0];
6300
  program_name = argv[0];
5820
 
6301
 
5821
  /* Parse options.  */
6302
  /* Parse options.  */
5822
  do 
6303
  do 
5823
    {
6304
    {
5824
      opt_char = getopt_long (argc, argv, "hpv", long_options, NULL);
6305
      opt_char = getopt_long (argc, argv, "hpv", long_options, NULL);
5825
      switch (opt_char)
6306
      switch (opt_char)
5826
	{
6307
	{
5827
	case '?':  /* Unrecognized option.  */
6308
	case '?':  /* Unrecognized option.  */
5828
	  print_usage (stderr, 1);
6309
	  print_usage (stderr, 1);
5829
	  break;
6310
	  break;
5830
 
6311
 
5831
	case 'h':
6312
	case 'h':
5832
	  print_usage (stdout, 0);
6313
	  print_usage (stdout, 0);
5833
	  break;
6314
	  break;
5834
 
6315
 
5835
	case 'p':
6316
	case 'p':
5836
	  options &= ~ DMGL_PARAMS;
6317
	  options &= ~ DMGL_PARAMS;
5837
	  break;
6318
	  break;
5838
 
6319
 
5839
	case 'v':
6320
	case 'v':
5840
	  options |= DMGL_VERBOSE;
6321
	  options |= DMGL_VERBOSE;
5841
	  break;
6322
	  break;
5842
	}
6323
	}
5843
    }
6324
    }
5844
  while (opt_char != -1);
6325
  while (opt_char != -1);
5845
 
6326
 
5846
  if (optind == argc) 
6327
  if (optind == argc) 
5847
    /* No command line arguments were provided.  Filter stdin.  */
6328
    /* No command line arguments were provided.  Filter stdin.  */
5848
    {
6329
    {
5849
      dyn_string_t mangled = dyn_string_new (3);
6330
      dyn_string_t mangled = dyn_string_new (3);
5850
      char *s;
6331
      char *s;
5851
 
6332
 
5852
      /* Read all of input.  */
6333
      /* Read all of input.  */
5853
      while (!feof (stdin))
6334
      while (!feof (stdin))
5854
	{
6335
	{
5855
	  char c;
6336
	  char c;
5856
 
6337
 
5857
	  /* Pile characters into mangled until we hit one that can't
6338
	  /* Pile characters into mangled until we hit one that can't
5858
	     occur in a mangled name.  */
6339
	     occur in a mangled name.  */
5859
	  c = getchar ();
6340
	  c = getchar ();
5860
	  while (!feof (stdin) && is_mangled_char (c))
6341
	  while (!feof (stdin) && is_mangled_char (c))
5861
	    {
6342
	    {
5862
	      dyn_string_append_char (mangled, c);
6343
	      dyn_string_append_char (mangled, c);
5863
	      if (feof (stdin))
6344
	      if (feof (stdin))
5864
		break;
6345
		break;
5865
	      c = getchar ();
6346
	      c = getchar ();
5866
	    }
6347
	    }
5867
 
6348
 
5868
	  if (dyn_string_length (mangled) > 0)
6349
	  if (dyn_string_length (mangled) > 0)
5869
	    {
6350
	    {
5870
#ifdef IN_GLIBCPP_V3
6351
#ifdef IN_GLIBCPP_V3
5871
	      s = __cxa_demangle (dyn_string_buf (mangled), NULL, NULL, NULL);
6352
	      s = __cxa_demangle (dyn_string_buf (mangled), NULL, NULL, NULL);
5872
#else
6353
#else
5873
	      s = cplus_demangle_v3 (dyn_string_buf (mangled), options);
6354
	      s = cplus_demangle_v3 (dyn_string_buf (mangled), options);
5874
#endif
6355
#endif
5875
 
6356
 
5876
	      if (s != NULL)
6357
	      if (s != NULL)
5877
		{
6358
		{
5878
		  fputs (s, stdout);
6359
		  fputs (s, stdout);
5879
		  free (s);
6360
		  free (s);
5880
		}
6361
		}
5881
	      else
6362
	      else
5882
		{
6363
		{
5883
		  /* It might not have been a mangled name.  Print the
6364
		  /* It might not have been a mangled name.  Print the
5884
		     original text.  */
6365
		     original text.  */
5885
		  fputs (dyn_string_buf (mangled), stdout);
6366
		  fputs (dyn_string_buf (mangled), stdout);
5886
		}
6367
		}
5887
 
6368
 
5888
	      dyn_string_clear (mangled);
6369
	      dyn_string_clear (mangled);
5889
	    }
6370
	    }
5890
 
6371
 
5891
	  /* If we haven't hit EOF yet, we've read one character that
6372
	  /* If we haven't hit EOF yet, we've read one character that
5892
	     can't occur in a mangled name, so print it out.  */
6373
	     can't occur in a mangled name, so print it out.  */
5893
	  if (!feof (stdin))
6374
	  if (!feof (stdin))
5894
	    putchar (c);
6375
	    putchar (c);
5895
	}
6376
	}
5896
 
6377
 
5897
      dyn_string_delete (mangled);
6378
      dyn_string_delete (mangled);
5898
    }
6379
    }
5899
  else
6380
  else
5900
    /* Demangle command line arguments.  */
6381
    /* Demangle command line arguments.  */
5901
    {
6382
    {
5902
      /* Loop over command line arguments.  */
6383
      /* Loop over command line arguments.  */
5903
      for (i = optind; i < argc; ++i)
6384
      for (i = optind; i < argc; ++i)
5904
	{
6385
	{
5905
	  char *s;
6386
	  char *s;
5906
#ifdef IN_GLIBCPP_V3
6387
#ifdef IN_GLIBCPP_V3
5907
	  int status;
6388
	  int status;
5908
#endif
6389
#endif
5909
 
6390
 
5910
	  /* Attempt to demangle.  */
6391
	  /* Attempt to demangle.  */
5911
#ifdef IN_GLIBCPP_V3
6392
#ifdef IN_GLIBCPP_V3
5912
	  s = __cxa_demangle (argv[i], NULL, NULL, &status);
6393
	  s = __cxa_demangle (argv[i], NULL, NULL, &status);
5913
#else
6394
#else
5914
	  s = cplus_demangle_v3 (argv[i], options);
6395
	  s = cplus_demangle_v3 (argv[i], options);
5915
#endif
6396
#endif
5916
 
6397
 
5917
	  /* If it worked, print the demangled name.  */
6398
	  /* If it worked, print the demangled name.  */
5918
	  if (s != NULL)
6399
	  if (s != NULL)
5919
	    {
6400
	    {
5920
	      printf ("%s\n", s);
6401
	      printf ("%s\n", s);
5921
	      free (s);
6402
	      free (s);
5922
	    }
6403
	    }
5923
	  else
6404
	  else
5924
	    {
6405
	    {
5925
#ifdef IN_GLIBCPP_V3
6406
#ifdef IN_GLIBCPP_V3
5926
	      fprintf (stderr, "Failed: %s (status %d)\n", argv[i], status);
6407
	      fprintf (stderr, "Failed: %s (status %d)\n", argv[i], status);
5927
#else
6408
#else
5928
	      fprintf (stderr, "Failed: %s\n", argv[i]);
6409
	      fprintf (stderr, "Failed: %s\n", argv[i]);
5929
#endif
6410
#endif
5930
	    }
6411
	    }
5931
	}
6412
	}
5932
    }
6413
    }
5933
 
6414
 
5934
  return 0;
6415
  return 0;
5935
}
6416
}
5936
 
6417
 
5937
#endif /* STANDALONE_DEMANGLER */
6418
#endif /* STANDALONE_DEMANGLER */
5938
>
6419
>
5939
>
6420
>
5940
>
6421
>
5941
>
6422
>
5942
>
6423
>