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
305 /* Number of d_print_flush calls so far. */
306 unsigned long int flush_count
;
309 #ifdef CP_DEMANGLE_DEBUG
310 static void d_dump (struct demangle_component
*, int);
313 static struct demangle_component
*
314 d_make_empty (struct d_info
*);
316 static struct demangle_component
*
317 d_make_comp (struct d_info
*, enum demangle_component_type
,
318 struct demangle_component
*,
319 struct demangle_component
*);
321 static struct demangle_component
*
322 d_make_name (struct d_info
*, const char *, int);
324 static struct demangle_component
*
325 d_make_demangle_mangled_name (struct d_info
*, const char *);
327 static struct demangle_component
*
328 d_make_builtin_type (struct d_info
*,
329 const struct demangle_builtin_type_info
*);
331 static struct demangle_component
*
332 d_make_operator (struct d_info
*,
333 const struct demangle_operator_info
*);
335 static struct demangle_component
*
336 d_make_extended_operator (struct d_info
*, int,
337 struct demangle_component
*);
339 static struct demangle_component
*
340 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
341 struct demangle_component
*);
343 static struct demangle_component
*
344 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
345 struct demangle_component
*);
347 static struct demangle_component
*
348 d_make_template_param (struct d_info
*, long);
350 static struct demangle_component
*
351 d_make_sub (struct d_info
*, const char *, int);
354 has_return_type (struct demangle_component
*);
357 is_ctor_dtor_or_conversion (struct demangle_component
*);
359 static struct demangle_component
*d_encoding (struct d_info
*, int);
361 static struct demangle_component
*d_name (struct d_info
*);
363 static struct demangle_component
*d_nested_name (struct d_info
*);
365 static struct demangle_component
*d_prefix (struct d_info
*);
367 static struct demangle_component
*d_unqualified_name (struct d_info
*);
369 static struct demangle_component
*d_source_name (struct d_info
*);
371 static long d_number (struct d_info
*);
373 static struct demangle_component
*d_identifier (struct d_info
*, int);
375 static struct demangle_component
*d_operator_name (struct d_info
*);
377 static struct demangle_component
*d_special_name (struct d_info
*);
379 static int d_call_offset (struct d_info
*, int);
381 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
383 static struct demangle_component
**
384 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
386 static struct demangle_component
*
387 d_function_type (struct d_info
*);
389 static struct demangle_component
*
390 d_bare_function_type (struct d_info
*, int);
392 static struct demangle_component
*
393 d_class_enum_type (struct d_info
*);
395 static struct demangle_component
*d_array_type (struct d_info
*);
397 static struct demangle_component
*d_vector_type (struct d_info
*);
399 static struct demangle_component
*
400 d_pointer_to_member_type (struct d_info
*);
402 static struct demangle_component
*
403 d_template_param (struct d_info
*);
405 static struct demangle_component
*d_template_args (struct d_info
*);
407 static struct demangle_component
*
408 d_template_arg (struct d_info
*);
410 static struct demangle_component
*d_expression (struct d_info
*);
412 static struct demangle_component
*d_expr_primary (struct d_info
*);
414 static struct demangle_component
*d_local_name (struct d_info
*);
416 static int d_discriminator (struct d_info
*);
418 static struct demangle_component
*d_lambda (struct d_info
*);
420 static struct demangle_component
*d_unnamed_type (struct d_info
*);
423 d_add_substitution (struct d_info
*, struct demangle_component
*);
425 static struct demangle_component
*d_substitution (struct d_info
*, int);
427 static void d_growable_string_init (struct d_growable_string
*, size_t);
430 d_growable_string_resize (struct d_growable_string
*, size_t);
433 d_growable_string_append_buffer (struct d_growable_string
*,
434 const char *, size_t);
436 d_growable_string_callback_adapter (const char *, size_t, void *);
439 d_print_init (struct d_print_info
*, int, demangle_callbackref
, void *);
441 static inline void d_print_error (struct d_print_info
*);
443 static inline int d_print_saw_error (struct d_print_info
*);
445 static inline void d_print_flush (struct d_print_info
*);
447 static inline void d_append_char (struct d_print_info
*, char);
449 static inline void d_append_buffer (struct d_print_info
*,
450 const char *, size_t);
452 static inline void d_append_string (struct d_print_info
*, const char *);
454 static inline char d_last_char (struct d_print_info
*);
457 d_print_comp (struct d_print_info
*, const struct demangle_component
*);
460 d_print_java_identifier (struct d_print_info
*, const char *, int);
463 d_print_mod_list (struct d_print_info
*, struct d_print_mod
*, int);
466 d_print_mod (struct d_print_info
*, const struct demangle_component
*);
469 d_print_function_type (struct d_print_info
*,
470 const struct demangle_component
*,
471 struct d_print_mod
*);
474 d_print_array_type (struct d_print_info
*,
475 const struct demangle_component
*,
476 struct d_print_mod
*);
479 d_print_expr_op (struct d_print_info
*, const struct demangle_component
*);
482 d_print_cast (struct d_print_info
*, const struct demangle_component
*);
484 static int d_demangle_callback (const char *, int,
485 demangle_callbackref
, void *);
486 static char *d_demangle (const char *, int, size_t *);
488 #ifdef CP_DEMANGLE_DEBUG
491 d_dump (struct demangle_component
*dc
, int indent
)
498 printf ("failed demangling\n");
502 for (i
= 0; i
< indent
; ++i
)
507 case DEMANGLE_COMPONENT_NAME
:
508 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
510 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
511 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
513 case DEMANGLE_COMPONENT_CTOR
:
514 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
515 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
517 case DEMANGLE_COMPONENT_DTOR
:
518 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
519 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
521 case DEMANGLE_COMPONENT_SUB_STD
:
522 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
524 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
525 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
527 case DEMANGLE_COMPONENT_OPERATOR
:
528 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
530 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
531 printf ("extended operator with %d args\n",
532 dc
->u
.s_extended_operator
.args
);
533 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
536 case DEMANGLE_COMPONENT_QUAL_NAME
:
537 printf ("qualified name\n");
539 case DEMANGLE_COMPONENT_LOCAL_NAME
:
540 printf ("local name\n");
542 case DEMANGLE_COMPONENT_TYPED_NAME
:
543 printf ("typed name\n");
545 case DEMANGLE_COMPONENT_TEMPLATE
:
546 printf ("template\n");
548 case DEMANGLE_COMPONENT_VTABLE
:
551 case DEMANGLE_COMPONENT_VTT
:
554 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
555 printf ("construction vtable\n");
557 case DEMANGLE_COMPONENT_TYPEINFO
:
558 printf ("typeinfo\n");
560 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
561 printf ("typeinfo name\n");
563 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
564 printf ("typeinfo function\n");
566 case DEMANGLE_COMPONENT_THUNK
:
569 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
570 printf ("virtual thunk\n");
572 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
573 printf ("covariant thunk\n");
575 case DEMANGLE_COMPONENT_JAVA_CLASS
:
576 printf ("java class\n");
578 case DEMANGLE_COMPONENT_GUARD
:
581 case DEMANGLE_COMPONENT_REFTEMP
:
582 printf ("reference temporary\n");
584 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
585 printf ("hidden alias\n");
587 case DEMANGLE_COMPONENT_RESTRICT
:
588 printf ("restrict\n");
590 case DEMANGLE_COMPONENT_VOLATILE
:
591 printf ("volatile\n");
593 case DEMANGLE_COMPONENT_CONST
:
596 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
597 printf ("restrict this\n");
599 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
600 printf ("volatile this\n");
602 case DEMANGLE_COMPONENT_CONST_THIS
:
603 printf ("const this\n");
605 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
606 printf ("vendor type qualifier\n");
608 case DEMANGLE_COMPONENT_POINTER
:
609 printf ("pointer\n");
611 case DEMANGLE_COMPONENT_REFERENCE
:
612 printf ("reference\n");
614 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
615 printf ("rvalue reference\n");
617 case DEMANGLE_COMPONENT_COMPLEX
:
618 printf ("complex\n");
620 case DEMANGLE_COMPONENT_IMAGINARY
:
621 printf ("imaginary\n");
623 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
624 printf ("vendor type\n");
626 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
627 printf ("function type\n");
629 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
630 printf ("array type\n");
632 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
633 printf ("pointer to member type\n");
635 case DEMANGLE_COMPONENT_FIXED_TYPE
:
636 printf ("fixed-point type\n");
638 case DEMANGLE_COMPONENT_ARGLIST
:
639 printf ("argument list\n");
641 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
642 printf ("template argument list\n");
644 case DEMANGLE_COMPONENT_CAST
:
647 case DEMANGLE_COMPONENT_UNARY
:
648 printf ("unary operator\n");
650 case DEMANGLE_COMPONENT_BINARY
:
651 printf ("binary operator\n");
653 case DEMANGLE_COMPONENT_BINARY_ARGS
:
654 printf ("binary operator arguments\n");
656 case DEMANGLE_COMPONENT_TRINARY
:
657 printf ("trinary operator\n");
659 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
660 printf ("trinary operator arguments 1\n");
662 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
663 printf ("trinary operator arguments 1\n");
665 case DEMANGLE_COMPONENT_LITERAL
:
666 printf ("literal\n");
668 case DEMANGLE_COMPONENT_LITERAL_NEG
:
669 printf ("negative literal\n");
671 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
672 printf ("java resource\n");
674 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
675 printf ("compound name\n");
677 case DEMANGLE_COMPONENT_CHARACTER
:
678 printf ("character '%c'\n", dc
->u
.s_character
.character
);
680 case DEMANGLE_COMPONENT_DECLTYPE
:
681 printf ("decltype\n");
683 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
684 printf ("pack expansion\n");
688 d_dump (d_left (dc
), indent
+ 2);
689 d_dump (d_right (dc
), indent
+ 2);
692 #endif /* CP_DEMANGLE_DEBUG */
694 /* Fill in a DEMANGLE_COMPONENT_NAME. */
696 CP_STATIC_IF_GLIBCPP_V3
698 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
700 if (p
== NULL
|| s
== NULL
|| len
== 0)
702 p
->type
= DEMANGLE_COMPONENT_NAME
;
704 p
->u
.s_name
.len
= len
;
708 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
710 CP_STATIC_IF_GLIBCPP_V3
712 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
713 struct demangle_component
*name
)
715 if (p
== NULL
|| args
< 0 || name
== NULL
)
717 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
718 p
->u
.s_extended_operator
.args
= args
;
719 p
->u
.s_extended_operator
.name
= name
;
723 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
725 CP_STATIC_IF_GLIBCPP_V3
727 cplus_demangle_fill_ctor (struct demangle_component
*p
,
728 enum gnu_v3_ctor_kinds kind
,
729 struct demangle_component
*name
)
733 || (int) kind
< gnu_v3_complete_object_ctor
734 || (int) kind
> gnu_v3_complete_object_allocating_ctor
)
736 p
->type
= DEMANGLE_COMPONENT_CTOR
;
737 p
->u
.s_ctor
.kind
= kind
;
738 p
->u
.s_ctor
.name
= name
;
742 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
744 CP_STATIC_IF_GLIBCPP_V3
746 cplus_demangle_fill_dtor (struct demangle_component
*p
,
747 enum gnu_v3_dtor_kinds kind
,
748 struct demangle_component
*name
)
752 || (int) kind
< gnu_v3_deleting_dtor
753 || (int) kind
> gnu_v3_base_object_dtor
)
755 p
->type
= DEMANGLE_COMPONENT_DTOR
;
756 p
->u
.s_dtor
.kind
= kind
;
757 p
->u
.s_dtor
.name
= name
;
761 /* Add a new component. */
763 static struct demangle_component
*
764 d_make_empty (struct d_info
*di
)
766 struct demangle_component
*p
;
768 if (di
->next_comp
>= di
->num_comps
)
770 p
= &di
->comps
[di
->next_comp
];
775 /* Add a new generic component. */
777 static struct demangle_component
*
778 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
779 struct demangle_component
*left
,
780 struct demangle_component
*right
)
782 struct demangle_component
*p
;
784 /* We check for errors here. A typical error would be a NULL return
785 from a subroutine. We catch those here, and return NULL
789 /* These types require two parameters. */
790 case DEMANGLE_COMPONENT_QUAL_NAME
:
791 case DEMANGLE_COMPONENT_LOCAL_NAME
:
792 case DEMANGLE_COMPONENT_TYPED_NAME
:
793 case DEMANGLE_COMPONENT_TEMPLATE
:
794 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
795 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
796 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
797 case DEMANGLE_COMPONENT_UNARY
:
798 case DEMANGLE_COMPONENT_BINARY
:
799 case DEMANGLE_COMPONENT_BINARY_ARGS
:
800 case DEMANGLE_COMPONENT_TRINARY
:
801 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
802 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
803 case DEMANGLE_COMPONENT_LITERAL
:
804 case DEMANGLE_COMPONENT_LITERAL_NEG
:
805 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
806 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
807 if (left
== NULL
|| right
== NULL
)
811 /* These types only require one parameter. */
812 case DEMANGLE_COMPONENT_VTABLE
:
813 case DEMANGLE_COMPONENT_VTT
:
814 case DEMANGLE_COMPONENT_TYPEINFO
:
815 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
816 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
817 case DEMANGLE_COMPONENT_THUNK
:
818 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
819 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
820 case DEMANGLE_COMPONENT_JAVA_CLASS
:
821 case DEMANGLE_COMPONENT_GUARD
:
822 case DEMANGLE_COMPONENT_REFTEMP
:
823 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
824 case DEMANGLE_COMPONENT_POINTER
:
825 case DEMANGLE_COMPONENT_REFERENCE
:
826 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
827 case DEMANGLE_COMPONENT_COMPLEX
:
828 case DEMANGLE_COMPONENT_IMAGINARY
:
829 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
830 case DEMANGLE_COMPONENT_CAST
:
831 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
832 case DEMANGLE_COMPONENT_DECLTYPE
:
833 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
834 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
835 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
840 /* This needs a right parameter, but the left parameter can be
842 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
847 /* These are allowed to have no parameters--in some cases they
848 will be filled in later. */
849 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
850 case DEMANGLE_COMPONENT_RESTRICT
:
851 case DEMANGLE_COMPONENT_VOLATILE
:
852 case DEMANGLE_COMPONENT_CONST
:
853 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
854 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
855 case DEMANGLE_COMPONENT_CONST_THIS
:
856 case DEMANGLE_COMPONENT_ARGLIST
:
857 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
860 /* Other types should not be seen here. */
865 p
= d_make_empty (di
);
869 p
->u
.s_binary
.left
= left
;
870 p
->u
.s_binary
.right
= right
;
875 /* Add a new demangle mangled name component. */
877 static struct demangle_component
*
878 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
880 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
881 return d_make_name (di
, s
, strlen (s
));
883 return d_encoding (di
, 0);
886 /* Add a new name component. */
888 static struct demangle_component
*
889 d_make_name (struct d_info
*di
, const char *s
, int len
)
891 struct demangle_component
*p
;
893 p
= d_make_empty (di
);
894 if (! cplus_demangle_fill_name (p
, s
, len
))
899 /* Add a new builtin type component. */
901 static struct demangle_component
*
902 d_make_builtin_type (struct d_info
*di
,
903 const struct demangle_builtin_type_info
*type
)
905 struct demangle_component
*p
;
909 p
= d_make_empty (di
);
912 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
913 p
->u
.s_builtin
.type
= type
;
918 /* Add a new operator component. */
920 static struct demangle_component
*
921 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
923 struct demangle_component
*p
;
925 p
= d_make_empty (di
);
928 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
929 p
->u
.s_operator
.op
= op
;
934 /* Add a new extended operator component. */
936 static struct demangle_component
*
937 d_make_extended_operator (struct d_info
*di
, int args
,
938 struct demangle_component
*name
)
940 struct demangle_component
*p
;
942 p
= d_make_empty (di
);
943 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
948 static struct demangle_component
*
949 d_make_default_arg (struct d_info
*di
, int num
,
950 struct demangle_component
*sub
)
952 struct demangle_component
*p
= d_make_empty (di
);
955 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
956 p
->u
.s_unary_num
.num
= num
;
957 p
->u
.s_unary_num
.sub
= sub
;
962 /* Add a new constructor component. */
964 static struct demangle_component
*
965 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
966 struct demangle_component
*name
)
968 struct demangle_component
*p
;
970 p
= d_make_empty (di
);
971 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
976 /* Add a new destructor component. */
978 static struct demangle_component
*
979 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
980 struct demangle_component
*name
)
982 struct demangle_component
*p
;
984 p
= d_make_empty (di
);
985 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
990 /* Add a new template parameter. */
992 static struct demangle_component
*
993 d_make_template_param (struct d_info
*di
, long i
)
995 struct demangle_component
*p
;
997 p
= d_make_empty (di
);
1000 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1001 p
->u
.s_number
.number
= i
;
1006 /* Add a new function parameter. */
1008 static struct demangle_component
*
1009 d_make_function_param (struct d_info
*di
, long i
)
1011 struct demangle_component
*p
;
1013 p
= d_make_empty (di
);
1016 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1017 p
->u
.s_number
.number
= i
;
1022 /* Add a new standard substitution component. */
1024 static struct demangle_component
*
1025 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1027 struct demangle_component
*p
;
1029 p
= d_make_empty (di
);
1032 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1033 p
->u
.s_string
.string
= name
;
1034 p
->u
.s_string
.len
= len
;
1039 /* <mangled-name> ::= _Z <encoding>
1041 TOP_LEVEL is non-zero when called at the top level. */
1043 CP_STATIC_IF_GLIBCPP_V3
1044 struct demangle_component
*
1045 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1047 if (! d_check_char (di
, '_')
1048 /* Allow missing _ if not at toplevel to work around a
1049 bug in G++ abi-version=2 mangling; see the comment in
1050 write_template_arg. */
1053 if (! d_check_char (di
, 'Z'))
1055 return d_encoding (di
, top_level
);
1058 /* Return whether a function should have a return type. The argument
1059 is the function name, which may be qualified in various ways. The
1060 rules are that template functions have return types with some
1061 exceptions, function types which are not part of a function name
1062 mangling have return types with some exceptions, and non-template
1063 function names do not have return types. The exceptions are that
1064 constructors, destructors, and conversion operators do not have
1068 has_return_type (struct demangle_component
*dc
)
1076 case DEMANGLE_COMPONENT_TEMPLATE
:
1077 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1078 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1079 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1080 case DEMANGLE_COMPONENT_CONST_THIS
:
1081 return has_return_type (d_left (dc
));
1085 /* Return whether a name is a constructor, a destructor, or a
1086 conversion operator. */
1089 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1097 case DEMANGLE_COMPONENT_QUAL_NAME
:
1098 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1099 return is_ctor_dtor_or_conversion (d_right (dc
));
1100 case DEMANGLE_COMPONENT_CTOR
:
1101 case DEMANGLE_COMPONENT_DTOR
:
1102 case DEMANGLE_COMPONENT_CAST
:
1107 /* <encoding> ::= <(function) name> <bare-function-type>
1111 TOP_LEVEL is non-zero when called at the top level, in which case
1112 if DMGL_PARAMS is not set we do not demangle the function
1113 parameters. We only set this at the top level, because otherwise
1114 we would not correctly demangle names in local scopes. */
1116 static struct demangle_component
*
1117 d_encoding (struct d_info
*di
, int top_level
)
1119 char peek
= d_peek_char (di
);
1121 if (peek
== 'G' || peek
== 'T')
1122 return d_special_name (di
);
1125 struct demangle_component
*dc
;
1129 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1131 /* Strip off any initial CV-qualifiers, as they really apply
1132 to the `this' parameter, and they were not output by the
1133 v2 demangler without DMGL_PARAMS. */
1134 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1135 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1136 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1139 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1140 there may be CV-qualifiers on its right argument which
1141 really apply here; this happens when parsing a class
1142 which is local to a function. */
1143 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1145 struct demangle_component
*dcr
;
1148 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1149 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1150 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1152 dc
->u
.s_binary
.right
= dcr
;
1158 peek
= d_peek_char (di
);
1159 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1161 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1162 d_bare_function_type (di
, has_return_type (dc
)));
1166 /* <name> ::= <nested-name>
1168 ::= <unscoped-template-name> <template-args>
1171 <unscoped-name> ::= <unqualified-name>
1172 ::= St <unqualified-name>
1174 <unscoped-template-name> ::= <unscoped-name>
1178 static struct demangle_component
*
1179 d_name (struct d_info
*di
)
1181 char peek
= d_peek_char (di
);
1182 struct demangle_component
*dc
;
1187 return d_nested_name (di
);
1190 return d_local_name (di
);
1194 return d_unqualified_name (di
);
1200 if (d_peek_next_char (di
) != 't')
1202 dc
= d_substitution (di
, 0);
1208 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1209 d_make_name (di
, "std", 3),
1210 d_unqualified_name (di
));
1215 if (d_peek_char (di
) != 'I')
1217 /* The grammar does not permit this case to occur if we
1218 called d_substitution() above (i.e., subst == 1). We
1219 don't bother to check. */
1223 /* This is <template-args>, which means that we just saw
1224 <unscoped-template-name>, which is a substitution
1225 candidate if we didn't just get it from a
1229 if (! d_add_substitution (di
, dc
))
1232 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1233 d_template_args (di
));
1240 dc
= d_unqualified_name (di
);
1241 if (d_peek_char (di
) == 'I')
1243 /* This is <template-args>, which means that we just saw
1244 <unscoped-template-name>, which is a substitution
1246 if (! d_add_substitution (di
, dc
))
1248 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1249 d_template_args (di
));
1255 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1256 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1259 static struct demangle_component
*
1260 d_nested_name (struct d_info
*di
)
1262 struct demangle_component
*ret
;
1263 struct demangle_component
**pret
;
1265 if (! d_check_char (di
, 'N'))
1268 pret
= d_cv_qualifiers (di
, &ret
, 1);
1272 *pret
= d_prefix (di
);
1276 if (! d_check_char (di
, 'E'))
1282 /* <prefix> ::= <prefix> <unqualified-name>
1283 ::= <template-prefix> <template-args>
1284 ::= <template-param>
1288 <template-prefix> ::= <prefix> <(template) unqualified-name>
1289 ::= <template-param>
1293 static struct demangle_component
*
1294 d_prefix (struct d_info
*di
)
1296 struct demangle_component
*ret
= NULL
;
1301 enum demangle_component_type comb_type
;
1302 struct demangle_component
*dc
;
1304 peek
= d_peek_char (di
);
1308 /* The older code accepts a <local-name> here, but I don't see
1309 that in the grammar. The older code does not accept a
1310 <template-param> here. */
1312 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1319 dc
= d_unqualified_name (di
);
1320 else if (peek
== 'S')
1321 dc
= d_substitution (di
, 1);
1322 else if (peek
== 'I')
1326 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1327 dc
= d_template_args (di
);
1329 else if (peek
== 'T')
1330 dc
= d_template_param (di
);
1331 else if (peek
== 'E')
1333 else if (peek
== 'M')
1335 /* Initializer scope for a lambda. We don't need to represent
1336 this; the normal code will just treat the variable as a type
1337 scope, which gives appropriate output. */
1349 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1351 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1353 if (! d_add_substitution (di
, ret
))
1359 /* <unqualified-name> ::= <operator-name>
1360 ::= <ctor-dtor-name>
1362 ::= <local-source-name>
1364 <local-source-name> ::= L <source-name> <discriminator>
1367 static struct demangle_component
*
1368 d_unqualified_name (struct d_info
*di
)
1372 peek
= d_peek_char (di
);
1373 if (IS_DIGIT (peek
))
1374 return d_source_name (di
);
1375 else if (IS_LOWER (peek
))
1377 struct demangle_component
*ret
;
1379 ret
= d_operator_name (di
);
1380 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1381 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1384 else if (peek
== 'C' || peek
== 'D')
1385 return d_ctor_dtor_name (di
);
1386 else if (peek
== 'L')
1388 struct demangle_component
* ret
;
1392 ret
= d_source_name (di
);
1395 if (! d_discriminator (di
))
1399 else if (peek
== 'U')
1401 switch (d_peek_next_char (di
))
1404 return d_lambda (di
);
1406 return d_unnamed_type (di
);
1415 /* <source-name> ::= <(positive length) number> <identifier> */
1417 static struct demangle_component
*
1418 d_source_name (struct d_info
*di
)
1421 struct demangle_component
*ret
;
1423 len
= d_number (di
);
1426 ret
= d_identifier (di
, len
);
1427 di
->last_name
= ret
;
1431 /* number ::= [n] <(non-negative decimal integer)> */
1434 d_number (struct d_info
*di
)
1441 peek
= d_peek_char (di
);
1446 peek
= d_peek_char (di
);
1452 if (! IS_DIGIT (peek
))
1458 ret
= ret
* 10 + peek
- '0';
1460 peek
= d_peek_char (di
);
1464 /* Like d_number, but returns a demangle_component. */
1466 static struct demangle_component
*
1467 d_number_component (struct d_info
*di
)
1469 struct demangle_component
*ret
= d_make_empty (di
);
1472 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1473 ret
->u
.s_number
.number
= d_number (di
);
1478 /* identifier ::= <(unqualified source code identifier)> */
1480 static struct demangle_component
*
1481 d_identifier (struct d_info
*di
, int len
)
1487 if (di
->send
- name
< len
)
1490 d_advance (di
, len
);
1492 /* A Java mangled name may have a trailing '$' if it is a C++
1493 keyword. This '$' is not included in the length count. We just
1495 if ((di
->options
& DMGL_JAVA
) != 0
1496 && d_peek_char (di
) == '$')
1499 /* Look for something which looks like a gcc encoding of an
1500 anonymous namespace, and replace it with a more user friendly
1502 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1503 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1504 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1508 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1509 if ((*s
== '.' || *s
== '_' || *s
== '$')
1512 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1513 return d_make_name (di
, "(anonymous namespace)",
1514 sizeof "(anonymous namespace)" - 1);
1518 return d_make_name (di
, name
, len
);
1521 /* operator_name ::= many different two character encodings.
1523 ::= v <digit> <source-name>
1526 #define NL(s) s, (sizeof s) - 1
1528 CP_STATIC_IF_GLIBCPP_V3
1529 const struct demangle_operator_info cplus_demangle_operators
[] =
1531 { "aN", NL ("&="), 2 },
1532 { "aS", NL ("="), 2 },
1533 { "aa", NL ("&&"), 2 },
1534 { "ad", NL ("&"), 1 },
1535 { "an", NL ("&"), 2 },
1536 { "cl", NL ("()"), 2 },
1537 { "cm", NL (","), 2 },
1538 { "co", NL ("~"), 1 },
1539 { "dV", NL ("/="), 2 },
1540 { "da", NL ("delete[]"), 1 },
1541 { "de", NL ("*"), 1 },
1542 { "dl", NL ("delete"), 1 },
1543 { "dt", NL ("."), 2 },
1544 { "dv", NL ("/"), 2 },
1545 { "eO", NL ("^="), 2 },
1546 { "eo", NL ("^"), 2 },
1547 { "eq", NL ("=="), 2 },
1548 { "ge", NL (">="), 2 },
1549 { "gt", NL (">"), 2 },
1550 { "ix", NL ("[]"), 2 },
1551 { "lS", NL ("<<="), 2 },
1552 { "le", NL ("<="), 2 },
1553 { "ls", NL ("<<"), 2 },
1554 { "lt", NL ("<"), 2 },
1555 { "mI", NL ("-="), 2 },
1556 { "mL", NL ("*="), 2 },
1557 { "mi", NL ("-"), 2 },
1558 { "ml", NL ("*"), 2 },
1559 { "mm", NL ("--"), 1 },
1560 { "na", NL ("new[]"), 1 },
1561 { "ne", NL ("!="), 2 },
1562 { "ng", NL ("-"), 1 },
1563 { "nt", NL ("!"), 1 },
1564 { "nw", NL ("new"), 1 },
1565 { "oR", NL ("|="), 2 },
1566 { "oo", NL ("||"), 2 },
1567 { "or", NL ("|"), 2 },
1568 { "pL", NL ("+="), 2 },
1569 { "pl", NL ("+"), 2 },
1570 { "pm", NL ("->*"), 2 },
1571 { "pp", NL ("++"), 1 },
1572 { "ps", NL ("+"), 1 },
1573 { "pt", NL ("->"), 2 },
1574 { "qu", NL ("?"), 3 },
1575 { "rM", NL ("%="), 2 },
1576 { "rS", NL (">>="), 2 },
1577 { "rm", NL ("%"), 2 },
1578 { "rs", NL (">>"), 2 },
1579 { "st", NL ("sizeof "), 1 },
1580 { "sz", NL ("sizeof "), 1 },
1581 { "at", NL ("alignof "), 1 },
1582 { "az", NL ("alignof "), 1 },
1583 { NULL
, NULL
, 0, 0 }
1586 static struct demangle_component
*
1587 d_operator_name (struct d_info
*di
)
1592 c1
= d_next_char (di
);
1593 c2
= d_next_char (di
);
1594 if (c1
== 'v' && IS_DIGIT (c2
))
1595 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1596 else if (c1
== 'c' && c2
== 'v')
1597 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1598 cplus_demangle_type (di
), NULL
);
1601 /* LOW is the inclusive lower bound. */
1603 /* HIGH is the exclusive upper bound. We subtract one to ignore
1604 the sentinel at the end of the array. */
1605 int high
= ((sizeof (cplus_demangle_operators
)
1606 / sizeof (cplus_demangle_operators
[0]))
1612 const struct demangle_operator_info
*p
;
1614 i
= low
+ (high
- low
) / 2;
1615 p
= cplus_demangle_operators
+ i
;
1617 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1618 return d_make_operator (di
, p
);
1620 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1630 static struct demangle_component
*
1631 d_make_character (struct d_info
*di
, int c
)
1633 struct demangle_component
*p
;
1634 p
= d_make_empty (di
);
1637 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1638 p
->u
.s_character
.character
= c
;
1643 static struct demangle_component
*
1644 d_java_resource (struct d_info
*di
)
1646 struct demangle_component
*p
= NULL
;
1647 struct demangle_component
*next
= NULL
;
1652 len
= d_number (di
);
1656 /* Eat the leading '_'. */
1657 if (d_next_char (di
) != '_')
1670 /* Each chunk is either a '$' escape... */
1688 next
= d_make_character (di
, c
);
1696 /* ... or a sequence of characters. */
1699 while (i
< len
&& str
[i
] && str
[i
] != '$')
1702 next
= d_make_name (di
, str
, i
);
1715 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1721 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1726 /* <special-name> ::= TV <type>
1730 ::= GV <(object) name>
1731 ::= T <call-offset> <(base) encoding>
1732 ::= Tc <call-offset> <call-offset> <(base) encoding>
1733 Also g++ extensions:
1734 ::= TC <type> <(offset) number> _ <(base) type>
1739 ::= Gr <resource name>
1742 static struct demangle_component
*
1743 d_special_name (struct d_info
*di
)
1745 di
->expansion
+= 20;
1746 if (d_check_char (di
, 'T'))
1748 switch (d_next_char (di
))
1752 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1753 cplus_demangle_type (di
), NULL
);
1755 di
->expansion
-= 10;
1756 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1757 cplus_demangle_type (di
), NULL
);
1759 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1760 cplus_demangle_type (di
), NULL
);
1762 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1763 cplus_demangle_type (di
), NULL
);
1766 if (! d_call_offset (di
, 'h'))
1768 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1769 d_encoding (di
, 0), NULL
);
1772 if (! d_call_offset (di
, 'v'))
1774 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1775 d_encoding (di
, 0), NULL
);
1778 if (! d_call_offset (di
, '\0'))
1780 if (! d_call_offset (di
, '\0'))
1782 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1783 d_encoding (di
, 0), NULL
);
1787 struct demangle_component
*derived_type
;
1789 struct demangle_component
*base_type
;
1791 derived_type
= cplus_demangle_type (di
);
1792 offset
= d_number (di
);
1795 if (! d_check_char (di
, '_'))
1797 base_type
= cplus_demangle_type (di
);
1798 /* We don't display the offset. FIXME: We should display
1799 it in verbose mode. */
1801 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1802 base_type
, derived_type
);
1806 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1807 cplus_demangle_type (di
), NULL
);
1809 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1810 cplus_demangle_type (di
), NULL
);
1816 else if (d_check_char (di
, 'G'))
1818 switch (d_next_char (di
))
1821 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1824 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, d_name (di
),
1828 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1829 d_encoding (di
, 0), NULL
);
1832 return d_java_resource (di
);
1842 /* <call-offset> ::= h <nv-offset> _
1845 <nv-offset> ::= <(offset) number>
1847 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1849 The C parameter, if not '\0', is a character we just read which is
1850 the start of the <call-offset>.
1852 We don't display the offset information anywhere. FIXME: We should
1853 display it in verbose mode. */
1856 d_call_offset (struct d_info
*di
, int c
)
1859 c
= d_next_char (di
);
1866 if (! d_check_char (di
, '_'))
1873 if (! d_check_char (di
, '_'))
1879 /* <ctor-dtor-name> ::= C1
1887 static struct demangle_component
*
1888 d_ctor_dtor_name (struct d_info
*di
)
1890 if (di
->last_name
!= NULL
)
1892 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1893 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1894 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1895 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1897 switch (d_peek_char (di
))
1901 enum gnu_v3_ctor_kinds kind
;
1903 switch (d_peek_next_char (di
))
1906 kind
= gnu_v3_complete_object_ctor
;
1909 kind
= gnu_v3_base_object_ctor
;
1912 kind
= gnu_v3_complete_object_allocating_ctor
;
1918 return d_make_ctor (di
, kind
, di
->last_name
);
1923 enum gnu_v3_dtor_kinds kind
;
1925 switch (d_peek_next_char (di
))
1928 kind
= gnu_v3_deleting_dtor
;
1931 kind
= gnu_v3_complete_object_dtor
;
1934 kind
= gnu_v3_base_object_dtor
;
1940 return d_make_dtor (di
, kind
, di
->last_name
);
1948 /* <type> ::= <builtin-type>
1950 ::= <class-enum-type>
1952 ::= <pointer-to-member-type>
1953 ::= <template-param>
1954 ::= <template-template-param> <template-args>
1956 ::= <CV-qualifiers> <type>
1959 ::= O <type> (C++0x)
1962 ::= U <source-name> <type>
1964 <builtin-type> ::= various one letter codes
1968 CP_STATIC_IF_GLIBCPP_V3
1969 const struct demangle_builtin_type_info
1970 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
1972 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
1973 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
1974 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
1975 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
1976 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
1977 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
1978 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
1979 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
1980 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
1981 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
1982 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1983 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
1984 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
1985 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
1986 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
1988 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1989 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1990 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1991 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
1992 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
1993 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1994 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
1995 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
1996 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
1997 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
1998 D_PRINT_UNSIGNED_LONG_LONG
},
1999 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2000 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2001 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2002 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2003 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2004 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2005 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2006 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2010 CP_STATIC_IF_GLIBCPP_V3
2011 struct demangle_component
*
2012 cplus_demangle_type (struct d_info
*di
)
2015 struct demangle_component
*ret
;
2018 /* The ABI specifies that when CV-qualifiers are used, the base type
2019 is substitutable, and the fully qualified type is substitutable,
2020 but the base type with a strict subset of the CV-qualifiers is
2021 not substitutable. The natural recursive implementation of the
2022 CV-qualifiers would cause subsets to be substitutable, so instead
2023 we pull them all off now.
2025 FIXME: The ABI says that order-insensitive vendor qualifiers
2026 should be handled in the same way, but we have no way to tell
2027 which vendor qualifiers are order-insensitive and which are
2028 order-sensitive. So we just assume that they are all
2029 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2030 __vector, and it treats it as order-sensitive when mangling
2033 peek
= d_peek_char (di
);
2034 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2036 struct demangle_component
**pret
;
2038 pret
= d_cv_qualifiers (di
, &ret
, 0);
2041 *pret
= cplus_demangle_type (di
);
2042 if (! *pret
|| ! d_add_substitution (di
, ret
))
2051 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2052 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2053 case 'o': case 's': case 't':
2054 case 'v': case 'w': case 'x': case 'y': case 'z':
2055 ret
= d_make_builtin_type (di
,
2056 &cplus_demangle_builtin_types
[peek
- 'a']);
2057 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2064 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2065 d_source_name (di
), NULL
);
2069 ret
= d_function_type (di
);
2072 case '0': case '1': case '2': case '3': case '4':
2073 case '5': case '6': case '7': case '8': case '9':
2076 ret
= d_class_enum_type (di
);
2080 ret
= d_array_type (di
);
2084 ret
= d_pointer_to_member_type (di
);
2088 ret
= d_template_param (di
);
2089 if (d_peek_char (di
) == 'I')
2091 /* This is <template-template-param> <template-args>. The
2092 <template-template-param> part is a substitution
2094 if (! d_add_substitution (di
, ret
))
2096 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2097 d_template_args (di
));
2102 /* If this is a special substitution, then it is the start of
2103 <class-enum-type>. */
2107 peek_next
= d_peek_next_char (di
);
2108 if (IS_DIGIT (peek_next
)
2110 || IS_UPPER (peek_next
))
2112 ret
= d_substitution (di
, 0);
2113 /* The substituted name may have been a template name and
2114 may be followed by tepmlate args. */
2115 if (d_peek_char (di
) == 'I')
2116 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2117 d_template_args (di
));
2123 ret
= d_class_enum_type (di
);
2124 /* If the substitution was a complete type, then it is not
2125 a new substitution candidate. However, if the
2126 substitution was followed by template arguments, then
2127 the whole thing is a substitution candidate. */
2128 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2136 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2137 cplus_demangle_type (di
), NULL
);
2142 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2143 cplus_demangle_type (di
), NULL
);
2148 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2149 cplus_demangle_type (di
), NULL
);
2154 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2155 cplus_demangle_type (di
), NULL
);
2160 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2161 cplus_demangle_type (di
), NULL
);
2166 ret
= d_source_name (di
);
2167 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2168 cplus_demangle_type (di
), ret
);
2174 peek
= d_next_char (di
);
2179 /* decltype (expression) */
2180 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2181 d_expression (di
), NULL
);
2182 if (ret
&& d_next_char (di
) != 'E')
2187 /* Pack expansion. */
2188 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2189 cplus_demangle_type (di
), NULL
);
2193 /* 32-bit decimal floating point */
2194 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2195 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2199 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2200 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2204 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2205 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2208 /* 16-bit half-precision FP */
2209 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2210 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2214 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2215 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2219 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2220 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2224 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2225 ret
= d_make_empty (di
);
2226 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2227 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2228 /* For demangling we don't care about the bits. */
2230 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2231 if (ret
->u
.s_fixed
.length
== NULL
)
2234 peek
= d_next_char (di
);
2235 ret
->u
.s_fixed
.sat
= (peek
== 's');
2239 ret
= d_vector_type (di
);
2243 /* decltype(nullptr) */
2244 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2245 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2259 if (! d_add_substitution (di
, ret
))
2266 /* <CV-qualifiers> ::= [r] [V] [K] */
2268 static struct demangle_component
**
2269 d_cv_qualifiers (struct d_info
*di
,
2270 struct demangle_component
**pret
, int member_fn
)
2274 peek
= d_peek_char (di
);
2275 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2277 enum demangle_component_type t
;
2283 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2284 : DEMANGLE_COMPONENT_RESTRICT
);
2285 di
->expansion
+= sizeof "restrict";
2287 else if (peek
== 'V')
2290 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2291 : DEMANGLE_COMPONENT_VOLATILE
);
2292 di
->expansion
+= sizeof "volatile";
2297 ? DEMANGLE_COMPONENT_CONST_THIS
2298 : DEMANGLE_COMPONENT_CONST
);
2299 di
->expansion
+= sizeof "const";
2302 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2305 pret
= &d_left (*pret
);
2307 peek
= d_peek_char (di
);
2313 /* <function-type> ::= F [Y] <bare-function-type> E */
2315 static struct demangle_component
*
2316 d_function_type (struct d_info
*di
)
2318 struct demangle_component
*ret
;
2320 if (! d_check_char (di
, 'F'))
2322 if (d_peek_char (di
) == 'Y')
2324 /* Function has C linkage. We don't print this information.
2325 FIXME: We should print it in verbose mode. */
2328 ret
= d_bare_function_type (di
, 1);
2329 if (! d_check_char (di
, 'E'))
2336 static struct demangle_component
*
2337 d_parmlist (struct d_info
*di
)
2339 struct demangle_component
*tl
;
2340 struct demangle_component
**ptl
;
2346 struct demangle_component
*type
;
2348 char peek
= d_peek_char (di
);
2349 if (peek
== '\0' || peek
== 'E')
2351 type
= cplus_demangle_type (di
);
2354 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2357 ptl
= &d_right (*ptl
);
2360 /* There should be at least one parameter type besides the optional
2361 return type. A function which takes no arguments will have a
2362 single parameter type void. */
2366 /* If we have a single parameter type void, omit it. */
2367 if (d_right (tl
) == NULL
2368 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2369 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2371 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2378 /* <bare-function-type> ::= [J]<type>+ */
2380 static struct demangle_component
*
2381 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2383 struct demangle_component
*return_type
;
2384 struct demangle_component
*tl
;
2387 /* Detect special qualifier indicating that the first argument
2388 is the return type. */
2389 peek
= d_peek_char (di
);
2393 has_return_type
= 1;
2396 if (has_return_type
)
2398 return_type
= cplus_demangle_type (di
);
2399 if (return_type
== NULL
)
2405 tl
= d_parmlist (di
);
2409 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2413 /* <class-enum-type> ::= <name> */
2415 static struct demangle_component
*
2416 d_class_enum_type (struct d_info
*di
)
2421 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2422 ::= A [<(dimension) expression>] _ <(element) type>
2425 static struct demangle_component
*
2426 d_array_type (struct d_info
*di
)
2429 struct demangle_component
*dim
;
2431 if (! d_check_char (di
, 'A'))
2434 peek
= d_peek_char (di
);
2437 else if (IS_DIGIT (peek
))
2445 peek
= d_peek_char (di
);
2447 while (IS_DIGIT (peek
));
2448 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2454 dim
= d_expression (di
);
2459 if (! d_check_char (di
, '_'))
2462 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2463 cplus_demangle_type (di
));
2466 /* <vector-type> ::= Dv <number> _ <type>
2467 ::= Dv _ <expression> _ <type> */
2469 static struct demangle_component
*
2470 d_vector_type (struct d_info
*di
)
2473 struct demangle_component
*dim
;
2475 peek
= d_peek_char (di
);
2479 dim
= d_expression (di
);
2482 dim
= d_number_component (di
);
2487 if (! d_check_char (di
, '_'))
2490 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2491 cplus_demangle_type (di
));
2494 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2496 static struct demangle_component
*
2497 d_pointer_to_member_type (struct d_info
*di
)
2499 struct demangle_component
*cl
;
2500 struct demangle_component
*mem
;
2501 struct demangle_component
**pmem
;
2503 if (! d_check_char (di
, 'M'))
2506 cl
= cplus_demangle_type (di
);
2508 /* The ABI specifies that any type can be a substitution source, and
2509 that M is followed by two types, and that when a CV-qualified
2510 type is seen both the base type and the CV-qualified types are
2511 substitution sources. The ABI also specifies that for a pointer
2512 to a CV-qualified member function, the qualifiers are attached to
2513 the second type. Given the grammar, a plain reading of the ABI
2514 suggests that both the CV-qualified member function and the
2515 non-qualified member function are substitution sources. However,
2516 g++ does not work that way. g++ treats only the CV-qualified
2517 member function as a substitution source. FIXME. So to work
2518 with g++, we need to pull off the CV-qualifiers here, in order to
2519 avoid calling add_substitution() in cplus_demangle_type(). But
2520 for a CV-qualified member which is not a function, g++ does
2521 follow the ABI, so we need to handle that case here by calling
2522 d_add_substitution ourselves. */
2524 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2527 *pmem
= cplus_demangle_type (di
);
2531 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2533 if (! d_add_substitution (di
, mem
))
2537 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2540 /* <non-negative number> _ */
2543 d_compact_number (struct d_info
*di
)
2546 if (d_peek_char (di
) == '_')
2548 else if (d_peek_char (di
) == 'n')
2551 num
= d_number (di
) + 1;
2553 if (! d_check_char (di
, '_'))
2558 /* <template-param> ::= T_
2559 ::= T <(parameter-2 non-negative) number> _
2562 static struct demangle_component
*
2563 d_template_param (struct d_info
*di
)
2567 if (! d_check_char (di
, 'T'))
2570 param
= d_compact_number (di
);
2576 return d_make_template_param (di
, param
);
2579 /* <template-args> ::= I <template-arg>+ E */
2581 static struct demangle_component
*
2582 d_template_args (struct d_info
*di
)
2584 struct demangle_component
*hold_last_name
;
2585 struct demangle_component
*al
;
2586 struct demangle_component
**pal
;
2588 /* Preserve the last name we saw--don't let the template arguments
2589 clobber it, as that would give us the wrong name for a subsequent
2590 constructor or destructor. */
2591 hold_last_name
= di
->last_name
;
2593 if (! d_check_char (di
, 'I'))
2596 if (d_peek_char (di
) == 'E')
2598 /* An argument pack can be empty. */
2600 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2607 struct demangle_component
*a
;
2609 a
= d_template_arg (di
);
2613 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2616 pal
= &d_right (*pal
);
2618 if (d_peek_char (di
) == 'E')
2625 di
->last_name
= hold_last_name
;
2630 /* <template-arg> ::= <type>
2631 ::= X <expression> E
2635 static struct demangle_component
*
2636 d_template_arg (struct d_info
*di
)
2638 struct demangle_component
*ret
;
2640 switch (d_peek_char (di
))
2644 ret
= d_expression (di
);
2645 if (! d_check_char (di
, 'E'))
2650 return d_expr_primary (di
);
2653 /* An argument pack. */
2654 return d_template_args (di
);
2657 return cplus_demangle_type (di
);
2661 /* Subroutine of <expression> ::= cl <expression>+ E */
2663 static struct demangle_component
*
2664 d_exprlist (struct d_info
*di
)
2666 struct demangle_component
*list
= NULL
;
2667 struct demangle_component
**p
= &list
;
2669 if (d_peek_char (di
) == 'E')
2672 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2677 struct demangle_component
*arg
= d_expression (di
);
2681 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2686 if (d_peek_char (di
) == 'E')
2696 /* <expression> ::= <(unary) operator-name> <expression>
2697 ::= <(binary) operator-name> <expression> <expression>
2698 ::= <(trinary) operator-name> <expression> <expression> <expression>
2699 ::= cl <expression>+ E
2701 ::= <template-param>
2702 ::= sr <type> <unqualified-name>
2703 ::= sr <type> <unqualified-name> <template-args>
2707 static struct demangle_component
*
2708 d_expression (struct d_info
*di
)
2712 peek
= d_peek_char (di
);
2714 return d_expr_primary (di
);
2715 else if (peek
== 'T')
2716 return d_template_param (di
);
2717 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2719 struct demangle_component
*type
;
2720 struct demangle_component
*name
;
2723 type
= cplus_demangle_type (di
);
2724 name
= d_unqualified_name (di
);
2725 if (d_peek_char (di
) != 'I')
2726 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2728 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2729 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2730 d_template_args (di
)));
2732 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
2735 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2736 d_expression (di
), NULL
);
2738 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
2740 /* Function parameter used in a late-specified return type. */
2743 index
= d_compact_number (di
);
2747 return d_make_function_param (di
, index
);
2749 else if (IS_DIGIT (peek
)
2750 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
2752 /* We can get an unqualified name as an expression in the case of
2753 a dependent function call, i.e. decltype(f(t)). */
2754 struct demangle_component
*name
;
2757 /* operator-function-id, i.e. operator+(t). */
2760 name
= d_unqualified_name (di
);
2763 if (d_peek_char (di
) == 'I')
2764 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2765 d_template_args (di
));
2771 struct demangle_component
*op
;
2774 op
= d_operator_name (di
);
2778 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2779 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2781 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2782 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2783 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2784 cplus_demangle_type (di
));
2790 case DEMANGLE_COMPONENT_OPERATOR
:
2791 args
= op
->u
.s_operator
.op
->args
;
2793 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2794 args
= op
->u
.s_extended_operator
.args
;
2796 case DEMANGLE_COMPONENT_CAST
:
2805 struct demangle_component
*operand
;
2806 if (op
->type
== DEMANGLE_COMPONENT_CAST
2807 && d_check_char (di
, '_'))
2808 operand
= d_exprlist (di
);
2810 operand
= d_expression (di
);
2811 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2816 struct demangle_component
*left
;
2817 struct demangle_component
*right
;
2818 const char *code
= op
->u
.s_operator
.op
->code
;
2820 left
= d_expression (di
);
2821 if (!strcmp (code
, "cl"))
2822 right
= d_exprlist (di
);
2823 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
2825 right
= d_unqualified_name (di
);
2826 if (d_peek_char (di
) == 'I')
2827 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
2828 right
, d_template_args (di
));
2831 right
= d_expression (di
);
2833 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2835 DEMANGLE_COMPONENT_BINARY_ARGS
,
2840 struct demangle_component
*first
;
2841 struct demangle_component
*second
;
2843 first
= d_expression (di
);
2844 second
= d_expression (di
);
2845 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2847 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2850 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2852 d_expression (di
))));
2860 /* <expr-primary> ::= L <type> <(value) number> E
2861 ::= L <type> <(value) float> E
2862 ::= L <mangled-name> E
2865 static struct demangle_component
*
2866 d_expr_primary (struct d_info
*di
)
2868 struct demangle_component
*ret
;
2870 if (! d_check_char (di
, 'L'))
2872 if (d_peek_char (di
) == '_'
2873 /* Workaround for G++ bug; see comment in write_template_arg. */
2874 || d_peek_char (di
) == 'Z')
2875 ret
= cplus_demangle_mangled_name (di
, 0);
2878 struct demangle_component
*type
;
2879 enum demangle_component_type t
;
2882 type
= cplus_demangle_type (di
);
2886 /* If we have a type we know how to print, we aren't going to
2887 print the type name itself. */
2888 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2889 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2890 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2892 /* Rather than try to interpret the literal value, we just
2893 collect it as a string. Note that it's possible to have a
2894 floating point literal here. The ABI specifies that the
2895 format of such literals is machine independent. That's fine,
2896 but what's not fine is that versions of g++ up to 3.2 with
2897 -fabi-version=1 used upper case letters in the hex constant,
2898 and dumped out gcc's internal representation. That makes it
2899 hard to tell where the constant ends, and hard to dump the
2900 constant in any readable form anyhow. We don't attempt to
2901 handle these cases. */
2903 t
= DEMANGLE_COMPONENT_LITERAL
;
2904 if (d_peek_char (di
) == 'n')
2906 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2910 while (d_peek_char (di
) != 'E')
2912 if (d_peek_char (di
) == '\0')
2916 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2918 if (! d_check_char (di
, 'E'))
2923 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2924 ::= Z <(function) encoding> E s [<discriminator>]
2927 static struct demangle_component
*
2928 d_local_name (struct d_info
*di
)
2930 struct demangle_component
*function
;
2932 if (! d_check_char (di
, 'Z'))
2935 function
= d_encoding (di
, 0);
2937 if (! d_check_char (di
, 'E'))
2940 if (d_peek_char (di
) == 's')
2943 if (! d_discriminator (di
))
2945 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
2946 d_make_name (di
, "string literal",
2947 sizeof "string literal" - 1));
2951 struct demangle_component
*name
;
2954 if (d_peek_char (di
) == 'd')
2956 /* Default argument scope: d <number> _. */
2958 num
= d_compact_number (di
);
2967 /* Lambdas and unnamed types have internal discriminators. */
2968 case DEMANGLE_COMPONENT_LAMBDA
:
2969 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
2972 if (! d_discriminator (di
))
2976 name
= d_make_default_arg (di
, num
, name
);
2977 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
2981 /* <discriminator> ::= _ <(non-negative) number>
2983 We demangle the discriminator, but we don't print it out. FIXME:
2984 We should print it out in verbose mode. */
2987 d_discriminator (struct d_info
*di
)
2991 if (d_peek_char (di
) != '_')
2994 discrim
= d_number (di
);
3000 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3002 static struct demangle_component
*
3003 d_lambda (struct d_info
*di
)
3005 struct demangle_component
*tl
;
3006 struct demangle_component
*ret
;
3009 if (! d_check_char (di
, 'U'))
3011 if (! d_check_char (di
, 'l'))
3014 tl
= d_parmlist (di
);
3018 if (! d_check_char (di
, 'E'))
3021 num
= d_compact_number (di
);
3025 ret
= d_make_empty (di
);
3028 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3029 ret
->u
.s_unary_num
.sub
= tl
;
3030 ret
->u
.s_unary_num
.num
= num
;
3033 if (! d_add_substitution (di
, ret
))
3039 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3041 static struct demangle_component
*
3042 d_unnamed_type (struct d_info
*di
)
3044 struct demangle_component
*ret
;
3047 if (! d_check_char (di
, 'U'))
3049 if (! d_check_char (di
, 't'))
3052 num
= d_compact_number (di
);
3056 ret
= d_make_empty (di
);
3059 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3060 ret
->u
.s_number
.number
= num
;
3063 if (! d_add_substitution (di
, ret
))
3069 /* Add a new substitution. */
3072 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3076 if (di
->next_sub
>= di
->num_subs
)
3078 di
->subs
[di
->next_sub
] = dc
;
3083 /* <substitution> ::= S <seq-id> _
3093 If PREFIX is non-zero, then this type is being used as a prefix in
3094 a qualified name. In this case, for the standard substitutions, we
3095 need to check whether we are being used as a prefix for a
3096 constructor or destructor, and return a full template name.
3097 Otherwise we will get something like std::iostream::~iostream()
3098 which does not correspond particularly well to any function which
3099 actually appears in the source.
3102 static const struct d_standard_sub_info standard_subs
[] =
3107 { 'a', NL ("std::allocator"),
3108 NL ("std::allocator"),
3110 { 'b', NL ("std::basic_string"),
3111 NL ("std::basic_string"),
3112 NL ("basic_string") },
3113 { 's', NL ("std::string"),
3114 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3115 NL ("basic_string") },
3116 { 'i', NL ("std::istream"),
3117 NL ("std::basic_istream<char, std::char_traits<char> >"),
3118 NL ("basic_istream") },
3119 { 'o', NL ("std::ostream"),
3120 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3121 NL ("basic_ostream") },
3122 { 'd', NL ("std::iostream"),
3123 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3124 NL ("basic_iostream") }
3127 static struct demangle_component
*
3128 d_substitution (struct d_info
*di
, int prefix
)
3132 if (! d_check_char (di
, 'S'))
3135 c
= d_next_char (di
);
3136 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3145 unsigned int new_id
;
3148 new_id
= id
* 36 + c
- '0';
3149 else if (IS_UPPER (c
))
3150 new_id
= id
* 36 + c
- 'A' + 10;
3156 c
= d_next_char (di
);
3163 if (id
>= (unsigned int) di
->next_sub
)
3168 return di
->subs
[id
];
3173 const struct d_standard_sub_info
*p
;
3174 const struct d_standard_sub_info
*pend
;
3176 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3177 if (! verbose
&& prefix
)
3181 peek
= d_peek_char (di
);
3182 if (peek
== 'C' || peek
== 'D')
3186 pend
= (&standard_subs
[0]
3187 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3188 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3195 if (p
->set_last_name
!= NULL
)
3196 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3197 p
->set_last_name_len
);
3200 s
= p
->full_expansion
;
3205 s
= p
->simple_expansion
;
3206 len
= p
->simple_len
;
3208 di
->expansion
+= len
;
3209 return d_make_sub (di
, s
, len
);
3217 /* Initialize a growable string. */
3220 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3225 dgs
->allocation_failure
= 0;
3228 d_growable_string_resize (dgs
, estimate
);
3231 /* Grow a growable string to a given size. */
3234 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3239 if (dgs
->allocation_failure
)
3242 /* Start allocation at two bytes to avoid any possibility of confusion
3243 with the special value of 1 used as a return in *palc to indicate
3244 allocation failures. */
3245 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3246 while (newalc
< need
)
3249 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3256 dgs
->allocation_failure
= 1;
3263 /* Append a buffer to a growable string. */
3266 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3267 const char *s
, size_t l
)
3271 need
= dgs
->len
+ l
+ 1;
3272 if (need
> dgs
->alc
)
3273 d_growable_string_resize (dgs
, need
);
3275 if (dgs
->allocation_failure
)
3278 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3279 dgs
->buf
[dgs
->len
+ l
] = '\0';
3283 /* Bridge growable strings to the callback mechanism. */
3286 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3288 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3290 d_growable_string_append_buffer (dgs
, s
, l
);
3293 /* Initialize a print information structure. */
3296 d_print_init (struct d_print_info
*dpi
, int options
,
3297 demangle_callbackref callback
, void *opaque
)
3299 dpi
->options
= options
;
3301 dpi
->last_char
= '\0';
3302 dpi
->templates
= NULL
;
3303 dpi
->modifiers
= NULL
;
3304 dpi
->flush_count
= 0;
3306 dpi
->callback
= callback
;
3307 dpi
->opaque
= opaque
;
3309 dpi
->demangle_failure
= 0;
3312 /* Indicate that an error occurred during printing, and test for error. */
3315 d_print_error (struct d_print_info
*dpi
)
3317 dpi
->demangle_failure
= 1;
3321 d_print_saw_error (struct d_print_info
*dpi
)
3323 return dpi
->demangle_failure
!= 0;
3326 /* Flush buffered characters to the callback. */
3329 d_print_flush (struct d_print_info
*dpi
)
3331 dpi
->buf
[dpi
->len
] = '\0';
3332 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3337 /* Append characters and buffers for printing. */
3340 d_append_char (struct d_print_info
*dpi
, char c
)
3342 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3343 d_print_flush (dpi
);
3345 dpi
->buf
[dpi
->len
++] = c
;
3350 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3354 for (i
= 0; i
< l
; i
++)
3355 d_append_char (dpi
, s
[i
]);
3359 d_append_string (struct d_print_info
*dpi
, const char *s
)
3361 d_append_buffer (dpi
, s
, strlen (s
));
3365 d_append_num (struct d_print_info
*dpi
, long l
)
3368 sprintf (buf
,"%ld", l
);
3369 d_append_string (dpi
, buf
);
3373 d_last_char (struct d_print_info
*dpi
)
3375 return dpi
->last_char
;
3378 /* Turn components into a human readable string. OPTIONS is the
3379 options bits passed to the demangler. DC is the tree to print.
3380 CALLBACK is a function to call to flush demangled string segments
3381 as they fill the intermediate buffer, and OPAQUE is a generalized
3382 callback argument. On success, this returns 1. On failure,
3383 it returns 0, indicating a bad parse. It does not use heap
3384 memory to build an output string, so cannot encounter memory
3385 allocation failure. */
3387 CP_STATIC_IF_GLIBCPP_V3
3389 cplus_demangle_print_callback (int options
,
3390 const struct demangle_component
*dc
,
3391 demangle_callbackref callback
, void *opaque
)
3393 struct d_print_info dpi
;
3395 d_print_init (&dpi
, options
, callback
, opaque
);
3397 d_print_comp (&dpi
, dc
);
3399 d_print_flush (&dpi
);
3401 return ! d_print_saw_error (&dpi
);
3404 /* Turn components into a human readable string. OPTIONS is the
3405 options bits passed to the demangler. DC is the tree to print.
3406 ESTIMATE is a guess at the length of the result. This returns a
3407 string allocated by malloc, or NULL on error. On success, this
3408 sets *PALC to the size of the allocated buffer. On failure, this
3409 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3412 CP_STATIC_IF_GLIBCPP_V3
3414 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3415 int estimate
, size_t *palc
)
3417 struct d_growable_string dgs
;
3419 d_growable_string_init (&dgs
, estimate
);
3421 if (! cplus_demangle_print_callback (options
, dc
,
3422 d_growable_string_callback_adapter
,
3430 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3434 /* Returns the I'th element of the template arglist ARGS, or NULL on
3437 static struct demangle_component
*
3438 d_index_template_argument (struct demangle_component
*args
, int i
)
3440 struct demangle_component
*a
;
3446 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3452 if (i
!= 0 || a
== NULL
)
3458 /* Returns the template argument from the current context indicated by DC,
3459 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3461 static struct demangle_component
*
3462 d_lookup_template_argument (struct d_print_info
*dpi
,
3463 const struct demangle_component
*dc
)
3465 if (dpi
->templates
== NULL
)
3467 d_print_error (dpi
);
3471 return d_index_template_argument
3472 (d_right (dpi
->templates
->template_decl
),
3473 dc
->u
.s_number
.number
);
3476 /* Returns a template argument pack used in DC (any will do), or NULL. */
3478 static struct demangle_component
*
3479 d_find_pack (struct d_print_info
*dpi
,
3480 const struct demangle_component
*dc
)
3482 struct demangle_component
*a
;
3488 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3489 a
= d_lookup_template_argument (dpi
, dc
);
3490 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3494 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3497 case DEMANGLE_COMPONENT_LAMBDA
:
3498 case DEMANGLE_COMPONENT_NAME
:
3499 case DEMANGLE_COMPONENT_OPERATOR
:
3500 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3501 case DEMANGLE_COMPONENT_SUB_STD
:
3502 case DEMANGLE_COMPONENT_CHARACTER
:
3503 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3506 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3507 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3508 case DEMANGLE_COMPONENT_CTOR
:
3509 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3510 case DEMANGLE_COMPONENT_DTOR
:
3511 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3514 a
= d_find_pack (dpi
, d_left (dc
));
3517 return d_find_pack (dpi
, d_right (dc
));
3521 /* Returns the length of the template argument pack DC. */
3524 d_pack_length (const struct demangle_component
*dc
)
3527 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3528 && d_left (dc
) != NULL
)
3536 /* DC is a component of a mangled expression. Print it, wrapped in parens
3540 d_print_subexpr (struct d_print_info
*dpi
,
3541 const struct demangle_component
*dc
)
3544 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3545 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3548 d_append_char (dpi
, '(');
3549 d_print_comp (dpi
, dc
);
3551 d_append_char (dpi
, ')');
3554 /* Subroutine to handle components. */
3557 d_print_comp (struct d_print_info
*dpi
,
3558 const struct demangle_component
*dc
)
3562 d_print_error (dpi
);
3565 if (d_print_saw_error (dpi
))
3570 case DEMANGLE_COMPONENT_NAME
:
3571 if ((dpi
->options
& DMGL_JAVA
) == 0)
3572 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3574 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3577 case DEMANGLE_COMPONENT_QUAL_NAME
:
3578 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3579 d_print_comp (dpi
, d_left (dc
));
3580 if ((dpi
->options
& DMGL_JAVA
) == 0)
3581 d_append_string (dpi
, "::");
3583 d_append_char (dpi
, '.');
3584 d_print_comp (dpi
, d_right (dc
));
3587 case DEMANGLE_COMPONENT_TYPED_NAME
:
3589 struct d_print_mod
*hold_modifiers
;
3590 struct demangle_component
*typed_name
;
3591 struct d_print_mod adpm
[4];
3593 struct d_print_template dpt
;
3595 /* Pass the name down to the type so that it can be printed in
3596 the right place for the type. We also have to pass down
3597 any CV-qualifiers, which apply to the this parameter. */
3598 hold_modifiers
= dpi
->modifiers
;
3601 typed_name
= d_left (dc
);
3602 while (typed_name
!= NULL
)
3604 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3606 d_print_error (dpi
);
3610 adpm
[i
].next
= dpi
->modifiers
;
3611 dpi
->modifiers
= &adpm
[i
];
3612 adpm
[i
].mod
= typed_name
;
3613 adpm
[i
].printed
= 0;
3614 adpm
[i
].templates
= dpi
->templates
;
3617 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3618 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3619 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3622 typed_name
= d_left (typed_name
);
3625 if (typed_name
== NULL
)
3627 d_print_error (dpi
);
3631 /* If typed_name is a template, then it applies to the
3632 function type as well. */
3633 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3635 dpt
.next
= dpi
->templates
;
3636 dpi
->templates
= &dpt
;
3637 dpt
.template_decl
= typed_name
;
3640 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3641 there may be CV-qualifiers on its right argument which
3642 really apply here; this happens when parsing a class which
3643 is local to a function. */
3644 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3646 struct demangle_component
*local_name
;
3648 local_name
= d_right (typed_name
);
3649 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
3650 local_name
= local_name
->u
.s_unary_num
.sub
;
3651 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3652 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3653 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3655 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3657 d_print_error (dpi
);
3661 adpm
[i
] = adpm
[i
- 1];
3662 adpm
[i
].next
= &adpm
[i
- 1];
3663 dpi
->modifiers
= &adpm
[i
];
3665 adpm
[i
- 1].mod
= local_name
;
3666 adpm
[i
- 1].printed
= 0;
3667 adpm
[i
- 1].templates
= dpi
->templates
;
3670 local_name
= d_left (local_name
);
3674 d_print_comp (dpi
, d_right (dc
));
3676 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3677 dpi
->templates
= dpt
.next
;
3679 /* If the modifiers didn't get printed by the type, print them
3684 if (! adpm
[i
].printed
)
3686 d_append_char (dpi
, ' ');
3687 d_print_mod (dpi
, adpm
[i
].mod
);
3691 dpi
->modifiers
= hold_modifiers
;
3696 case DEMANGLE_COMPONENT_TEMPLATE
:
3698 struct d_print_mod
*hold_dpm
;
3699 struct demangle_component
*dcl
;
3701 /* Don't push modifiers into a template definition. Doing so
3702 could give the wrong definition for a template argument.
3703 Instead, treat the template essentially as a name. */
3705 hold_dpm
= dpi
->modifiers
;
3706 dpi
->modifiers
= NULL
;
3710 if ((dpi
->options
& DMGL_JAVA
) != 0
3711 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3712 && dcl
->u
.s_name
.len
== 6
3713 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3715 /* Special-case Java arrays, so that JArray<TYPE> appears
3716 instead as TYPE[]. */
3718 d_print_comp (dpi
, d_right (dc
));
3719 d_append_string (dpi
, "[]");
3723 d_print_comp (dpi
, dcl
);
3724 if (d_last_char (dpi
) == '<')
3725 d_append_char (dpi
, ' ');
3726 d_append_char (dpi
, '<');
3727 d_print_comp (dpi
, d_right (dc
));
3728 /* Avoid generating two consecutive '>' characters, to avoid
3729 the C++ syntactic ambiguity. */
3730 if (d_last_char (dpi
) == '>')
3731 d_append_char (dpi
, ' ');
3732 d_append_char (dpi
, '>');
3735 dpi
->modifiers
= hold_dpm
;
3740 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3742 struct d_print_template
*hold_dpt
;
3743 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
3745 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3746 a
= d_index_template_argument (a
, dpi
->pack_index
);
3750 d_print_error (dpi
);
3754 /* While processing this parameter, we need to pop the list of
3755 templates. This is because the template parameter may
3756 itself be a reference to a parameter of an outer
3759 hold_dpt
= dpi
->templates
;
3760 dpi
->templates
= hold_dpt
->next
;
3762 d_print_comp (dpi
, a
);
3764 dpi
->templates
= hold_dpt
;
3769 case DEMANGLE_COMPONENT_CTOR
:
3770 d_print_comp (dpi
, dc
->u
.s_ctor
.name
);
3773 case DEMANGLE_COMPONENT_DTOR
:
3774 d_append_char (dpi
, '~');
3775 d_print_comp (dpi
, dc
->u
.s_dtor
.name
);
3778 case DEMANGLE_COMPONENT_VTABLE
:
3779 d_append_string (dpi
, "vtable for ");
3780 d_print_comp (dpi
, d_left (dc
));
3783 case DEMANGLE_COMPONENT_VTT
:
3784 d_append_string (dpi
, "VTT for ");
3785 d_print_comp (dpi
, d_left (dc
));
3788 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3789 d_append_string (dpi
, "construction vtable for ");
3790 d_print_comp (dpi
, d_left (dc
));
3791 d_append_string (dpi
, "-in-");
3792 d_print_comp (dpi
, d_right (dc
));
3795 case DEMANGLE_COMPONENT_TYPEINFO
:
3796 d_append_string (dpi
, "typeinfo for ");
3797 d_print_comp (dpi
, d_left (dc
));
3800 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3801 d_append_string (dpi
, "typeinfo name for ");
3802 d_print_comp (dpi
, d_left (dc
));
3805 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3806 d_append_string (dpi
, "typeinfo fn for ");
3807 d_print_comp (dpi
, d_left (dc
));
3810 case DEMANGLE_COMPONENT_THUNK
:
3811 d_append_string (dpi
, "non-virtual thunk to ");
3812 d_print_comp (dpi
, d_left (dc
));
3815 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3816 d_append_string (dpi
, "virtual thunk to ");
3817 d_print_comp (dpi
, d_left (dc
));
3820 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3821 d_append_string (dpi
, "covariant return thunk to ");
3822 d_print_comp (dpi
, d_left (dc
));
3825 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3826 d_append_string (dpi
, "java Class for ");
3827 d_print_comp (dpi
, d_left (dc
));
3830 case DEMANGLE_COMPONENT_GUARD
:
3831 d_append_string (dpi
, "guard variable for ");
3832 d_print_comp (dpi
, d_left (dc
));
3835 case DEMANGLE_COMPONENT_REFTEMP
:
3836 d_append_string (dpi
, "reference temporary for ");
3837 d_print_comp (dpi
, d_left (dc
));
3840 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3841 d_append_string (dpi
, "hidden alias for ");
3842 d_print_comp (dpi
, d_left (dc
));
3845 case DEMANGLE_COMPONENT_SUB_STD
:
3846 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3849 case DEMANGLE_COMPONENT_RESTRICT
:
3850 case DEMANGLE_COMPONENT_VOLATILE
:
3851 case DEMANGLE_COMPONENT_CONST
:
3853 struct d_print_mod
*pdpm
;
3855 /* When printing arrays, it's possible to have cases where the
3856 same CV-qualifier gets pushed on the stack multiple times.
3857 We only need to print it once. */
3859 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3861 if (! pdpm
->printed
)
3863 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3864 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3865 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3867 if (pdpm
->mod
->type
== dc
->type
)
3869 d_print_comp (dpi
, d_left (dc
));
3876 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3877 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3878 case DEMANGLE_COMPONENT_CONST_THIS
:
3879 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3880 case DEMANGLE_COMPONENT_POINTER
:
3881 case DEMANGLE_COMPONENT_REFERENCE
:
3882 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3883 case DEMANGLE_COMPONENT_COMPLEX
:
3884 case DEMANGLE_COMPONENT_IMAGINARY
:
3886 /* We keep a list of modifiers on the stack. */
3887 struct d_print_mod dpm
;
3889 dpm
.next
= dpi
->modifiers
;
3890 dpi
->modifiers
= &dpm
;
3893 dpm
.templates
= dpi
->templates
;
3895 d_print_comp (dpi
, d_left (dc
));
3897 /* If the modifier didn't get printed by the type, print it
3900 d_print_mod (dpi
, dc
);
3902 dpi
->modifiers
= dpm
.next
;
3907 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3908 if ((dpi
->options
& DMGL_JAVA
) == 0)
3909 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
3910 dc
->u
.s_builtin
.type
->len
);
3912 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
3913 dc
->u
.s_builtin
.type
->java_len
);
3916 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3917 d_print_comp (dpi
, d_left (dc
));
3920 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3922 if ((dpi
->options
& DMGL_RET_POSTFIX
) != 0)
3923 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3925 /* Print return type if present */
3926 if (d_left (dc
) != NULL
)
3928 struct d_print_mod dpm
;
3930 /* We must pass this type down as a modifier in order to
3931 print it in the right location. */
3932 dpm
.next
= dpi
->modifiers
;
3933 dpi
->modifiers
= &dpm
;
3936 dpm
.templates
= dpi
->templates
;
3938 d_print_comp (dpi
, d_left (dc
));
3940 dpi
->modifiers
= dpm
.next
;
3945 /* In standard prefix notation, there is a space between the
3946 return type and the function signature. */
3947 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3948 d_append_char (dpi
, ' ');
3951 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3952 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3957 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3959 struct d_print_mod
*hold_modifiers
;
3960 struct d_print_mod adpm
[4];
3962 struct d_print_mod
*pdpm
;
3964 /* We must pass this type down as a modifier in order to print
3965 multi-dimensional arrays correctly. If the array itself is
3966 CV-qualified, we act as though the element type were
3967 CV-qualified. We do this by copying the modifiers down
3968 rather than fiddling pointers, so that we don't wind up
3969 with a d_print_mod higher on the stack pointing into our
3970 stack frame after we return. */
3972 hold_modifiers
= dpi
->modifiers
;
3974 adpm
[0].next
= hold_modifiers
;
3975 dpi
->modifiers
= &adpm
[0];
3977 adpm
[0].printed
= 0;
3978 adpm
[0].templates
= dpi
->templates
;
3981 pdpm
= hold_modifiers
;
3983 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
3984 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
3985 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
3987 if (! pdpm
->printed
)
3989 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3991 d_print_error (dpi
);
3996 adpm
[i
].next
= dpi
->modifiers
;
3997 dpi
->modifiers
= &adpm
[i
];
4005 d_print_comp (dpi
, d_right (dc
));
4007 dpi
->modifiers
= hold_modifiers
;
4009 if (adpm
[0].printed
)
4015 d_print_mod (dpi
, adpm
[i
].mod
);
4018 d_print_array_type (dpi
, dc
, dpi
->modifiers
);
4023 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4024 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4026 struct d_print_mod dpm
;
4028 dpm
.next
= dpi
->modifiers
;
4029 dpi
->modifiers
= &dpm
;
4032 dpm
.templates
= dpi
->templates
;
4034 d_print_comp (dpi
, d_right (dc
));
4036 /* If the modifier didn't get printed by the type, print it
4039 d_print_mod (dpi
, dc
);
4041 dpi
->modifiers
= dpm
.next
;
4046 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4047 if (dc
->u
.s_fixed
.sat
)
4048 d_append_string (dpi
, "_Sat ");
4049 /* Don't print "int _Accum". */
4050 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4051 != &cplus_demangle_builtin_types
['i'-'a'])
4053 d_print_comp (dpi
, dc
->u
.s_fixed
.length
);
4054 d_append_char (dpi
, ' ');
4056 if (dc
->u
.s_fixed
.accum
)
4057 d_append_string (dpi
, "_Accum");
4059 d_append_string (dpi
, "_Fract");
4062 case DEMANGLE_COMPONENT_ARGLIST
:
4063 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4064 if (d_left (dc
) != NULL
)
4065 d_print_comp (dpi
, d_left (dc
));
4066 if (d_right (dc
) != NULL
)
4069 unsigned long int flush_count
;
4070 /* Make sure ", " isn't flushed by d_append_string, otherwise
4071 dpi->len -= 2 wouldn't work. */
4072 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4073 d_print_flush (dpi
);
4074 d_append_string (dpi
, ", ");
4076 flush_count
= dpi
->flush_count
;
4077 d_print_comp (dpi
, d_right (dc
));
4078 /* If that didn't print anything (which can happen with empty
4079 template argument packs), remove the comma and space. */
4080 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4085 case DEMANGLE_COMPONENT_OPERATOR
:
4089 d_append_string (dpi
, "operator");
4090 c
= dc
->u
.s_operator
.op
->name
[0];
4092 d_append_char (dpi
, ' ');
4093 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4094 dc
->u
.s_operator
.op
->len
);
4098 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4099 d_append_string (dpi
, "operator ");
4100 d_print_comp (dpi
, dc
->u
.s_extended_operator
.name
);
4103 case DEMANGLE_COMPONENT_CAST
:
4104 d_append_string (dpi
, "operator ");
4105 d_print_cast (dpi
, dc
);
4108 case DEMANGLE_COMPONENT_UNARY
:
4109 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
4110 d_print_expr_op (dpi
, d_left (dc
));
4113 d_append_char (dpi
, '(');
4114 d_print_cast (dpi
, d_left (dc
));
4115 d_append_char (dpi
, ')');
4117 d_print_subexpr (dpi
, d_right (dc
));
4120 case DEMANGLE_COMPONENT_BINARY
:
4121 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4123 d_print_error (dpi
);
4127 /* We wrap an expression which uses the greater-than operator in
4128 an extra layer of parens so that it does not get confused
4129 with the '>' which ends the template parameters. */
4130 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4131 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4132 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4133 d_append_char (dpi
, '(');
4135 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4136 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4138 d_append_char (dpi
, '[');
4139 d_print_comp (dpi
, d_right (d_right (dc
)));
4140 d_append_char (dpi
, ']');
4144 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4145 d_print_expr_op (dpi
, d_left (dc
));
4146 d_print_subexpr (dpi
, d_right (d_right (dc
)));
4149 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4150 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4151 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4152 d_append_char (dpi
, ')');
4156 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4157 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4158 d_print_error (dpi
);
4161 case DEMANGLE_COMPONENT_TRINARY
:
4162 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4163 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4165 d_print_error (dpi
);
4168 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4169 d_print_expr_op (dpi
, d_left (dc
));
4170 d_print_subexpr (dpi
, d_left (d_right (d_right (dc
))));
4171 d_append_string (dpi
, " : ");
4172 d_print_subexpr (dpi
, d_right (d_right (d_right (dc
))));
4175 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4176 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4177 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4178 d_print_error (dpi
);
4181 case DEMANGLE_COMPONENT_LITERAL
:
4182 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4184 enum d_builtin_type_print tp
;
4186 /* For some builtin types, produce simpler output. */
4187 tp
= D_PRINT_DEFAULT
;
4188 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4190 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4194 case D_PRINT_UNSIGNED
:
4196 case D_PRINT_UNSIGNED_LONG
:
4197 case D_PRINT_LONG_LONG
:
4198 case D_PRINT_UNSIGNED_LONG_LONG
:
4199 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4201 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4202 d_append_char (dpi
, '-');
4203 d_print_comp (dpi
, d_right (dc
));
4208 case D_PRINT_UNSIGNED
:
4209 d_append_char (dpi
, 'u');
4212 d_append_char (dpi
, 'l');
4214 case D_PRINT_UNSIGNED_LONG
:
4215 d_append_string (dpi
, "ul");
4217 case D_PRINT_LONG_LONG
:
4218 d_append_string (dpi
, "ll");
4220 case D_PRINT_UNSIGNED_LONG_LONG
:
4221 d_append_string (dpi
, "ull");
4229 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4230 && d_right (dc
)->u
.s_name
.len
== 1
4231 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4233 switch (d_right (dc
)->u
.s_name
.s
[0])
4236 d_append_string (dpi
, "false");
4239 d_append_string (dpi
, "true");
4252 d_append_char (dpi
, '(');
4253 d_print_comp (dpi
, d_left (dc
));
4254 d_append_char (dpi
, ')');
4255 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4256 d_append_char (dpi
, '-');
4257 if (tp
== D_PRINT_FLOAT
)
4258 d_append_char (dpi
, '[');
4259 d_print_comp (dpi
, d_right (dc
));
4260 if (tp
== D_PRINT_FLOAT
)
4261 d_append_char (dpi
, ']');
4265 case DEMANGLE_COMPONENT_NUMBER
:
4266 d_append_num (dpi
, dc
->u
.s_number
.number
);
4269 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4270 d_append_string (dpi
, "java resource ");
4271 d_print_comp (dpi
, d_left (dc
));
4274 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4275 d_print_comp (dpi
, d_left (dc
));
4276 d_print_comp (dpi
, d_right (dc
));
4279 case DEMANGLE_COMPONENT_CHARACTER
:
4280 d_append_char (dpi
, dc
->u
.s_character
.character
);
4283 case DEMANGLE_COMPONENT_DECLTYPE
:
4284 d_append_string (dpi
, "decltype (");
4285 d_print_comp (dpi
, d_left (dc
));
4286 d_append_char (dpi
, ')');
4289 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4293 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4296 /* d_find_pack won't find anything if the only packs involved
4297 in this expansion are function parameter packs; in that
4298 case, just print the pattern and "...". */
4299 d_print_subexpr (dpi
, d_left (dc
));
4300 d_append_string (dpi
, "...");
4304 len
= d_pack_length (a
);
4306 for (i
= 0; i
< len
; ++i
)
4308 dpi
->pack_index
= i
;
4309 d_print_comp (dpi
, dc
);
4311 d_append_string (dpi
, ", ");
4316 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4317 d_append_string (dpi
, "{parm#");
4318 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4319 d_append_char (dpi
, '}');
4322 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4323 d_append_string (dpi
, "global constructors keyed to ");
4324 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4327 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4328 d_append_string (dpi
, "global destructors keyed to ");
4329 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4332 case DEMANGLE_COMPONENT_LAMBDA
:
4333 d_append_string (dpi
, "{lambda(");
4334 d_print_comp (dpi
, dc
->u
.s_unary_num
.sub
);
4335 d_append_string (dpi
, ")#");
4336 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4337 d_append_char (dpi
, '}');
4340 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4341 d_append_string (dpi
, "{unnamed type#");
4342 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4343 d_append_char (dpi
, '}');
4347 d_print_error (dpi
);
4352 /* Print a Java dentifier. For Java we try to handle encoded extended
4353 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4354 so we don't it for C++. Characters are encoded as
4358 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
4364 for (p
= name
; p
< end
; ++p
)
4375 for (q
= p
+ 3; q
< end
; ++q
)
4381 else if (*q
>= 'A' && *q
<= 'F')
4382 dig
= *q
- 'A' + 10;
4383 else if (*q
>= 'a' && *q
<= 'f')
4384 dig
= *q
- 'a' + 10;
4390 /* If the Unicode character is larger than 256, we don't try
4391 to deal with it here. FIXME. */
4392 if (q
< end
&& *q
== '_' && c
< 256)
4394 d_append_char (dpi
, c
);
4400 d_append_char (dpi
, *p
);
4404 /* Print a list of modifiers. SUFFIX is 1 if we are printing
4405 qualifiers on this after printing a function. */
4408 d_print_mod_list (struct d_print_info
*dpi
,
4409 struct d_print_mod
*mods
, int suffix
)
4411 struct d_print_template
*hold_dpt
;
4413 if (mods
== NULL
|| d_print_saw_error (dpi
))
4418 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4419 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4420 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
4422 d_print_mod_list (dpi
, mods
->next
, suffix
);
4428 hold_dpt
= dpi
->templates
;
4429 dpi
->templates
= mods
->templates
;
4431 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4433 d_print_function_type (dpi
, mods
->mod
, mods
->next
);
4434 dpi
->templates
= hold_dpt
;
4437 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4439 d_print_array_type (dpi
, mods
->mod
, mods
->next
);
4440 dpi
->templates
= hold_dpt
;
4443 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4445 struct d_print_mod
*hold_modifiers
;
4446 struct demangle_component
*dc
;
4448 /* When this is on the modifier stack, we have pulled any
4449 qualifiers off the right argument already. Otherwise, we
4450 print it as usual, but don't let the left argument see any
4453 hold_modifiers
= dpi
->modifiers
;
4454 dpi
->modifiers
= NULL
;
4455 d_print_comp (dpi
, d_left (mods
->mod
));
4456 dpi
->modifiers
= hold_modifiers
;
4458 if ((dpi
->options
& DMGL_JAVA
) == 0)
4459 d_append_string (dpi
, "::");
4461 d_append_char (dpi
, '.');
4463 dc
= d_right (mods
->mod
);
4465 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4467 d_append_string (dpi
, "{default arg#");
4468 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4469 d_append_string (dpi
, "}::");
4470 dc
= dc
->u
.s_unary_num
.sub
;
4473 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4474 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4475 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
4478 d_print_comp (dpi
, dc
);
4480 dpi
->templates
= hold_dpt
;
4484 d_print_mod (dpi
, mods
->mod
);
4486 dpi
->templates
= hold_dpt
;
4488 d_print_mod_list (dpi
, mods
->next
, suffix
);
4491 /* Print a modifier. */
4494 d_print_mod (struct d_print_info
*dpi
,
4495 const struct demangle_component
*mod
)
4499 case DEMANGLE_COMPONENT_RESTRICT
:
4500 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4501 d_append_string (dpi
, " restrict");
4503 case DEMANGLE_COMPONENT_VOLATILE
:
4504 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4505 d_append_string (dpi
, " volatile");
4507 case DEMANGLE_COMPONENT_CONST
:
4508 case DEMANGLE_COMPONENT_CONST_THIS
:
4509 d_append_string (dpi
, " const");
4511 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4512 d_append_char (dpi
, ' ');
4513 d_print_comp (dpi
, d_right (mod
));
4515 case DEMANGLE_COMPONENT_POINTER
:
4516 /* There is no pointer symbol in Java. */
4517 if ((dpi
->options
& DMGL_JAVA
) == 0)
4518 d_append_char (dpi
, '*');
4520 case DEMANGLE_COMPONENT_REFERENCE
:
4521 d_append_char (dpi
, '&');
4523 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4524 d_append_string (dpi
, "&&");
4526 case DEMANGLE_COMPONENT_COMPLEX
:
4527 d_append_string (dpi
, "complex ");
4529 case DEMANGLE_COMPONENT_IMAGINARY
:
4530 d_append_string (dpi
, "imaginary ");
4532 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4533 if (d_last_char (dpi
) != '(')
4534 d_append_char (dpi
, ' ');
4535 d_print_comp (dpi
, d_left (mod
));
4536 d_append_string (dpi
, "::*");
4538 case DEMANGLE_COMPONENT_TYPED_NAME
:
4539 d_print_comp (dpi
, d_left (mod
));
4541 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4542 d_append_string (dpi
, " __vector(");
4543 d_print_comp (dpi
, d_left (mod
));
4544 d_append_char (dpi
, ')');
4548 /* Otherwise, we have something that won't go back on the
4549 modifier stack, so we can just print it. */
4550 d_print_comp (dpi
, mod
);
4555 /* Print a function type, except for the return type. */
4558 d_print_function_type (struct d_print_info
*dpi
,
4559 const struct demangle_component
*dc
,
4560 struct d_print_mod
*mods
)
4564 struct d_print_mod
*p
;
4565 struct d_print_mod
*hold_modifiers
;
4569 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4574 switch (p
->mod
->type
)
4576 case DEMANGLE_COMPONENT_POINTER
:
4577 case DEMANGLE_COMPONENT_REFERENCE
:
4578 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4581 case DEMANGLE_COMPONENT_RESTRICT
:
4582 case DEMANGLE_COMPONENT_VOLATILE
:
4583 case DEMANGLE_COMPONENT_CONST
:
4584 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4585 case DEMANGLE_COMPONENT_COMPLEX
:
4586 case DEMANGLE_COMPONENT_IMAGINARY
:
4587 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4591 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4592 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4593 case DEMANGLE_COMPONENT_CONST_THIS
:
4606 if (d_last_char (dpi
) != '('
4607 && d_last_char (dpi
) != '*')
4610 if (need_space
&& d_last_char (dpi
) != ' ')
4611 d_append_char (dpi
, ' ');
4612 d_append_char (dpi
, '(');
4615 hold_modifiers
= dpi
->modifiers
;
4616 dpi
->modifiers
= NULL
;
4618 d_print_mod_list (dpi
, mods
, 0);
4621 d_append_char (dpi
, ')');
4623 d_append_char (dpi
, '(');
4625 if (d_right (dc
) != NULL
)
4626 d_print_comp (dpi
, d_right (dc
));
4628 d_append_char (dpi
, ')');
4630 d_print_mod_list (dpi
, mods
, 1);
4632 dpi
->modifiers
= hold_modifiers
;
4635 /* Print an array type, except for the element type. */
4638 d_print_array_type (struct d_print_info
*dpi
,
4639 const struct demangle_component
*dc
,
4640 struct d_print_mod
*mods
)
4648 struct d_print_mod
*p
;
4651 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4655 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4670 d_append_string (dpi
, " (");
4672 d_print_mod_list (dpi
, mods
, 0);
4675 d_append_char (dpi
, ')');
4679 d_append_char (dpi
, ' ');
4681 d_append_char (dpi
, '[');
4683 if (d_left (dc
) != NULL
)
4684 d_print_comp (dpi
, d_left (dc
));
4686 d_append_char (dpi
, ']');
4689 /* Print an operator in an expression. */
4692 d_print_expr_op (struct d_print_info
*dpi
,
4693 const struct demangle_component
*dc
)
4695 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4696 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4697 dc
->u
.s_operator
.op
->len
);
4699 d_print_comp (dpi
, dc
);
4705 d_print_cast (struct d_print_info
*dpi
,
4706 const struct demangle_component
*dc
)
4708 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4709 d_print_comp (dpi
, d_left (dc
));
4712 struct d_print_mod
*hold_dpm
;
4713 struct d_print_template dpt
;
4715 /* It appears that for a templated cast operator, we need to put
4716 the template parameters in scope for the operator name, but
4717 not for the parameters. The effect is that we need to handle
4718 the template printing here. */
4720 hold_dpm
= dpi
->modifiers
;
4721 dpi
->modifiers
= NULL
;
4723 dpt
.next
= dpi
->templates
;
4724 dpi
->templates
= &dpt
;
4725 dpt
.template_decl
= d_left (dc
);
4727 d_print_comp (dpi
, d_left (d_left (dc
)));
4729 dpi
->templates
= dpt
.next
;
4731 if (d_last_char (dpi
) == '<')
4732 d_append_char (dpi
, ' ');
4733 d_append_char (dpi
, '<');
4734 d_print_comp (dpi
, d_right (d_left (dc
)));
4735 /* Avoid generating two consecutive '>' characters, to avoid
4736 the C++ syntactic ambiguity. */
4737 if (d_last_char (dpi
) == '>')
4738 d_append_char (dpi
, ' ');
4739 d_append_char (dpi
, '>');
4741 dpi
->modifiers
= hold_dpm
;
4745 /* Initialize the information structure we use to pass around
4748 CP_STATIC_IF_GLIBCPP_V3
4750 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4754 di
->send
= mangled
+ len
;
4755 di
->options
= options
;
4759 /* We can not need more components than twice the number of chars in
4760 the mangled string. Most components correspond directly to
4761 chars, but the ARGLIST types are exceptions. */
4762 di
->num_comps
= 2 * len
;
4765 /* Similarly, we can not need more substitutions than there are
4766 chars in the mangled string. */
4771 di
->last_name
= NULL
;
4776 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4777 mangled name, return strings in repeated callback giving the demangled
4778 name. OPTIONS is the usual libiberty demangler options. On success,
4779 this returns 1. On failure, returns 0. */
4782 d_demangle_callback (const char *mangled
, int options
,
4783 demangle_callbackref callback
, void *opaque
)
4794 struct demangle_component
*dc
;
4797 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4799 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
4800 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
4801 && (mangled
[9] == 'D' || mangled
[9] == 'I')
4802 && mangled
[10] == '_')
4803 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
4806 if ((options
& DMGL_TYPES
) == 0)
4811 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
4814 #ifdef CP_DYNAMIC_ARRAYS
4815 __extension__
struct demangle_component comps
[di
.num_comps
];
4816 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4821 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4822 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4828 dc
= cplus_demangle_type (&di
);
4831 dc
= cplus_demangle_mangled_name (&di
, 1);
4833 case DCT_GLOBAL_CTORS
:
4834 case DCT_GLOBAL_DTORS
:
4835 d_advance (&di
, 11);
4836 dc
= d_make_comp (&di
,
4837 (type
== DCT_GLOBAL_CTORS
4838 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
4839 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
4840 d_make_demangle_mangled_name (&di
, d_str (&di
)),
4842 d_advance (&di
, strlen (d_str (&di
)));
4846 /* If DMGL_PARAMS is set, then if we didn't consume the entire
4847 mangled string, then we didn't successfully demangle it. If
4848 DMGL_PARAMS is not set, we didn't look at the trailing
4850 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
4853 #ifdef CP_DEMANGLE_DEBUG
4857 status
= (dc
!= NULL
)
4858 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
4865 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4866 name, return a buffer allocated with malloc holding the demangled
4867 name. OPTIONS is the usual libiberty demangler options. On
4868 success, this sets *PALC to the allocated size of the returned
4869 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4870 a memory allocation failure, and returns NULL. */
4873 d_demangle (const char *mangled
, int options
, size_t *palc
)
4875 struct d_growable_string dgs
;
4878 d_growable_string_init (&dgs
, 0);
4880 status
= d_demangle_callback (mangled
, options
,
4881 d_growable_string_callback_adapter
, &dgs
);
4889 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4893 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4895 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
4897 /* ia64 ABI-mandated entry point in the C++ runtime library for
4898 performing demangling. MANGLED_NAME is a NUL-terminated character
4899 string containing the name to be demangled.
4901 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
4902 *LENGTH bytes, into which the demangled name is stored. If
4903 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
4904 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
4905 is placed in a region of memory allocated with malloc.
4907 If LENGTH is non-NULL, the length of the buffer containing the
4908 demangled name, is placed in *LENGTH.
4910 The return value is a pointer to the start of the NUL-terminated
4911 demangled name, or NULL if the demangling fails. The caller is
4912 responsible for deallocating this memory using free.
4914 *STATUS is set to one of the following values:
4915 0: The demangling operation succeeded.
4916 -1: A memory allocation failure occurred.
4917 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4918 -3: One of the arguments is invalid.
4920 The demangling is performed using the C++ ABI mangling rules, with
4924 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
4925 size_t *length
, int *status
)
4930 if (mangled_name
== NULL
)
4937 if (output_buffer
!= NULL
&& length
== NULL
)
4944 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
4946 if (demangled
== NULL
)
4958 if (output_buffer
== NULL
)
4965 if (strlen (demangled
) < *length
)
4967 strcpy (output_buffer
, demangled
);
4969 demangled
= output_buffer
;
4973 free (output_buffer
);
4984 extern int __gcclibcxx_demangle_callback (const char *,
4986 (const char *, size_t, void *),
4989 /* Alternative, allocationless entry point in the C++ runtime library
4990 for performing demangling. MANGLED_NAME is a NUL-terminated character
4991 string containing the name to be demangled.
4993 CALLBACK is a callback function, called with demangled string
4994 segments as demangling progresses; it is called at least once,
4995 but may be called more than once. OPAQUE is a generalized pointer
4996 used as a callback argument.
4998 The return code is one of the following values, equivalent to
4999 the STATUS values of __cxa_demangle() (excluding -1, since this
5000 function performs no memory allocations):
5001 0: The demangling operation succeeded.
5002 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5003 -3: One of the arguments is invalid.
5005 The demangling is performed using the C++ ABI mangling rules, with
5009 __gcclibcxx_demangle_callback (const char *mangled_name
,
5010 void (*callback
) (const char *, size_t, void *),
5015 if (mangled_name
== NULL
|| callback
== NULL
)
5018 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5026 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5028 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5029 mangled name, return a buffer allocated with malloc holding the
5030 demangled name. Otherwise, return NULL. */
5033 cplus_demangle_v3 (const char *mangled
, int options
)
5037 return d_demangle (mangled
, options
, &alc
);
5041 cplus_demangle_v3_callback (const char *mangled
, int options
,
5042 demangle_callbackref callback
, void *opaque
)
5044 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5047 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5048 conventions, but the output formatting is a little different.
5049 This instructs the C++ demangler not to emit pointer characters ("*"), to
5050 use Java's namespace separator symbol ("." instead of "::"), and to output
5051 JArray<TYPE> as TYPE[]. */
5054 java_demangle_v3 (const char *mangled
)
5058 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5062 java_demangle_v3_callback (const char *mangled
,
5063 demangle_callbackref callback
, void *opaque
)
5065 return d_demangle_callback (mangled
,
5066 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5070 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5072 #ifndef IN_GLIBCPP_V3
5074 /* Demangle a string in order to find out whether it is a constructor
5075 or destructor. Return non-zero on success. Set *CTOR_KIND and
5076 *DTOR_KIND appropriately. */
5079 is_ctor_or_dtor (const char *mangled
,
5080 enum gnu_v3_ctor_kinds
*ctor_kind
,
5081 enum gnu_v3_dtor_kinds
*dtor_kind
)
5084 struct demangle_component
*dc
;
5087 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5088 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5090 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5093 #ifdef CP_DYNAMIC_ARRAYS
5094 __extension__
struct demangle_component comps
[di
.num_comps
];
5095 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5100 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5101 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5104 dc
= cplus_demangle_mangled_name (&di
, 1);
5106 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5107 to demangle the entire string. */
5117 case DEMANGLE_COMPONENT_TYPED_NAME
:
5118 case DEMANGLE_COMPONENT_TEMPLATE
:
5119 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5120 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5121 case DEMANGLE_COMPONENT_CONST_THIS
:
5124 case DEMANGLE_COMPONENT_QUAL_NAME
:
5125 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5128 case DEMANGLE_COMPONENT_CTOR
:
5129 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5133 case DEMANGLE_COMPONENT_DTOR
:
5134 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5145 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5146 name. A non-zero return indicates the type of constructor. */
5148 enum gnu_v3_ctor_kinds
5149 is_gnu_v3_mangled_ctor (const char *name
)
5151 enum gnu_v3_ctor_kinds ctor_kind
;
5152 enum gnu_v3_dtor_kinds dtor_kind
;
5154 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5155 return (enum gnu_v3_ctor_kinds
) 0;
5160 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5161 name. A non-zero return indicates the type of destructor. */
5163 enum gnu_v3_dtor_kinds
5164 is_gnu_v3_mangled_dtor (const char *name
)
5166 enum gnu_v3_ctor_kinds ctor_kind
;
5167 enum gnu_v3_dtor_kinds dtor_kind
;
5169 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5170 return (enum gnu_v3_dtor_kinds
) 0;
5174 #endif /* IN_GLIBCPP_V3 */
5176 #ifdef STANDALONE_DEMANGLER
5179 #include "dyn-string.h"
5181 static void print_usage (FILE* fp
, int exit_value
);
5183 #define IS_ALPHA(CHAR) \
5184 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5185 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5187 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5188 #define is_mangled_char(CHAR) \
5189 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5190 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5192 /* The name of this program, as invoked. */
5193 const char* program_name
;
5195 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5198 print_usage (FILE* fp
, int exit_value
)
5200 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5201 fprintf (fp
, "Options:\n");
5202 fprintf (fp
, " -h,--help Display this message.\n");
5203 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5204 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5205 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5210 /* Option specification for getopt_long. */
5211 static const struct option long_options
[] =
5213 { "help", no_argument
, NULL
, 'h' },
5214 { "no-params", no_argument
, NULL
, 'p' },
5215 { "verbose", no_argument
, NULL
, 'v' },
5216 { NULL
, no_argument
, NULL
, 0 },
5219 /* Main entry for a demangling filter executable. It will demangle
5220 its command line arguments, if any. If none are provided, it will
5221 filter stdin to stdout, replacing any recognized mangled C++ names
5222 with their demangled equivalents. */
5225 main (int argc
, char *argv
[])
5229 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5231 /* Use the program name of this program, as invoked. */
5232 program_name
= argv
[0];
5234 /* Parse options. */
5237 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5240 case '?': /* Unrecognized option. */
5241 print_usage (stderr
, 1);
5245 print_usage (stdout
, 0);
5249 options
&= ~ DMGL_PARAMS
;
5253 options
|= DMGL_VERBOSE
;
5257 while (opt_char
!= -1);
5260 /* No command line arguments were provided. Filter stdin. */
5262 dyn_string_t mangled
= dyn_string_new (3);
5265 /* Read all of input. */
5266 while (!feof (stdin
))
5270 /* Pile characters into mangled until we hit one that can't
5271 occur in a mangled name. */
5273 while (!feof (stdin
) && is_mangled_char (c
))
5275 dyn_string_append_char (mangled
, c
);
5281 if (dyn_string_length (mangled
) > 0)
5283 #ifdef IN_GLIBCPP_V3
5284 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
5286 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
5296 /* It might not have been a mangled name. Print the
5298 fputs (dyn_string_buf (mangled
), stdout
);
5301 dyn_string_clear (mangled
);
5304 /* If we haven't hit EOF yet, we've read one character that
5305 can't occur in a mangled name, so print it out. */
5310 dyn_string_delete (mangled
);
5313 /* Demangle command line arguments. */
5315 /* Loop over command line arguments. */
5316 for (i
= optind
; i
< argc
; ++i
)
5319 #ifdef IN_GLIBCPP_V3
5323 /* Attempt to demangle. */
5324 #ifdef IN_GLIBCPP_V3
5325 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
5327 s
= cplus_demangle_v3 (argv
[i
], options
);
5330 /* If it worked, print the demangled name. */
5338 #ifdef IN_GLIBCPP_V3
5339 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
5341 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
5350 #endif /* STANDALONE_DEMANGLER */