merge from gcc
[deliverable/binutils-gdb.git] / libiberty / cp-demangle.c
CommitLineData
d00edca5
DD
1/* Demangler for g++ V3 ABI.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@wasabisystems.com>.
eb383413 4
9ad1aa29 5 This file is part of the libiberty library, which is part of GCC.
74bcd529 6
9ad1aa29 7 This file is free software; you can redistribute it and/or modify
eb383413
L
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
35efcd67
DD
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combined
19 executable.)
20
eb383413
L
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/
30
858b45cf
DD
31/* This code implements a demangler for the g++ V3 ABI. The ABI is
32 described on this web page:
33 http://www.codesourcery.com/cxx-abi/abi.html#mangling
34
35 This code was written while looking at the demangler written by
36 Alex Samuel <samuel@codesourcery.com>.
37
38 This code first pulls the mangled name apart into a list of
39 components, and then walks the list generating the demangled
40 name.
41
42 This file will normally define the following functions, q.v.:
43 char *cplus_demangle_v3(const char *mangled, int options)
44 char *java_demangle_v3(const char *mangled)
45 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
46 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
47
48 Preprocessor macros you can define while compiling this file:
49
50 IN_LIBGCC2
51 If defined, this file defines the following function, q.v.:
52 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
53 int *status)
54 instead of cplus_demangle_v3() and java_demangle_v3().
55
56 IN_GLIBCPP_V3
57 If defined, this file defines only __cxa_demangle().
58
59 STANDALONE_DEMANGLER
60 If defined, this file defines a main() function which demangles
61 any arguments, or, if none, demangles stdin.
62
63 CP_DEMANGLE_DEBUG
64 If defined, turns on debugging mode, which prints information on
65 stdout about the mangled string. This is not generally useful.
66*/
67
eb383413
L
68#ifdef HAVE_CONFIG_H
69#include "config.h"
70#endif
71
d00edca5 72#include <stdio.h>
b1233257 73
eb383413
L
74#ifdef HAVE_STDLIB_H
75#include <stdlib.h>
76#endif
eb383413
L
77#ifdef HAVE_STRING_H
78#include <string.h>
79#endif
80
81#include "ansidecl.h"
82#include "libiberty.h"
eb383413
L
83#include "demangle.h"
84
858b45cf
DD
85/* We avoid pulling in the ctype tables, to prevent pulling in
86 additional unresolved symbols when this code is used in a library.
87 FIXME: Is this really a valid reason? This comes from the original
88 V3 demangler code.
d00edca5 89
858b45cf
DD
90 As of this writing this file has the following undefined references
91 when compiled with -DIN_GLIBCPP_V3: malloc, realloc, free, memcpy,
92 strcpy, strcat, strlen. */
d00edca5 93
d00edca5 94#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
858b45cf
DD
95#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
96#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
03d5f569 97
74bcd529
DD
98/* The prefix prepended by GCC to an identifier represnting the
99 anonymous namespace. */
100#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
d00edca5
DD
101#define ANONYMOUS_NAMESPACE_PREFIX_LEN \
102 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
74bcd529 103
d00edca5 104/* Information we keep for operators. */
eb383413 105
d00edca5 106struct d_operator_info
eb383413 107{
d00edca5
DD
108 /* Mangled name. */
109 const char *code;
110 /* Real name. */
111 const char *name;
112 /* Number of arguments. */
113 int args;
114};
59666b35 115
d00edca5 116/* How to print the value of a builtin type. */
59666b35 117
d00edca5
DD
118enum d_builtin_type_print
119{
120 /* Print as (type)val. */
121 D_PRINT_DEFAULT,
122 /* Print as integer. */
123 D_PRINT_INT,
124 /* Print as long, with trailing `l'. */
125 D_PRINT_LONG,
126 /* Print as bool. */
127 D_PRINT_BOOL,
128 /* Print in usual way, but here to detect void. */
129 D_PRINT_VOID
eb383413
L
130};
131
d00edca5 132/* Information we keep for a builtin type. */
eb383413 133
d00edca5 134struct d_builtin_type_info
eb383413 135{
d00edca5
DD
136 /* Type name. */
137 const char *name;
138 /* Type name when using Java. */
139 const char *java_name;
140 /* How to print a value of this type. */
141 enum d_builtin_type_print print;
142};
eb383413 143
97ceaf5b
DD
144/* Information we keep for the standard substitutions. */
145
146struct d_standard_sub_info
147{
148 /* The code for this substitution. */
149 char code;
150 /* The simple string it expands to. */
151 const char *simple_expansion;
152 /* The results of a full, verbose, expansion. This is used when
153 qualifying a constructor/destructor, or when in verbose mode. */
154 const char *full_expansion;
155 /* What to set the last_name field of d_info to; NULL if we should
156 not set it. This is only relevant when qualifying a
157 constructor/destructor. */
158 const char *set_last_name;
159};
160
d00edca5
DD
161/* Component types found in mangled names. */
162
163enum d_comp_type
164{
165 /* A name. */
166 D_COMP_NAME,
167 /* A qualified name. */
168 D_COMP_QUAL_NAME,
169 /* A typed name. */
170 D_COMP_TYPED_NAME,
171 /* A template. */
172 D_COMP_TEMPLATE,
173 /* A template parameter. */
174 D_COMP_TEMPLATE_PARAM,
175 /* A constructor. */
176 D_COMP_CTOR,
177 /* A destructor. */
178 D_COMP_DTOR,
179 /* A vtable. */
180 D_COMP_VTABLE,
181 /* A VTT structure. */
182 D_COMP_VTT,
183 /* A construction vtable. */
184 D_COMP_CONSTRUCTION_VTABLE,
185 /* A typeinfo structure. */
186 D_COMP_TYPEINFO,
187 /* A typeinfo name. */
188 D_COMP_TYPEINFO_NAME,
189 /* A typeinfo function. */
190 D_COMP_TYPEINFO_FN,
191 /* A thunk. */
192 D_COMP_THUNK,
193 /* A virtual thunk. */
194 D_COMP_VIRTUAL_THUNK,
195 /* A covariant thunk. */
196 D_COMP_COVARIANT_THUNK,
197 /* A Java class. */
198 D_COMP_JAVA_CLASS,
199 /* A guard variable. */
200 D_COMP_GUARD,
201 /* A reference temporary. */
202 D_COMP_REFTEMP,
203 /* A standard substitution. */
204 D_COMP_SUB_STD,
205 /* The restrict qualifier. */
206 D_COMP_RESTRICT,
207 /* The volatile qualifier. */
208 D_COMP_VOLATILE,
209 /* The const qualifier. */
210 D_COMP_CONST,
858b45cf
DD
211 /* The restrict qualifier modifying a member function. */
212 D_COMP_RESTRICT_THIS,
213 /* The volatile qualifier modifying a member function. */
214 D_COMP_VOLATILE_THIS,
215 /* The const qualifier modifying a member function. */
216 D_COMP_CONST_THIS,
d00edca5
DD
217 /* A vendor qualifier. */
218 D_COMP_VENDOR_TYPE_QUAL,
219 /* A pointer. */
220 D_COMP_POINTER,
221 /* A reference. */
222 D_COMP_REFERENCE,
223 /* A complex type. */
224 D_COMP_COMPLEX,
225 /* An imaginary type. */
226 D_COMP_IMAGINARY,
227 /* A builtin type. */
228 D_COMP_BUILTIN_TYPE,
229 /* A vendor's builtin type. */
230 D_COMP_VENDOR_TYPE,
231 /* A function type. */
232 D_COMP_FUNCTION_TYPE,
233 /* An array type. */
234 D_COMP_ARRAY_TYPE,
235 /* A pointer to member type. */
236 D_COMP_PTRMEM_TYPE,
237 /* An argument list. */
238 D_COMP_ARGLIST,
239 /* A template argument list. */
240 D_COMP_TEMPLATE_ARGLIST,
241 /* An operator. */
242 D_COMP_OPERATOR,
243 /* An extended operator. */
244 D_COMP_EXTENDED_OPERATOR,
245 /* A typecast. */
246 D_COMP_CAST,
247 /* A unary expression. */
248 D_COMP_UNARY,
249 /* A binary expression. */
250 D_COMP_BINARY,
251 /* Arguments to a binary expression. */
252 D_COMP_BINARY_ARGS,
253 /* A trinary expression. */
254 D_COMP_TRINARY,
255 /* Arguments to a trinary expression. */
256 D_COMP_TRINARY_ARG1,
257 D_COMP_TRINARY_ARG2,
258 /* A literal. */
97ceaf5b
DD
259 D_COMP_LITERAL,
260 /* A negative literal. */
261 D_COMP_LITERAL_NEG
eb383413
L
262};
263
d00edca5 264/* A component of the mangled name. */
eb383413 265
d00edca5 266struct d_comp
eb383413 267{
d00edca5
DD
268 /* The type of this component. */
269 enum d_comp_type type;
270 union
271 {
272 /* For D_COMP_NAME. */
273 struct
274 {
275 /* A pointer to the name (not NULL terminated) and it's
276 length. */
277 const char *s;
278 int len;
279 } s_name;
eb383413 280
d00edca5
DD
281 /* For D_COMP_OPERATOR. */
282 struct
283 {
284 /* Operator. */
285 const struct d_operator_info *op;
286 } s_operator;
eb383413 287
d00edca5
DD
288 /* For D_COMP_EXTENDED_OPERATOR. */
289 struct
290 {
291 /* Number of arguments. */
292 int args;
293 /* Name. */
294 struct d_comp *name;
295 } s_extended_operator;
eb383413 296
d00edca5
DD
297 /* For D_COMP_CTOR. */
298 struct
299 {
300 enum gnu_v3_ctor_kinds kind;
301 struct d_comp *name;
302 } s_ctor;
eb383413 303
d00edca5
DD
304 /* For D_COMP_DTOR. */
305 struct
306 {
307 enum gnu_v3_dtor_kinds kind;
308 struct d_comp *name;
309 } s_dtor;
eb383413 310
d00edca5
DD
311 /* For D_COMP_BUILTIN_TYPE. */
312 struct
313 {
314 const struct d_builtin_type_info *type;
315 } s_builtin;
316
317 /* For D_COMP_SUB_STD. */
318 struct
319 {
320 const char* string;
321 } s_string;
eb383413 322
d00edca5
DD
323 /* For D_COMP_TEMPLATE_PARAM. */
324 struct
325 {
326 long number;
327 } s_number;
eb383413 328
d00edca5
DD
329 /* For other types. */
330 struct
331 {
332 struct d_comp *left;
333 struct d_comp *right;
334 } s_binary;
eb383413 335
d00edca5
DD
336 } u;
337};
eb383413 338
d00edca5
DD
339#define d_left(dc) ((dc)->u.s_binary.left)
340#define d_right(dc) ((dc)->u.s_binary.right)
341
342/* The information structure we pass around. */
343
344struct d_info
345{
346 /* The string we are demangling. */
347 const char *s;
348 /* The options passed to the demangler. */
349 int options;
350 /* The next character in the string to consider. */
351 const char *n;
352 /* The array of components. */
353 struct d_comp *comps;
354 /* The index of the next available component. */
355 int next_comp;
356 /* The number of available component structures. */
357 int num_comps;
358 /* The array of substitutions. */
359 struct d_comp **subs;
360 /* The index of the next substitution. */
361 int next_sub;
362 /* The number of available entries in the subs array. */
363 int num_subs;
364 /* The last name we saw, for constructors and destructors. */
365 struct d_comp *last_name;
366};
eb383413 367
d00edca5
DD
368#define d_peek_char(di) (*((di)->n))
369#define d_peek_next_char(di) ((di)->n[1])
370#define d_advance(di, i) ((di)->n += (i))
371#define d_next_char(di) (*((di)->n++))
372#define d_str(di) ((di)->n)
eb383413 373
d00edca5 374/* A list of templates. This is used while printing. */
eb383413 375
d00edca5
DD
376struct d_print_template
377{
378 /* Next template on the list. */
379 struct d_print_template *next;
380 /* This template. */
381 const struct d_comp *template;
382};
eb383413 383
d00edca5 384/* A list of type modifiers. This is used while printing. */
eb383413 385
d00edca5
DD
386struct d_print_mod
387{
388 /* Next modifier on the list. These are in the reverse of the order
389 in which they appeared in the mangled string. */
390 struct d_print_mod *next;
391 /* The modifier. */
392 const struct d_comp *mod;
393 /* Whether this modifier was printed. */
394 int printed;
331c3da2
DD
395 /* The list of templates which applies to this modifier. */
396 struct d_print_template *templates;
d00edca5 397};
eb383413 398
d00edca5
DD
399/* We use this structure to hold information during printing. */
400
401struct d_print_info
402{
403 /* The options passed to the demangler. */
404 int options;
405 /* Buffer holding the result. */
406 char *buf;
407 /* Current length of data in buffer. */
408 size_t len;
409 /* Allocated size of buffer. */
410 size_t alc;
411 /* The current list of templates, if any. */
412 struct d_print_template *templates;
413 /* The current list of modifiers (e.g., pointer, reference, etc.),
414 if any. */
415 struct d_print_mod *modifiers;
416 /* Set to 1 if we had a memory allocation failure. */
417 int allocation_failure;
418};
e61231f1 419
d00edca5 420#define d_print_saw_error(dpi) ((dpi)->buf == NULL)
e61231f1 421
d00edca5
DD
422#define d_append_char(dpi, c) \
423 do \
424 { \
425 if ((dpi)->buf != NULL && (dpi)->len < (dpi)->alc) \
426 (dpi)->buf[(dpi)->len++] = (c); \
427 else \
428 d_print_append_char ((dpi), (c)); \
429 } \
430 while (0)
e61231f1 431
d00edca5
DD
432#define d_append_buffer(dpi, s, l) \
433 do \
434 { \
435 if ((dpi)->buf != NULL && (dpi)->len + (l) <= (dpi)->alc) \
436 { \
437 memcpy ((dpi)->buf + (dpi)->len, (s), (l)); \
438 (dpi)->len += l; \
439 } \
440 else \
441 d_print_append_buffer ((dpi), (s), (l)); \
442 } \
443 while (0)
eb383413 444
d00edca5
DD
445#define d_append_string(dpi, s) \
446 do \
447 { \
448 size_t d_append_string_len = strlen (s); \
449 d_append_buffer ((dpi), (s), d_append_string_len); \
450 } \
03d5f569
JM
451 while (0)
452
858b45cf
DD
453#define d_last_char(dpi) \
454 ((dpi)->buf == NULL || (dpi)->len == 0 ? '\0' : (dpi)->buf[(dpi)->len - 1])
455
eb383413 456#ifdef CP_DEMANGLE_DEBUG
d00edca5 457static void d_dump PARAMS ((struct d_comp *, int));
eb383413 458#endif
d00edca5
DD
459static struct d_comp *d_make_empty PARAMS ((struct d_info *,
460 enum d_comp_type));
461static struct d_comp *d_make_comp PARAMS ((struct d_info *, enum d_comp_type,
462 struct d_comp *, struct d_comp *));
463static struct d_comp *d_make_name PARAMS ((struct d_info *, const char *,
464 int));
465static struct d_comp *d_make_builtin_type PARAMS ((struct d_info *,
466 const struct d_builtin_type_info *));
467static struct d_comp *d_make_operator PARAMS ((struct d_info *,
468 const struct d_operator_info *));
469static struct d_comp *d_make_extended_operator PARAMS ((struct d_info *,
470 int,
471 struct d_comp *));
472static struct d_comp *d_make_ctor PARAMS ((struct d_info *,
473 enum gnu_v3_ctor_kinds,
474 struct d_comp *));
475static struct d_comp *d_make_dtor PARAMS ((struct d_info *,
476 enum gnu_v3_dtor_kinds,
477 struct d_comp *));
478static struct d_comp *d_make_template_param PARAMS ((struct d_info *, long));
479static struct d_comp *d_make_sub PARAMS ((struct d_info *, const char *));
331c3da2 480static struct d_comp *d_mangled_name PARAMS ((struct d_info *, int));
d00edca5
DD
481static int has_return_type PARAMS ((struct d_comp *));
482static int is_ctor_dtor_or_conversion PARAMS ((struct d_comp *));
6d95373e 483static struct d_comp *d_encoding PARAMS ((struct d_info *, int));
d00edca5
DD
484static struct d_comp *d_name PARAMS ((struct d_info *));
485static struct d_comp *d_nested_name PARAMS ((struct d_info *));
486static struct d_comp *d_prefix PARAMS ((struct d_info *));
487static struct d_comp *d_unqualified_name PARAMS ((struct d_info *));
488static struct d_comp *d_source_name PARAMS ((struct d_info *));
489static long d_number PARAMS ((struct d_info *));
490static struct d_comp *d_identifier PARAMS ((struct d_info *, int));
491static struct d_comp *d_operator_name PARAMS ((struct d_info *));
492static struct d_comp *d_special_name PARAMS ((struct d_info *));
493static int d_call_offset PARAMS ((struct d_info *, int));
494static struct d_comp *d_ctor_dtor_name PARAMS ((struct d_info *));
495static struct d_comp *d_type PARAMS ((struct d_info *));
496static struct d_comp **d_cv_qualifiers PARAMS ((struct d_info *,
858b45cf 497 struct d_comp **, int));
d00edca5
DD
498static struct d_comp *d_function_type PARAMS ((struct d_info *));
499static struct d_comp *d_bare_function_type PARAMS ((struct d_info *, int));
500static struct d_comp *d_class_enum_type PARAMS ((struct d_info *));
501static struct d_comp *d_array_type PARAMS ((struct d_info *));
502static struct d_comp *d_pointer_to_member_type PARAMS ((struct d_info *));
503static struct d_comp *d_template_param PARAMS ((struct d_info *));
504static struct d_comp *d_template_args PARAMS ((struct d_info *));
505static struct d_comp *d_template_arg PARAMS ((struct d_info *));
506static struct d_comp *d_expression PARAMS ((struct d_info *));
507static struct d_comp *d_expr_primary PARAMS ((struct d_info *));
508static struct d_comp *d_local_name PARAMS ((struct d_info *));
509static int d_discriminator PARAMS ((struct d_info *));
510static int d_add_substitution PARAMS ((struct d_info *, struct d_comp *));
97ceaf5b 511static struct d_comp *d_substitution PARAMS ((struct d_info *, int));
d00edca5
DD
512static void d_print_resize PARAMS ((struct d_print_info *, size_t));
513static void d_print_append_char PARAMS ((struct d_print_info *, int));
514static void d_print_append_buffer PARAMS ((struct d_print_info *, const char *,
515 size_t));
516static void d_print_error PARAMS ((struct d_print_info *));
517static char *d_print PARAMS ((int, const struct d_comp *, size_t *));
518static void d_print_comp PARAMS ((struct d_print_info *,
519 const struct d_comp *));
520static void d_print_identifier PARAMS ((struct d_print_info *, const char *,
521 int));
522static void d_print_mod_list PARAMS ((struct d_print_info *,
858b45cf 523 struct d_print_mod *, int));
d00edca5
DD
524static void d_print_mod PARAMS ((struct d_print_info *,
525 const struct d_comp *));
526static void d_print_function_type PARAMS ((struct d_print_info *,
527 const struct d_comp *,
528 struct d_print_mod *));
529static void d_print_array_type PARAMS ((struct d_print_info *,
530 const struct d_comp *,
531 struct d_print_mod *));
532static void d_print_expr_op PARAMS ((struct d_print_info *,
533 const struct d_comp *));
534static void d_print_cast PARAMS ((struct d_print_info *,
535 const struct d_comp *));
536static int d_init_info PARAMS ((const char *, int, size_t, struct d_info *));
537static char *d_demangle PARAMS ((const char *, int, size_t *));
538
eb383413 539#ifdef CP_DEMANGLE_DEBUG
d00edca5
DD
540
541static void
542d_dump (dc, indent)
543 struct d_comp *dc;
544 int indent;
eb383413
L
545{
546 int i;
eb383413 547
d00edca5
DD
548 if (dc == NULL)
549 return;
550
551 for (i = 0; i < indent; ++i)
552 putchar (' ');
553
554 switch (dc->type)
555 {
556 case D_COMP_NAME:
557 printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s);
558 return;
559 case D_COMP_TEMPLATE_PARAM:
560 printf ("template parameter %ld\n", dc->u.s_number.number);
561 return;
562 case D_COMP_CTOR:
563 printf ("constructor %d\n", (int) dc->u.s_ctor.kind);
564 d_dump (dc->u.s_ctor.name, indent + 2);
565 return;
566 case D_COMP_DTOR:
567 printf ("destructor %d\n", (int) dc->u.s_dtor.kind);
568 d_dump (dc->u.s_dtor.name, indent + 2);
569 return;
570 case D_COMP_SUB_STD:
571 printf ("standard substitution %s\n", dc->u.s_string.string);
572 return;
573 case D_COMP_BUILTIN_TYPE:
574 printf ("builtin type %s\n", dc->u.s_builtin.type->name);
575 return;
576 case D_COMP_OPERATOR:
577 printf ("operator %s\n", dc->u.s_operator.op->name);
578 return;
579 case D_COMP_EXTENDED_OPERATOR:
580 printf ("extended operator with %d args\n",
581 dc->u.s_extended_operator.args);
582 d_dump (dc->u.s_extended_operator.name, indent + 2);
583 return;
584
585 case D_COMP_QUAL_NAME:
586 printf ("qualified name\n");
587 break;
588 case D_COMP_TYPED_NAME:
589 printf ("typed name\n");
590 break;
591 case D_COMP_TEMPLATE:
592 printf ("template\n");
593 break;
594 case D_COMP_VTABLE:
595 printf ("vtable\n");
596 break;
597 case D_COMP_VTT:
598 printf ("VTT\n");
599 break;
600 case D_COMP_CONSTRUCTION_VTABLE:
601 printf ("construction vtable\n");
602 break;
603 case D_COMP_TYPEINFO:
604 printf ("typeinfo\n");
605 break;
606 case D_COMP_TYPEINFO_NAME:
607 printf ("typeinfo name\n");
608 break;
609 case D_COMP_TYPEINFO_FN:
610 printf ("typeinfo function\n");
611 break;
612 case D_COMP_THUNK:
613 printf ("thunk\n");
614 break;
615 case D_COMP_VIRTUAL_THUNK:
616 printf ("virtual thunk\n");
617 break;
618 case D_COMP_COVARIANT_THUNK:
619 printf ("covariant thunk\n");
620 break;
621 case D_COMP_JAVA_CLASS:
622 printf ("java class\n");
623 break;
624 case D_COMP_GUARD:
625 printf ("guard\n");
626 break;
627 case D_COMP_REFTEMP:
628 printf ("reference temporary\n");
629 break;
630 case D_COMP_RESTRICT:
631 printf ("restrict\n");
632 break;
633 case D_COMP_VOLATILE:
634 printf ("volatile\n");
635 break;
636 case D_COMP_CONST:
637 printf ("const\n");
638 break;
858b45cf
DD
639 case D_COMP_RESTRICT_THIS:
640 printf ("restrict this\n");
641 break;
642 case D_COMP_VOLATILE_THIS:
643 printf ("volatile this\n");
644 break;
645 case D_COMP_CONST_THIS:
646 printf ("const this\n");
647 break;
d00edca5
DD
648 case D_COMP_VENDOR_TYPE_QUAL:
649 printf ("vendor type qualifier\n");
650 break;
651 case D_COMP_POINTER:
652 printf ("pointer\n");
653 break;
654 case D_COMP_REFERENCE:
655 printf ("reference\n");
656 break;
657 case D_COMP_COMPLEX:
658 printf ("complex\n");
659 break;
660 case D_COMP_IMAGINARY:
661 printf ("imaginary\n");
662 break;
663 case D_COMP_VENDOR_TYPE:
664 printf ("vendor type\n");
665 break;
666 case D_COMP_FUNCTION_TYPE:
667 printf ("function type\n");
668 break;
669 case D_COMP_ARRAY_TYPE:
670 printf ("array type\n");
671 break;
672 case D_COMP_PTRMEM_TYPE:
673 printf ("pointer to member type\n");
674 break;
675 case D_COMP_ARGLIST:
676 printf ("argument list\n");
677 break;
678 case D_COMP_TEMPLATE_ARGLIST:
679 printf ("template argument list\n");
680 break;
681 case D_COMP_CAST:
682 printf ("cast\n");
683 break;
684 case D_COMP_UNARY:
685 printf ("unary operator\n");
686 break;
687 case D_COMP_BINARY:
688 printf ("binary operator\n");
689 break;
690 case D_COMP_BINARY_ARGS:
691 printf ("binary operator arguments\n");
692 break;
693 case D_COMP_TRINARY:
694 printf ("trinary operator\n");
695 break;
696 case D_COMP_TRINARY_ARG1:
697 printf ("trinary operator arguments 1\n");
698 break;
699 case D_COMP_TRINARY_ARG2:
700 printf ("trinary operator arguments 1\n");
701 break;
702 case D_COMP_LITERAL:
703 printf ("literal\n");
704 break;
97ceaf5b
DD
705 case D_COMP_LITERAL_NEG:
706 printf ("negative literal\n");
707 break;
eb383413
L
708 }
709
d00edca5
DD
710 d_dump (d_left (dc), indent + 2);
711 d_dump (d_right (dc), indent + 2);
712}
713
714#endif /* CP_DEMANGLE_DEBUG */
715
716/* Add a new component. */
717
718static struct d_comp *
719d_make_empty (di, type)
720 struct d_info *di;
721 enum d_comp_type type;
722{
723 struct d_comp *p;
724
725 if (di->next_comp >= di->num_comps)
726 return NULL;
727 p = &di->comps[di->next_comp];
728 p->type = type;
729 ++di->next_comp;
730 return p;
731}
732
733/* Add a new generic component. */
734
735static struct d_comp *
736d_make_comp (di, type, left, right)
737 struct d_info *di;
738 enum d_comp_type type;
739 struct d_comp *left;
740 struct d_comp *right;
741{
742 struct d_comp *p;
743
744 /* We check for errors here. A typical error would be a NULL return
331c3da2
DD
745 from a subroutine. We catch those here, and return NULL
746 upward. */
d00edca5
DD
747 switch (type)
748 {
749 /* These types require two parameters. */
750 case D_COMP_QUAL_NAME:
751 case D_COMP_TYPED_NAME:
752 case D_COMP_TEMPLATE:
753 case D_COMP_VENDOR_TYPE_QUAL:
754 case D_COMP_PTRMEM_TYPE:
755 case D_COMP_UNARY:
756 case D_COMP_BINARY:
757 case D_COMP_BINARY_ARGS:
758 case D_COMP_TRINARY:
759 case D_COMP_TRINARY_ARG1:
760 case D_COMP_TRINARY_ARG2:
761 case D_COMP_LITERAL:
97ceaf5b 762 case D_COMP_LITERAL_NEG:
d00edca5
DD
763 if (left == NULL || right == NULL)
764 return NULL;
765 break;
766
767 /* These types only require one parameter. */
768 case D_COMP_VTABLE:
769 case D_COMP_VTT:
770 case D_COMP_CONSTRUCTION_VTABLE:
771 case D_COMP_TYPEINFO:
772 case D_COMP_TYPEINFO_NAME:
773 case D_COMP_TYPEINFO_FN:
774 case D_COMP_THUNK:
775 case D_COMP_VIRTUAL_THUNK:
776 case D_COMP_COVARIANT_THUNK:
777 case D_COMP_JAVA_CLASS:
778 case D_COMP_GUARD:
779 case D_COMP_REFTEMP:
780 case D_COMP_POINTER:
781 case D_COMP_REFERENCE:
782 case D_COMP_COMPLEX:
783 case D_COMP_IMAGINARY:
784 case D_COMP_VENDOR_TYPE:
785 case D_COMP_ARGLIST:
786 case D_COMP_TEMPLATE_ARGLIST:
787 case D_COMP_CAST:
788 if (left == NULL)
789 return NULL;
790 break;
791
792 /* This needs a right parameter, but the left parameter can be
793 empty. */
794 case D_COMP_ARRAY_TYPE:
795 if (right == NULL)
796 return NULL;
797 break;
798
799 /* These are allowed to have no parameters--in some cases they
800 will be filled in later. */
801 case D_COMP_FUNCTION_TYPE:
802 case D_COMP_RESTRICT:
803 case D_COMP_VOLATILE:
804 case D_COMP_CONST:
858b45cf
DD
805 case D_COMP_RESTRICT_THIS:
806 case D_COMP_VOLATILE_THIS:
807 case D_COMP_CONST_THIS:
d00edca5
DD
808 break;
809
810 /* Other types should not be seen here. */
811 default:
812 return NULL;
eb383413 813 }
d00edca5
DD
814
815 p = d_make_empty (di, type);
816 if (p != NULL)
eb383413 817 {
d00edca5
DD
818 p->u.s_binary.left = left;
819 p->u.s_binary.right = right;
eb383413 820 }
d00edca5
DD
821 return p;
822}
eb383413 823
d00edca5 824/* Add a new name component. */
03d5f569 825
d00edca5
DD
826static struct d_comp *
827d_make_name (di, s, len)
828 struct d_info *di;
829 const char *s;
830 int len;
831{
832 struct d_comp *p;
03d5f569 833
858b45cf
DD
834 if (s == NULL || len == 0)
835 return NULL;
d00edca5
DD
836 p = d_make_empty (di, D_COMP_NAME);
837 if (p != NULL)
838 {
839 p->u.s_name.s = s;
840 p->u.s_name.len = len;
eb383413 841 }
d00edca5 842 return p;
eb383413
L
843}
844
d00edca5 845/* Add a new builtin type component. */
eb383413 846
d00edca5
DD
847static struct d_comp *
848d_make_builtin_type (di, type)
849 struct d_info *di;
850 const struct d_builtin_type_info *type;
eb383413 851{
d00edca5
DD
852 struct d_comp *p;
853
331c3da2
DD
854 if (type == NULL)
855 return NULL;
d00edca5
DD
856 p = d_make_empty (di, D_COMP_BUILTIN_TYPE);
857 if (p != NULL)
858 p->u.s_builtin.type = type;
859 return p;
860}
eb383413 861
d00edca5 862/* Add a new operator component. */
eb383413 863
d00edca5
DD
864static struct d_comp *
865d_make_operator (di, op)
866 struct d_info *di;
867 const struct d_operator_info *op;
eb383413 868{
d00edca5
DD
869 struct d_comp *p;
870
871 p = d_make_empty (di, D_COMP_OPERATOR);
872 if (p != NULL)
873 p->u.s_operator.op = op;
874 return p;
eb383413
L
875}
876
d00edca5 877/* Add a new extended operator component. */
eb383413 878
d00edca5
DD
879static struct d_comp *
880d_make_extended_operator (di, args, name)
881 struct d_info *di;
882 int args;
883 struct d_comp *name;
eb383413 884{
d00edca5 885 struct d_comp *p;
03d5f569 886
331c3da2
DD
887 if (name == NULL)
888 return NULL;
d00edca5
DD
889 p = d_make_empty (di, D_COMP_EXTENDED_OPERATOR);
890 if (p != NULL)
891 {
892 p->u.s_extended_operator.args = args;
893 p->u.s_extended_operator.name = name;
894 }
895 return p;
eb383413
L
896}
897
d00edca5 898/* Add a new constructor component. */
eb383413 899
d00edca5
DD
900static struct d_comp *
901d_make_ctor (di, kind, name)
902 struct d_info *di;
903 enum gnu_v3_ctor_kinds kind;
904 struct d_comp *name;
eb383413 905{
d00edca5
DD
906 struct d_comp *p;
907
331c3da2
DD
908 if (name == NULL)
909 return NULL;
d00edca5
DD
910 p = d_make_empty (di, D_COMP_CTOR);
911 if (p != NULL)
912 {
913 p->u.s_ctor.kind = kind;
914 p->u.s_ctor.name = name;
915 }
916 return p;
eb383413
L
917}
918
d00edca5 919/* Add a new destructor component. */
eb383413 920
d00edca5
DD
921static struct d_comp *
922d_make_dtor (di, kind, name)
923 struct d_info *di;
924 enum gnu_v3_dtor_kinds kind;
925 struct d_comp *name;
eb383413 926{
d00edca5
DD
927 struct d_comp *p;
928
331c3da2
DD
929 if (name == NULL)
930 return NULL;
d00edca5
DD
931 p = d_make_empty (di, D_COMP_DTOR);
932 if (p != NULL)
933 {
934 p->u.s_dtor.kind = kind;
935 p->u.s_dtor.name = name;
936 }
937 return p;
eb383413
L
938}
939
d00edca5 940/* Add a new template parameter. */
59666b35 941
d00edca5
DD
942static struct d_comp *
943d_make_template_param (di, i)
944 struct d_info *di;
945 long i;
59666b35 946{
d00edca5
DD
947 struct d_comp *p;
948
949 p = d_make_empty (di, D_COMP_TEMPLATE_PARAM);
950 if (p != NULL)
951 p->u.s_number.number = i;
952 return p;
59666b35
DD
953}
954
d00edca5 955/* Add a new standard substitution component. */
59666b35 956
d00edca5
DD
957static struct d_comp *
958d_make_sub (di, name)
959 struct d_info *di;
960 const char *name;
59666b35 961{
d00edca5
DD
962 struct d_comp *p;
963
964 p = d_make_empty (di, D_COMP_SUB_STD);
965 if (p != NULL)
966 p->u.s_string.string = name;
967 return p;
59666b35
DD
968}
969
331c3da2
DD
970/* <mangled-name> ::= _Z <encoding>
971
972 TOP_LEVEL is non-zero when called at the top level. */
59666b35 973
d00edca5 974static struct d_comp *
331c3da2 975d_mangled_name (di, top_level)
d00edca5 976 struct d_info *di;
331c3da2 977 int top_level;
59666b35 978{
d00edca5
DD
979 if (d_next_char (di) != '_')
980 return NULL;
981 if (d_next_char (di) != 'Z')
982 return NULL;
331c3da2 983 return d_encoding (di, top_level);
59666b35
DD
984}
985
d00edca5
DD
986/* Return whether a function should have a return type. The argument
987 is the function name, which may be qualified in various ways. The
988 rules are that template functions have return types with some
989 exceptions, function types which are not part of a function name
990 mangling have return types with some exceptions, and non-template
991 function names do not have return types. The exceptions are that
992 constructors, destructors, and conversion operators do not have
993 return types. */
59666b35
DD
994
995static int
d00edca5
DD
996has_return_type (dc)
997 struct d_comp *dc;
59666b35 998{
d00edca5
DD
999 if (dc == NULL)
1000 return 0;
1001 switch (dc->type)
1002 {
1003 default:
1004 return 0;
1005 case D_COMP_TEMPLATE:
1006 return ! is_ctor_dtor_or_conversion (d_left (dc));
858b45cf
DD
1007 case D_COMP_RESTRICT_THIS:
1008 case D_COMP_VOLATILE_THIS:
1009 case D_COMP_CONST_THIS:
54a962d9 1010 return has_return_type (d_left (dc));
d00edca5 1011 }
59666b35
DD
1012}
1013
d00edca5
DD
1014/* Return whether a name is a constructor, a destructor, or a
1015 conversion operator. */
eb383413
L
1016
1017static int
d00edca5
DD
1018is_ctor_dtor_or_conversion (dc)
1019 struct d_comp *dc;
eb383413 1020{
d00edca5
DD
1021 if (dc == NULL)
1022 return 0;
1023 switch (dc->type)
1024 {
1025 default:
1026 return 0;
1027 case D_COMP_QUAL_NAME:
1028 return is_ctor_dtor_or_conversion (d_right (dc));
1029 case D_COMP_CTOR:
1030 case D_COMP_DTOR:
1031 case D_COMP_CAST:
1032 return 1;
1033 }
eb383413
L
1034}
1035
d00edca5
DD
1036/* <encoding> ::= <(function) name> <bare-function-type>
1037 ::= <(data) name>
6d95373e
DD
1038 ::= <special-name>
1039
1040 TOP_LEVEL is non-zero when called at the top level, in which case
1041 if DMGL_PARAMS is not set we do not demangle the function
1042 parameters. We only set this at the top level, because otherwise
1043 we would not correctly demangle names in local scopes. */
eb383413 1044
d00edca5 1045static struct d_comp *
6d95373e 1046d_encoding (di, top_level)
d00edca5 1047 struct d_info *di;
6d95373e 1048 int top_level;
eb383413 1049{
d00edca5 1050 char peek = d_peek_char (di);
03d5f569 1051
d00edca5
DD
1052 if (peek == 'G' || peek == 'T')
1053 return d_special_name (di);
1054 else
03d5f569 1055 {
d00edca5
DD
1056 struct d_comp *dc;
1057
1058 dc = d_name (di);
331c3da2
DD
1059
1060 if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0)
1061 {
1062 /* Strip off any initial CV-qualifiers, as they really apply
1063 to the `this' parameter, and they were not output by the
1064 v2 demangler without DMGL_PARAMS. */
858b45cf
DD
1065 while (dc->type == D_COMP_RESTRICT_THIS
1066 || dc->type == D_COMP_VOLATILE_THIS
1067 || dc->type == D_COMP_CONST_THIS)
331c3da2
DD
1068 dc = d_left (dc);
1069 return dc;
1070 }
1071
d00edca5 1072 peek = d_peek_char (di);
331c3da2 1073 if (peek == '\0' || peek == 'E')
d00edca5
DD
1074 return dc;
1075 return d_make_comp (di, D_COMP_TYPED_NAME, dc,
1076 d_bare_function_type (di, has_return_type (dc)));
03d5f569 1077 }
d00edca5
DD
1078}
1079
1080/* <name> ::= <nested-name>
1081 ::= <unscoped-name>
1082 ::= <unscoped-template-name> <template-args>
1083 ::= <local-name>
1084
1085 <unscoped-name> ::= <unqualified-name>
1086 ::= St <unqualified-name>
eb383413 1087
d00edca5
DD
1088 <unscoped-template-name> ::= <unscoped-name>
1089 ::= <substitution>
1090*/
1091
1092static struct d_comp *
1093d_name (di)
1094 struct d_info *di;
1095{
1096 char peek = d_peek_char (di);
1097 struct d_comp *dc;
1098
1099 switch (peek)
eb383413 1100 {
d00edca5
DD
1101 case 'N':
1102 return d_nested_name (di);
1103
1104 case 'Z':
1105 return d_local_name (di);
1106
1107 case 'S':
1108 {
1109 int subst;
1110
1111 if (d_peek_next_char (di) != 't')
1112 {
97ceaf5b 1113 dc = d_substitution (di, 0);
d00edca5
DD
1114 subst = 1;
1115 }
1116 else
1117 {
1118 d_advance (di, 2);
1119 dc = d_make_comp (di, D_COMP_QUAL_NAME, d_make_name (di, "std", 3),
1120 d_unqualified_name (di));
1121 subst = 0;
1122 }
1123
1124 if (d_peek_char (di) != 'I')
1125 {
1126 /* The grammar does not permit this case to occur if we
1127 called d_substitution() above (i.e., subst == 1). We
1128 don't bother to check. */
1129 }
1130 else
1131 {
1132 /* This is <template-args>, which means that we just saw
1133 <unscoped-template-name>, which is a substitution
1134 candidate if we didn't just get it from a
1135 substitution. */
1136 if (! subst)
1137 {
1138 if (! d_add_substitution (di, dc))
1139 return NULL;
1140 }
1141 dc = d_make_comp (di, D_COMP_TEMPLATE, dc, d_template_args (di));
1142 }
1143
1144 return dc;
1145 }
1146
1147 default:
1148 dc = d_unqualified_name (di);
1149 if (d_peek_char (di) == 'I')
03d5f569 1150 {
d00edca5
DD
1151 /* This is <template-args>, which means that we just saw
1152 <unscoped-template-name>, which is a substitution
1153 candidate. */
1154 if (! d_add_substitution (di, dc))
1155 return NULL;
1156 dc = d_make_comp (di, D_COMP_TEMPLATE, dc, d_template_args (di));
03d5f569 1157 }
d00edca5 1158 return dc;
eb383413 1159 }
d00edca5 1160}
eb383413 1161
d00edca5
DD
1162/* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1163 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1164*/
eb383413 1165
d00edca5
DD
1166static struct d_comp *
1167d_nested_name (di)
1168 struct d_info *di;
1169{
1170 struct d_comp *ret;
1171 struct d_comp **pret;
03d5f569 1172
d00edca5
DD
1173 if (d_next_char (di) != 'N')
1174 return NULL;
eb383413 1175
858b45cf 1176 pret = d_cv_qualifiers (di, &ret, 1);
d00edca5
DD
1177 if (pret == NULL)
1178 return NULL;
1179
1180 *pret = d_prefix (di);
1181 if (*pret == NULL)
1182 return NULL;
eb383413 1183
d00edca5 1184 if (d_next_char (di) != 'E')
eb383413
L
1185 return NULL;
1186
d00edca5 1187 return ret;
eb383413
L
1188}
1189
d00edca5
DD
1190/* <prefix> ::= <prefix> <unqualified-name>
1191 ::= <template-prefix> <template-args>
1192 ::= <template-param>
1193 ::=
1194 ::= <substitution>
eb383413 1195
d00edca5
DD
1196 <template-prefix> ::= <prefix> <(template) unqualified-name>
1197 ::= <template-param>
1198 ::= <substitution>
1199*/
1200
1201static struct d_comp *
1202d_prefix (di)
1203 struct d_info *di;
eb383413 1204{
d00edca5 1205 struct d_comp *ret = NULL;
eb383413 1206
d00edca5 1207 while (1)
eb383413 1208 {
d00edca5
DD
1209 char peek;
1210 enum d_comp_type comb_type;
1211 struct d_comp *dc;
1212
1213 peek = d_peek_char (di);
1214 if (peek == '\0')
1215 return NULL;
1216
1217 /* The older code accepts a <local-name> here, but I don't see
1218 that in the grammar. The older code does not accept a
1219 <template-param> here. */
eb383413 1220
d00edca5
DD
1221 comb_type = D_COMP_QUAL_NAME;
1222 if (IS_DIGIT (peek)
858b45cf 1223 || IS_LOWER (peek)
d00edca5
DD
1224 || peek == 'C'
1225 || peek == 'D')
1226 dc = d_unqualified_name (di);
1227 else if (peek == 'S')
97ceaf5b 1228 dc = d_substitution (di, 1);
d00edca5
DD
1229 else if (peek == 'I')
1230 {
1231 if (ret == NULL)
1232 return NULL;
1233 comb_type = D_COMP_TEMPLATE;
1234 dc = d_template_args (di);
1235 }
1236 else if (peek == 'T')
1237 dc = d_template_param (di);
1238 else if (peek == 'E')
1239 return ret;
1240 else
1241 return NULL;
1242
1243 if (ret == NULL)
1244 ret = dc;
eb383413 1245 else
d00edca5
DD
1246 ret = d_make_comp (di, comb_type, ret, dc);
1247
1248 if (peek != 'S' && d_peek_char (di) != 'E')
1249 {
1250 if (! d_add_substitution (di, ret))
1251 return NULL;
1252 }
eb383413
L
1253 }
1254}
1255
d00edca5
DD
1256/* <unqualified-name> ::= <operator-name>
1257 ::= <ctor-dtor-name>
1258 ::= <source-name>
1259*/
eb383413 1260
d00edca5
DD
1261static struct d_comp *
1262d_unqualified_name (di)
1263 struct d_info *di;
eb383413 1264{
d00edca5
DD
1265 char peek;
1266
1267 peek = d_peek_char (di);
1268 if (IS_DIGIT (peek))
1269 return d_source_name (di);
858b45cf 1270 else if (IS_LOWER (peek))
d00edca5
DD
1271 return d_operator_name (di);
1272 else if (peek == 'C' || peek == 'D')
1273 return d_ctor_dtor_name (di);
1274 else
03d5f569 1275 return NULL;
eb383413
L
1276}
1277
d00edca5 1278/* <source-name> ::= <(positive length) number> <identifier> */
eb383413 1279
d00edca5
DD
1280static struct d_comp *
1281d_source_name (di)
1282 struct d_info *di;
eb383413 1283{
d00edca5
DD
1284 long len;
1285 struct d_comp *ret;
1286
1287 len = d_number (di);
1288 if (len <= 0)
1289 return NULL;
1290 ret = d_identifier (di, len);
1291 di->last_name = ret;
1292 return ret;
eb383413
L
1293}
1294
d00edca5 1295/* number ::= [n] <(non-negative decimal integer)> */
eb383413 1296
d00edca5
DD
1297static long
1298d_number (di)
1299 struct d_info *di;
eb383413 1300{
d00edca5
DD
1301 int sign;
1302 char peek;
1303 long ret;
eb383413 1304
d00edca5
DD
1305 sign = 1;
1306 peek = d_peek_char (di);
1307 if (peek == 'n')
1308 {
1309 sign = -1;
1310 d_advance (di, 1);
1311 peek = d_peek_char (di);
1312 }
eb383413 1313
d00edca5
DD
1314 ret = 0;
1315 while (1)
eb383413 1316 {
d00edca5
DD
1317 if (! IS_DIGIT (peek))
1318 return ret * sign;
1319 ret = ret * 10 + peek - '0';
1320 d_advance (di, 1);
1321 peek = d_peek_char (di);
eb383413 1322 }
eb383413
L
1323}
1324
d00edca5 1325/* identifier ::= <(unqualified source code identifier)> */
eb383413 1326
d00edca5
DD
1327static struct d_comp *
1328d_identifier (di, len)
1329 struct d_info *di;
1330 int len;
eb383413 1331{
d00edca5 1332 const char *name;
eb383413 1333
d00edca5
DD
1334 name = d_str (di);
1335 d_advance (di, len);
eb383413 1336
d00edca5
DD
1337 /* Look for something which looks like a gcc encoding of an
1338 anonymous namespace, and replace it with a more user friendly
1339 name. */
1340 if (len >= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN + 2
1341 && memcmp (name, ANONYMOUS_NAMESPACE_PREFIX,
1342 ANONYMOUS_NAMESPACE_PREFIX_LEN) == 0)
eb383413 1343 {
d00edca5
DD
1344 const char *s;
1345
1346 s = name + ANONYMOUS_NAMESPACE_PREFIX_LEN;
1347 if ((*s == '.' || *s == '_' || *s == '$')
1348 && s[1] == 'N')
1349 return d_make_name (di, "(anonymous namespace)",
1350 sizeof "(anonymous namespace)" - 1);
eb383413 1351 }
d00edca5
DD
1352
1353 return d_make_name (di, name, len);
eb383413
L
1354}
1355
d00edca5
DD
1356/* operator_name ::= many different two character encodings.
1357 ::= cv <type>
1358 ::= v <digit> <source-name>
1359*/
eb383413 1360
d00edca5
DD
1361static const struct d_operator_info d_operators[] =
1362{
1363 { "aN", "&=", 2 },
1364 { "aS", "=", 2 },
1365 { "aa", "&&", 2 },
1366 { "ad", "&", 1 },
1367 { "an", "&", 2 },
1368 { "cl", "()", 0 },
1369 { "cm", ",", 2 },
1370 { "co", "~", 1 },
1371 { "dV", "/=", 2 },
1372 { "da", "delete[]", 1 },
1373 { "de", "*", 1 },
1374 { "dl", "delete", 1 },
1375 { "dv", "/", 2 },
1376 { "eO", "^=", 2 },
1377 { "eo", "^", 2 },
1378 { "eq", "==", 2 },
1379 { "ge", ">=", 2 },
1380 { "gt", ">", 2 },
1381 { "ix", "[]", 2 },
1382 { "lS", "<<=", 2 },
1383 { "le", "<=", 2 },
1384 { "ls", "<<", 2 },
1385 { "lt", "<", 2 },
1386 { "mI", "-=", 2 },
1387 { "mL", "*=", 2 },
1388 { "mi", "-", 2 },
1389 { "ml", "*", 2 },
1390 { "mm", "--", 1 },
1391 { "na", "new[]", 1 },
1392 { "ne", "!=", 2 },
1393 { "ng", "-", 1 },
1394 { "nt", "!", 1 },
1395 { "nw", "new", 1 },
1396 { "oR", "|=", 2 },
1397 { "oo", "||", 2 },
1398 { "or", "|", 2 },
1399 { "pL", "+=", 2 },
1400 { "pl", "+", 2 },
1401 { "pm", "->*", 2 },
1402 { "pp", "++", 1 },
1403 { "ps", "+", 1 },
1404 { "pt", "->", 2 },
1405 { "qu", "?", 3 },
1406 { "rM", "%=", 2 },
1407 { "rS", ">>=", 2 },
1408 { "rm", "%", 2 },
1409 { "rs", ">>", 2 },
1410 { "st", "sizeof ", 1 },
1411 { "sz", "sizeof ", 1 }
1412};
eb383413 1413
d00edca5
DD
1414static struct d_comp *
1415d_operator_name (di)
1416 struct d_info *di;
eb383413 1417{
d00edca5
DD
1418 char c1;
1419 char c2;
eb383413 1420
d00edca5
DD
1421 c1 = d_next_char (di);
1422 c2 = d_next_char (di);
1423 if (c1 == 'v' && IS_DIGIT (c2))
1424 return d_make_extended_operator (di, c2 - '0', d_source_name (di));
1425 else if (c1 == 'c' && c2 == 'v')
1426 return d_make_comp (di, D_COMP_CAST, d_type (di), NULL);
1427 else
eb383413 1428 {
d00edca5
DD
1429 int low = 0;
1430 int high = sizeof (d_operators) / sizeof (d_operators[0]);
eb383413 1431
d00edca5
DD
1432 while (1)
1433 {
1434 int i;
1435 const struct d_operator_info *p;
eb383413 1436
d00edca5
DD
1437 i = low + (high - low) / 2;
1438 p = d_operators + i;
eb383413 1439
d00edca5
DD
1440 if (c1 == p->code[0] && c2 == p->code[1])
1441 return d_make_operator (di, p);
1442
1443 if (c1 < p->code[0] || (c1 == p->code[0] && c2 < p->code[1]))
1444 high = i;
1445 else
1446 low = i + 1;
1447 if (low == high)
1448 return NULL;
1449 }
1450 }
eb383413
L
1451}
1452
d00edca5
DD
1453/* <special-name> ::= TV <type>
1454 ::= TT <type>
1455 ::= TI <type>
1456 ::= TS <type>
1457 ::= GV <(object) name>
1458 ::= T <call-offset> <(base) encoding>
1459 ::= Tc <call-offset> <call-offset> <(base) encoding>
1460 Also g++ extensions:
1461 ::= TC <type> <(offset) number> _ <(base) type>
1462 ::= TF <type>
1463 ::= TJ <type>
1464 ::= GR <name>
1465*/
eb383413 1466
d00edca5
DD
1467static struct d_comp *
1468d_special_name (di)
1469 struct d_info *di;
eb383413 1470{
d00edca5 1471 char c;
eb383413 1472
d00edca5
DD
1473 c = d_next_char (di);
1474 if (c == 'T')
03d5f569 1475 {
d00edca5
DD
1476 switch (d_next_char (di))
1477 {
1478 case 'V':
1479 return d_make_comp (di, D_COMP_VTABLE, d_type (di), NULL);
1480 case 'T':
1481 return d_make_comp (di, D_COMP_VTT, d_type (di), NULL);
1482 case 'I':
1483 return d_make_comp (di, D_COMP_TYPEINFO, d_type (di), NULL);
1484 case 'S':
1485 return d_make_comp (di, D_COMP_TYPEINFO_NAME, d_type (di), NULL);
eb383413 1486
d00edca5
DD
1487 case 'h':
1488 if (! d_call_offset (di, 'h'))
1489 return NULL;
6d95373e 1490 return d_make_comp (di, D_COMP_THUNK, d_encoding (di, 0), NULL);
eb383413 1491
d00edca5
DD
1492 case 'v':
1493 if (! d_call_offset (di, 'v'))
1494 return NULL;
6d95373e 1495 return d_make_comp (di, D_COMP_VIRTUAL_THUNK, d_encoding (di, 0),
d00edca5 1496 NULL);
eb383413 1497
d00edca5
DD
1498 case 'c':
1499 if (! d_call_offset (di, '\0'))
1500 return NULL;
1501 if (! d_call_offset (di, '\0'))
1502 return NULL;
6d95373e 1503 return d_make_comp (di, D_COMP_COVARIANT_THUNK, d_encoding (di, 0),
d00edca5 1504 NULL);
eb383413 1505
d00edca5
DD
1506 case 'C':
1507 {
1508 struct d_comp *derived_type;
1509 long offset;
1510 struct d_comp *base_type;
1511
1512 derived_type = d_type (di);
1513 offset = d_number (di);
1514 if (offset < 0)
1515 return NULL;
1516 if (d_next_char (di) != '_')
1517 return NULL;
1518 base_type = d_type (di);
1519 /* We don't display the offset. FIXME: We should display
1520 it in verbose mode. */
1521 return d_make_comp (di, D_COMP_CONSTRUCTION_VTABLE, base_type,
1522 derived_type);
1523 }
eb383413 1524
d00edca5
DD
1525 case 'F':
1526 return d_make_comp (di, D_COMP_TYPEINFO_FN, d_type (di), NULL);
1527 case 'J':
1528 return d_make_comp (di, D_COMP_JAVA_CLASS, d_type (di), NULL);
eb383413 1529
d00edca5
DD
1530 default:
1531 return NULL;
1532 }
eb383413 1533 }
d00edca5 1534 else if (c == 'G')
eb383413 1535 {
d00edca5
DD
1536 switch (d_next_char (di))
1537 {
1538 case 'V':
1539 return d_make_comp (di, D_COMP_GUARD, d_name (di), NULL);
1540
1541 case 'R':
1542 return d_make_comp (di, D_COMP_REFTEMP, d_name (di), NULL);
1543
1544 default:
1545 return NULL;
1546 }
eb383413 1547 }
d00edca5
DD
1548 else
1549 return NULL;
eb383413
L
1550}
1551
d00edca5
DD
1552/* <call-offset> ::= h <nv-offset> _
1553 ::= v <v-offset> _
eb383413 1554
d00edca5 1555 <nv-offset> ::= <(offset) number>
eb383413 1556
d00edca5 1557 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
eb383413 1558
d00edca5
DD
1559 The C parameter, if not '\0', is a character we just read which is
1560 the start of the <call-offset>.
eb383413 1561
d00edca5
DD
1562 We don't display the offset information anywhere. FIXME: We should
1563 display it in verbose mode. */
eb383413 1564
d00edca5
DD
1565static int
1566d_call_offset (di, c)
1567 struct d_info *di;
1568 int c;
eb383413 1569{
d00edca5
DD
1570 long offset;
1571 long virtual_offset;
eb383413 1572
d00edca5
DD
1573 if (c == '\0')
1574 c = d_next_char (di);
eb383413 1575
d00edca5
DD
1576 if (c == 'h')
1577 offset = d_number (di);
1578 else if (c == 'v')
eb383413 1579 {
d00edca5
DD
1580 offset = d_number (di);
1581 if (d_next_char (di) != '_')
1582 return 0;
1583 virtual_offset = d_number (di);
eb383413 1584 }
d00edca5
DD
1585 else
1586 return 0;
eb383413 1587
d00edca5
DD
1588 if (d_next_char (di) != '_')
1589 return 0;
eb383413 1590
d00edca5 1591 return 1;
eb383413
L
1592}
1593
d00edca5
DD
1594/* <ctor-dtor-name> ::= C1
1595 ::= C2
1596 ::= C3
1597 ::= D0
1598 ::= D1
1599 ::= D2
1600*/
1601
1602static struct d_comp *
1603d_ctor_dtor_name (di)
1604 struct d_info *di;
1605{
1606 switch (d_next_char (di))
1607 {
1608 case 'C':
1609 {
1610 enum gnu_v3_ctor_kinds kind;
1611
1612 switch (d_next_char (di))
1613 {
1614 case '1':
1615 kind = gnu_v3_complete_object_ctor;
1616 break;
1617 case '2':
1618 kind = gnu_v3_base_object_ctor;
1619 break;
1620 case '3':
1621 kind = gnu_v3_complete_object_allocating_ctor;
1622 break;
1623 default:
1624 return NULL;
1625 }
1626 return d_make_ctor (di, kind, di->last_name);
1627 }
1628
1629 case 'D':
1630 {
1631 enum gnu_v3_dtor_kinds kind;
1632
1633 switch (d_next_char (di))
1634 {
1635 case '0':
1636 kind = gnu_v3_deleting_dtor;
1637 break;
1638 case '1':
1639 kind = gnu_v3_complete_object_dtor;
1640 break;
1641 case '2':
1642 kind = gnu_v3_base_object_dtor;
1643 break;
1644 default:
1645 return NULL;
1646 }
1647 return d_make_dtor (di, kind, di->last_name);
1648 }
eb383413 1649
d00edca5
DD
1650 default:
1651 return NULL;
1652 }
1653}
eb383413 1654
d00edca5
DD
1655/* <type> ::= <builtin-type>
1656 ::= <function-type>
1657 ::= <class-enum-type>
1658 ::= <array-type>
1659 ::= <pointer-to-member-type>
1660 ::= <template-param>
1661 ::= <template-template-param> <template-args>
1662 ::= <substitution>
1663 ::= <CV-qualifiers> <type>
1664 ::= P <type>
1665 ::= R <type>
1666 ::= C <type>
1667 ::= G <type>
1668 ::= U <source-name> <type>
1669
1670 <builtin-type> ::= various one letter codes
1671 ::= u <source-name>
1672*/
eb383413 1673
d00edca5
DD
1674static const struct d_builtin_type_info d_builtin_types[26] =
1675{
1676 /* a */ { "signed char", "signed char", D_PRINT_INT },
1677 /* b */ { "bool", "boolean", D_PRINT_BOOL },
1678 /* c */ { "char", "byte", D_PRINT_INT },
1679 /* d */ { "double", "double", D_PRINT_DEFAULT },
1680 /* e */ { "long double", "long double", D_PRINT_DEFAULT },
1681 /* f */ { "float", "float", D_PRINT_DEFAULT },
1682 /* g */ { "__float128", "__float128", D_PRINT_DEFAULT },
1683 /* h */ { "unsigned char", "unsigned char", D_PRINT_INT },
1684 /* i */ { "int", "int", D_PRINT_INT },
1685 /* j */ { "unsigned int", "unsigned", D_PRINT_INT },
1686 /* k */ { NULL, NULL, D_PRINT_DEFAULT },
1687 /* l */ { "long", "long", D_PRINT_LONG },
1688 /* m */ { "unsigned long", "unsigned long", D_PRINT_LONG },
1689 /* n */ { "__int128", "__int128", D_PRINT_DEFAULT },
1690 /* o */ { "unsigned __int128", "unsigned __int128", D_PRINT_DEFAULT },
1691 /* p */ { NULL, NULL, D_PRINT_DEFAULT },
1692 /* q */ { NULL, NULL, D_PRINT_DEFAULT },
1693 /* r */ { NULL, NULL, D_PRINT_DEFAULT },
1694 /* s */ { "short", "short", D_PRINT_INT },
1695 /* t */ { "unsigned short", "unsigned short", D_PRINT_INT },
1696 /* u */ { NULL, NULL, D_PRINT_DEFAULT },
1697 /* v */ { "void", "void", D_PRINT_VOID },
1698 /* w */ { "wchar_t", "char", D_PRINT_INT },
1699 /* x */ { "long long", "long", D_PRINT_DEFAULT },
1700 /* y */ { "unsigned long long", "unsigned long long", D_PRINT_DEFAULT },
1701 /* z */ { "...", "...", D_PRINT_DEFAULT },
1702};
eb383413 1703
d00edca5
DD
1704static struct d_comp *
1705d_type (di)
1706 struct d_info *di;
eb383413 1707{
d00edca5
DD
1708 char peek;
1709 struct d_comp *ret;
1710 int can_subst;
1711
1712 /* The ABI specifies that when CV-qualifiers are used, the base type
1713 is substitutable, and the fully qualified type is substitutable,
1714 but the base type with a strict subset of the CV-qualifiers is
1715 not substitutable. The natural recursive implementation of the
1716 CV-qualifiers would cause subsets to be substitutable, so instead
1717 we pull them all off now.
1718
331c3da2
DD
1719 FIXME: The ABI says that order-insensitive vendor qualifiers
1720 should be handled in the same way, but we have no way to tell
1721 which vendor qualifiers are order-insensitive and which are
1722 order-sensitive. So we just assume that they are all
1723 order-sensitive. g++ 3.4 supports only one vendor qualifier,
1724 __vector, and it treats it as order-sensitive when mangling
1725 names. */
d00edca5
DD
1726
1727 peek = d_peek_char (di);
1728 if (peek == 'r' || peek == 'V' || peek == 'K')
1729 {
1730 struct d_comp **pret;
74bcd529 1731
858b45cf 1732 pret = d_cv_qualifiers (di, &ret, 0);
331c3da2
DD
1733 if (pret == NULL)
1734 return NULL;
d00edca5
DD
1735 *pret = d_type (di);
1736 if (! d_add_substitution (di, ret))
1737 return NULL;
1738 return ret;
1739 }
eb383413 1740
d00edca5 1741 can_subst = 1;
eb383413 1742
74bcd529 1743 switch (peek)
eb383413 1744 {
d00edca5
DD
1745 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1746 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
1747 case 'o': case 's': case 't':
1748 case 'v': case 'w': case 'x': case 'y': case 'z':
d00edca5
DD
1749 ret = d_make_builtin_type (di, &d_builtin_types[peek - 'a']);
1750 can_subst = 0;
1751 d_advance (di, 1);
1752 break;
1753
1754 case 'u':
1755 d_advance (di, 1);
1756 ret = d_make_comp (di, D_COMP_VENDOR_TYPE, d_source_name (di), NULL);
1757 break;
1758
1759 case 'F':
1760 ret = d_function_type (di);
eb383413
L
1761 break;
1762
d00edca5
DD
1763 case '0': case '1': case '2': case '3': case '4':
1764 case '5': case '6': case '7': case '8': case '9':
1765 case 'N':
eb383413 1766 case 'Z':
d00edca5 1767 ret = d_class_enum_type (di);
eb383413
L
1768 break;
1769
d00edca5
DD
1770 case 'A':
1771 ret = d_array_type (di);
1772 break;
1773
1774 case 'M':
1775 ret = d_pointer_to_member_type (di);
1776 break;
1777
1778 case 'T':
1779 ret = d_template_param (di);
1780 if (d_peek_char (di) == 'I')
03d5f569 1781 {
d00edca5
DD
1782 /* This is <template-template-param> <template-args>. The
1783 <template-template-param> part is a substitution
1784 candidate. */
1785 if (! d_add_substitution (di, ret))
1786 return NULL;
1787 ret = d_make_comp (di, D_COMP_TEMPLATE, ret, d_template_args (di));
03d5f569 1788 }
d00edca5
DD
1789 break;
1790
1791 case 'S':
1792 /* If this is a special substitution, then it is the start of
1793 <class-enum-type>. */
1794 {
1795 char peek_next;
74bcd529 1796
d00edca5
DD
1797 peek_next = d_peek_next_char (di);
1798 if (IS_DIGIT (peek_next)
1799 || peek_next == '_'
858b45cf 1800 || IS_UPPER (peek_next))
d00edca5 1801 {
97ceaf5b 1802 ret = d_substitution (di, 0);
d00edca5
DD
1803 /* The substituted name may have been a template name and
1804 may be followed by tepmlate args. */
1805 if (d_peek_char (di) == 'I')
1806 ret = d_make_comp (di, D_COMP_TEMPLATE, ret,
1807 d_template_args (di));
1808 else
1809 can_subst = 0;
1810 }
1811 else
1812 {
1813 ret = d_class_enum_type (di);
1814 /* If the substitution was a complete type, then it is not
1815 a new substitution candidate. However, if the
1816 substitution was followed by template arguments, then
1817 the whole thing is a substitution candidate. */
331c3da2 1818 if (ret != NULL && ret->type == D_COMP_SUB_STD)
d00edca5
DD
1819 can_subst = 0;
1820 }
1821 }
eb383413
L
1822 break;
1823
d00edca5
DD
1824 case 'P':
1825 d_advance (di, 1);
1826 ret = d_make_comp (di, D_COMP_POINTER, d_type (di), NULL);
1827 break;
eb383413 1828
d00edca5
DD
1829 case 'R':
1830 d_advance (di, 1);
1831 ret = d_make_comp (di, D_COMP_REFERENCE, d_type (di), NULL);
1832 break;
eb383413 1833
d00edca5
DD
1834 case 'C':
1835 d_advance (di, 1);
1836 ret = d_make_comp (di, D_COMP_COMPLEX, d_type (di), NULL);
1837 break;
1838
1839 case 'G':
1840 d_advance (di, 1);
1841 ret = d_make_comp (di, D_COMP_IMAGINARY, d_type (di), NULL);
1842 break;
eb383413 1843
d00edca5
DD
1844 case 'U':
1845 d_advance (di, 1);
1846 ret = d_source_name (di);
1847 ret = d_make_comp (di, D_COMP_VENDOR_TYPE_QUAL, d_type (di), ret);
eb383413 1848 break;
d00edca5
DD
1849
1850 default:
1851 return NULL;
eb383413
L
1852 }
1853
d00edca5
DD
1854 if (can_subst)
1855 {
1856 if (! d_add_substitution (di, ret))
1857 return NULL;
1858 }
eb383413 1859
d00edca5
DD
1860 return ret;
1861}
eb383413 1862
d00edca5 1863/* <CV-qualifiers> ::= [r] [V] [K] */
eb383413 1864
d00edca5 1865static struct d_comp **
858b45cf 1866d_cv_qualifiers (di, pret, member_fn)
d00edca5
DD
1867 struct d_info *di;
1868 struct d_comp **pret;
858b45cf 1869 int member_fn;
eb383413
L
1870{
1871 char peek;
1872
d00edca5
DD
1873 peek = d_peek_char (di);
1874 while (peek == 'r' || peek == 'V' || peek == 'K')
eb383413 1875 {
d00edca5 1876 enum d_comp_type t;
59666b35 1877
d00edca5
DD
1878 d_advance (di, 1);
1879 if (peek == 'r')
858b45cf 1880 t = member_fn ? D_COMP_RESTRICT_THIS: D_COMP_RESTRICT;
d00edca5 1881 else if (peek == 'V')
858b45cf 1882 t = member_fn ? D_COMP_VOLATILE_THIS : D_COMP_VOLATILE;
d00edca5 1883 else
858b45cf 1884 t = member_fn ? D_COMP_CONST_THIS: D_COMP_CONST;
eb383413 1885
d00edca5
DD
1886 *pret = d_make_comp (di, t, NULL, NULL);
1887 if (*pret == NULL)
1888 return NULL;
1889 pret = &d_left (*pret);
eb383413 1890
d00edca5
DD
1891 peek = d_peek_char (di);
1892 }
eb383413 1893
d00edca5
DD
1894 return pret;
1895}
eb383413 1896
d00edca5 1897/* <function-type> ::= F [Y] <bare-function-type> E */
eb383413 1898
d00edca5
DD
1899static struct d_comp *
1900d_function_type (di)
1901 struct d_info *di;
eb383413 1902{
d00edca5 1903 struct d_comp *ret;
eb383413 1904
d00edca5
DD
1905 if (d_next_char (di) != 'F')
1906 return NULL;
1907 if (d_peek_char (di) == 'Y')
1908 {
1909 /* Function has C linkage. We don't print this information.
1910 FIXME: We should print it in verbose mode. */
1911 d_advance (di, 1);
1912 }
1913 ret = d_bare_function_type (di, 1);
1914 if (d_next_char (di) != 'E')
1915 return NULL;
1916 return ret;
1917}
74bcd529 1918
d00edca5 1919/* <bare-function-type> ::= <type>+ */
eb383413 1920
d00edca5
DD
1921static struct d_comp *
1922d_bare_function_type (di, has_return_type)
1923 struct d_info *di;
1924 int has_return_type;
1925{
1926 struct d_comp *return_type;
1927 struct d_comp *tl;
1928 struct d_comp **ptl;
eb383413 1929
d00edca5
DD
1930 return_type = NULL;
1931 tl = NULL;
1932 ptl = &tl;
eb383413
L
1933 while (1)
1934 {
1935 char peek;
d00edca5 1936 struct d_comp *type;
eb383413 1937
d00edca5
DD
1938 peek = d_peek_char (di);
1939 if (peek == '\0' || peek == 'E')
1940 break;
1941 type = d_type (di);
1942 if (type == NULL)
1943 return NULL;
1944 if (has_return_type)
eb383413 1945 {
d00edca5
DD
1946 return_type = type;
1947 has_return_type = 0;
eb383413 1948 }
d00edca5 1949 else
eb383413 1950 {
d00edca5 1951 *ptl = d_make_comp (di, D_COMP_ARGLIST, type, NULL);
331c3da2
DD
1952 if (*ptl == NULL)
1953 return NULL;
d00edca5 1954 ptl = &d_right (*ptl);
eb383413 1955 }
eb383413 1956 }
eb383413 1957
d00edca5
DD
1958 /* There should be at least one parameter type besides the optional
1959 return type. A function which takes no arguments will have a
1960 single parameter type void. */
1961 if (tl == NULL)
1962 return NULL;
eb383413 1963
d00edca5
DD
1964 /* If we have a single parameter type void, omit it. */
1965 if (d_right (tl) == NULL
1966 && d_left (tl)->type == D_COMP_BUILTIN_TYPE
1967 && d_left (tl)->u.s_builtin.type->print == D_PRINT_VOID)
1968 tl = NULL;
eb383413 1969
d00edca5
DD
1970 return d_make_comp (di, D_COMP_FUNCTION_TYPE, return_type, tl);
1971}
eb383413 1972
d00edca5 1973/* <class-enum-type> ::= <name> */
eb383413 1974
d00edca5
DD
1975static struct d_comp *
1976d_class_enum_type (di)
1977 struct d_info *di;
1978{
1979 return d_name (di);
1980}
74bcd529 1981
d00edca5
DD
1982/* <array-type> ::= A <(positive dimension) number> _ <(element) type>
1983 ::= A [<(dimension) expression>] _ <(element) type>
1984*/
74bcd529 1985
d00edca5
DD
1986static struct d_comp *
1987d_array_type (di)
1988 struct d_info *di;
1989{
1990 char peek;
1991 struct d_comp *dim;
74bcd529 1992
d00edca5
DD
1993 if (d_next_char (di) != 'A')
1994 return NULL;
1995
1996 peek = d_peek_char (di);
1997 if (peek == '_')
1998 dim = NULL;
1999 else if (IS_DIGIT (peek))
74bcd529 2000 {
d00edca5 2001 const char *s;
74bcd529 2002
d00edca5
DD
2003 s = d_str (di);
2004 do
2005 {
2006 d_advance (di, 1);
2007 peek = d_peek_char (di);
2008 }
2009 while (IS_DIGIT (peek));
2010 dim = d_make_name (di, s, d_str (di) - s);
331c3da2
DD
2011 if (dim == NULL)
2012 return NULL;
74bcd529 2013 }
eb383413 2014 else
d00edca5
DD
2015 {
2016 dim = d_expression (di);
2017 if (dim == NULL)
2018 return NULL;
2019 }
eb383413 2020
d00edca5
DD
2021 if (d_next_char (di) != '_')
2022 return NULL;
eb383413 2023
d00edca5
DD
2024 return d_make_comp (di, D_COMP_ARRAY_TYPE, dim, d_type (di));
2025}
eb383413 2026
d00edca5 2027/* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
eb383413 2028
d00edca5
DD
2029static struct d_comp *
2030d_pointer_to_member_type (di)
2031 struct d_info *di;
eb383413 2032{
d00edca5
DD
2033 struct d_comp *cl;
2034 struct d_comp *mem;
2035 struct d_comp **pmem;
eb383413 2036
d00edca5
DD
2037 if (d_next_char (di) != 'M')
2038 return NULL;
eb383413 2039
d00edca5 2040 cl = d_type (di);
eb383413 2041
d00edca5
DD
2042 /* The ABI specifies that any type can be a substitution source, and
2043 that M is followed by two types, and that when a CV-qualified
2044 type is seen both the base type and the CV-qualified types are
2045 substitution sources. The ABI also specifies that for a pointer
2046 to a CV-qualified member function, the qualifiers are attached to
2047 the second type. Given the grammar, a plain reading of the ABI
2048 suggests that both the CV-qualified member function and the
2049 non-qualified member function are substitution sources. However,
2050 g++ does not work that way. g++ treats only the CV-qualified
2051 member function as a substitution source. FIXME. So to work
2052 with g++, we need to pull off the CV-qualifiers here, in order to
2053 avoid calling add_substitution() in d_type(). */
eb383413 2054
858b45cf 2055 pmem = d_cv_qualifiers (di, &mem, 1);
331c3da2
DD
2056 if (pmem == NULL)
2057 return NULL;
d00edca5 2058 *pmem = d_type (di);
eb383413 2059
d00edca5 2060 return d_make_comp (di, D_COMP_PTRMEM_TYPE, cl, mem);
eb383413
L
2061}
2062
d00edca5
DD
2063/* <template-param> ::= T_
2064 ::= T <(parameter-2 non-negative) number> _
2065*/
eb383413 2066
d00edca5
DD
2067static struct d_comp *
2068d_template_param (di)
2069 struct d_info *di;
eb383413 2070{
d00edca5 2071 long param;
eb383413 2072
d00edca5
DD
2073 if (d_next_char (di) != 'T')
2074 return NULL;
eb383413 2075
d00edca5
DD
2076 if (d_peek_char (di) == '_')
2077 param = 0;
2078 else
2079 {
2080 param = d_number (di);
2081 if (param < 0)
2082 return NULL;
2083 param += 1;
2084 }
03d5f569 2085
d00edca5
DD
2086 if (d_next_char (di) != '_')
2087 return NULL;
eb383413 2088
d00edca5 2089 return d_make_template_param (di, param);
eb383413
L
2090}
2091
d00edca5
DD
2092/* <template-args> ::= I <template-arg>+ E */
2093
2094static struct d_comp *
2095d_template_args (di)
2096 struct d_info *di;
eb383413 2097{
d00edca5
DD
2098 struct d_comp *hold_last_name;
2099 struct d_comp *al;
2100 struct d_comp **pal;
eb383413 2101
d00edca5
DD
2102 /* Preserve the last name we saw--don't let the template arguments
2103 clobber it, as that would give us the wrong name for a subsequent
2104 constructor or destructor. */
2105 hold_last_name = di->last_name;
eb383413 2106
d00edca5
DD
2107 if (d_next_char (di) != 'I')
2108 return NULL;
eb383413 2109
d00edca5
DD
2110 al = NULL;
2111 pal = &al;
eb383413
L
2112 while (1)
2113 {
d00edca5
DD
2114 struct d_comp *a;
2115
2116 a = d_template_arg (di);
2117 if (a == NULL)
2118 return NULL;
2119
2120 *pal = d_make_comp (di, D_COMP_TEMPLATE_ARGLIST, a, NULL);
331c3da2
DD
2121 if (*pal == NULL)
2122 return NULL;
d00edca5
DD
2123 pal = &d_right (*pal);
2124
2125 if (d_peek_char (di) == 'E')
03d5f569 2126 {
d00edca5
DD
2127 d_advance (di, 1);
2128 break;
03d5f569 2129 }
eb383413
L
2130 }
2131
d00edca5
DD
2132 di->last_name = hold_last_name;
2133
2134 return al;
eb383413
L
2135}
2136
d00edca5
DD
2137/* <template-arg> ::= <type>
2138 ::= X <expression> E
2139 ::= <expr-primary>
2140*/
eb383413 2141
d00edca5
DD
2142static struct d_comp *
2143d_template_arg (di)
2144 struct d_info *di;
eb383413 2145{
d00edca5 2146 struct d_comp *ret;
03d5f569 2147
d00edca5 2148 switch (d_peek_char (di))
eb383413 2149 {
d00edca5
DD
2150 case 'X':
2151 d_advance (di, 1);
2152 ret = d_expression (di);
2153 if (d_next_char (di) != 'E')
2154 return NULL;
2155 return ret;
b851d07b 2156
d00edca5
DD
2157 case 'L':
2158 return d_expr_primary (di);
eb383413 2159
d00edca5
DD
2160 default:
2161 return d_type (di);
74bcd529 2162 }
eb383413
L
2163}
2164
d00edca5
DD
2165/* <expression> ::= <(unary) operator-name> <expression>
2166 ::= <(binary) operator-name> <expression> <expression>
2167 ::= <(trinary) operator-name> <expression> <expression> <expression>
2168 ::= st <type>
2169 ::= <template-param>
2170 ::= sr <type> <unqualified-name>
2171 ::= sr <type> <unqualified-name> <template-args>
2172 ::= <expr-primary>
2173*/
2174
2175static struct d_comp *
2176d_expression (di)
2177 struct d_info *di;
eb383413 2178{
d00edca5 2179 char peek;
eb383413 2180
d00edca5
DD
2181 peek = d_peek_char (di);
2182 if (peek == 'L')
2183 return d_expr_primary (di);
2184 else if (peek == 'T')
2185 return d_template_param (di);
2186 else if (peek == 's' && d_peek_next_char (di) == 'r')
eb383413 2187 {
d00edca5
DD
2188 struct d_comp *type;
2189 struct d_comp *name;
eb383413 2190
d00edca5
DD
2191 d_advance (di, 2);
2192 type = d_type (di);
2193 name = d_unqualified_name (di);
2194 if (d_peek_char (di) != 'I')
2195 return d_make_comp (di, D_COMP_QUAL_NAME, type, name);
2196 else
2197 return d_make_comp (di, D_COMP_QUAL_NAME, type,
2198 d_make_comp (di, D_COMP_TEMPLATE, name,
2199 d_template_args (di)));
793011ca 2200 }
d00edca5 2201 else
eb383413 2202 {
d00edca5
DD
2203 struct d_comp *op;
2204 int args;
eb383413 2205
d00edca5
DD
2206 op = d_operator_name (di);
2207 if (op == NULL)
2208 return NULL;
eb383413 2209
d00edca5
DD
2210 if (op->type == D_COMP_OPERATOR
2211 && strcmp (op->u.s_operator.op->code, "st") == 0)
2212 return d_make_comp (di, D_COMP_UNARY, op, d_type (di));
eb383413 2213
d00edca5
DD
2214 switch (op->type)
2215 {
2216 default:
2217 return NULL;
2218 case D_COMP_OPERATOR:
2219 args = op->u.s_operator.op->args;
2220 break;
2221 case D_COMP_EXTENDED_OPERATOR:
2222 args = op->u.s_extended_operator.args;
2223 break;
2224 case D_COMP_CAST:
2225 args = 1;
2226 break;
2227 }
2228
2229 switch (args)
2230 {
2231 case 1:
2232 return d_make_comp (di, D_COMP_UNARY, op, d_expression (di));
2233 case 2:
2234 {
2235 struct d_comp *left;
2236
2237 left = d_expression (di);
2238 return d_make_comp (di, D_COMP_BINARY, op,
2239 d_make_comp (di, D_COMP_BINARY_ARGS, left,
2240 d_expression (di)));
2241 }
2242 case 3:
2243 {
2244 struct d_comp *first;
2245 struct d_comp *second;
2246
2247 first = d_expression (di);
2248 second = d_expression (di);
2249 return d_make_comp (di, D_COMP_TRINARY, op,
2250 d_make_comp (di, D_COMP_TRINARY_ARG1, first,
2251 d_make_comp (di,
2252 D_COMP_TRINARY_ARG2,
2253 second,
2254 d_expression (di))));
2255 }
2256 default:
2257 return NULL;
2258 }
eb383413
L
2259 }
2260}
2261
d00edca5
DD
2262/* <expr-primary> ::= L <type> <(value) number> E
2263 ::= L <type> <(value) float> E
2264 ::= L <mangled-name> E
2265*/
74bcd529 2266
d00edca5
DD
2267static struct d_comp *
2268d_expr_primary (di)
2269 struct d_info *di;
74bcd529 2270{
d00edca5 2271 struct d_comp *ret;
74bcd529 2272
d00edca5
DD
2273 if (d_next_char (di) != 'L')
2274 return NULL;
2275 if (d_peek_char (di) == '_')
331c3da2 2276 ret = d_mangled_name (di, 0);
d00edca5 2277 else
74bcd529 2278 {
d00edca5 2279 struct d_comp *type;
97ceaf5b 2280 enum d_comp_type t;
d00edca5
DD
2281 const char *s;
2282
2283 type = d_type (di);
2284
2285 /* Rather than try to interpret the literal value, we just
2286 collect it as a string. Note that it's possible to have a
2287 floating point literal here. The ABI specifies that the
2288 format of such literals is machine independent. That's fine,
2289 but what's not fine is that versions of g++ up to 3.2 with
2290 -fabi-version=1 used upper case letters in the hex constant,
2291 and dumped out gcc's internal representation. That makes it
2292 hard to tell where the constant ends, and hard to dump the
2293 constant in any readable form anyhow. We don't attempt to
2294 handle these cases. */
2295
97ceaf5b
DD
2296 t = D_COMP_LITERAL;
2297 if (d_peek_char (di) == 'n')
2298 {
2299 t = D_COMP_LITERAL_NEG;
2300 d_advance (di, 1);
2301 }
d00edca5
DD
2302 s = d_str (di);
2303 while (d_peek_char (di) != 'E')
2304 d_advance (di, 1);
97ceaf5b 2305 ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s));
d00edca5
DD
2306 }
2307 if (d_next_char (di) != 'E')
2308 return NULL;
2309 return ret;
74bcd529
DD
2310}
2311
d00edca5
DD
2312/* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2313 ::= Z <(function) encoding> E s [<discriminator>]
2314*/
74bcd529 2315
d00edca5
DD
2316static struct d_comp *
2317d_local_name (di)
2318 struct d_info *di;
74bcd529 2319{
d00edca5 2320 struct d_comp *function;
74bcd529 2321
d00edca5
DD
2322 if (d_next_char (di) != 'Z')
2323 return NULL;
74bcd529 2324
6d95373e 2325 function = d_encoding (di, 0);
74bcd529 2326
d00edca5
DD
2327 if (d_next_char (di) != 'E')
2328 return NULL;
74bcd529 2329
d00edca5 2330 if (d_peek_char (di) == 's')
74bcd529 2331 {
d00edca5
DD
2332 d_advance (di, 1);
2333 if (! d_discriminator (di))
2334 return NULL;
2335 return d_make_comp (di, D_COMP_QUAL_NAME, function,
2336 d_make_name (di, "string literal",
2337 sizeof "string literal" - 1));
74bcd529 2338 }
d00edca5 2339 else
74bcd529 2340 {
d00edca5 2341 struct d_comp *name;
74bcd529 2342
d00edca5
DD
2343 name = d_name (di);
2344 if (! d_discriminator (di))
2345 return NULL;
2346 return d_make_comp (di, D_COMP_QUAL_NAME, function, name);
74bcd529 2347 }
74bcd529
DD
2348}
2349
d00edca5 2350/* <discriminator> ::= _ <(non-negative) number>
eb383413 2351
d00edca5
DD
2352 We demangle the discriminator, but we don't print it out. FIXME:
2353 We should print it out in verbose mode. */
74bcd529 2354
d00edca5
DD
2355static int
2356d_discriminator (di)
2357 struct d_info *di;
2358{
2359 long discrim;
74bcd529 2360
d00edca5
DD
2361 if (d_peek_char (di) != '_')
2362 return 1;
2363 d_advance (di, 1);
2364 discrim = d_number (di);
2365 if (discrim < 0)
2366 return 0;
2367 return 1;
2368}
eb383413 2369
d00edca5 2370/* Add a new substitution. */
eb383413 2371
d00edca5
DD
2372static int
2373d_add_substitution (di, dc)
2374 struct d_info *di;
2375 struct d_comp *dc;
eb383413 2376{
331c3da2
DD
2377 if (dc == NULL)
2378 return 0;
d00edca5
DD
2379 if (di->next_sub >= di->num_subs)
2380 return 0;
2381 di->subs[di->next_sub] = dc;
2382 ++di->next_sub;
2383 return 1;
2384}
2385
2386/* <substitution> ::= S <seq-id> _
2387 ::= S_
2388 ::= St
2389 ::= Sa
2390 ::= Sb
2391 ::= Ss
2392 ::= Si
2393 ::= So
2394 ::= Sd
97ceaf5b
DD
2395
2396 If PREFIX is non-zero, then this type is being used as a prefix in
2397 a qualified name. In this case, for the standard substitutions, we
2398 need to check whether we are being used as a prefix for a
2399 constructor or destructor, and return a full template name.
2400 Otherwise we will get something like std::iostream::~iostream()
2401 which does not correspond particularly well to any function which
2402 actually appears in the source.
d00edca5 2403*/
eb383413 2404
97ceaf5b
DD
2405static const struct d_standard_sub_info standard_subs[] =
2406{
2407 { 't', "std", "std", NULL },
2408 { 'a', "std::allocator", "std::allocator", "allocator" },
2409 { 'b', "std::basic_string", "std::basic_string", "basic_string" },
2410 { 's', "std::string",
2411 "std::basic_string<char, std::char_traits<char>, std::allocator<char> >",
2412 "basic_string" },
2413 { 'i', "std::istream",
2414 "std::basic_istream<char, std::char_traits<char> >",
2415 "basic_istream" },
2416 { 'o', "std::ostream",
2417 "std::basic_ostream<char, std::char_traits<char> >",
2418 "basic_ostream" },
2419 { 'd', "std::iostream",
2420 "std::basic_iostream<char, std::char_traits<char> >",
2421 "basic_iostream" }
2422};
2423
d00edca5 2424static struct d_comp *
97ceaf5b 2425d_substitution (di, prefix)
d00edca5 2426 struct d_info *di;
97ceaf5b 2427 int prefix;
d00edca5
DD
2428{
2429 char c;
eb383413 2430
d00edca5
DD
2431 if (d_next_char (di) != 'S')
2432 return NULL;
e7e9b069 2433
d00edca5 2434 c = d_next_char (di);
858b45cf 2435 if (c == '_' || IS_DIGIT (c) || IS_UPPER (c))
eb383413 2436 {
d00edca5 2437 int id;
eb383413 2438
d00edca5
DD
2439 id = 0;
2440 if (c != '_')
eb383413 2441 {
d00edca5 2442 do
eb383413 2443 {
d00edca5
DD
2444 if (IS_DIGIT (c))
2445 id = id * 36 + c - '0';
858b45cf 2446 else if (IS_UPPER (c))
d00edca5
DD
2447 id = id * 36 + c - 'A' + 10;
2448 else
2449 return NULL;
2450 c = d_next_char (di);
eb383413 2451 }
d00edca5 2452 while (c != '_');
eb383413 2453
d00edca5 2454 ++id;
eb383413 2455 }
eb383413 2456
d00edca5
DD
2457 if (id >= di->next_sub)
2458 return NULL;
eb383413 2459
d00edca5 2460 return di->subs[id];
eb383413 2461 }
d00edca5 2462 else
eb383413 2463 {
97ceaf5b
DD
2464 int verbose;
2465 const struct d_standard_sub_info *p;
2466 const struct d_standard_sub_info *pend;
2467
2468 verbose = (di->options & DMGL_VERBOSE) != 0;
2469 if (! verbose && prefix)
e61231f1 2470 {
97ceaf5b
DD
2471 char peek;
2472
2473 peek = d_peek_char (di);
2474 if (peek == 'C' || peek == 'D')
2475 verbose = 1;
eb383413 2476 }
97ceaf5b
DD
2477
2478 pend = (&standard_subs[0]
2479 + sizeof standard_subs / sizeof standard_subs[0]);
2480 for (p = &standard_subs[0]; p < pend; ++p)
2481 {
2482 if (c == p->code)
2483 {
2484 if (p->set_last_name != NULL)
2485 di->last_name = d_make_sub (di, p->set_last_name);
2486 if (verbose)
2487 return d_make_sub (di, p->full_expansion);
2488 else
2489 return d_make_sub (di, p->simple_expansion);
2490 }
2491 }
2492
2493 return NULL;
eb383413 2494 }
eb383413
L
2495}
2496
d00edca5 2497/* Resize the print buffer. */
eb383413 2498
d00edca5
DD
2499static void
2500d_print_resize (dpi, add)
2501 struct d_print_info *dpi;
2502 size_t add;
2503{
2504 size_t need;
eb383413 2505
331c3da2
DD
2506 if (dpi->buf == NULL)
2507 return;
d00edca5
DD
2508 need = dpi->len + add;
2509 while (need > dpi->alc)
eb383413 2510 {
d00edca5
DD
2511 size_t newalc;
2512 char *newbuf;
59666b35 2513
d00edca5
DD
2514 newalc = dpi->alc * 2;
2515 newbuf = realloc (dpi->buf, newalc);
2516 if (newbuf == NULL)
0976f6a7 2517 {
d00edca5
DD
2518 free (dpi->buf);
2519 dpi->buf = NULL;
2520 dpi->allocation_failure = 1;
2521 return;
eb383413 2522 }
d00edca5
DD
2523 dpi->buf = newbuf;
2524 dpi->alc = newalc;
eb383413 2525 }
d00edca5 2526}
0976f6a7 2527
d00edca5 2528/* Append a character to the print buffer. */
0976f6a7 2529
d00edca5
DD
2530static void
2531d_print_append_char (dpi, c)
2532 struct d_print_info *dpi;
2533 int c;
2534{
2535 if (dpi->buf != NULL)
2536 {
2537 if (dpi->len >= dpi->alc)
2538 {
2539 d_print_resize (dpi, 1);
2540 if (dpi->buf == NULL)
2541 return;
2542 }
0976f6a7 2543
d00edca5
DD
2544 dpi->buf[dpi->len] = c;
2545 ++dpi->len;
74bcd529 2546 }
eb383413
L
2547}
2548
d00edca5
DD
2549/* Append a buffer to the print buffer. */
2550
2551static void
2552d_print_append_buffer (dpi, s, l)
2553 struct d_print_info *dpi;
2554 const char *s;
2555 size_t l;
eb383413 2556{
d00edca5 2557 if (dpi->buf != NULL)
eb383413 2558 {
d00edca5 2559 if (dpi->len + l > dpi->alc)
eb383413 2560 {
d00edca5
DD
2561 d_print_resize (dpi, l);
2562 if (dpi->buf == NULL)
2563 return;
eb383413 2564 }
eb383413 2565
d00edca5
DD
2566 memcpy (dpi->buf + dpi->len, s, l);
2567 dpi->len += l;
2568 }
eb383413
L
2569}
2570
d00edca5 2571/* Indicate that an error occurred during printing. */
eb383413 2572
d00edca5
DD
2573static void
2574d_print_error (dpi)
2575 struct d_print_info *dpi;
bc9bf259 2576{
d00edca5
DD
2577 free (dpi->buf);
2578 dpi->buf = NULL;
2579}
bc9bf259 2580
d00edca5
DD
2581/* Turn components into a human readable string. Returns a string
2582 allocated by malloc, or NULL on error. On success, this sets *PALC
2583 to the size of the allocated buffer. On failure, this sets *PALC
2584 to 0 for a bad parse, or to 1 for a memory allocation failure. */
eb383413 2585
d00edca5
DD
2586static char *
2587d_print (options, dc, palc)
2588 int options;
2589 const struct d_comp *dc;
2590 size_t *palc;
2591{
2592 struct d_print_info dpi;
eb383413 2593
d00edca5 2594 dpi.options = options;
eb383413 2595
d00edca5
DD
2596 dpi.alc = 64;
2597 dpi.buf = malloc (dpi.alc);
2598 if (dpi.buf == NULL)
eb383413 2599 {
d00edca5
DD
2600 *palc = 1;
2601 return NULL;
eb383413 2602 }
eb383413 2603
d00edca5
DD
2604 dpi.len = 0;
2605 dpi.templates = NULL;
2606 dpi.modifiers = NULL;
eb383413 2607
d00edca5 2608 dpi.allocation_failure = 0;
eb383413 2609
d00edca5 2610 d_print_comp (&dpi, dc);
eb383413 2611
d00edca5 2612 d_append_char (&dpi, '\0');
eb383413 2613
d00edca5
DD
2614 if (dpi.buf != NULL)
2615 *palc = dpi.alc;
2616 else
2617 *palc = dpi.allocation_failure;
eb383413 2618
d00edca5 2619 return dpi.buf;
eb383413
L
2620}
2621
d00edca5 2622/* Subroutine to handle components. */
eb383413 2623
d00edca5
DD
2624static void
2625d_print_comp (dpi, dc)
2626 struct d_print_info *dpi;
2627 const struct d_comp *dc;
eb383413 2628{
d00edca5 2629 if (dc == NULL)
eb383413 2630 {
d00edca5
DD
2631 d_print_error (dpi);
2632 return;
eb383413 2633 }
d00edca5
DD
2634 if (d_print_saw_error (dpi))
2635 return;
eb383413 2636
d00edca5 2637 switch (dc->type)
eb383413 2638 {
d00edca5
DD
2639 case D_COMP_NAME:
2640 d_print_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len);
2641 return;
eb383413 2642
d00edca5
DD
2643 case D_COMP_QUAL_NAME:
2644 d_print_comp (dpi, d_left (dc));
2645 d_append_string (dpi, (dpi->options & DMGL_JAVA) == 0 ? "::" : ".");
2646 d_print_comp (dpi, d_right (dc));
2647 return;
eb383413 2648
d00edca5
DD
2649 case D_COMP_TYPED_NAME:
2650 {
858b45cf
DD
2651 struct d_print_mod *hold_modifiers;
2652 struct d_comp *typed_name;
2653 struct d_print_mod adpm[4];
2654 unsigned int i;
d00edca5
DD
2655 struct d_print_template dpt;
2656
2657 /* Pass the name down to the type so that it can be printed in
858b45cf
DD
2658 the right place for the type. We also have to pass down
2659 any CV-qualifiers, which apply to the this parameter. */
2660 hold_modifiers = dpi->modifiers;
2661 i = 0;
d00edca5 2662 typed_name = d_left (dc);
858b45cf
DD
2663 while (typed_name != NULL)
2664 {
2665 if (i >= sizeof adpm / sizeof adpm[0])
2666 {
2667 d_print_error (dpi);
2668 return;
2669 }
d00edca5 2670
858b45cf
DD
2671 adpm[i].next = dpi->modifiers;
2672 dpi->modifiers = &adpm[i];
2673 adpm[i].mod = typed_name;
2674 adpm[i].printed = 0;
2675 adpm[i].templates = dpi->templates;
2676 ++i;
2677
2678 if (typed_name->type != D_COMP_RESTRICT_THIS
2679 && typed_name->type != D_COMP_VOLATILE_THIS
2680 && typed_name->type != D_COMP_CONST_THIS)
2681 break;
2682
2683 typed_name = d_left (typed_name);
2684 }
d00edca5
DD
2685
2686 /* If typed_name is a template, then it applies to the
2687 function type as well. */
2688 if (typed_name->type == D_COMP_TEMPLATE)
2689 {
2690 dpt.next = dpi->templates;
2691 dpi->templates = &dpt;
2692 dpt.template = typed_name;
2693 }
eb383413 2694
d00edca5 2695 d_print_comp (dpi, d_right (dc));
74bcd529 2696
d00edca5
DD
2697 if (typed_name->type == D_COMP_TEMPLATE)
2698 dpi->templates = dpt.next;
eb383413 2699
858b45cf 2700 /* If the modifiers didn't get printed by the type, print them
d00edca5 2701 now. */
858b45cf 2702 while (i > 0)
d00edca5 2703 {
858b45cf
DD
2704 --i;
2705 if (! adpm[i].printed)
2706 {
2707 d_append_char (dpi, ' ');
2708 d_print_mod (dpi, adpm[i].mod);
2709 }
d00edca5 2710 }
eb383413 2711
858b45cf 2712 dpi->modifiers = hold_modifiers;
eb383413 2713
d00edca5
DD
2714 return;
2715 }
eb383413 2716
d00edca5 2717 case D_COMP_TEMPLATE:
331c3da2
DD
2718 {
2719 struct d_print_mod *hold_dpm;
2720
2721 /* Don't push modifiers into a template definition. Doing so
2722 could give the wrong definition for a template argument.
2723 Instead, treat the template essentially as a name. */
2724
2725 hold_dpm = dpi->modifiers;
2726 dpi->modifiers = NULL;
2727
2728 d_print_comp (dpi, d_left (dc));
858b45cf
DD
2729 if (d_last_char (dpi) == '<')
2730 d_append_char (dpi, ' ');
331c3da2
DD
2731 d_append_char (dpi, '<');
2732 d_print_comp (dpi, d_right (dc));
2733 /* Avoid generating two consecutive '>' characters, to avoid
2734 the C++ syntactic ambiguity. */
858b45cf 2735 if (d_last_char (dpi) == '>')
331c3da2
DD
2736 d_append_char (dpi, ' ');
2737 d_append_char (dpi, '>');
2738
2739 dpi->modifiers = hold_dpm;
2740
2741 return;
2742 }
d00edca5
DD
2743
2744 case D_COMP_TEMPLATE_PARAM:
2745 {
2746 long i;
2747 struct d_comp *a;
2748 struct d_print_template *hold_dpt;
eb383413 2749
d00edca5
DD
2750 if (dpi->templates == NULL)
2751 {
2752 d_print_error (dpi);
2753 return;
2754 }
2755 i = dc->u.s_number.number;
2756 for (a = d_right (dpi->templates->template);
2757 a != NULL;
2758 a = d_right (a))
2759 {
2760 if (a->type != D_COMP_TEMPLATE_ARGLIST)
2761 {
2762 d_print_error (dpi);
2763 return;
2764 }
2765 if (i <= 0)
2766 break;
2767 --i;
2768 }
2769 if (i != 0 || a == NULL)
2770 {
2771 d_print_error (dpi);
2772 return;
2773 }
59666b35 2774
d00edca5
DD
2775 /* While processing this parameter, we need to pop the list of
2776 templates. This is because the template parameter may
2777 itself be a reference to a parameter of an outer
2778 template. */
59666b35 2779
d00edca5
DD
2780 hold_dpt = dpi->templates;
2781 dpi->templates = hold_dpt->next;
eb383413 2782
d00edca5 2783 d_print_comp (dpi, d_left (a));
03d5f569 2784
d00edca5 2785 dpi->templates = hold_dpt;
59666b35 2786
d00edca5
DD
2787 return;
2788 }
eb383413 2789
d00edca5
DD
2790 case D_COMP_CTOR:
2791 d_print_comp (dpi, dc->u.s_ctor.name);
2792 return;
2793
2794 case D_COMP_DTOR:
2795 d_append_char (dpi, '~');
2796 d_print_comp (dpi, dc->u.s_dtor.name);
2797 return;
2798
2799 case D_COMP_VTABLE:
2800 d_append_string (dpi, "vtable for ");
2801 d_print_comp (dpi, d_left (dc));
2802 return;
2803
2804 case D_COMP_VTT:
2805 d_append_string (dpi, "VTT for ");
2806 d_print_comp (dpi, d_left (dc));
2807 return;
2808
2809 case D_COMP_CONSTRUCTION_VTABLE:
2810 d_append_string (dpi, "construction vtable for ");
2811 d_print_comp (dpi, d_left (dc));
2812 d_append_string (dpi, "-in-");
2813 d_print_comp (dpi, d_right (dc));
2814 return;
2815
2816 case D_COMP_TYPEINFO:
2817 d_append_string (dpi, "typeinfo for ");
2818 d_print_comp (dpi, d_left (dc));
2819 return;
2820
2821 case D_COMP_TYPEINFO_NAME:
2822 d_append_string (dpi, "typeinfo name for ");
2823 d_print_comp (dpi, d_left (dc));
2824 return;
2825
2826 case D_COMP_TYPEINFO_FN:
2827 d_append_string (dpi, "typeinfo fn for ");
2828 d_print_comp (dpi, d_left (dc));
2829 return;
2830
2831 case D_COMP_THUNK:
2832 d_append_string (dpi, "non-virtual thunk to ");
2833 d_print_comp (dpi, d_left (dc));
2834 return;
2835
2836 case D_COMP_VIRTUAL_THUNK:
2837 d_append_string (dpi, "virtual thunk to ");
2838 d_print_comp (dpi, d_left (dc));
2839 return;
2840
2841 case D_COMP_COVARIANT_THUNK:
2842 d_append_string (dpi, "covariant return thunk to ");
2843 d_print_comp (dpi, d_left (dc));
2844 return;
2845
2846 case D_COMP_JAVA_CLASS:
2847 d_append_string (dpi, "java Class for ");
2848 d_print_comp (dpi, d_left (dc));
2849 return;
2850
2851 case D_COMP_GUARD:
2852 d_append_string (dpi, "guard variable for ");
2853 d_print_comp (dpi, d_left (dc));
2854 return;
2855
2856 case D_COMP_REFTEMP:
2857 d_append_string (dpi, "reference temporary for ");
2858 d_print_comp (dpi, d_left (dc));
2859 return;
2860
2861 case D_COMP_SUB_STD:
2862 d_append_string (dpi, dc->u.s_string.string);
2863 return;
2864
2865 case D_COMP_RESTRICT:
2866 case D_COMP_VOLATILE:
2867 case D_COMP_CONST:
858b45cf
DD
2868 case D_COMP_RESTRICT_THIS:
2869 case D_COMP_VOLATILE_THIS:
2870 case D_COMP_CONST_THIS:
d00edca5
DD
2871 case D_COMP_VENDOR_TYPE_QUAL:
2872 case D_COMP_POINTER:
2873 case D_COMP_REFERENCE:
2874 case D_COMP_COMPLEX:
2875 case D_COMP_IMAGINARY:
2876 {
2877 /* We keep a list of modifiers on the stack. */
2878 struct d_print_mod dpm;
eb383413 2879
d00edca5
DD
2880 dpm.next = dpi->modifiers;
2881 dpi->modifiers = &dpm;
2882 dpm.mod = dc;
2883 dpm.printed = 0;
331c3da2 2884 dpm.templates = dpi->templates;
eb383413 2885
d00edca5 2886 d_print_comp (dpi, d_left (dc));
59666b35 2887
d00edca5
DD
2888 /* If the modifier didn't get printed by the type, print it
2889 now. */
2890 if (! dpm.printed)
2891 d_print_mod (dpi, dc);
eb383413 2892
d00edca5 2893 dpi->modifiers = dpm.next;
eb383413 2894
d00edca5
DD
2895 return;
2896 }
eb383413 2897
d00edca5
DD
2898 case D_COMP_BUILTIN_TYPE:
2899 if ((dpi->options & DMGL_JAVA) == 0)
2900 d_append_string (dpi, dc->u.s_builtin.type->name);
2901 else
2902 d_append_string (dpi, dc->u.s_builtin.type->java_name);
2903 return;
eb383413 2904
d00edca5
DD
2905 case D_COMP_VENDOR_TYPE:
2906 d_print_comp (dpi, d_left (dc));
2907 return;
eb383413 2908
d00edca5
DD
2909 case D_COMP_FUNCTION_TYPE:
2910 {
2911 if (d_left (dc) != NULL)
2912 {
2913 struct d_print_mod dpm;
eb383413 2914
d00edca5
DD
2915 /* We must pass this type down as a modifier in order to
2916 print it in the right location. */
eb383413 2917
d00edca5
DD
2918 dpm.next = dpi->modifiers;
2919 dpi->modifiers = &dpm;
2920 dpm.mod = dc;
2921 dpm.printed = 0;
331c3da2 2922 dpm.templates = dpi->templates;
eb383413 2923
d00edca5 2924 d_print_comp (dpi, d_left (dc));
eb383413 2925
d00edca5 2926 dpi->modifiers = dpm.next;
eb383413 2927
d00edca5
DD
2928 if (dpm.printed)
2929 return;
eb383413 2930
d00edca5
DD
2931 d_append_char (dpi, ' ');
2932 }
eb383413 2933
d00edca5 2934 d_print_function_type (dpi, dc, dpi->modifiers);
03d5f569 2935
d00edca5
DD
2936 return;
2937 }
eb383413 2938
d00edca5
DD
2939 case D_COMP_ARRAY_TYPE:
2940 {
2941 struct d_print_mod dpm;
eb383413 2942
d00edca5
DD
2943 /* We must pass this type down as a modifier in order to print
2944 multi-dimensional arrays correctly. */
03d5f569 2945
d00edca5
DD
2946 dpm.next = dpi->modifiers;
2947 dpi->modifiers = &dpm;
2948 dpm.mod = dc;
2949 dpm.printed = 0;
331c3da2 2950 dpm.templates = dpi->templates;
eb383413 2951
d00edca5 2952 d_print_comp (dpi, d_right (dc));
eb383413 2953
d00edca5 2954 dpi->modifiers = dpm.next;
eb383413 2955
d00edca5
DD
2956 if (dpm.printed)
2957 return;
eb383413 2958
d00edca5 2959 d_print_array_type (dpi, dc, dpi->modifiers);
eb383413 2960
d00edca5
DD
2961 return;
2962 }
eb383413 2963
d00edca5
DD
2964 case D_COMP_PTRMEM_TYPE:
2965 {
d00edca5
DD
2966 struct d_print_mod dpm;
2967
d00edca5
DD
2968 dpm.next = dpi->modifiers;
2969 dpi->modifiers = &dpm;
2970 dpm.mod = dc;
2971 dpm.printed = 0;
331c3da2 2972 dpm.templates = dpi->templates;
d00edca5 2973
858b45cf 2974 d_print_comp (dpi, d_right (dc));
d00edca5
DD
2975
2976 /* If the modifier didn't get printed by the type, print it
2977 now. */
2978 if (! dpm.printed)
2979 {
2980 d_append_char (dpi, ' ');
2981 d_print_comp (dpi, d_left (dc));
2982 d_append_string (dpi, "::*");
2983 }
eb383413 2984
d00edca5 2985 dpi->modifiers = dpm.next;
eb383413 2986
d00edca5
DD
2987 return;
2988 }
eb383413 2989
d00edca5
DD
2990 case D_COMP_ARGLIST:
2991 case D_COMP_TEMPLATE_ARGLIST:
2992 d_print_comp (dpi, d_left (dc));
2993 if (d_right (dc) != NULL)
2994 {
2995 d_append_string (dpi, ", ");
2996 d_print_comp (dpi, d_right (dc));
2997 }
2998 return;
eb383413 2999
d00edca5
DD
3000 case D_COMP_OPERATOR:
3001 {
3002 char c;
3003
3004 d_append_string (dpi, "operator");
3005 c = dc->u.s_operator.op->name[0];
858b45cf 3006 if (IS_LOWER (c))
d00edca5
DD
3007 d_append_char (dpi, ' ');
3008 d_append_string (dpi, dc->u.s_operator.op->name);
3009 return;
3010 }
eb383413 3011
d00edca5
DD
3012 case D_COMP_EXTENDED_OPERATOR:
3013 d_append_string (dpi, "operator ");
3014 d_print_comp (dpi, dc->u.s_extended_operator.name);
3015 return;
eb383413 3016
d00edca5
DD
3017 case D_COMP_CAST:
3018 d_append_string (dpi, "operator ");
3019 d_print_cast (dpi, dc);
3020 return;
eb383413 3021
d00edca5
DD
3022 case D_COMP_UNARY:
3023 if (d_left (dc)->type != D_COMP_CAST)
3024 d_print_expr_op (dpi, d_left (dc));
3025 else
eb383413 3026 {
d00edca5
DD
3027 d_append_string (dpi, "((");
3028 d_print_cast (dpi, d_left (dc));
3029 d_append_char (dpi, ')');
eb383413 3030 }
d00edca5
DD
3031 d_append_char (dpi, '(');
3032 d_print_comp (dpi, d_right (dc));
3033 d_append_char (dpi, ')');
3034 if (d_left (dc)->type == D_COMP_CAST)
3035 d_append_char (dpi, ')');
3036 return;
3037
3038 case D_COMP_BINARY:
3039 if (d_right (dc)->type != D_COMP_BINARY_ARGS)
eb383413 3040 {
d00edca5
DD
3041 d_print_error (dpi);
3042 return;
eb383413 3043 }
858b45cf
DD
3044
3045 /* We wrap an expression which uses the greater-than operator in
3046 an extra layer of parens so that it does not get confused
3047 with the '>' which ends the template parameters. */
3048 if (d_left (dc)->type == D_COMP_OPERATOR
3049 && strcmp (d_left (dc)->u.s_operator.op->name, ">") == 0)
3050 d_append_char (dpi, '(');
3051
d00edca5
DD
3052 d_append_char (dpi, '(');
3053 d_print_comp (dpi, d_left (d_right (dc)));
3054 d_append_string (dpi, ") ");
3055 d_print_expr_op (dpi, d_left (dc));
3056 d_append_string (dpi, " (");
3057 d_print_comp (dpi, d_right (d_right (dc)));
3058 d_append_char (dpi, ')');
858b45cf
DD
3059
3060 if (d_left (dc)->type == D_COMP_OPERATOR
3061 && strcmp (d_left (dc)->u.s_operator.op->name, ">") == 0)
3062 d_append_char (dpi, ')');
3063
d00edca5
DD
3064 return;
3065
3066 case D_COMP_BINARY_ARGS:
3067 /* We should only see this as part of D_COMP_BINARY. */
3068 d_print_error (dpi);
3069 return;
3070
3071 case D_COMP_TRINARY:
3072 if (d_right (dc)->type != D_COMP_TRINARY_ARG1
3073 || d_right (d_right (dc))->type != D_COMP_TRINARY_ARG2)
3074 {
3075 d_print_error (dpi);
3076 return;
3077 }
3078 d_append_char (dpi, '(');
3079 d_print_comp (dpi, d_left (d_right (dc)));
3080 d_append_string (dpi, ") ");
3081 d_print_expr_op (dpi, d_left (dc));
3082 d_append_string (dpi, " (");
3083 d_print_comp (dpi, d_left (d_right (d_right (dc))));
3084 d_append_string (dpi, ") : (");
3085 d_print_comp (dpi, d_right (d_right (d_right (dc))));
3086 d_append_char (dpi, ')');
3087 return;
3088
3089 case D_COMP_TRINARY_ARG1:
3090 case D_COMP_TRINARY_ARG2:
3091 /* We should only see these are part of D_COMP_TRINARY. */
3092 d_print_error (dpi);
3093 return;
3094
3095 case D_COMP_LITERAL:
97ceaf5b 3096 case D_COMP_LITERAL_NEG:
d00edca5
DD
3097 /* For some builtin types, produce simpler output. */
3098 if (d_left (dc)->type == D_COMP_BUILTIN_TYPE)
3099 {
3100 switch (d_left (dc)->u.s_builtin.type->print)
3101 {
3102 case D_PRINT_INT:
3103 if (d_right (dc)->type == D_COMP_NAME)
3104 {
97ceaf5b
DD
3105 if (dc->type == D_COMP_LITERAL_NEG)
3106 d_append_char (dpi, '-');
d00edca5
DD
3107 d_print_comp (dpi, d_right (dc));
3108 return;
3109 }
3110 break;
3111
3112 case D_PRINT_LONG:
3113 if (d_right (dc)->type == D_COMP_NAME)
3114 {
97ceaf5b
DD
3115 if (dc->type == D_COMP_LITERAL_NEG)
3116 d_append_char (dpi, '-');
d00edca5
DD
3117 d_print_comp (dpi, d_right (dc));
3118 d_append_char (dpi, 'l');
3119 return;
3120 }
3121 break;
eb383413 3122
d00edca5
DD
3123 case D_PRINT_BOOL:
3124 if (d_right (dc)->type == D_COMP_NAME
97ceaf5b
DD
3125 && d_right (dc)->u.s_name.len == 1
3126 && dc->type == D_COMP_LITERAL)
d00edca5
DD
3127 {
3128 switch (d_right (dc)->u.s_name.s[0])
3129 {
3130 case '0':
3131 d_append_string (dpi, "false");
3132 return;
3133 case '1':
3134 d_append_string (dpi, "true");
3135 return;
3136 default:
3137 break;
3138 }
3139 }
3140 break;
03d5f569 3141
d00edca5
DD
3142 default:
3143 break;
3144 }
3145 }
eb383413 3146
d00edca5
DD
3147 d_append_char (dpi, '(');
3148 d_print_comp (dpi, d_left (dc));
3149 d_append_char (dpi, ')');
97ceaf5b
DD
3150 if (dc->type == D_COMP_LITERAL_NEG)
3151 d_append_char (dpi, '-');
d00edca5
DD
3152 d_print_comp (dpi, d_right (dc));
3153 return;
eb383413 3154
d00edca5
DD
3155 default:
3156 d_print_error (dpi);
3157 return;
3158 }
eb383413
L
3159}
3160
d00edca5 3161/* Print an identifier. */
eb383413 3162
d00edca5
DD
3163static void
3164d_print_identifier (dpi, name, len)
3165 struct d_print_info *dpi;
3166 const char *name;
3167 int len;
eb383413 3168{
d00edca5
DD
3169 if ((dpi->options & DMGL_JAVA) == 0)
3170 d_append_buffer (dpi, name, len);
3171 else
eb383413 3172 {
d00edca5
DD
3173 const char *p;
3174 const char *end;
eb383413 3175
d00edca5
DD
3176 /* For Java we try to handle encoded extended Unicode
3177 characters. The C++ ABI doesn't mention Unicode encoding, so
3178 we don't it for C++. Characters are encoded as
3179 __U<hex-char>+_. */
3180 end = name + len;
3181 for (p = name; p < end; ++p)
eb383413 3182 {
d00edca5
DD
3183 if (end - p > 3
3184 && p[0] == '_'
3185 && p[1] == '_'
3186 && p[2] == 'U')
3187 {
3188 unsigned long c;
3189 const char *q;
eb383413 3190
d00edca5
DD
3191 c = 0;
3192 for (q = p + 3; q < end; ++q)
3193 {
3194 int dig;
3195
858b45cf 3196 if (IS_DIGIT (*q))
d00edca5
DD
3197 dig = *q - '0';
3198 else if (*q >= 'A' && *q <= 'F')
3199 dig = *q - 'A' + 10;
3200 else if (*q >= 'a' && *q <= 'f')
3201 dig = *q - 'a' + 10;
3202 else
3203 break;
3204
3205 c = c * 16 + dig;
3206 }
3207 /* If the Unicode character is larger than 256, we don't
3208 try to deal with it here. FIXME. */
3209 if (q < end && *q == '_' && c < 256)
3210 {
3211 d_append_char (dpi, c);
3212 p = q;
3213 continue;
3214 }
3215 }
eb383413 3216
d00edca5
DD
3217 d_append_char (dpi, *p);
3218 }
eb383413 3219 }
eb383413
L
3220}
3221
858b45cf
DD
3222/* Print a list of modifiers. SUFFIX is 1 if we are printing
3223 qualifiers on this after printing a function. */
eb383413 3224
d00edca5 3225static void
858b45cf 3226d_print_mod_list (dpi, mods, suffix)
d00edca5
DD
3227 struct d_print_info *dpi;
3228 struct d_print_mod *mods;
858b45cf 3229 int suffix;
eb383413 3230{
331c3da2
DD
3231 struct d_print_template *hold_dpt;
3232
858b45cf 3233 if (mods == NULL || d_print_saw_error (dpi))
d00edca5 3234 return;
eb383413 3235
858b45cf
DD
3236 if (mods->printed
3237 || (! suffix
3238 && (mods->mod->type == D_COMP_RESTRICT_THIS
3239 || mods->mod->type == D_COMP_VOLATILE_THIS
3240 || mods->mod->type == D_COMP_CONST_THIS)))
3241 {
3242 d_print_mod_list (dpi, mods->next, suffix);
3243 return;
3244 }
3245
331c3da2
DD
3246 mods->printed = 1;
3247
3248 hold_dpt = dpi->templates;
3249 dpi->templates = mods->templates;
3250
d00edca5 3251 if (mods->mod->type == D_COMP_FUNCTION_TYPE)
eb383413 3252 {
d00edca5 3253 d_print_function_type (dpi, mods->mod, mods->next);
331c3da2 3254 dpi->templates = hold_dpt;
d00edca5
DD
3255 return;
3256 }
3257 else if (mods->mod->type == D_COMP_ARRAY_TYPE)
3258 {
d00edca5 3259 d_print_array_type (dpi, mods->mod, mods->next);
331c3da2 3260 dpi->templates = hold_dpt;
d00edca5
DD
3261 return;
3262 }
eb383413 3263
d00edca5 3264 d_print_mod (dpi, mods->mod);
eb383413 3265
331c3da2
DD
3266 dpi->templates = hold_dpt;
3267
858b45cf 3268 d_print_mod_list (dpi, mods->next, suffix);
eb383413 3269}
331c3da2 3270
d00edca5 3271/* Print a modifier. */
eb383413 3272
d00edca5
DD
3273static void
3274d_print_mod (dpi, mod)
3275 struct d_print_info *dpi;
3276 const struct d_comp *mod;
3277{
3278 switch (mod->type)
3279 {
3280 case D_COMP_RESTRICT:
858b45cf 3281 case D_COMP_RESTRICT_THIS:
d00edca5
DD
3282 d_append_string (dpi, " restrict");
3283 return;
3284 case D_COMP_VOLATILE:
858b45cf 3285 case D_COMP_VOLATILE_THIS:
d00edca5
DD
3286 d_append_string (dpi, " volatile");
3287 return;
3288 case D_COMP_CONST:
858b45cf 3289 case D_COMP_CONST_THIS:
d00edca5
DD
3290 d_append_string (dpi, " const");
3291 return;
3292 case D_COMP_VENDOR_TYPE_QUAL:
3293 d_append_char (dpi, ' ');
3294 d_print_comp (dpi, d_right (mod));
3295 return;
3296 case D_COMP_POINTER:
3297 /* There is no pointer symbol in Java. */
3298 if ((dpi->options & DMGL_JAVA) == 0)
3299 d_append_char (dpi, '*');
3300 return;
3301 case D_COMP_REFERENCE:
3302 d_append_char (dpi, '&');
3303 return;
3304 case D_COMP_COMPLEX:
3305 d_append_string (dpi, "complex ");
3306 return;
3307 case D_COMP_IMAGINARY:
3308 d_append_string (dpi, "imaginary ");
3309 return;
3310 case D_COMP_PTRMEM_TYPE:
858b45cf 3311 if (d_last_char (dpi) != '(')
d00edca5
DD
3312 d_append_char (dpi, ' ');
3313 d_print_comp (dpi, d_left (mod));
3314 d_append_string (dpi, "::*");
3315 return;
3316 case D_COMP_TYPED_NAME:
3317 d_print_comp (dpi, d_left (mod));
3318 return;
3319 default:
3320 /* Otherwise, we have something that won't go back on the
3321 modifier stack, so we can just print it. */
3322 d_print_comp (dpi, mod);
3323 return;
3324 }
3325}
eb383413 3326
d00edca5 3327/* Print a function type, except for the return type. */
eb383413 3328
d00edca5
DD
3329static void
3330d_print_function_type (dpi, dc, mods)
3331 struct d_print_info *dpi;
3332 const struct d_comp *dc;
3333 struct d_print_mod *mods;
eb383413 3334{
331c3da2
DD
3335 int need_paren;
3336 int saw_mod;
3337 struct d_print_mod *p;
3338
3339 need_paren = 0;
3340 saw_mod = 0;
3341 for (p = mods; p != NULL; p = p->next)
d00edca5 3342 {
331c3da2
DD
3343 if (p->printed)
3344 break;
eb383413 3345
331c3da2
DD
3346 saw_mod = 1;
3347 switch (p->mod->type)
d00edca5 3348 {
331c3da2
DD
3349 case D_COMP_RESTRICT:
3350 case D_COMP_VOLATILE:
3351 case D_COMP_CONST:
3352 case D_COMP_VENDOR_TYPE_QUAL:
3353 case D_COMP_POINTER:
3354 case D_COMP_REFERENCE:
3355 case D_COMP_COMPLEX:
3356 case D_COMP_IMAGINARY:
3357 case D_COMP_PTRMEM_TYPE:
3358 need_paren = 1;
3359 break;
858b45cf
DD
3360 case D_COMP_RESTRICT_THIS:
3361 case D_COMP_VOLATILE_THIS:
3362 case D_COMP_CONST_THIS:
3363 break;
331c3da2
DD
3364 default:
3365 break;
d00edca5 3366 }
331c3da2
DD
3367 if (need_paren)
3368 break;
3369 }
eb383413 3370
331c3da2
DD
3371 if (d_left (dc) != NULL && ! saw_mod)
3372 need_paren = 1;
eb383413 3373
331c3da2 3374 if (need_paren)
858b45cf
DD
3375 {
3376 switch (d_last_char (dpi))
3377 {
3378 case ' ':
3379 case '(':
3380 case '*':
3381 break;
3382
3383 default:
3384 d_append_char (dpi, ' ');
3385 break;
3386 }
3387
3388 d_append_char (dpi, '(');
3389 }
eb383413 3390
858b45cf 3391 d_print_mod_list (dpi, mods, 0);
eb383413 3392
331c3da2
DD
3393 if (need_paren)
3394 d_append_char (dpi, ')');
eb383413 3395
d00edca5 3396 d_append_char (dpi, '(');
eb383413 3397
d00edca5
DD
3398 if (d_right (dc) != NULL)
3399 d_print_comp (dpi, d_right (dc));
eb383413 3400
d00edca5 3401 d_append_char (dpi, ')');
858b45cf
DD
3402
3403 d_print_mod_list (dpi, mods, 1);
d00edca5 3404}
eb383413 3405
d00edca5 3406/* Print an array type, except for the element type. */
eb383413 3407
d00edca5
DD
3408static void
3409d_print_array_type (dpi, dc, mods)
3410 struct d_print_info *dpi;
3411 const struct d_comp *dc;
3412 struct d_print_mod *mods;
3413{
3414 int need_space;
eb383413 3415
d00edca5
DD
3416 need_space = 1;
3417 if (mods != NULL)
eb383413 3418 {
d00edca5
DD
3419 int need_paren;
3420 struct d_print_mod *p;
03d5f569 3421
d00edca5
DD
3422 need_paren = 0;
3423 for (p = mods; p != NULL; p = p->next)
eb383413 3424 {
d00edca5
DD
3425 if (p->printed)
3426 break;
eb383413 3427
d00edca5 3428 if (p->mod->type == D_COMP_ARRAY_TYPE)
eb383413 3429 {
d00edca5
DD
3430 need_space = 0;
3431 break;
eb383413
L
3432 }
3433 else
3434 {
d00edca5
DD
3435 need_paren = 1;
3436 need_space = 1;
3437 break;
eb383413 3438 }
d00edca5 3439 }
eb383413 3440
d00edca5
DD
3441 if (need_paren)
3442 d_append_string (dpi, " (");
eb383413 3443
858b45cf 3444 d_print_mod_list (dpi, mods, 0);
eb383413 3445
d00edca5
DD
3446 if (need_paren)
3447 d_append_char (dpi, ')');
3448 }
eb383413 3449
d00edca5
DD
3450 if (need_space)
3451 d_append_char (dpi, ' ');
03d5f569 3452
d00edca5 3453 d_append_char (dpi, '[');
03d5f569 3454
d00edca5
DD
3455 if (d_left (dc) != NULL)
3456 d_print_comp (dpi, d_left (dc));
eb383413 3457
d00edca5
DD
3458 d_append_char (dpi, ']');
3459}
eb383413 3460
d00edca5 3461/* Print an operator in an expression. */
eb383413 3462
d00edca5
DD
3463static void
3464d_print_expr_op (dpi, dc)
3465 struct d_print_info *dpi;
3466 const struct d_comp *dc;
3467{
3468 if (dc->type == D_COMP_OPERATOR)
3469 d_append_string (dpi, dc->u.s_operator.op->name);
3470 else
3471 d_print_comp (dpi, dc);
eb383413
L
3472}
3473
d00edca5 3474/* Print a cast. */
eb383413 3475
d00edca5
DD
3476static void
3477d_print_cast (dpi, dc)
3478 struct d_print_info *dpi;
3479 const struct d_comp *dc;
eb383413 3480{
d00edca5
DD
3481 if (d_left (dc)->type != D_COMP_TEMPLATE)
3482 d_print_comp (dpi, d_left (dc));
3483 else
3484 {
331c3da2 3485 struct d_print_mod *hold_dpm;
d00edca5 3486 struct d_print_template dpt;
0976f6a7 3487
d00edca5
DD
3488 /* It appears that for a templated cast operator, we need to put
3489 the template parameters in scope for the operator name, but
3490 not for the parameters. The effect is that we need to handle
24afc00d 3491 the template printing here. */
eb383413 3492
331c3da2
DD
3493 hold_dpm = dpi->modifiers;
3494 dpi->modifiers = NULL;
3495
d00edca5
DD
3496 dpt.next = dpi->templates;
3497 dpi->templates = &dpt;
3498 dpt.template = d_left (dc);
0976f6a7 3499
d00edca5 3500 d_print_comp (dpi, d_left (d_left (dc)));
0976f6a7 3501
d00edca5 3502 dpi->templates = dpt.next;
eb383413 3503
858b45cf
DD
3504 if (d_last_char (dpi) == '<')
3505 d_append_char (dpi, ' ');
d00edca5
DD
3506 d_append_char (dpi, '<');
3507 d_print_comp (dpi, d_right (d_left (dc)));
3508 /* Avoid generating two consecutive '>' characters, to avoid
3509 the C++ syntactic ambiguity. */
858b45cf 3510 if (d_last_char (dpi) == '>')
d00edca5
DD
3511 d_append_char (dpi, ' ');
3512 d_append_char (dpi, '>');
331c3da2
DD
3513
3514 dpi->modifiers = hold_dpm;
eb383413 3515 }
d00edca5
DD
3516}
3517
3518/* Initialize the information structure we use to pass around
3519 information. */
3520
3521static int
3522d_init_info (mangled, options, len, di)
3523 const char *mangled;
3524 int options;
3525 size_t len;
3526 struct d_info *di;
eb383413 3527{
d00edca5
DD
3528 di->s = mangled;
3529 di->options = options;
eb383413 3530
d00edca5
DD
3531 di->n = mangled;
3532
3533 /* We can not need more components than twice the number of chars in
3534 the mangled string. Most components correspond directly to
3535 chars, but the ARGLIST types are exceptions. */
3536 di->num_comps = 2 * len;
3537 di->comps = (struct d_comp *) malloc (di->num_comps
3538 * sizeof (struct d_comp));
3539 di->next_comp = 0;
3540
3541 /* Similarly, we can not need more substitutions than there are
331c3da2
DD
3542 chars in the mangled string. */
3543 di->num_subs = len;
d00edca5
DD
3544 di->subs = (struct d_comp **) malloc (di->num_subs
3545 * sizeof (struct d_comp *));
3546 di->next_sub = 0;
3547
3548 di->last_name = NULL;
3549
3550 if (di->comps == NULL || di->subs == NULL)
eb383413 3551 {
d00edca5
DD
3552 if (di->comps != NULL)
3553 free (di->comps);
3554 if (di->subs != NULL)
3555 free (di->subs);
3556 return 0;
eb383413
L
3557 }
3558
d00edca5 3559 return 1;
eb383413
L
3560}
3561
d00edca5
DD
3562/* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
3563 name, return a buffer allocated with malloc holding the demangled
3564 name. OPTIONS is the usual libiberty demangler options. On
3565 success, this sets *PALC to the allocated size of the returned
3566 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
3567 a memory allocation failure. On failure, this returns NULL. */
eb383413 3568
d00edca5
DD
3569static char *
3570d_demangle (mangled, options, palc)
3571 const char* mangled;
3572 int options;
3573 size_t *palc;
eb383413 3574{
d00edca5
DD
3575 size_t len;
3576 int type;
3577 struct d_info di;
3578 struct d_comp *dc;
3579 char *ret;
eb383413 3580
d00edca5 3581 *palc = 0;
eb383413 3582
d00edca5
DD
3583 len = strlen (mangled);
3584
3585 if (mangled[0] == '_' && mangled[1] == 'Z')
3586 type = 0;
3587 else if (strncmp (mangled, "_GLOBAL_", 8) == 0
3588 && (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
3589 && (mangled[9] == 'D' || mangled[9] == 'I')
3590 && mangled[10] == '_')
3591 {
3592 char *r;
eb383413 3593
d00edca5
DD
3594 r = malloc (40 + len - 11);
3595 if (r == NULL)
3596 *palc = 1;
3597 else
eb383413 3598 {
d00edca5
DD
3599 if (mangled[9] == 'I')
3600 strcpy (r, "global constructors keyed to ");
3601 else
3602 strcpy (r, "global destructors keyed to ");
3603 strcat (r, mangled + 11);
eb383413 3604 }
d00edca5 3605 return r;
eb383413
L
3606 }
3607 else
3608 {
d00edca5
DD
3609 if ((options & DMGL_TYPES) == 0)
3610 return NULL;
3611 type = 1;
eb383413
L
3612 }
3613
d00edca5 3614 if (! d_init_info (mangled, options, len, &di))
03d5f569 3615 {
d00edca5
DD
3616 *palc = 1;
3617 return NULL;
03d5f569
JM
3618 }
3619
d00edca5 3620 if (! type)
331c3da2 3621 dc = d_mangled_name (&di, 1);
d00edca5
DD
3622 else
3623 dc = d_type (&di);
3624
24afc00d
DD
3625 /* If we didn't consume the entire mangled string, then we didn't
3626 successfully demangle it. */
3627 if (d_peek_char (&di) != '\0')
3628 dc = NULL;
3629
d00edca5
DD
3630#ifdef CP_DEMANGLE_DEBUG
3631 if (dc == NULL)
3632 printf ("failed demangling\n");
3633 else
3634 d_dump (dc, 0);
3635#endif
3636
3637 free (di.subs);
3638 di.subs = NULL;
03d5f569 3639
d00edca5
DD
3640 ret = NULL;
3641 if (dc != NULL)
3642 ret = d_print (options, dc, palc);
03d5f569 3643
d00edca5 3644 free (di.comps);
03d5f569 3645
d00edca5 3646 return ret;
eb383413
L
3647}
3648
0c4460bb 3649#if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
d00edca5 3650
03d5f569
JM
3651extern char *__cxa_demangle PARAMS ((const char *, char *, size_t *, int *));
3652
d00edca5
DD
3653/* ia64 ABI-mandated entry point in the C++ runtime library for
3654 performing demangling. MANGLED_NAME is a NUL-terminated character
3655 string containing the name to be demangled.
03d5f569
JM
3656
3657 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
3658 *LENGTH bytes, into which the demangled name is stored. If
3659 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
3660 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
d00edca5 3661 is placed in a region of memory allocated with malloc.
03d5f569
JM
3662
3663 If LENGTH is non-NULL, the length of the buffer conaining the
d00edca5 3664 demangled name, is placed in *LENGTH.
03d5f569
JM
3665
3666 The return value is a pointer to the start of the NUL-terminated
3667 demangled name, or NULL if the demangling fails. The caller is
d00edca5 3668 responsible for deallocating this memory using free.
03d5f569
JM
3669
3670 *STATUS is set to one of the following values:
3671 0: The demangling operation succeeded.
d00edca5 3672 -1: A memory allocation failure occurred.
03d5f569
JM
3673 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
3674 -3: One of the arguments is invalid.
3675
d00edca5 3676 The demangling is performed using the C++ ABI mangling rules, with
03d5f569
JM
3677 GNU extensions. */
3678
3679char *
3680__cxa_demangle (mangled_name, output_buffer, length, status)
3681 const char *mangled_name;
3682 char *output_buffer;
3683 size_t *length;
3684 int *status;
3685{
d00edca5
DD
3686 char *demangled;
3687 size_t alc;
03d5f569
JM
3688
3689 if (status == NULL)
3690 return NULL;
3691
d00edca5
DD
3692 if (mangled_name == NULL)
3693 {
03d5f569
JM
3694 *status = -3;
3695 return NULL;
3696 }
03d5f569 3697
d00edca5 3698 if (output_buffer != NULL && length == NULL)
03d5f569 3699 {
d00edca5
DD
3700 *status = -3;
3701 return NULL;
03d5f569 3702 }
d00edca5
DD
3703
3704 demangled = d_demangle (mangled_name, DMGL_TYPES, &alc);
3705
3706 if (demangled == NULL)
03d5f569 3707 {
d00edca5
DD
3708 if (alc == 1)
3709 *status = -1;
3710 else
3711 *status = -2;
03d5f569
JM
3712 return NULL;
3713 }
d00edca5
DD
3714
3715 if (output_buffer == NULL)
3716 {
3717 if (length != NULL)
3718 *length = alc;
3719 }
03d5f569 3720 else
03d5f569 3721 {
d00edca5
DD
3722 if (strlen (demangled) < *length)
3723 {
3724 strcpy (output_buffer, demangled);
3725 free (demangled);
3726 demangled = output_buffer;
3727 }
3728 else
3729 {
3730 free (output_buffer);
3731 *length = alc;
3732 }
03d5f569 3733 }
d00edca5
DD
3734
3735 *status = 0;
3736
3737 return demangled;
03d5f569
JM
3738}
3739
0c4460bb 3740#else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
03d5f569 3741
d00edca5
DD
3742/* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
3743 mangled name, return a buffer allocated with malloc holding the
3744 demangled name. Otherwise, return NULL. */
eb383413
L
3745
3746char *
44354ae1 3747cplus_demangle_v3 (mangled, options)
eb383413 3748 const char* mangled;
44354ae1 3749 int options;
eb383413 3750{
d00edca5 3751 size_t alc;
849ee224 3752
d00edca5 3753 return d_demangle (mangled, options, &alc);
eb383413
L
3754}
3755
bc9bf259
DD
3756/* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
3757 conventions, but the output formatting is a little different.
3758 This instructs the C++ demangler not to emit pointer characters ("*"), and
3759 to use Java's namespace separator symbol ("." instead of "::"). It then
3760 does an additional pass over the demangled output to replace instances
3761 of JArray<TYPE> with TYPE[]. */
3762
3763char *
3764java_demangle_v3 (mangled)
3765 const char* mangled;
3766{
d00edca5
DD
3767 size_t alc;
3768 char *demangled;
3769 int nesting;
3770 char *from;
3771 char *to;
3772
51948b34 3773 demangled = d_demangle (mangled, DMGL_JAVA | DMGL_PARAMS, &alc);
d00edca5
DD
3774
3775 if (demangled == NULL)
3776 return NULL;
3777
3778 nesting = 0;
3779 from = demangled;
3780 to = from;
3781 while (*from != '\0')
bc9bf259 3782 {
d00edca5
DD
3783 if (strncmp (from, "JArray<", 7) == 0)
3784 {
3785 from += 7;
bc9bf259 3786 ++nesting;
bc9bf259 3787 }
d00edca5
DD
3788 else if (nesting > 0 && *from == '>')
3789 {
3790 while (to > demangled && to[-1] == ' ')
3791 --to;
3792 *to++ = '[';
3793 *to++ = ']';
bc9bf259 3794 --nesting;
d00edca5 3795 ++from;
bc9bf259
DD
3796 }
3797 else
d00edca5 3798 *to++ = *from++;
bc9bf259
DD
3799 }
3800
d00edca5 3801 *to = '\0';
f2160d2b 3802
d00edca5 3803 return demangled;
bc9bf259
DD
3804}
3805
0c4460bb 3806#endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
03d5f569 3807
2a9dffbf 3808#ifndef IN_GLIBCPP_V3
d00edca5
DD
3809
3810/* Demangle a string in order to find out whether it is a constructor
3811 or destructor. Return non-zero on success. Set *CTOR_KIND and
3812 *DTOR_KIND appropriately. */
3813
3814static int
3815is_ctor_or_dtor (mangled, ctor_kind, dtor_kind)
3816 const char *mangled;
3817 enum gnu_v3_ctor_kinds *ctor_kind;
3818 enum gnu_v3_dtor_kinds *dtor_kind;
e61231f1 3819{
d00edca5
DD
3820 struct d_info di;
3821 struct d_comp *dc;
858b45cf 3822 int ret;
e61231f1 3823
d00edca5
DD
3824 *ctor_kind = (enum gnu_v3_ctor_kinds) 0;
3825 *dtor_kind = (enum gnu_v3_dtor_kinds) 0;
3826
3827 if (! d_init_info (mangled, DMGL_GNU_V3, strlen (mangled), &di))
e61231f1
JB
3828 return 0;
3829
331c3da2 3830 dc = d_mangled_name (&di, 1);
d00edca5 3831
858b45cf
DD
3832 ret = 0;
3833 if (d_peek_char (&di) == '\0')
e61231f1 3834 {
858b45cf 3835 while (dc != NULL)
d00edca5 3836 {
858b45cf
DD
3837 switch (dc->type)
3838 {
3839 default:
3840 dc = NULL;
3841 break;
3842 case D_COMP_TYPED_NAME:
3843 case D_COMP_TEMPLATE:
3844 case D_COMP_RESTRICT_THIS:
3845 case D_COMP_VOLATILE_THIS:
3846 case D_COMP_CONST_THIS:
3847 dc = d_left (dc);
3848 break;
3849 case D_COMP_QUAL_NAME:
3850 dc = d_right (dc);
3851 break;
3852 case D_COMP_CTOR:
3853 *ctor_kind = dc->u.s_ctor.kind;
3854 ret = 1;
3855 dc = NULL;
3856 break;
3857 case D_COMP_DTOR:
3858 *dtor_kind = dc->u.s_dtor.kind;
3859 ret = 1;
3860 dc = NULL;
3861 break;
3862 }
d00edca5 3863 }
e61231f1
JB
3864 }
3865
858b45cf
DD
3866 free (di.subs);
3867 free (di.comps);
3868
3869 return ret;
e61231f1
JB
3870}
3871
d00edca5
DD
3872/* Return whether NAME is the mangled form of a g++ V3 ABI constructor
3873 name. A non-zero return indicates the type of constructor. */
e61231f1 3874
e61231f1 3875enum gnu_v3_ctor_kinds
457161bf
DD
3876is_gnu_v3_mangled_ctor (name)
3877 const char *name;
e61231f1 3878{
d00edca5
DD
3879 enum gnu_v3_ctor_kinds ctor_kind;
3880 enum gnu_v3_dtor_kinds dtor_kind;
e61231f1 3881
d00edca5 3882 if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
585cc78f 3883 return (enum gnu_v3_ctor_kinds) 0;
d00edca5 3884 return ctor_kind;
e61231f1
JB
3885}
3886
3887
d00edca5
DD
3888/* Return whether NAME is the mangled form of a g++ V3 ABI destructor
3889 name. A non-zero return indicates the type of destructor. */
3890
e61231f1 3891enum gnu_v3_dtor_kinds
457161bf
DD
3892is_gnu_v3_mangled_dtor (name)
3893 const char *name;
e61231f1 3894{
d00edca5
DD
3895 enum gnu_v3_ctor_kinds ctor_kind;
3896 enum gnu_v3_dtor_kinds dtor_kind;
e61231f1 3897
d00edca5 3898 if (! is_ctor_or_dtor (name, &ctor_kind, &dtor_kind))
585cc78f 3899 return (enum gnu_v3_dtor_kinds) 0;
d00edca5 3900 return dtor_kind;
e61231f1
JB
3901}
3902
d00edca5 3903#endif /* IN_GLIBCPP_V3 */
e61231f1 3904
eb383413
L
3905#ifdef STANDALONE_DEMANGLER
3906
3907#include "getopt.h"
d00edca5
DD
3908#include "dyn-string.h"
3909
3910static void print_usage PARAMS ((FILE* fp, int exit_value));
eb383413 3911
d00edca5
DD
3912#define IS_ALPHA(CHAR) \
3913 (((CHAR) >= 'a' && (CHAR) <= 'z') \
3914 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
eb383413
L
3915
3916/* Non-zero if CHAR is a character than can occur in a mangled name. */
3917#define is_mangled_char(CHAR) \
74bcd529
DD
3918 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
3919 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
eb383413
L
3920
3921/* The name of this program, as invoked. */
3922const char* program_name;
3923
3924/* Prints usage summary to FP and then exits with EXIT_VALUE. */
3925
3926static void
3927print_usage (fp, exit_value)
3928 FILE* fp;
3929 int exit_value;
3930{
3931 fprintf (fp, "Usage: %s [options] [names ...]\n", program_name);
74bcd529 3932 fprintf (fp, "Options:\n");
eb383413 3933 fprintf (fp, " -h,--help Display this message.\n");
6d95373e 3934 fprintf (fp, " -p,--no-params Don't display function parameters\n");
eb383413
L
3935 fprintf (fp, " -v,--verbose Produce verbose demanglings.\n");
3936 fprintf (fp, "If names are provided, they are demangled. Otherwise filters standard input.\n");
3937
3938 exit (exit_value);
3939}
3940
3941/* Option specification for getopt_long. */
c23795e2 3942static const struct option long_options[] =
eb383413 3943{
6d95373e
DD
3944 { "help", no_argument, NULL, 'h' },
3945 { "no-params", no_argument, NULL, 'p' },
3946 { "verbose", no_argument, NULL, 'v' },
3947 { NULL, no_argument, NULL, 0 },
eb383413
L
3948};
3949
3950/* Main entry for a demangling filter executable. It will demangle
3951 its command line arguments, if any. If none are provided, it will
3952 filter stdin to stdout, replacing any recognized mangled C++ names
3953 with their demangled equivalents. */
3954
3955int
3956main (argc, argv)
3957 int argc;
3958 char *argv[];
3959{
eb383413
L
3960 int i;
3961 int opt_char;
d00edca5 3962 int options = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
eb383413
L
3963
3964 /* Use the program name of this program, as invoked. */
3965 program_name = argv[0];
3966
3967 /* Parse options. */
3968 do
3969 {
6d95373e 3970 opt_char = getopt_long (argc, argv, "hpv", long_options, NULL);
eb383413
L
3971 switch (opt_char)
3972 {
3973 case '?': /* Unrecognized option. */
3974 print_usage (stderr, 1);
3975 break;
3976
3977 case 'h':
3978 print_usage (stdout, 0);
3979 break;
3980
6d95373e
DD
3981 case 'p':
3982 options &= ~ DMGL_PARAMS;
3983 break;
3984
eb383413 3985 case 'v':
d00edca5 3986 options |= DMGL_VERBOSE;
eb383413
L
3987 break;
3988 }
3989 }
3990 while (opt_char != -1);
3991
3992 if (optind == argc)
3993 /* No command line arguments were provided. Filter stdin. */
3994 {
3995 dyn_string_t mangled = dyn_string_new (3);
d00edca5 3996 char *s;
eb383413
L
3997
3998 /* Read all of input. */
3999 while (!feof (stdin))
4000 {
d00edca5 4001 char c;
eb383413
L
4002
4003 /* Pile characters into mangled until we hit one that can't
4004 occur in a mangled name. */
4005 c = getchar ();
4006 while (!feof (stdin) && is_mangled_char (c))
4007 {
4008 dyn_string_append_char (mangled, c);
4009 if (feof (stdin))
4010 break;
4011 c = getchar ();
4012 }
4013
d00edca5 4014 if (dyn_string_length (mangled) > 0)
03d5f569 4015 {
d00edca5
DD
4016 s = cplus_demangle_v3 (dyn_string_buf (mangled), options);
4017
4018 if (s != NULL)
4019 {
4020 fputs (s, stdout);
4021 free (s);
4022 }
4023 else
4024 {
4025 /* It might not have been a mangled name. Print the
4026 original text. */
4027 fputs (dyn_string_buf (mangled), stdout);
4028 }
4029
4030 dyn_string_clear (mangled);
03d5f569 4031 }
eb383413
L
4032
4033 /* If we haven't hit EOF yet, we've read one character that
4034 can't occur in a mangled name, so print it out. */
4035 if (!feof (stdin))
4036 putchar (c);
eb383413
L
4037 }
4038
4039 dyn_string_delete (mangled);
eb383413
L
4040 }
4041 else
4042 /* Demangle command line arguments. */
4043 {
eb383413
L
4044 /* Loop over command line arguments. */
4045 for (i = optind; i < argc; ++i)
4046 {
d00edca5
DD
4047 char *s;
4048
eb383413 4049 /* Attempt to demangle. */
d00edca5 4050 s = cplus_demangle_v3 (argv[i], options);
eb383413
L
4051
4052 /* If it worked, print the demangled name. */
d00edca5 4053 if (s != NULL)
03d5f569 4054 {
d00edca5
DD
4055 printf ("%s\n", s);
4056 free (s);
03d5f569 4057 }
d00edca5
DD
4058 else
4059 fprintf (stderr, "Failed: %s\n", argv[i]);
eb383413 4060 }
eb383413
L
4061 }
4062
4063 return 0;
4064}
4065
4066#endif /* STANDALONE_DEMANGLER */
This page took 0.378632 seconds and 4 git commands to generate.