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_builtin_type (struct d_info
*,
326 const struct demangle_builtin_type_info
*);
328 static struct demangle_component
*
329 d_make_operator (struct d_info
*,
330 const struct demangle_operator_info
*);
332 static struct demangle_component
*
333 d_make_extended_operator (struct d_info
*, int,
334 struct demangle_component
*);
336 static struct demangle_component
*
337 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
338 struct demangle_component
*);
340 static struct demangle_component
*
341 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
342 struct demangle_component
*);
344 static struct demangle_component
*
345 d_make_template_param (struct d_info
*, long);
347 static struct demangle_component
*
348 d_make_sub (struct d_info
*, const char *, int);
351 has_return_type (struct demangle_component
*);
354 is_ctor_dtor_or_conversion (struct demangle_component
*);
356 static struct demangle_component
*d_encoding (struct d_info
*, int);
358 static struct demangle_component
*d_name (struct d_info
*);
360 static struct demangle_component
*d_nested_name (struct d_info
*);
362 static struct demangle_component
*d_prefix (struct d_info
*);
364 static struct demangle_component
*d_unqualified_name (struct d_info
*);
366 static struct demangle_component
*d_source_name (struct d_info
*);
368 static long d_number (struct d_info
*);
370 static struct demangle_component
*d_identifier (struct d_info
*, int);
372 static struct demangle_component
*d_operator_name (struct d_info
*);
374 static struct demangle_component
*d_special_name (struct d_info
*);
376 static int d_call_offset (struct d_info
*, int);
378 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
380 static struct demangle_component
**
381 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
383 static struct demangle_component
*
384 d_function_type (struct d_info
*);
386 static struct demangle_component
*
387 d_bare_function_type (struct d_info
*, int);
389 static struct demangle_component
*
390 d_class_enum_type (struct d_info
*);
392 static struct demangle_component
*d_array_type (struct d_info
*);
394 static struct demangle_component
*d_vector_type (struct d_info
*);
396 static struct demangle_component
*
397 d_pointer_to_member_type (struct d_info
*);
399 static struct demangle_component
*
400 d_template_param (struct d_info
*);
402 static struct demangle_component
*d_template_args (struct d_info
*);
404 static struct demangle_component
*
405 d_template_arg (struct d_info
*);
407 static struct demangle_component
*d_expression (struct d_info
*);
409 static struct demangle_component
*d_expr_primary (struct d_info
*);
411 static struct demangle_component
*d_local_name (struct d_info
*);
413 static int d_discriminator (struct d_info
*);
415 static struct demangle_component
*d_lambda (struct d_info
*);
417 static struct demangle_component
*d_unnamed_type (struct d_info
*);
420 d_add_substitution (struct d_info
*, struct demangle_component
*);
422 static struct demangle_component
*d_substitution (struct d_info
*, int);
424 static void d_growable_string_init (struct d_growable_string
*, size_t);
427 d_growable_string_resize (struct d_growable_string
*, size_t);
430 d_growable_string_append_buffer (struct d_growable_string
*,
431 const char *, size_t);
433 d_growable_string_callback_adapter (const char *, size_t, void *);
436 d_print_init (struct d_print_info
*, int, demangle_callbackref
, void *);
438 static inline void d_print_error (struct d_print_info
*);
440 static inline int d_print_saw_error (struct d_print_info
*);
442 static inline void d_print_flush (struct d_print_info
*);
444 static inline void d_append_char (struct d_print_info
*, char);
446 static inline void d_append_buffer (struct d_print_info
*,
447 const char *, size_t);
449 static inline void d_append_string (struct d_print_info
*, const char *);
451 static inline char d_last_char (struct d_print_info
*);
454 d_print_comp (struct d_print_info
*, const struct demangle_component
*);
457 d_print_java_identifier (struct d_print_info
*, const char *, int);
460 d_print_mod_list (struct d_print_info
*, struct d_print_mod
*, int);
463 d_print_mod (struct d_print_info
*, const struct demangle_component
*);
466 d_print_function_type (struct d_print_info
*,
467 const struct demangle_component
*,
468 struct d_print_mod
*);
471 d_print_array_type (struct d_print_info
*,
472 const struct demangle_component
*,
473 struct d_print_mod
*);
476 d_print_expr_op (struct d_print_info
*, const struct demangle_component
*);
479 d_print_cast (struct d_print_info
*, const struct demangle_component
*);
481 static int d_demangle_callback (const char *, int,
482 demangle_callbackref
, void *);
483 static char *d_demangle (const char *, int, size_t *);
485 #ifdef CP_DEMANGLE_DEBUG
488 d_dump (struct demangle_component
*dc
, int indent
)
495 printf ("failed demangling\n");
499 for (i
= 0; i
< indent
; ++i
)
504 case DEMANGLE_COMPONENT_NAME
:
505 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
507 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
508 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
510 case DEMANGLE_COMPONENT_CTOR
:
511 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
512 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
514 case DEMANGLE_COMPONENT_DTOR
:
515 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
516 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
518 case DEMANGLE_COMPONENT_SUB_STD
:
519 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
521 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
522 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
524 case DEMANGLE_COMPONENT_OPERATOR
:
525 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
527 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
528 printf ("extended operator with %d args\n",
529 dc
->u
.s_extended_operator
.args
);
530 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
533 case DEMANGLE_COMPONENT_QUAL_NAME
:
534 printf ("qualified name\n");
536 case DEMANGLE_COMPONENT_LOCAL_NAME
:
537 printf ("local name\n");
539 case DEMANGLE_COMPONENT_TYPED_NAME
:
540 printf ("typed name\n");
542 case DEMANGLE_COMPONENT_TEMPLATE
:
543 printf ("template\n");
545 case DEMANGLE_COMPONENT_VTABLE
:
548 case DEMANGLE_COMPONENT_VTT
:
551 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
552 printf ("construction vtable\n");
554 case DEMANGLE_COMPONENT_TYPEINFO
:
555 printf ("typeinfo\n");
557 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
558 printf ("typeinfo name\n");
560 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
561 printf ("typeinfo function\n");
563 case DEMANGLE_COMPONENT_THUNK
:
566 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
567 printf ("virtual thunk\n");
569 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
570 printf ("covariant thunk\n");
572 case DEMANGLE_COMPONENT_JAVA_CLASS
:
573 printf ("java class\n");
575 case DEMANGLE_COMPONENT_GUARD
:
578 case DEMANGLE_COMPONENT_REFTEMP
:
579 printf ("reference temporary\n");
581 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
582 printf ("hidden alias\n");
584 case DEMANGLE_COMPONENT_RESTRICT
:
585 printf ("restrict\n");
587 case DEMANGLE_COMPONENT_VOLATILE
:
588 printf ("volatile\n");
590 case DEMANGLE_COMPONENT_CONST
:
593 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
594 printf ("restrict this\n");
596 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
597 printf ("volatile this\n");
599 case DEMANGLE_COMPONENT_CONST_THIS
:
600 printf ("const this\n");
602 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
603 printf ("vendor type qualifier\n");
605 case DEMANGLE_COMPONENT_POINTER
:
606 printf ("pointer\n");
608 case DEMANGLE_COMPONENT_REFERENCE
:
609 printf ("reference\n");
611 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
612 printf ("rvalue reference\n");
614 case DEMANGLE_COMPONENT_COMPLEX
:
615 printf ("complex\n");
617 case DEMANGLE_COMPONENT_IMAGINARY
:
618 printf ("imaginary\n");
620 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
621 printf ("vendor type\n");
623 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
624 printf ("function type\n");
626 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
627 printf ("array type\n");
629 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
630 printf ("pointer to member type\n");
632 case DEMANGLE_COMPONENT_FIXED_TYPE
:
633 printf ("fixed-point type\n");
635 case DEMANGLE_COMPONENT_ARGLIST
:
636 printf ("argument list\n");
638 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
639 printf ("template argument list\n");
641 case DEMANGLE_COMPONENT_CAST
:
644 case DEMANGLE_COMPONENT_UNARY
:
645 printf ("unary operator\n");
647 case DEMANGLE_COMPONENT_BINARY
:
648 printf ("binary operator\n");
650 case DEMANGLE_COMPONENT_BINARY_ARGS
:
651 printf ("binary operator arguments\n");
653 case DEMANGLE_COMPONENT_TRINARY
:
654 printf ("trinary operator\n");
656 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
657 printf ("trinary operator arguments 1\n");
659 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
660 printf ("trinary operator arguments 1\n");
662 case DEMANGLE_COMPONENT_LITERAL
:
663 printf ("literal\n");
665 case DEMANGLE_COMPONENT_LITERAL_NEG
:
666 printf ("negative literal\n");
668 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
669 printf ("java resource\n");
671 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
672 printf ("compound name\n");
674 case DEMANGLE_COMPONENT_CHARACTER
:
675 printf ("character '%c'\n", dc
->u
.s_character
.character
);
677 case DEMANGLE_COMPONENT_DECLTYPE
:
678 printf ("decltype\n");
680 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
681 printf ("pack expansion\n");
685 d_dump (d_left (dc
), indent
+ 2);
686 d_dump (d_right (dc
), indent
+ 2);
689 #endif /* CP_DEMANGLE_DEBUG */
691 /* Fill in a DEMANGLE_COMPONENT_NAME. */
693 CP_STATIC_IF_GLIBCPP_V3
695 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
697 if (p
== NULL
|| s
== NULL
|| len
== 0)
699 p
->type
= DEMANGLE_COMPONENT_NAME
;
701 p
->u
.s_name
.len
= len
;
705 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
707 CP_STATIC_IF_GLIBCPP_V3
709 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
710 struct demangle_component
*name
)
712 if (p
== NULL
|| args
< 0 || name
== NULL
)
714 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
715 p
->u
.s_extended_operator
.args
= args
;
716 p
->u
.s_extended_operator
.name
= name
;
720 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
722 CP_STATIC_IF_GLIBCPP_V3
724 cplus_demangle_fill_ctor (struct demangle_component
*p
,
725 enum gnu_v3_ctor_kinds kind
,
726 struct demangle_component
*name
)
730 || (int) kind
< gnu_v3_complete_object_ctor
731 || (int) kind
> gnu_v3_complete_object_allocating_ctor
)
733 p
->type
= DEMANGLE_COMPONENT_CTOR
;
734 p
->u
.s_ctor
.kind
= kind
;
735 p
->u
.s_ctor
.name
= name
;
739 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
741 CP_STATIC_IF_GLIBCPP_V3
743 cplus_demangle_fill_dtor (struct demangle_component
*p
,
744 enum gnu_v3_dtor_kinds kind
,
745 struct demangle_component
*name
)
749 || (int) kind
< gnu_v3_deleting_dtor
750 || (int) kind
> gnu_v3_base_object_dtor
)
752 p
->type
= DEMANGLE_COMPONENT_DTOR
;
753 p
->u
.s_dtor
.kind
= kind
;
754 p
->u
.s_dtor
.name
= name
;
758 /* Add a new component. */
760 static struct demangle_component
*
761 d_make_empty (struct d_info
*di
)
763 struct demangle_component
*p
;
765 if (di
->next_comp
>= di
->num_comps
)
767 p
= &di
->comps
[di
->next_comp
];
772 /* Add a new generic component. */
774 static struct demangle_component
*
775 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
776 struct demangle_component
*left
,
777 struct demangle_component
*right
)
779 struct demangle_component
*p
;
781 /* We check for errors here. A typical error would be a NULL return
782 from a subroutine. We catch those here, and return NULL
786 /* These types require two parameters. */
787 case DEMANGLE_COMPONENT_QUAL_NAME
:
788 case DEMANGLE_COMPONENT_LOCAL_NAME
:
789 case DEMANGLE_COMPONENT_TYPED_NAME
:
790 case DEMANGLE_COMPONENT_TEMPLATE
:
791 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
792 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
793 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
794 case DEMANGLE_COMPONENT_UNARY
:
795 case DEMANGLE_COMPONENT_BINARY
:
796 case DEMANGLE_COMPONENT_BINARY_ARGS
:
797 case DEMANGLE_COMPONENT_TRINARY
:
798 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
799 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
800 case DEMANGLE_COMPONENT_LITERAL
:
801 case DEMANGLE_COMPONENT_LITERAL_NEG
:
802 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
803 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
804 if (left
== NULL
|| right
== NULL
)
808 /* These types only require one parameter. */
809 case DEMANGLE_COMPONENT_VTABLE
:
810 case DEMANGLE_COMPONENT_VTT
:
811 case DEMANGLE_COMPONENT_TYPEINFO
:
812 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
813 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
814 case DEMANGLE_COMPONENT_THUNK
:
815 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
816 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
817 case DEMANGLE_COMPONENT_JAVA_CLASS
:
818 case DEMANGLE_COMPONENT_GUARD
:
819 case DEMANGLE_COMPONENT_REFTEMP
:
820 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
821 case DEMANGLE_COMPONENT_POINTER
:
822 case DEMANGLE_COMPONENT_REFERENCE
:
823 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
824 case DEMANGLE_COMPONENT_COMPLEX
:
825 case DEMANGLE_COMPONENT_IMAGINARY
:
826 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
827 case DEMANGLE_COMPONENT_CAST
:
828 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
829 case DEMANGLE_COMPONENT_DECLTYPE
:
830 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
831 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
832 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
837 /* This needs a right parameter, but the left parameter can be
839 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
844 /* These are allowed to have no parameters--in some cases they
845 will be filled in later. */
846 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
847 case DEMANGLE_COMPONENT_RESTRICT
:
848 case DEMANGLE_COMPONENT_VOLATILE
:
849 case DEMANGLE_COMPONENT_CONST
:
850 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
851 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
852 case DEMANGLE_COMPONENT_CONST_THIS
:
853 case DEMANGLE_COMPONENT_ARGLIST
:
854 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
857 /* Other types should not be seen here. */
862 p
= d_make_empty (di
);
866 p
->u
.s_binary
.left
= left
;
867 p
->u
.s_binary
.right
= right
;
872 /* Add a new name component. */
874 static struct demangle_component
*
875 d_make_name (struct d_info
*di
, const char *s
, int len
)
877 struct demangle_component
*p
;
879 p
= d_make_empty (di
);
880 if (! cplus_demangle_fill_name (p
, s
, len
))
885 /* Add a new builtin type component. */
887 static struct demangle_component
*
888 d_make_builtin_type (struct d_info
*di
,
889 const struct demangle_builtin_type_info
*type
)
891 struct demangle_component
*p
;
895 p
= d_make_empty (di
);
898 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
899 p
->u
.s_builtin
.type
= type
;
904 /* Add a new operator component. */
906 static struct demangle_component
*
907 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
909 struct demangle_component
*p
;
911 p
= d_make_empty (di
);
914 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
915 p
->u
.s_operator
.op
= op
;
920 /* Add a new extended operator component. */
922 static struct demangle_component
*
923 d_make_extended_operator (struct d_info
*di
, int args
,
924 struct demangle_component
*name
)
926 struct demangle_component
*p
;
928 p
= d_make_empty (di
);
929 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
934 static struct demangle_component
*
935 d_make_default_arg (struct d_info
*di
, int num
,
936 struct demangle_component
*sub
)
938 struct demangle_component
*p
= d_make_empty (di
);
941 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
942 p
->u
.s_unary_num
.num
= num
;
943 p
->u
.s_unary_num
.sub
= sub
;
948 /* Add a new constructor component. */
950 static struct demangle_component
*
951 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
952 struct demangle_component
*name
)
954 struct demangle_component
*p
;
956 p
= d_make_empty (di
);
957 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
962 /* Add a new destructor component. */
964 static struct demangle_component
*
965 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
966 struct demangle_component
*name
)
968 struct demangle_component
*p
;
970 p
= d_make_empty (di
);
971 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
976 /* Add a new template parameter. */
978 static struct demangle_component
*
979 d_make_template_param (struct d_info
*di
, long i
)
981 struct demangle_component
*p
;
983 p
= d_make_empty (di
);
986 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
987 p
->u
.s_number
.number
= i
;
992 /* Add a new function parameter. */
994 static struct demangle_component
*
995 d_make_function_param (struct d_info
*di
, long i
)
997 struct demangle_component
*p
;
999 p
= d_make_empty (di
);
1002 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1003 p
->u
.s_number
.number
= i
;
1008 /* Add a new standard substitution component. */
1010 static struct demangle_component
*
1011 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1013 struct demangle_component
*p
;
1015 p
= d_make_empty (di
);
1018 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1019 p
->u
.s_string
.string
= name
;
1020 p
->u
.s_string
.len
= len
;
1025 /* <mangled-name> ::= _Z <encoding>
1027 TOP_LEVEL is non-zero when called at the top level. */
1029 CP_STATIC_IF_GLIBCPP_V3
1030 struct demangle_component
*
1031 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1033 if (! d_check_char (di
, '_')
1034 /* Allow missing _ if not at toplevel to work around a
1035 bug in G++ abi-version=2 mangling; see the comment in
1036 write_template_arg. */
1039 if (! d_check_char (di
, 'Z'))
1041 return d_encoding (di
, top_level
);
1044 /* Return whether a function should have a return type. The argument
1045 is the function name, which may be qualified in various ways. The
1046 rules are that template functions have return types with some
1047 exceptions, function types which are not part of a function name
1048 mangling have return types with some exceptions, and non-template
1049 function names do not have return types. The exceptions are that
1050 constructors, destructors, and conversion operators do not have
1054 has_return_type (struct demangle_component
*dc
)
1062 case DEMANGLE_COMPONENT_TEMPLATE
:
1063 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1064 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1065 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1066 case DEMANGLE_COMPONENT_CONST_THIS
:
1067 return has_return_type (d_left (dc
));
1071 /* Return whether a name is a constructor, a destructor, or a
1072 conversion operator. */
1075 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1083 case DEMANGLE_COMPONENT_QUAL_NAME
:
1084 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1085 return is_ctor_dtor_or_conversion (d_right (dc
));
1086 case DEMANGLE_COMPONENT_CTOR
:
1087 case DEMANGLE_COMPONENT_DTOR
:
1088 case DEMANGLE_COMPONENT_CAST
:
1093 /* <encoding> ::= <(function) name> <bare-function-type>
1097 TOP_LEVEL is non-zero when called at the top level, in which case
1098 if DMGL_PARAMS is not set we do not demangle the function
1099 parameters. We only set this at the top level, because otherwise
1100 we would not correctly demangle names in local scopes. */
1102 static struct demangle_component
*
1103 d_encoding (struct d_info
*di
, int top_level
)
1105 char peek
= d_peek_char (di
);
1107 if (peek
== 'G' || peek
== 'T')
1108 return d_special_name (di
);
1111 struct demangle_component
*dc
;
1115 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1117 /* Strip off any initial CV-qualifiers, as they really apply
1118 to the `this' parameter, and they were not output by the
1119 v2 demangler without DMGL_PARAMS. */
1120 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1121 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1122 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1125 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1126 there may be CV-qualifiers on its right argument which
1127 really apply here; this happens when parsing a class
1128 which is local to a function. */
1129 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1131 struct demangle_component
*dcr
;
1134 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1135 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1136 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1138 dc
->u
.s_binary
.right
= dcr
;
1144 peek
= d_peek_char (di
);
1145 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1147 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1148 d_bare_function_type (di
, has_return_type (dc
)));
1152 /* <name> ::= <nested-name>
1154 ::= <unscoped-template-name> <template-args>
1157 <unscoped-name> ::= <unqualified-name>
1158 ::= St <unqualified-name>
1160 <unscoped-template-name> ::= <unscoped-name>
1164 static struct demangle_component
*
1165 d_name (struct d_info
*di
)
1167 char peek
= d_peek_char (di
);
1168 struct demangle_component
*dc
;
1173 return d_nested_name (di
);
1176 return d_local_name (di
);
1180 return d_unqualified_name (di
);
1186 if (d_peek_next_char (di
) != 't')
1188 dc
= d_substitution (di
, 0);
1194 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1195 d_make_name (di
, "std", 3),
1196 d_unqualified_name (di
));
1201 if (d_peek_char (di
) != 'I')
1203 /* The grammar does not permit this case to occur if we
1204 called d_substitution() above (i.e., subst == 1). We
1205 don't bother to check. */
1209 /* This is <template-args>, which means that we just saw
1210 <unscoped-template-name>, which is a substitution
1211 candidate if we didn't just get it from a
1215 if (! d_add_substitution (di
, dc
))
1218 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1219 d_template_args (di
));
1226 dc
= d_unqualified_name (di
);
1227 if (d_peek_char (di
) == 'I')
1229 /* This is <template-args>, which means that we just saw
1230 <unscoped-template-name>, which is a substitution
1232 if (! d_add_substitution (di
, dc
))
1234 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1235 d_template_args (di
));
1241 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1242 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1245 static struct demangle_component
*
1246 d_nested_name (struct d_info
*di
)
1248 struct demangle_component
*ret
;
1249 struct demangle_component
**pret
;
1251 if (! d_check_char (di
, 'N'))
1254 pret
= d_cv_qualifiers (di
, &ret
, 1);
1258 *pret
= d_prefix (di
);
1262 if (! d_check_char (di
, 'E'))
1268 /* <prefix> ::= <prefix> <unqualified-name>
1269 ::= <template-prefix> <template-args>
1270 ::= <template-param>
1274 <template-prefix> ::= <prefix> <(template) unqualified-name>
1275 ::= <template-param>
1279 static struct demangle_component
*
1280 d_prefix (struct d_info
*di
)
1282 struct demangle_component
*ret
= NULL
;
1287 enum demangle_component_type comb_type
;
1288 struct demangle_component
*dc
;
1290 peek
= d_peek_char (di
);
1294 /* The older code accepts a <local-name> here, but I don't see
1295 that in the grammar. The older code does not accept a
1296 <template-param> here. */
1298 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1305 dc
= d_unqualified_name (di
);
1306 else if (peek
== 'S')
1307 dc
= d_substitution (di
, 1);
1308 else if (peek
== 'I')
1312 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1313 dc
= d_template_args (di
);
1315 else if (peek
== 'T')
1316 dc
= d_template_param (di
);
1317 else if (peek
== 'E')
1319 else if (peek
== 'M')
1321 /* Initializer scope for a lambda. We don't need to represent
1322 this; the normal code will just treat the variable as a type
1323 scope, which gives appropriate output. */
1335 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1337 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1339 if (! d_add_substitution (di
, ret
))
1345 /* <unqualified-name> ::= <operator-name>
1346 ::= <ctor-dtor-name>
1348 ::= <local-source-name>
1350 <local-source-name> ::= L <source-name> <discriminator>
1353 static struct demangle_component
*
1354 d_unqualified_name (struct d_info
*di
)
1358 peek
= d_peek_char (di
);
1359 if (IS_DIGIT (peek
))
1360 return d_source_name (di
);
1361 else if (IS_LOWER (peek
))
1363 struct demangle_component
*ret
;
1365 ret
= d_operator_name (di
);
1366 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1367 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1370 else if (peek
== 'C' || peek
== 'D')
1371 return d_ctor_dtor_name (di
);
1372 else if (peek
== 'L')
1374 struct demangle_component
* ret
;
1378 ret
= d_source_name (di
);
1381 if (! d_discriminator (di
))
1385 else if (peek
== 'U')
1387 switch (d_peek_next_char (di
))
1390 return d_lambda (di
);
1392 return d_unnamed_type (di
);
1401 /* <source-name> ::= <(positive length) number> <identifier> */
1403 static struct demangle_component
*
1404 d_source_name (struct d_info
*di
)
1407 struct demangle_component
*ret
;
1409 len
= d_number (di
);
1412 ret
= d_identifier (di
, len
);
1413 di
->last_name
= ret
;
1417 /* number ::= [n] <(non-negative decimal integer)> */
1420 d_number (struct d_info
*di
)
1427 peek
= d_peek_char (di
);
1432 peek
= d_peek_char (di
);
1438 if (! IS_DIGIT (peek
))
1444 ret
= ret
* 10 + peek
- '0';
1446 peek
= d_peek_char (di
);
1450 /* Like d_number, but returns a demangle_component. */
1452 static struct demangle_component
*
1453 d_number_component (struct d_info
*di
)
1455 struct demangle_component
*ret
= d_make_empty (di
);
1458 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1459 ret
->u
.s_number
.number
= d_number (di
);
1464 /* identifier ::= <(unqualified source code identifier)> */
1466 static struct demangle_component
*
1467 d_identifier (struct d_info
*di
, int len
)
1473 if (di
->send
- name
< len
)
1476 d_advance (di
, len
);
1478 /* A Java mangled name may have a trailing '$' if it is a C++
1479 keyword. This '$' is not included in the length count. We just
1481 if ((di
->options
& DMGL_JAVA
) != 0
1482 && d_peek_char (di
) == '$')
1485 /* Look for something which looks like a gcc encoding of an
1486 anonymous namespace, and replace it with a more user friendly
1488 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1489 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1490 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1494 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1495 if ((*s
== '.' || *s
== '_' || *s
== '$')
1498 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1499 return d_make_name (di
, "(anonymous namespace)",
1500 sizeof "(anonymous namespace)" - 1);
1504 return d_make_name (di
, name
, len
);
1507 /* operator_name ::= many different two character encodings.
1509 ::= v <digit> <source-name>
1512 #define NL(s) s, (sizeof s) - 1
1514 CP_STATIC_IF_GLIBCPP_V3
1515 const struct demangle_operator_info cplus_demangle_operators
[] =
1517 { "aN", NL ("&="), 2 },
1518 { "aS", NL ("="), 2 },
1519 { "aa", NL ("&&"), 2 },
1520 { "ad", NL ("&"), 1 },
1521 { "an", NL ("&"), 2 },
1522 { "cl", NL ("()"), 2 },
1523 { "cm", NL (","), 2 },
1524 { "co", NL ("~"), 1 },
1525 { "dV", NL ("/="), 2 },
1526 { "da", NL ("delete[]"), 1 },
1527 { "de", NL ("*"), 1 },
1528 { "dl", NL ("delete"), 1 },
1529 { "dt", NL ("."), 2 },
1530 { "dv", NL ("/"), 2 },
1531 { "eO", NL ("^="), 2 },
1532 { "eo", NL ("^"), 2 },
1533 { "eq", NL ("=="), 2 },
1534 { "ge", NL (">="), 2 },
1535 { "gt", NL (">"), 2 },
1536 { "ix", NL ("[]"), 2 },
1537 { "lS", NL ("<<="), 2 },
1538 { "le", NL ("<="), 2 },
1539 { "ls", NL ("<<"), 2 },
1540 { "lt", NL ("<"), 2 },
1541 { "mI", NL ("-="), 2 },
1542 { "mL", NL ("*="), 2 },
1543 { "mi", NL ("-"), 2 },
1544 { "ml", NL ("*"), 2 },
1545 { "mm", NL ("--"), 1 },
1546 { "na", NL ("new[]"), 1 },
1547 { "ne", NL ("!="), 2 },
1548 { "ng", NL ("-"), 1 },
1549 { "nt", NL ("!"), 1 },
1550 { "nw", NL ("new"), 1 },
1551 { "oR", NL ("|="), 2 },
1552 { "oo", NL ("||"), 2 },
1553 { "or", NL ("|"), 2 },
1554 { "pL", NL ("+="), 2 },
1555 { "pl", NL ("+"), 2 },
1556 { "pm", NL ("->*"), 2 },
1557 { "pp", NL ("++"), 1 },
1558 { "ps", NL ("+"), 1 },
1559 { "pt", NL ("->"), 2 },
1560 { "qu", NL ("?"), 3 },
1561 { "rM", NL ("%="), 2 },
1562 { "rS", NL (">>="), 2 },
1563 { "rm", NL ("%"), 2 },
1564 { "rs", NL (">>"), 2 },
1565 { "st", NL ("sizeof "), 1 },
1566 { "sz", NL ("sizeof "), 1 },
1567 { "at", NL ("alignof "), 1 },
1568 { "az", NL ("alignof "), 1 },
1569 { NULL
, NULL
, 0, 0 }
1572 static struct demangle_component
*
1573 d_operator_name (struct d_info
*di
)
1578 c1
= d_next_char (di
);
1579 c2
= d_next_char (di
);
1580 if (c1
== 'v' && IS_DIGIT (c2
))
1581 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1582 else if (c1
== 'c' && c2
== 'v')
1583 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1584 cplus_demangle_type (di
), NULL
);
1587 /* LOW is the inclusive lower bound. */
1589 /* HIGH is the exclusive upper bound. We subtract one to ignore
1590 the sentinel at the end of the array. */
1591 int high
= ((sizeof (cplus_demangle_operators
)
1592 / sizeof (cplus_demangle_operators
[0]))
1598 const struct demangle_operator_info
*p
;
1600 i
= low
+ (high
- low
) / 2;
1601 p
= cplus_demangle_operators
+ i
;
1603 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1604 return d_make_operator (di
, p
);
1606 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1616 static struct demangle_component
*
1617 d_make_character (struct d_info
*di
, int c
)
1619 struct demangle_component
*p
;
1620 p
= d_make_empty (di
);
1623 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1624 p
->u
.s_character
.character
= c
;
1629 static struct demangle_component
*
1630 d_java_resource (struct d_info
*di
)
1632 struct demangle_component
*p
= NULL
;
1633 struct demangle_component
*next
= NULL
;
1638 len
= d_number (di
);
1642 /* Eat the leading '_'. */
1643 if (d_next_char (di
) != '_')
1656 /* Each chunk is either a '$' escape... */
1674 next
= d_make_character (di
, c
);
1682 /* ... or a sequence of characters. */
1685 while (i
< len
&& str
[i
] && str
[i
] != '$')
1688 next
= d_make_name (di
, str
, i
);
1701 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1707 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1712 /* <special-name> ::= TV <type>
1716 ::= GV <(object) name>
1717 ::= T <call-offset> <(base) encoding>
1718 ::= Tc <call-offset> <call-offset> <(base) encoding>
1719 Also g++ extensions:
1720 ::= TC <type> <(offset) number> _ <(base) type>
1725 ::= Gr <resource name>
1728 static struct demangle_component
*
1729 d_special_name (struct d_info
*di
)
1731 di
->expansion
+= 20;
1732 if (d_check_char (di
, 'T'))
1734 switch (d_next_char (di
))
1738 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1739 cplus_demangle_type (di
), NULL
);
1741 di
->expansion
-= 10;
1742 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1743 cplus_demangle_type (di
), NULL
);
1745 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1746 cplus_demangle_type (di
), NULL
);
1748 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1749 cplus_demangle_type (di
), NULL
);
1752 if (! d_call_offset (di
, 'h'))
1754 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1755 d_encoding (di
, 0), NULL
);
1758 if (! d_call_offset (di
, 'v'))
1760 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1761 d_encoding (di
, 0), NULL
);
1764 if (! d_call_offset (di
, '\0'))
1766 if (! d_call_offset (di
, '\0'))
1768 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1769 d_encoding (di
, 0), NULL
);
1773 struct demangle_component
*derived_type
;
1775 struct demangle_component
*base_type
;
1777 derived_type
= cplus_demangle_type (di
);
1778 offset
= d_number (di
);
1781 if (! d_check_char (di
, '_'))
1783 base_type
= cplus_demangle_type (di
);
1784 /* We don't display the offset. FIXME: We should display
1785 it in verbose mode. */
1787 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1788 base_type
, derived_type
);
1792 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1793 cplus_demangle_type (di
), NULL
);
1795 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1796 cplus_demangle_type (di
), NULL
);
1802 else if (d_check_char (di
, 'G'))
1804 switch (d_next_char (di
))
1807 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1810 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, d_name (di
),
1814 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1815 d_encoding (di
, 0), NULL
);
1818 return d_java_resource (di
);
1828 /* <call-offset> ::= h <nv-offset> _
1831 <nv-offset> ::= <(offset) number>
1833 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1835 The C parameter, if not '\0', is a character we just read which is
1836 the start of the <call-offset>.
1838 We don't display the offset information anywhere. FIXME: We should
1839 display it in verbose mode. */
1842 d_call_offset (struct d_info
*di
, int c
)
1845 c
= d_next_char (di
);
1852 if (! d_check_char (di
, '_'))
1859 if (! d_check_char (di
, '_'))
1865 /* <ctor-dtor-name> ::= C1
1873 static struct demangle_component
*
1874 d_ctor_dtor_name (struct d_info
*di
)
1876 if (di
->last_name
!= NULL
)
1878 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1879 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1880 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1881 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1883 switch (d_peek_char (di
))
1887 enum gnu_v3_ctor_kinds kind
;
1889 switch (d_peek_next_char (di
))
1892 kind
= gnu_v3_complete_object_ctor
;
1895 kind
= gnu_v3_base_object_ctor
;
1898 kind
= gnu_v3_complete_object_allocating_ctor
;
1904 return d_make_ctor (di
, kind
, di
->last_name
);
1909 enum gnu_v3_dtor_kinds kind
;
1911 switch (d_peek_next_char (di
))
1914 kind
= gnu_v3_deleting_dtor
;
1917 kind
= gnu_v3_complete_object_dtor
;
1920 kind
= gnu_v3_base_object_dtor
;
1926 return d_make_dtor (di
, kind
, di
->last_name
);
1934 /* <type> ::= <builtin-type>
1936 ::= <class-enum-type>
1938 ::= <pointer-to-member-type>
1939 ::= <template-param>
1940 ::= <template-template-param> <template-args>
1942 ::= <CV-qualifiers> <type>
1945 ::= O <type> (C++0x)
1948 ::= U <source-name> <type>
1950 <builtin-type> ::= various one letter codes
1954 CP_STATIC_IF_GLIBCPP_V3
1955 const struct demangle_builtin_type_info
1956 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
1958 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
1959 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
1960 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
1961 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
1962 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
1963 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
1964 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
1965 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
1966 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
1967 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
1968 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1969 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
1970 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
1971 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
1972 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
1974 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1975 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1976 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1977 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
1978 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
1979 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1980 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
1981 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
1982 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
1983 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
1984 D_PRINT_UNSIGNED_LONG_LONG
},
1985 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
1986 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
1987 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
1988 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
1989 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
1990 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
1991 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
1992 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
1996 CP_STATIC_IF_GLIBCPP_V3
1997 struct demangle_component
*
1998 cplus_demangle_type (struct d_info
*di
)
2001 struct demangle_component
*ret
;
2004 /* The ABI specifies that when CV-qualifiers are used, the base type
2005 is substitutable, and the fully qualified type is substitutable,
2006 but the base type with a strict subset of the CV-qualifiers is
2007 not substitutable. The natural recursive implementation of the
2008 CV-qualifiers would cause subsets to be substitutable, so instead
2009 we pull them all off now.
2011 FIXME: The ABI says that order-insensitive vendor qualifiers
2012 should be handled in the same way, but we have no way to tell
2013 which vendor qualifiers are order-insensitive and which are
2014 order-sensitive. So we just assume that they are all
2015 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2016 __vector, and it treats it as order-sensitive when mangling
2019 peek
= d_peek_char (di
);
2020 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2022 struct demangle_component
**pret
;
2024 pret
= d_cv_qualifiers (di
, &ret
, 0);
2027 *pret
= cplus_demangle_type (di
);
2028 if (! *pret
|| ! d_add_substitution (di
, ret
))
2037 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2038 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2039 case 'o': case 's': case 't':
2040 case 'v': case 'w': case 'x': case 'y': case 'z':
2041 ret
= d_make_builtin_type (di
,
2042 &cplus_demangle_builtin_types
[peek
- 'a']);
2043 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2050 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2051 d_source_name (di
), NULL
);
2055 ret
= d_function_type (di
);
2058 case '0': case '1': case '2': case '3': case '4':
2059 case '5': case '6': case '7': case '8': case '9':
2062 ret
= d_class_enum_type (di
);
2066 ret
= d_array_type (di
);
2070 ret
= d_pointer_to_member_type (di
);
2074 ret
= d_template_param (di
);
2075 if (d_peek_char (di
) == 'I')
2077 /* This is <template-template-param> <template-args>. The
2078 <template-template-param> part is a substitution
2080 if (! d_add_substitution (di
, ret
))
2082 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2083 d_template_args (di
));
2088 /* If this is a special substitution, then it is the start of
2089 <class-enum-type>. */
2093 peek_next
= d_peek_next_char (di
);
2094 if (IS_DIGIT (peek_next
)
2096 || IS_UPPER (peek_next
))
2098 ret
= d_substitution (di
, 0);
2099 /* The substituted name may have been a template name and
2100 may be followed by tepmlate args. */
2101 if (d_peek_char (di
) == 'I')
2102 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2103 d_template_args (di
));
2109 ret
= d_class_enum_type (di
);
2110 /* If the substitution was a complete type, then it is not
2111 a new substitution candidate. However, if the
2112 substitution was followed by template arguments, then
2113 the whole thing is a substitution candidate. */
2114 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2122 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2123 cplus_demangle_type (di
), NULL
);
2128 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2129 cplus_demangle_type (di
), NULL
);
2134 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2135 cplus_demangle_type (di
), NULL
);
2140 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2141 cplus_demangle_type (di
), NULL
);
2146 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2147 cplus_demangle_type (di
), NULL
);
2152 ret
= d_source_name (di
);
2153 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2154 cplus_demangle_type (di
), ret
);
2160 peek
= d_next_char (di
);
2165 /* decltype (expression) */
2166 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2167 d_expression (di
), NULL
);
2168 if (ret
&& d_next_char (di
) != 'E')
2173 /* Pack expansion. */
2174 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2175 cplus_demangle_type (di
), NULL
);
2179 /* 32-bit decimal floating point */
2180 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2181 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2185 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2186 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2190 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2191 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2194 /* 16-bit half-precision FP */
2195 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2196 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2200 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2201 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2205 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2206 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2210 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2211 ret
= d_make_empty (di
);
2212 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2213 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2214 /* For demangling we don't care about the bits. */
2216 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2217 if (ret
->u
.s_fixed
.length
== NULL
)
2220 peek
= d_next_char (di
);
2221 ret
->u
.s_fixed
.sat
= (peek
== 's');
2225 ret
= d_vector_type (di
);
2229 /* decltype(nullptr) */
2230 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2231 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2245 if (! d_add_substitution (di
, ret
))
2252 /* <CV-qualifiers> ::= [r] [V] [K] */
2254 static struct demangle_component
**
2255 d_cv_qualifiers (struct d_info
*di
,
2256 struct demangle_component
**pret
, int member_fn
)
2260 peek
= d_peek_char (di
);
2261 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2263 enum demangle_component_type t
;
2269 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2270 : DEMANGLE_COMPONENT_RESTRICT
);
2271 di
->expansion
+= sizeof "restrict";
2273 else if (peek
== 'V')
2276 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2277 : DEMANGLE_COMPONENT_VOLATILE
);
2278 di
->expansion
+= sizeof "volatile";
2283 ? DEMANGLE_COMPONENT_CONST_THIS
2284 : DEMANGLE_COMPONENT_CONST
);
2285 di
->expansion
+= sizeof "const";
2288 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2291 pret
= &d_left (*pret
);
2293 peek
= d_peek_char (di
);
2299 /* <function-type> ::= F [Y] <bare-function-type> E */
2301 static struct demangle_component
*
2302 d_function_type (struct d_info
*di
)
2304 struct demangle_component
*ret
;
2306 if (! d_check_char (di
, 'F'))
2308 if (d_peek_char (di
) == 'Y')
2310 /* Function has C linkage. We don't print this information.
2311 FIXME: We should print it in verbose mode. */
2314 ret
= d_bare_function_type (di
, 1);
2315 if (! d_check_char (di
, 'E'))
2322 static struct demangle_component
*
2323 d_parmlist (struct d_info
*di
)
2325 struct demangle_component
*tl
;
2326 struct demangle_component
**ptl
;
2332 struct demangle_component
*type
;
2334 char peek
= d_peek_char (di
);
2335 if (peek
== '\0' || peek
== 'E')
2337 type
= cplus_demangle_type (di
);
2340 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2343 ptl
= &d_right (*ptl
);
2346 /* There should be at least one parameter type besides the optional
2347 return type. A function which takes no arguments will have a
2348 single parameter type void. */
2352 /* If we have a single parameter type void, omit it. */
2353 if (d_right (tl
) == NULL
2354 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2355 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2357 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2364 /* <bare-function-type> ::= [J]<type>+ */
2366 static struct demangle_component
*
2367 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2369 struct demangle_component
*return_type
;
2370 struct demangle_component
*tl
;
2373 /* Detect special qualifier indicating that the first argument
2374 is the return type. */
2375 peek
= d_peek_char (di
);
2379 has_return_type
= 1;
2382 if (has_return_type
)
2384 return_type
= cplus_demangle_type (di
);
2385 if (return_type
== NULL
)
2391 tl
= d_parmlist (di
);
2395 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2399 /* <class-enum-type> ::= <name> */
2401 static struct demangle_component
*
2402 d_class_enum_type (struct d_info
*di
)
2407 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2408 ::= A [<(dimension) expression>] _ <(element) type>
2411 static struct demangle_component
*
2412 d_array_type (struct d_info
*di
)
2415 struct demangle_component
*dim
;
2417 if (! d_check_char (di
, 'A'))
2420 peek
= d_peek_char (di
);
2423 else if (IS_DIGIT (peek
))
2431 peek
= d_peek_char (di
);
2433 while (IS_DIGIT (peek
));
2434 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2440 dim
= d_expression (di
);
2445 if (! d_check_char (di
, '_'))
2448 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2449 cplus_demangle_type (di
));
2452 /* <vector-type> ::= Dv <number> _ <type>
2453 ::= Dv _ <expression> _ <type> */
2455 static struct demangle_component
*
2456 d_vector_type (struct d_info
*di
)
2459 struct demangle_component
*dim
;
2461 peek
= d_peek_char (di
);
2465 dim
= d_expression (di
);
2468 dim
= d_number_component (di
);
2473 if (! d_check_char (di
, '_'))
2476 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2477 cplus_demangle_type (di
));
2480 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2482 static struct demangle_component
*
2483 d_pointer_to_member_type (struct d_info
*di
)
2485 struct demangle_component
*cl
;
2486 struct demangle_component
*mem
;
2487 struct demangle_component
**pmem
;
2489 if (! d_check_char (di
, 'M'))
2492 cl
= cplus_demangle_type (di
);
2494 /* The ABI specifies that any type can be a substitution source, and
2495 that M is followed by two types, and that when a CV-qualified
2496 type is seen both the base type and the CV-qualified types are
2497 substitution sources. The ABI also specifies that for a pointer
2498 to a CV-qualified member function, the qualifiers are attached to
2499 the second type. Given the grammar, a plain reading of the ABI
2500 suggests that both the CV-qualified member function and the
2501 non-qualified member function are substitution sources. However,
2502 g++ does not work that way. g++ treats only the CV-qualified
2503 member function as a substitution source. FIXME. So to work
2504 with g++, we need to pull off the CV-qualifiers here, in order to
2505 avoid calling add_substitution() in cplus_demangle_type(). But
2506 for a CV-qualified member which is not a function, g++ does
2507 follow the ABI, so we need to handle that case here by calling
2508 d_add_substitution ourselves. */
2510 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2513 *pmem
= cplus_demangle_type (di
);
2517 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2519 if (! d_add_substitution (di
, mem
))
2523 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2526 /* <non-negative number> _ */
2529 d_compact_number (struct d_info
*di
)
2532 if (d_peek_char (di
) == '_')
2534 else if (d_peek_char (di
) == 'n')
2537 num
= d_number (di
) + 1;
2539 if (! d_check_char (di
, '_'))
2544 /* <template-param> ::= T_
2545 ::= T <(parameter-2 non-negative) number> _
2548 static struct demangle_component
*
2549 d_template_param (struct d_info
*di
)
2553 if (! d_check_char (di
, 'T'))
2556 param
= d_compact_number (di
);
2562 return d_make_template_param (di
, param
);
2565 /* <template-args> ::= I <template-arg>+ E */
2567 static struct demangle_component
*
2568 d_template_args (struct d_info
*di
)
2570 struct demangle_component
*hold_last_name
;
2571 struct demangle_component
*al
;
2572 struct demangle_component
**pal
;
2574 /* Preserve the last name we saw--don't let the template arguments
2575 clobber it, as that would give us the wrong name for a subsequent
2576 constructor or destructor. */
2577 hold_last_name
= di
->last_name
;
2579 if (! d_check_char (di
, 'I'))
2582 if (d_peek_char (di
) == 'E')
2584 /* An argument pack can be empty. */
2586 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2593 struct demangle_component
*a
;
2595 a
= d_template_arg (di
);
2599 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2602 pal
= &d_right (*pal
);
2604 if (d_peek_char (di
) == 'E')
2611 di
->last_name
= hold_last_name
;
2616 /* <template-arg> ::= <type>
2617 ::= X <expression> E
2621 static struct demangle_component
*
2622 d_template_arg (struct d_info
*di
)
2624 struct demangle_component
*ret
;
2626 switch (d_peek_char (di
))
2630 ret
= d_expression (di
);
2631 if (! d_check_char (di
, 'E'))
2636 return d_expr_primary (di
);
2639 /* An argument pack. */
2640 return d_template_args (di
);
2643 return cplus_demangle_type (di
);
2647 /* Subroutine of <expression> ::= cl <expression>+ E */
2649 static struct demangle_component
*
2650 d_exprlist (struct d_info
*di
)
2652 struct demangle_component
*list
= NULL
;
2653 struct demangle_component
**p
= &list
;
2655 if (d_peek_char (di
) == 'E')
2658 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2663 struct demangle_component
*arg
= d_expression (di
);
2667 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2672 if (d_peek_char (di
) == 'E')
2682 /* <expression> ::= <(unary) operator-name> <expression>
2683 ::= <(binary) operator-name> <expression> <expression>
2684 ::= <(trinary) operator-name> <expression> <expression> <expression>
2685 ::= cl <expression>+ E
2687 ::= <template-param>
2688 ::= sr <type> <unqualified-name>
2689 ::= sr <type> <unqualified-name> <template-args>
2693 static struct demangle_component
*
2694 d_expression (struct d_info
*di
)
2698 peek
= d_peek_char (di
);
2700 return d_expr_primary (di
);
2701 else if (peek
== 'T')
2702 return d_template_param (di
);
2703 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2705 struct demangle_component
*type
;
2706 struct demangle_component
*name
;
2709 type
= cplus_demangle_type (di
);
2710 name
= d_unqualified_name (di
);
2711 if (d_peek_char (di
) != 'I')
2712 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2714 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2715 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2716 d_template_args (di
)));
2718 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
2721 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2722 d_expression (di
), NULL
);
2724 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
2726 /* Function parameter used in a late-specified return type. */
2729 index
= d_compact_number (di
);
2733 return d_make_function_param (di
, index
);
2735 else if (IS_DIGIT (peek
)
2736 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
2738 /* We can get an unqualified name as an expression in the case of
2739 a dependent function call, i.e. decltype(f(t)). */
2740 struct demangle_component
*name
;
2743 /* operator-function-id, i.e. operator+(t). */
2746 name
= d_unqualified_name (di
);
2749 if (d_peek_char (di
) == 'I')
2750 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2751 d_template_args (di
));
2757 struct demangle_component
*op
;
2760 op
= d_operator_name (di
);
2764 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2765 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2767 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2768 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2769 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2770 cplus_demangle_type (di
));
2776 case DEMANGLE_COMPONENT_OPERATOR
:
2777 args
= op
->u
.s_operator
.op
->args
;
2779 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2780 args
= op
->u
.s_extended_operator
.args
;
2782 case DEMANGLE_COMPONENT_CAST
:
2791 struct demangle_component
*operand
;
2792 if (op
->type
== DEMANGLE_COMPONENT_CAST
2793 && d_check_char (di
, '_'))
2794 operand
= d_exprlist (di
);
2796 operand
= d_expression (di
);
2797 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2802 struct demangle_component
*left
;
2803 struct demangle_component
*right
;
2804 const char *code
= op
->u
.s_operator
.op
->code
;
2806 left
= d_expression (di
);
2807 if (!strcmp (code
, "cl"))
2808 right
= d_exprlist (di
);
2809 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
2811 right
= d_unqualified_name (di
);
2812 if (d_peek_char (di
) == 'I')
2813 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
2814 right
, d_template_args (di
));
2817 right
= d_expression (di
);
2819 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2821 DEMANGLE_COMPONENT_BINARY_ARGS
,
2826 struct demangle_component
*first
;
2827 struct demangle_component
*second
;
2829 first
= d_expression (di
);
2830 second
= d_expression (di
);
2831 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2833 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2836 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2838 d_expression (di
))));
2846 /* <expr-primary> ::= L <type> <(value) number> E
2847 ::= L <type> <(value) float> E
2848 ::= L <mangled-name> E
2851 static struct demangle_component
*
2852 d_expr_primary (struct d_info
*di
)
2854 struct demangle_component
*ret
;
2856 if (! d_check_char (di
, 'L'))
2858 if (d_peek_char (di
) == '_'
2859 /* Workaround for G++ bug; see comment in write_template_arg. */
2860 || d_peek_char (di
) == 'Z')
2861 ret
= cplus_demangle_mangled_name (di
, 0);
2864 struct demangle_component
*type
;
2865 enum demangle_component_type t
;
2868 type
= cplus_demangle_type (di
);
2872 /* If we have a type we know how to print, we aren't going to
2873 print the type name itself. */
2874 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2875 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2876 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2878 /* Rather than try to interpret the literal value, we just
2879 collect it as a string. Note that it's possible to have a
2880 floating point literal here. The ABI specifies that the
2881 format of such literals is machine independent. That's fine,
2882 but what's not fine is that versions of g++ up to 3.2 with
2883 -fabi-version=1 used upper case letters in the hex constant,
2884 and dumped out gcc's internal representation. That makes it
2885 hard to tell where the constant ends, and hard to dump the
2886 constant in any readable form anyhow. We don't attempt to
2887 handle these cases. */
2889 t
= DEMANGLE_COMPONENT_LITERAL
;
2890 if (d_peek_char (di
) == 'n')
2892 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2896 while (d_peek_char (di
) != 'E')
2898 if (d_peek_char (di
) == '\0')
2902 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2904 if (! d_check_char (di
, 'E'))
2909 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2910 ::= Z <(function) encoding> E s [<discriminator>]
2913 static struct demangle_component
*
2914 d_local_name (struct d_info
*di
)
2916 struct demangle_component
*function
;
2918 if (! d_check_char (di
, 'Z'))
2921 function
= d_encoding (di
, 0);
2923 if (! d_check_char (di
, 'E'))
2926 if (d_peek_char (di
) == 's')
2929 if (! d_discriminator (di
))
2931 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
2932 d_make_name (di
, "string literal",
2933 sizeof "string literal" - 1));
2937 struct demangle_component
*name
;
2940 if (d_peek_char (di
) == 'd')
2942 /* Default argument scope: d <number> _. */
2944 num
= d_compact_number (di
);
2953 /* Lambdas and unnamed types have internal discriminators. */
2954 case DEMANGLE_COMPONENT_LAMBDA
:
2955 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
2958 if (! d_discriminator (di
))
2962 name
= d_make_default_arg (di
, num
, name
);
2963 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
2967 /* <discriminator> ::= _ <(non-negative) number>
2969 We demangle the discriminator, but we don't print it out. FIXME:
2970 We should print it out in verbose mode. */
2973 d_discriminator (struct d_info
*di
)
2977 if (d_peek_char (di
) != '_')
2980 discrim
= d_number (di
);
2986 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
2988 static struct demangle_component
*
2989 d_lambda (struct d_info
*di
)
2991 struct demangle_component
*tl
;
2992 struct demangle_component
*ret
;
2995 if (! d_check_char (di
, 'U'))
2997 if (! d_check_char (di
, 'l'))
3000 tl
= d_parmlist (di
);
3004 if (! d_check_char (di
, 'E'))
3007 num
= d_compact_number (di
);
3011 ret
= d_make_empty (di
);
3014 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3015 ret
->u
.s_unary_num
.sub
= tl
;
3016 ret
->u
.s_unary_num
.num
= num
;
3019 if (! d_add_substitution (di
, ret
))
3025 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3027 static struct demangle_component
*
3028 d_unnamed_type (struct d_info
*di
)
3030 struct demangle_component
*ret
;
3033 if (! d_check_char (di
, 'U'))
3035 if (! d_check_char (di
, 't'))
3038 num
= d_compact_number (di
);
3042 ret
= d_make_empty (di
);
3045 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3046 ret
->u
.s_number
.number
= num
;
3049 if (! d_add_substitution (di
, ret
))
3055 /* Add a new substitution. */
3058 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3062 if (di
->next_sub
>= di
->num_subs
)
3064 di
->subs
[di
->next_sub
] = dc
;
3069 /* <substitution> ::= S <seq-id> _
3079 If PREFIX is non-zero, then this type is being used as a prefix in
3080 a qualified name. In this case, for the standard substitutions, we
3081 need to check whether we are being used as a prefix for a
3082 constructor or destructor, and return a full template name.
3083 Otherwise we will get something like std::iostream::~iostream()
3084 which does not correspond particularly well to any function which
3085 actually appears in the source.
3088 static const struct d_standard_sub_info standard_subs
[] =
3093 { 'a', NL ("std::allocator"),
3094 NL ("std::allocator"),
3096 { 'b', NL ("std::basic_string"),
3097 NL ("std::basic_string"),
3098 NL ("basic_string") },
3099 { 's', NL ("std::string"),
3100 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3101 NL ("basic_string") },
3102 { 'i', NL ("std::istream"),
3103 NL ("std::basic_istream<char, std::char_traits<char> >"),
3104 NL ("basic_istream") },
3105 { 'o', NL ("std::ostream"),
3106 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3107 NL ("basic_ostream") },
3108 { 'd', NL ("std::iostream"),
3109 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3110 NL ("basic_iostream") }
3113 static struct demangle_component
*
3114 d_substitution (struct d_info
*di
, int prefix
)
3118 if (! d_check_char (di
, 'S'))
3121 c
= d_next_char (di
);
3122 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3131 unsigned int new_id
;
3134 new_id
= id
* 36 + c
- '0';
3135 else if (IS_UPPER (c
))
3136 new_id
= id
* 36 + c
- 'A' + 10;
3142 c
= d_next_char (di
);
3149 if (id
>= (unsigned int) di
->next_sub
)
3154 return di
->subs
[id
];
3159 const struct d_standard_sub_info
*p
;
3160 const struct d_standard_sub_info
*pend
;
3162 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3163 if (! verbose
&& prefix
)
3167 peek
= d_peek_char (di
);
3168 if (peek
== 'C' || peek
== 'D')
3172 pend
= (&standard_subs
[0]
3173 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3174 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3181 if (p
->set_last_name
!= NULL
)
3182 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3183 p
->set_last_name_len
);
3186 s
= p
->full_expansion
;
3191 s
= p
->simple_expansion
;
3192 len
= p
->simple_len
;
3194 di
->expansion
+= len
;
3195 return d_make_sub (di
, s
, len
);
3203 /* Initialize a growable string. */
3206 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3211 dgs
->allocation_failure
= 0;
3214 d_growable_string_resize (dgs
, estimate
);
3217 /* Grow a growable string to a given size. */
3220 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3225 if (dgs
->allocation_failure
)
3228 /* Start allocation at two bytes to avoid any possibility of confusion
3229 with the special value of 1 used as a return in *palc to indicate
3230 allocation failures. */
3231 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3232 while (newalc
< need
)
3235 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3242 dgs
->allocation_failure
= 1;
3249 /* Append a buffer to a growable string. */
3252 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3253 const char *s
, size_t l
)
3257 need
= dgs
->len
+ l
+ 1;
3258 if (need
> dgs
->alc
)
3259 d_growable_string_resize (dgs
, need
);
3261 if (dgs
->allocation_failure
)
3264 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3265 dgs
->buf
[dgs
->len
+ l
] = '\0';
3269 /* Bridge growable strings to the callback mechanism. */
3272 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3274 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3276 d_growable_string_append_buffer (dgs
, s
, l
);
3279 /* Initialize a print information structure. */
3282 d_print_init (struct d_print_info
*dpi
, int options
,
3283 demangle_callbackref callback
, void *opaque
)
3285 dpi
->options
= options
;
3287 dpi
->last_char
= '\0';
3288 dpi
->templates
= NULL
;
3289 dpi
->modifiers
= NULL
;
3290 dpi
->flush_count
= 0;
3292 dpi
->callback
= callback
;
3293 dpi
->opaque
= opaque
;
3295 dpi
->demangle_failure
= 0;
3298 /* Indicate that an error occurred during printing, and test for error. */
3301 d_print_error (struct d_print_info
*dpi
)
3303 dpi
->demangle_failure
= 1;
3307 d_print_saw_error (struct d_print_info
*dpi
)
3309 return dpi
->demangle_failure
!= 0;
3312 /* Flush buffered characters to the callback. */
3315 d_print_flush (struct d_print_info
*dpi
)
3317 dpi
->buf
[dpi
->len
] = '\0';
3318 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3323 /* Append characters and buffers for printing. */
3326 d_append_char (struct d_print_info
*dpi
, char c
)
3328 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3329 d_print_flush (dpi
);
3331 dpi
->buf
[dpi
->len
++] = c
;
3336 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3340 for (i
= 0; i
< l
; i
++)
3341 d_append_char (dpi
, s
[i
]);
3345 d_append_string (struct d_print_info
*dpi
, const char *s
)
3347 d_append_buffer (dpi
, s
, strlen (s
));
3351 d_append_num (struct d_print_info
*dpi
, long l
)
3354 sprintf (buf
,"%ld", l
);
3355 d_append_string (dpi
, buf
);
3359 d_last_char (struct d_print_info
*dpi
)
3361 return dpi
->last_char
;
3364 /* Turn components into a human readable string. OPTIONS is the
3365 options bits passed to the demangler. DC is the tree to print.
3366 CALLBACK is a function to call to flush demangled string segments
3367 as they fill the intermediate buffer, and OPAQUE is a generalized
3368 callback argument. On success, this returns 1. On failure,
3369 it returns 0, indicating a bad parse. It does not use heap
3370 memory to build an output string, so cannot encounter memory
3371 allocation failure. */
3373 CP_STATIC_IF_GLIBCPP_V3
3375 cplus_demangle_print_callback (int options
,
3376 const struct demangle_component
*dc
,
3377 demangle_callbackref callback
, void *opaque
)
3379 struct d_print_info dpi
;
3381 d_print_init (&dpi
, options
, callback
, opaque
);
3383 d_print_comp (&dpi
, dc
);
3385 d_print_flush (&dpi
);
3387 return ! d_print_saw_error (&dpi
);
3390 /* Turn components into a human readable string. OPTIONS is the
3391 options bits passed to the demangler. DC is the tree to print.
3392 ESTIMATE is a guess at the length of the result. This returns a
3393 string allocated by malloc, or NULL on error. On success, this
3394 sets *PALC to the size of the allocated buffer. On failure, this
3395 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3398 CP_STATIC_IF_GLIBCPP_V3
3400 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3401 int estimate
, size_t *palc
)
3403 struct d_growable_string dgs
;
3405 d_growable_string_init (&dgs
, estimate
);
3407 if (! cplus_demangle_print_callback (options
, dc
,
3408 d_growable_string_callback_adapter
,
3416 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3420 /* Returns the I'th element of the template arglist ARGS, or NULL on
3423 static struct demangle_component
*
3424 d_index_template_argument (struct demangle_component
*args
, int i
)
3426 struct demangle_component
*a
;
3432 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3438 if (i
!= 0 || a
== NULL
)
3444 /* Returns the template argument from the current context indicated by DC,
3445 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3447 static struct demangle_component
*
3448 d_lookup_template_argument (struct d_print_info
*dpi
,
3449 const struct demangle_component
*dc
)
3451 if (dpi
->templates
== NULL
)
3453 d_print_error (dpi
);
3457 return d_index_template_argument
3458 (d_right (dpi
->templates
->template_decl
),
3459 dc
->u
.s_number
.number
);
3462 /* Returns a template argument pack used in DC (any will do), or NULL. */
3464 static struct demangle_component
*
3465 d_find_pack (struct d_print_info
*dpi
,
3466 const struct demangle_component
*dc
)
3468 struct demangle_component
*a
;
3474 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3475 a
= d_lookup_template_argument (dpi
, dc
);
3476 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3480 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3483 case DEMANGLE_COMPONENT_LAMBDA
:
3484 case DEMANGLE_COMPONENT_NAME
:
3485 case DEMANGLE_COMPONENT_OPERATOR
:
3486 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3487 case DEMANGLE_COMPONENT_SUB_STD
:
3488 case DEMANGLE_COMPONENT_CHARACTER
:
3489 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3492 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3493 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3494 case DEMANGLE_COMPONENT_CTOR
:
3495 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3496 case DEMANGLE_COMPONENT_DTOR
:
3497 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3500 a
= d_find_pack (dpi
, d_left (dc
));
3503 return d_find_pack (dpi
, d_right (dc
));
3507 /* Returns the length of the template argument pack DC. */
3510 d_pack_length (const struct demangle_component
*dc
)
3513 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3514 && d_left (dc
) != NULL
)
3522 /* DC is a component of a mangled expression. Print it, wrapped in parens
3526 d_print_subexpr (struct d_print_info
*dpi
,
3527 const struct demangle_component
*dc
)
3530 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3531 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3534 d_append_char (dpi
, '(');
3535 d_print_comp (dpi
, dc
);
3537 d_append_char (dpi
, ')');
3540 /* Subroutine to handle components. */
3543 d_print_comp (struct d_print_info
*dpi
,
3544 const struct demangle_component
*dc
)
3548 d_print_error (dpi
);
3551 if (d_print_saw_error (dpi
))
3556 case DEMANGLE_COMPONENT_NAME
:
3557 if ((dpi
->options
& DMGL_JAVA
) == 0)
3558 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3560 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3563 case DEMANGLE_COMPONENT_QUAL_NAME
:
3564 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3565 d_print_comp (dpi
, d_left (dc
));
3566 if ((dpi
->options
& DMGL_JAVA
) == 0)
3567 d_append_string (dpi
, "::");
3569 d_append_char (dpi
, '.');
3570 d_print_comp (dpi
, d_right (dc
));
3573 case DEMANGLE_COMPONENT_TYPED_NAME
:
3575 struct d_print_mod
*hold_modifiers
;
3576 struct demangle_component
*typed_name
;
3577 struct d_print_mod adpm
[4];
3579 struct d_print_template dpt
;
3581 /* Pass the name down to the type so that it can be printed in
3582 the right place for the type. We also have to pass down
3583 any CV-qualifiers, which apply to the this parameter. */
3584 hold_modifiers
= dpi
->modifiers
;
3587 typed_name
= d_left (dc
);
3588 while (typed_name
!= NULL
)
3590 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3592 d_print_error (dpi
);
3596 adpm
[i
].next
= dpi
->modifiers
;
3597 dpi
->modifiers
= &adpm
[i
];
3598 adpm
[i
].mod
= typed_name
;
3599 adpm
[i
].printed
= 0;
3600 adpm
[i
].templates
= dpi
->templates
;
3603 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3604 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3605 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3608 typed_name
= d_left (typed_name
);
3611 if (typed_name
== NULL
)
3613 d_print_error (dpi
);
3617 /* If typed_name is a template, then it applies to the
3618 function type as well. */
3619 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3621 dpt
.next
= dpi
->templates
;
3622 dpi
->templates
= &dpt
;
3623 dpt
.template_decl
= typed_name
;
3626 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3627 there may be CV-qualifiers on its right argument which
3628 really apply here; this happens when parsing a class which
3629 is local to a function. */
3630 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3632 struct demangle_component
*local_name
;
3634 local_name
= d_right (typed_name
);
3635 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
3636 local_name
= local_name
->u
.s_unary_num
.sub
;
3637 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3638 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3639 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3641 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3643 d_print_error (dpi
);
3647 adpm
[i
] = adpm
[i
- 1];
3648 adpm
[i
].next
= &adpm
[i
- 1];
3649 dpi
->modifiers
= &adpm
[i
];
3651 adpm
[i
- 1].mod
= local_name
;
3652 adpm
[i
- 1].printed
= 0;
3653 adpm
[i
- 1].templates
= dpi
->templates
;
3656 local_name
= d_left (local_name
);
3660 d_print_comp (dpi
, d_right (dc
));
3662 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3663 dpi
->templates
= dpt
.next
;
3665 /* If the modifiers didn't get printed by the type, print them
3670 if (! adpm
[i
].printed
)
3672 d_append_char (dpi
, ' ');
3673 d_print_mod (dpi
, adpm
[i
].mod
);
3677 dpi
->modifiers
= hold_modifiers
;
3682 case DEMANGLE_COMPONENT_TEMPLATE
:
3684 struct d_print_mod
*hold_dpm
;
3685 struct demangle_component
*dcl
;
3687 /* Don't push modifiers into a template definition. Doing so
3688 could give the wrong definition for a template argument.
3689 Instead, treat the template essentially as a name. */
3691 hold_dpm
= dpi
->modifiers
;
3692 dpi
->modifiers
= NULL
;
3696 if ((dpi
->options
& DMGL_JAVA
) != 0
3697 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3698 && dcl
->u
.s_name
.len
== 6
3699 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3701 /* Special-case Java arrays, so that JArray<TYPE> appears
3702 instead as TYPE[]. */
3704 d_print_comp (dpi
, d_right (dc
));
3705 d_append_string (dpi
, "[]");
3709 d_print_comp (dpi
, dcl
);
3710 if (d_last_char (dpi
) == '<')
3711 d_append_char (dpi
, ' ');
3712 d_append_char (dpi
, '<');
3713 d_print_comp (dpi
, d_right (dc
));
3714 /* Avoid generating two consecutive '>' characters, to avoid
3715 the C++ syntactic ambiguity. */
3716 if (d_last_char (dpi
) == '>')
3717 d_append_char (dpi
, ' ');
3718 d_append_char (dpi
, '>');
3721 dpi
->modifiers
= hold_dpm
;
3726 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3728 struct d_print_template
*hold_dpt
;
3729 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
3731 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3732 a
= d_index_template_argument (a
, dpi
->pack_index
);
3736 d_print_error (dpi
);
3740 /* While processing this parameter, we need to pop the list of
3741 templates. This is because the template parameter may
3742 itself be a reference to a parameter of an outer
3745 hold_dpt
= dpi
->templates
;
3746 dpi
->templates
= hold_dpt
->next
;
3748 d_print_comp (dpi
, a
);
3750 dpi
->templates
= hold_dpt
;
3755 case DEMANGLE_COMPONENT_CTOR
:
3756 d_print_comp (dpi
, dc
->u
.s_ctor
.name
);
3759 case DEMANGLE_COMPONENT_DTOR
:
3760 d_append_char (dpi
, '~');
3761 d_print_comp (dpi
, dc
->u
.s_dtor
.name
);
3764 case DEMANGLE_COMPONENT_VTABLE
:
3765 d_append_string (dpi
, "vtable for ");
3766 d_print_comp (dpi
, d_left (dc
));
3769 case DEMANGLE_COMPONENT_VTT
:
3770 d_append_string (dpi
, "VTT for ");
3771 d_print_comp (dpi
, d_left (dc
));
3774 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3775 d_append_string (dpi
, "construction vtable for ");
3776 d_print_comp (dpi
, d_left (dc
));
3777 d_append_string (dpi
, "-in-");
3778 d_print_comp (dpi
, d_right (dc
));
3781 case DEMANGLE_COMPONENT_TYPEINFO
:
3782 d_append_string (dpi
, "typeinfo for ");
3783 d_print_comp (dpi
, d_left (dc
));
3786 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3787 d_append_string (dpi
, "typeinfo name for ");
3788 d_print_comp (dpi
, d_left (dc
));
3791 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3792 d_append_string (dpi
, "typeinfo fn for ");
3793 d_print_comp (dpi
, d_left (dc
));
3796 case DEMANGLE_COMPONENT_THUNK
:
3797 d_append_string (dpi
, "non-virtual thunk to ");
3798 d_print_comp (dpi
, d_left (dc
));
3801 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3802 d_append_string (dpi
, "virtual thunk to ");
3803 d_print_comp (dpi
, d_left (dc
));
3806 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3807 d_append_string (dpi
, "covariant return thunk to ");
3808 d_print_comp (dpi
, d_left (dc
));
3811 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3812 d_append_string (dpi
, "java Class for ");
3813 d_print_comp (dpi
, d_left (dc
));
3816 case DEMANGLE_COMPONENT_GUARD
:
3817 d_append_string (dpi
, "guard variable for ");
3818 d_print_comp (dpi
, d_left (dc
));
3821 case DEMANGLE_COMPONENT_REFTEMP
:
3822 d_append_string (dpi
, "reference temporary for ");
3823 d_print_comp (dpi
, d_left (dc
));
3826 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3827 d_append_string (dpi
, "hidden alias for ");
3828 d_print_comp (dpi
, d_left (dc
));
3831 case DEMANGLE_COMPONENT_SUB_STD
:
3832 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3835 case DEMANGLE_COMPONENT_RESTRICT
:
3836 case DEMANGLE_COMPONENT_VOLATILE
:
3837 case DEMANGLE_COMPONENT_CONST
:
3839 struct d_print_mod
*pdpm
;
3841 /* When printing arrays, it's possible to have cases where the
3842 same CV-qualifier gets pushed on the stack multiple times.
3843 We only need to print it once. */
3845 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3847 if (! pdpm
->printed
)
3849 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3850 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3851 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3853 if (pdpm
->mod
->type
== dc
->type
)
3855 d_print_comp (dpi
, d_left (dc
));
3862 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3863 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3864 case DEMANGLE_COMPONENT_CONST_THIS
:
3865 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3866 case DEMANGLE_COMPONENT_POINTER
:
3867 case DEMANGLE_COMPONENT_REFERENCE
:
3868 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3869 case DEMANGLE_COMPONENT_COMPLEX
:
3870 case DEMANGLE_COMPONENT_IMAGINARY
:
3872 /* We keep a list of modifiers on the stack. */
3873 struct d_print_mod dpm
;
3875 dpm
.next
= dpi
->modifiers
;
3876 dpi
->modifiers
= &dpm
;
3879 dpm
.templates
= dpi
->templates
;
3881 d_print_comp (dpi
, d_left (dc
));
3883 /* If the modifier didn't get printed by the type, print it
3886 d_print_mod (dpi
, dc
);
3888 dpi
->modifiers
= dpm
.next
;
3893 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3894 if ((dpi
->options
& DMGL_JAVA
) == 0)
3895 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
3896 dc
->u
.s_builtin
.type
->len
);
3898 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
3899 dc
->u
.s_builtin
.type
->java_len
);
3902 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3903 d_print_comp (dpi
, d_left (dc
));
3906 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3908 if ((dpi
->options
& DMGL_RET_POSTFIX
) != 0)
3909 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3911 /* Print return type if present */
3912 if (d_left (dc
) != NULL
)
3914 struct d_print_mod dpm
;
3916 /* We must pass this type down as a modifier in order to
3917 print it in the right location. */
3918 dpm
.next
= dpi
->modifiers
;
3919 dpi
->modifiers
= &dpm
;
3922 dpm
.templates
= dpi
->templates
;
3924 d_print_comp (dpi
, d_left (dc
));
3926 dpi
->modifiers
= dpm
.next
;
3931 /* In standard prefix notation, there is a space between the
3932 return type and the function signature. */
3933 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3934 d_append_char (dpi
, ' ');
3937 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3938 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3943 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3945 struct d_print_mod
*hold_modifiers
;
3946 struct d_print_mod adpm
[4];
3948 struct d_print_mod
*pdpm
;
3950 /* We must pass this type down as a modifier in order to print
3951 multi-dimensional arrays correctly. If the array itself is
3952 CV-qualified, we act as though the element type were
3953 CV-qualified. We do this by copying the modifiers down
3954 rather than fiddling pointers, so that we don't wind up
3955 with a d_print_mod higher on the stack pointing into our
3956 stack frame after we return. */
3958 hold_modifiers
= dpi
->modifiers
;
3960 adpm
[0].next
= hold_modifiers
;
3961 dpi
->modifiers
= &adpm
[0];
3963 adpm
[0].printed
= 0;
3964 adpm
[0].templates
= dpi
->templates
;
3967 pdpm
= hold_modifiers
;
3969 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
3970 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
3971 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
3973 if (! pdpm
->printed
)
3975 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3977 d_print_error (dpi
);
3982 adpm
[i
].next
= dpi
->modifiers
;
3983 dpi
->modifiers
= &adpm
[i
];
3991 d_print_comp (dpi
, d_right (dc
));
3993 dpi
->modifiers
= hold_modifiers
;
3995 if (adpm
[0].printed
)
4001 d_print_mod (dpi
, adpm
[i
].mod
);
4004 d_print_array_type (dpi
, dc
, dpi
->modifiers
);
4009 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4010 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4012 struct d_print_mod dpm
;
4014 dpm
.next
= dpi
->modifiers
;
4015 dpi
->modifiers
= &dpm
;
4018 dpm
.templates
= dpi
->templates
;
4020 d_print_comp (dpi
, d_right (dc
));
4022 /* If the modifier didn't get printed by the type, print it
4025 d_print_mod (dpi
, dc
);
4027 dpi
->modifiers
= dpm
.next
;
4032 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4033 if (dc
->u
.s_fixed
.sat
)
4034 d_append_string (dpi
, "_Sat ");
4035 /* Don't print "int _Accum". */
4036 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4037 != &cplus_demangle_builtin_types
['i'-'a'])
4039 d_print_comp (dpi
, dc
->u
.s_fixed
.length
);
4040 d_append_char (dpi
, ' ');
4042 if (dc
->u
.s_fixed
.accum
)
4043 d_append_string (dpi
, "_Accum");
4045 d_append_string (dpi
, "_Fract");
4048 case DEMANGLE_COMPONENT_ARGLIST
:
4049 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4050 if (d_left (dc
) != NULL
)
4051 d_print_comp (dpi
, d_left (dc
));
4052 if (d_right (dc
) != NULL
)
4055 unsigned long int flush_count
;
4056 /* Make sure ", " isn't flushed by d_append_string, otherwise
4057 dpi->len -= 2 wouldn't work. */
4058 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4059 d_print_flush (dpi
);
4060 d_append_string (dpi
, ", ");
4062 flush_count
= dpi
->flush_count
;
4063 d_print_comp (dpi
, d_right (dc
));
4064 /* If that didn't print anything (which can happen with empty
4065 template argument packs), remove the comma and space. */
4066 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4071 case DEMANGLE_COMPONENT_OPERATOR
:
4075 d_append_string (dpi
, "operator");
4076 c
= dc
->u
.s_operator
.op
->name
[0];
4078 d_append_char (dpi
, ' ');
4079 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4080 dc
->u
.s_operator
.op
->len
);
4084 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4085 d_append_string (dpi
, "operator ");
4086 d_print_comp (dpi
, dc
->u
.s_extended_operator
.name
);
4089 case DEMANGLE_COMPONENT_CAST
:
4090 d_append_string (dpi
, "operator ");
4091 d_print_cast (dpi
, dc
);
4094 case DEMANGLE_COMPONENT_UNARY
:
4095 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
4096 d_print_expr_op (dpi
, d_left (dc
));
4099 d_append_char (dpi
, '(');
4100 d_print_cast (dpi
, d_left (dc
));
4101 d_append_char (dpi
, ')');
4103 d_print_subexpr (dpi
, d_right (dc
));
4106 case DEMANGLE_COMPONENT_BINARY
:
4107 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4109 d_print_error (dpi
);
4113 /* We wrap an expression which uses the greater-than operator in
4114 an extra layer of parens so that it does not get confused
4115 with the '>' which ends the template parameters. */
4116 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4117 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4118 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4119 d_append_char (dpi
, '(');
4121 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4122 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4124 d_append_char (dpi
, '[');
4125 d_print_comp (dpi
, d_right (d_right (dc
)));
4126 d_append_char (dpi
, ']');
4130 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4131 d_print_expr_op (dpi
, d_left (dc
));
4132 d_print_subexpr (dpi
, d_right (d_right (dc
)));
4135 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4136 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4137 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4138 d_append_char (dpi
, ')');
4142 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4143 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4144 d_print_error (dpi
);
4147 case DEMANGLE_COMPONENT_TRINARY
:
4148 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4149 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4151 d_print_error (dpi
);
4154 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4155 d_print_expr_op (dpi
, d_left (dc
));
4156 d_print_subexpr (dpi
, d_left (d_right (d_right (dc
))));
4157 d_append_string (dpi
, " : ");
4158 d_print_subexpr (dpi
, d_right (d_right (d_right (dc
))));
4161 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4162 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4163 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4164 d_print_error (dpi
);
4167 case DEMANGLE_COMPONENT_LITERAL
:
4168 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4170 enum d_builtin_type_print tp
;
4172 /* For some builtin types, produce simpler output. */
4173 tp
= D_PRINT_DEFAULT
;
4174 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4176 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4180 case D_PRINT_UNSIGNED
:
4182 case D_PRINT_UNSIGNED_LONG
:
4183 case D_PRINT_LONG_LONG
:
4184 case D_PRINT_UNSIGNED_LONG_LONG
:
4185 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4187 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4188 d_append_char (dpi
, '-');
4189 d_print_comp (dpi
, d_right (dc
));
4194 case D_PRINT_UNSIGNED
:
4195 d_append_char (dpi
, 'u');
4198 d_append_char (dpi
, 'l');
4200 case D_PRINT_UNSIGNED_LONG
:
4201 d_append_string (dpi
, "ul");
4203 case D_PRINT_LONG_LONG
:
4204 d_append_string (dpi
, "ll");
4206 case D_PRINT_UNSIGNED_LONG_LONG
:
4207 d_append_string (dpi
, "ull");
4215 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4216 && d_right (dc
)->u
.s_name
.len
== 1
4217 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4219 switch (d_right (dc
)->u
.s_name
.s
[0])
4222 d_append_string (dpi
, "false");
4225 d_append_string (dpi
, "true");
4238 d_append_char (dpi
, '(');
4239 d_print_comp (dpi
, d_left (dc
));
4240 d_append_char (dpi
, ')');
4241 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4242 d_append_char (dpi
, '-');
4243 if (tp
== D_PRINT_FLOAT
)
4244 d_append_char (dpi
, '[');
4245 d_print_comp (dpi
, d_right (dc
));
4246 if (tp
== D_PRINT_FLOAT
)
4247 d_append_char (dpi
, ']');
4251 case DEMANGLE_COMPONENT_NUMBER
:
4252 d_append_num (dpi
, dc
->u
.s_number
.number
);
4255 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4256 d_append_string (dpi
, "java resource ");
4257 d_print_comp (dpi
, d_left (dc
));
4260 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4261 d_print_comp (dpi
, d_left (dc
));
4262 d_print_comp (dpi
, d_right (dc
));
4265 case DEMANGLE_COMPONENT_CHARACTER
:
4266 d_append_char (dpi
, dc
->u
.s_character
.character
);
4269 case DEMANGLE_COMPONENT_DECLTYPE
:
4270 d_append_string (dpi
, "decltype (");
4271 d_print_comp (dpi
, d_left (dc
));
4272 d_append_char (dpi
, ')');
4275 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4279 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4282 /* d_find_pack won't find anything if the only packs involved
4283 in this expansion are function parameter packs; in that
4284 case, just print the pattern and "...". */
4285 d_print_subexpr (dpi
, d_left (dc
));
4286 d_append_string (dpi
, "...");
4290 len
= d_pack_length (a
);
4292 for (i
= 0; i
< len
; ++i
)
4294 dpi
->pack_index
= i
;
4295 d_print_comp (dpi
, dc
);
4297 d_append_string (dpi
, ", ");
4302 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4303 d_append_string (dpi
, "{parm#");
4304 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4305 d_append_char (dpi
, '}');
4308 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4309 d_append_string (dpi
, "global constructors keyed to ");
4310 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4313 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4314 d_append_string (dpi
, "global destructors keyed to ");
4315 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4318 case DEMANGLE_COMPONENT_LAMBDA
:
4319 d_append_string (dpi
, "{lambda(");
4320 d_print_comp (dpi
, dc
->u
.s_unary_num
.sub
);
4321 d_append_string (dpi
, ")#");
4322 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4323 d_append_char (dpi
, '}');
4326 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4327 d_append_string (dpi
, "{unnamed type#");
4328 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4329 d_append_char (dpi
, '}');
4333 d_print_error (dpi
);
4338 /* Print a Java dentifier. For Java we try to handle encoded extended
4339 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4340 so we don't it for C++. Characters are encoded as
4344 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
4350 for (p
= name
; p
< end
; ++p
)
4361 for (q
= p
+ 3; q
< end
; ++q
)
4367 else if (*q
>= 'A' && *q
<= 'F')
4368 dig
= *q
- 'A' + 10;
4369 else if (*q
>= 'a' && *q
<= 'f')
4370 dig
= *q
- 'a' + 10;
4376 /* If the Unicode character is larger than 256, we don't try
4377 to deal with it here. FIXME. */
4378 if (q
< end
&& *q
== '_' && c
< 256)
4380 d_append_char (dpi
, c
);
4386 d_append_char (dpi
, *p
);
4390 /* Print a list of modifiers. SUFFIX is 1 if we are printing
4391 qualifiers on this after printing a function. */
4394 d_print_mod_list (struct d_print_info
*dpi
,
4395 struct d_print_mod
*mods
, int suffix
)
4397 struct d_print_template
*hold_dpt
;
4399 if (mods
== NULL
|| d_print_saw_error (dpi
))
4404 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4405 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4406 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
4408 d_print_mod_list (dpi
, mods
->next
, suffix
);
4414 hold_dpt
= dpi
->templates
;
4415 dpi
->templates
= mods
->templates
;
4417 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4419 d_print_function_type (dpi
, mods
->mod
, mods
->next
);
4420 dpi
->templates
= hold_dpt
;
4423 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4425 d_print_array_type (dpi
, mods
->mod
, mods
->next
);
4426 dpi
->templates
= hold_dpt
;
4429 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4431 struct d_print_mod
*hold_modifiers
;
4432 struct demangle_component
*dc
;
4434 /* When this is on the modifier stack, we have pulled any
4435 qualifiers off the right argument already. Otherwise, we
4436 print it as usual, but don't let the left argument see any
4439 hold_modifiers
= dpi
->modifiers
;
4440 dpi
->modifiers
= NULL
;
4441 d_print_comp (dpi
, d_left (mods
->mod
));
4442 dpi
->modifiers
= hold_modifiers
;
4444 if ((dpi
->options
& DMGL_JAVA
) == 0)
4445 d_append_string (dpi
, "::");
4447 d_append_char (dpi
, '.');
4449 dc
= d_right (mods
->mod
);
4451 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4453 d_append_string (dpi
, "{default arg#");
4454 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4455 d_append_string (dpi
, "}::");
4456 dc
= dc
->u
.s_unary_num
.sub
;
4459 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4460 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4461 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
4464 d_print_comp (dpi
, dc
);
4466 dpi
->templates
= hold_dpt
;
4470 d_print_mod (dpi
, mods
->mod
);
4472 dpi
->templates
= hold_dpt
;
4474 d_print_mod_list (dpi
, mods
->next
, suffix
);
4477 /* Print a modifier. */
4480 d_print_mod (struct d_print_info
*dpi
,
4481 const struct demangle_component
*mod
)
4485 case DEMANGLE_COMPONENT_RESTRICT
:
4486 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4487 d_append_string (dpi
, " restrict");
4489 case DEMANGLE_COMPONENT_VOLATILE
:
4490 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4491 d_append_string (dpi
, " volatile");
4493 case DEMANGLE_COMPONENT_CONST
:
4494 case DEMANGLE_COMPONENT_CONST_THIS
:
4495 d_append_string (dpi
, " const");
4497 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4498 d_append_char (dpi
, ' ');
4499 d_print_comp (dpi
, d_right (mod
));
4501 case DEMANGLE_COMPONENT_POINTER
:
4502 /* There is no pointer symbol in Java. */
4503 if ((dpi
->options
& DMGL_JAVA
) == 0)
4504 d_append_char (dpi
, '*');
4506 case DEMANGLE_COMPONENT_REFERENCE
:
4507 d_append_char (dpi
, '&');
4509 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4510 d_append_string (dpi
, "&&");
4512 case DEMANGLE_COMPONENT_COMPLEX
:
4513 d_append_string (dpi
, "complex ");
4515 case DEMANGLE_COMPONENT_IMAGINARY
:
4516 d_append_string (dpi
, "imaginary ");
4518 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4519 if (d_last_char (dpi
) != '(')
4520 d_append_char (dpi
, ' ');
4521 d_print_comp (dpi
, d_left (mod
));
4522 d_append_string (dpi
, "::*");
4524 case DEMANGLE_COMPONENT_TYPED_NAME
:
4525 d_print_comp (dpi
, d_left (mod
));
4527 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4528 d_append_string (dpi
, " __vector(");
4529 d_print_comp (dpi
, d_left (mod
));
4530 d_append_char (dpi
, ')');
4534 /* Otherwise, we have something that won't go back on the
4535 modifier stack, so we can just print it. */
4536 d_print_comp (dpi
, mod
);
4541 /* Print a function type, except for the return type. */
4544 d_print_function_type (struct d_print_info
*dpi
,
4545 const struct demangle_component
*dc
,
4546 struct d_print_mod
*mods
)
4551 struct d_print_mod
*p
;
4552 struct d_print_mod
*hold_modifiers
;
4557 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4563 switch (p
->mod
->type
)
4565 case DEMANGLE_COMPONENT_POINTER
:
4566 case DEMANGLE_COMPONENT_REFERENCE
:
4567 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4570 case DEMANGLE_COMPONENT_RESTRICT
:
4571 case DEMANGLE_COMPONENT_VOLATILE
:
4572 case DEMANGLE_COMPONENT_CONST
:
4573 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4574 case DEMANGLE_COMPONENT_COMPLEX
:
4575 case DEMANGLE_COMPONENT_IMAGINARY
:
4576 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4580 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4581 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4582 case DEMANGLE_COMPONENT_CONST_THIS
:
4591 if (d_left (dc
) != NULL
&& ! saw_mod
)
4598 if (d_last_char (dpi
) != '('
4599 && d_last_char (dpi
) != '*')
4602 if (need_space
&& d_last_char (dpi
) != ' ')
4603 d_append_char (dpi
, ' ');
4604 d_append_char (dpi
, '(');
4607 hold_modifiers
= dpi
->modifiers
;
4608 dpi
->modifiers
= NULL
;
4610 d_print_mod_list (dpi
, mods
, 0);
4613 d_append_char (dpi
, ')');
4615 d_append_char (dpi
, '(');
4617 if (d_right (dc
) != NULL
)
4618 d_print_comp (dpi
, d_right (dc
));
4620 d_append_char (dpi
, ')');
4622 d_print_mod_list (dpi
, mods
, 1);
4624 dpi
->modifiers
= hold_modifiers
;
4627 /* Print an array type, except for the element type. */
4630 d_print_array_type (struct d_print_info
*dpi
,
4631 const struct demangle_component
*dc
,
4632 struct d_print_mod
*mods
)
4640 struct d_print_mod
*p
;
4643 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4647 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4662 d_append_string (dpi
, " (");
4664 d_print_mod_list (dpi
, mods
, 0);
4667 d_append_char (dpi
, ')');
4671 d_append_char (dpi
, ' ');
4673 d_append_char (dpi
, '[');
4675 if (d_left (dc
) != NULL
)
4676 d_print_comp (dpi
, d_left (dc
));
4678 d_append_char (dpi
, ']');
4681 /* Print an operator in an expression. */
4684 d_print_expr_op (struct d_print_info
*dpi
,
4685 const struct demangle_component
*dc
)
4687 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4688 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4689 dc
->u
.s_operator
.op
->len
);
4691 d_print_comp (dpi
, dc
);
4697 d_print_cast (struct d_print_info
*dpi
,
4698 const struct demangle_component
*dc
)
4700 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4701 d_print_comp (dpi
, d_left (dc
));
4704 struct d_print_mod
*hold_dpm
;
4705 struct d_print_template dpt
;
4707 /* It appears that for a templated cast operator, we need to put
4708 the template parameters in scope for the operator name, but
4709 not for the parameters. The effect is that we need to handle
4710 the template printing here. */
4712 hold_dpm
= dpi
->modifiers
;
4713 dpi
->modifiers
= NULL
;
4715 dpt
.next
= dpi
->templates
;
4716 dpi
->templates
= &dpt
;
4717 dpt
.template_decl
= d_left (dc
);
4719 d_print_comp (dpi
, d_left (d_left (dc
)));
4721 dpi
->templates
= dpt
.next
;
4723 if (d_last_char (dpi
) == '<')
4724 d_append_char (dpi
, ' ');
4725 d_append_char (dpi
, '<');
4726 d_print_comp (dpi
, d_right (d_left (dc
)));
4727 /* Avoid generating two consecutive '>' characters, to avoid
4728 the C++ syntactic ambiguity. */
4729 if (d_last_char (dpi
) == '>')
4730 d_append_char (dpi
, ' ');
4731 d_append_char (dpi
, '>');
4733 dpi
->modifiers
= hold_dpm
;
4737 /* Initialize the information structure we use to pass around
4740 CP_STATIC_IF_GLIBCPP_V3
4742 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4746 di
->send
= mangled
+ len
;
4747 di
->options
= options
;
4751 /* We can not need more components than twice the number of chars in
4752 the mangled string. Most components correspond directly to
4753 chars, but the ARGLIST types are exceptions. */
4754 di
->num_comps
= 2 * len
;
4757 /* Similarly, we can not need more substitutions than there are
4758 chars in the mangled string. */
4763 di
->last_name
= NULL
;
4768 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4769 mangled name, return strings in repeated callback giving the demangled
4770 name. OPTIONS is the usual libiberty demangler options. On success,
4771 this returns 1. On failure, returns 0. */
4774 d_demangle_callback (const char *mangled
, int options
,
4775 demangle_callbackref callback
, void *opaque
)
4786 struct demangle_component
*dc
;
4789 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4791 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
4792 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
4793 && (mangled
[9] == 'D' || mangled
[9] == 'I')
4794 && mangled
[10] == '_')
4795 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
4798 if ((options
& DMGL_TYPES
) == 0)
4803 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
4806 #ifdef CP_DYNAMIC_ARRAYS
4807 __extension__
struct demangle_component comps
[di
.num_comps
];
4808 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4813 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4814 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4820 dc
= cplus_demangle_type (&di
);
4823 dc
= cplus_demangle_mangled_name (&di
, 1);
4825 case DCT_GLOBAL_CTORS
:
4826 case DCT_GLOBAL_DTORS
:
4827 d_advance (&di
, 11);
4828 dc
= d_make_comp (&di
,
4829 (type
== DCT_GLOBAL_CTORS
4830 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
4831 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
4832 d_make_name (&di
, d_str (&di
), strlen (d_str (&di
))),
4834 d_advance (&di
, strlen (d_str (&di
)));
4838 /* If DMGL_PARAMS is set, then if we didn't consume the entire
4839 mangled string, then we didn't successfully demangle it. If
4840 DMGL_PARAMS is not set, we didn't look at the trailing
4842 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
4845 #ifdef CP_DEMANGLE_DEBUG
4849 status
= (dc
!= NULL
)
4850 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
4857 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4858 name, return a buffer allocated with malloc holding the demangled
4859 name. OPTIONS is the usual libiberty demangler options. On
4860 success, this sets *PALC to the allocated size of the returned
4861 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4862 a memory allocation failure, and returns NULL. */
4865 d_demangle (const char *mangled
, int options
, size_t *palc
)
4867 struct d_growable_string dgs
;
4870 d_growable_string_init (&dgs
, 0);
4872 status
= d_demangle_callback (mangled
, options
,
4873 d_growable_string_callback_adapter
, &dgs
);
4881 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4885 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4887 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
4889 /* ia64 ABI-mandated entry point in the C++ runtime library for
4890 performing demangling. MANGLED_NAME is a NUL-terminated character
4891 string containing the name to be demangled.
4893 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
4894 *LENGTH bytes, into which the demangled name is stored. If
4895 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
4896 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
4897 is placed in a region of memory allocated with malloc.
4899 If LENGTH is non-NULL, the length of the buffer containing the
4900 demangled name, is placed in *LENGTH.
4902 The return value is a pointer to the start of the NUL-terminated
4903 demangled name, or NULL if the demangling fails. The caller is
4904 responsible for deallocating this memory using free.
4906 *STATUS is set to one of the following values:
4907 0: The demangling operation succeeded.
4908 -1: A memory allocation failure occurred.
4909 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4910 -3: One of the arguments is invalid.
4912 The demangling is performed using the C++ ABI mangling rules, with
4916 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
4917 size_t *length
, int *status
)
4922 if (mangled_name
== NULL
)
4929 if (output_buffer
!= NULL
&& length
== NULL
)
4936 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
4938 if (demangled
== NULL
)
4950 if (output_buffer
== NULL
)
4957 if (strlen (demangled
) < *length
)
4959 strcpy (output_buffer
, demangled
);
4961 demangled
= output_buffer
;
4965 free (output_buffer
);
4976 extern int __gcclibcxx_demangle_callback (const char *,
4978 (const char *, size_t, void *),
4981 /* Alternative, allocationless entry point in the C++ runtime library
4982 for performing demangling. MANGLED_NAME is a NUL-terminated character
4983 string containing the name to be demangled.
4985 CALLBACK is a callback function, called with demangled string
4986 segments as demangling progresses; it is called at least once,
4987 but may be called more than once. OPAQUE is a generalized pointer
4988 used as a callback argument.
4990 The return code is one of the following values, equivalent to
4991 the STATUS values of __cxa_demangle() (excluding -1, since this
4992 function performs no memory allocations):
4993 0: The demangling operation succeeded.
4994 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4995 -3: One of the arguments is invalid.
4997 The demangling is performed using the C++ ABI mangling rules, with
5001 __gcclibcxx_demangle_callback (const char *mangled_name
,
5002 void (*callback
) (const char *, size_t, void *),
5007 if (mangled_name
== NULL
|| callback
== NULL
)
5010 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5018 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5020 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5021 mangled name, return a buffer allocated with malloc holding the
5022 demangled name. Otherwise, return NULL. */
5025 cplus_demangle_v3 (const char *mangled
, int options
)
5029 return d_demangle (mangled
, options
, &alc
);
5033 cplus_demangle_v3_callback (const char *mangled
, int options
,
5034 demangle_callbackref callback
, void *opaque
)
5036 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5039 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5040 conventions, but the output formatting is a little different.
5041 This instructs the C++ demangler not to emit pointer characters ("*"), to
5042 use Java's namespace separator symbol ("." instead of "::"), and to output
5043 JArray<TYPE> as TYPE[]. */
5046 java_demangle_v3 (const char *mangled
)
5050 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5054 java_demangle_v3_callback (const char *mangled
,
5055 demangle_callbackref callback
, void *opaque
)
5057 return d_demangle_callback (mangled
,
5058 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5062 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5064 #ifndef IN_GLIBCPP_V3
5066 /* Demangle a string in order to find out whether it is a constructor
5067 or destructor. Return non-zero on success. Set *CTOR_KIND and
5068 *DTOR_KIND appropriately. */
5071 is_ctor_or_dtor (const char *mangled
,
5072 enum gnu_v3_ctor_kinds
*ctor_kind
,
5073 enum gnu_v3_dtor_kinds
*dtor_kind
)
5076 struct demangle_component
*dc
;
5079 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5080 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5082 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5085 #ifdef CP_DYNAMIC_ARRAYS
5086 __extension__
struct demangle_component comps
[di
.num_comps
];
5087 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5092 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5093 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5096 dc
= cplus_demangle_mangled_name (&di
, 1);
5098 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5099 to demangle the entire string. */
5109 case DEMANGLE_COMPONENT_TYPED_NAME
:
5110 case DEMANGLE_COMPONENT_TEMPLATE
:
5111 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5112 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5113 case DEMANGLE_COMPONENT_CONST_THIS
:
5116 case DEMANGLE_COMPONENT_QUAL_NAME
:
5117 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5120 case DEMANGLE_COMPONENT_CTOR
:
5121 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5125 case DEMANGLE_COMPONENT_DTOR
:
5126 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5137 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5138 name. A non-zero return indicates the type of constructor. */
5140 enum gnu_v3_ctor_kinds
5141 is_gnu_v3_mangled_ctor (const char *name
)
5143 enum gnu_v3_ctor_kinds ctor_kind
;
5144 enum gnu_v3_dtor_kinds dtor_kind
;
5146 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5147 return (enum gnu_v3_ctor_kinds
) 0;
5152 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5153 name. A non-zero return indicates the type of destructor. */
5155 enum gnu_v3_dtor_kinds
5156 is_gnu_v3_mangled_dtor (const char *name
)
5158 enum gnu_v3_ctor_kinds ctor_kind
;
5159 enum gnu_v3_dtor_kinds dtor_kind
;
5161 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5162 return (enum gnu_v3_dtor_kinds
) 0;
5166 #endif /* IN_GLIBCPP_V3 */
5168 #ifdef STANDALONE_DEMANGLER
5171 #include "dyn-string.h"
5173 static void print_usage (FILE* fp
, int exit_value
);
5175 #define IS_ALPHA(CHAR) \
5176 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5177 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5179 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5180 #define is_mangled_char(CHAR) \
5181 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5182 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5184 /* The name of this program, as invoked. */
5185 const char* program_name
;
5187 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5190 print_usage (FILE* fp
, int exit_value
)
5192 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5193 fprintf (fp
, "Options:\n");
5194 fprintf (fp
, " -h,--help Display this message.\n");
5195 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5196 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5197 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5202 /* Option specification for getopt_long. */
5203 static const struct option long_options
[] =
5205 { "help", no_argument
, NULL
, 'h' },
5206 { "no-params", no_argument
, NULL
, 'p' },
5207 { "verbose", no_argument
, NULL
, 'v' },
5208 { NULL
, no_argument
, NULL
, 0 },
5211 /* Main entry for a demangling filter executable. It will demangle
5212 its command line arguments, if any. If none are provided, it will
5213 filter stdin to stdout, replacing any recognized mangled C++ names
5214 with their demangled equivalents. */
5217 main (int argc
, char *argv
[])
5221 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5223 /* Use the program name of this program, as invoked. */
5224 program_name
= argv
[0];
5226 /* Parse options. */
5229 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5232 case '?': /* Unrecognized option. */
5233 print_usage (stderr
, 1);
5237 print_usage (stdout
, 0);
5241 options
&= ~ DMGL_PARAMS
;
5245 options
|= DMGL_VERBOSE
;
5249 while (opt_char
!= -1);
5252 /* No command line arguments were provided. Filter stdin. */
5254 dyn_string_t mangled
= dyn_string_new (3);
5257 /* Read all of input. */
5258 while (!feof (stdin
))
5262 /* Pile characters into mangled until we hit one that can't
5263 occur in a mangled name. */
5265 while (!feof (stdin
) && is_mangled_char (c
))
5267 dyn_string_append_char (mangled
, c
);
5273 if (dyn_string_length (mangled
) > 0)
5275 #ifdef IN_GLIBCPP_V3
5276 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
5278 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
5288 /* It might not have been a mangled name. Print the
5290 fputs (dyn_string_buf (mangled
), stdout
);
5293 dyn_string_clear (mangled
);
5296 /* If we haven't hit EOF yet, we've read one character that
5297 can't occur in a mangled name, so print it out. */
5302 dyn_string_delete (mangled
);
5305 /* Demangle command line arguments. */
5307 /* Loop over command line arguments. */
5308 for (i
= optind
; i
< argc
; ++i
)
5311 #ifdef IN_GLIBCPP_V3
5315 /* Attempt to demangle. */
5316 #ifdef IN_GLIBCPP_V3
5317 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
5319 s
= cplus_demangle_v3 (argv
[i
], options
);
5322 /* If it worked, print the demangled name. */
5330 #ifdef IN_GLIBCPP_V3
5331 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
5333 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
5342 #endif /* STANDALONE_DEMANGLER */