1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@wasabisystems.com>.
6 This file is part of the libiberty library, which is part of GCC.
8 This file is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combined
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 /* This code implements a demangler for the g++ V3 ABI. The ABI is
33 described on this web page:
34 http://www.codesourcery.com/cxx-abi/abi.html#mangling
36 This code was written while looking at the demangler written by
37 Alex Samuel <samuel@codesourcery.com>.
39 This code first pulls the mangled name apart into a list of
40 components, and then walks the list generating the demangled
43 This file will normally define the following functions, q.v.:
44 char *cplus_demangle_v3(const char *mangled, int options)
45 char *java_demangle_v3(const char *mangled)
46 int cplus_demangle_v3_callback(const char *mangled, int options,
47 demangle_callbackref callback)
48 int java_demangle_v3_callback(const char *mangled,
49 demangle_callbackref callback)
50 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
51 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
53 Also, the interface to the component list is public, and defined in
54 demangle.h. The interface consists of these types, which are
55 defined in demangle.h:
56 enum demangle_component_type
57 struct demangle_component
59 and these functions defined in this file:
60 cplus_demangle_fill_name
61 cplus_demangle_fill_extended_operator
62 cplus_demangle_fill_ctor
63 cplus_demangle_fill_dtor
65 cplus_demangle_print_callback
66 and other functions defined in the file cp-demint.c.
68 This file also defines some other functions and variables which are
69 only to be used by the file cp-demint.c.
71 Preprocessor macros you can define while compiling this file:
74 If defined, this file defines the following functions, q.v.:
75 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
77 int __gcclibcxx_demangle_callback (const char *,
79 (const char *, size_t, void *),
81 instead of cplus_demangle_v3[_callback]() and
82 java_demangle_v3[_callback]().
85 If defined, this file defines only __cxa_demangle() and
86 __gcclibcxx_demangle_callback(), and no other publically visible
87 functions or variables.
90 If defined, this file defines a main() function which demangles
91 any arguments, or, if none, demangles stdin.
94 If defined, turns on debugging mode, which prints information on
95 stdout about the mangled string. This is not generally useful.
98 #if defined (_AIX) && !defined (__GNUC__)
120 # define alloca __builtin_alloca
122 extern char *alloca ();
123 # endif /* __GNUC__ */
125 #endif /* HAVE_ALLOCA_H */
127 #include "ansidecl.h"
128 #include "libiberty.h"
129 #include "demangle.h"
130 #include "cp-demangle.h"
132 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
133 also rename them via #define to avoid compiler errors when the
134 static definition conflicts with the extern declaration in a header
138 #define CP_STATIC_IF_GLIBCPP_V3 static
140 #define cplus_demangle_fill_name d_fill_name
141 static int d_fill_name (struct demangle_component
*, const char *, int);
143 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
145 d_fill_extended_operator (struct demangle_component
*, int,
146 struct demangle_component
*);
148 #define cplus_demangle_fill_ctor d_fill_ctor
150 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
151 struct demangle_component
*);
153 #define cplus_demangle_fill_dtor d_fill_dtor
155 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
156 struct demangle_component
*);
158 #define cplus_demangle_mangled_name d_mangled_name
159 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
161 #define cplus_demangle_type d_type
162 static struct demangle_component
*d_type (struct d_info
*);
164 #define cplus_demangle_print d_print
165 static char *d_print (int, const struct demangle_component
*, int, size_t *);
167 #define cplus_demangle_print_callback d_print_callback
168 static int d_print_callback (int, const struct demangle_component
*,
169 demangle_callbackref
, void *);
171 #define cplus_demangle_init_info d_init_info
172 static void d_init_info (const char *, int, size_t, struct d_info
*);
174 #else /* ! defined(IN_GLIBCPP_V3) */
175 #define CP_STATIC_IF_GLIBCPP_V3
176 #endif /* ! defined(IN_GLIBCPP_V3) */
178 /* See if the compiler supports dynamic arrays. */
181 #define CP_DYNAMIC_ARRAYS
184 #ifdef __STDC_VERSION__
185 #if __STDC_VERSION__ >= 199901L
186 #define CP_DYNAMIC_ARRAYS
187 #endif /* __STDC__VERSION >= 199901L */
188 #endif /* defined (__STDC_VERSION__) */
189 #endif /* defined (__STDC__) */
190 #endif /* ! defined (__GNUC__) */
192 /* We avoid pulling in the ctype tables, to prevent pulling in
193 additional unresolved symbols when this code is used in a library.
194 FIXME: Is this really a valid reason? This comes from the original
197 As of this writing this file has the following undefined references
198 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
201 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
202 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
203 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
205 /* The prefix prepended by GCC to an identifier represnting the
206 anonymous namespace. */
207 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
208 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
209 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
211 /* Information we keep for the standard substitutions. */
213 struct d_standard_sub_info
215 /* The code for this substitution. */
217 /* The simple string it expands to. */
218 const char *simple_expansion
;
219 /* The length of the simple expansion. */
221 /* The results of a full, verbose, expansion. This is used when
222 qualifying a constructor/destructor, or when in verbose mode. */
223 const char *full_expansion
;
224 /* The length of the full expansion. */
226 /* What to set the last_name field of d_info to; NULL if we should
227 not set it. This is only relevant when qualifying a
228 constructor/destructor. */
229 const char *set_last_name
;
230 /* The length of set_last_name. */
231 int set_last_name_len
;
234 /* Accessors for subtrees of struct demangle_component. */
236 #define d_left(dc) ((dc)->u.s_binary.left)
237 #define d_right(dc) ((dc)->u.s_binary.right)
239 /* A list of templates. This is used while printing. */
241 struct d_print_template
243 /* Next template on the list. */
244 struct d_print_template
*next
;
246 const struct demangle_component
*template_decl
;
249 /* A list of type modifiers. This is used while printing. */
253 /* Next modifier on the list. These are in the reverse of the order
254 in which they appeared in the mangled string. */
255 struct d_print_mod
*next
;
257 const struct demangle_component
*mod
;
258 /* Whether this modifier was printed. */
260 /* The list of templates which applies to this modifier. */
261 struct d_print_template
*templates
;
264 /* We use these structures to hold information during printing. */
266 struct d_growable_string
268 /* Buffer holding the result. */
270 /* Current length of data in buffer. */
272 /* Allocated size of buffer. */
274 /* Set to 1 if we had a memory allocation failure. */
275 int allocation_failure
;
278 enum { D_PRINT_BUFFER_LENGTH
= 256 };
281 /* The options passed to the demangler. */
283 /* Fixed-length allocated buffer for demangled data, flushed to the
284 callback with a NUL termination once full. */
285 char buf
[D_PRINT_BUFFER_LENGTH
];
286 /* Current length of data in buffer. */
288 /* The last character printed, saved individually so that it survives
291 /* Callback function to handle demangled buffer flush. */
292 demangle_callbackref callback
;
293 /* Opaque callback argument. */
295 /* The current list of templates, if any. */
296 struct d_print_template
*templates
;
297 /* The current list of modifiers (e.g., pointer, reference, etc.),
299 struct d_print_mod
*modifiers
;
300 /* Set to 1 if we saw a demangling error. */
301 int demangle_failure
;
302 /* The current index into any template argument packs we are using
307 #ifdef CP_DEMANGLE_DEBUG
308 static void d_dump (struct demangle_component
*, int);
311 static struct demangle_component
*
312 d_make_empty (struct d_info
*);
314 static struct demangle_component
*
315 d_make_comp (struct d_info
*, enum demangle_component_type
,
316 struct demangle_component
*,
317 struct demangle_component
*);
319 static struct demangle_component
*
320 d_make_name (struct d_info
*, const char *, int);
322 static struct demangle_component
*
323 d_make_builtin_type (struct d_info
*,
324 const struct demangle_builtin_type_info
*);
326 static struct demangle_component
*
327 d_make_operator (struct d_info
*,
328 const struct demangle_operator_info
*);
330 static struct demangle_component
*
331 d_make_extended_operator (struct d_info
*, int,
332 struct demangle_component
*);
334 static struct demangle_component
*
335 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
336 struct demangle_component
*);
338 static struct demangle_component
*
339 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
340 struct demangle_component
*);
342 static struct demangle_component
*
343 d_make_template_param (struct d_info
*, long);
345 static struct demangle_component
*
346 d_make_sub (struct d_info
*, const char *, int);
349 has_return_type (struct demangle_component
*);
352 is_ctor_dtor_or_conversion (struct demangle_component
*);
354 static struct demangle_component
*d_encoding (struct d_info
*, int);
356 static struct demangle_component
*d_name (struct d_info
*);
358 static struct demangle_component
*d_nested_name (struct d_info
*);
360 static struct demangle_component
*d_prefix (struct d_info
*);
362 static struct demangle_component
*d_unqualified_name (struct d_info
*);
364 static struct demangle_component
*d_source_name (struct d_info
*);
366 static long d_number (struct d_info
*);
368 static struct demangle_component
*d_identifier (struct d_info
*, int);
370 static struct demangle_component
*d_operator_name (struct d_info
*);
372 static struct demangle_component
*d_special_name (struct d_info
*);
374 static int d_call_offset (struct d_info
*, int);
376 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
378 static struct demangle_component
**
379 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
381 static struct demangle_component
*
382 d_function_type (struct d_info
*);
384 static struct demangle_component
*
385 d_bare_function_type (struct d_info
*, int);
387 static struct demangle_component
*
388 d_class_enum_type (struct d_info
*);
390 static struct demangle_component
*d_array_type (struct d_info
*);
392 static struct demangle_component
*d_vector_type (struct d_info
*);
394 static struct demangle_component
*
395 d_pointer_to_member_type (struct d_info
*);
397 static struct demangle_component
*
398 d_template_param (struct d_info
*);
400 static struct demangle_component
*d_template_args (struct d_info
*);
402 static struct demangle_component
*
403 d_template_arg (struct d_info
*);
405 static struct demangle_component
*d_expression (struct d_info
*);
407 static struct demangle_component
*d_expr_primary (struct d_info
*);
409 static struct demangle_component
*d_local_name (struct d_info
*);
411 static int d_discriminator (struct d_info
*);
413 static struct demangle_component
*d_lambda (struct d_info
*);
415 static struct demangle_component
*d_unnamed_type (struct d_info
*);
418 d_add_substitution (struct d_info
*, struct demangle_component
*);
420 static struct demangle_component
*d_substitution (struct d_info
*, int);
422 static void d_growable_string_init (struct d_growable_string
*, size_t);
425 d_growable_string_resize (struct d_growable_string
*, size_t);
428 d_growable_string_append_buffer (struct d_growable_string
*,
429 const char *, size_t);
431 d_growable_string_callback_adapter (const char *, size_t, void *);
434 d_print_init (struct d_print_info
*, int, demangle_callbackref
, void *);
436 static inline void d_print_error (struct d_print_info
*);
438 static inline int d_print_saw_error (struct d_print_info
*);
440 static inline void d_print_flush (struct d_print_info
*);
442 static inline void d_append_char (struct d_print_info
*, char);
444 static inline void d_append_buffer (struct d_print_info
*,
445 const char *, size_t);
447 static inline void d_append_string (struct d_print_info
*, const char *);
449 static inline char d_last_char (struct d_print_info
*);
452 d_print_comp (struct d_print_info
*, const struct demangle_component
*);
455 d_print_java_identifier (struct d_print_info
*, const char *, int);
458 d_print_mod_list (struct d_print_info
*, struct d_print_mod
*, int);
461 d_print_mod (struct d_print_info
*, const struct demangle_component
*);
464 d_print_function_type (struct d_print_info
*,
465 const struct demangle_component
*,
466 struct d_print_mod
*);
469 d_print_array_type (struct d_print_info
*,
470 const struct demangle_component
*,
471 struct d_print_mod
*);
474 d_print_expr_op (struct d_print_info
*, const struct demangle_component
*);
477 d_print_cast (struct d_print_info
*, const struct demangle_component
*);
479 static int d_demangle_callback (const char *, int,
480 demangle_callbackref
, void *);
481 static char *d_demangle (const char *, int, size_t *);
483 #ifdef CP_DEMANGLE_DEBUG
486 d_dump (struct demangle_component
*dc
, int indent
)
493 printf ("failed demangling\n");
497 for (i
= 0; i
< indent
; ++i
)
502 case DEMANGLE_COMPONENT_NAME
:
503 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
505 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
506 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
508 case DEMANGLE_COMPONENT_CTOR
:
509 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
510 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
512 case DEMANGLE_COMPONENT_DTOR
:
513 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
514 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
516 case DEMANGLE_COMPONENT_SUB_STD
:
517 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
519 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
520 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
522 case DEMANGLE_COMPONENT_OPERATOR
:
523 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
525 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
526 printf ("extended operator with %d args\n",
527 dc
->u
.s_extended_operator
.args
);
528 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
531 case DEMANGLE_COMPONENT_QUAL_NAME
:
532 printf ("qualified name\n");
534 case DEMANGLE_COMPONENT_LOCAL_NAME
:
535 printf ("local name\n");
537 case DEMANGLE_COMPONENT_TYPED_NAME
:
538 printf ("typed name\n");
540 case DEMANGLE_COMPONENT_TEMPLATE
:
541 printf ("template\n");
543 case DEMANGLE_COMPONENT_VTABLE
:
546 case DEMANGLE_COMPONENT_VTT
:
549 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
550 printf ("construction vtable\n");
552 case DEMANGLE_COMPONENT_TYPEINFO
:
553 printf ("typeinfo\n");
555 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
556 printf ("typeinfo name\n");
558 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
559 printf ("typeinfo function\n");
561 case DEMANGLE_COMPONENT_THUNK
:
564 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
565 printf ("virtual thunk\n");
567 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
568 printf ("covariant thunk\n");
570 case DEMANGLE_COMPONENT_JAVA_CLASS
:
571 printf ("java class\n");
573 case DEMANGLE_COMPONENT_GUARD
:
576 case DEMANGLE_COMPONENT_REFTEMP
:
577 printf ("reference temporary\n");
579 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
580 printf ("hidden alias\n");
582 case DEMANGLE_COMPONENT_RESTRICT
:
583 printf ("restrict\n");
585 case DEMANGLE_COMPONENT_VOLATILE
:
586 printf ("volatile\n");
588 case DEMANGLE_COMPONENT_CONST
:
591 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
592 printf ("restrict this\n");
594 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
595 printf ("volatile this\n");
597 case DEMANGLE_COMPONENT_CONST_THIS
:
598 printf ("const this\n");
600 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
601 printf ("vendor type qualifier\n");
603 case DEMANGLE_COMPONENT_POINTER
:
604 printf ("pointer\n");
606 case DEMANGLE_COMPONENT_REFERENCE
:
607 printf ("reference\n");
609 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
610 printf ("rvalue reference\n");
612 case DEMANGLE_COMPONENT_COMPLEX
:
613 printf ("complex\n");
615 case DEMANGLE_COMPONENT_IMAGINARY
:
616 printf ("imaginary\n");
618 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
619 printf ("vendor type\n");
621 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
622 printf ("function type\n");
624 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
625 printf ("array type\n");
627 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
628 printf ("pointer to member type\n");
630 case DEMANGLE_COMPONENT_FIXED_TYPE
:
631 printf ("fixed-point type\n");
633 case DEMANGLE_COMPONENT_ARGLIST
:
634 printf ("argument list\n");
636 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
637 printf ("template argument list\n");
639 case DEMANGLE_COMPONENT_CAST
:
642 case DEMANGLE_COMPONENT_UNARY
:
643 printf ("unary operator\n");
645 case DEMANGLE_COMPONENT_BINARY
:
646 printf ("binary operator\n");
648 case DEMANGLE_COMPONENT_BINARY_ARGS
:
649 printf ("binary operator arguments\n");
651 case DEMANGLE_COMPONENT_TRINARY
:
652 printf ("trinary operator\n");
654 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
655 printf ("trinary operator arguments 1\n");
657 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
658 printf ("trinary operator arguments 1\n");
660 case DEMANGLE_COMPONENT_LITERAL
:
661 printf ("literal\n");
663 case DEMANGLE_COMPONENT_LITERAL_NEG
:
664 printf ("negative literal\n");
666 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
667 printf ("java resource\n");
669 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
670 printf ("compound name\n");
672 case DEMANGLE_COMPONENT_CHARACTER
:
673 printf ("character '%c'\n", dc
->u
.s_character
.character
);
675 case DEMANGLE_COMPONENT_DECLTYPE
:
676 printf ("decltype\n");
678 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
679 printf ("pack expansion\n");
683 d_dump (d_left (dc
), indent
+ 2);
684 d_dump (d_right (dc
), indent
+ 2);
687 #endif /* CP_DEMANGLE_DEBUG */
689 /* Fill in a DEMANGLE_COMPONENT_NAME. */
691 CP_STATIC_IF_GLIBCPP_V3
693 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
695 if (p
== NULL
|| s
== NULL
|| len
== 0)
697 p
->type
= DEMANGLE_COMPONENT_NAME
;
699 p
->u
.s_name
.len
= len
;
703 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
705 CP_STATIC_IF_GLIBCPP_V3
707 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
708 struct demangle_component
*name
)
710 if (p
== NULL
|| args
< 0 || name
== NULL
)
712 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
713 p
->u
.s_extended_operator
.args
= args
;
714 p
->u
.s_extended_operator
.name
= name
;
718 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
720 CP_STATIC_IF_GLIBCPP_V3
722 cplus_demangle_fill_ctor (struct demangle_component
*p
,
723 enum gnu_v3_ctor_kinds kind
,
724 struct demangle_component
*name
)
728 || (int) kind
< gnu_v3_complete_object_ctor
729 || (int) kind
> gnu_v3_complete_object_allocating_ctor
)
731 p
->type
= DEMANGLE_COMPONENT_CTOR
;
732 p
->u
.s_ctor
.kind
= kind
;
733 p
->u
.s_ctor
.name
= name
;
737 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
739 CP_STATIC_IF_GLIBCPP_V3
741 cplus_demangle_fill_dtor (struct demangle_component
*p
,
742 enum gnu_v3_dtor_kinds kind
,
743 struct demangle_component
*name
)
747 || (int) kind
< gnu_v3_deleting_dtor
748 || (int) kind
> gnu_v3_base_object_dtor
)
750 p
->type
= DEMANGLE_COMPONENT_DTOR
;
751 p
->u
.s_dtor
.kind
= kind
;
752 p
->u
.s_dtor
.name
= name
;
756 /* Add a new component. */
758 static struct demangle_component
*
759 d_make_empty (struct d_info
*di
)
761 struct demangle_component
*p
;
763 if (di
->next_comp
>= di
->num_comps
)
765 p
= &di
->comps
[di
->next_comp
];
770 /* Add a new generic component. */
772 static struct demangle_component
*
773 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
774 struct demangle_component
*left
,
775 struct demangle_component
*right
)
777 struct demangle_component
*p
;
779 /* We check for errors here. A typical error would be a NULL return
780 from a subroutine. We catch those here, and return NULL
784 /* These types require two parameters. */
785 case DEMANGLE_COMPONENT_QUAL_NAME
:
786 case DEMANGLE_COMPONENT_LOCAL_NAME
:
787 case DEMANGLE_COMPONENT_TYPED_NAME
:
788 case DEMANGLE_COMPONENT_TEMPLATE
:
789 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
790 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
791 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
792 case DEMANGLE_COMPONENT_UNARY
:
793 case DEMANGLE_COMPONENT_BINARY
:
794 case DEMANGLE_COMPONENT_BINARY_ARGS
:
795 case DEMANGLE_COMPONENT_TRINARY
:
796 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
797 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
798 case DEMANGLE_COMPONENT_LITERAL
:
799 case DEMANGLE_COMPONENT_LITERAL_NEG
:
800 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
801 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
802 if (left
== NULL
|| right
== NULL
)
806 /* These types only require one parameter. */
807 case DEMANGLE_COMPONENT_VTABLE
:
808 case DEMANGLE_COMPONENT_VTT
:
809 case DEMANGLE_COMPONENT_TYPEINFO
:
810 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
811 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
812 case DEMANGLE_COMPONENT_THUNK
:
813 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
814 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
815 case DEMANGLE_COMPONENT_JAVA_CLASS
:
816 case DEMANGLE_COMPONENT_GUARD
:
817 case DEMANGLE_COMPONENT_REFTEMP
:
818 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
819 case DEMANGLE_COMPONENT_POINTER
:
820 case DEMANGLE_COMPONENT_REFERENCE
:
821 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
822 case DEMANGLE_COMPONENT_COMPLEX
:
823 case DEMANGLE_COMPONENT_IMAGINARY
:
824 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
825 case DEMANGLE_COMPONENT_CAST
:
826 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
827 case DEMANGLE_COMPONENT_DECLTYPE
:
828 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
829 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
830 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
835 /* This needs a right parameter, but the left parameter can be
837 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
842 /* These are allowed to have no parameters--in some cases they
843 will be filled in later. */
844 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
845 case DEMANGLE_COMPONENT_RESTRICT
:
846 case DEMANGLE_COMPONENT_VOLATILE
:
847 case DEMANGLE_COMPONENT_CONST
:
848 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
849 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
850 case DEMANGLE_COMPONENT_CONST_THIS
:
851 case DEMANGLE_COMPONENT_ARGLIST
:
852 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
855 /* Other types should not be seen here. */
860 p
= d_make_empty (di
);
864 p
->u
.s_binary
.left
= left
;
865 p
->u
.s_binary
.right
= right
;
870 /* Add a new name component. */
872 static struct demangle_component
*
873 d_make_name (struct d_info
*di
, const char *s
, int len
)
875 struct demangle_component
*p
;
877 p
= d_make_empty (di
);
878 if (! cplus_demangle_fill_name (p
, s
, len
))
883 /* Add a new builtin type component. */
885 static struct demangle_component
*
886 d_make_builtin_type (struct d_info
*di
,
887 const struct demangle_builtin_type_info
*type
)
889 struct demangle_component
*p
;
893 p
= d_make_empty (di
);
896 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
897 p
->u
.s_builtin
.type
= type
;
902 /* Add a new operator component. */
904 static struct demangle_component
*
905 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
907 struct demangle_component
*p
;
909 p
= d_make_empty (di
);
912 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
913 p
->u
.s_operator
.op
= op
;
918 /* Add a new extended operator component. */
920 static struct demangle_component
*
921 d_make_extended_operator (struct d_info
*di
, int args
,
922 struct demangle_component
*name
)
924 struct demangle_component
*p
;
926 p
= d_make_empty (di
);
927 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
932 static struct demangle_component
*
933 d_make_default_arg (struct d_info
*di
, int num
,
934 struct demangle_component
*sub
)
936 struct demangle_component
*p
= d_make_empty (di
);
939 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
940 p
->u
.s_unary_num
.num
= num
;
941 p
->u
.s_unary_num
.sub
= sub
;
946 /* Add a new constructor component. */
948 static struct demangle_component
*
949 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
950 struct demangle_component
*name
)
952 struct demangle_component
*p
;
954 p
= d_make_empty (di
);
955 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
960 /* Add a new destructor component. */
962 static struct demangle_component
*
963 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
964 struct demangle_component
*name
)
966 struct demangle_component
*p
;
968 p
= d_make_empty (di
);
969 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
974 /* Add a new template parameter. */
976 static struct demangle_component
*
977 d_make_template_param (struct d_info
*di
, long i
)
979 struct demangle_component
*p
;
981 p
= d_make_empty (di
);
984 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
985 p
->u
.s_number
.number
= i
;
990 /* Add a new function parameter. */
992 static struct demangle_component
*
993 d_make_function_param (struct d_info
*di
, long i
)
995 struct demangle_component
*p
;
997 p
= d_make_empty (di
);
1000 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1001 p
->u
.s_number
.number
= i
;
1006 /* Add a new standard substitution component. */
1008 static struct demangle_component
*
1009 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1011 struct demangle_component
*p
;
1013 p
= d_make_empty (di
);
1016 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1017 p
->u
.s_string
.string
= name
;
1018 p
->u
.s_string
.len
= len
;
1023 /* <mangled-name> ::= _Z <encoding>
1025 TOP_LEVEL is non-zero when called at the top level. */
1027 CP_STATIC_IF_GLIBCPP_V3
1028 struct demangle_component
*
1029 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1031 if (! d_check_char (di
, '_')
1032 /* Allow missing _ if not at toplevel to work around a
1033 bug in G++ abi-version=2 mangling; see the comment in
1034 write_template_arg. */
1037 if (! d_check_char (di
, 'Z'))
1039 return d_encoding (di
, top_level
);
1042 /* Return whether a function should have a return type. The argument
1043 is the function name, which may be qualified in various ways. The
1044 rules are that template functions have return types with some
1045 exceptions, function types which are not part of a function name
1046 mangling have return types with some exceptions, and non-template
1047 function names do not have return types. The exceptions are that
1048 constructors, destructors, and conversion operators do not have
1052 has_return_type (struct demangle_component
*dc
)
1060 case DEMANGLE_COMPONENT_TEMPLATE
:
1061 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1062 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1063 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1064 case DEMANGLE_COMPONENT_CONST_THIS
:
1065 return has_return_type (d_left (dc
));
1069 /* Return whether a name is a constructor, a destructor, or a
1070 conversion operator. */
1073 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1081 case DEMANGLE_COMPONENT_QUAL_NAME
:
1082 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1083 return is_ctor_dtor_or_conversion (d_right (dc
));
1084 case DEMANGLE_COMPONENT_CTOR
:
1085 case DEMANGLE_COMPONENT_DTOR
:
1086 case DEMANGLE_COMPONENT_CAST
:
1091 /* <encoding> ::= <(function) name> <bare-function-type>
1095 TOP_LEVEL is non-zero when called at the top level, in which case
1096 if DMGL_PARAMS is not set we do not demangle the function
1097 parameters. We only set this at the top level, because otherwise
1098 we would not correctly demangle names in local scopes. */
1100 static struct demangle_component
*
1101 d_encoding (struct d_info
*di
, int top_level
)
1103 char peek
= d_peek_char (di
);
1105 if (peek
== 'G' || peek
== 'T')
1106 return d_special_name (di
);
1109 struct demangle_component
*dc
;
1113 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1115 /* Strip off any initial CV-qualifiers, as they really apply
1116 to the `this' parameter, and they were not output by the
1117 v2 demangler without DMGL_PARAMS. */
1118 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1119 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1120 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1123 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1124 there may be CV-qualifiers on its right argument which
1125 really apply here; this happens when parsing a class
1126 which is local to a function. */
1127 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1129 struct demangle_component
*dcr
;
1132 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1133 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1134 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1136 dc
->u
.s_binary
.right
= dcr
;
1142 peek
= d_peek_char (di
);
1143 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1145 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1146 d_bare_function_type (di
, has_return_type (dc
)));
1150 /* <name> ::= <nested-name>
1152 ::= <unscoped-template-name> <template-args>
1155 <unscoped-name> ::= <unqualified-name>
1156 ::= St <unqualified-name>
1158 <unscoped-template-name> ::= <unscoped-name>
1162 static struct demangle_component
*
1163 d_name (struct d_info
*di
)
1165 char peek
= d_peek_char (di
);
1166 struct demangle_component
*dc
;
1171 return d_nested_name (di
);
1174 return d_local_name (di
);
1178 return d_unqualified_name (di
);
1184 if (d_peek_next_char (di
) != 't')
1186 dc
= d_substitution (di
, 0);
1192 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1193 d_make_name (di
, "std", 3),
1194 d_unqualified_name (di
));
1199 if (d_peek_char (di
) != 'I')
1201 /* The grammar does not permit this case to occur if we
1202 called d_substitution() above (i.e., subst == 1). We
1203 don't bother to check. */
1207 /* This is <template-args>, which means that we just saw
1208 <unscoped-template-name>, which is a substitution
1209 candidate if we didn't just get it from a
1213 if (! d_add_substitution (di
, dc
))
1216 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1217 d_template_args (di
));
1224 dc
= d_unqualified_name (di
);
1225 if (d_peek_char (di
) == 'I')
1227 /* This is <template-args>, which means that we just saw
1228 <unscoped-template-name>, which is a substitution
1230 if (! d_add_substitution (di
, dc
))
1232 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1233 d_template_args (di
));
1239 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1240 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1243 static struct demangle_component
*
1244 d_nested_name (struct d_info
*di
)
1246 struct demangle_component
*ret
;
1247 struct demangle_component
**pret
;
1249 if (! d_check_char (di
, 'N'))
1252 pret
= d_cv_qualifiers (di
, &ret
, 1);
1256 *pret
= d_prefix (di
);
1260 if (! d_check_char (di
, 'E'))
1266 /* <prefix> ::= <prefix> <unqualified-name>
1267 ::= <template-prefix> <template-args>
1268 ::= <template-param>
1272 <template-prefix> ::= <prefix> <(template) unqualified-name>
1273 ::= <template-param>
1277 static struct demangle_component
*
1278 d_prefix (struct d_info
*di
)
1280 struct demangle_component
*ret
= NULL
;
1285 enum demangle_component_type comb_type
;
1286 struct demangle_component
*dc
;
1288 peek
= d_peek_char (di
);
1292 /* The older code accepts a <local-name> here, but I don't see
1293 that in the grammar. The older code does not accept a
1294 <template-param> here. */
1296 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1303 dc
= d_unqualified_name (di
);
1304 else if (peek
== 'S')
1305 dc
= d_substitution (di
, 1);
1306 else if (peek
== 'I')
1310 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1311 dc
= d_template_args (di
);
1313 else if (peek
== 'T')
1314 dc
= d_template_param (di
);
1315 else if (peek
== 'E')
1317 else if (peek
== 'M')
1319 /* Initializer scope for a lambda. We don't need to represent
1320 this; the normal code will just treat the variable as a type
1321 scope, which gives appropriate output. */
1333 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1335 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1337 if (! d_add_substitution (di
, ret
))
1343 /* <unqualified-name> ::= <operator-name>
1344 ::= <ctor-dtor-name>
1346 ::= <local-source-name>
1348 <local-source-name> ::= L <source-name> <discriminator>
1351 static struct demangle_component
*
1352 d_unqualified_name (struct d_info
*di
)
1356 peek
= d_peek_char (di
);
1357 if (IS_DIGIT (peek
))
1358 return d_source_name (di
);
1359 else if (IS_LOWER (peek
))
1361 struct demangle_component
*ret
;
1363 ret
= d_operator_name (di
);
1364 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1365 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1368 else if (peek
== 'C' || peek
== 'D')
1369 return d_ctor_dtor_name (di
);
1370 else if (peek
== 'L')
1372 struct demangle_component
* ret
;
1376 ret
= d_source_name (di
);
1379 if (! d_discriminator (di
))
1383 else if (peek
== 'U')
1385 switch (d_peek_next_char (di
))
1388 return d_lambda (di
);
1390 return d_unnamed_type (di
);
1399 /* <source-name> ::= <(positive length) number> <identifier> */
1401 static struct demangle_component
*
1402 d_source_name (struct d_info
*di
)
1405 struct demangle_component
*ret
;
1407 len
= d_number (di
);
1410 ret
= d_identifier (di
, len
);
1411 di
->last_name
= ret
;
1415 /* number ::= [n] <(non-negative decimal integer)> */
1418 d_number (struct d_info
*di
)
1425 peek
= d_peek_char (di
);
1430 peek
= d_peek_char (di
);
1436 if (! IS_DIGIT (peek
))
1442 ret
= ret
* 10 + peek
- '0';
1444 peek
= d_peek_char (di
);
1448 /* Like d_number, but returns a demangle_component. */
1450 static struct demangle_component
*
1451 d_number_component (struct d_info
*di
)
1453 struct demangle_component
*ret
= d_make_empty (di
);
1456 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1457 ret
->u
.s_number
.number
= d_number (di
);
1462 /* identifier ::= <(unqualified source code identifier)> */
1464 static struct demangle_component
*
1465 d_identifier (struct d_info
*di
, int len
)
1471 if (di
->send
- name
< len
)
1474 d_advance (di
, len
);
1476 /* A Java mangled name may have a trailing '$' if it is a C++
1477 keyword. This '$' is not included in the length count. We just
1479 if ((di
->options
& DMGL_JAVA
) != 0
1480 && d_peek_char (di
) == '$')
1483 /* Look for something which looks like a gcc encoding of an
1484 anonymous namespace, and replace it with a more user friendly
1486 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1487 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1488 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1492 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1493 if ((*s
== '.' || *s
== '_' || *s
== '$')
1496 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1497 return d_make_name (di
, "(anonymous namespace)",
1498 sizeof "(anonymous namespace)" - 1);
1502 return d_make_name (di
, name
, len
);
1505 /* operator_name ::= many different two character encodings.
1507 ::= v <digit> <source-name>
1510 #define NL(s) s, (sizeof s) - 1
1512 CP_STATIC_IF_GLIBCPP_V3
1513 const struct demangle_operator_info cplus_demangle_operators
[] =
1515 { "aN", NL ("&="), 2 },
1516 { "aS", NL ("="), 2 },
1517 { "aa", NL ("&&"), 2 },
1518 { "ad", NL ("&"), 1 },
1519 { "an", NL ("&"), 2 },
1520 { "cl", NL ("()"), 2 },
1521 { "cm", NL (","), 2 },
1522 { "co", NL ("~"), 1 },
1523 { "dV", NL ("/="), 2 },
1524 { "da", NL ("delete[]"), 1 },
1525 { "de", NL ("*"), 1 },
1526 { "dl", NL ("delete"), 1 },
1527 { "dt", NL ("."), 2 },
1528 { "dv", NL ("/"), 2 },
1529 { "eO", NL ("^="), 2 },
1530 { "eo", NL ("^"), 2 },
1531 { "eq", NL ("=="), 2 },
1532 { "ge", NL (">="), 2 },
1533 { "gt", NL (">"), 2 },
1534 { "ix", NL ("[]"), 2 },
1535 { "lS", NL ("<<="), 2 },
1536 { "le", NL ("<="), 2 },
1537 { "ls", NL ("<<"), 2 },
1538 { "lt", NL ("<"), 2 },
1539 { "mI", NL ("-="), 2 },
1540 { "mL", NL ("*="), 2 },
1541 { "mi", NL ("-"), 2 },
1542 { "ml", NL ("*"), 2 },
1543 { "mm", NL ("--"), 1 },
1544 { "na", NL ("new[]"), 1 },
1545 { "ne", NL ("!="), 2 },
1546 { "ng", NL ("-"), 1 },
1547 { "nt", NL ("!"), 1 },
1548 { "nw", NL ("new"), 1 },
1549 { "oR", NL ("|="), 2 },
1550 { "oo", NL ("||"), 2 },
1551 { "or", NL ("|"), 2 },
1552 { "pL", NL ("+="), 2 },
1553 { "pl", NL ("+"), 2 },
1554 { "pm", NL ("->*"), 2 },
1555 { "pp", NL ("++"), 1 },
1556 { "ps", NL ("+"), 1 },
1557 { "pt", NL ("->"), 2 },
1558 { "qu", NL ("?"), 3 },
1559 { "rM", NL ("%="), 2 },
1560 { "rS", NL (">>="), 2 },
1561 { "rm", NL ("%"), 2 },
1562 { "rs", NL (">>"), 2 },
1563 { "st", NL ("sizeof "), 1 },
1564 { "sz", NL ("sizeof "), 1 },
1565 { "at", NL ("alignof "), 1 },
1566 { "az", NL ("alignof "), 1 },
1567 { NULL
, NULL
, 0, 0 }
1570 static struct demangle_component
*
1571 d_operator_name (struct d_info
*di
)
1576 c1
= d_next_char (di
);
1577 c2
= d_next_char (di
);
1578 if (c1
== 'v' && IS_DIGIT (c2
))
1579 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1580 else if (c1
== 'c' && c2
== 'v')
1581 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1582 cplus_demangle_type (di
), NULL
);
1585 /* LOW is the inclusive lower bound. */
1587 /* HIGH is the exclusive upper bound. We subtract one to ignore
1588 the sentinel at the end of the array. */
1589 int high
= ((sizeof (cplus_demangle_operators
)
1590 / sizeof (cplus_demangle_operators
[0]))
1596 const struct demangle_operator_info
*p
;
1598 i
= low
+ (high
- low
) / 2;
1599 p
= cplus_demangle_operators
+ i
;
1601 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1602 return d_make_operator (di
, p
);
1604 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1614 static struct demangle_component
*
1615 d_make_character (struct d_info
*di
, int c
)
1617 struct demangle_component
*p
;
1618 p
= d_make_empty (di
);
1621 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1622 p
->u
.s_character
.character
= c
;
1627 static struct demangle_component
*
1628 d_java_resource (struct d_info
*di
)
1630 struct demangle_component
*p
= NULL
;
1631 struct demangle_component
*next
= NULL
;
1636 len
= d_number (di
);
1640 /* Eat the leading '_'. */
1641 if (d_next_char (di
) != '_')
1654 /* Each chunk is either a '$' escape... */
1672 next
= d_make_character (di
, c
);
1680 /* ... or a sequence of characters. */
1683 while (i
< len
&& str
[i
] && str
[i
] != '$')
1686 next
= d_make_name (di
, str
, i
);
1699 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1705 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1710 /* <special-name> ::= TV <type>
1714 ::= GV <(object) name>
1715 ::= T <call-offset> <(base) encoding>
1716 ::= Tc <call-offset> <call-offset> <(base) encoding>
1717 Also g++ extensions:
1718 ::= TC <type> <(offset) number> _ <(base) type>
1723 ::= Gr <resource name>
1726 static struct demangle_component
*
1727 d_special_name (struct d_info
*di
)
1729 di
->expansion
+= 20;
1730 if (d_check_char (di
, 'T'))
1732 switch (d_next_char (di
))
1736 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1737 cplus_demangle_type (di
), NULL
);
1739 di
->expansion
-= 10;
1740 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1741 cplus_demangle_type (di
), NULL
);
1743 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1744 cplus_demangle_type (di
), NULL
);
1746 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1747 cplus_demangle_type (di
), NULL
);
1750 if (! d_call_offset (di
, 'h'))
1752 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1753 d_encoding (di
, 0), NULL
);
1756 if (! d_call_offset (di
, 'v'))
1758 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1759 d_encoding (di
, 0), NULL
);
1762 if (! d_call_offset (di
, '\0'))
1764 if (! d_call_offset (di
, '\0'))
1766 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1767 d_encoding (di
, 0), NULL
);
1771 struct demangle_component
*derived_type
;
1773 struct demangle_component
*base_type
;
1775 derived_type
= cplus_demangle_type (di
);
1776 offset
= d_number (di
);
1779 if (! d_check_char (di
, '_'))
1781 base_type
= cplus_demangle_type (di
);
1782 /* We don't display the offset. FIXME: We should display
1783 it in verbose mode. */
1785 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1786 base_type
, derived_type
);
1790 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1791 cplus_demangle_type (di
), NULL
);
1793 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1794 cplus_demangle_type (di
), NULL
);
1800 else if (d_check_char (di
, 'G'))
1802 switch (d_next_char (di
))
1805 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1808 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, d_name (di
),
1812 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1813 d_encoding (di
, 0), NULL
);
1816 return d_java_resource (di
);
1826 /* <call-offset> ::= h <nv-offset> _
1829 <nv-offset> ::= <(offset) number>
1831 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1833 The C parameter, if not '\0', is a character we just read which is
1834 the start of the <call-offset>.
1836 We don't display the offset information anywhere. FIXME: We should
1837 display it in verbose mode. */
1840 d_call_offset (struct d_info
*di
, int c
)
1843 c
= d_next_char (di
);
1850 if (! d_check_char (di
, '_'))
1857 if (! d_check_char (di
, '_'))
1863 /* <ctor-dtor-name> ::= C1
1871 static struct demangle_component
*
1872 d_ctor_dtor_name (struct d_info
*di
)
1874 if (di
->last_name
!= NULL
)
1876 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1877 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1878 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1879 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1881 switch (d_peek_char (di
))
1885 enum gnu_v3_ctor_kinds kind
;
1887 switch (d_peek_next_char (di
))
1890 kind
= gnu_v3_complete_object_ctor
;
1893 kind
= gnu_v3_base_object_ctor
;
1896 kind
= gnu_v3_complete_object_allocating_ctor
;
1902 return d_make_ctor (di
, kind
, di
->last_name
);
1907 enum gnu_v3_dtor_kinds kind
;
1909 switch (d_peek_next_char (di
))
1912 kind
= gnu_v3_deleting_dtor
;
1915 kind
= gnu_v3_complete_object_dtor
;
1918 kind
= gnu_v3_base_object_dtor
;
1924 return d_make_dtor (di
, kind
, di
->last_name
);
1932 /* <type> ::= <builtin-type>
1934 ::= <class-enum-type>
1936 ::= <pointer-to-member-type>
1937 ::= <template-param>
1938 ::= <template-template-param> <template-args>
1940 ::= <CV-qualifiers> <type>
1943 ::= O <type> (C++0x)
1946 ::= U <source-name> <type>
1948 <builtin-type> ::= various one letter codes
1952 CP_STATIC_IF_GLIBCPP_V3
1953 const struct demangle_builtin_type_info
1954 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
1956 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
1957 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
1958 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
1959 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
1960 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
1961 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
1962 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
1963 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
1964 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
1965 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
1966 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1967 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
1968 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
1969 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
1970 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
1972 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1973 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1974 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1975 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
1976 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
1977 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1978 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
1979 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
1980 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
1981 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
1982 D_PRINT_UNSIGNED_LONG_LONG
},
1983 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
1984 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
1985 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
1986 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
1987 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
1988 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
1989 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
1990 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
1994 CP_STATIC_IF_GLIBCPP_V3
1995 struct demangle_component
*
1996 cplus_demangle_type (struct d_info
*di
)
1999 struct demangle_component
*ret
;
2002 /* The ABI specifies that when CV-qualifiers are used, the base type
2003 is substitutable, and the fully qualified type is substitutable,
2004 but the base type with a strict subset of the CV-qualifiers is
2005 not substitutable. The natural recursive implementation of the
2006 CV-qualifiers would cause subsets to be substitutable, so instead
2007 we pull them all off now.
2009 FIXME: The ABI says that order-insensitive vendor qualifiers
2010 should be handled in the same way, but we have no way to tell
2011 which vendor qualifiers are order-insensitive and which are
2012 order-sensitive. So we just assume that they are all
2013 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2014 __vector, and it treats it as order-sensitive when mangling
2017 peek
= d_peek_char (di
);
2018 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2020 struct demangle_component
**pret
;
2022 pret
= d_cv_qualifiers (di
, &ret
, 0);
2025 *pret
= cplus_demangle_type (di
);
2026 if (! *pret
|| ! d_add_substitution (di
, ret
))
2035 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2036 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2037 case 'o': case 's': case 't':
2038 case 'v': case 'w': case 'x': case 'y': case 'z':
2039 ret
= d_make_builtin_type (di
,
2040 &cplus_demangle_builtin_types
[peek
- 'a']);
2041 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2048 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2049 d_source_name (di
), NULL
);
2053 ret
= d_function_type (di
);
2056 case '0': case '1': case '2': case '3': case '4':
2057 case '5': case '6': case '7': case '8': case '9':
2060 ret
= d_class_enum_type (di
);
2064 ret
= d_array_type (di
);
2068 ret
= d_pointer_to_member_type (di
);
2072 ret
= d_template_param (di
);
2073 if (d_peek_char (di
) == 'I')
2075 /* This is <template-template-param> <template-args>. The
2076 <template-template-param> part is a substitution
2078 if (! d_add_substitution (di
, ret
))
2080 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2081 d_template_args (di
));
2086 /* If this is a special substitution, then it is the start of
2087 <class-enum-type>. */
2091 peek_next
= d_peek_next_char (di
);
2092 if (IS_DIGIT (peek_next
)
2094 || IS_UPPER (peek_next
))
2096 ret
= d_substitution (di
, 0);
2097 /* The substituted name may have been a template name and
2098 may be followed by tepmlate args. */
2099 if (d_peek_char (di
) == 'I')
2100 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2101 d_template_args (di
));
2107 ret
= d_class_enum_type (di
);
2108 /* If the substitution was a complete type, then it is not
2109 a new substitution candidate. However, if the
2110 substitution was followed by template arguments, then
2111 the whole thing is a substitution candidate. */
2112 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2120 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2121 cplus_demangle_type (di
), NULL
);
2126 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2127 cplus_demangle_type (di
), NULL
);
2132 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2133 cplus_demangle_type (di
), NULL
);
2138 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2139 cplus_demangle_type (di
), NULL
);
2144 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2145 cplus_demangle_type (di
), NULL
);
2150 ret
= d_source_name (di
);
2151 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2152 cplus_demangle_type (di
), ret
);
2158 peek
= d_next_char (di
);
2163 /* decltype (expression) */
2164 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2165 d_expression (di
), NULL
);
2166 if (ret
&& d_next_char (di
) != 'E')
2171 /* Pack expansion. */
2172 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2173 cplus_demangle_type (di
), NULL
);
2177 /* 32-bit decimal floating point */
2178 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2179 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2183 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2184 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2188 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2189 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2192 /* 16-bit half-precision FP */
2193 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2194 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2198 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2199 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2203 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2204 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2208 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2209 ret
= d_make_empty (di
);
2210 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2211 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2212 /* For demangling we don't care about the bits. */
2214 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2215 if (ret
->u
.s_fixed
.length
== NULL
)
2218 peek
= d_next_char (di
);
2219 ret
->u
.s_fixed
.sat
= (peek
== 's');
2223 ret
= d_vector_type (di
);
2227 /* decltype(nullptr) */
2228 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2229 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2243 if (! d_add_substitution (di
, ret
))
2250 /* <CV-qualifiers> ::= [r] [V] [K] */
2252 static struct demangle_component
**
2253 d_cv_qualifiers (struct d_info
*di
,
2254 struct demangle_component
**pret
, int member_fn
)
2258 peek
= d_peek_char (di
);
2259 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2261 enum demangle_component_type t
;
2267 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2268 : DEMANGLE_COMPONENT_RESTRICT
);
2269 di
->expansion
+= sizeof "restrict";
2271 else if (peek
== 'V')
2274 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2275 : DEMANGLE_COMPONENT_VOLATILE
);
2276 di
->expansion
+= sizeof "volatile";
2281 ? DEMANGLE_COMPONENT_CONST_THIS
2282 : DEMANGLE_COMPONENT_CONST
);
2283 di
->expansion
+= sizeof "const";
2286 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2289 pret
= &d_left (*pret
);
2291 peek
= d_peek_char (di
);
2297 /* <function-type> ::= F [Y] <bare-function-type> E */
2299 static struct demangle_component
*
2300 d_function_type (struct d_info
*di
)
2302 struct demangle_component
*ret
;
2304 if (! d_check_char (di
, 'F'))
2306 if (d_peek_char (di
) == 'Y')
2308 /* Function has C linkage. We don't print this information.
2309 FIXME: We should print it in verbose mode. */
2312 ret
= d_bare_function_type (di
, 1);
2313 if (! d_check_char (di
, 'E'))
2320 static struct demangle_component
*
2321 d_parmlist (struct d_info
*di
)
2323 struct demangle_component
*tl
;
2324 struct demangle_component
**ptl
;
2330 struct demangle_component
*type
;
2332 char peek
= d_peek_char (di
);
2333 if (peek
== '\0' || peek
== 'E')
2335 type
= cplus_demangle_type (di
);
2338 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2341 ptl
= &d_right (*ptl
);
2344 /* There should be at least one parameter type besides the optional
2345 return type. A function which takes no arguments will have a
2346 single parameter type void. */
2350 /* If we have a single parameter type void, omit it. */
2351 if (d_right (tl
) == NULL
2352 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2353 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2355 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2362 /* <bare-function-type> ::= [J]<type>+ */
2364 static struct demangle_component
*
2365 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2367 struct demangle_component
*return_type
;
2368 struct demangle_component
*tl
;
2371 /* Detect special qualifier indicating that the first argument
2372 is the return type. */
2373 peek
= d_peek_char (di
);
2377 has_return_type
= 1;
2380 if (has_return_type
)
2382 return_type
= cplus_demangle_type (di
);
2383 if (return_type
== NULL
)
2389 tl
= d_parmlist (di
);
2393 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2397 /* <class-enum-type> ::= <name> */
2399 static struct demangle_component
*
2400 d_class_enum_type (struct d_info
*di
)
2405 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2406 ::= A [<(dimension) expression>] _ <(element) type>
2409 static struct demangle_component
*
2410 d_array_type (struct d_info
*di
)
2413 struct demangle_component
*dim
;
2415 if (! d_check_char (di
, 'A'))
2418 peek
= d_peek_char (di
);
2421 else if (IS_DIGIT (peek
))
2429 peek
= d_peek_char (di
);
2431 while (IS_DIGIT (peek
));
2432 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2438 dim
= d_expression (di
);
2443 if (! d_check_char (di
, '_'))
2446 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2447 cplus_demangle_type (di
));
2450 /* <vector-type> ::= Dv <number> _ <type>
2451 ::= Dv _ <expression> _ <type> */
2453 static struct demangle_component
*
2454 d_vector_type (struct d_info
*di
)
2457 struct demangle_component
*dim
;
2459 peek
= d_peek_char (di
);
2463 dim
= d_expression (di
);
2466 dim
= d_number_component (di
);
2471 if (! d_check_char (di
, '_'))
2474 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2475 cplus_demangle_type (di
));
2478 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2480 static struct demangle_component
*
2481 d_pointer_to_member_type (struct d_info
*di
)
2483 struct demangle_component
*cl
;
2484 struct demangle_component
*mem
;
2485 struct demangle_component
**pmem
;
2487 if (! d_check_char (di
, 'M'))
2490 cl
= cplus_demangle_type (di
);
2492 /* The ABI specifies that any type can be a substitution source, and
2493 that M is followed by two types, and that when a CV-qualified
2494 type is seen both the base type and the CV-qualified types are
2495 substitution sources. The ABI also specifies that for a pointer
2496 to a CV-qualified member function, the qualifiers are attached to
2497 the second type. Given the grammar, a plain reading of the ABI
2498 suggests that both the CV-qualified member function and the
2499 non-qualified member function are substitution sources. However,
2500 g++ does not work that way. g++ treats only the CV-qualified
2501 member function as a substitution source. FIXME. So to work
2502 with g++, we need to pull off the CV-qualifiers here, in order to
2503 avoid calling add_substitution() in cplus_demangle_type(). But
2504 for a CV-qualified member which is not a function, g++ does
2505 follow the ABI, so we need to handle that case here by calling
2506 d_add_substitution ourselves. */
2508 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2511 *pmem
= cplus_demangle_type (di
);
2515 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2517 if (! d_add_substitution (di
, mem
))
2521 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2524 /* <non-negative number> _ */
2527 d_compact_number (struct d_info
*di
)
2530 if (d_peek_char (di
) == '_')
2532 else if (d_peek_char (di
) == 'n')
2535 num
= d_number (di
) + 1;
2537 if (! d_check_char (di
, '_'))
2542 /* <template-param> ::= T_
2543 ::= T <(parameter-2 non-negative) number> _
2546 static struct demangle_component
*
2547 d_template_param (struct d_info
*di
)
2551 if (! d_check_char (di
, 'T'))
2554 param
= d_compact_number (di
);
2560 return d_make_template_param (di
, param
);
2563 /* <template-args> ::= I <template-arg>+ E */
2565 static struct demangle_component
*
2566 d_template_args (struct d_info
*di
)
2568 struct demangle_component
*hold_last_name
;
2569 struct demangle_component
*al
;
2570 struct demangle_component
**pal
;
2572 /* Preserve the last name we saw--don't let the template arguments
2573 clobber it, as that would give us the wrong name for a subsequent
2574 constructor or destructor. */
2575 hold_last_name
= di
->last_name
;
2577 if (! d_check_char (di
, 'I'))
2580 if (d_peek_char (di
) == 'E')
2582 /* An argument pack can be empty. */
2584 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2591 struct demangle_component
*a
;
2593 a
= d_template_arg (di
);
2597 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2600 pal
= &d_right (*pal
);
2602 if (d_peek_char (di
) == 'E')
2609 di
->last_name
= hold_last_name
;
2614 /* <template-arg> ::= <type>
2615 ::= X <expression> E
2619 static struct demangle_component
*
2620 d_template_arg (struct d_info
*di
)
2622 struct demangle_component
*ret
;
2624 switch (d_peek_char (di
))
2628 ret
= d_expression (di
);
2629 if (! d_check_char (di
, 'E'))
2634 return d_expr_primary (di
);
2637 /* An argument pack. */
2638 return d_template_args (di
);
2641 return cplus_demangle_type (di
);
2645 /* Subroutine of <expression> ::= cl <expression>+ E */
2647 static struct demangle_component
*
2648 d_exprlist (struct d_info
*di
)
2650 struct demangle_component
*list
= NULL
;
2651 struct demangle_component
**p
= &list
;
2653 if (d_peek_char (di
) == 'E')
2656 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2661 struct demangle_component
*arg
= d_expression (di
);
2665 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2670 if (d_peek_char (di
) == 'E')
2680 /* <expression> ::= <(unary) operator-name> <expression>
2681 ::= <(binary) operator-name> <expression> <expression>
2682 ::= <(trinary) operator-name> <expression> <expression> <expression>
2683 ::= cl <expression>+ E
2685 ::= <template-param>
2686 ::= sr <type> <unqualified-name>
2687 ::= sr <type> <unqualified-name> <template-args>
2691 static struct demangle_component
*
2692 d_expression (struct d_info
*di
)
2696 peek
= d_peek_char (di
);
2698 return d_expr_primary (di
);
2699 else if (peek
== 'T')
2700 return d_template_param (di
);
2701 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2703 struct demangle_component
*type
;
2704 struct demangle_component
*name
;
2707 type
= cplus_demangle_type (di
);
2708 name
= d_unqualified_name (di
);
2709 if (d_peek_char (di
) != 'I')
2710 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2712 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2713 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2714 d_template_args (di
)));
2716 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
2719 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2720 d_expression (di
), NULL
);
2722 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
2724 /* Function parameter used in a late-specified return type. */
2727 index
= d_compact_number (di
);
2731 return d_make_function_param (di
, index
);
2733 else if (IS_DIGIT (peek
)
2734 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
2736 /* We can get an unqualified name as an expression in the case of
2737 a dependent function call, i.e. decltype(f(t)). */
2738 struct demangle_component
*name
;
2741 /* operator-function-id, i.e. operator+(t). */
2744 name
= d_unqualified_name (di
);
2747 if (d_peek_char (di
) == 'I')
2748 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2749 d_template_args (di
));
2755 struct demangle_component
*op
;
2758 op
= d_operator_name (di
);
2762 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2763 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2765 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2766 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2767 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2768 cplus_demangle_type (di
));
2774 case DEMANGLE_COMPONENT_OPERATOR
:
2775 args
= op
->u
.s_operator
.op
->args
;
2777 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2778 args
= op
->u
.s_extended_operator
.args
;
2780 case DEMANGLE_COMPONENT_CAST
:
2789 struct demangle_component
*operand
;
2790 if (op
->type
== DEMANGLE_COMPONENT_CAST
2791 && d_check_char (di
, '_'))
2792 operand
= d_exprlist (di
);
2794 operand
= d_expression (di
);
2795 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2800 struct demangle_component
*left
;
2801 struct demangle_component
*right
;
2802 const char *code
= op
->u
.s_operator
.op
->code
;
2804 left
= d_expression (di
);
2805 if (!strcmp (code
, "cl"))
2806 right
= d_exprlist (di
);
2807 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
2809 right
= d_unqualified_name (di
);
2810 if (d_peek_char (di
) == 'I')
2811 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
2812 right
, d_template_args (di
));
2815 right
= d_expression (di
);
2817 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2819 DEMANGLE_COMPONENT_BINARY_ARGS
,
2824 struct demangle_component
*first
;
2825 struct demangle_component
*second
;
2827 first
= d_expression (di
);
2828 second
= d_expression (di
);
2829 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2831 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2834 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2836 d_expression (di
))));
2844 /* <expr-primary> ::= L <type> <(value) number> E
2845 ::= L <type> <(value) float> E
2846 ::= L <mangled-name> E
2849 static struct demangle_component
*
2850 d_expr_primary (struct d_info
*di
)
2852 struct demangle_component
*ret
;
2854 if (! d_check_char (di
, 'L'))
2856 if (d_peek_char (di
) == '_'
2857 /* Workaround for G++ bug; see comment in write_template_arg. */
2858 || d_peek_char (di
) == 'Z')
2859 ret
= cplus_demangle_mangled_name (di
, 0);
2862 struct demangle_component
*type
;
2863 enum demangle_component_type t
;
2866 type
= cplus_demangle_type (di
);
2870 /* If we have a type we know how to print, we aren't going to
2871 print the type name itself. */
2872 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2873 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2874 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2876 /* Rather than try to interpret the literal value, we just
2877 collect it as a string. Note that it's possible to have a
2878 floating point literal here. The ABI specifies that the
2879 format of such literals is machine independent. That's fine,
2880 but what's not fine is that versions of g++ up to 3.2 with
2881 -fabi-version=1 used upper case letters in the hex constant,
2882 and dumped out gcc's internal representation. That makes it
2883 hard to tell where the constant ends, and hard to dump the
2884 constant in any readable form anyhow. We don't attempt to
2885 handle these cases. */
2887 t
= DEMANGLE_COMPONENT_LITERAL
;
2888 if (d_peek_char (di
) == 'n')
2890 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2894 while (d_peek_char (di
) != 'E')
2896 if (d_peek_char (di
) == '\0')
2900 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2902 if (! d_check_char (di
, 'E'))
2907 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2908 ::= Z <(function) encoding> E s [<discriminator>]
2911 static struct demangle_component
*
2912 d_local_name (struct d_info
*di
)
2914 struct demangle_component
*function
;
2916 if (! d_check_char (di
, 'Z'))
2919 function
= d_encoding (di
, 0);
2921 if (! d_check_char (di
, 'E'))
2924 if (d_peek_char (di
) == 's')
2927 if (! d_discriminator (di
))
2929 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
2930 d_make_name (di
, "string literal",
2931 sizeof "string literal" - 1));
2935 struct demangle_component
*name
;
2938 if (d_peek_char (di
) == 'd')
2940 /* Default argument scope: d <number> _. */
2942 num
= d_compact_number (di
);
2951 /* Lambdas and unnamed types have internal discriminators. */
2952 case DEMANGLE_COMPONENT_LAMBDA
:
2953 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
2956 if (! d_discriminator (di
))
2960 name
= d_make_default_arg (di
, num
, name
);
2961 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
2965 /* <discriminator> ::= _ <(non-negative) number>
2967 We demangle the discriminator, but we don't print it out. FIXME:
2968 We should print it out in verbose mode. */
2971 d_discriminator (struct d_info
*di
)
2975 if (d_peek_char (di
) != '_')
2978 discrim
= d_number (di
);
2984 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
2986 static struct demangle_component
*
2987 d_lambda (struct d_info
*di
)
2989 struct demangle_component
*tl
;
2990 struct demangle_component
*ret
;
2993 if (! d_check_char (di
, 'U'))
2995 if (! d_check_char (di
, 'l'))
2998 tl
= d_parmlist (di
);
3002 if (! d_check_char (di
, 'E'))
3005 num
= d_compact_number (di
);
3009 ret
= d_make_empty (di
);
3012 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3013 ret
->u
.s_unary_num
.sub
= tl
;
3014 ret
->u
.s_unary_num
.num
= num
;
3017 if (! d_add_substitution (di
, ret
))
3023 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3025 static struct demangle_component
*
3026 d_unnamed_type (struct d_info
*di
)
3028 struct demangle_component
*ret
;
3031 if (! d_check_char (di
, 'U'))
3033 if (! d_check_char (di
, 't'))
3036 num
= d_compact_number (di
);
3040 ret
= d_make_empty (di
);
3043 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3044 ret
->u
.s_number
.number
= num
;
3047 if (! d_add_substitution (di
, ret
))
3053 /* Add a new substitution. */
3056 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3060 if (di
->next_sub
>= di
->num_subs
)
3062 di
->subs
[di
->next_sub
] = dc
;
3067 /* <substitution> ::= S <seq-id> _
3077 If PREFIX is non-zero, then this type is being used as a prefix in
3078 a qualified name. In this case, for the standard substitutions, we
3079 need to check whether we are being used as a prefix for a
3080 constructor or destructor, and return a full template name.
3081 Otherwise we will get something like std::iostream::~iostream()
3082 which does not correspond particularly well to any function which
3083 actually appears in the source.
3086 static const struct d_standard_sub_info standard_subs
[] =
3091 { 'a', NL ("std::allocator"),
3092 NL ("std::allocator"),
3094 { 'b', NL ("std::basic_string"),
3095 NL ("std::basic_string"),
3096 NL ("basic_string") },
3097 { 's', NL ("std::string"),
3098 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3099 NL ("basic_string") },
3100 { 'i', NL ("std::istream"),
3101 NL ("std::basic_istream<char, std::char_traits<char> >"),
3102 NL ("basic_istream") },
3103 { 'o', NL ("std::ostream"),
3104 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3105 NL ("basic_ostream") },
3106 { 'd', NL ("std::iostream"),
3107 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3108 NL ("basic_iostream") }
3111 static struct demangle_component
*
3112 d_substitution (struct d_info
*di
, int prefix
)
3116 if (! d_check_char (di
, 'S'))
3119 c
= d_next_char (di
);
3120 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3129 unsigned int new_id
;
3132 new_id
= id
* 36 + c
- '0';
3133 else if (IS_UPPER (c
))
3134 new_id
= id
* 36 + c
- 'A' + 10;
3140 c
= d_next_char (di
);
3147 if (id
>= (unsigned int) di
->next_sub
)
3152 return di
->subs
[id
];
3157 const struct d_standard_sub_info
*p
;
3158 const struct d_standard_sub_info
*pend
;
3160 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3161 if (! verbose
&& prefix
)
3165 peek
= d_peek_char (di
);
3166 if (peek
== 'C' || peek
== 'D')
3170 pend
= (&standard_subs
[0]
3171 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3172 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3179 if (p
->set_last_name
!= NULL
)
3180 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3181 p
->set_last_name_len
);
3184 s
= p
->full_expansion
;
3189 s
= p
->simple_expansion
;
3190 len
= p
->simple_len
;
3192 di
->expansion
+= len
;
3193 return d_make_sub (di
, s
, len
);
3201 /* Initialize a growable string. */
3204 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3209 dgs
->allocation_failure
= 0;
3212 d_growable_string_resize (dgs
, estimate
);
3215 /* Grow a growable string to a given size. */
3218 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3223 if (dgs
->allocation_failure
)
3226 /* Start allocation at two bytes to avoid any possibility of confusion
3227 with the special value of 1 used as a return in *palc to indicate
3228 allocation failures. */
3229 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3230 while (newalc
< need
)
3233 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3240 dgs
->allocation_failure
= 1;
3247 /* Append a buffer to a growable string. */
3250 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3251 const char *s
, size_t l
)
3255 need
= dgs
->len
+ l
+ 1;
3256 if (need
> dgs
->alc
)
3257 d_growable_string_resize (dgs
, need
);
3259 if (dgs
->allocation_failure
)
3262 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3263 dgs
->buf
[dgs
->len
+ l
] = '\0';
3267 /* Bridge growable strings to the callback mechanism. */
3270 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3272 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3274 d_growable_string_append_buffer (dgs
, s
, l
);
3277 /* Initialize a print information structure. */
3280 d_print_init (struct d_print_info
*dpi
, int options
,
3281 demangle_callbackref callback
, void *opaque
)
3283 dpi
->options
= options
;
3285 dpi
->last_char
= '\0';
3286 dpi
->templates
= NULL
;
3287 dpi
->modifiers
= NULL
;
3289 dpi
->callback
= callback
;
3290 dpi
->opaque
= opaque
;
3292 dpi
->demangle_failure
= 0;
3295 /* Indicate that an error occurred during printing, and test for error. */
3298 d_print_error (struct d_print_info
*dpi
)
3300 dpi
->demangle_failure
= 1;
3304 d_print_saw_error (struct d_print_info
*dpi
)
3306 return dpi
->demangle_failure
!= 0;
3309 /* Flush buffered characters to the callback. */
3312 d_print_flush (struct d_print_info
*dpi
)
3314 dpi
->buf
[dpi
->len
] = '\0';
3315 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3319 /* Append characters and buffers for printing. */
3322 d_append_char (struct d_print_info
*dpi
, char c
)
3324 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3325 d_print_flush (dpi
);
3327 dpi
->buf
[dpi
->len
++] = c
;
3332 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3336 for (i
= 0; i
< l
; i
++)
3337 d_append_char (dpi
, s
[i
]);
3341 d_append_string (struct d_print_info
*dpi
, const char *s
)
3343 d_append_buffer (dpi
, s
, strlen (s
));
3347 d_append_num (struct d_print_info
*dpi
, long l
)
3350 sprintf (buf
,"%ld", l
);
3351 d_append_string (dpi
, buf
);
3355 d_last_char (struct d_print_info
*dpi
)
3357 return dpi
->last_char
;
3360 /* Turn components into a human readable string. OPTIONS is the
3361 options bits passed to the demangler. DC is the tree to print.
3362 CALLBACK is a function to call to flush demangled string segments
3363 as they fill the intermediate buffer, and OPAQUE is a generalized
3364 callback argument. On success, this returns 1. On failure,
3365 it returns 0, indicating a bad parse. It does not use heap
3366 memory to build an output string, so cannot encounter memory
3367 allocation failure. */
3369 CP_STATIC_IF_GLIBCPP_V3
3371 cplus_demangle_print_callback (int options
,
3372 const struct demangle_component
*dc
,
3373 demangle_callbackref callback
, void *opaque
)
3375 struct d_print_info dpi
;
3377 d_print_init (&dpi
, options
, callback
, opaque
);
3379 d_print_comp (&dpi
, dc
);
3381 d_print_flush (&dpi
);
3383 return ! d_print_saw_error (&dpi
);
3386 /* Turn components into a human readable string. OPTIONS is the
3387 options bits passed to the demangler. DC is the tree to print.
3388 ESTIMATE is a guess at the length of the result. This returns a
3389 string allocated by malloc, or NULL on error. On success, this
3390 sets *PALC to the size of the allocated buffer. On failure, this
3391 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3394 CP_STATIC_IF_GLIBCPP_V3
3396 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3397 int estimate
, size_t *palc
)
3399 struct d_growable_string dgs
;
3401 d_growable_string_init (&dgs
, estimate
);
3403 if (! cplus_demangle_print_callback (options
, dc
,
3404 d_growable_string_callback_adapter
,
3412 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3416 /* Returns the I'th element of the template arglist ARGS, or NULL on
3419 static struct demangle_component
*
3420 d_index_template_argument (struct demangle_component
*args
, int i
)
3422 struct demangle_component
*a
;
3428 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3434 if (i
!= 0 || a
== NULL
)
3440 /* Returns the template argument from the current context indicated by DC,
3441 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3443 static struct demangle_component
*
3444 d_lookup_template_argument (struct d_print_info
*dpi
,
3445 const struct demangle_component
*dc
)
3447 if (dpi
->templates
== NULL
)
3449 d_print_error (dpi
);
3453 return d_index_template_argument
3454 (d_right (dpi
->templates
->template_decl
),
3455 dc
->u
.s_number
.number
);
3458 /* Returns a template argument pack used in DC (any will do), or NULL. */
3460 static struct demangle_component
*
3461 d_find_pack (struct d_print_info
*dpi
,
3462 const struct demangle_component
*dc
)
3464 struct demangle_component
*a
;
3470 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3471 a
= d_lookup_template_argument (dpi
, dc
);
3472 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3476 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3479 case DEMANGLE_COMPONENT_NAME
:
3480 case DEMANGLE_COMPONENT_OPERATOR
:
3481 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3482 case DEMANGLE_COMPONENT_SUB_STD
:
3483 case DEMANGLE_COMPONENT_CHARACTER
:
3484 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3487 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3488 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3489 case DEMANGLE_COMPONENT_CTOR
:
3490 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3491 case DEMANGLE_COMPONENT_DTOR
:
3492 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3495 a
= d_find_pack (dpi
, d_left (dc
));
3498 return d_find_pack (dpi
, d_right (dc
));
3502 /* Returns the length of the template argument pack DC. */
3505 d_pack_length (const struct demangle_component
*dc
)
3508 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3509 && d_left (dc
) != NULL
)
3517 /* DC is a component of a mangled expression. Print it, wrapped in parens
3521 d_print_subexpr (struct d_print_info
*dpi
,
3522 const struct demangle_component
*dc
)
3525 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3526 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3529 d_append_char (dpi
, '(');
3530 d_print_comp (dpi
, dc
);
3532 d_append_char (dpi
, ')');
3535 /* Subroutine to handle components. */
3538 d_print_comp (struct d_print_info
*dpi
,
3539 const struct demangle_component
*dc
)
3543 d_print_error (dpi
);
3546 if (d_print_saw_error (dpi
))
3551 case DEMANGLE_COMPONENT_NAME
:
3552 if ((dpi
->options
& DMGL_JAVA
) == 0)
3553 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3555 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3558 case DEMANGLE_COMPONENT_QUAL_NAME
:
3559 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3560 d_print_comp (dpi
, d_left (dc
));
3561 if ((dpi
->options
& DMGL_JAVA
) == 0)
3562 d_append_string (dpi
, "::");
3564 d_append_char (dpi
, '.');
3565 d_print_comp (dpi
, d_right (dc
));
3568 case DEMANGLE_COMPONENT_TYPED_NAME
:
3570 struct d_print_mod
*hold_modifiers
;
3571 struct demangle_component
*typed_name
;
3572 struct d_print_mod adpm
[4];
3574 struct d_print_template dpt
;
3576 /* Pass the name down to the type so that it can be printed in
3577 the right place for the type. We also have to pass down
3578 any CV-qualifiers, which apply to the this parameter. */
3579 hold_modifiers
= dpi
->modifiers
;
3582 typed_name
= d_left (dc
);
3583 while (typed_name
!= NULL
)
3585 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3587 d_print_error (dpi
);
3591 adpm
[i
].next
= dpi
->modifiers
;
3592 dpi
->modifiers
= &adpm
[i
];
3593 adpm
[i
].mod
= typed_name
;
3594 adpm
[i
].printed
= 0;
3595 adpm
[i
].templates
= dpi
->templates
;
3598 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3599 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3600 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3603 typed_name
= d_left (typed_name
);
3606 if (typed_name
== NULL
)
3608 d_print_error (dpi
);
3612 /* If typed_name is a template, then it applies to the
3613 function type as well. */
3614 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3616 dpt
.next
= dpi
->templates
;
3617 dpi
->templates
= &dpt
;
3618 dpt
.template_decl
= typed_name
;
3621 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3622 there may be CV-qualifiers on its right argument which
3623 really apply here; this happens when parsing a class which
3624 is local to a function. */
3625 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3627 struct demangle_component
*local_name
;
3629 local_name
= d_right (typed_name
);
3630 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
3631 local_name
= local_name
->u
.s_unary_num
.sub
;
3632 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3633 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3634 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3636 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3638 d_print_error (dpi
);
3642 adpm
[i
] = adpm
[i
- 1];
3643 adpm
[i
].next
= &adpm
[i
- 1];
3644 dpi
->modifiers
= &adpm
[i
];
3646 adpm
[i
- 1].mod
= local_name
;
3647 adpm
[i
- 1].printed
= 0;
3648 adpm
[i
- 1].templates
= dpi
->templates
;
3651 local_name
= d_left (local_name
);
3655 d_print_comp (dpi
, d_right (dc
));
3657 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3658 dpi
->templates
= dpt
.next
;
3660 /* If the modifiers didn't get printed by the type, print them
3665 if (! adpm
[i
].printed
)
3667 d_append_char (dpi
, ' ');
3668 d_print_mod (dpi
, adpm
[i
].mod
);
3672 dpi
->modifiers
= hold_modifiers
;
3677 case DEMANGLE_COMPONENT_TEMPLATE
:
3679 struct d_print_mod
*hold_dpm
;
3680 struct demangle_component
*dcl
;
3682 /* Don't push modifiers into a template definition. Doing so
3683 could give the wrong definition for a template argument.
3684 Instead, treat the template essentially as a name. */
3686 hold_dpm
= dpi
->modifiers
;
3687 dpi
->modifiers
= NULL
;
3691 if ((dpi
->options
& DMGL_JAVA
) != 0
3692 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3693 && dcl
->u
.s_name
.len
== 6
3694 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3696 /* Special-case Java arrays, so that JArray<TYPE> appears
3697 instead as TYPE[]. */
3699 d_print_comp (dpi
, d_right (dc
));
3700 d_append_string (dpi
, "[]");
3704 d_print_comp (dpi
, dcl
);
3705 if (d_last_char (dpi
) == '<')
3706 d_append_char (dpi
, ' ');
3707 d_append_char (dpi
, '<');
3708 d_print_comp (dpi
, d_right (dc
));
3709 /* Avoid generating two consecutive '>' characters, to avoid
3710 the C++ syntactic ambiguity. */
3711 if (d_last_char (dpi
) == '>')
3712 d_append_char (dpi
, ' ');
3713 d_append_char (dpi
, '>');
3716 dpi
->modifiers
= hold_dpm
;
3721 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3723 struct d_print_template
*hold_dpt
;
3724 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
3726 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3727 a
= d_index_template_argument (a
, dpi
->pack_index
);
3731 d_print_error (dpi
);
3735 /* While processing this parameter, we need to pop the list of
3736 templates. This is because the template parameter may
3737 itself be a reference to a parameter of an outer
3740 hold_dpt
= dpi
->templates
;
3741 dpi
->templates
= hold_dpt
->next
;
3743 d_print_comp (dpi
, a
);
3745 dpi
->templates
= hold_dpt
;
3750 case DEMANGLE_COMPONENT_CTOR
:
3751 d_print_comp (dpi
, dc
->u
.s_ctor
.name
);
3754 case DEMANGLE_COMPONENT_DTOR
:
3755 d_append_char (dpi
, '~');
3756 d_print_comp (dpi
, dc
->u
.s_dtor
.name
);
3759 case DEMANGLE_COMPONENT_VTABLE
:
3760 d_append_string (dpi
, "vtable for ");
3761 d_print_comp (dpi
, d_left (dc
));
3764 case DEMANGLE_COMPONENT_VTT
:
3765 d_append_string (dpi
, "VTT for ");
3766 d_print_comp (dpi
, d_left (dc
));
3769 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3770 d_append_string (dpi
, "construction vtable for ");
3771 d_print_comp (dpi
, d_left (dc
));
3772 d_append_string (dpi
, "-in-");
3773 d_print_comp (dpi
, d_right (dc
));
3776 case DEMANGLE_COMPONENT_TYPEINFO
:
3777 d_append_string (dpi
, "typeinfo for ");
3778 d_print_comp (dpi
, d_left (dc
));
3781 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3782 d_append_string (dpi
, "typeinfo name for ");
3783 d_print_comp (dpi
, d_left (dc
));
3786 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3787 d_append_string (dpi
, "typeinfo fn for ");
3788 d_print_comp (dpi
, d_left (dc
));
3791 case DEMANGLE_COMPONENT_THUNK
:
3792 d_append_string (dpi
, "non-virtual thunk to ");
3793 d_print_comp (dpi
, d_left (dc
));
3796 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3797 d_append_string (dpi
, "virtual thunk to ");
3798 d_print_comp (dpi
, d_left (dc
));
3801 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3802 d_append_string (dpi
, "covariant return thunk to ");
3803 d_print_comp (dpi
, d_left (dc
));
3806 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3807 d_append_string (dpi
, "java Class for ");
3808 d_print_comp (dpi
, d_left (dc
));
3811 case DEMANGLE_COMPONENT_GUARD
:
3812 d_append_string (dpi
, "guard variable for ");
3813 d_print_comp (dpi
, d_left (dc
));
3816 case DEMANGLE_COMPONENT_REFTEMP
:
3817 d_append_string (dpi
, "reference temporary for ");
3818 d_print_comp (dpi
, d_left (dc
));
3821 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3822 d_append_string (dpi
, "hidden alias for ");
3823 d_print_comp (dpi
, d_left (dc
));
3826 case DEMANGLE_COMPONENT_SUB_STD
:
3827 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3830 case DEMANGLE_COMPONENT_RESTRICT
:
3831 case DEMANGLE_COMPONENT_VOLATILE
:
3832 case DEMANGLE_COMPONENT_CONST
:
3834 struct d_print_mod
*pdpm
;
3836 /* When printing arrays, it's possible to have cases where the
3837 same CV-qualifier gets pushed on the stack multiple times.
3838 We only need to print it once. */
3840 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3842 if (! pdpm
->printed
)
3844 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3845 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3846 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3848 if (pdpm
->mod
->type
== dc
->type
)
3850 d_print_comp (dpi
, d_left (dc
));
3857 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3858 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3859 case DEMANGLE_COMPONENT_CONST_THIS
:
3860 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3861 case DEMANGLE_COMPONENT_POINTER
:
3862 case DEMANGLE_COMPONENT_REFERENCE
:
3863 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3864 case DEMANGLE_COMPONENT_COMPLEX
:
3865 case DEMANGLE_COMPONENT_IMAGINARY
:
3867 /* We keep a list of modifiers on the stack. */
3868 struct d_print_mod dpm
;
3870 dpm
.next
= dpi
->modifiers
;
3871 dpi
->modifiers
= &dpm
;
3874 dpm
.templates
= dpi
->templates
;
3876 d_print_comp (dpi
, d_left (dc
));
3878 /* If the modifier didn't get printed by the type, print it
3881 d_print_mod (dpi
, dc
);
3883 dpi
->modifiers
= dpm
.next
;
3888 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3889 if ((dpi
->options
& DMGL_JAVA
) == 0)
3890 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
3891 dc
->u
.s_builtin
.type
->len
);
3893 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
3894 dc
->u
.s_builtin
.type
->java_len
);
3897 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3898 d_print_comp (dpi
, d_left (dc
));
3901 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3903 if ((dpi
->options
& DMGL_RET_POSTFIX
) != 0)
3904 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3906 /* Print return type if present */
3907 if (d_left (dc
) != NULL
)
3909 struct d_print_mod dpm
;
3911 /* We must pass this type down as a modifier in order to
3912 print it in the right location. */
3913 dpm
.next
= dpi
->modifiers
;
3914 dpi
->modifiers
= &dpm
;
3917 dpm
.templates
= dpi
->templates
;
3919 d_print_comp (dpi
, d_left (dc
));
3921 dpi
->modifiers
= dpm
.next
;
3926 /* In standard prefix notation, there is a space between the
3927 return type and the function signature. */
3928 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3929 d_append_char (dpi
, ' ');
3932 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3933 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3938 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3940 struct d_print_mod
*hold_modifiers
;
3941 struct d_print_mod adpm
[4];
3943 struct d_print_mod
*pdpm
;
3945 /* We must pass this type down as a modifier in order to print
3946 multi-dimensional arrays correctly. If the array itself is
3947 CV-qualified, we act as though the element type were
3948 CV-qualified. We do this by copying the modifiers down
3949 rather than fiddling pointers, so that we don't wind up
3950 with a d_print_mod higher on the stack pointing into our
3951 stack frame after we return. */
3953 hold_modifiers
= dpi
->modifiers
;
3955 adpm
[0].next
= hold_modifiers
;
3956 dpi
->modifiers
= &adpm
[0];
3958 adpm
[0].printed
= 0;
3959 adpm
[0].templates
= dpi
->templates
;
3962 pdpm
= hold_modifiers
;
3964 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
3965 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
3966 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
3968 if (! pdpm
->printed
)
3970 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3972 d_print_error (dpi
);
3977 adpm
[i
].next
= dpi
->modifiers
;
3978 dpi
->modifiers
= &adpm
[i
];
3986 d_print_comp (dpi
, d_right (dc
));
3988 dpi
->modifiers
= hold_modifiers
;
3990 if (adpm
[0].printed
)
3996 d_print_mod (dpi
, adpm
[i
].mod
);
3999 d_print_array_type (dpi
, dc
, dpi
->modifiers
);
4004 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4005 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4007 struct d_print_mod dpm
;
4009 dpm
.next
= dpi
->modifiers
;
4010 dpi
->modifiers
= &dpm
;
4013 dpm
.templates
= dpi
->templates
;
4015 d_print_comp (dpi
, d_right (dc
));
4017 /* If the modifier didn't get printed by the type, print it
4020 d_print_mod (dpi
, dc
);
4022 dpi
->modifiers
= dpm
.next
;
4027 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4028 if (dc
->u
.s_fixed
.sat
)
4029 d_append_string (dpi
, "_Sat ");
4030 /* Don't print "int _Accum". */
4031 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4032 != &cplus_demangle_builtin_types
['i'-'a'])
4034 d_print_comp (dpi
, dc
->u
.s_fixed
.length
);
4035 d_append_char (dpi
, ' ');
4037 if (dc
->u
.s_fixed
.accum
)
4038 d_append_string (dpi
, "_Accum");
4040 d_append_string (dpi
, "_Fract");
4043 case DEMANGLE_COMPONENT_ARGLIST
:
4044 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4045 if (d_left (dc
) != NULL
)
4046 d_print_comp (dpi
, d_left (dc
));
4047 if (d_right (dc
) != NULL
)
4050 d_append_string (dpi
, ", ");
4052 d_print_comp (dpi
, d_right (dc
));
4053 /* If that didn't print anything (which can happen with empty
4054 template argument packs), remove the comma and space. */
4055 if (dpi
->len
== len
)
4060 case DEMANGLE_COMPONENT_OPERATOR
:
4064 d_append_string (dpi
, "operator");
4065 c
= dc
->u
.s_operator
.op
->name
[0];
4067 d_append_char (dpi
, ' ');
4068 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4069 dc
->u
.s_operator
.op
->len
);
4073 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4074 d_append_string (dpi
, "operator ");
4075 d_print_comp (dpi
, dc
->u
.s_extended_operator
.name
);
4078 case DEMANGLE_COMPONENT_CAST
:
4079 d_append_string (dpi
, "operator ");
4080 d_print_cast (dpi
, dc
);
4083 case DEMANGLE_COMPONENT_UNARY
:
4084 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
4085 d_print_expr_op (dpi
, d_left (dc
));
4088 d_append_char (dpi
, '(');
4089 d_print_cast (dpi
, d_left (dc
));
4090 d_append_char (dpi
, ')');
4092 d_print_subexpr (dpi
, d_right (dc
));
4095 case DEMANGLE_COMPONENT_BINARY
:
4096 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4098 d_print_error (dpi
);
4102 /* We wrap an expression which uses the greater-than operator in
4103 an extra layer of parens so that it does not get confused
4104 with the '>' which ends the template parameters. */
4105 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4106 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4107 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4108 d_append_char (dpi
, '(');
4110 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4111 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4113 d_append_char (dpi
, '[');
4114 d_print_comp (dpi
, d_right (d_right (dc
)));
4115 d_append_char (dpi
, ']');
4119 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4120 d_print_expr_op (dpi
, d_left (dc
));
4121 d_print_subexpr (dpi
, d_right (d_right (dc
)));
4124 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4125 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4126 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4127 d_append_char (dpi
, ')');
4131 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4132 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4133 d_print_error (dpi
);
4136 case DEMANGLE_COMPONENT_TRINARY
:
4137 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4138 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4140 d_print_error (dpi
);
4143 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4144 d_print_expr_op (dpi
, d_left (dc
));
4145 d_print_subexpr (dpi
, d_left (d_right (d_right (dc
))));
4146 d_append_string (dpi
, " : ");
4147 d_print_subexpr (dpi
, d_right (d_right (d_right (dc
))));
4150 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4151 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4152 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4153 d_print_error (dpi
);
4156 case DEMANGLE_COMPONENT_LITERAL
:
4157 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4159 enum d_builtin_type_print tp
;
4161 /* For some builtin types, produce simpler output. */
4162 tp
= D_PRINT_DEFAULT
;
4163 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4165 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4169 case D_PRINT_UNSIGNED
:
4171 case D_PRINT_UNSIGNED_LONG
:
4172 case D_PRINT_LONG_LONG
:
4173 case D_PRINT_UNSIGNED_LONG_LONG
:
4174 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4176 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4177 d_append_char (dpi
, '-');
4178 d_print_comp (dpi
, d_right (dc
));
4183 case D_PRINT_UNSIGNED
:
4184 d_append_char (dpi
, 'u');
4187 d_append_char (dpi
, 'l');
4189 case D_PRINT_UNSIGNED_LONG
:
4190 d_append_string (dpi
, "ul");
4192 case D_PRINT_LONG_LONG
:
4193 d_append_string (dpi
, "ll");
4195 case D_PRINT_UNSIGNED_LONG_LONG
:
4196 d_append_string (dpi
, "ull");
4204 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4205 && d_right (dc
)->u
.s_name
.len
== 1
4206 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4208 switch (d_right (dc
)->u
.s_name
.s
[0])
4211 d_append_string (dpi
, "false");
4214 d_append_string (dpi
, "true");
4227 d_append_char (dpi
, '(');
4228 d_print_comp (dpi
, d_left (dc
));
4229 d_append_char (dpi
, ')');
4230 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4231 d_append_char (dpi
, '-');
4232 if (tp
== D_PRINT_FLOAT
)
4233 d_append_char (dpi
, '[');
4234 d_print_comp (dpi
, d_right (dc
));
4235 if (tp
== D_PRINT_FLOAT
)
4236 d_append_char (dpi
, ']');
4240 case DEMANGLE_COMPONENT_NUMBER
:
4241 d_append_num (dpi
, dc
->u
.s_number
.number
);
4244 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4245 d_append_string (dpi
, "java resource ");
4246 d_print_comp (dpi
, d_left (dc
));
4249 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4250 d_print_comp (dpi
, d_left (dc
));
4251 d_print_comp (dpi
, d_right (dc
));
4254 case DEMANGLE_COMPONENT_CHARACTER
:
4255 d_append_char (dpi
, dc
->u
.s_character
.character
);
4258 case DEMANGLE_COMPONENT_DECLTYPE
:
4259 d_append_string (dpi
, "decltype (");
4260 d_print_comp (dpi
, d_left (dc
));
4261 d_append_char (dpi
, ')');
4264 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4268 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4271 /* d_find_pack won't find anything if the only packs involved
4272 in this expansion are function parameter packs; in that
4273 case, just print the pattern and "...". */
4274 d_print_subexpr (dpi
, d_left (dc
));
4275 d_append_string (dpi
, "...");
4279 len
= d_pack_length (a
);
4281 for (i
= 0; i
< len
; ++i
)
4283 dpi
->pack_index
= i
;
4284 d_print_comp (dpi
, dc
);
4286 d_append_string (dpi
, ", ");
4291 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4292 d_append_string (dpi
, "{parm#");
4293 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4294 d_append_char (dpi
, '}');
4297 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4298 d_append_string (dpi
, "global constructors keyed to ");
4299 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4302 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4303 d_append_string (dpi
, "global destructors keyed to ");
4304 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4307 case DEMANGLE_COMPONENT_LAMBDA
:
4308 d_append_string (dpi
, "{lambda(");
4309 d_print_comp (dpi
, dc
->u
.s_unary_num
.sub
);
4310 d_append_string (dpi
, ")#");
4311 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4312 d_append_char (dpi
, '}');
4315 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4316 d_append_string (dpi
, "{unnamed type#");
4317 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4318 d_append_char (dpi
, '}');
4322 d_print_error (dpi
);
4327 /* Print a Java dentifier. For Java we try to handle encoded extended
4328 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4329 so we don't it for C++. Characters are encoded as
4333 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
4339 for (p
= name
; p
< end
; ++p
)
4350 for (q
= p
+ 3; q
< end
; ++q
)
4356 else if (*q
>= 'A' && *q
<= 'F')
4357 dig
= *q
- 'A' + 10;
4358 else if (*q
>= 'a' && *q
<= 'f')
4359 dig
= *q
- 'a' + 10;
4365 /* If the Unicode character is larger than 256, we don't try
4366 to deal with it here. FIXME. */
4367 if (q
< end
&& *q
== '_' && c
< 256)
4369 d_append_char (dpi
, c
);
4375 d_append_char (dpi
, *p
);
4379 /* Print a list of modifiers. SUFFIX is 1 if we are printing
4380 qualifiers on this after printing a function. */
4383 d_print_mod_list (struct d_print_info
*dpi
,
4384 struct d_print_mod
*mods
, int suffix
)
4386 struct d_print_template
*hold_dpt
;
4388 if (mods
== NULL
|| d_print_saw_error (dpi
))
4393 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4394 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4395 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
4397 d_print_mod_list (dpi
, mods
->next
, suffix
);
4403 hold_dpt
= dpi
->templates
;
4404 dpi
->templates
= mods
->templates
;
4406 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4408 d_print_function_type (dpi
, mods
->mod
, mods
->next
);
4409 dpi
->templates
= hold_dpt
;
4412 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4414 d_print_array_type (dpi
, mods
->mod
, mods
->next
);
4415 dpi
->templates
= hold_dpt
;
4418 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4420 struct d_print_mod
*hold_modifiers
;
4421 struct demangle_component
*dc
;
4423 /* When this is on the modifier stack, we have pulled any
4424 qualifiers off the right argument already. Otherwise, we
4425 print it as usual, but don't let the left argument see any
4428 hold_modifiers
= dpi
->modifiers
;
4429 dpi
->modifiers
= NULL
;
4430 d_print_comp (dpi
, d_left (mods
->mod
));
4431 dpi
->modifiers
= hold_modifiers
;
4433 if ((dpi
->options
& DMGL_JAVA
) == 0)
4434 d_append_string (dpi
, "::");
4436 d_append_char (dpi
, '.');
4438 dc
= d_right (mods
->mod
);
4440 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4442 d_append_string (dpi
, "{default arg#");
4443 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4444 d_append_string (dpi
, "}::");
4445 dc
= dc
->u
.s_unary_num
.sub
;
4448 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4449 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4450 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
4453 d_print_comp (dpi
, dc
);
4455 dpi
->templates
= hold_dpt
;
4459 d_print_mod (dpi
, mods
->mod
);
4461 dpi
->templates
= hold_dpt
;
4463 d_print_mod_list (dpi
, mods
->next
, suffix
);
4466 /* Print a modifier. */
4469 d_print_mod (struct d_print_info
*dpi
,
4470 const struct demangle_component
*mod
)
4474 case DEMANGLE_COMPONENT_RESTRICT
:
4475 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4476 d_append_string (dpi
, " restrict");
4478 case DEMANGLE_COMPONENT_VOLATILE
:
4479 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4480 d_append_string (dpi
, " volatile");
4482 case DEMANGLE_COMPONENT_CONST
:
4483 case DEMANGLE_COMPONENT_CONST_THIS
:
4484 d_append_string (dpi
, " const");
4486 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4487 d_append_char (dpi
, ' ');
4488 d_print_comp (dpi
, d_right (mod
));
4490 case DEMANGLE_COMPONENT_POINTER
:
4491 /* There is no pointer symbol in Java. */
4492 if ((dpi
->options
& DMGL_JAVA
) == 0)
4493 d_append_char (dpi
, '*');
4495 case DEMANGLE_COMPONENT_REFERENCE
:
4496 d_append_char (dpi
, '&');
4498 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4499 d_append_string (dpi
, "&&");
4501 case DEMANGLE_COMPONENT_COMPLEX
:
4502 d_append_string (dpi
, "complex ");
4504 case DEMANGLE_COMPONENT_IMAGINARY
:
4505 d_append_string (dpi
, "imaginary ");
4507 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4508 if (d_last_char (dpi
) != '(')
4509 d_append_char (dpi
, ' ');
4510 d_print_comp (dpi
, d_left (mod
));
4511 d_append_string (dpi
, "::*");
4513 case DEMANGLE_COMPONENT_TYPED_NAME
:
4514 d_print_comp (dpi
, d_left (mod
));
4516 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4517 d_append_string (dpi
, " __vector(");
4518 d_print_comp (dpi
, d_left (mod
));
4519 d_append_char (dpi
, ')');
4523 /* Otherwise, we have something that won't go back on the
4524 modifier stack, so we can just print it. */
4525 d_print_comp (dpi
, mod
);
4530 /* Print a function type, except for the return type. */
4533 d_print_function_type (struct d_print_info
*dpi
,
4534 const struct demangle_component
*dc
,
4535 struct d_print_mod
*mods
)
4540 struct d_print_mod
*p
;
4541 struct d_print_mod
*hold_modifiers
;
4546 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4552 switch (p
->mod
->type
)
4554 case DEMANGLE_COMPONENT_POINTER
:
4555 case DEMANGLE_COMPONENT_REFERENCE
:
4556 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4559 case DEMANGLE_COMPONENT_RESTRICT
:
4560 case DEMANGLE_COMPONENT_VOLATILE
:
4561 case DEMANGLE_COMPONENT_CONST
:
4562 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4563 case DEMANGLE_COMPONENT_COMPLEX
:
4564 case DEMANGLE_COMPONENT_IMAGINARY
:
4565 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4569 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4570 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4571 case DEMANGLE_COMPONENT_CONST_THIS
:
4580 if (d_left (dc
) != NULL
&& ! saw_mod
)
4587 if (d_last_char (dpi
) != '('
4588 && d_last_char (dpi
) != '*')
4591 if (need_space
&& d_last_char (dpi
) != ' ')
4592 d_append_char (dpi
, ' ');
4593 d_append_char (dpi
, '(');
4596 hold_modifiers
= dpi
->modifiers
;
4597 dpi
->modifiers
= NULL
;
4599 d_print_mod_list (dpi
, mods
, 0);
4602 d_append_char (dpi
, ')');
4604 d_append_char (dpi
, '(');
4606 if (d_right (dc
) != NULL
)
4607 d_print_comp (dpi
, d_right (dc
));
4609 d_append_char (dpi
, ')');
4611 d_print_mod_list (dpi
, mods
, 1);
4613 dpi
->modifiers
= hold_modifiers
;
4616 /* Print an array type, except for the element type. */
4619 d_print_array_type (struct d_print_info
*dpi
,
4620 const struct demangle_component
*dc
,
4621 struct d_print_mod
*mods
)
4629 struct d_print_mod
*p
;
4632 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4636 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4651 d_append_string (dpi
, " (");
4653 d_print_mod_list (dpi
, mods
, 0);
4656 d_append_char (dpi
, ')');
4660 d_append_char (dpi
, ' ');
4662 d_append_char (dpi
, '[');
4664 if (d_left (dc
) != NULL
)
4665 d_print_comp (dpi
, d_left (dc
));
4667 d_append_char (dpi
, ']');
4670 /* Print an operator in an expression. */
4673 d_print_expr_op (struct d_print_info
*dpi
,
4674 const struct demangle_component
*dc
)
4676 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4677 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4678 dc
->u
.s_operator
.op
->len
);
4680 d_print_comp (dpi
, dc
);
4686 d_print_cast (struct d_print_info
*dpi
,
4687 const struct demangle_component
*dc
)
4689 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4690 d_print_comp (dpi
, d_left (dc
));
4693 struct d_print_mod
*hold_dpm
;
4694 struct d_print_template dpt
;
4696 /* It appears that for a templated cast operator, we need to put
4697 the template parameters in scope for the operator name, but
4698 not for the parameters. The effect is that we need to handle
4699 the template printing here. */
4701 hold_dpm
= dpi
->modifiers
;
4702 dpi
->modifiers
= NULL
;
4704 dpt
.next
= dpi
->templates
;
4705 dpi
->templates
= &dpt
;
4706 dpt
.template_decl
= d_left (dc
);
4708 d_print_comp (dpi
, d_left (d_left (dc
)));
4710 dpi
->templates
= dpt
.next
;
4712 if (d_last_char (dpi
) == '<')
4713 d_append_char (dpi
, ' ');
4714 d_append_char (dpi
, '<');
4715 d_print_comp (dpi
, d_right (d_left (dc
)));
4716 /* Avoid generating two consecutive '>' characters, to avoid
4717 the C++ syntactic ambiguity. */
4718 if (d_last_char (dpi
) == '>')
4719 d_append_char (dpi
, ' ');
4720 d_append_char (dpi
, '>');
4722 dpi
->modifiers
= hold_dpm
;
4726 /* Initialize the information structure we use to pass around
4729 CP_STATIC_IF_GLIBCPP_V3
4731 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4735 di
->send
= mangled
+ len
;
4736 di
->options
= options
;
4740 /* We can not need more components than twice the number of chars in
4741 the mangled string. Most components correspond directly to
4742 chars, but the ARGLIST types are exceptions. */
4743 di
->num_comps
= 2 * len
;
4746 /* Similarly, we can not need more substitutions than there are
4747 chars in the mangled string. */
4752 di
->last_name
= NULL
;
4757 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4758 mangled name, return strings in repeated callback giving the demangled
4759 name. OPTIONS is the usual libiberty demangler options. On success,
4760 this returns 1. On failure, returns 0. */
4763 d_demangle_callback (const char *mangled
, int options
,
4764 demangle_callbackref callback
, void *opaque
)
4775 struct demangle_component
*dc
;
4778 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4780 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
4781 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
4782 && (mangled
[9] == 'D' || mangled
[9] == 'I')
4783 && mangled
[10] == '_')
4784 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
4787 if ((options
& DMGL_TYPES
) == 0)
4792 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
4795 #ifdef CP_DYNAMIC_ARRAYS
4796 __extension__
struct demangle_component comps
[di
.num_comps
];
4797 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4802 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4803 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4809 dc
= cplus_demangle_type (&di
);
4812 dc
= cplus_demangle_mangled_name (&di
, 1);
4814 case DCT_GLOBAL_CTORS
:
4815 case DCT_GLOBAL_DTORS
:
4816 d_advance (&di
, 11);
4817 dc
= d_make_comp (&di
,
4818 (type
== DCT_GLOBAL_CTORS
4819 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
4820 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
4821 d_make_name (&di
, d_str (&di
), strlen (d_str (&di
))),
4823 d_advance (&di
, strlen (d_str (&di
)));
4827 /* If DMGL_PARAMS is set, then if we didn't consume the entire
4828 mangled string, then we didn't successfully demangle it. If
4829 DMGL_PARAMS is not set, we didn't look at the trailing
4831 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
4834 #ifdef CP_DEMANGLE_DEBUG
4838 status
= (dc
!= NULL
)
4839 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
4846 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4847 name, return a buffer allocated with malloc holding the demangled
4848 name. OPTIONS is the usual libiberty demangler options. On
4849 success, this sets *PALC to the allocated size of the returned
4850 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4851 a memory allocation failure, and returns NULL. */
4854 d_demangle (const char *mangled
, int options
, size_t *palc
)
4856 struct d_growable_string dgs
;
4859 d_growable_string_init (&dgs
, 0);
4861 status
= d_demangle_callback (mangled
, options
,
4862 d_growable_string_callback_adapter
, &dgs
);
4870 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4874 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4876 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
4878 /* ia64 ABI-mandated entry point in the C++ runtime library for
4879 performing demangling. MANGLED_NAME is a NUL-terminated character
4880 string containing the name to be demangled.
4882 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
4883 *LENGTH bytes, into which the demangled name is stored. If
4884 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
4885 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
4886 is placed in a region of memory allocated with malloc.
4888 If LENGTH is non-NULL, the length of the buffer containing the
4889 demangled name, is placed in *LENGTH.
4891 The return value is a pointer to the start of the NUL-terminated
4892 demangled name, or NULL if the demangling fails. The caller is
4893 responsible for deallocating this memory using free.
4895 *STATUS is set to one of the following values:
4896 0: The demangling operation succeeded.
4897 -1: A memory allocation failure occurred.
4898 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4899 -3: One of the arguments is invalid.
4901 The demangling is performed using the C++ ABI mangling rules, with
4905 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
4906 size_t *length
, int *status
)
4911 if (mangled_name
== NULL
)
4918 if (output_buffer
!= NULL
&& length
== NULL
)
4925 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
4927 if (demangled
== NULL
)
4939 if (output_buffer
== NULL
)
4946 if (strlen (demangled
) < *length
)
4948 strcpy (output_buffer
, demangled
);
4950 demangled
= output_buffer
;
4954 free (output_buffer
);
4965 extern int __gcclibcxx_demangle_callback (const char *,
4967 (const char *, size_t, void *),
4970 /* Alternative, allocationless entry point in the C++ runtime library
4971 for performing demangling. MANGLED_NAME is a NUL-terminated character
4972 string containing the name to be demangled.
4974 CALLBACK is a callback function, called with demangled string
4975 segments as demangling progresses; it is called at least once,
4976 but may be called more than once. OPAQUE is a generalized pointer
4977 used as a callback argument.
4979 The return code is one of the following values, equivalent to
4980 the STATUS values of __cxa_demangle() (excluding -1, since this
4981 function performs no memory allocations):
4982 0: The demangling operation succeeded.
4983 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4984 -3: One of the arguments is invalid.
4986 The demangling is performed using the C++ ABI mangling rules, with
4990 __gcclibcxx_demangle_callback (const char *mangled_name
,
4991 void (*callback
) (const char *, size_t, void *),
4996 if (mangled_name
== NULL
|| callback
== NULL
)
4999 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5007 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5009 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5010 mangled name, return a buffer allocated with malloc holding the
5011 demangled name. Otherwise, return NULL. */
5014 cplus_demangle_v3 (const char *mangled
, int options
)
5018 return d_demangle (mangled
, options
, &alc
);
5022 cplus_demangle_v3_callback (const char *mangled
, int options
,
5023 demangle_callbackref callback
, void *opaque
)
5025 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5028 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5029 conventions, but the output formatting is a little different.
5030 This instructs the C++ demangler not to emit pointer characters ("*"), to
5031 use Java's namespace separator symbol ("." instead of "::"), and to output
5032 JArray<TYPE> as TYPE[]. */
5035 java_demangle_v3 (const char *mangled
)
5039 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5043 java_demangle_v3_callback (const char *mangled
,
5044 demangle_callbackref callback
, void *opaque
)
5046 return d_demangle_callback (mangled
,
5047 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5051 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5053 #ifndef IN_GLIBCPP_V3
5055 /* Demangle a string in order to find out whether it is a constructor
5056 or destructor. Return non-zero on success. Set *CTOR_KIND and
5057 *DTOR_KIND appropriately. */
5060 is_ctor_or_dtor (const char *mangled
,
5061 enum gnu_v3_ctor_kinds
*ctor_kind
,
5062 enum gnu_v3_dtor_kinds
*dtor_kind
)
5065 struct demangle_component
*dc
;
5068 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5069 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5071 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5074 #ifdef CP_DYNAMIC_ARRAYS
5075 __extension__
struct demangle_component comps
[di
.num_comps
];
5076 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5081 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5082 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5085 dc
= cplus_demangle_mangled_name (&di
, 1);
5087 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5088 to demangle the entire string. */
5098 case DEMANGLE_COMPONENT_TYPED_NAME
:
5099 case DEMANGLE_COMPONENT_TEMPLATE
:
5100 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5101 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5102 case DEMANGLE_COMPONENT_CONST_THIS
:
5105 case DEMANGLE_COMPONENT_QUAL_NAME
:
5106 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5109 case DEMANGLE_COMPONENT_CTOR
:
5110 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5114 case DEMANGLE_COMPONENT_DTOR
:
5115 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5126 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5127 name. A non-zero return indicates the type of constructor. */
5129 enum gnu_v3_ctor_kinds
5130 is_gnu_v3_mangled_ctor (const char *name
)
5132 enum gnu_v3_ctor_kinds ctor_kind
;
5133 enum gnu_v3_dtor_kinds dtor_kind
;
5135 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5136 return (enum gnu_v3_ctor_kinds
) 0;
5141 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5142 name. A non-zero return indicates the type of destructor. */
5144 enum gnu_v3_dtor_kinds
5145 is_gnu_v3_mangled_dtor (const char *name
)
5147 enum gnu_v3_ctor_kinds ctor_kind
;
5148 enum gnu_v3_dtor_kinds dtor_kind
;
5150 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5151 return (enum gnu_v3_dtor_kinds
) 0;
5155 #endif /* IN_GLIBCPP_V3 */
5157 #ifdef STANDALONE_DEMANGLER
5160 #include "dyn-string.h"
5162 static void print_usage (FILE* fp
, int exit_value
);
5164 #define IS_ALPHA(CHAR) \
5165 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5166 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5168 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5169 #define is_mangled_char(CHAR) \
5170 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5171 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5173 /* The name of this program, as invoked. */
5174 const char* program_name
;
5176 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5179 print_usage (FILE* fp
, int exit_value
)
5181 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5182 fprintf (fp
, "Options:\n");
5183 fprintf (fp
, " -h,--help Display this message.\n");
5184 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5185 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5186 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5191 /* Option specification for getopt_long. */
5192 static const struct option long_options
[] =
5194 { "help", no_argument
, NULL
, 'h' },
5195 { "no-params", no_argument
, NULL
, 'p' },
5196 { "verbose", no_argument
, NULL
, 'v' },
5197 { NULL
, no_argument
, NULL
, 0 },
5200 /* Main entry for a demangling filter executable. It will demangle
5201 its command line arguments, if any. If none are provided, it will
5202 filter stdin to stdout, replacing any recognized mangled C++ names
5203 with their demangled equivalents. */
5206 main (int argc
, char *argv
[])
5210 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5212 /* Use the program name of this program, as invoked. */
5213 program_name
= argv
[0];
5215 /* Parse options. */
5218 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5221 case '?': /* Unrecognized option. */
5222 print_usage (stderr
, 1);
5226 print_usage (stdout
, 0);
5230 options
&= ~ DMGL_PARAMS
;
5234 options
|= DMGL_VERBOSE
;
5238 while (opt_char
!= -1);
5241 /* No command line arguments were provided. Filter stdin. */
5243 dyn_string_t mangled
= dyn_string_new (3);
5246 /* Read all of input. */
5247 while (!feof (stdin
))
5251 /* Pile characters into mangled until we hit one that can't
5252 occur in a mangled name. */
5254 while (!feof (stdin
) && is_mangled_char (c
))
5256 dyn_string_append_char (mangled
, c
);
5262 if (dyn_string_length (mangled
) > 0)
5264 #ifdef IN_GLIBCPP_V3
5265 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
5267 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
5277 /* It might not have been a mangled name. Print the
5279 fputs (dyn_string_buf (mangled
), stdout
);
5282 dyn_string_clear (mangled
);
5285 /* If we haven't hit EOF yet, we've read one character that
5286 can't occur in a mangled name, so print it out. */
5291 dyn_string_delete (mangled
);
5294 /* Demangle command line arguments. */
5296 /* Loop over command line arguments. */
5297 for (i
= optind
; i
< argc
; ++i
)
5300 #ifdef IN_GLIBCPP_V3
5304 /* Attempt to demangle. */
5305 #ifdef IN_GLIBCPP_V3
5306 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
5308 s
= cplus_demangle_v3 (argv
[i
], options
);
5311 /* If it worked, print the demangled name. */
5319 #ifdef IN_GLIBCPP_V3
5320 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
5322 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
5331 #endif /* STANDALONE_DEMANGLER */