1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@wasabisystems.com>.
6 This file is part of the libiberty library, which is part of GCC.
8 This file is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combined
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 /* This code implements a demangler for the g++ V3 ABI. The ABI is
33 described on this web page:
34 http://www.codesourcery.com/cxx-abi/abi.html#mangling
36 This code was written while looking at the demangler written by
37 Alex Samuel <samuel@codesourcery.com>.
39 This code first pulls the mangled name apart into a list of
40 components, and then walks the list generating the demangled
43 This file will normally define the following functions, q.v.:
44 char *cplus_demangle_v3(const char *mangled, int options)
45 char *java_demangle_v3(const char *mangled)
46 int cplus_demangle_v3_callback(const char *mangled, int options,
47 demangle_callbackref callback)
48 int java_demangle_v3_callback(const char *mangled,
49 demangle_callbackref callback)
50 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
51 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
53 Also, the interface to the component list is public, and defined in
54 demangle.h. The interface consists of these types, which are
55 defined in demangle.h:
56 enum demangle_component_type
57 struct demangle_component
59 and these functions defined in this file:
60 cplus_demangle_fill_name
61 cplus_demangle_fill_extended_operator
62 cplus_demangle_fill_ctor
63 cplus_demangle_fill_dtor
65 cplus_demangle_print_callback
66 and other functions defined in the file cp-demint.c.
68 This file also defines some other functions and variables which are
69 only to be used by the file cp-demint.c.
71 Preprocessor macros you can define while compiling this file:
74 If defined, this file defines the following functions, q.v.:
75 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
77 int __gcclibcxx_demangle_callback (const char *,
79 (const char *, size_t, void *),
81 instead of cplus_demangle_v3[_callback]() and
82 java_demangle_v3[_callback]().
85 If defined, this file defines only __cxa_demangle() and
86 __gcclibcxx_demangle_callback(), and no other publically visible
87 functions or variables.
90 If defined, this file defines a main() function which demangles
91 any arguments, or, if none, demangles stdin.
94 If defined, turns on debugging mode, which prints information on
95 stdout about the mangled string. This is not generally useful.
98 #if defined (_AIX) && !defined (__GNUC__)
120 # define alloca __builtin_alloca
122 extern char *alloca ();
123 # endif /* __GNUC__ */
125 #endif /* HAVE_ALLOCA_H */
127 #include "ansidecl.h"
128 #include "libiberty.h"
129 #include "demangle.h"
130 #include "cp-demangle.h"
132 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
133 also rename them via #define to avoid compiler errors when the
134 static definition conflicts with the extern declaration in a header
138 #define CP_STATIC_IF_GLIBCPP_V3 static
140 #define cplus_demangle_fill_name d_fill_name
141 static int d_fill_name (struct demangle_component
*, const char *, int);
143 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
145 d_fill_extended_operator (struct demangle_component
*, int,
146 struct demangle_component
*);
148 #define cplus_demangle_fill_ctor d_fill_ctor
150 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
151 struct demangle_component
*);
153 #define cplus_demangle_fill_dtor d_fill_dtor
155 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
156 struct demangle_component
*);
158 #define cplus_demangle_mangled_name d_mangled_name
159 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
161 #define cplus_demangle_type d_type
162 static struct demangle_component
*d_type (struct d_info
*);
164 #define cplus_demangle_print d_print
165 static char *d_print (int, const struct demangle_component
*, int, size_t *);
167 #define cplus_demangle_print_callback d_print_callback
168 static int d_print_callback (int, const struct demangle_component
*,
169 demangle_callbackref
, void *);
171 #define cplus_demangle_init_info d_init_info
172 static void d_init_info (const char *, int, size_t, struct d_info
*);
174 #else /* ! defined(IN_GLIBCPP_V3) */
175 #define CP_STATIC_IF_GLIBCPP_V3
176 #endif /* ! defined(IN_GLIBCPP_V3) */
178 /* See if the compiler supports dynamic arrays. */
181 #define CP_DYNAMIC_ARRAYS
184 #ifdef __STDC_VERSION__
185 #if __STDC_VERSION__ >= 199901L
186 #define CP_DYNAMIC_ARRAYS
187 #endif /* __STDC__VERSION >= 199901L */
188 #endif /* defined (__STDC_VERSION__) */
189 #endif /* defined (__STDC__) */
190 #endif /* ! defined (__GNUC__) */
192 /* We avoid pulling in the ctype tables, to prevent pulling in
193 additional unresolved symbols when this code is used in a library.
194 FIXME: Is this really a valid reason? This comes from the original
197 As of this writing this file has the following undefined references
198 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
201 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
202 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
203 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
205 /* The prefix prepended by GCC to an identifier represnting the
206 anonymous namespace. */
207 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
208 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
209 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
211 /* Information we keep for the standard substitutions. */
213 struct d_standard_sub_info
215 /* The code for this substitution. */
217 /* The simple string it expands to. */
218 const char *simple_expansion
;
219 /* The length of the simple expansion. */
221 /* The results of a full, verbose, expansion. This is used when
222 qualifying a constructor/destructor, or when in verbose mode. */
223 const char *full_expansion
;
224 /* The length of the full expansion. */
226 /* What to set the last_name field of d_info to; NULL if we should
227 not set it. This is only relevant when qualifying a
228 constructor/destructor. */
229 const char *set_last_name
;
230 /* The length of set_last_name. */
231 int set_last_name_len
;
234 /* Accessors for subtrees of struct demangle_component. */
236 #define d_left(dc) ((dc)->u.s_binary.left)
237 #define d_right(dc) ((dc)->u.s_binary.right)
239 /* A list of templates. This is used while printing. */
241 struct d_print_template
243 /* Next template on the list. */
244 struct d_print_template
*next
;
246 const struct demangle_component
*template_decl
;
249 /* A list of type modifiers. This is used while printing. */
253 /* Next modifier on the list. These are in the reverse of the order
254 in which they appeared in the mangled string. */
255 struct d_print_mod
*next
;
257 const struct demangle_component
*mod
;
258 /* Whether this modifier was printed. */
260 /* The list of templates which applies to this modifier. */
261 struct d_print_template
*templates
;
264 /* We use these structures to hold information during printing. */
266 struct d_growable_string
268 /* Buffer holding the result. */
270 /* Current length of data in buffer. */
272 /* Allocated size of buffer. */
274 /* Set to 1 if we had a memory allocation failure. */
275 int allocation_failure
;
278 enum { D_PRINT_BUFFER_LENGTH
= 256 };
281 /* The options passed to the demangler. */
283 /* Fixed-length allocated buffer for demangled data, flushed to the
284 callback with a NUL termination once full. */
285 char buf
[D_PRINT_BUFFER_LENGTH
];
286 /* Current length of data in buffer. */
288 /* The last character printed, saved individually so that it survives
291 /* Callback function to handle demangled buffer flush. */
292 demangle_callbackref callback
;
293 /* Opaque callback argument. */
295 /* The current list of templates, if any. */
296 struct d_print_template
*templates
;
297 /* The current list of modifiers (e.g., pointer, reference, etc.),
299 struct d_print_mod
*modifiers
;
300 /* Set to 1 if we saw a demangling error. */
301 int demangle_failure
;
302 /* The current index into any template argument packs we are using
305 /* Number of d_print_flush calls so far. */
306 unsigned long int flush_count
;
309 #ifdef CP_DEMANGLE_DEBUG
310 static void d_dump (struct demangle_component
*, int);
313 static struct demangle_component
*
314 d_make_empty (struct d_info
*);
316 static struct demangle_component
*
317 d_make_comp (struct d_info
*, enum demangle_component_type
,
318 struct demangle_component
*,
319 struct demangle_component
*);
321 static struct demangle_component
*
322 d_make_name (struct d_info
*, const char *, int);
324 static struct demangle_component
*
325 d_make_demangle_mangled_name (struct d_info
*, const char *);
327 static struct demangle_component
*
328 d_make_builtin_type (struct d_info
*,
329 const struct demangle_builtin_type_info
*);
331 static struct demangle_component
*
332 d_make_operator (struct d_info
*,
333 const struct demangle_operator_info
*);
335 static struct demangle_component
*
336 d_make_extended_operator (struct d_info
*, int,
337 struct demangle_component
*);
339 static struct demangle_component
*
340 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
341 struct demangle_component
*);
343 static struct demangle_component
*
344 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
345 struct demangle_component
*);
347 static struct demangle_component
*
348 d_make_template_param (struct d_info
*, long);
350 static struct demangle_component
*
351 d_make_sub (struct d_info
*, const char *, int);
354 has_return_type (struct demangle_component
*);
357 is_ctor_dtor_or_conversion (struct demangle_component
*);
359 static struct demangle_component
*d_encoding (struct d_info
*, int);
361 static struct demangle_component
*d_name (struct d_info
*);
363 static struct demangle_component
*d_nested_name (struct d_info
*);
365 static struct demangle_component
*d_prefix (struct d_info
*);
367 static struct demangle_component
*d_unqualified_name (struct d_info
*);
369 static struct demangle_component
*d_source_name (struct d_info
*);
371 static long d_number (struct d_info
*);
373 static struct demangle_component
*d_identifier (struct d_info
*, int);
375 static struct demangle_component
*d_operator_name (struct d_info
*);
377 static struct demangle_component
*d_special_name (struct d_info
*);
379 static int d_call_offset (struct d_info
*, int);
381 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
383 static struct demangle_component
**
384 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
386 static struct demangle_component
*
387 d_function_type (struct d_info
*);
389 static struct demangle_component
*
390 d_bare_function_type (struct d_info
*, int);
392 static struct demangle_component
*
393 d_class_enum_type (struct d_info
*);
395 static struct demangle_component
*d_array_type (struct d_info
*);
397 static struct demangle_component
*d_vector_type (struct d_info
*);
399 static struct demangle_component
*
400 d_pointer_to_member_type (struct d_info
*);
402 static struct demangle_component
*
403 d_template_param (struct d_info
*);
405 static struct demangle_component
*d_template_args (struct d_info
*);
407 static struct demangle_component
*
408 d_template_arg (struct d_info
*);
410 static struct demangle_component
*d_expression (struct d_info
*);
412 static struct demangle_component
*d_expr_primary (struct d_info
*);
414 static struct demangle_component
*d_local_name (struct d_info
*);
416 static int d_discriminator (struct d_info
*);
418 static struct demangle_component
*d_lambda (struct d_info
*);
420 static struct demangle_component
*d_unnamed_type (struct d_info
*);
422 static struct demangle_component
*
423 d_clone_suffix (struct d_info
*, struct demangle_component
*);
426 d_add_substitution (struct d_info
*, struct demangle_component
*);
428 static struct demangle_component
*d_substitution (struct d_info
*, int);
430 static void d_growable_string_init (struct d_growable_string
*, size_t);
433 d_growable_string_resize (struct d_growable_string
*, size_t);
436 d_growable_string_append_buffer (struct d_growable_string
*,
437 const char *, size_t);
439 d_growable_string_callback_adapter (const char *, size_t, void *);
442 d_print_init (struct d_print_info
*, int, demangle_callbackref
, void *);
444 static inline void d_print_error (struct d_print_info
*);
446 static inline int d_print_saw_error (struct d_print_info
*);
448 static inline void d_print_flush (struct d_print_info
*);
450 static inline void d_append_char (struct d_print_info
*, char);
452 static inline void d_append_buffer (struct d_print_info
*,
453 const char *, size_t);
455 static inline void d_append_string (struct d_print_info
*, const char *);
457 static inline char d_last_char (struct d_print_info
*);
460 d_print_comp (struct d_print_info
*, const struct demangle_component
*);
463 d_print_java_identifier (struct d_print_info
*, const char *, int);
466 d_print_mod_list (struct d_print_info
*, struct d_print_mod
*, int);
469 d_print_mod (struct d_print_info
*, const struct demangle_component
*);
472 d_print_function_type (struct d_print_info
*,
473 const struct demangle_component
*,
474 struct d_print_mod
*);
477 d_print_array_type (struct d_print_info
*,
478 const struct demangle_component
*,
479 struct d_print_mod
*);
482 d_print_expr_op (struct d_print_info
*, const struct demangle_component
*);
485 d_print_cast (struct d_print_info
*, const struct demangle_component
*);
487 static int d_demangle_callback (const char *, int,
488 demangle_callbackref
, void *);
489 static char *d_demangle (const char *, int, size_t *);
491 #ifdef CP_DEMANGLE_DEBUG
494 d_dump (struct demangle_component
*dc
, int indent
)
501 printf ("failed demangling\n");
505 for (i
= 0; i
< indent
; ++i
)
510 case DEMANGLE_COMPONENT_NAME
:
511 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
513 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
514 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
516 case DEMANGLE_COMPONENT_CTOR
:
517 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
518 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
520 case DEMANGLE_COMPONENT_DTOR
:
521 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
522 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
524 case DEMANGLE_COMPONENT_SUB_STD
:
525 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
527 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
528 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
530 case DEMANGLE_COMPONENT_OPERATOR
:
531 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
533 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
534 printf ("extended operator with %d args\n",
535 dc
->u
.s_extended_operator
.args
);
536 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
539 case DEMANGLE_COMPONENT_QUAL_NAME
:
540 printf ("qualified name\n");
542 case DEMANGLE_COMPONENT_LOCAL_NAME
:
543 printf ("local name\n");
545 case DEMANGLE_COMPONENT_TYPED_NAME
:
546 printf ("typed name\n");
548 case DEMANGLE_COMPONENT_TEMPLATE
:
549 printf ("template\n");
551 case DEMANGLE_COMPONENT_VTABLE
:
554 case DEMANGLE_COMPONENT_VTT
:
557 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
558 printf ("construction vtable\n");
560 case DEMANGLE_COMPONENT_TYPEINFO
:
561 printf ("typeinfo\n");
563 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
564 printf ("typeinfo name\n");
566 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
567 printf ("typeinfo function\n");
569 case DEMANGLE_COMPONENT_THUNK
:
572 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
573 printf ("virtual thunk\n");
575 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
576 printf ("covariant thunk\n");
578 case DEMANGLE_COMPONENT_JAVA_CLASS
:
579 printf ("java class\n");
581 case DEMANGLE_COMPONENT_GUARD
:
584 case DEMANGLE_COMPONENT_REFTEMP
:
585 printf ("reference temporary\n");
587 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
588 printf ("hidden alias\n");
590 case DEMANGLE_COMPONENT_RESTRICT
:
591 printf ("restrict\n");
593 case DEMANGLE_COMPONENT_VOLATILE
:
594 printf ("volatile\n");
596 case DEMANGLE_COMPONENT_CONST
:
599 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
600 printf ("restrict this\n");
602 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
603 printf ("volatile this\n");
605 case DEMANGLE_COMPONENT_CONST_THIS
:
606 printf ("const this\n");
608 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
609 printf ("vendor type qualifier\n");
611 case DEMANGLE_COMPONENT_POINTER
:
612 printf ("pointer\n");
614 case DEMANGLE_COMPONENT_REFERENCE
:
615 printf ("reference\n");
617 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
618 printf ("rvalue reference\n");
620 case DEMANGLE_COMPONENT_COMPLEX
:
621 printf ("complex\n");
623 case DEMANGLE_COMPONENT_IMAGINARY
:
624 printf ("imaginary\n");
626 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
627 printf ("vendor type\n");
629 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
630 printf ("function type\n");
632 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
633 printf ("array type\n");
635 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
636 printf ("pointer to member type\n");
638 case DEMANGLE_COMPONENT_FIXED_TYPE
:
639 printf ("fixed-point type\n");
641 case DEMANGLE_COMPONENT_ARGLIST
:
642 printf ("argument list\n");
644 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
645 printf ("template argument list\n");
647 case DEMANGLE_COMPONENT_CAST
:
650 case DEMANGLE_COMPONENT_UNARY
:
651 printf ("unary operator\n");
653 case DEMANGLE_COMPONENT_BINARY
:
654 printf ("binary operator\n");
656 case DEMANGLE_COMPONENT_BINARY_ARGS
:
657 printf ("binary operator arguments\n");
659 case DEMANGLE_COMPONENT_TRINARY
:
660 printf ("trinary operator\n");
662 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
663 printf ("trinary operator arguments 1\n");
665 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
666 printf ("trinary operator arguments 1\n");
668 case DEMANGLE_COMPONENT_LITERAL
:
669 printf ("literal\n");
671 case DEMANGLE_COMPONENT_LITERAL_NEG
:
672 printf ("negative literal\n");
674 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
675 printf ("java resource\n");
677 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
678 printf ("compound name\n");
680 case DEMANGLE_COMPONENT_CHARACTER
:
681 printf ("character '%c'\n", dc
->u
.s_character
.character
);
683 case DEMANGLE_COMPONENT_DECLTYPE
:
684 printf ("decltype\n");
686 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
687 printf ("pack expansion\n");
691 d_dump (d_left (dc
), indent
+ 2);
692 d_dump (d_right (dc
), indent
+ 2);
695 #endif /* CP_DEMANGLE_DEBUG */
697 /* Fill in a DEMANGLE_COMPONENT_NAME. */
699 CP_STATIC_IF_GLIBCPP_V3
701 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
703 if (p
== NULL
|| s
== NULL
|| len
== 0)
705 p
->type
= DEMANGLE_COMPONENT_NAME
;
707 p
->u
.s_name
.len
= len
;
711 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
713 CP_STATIC_IF_GLIBCPP_V3
715 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
716 struct demangle_component
*name
)
718 if (p
== NULL
|| args
< 0 || name
== NULL
)
720 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
721 p
->u
.s_extended_operator
.args
= args
;
722 p
->u
.s_extended_operator
.name
= name
;
726 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
728 CP_STATIC_IF_GLIBCPP_V3
730 cplus_demangle_fill_ctor (struct demangle_component
*p
,
731 enum gnu_v3_ctor_kinds kind
,
732 struct demangle_component
*name
)
736 || (int) kind
< gnu_v3_complete_object_ctor
737 || (int) kind
> gnu_v3_complete_object_allocating_ctor
)
739 p
->type
= DEMANGLE_COMPONENT_CTOR
;
740 p
->u
.s_ctor
.kind
= kind
;
741 p
->u
.s_ctor
.name
= name
;
745 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
747 CP_STATIC_IF_GLIBCPP_V3
749 cplus_demangle_fill_dtor (struct demangle_component
*p
,
750 enum gnu_v3_dtor_kinds kind
,
751 struct demangle_component
*name
)
755 || (int) kind
< gnu_v3_deleting_dtor
756 || (int) kind
> gnu_v3_base_object_dtor
)
758 p
->type
= DEMANGLE_COMPONENT_DTOR
;
759 p
->u
.s_dtor
.kind
= kind
;
760 p
->u
.s_dtor
.name
= name
;
764 /* Add a new component. */
766 static struct demangle_component
*
767 d_make_empty (struct d_info
*di
)
769 struct demangle_component
*p
;
771 if (di
->next_comp
>= di
->num_comps
)
773 p
= &di
->comps
[di
->next_comp
];
778 /* Add a new generic component. */
780 static struct demangle_component
*
781 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
782 struct demangle_component
*left
,
783 struct demangle_component
*right
)
785 struct demangle_component
*p
;
787 /* We check for errors here. A typical error would be a NULL return
788 from a subroutine. We catch those here, and return NULL
792 /* These types require two parameters. */
793 case DEMANGLE_COMPONENT_QUAL_NAME
:
794 case DEMANGLE_COMPONENT_LOCAL_NAME
:
795 case DEMANGLE_COMPONENT_TYPED_NAME
:
796 case DEMANGLE_COMPONENT_TEMPLATE
:
797 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
798 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
799 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
800 case DEMANGLE_COMPONENT_UNARY
:
801 case DEMANGLE_COMPONENT_BINARY
:
802 case DEMANGLE_COMPONENT_BINARY_ARGS
:
803 case DEMANGLE_COMPONENT_TRINARY
:
804 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
805 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
806 case DEMANGLE_COMPONENT_LITERAL
:
807 case DEMANGLE_COMPONENT_LITERAL_NEG
:
808 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
809 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
810 case DEMANGLE_COMPONENT_CLONE
:
811 if (left
== NULL
|| right
== NULL
)
815 /* These types only require one parameter. */
816 case DEMANGLE_COMPONENT_VTABLE
:
817 case DEMANGLE_COMPONENT_VTT
:
818 case DEMANGLE_COMPONENT_TYPEINFO
:
819 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
820 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
821 case DEMANGLE_COMPONENT_THUNK
:
822 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
823 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
824 case DEMANGLE_COMPONENT_JAVA_CLASS
:
825 case DEMANGLE_COMPONENT_GUARD
:
826 case DEMANGLE_COMPONENT_REFTEMP
:
827 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
828 case DEMANGLE_COMPONENT_POINTER
:
829 case DEMANGLE_COMPONENT_REFERENCE
:
830 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
831 case DEMANGLE_COMPONENT_COMPLEX
:
832 case DEMANGLE_COMPONENT_IMAGINARY
:
833 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
834 case DEMANGLE_COMPONENT_CAST
:
835 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
836 case DEMANGLE_COMPONENT_DECLTYPE
:
837 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
838 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
839 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
844 /* This needs a right parameter, but the left parameter can be
846 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
851 /* These are allowed to have no parameters--in some cases they
852 will be filled in later. */
853 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
854 case DEMANGLE_COMPONENT_RESTRICT
:
855 case DEMANGLE_COMPONENT_VOLATILE
:
856 case DEMANGLE_COMPONENT_CONST
:
857 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
858 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
859 case DEMANGLE_COMPONENT_CONST_THIS
:
860 case DEMANGLE_COMPONENT_ARGLIST
:
861 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
864 /* Other types should not be seen here. */
869 p
= d_make_empty (di
);
873 p
->u
.s_binary
.left
= left
;
874 p
->u
.s_binary
.right
= right
;
879 /* Add a new demangle mangled name component. */
881 static struct demangle_component
*
882 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
884 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
885 return d_make_name (di
, s
, strlen (s
));
887 return d_encoding (di
, 0);
890 /* Add a new name component. */
892 static struct demangle_component
*
893 d_make_name (struct d_info
*di
, const char *s
, int len
)
895 struct demangle_component
*p
;
897 p
= d_make_empty (di
);
898 if (! cplus_demangle_fill_name (p
, s
, len
))
903 /* Add a new builtin type component. */
905 static struct demangle_component
*
906 d_make_builtin_type (struct d_info
*di
,
907 const struct demangle_builtin_type_info
*type
)
909 struct demangle_component
*p
;
913 p
= d_make_empty (di
);
916 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
917 p
->u
.s_builtin
.type
= type
;
922 /* Add a new operator component. */
924 static struct demangle_component
*
925 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
927 struct demangle_component
*p
;
929 p
= d_make_empty (di
);
932 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
933 p
->u
.s_operator
.op
= op
;
938 /* Add a new extended operator component. */
940 static struct demangle_component
*
941 d_make_extended_operator (struct d_info
*di
, int args
,
942 struct demangle_component
*name
)
944 struct demangle_component
*p
;
946 p
= d_make_empty (di
);
947 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
952 static struct demangle_component
*
953 d_make_default_arg (struct d_info
*di
, int num
,
954 struct demangle_component
*sub
)
956 struct demangle_component
*p
= d_make_empty (di
);
959 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
960 p
->u
.s_unary_num
.num
= num
;
961 p
->u
.s_unary_num
.sub
= sub
;
966 /* Add a new constructor component. */
968 static struct demangle_component
*
969 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
970 struct demangle_component
*name
)
972 struct demangle_component
*p
;
974 p
= d_make_empty (di
);
975 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
980 /* Add a new destructor component. */
982 static struct demangle_component
*
983 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
984 struct demangle_component
*name
)
986 struct demangle_component
*p
;
988 p
= d_make_empty (di
);
989 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
994 /* Add a new template parameter. */
996 static struct demangle_component
*
997 d_make_template_param (struct d_info
*di
, long i
)
999 struct demangle_component
*p
;
1001 p
= d_make_empty (di
);
1004 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1005 p
->u
.s_number
.number
= i
;
1010 /* Add a new function parameter. */
1012 static struct demangle_component
*
1013 d_make_function_param (struct d_info
*di
, long i
)
1015 struct demangle_component
*p
;
1017 p
= d_make_empty (di
);
1020 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1021 p
->u
.s_number
.number
= i
;
1026 /* Add a new standard substitution component. */
1028 static struct demangle_component
*
1029 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1031 struct demangle_component
*p
;
1033 p
= d_make_empty (di
);
1036 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1037 p
->u
.s_string
.string
= name
;
1038 p
->u
.s_string
.len
= len
;
1043 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1045 TOP_LEVEL is non-zero when called at the top level. */
1047 CP_STATIC_IF_GLIBCPP_V3
1048 struct demangle_component
*
1049 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1051 struct demangle_component
*p
;
1053 if (! d_check_char (di
, '_')
1054 /* Allow missing _ if not at toplevel to work around a
1055 bug in G++ abi-version=2 mangling; see the comment in
1056 write_template_arg. */
1059 if (! d_check_char (di
, 'Z'))
1061 p
= d_encoding (di
, top_level
);
1063 /* If at top level and parsing parameters, check for a clone
1065 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1066 while (d_peek_char (di
) == '.'
1067 && (IS_LOWER (d_peek_next_char (di
))
1068 || d_peek_next_char (di
) == '_'
1069 || IS_DIGIT (d_peek_next_char (di
))))
1070 p
= d_clone_suffix (di
, p
);
1075 /* Return whether a function should have a return type. The argument
1076 is the function name, which may be qualified in various ways. The
1077 rules are that template functions have return types with some
1078 exceptions, function types which are not part of a function name
1079 mangling have return types with some exceptions, and non-template
1080 function names do not have return types. The exceptions are that
1081 constructors, destructors, and conversion operators do not have
1085 has_return_type (struct demangle_component
*dc
)
1093 case DEMANGLE_COMPONENT_TEMPLATE
:
1094 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1095 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1096 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1097 case DEMANGLE_COMPONENT_CONST_THIS
:
1098 return has_return_type (d_left (dc
));
1102 /* Return whether a name is a constructor, a destructor, or a
1103 conversion operator. */
1106 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1114 case DEMANGLE_COMPONENT_QUAL_NAME
:
1115 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1116 return is_ctor_dtor_or_conversion (d_right (dc
));
1117 case DEMANGLE_COMPONENT_CTOR
:
1118 case DEMANGLE_COMPONENT_DTOR
:
1119 case DEMANGLE_COMPONENT_CAST
:
1124 /* <encoding> ::= <(function) name> <bare-function-type>
1128 TOP_LEVEL is non-zero when called at the top level, in which case
1129 if DMGL_PARAMS is not set we do not demangle the function
1130 parameters. We only set this at the top level, because otherwise
1131 we would not correctly demangle names in local scopes. */
1133 static struct demangle_component
*
1134 d_encoding (struct d_info
*di
, int top_level
)
1136 char peek
= d_peek_char (di
);
1138 if (peek
== 'G' || peek
== 'T')
1139 return d_special_name (di
);
1142 struct demangle_component
*dc
;
1146 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1148 /* Strip off any initial CV-qualifiers, as they really apply
1149 to the `this' parameter, and they were not output by the
1150 v2 demangler without DMGL_PARAMS. */
1151 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1152 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1153 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1156 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1157 there may be CV-qualifiers on its right argument which
1158 really apply here; this happens when parsing a class
1159 which is local to a function. */
1160 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1162 struct demangle_component
*dcr
;
1165 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1166 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1167 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1169 dc
->u
.s_binary
.right
= dcr
;
1175 peek
= d_peek_char (di
);
1176 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1178 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1179 d_bare_function_type (di
, has_return_type (dc
)));
1183 /* <name> ::= <nested-name>
1185 ::= <unscoped-template-name> <template-args>
1188 <unscoped-name> ::= <unqualified-name>
1189 ::= St <unqualified-name>
1191 <unscoped-template-name> ::= <unscoped-name>
1195 static struct demangle_component
*
1196 d_name (struct d_info
*di
)
1198 char peek
= d_peek_char (di
);
1199 struct demangle_component
*dc
;
1204 return d_nested_name (di
);
1207 return d_local_name (di
);
1211 return d_unqualified_name (di
);
1217 if (d_peek_next_char (di
) != 't')
1219 dc
= d_substitution (di
, 0);
1225 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1226 d_make_name (di
, "std", 3),
1227 d_unqualified_name (di
));
1232 if (d_peek_char (di
) != 'I')
1234 /* The grammar does not permit this case to occur if we
1235 called d_substitution() above (i.e., subst == 1). We
1236 don't bother to check. */
1240 /* This is <template-args>, which means that we just saw
1241 <unscoped-template-name>, which is a substitution
1242 candidate if we didn't just get it from a
1246 if (! d_add_substitution (di
, dc
))
1249 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1250 d_template_args (di
));
1257 dc
= d_unqualified_name (di
);
1258 if (d_peek_char (di
) == 'I')
1260 /* This is <template-args>, which means that we just saw
1261 <unscoped-template-name>, which is a substitution
1263 if (! d_add_substitution (di
, dc
))
1265 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1266 d_template_args (di
));
1272 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1273 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1276 static struct demangle_component
*
1277 d_nested_name (struct d_info
*di
)
1279 struct demangle_component
*ret
;
1280 struct demangle_component
**pret
;
1282 if (! d_check_char (di
, 'N'))
1285 pret
= d_cv_qualifiers (di
, &ret
, 1);
1289 *pret
= d_prefix (di
);
1293 if (! d_check_char (di
, 'E'))
1299 /* <prefix> ::= <prefix> <unqualified-name>
1300 ::= <template-prefix> <template-args>
1301 ::= <template-param>
1305 <template-prefix> ::= <prefix> <(template) unqualified-name>
1306 ::= <template-param>
1310 static struct demangle_component
*
1311 d_prefix (struct d_info
*di
)
1313 struct demangle_component
*ret
= NULL
;
1318 enum demangle_component_type comb_type
;
1319 struct demangle_component
*dc
;
1321 peek
= d_peek_char (di
);
1325 /* The older code accepts a <local-name> here, but I don't see
1326 that in the grammar. The older code does not accept a
1327 <template-param> here. */
1329 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1336 dc
= d_unqualified_name (di
);
1337 else if (peek
== 'S')
1338 dc
= d_substitution (di
, 1);
1339 else if (peek
== 'I')
1343 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1344 dc
= d_template_args (di
);
1346 else if (peek
== 'T')
1347 dc
= d_template_param (di
);
1348 else if (peek
== 'E')
1350 else if (peek
== 'M')
1352 /* Initializer scope for a lambda. We don't need to represent
1353 this; the normal code will just treat the variable as a type
1354 scope, which gives appropriate output. */
1366 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1368 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1370 if (! d_add_substitution (di
, ret
))
1376 /* <unqualified-name> ::= <operator-name>
1377 ::= <ctor-dtor-name>
1379 ::= <local-source-name>
1381 <local-source-name> ::= L <source-name> <discriminator>
1384 static struct demangle_component
*
1385 d_unqualified_name (struct d_info
*di
)
1389 peek
= d_peek_char (di
);
1390 if (IS_DIGIT (peek
))
1391 return d_source_name (di
);
1392 else if (IS_LOWER (peek
))
1394 struct demangle_component
*ret
;
1396 ret
= d_operator_name (di
);
1397 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1398 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1401 else if (peek
== 'C' || peek
== 'D')
1402 return d_ctor_dtor_name (di
);
1403 else if (peek
== 'L')
1405 struct demangle_component
* ret
;
1409 ret
= d_source_name (di
);
1412 if (! d_discriminator (di
))
1416 else if (peek
== 'U')
1418 switch (d_peek_next_char (di
))
1421 return d_lambda (di
);
1423 return d_unnamed_type (di
);
1432 /* <source-name> ::= <(positive length) number> <identifier> */
1434 static struct demangle_component
*
1435 d_source_name (struct d_info
*di
)
1438 struct demangle_component
*ret
;
1440 len
= d_number (di
);
1443 ret
= d_identifier (di
, len
);
1444 di
->last_name
= ret
;
1448 /* number ::= [n] <(non-negative decimal integer)> */
1451 d_number (struct d_info
*di
)
1458 peek
= d_peek_char (di
);
1463 peek
= d_peek_char (di
);
1469 if (! IS_DIGIT (peek
))
1475 ret
= ret
* 10 + peek
- '0';
1477 peek
= d_peek_char (di
);
1481 /* Like d_number, but returns a demangle_component. */
1483 static struct demangle_component
*
1484 d_number_component (struct d_info
*di
)
1486 struct demangle_component
*ret
= d_make_empty (di
);
1489 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1490 ret
->u
.s_number
.number
= d_number (di
);
1495 /* identifier ::= <(unqualified source code identifier)> */
1497 static struct demangle_component
*
1498 d_identifier (struct d_info
*di
, int len
)
1504 if (di
->send
- name
< len
)
1507 d_advance (di
, len
);
1509 /* A Java mangled name may have a trailing '$' if it is a C++
1510 keyword. This '$' is not included in the length count. We just
1512 if ((di
->options
& DMGL_JAVA
) != 0
1513 && d_peek_char (di
) == '$')
1516 /* Look for something which looks like a gcc encoding of an
1517 anonymous namespace, and replace it with a more user friendly
1519 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1520 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1521 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1525 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1526 if ((*s
== '.' || *s
== '_' || *s
== '$')
1529 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1530 return d_make_name (di
, "(anonymous namespace)",
1531 sizeof "(anonymous namespace)" - 1);
1535 return d_make_name (di
, name
, len
);
1538 /* operator_name ::= many different two character encodings.
1540 ::= v <digit> <source-name>
1543 #define NL(s) s, (sizeof s) - 1
1545 CP_STATIC_IF_GLIBCPP_V3
1546 const struct demangle_operator_info cplus_demangle_operators
[] =
1548 { "aN", NL ("&="), 2 },
1549 { "aS", NL ("="), 2 },
1550 { "aa", NL ("&&"), 2 },
1551 { "ad", NL ("&"), 1 },
1552 { "an", NL ("&"), 2 },
1553 { "cl", NL ("()"), 2 },
1554 { "cm", NL (","), 2 },
1555 { "co", NL ("~"), 1 },
1556 { "dV", NL ("/="), 2 },
1557 { "da", NL ("delete[]"), 1 },
1558 { "de", NL ("*"), 1 },
1559 { "dl", NL ("delete"), 1 },
1560 { "dt", NL ("."), 2 },
1561 { "dv", NL ("/"), 2 },
1562 { "eO", NL ("^="), 2 },
1563 { "eo", NL ("^"), 2 },
1564 { "eq", NL ("=="), 2 },
1565 { "ge", NL (">="), 2 },
1566 { "gt", NL (">"), 2 },
1567 { "ix", NL ("[]"), 2 },
1568 { "lS", NL ("<<="), 2 },
1569 { "le", NL ("<="), 2 },
1570 { "ls", NL ("<<"), 2 },
1571 { "lt", NL ("<"), 2 },
1572 { "mI", NL ("-="), 2 },
1573 { "mL", NL ("*="), 2 },
1574 { "mi", NL ("-"), 2 },
1575 { "ml", NL ("*"), 2 },
1576 { "mm", NL ("--"), 1 },
1577 { "na", NL ("new[]"), 1 },
1578 { "ne", NL ("!="), 2 },
1579 { "ng", NL ("-"), 1 },
1580 { "nt", NL ("!"), 1 },
1581 { "nw", NL ("new"), 1 },
1582 { "oR", NL ("|="), 2 },
1583 { "oo", NL ("||"), 2 },
1584 { "or", NL ("|"), 2 },
1585 { "pL", NL ("+="), 2 },
1586 { "pl", NL ("+"), 2 },
1587 { "pm", NL ("->*"), 2 },
1588 { "pp", NL ("++"), 1 },
1589 { "ps", NL ("+"), 1 },
1590 { "pt", NL ("->"), 2 },
1591 { "qu", NL ("?"), 3 },
1592 { "rM", NL ("%="), 2 },
1593 { "rS", NL (">>="), 2 },
1594 { "rm", NL ("%"), 2 },
1595 { "rs", NL (">>"), 2 },
1596 { "st", NL ("sizeof "), 1 },
1597 { "sz", NL ("sizeof "), 1 },
1598 { "at", NL ("alignof "), 1 },
1599 { "az", NL ("alignof "), 1 },
1600 { NULL
, NULL
, 0, 0 }
1603 static struct demangle_component
*
1604 d_operator_name (struct d_info
*di
)
1609 c1
= d_next_char (di
);
1610 c2
= d_next_char (di
);
1611 if (c1
== 'v' && IS_DIGIT (c2
))
1612 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1613 else if (c1
== 'c' && c2
== 'v')
1614 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1615 cplus_demangle_type (di
), NULL
);
1618 /* LOW is the inclusive lower bound. */
1620 /* HIGH is the exclusive upper bound. We subtract one to ignore
1621 the sentinel at the end of the array. */
1622 int high
= ((sizeof (cplus_demangle_operators
)
1623 / sizeof (cplus_demangle_operators
[0]))
1629 const struct demangle_operator_info
*p
;
1631 i
= low
+ (high
- low
) / 2;
1632 p
= cplus_demangle_operators
+ i
;
1634 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1635 return d_make_operator (di
, p
);
1637 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1647 static struct demangle_component
*
1648 d_make_character (struct d_info
*di
, int c
)
1650 struct demangle_component
*p
;
1651 p
= d_make_empty (di
);
1654 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1655 p
->u
.s_character
.character
= c
;
1660 static struct demangle_component
*
1661 d_java_resource (struct d_info
*di
)
1663 struct demangle_component
*p
= NULL
;
1664 struct demangle_component
*next
= NULL
;
1669 len
= d_number (di
);
1673 /* Eat the leading '_'. */
1674 if (d_next_char (di
) != '_')
1687 /* Each chunk is either a '$' escape... */
1705 next
= d_make_character (di
, c
);
1713 /* ... or a sequence of characters. */
1716 while (i
< len
&& str
[i
] && str
[i
] != '$')
1719 next
= d_make_name (di
, str
, i
);
1732 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1738 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1743 /* <special-name> ::= TV <type>
1747 ::= GV <(object) name>
1748 ::= T <call-offset> <(base) encoding>
1749 ::= Tc <call-offset> <call-offset> <(base) encoding>
1750 Also g++ extensions:
1751 ::= TC <type> <(offset) number> _ <(base) type>
1756 ::= Gr <resource name>
1759 static struct demangle_component
*
1760 d_special_name (struct d_info
*di
)
1762 di
->expansion
+= 20;
1763 if (d_check_char (di
, 'T'))
1765 switch (d_next_char (di
))
1769 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1770 cplus_demangle_type (di
), NULL
);
1772 di
->expansion
-= 10;
1773 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1774 cplus_demangle_type (di
), NULL
);
1776 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1777 cplus_demangle_type (di
), NULL
);
1779 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1780 cplus_demangle_type (di
), NULL
);
1783 if (! d_call_offset (di
, 'h'))
1785 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1786 d_encoding (di
, 0), NULL
);
1789 if (! d_call_offset (di
, 'v'))
1791 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1792 d_encoding (di
, 0), NULL
);
1795 if (! d_call_offset (di
, '\0'))
1797 if (! d_call_offset (di
, '\0'))
1799 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1800 d_encoding (di
, 0), NULL
);
1804 struct demangle_component
*derived_type
;
1806 struct demangle_component
*base_type
;
1808 derived_type
= cplus_demangle_type (di
);
1809 offset
= d_number (di
);
1812 if (! d_check_char (di
, '_'))
1814 base_type
= cplus_demangle_type (di
);
1815 /* We don't display the offset. FIXME: We should display
1816 it in verbose mode. */
1818 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1819 base_type
, derived_type
);
1823 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1824 cplus_demangle_type (di
), NULL
);
1826 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1827 cplus_demangle_type (di
), NULL
);
1833 else if (d_check_char (di
, 'G'))
1835 switch (d_next_char (di
))
1838 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1841 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, d_name (di
),
1845 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1846 d_encoding (di
, 0), NULL
);
1849 return d_java_resource (di
);
1859 /* <call-offset> ::= h <nv-offset> _
1862 <nv-offset> ::= <(offset) number>
1864 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1866 The C parameter, if not '\0', is a character we just read which is
1867 the start of the <call-offset>.
1869 We don't display the offset information anywhere. FIXME: We should
1870 display it in verbose mode. */
1873 d_call_offset (struct d_info
*di
, int c
)
1876 c
= d_next_char (di
);
1883 if (! d_check_char (di
, '_'))
1890 if (! d_check_char (di
, '_'))
1896 /* <ctor-dtor-name> ::= C1
1904 static struct demangle_component
*
1905 d_ctor_dtor_name (struct d_info
*di
)
1907 if (di
->last_name
!= NULL
)
1909 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1910 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1911 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1912 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1914 switch (d_peek_char (di
))
1918 enum gnu_v3_ctor_kinds kind
;
1920 switch (d_peek_next_char (di
))
1923 kind
= gnu_v3_complete_object_ctor
;
1926 kind
= gnu_v3_base_object_ctor
;
1929 kind
= gnu_v3_complete_object_allocating_ctor
;
1935 return d_make_ctor (di
, kind
, di
->last_name
);
1940 enum gnu_v3_dtor_kinds kind
;
1942 switch (d_peek_next_char (di
))
1945 kind
= gnu_v3_deleting_dtor
;
1948 kind
= gnu_v3_complete_object_dtor
;
1951 kind
= gnu_v3_base_object_dtor
;
1957 return d_make_dtor (di
, kind
, di
->last_name
);
1965 /* <type> ::= <builtin-type>
1967 ::= <class-enum-type>
1969 ::= <pointer-to-member-type>
1970 ::= <template-param>
1971 ::= <template-template-param> <template-args>
1973 ::= <CV-qualifiers> <type>
1976 ::= O <type> (C++0x)
1979 ::= U <source-name> <type>
1981 <builtin-type> ::= various one letter codes
1985 CP_STATIC_IF_GLIBCPP_V3
1986 const struct demangle_builtin_type_info
1987 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
1989 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
1990 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
1991 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
1992 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
1993 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
1994 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
1995 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
1996 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
1997 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
1998 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
1999 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2000 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2001 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2002 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2003 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2005 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2006 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2007 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2008 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2009 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2010 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2011 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2012 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2013 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2014 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2015 D_PRINT_UNSIGNED_LONG_LONG
},
2016 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2017 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2018 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2019 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2020 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2021 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2022 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2023 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2027 CP_STATIC_IF_GLIBCPP_V3
2028 struct demangle_component
*
2029 cplus_demangle_type (struct d_info
*di
)
2032 struct demangle_component
*ret
;
2035 /* The ABI specifies that when CV-qualifiers are used, the base type
2036 is substitutable, and the fully qualified type is substitutable,
2037 but the base type with a strict subset of the CV-qualifiers is
2038 not substitutable. The natural recursive implementation of the
2039 CV-qualifiers would cause subsets to be substitutable, so instead
2040 we pull them all off now.
2042 FIXME: The ABI says that order-insensitive vendor qualifiers
2043 should be handled in the same way, but we have no way to tell
2044 which vendor qualifiers are order-insensitive and which are
2045 order-sensitive. So we just assume that they are all
2046 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2047 __vector, and it treats it as order-sensitive when mangling
2050 peek
= d_peek_char (di
);
2051 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2053 struct demangle_component
**pret
;
2055 pret
= d_cv_qualifiers (di
, &ret
, 0);
2058 *pret
= cplus_demangle_type (di
);
2059 if (! *pret
|| ! d_add_substitution (di
, ret
))
2068 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2069 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2070 case 'o': case 's': case 't':
2071 case 'v': case 'w': case 'x': case 'y': case 'z':
2072 ret
= d_make_builtin_type (di
,
2073 &cplus_demangle_builtin_types
[peek
- 'a']);
2074 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2081 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2082 d_source_name (di
), NULL
);
2086 ret
= d_function_type (di
);
2089 case '0': case '1': case '2': case '3': case '4':
2090 case '5': case '6': case '7': case '8': case '9':
2093 ret
= d_class_enum_type (di
);
2097 ret
= d_array_type (di
);
2101 ret
= d_pointer_to_member_type (di
);
2105 ret
= d_template_param (di
);
2106 if (d_peek_char (di
) == 'I')
2108 /* This is <template-template-param> <template-args>. The
2109 <template-template-param> part is a substitution
2111 if (! d_add_substitution (di
, ret
))
2113 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2114 d_template_args (di
));
2119 /* If this is a special substitution, then it is the start of
2120 <class-enum-type>. */
2124 peek_next
= d_peek_next_char (di
);
2125 if (IS_DIGIT (peek_next
)
2127 || IS_UPPER (peek_next
))
2129 ret
= d_substitution (di
, 0);
2130 /* The substituted name may have been a template name and
2131 may be followed by tepmlate args. */
2132 if (d_peek_char (di
) == 'I')
2133 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2134 d_template_args (di
));
2140 ret
= d_class_enum_type (di
);
2141 /* If the substitution was a complete type, then it is not
2142 a new substitution candidate. However, if the
2143 substitution was followed by template arguments, then
2144 the whole thing is a substitution candidate. */
2145 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2153 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2154 cplus_demangle_type (di
), NULL
);
2159 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2160 cplus_demangle_type (di
), NULL
);
2165 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2166 cplus_demangle_type (di
), NULL
);
2171 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2172 cplus_demangle_type (di
), NULL
);
2177 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2178 cplus_demangle_type (di
), NULL
);
2183 ret
= d_source_name (di
);
2184 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2185 cplus_demangle_type (di
), ret
);
2191 peek
= d_next_char (di
);
2196 /* decltype (expression) */
2197 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2198 d_expression (di
), NULL
);
2199 if (ret
&& d_next_char (di
) != 'E')
2204 /* Pack expansion. */
2205 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2206 cplus_demangle_type (di
), NULL
);
2210 /* 32-bit decimal floating point */
2211 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2212 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2216 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2217 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2221 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2222 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2225 /* 16-bit half-precision FP */
2226 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2227 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2231 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2232 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2236 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2237 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2241 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2242 ret
= d_make_empty (di
);
2243 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2244 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2245 /* For demangling we don't care about the bits. */
2247 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2248 if (ret
->u
.s_fixed
.length
== NULL
)
2251 peek
= d_next_char (di
);
2252 ret
->u
.s_fixed
.sat
= (peek
== 's');
2256 ret
= d_vector_type (di
);
2260 /* decltype(nullptr) */
2261 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2262 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2276 if (! d_add_substitution (di
, ret
))
2283 /* <CV-qualifiers> ::= [r] [V] [K] */
2285 static struct demangle_component
**
2286 d_cv_qualifiers (struct d_info
*di
,
2287 struct demangle_component
**pret
, int member_fn
)
2291 peek
= d_peek_char (di
);
2292 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2294 enum demangle_component_type t
;
2300 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2301 : DEMANGLE_COMPONENT_RESTRICT
);
2302 di
->expansion
+= sizeof "restrict";
2304 else if (peek
== 'V')
2307 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2308 : DEMANGLE_COMPONENT_VOLATILE
);
2309 di
->expansion
+= sizeof "volatile";
2314 ? DEMANGLE_COMPONENT_CONST_THIS
2315 : DEMANGLE_COMPONENT_CONST
);
2316 di
->expansion
+= sizeof "const";
2319 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2322 pret
= &d_left (*pret
);
2324 peek
= d_peek_char (di
);
2330 /* <function-type> ::= F [Y] <bare-function-type> E */
2332 static struct demangle_component
*
2333 d_function_type (struct d_info
*di
)
2335 struct demangle_component
*ret
;
2337 if (! d_check_char (di
, 'F'))
2339 if (d_peek_char (di
) == 'Y')
2341 /* Function has C linkage. We don't print this information.
2342 FIXME: We should print it in verbose mode. */
2345 ret
= d_bare_function_type (di
, 1);
2346 if (! d_check_char (di
, 'E'))
2353 static struct demangle_component
*
2354 d_parmlist (struct d_info
*di
)
2356 struct demangle_component
*tl
;
2357 struct demangle_component
**ptl
;
2363 struct demangle_component
*type
;
2365 char peek
= d_peek_char (di
);
2366 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2368 type
= cplus_demangle_type (di
);
2371 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2374 ptl
= &d_right (*ptl
);
2377 /* There should be at least one parameter type besides the optional
2378 return type. A function which takes no arguments will have a
2379 single parameter type void. */
2383 /* If we have a single parameter type void, omit it. */
2384 if (d_right (tl
) == NULL
2385 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2386 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2388 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2395 /* <bare-function-type> ::= [J]<type>+ */
2397 static struct demangle_component
*
2398 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2400 struct demangle_component
*return_type
;
2401 struct demangle_component
*tl
;
2404 /* Detect special qualifier indicating that the first argument
2405 is the return type. */
2406 peek
= d_peek_char (di
);
2410 has_return_type
= 1;
2413 if (has_return_type
)
2415 return_type
= cplus_demangle_type (di
);
2416 if (return_type
== NULL
)
2422 tl
= d_parmlist (di
);
2426 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2430 /* <class-enum-type> ::= <name> */
2432 static struct demangle_component
*
2433 d_class_enum_type (struct d_info
*di
)
2438 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2439 ::= A [<(dimension) expression>] _ <(element) type>
2442 static struct demangle_component
*
2443 d_array_type (struct d_info
*di
)
2446 struct demangle_component
*dim
;
2448 if (! d_check_char (di
, 'A'))
2451 peek
= d_peek_char (di
);
2454 else if (IS_DIGIT (peek
))
2462 peek
= d_peek_char (di
);
2464 while (IS_DIGIT (peek
));
2465 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2471 dim
= d_expression (di
);
2476 if (! d_check_char (di
, '_'))
2479 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2480 cplus_demangle_type (di
));
2483 /* <vector-type> ::= Dv <number> _ <type>
2484 ::= Dv _ <expression> _ <type> */
2486 static struct demangle_component
*
2487 d_vector_type (struct d_info
*di
)
2490 struct demangle_component
*dim
;
2492 peek
= d_peek_char (di
);
2496 dim
= d_expression (di
);
2499 dim
= d_number_component (di
);
2504 if (! d_check_char (di
, '_'))
2507 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2508 cplus_demangle_type (di
));
2511 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2513 static struct demangle_component
*
2514 d_pointer_to_member_type (struct d_info
*di
)
2516 struct demangle_component
*cl
;
2517 struct demangle_component
*mem
;
2518 struct demangle_component
**pmem
;
2520 if (! d_check_char (di
, 'M'))
2523 cl
= cplus_demangle_type (di
);
2525 /* The ABI specifies that any type can be a substitution source, and
2526 that M is followed by two types, and that when a CV-qualified
2527 type is seen both the base type and the CV-qualified types are
2528 substitution sources. The ABI also specifies that for a pointer
2529 to a CV-qualified member function, the qualifiers are attached to
2530 the second type. Given the grammar, a plain reading of the ABI
2531 suggests that both the CV-qualified member function and the
2532 non-qualified member function are substitution sources. However,
2533 g++ does not work that way. g++ treats only the CV-qualified
2534 member function as a substitution source. FIXME. So to work
2535 with g++, we need to pull off the CV-qualifiers here, in order to
2536 avoid calling add_substitution() in cplus_demangle_type(). But
2537 for a CV-qualified member which is not a function, g++ does
2538 follow the ABI, so we need to handle that case here by calling
2539 d_add_substitution ourselves. */
2541 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2544 *pmem
= cplus_demangle_type (di
);
2548 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2550 if (! d_add_substitution (di
, mem
))
2554 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2557 /* <non-negative number> _ */
2560 d_compact_number (struct d_info
*di
)
2563 if (d_peek_char (di
) == '_')
2565 else if (d_peek_char (di
) == 'n')
2568 num
= d_number (di
) + 1;
2570 if (! d_check_char (di
, '_'))
2575 /* <template-param> ::= T_
2576 ::= T <(parameter-2 non-negative) number> _
2579 static struct demangle_component
*
2580 d_template_param (struct d_info
*di
)
2584 if (! d_check_char (di
, 'T'))
2587 param
= d_compact_number (di
);
2593 return d_make_template_param (di
, param
);
2596 /* <template-args> ::= I <template-arg>+ E */
2598 static struct demangle_component
*
2599 d_template_args (struct d_info
*di
)
2601 struct demangle_component
*hold_last_name
;
2602 struct demangle_component
*al
;
2603 struct demangle_component
**pal
;
2605 /* Preserve the last name we saw--don't let the template arguments
2606 clobber it, as that would give us the wrong name for a subsequent
2607 constructor or destructor. */
2608 hold_last_name
= di
->last_name
;
2610 if (! d_check_char (di
, 'I'))
2613 if (d_peek_char (di
) == 'E')
2615 /* An argument pack can be empty. */
2617 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2624 struct demangle_component
*a
;
2626 a
= d_template_arg (di
);
2630 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2633 pal
= &d_right (*pal
);
2635 if (d_peek_char (di
) == 'E')
2642 di
->last_name
= hold_last_name
;
2647 /* <template-arg> ::= <type>
2648 ::= X <expression> E
2652 static struct demangle_component
*
2653 d_template_arg (struct d_info
*di
)
2655 struct demangle_component
*ret
;
2657 switch (d_peek_char (di
))
2661 ret
= d_expression (di
);
2662 if (! d_check_char (di
, 'E'))
2667 return d_expr_primary (di
);
2670 /* An argument pack. */
2671 return d_template_args (di
);
2674 return cplus_demangle_type (di
);
2678 /* Subroutine of <expression> ::= cl <expression>+ E */
2680 static struct demangle_component
*
2681 d_exprlist (struct d_info
*di
)
2683 struct demangle_component
*list
= NULL
;
2684 struct demangle_component
**p
= &list
;
2686 if (d_peek_char (di
) == 'E')
2689 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2694 struct demangle_component
*arg
= d_expression (di
);
2698 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2703 if (d_peek_char (di
) == 'E')
2713 /* <expression> ::= <(unary) operator-name> <expression>
2714 ::= <(binary) operator-name> <expression> <expression>
2715 ::= <(trinary) operator-name> <expression> <expression> <expression>
2716 ::= cl <expression>+ E
2718 ::= <template-param>
2719 ::= sr <type> <unqualified-name>
2720 ::= sr <type> <unqualified-name> <template-args>
2724 static struct demangle_component
*
2725 d_expression (struct d_info
*di
)
2729 peek
= d_peek_char (di
);
2731 return d_expr_primary (di
);
2732 else if (peek
== 'T')
2733 return d_template_param (di
);
2734 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2736 struct demangle_component
*type
;
2737 struct demangle_component
*name
;
2740 type
= cplus_demangle_type (di
);
2741 name
= d_unqualified_name (di
);
2742 if (d_peek_char (di
) != 'I')
2743 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2745 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2746 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2747 d_template_args (di
)));
2749 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
2752 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2753 d_expression (di
), NULL
);
2755 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
2757 /* Function parameter used in a late-specified return type. */
2760 index
= d_compact_number (di
);
2764 return d_make_function_param (di
, index
);
2766 else if (IS_DIGIT (peek
)
2767 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
2769 /* We can get an unqualified name as an expression in the case of
2770 a dependent function call, i.e. decltype(f(t)). */
2771 struct demangle_component
*name
;
2774 /* operator-function-id, i.e. operator+(t). */
2777 name
= d_unqualified_name (di
);
2780 if (d_peek_char (di
) == 'I')
2781 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2782 d_template_args (di
));
2788 struct demangle_component
*op
;
2791 op
= d_operator_name (di
);
2795 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2796 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2798 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2799 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2800 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2801 cplus_demangle_type (di
));
2807 case DEMANGLE_COMPONENT_OPERATOR
:
2808 args
= op
->u
.s_operator
.op
->args
;
2810 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2811 args
= op
->u
.s_extended_operator
.args
;
2813 case DEMANGLE_COMPONENT_CAST
:
2822 struct demangle_component
*operand
;
2823 if (op
->type
== DEMANGLE_COMPONENT_CAST
2824 && d_check_char (di
, '_'))
2825 operand
= d_exprlist (di
);
2827 operand
= d_expression (di
);
2828 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2833 struct demangle_component
*left
;
2834 struct demangle_component
*right
;
2835 const char *code
= op
->u
.s_operator
.op
->code
;
2837 left
= d_expression (di
);
2838 if (!strcmp (code
, "cl"))
2839 right
= d_exprlist (di
);
2840 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
2842 right
= d_unqualified_name (di
);
2843 if (d_peek_char (di
) == 'I')
2844 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
2845 right
, d_template_args (di
));
2848 right
= d_expression (di
);
2850 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2852 DEMANGLE_COMPONENT_BINARY_ARGS
,
2857 struct demangle_component
*first
;
2858 struct demangle_component
*second
;
2860 first
= d_expression (di
);
2861 second
= d_expression (di
);
2862 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2864 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2867 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2869 d_expression (di
))));
2877 /* <expr-primary> ::= L <type> <(value) number> E
2878 ::= L <type> <(value) float> E
2879 ::= L <mangled-name> E
2882 static struct demangle_component
*
2883 d_expr_primary (struct d_info
*di
)
2885 struct demangle_component
*ret
;
2887 if (! d_check_char (di
, 'L'))
2889 if (d_peek_char (di
) == '_'
2890 /* Workaround for G++ bug; see comment in write_template_arg. */
2891 || d_peek_char (di
) == 'Z')
2892 ret
= cplus_demangle_mangled_name (di
, 0);
2895 struct demangle_component
*type
;
2896 enum demangle_component_type t
;
2899 type
= cplus_demangle_type (di
);
2903 /* If we have a type we know how to print, we aren't going to
2904 print the type name itself. */
2905 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2906 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2907 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2909 /* Rather than try to interpret the literal value, we just
2910 collect it as a string. Note that it's possible to have a
2911 floating point literal here. The ABI specifies that the
2912 format of such literals is machine independent. That's fine,
2913 but what's not fine is that versions of g++ up to 3.2 with
2914 -fabi-version=1 used upper case letters in the hex constant,
2915 and dumped out gcc's internal representation. That makes it
2916 hard to tell where the constant ends, and hard to dump the
2917 constant in any readable form anyhow. We don't attempt to
2918 handle these cases. */
2920 t
= DEMANGLE_COMPONENT_LITERAL
;
2921 if (d_peek_char (di
) == 'n')
2923 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2927 while (d_peek_char (di
) != 'E')
2929 if (d_peek_char (di
) == '\0')
2933 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2935 if (! d_check_char (di
, 'E'))
2940 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2941 ::= Z <(function) encoding> E s [<discriminator>]
2944 static struct demangle_component
*
2945 d_local_name (struct d_info
*di
)
2947 struct demangle_component
*function
;
2949 if (! d_check_char (di
, 'Z'))
2952 function
= d_encoding (di
, 0);
2954 if (! d_check_char (di
, 'E'))
2957 if (d_peek_char (di
) == 's')
2960 if (! d_discriminator (di
))
2962 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
2963 d_make_name (di
, "string literal",
2964 sizeof "string literal" - 1));
2968 struct demangle_component
*name
;
2971 if (d_peek_char (di
) == 'd')
2973 /* Default argument scope: d <number> _. */
2975 num
= d_compact_number (di
);
2984 /* Lambdas and unnamed types have internal discriminators. */
2985 case DEMANGLE_COMPONENT_LAMBDA
:
2986 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
2989 if (! d_discriminator (di
))
2993 name
= d_make_default_arg (di
, num
, name
);
2994 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
2998 /* <discriminator> ::= _ <(non-negative) number>
3000 We demangle the discriminator, but we don't print it out. FIXME:
3001 We should print it out in verbose mode. */
3004 d_discriminator (struct d_info
*di
)
3008 if (d_peek_char (di
) != '_')
3011 discrim
= d_number (di
);
3017 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3019 static struct demangle_component
*
3020 d_lambda (struct d_info
*di
)
3022 struct demangle_component
*tl
;
3023 struct demangle_component
*ret
;
3026 if (! d_check_char (di
, 'U'))
3028 if (! d_check_char (di
, 'l'))
3031 tl
= d_parmlist (di
);
3035 if (! d_check_char (di
, 'E'))
3038 num
= d_compact_number (di
);
3042 ret
= d_make_empty (di
);
3045 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3046 ret
->u
.s_unary_num
.sub
= tl
;
3047 ret
->u
.s_unary_num
.num
= num
;
3050 if (! d_add_substitution (di
, ret
))
3056 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3058 static struct demangle_component
*
3059 d_unnamed_type (struct d_info
*di
)
3061 struct demangle_component
*ret
;
3064 if (! d_check_char (di
, 'U'))
3066 if (! d_check_char (di
, 't'))
3069 num
= d_compact_number (di
);
3073 ret
= d_make_empty (di
);
3076 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3077 ret
->u
.s_number
.number
= num
;
3080 if (! d_add_substitution (di
, ret
))
3086 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3089 static struct demangle_component
*
3090 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3092 const char *suffix
= d_str (di
);
3093 const char *pend
= suffix
;
3094 struct demangle_component
*n
;
3096 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3099 while (IS_LOWER (*pend
) || *pend
== '_')
3102 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3105 while (IS_DIGIT (*pend
))
3108 d_advance (di
, pend
- suffix
);
3109 n
= d_make_name (di
, suffix
, pend
- suffix
);
3110 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3113 /* Add a new substitution. */
3116 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3120 if (di
->next_sub
>= di
->num_subs
)
3122 di
->subs
[di
->next_sub
] = dc
;
3127 /* <substitution> ::= S <seq-id> _
3137 If PREFIX is non-zero, then this type is being used as a prefix in
3138 a qualified name. In this case, for the standard substitutions, we
3139 need to check whether we are being used as a prefix for a
3140 constructor or destructor, and return a full template name.
3141 Otherwise we will get something like std::iostream::~iostream()
3142 which does not correspond particularly well to any function which
3143 actually appears in the source.
3146 static const struct d_standard_sub_info standard_subs
[] =
3151 { 'a', NL ("std::allocator"),
3152 NL ("std::allocator"),
3154 { 'b', NL ("std::basic_string"),
3155 NL ("std::basic_string"),
3156 NL ("basic_string") },
3157 { 's', NL ("std::string"),
3158 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3159 NL ("basic_string") },
3160 { 'i', NL ("std::istream"),
3161 NL ("std::basic_istream<char, std::char_traits<char> >"),
3162 NL ("basic_istream") },
3163 { 'o', NL ("std::ostream"),
3164 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3165 NL ("basic_ostream") },
3166 { 'd', NL ("std::iostream"),
3167 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3168 NL ("basic_iostream") }
3171 static struct demangle_component
*
3172 d_substitution (struct d_info
*di
, int prefix
)
3176 if (! d_check_char (di
, 'S'))
3179 c
= d_next_char (di
);
3180 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3189 unsigned int new_id
;
3192 new_id
= id
* 36 + c
- '0';
3193 else if (IS_UPPER (c
))
3194 new_id
= id
* 36 + c
- 'A' + 10;
3200 c
= d_next_char (di
);
3207 if (id
>= (unsigned int) di
->next_sub
)
3212 return di
->subs
[id
];
3217 const struct d_standard_sub_info
*p
;
3218 const struct d_standard_sub_info
*pend
;
3220 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3221 if (! verbose
&& prefix
)
3225 peek
= d_peek_char (di
);
3226 if (peek
== 'C' || peek
== 'D')
3230 pend
= (&standard_subs
[0]
3231 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3232 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3239 if (p
->set_last_name
!= NULL
)
3240 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3241 p
->set_last_name_len
);
3244 s
= p
->full_expansion
;
3249 s
= p
->simple_expansion
;
3250 len
= p
->simple_len
;
3252 di
->expansion
+= len
;
3253 return d_make_sub (di
, s
, len
);
3261 /* Initialize a growable string. */
3264 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3269 dgs
->allocation_failure
= 0;
3272 d_growable_string_resize (dgs
, estimate
);
3275 /* Grow a growable string to a given size. */
3278 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3283 if (dgs
->allocation_failure
)
3286 /* Start allocation at two bytes to avoid any possibility of confusion
3287 with the special value of 1 used as a return in *palc to indicate
3288 allocation failures. */
3289 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3290 while (newalc
< need
)
3293 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3300 dgs
->allocation_failure
= 1;
3307 /* Append a buffer to a growable string. */
3310 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3311 const char *s
, size_t l
)
3315 need
= dgs
->len
+ l
+ 1;
3316 if (need
> dgs
->alc
)
3317 d_growable_string_resize (dgs
, need
);
3319 if (dgs
->allocation_failure
)
3322 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3323 dgs
->buf
[dgs
->len
+ l
] = '\0';
3327 /* Bridge growable strings to the callback mechanism. */
3330 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3332 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3334 d_growable_string_append_buffer (dgs
, s
, l
);
3337 /* Initialize a print information structure. */
3340 d_print_init (struct d_print_info
*dpi
, int options
,
3341 demangle_callbackref callback
, void *opaque
)
3343 dpi
->options
= options
;
3345 dpi
->last_char
= '\0';
3346 dpi
->templates
= NULL
;
3347 dpi
->modifiers
= NULL
;
3348 dpi
->flush_count
= 0;
3350 dpi
->callback
= callback
;
3351 dpi
->opaque
= opaque
;
3353 dpi
->demangle_failure
= 0;
3356 /* Indicate that an error occurred during printing, and test for error. */
3359 d_print_error (struct d_print_info
*dpi
)
3361 dpi
->demangle_failure
= 1;
3365 d_print_saw_error (struct d_print_info
*dpi
)
3367 return dpi
->demangle_failure
!= 0;
3370 /* Flush buffered characters to the callback. */
3373 d_print_flush (struct d_print_info
*dpi
)
3375 dpi
->buf
[dpi
->len
] = '\0';
3376 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3381 /* Append characters and buffers for printing. */
3384 d_append_char (struct d_print_info
*dpi
, char c
)
3386 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3387 d_print_flush (dpi
);
3389 dpi
->buf
[dpi
->len
++] = c
;
3394 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3398 for (i
= 0; i
< l
; i
++)
3399 d_append_char (dpi
, s
[i
]);
3403 d_append_string (struct d_print_info
*dpi
, const char *s
)
3405 d_append_buffer (dpi
, s
, strlen (s
));
3409 d_append_num (struct d_print_info
*dpi
, long l
)
3412 sprintf (buf
,"%ld", l
);
3413 d_append_string (dpi
, buf
);
3417 d_last_char (struct d_print_info
*dpi
)
3419 return dpi
->last_char
;
3422 /* Turn components into a human readable string. OPTIONS is the
3423 options bits passed to the demangler. DC is the tree to print.
3424 CALLBACK is a function to call to flush demangled string segments
3425 as they fill the intermediate buffer, and OPAQUE is a generalized
3426 callback argument. On success, this returns 1. On failure,
3427 it returns 0, indicating a bad parse. It does not use heap
3428 memory to build an output string, so cannot encounter memory
3429 allocation failure. */
3431 CP_STATIC_IF_GLIBCPP_V3
3433 cplus_demangle_print_callback (int options
,
3434 const struct demangle_component
*dc
,
3435 demangle_callbackref callback
, void *opaque
)
3437 struct d_print_info dpi
;
3439 d_print_init (&dpi
, options
, callback
, opaque
);
3441 d_print_comp (&dpi
, dc
);
3443 d_print_flush (&dpi
);
3445 return ! d_print_saw_error (&dpi
);
3448 /* Turn components into a human readable string. OPTIONS is the
3449 options bits passed to the demangler. DC is the tree to print.
3450 ESTIMATE is a guess at the length of the result. This returns a
3451 string allocated by malloc, or NULL on error. On success, this
3452 sets *PALC to the size of the allocated buffer. On failure, this
3453 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3456 CP_STATIC_IF_GLIBCPP_V3
3458 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3459 int estimate
, size_t *palc
)
3461 struct d_growable_string dgs
;
3463 d_growable_string_init (&dgs
, estimate
);
3465 if (! cplus_demangle_print_callback (options
, dc
,
3466 d_growable_string_callback_adapter
,
3474 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3478 /* Returns the I'th element of the template arglist ARGS, or NULL on
3481 static struct demangle_component
*
3482 d_index_template_argument (struct demangle_component
*args
, int i
)
3484 struct demangle_component
*a
;
3490 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3496 if (i
!= 0 || a
== NULL
)
3502 /* Returns the template argument from the current context indicated by DC,
3503 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3505 static struct demangle_component
*
3506 d_lookup_template_argument (struct d_print_info
*dpi
,
3507 const struct demangle_component
*dc
)
3509 if (dpi
->templates
== NULL
)
3511 d_print_error (dpi
);
3515 return d_index_template_argument
3516 (d_right (dpi
->templates
->template_decl
),
3517 dc
->u
.s_number
.number
);
3520 /* Returns a template argument pack used in DC (any will do), or NULL. */
3522 static struct demangle_component
*
3523 d_find_pack (struct d_print_info
*dpi
,
3524 const struct demangle_component
*dc
)
3526 struct demangle_component
*a
;
3532 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3533 a
= d_lookup_template_argument (dpi
, dc
);
3534 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3538 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3541 case DEMANGLE_COMPONENT_LAMBDA
:
3542 case DEMANGLE_COMPONENT_NAME
:
3543 case DEMANGLE_COMPONENT_OPERATOR
:
3544 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3545 case DEMANGLE_COMPONENT_SUB_STD
:
3546 case DEMANGLE_COMPONENT_CHARACTER
:
3547 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3550 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3551 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3552 case DEMANGLE_COMPONENT_CTOR
:
3553 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3554 case DEMANGLE_COMPONENT_DTOR
:
3555 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3558 a
= d_find_pack (dpi
, d_left (dc
));
3561 return d_find_pack (dpi
, d_right (dc
));
3565 /* Returns the length of the template argument pack DC. */
3568 d_pack_length (const struct demangle_component
*dc
)
3571 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3572 && d_left (dc
) != NULL
)
3580 /* DC is a component of a mangled expression. Print it, wrapped in parens
3584 d_print_subexpr (struct d_print_info
*dpi
,
3585 const struct demangle_component
*dc
)
3588 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3589 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3592 d_append_char (dpi
, '(');
3593 d_print_comp (dpi
, dc
);
3595 d_append_char (dpi
, ')');
3598 /* Subroutine to handle components. */
3601 d_print_comp (struct d_print_info
*dpi
,
3602 const struct demangle_component
*dc
)
3606 d_print_error (dpi
);
3609 if (d_print_saw_error (dpi
))
3614 case DEMANGLE_COMPONENT_NAME
:
3615 if ((dpi
->options
& DMGL_JAVA
) == 0)
3616 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3618 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3621 case DEMANGLE_COMPONENT_QUAL_NAME
:
3622 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3623 d_print_comp (dpi
, d_left (dc
));
3624 if ((dpi
->options
& DMGL_JAVA
) == 0)
3625 d_append_string (dpi
, "::");
3627 d_append_char (dpi
, '.');
3628 d_print_comp (dpi
, d_right (dc
));
3631 case DEMANGLE_COMPONENT_TYPED_NAME
:
3633 struct d_print_mod
*hold_modifiers
;
3634 struct demangle_component
*typed_name
;
3635 struct d_print_mod adpm
[4];
3637 struct d_print_template dpt
;
3639 /* Pass the name down to the type so that it can be printed in
3640 the right place for the type. We also have to pass down
3641 any CV-qualifiers, which apply to the this parameter. */
3642 hold_modifiers
= dpi
->modifiers
;
3645 typed_name
= d_left (dc
);
3646 while (typed_name
!= NULL
)
3648 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3650 d_print_error (dpi
);
3654 adpm
[i
].next
= dpi
->modifiers
;
3655 dpi
->modifiers
= &adpm
[i
];
3656 adpm
[i
].mod
= typed_name
;
3657 adpm
[i
].printed
= 0;
3658 adpm
[i
].templates
= dpi
->templates
;
3661 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3662 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3663 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3666 typed_name
= d_left (typed_name
);
3669 if (typed_name
== NULL
)
3671 d_print_error (dpi
);
3675 /* If typed_name is a template, then it applies to the
3676 function type as well. */
3677 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3679 dpt
.next
= dpi
->templates
;
3680 dpi
->templates
= &dpt
;
3681 dpt
.template_decl
= typed_name
;
3684 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3685 there may be CV-qualifiers on its right argument which
3686 really apply here; this happens when parsing a class which
3687 is local to a function. */
3688 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3690 struct demangle_component
*local_name
;
3692 local_name
= d_right (typed_name
);
3693 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
3694 local_name
= local_name
->u
.s_unary_num
.sub
;
3695 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3696 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3697 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3699 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3701 d_print_error (dpi
);
3705 adpm
[i
] = adpm
[i
- 1];
3706 adpm
[i
].next
= &adpm
[i
- 1];
3707 dpi
->modifiers
= &adpm
[i
];
3709 adpm
[i
- 1].mod
= local_name
;
3710 adpm
[i
- 1].printed
= 0;
3711 adpm
[i
- 1].templates
= dpi
->templates
;
3714 local_name
= d_left (local_name
);
3718 d_print_comp (dpi
, d_right (dc
));
3720 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3721 dpi
->templates
= dpt
.next
;
3723 /* If the modifiers didn't get printed by the type, print them
3728 if (! adpm
[i
].printed
)
3730 d_append_char (dpi
, ' ');
3731 d_print_mod (dpi
, adpm
[i
].mod
);
3735 dpi
->modifiers
= hold_modifiers
;
3740 case DEMANGLE_COMPONENT_TEMPLATE
:
3742 struct d_print_mod
*hold_dpm
;
3743 struct demangle_component
*dcl
;
3745 /* Don't push modifiers into a template definition. Doing so
3746 could give the wrong definition for a template argument.
3747 Instead, treat the template essentially as a name. */
3749 hold_dpm
= dpi
->modifiers
;
3750 dpi
->modifiers
= NULL
;
3754 if ((dpi
->options
& DMGL_JAVA
) != 0
3755 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3756 && dcl
->u
.s_name
.len
== 6
3757 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3759 /* Special-case Java arrays, so that JArray<TYPE> appears
3760 instead as TYPE[]. */
3762 d_print_comp (dpi
, d_right (dc
));
3763 d_append_string (dpi
, "[]");
3767 d_print_comp (dpi
, dcl
);
3768 if (d_last_char (dpi
) == '<')
3769 d_append_char (dpi
, ' ');
3770 d_append_char (dpi
, '<');
3771 d_print_comp (dpi
, d_right (dc
));
3772 /* Avoid generating two consecutive '>' characters, to avoid
3773 the C++ syntactic ambiguity. */
3774 if (d_last_char (dpi
) == '>')
3775 d_append_char (dpi
, ' ');
3776 d_append_char (dpi
, '>');
3779 dpi
->modifiers
= hold_dpm
;
3784 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3786 struct d_print_template
*hold_dpt
;
3787 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
3789 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3790 a
= d_index_template_argument (a
, dpi
->pack_index
);
3794 d_print_error (dpi
);
3798 /* While processing this parameter, we need to pop the list of
3799 templates. This is because the template parameter may
3800 itself be a reference to a parameter of an outer
3803 hold_dpt
= dpi
->templates
;
3804 dpi
->templates
= hold_dpt
->next
;
3806 d_print_comp (dpi
, a
);
3808 dpi
->templates
= hold_dpt
;
3813 case DEMANGLE_COMPONENT_CTOR
:
3814 d_print_comp (dpi
, dc
->u
.s_ctor
.name
);
3817 case DEMANGLE_COMPONENT_DTOR
:
3818 d_append_char (dpi
, '~');
3819 d_print_comp (dpi
, dc
->u
.s_dtor
.name
);
3822 case DEMANGLE_COMPONENT_VTABLE
:
3823 d_append_string (dpi
, "vtable for ");
3824 d_print_comp (dpi
, d_left (dc
));
3827 case DEMANGLE_COMPONENT_VTT
:
3828 d_append_string (dpi
, "VTT for ");
3829 d_print_comp (dpi
, d_left (dc
));
3832 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3833 d_append_string (dpi
, "construction vtable for ");
3834 d_print_comp (dpi
, d_left (dc
));
3835 d_append_string (dpi
, "-in-");
3836 d_print_comp (dpi
, d_right (dc
));
3839 case DEMANGLE_COMPONENT_TYPEINFO
:
3840 d_append_string (dpi
, "typeinfo for ");
3841 d_print_comp (dpi
, d_left (dc
));
3844 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3845 d_append_string (dpi
, "typeinfo name for ");
3846 d_print_comp (dpi
, d_left (dc
));
3849 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3850 d_append_string (dpi
, "typeinfo fn for ");
3851 d_print_comp (dpi
, d_left (dc
));
3854 case DEMANGLE_COMPONENT_THUNK
:
3855 d_append_string (dpi
, "non-virtual thunk to ");
3856 d_print_comp (dpi
, d_left (dc
));
3859 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3860 d_append_string (dpi
, "virtual thunk to ");
3861 d_print_comp (dpi
, d_left (dc
));
3864 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3865 d_append_string (dpi
, "covariant return thunk to ");
3866 d_print_comp (dpi
, d_left (dc
));
3869 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3870 d_append_string (dpi
, "java Class for ");
3871 d_print_comp (dpi
, d_left (dc
));
3874 case DEMANGLE_COMPONENT_GUARD
:
3875 d_append_string (dpi
, "guard variable for ");
3876 d_print_comp (dpi
, d_left (dc
));
3879 case DEMANGLE_COMPONENT_REFTEMP
:
3880 d_append_string (dpi
, "reference temporary for ");
3881 d_print_comp (dpi
, d_left (dc
));
3884 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3885 d_append_string (dpi
, "hidden alias for ");
3886 d_print_comp (dpi
, d_left (dc
));
3889 case DEMANGLE_COMPONENT_SUB_STD
:
3890 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3893 case DEMANGLE_COMPONENT_RESTRICT
:
3894 case DEMANGLE_COMPONENT_VOLATILE
:
3895 case DEMANGLE_COMPONENT_CONST
:
3897 struct d_print_mod
*pdpm
;
3899 /* When printing arrays, it's possible to have cases where the
3900 same CV-qualifier gets pushed on the stack multiple times.
3901 We only need to print it once. */
3903 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3905 if (! pdpm
->printed
)
3907 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3908 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3909 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3911 if (pdpm
->mod
->type
== dc
->type
)
3913 d_print_comp (dpi
, d_left (dc
));
3920 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3921 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3922 case DEMANGLE_COMPONENT_CONST_THIS
:
3923 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3924 case DEMANGLE_COMPONENT_POINTER
:
3925 case DEMANGLE_COMPONENT_REFERENCE
:
3926 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3927 case DEMANGLE_COMPONENT_COMPLEX
:
3928 case DEMANGLE_COMPONENT_IMAGINARY
:
3930 /* We keep a list of modifiers on the stack. */
3931 struct d_print_mod dpm
;
3933 dpm
.next
= dpi
->modifiers
;
3934 dpi
->modifiers
= &dpm
;
3937 dpm
.templates
= dpi
->templates
;
3939 d_print_comp (dpi
, d_left (dc
));
3941 /* If the modifier didn't get printed by the type, print it
3944 d_print_mod (dpi
, dc
);
3946 dpi
->modifiers
= dpm
.next
;
3951 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3952 if ((dpi
->options
& DMGL_JAVA
) == 0)
3953 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
3954 dc
->u
.s_builtin
.type
->len
);
3956 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
3957 dc
->u
.s_builtin
.type
->java_len
);
3960 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3961 d_print_comp (dpi
, d_left (dc
));
3964 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3966 if ((dpi
->options
& DMGL_RET_POSTFIX
) != 0)
3967 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3969 /* Print return type if present */
3970 if (d_left (dc
) != NULL
)
3972 struct d_print_mod dpm
;
3974 /* We must pass this type down as a modifier in order to
3975 print it in the right location. */
3976 dpm
.next
= dpi
->modifiers
;
3977 dpi
->modifiers
= &dpm
;
3980 dpm
.templates
= dpi
->templates
;
3982 d_print_comp (dpi
, d_left (dc
));
3984 dpi
->modifiers
= dpm
.next
;
3989 /* In standard prefix notation, there is a space between the
3990 return type and the function signature. */
3991 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3992 d_append_char (dpi
, ' ');
3995 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3996 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
4001 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4003 struct d_print_mod
*hold_modifiers
;
4004 struct d_print_mod adpm
[4];
4006 struct d_print_mod
*pdpm
;
4008 /* We must pass this type down as a modifier in order to print
4009 multi-dimensional arrays correctly. If the array itself is
4010 CV-qualified, we act as though the element type were
4011 CV-qualified. We do this by copying the modifiers down
4012 rather than fiddling pointers, so that we don't wind up
4013 with a d_print_mod higher on the stack pointing into our
4014 stack frame after we return. */
4016 hold_modifiers
= dpi
->modifiers
;
4018 adpm
[0].next
= hold_modifiers
;
4019 dpi
->modifiers
= &adpm
[0];
4021 adpm
[0].printed
= 0;
4022 adpm
[0].templates
= dpi
->templates
;
4025 pdpm
= hold_modifiers
;
4027 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4028 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4029 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4031 if (! pdpm
->printed
)
4033 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4035 d_print_error (dpi
);
4040 adpm
[i
].next
= dpi
->modifiers
;
4041 dpi
->modifiers
= &adpm
[i
];
4049 d_print_comp (dpi
, d_right (dc
));
4051 dpi
->modifiers
= hold_modifiers
;
4053 if (adpm
[0].printed
)
4059 d_print_mod (dpi
, adpm
[i
].mod
);
4062 d_print_array_type (dpi
, dc
, dpi
->modifiers
);
4067 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4068 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4070 struct d_print_mod dpm
;
4072 dpm
.next
= dpi
->modifiers
;
4073 dpi
->modifiers
= &dpm
;
4076 dpm
.templates
= dpi
->templates
;
4078 d_print_comp (dpi
, d_right (dc
));
4080 /* If the modifier didn't get printed by the type, print it
4083 d_print_mod (dpi
, dc
);
4085 dpi
->modifiers
= dpm
.next
;
4090 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4091 if (dc
->u
.s_fixed
.sat
)
4092 d_append_string (dpi
, "_Sat ");
4093 /* Don't print "int _Accum". */
4094 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4095 != &cplus_demangle_builtin_types
['i'-'a'])
4097 d_print_comp (dpi
, dc
->u
.s_fixed
.length
);
4098 d_append_char (dpi
, ' ');
4100 if (dc
->u
.s_fixed
.accum
)
4101 d_append_string (dpi
, "_Accum");
4103 d_append_string (dpi
, "_Fract");
4106 case DEMANGLE_COMPONENT_ARGLIST
:
4107 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4108 if (d_left (dc
) != NULL
)
4109 d_print_comp (dpi
, d_left (dc
));
4110 if (d_right (dc
) != NULL
)
4113 unsigned long int flush_count
;
4114 /* Make sure ", " isn't flushed by d_append_string, otherwise
4115 dpi->len -= 2 wouldn't work. */
4116 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4117 d_print_flush (dpi
);
4118 d_append_string (dpi
, ", ");
4120 flush_count
= dpi
->flush_count
;
4121 d_print_comp (dpi
, d_right (dc
));
4122 /* If that didn't print anything (which can happen with empty
4123 template argument packs), remove the comma and space. */
4124 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4129 case DEMANGLE_COMPONENT_OPERATOR
:
4133 d_append_string (dpi
, "operator");
4134 c
= dc
->u
.s_operator
.op
->name
[0];
4136 d_append_char (dpi
, ' ');
4137 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4138 dc
->u
.s_operator
.op
->len
);
4142 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4143 d_append_string (dpi
, "operator ");
4144 d_print_comp (dpi
, dc
->u
.s_extended_operator
.name
);
4147 case DEMANGLE_COMPONENT_CAST
:
4148 d_append_string (dpi
, "operator ");
4149 d_print_cast (dpi
, dc
);
4152 case DEMANGLE_COMPONENT_UNARY
:
4153 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
4154 d_print_expr_op (dpi
, d_left (dc
));
4157 d_append_char (dpi
, '(');
4158 d_print_cast (dpi
, d_left (dc
));
4159 d_append_char (dpi
, ')');
4161 d_print_subexpr (dpi
, d_right (dc
));
4164 case DEMANGLE_COMPONENT_BINARY
:
4165 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4167 d_print_error (dpi
);
4171 /* We wrap an expression which uses the greater-than operator in
4172 an extra layer of parens so that it does not get confused
4173 with the '>' which ends the template parameters. */
4174 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4175 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4176 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4177 d_append_char (dpi
, '(');
4179 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4180 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4182 d_append_char (dpi
, '[');
4183 d_print_comp (dpi
, d_right (d_right (dc
)));
4184 d_append_char (dpi
, ']');
4188 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4189 d_print_expr_op (dpi
, d_left (dc
));
4190 d_print_subexpr (dpi
, d_right (d_right (dc
)));
4193 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4194 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4195 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4196 d_append_char (dpi
, ')');
4200 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4201 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4202 d_print_error (dpi
);
4205 case DEMANGLE_COMPONENT_TRINARY
:
4206 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4207 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4209 d_print_error (dpi
);
4212 d_print_subexpr (dpi
, d_left (d_right (dc
)));
4213 d_print_expr_op (dpi
, d_left (dc
));
4214 d_print_subexpr (dpi
, d_left (d_right (d_right (dc
))));
4215 d_append_string (dpi
, " : ");
4216 d_print_subexpr (dpi
, d_right (d_right (d_right (dc
))));
4219 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4220 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4221 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4222 d_print_error (dpi
);
4225 case DEMANGLE_COMPONENT_LITERAL
:
4226 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4228 enum d_builtin_type_print tp
;
4230 /* For some builtin types, produce simpler output. */
4231 tp
= D_PRINT_DEFAULT
;
4232 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4234 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4238 case D_PRINT_UNSIGNED
:
4240 case D_PRINT_UNSIGNED_LONG
:
4241 case D_PRINT_LONG_LONG
:
4242 case D_PRINT_UNSIGNED_LONG_LONG
:
4243 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4245 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4246 d_append_char (dpi
, '-');
4247 d_print_comp (dpi
, d_right (dc
));
4252 case D_PRINT_UNSIGNED
:
4253 d_append_char (dpi
, 'u');
4256 d_append_char (dpi
, 'l');
4258 case D_PRINT_UNSIGNED_LONG
:
4259 d_append_string (dpi
, "ul");
4261 case D_PRINT_LONG_LONG
:
4262 d_append_string (dpi
, "ll");
4264 case D_PRINT_UNSIGNED_LONG_LONG
:
4265 d_append_string (dpi
, "ull");
4273 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4274 && d_right (dc
)->u
.s_name
.len
== 1
4275 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4277 switch (d_right (dc
)->u
.s_name
.s
[0])
4280 d_append_string (dpi
, "false");
4283 d_append_string (dpi
, "true");
4296 d_append_char (dpi
, '(');
4297 d_print_comp (dpi
, d_left (dc
));
4298 d_append_char (dpi
, ')');
4299 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4300 d_append_char (dpi
, '-');
4301 if (tp
== D_PRINT_FLOAT
)
4302 d_append_char (dpi
, '[');
4303 d_print_comp (dpi
, d_right (dc
));
4304 if (tp
== D_PRINT_FLOAT
)
4305 d_append_char (dpi
, ']');
4309 case DEMANGLE_COMPONENT_NUMBER
:
4310 d_append_num (dpi
, dc
->u
.s_number
.number
);
4313 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4314 d_append_string (dpi
, "java resource ");
4315 d_print_comp (dpi
, d_left (dc
));
4318 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4319 d_print_comp (dpi
, d_left (dc
));
4320 d_print_comp (dpi
, d_right (dc
));
4323 case DEMANGLE_COMPONENT_CHARACTER
:
4324 d_append_char (dpi
, dc
->u
.s_character
.character
);
4327 case DEMANGLE_COMPONENT_DECLTYPE
:
4328 d_append_string (dpi
, "decltype (");
4329 d_print_comp (dpi
, d_left (dc
));
4330 d_append_char (dpi
, ')');
4333 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4337 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4340 /* d_find_pack won't find anything if the only packs involved
4341 in this expansion are function parameter packs; in that
4342 case, just print the pattern and "...". */
4343 d_print_subexpr (dpi
, d_left (dc
));
4344 d_append_string (dpi
, "...");
4348 len
= d_pack_length (a
);
4350 for (i
= 0; i
< len
; ++i
)
4352 dpi
->pack_index
= i
;
4353 d_print_comp (dpi
, dc
);
4355 d_append_string (dpi
, ", ");
4360 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4361 d_append_string (dpi
, "{parm#");
4362 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4363 d_append_char (dpi
, '}');
4366 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4367 d_append_string (dpi
, "global constructors keyed to ");
4368 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4371 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4372 d_append_string (dpi
, "global destructors keyed to ");
4373 d_print_comp (dpi
, dc
->u
.s_binary
.left
);
4376 case DEMANGLE_COMPONENT_LAMBDA
:
4377 d_append_string (dpi
, "{lambda(");
4378 d_print_comp (dpi
, dc
->u
.s_unary_num
.sub
);
4379 d_append_string (dpi
, ")#");
4380 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4381 d_append_char (dpi
, '}');
4384 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4385 d_append_string (dpi
, "{unnamed type#");
4386 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4387 d_append_char (dpi
, '}');
4390 case DEMANGLE_COMPONENT_CLONE
:
4391 d_print_comp (dpi
, d_left (dc
));
4392 d_append_string (dpi
, " [clone ");
4393 d_print_comp (dpi
, d_right (dc
));
4394 d_append_char (dpi
, ']');
4398 d_print_error (dpi
);
4403 /* Print a Java dentifier. For Java we try to handle encoded extended
4404 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4405 so we don't it for C++. Characters are encoded as
4409 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
4415 for (p
= name
; p
< end
; ++p
)
4426 for (q
= p
+ 3; q
< end
; ++q
)
4432 else if (*q
>= 'A' && *q
<= 'F')
4433 dig
= *q
- 'A' + 10;
4434 else if (*q
>= 'a' && *q
<= 'f')
4435 dig
= *q
- 'a' + 10;
4441 /* If the Unicode character is larger than 256, we don't try
4442 to deal with it here. FIXME. */
4443 if (q
< end
&& *q
== '_' && c
< 256)
4445 d_append_char (dpi
, c
);
4451 d_append_char (dpi
, *p
);
4455 /* Print a list of modifiers. SUFFIX is 1 if we are printing
4456 qualifiers on this after printing a function. */
4459 d_print_mod_list (struct d_print_info
*dpi
,
4460 struct d_print_mod
*mods
, int suffix
)
4462 struct d_print_template
*hold_dpt
;
4464 if (mods
== NULL
|| d_print_saw_error (dpi
))
4469 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4470 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4471 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
4473 d_print_mod_list (dpi
, mods
->next
, suffix
);
4479 hold_dpt
= dpi
->templates
;
4480 dpi
->templates
= mods
->templates
;
4482 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4484 d_print_function_type (dpi
, mods
->mod
, mods
->next
);
4485 dpi
->templates
= hold_dpt
;
4488 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4490 d_print_array_type (dpi
, mods
->mod
, mods
->next
);
4491 dpi
->templates
= hold_dpt
;
4494 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4496 struct d_print_mod
*hold_modifiers
;
4497 struct demangle_component
*dc
;
4499 /* When this is on the modifier stack, we have pulled any
4500 qualifiers off the right argument already. Otherwise, we
4501 print it as usual, but don't let the left argument see any
4504 hold_modifiers
= dpi
->modifiers
;
4505 dpi
->modifiers
= NULL
;
4506 d_print_comp (dpi
, d_left (mods
->mod
));
4507 dpi
->modifiers
= hold_modifiers
;
4509 if ((dpi
->options
& DMGL_JAVA
) == 0)
4510 d_append_string (dpi
, "::");
4512 d_append_char (dpi
, '.');
4514 dc
= d_right (mods
->mod
);
4516 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4518 d_append_string (dpi
, "{default arg#");
4519 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4520 d_append_string (dpi
, "}::");
4521 dc
= dc
->u
.s_unary_num
.sub
;
4524 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4525 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4526 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
4529 d_print_comp (dpi
, dc
);
4531 dpi
->templates
= hold_dpt
;
4535 d_print_mod (dpi
, mods
->mod
);
4537 dpi
->templates
= hold_dpt
;
4539 d_print_mod_list (dpi
, mods
->next
, suffix
);
4542 /* Print a modifier. */
4545 d_print_mod (struct d_print_info
*dpi
,
4546 const struct demangle_component
*mod
)
4550 case DEMANGLE_COMPONENT_RESTRICT
:
4551 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4552 d_append_string (dpi
, " restrict");
4554 case DEMANGLE_COMPONENT_VOLATILE
:
4555 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4556 d_append_string (dpi
, " volatile");
4558 case DEMANGLE_COMPONENT_CONST
:
4559 case DEMANGLE_COMPONENT_CONST_THIS
:
4560 d_append_string (dpi
, " const");
4562 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4563 d_append_char (dpi
, ' ');
4564 d_print_comp (dpi
, d_right (mod
));
4566 case DEMANGLE_COMPONENT_POINTER
:
4567 /* There is no pointer symbol in Java. */
4568 if ((dpi
->options
& DMGL_JAVA
) == 0)
4569 d_append_char (dpi
, '*');
4571 case DEMANGLE_COMPONENT_REFERENCE
:
4572 d_append_char (dpi
, '&');
4574 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4575 d_append_string (dpi
, "&&");
4577 case DEMANGLE_COMPONENT_COMPLEX
:
4578 d_append_string (dpi
, "complex ");
4580 case DEMANGLE_COMPONENT_IMAGINARY
:
4581 d_append_string (dpi
, "imaginary ");
4583 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4584 if (d_last_char (dpi
) != '(')
4585 d_append_char (dpi
, ' ');
4586 d_print_comp (dpi
, d_left (mod
));
4587 d_append_string (dpi
, "::*");
4589 case DEMANGLE_COMPONENT_TYPED_NAME
:
4590 d_print_comp (dpi
, d_left (mod
));
4592 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4593 d_append_string (dpi
, " __vector(");
4594 d_print_comp (dpi
, d_left (mod
));
4595 d_append_char (dpi
, ')');
4599 /* Otherwise, we have something that won't go back on the
4600 modifier stack, so we can just print it. */
4601 d_print_comp (dpi
, mod
);
4606 /* Print a function type, except for the return type. */
4609 d_print_function_type (struct d_print_info
*dpi
,
4610 const struct demangle_component
*dc
,
4611 struct d_print_mod
*mods
)
4615 struct d_print_mod
*p
;
4616 struct d_print_mod
*hold_modifiers
;
4620 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4625 switch (p
->mod
->type
)
4627 case DEMANGLE_COMPONENT_POINTER
:
4628 case DEMANGLE_COMPONENT_REFERENCE
:
4629 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4632 case DEMANGLE_COMPONENT_RESTRICT
:
4633 case DEMANGLE_COMPONENT_VOLATILE
:
4634 case DEMANGLE_COMPONENT_CONST
:
4635 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4636 case DEMANGLE_COMPONENT_COMPLEX
:
4637 case DEMANGLE_COMPONENT_IMAGINARY
:
4638 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4642 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4643 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4644 case DEMANGLE_COMPONENT_CONST_THIS
:
4657 if (d_last_char (dpi
) != '('
4658 && d_last_char (dpi
) != '*')
4661 if (need_space
&& d_last_char (dpi
) != ' ')
4662 d_append_char (dpi
, ' ');
4663 d_append_char (dpi
, '(');
4666 hold_modifiers
= dpi
->modifiers
;
4667 dpi
->modifiers
= NULL
;
4669 d_print_mod_list (dpi
, mods
, 0);
4672 d_append_char (dpi
, ')');
4674 d_append_char (dpi
, '(');
4676 if (d_right (dc
) != NULL
)
4677 d_print_comp (dpi
, d_right (dc
));
4679 d_append_char (dpi
, ')');
4681 d_print_mod_list (dpi
, mods
, 1);
4683 dpi
->modifiers
= hold_modifiers
;
4686 /* Print an array type, except for the element type. */
4689 d_print_array_type (struct d_print_info
*dpi
,
4690 const struct demangle_component
*dc
,
4691 struct d_print_mod
*mods
)
4699 struct d_print_mod
*p
;
4702 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4706 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4721 d_append_string (dpi
, " (");
4723 d_print_mod_list (dpi
, mods
, 0);
4726 d_append_char (dpi
, ')');
4730 d_append_char (dpi
, ' ');
4732 d_append_char (dpi
, '[');
4734 if (d_left (dc
) != NULL
)
4735 d_print_comp (dpi
, d_left (dc
));
4737 d_append_char (dpi
, ']');
4740 /* Print an operator in an expression. */
4743 d_print_expr_op (struct d_print_info
*dpi
,
4744 const struct demangle_component
*dc
)
4746 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4747 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4748 dc
->u
.s_operator
.op
->len
);
4750 d_print_comp (dpi
, dc
);
4756 d_print_cast (struct d_print_info
*dpi
,
4757 const struct demangle_component
*dc
)
4759 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4760 d_print_comp (dpi
, d_left (dc
));
4763 struct d_print_mod
*hold_dpm
;
4764 struct d_print_template dpt
;
4766 /* It appears that for a templated cast operator, we need to put
4767 the template parameters in scope for the operator name, but
4768 not for the parameters. The effect is that we need to handle
4769 the template printing here. */
4771 hold_dpm
= dpi
->modifiers
;
4772 dpi
->modifiers
= NULL
;
4774 dpt
.next
= dpi
->templates
;
4775 dpi
->templates
= &dpt
;
4776 dpt
.template_decl
= d_left (dc
);
4778 d_print_comp (dpi
, d_left (d_left (dc
)));
4780 dpi
->templates
= dpt
.next
;
4782 if (d_last_char (dpi
) == '<')
4783 d_append_char (dpi
, ' ');
4784 d_append_char (dpi
, '<');
4785 d_print_comp (dpi
, d_right (d_left (dc
)));
4786 /* Avoid generating two consecutive '>' characters, to avoid
4787 the C++ syntactic ambiguity. */
4788 if (d_last_char (dpi
) == '>')
4789 d_append_char (dpi
, ' ');
4790 d_append_char (dpi
, '>');
4792 dpi
->modifiers
= hold_dpm
;
4796 /* Initialize the information structure we use to pass around
4799 CP_STATIC_IF_GLIBCPP_V3
4801 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4805 di
->send
= mangled
+ len
;
4806 di
->options
= options
;
4810 /* We can not need more components than twice the number of chars in
4811 the mangled string. Most components correspond directly to
4812 chars, but the ARGLIST types are exceptions. */
4813 di
->num_comps
= 2 * len
;
4816 /* Similarly, we can not need more substitutions than there are
4817 chars in the mangled string. */
4822 di
->last_name
= NULL
;
4827 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4828 mangled name, return strings in repeated callback giving the demangled
4829 name. OPTIONS is the usual libiberty demangler options. On success,
4830 this returns 1. On failure, returns 0. */
4833 d_demangle_callback (const char *mangled
, int options
,
4834 demangle_callbackref callback
, void *opaque
)
4845 struct demangle_component
*dc
;
4848 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4850 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
4851 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
4852 && (mangled
[9] == 'D' || mangled
[9] == 'I')
4853 && mangled
[10] == '_')
4854 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
4857 if ((options
& DMGL_TYPES
) == 0)
4862 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
4865 #ifdef CP_DYNAMIC_ARRAYS
4866 __extension__
struct demangle_component comps
[di
.num_comps
];
4867 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4872 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4873 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4879 dc
= cplus_demangle_type (&di
);
4882 dc
= cplus_demangle_mangled_name (&di
, 1);
4884 case DCT_GLOBAL_CTORS
:
4885 case DCT_GLOBAL_DTORS
:
4886 d_advance (&di
, 11);
4887 dc
= d_make_comp (&di
,
4888 (type
== DCT_GLOBAL_CTORS
4889 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
4890 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
4891 d_make_demangle_mangled_name (&di
, d_str (&di
)),
4893 d_advance (&di
, strlen (d_str (&di
)));
4897 /* If DMGL_PARAMS is set, then if we didn't consume the entire
4898 mangled string, then we didn't successfully demangle it. If
4899 DMGL_PARAMS is not set, we didn't look at the trailing
4901 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
4904 #ifdef CP_DEMANGLE_DEBUG
4908 status
= (dc
!= NULL
)
4909 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
4916 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4917 name, return a buffer allocated with malloc holding the demangled
4918 name. OPTIONS is the usual libiberty demangler options. On
4919 success, this sets *PALC to the allocated size of the returned
4920 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4921 a memory allocation failure, and returns NULL. */
4924 d_demangle (const char *mangled
, int options
, size_t *palc
)
4926 struct d_growable_string dgs
;
4929 d_growable_string_init (&dgs
, 0);
4931 status
= d_demangle_callback (mangled
, options
,
4932 d_growable_string_callback_adapter
, &dgs
);
4940 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4944 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4946 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
4948 /* ia64 ABI-mandated entry point in the C++ runtime library for
4949 performing demangling. MANGLED_NAME is a NUL-terminated character
4950 string containing the name to be demangled.
4952 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
4953 *LENGTH bytes, into which the demangled name is stored. If
4954 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
4955 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
4956 is placed in a region of memory allocated with malloc.
4958 If LENGTH is non-NULL, the length of the buffer containing the
4959 demangled name, is placed in *LENGTH.
4961 The return value is a pointer to the start of the NUL-terminated
4962 demangled name, or NULL if the demangling fails. The caller is
4963 responsible for deallocating this memory using free.
4965 *STATUS is set to one of the following values:
4966 0: The demangling operation succeeded.
4967 -1: A memory allocation failure occurred.
4968 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4969 -3: One of the arguments is invalid.
4971 The demangling is performed using the C++ ABI mangling rules, with
4975 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
4976 size_t *length
, int *status
)
4981 if (mangled_name
== NULL
)
4988 if (output_buffer
!= NULL
&& length
== NULL
)
4995 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
4997 if (demangled
== NULL
)
5009 if (output_buffer
== NULL
)
5016 if (strlen (demangled
) < *length
)
5018 strcpy (output_buffer
, demangled
);
5020 demangled
= output_buffer
;
5024 free (output_buffer
);
5035 extern int __gcclibcxx_demangle_callback (const char *,
5037 (const char *, size_t, void *),
5040 /* Alternative, allocationless entry point in the C++ runtime library
5041 for performing demangling. MANGLED_NAME is a NUL-terminated character
5042 string containing the name to be demangled.
5044 CALLBACK is a callback function, called with demangled string
5045 segments as demangling progresses; it is called at least once,
5046 but may be called more than once. OPAQUE is a generalized pointer
5047 used as a callback argument.
5049 The return code is one of the following values, equivalent to
5050 the STATUS values of __cxa_demangle() (excluding -1, since this
5051 function performs no memory allocations):
5052 0: The demangling operation succeeded.
5053 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5054 -3: One of the arguments is invalid.
5056 The demangling is performed using the C++ ABI mangling rules, with
5060 __gcclibcxx_demangle_callback (const char *mangled_name
,
5061 void (*callback
) (const char *, size_t, void *),
5066 if (mangled_name
== NULL
|| callback
== NULL
)
5069 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5077 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5079 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5080 mangled name, return a buffer allocated with malloc holding the
5081 demangled name. Otherwise, return NULL. */
5084 cplus_demangle_v3 (const char *mangled
, int options
)
5088 return d_demangle (mangled
, options
, &alc
);
5092 cplus_demangle_v3_callback (const char *mangled
, int options
,
5093 demangle_callbackref callback
, void *opaque
)
5095 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5098 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5099 conventions, but the output formatting is a little different.
5100 This instructs the C++ demangler not to emit pointer characters ("*"), to
5101 use Java's namespace separator symbol ("." instead of "::"), and to output
5102 JArray<TYPE> as TYPE[]. */
5105 java_demangle_v3 (const char *mangled
)
5109 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5113 java_demangle_v3_callback (const char *mangled
,
5114 demangle_callbackref callback
, void *opaque
)
5116 return d_demangle_callback (mangled
,
5117 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5121 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5123 #ifndef IN_GLIBCPP_V3
5125 /* Demangle a string in order to find out whether it is a constructor
5126 or destructor. Return non-zero on success. Set *CTOR_KIND and
5127 *DTOR_KIND appropriately. */
5130 is_ctor_or_dtor (const char *mangled
,
5131 enum gnu_v3_ctor_kinds
*ctor_kind
,
5132 enum gnu_v3_dtor_kinds
*dtor_kind
)
5135 struct demangle_component
*dc
;
5138 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5139 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5141 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5144 #ifdef CP_DYNAMIC_ARRAYS
5145 __extension__
struct demangle_component comps
[di
.num_comps
];
5146 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5151 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5152 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5155 dc
= cplus_demangle_mangled_name (&di
, 1);
5157 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5158 to demangle the entire string. */
5168 case DEMANGLE_COMPONENT_TYPED_NAME
:
5169 case DEMANGLE_COMPONENT_TEMPLATE
:
5170 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5171 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5172 case DEMANGLE_COMPONENT_CONST_THIS
:
5175 case DEMANGLE_COMPONENT_QUAL_NAME
:
5176 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5179 case DEMANGLE_COMPONENT_CTOR
:
5180 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5184 case DEMANGLE_COMPONENT_DTOR
:
5185 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5196 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5197 name. A non-zero return indicates the type of constructor. */
5199 enum gnu_v3_ctor_kinds
5200 is_gnu_v3_mangled_ctor (const char *name
)
5202 enum gnu_v3_ctor_kinds ctor_kind
;
5203 enum gnu_v3_dtor_kinds dtor_kind
;
5205 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5206 return (enum gnu_v3_ctor_kinds
) 0;
5211 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5212 name. A non-zero return indicates the type of destructor. */
5214 enum gnu_v3_dtor_kinds
5215 is_gnu_v3_mangled_dtor (const char *name
)
5217 enum gnu_v3_ctor_kinds ctor_kind
;
5218 enum gnu_v3_dtor_kinds dtor_kind
;
5220 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5221 return (enum gnu_v3_dtor_kinds
) 0;
5225 #endif /* IN_GLIBCPP_V3 */
5227 #ifdef STANDALONE_DEMANGLER
5230 #include "dyn-string.h"
5232 static void print_usage (FILE* fp
, int exit_value
);
5234 #define IS_ALPHA(CHAR) \
5235 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5236 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5238 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5239 #define is_mangled_char(CHAR) \
5240 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5241 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5243 /* The name of this program, as invoked. */
5244 const char* program_name
;
5246 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5249 print_usage (FILE* fp
, int exit_value
)
5251 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5252 fprintf (fp
, "Options:\n");
5253 fprintf (fp
, " -h,--help Display this message.\n");
5254 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5255 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5256 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5261 /* Option specification for getopt_long. */
5262 static const struct option long_options
[] =
5264 { "help", no_argument
, NULL
, 'h' },
5265 { "no-params", no_argument
, NULL
, 'p' },
5266 { "verbose", no_argument
, NULL
, 'v' },
5267 { NULL
, no_argument
, NULL
, 0 },
5270 /* Main entry for a demangling filter executable. It will demangle
5271 its command line arguments, if any. If none are provided, it will
5272 filter stdin to stdout, replacing any recognized mangled C++ names
5273 with their demangled equivalents. */
5276 main (int argc
, char *argv
[])
5280 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5282 /* Use the program name of this program, as invoked. */
5283 program_name
= argv
[0];
5285 /* Parse options. */
5288 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5291 case '?': /* Unrecognized option. */
5292 print_usage (stderr
, 1);
5296 print_usage (stdout
, 0);
5300 options
&= ~ DMGL_PARAMS
;
5304 options
|= DMGL_VERBOSE
;
5308 while (opt_char
!= -1);
5311 /* No command line arguments were provided. Filter stdin. */
5313 dyn_string_t mangled
= dyn_string_new (3);
5316 /* Read all of input. */
5317 while (!feof (stdin
))
5321 /* Pile characters into mangled until we hit one that can't
5322 occur in a mangled name. */
5324 while (!feof (stdin
) && is_mangled_char (c
))
5326 dyn_string_append_char (mangled
, c
);
5332 if (dyn_string_length (mangled
) > 0)
5334 #ifdef IN_GLIBCPP_V3
5335 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
5337 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
5347 /* It might not have been a mangled name. Print the
5349 fputs (dyn_string_buf (mangled
), stdout
);
5352 dyn_string_clear (mangled
);
5355 /* If we haven't hit EOF yet, we've read one character that
5356 can't occur in a mangled name, so print it out. */
5361 dyn_string_delete (mangled
);
5364 /* Demangle command line arguments. */
5366 /* Loop over command line arguments. */
5367 for (i
= optind
; i
< argc
; ++i
)
5370 #ifdef IN_GLIBCPP_V3
5374 /* Attempt to demangle. */
5375 #ifdef IN_GLIBCPP_V3
5376 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
5378 s
= cplus_demangle_v3 (argv
[i
], options
);
5381 /* If it worked, print the demangled name. */
5389 #ifdef IN_GLIBCPP_V3
5390 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
5392 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
5401 #endif /* STANDALONE_DEMANGLER */