1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
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
;
304 #ifdef CP_DEMANGLE_DEBUG
305 static void d_dump (struct demangle_component
*, int);
308 static struct demangle_component
*
309 d_make_empty (struct d_info
*);
311 static struct demangle_component
*
312 d_make_comp (struct d_info
*, enum demangle_component_type
,
313 struct demangle_component
*,
314 struct demangle_component
*);
316 static struct demangle_component
*
317 d_make_name (struct d_info
*, const char *, int);
319 static struct demangle_component
*
320 d_make_builtin_type (struct d_info
*,
321 const struct demangle_builtin_type_info
*);
323 static struct demangle_component
*
324 d_make_operator (struct d_info
*,
325 const struct demangle_operator_info
*);
327 static struct demangle_component
*
328 d_make_extended_operator (struct d_info
*, int,
329 struct demangle_component
*);
331 static struct demangle_component
*
332 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
333 struct demangle_component
*);
335 static struct demangle_component
*
336 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
337 struct demangle_component
*);
339 static struct demangle_component
*
340 d_make_template_param (struct d_info
*, long);
342 static struct demangle_component
*
343 d_make_sub (struct d_info
*, const char *, int);
346 has_return_type (struct demangle_component
*);
349 is_ctor_dtor_or_conversion (struct demangle_component
*);
351 static struct demangle_component
*d_encoding (struct d_info
*, int);
353 static struct demangle_component
*d_name (struct d_info
*);
355 static struct demangle_component
*d_nested_name (struct d_info
*);
357 static struct demangle_component
*d_prefix (struct d_info
*);
359 static struct demangle_component
*d_unqualified_name (struct d_info
*);
361 static struct demangle_component
*d_source_name (struct d_info
*);
363 static long d_number (struct d_info
*);
365 static struct demangle_component
*d_identifier (struct d_info
*, int);
367 static struct demangle_component
*d_operator_name (struct d_info
*);
369 static struct demangle_component
*d_special_name (struct d_info
*);
371 static int d_call_offset (struct d_info
*, int);
373 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
375 static struct demangle_component
**
376 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
378 static struct demangle_component
*
379 d_function_type (struct d_info
*);
381 static struct demangle_component
*
382 d_bare_function_type (struct d_info
*, int);
384 static struct demangle_component
*
385 d_class_enum_type (struct d_info
*);
387 static struct demangle_component
*d_array_type (struct d_info
*);
389 static struct demangle_component
*
390 d_pointer_to_member_type (struct d_info
*);
392 static struct demangle_component
*
393 d_template_param (struct d_info
*);
395 static struct demangle_component
*d_template_args (struct d_info
*);
397 static struct demangle_component
*
398 d_template_arg (struct d_info
*);
400 static struct demangle_component
*d_expression (struct d_info
*);
402 static struct demangle_component
*d_expr_primary (struct d_info
*);
404 static struct demangle_component
*d_local_name (struct d_info
*);
406 static int d_discriminator (struct d_info
*);
409 d_add_substitution (struct d_info
*, struct demangle_component
*);
411 static struct demangle_component
*d_substitution (struct d_info
*, int);
413 static void d_growable_string_init (struct d_growable_string
*, size_t);
416 d_growable_string_resize (struct d_growable_string
*, size_t);
419 d_growable_string_append_buffer (struct d_growable_string
*,
420 const char *, size_t);
422 d_growable_string_callback_adapter (const char *, size_t, void *);
425 d_print_init (struct d_print_info
*, int, demangle_callbackref
, void *);
427 static inline void d_print_error (struct d_print_info
*);
429 static inline int d_print_saw_error (struct d_print_info
*);
431 static inline void d_print_flush (struct d_print_info
*);
433 static inline void d_append_char (struct d_print_info
*, char);
435 static inline void d_append_buffer (struct d_print_info
*,
436 const char *, size_t);
438 static inline void d_append_string (struct d_print_info
*, const char *);
440 static inline char d_last_char (struct d_print_info
*);
443 d_print_comp (struct d_print_info
*, const struct demangle_component
*);
446 d_print_java_identifier (struct d_print_info
*, const char *, int);
449 d_print_mod_list (struct d_print_info
*, struct d_print_mod
*, int);
452 d_print_mod (struct d_print_info
*, const struct demangle_component
*);
455 d_print_function_type (struct d_print_info
*,
456 const struct demangle_component
*,
457 struct d_print_mod
*);
460 d_print_array_type (struct d_print_info
*,
461 const struct demangle_component
*,
462 struct d_print_mod
*);
465 d_print_expr_op (struct d_print_info
*, const struct demangle_component
*);
468 d_print_cast (struct d_print_info
*, const struct demangle_component
*);
470 static int d_demangle_callback (const char *, int,
471 demangle_callbackref
, void *);
472 static char *d_demangle (const char *, int, size_t *);
474 #ifdef CP_DEMANGLE_DEBUG
477 d_dump (struct demangle_component
*dc
, int indent
)
484 printf ("failed demangling\n");
488 for (i
= 0; i
< indent
; ++i
)
493 case DEMANGLE_COMPONENT_NAME
:
494 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
496 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
497 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
499 case DEMANGLE_COMPONENT_CTOR
:
500 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
501 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
503 case DEMANGLE_COMPONENT_DTOR
:
504 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
505 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
507 case DEMANGLE_COMPONENT_SUB_STD
:
508 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
510 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
511 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
513 case DEMANGLE_COMPONENT_OPERATOR
:
514 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
516 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
517 printf ("extended operator with %d args\n",
518 dc
->u
.s_extended_operator
.args
);
519 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
522 case DEMANGLE_COMPONENT_QUAL_NAME
:
523 printf ("qualified name\n");
525 case DEMANGLE_COMPONENT_LOCAL_NAME
:
526 printf ("local name\n");
528 case DEMANGLE_COMPONENT_TYPED_NAME
:
529 printf ("typed name\n");
531 case DEMANGLE_COMPONENT_TEMPLATE
:
532 printf ("template\n");
534 case DEMANGLE_COMPONENT_VTABLE
:
537 case DEMANGLE_COMPONENT_VTT
:
540 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
541 printf ("construction vtable\n");
543 case DEMANGLE_COMPONENT_TYPEINFO
:
544 printf ("typeinfo\n");
546 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
547 printf ("typeinfo name\n");
549 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
550 printf ("typeinfo function\n");
552 case DEMANGLE_COMPONENT_THUNK
:
555 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
556 printf ("virtual thunk\n");
558 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
559 printf ("covariant thunk\n");
561 case DEMANGLE_COMPONENT_JAVA_CLASS
:
562 printf ("java class\n");
564 case DEMANGLE_COMPONENT_GUARD
:
567 case DEMANGLE_COMPONENT_REFTEMP
:
568 printf ("reference temporary\n");
570 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
571 printf ("hidden alias\n");
573 case DEMANGLE_COMPONENT_RESTRICT
:
574 printf ("restrict\n");
576 case DEMANGLE_COMPONENT_VOLATILE
:
577 printf ("volatile\n");
579 case DEMANGLE_COMPONENT_CONST
:
582 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
583 printf ("restrict this\n");
585 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
586 printf ("volatile this\n");
588 case DEMANGLE_COMPONENT_CONST_THIS
:
589 printf ("const this\n");
591 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
592 printf ("vendor type qualifier\n");
594 case DEMANGLE_COMPONENT_POINTER
:
595 printf ("pointer\n");
597 case DEMANGLE_COMPONENT_REFERENCE
:
598 printf ("reference\n");
600 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
601 printf ("rvalue reference\n");
603 case DEMANGLE_COMPONENT_COMPLEX
:
604 printf ("complex\n");
606 case DEMANGLE_COMPONENT_IMAGINARY
:
607 printf ("imaginary\n");
609 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
610 printf ("vendor type\n");
612 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
613 printf ("function type\n");
615 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
616 printf ("array type\n");
618 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
619 printf ("pointer to member type\n");
621 case DEMANGLE_COMPONENT_ARGLIST
:
622 printf ("argument list\n");
624 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
625 printf ("template argument list\n");
627 case DEMANGLE_COMPONENT_CAST
:
630 case DEMANGLE_COMPONENT_UNARY
:
631 printf ("unary operator\n");
633 case DEMANGLE_COMPONENT_BINARY
:
634 printf ("binary operator\n");
636 case DEMANGLE_COMPONENT_BINARY_ARGS
:
637 printf ("binary operator arguments\n");
639 case DEMANGLE_COMPONENT_TRINARY
:
640 printf ("trinary operator\n");
642 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
643 printf ("trinary operator arguments 1\n");
645 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
646 printf ("trinary operator arguments 1\n");
648 case DEMANGLE_COMPONENT_LITERAL
:
649 printf ("literal\n");
651 case DEMANGLE_COMPONENT_LITERAL_NEG
:
652 printf ("negative literal\n");
654 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
655 printf ("java resource\n");
657 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
658 printf ("compound name\n");
660 case DEMANGLE_COMPONENT_CHARACTER
:
661 printf ("character '%c'\n", dc
->u
.s_character
.character
);
665 d_dump (d_left (dc
), indent
+ 2);
666 d_dump (d_right (dc
), indent
+ 2);
669 #endif /* CP_DEMANGLE_DEBUG */
671 /* Fill in a DEMANGLE_COMPONENT_NAME. */
673 CP_STATIC_IF_GLIBCPP_V3
675 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
677 if (p
== NULL
|| s
== NULL
|| len
== 0)
679 p
->type
= DEMANGLE_COMPONENT_NAME
;
681 p
->u
.s_name
.len
= len
;
685 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
687 CP_STATIC_IF_GLIBCPP_V3
689 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
690 struct demangle_component
*name
)
692 if (p
== NULL
|| args
< 0 || name
== NULL
)
694 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
695 p
->u
.s_extended_operator
.args
= args
;
696 p
->u
.s_extended_operator
.name
= name
;
700 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
702 CP_STATIC_IF_GLIBCPP_V3
704 cplus_demangle_fill_ctor (struct demangle_component
*p
,
705 enum gnu_v3_ctor_kinds kind
,
706 struct demangle_component
*name
)
710 || (kind
< gnu_v3_complete_object_ctor
711 && kind
> gnu_v3_complete_object_allocating_ctor
))
713 p
->type
= DEMANGLE_COMPONENT_CTOR
;
714 p
->u
.s_ctor
.kind
= kind
;
715 p
->u
.s_ctor
.name
= name
;
719 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
721 CP_STATIC_IF_GLIBCPP_V3
723 cplus_demangle_fill_dtor (struct demangle_component
*p
,
724 enum gnu_v3_dtor_kinds kind
,
725 struct demangle_component
*name
)
729 || (kind
< gnu_v3_deleting_dtor
730 && kind
> gnu_v3_base_object_dtor
))
732 p
->type
= DEMANGLE_COMPONENT_DTOR
;
733 p
->u
.s_dtor
.kind
= kind
;
734 p
->u
.s_dtor
.name
= name
;
738 /* Add a new component. */
740 static struct demangle_component
*
741 d_make_empty (struct d_info
*di
)
743 struct demangle_component
*p
;
745 if (di
->next_comp
>= di
->num_comps
)
747 p
= &di
->comps
[di
->next_comp
];
752 /* Add a new generic component. */
754 static struct demangle_component
*
755 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
756 struct demangle_component
*left
,
757 struct demangle_component
*right
)
759 struct demangle_component
*p
;
761 /* We check for errors here. A typical error would be a NULL return
762 from a subroutine. We catch those here, and return NULL
766 /* These types require two parameters. */
767 case DEMANGLE_COMPONENT_QUAL_NAME
:
768 case DEMANGLE_COMPONENT_LOCAL_NAME
:
769 case DEMANGLE_COMPONENT_TYPED_NAME
:
770 case DEMANGLE_COMPONENT_TEMPLATE
:
771 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
772 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
773 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
774 case DEMANGLE_COMPONENT_UNARY
:
775 case DEMANGLE_COMPONENT_BINARY
:
776 case DEMANGLE_COMPONENT_BINARY_ARGS
:
777 case DEMANGLE_COMPONENT_TRINARY
:
778 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
779 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
780 case DEMANGLE_COMPONENT_LITERAL
:
781 case DEMANGLE_COMPONENT_LITERAL_NEG
:
782 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
783 if (left
== NULL
|| right
== NULL
)
787 /* These types only require one parameter. */
788 case DEMANGLE_COMPONENT_VTABLE
:
789 case DEMANGLE_COMPONENT_VTT
:
790 case DEMANGLE_COMPONENT_TYPEINFO
:
791 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
792 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
793 case DEMANGLE_COMPONENT_THUNK
:
794 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
795 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
796 case DEMANGLE_COMPONENT_JAVA_CLASS
:
797 case DEMANGLE_COMPONENT_GUARD
:
798 case DEMANGLE_COMPONENT_REFTEMP
:
799 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
800 case DEMANGLE_COMPONENT_POINTER
:
801 case DEMANGLE_COMPONENT_REFERENCE
:
802 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
803 case DEMANGLE_COMPONENT_COMPLEX
:
804 case DEMANGLE_COMPONENT_IMAGINARY
:
805 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
806 case DEMANGLE_COMPONENT_ARGLIST
:
807 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
808 case DEMANGLE_COMPONENT_CAST
:
809 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
814 /* This needs a right parameter, but the left parameter can be
816 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
821 /* These are allowed to have no parameters--in some cases they
822 will be filled in later. */
823 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
824 case DEMANGLE_COMPONENT_RESTRICT
:
825 case DEMANGLE_COMPONENT_VOLATILE
:
826 case DEMANGLE_COMPONENT_CONST
:
827 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
828 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
829 case DEMANGLE_COMPONENT_CONST_THIS
:
832 /* Other types should not be seen here. */
837 p
= d_make_empty (di
);
841 p
->u
.s_binary
.left
= left
;
842 p
->u
.s_binary
.right
= right
;
847 /* Add a new name component. */
849 static struct demangle_component
*
850 d_make_name (struct d_info
*di
, const char *s
, int len
)
852 struct demangle_component
*p
;
854 p
= d_make_empty (di
);
855 if (! cplus_demangle_fill_name (p
, s
, len
))
860 /* Add a new builtin type component. */
862 static struct demangle_component
*
863 d_make_builtin_type (struct d_info
*di
,
864 const struct demangle_builtin_type_info
*type
)
866 struct demangle_component
*p
;
870 p
= d_make_empty (di
);
873 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
874 p
->u
.s_builtin
.type
= type
;
879 /* Add a new operator component. */
881 static struct demangle_component
*
882 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
884 struct demangle_component
*p
;
886 p
= d_make_empty (di
);
889 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
890 p
->u
.s_operator
.op
= op
;
895 /* Add a new extended operator component. */
897 static struct demangle_component
*
898 d_make_extended_operator (struct d_info
*di
, int args
,
899 struct demangle_component
*name
)
901 struct demangle_component
*p
;
903 p
= d_make_empty (di
);
904 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
909 /* Add a new constructor component. */
911 static struct demangle_component
*
912 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
913 struct demangle_component
*name
)
915 struct demangle_component
*p
;
917 p
= d_make_empty (di
);
918 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
923 /* Add a new destructor component. */
925 static struct demangle_component
*
926 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
927 struct demangle_component
*name
)
929 struct demangle_component
*p
;
931 p
= d_make_empty (di
);
932 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
937 /* Add a new template parameter. */
939 static struct demangle_component
*
940 d_make_template_param (struct d_info
*di
, long i
)
942 struct demangle_component
*p
;
944 p
= d_make_empty (di
);
947 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
948 p
->u
.s_number
.number
= i
;
953 /* Add a new standard substitution component. */
955 static struct demangle_component
*
956 d_make_sub (struct d_info
*di
, const char *name
, int len
)
958 struct demangle_component
*p
;
960 p
= d_make_empty (di
);
963 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
964 p
->u
.s_string
.string
= name
;
965 p
->u
.s_string
.len
= len
;
970 /* <mangled-name> ::= _Z <encoding>
972 TOP_LEVEL is non-zero when called at the top level. */
974 CP_STATIC_IF_GLIBCPP_V3
975 struct demangle_component
*
976 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
978 if (! d_check_char (di
, '_'))
980 if (! d_check_char (di
, 'Z'))
982 return d_encoding (di
, top_level
);
985 /* Return whether a function should have a return type. The argument
986 is the function name, which may be qualified in various ways. The
987 rules are that template functions have return types with some
988 exceptions, function types which are not part of a function name
989 mangling have return types with some exceptions, and non-template
990 function names do not have return types. The exceptions are that
991 constructors, destructors, and conversion operators do not have
995 has_return_type (struct demangle_component
*dc
)
1003 case DEMANGLE_COMPONENT_TEMPLATE
:
1004 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1005 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1006 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1007 case DEMANGLE_COMPONENT_CONST_THIS
:
1008 return has_return_type (d_left (dc
));
1012 /* Return whether a name is a constructor, a destructor, or a
1013 conversion operator. */
1016 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1024 case DEMANGLE_COMPONENT_QUAL_NAME
:
1025 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1026 return is_ctor_dtor_or_conversion (d_right (dc
));
1027 case DEMANGLE_COMPONENT_CTOR
:
1028 case DEMANGLE_COMPONENT_DTOR
:
1029 case DEMANGLE_COMPONENT_CAST
:
1034 /* <encoding> ::= <(function) name> <bare-function-type>
1038 TOP_LEVEL is non-zero when called at the top level, in which case
1039 if DMGL_PARAMS is not set we do not demangle the function
1040 parameters. We only set this at the top level, because otherwise
1041 we would not correctly demangle names in local scopes. */
1043 static struct demangle_component
*
1044 d_encoding (struct d_info
*di
, int top_level
)
1046 char peek
= d_peek_char (di
);
1048 if (peek
== 'G' || peek
== 'T')
1049 return d_special_name (di
);
1052 struct demangle_component
*dc
;
1056 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1058 /* Strip off any initial CV-qualifiers, as they really apply
1059 to the `this' parameter, and they were not output by the
1060 v2 demangler without DMGL_PARAMS. */
1061 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1062 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1063 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1066 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1067 there may be CV-qualifiers on its right argument which
1068 really apply here; this happens when parsing a class
1069 which is local to a function. */
1070 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1072 struct demangle_component
*dcr
;
1075 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1076 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1077 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1079 dc
->u
.s_binary
.right
= dcr
;
1085 peek
= d_peek_char (di
);
1086 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1088 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1089 d_bare_function_type (di
, has_return_type (dc
)));
1093 /* <name> ::= <nested-name>
1095 ::= <unscoped-template-name> <template-args>
1098 <unscoped-name> ::= <unqualified-name>
1099 ::= St <unqualified-name>
1101 <unscoped-template-name> ::= <unscoped-name>
1105 static struct demangle_component
*
1106 d_name (struct d_info
*di
)
1108 char peek
= d_peek_char (di
);
1109 struct demangle_component
*dc
;
1114 return d_nested_name (di
);
1117 return d_local_name (di
);
1120 return d_unqualified_name (di
);
1126 if (d_peek_next_char (di
) != 't')
1128 dc
= d_substitution (di
, 0);
1134 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1135 d_make_name (di
, "std", 3),
1136 d_unqualified_name (di
));
1141 if (d_peek_char (di
) != 'I')
1143 /* The grammar does not permit this case to occur if we
1144 called d_substitution() above (i.e., subst == 1). We
1145 don't bother to check. */
1149 /* This is <template-args>, which means that we just saw
1150 <unscoped-template-name>, which is a substitution
1151 candidate if we didn't just get it from a
1155 if (! d_add_substitution (di
, dc
))
1158 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1159 d_template_args (di
));
1166 dc
= d_unqualified_name (di
);
1167 if (d_peek_char (di
) == 'I')
1169 /* This is <template-args>, which means that we just saw
1170 <unscoped-template-name>, which is a substitution
1172 if (! d_add_substitution (di
, dc
))
1174 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1175 d_template_args (di
));
1181 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1182 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1185 static struct demangle_component
*
1186 d_nested_name (struct d_info
*di
)
1188 struct demangle_component
*ret
;
1189 struct demangle_component
**pret
;
1191 if (! d_check_char (di
, 'N'))
1194 pret
= d_cv_qualifiers (di
, &ret
, 1);
1198 *pret
= d_prefix (di
);
1202 if (! d_check_char (di
, 'E'))
1208 /* <prefix> ::= <prefix> <unqualified-name>
1209 ::= <template-prefix> <template-args>
1210 ::= <template-param>
1214 <template-prefix> ::= <prefix> <(template) unqualified-name>
1215 ::= <template-param>
1219 static struct demangle_component
*
1220 d_prefix (struct d_info
*di
)
1222 struct demangle_component
*ret
= NULL
;
1227 enum demangle_component_type comb_type
;
1228 struct demangle_component
*dc
;
1230 peek
= d_peek_char (di
);
1234 /* The older code accepts a <local-name> here, but I don't see
1235 that in the grammar. The older code does not accept a
1236 <template-param> here. */
1238 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1244 dc
= d_unqualified_name (di
);
1245 else if (peek
== 'S')
1246 dc
= d_substitution (di
, 1);
1247 else if (peek
== 'I')
1251 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1252 dc
= d_template_args (di
);
1254 else if (peek
== 'T')
1255 dc
= d_template_param (di
);
1256 else if (peek
== 'E')
1264 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1266 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1268 if (! d_add_substitution (di
, ret
))
1274 /* <unqualified-name> ::= <operator-name>
1275 ::= <ctor-dtor-name>
1277 ::= <local-source-name>
1279 <local-source-name> ::= L <source-name> <discriminator>
1282 static struct demangle_component
*
1283 d_unqualified_name (struct d_info
*di
)
1287 peek
= d_peek_char (di
);
1288 if (IS_DIGIT (peek
))
1289 return d_source_name (di
);
1290 else if (IS_LOWER (peek
))
1292 struct demangle_component
*ret
;
1294 ret
= d_operator_name (di
);
1295 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1296 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1299 else if (peek
== 'C' || peek
== 'D')
1300 return d_ctor_dtor_name (di
);
1301 else if (peek
== 'L')
1303 struct demangle_component
* ret
;
1307 ret
= d_source_name (di
);
1310 if (! d_discriminator (di
))
1318 /* <source-name> ::= <(positive length) number> <identifier> */
1320 static struct demangle_component
*
1321 d_source_name (struct d_info
*di
)
1324 struct demangle_component
*ret
;
1326 len
= d_number (di
);
1329 ret
= d_identifier (di
, len
);
1330 di
->last_name
= ret
;
1334 /* number ::= [n] <(non-negative decimal integer)> */
1337 d_number (struct d_info
*di
)
1344 peek
= d_peek_char (di
);
1349 peek
= d_peek_char (di
);
1355 if (! IS_DIGIT (peek
))
1361 ret
= ret
* 10 + peek
- '0';
1363 peek
= d_peek_char (di
);
1367 /* identifier ::= <(unqualified source code identifier)> */
1369 static struct demangle_component
*
1370 d_identifier (struct d_info
*di
, int len
)
1376 if (di
->send
- name
< len
)
1379 d_advance (di
, len
);
1381 /* A Java mangled name may have a trailing '$' if it is a C++
1382 keyword. This '$' is not included in the length count. We just
1384 if ((di
->options
& DMGL_JAVA
) != 0
1385 && d_peek_char (di
) == '$')
1388 /* Look for something which looks like a gcc encoding of an
1389 anonymous namespace, and replace it with a more user friendly
1391 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1392 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1393 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1397 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1398 if ((*s
== '.' || *s
== '_' || *s
== '$')
1401 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1402 return d_make_name (di
, "(anonymous namespace)",
1403 sizeof "(anonymous namespace)" - 1);
1407 return d_make_name (di
, name
, len
);
1410 /* operator_name ::= many different two character encodings.
1412 ::= v <digit> <source-name>
1415 #define NL(s) s, (sizeof s) - 1
1417 CP_STATIC_IF_GLIBCPP_V3
1418 const struct demangle_operator_info cplus_demangle_operators
[] =
1420 { "aN", NL ("&="), 2 },
1421 { "aS", NL ("="), 2 },
1422 { "aa", NL ("&&"), 2 },
1423 { "ad", NL ("&"), 1 },
1424 { "an", NL ("&"), 2 },
1425 { "cl", NL ("()"), 0 },
1426 { "cm", NL (","), 2 },
1427 { "co", NL ("~"), 1 },
1428 { "dV", NL ("/="), 2 },
1429 { "da", NL ("delete[]"), 1 },
1430 { "de", NL ("*"), 1 },
1431 { "dl", NL ("delete"), 1 },
1432 { "dv", NL ("/"), 2 },
1433 { "eO", NL ("^="), 2 },
1434 { "eo", NL ("^"), 2 },
1435 { "eq", NL ("=="), 2 },
1436 { "ge", NL (">="), 2 },
1437 { "gt", NL (">"), 2 },
1438 { "ix", NL ("[]"), 2 },
1439 { "lS", NL ("<<="), 2 },
1440 { "le", NL ("<="), 2 },
1441 { "ls", NL ("<<"), 2 },
1442 { "lt", NL ("<"), 2 },
1443 { "mI", NL ("-="), 2 },
1444 { "mL", NL ("*="), 2 },
1445 { "mi", NL ("-"), 2 },
1446 { "ml", NL ("*"), 2 },
1447 { "mm", NL ("--"), 1 },
1448 { "na", NL ("new[]"), 1 },
1449 { "ne", NL ("!="), 2 },
1450 { "ng", NL ("-"), 1 },
1451 { "nt", NL ("!"), 1 },
1452 { "nw", NL ("new"), 1 },
1453 { "oR", NL ("|="), 2 },
1454 { "oo", NL ("||"), 2 },
1455 { "or", NL ("|"), 2 },
1456 { "pL", NL ("+="), 2 },
1457 { "pl", NL ("+"), 2 },
1458 { "pm", NL ("->*"), 2 },
1459 { "pp", NL ("++"), 1 },
1460 { "ps", NL ("+"), 1 },
1461 { "pt", NL ("->"), 2 },
1462 { "qu", NL ("?"), 3 },
1463 { "rM", NL ("%="), 2 },
1464 { "rS", NL (">>="), 2 },
1465 { "rm", NL ("%"), 2 },
1466 { "rs", NL (">>"), 2 },
1467 { "st", NL ("sizeof "), 1 },
1468 { "sz", NL ("sizeof "), 1 },
1469 { NULL
, NULL
, 0, 0 }
1472 static struct demangle_component
*
1473 d_operator_name (struct d_info
*di
)
1478 c1
= d_next_char (di
);
1479 c2
= d_next_char (di
);
1480 if (c1
== 'v' && IS_DIGIT (c2
))
1481 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1482 else if (c1
== 'c' && c2
== 'v')
1483 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1484 cplus_demangle_type (di
), NULL
);
1487 /* LOW is the inclusive lower bound. */
1489 /* HIGH is the exclusive upper bound. We subtract one to ignore
1490 the sentinel at the end of the array. */
1491 int high
= ((sizeof (cplus_demangle_operators
)
1492 / sizeof (cplus_demangle_operators
[0]))
1498 const struct demangle_operator_info
*p
;
1500 i
= low
+ (high
- low
) / 2;
1501 p
= cplus_demangle_operators
+ i
;
1503 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1504 return d_make_operator (di
, p
);
1506 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1516 static struct demangle_component
*
1517 d_make_character (struct d_info
*di
, int c
)
1519 struct demangle_component
*p
;
1520 p
= d_make_empty (di
);
1523 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1524 p
->u
.s_character
.character
= c
;
1529 static struct demangle_component
*
1530 d_java_resource (struct d_info
*di
)
1532 struct demangle_component
*p
= NULL
;
1533 struct demangle_component
*next
= NULL
;
1538 len
= d_number (di
);
1542 /* Eat the leading '_'. */
1543 if (d_next_char (di
) != '_')
1556 /* Each chunk is either a '$' escape... */
1574 next
= d_make_character (di
, c
);
1582 /* ... or a sequence of characters. */
1585 while (i
< len
&& str
[i
] && str
[i
] != '$')
1588 next
= d_make_name (di
, str
, i
);
1601 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1607 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1612 /* <special-name> ::= TV <type>
1616 ::= GV <(object) name>
1617 ::= T <call-offset> <(base) encoding>
1618 ::= Tc <call-offset> <call-offset> <(base) encoding>
1619 Also g++ extensions:
1620 ::= TC <type> <(offset) number> _ <(base) type>
1625 ::= Gr <resource name>
1628 static struct demangle_component
*
1629 d_special_name (struct d_info
*di
)
1631 di
->expansion
+= 20;
1632 if (d_check_char (di
, 'T'))
1634 switch (d_next_char (di
))
1638 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1639 cplus_demangle_type (di
), NULL
);
1641 di
->expansion
-= 10;
1642 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1643 cplus_demangle_type (di
), NULL
);
1645 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1646 cplus_demangle_type (di
), NULL
);
1648 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1649 cplus_demangle_type (di
), NULL
);
1652 if (! d_call_offset (di
, 'h'))
1654 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1655 d_encoding (di
, 0), NULL
);
1658 if (! d_call_offset (di
, 'v'))
1660 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1661 d_encoding (di
, 0), NULL
);
1664 if (! d_call_offset (di
, '\0'))
1666 if (! d_call_offset (di
, '\0'))
1668 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1669 d_encoding (di
, 0), NULL
);
1673 struct demangle_component
*derived_type
;
1675 struct demangle_component
*base_type
;
1677 derived_type
= cplus_demangle_type (di
);
1678 offset
= d_number (di
);
1681 if (! d_check_char (di
, '_'))
1683 base_type
= cplus_demangle_type (di
);
1684 /* We don't display the offset. FIXME: We should display
1685 it in verbose mode. */
1687 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1688 base_type
, derived_type
);
1692 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1693 cplus_demangle_type (di
), NULL
);
1695 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1696 cplus_demangle_type (di
), NULL
);
1702 else if (d_check_char (di
, 'G'))
1704 switch (d_next_char (di
))
1707 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1710 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, d_name (di
),
1714 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1715 d_encoding (di
, 0), NULL
);
1718 return d_java_resource (di
);
1728 /* <call-offset> ::= h <nv-offset> _
1731 <nv-offset> ::= <(offset) number>
1733 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1735 The C parameter, if not '\0', is a character we just read which is
1736 the start of the <call-offset>.
1738 We don't display the offset information anywhere. FIXME: We should
1739 display it in verbose mode. */
1742 d_call_offset (struct d_info
*di
, int c
)
1745 c
= d_next_char (di
);
1752 if (! d_check_char (di
, '_'))
1759 if (! d_check_char (di
, '_'))
1765 /* <ctor-dtor-name> ::= C1
1773 static struct demangle_component
*
1774 d_ctor_dtor_name (struct d_info
*di
)
1776 if (di
->last_name
!= NULL
)
1778 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1779 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1780 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1781 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1783 switch (d_peek_char (di
))
1787 enum gnu_v3_ctor_kinds kind
;
1789 switch (d_peek_next_char (di
))
1792 kind
= gnu_v3_complete_object_ctor
;
1795 kind
= gnu_v3_base_object_ctor
;
1798 kind
= gnu_v3_complete_object_allocating_ctor
;
1804 return d_make_ctor (di
, kind
, di
->last_name
);
1809 enum gnu_v3_dtor_kinds kind
;
1811 switch (d_peek_next_char (di
))
1814 kind
= gnu_v3_deleting_dtor
;
1817 kind
= gnu_v3_complete_object_dtor
;
1820 kind
= gnu_v3_base_object_dtor
;
1826 return d_make_dtor (di
, kind
, di
->last_name
);
1834 /* <type> ::= <builtin-type>
1836 ::= <class-enum-type>
1838 ::= <pointer-to-member-type>
1839 ::= <template-param>
1840 ::= <template-template-param> <template-args>
1842 ::= <CV-qualifiers> <type>
1845 ::= O <type> (C++0x)
1848 ::= U <source-name> <type>
1850 <builtin-type> ::= various one letter codes
1854 CP_STATIC_IF_GLIBCPP_V3
1855 const struct demangle_builtin_type_info
1856 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
1858 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
1859 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
1860 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
1861 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
1862 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
1863 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
1864 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
1865 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
1866 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
1867 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
1868 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1869 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
1870 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
1871 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
1872 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
1874 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1875 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1876 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1877 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
1878 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
1879 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1880 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
1881 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
1882 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
1883 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
1884 D_PRINT_UNSIGNED_LONG_LONG
},
1885 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
1888 CP_STATIC_IF_GLIBCPP_V3
1889 struct demangle_component
*
1890 cplus_demangle_type (struct d_info
*di
)
1893 struct demangle_component
*ret
;
1896 /* The ABI specifies that when CV-qualifiers are used, the base type
1897 is substitutable, and the fully qualified type is substitutable,
1898 but the base type with a strict subset of the CV-qualifiers is
1899 not substitutable. The natural recursive implementation of the
1900 CV-qualifiers would cause subsets to be substitutable, so instead
1901 we pull them all off now.
1903 FIXME: The ABI says that order-insensitive vendor qualifiers
1904 should be handled in the same way, but we have no way to tell
1905 which vendor qualifiers are order-insensitive and which are
1906 order-sensitive. So we just assume that they are all
1907 order-sensitive. g++ 3.4 supports only one vendor qualifier,
1908 __vector, and it treats it as order-sensitive when mangling
1911 peek
= d_peek_char (di
);
1912 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
1914 struct demangle_component
**pret
;
1916 pret
= d_cv_qualifiers (di
, &ret
, 0);
1919 *pret
= cplus_demangle_type (di
);
1920 if (! *pret
|| ! d_add_substitution (di
, ret
))
1929 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1930 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
1931 case 'o': case 's': case 't':
1932 case 'v': case 'w': case 'x': case 'y': case 'z':
1933 ret
= d_make_builtin_type (di
,
1934 &cplus_demangle_builtin_types
[peek
- 'a']);
1935 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
1942 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
1943 d_source_name (di
), NULL
);
1947 ret
= d_function_type (di
);
1950 case '0': case '1': case '2': case '3': case '4':
1951 case '5': case '6': case '7': case '8': case '9':
1954 ret
= d_class_enum_type (di
);
1958 ret
= d_array_type (di
);
1962 ret
= d_pointer_to_member_type (di
);
1966 ret
= d_template_param (di
);
1967 if (d_peek_char (di
) == 'I')
1969 /* This is <template-template-param> <template-args>. The
1970 <template-template-param> part is a substitution
1972 if (! d_add_substitution (di
, ret
))
1974 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
1975 d_template_args (di
));
1980 /* If this is a special substitution, then it is the start of
1981 <class-enum-type>. */
1985 peek_next
= d_peek_next_char (di
);
1986 if (IS_DIGIT (peek_next
)
1988 || IS_UPPER (peek_next
))
1990 ret
= d_substitution (di
, 0);
1991 /* The substituted name may have been a template name and
1992 may be followed by tepmlate args. */
1993 if (d_peek_char (di
) == 'I')
1994 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
1995 d_template_args (di
));
2001 ret
= d_class_enum_type (di
);
2002 /* If the substitution was a complete type, then it is not
2003 a new substitution candidate. However, if the
2004 substitution was followed by template arguments, then
2005 the whole thing is a substitution candidate. */
2006 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2014 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2015 cplus_demangle_type (di
), NULL
);
2020 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2021 cplus_demangle_type (di
), NULL
);
2026 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2027 cplus_demangle_type (di
), NULL
);
2032 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2033 cplus_demangle_type (di
), NULL
);
2038 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2039 cplus_demangle_type (di
), NULL
);
2044 ret
= d_source_name (di
);
2045 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2046 cplus_demangle_type (di
), ret
);
2055 if (! d_add_substitution (di
, ret
))
2062 /* <CV-qualifiers> ::= [r] [V] [K] */
2064 static struct demangle_component
**
2065 d_cv_qualifiers (struct d_info
*di
,
2066 struct demangle_component
**pret
, int member_fn
)
2070 peek
= d_peek_char (di
);
2071 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2073 enum demangle_component_type t
;
2079 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2080 : DEMANGLE_COMPONENT_RESTRICT
);
2081 di
->expansion
+= sizeof "restrict";
2083 else if (peek
== 'V')
2086 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2087 : DEMANGLE_COMPONENT_VOLATILE
);
2088 di
->expansion
+= sizeof "volatile";
2093 ? DEMANGLE_COMPONENT_CONST_THIS
2094 : DEMANGLE_COMPONENT_CONST
);
2095 di
->expansion
+= sizeof "const";
2098 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2101 pret
= &d_left (*pret
);
2103 peek
= d_peek_char (di
);
2109 /* <function-type> ::= F [Y] <bare-function-type> E */
2111 static struct demangle_component
*
2112 d_function_type (struct d_info
*di
)
2114 struct demangle_component
*ret
;
2116 if (! d_check_char (di
, 'F'))
2118 if (d_peek_char (di
) == 'Y')
2120 /* Function has C linkage. We don't print this information.
2121 FIXME: We should print it in verbose mode. */
2124 ret
= d_bare_function_type (di
, 1);
2125 if (! d_check_char (di
, 'E'))
2130 /* <bare-function-type> ::= [J]<type>+ */
2132 static struct demangle_component
*
2133 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2135 struct demangle_component
*return_type
;
2136 struct demangle_component
*tl
;
2137 struct demangle_component
**ptl
;
2140 /* Detect special qualifier indicating that the first argument
2141 is the return type. */
2142 peek
= d_peek_char (di
);
2146 has_return_type
= 1;
2154 struct demangle_component
*type
;
2156 peek
= d_peek_char (di
);
2157 if (peek
== '\0' || peek
== 'E')
2159 type
= cplus_demangle_type (di
);
2162 if (has_return_type
)
2165 has_return_type
= 0;
2169 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2172 ptl
= &d_right (*ptl
);
2176 /* There should be at least one parameter type besides the optional
2177 return type. A function which takes no arguments will have a
2178 single parameter type void. */
2182 /* If we have a single parameter type void, omit it. */
2183 if (d_right (tl
) == NULL
2184 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2185 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2187 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2191 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
, return_type
, tl
);
2194 /* <class-enum-type> ::= <name> */
2196 static struct demangle_component
*
2197 d_class_enum_type (struct d_info
*di
)
2202 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2203 ::= A [<(dimension) expression>] _ <(element) type>
2206 static struct demangle_component
*
2207 d_array_type (struct d_info
*di
)
2210 struct demangle_component
*dim
;
2212 if (! d_check_char (di
, 'A'))
2215 peek
= d_peek_char (di
);
2218 else if (IS_DIGIT (peek
))
2226 peek
= d_peek_char (di
);
2228 while (IS_DIGIT (peek
));
2229 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2235 dim
= d_expression (di
);
2240 if (! d_check_char (di
, '_'))
2243 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2244 cplus_demangle_type (di
));
2247 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2249 static struct demangle_component
*
2250 d_pointer_to_member_type (struct d_info
*di
)
2252 struct demangle_component
*cl
;
2253 struct demangle_component
*mem
;
2254 struct demangle_component
**pmem
;
2256 if (! d_check_char (di
, 'M'))
2259 cl
= cplus_demangle_type (di
);
2261 /* The ABI specifies that any type can be a substitution source, and
2262 that M is followed by two types, and that when a CV-qualified
2263 type is seen both the base type and the CV-qualified types are
2264 substitution sources. The ABI also specifies that for a pointer
2265 to a CV-qualified member function, the qualifiers are attached to
2266 the second type. Given the grammar, a plain reading of the ABI
2267 suggests that both the CV-qualified member function and the
2268 non-qualified member function are substitution sources. However,
2269 g++ does not work that way. g++ treats only the CV-qualified
2270 member function as a substitution source. FIXME. So to work
2271 with g++, we need to pull off the CV-qualifiers here, in order to
2272 avoid calling add_substitution() in cplus_demangle_type(). But
2273 for a CV-qualified member which is not a function, g++ does
2274 follow the ABI, so we need to handle that case here by calling
2275 d_add_substitution ourselves. */
2277 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2280 *pmem
= cplus_demangle_type (di
);
2284 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2286 if (! d_add_substitution (di
, mem
))
2290 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2293 /* <template-param> ::= T_
2294 ::= T <(parameter-2 non-negative) number> _
2297 static struct demangle_component
*
2298 d_template_param (struct d_info
*di
)
2302 if (! d_check_char (di
, 'T'))
2305 if (d_peek_char (di
) == '_')
2309 param
= d_number (di
);
2315 if (! d_check_char (di
, '_'))
2320 return d_make_template_param (di
, param
);
2323 /* <template-args> ::= I <template-arg>+ E */
2325 static struct demangle_component
*
2326 d_template_args (struct d_info
*di
)
2328 struct demangle_component
*hold_last_name
;
2329 struct demangle_component
*al
;
2330 struct demangle_component
**pal
;
2332 /* Preserve the last name we saw--don't let the template arguments
2333 clobber it, as that would give us the wrong name for a subsequent
2334 constructor or destructor. */
2335 hold_last_name
= di
->last_name
;
2337 if (! d_check_char (di
, 'I'))
2344 struct demangle_component
*a
;
2346 a
= d_template_arg (di
);
2350 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2353 pal
= &d_right (*pal
);
2355 if (d_peek_char (di
) == 'E')
2362 di
->last_name
= hold_last_name
;
2367 /* <template-arg> ::= <type>
2368 ::= X <expression> E
2372 static struct demangle_component
*
2373 d_template_arg (struct d_info
*di
)
2375 struct demangle_component
*ret
;
2377 switch (d_peek_char (di
))
2381 ret
= d_expression (di
);
2382 if (! d_check_char (di
, 'E'))
2387 return d_expr_primary (di
);
2390 return cplus_demangle_type (di
);
2394 /* <expression> ::= <(unary) operator-name> <expression>
2395 ::= <(binary) operator-name> <expression> <expression>
2396 ::= <(trinary) operator-name> <expression> <expression> <expression>
2398 ::= <template-param>
2399 ::= sr <type> <unqualified-name>
2400 ::= sr <type> <unqualified-name> <template-args>
2404 static struct demangle_component
*
2405 d_expression (struct d_info
*di
)
2409 peek
= d_peek_char (di
);
2411 return d_expr_primary (di
);
2412 else if (peek
== 'T')
2413 return d_template_param (di
);
2414 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2416 struct demangle_component
*type
;
2417 struct demangle_component
*name
;
2420 type
= cplus_demangle_type (di
);
2421 name
= d_unqualified_name (di
);
2422 if (d_peek_char (di
) != 'I')
2423 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2425 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2426 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2427 d_template_args (di
)));
2431 struct demangle_component
*op
;
2434 op
= d_operator_name (di
);
2438 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2439 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2441 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2442 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2443 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2444 cplus_demangle_type (di
));
2450 case DEMANGLE_COMPONENT_OPERATOR
:
2451 args
= op
->u
.s_operator
.op
->args
;
2453 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2454 args
= op
->u
.s_extended_operator
.args
;
2456 case DEMANGLE_COMPONENT_CAST
:
2464 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2468 struct demangle_component
*left
;
2470 left
= d_expression (di
);
2471 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2473 DEMANGLE_COMPONENT_BINARY_ARGS
,
2475 d_expression (di
)));
2479 struct demangle_component
*first
;
2480 struct demangle_component
*second
;
2482 first
= d_expression (di
);
2483 second
= d_expression (di
);
2484 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2486 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2489 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2491 d_expression (di
))));
2499 /* <expr-primary> ::= L <type> <(value) number> E
2500 ::= L <type> <(value) float> E
2501 ::= L <mangled-name> E
2504 static struct demangle_component
*
2505 d_expr_primary (struct d_info
*di
)
2507 struct demangle_component
*ret
;
2509 if (! d_check_char (di
, 'L'))
2511 if (d_peek_char (di
) == '_')
2512 ret
= cplus_demangle_mangled_name (di
, 0);
2515 struct demangle_component
*type
;
2516 enum demangle_component_type t
;
2519 type
= cplus_demangle_type (di
);
2523 /* If we have a type we know how to print, we aren't going to
2524 print the type name itself. */
2525 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2526 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2527 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2529 /* Rather than try to interpret the literal value, we just
2530 collect it as a string. Note that it's possible to have a
2531 floating point literal here. The ABI specifies that the
2532 format of such literals is machine independent. That's fine,
2533 but what's not fine is that versions of g++ up to 3.2 with
2534 -fabi-version=1 used upper case letters in the hex constant,
2535 and dumped out gcc's internal representation. That makes it
2536 hard to tell where the constant ends, and hard to dump the
2537 constant in any readable form anyhow. We don't attempt to
2538 handle these cases. */
2540 t
= DEMANGLE_COMPONENT_LITERAL
;
2541 if (d_peek_char (di
) == 'n')
2543 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2547 while (d_peek_char (di
) != 'E')
2549 if (d_peek_char (di
) == '\0')
2553 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2555 if (! d_check_char (di
, 'E'))
2560 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2561 ::= Z <(function) encoding> E s [<discriminator>]
2564 static struct demangle_component
*
2565 d_local_name (struct d_info
*di
)
2567 struct demangle_component
*function
;
2569 if (! d_check_char (di
, 'Z'))
2572 function
= d_encoding (di
, 0);
2574 if (! d_check_char (di
, 'E'))
2577 if (d_peek_char (di
) == 's')
2580 if (! d_discriminator (di
))
2582 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
2583 d_make_name (di
, "string literal",
2584 sizeof "string literal" - 1));
2588 struct demangle_component
*name
;
2591 if (! d_discriminator (di
))
2593 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
2597 /* <discriminator> ::= _ <(non-negative) number>
2599 We demangle the discriminator, but we don't print it out. FIXME:
2600 We should print it out in verbose mode. */
2603 d_discriminator (struct d_info
*di
)
2607 if (d_peek_char (di
) != '_')
2610 discrim
= d_number (di
);
2616 /* Add a new substitution. */
2619 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
2623 if (di
->next_sub
>= di
->num_subs
)
2625 di
->subs
[di
->next_sub
] = dc
;
2630 /* <substitution> ::= S <seq-id> _
2640 If PREFIX is non-zero, then this type is being used as a prefix in
2641 a qualified name. In this case, for the standard substitutions, we
2642 need to check whether we are being used as a prefix for a
2643 constructor or destructor, and return a full template name.
2644 Otherwise we will get something like std::iostream::~iostream()
2645 which does not correspond particularly well to any function which
2646 actually appears in the source.
2649 static const struct d_standard_sub_info standard_subs
[] =
2654 { 'a', NL ("std::allocator"),
2655 NL ("std::allocator"),
2657 { 'b', NL ("std::basic_string"),
2658 NL ("std::basic_string"),
2659 NL ("basic_string") },
2660 { 's', NL ("std::string"),
2661 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
2662 NL ("basic_string") },
2663 { 'i', NL ("std::istream"),
2664 NL ("std::basic_istream<char, std::char_traits<char> >"),
2665 NL ("basic_istream") },
2666 { 'o', NL ("std::ostream"),
2667 NL ("std::basic_ostream<char, std::char_traits<char> >"),
2668 NL ("basic_ostream") },
2669 { 'd', NL ("std::iostream"),
2670 NL ("std::basic_iostream<char, std::char_traits<char> >"),
2671 NL ("basic_iostream") }
2674 static struct demangle_component
*
2675 d_substitution (struct d_info
*di
, int prefix
)
2679 if (! d_check_char (di
, 'S'))
2682 c
= d_next_char (di
);
2683 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
2692 unsigned int new_id
;
2695 new_id
= id
* 36 + c
- '0';
2696 else if (IS_UPPER (c
))
2697 new_id
= id
* 36 + c
- 'A' + 10;
2703 c
= d_next_char (di
);
2710 if (id
>= (unsigned int) di
->next_sub
)
2715 return di
->subs
[id
];
2720 const struct d_standard_sub_info
*p
;
2721 const struct d_standard_sub_info
*pend
;
2723 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
2724 if (! verbose
&& prefix
)
2728 peek
= d_peek_char (di
);
2729 if (peek
== 'C' || peek
== 'D')
2733 pend
= (&standard_subs
[0]
2734 + sizeof standard_subs
/ sizeof standard_subs
[0]);
2735 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
2742 if (p
->set_last_name
!= NULL
)
2743 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
2744 p
->set_last_name_len
);
2747 s
= p
->full_expansion
;
2752 s
= p
->simple_expansion
;
2753 len
= p
->simple_len
;
2755 di
->expansion
+= len
;
2756 return d_make_sub (di
, s
, len
);
2764 /* Initialize a growable string. */
2767 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
2772 dgs
->allocation_failure
= 0;
2775 d_growable_string_resize (dgs
, estimate
);
2778 /* Grow a growable string to a given size. */
2781 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
2786 if (dgs
->allocation_failure
)
2789 /* Start allocation at two bytes to avoid any possibility of confusion
2790 with the special value of 1 used as a return in *palc to indicate
2791 allocation failures. */
2792 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
2793 while (newalc
< need
)
2796 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
2803 dgs
->allocation_failure
= 1;
2810 /* Append a buffer to a growable string. */
2813 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
2814 const char *s
, size_t l
)
2818 need
= dgs
->len
+ l
+ 1;
2819 if (need
> dgs
->alc
)
2820 d_growable_string_resize (dgs
, need
);
2822 if (dgs
->allocation_failure
)
2825 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
2826 dgs
->buf
[dgs
->len
+ l
] = '\0';
2830 /* Bridge growable strings to the callback mechanism. */
2833 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
2835 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
2837 d_growable_string_append_buffer (dgs
, s
, l
);
2840 /* Initialize a print information structure. */
2843 d_print_init (struct d_print_info
*dpi
, int options
,
2844 demangle_callbackref callback
, void *opaque
)
2846 dpi
->options
= options
;
2848 dpi
->last_char
= '\0';
2849 dpi
->templates
= NULL
;
2850 dpi
->modifiers
= NULL
;
2852 dpi
->callback
= callback
;
2853 dpi
->opaque
= opaque
;
2855 dpi
->demangle_failure
= 0;
2858 /* Indicate that an error occurred during printing, and test for error. */
2861 d_print_error (struct d_print_info
*dpi
)
2863 dpi
->demangle_failure
= 1;
2867 d_print_saw_error (struct d_print_info
*dpi
)
2869 return dpi
->demangle_failure
!= 0;
2872 /* Flush buffered characters to the callback. */
2875 d_print_flush (struct d_print_info
*dpi
)
2877 dpi
->buf
[dpi
->len
] = '\0';
2878 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
2882 /* Append characters and buffers for printing. */
2885 d_append_char (struct d_print_info
*dpi
, char c
)
2887 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
2888 d_print_flush (dpi
);
2890 dpi
->buf
[dpi
->len
++] = c
;
2895 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
2899 for (i
= 0; i
< l
; i
++)
2900 d_append_char (dpi
, s
[i
]);
2904 d_append_string (struct d_print_info
*dpi
, const char *s
)
2906 d_append_buffer (dpi
, s
, strlen (s
));
2910 d_last_char (struct d_print_info
*dpi
)
2912 return dpi
->last_char
;
2915 /* Turn components into a human readable string. OPTIONS is the
2916 options bits passed to the demangler. DC is the tree to print.
2917 CALLBACK is a function to call to flush demangled string segments
2918 as they fill the intermediate buffer, and OPAQUE is a generalized
2919 callback argument. On success, this returns 1. On failure,
2920 it returns 0, indicating a bad parse. It does not use heap
2921 memory to build an output string, so cannot encounter memory
2922 allocation failure. */
2924 CP_STATIC_IF_GLIBCPP_V3
2926 cplus_demangle_print_callback (int options
,
2927 const struct demangle_component
*dc
,
2928 demangle_callbackref callback
, void *opaque
)
2930 struct d_print_info dpi
;
2932 d_print_init (&dpi
, options
, callback
, opaque
);
2934 d_print_comp (&dpi
, dc
);
2936 d_print_flush (&dpi
);
2938 return ! d_print_saw_error (&dpi
);
2941 /* Turn components into a human readable string. OPTIONS is the
2942 options bits passed to the demangler. DC is the tree to print.
2943 ESTIMATE is a guess at the length of the result. This returns a
2944 string allocated by malloc, or NULL on error. On success, this
2945 sets *PALC to the size of the allocated buffer. On failure, this
2946 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
2949 CP_STATIC_IF_GLIBCPP_V3
2951 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
2952 int estimate
, size_t *palc
)
2954 struct d_growable_string dgs
;
2956 d_growable_string_init (&dgs
, estimate
);
2958 if (! cplus_demangle_print_callback (options
, dc
,
2959 d_growable_string_callback_adapter
,
2967 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
2971 /* Subroutine to handle components. */
2974 d_print_comp (struct d_print_info
*dpi
,
2975 const struct demangle_component
*dc
)
2979 d_print_error (dpi
);
2982 if (d_print_saw_error (dpi
))
2987 case DEMANGLE_COMPONENT_NAME
:
2988 if ((dpi
->options
& DMGL_JAVA
) == 0)
2989 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
2991 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
2994 case DEMANGLE_COMPONENT_QUAL_NAME
:
2995 case DEMANGLE_COMPONENT_LOCAL_NAME
:
2996 d_print_comp (dpi
, d_left (dc
));
2997 if ((dpi
->options
& DMGL_JAVA
) == 0)
2998 d_append_string (dpi
, "::");
3000 d_append_char (dpi
, '.');
3001 d_print_comp (dpi
, d_right (dc
));
3004 case DEMANGLE_COMPONENT_TYPED_NAME
:
3006 struct d_print_mod
*hold_modifiers
;
3007 struct demangle_component
*typed_name
;
3008 struct d_print_mod adpm
[4];
3010 struct d_print_template dpt
;
3012 /* Pass the name down to the type so that it can be printed in
3013 the right place for the type. We also have to pass down
3014 any CV-qualifiers, which apply to the this parameter. */
3015 hold_modifiers
= dpi
->modifiers
;
3017 typed_name
= d_left (dc
);
3018 while (typed_name
!= NULL
)
3020 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3022 d_print_error (dpi
);
3026 adpm
[i
].next
= dpi
->modifiers
;
3027 dpi
->modifiers
= &adpm
[i
];
3028 adpm
[i
].mod
= typed_name
;
3029 adpm
[i
].printed
= 0;
3030 adpm
[i
].templates
= dpi
->templates
;
3033 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3034 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3035 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3038 typed_name
= d_left (typed_name
);
3041 if (typed_name
== NULL
)
3043 d_print_error (dpi
);
3047 /* If typed_name is a template, then it applies to the
3048 function type as well. */
3049 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3051 dpt
.next
= dpi
->templates
;
3052 dpi
->templates
= &dpt
;
3053 dpt
.template_decl
= typed_name
;
3056 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3057 there may be CV-qualifiers on its right argument which
3058 really apply here; this happens when parsing a class which
3059 is local to a function. */
3060 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3062 struct demangle_component
*local_name
;
3064 local_name
= d_right (typed_name
);
3065 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3066 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3067 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3069 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3071 d_print_error (dpi
);
3075 adpm
[i
] = adpm
[i
- 1];
3076 adpm
[i
].next
= &adpm
[i
- 1];
3077 dpi
->modifiers
= &adpm
[i
];
3079 adpm
[i
- 1].mod
= local_name
;
3080 adpm
[i
- 1].printed
= 0;
3081 adpm
[i
- 1].templates
= dpi
->templates
;
3084 local_name
= d_left (local_name
);
3088 d_print_comp (dpi
, d_right (dc
));
3090 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3091 dpi
->templates
= dpt
.next
;
3093 /* If the modifiers didn't get printed by the type, print them
3098 if (! adpm
[i
].printed
)
3100 d_append_char (dpi
, ' ');
3101 d_print_mod (dpi
, adpm
[i
].mod
);
3105 dpi
->modifiers
= hold_modifiers
;
3110 case DEMANGLE_COMPONENT_TEMPLATE
:
3112 struct d_print_mod
*hold_dpm
;
3113 struct demangle_component
*dcl
;
3115 /* Don't push modifiers into a template definition. Doing so
3116 could give the wrong definition for a template argument.
3117 Instead, treat the template essentially as a name. */
3119 hold_dpm
= dpi
->modifiers
;
3120 dpi
->modifiers
= NULL
;
3124 if ((dpi
->options
& DMGL_JAVA
) != 0
3125 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3126 && dcl
->u
.s_name
.len
== 6
3127 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3129 /* Special-case Java arrays, so that JArray<TYPE> appears
3130 instead as TYPE[]. */
3132 d_print_comp (dpi
, d_right (dc
));
3133 d_append_string (dpi
, "[]");
3137 d_print_comp (dpi
, dcl
);
3138 if (d_last_char (dpi
) == '<')
3139 d_append_char (dpi
, ' ');
3140 d_append_char (dpi
, '<');
3141 d_print_comp (dpi
, d_right (dc
));
3142 /* Avoid generating two consecutive '>' characters, to avoid
3143 the C++ syntactic ambiguity. */
3144 if (d_last_char (dpi
) == '>')
3145 d_append_char (dpi
, ' ');
3146 d_append_char (dpi
, '>');
3149 dpi
->modifiers
= hold_dpm
;
3154 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3157 struct demangle_component
*a
;
3158 struct d_print_template
*hold_dpt
;
3160 if (dpi
->templates
== NULL
)
3162 d_print_error (dpi
);
3165 i
= dc
->u
.s_number
.number
;
3166 for (a
= d_right (dpi
->templates
->template_decl
);
3170 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3172 d_print_error (dpi
);
3179 if (i
!= 0 || a
== NULL
)
3181 d_print_error (dpi
);
3185 /* While processing this parameter, we need to pop the list of
3186 templates. This is because the template parameter may
3187 itself be a reference to a parameter of an outer
3190 hold_dpt
= dpi
->templates
;
3191 dpi
->templates
= hold_dpt
->next
;
3193 d_print_comp (dpi
, d_left (a
));
3195 dpi
->templates
= hold_dpt
;
3200 case DEMANGLE_COMPONENT_CTOR
:
3201 d_print_comp (dpi
, dc
->u
.s_ctor
.name
);
3204 case DEMANGLE_COMPONENT_DTOR
:
3205 d_append_char (dpi
, '~');
3206 d_print_comp (dpi
, dc
->u
.s_dtor
.name
);
3209 case DEMANGLE_COMPONENT_VTABLE
:
3210 d_append_string (dpi
, "vtable for ");
3211 d_print_comp (dpi
, d_left (dc
));
3214 case DEMANGLE_COMPONENT_VTT
:
3215 d_append_string (dpi
, "VTT for ");
3216 d_print_comp (dpi
, d_left (dc
));
3219 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3220 d_append_string (dpi
, "construction vtable for ");
3221 d_print_comp (dpi
, d_left (dc
));
3222 d_append_string (dpi
, "-in-");
3223 d_print_comp (dpi
, d_right (dc
));
3226 case DEMANGLE_COMPONENT_TYPEINFO
:
3227 d_append_string (dpi
, "typeinfo for ");
3228 d_print_comp (dpi
, d_left (dc
));
3231 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3232 d_append_string (dpi
, "typeinfo name for ");
3233 d_print_comp (dpi
, d_left (dc
));
3236 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3237 d_append_string (dpi
, "typeinfo fn for ");
3238 d_print_comp (dpi
, d_left (dc
));
3241 case DEMANGLE_COMPONENT_THUNK
:
3242 d_append_string (dpi
, "non-virtual thunk to ");
3243 d_print_comp (dpi
, d_left (dc
));
3246 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3247 d_append_string (dpi
, "virtual thunk to ");
3248 d_print_comp (dpi
, d_left (dc
));
3251 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3252 d_append_string (dpi
, "covariant return thunk to ");
3253 d_print_comp (dpi
, d_left (dc
));
3256 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3257 d_append_string (dpi
, "java Class for ");
3258 d_print_comp (dpi
, d_left (dc
));
3261 case DEMANGLE_COMPONENT_GUARD
:
3262 d_append_string (dpi
, "guard variable for ");
3263 d_print_comp (dpi
, d_left (dc
));
3266 case DEMANGLE_COMPONENT_REFTEMP
:
3267 d_append_string (dpi
, "reference temporary for ");
3268 d_print_comp (dpi
, d_left (dc
));
3271 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3272 d_append_string (dpi
, "hidden alias for ");
3273 d_print_comp (dpi
, d_left (dc
));
3276 case DEMANGLE_COMPONENT_SUB_STD
:
3277 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3280 case DEMANGLE_COMPONENT_RESTRICT
:
3281 case DEMANGLE_COMPONENT_VOLATILE
:
3282 case DEMANGLE_COMPONENT_CONST
:
3284 struct d_print_mod
*pdpm
;
3286 /* When printing arrays, it's possible to have cases where the
3287 same CV-qualifier gets pushed on the stack multiple times.
3288 We only need to print it once. */
3290 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3292 if (! pdpm
->printed
)
3294 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3295 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3296 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3298 if (pdpm
->mod
->type
== dc
->type
)
3300 d_print_comp (dpi
, d_left (dc
));
3307 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3308 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3309 case DEMANGLE_COMPONENT_CONST_THIS
:
3310 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3311 case DEMANGLE_COMPONENT_POINTER
:
3312 case DEMANGLE_COMPONENT_REFERENCE
:
3313 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3314 case DEMANGLE_COMPONENT_COMPLEX
:
3315 case DEMANGLE_COMPONENT_IMAGINARY
:
3317 /* We keep a list of modifiers on the stack. */
3318 struct d_print_mod dpm
;
3320 dpm
.next
= dpi
->modifiers
;
3321 dpi
->modifiers
= &dpm
;
3324 dpm
.templates
= dpi
->templates
;
3326 d_print_comp (dpi
, d_left (dc
));
3328 /* If the modifier didn't get printed by the type, print it
3331 d_print_mod (dpi
, dc
);
3333 dpi
->modifiers
= dpm
.next
;
3338 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3339 if ((dpi
->options
& DMGL_JAVA
) == 0)
3340 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
3341 dc
->u
.s_builtin
.type
->len
);
3343 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
3344 dc
->u
.s_builtin
.type
->java_len
);
3347 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3348 d_print_comp (dpi
, d_left (dc
));
3351 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3353 if ((dpi
->options
& DMGL_RET_POSTFIX
) != 0)
3354 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3356 /* Print return type if present */
3357 if (d_left (dc
) != NULL
)
3359 struct d_print_mod dpm
;
3361 /* We must pass this type down as a modifier in order to
3362 print it in the right location. */
3363 dpm
.next
= dpi
->modifiers
;
3364 dpi
->modifiers
= &dpm
;
3367 dpm
.templates
= dpi
->templates
;
3369 d_print_comp (dpi
, d_left (dc
));
3371 dpi
->modifiers
= dpm
.next
;
3376 /* In standard prefix notation, there is a space between the
3377 return type and the function signature. */
3378 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3379 d_append_char (dpi
, ' ');
3382 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3383 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3388 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3390 struct d_print_mod
*hold_modifiers
;
3391 struct d_print_mod adpm
[4];
3393 struct d_print_mod
*pdpm
;
3395 /* We must pass this type down as a modifier in order to print
3396 multi-dimensional arrays correctly. If the array itself is
3397 CV-qualified, we act as though the element type were
3398 CV-qualified. We do this by copying the modifiers down
3399 rather than fiddling pointers, so that we don't wind up
3400 with a d_print_mod higher on the stack pointing into our
3401 stack frame after we return. */
3403 hold_modifiers
= dpi
->modifiers
;
3405 adpm
[0].next
= hold_modifiers
;
3406 dpi
->modifiers
= &adpm
[0];
3408 adpm
[0].printed
= 0;
3409 adpm
[0].templates
= dpi
->templates
;
3412 pdpm
= hold_modifiers
;
3414 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
3415 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
3416 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
3418 if (! pdpm
->printed
)
3420 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3422 d_print_error (dpi
);
3427 adpm
[i
].next
= dpi
->modifiers
;
3428 dpi
->modifiers
= &adpm
[i
];
3436 d_print_comp (dpi
, d_right (dc
));
3438 dpi
->modifiers
= hold_modifiers
;
3440 if (adpm
[0].printed
)
3446 d_print_mod (dpi
, adpm
[i
].mod
);
3449 d_print_array_type (dpi
, dc
, dpi
->modifiers
);
3454 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3456 struct d_print_mod dpm
;
3458 dpm
.next
= dpi
->modifiers
;
3459 dpi
->modifiers
= &dpm
;
3462 dpm
.templates
= dpi
->templates
;
3464 d_print_comp (dpi
, d_right (dc
));
3466 /* If the modifier didn't get printed by the type, print it
3470 d_append_char (dpi
, ' ');
3471 d_print_comp (dpi
, d_left (dc
));
3472 d_append_string (dpi
, "::*");
3475 dpi
->modifiers
= dpm
.next
;
3480 case DEMANGLE_COMPONENT_ARGLIST
:
3481 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3482 d_print_comp (dpi
, d_left (dc
));
3483 if (d_right (dc
) != NULL
)
3485 d_append_string (dpi
, ", ");
3486 d_print_comp (dpi
, d_right (dc
));
3490 case DEMANGLE_COMPONENT_OPERATOR
:
3494 d_append_string (dpi
, "operator");
3495 c
= dc
->u
.s_operator
.op
->name
[0];
3497 d_append_char (dpi
, ' ');
3498 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
3499 dc
->u
.s_operator
.op
->len
);
3503 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3504 d_append_string (dpi
, "operator ");
3505 d_print_comp (dpi
, dc
->u
.s_extended_operator
.name
);
3508 case DEMANGLE_COMPONENT_CAST
:
3509 d_append_string (dpi
, "operator ");
3510 d_print_cast (dpi
, dc
);
3513 case DEMANGLE_COMPONENT_UNARY
:
3514 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
3515 d_print_expr_op (dpi
, d_left (dc
));
3518 d_append_char (dpi
, '(');
3519 d_print_cast (dpi
, d_left (dc
));
3520 d_append_char (dpi
, ')');
3522 d_append_char (dpi
, '(');
3523 d_print_comp (dpi
, d_right (dc
));
3524 d_append_char (dpi
, ')');
3527 case DEMANGLE_COMPONENT_BINARY
:
3528 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
3530 d_print_error (dpi
);
3534 /* We wrap an expression which uses the greater-than operator in
3535 an extra layer of parens so that it does not get confused
3536 with the '>' which ends the template parameters. */
3537 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
3538 && d_left (dc
)->u
.s_operator
.op
->len
== 1
3539 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
3540 d_append_char (dpi
, '(');
3542 d_append_char (dpi
, '(');
3543 d_print_comp (dpi
, d_left (d_right (dc
)));
3544 d_append_string (dpi
, ") ");
3545 d_print_expr_op (dpi
, d_left (dc
));
3546 d_append_string (dpi
, " (");
3547 d_print_comp (dpi
, d_right (d_right (dc
)));
3548 d_append_char (dpi
, ')');
3550 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
3551 && d_left (dc
)->u
.s_operator
.op
->len
== 1
3552 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
3553 d_append_char (dpi
, ')');
3557 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3558 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
3559 d_print_error (dpi
);
3562 case DEMANGLE_COMPONENT_TRINARY
:
3563 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
3564 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
3566 d_print_error (dpi
);
3569 d_append_char (dpi
, '(');
3570 d_print_comp (dpi
, d_left (d_right (dc
)));
3571 d_append_string (dpi
, ") ");
3572 d_print_expr_op (dpi
, d_left (dc
));
3573 d_append_string (dpi
, " (");
3574 d_print_comp (dpi
, d_left (d_right (d_right (dc
))));
3575 d_append_string (dpi
, ") : (");
3576 d_print_comp (dpi
, d_right (d_right (d_right (dc
))));
3577 d_append_char (dpi
, ')');
3580 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3581 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3582 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
3583 d_print_error (dpi
);
3586 case DEMANGLE_COMPONENT_LITERAL
:
3587 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3589 enum d_builtin_type_print tp
;
3591 /* For some builtin types, produce simpler output. */
3592 tp
= D_PRINT_DEFAULT
;
3593 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
3595 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
3599 case D_PRINT_UNSIGNED
:
3601 case D_PRINT_UNSIGNED_LONG
:
3602 case D_PRINT_LONG_LONG
:
3603 case D_PRINT_UNSIGNED_LONG_LONG
:
3604 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
3606 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
3607 d_append_char (dpi
, '-');
3608 d_print_comp (dpi
, d_right (dc
));
3613 case D_PRINT_UNSIGNED
:
3614 d_append_char (dpi
, 'u');
3617 d_append_char (dpi
, 'l');
3619 case D_PRINT_UNSIGNED_LONG
:
3620 d_append_string (dpi
, "ul");
3622 case D_PRINT_LONG_LONG
:
3623 d_append_string (dpi
, "ll");
3625 case D_PRINT_UNSIGNED_LONG_LONG
:
3626 d_append_string (dpi
, "ull");
3634 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
3635 && d_right (dc
)->u
.s_name
.len
== 1
3636 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
3638 switch (d_right (dc
)->u
.s_name
.s
[0])
3641 d_append_string (dpi
, "false");
3644 d_append_string (dpi
, "true");
3657 d_append_char (dpi
, '(');
3658 d_print_comp (dpi
, d_left (dc
));
3659 d_append_char (dpi
, ')');
3660 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
3661 d_append_char (dpi
, '-');
3662 if (tp
== D_PRINT_FLOAT
)
3663 d_append_char (dpi
, '[');
3664 d_print_comp (dpi
, d_right (dc
));
3665 if (tp
== D_PRINT_FLOAT
)
3666 d_append_char (dpi
, ']');
3670 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
3671 d_append_string (dpi
, "java resource ");
3672 d_print_comp (dpi
, d_left (dc
));
3675 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
3676 d_print_comp (dpi
, d_left (dc
));
3677 d_print_comp (dpi
, d_right (dc
));
3680 case DEMANGLE_COMPONENT_CHARACTER
:
3681 d_append_char (dpi
, dc
->u
.s_character
.character
);
3685 d_print_error (dpi
);
3690 /* Print a Java dentifier. For Java we try to handle encoded extended
3691 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
3692 so we don't it for C++. Characters are encoded as
3696 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
3702 for (p
= name
; p
< end
; ++p
)
3713 for (q
= p
+ 3; q
< end
; ++q
)
3719 else if (*q
>= 'A' && *q
<= 'F')
3720 dig
= *q
- 'A' + 10;
3721 else if (*q
>= 'a' && *q
<= 'f')
3722 dig
= *q
- 'a' + 10;
3728 /* If the Unicode character is larger than 256, we don't try
3729 to deal with it here. FIXME. */
3730 if (q
< end
&& *q
== '_' && c
< 256)
3732 d_append_char (dpi
, c
);
3738 d_append_char (dpi
, *p
);
3742 /* Print a list of modifiers. SUFFIX is 1 if we are printing
3743 qualifiers on this after printing a function. */
3746 d_print_mod_list (struct d_print_info
*dpi
,
3747 struct d_print_mod
*mods
, int suffix
)
3749 struct d_print_template
*hold_dpt
;
3751 if (mods
== NULL
|| d_print_saw_error (dpi
))
3756 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3757 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3758 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
3760 d_print_mod_list (dpi
, mods
->next
, suffix
);
3766 hold_dpt
= dpi
->templates
;
3767 dpi
->templates
= mods
->templates
;
3769 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
3771 d_print_function_type (dpi
, mods
->mod
, mods
->next
);
3772 dpi
->templates
= hold_dpt
;
3775 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
3777 d_print_array_type (dpi
, mods
->mod
, mods
->next
);
3778 dpi
->templates
= hold_dpt
;
3781 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3783 struct d_print_mod
*hold_modifiers
;
3784 struct demangle_component
*dc
;
3786 /* When this is on the modifier stack, we have pulled any
3787 qualifiers off the right argument already. Otherwise, we
3788 print it as usual, but don't let the left argument see any
3791 hold_modifiers
= dpi
->modifiers
;
3792 dpi
->modifiers
= NULL
;
3793 d_print_comp (dpi
, d_left (mods
->mod
));
3794 dpi
->modifiers
= hold_modifiers
;
3796 if ((dpi
->options
& DMGL_JAVA
) == 0)
3797 d_append_string (dpi
, "::");
3799 d_append_char (dpi
, '.');
3801 dc
= d_right (mods
->mod
);
3802 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3803 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3804 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3807 d_print_comp (dpi
, dc
);
3809 dpi
->templates
= hold_dpt
;
3813 d_print_mod (dpi
, mods
->mod
);
3815 dpi
->templates
= hold_dpt
;
3817 d_print_mod_list (dpi
, mods
->next
, suffix
);
3820 /* Print a modifier. */
3823 d_print_mod (struct d_print_info
*dpi
,
3824 const struct demangle_component
*mod
)
3828 case DEMANGLE_COMPONENT_RESTRICT
:
3829 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3830 d_append_string (dpi
, " restrict");
3832 case DEMANGLE_COMPONENT_VOLATILE
:
3833 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3834 d_append_string (dpi
, " volatile");
3836 case DEMANGLE_COMPONENT_CONST
:
3837 case DEMANGLE_COMPONENT_CONST_THIS
:
3838 d_append_string (dpi
, " const");
3840 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3841 d_append_char (dpi
, ' ');
3842 d_print_comp (dpi
, d_right (mod
));
3844 case DEMANGLE_COMPONENT_POINTER
:
3845 /* There is no pointer symbol in Java. */
3846 if ((dpi
->options
& DMGL_JAVA
) == 0)
3847 d_append_char (dpi
, '*');
3849 case DEMANGLE_COMPONENT_REFERENCE
:
3850 d_append_char (dpi
, '&');
3852 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3853 d_append_string (dpi
, "&&");
3855 case DEMANGLE_COMPONENT_COMPLEX
:
3856 d_append_string (dpi
, "complex ");
3858 case DEMANGLE_COMPONENT_IMAGINARY
:
3859 d_append_string (dpi
, "imaginary ");
3861 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3862 if (d_last_char (dpi
) != '(')
3863 d_append_char (dpi
, ' ');
3864 d_print_comp (dpi
, d_left (mod
));
3865 d_append_string (dpi
, "::*");
3867 case DEMANGLE_COMPONENT_TYPED_NAME
:
3868 d_print_comp (dpi
, d_left (mod
));
3871 /* Otherwise, we have something that won't go back on the
3872 modifier stack, so we can just print it. */
3873 d_print_comp (dpi
, mod
);
3878 /* Print a function type, except for the return type. */
3881 d_print_function_type (struct d_print_info
*dpi
,
3882 const struct demangle_component
*dc
,
3883 struct d_print_mod
*mods
)
3888 struct d_print_mod
*p
;
3889 struct d_print_mod
*hold_modifiers
;
3894 for (p
= mods
; p
!= NULL
; p
= p
->next
)
3900 switch (p
->mod
->type
)
3902 case DEMANGLE_COMPONENT_POINTER
:
3903 case DEMANGLE_COMPONENT_REFERENCE
:
3904 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3907 case DEMANGLE_COMPONENT_RESTRICT
:
3908 case DEMANGLE_COMPONENT_VOLATILE
:
3909 case DEMANGLE_COMPONENT_CONST
:
3910 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3911 case DEMANGLE_COMPONENT_COMPLEX
:
3912 case DEMANGLE_COMPONENT_IMAGINARY
:
3913 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3917 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3918 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3919 case DEMANGLE_COMPONENT_CONST_THIS
:
3928 if (d_left (dc
) != NULL
&& ! saw_mod
)
3935 if (d_last_char (dpi
) != '('
3936 && d_last_char (dpi
) != '*')
3939 if (need_space
&& d_last_char (dpi
) != ' ')
3940 d_append_char (dpi
, ' ');
3941 d_append_char (dpi
, '(');
3944 hold_modifiers
= dpi
->modifiers
;
3945 dpi
->modifiers
= NULL
;
3947 d_print_mod_list (dpi
, mods
, 0);
3950 d_append_char (dpi
, ')');
3952 d_append_char (dpi
, '(');
3954 if (d_right (dc
) != NULL
)
3955 d_print_comp (dpi
, d_right (dc
));
3957 d_append_char (dpi
, ')');
3959 d_print_mod_list (dpi
, mods
, 1);
3961 dpi
->modifiers
= hold_modifiers
;
3964 /* Print an array type, except for the element type. */
3967 d_print_array_type (struct d_print_info
*dpi
,
3968 const struct demangle_component
*dc
,
3969 struct d_print_mod
*mods
)
3977 struct d_print_mod
*p
;
3980 for (p
= mods
; p
!= NULL
; p
= p
->next
)
3984 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
3999 d_append_string (dpi
, " (");
4001 d_print_mod_list (dpi
, mods
, 0);
4004 d_append_char (dpi
, ')');
4008 d_append_char (dpi
, ' ');
4010 d_append_char (dpi
, '[');
4012 if (d_left (dc
) != NULL
)
4013 d_print_comp (dpi
, d_left (dc
));
4015 d_append_char (dpi
, ']');
4018 /* Print an operator in an expression. */
4021 d_print_expr_op (struct d_print_info
*dpi
,
4022 const struct demangle_component
*dc
)
4024 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4025 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4026 dc
->u
.s_operator
.op
->len
);
4028 d_print_comp (dpi
, dc
);
4034 d_print_cast (struct d_print_info
*dpi
,
4035 const struct demangle_component
*dc
)
4037 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4038 d_print_comp (dpi
, d_left (dc
));
4041 struct d_print_mod
*hold_dpm
;
4042 struct d_print_template dpt
;
4044 /* It appears that for a templated cast operator, we need to put
4045 the template parameters in scope for the operator name, but
4046 not for the parameters. The effect is that we need to handle
4047 the template printing here. */
4049 hold_dpm
= dpi
->modifiers
;
4050 dpi
->modifiers
= NULL
;
4052 dpt
.next
= dpi
->templates
;
4053 dpi
->templates
= &dpt
;
4054 dpt
.template_decl
= d_left (dc
);
4056 d_print_comp (dpi
, d_left (d_left (dc
)));
4058 dpi
->templates
= dpt
.next
;
4060 if (d_last_char (dpi
) == '<')
4061 d_append_char (dpi
, ' ');
4062 d_append_char (dpi
, '<');
4063 d_print_comp (dpi
, d_right (d_left (dc
)));
4064 /* Avoid generating two consecutive '>' characters, to avoid
4065 the C++ syntactic ambiguity. */
4066 if (d_last_char (dpi
) == '>')
4067 d_append_char (dpi
, ' ');
4068 d_append_char (dpi
, '>');
4070 dpi
->modifiers
= hold_dpm
;
4074 /* Initialize the information structure we use to pass around
4077 CP_STATIC_IF_GLIBCPP_V3
4079 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4083 di
->send
= mangled
+ len
;
4084 di
->options
= options
;
4088 /* We can not need more components than twice the number of chars in
4089 the mangled string. Most components correspond directly to
4090 chars, but the ARGLIST types are exceptions. */
4091 di
->num_comps
= 2 * len
;
4094 /* Similarly, we can not need more substitutions than there are
4095 chars in the mangled string. */
4100 di
->last_name
= NULL
;
4105 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4106 mangled name, return strings in repeated callback giving the demangled
4107 name. OPTIONS is the usual libiberty demangler options. On success,
4108 this returns 1. On failure, returns 0. */
4111 d_demangle_callback (const char *mangled
, int options
,
4112 demangle_callbackref callback
, void *opaque
)
4116 struct demangle_component
*dc
;
4119 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4121 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
4122 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
4123 && (mangled
[9] == 'D' || mangled
[9] == 'I')
4124 && mangled
[10] == '_')
4128 intro
= (mangled
[9] == 'I')
4129 ? "global constructors keyed to "
4130 : "global destructors keyed to ";
4132 callback (intro
, strlen (intro
), opaque
);
4133 callback (mangled
+ 11, strlen (mangled
+ 11), opaque
);
4138 if ((options
& DMGL_TYPES
) == 0)
4143 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
4146 #ifdef CP_DYNAMIC_ARRAYS
4147 __extension__
struct demangle_component comps
[di
.num_comps
];
4148 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4153 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4154 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4158 dc
= cplus_demangle_type (&di
);
4160 dc
= cplus_demangle_mangled_name (&di
, 1);
4162 /* If DMGL_PARAMS is set, then if we didn't consume the entire
4163 mangled string, then we didn't successfully demangle it. If
4164 DMGL_PARAMS is not set, we didn't look at the trailing
4166 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
4169 #ifdef CP_DEMANGLE_DEBUG
4173 status
= (dc
!= NULL
)
4174 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
4181 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4182 name, return a buffer allocated with malloc holding the demangled
4183 name. OPTIONS is the usual libiberty demangler options. On
4184 success, this sets *PALC to the allocated size of the returned
4185 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4186 a memory allocation failure, and returns NULL. */
4189 d_demangle (const char *mangled
, int options
, size_t *palc
)
4191 struct d_growable_string dgs
;
4194 d_growable_string_init (&dgs
, 0);
4196 status
= d_demangle_callback (mangled
, options
,
4197 d_growable_string_callback_adapter
, &dgs
);
4205 *palc
= dgs
.allocation_failure
? 1 : 0;
4209 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4211 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
4213 /* ia64 ABI-mandated entry point in the C++ runtime library for
4214 performing demangling. MANGLED_NAME is a NUL-terminated character
4215 string containing the name to be demangled.
4217 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
4218 *LENGTH bytes, into which the demangled name is stored. If
4219 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
4220 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
4221 is placed in a region of memory allocated with malloc.
4223 If LENGTH is non-NULL, the length of the buffer containing the
4224 demangled name, is placed in *LENGTH.
4226 The return value is a pointer to the start of the NUL-terminated
4227 demangled name, or NULL if the demangling fails. The caller is
4228 responsible for deallocating this memory using free.
4230 *STATUS is set to one of the following values:
4231 0: The demangling operation succeeded.
4232 -1: A memory allocation failure occurred.
4233 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4234 -3: One of the arguments is invalid.
4236 The demangling is performed using the C++ ABI mangling rules, with
4240 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
4241 size_t *length
, int *status
)
4246 if (mangled_name
== NULL
)
4253 if (output_buffer
!= NULL
&& length
== NULL
)
4260 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
4262 if (demangled
== NULL
)
4274 if (output_buffer
== NULL
)
4281 if (strlen (demangled
) < *length
)
4283 strcpy (output_buffer
, demangled
);
4285 demangled
= output_buffer
;
4289 free (output_buffer
);
4300 extern int __gcclibcxx_demangle_callback (const char *,
4302 (const char *, size_t, void *),
4305 /* Alternative, allocationless entry point in the C++ runtime library
4306 for performing demangling. MANGLED_NAME is a NUL-terminated character
4307 string containing the name to be demangled.
4309 CALLBACK is a callback function, called with demangled string
4310 segments as demangling progresses; it is called at least once,
4311 but may be called more than once. OPAQUE is a generalized pointer
4312 used as a callback argument.
4314 The return code is one of the following values, equivalent to
4315 the STATUS values of __cxa_demangle() (excluding -1, since this
4316 function performs no memory allocations):
4317 0: The demangling operation succeeded.
4318 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4319 -3: One of the arguments is invalid.
4321 The demangling is performed using the C++ ABI mangling rules, with
4325 __gcclibcxx_demangle_callback (const char *mangled_name
,
4326 void (*callback
) (const char *, size_t, void *),
4331 if (mangled_name
== NULL
|| callback
== NULL
)
4334 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
4342 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
4344 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
4345 mangled name, return a buffer allocated with malloc holding the
4346 demangled name. Otherwise, return NULL. */
4349 cplus_demangle_v3 (const char *mangled
, int options
)
4353 return d_demangle (mangled
, options
, &alc
);
4357 cplus_demangle_v3_callback (const char *mangled
, int options
,
4358 demangle_callbackref callback
, void *opaque
)
4360 return d_demangle_callback (mangled
, options
, callback
, opaque
);
4363 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
4364 conventions, but the output formatting is a little different.
4365 This instructs the C++ demangler not to emit pointer characters ("*"), to
4366 use Java's namespace separator symbol ("." instead of "::"), and to output
4367 JArray<TYPE> as TYPE[]. */
4370 java_demangle_v3 (const char *mangled
)
4374 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
4378 java_demangle_v3_callback (const char *mangled
,
4379 demangle_callbackref callback
, void *opaque
)
4381 return d_demangle_callback (mangled
,
4382 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
4386 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
4388 #ifndef IN_GLIBCPP_V3
4390 /* Demangle a string in order to find out whether it is a constructor
4391 or destructor. Return non-zero on success. Set *CTOR_KIND and
4392 *DTOR_KIND appropriately. */
4395 is_ctor_or_dtor (const char *mangled
,
4396 enum gnu_v3_ctor_kinds
*ctor_kind
,
4397 enum gnu_v3_dtor_kinds
*dtor_kind
)
4400 struct demangle_component
*dc
;
4403 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
4404 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
4406 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
4409 #ifdef CP_DYNAMIC_ARRAYS
4410 __extension__
struct demangle_component comps
[di
.num_comps
];
4411 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4416 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4417 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4420 dc
= cplus_demangle_mangled_name (&di
, 1);
4422 /* Note that because we did not pass DMGL_PARAMS, we don't expect
4423 to demangle the entire string. */
4433 case DEMANGLE_COMPONENT_TYPED_NAME
:
4434 case DEMANGLE_COMPONENT_TEMPLATE
:
4435 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4436 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4437 case DEMANGLE_COMPONENT_CONST_THIS
:
4440 case DEMANGLE_COMPONENT_QUAL_NAME
:
4441 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4444 case DEMANGLE_COMPONENT_CTOR
:
4445 *ctor_kind
= dc
->u
.s_ctor
.kind
;
4449 case DEMANGLE_COMPONENT_DTOR
:
4450 *dtor_kind
= dc
->u
.s_dtor
.kind
;
4461 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
4462 name. A non-zero return indicates the type of constructor. */
4464 enum gnu_v3_ctor_kinds
4465 is_gnu_v3_mangled_ctor (const char *name
)
4467 enum gnu_v3_ctor_kinds ctor_kind
;
4468 enum gnu_v3_dtor_kinds dtor_kind
;
4470 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
4471 return (enum gnu_v3_ctor_kinds
) 0;
4476 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
4477 name. A non-zero return indicates the type of destructor. */
4479 enum gnu_v3_dtor_kinds
4480 is_gnu_v3_mangled_dtor (const char *name
)
4482 enum gnu_v3_ctor_kinds ctor_kind
;
4483 enum gnu_v3_dtor_kinds dtor_kind
;
4485 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
4486 return (enum gnu_v3_dtor_kinds
) 0;
4490 #endif /* IN_GLIBCPP_V3 */
4492 #ifdef STANDALONE_DEMANGLER
4495 #include "dyn-string.h"
4497 static void print_usage (FILE* fp
, int exit_value
);
4499 #define IS_ALPHA(CHAR) \
4500 (((CHAR) >= 'a' && (CHAR) <= 'z') \
4501 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
4503 /* Non-zero if CHAR is a character than can occur in a mangled name. */
4504 #define is_mangled_char(CHAR) \
4505 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
4506 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
4508 /* The name of this program, as invoked. */
4509 const char* program_name
;
4511 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
4514 print_usage (FILE* fp
, int exit_value
)
4516 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
4517 fprintf (fp
, "Options:\n");
4518 fprintf (fp
, " -h,--help Display this message.\n");
4519 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
4520 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
4521 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
4526 /* Option specification for getopt_long. */
4527 static const struct option long_options
[] =
4529 { "help", no_argument
, NULL
, 'h' },
4530 { "no-params", no_argument
, NULL
, 'p' },
4531 { "verbose", no_argument
, NULL
, 'v' },
4532 { NULL
, no_argument
, NULL
, 0 },
4535 /* Main entry for a demangling filter executable. It will demangle
4536 its command line arguments, if any. If none are provided, it will
4537 filter stdin to stdout, replacing any recognized mangled C++ names
4538 with their demangled equivalents. */
4541 main (int argc
, char *argv
[])
4545 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
4547 /* Use the program name of this program, as invoked. */
4548 program_name
= argv
[0];
4550 /* Parse options. */
4553 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
4556 case '?': /* Unrecognized option. */
4557 print_usage (stderr
, 1);
4561 print_usage (stdout
, 0);
4565 options
&= ~ DMGL_PARAMS
;
4569 options
|= DMGL_VERBOSE
;
4573 while (opt_char
!= -1);
4576 /* No command line arguments were provided. Filter stdin. */
4578 dyn_string_t mangled
= dyn_string_new (3);
4581 /* Read all of input. */
4582 while (!feof (stdin
))
4586 /* Pile characters into mangled until we hit one that can't
4587 occur in a mangled name. */
4589 while (!feof (stdin
) && is_mangled_char (c
))
4591 dyn_string_append_char (mangled
, c
);
4597 if (dyn_string_length (mangled
) > 0)
4599 #ifdef IN_GLIBCPP_V3
4600 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
4602 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
4612 /* It might not have been a mangled name. Print the
4614 fputs (dyn_string_buf (mangled
), stdout
);
4617 dyn_string_clear (mangled
);
4620 /* If we haven't hit EOF yet, we've read one character that
4621 can't occur in a mangled name, so print it out. */
4626 dyn_string_delete (mangled
);
4629 /* Demangle command line arguments. */
4631 /* Loop over command line arguments. */
4632 for (i
= optind
; i
< argc
; ++i
)
4635 #ifdef IN_GLIBCPP_V3
4639 /* Attempt to demangle. */
4640 #ifdef IN_GLIBCPP_V3
4641 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
4643 s
= cplus_demangle_v3 (argv
[i
], options
);
4646 /* If it worked, print the demangled name. */
4654 #ifdef IN_GLIBCPP_V3
4655 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
4657 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
4666 #endif /* STANDALONE_DEMANGLER */