1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 /* A demangle component and some scope captured when it was first
283 /* The component whose scope this is. */
284 const struct demangle_component
*container
;
285 /* The list of templates, if any, that was current when this
286 scope was captured. */
287 struct d_print_template
*templates
;
290 enum { D_PRINT_BUFFER_LENGTH
= 256 };
293 /* Fixed-length allocated buffer for demangled data, flushed to the
294 callback with a NUL termination once full. */
295 char buf
[D_PRINT_BUFFER_LENGTH
];
296 /* Current length of data in buffer. */
298 /* The last character printed, saved individually so that it survives
301 /* Callback function to handle demangled buffer flush. */
302 demangle_callbackref callback
;
303 /* Opaque callback argument. */
305 /* The current list of templates, if any. */
306 struct d_print_template
*templates
;
307 /* The current list of modifiers (e.g., pointer, reference, etc.),
309 struct d_print_mod
*modifiers
;
310 /* Set to 1 if we saw a demangling error. */
311 int demangle_failure
;
312 /* The current index into any template argument packs we are using
315 /* Number of d_print_flush calls so far. */
316 unsigned long int flush_count
;
317 /* Array of saved scopes for evaluating substitutions. */
318 struct d_saved_scope
*saved_scopes
;
319 /* Number of saved scopes in the above array. */
320 int num_saved_scopes
;
323 #ifdef CP_DEMANGLE_DEBUG
324 static void d_dump (struct demangle_component
*, int);
327 static struct demangle_component
*
328 d_make_empty (struct d_info
*);
330 static struct demangle_component
*
331 d_make_comp (struct d_info
*, enum demangle_component_type
,
332 struct demangle_component
*,
333 struct demangle_component
*);
335 static struct demangle_component
*
336 d_make_name (struct d_info
*, const char *, int);
338 static struct demangle_component
*
339 d_make_demangle_mangled_name (struct d_info
*, const char *);
341 static struct demangle_component
*
342 d_make_builtin_type (struct d_info
*,
343 const struct demangle_builtin_type_info
*);
345 static struct demangle_component
*
346 d_make_operator (struct d_info
*,
347 const struct demangle_operator_info
*);
349 static struct demangle_component
*
350 d_make_extended_operator (struct d_info
*, int,
351 struct demangle_component
*);
353 static struct demangle_component
*
354 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
355 struct demangle_component
*);
357 static struct demangle_component
*
358 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
359 struct demangle_component
*);
361 static struct demangle_component
*
362 d_make_template_param (struct d_info
*, long);
364 static struct demangle_component
*
365 d_make_sub (struct d_info
*, const char *, int);
368 has_return_type (struct demangle_component
*);
371 is_ctor_dtor_or_conversion (struct demangle_component
*);
373 static struct demangle_component
*d_encoding (struct d_info
*, int);
375 static struct demangle_component
*d_name (struct d_info
*);
377 static struct demangle_component
*d_nested_name (struct d_info
*);
379 static struct demangle_component
*d_prefix (struct d_info
*);
381 static struct demangle_component
*d_unqualified_name (struct d_info
*);
383 static struct demangle_component
*d_source_name (struct d_info
*);
385 static long d_number (struct d_info
*);
387 static struct demangle_component
*d_identifier (struct d_info
*, int);
389 static struct demangle_component
*d_operator_name (struct d_info
*);
391 static struct demangle_component
*d_special_name (struct d_info
*);
393 static int d_call_offset (struct d_info
*, int);
395 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
397 static struct demangle_component
**
398 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
400 static struct demangle_component
*
401 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
403 static struct demangle_component
*
404 d_function_type (struct d_info
*);
406 static struct demangle_component
*
407 d_bare_function_type (struct d_info
*, int);
409 static struct demangle_component
*
410 d_class_enum_type (struct d_info
*);
412 static struct demangle_component
*d_array_type (struct d_info
*);
414 static struct demangle_component
*d_vector_type (struct d_info
*);
416 static struct demangle_component
*
417 d_pointer_to_member_type (struct d_info
*);
419 static struct demangle_component
*
420 d_template_param (struct d_info
*);
422 static struct demangle_component
*d_template_args (struct d_info
*);
424 static struct demangle_component
*
425 d_template_arg (struct d_info
*);
427 static struct demangle_component
*d_expression (struct d_info
*);
429 static struct demangle_component
*d_expr_primary (struct d_info
*);
431 static struct demangle_component
*d_local_name (struct d_info
*);
433 static int d_discriminator (struct d_info
*);
435 static struct demangle_component
*d_lambda (struct d_info
*);
437 static struct demangle_component
*d_unnamed_type (struct d_info
*);
439 static struct demangle_component
*
440 d_clone_suffix (struct d_info
*, struct demangle_component
*);
443 d_add_substitution (struct d_info
*, struct demangle_component
*);
445 static struct demangle_component
*d_substitution (struct d_info
*, int);
447 static void d_growable_string_init (struct d_growable_string
*, size_t);
450 d_growable_string_resize (struct d_growable_string
*, size_t);
453 d_growable_string_append_buffer (struct d_growable_string
*,
454 const char *, size_t);
456 d_growable_string_callback_adapter (const char *, size_t, void *);
459 d_print_init (struct d_print_info
*, demangle_callbackref
, void *);
461 static inline void d_print_error (struct d_print_info
*);
463 static inline int d_print_saw_error (struct d_print_info
*);
465 static inline void d_print_flush (struct d_print_info
*);
467 static inline void d_append_char (struct d_print_info
*, char);
469 static inline void d_append_buffer (struct d_print_info
*,
470 const char *, size_t);
472 static inline void d_append_string (struct d_print_info
*, const char *);
474 static inline char d_last_char (struct d_print_info
*);
477 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
480 d_print_java_identifier (struct d_print_info
*, const char *, int);
483 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
486 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
489 d_print_function_type (struct d_print_info
*, int,
490 const struct demangle_component
*,
491 struct d_print_mod
*);
494 d_print_array_type (struct d_print_info
*, int,
495 const struct demangle_component
*,
496 struct d_print_mod
*);
499 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
502 d_print_cast (struct d_print_info
*, int, const struct demangle_component
*);
504 static int d_demangle_callback (const char *, int,
505 demangle_callbackref
, void *);
506 static char *d_demangle (const char *, int, size_t *);
508 #ifdef CP_DEMANGLE_DEBUG
511 d_dump (struct demangle_component
*dc
, int indent
)
518 printf ("failed demangling\n");
522 for (i
= 0; i
< indent
; ++i
)
527 case DEMANGLE_COMPONENT_NAME
:
528 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
530 case DEMANGLE_COMPONENT_TAGGED_NAME
:
531 printf ("tagged name\n");
532 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
533 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
535 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
536 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
538 case DEMANGLE_COMPONENT_CTOR
:
539 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
540 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
542 case DEMANGLE_COMPONENT_DTOR
:
543 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
544 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
546 case DEMANGLE_COMPONENT_SUB_STD
:
547 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
549 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
550 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
552 case DEMANGLE_COMPONENT_OPERATOR
:
553 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
555 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
556 printf ("extended operator with %d args\n",
557 dc
->u
.s_extended_operator
.args
);
558 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
561 case DEMANGLE_COMPONENT_QUAL_NAME
:
562 printf ("qualified name\n");
564 case DEMANGLE_COMPONENT_LOCAL_NAME
:
565 printf ("local name\n");
567 case DEMANGLE_COMPONENT_TYPED_NAME
:
568 printf ("typed name\n");
570 case DEMANGLE_COMPONENT_TEMPLATE
:
571 printf ("template\n");
573 case DEMANGLE_COMPONENT_VTABLE
:
576 case DEMANGLE_COMPONENT_VTT
:
579 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
580 printf ("construction vtable\n");
582 case DEMANGLE_COMPONENT_TYPEINFO
:
583 printf ("typeinfo\n");
585 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
586 printf ("typeinfo name\n");
588 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
589 printf ("typeinfo function\n");
591 case DEMANGLE_COMPONENT_THUNK
:
594 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
595 printf ("virtual thunk\n");
597 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
598 printf ("covariant thunk\n");
600 case DEMANGLE_COMPONENT_JAVA_CLASS
:
601 printf ("java class\n");
603 case DEMANGLE_COMPONENT_GUARD
:
606 case DEMANGLE_COMPONENT_REFTEMP
:
607 printf ("reference temporary\n");
609 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
610 printf ("hidden alias\n");
612 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
613 printf ("transaction clone\n");
615 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
616 printf ("non-transaction clone\n");
618 case DEMANGLE_COMPONENT_RESTRICT
:
619 printf ("restrict\n");
621 case DEMANGLE_COMPONENT_VOLATILE
:
622 printf ("volatile\n");
624 case DEMANGLE_COMPONENT_CONST
:
627 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
628 printf ("restrict this\n");
630 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
631 printf ("volatile this\n");
633 case DEMANGLE_COMPONENT_CONST_THIS
:
634 printf ("const this\n");
636 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
637 printf ("reference this\n");
639 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
640 printf ("rvalue reference this\n");
642 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
643 printf ("vendor type qualifier\n");
645 case DEMANGLE_COMPONENT_POINTER
:
646 printf ("pointer\n");
648 case DEMANGLE_COMPONENT_REFERENCE
:
649 printf ("reference\n");
651 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
652 printf ("rvalue reference\n");
654 case DEMANGLE_COMPONENT_COMPLEX
:
655 printf ("complex\n");
657 case DEMANGLE_COMPONENT_IMAGINARY
:
658 printf ("imaginary\n");
660 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
661 printf ("vendor type\n");
663 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
664 printf ("function type\n");
666 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
667 printf ("array type\n");
669 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
670 printf ("pointer to member type\n");
672 case DEMANGLE_COMPONENT_FIXED_TYPE
:
673 printf ("fixed-point type\n");
675 case DEMANGLE_COMPONENT_ARGLIST
:
676 printf ("argument list\n");
678 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
679 printf ("template argument list\n");
681 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
682 printf ("initializer list\n");
684 case DEMANGLE_COMPONENT_CAST
:
687 case DEMANGLE_COMPONENT_NULLARY
:
688 printf ("nullary operator\n");
690 case DEMANGLE_COMPONENT_UNARY
:
691 printf ("unary operator\n");
693 case DEMANGLE_COMPONENT_BINARY
:
694 printf ("binary operator\n");
696 case DEMANGLE_COMPONENT_BINARY_ARGS
:
697 printf ("binary operator arguments\n");
699 case DEMANGLE_COMPONENT_TRINARY
:
700 printf ("trinary operator\n");
702 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
703 printf ("trinary operator arguments 1\n");
705 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
706 printf ("trinary operator arguments 1\n");
708 case DEMANGLE_COMPONENT_LITERAL
:
709 printf ("literal\n");
711 case DEMANGLE_COMPONENT_LITERAL_NEG
:
712 printf ("negative literal\n");
714 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
715 printf ("java resource\n");
717 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
718 printf ("compound name\n");
720 case DEMANGLE_COMPONENT_CHARACTER
:
721 printf ("character '%c'\n", dc
->u
.s_character
.character
);
723 case DEMANGLE_COMPONENT_DECLTYPE
:
724 printf ("decltype\n");
726 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
727 printf ("pack expansion\n");
729 case DEMANGLE_COMPONENT_TLS_INIT
:
730 printf ("tls init function\n");
732 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
733 printf ("tls wrapper function\n");
735 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
736 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
737 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
739 case DEMANGLE_COMPONENT_LAMBDA
:
740 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
741 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
745 d_dump (d_left (dc
), indent
+ 2);
746 d_dump (d_right (dc
), indent
+ 2);
749 #endif /* CP_DEMANGLE_DEBUG */
751 /* Fill in a DEMANGLE_COMPONENT_NAME. */
753 CP_STATIC_IF_GLIBCPP_V3
755 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
757 if (p
== NULL
|| s
== NULL
|| len
== 0)
759 p
->type
= DEMANGLE_COMPONENT_NAME
;
761 p
->u
.s_name
.len
= len
;
765 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
767 CP_STATIC_IF_GLIBCPP_V3
769 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
770 struct demangle_component
*name
)
772 if (p
== NULL
|| args
< 0 || name
== NULL
)
774 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
775 p
->u
.s_extended_operator
.args
= args
;
776 p
->u
.s_extended_operator
.name
= name
;
780 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
782 CP_STATIC_IF_GLIBCPP_V3
784 cplus_demangle_fill_ctor (struct demangle_component
*p
,
785 enum gnu_v3_ctor_kinds kind
,
786 struct demangle_component
*name
)
790 || (int) kind
< gnu_v3_complete_object_ctor
791 || (int) kind
> gnu_v3_object_ctor_group
)
793 p
->type
= DEMANGLE_COMPONENT_CTOR
;
794 p
->u
.s_ctor
.kind
= kind
;
795 p
->u
.s_ctor
.name
= name
;
799 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
801 CP_STATIC_IF_GLIBCPP_V3
803 cplus_demangle_fill_dtor (struct demangle_component
*p
,
804 enum gnu_v3_dtor_kinds kind
,
805 struct demangle_component
*name
)
809 || (int) kind
< gnu_v3_deleting_dtor
810 || (int) kind
> gnu_v3_object_dtor_group
)
812 p
->type
= DEMANGLE_COMPONENT_DTOR
;
813 p
->u
.s_dtor
.kind
= kind
;
814 p
->u
.s_dtor
.name
= name
;
818 /* Add a new component. */
820 static struct demangle_component
*
821 d_make_empty (struct d_info
*di
)
823 struct demangle_component
*p
;
825 if (di
->next_comp
>= di
->num_comps
)
827 p
= &di
->comps
[di
->next_comp
];
832 /* Add a new generic component. */
834 static struct demangle_component
*
835 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
836 struct demangle_component
*left
,
837 struct demangle_component
*right
)
839 struct demangle_component
*p
;
841 /* We check for errors here. A typical error would be a NULL return
842 from a subroutine. We catch those here, and return NULL
846 /* These types require two parameters. */
847 case DEMANGLE_COMPONENT_QUAL_NAME
:
848 case DEMANGLE_COMPONENT_LOCAL_NAME
:
849 case DEMANGLE_COMPONENT_TYPED_NAME
:
850 case DEMANGLE_COMPONENT_TAGGED_NAME
:
851 case DEMANGLE_COMPONENT_TEMPLATE
:
852 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
853 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
854 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
855 case DEMANGLE_COMPONENT_UNARY
:
856 case DEMANGLE_COMPONENT_BINARY
:
857 case DEMANGLE_COMPONENT_BINARY_ARGS
:
858 case DEMANGLE_COMPONENT_TRINARY
:
859 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
860 case DEMANGLE_COMPONENT_LITERAL
:
861 case DEMANGLE_COMPONENT_LITERAL_NEG
:
862 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
863 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
864 case DEMANGLE_COMPONENT_CLONE
:
865 if (left
== NULL
|| right
== NULL
)
869 /* These types only require one parameter. */
870 case DEMANGLE_COMPONENT_VTABLE
:
871 case DEMANGLE_COMPONENT_VTT
:
872 case DEMANGLE_COMPONENT_TYPEINFO
:
873 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
874 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
875 case DEMANGLE_COMPONENT_THUNK
:
876 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
877 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
878 case DEMANGLE_COMPONENT_JAVA_CLASS
:
879 case DEMANGLE_COMPONENT_GUARD
:
880 case DEMANGLE_COMPONENT_TLS_INIT
:
881 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
882 case DEMANGLE_COMPONENT_REFTEMP
:
883 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
884 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
885 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
886 case DEMANGLE_COMPONENT_POINTER
:
887 case DEMANGLE_COMPONENT_REFERENCE
:
888 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
889 case DEMANGLE_COMPONENT_COMPLEX
:
890 case DEMANGLE_COMPONENT_IMAGINARY
:
891 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
892 case DEMANGLE_COMPONENT_CAST
:
893 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
894 case DEMANGLE_COMPONENT_DECLTYPE
:
895 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
896 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
897 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
898 case DEMANGLE_COMPONENT_NULLARY
:
899 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
904 /* This needs a right parameter, but the left parameter can be
906 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
907 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
912 /* These are allowed to have no parameters--in some cases they
913 will be filled in later. */
914 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
915 case DEMANGLE_COMPONENT_RESTRICT
:
916 case DEMANGLE_COMPONENT_VOLATILE
:
917 case DEMANGLE_COMPONENT_CONST
:
918 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
919 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
920 case DEMANGLE_COMPONENT_CONST_THIS
:
921 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
922 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
923 case DEMANGLE_COMPONENT_ARGLIST
:
924 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
927 /* Other types should not be seen here. */
932 p
= d_make_empty (di
);
936 p
->u
.s_binary
.left
= left
;
937 p
->u
.s_binary
.right
= right
;
942 /* Add a new demangle mangled name component. */
944 static struct demangle_component
*
945 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
947 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
948 return d_make_name (di
, s
, strlen (s
));
950 return d_encoding (di
, 0);
953 /* Add a new name component. */
955 static struct demangle_component
*
956 d_make_name (struct d_info
*di
, const char *s
, int len
)
958 struct demangle_component
*p
;
960 p
= d_make_empty (di
);
961 if (! cplus_demangle_fill_name (p
, s
, len
))
966 /* Add a new builtin type component. */
968 static struct demangle_component
*
969 d_make_builtin_type (struct d_info
*di
,
970 const struct demangle_builtin_type_info
*type
)
972 struct demangle_component
*p
;
976 p
= d_make_empty (di
);
979 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
980 p
->u
.s_builtin
.type
= type
;
985 /* Add a new operator component. */
987 static struct demangle_component
*
988 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
990 struct demangle_component
*p
;
992 p
= d_make_empty (di
);
995 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
996 p
->u
.s_operator
.op
= op
;
1001 /* Add a new extended operator component. */
1003 static struct demangle_component
*
1004 d_make_extended_operator (struct d_info
*di
, int args
,
1005 struct demangle_component
*name
)
1007 struct demangle_component
*p
;
1009 p
= d_make_empty (di
);
1010 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1015 static struct demangle_component
*
1016 d_make_default_arg (struct d_info
*di
, int num
,
1017 struct demangle_component
*sub
)
1019 struct demangle_component
*p
= d_make_empty (di
);
1022 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1023 p
->u
.s_unary_num
.num
= num
;
1024 p
->u
.s_unary_num
.sub
= sub
;
1029 /* Add a new constructor component. */
1031 static struct demangle_component
*
1032 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1033 struct demangle_component
*name
)
1035 struct demangle_component
*p
;
1037 p
= d_make_empty (di
);
1038 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1043 /* Add a new destructor component. */
1045 static struct demangle_component
*
1046 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1047 struct demangle_component
*name
)
1049 struct demangle_component
*p
;
1051 p
= d_make_empty (di
);
1052 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1057 /* Add a new template parameter. */
1059 static struct demangle_component
*
1060 d_make_template_param (struct d_info
*di
, long i
)
1062 struct demangle_component
*p
;
1064 p
= d_make_empty (di
);
1067 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1068 p
->u
.s_number
.number
= i
;
1073 /* Add a new function parameter. */
1075 static struct demangle_component
*
1076 d_make_function_param (struct d_info
*di
, long i
)
1078 struct demangle_component
*p
;
1080 p
= d_make_empty (di
);
1083 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1084 p
->u
.s_number
.number
= i
;
1089 /* Add a new standard substitution component. */
1091 static struct demangle_component
*
1092 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1094 struct demangle_component
*p
;
1096 p
= d_make_empty (di
);
1099 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1100 p
->u
.s_string
.string
= name
;
1101 p
->u
.s_string
.len
= len
;
1106 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1108 TOP_LEVEL is non-zero when called at the top level. */
1110 CP_STATIC_IF_GLIBCPP_V3
1111 struct demangle_component
*
1112 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1114 struct demangle_component
*p
;
1116 if (! d_check_char (di
, '_')
1117 /* Allow missing _ if not at toplevel to work around a
1118 bug in G++ abi-version=2 mangling; see the comment in
1119 write_template_arg. */
1122 if (! d_check_char (di
, 'Z'))
1124 p
= d_encoding (di
, top_level
);
1126 /* If at top level and parsing parameters, check for a clone
1128 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1129 while (d_peek_char (di
) == '.'
1130 && (IS_LOWER (d_peek_next_char (di
))
1131 || d_peek_next_char (di
) == '_'
1132 || IS_DIGIT (d_peek_next_char (di
))))
1133 p
= d_clone_suffix (di
, p
);
1138 /* Return whether a function should have a return type. The argument
1139 is the function name, which may be qualified in various ways. The
1140 rules are that template functions have return types with some
1141 exceptions, function types which are not part of a function name
1142 mangling have return types with some exceptions, and non-template
1143 function names do not have return types. The exceptions are that
1144 constructors, destructors, and conversion operators do not have
1148 has_return_type (struct demangle_component
*dc
)
1156 case DEMANGLE_COMPONENT_TEMPLATE
:
1157 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1158 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1159 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1160 case DEMANGLE_COMPONENT_CONST_THIS
:
1161 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1162 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1163 return has_return_type (d_left (dc
));
1167 /* Return whether a name is a constructor, a destructor, or a
1168 conversion operator. */
1171 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1179 case DEMANGLE_COMPONENT_QUAL_NAME
:
1180 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1181 return is_ctor_dtor_or_conversion (d_right (dc
));
1182 case DEMANGLE_COMPONENT_CTOR
:
1183 case DEMANGLE_COMPONENT_DTOR
:
1184 case DEMANGLE_COMPONENT_CAST
:
1189 /* <encoding> ::= <(function) name> <bare-function-type>
1193 TOP_LEVEL is non-zero when called at the top level, in which case
1194 if DMGL_PARAMS is not set we do not demangle the function
1195 parameters. We only set this at the top level, because otherwise
1196 we would not correctly demangle names in local scopes. */
1198 static struct demangle_component
*
1199 d_encoding (struct d_info
*di
, int top_level
)
1201 char peek
= d_peek_char (di
);
1203 if (peek
== 'G' || peek
== 'T')
1204 return d_special_name (di
);
1207 struct demangle_component
*dc
;
1211 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1213 /* Strip off any initial CV-qualifiers, as they really apply
1214 to the `this' parameter, and they were not output by the
1215 v2 demangler without DMGL_PARAMS. */
1216 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1217 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1218 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1219 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1220 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1223 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1224 there may be CV-qualifiers on its right argument which
1225 really apply here; this happens when parsing a class
1226 which is local to a function. */
1227 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1229 struct demangle_component
*dcr
;
1232 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1233 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1234 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1235 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1236 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1238 dc
->u
.s_binary
.right
= dcr
;
1244 peek
= d_peek_char (di
);
1245 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1247 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1248 d_bare_function_type (di
, has_return_type (dc
)));
1252 /* <tagged-name> ::= <name> B <source-name> */
1254 static struct demangle_component
*
1255 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1258 while (peek
= d_peek_char (di
),
1261 struct demangle_component
*tag
;
1263 tag
= d_source_name (di
);
1264 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1269 /* <name> ::= <nested-name>
1271 ::= <unscoped-template-name> <template-args>
1274 <unscoped-name> ::= <unqualified-name>
1275 ::= St <unqualified-name>
1277 <unscoped-template-name> ::= <unscoped-name>
1281 static struct demangle_component
*
1282 d_name (struct d_info
*di
)
1284 char peek
= d_peek_char (di
);
1285 struct demangle_component
*dc
;
1290 return d_nested_name (di
);
1293 return d_local_name (di
);
1296 return d_unqualified_name (di
);
1302 if (d_peek_next_char (di
) != 't')
1304 dc
= d_substitution (di
, 0);
1310 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1311 d_make_name (di
, "std", 3),
1312 d_unqualified_name (di
));
1317 if (d_peek_char (di
) != 'I')
1319 /* The grammar does not permit this case to occur if we
1320 called d_substitution() above (i.e., subst == 1). We
1321 don't bother to check. */
1325 /* This is <template-args>, which means that we just saw
1326 <unscoped-template-name>, which is a substitution
1327 candidate if we didn't just get it from a
1331 if (! d_add_substitution (di
, dc
))
1334 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1335 d_template_args (di
));
1343 dc
= d_unqualified_name (di
);
1344 if (d_peek_char (di
) == 'I')
1346 /* This is <template-args>, which means that we just saw
1347 <unscoped-template-name>, which is a substitution
1349 if (! d_add_substitution (di
, dc
))
1351 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1352 d_template_args (di
));
1358 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1359 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1362 static struct demangle_component
*
1363 d_nested_name (struct d_info
*di
)
1365 struct demangle_component
*ret
;
1366 struct demangle_component
**pret
;
1367 struct demangle_component
*rqual
;
1369 if (! d_check_char (di
, 'N'))
1372 pret
= d_cv_qualifiers (di
, &ret
, 1);
1376 /* Parse the ref-qualifier now and then attach it
1377 once we have something to attach it to. */
1378 rqual
= d_ref_qualifier (di
, NULL
);
1380 *pret
= d_prefix (di
);
1386 d_left (rqual
) = ret
;
1390 if (! d_check_char (di
, 'E'))
1396 /* <prefix> ::= <prefix> <unqualified-name>
1397 ::= <template-prefix> <template-args>
1398 ::= <template-param>
1403 <template-prefix> ::= <prefix> <(template) unqualified-name>
1404 ::= <template-param>
1408 static struct demangle_component
*
1409 d_prefix (struct d_info
*di
)
1411 struct demangle_component
*ret
= NULL
;
1416 enum demangle_component_type comb_type
;
1417 struct demangle_component
*dc
;
1419 peek
= d_peek_char (di
);
1423 /* The older code accepts a <local-name> here, but I don't see
1424 that in the grammar. The older code does not accept a
1425 <template-param> here. */
1427 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1430 char peek2
= d_peek_next_char (di
);
1431 if (peek2
== 'T' || peek2
== 't')
1433 dc
= cplus_demangle_type (di
);
1435 /* Destructor name. */
1436 dc
= d_unqualified_name (di
);
1438 else if (IS_DIGIT (peek
)
1443 dc
= d_unqualified_name (di
);
1444 else if (peek
== 'S')
1445 dc
= d_substitution (di
, 1);
1446 else if (peek
== 'I')
1450 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1451 dc
= d_template_args (di
);
1453 else if (peek
== 'T')
1454 dc
= d_template_param (di
);
1455 else if (peek
== 'E')
1457 else if (peek
== 'M')
1459 /* Initializer scope for a lambda. We don't need to represent
1460 this; the normal code will just treat the variable as a type
1461 scope, which gives appropriate output. */
1473 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1475 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1477 if (! d_add_substitution (di
, ret
))
1483 /* <unqualified-name> ::= <operator-name>
1484 ::= <ctor-dtor-name>
1486 ::= <local-source-name>
1488 <local-source-name> ::= L <source-name> <discriminator>
1491 static struct demangle_component
*
1492 d_unqualified_name (struct d_info
*di
)
1494 struct demangle_component
*ret
;
1497 peek
= d_peek_char (di
);
1498 if (IS_DIGIT (peek
))
1499 ret
= d_source_name (di
);
1500 else if (IS_LOWER (peek
))
1502 ret
= d_operator_name (di
);
1503 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1505 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1506 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1507 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1508 d_source_name (di
));
1511 else if (peek
== 'C' || peek
== 'D')
1512 ret
= d_ctor_dtor_name (di
);
1513 else if (peek
== 'L')
1517 ret
= d_source_name (di
);
1520 if (! d_discriminator (di
))
1523 else if (peek
== 'U')
1525 switch (d_peek_next_char (di
))
1528 ret
= d_lambda (di
);
1531 ret
= d_unnamed_type (di
);
1540 if (d_peek_char (di
) == 'B')
1541 ret
= d_abi_tags (di
, ret
);
1545 /* <source-name> ::= <(positive length) number> <identifier> */
1547 static struct demangle_component
*
1548 d_source_name (struct d_info
*di
)
1551 struct demangle_component
*ret
;
1553 len
= d_number (di
);
1556 ret
= d_identifier (di
, len
);
1557 di
->last_name
= ret
;
1561 /* number ::= [n] <(non-negative decimal integer)> */
1564 d_number (struct d_info
*di
)
1571 peek
= d_peek_char (di
);
1576 peek
= d_peek_char (di
);
1582 if (! IS_DIGIT (peek
))
1588 ret
= ret
* 10 + peek
- '0';
1590 peek
= d_peek_char (di
);
1594 /* Like d_number, but returns a demangle_component. */
1596 static struct demangle_component
*
1597 d_number_component (struct d_info
*di
)
1599 struct demangle_component
*ret
= d_make_empty (di
);
1602 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1603 ret
->u
.s_number
.number
= d_number (di
);
1608 /* identifier ::= <(unqualified source code identifier)> */
1610 static struct demangle_component
*
1611 d_identifier (struct d_info
*di
, int len
)
1617 if (di
->send
- name
< len
)
1620 d_advance (di
, len
);
1622 /* A Java mangled name may have a trailing '$' if it is a C++
1623 keyword. This '$' is not included in the length count. We just
1625 if ((di
->options
& DMGL_JAVA
) != 0
1626 && d_peek_char (di
) == '$')
1629 /* Look for something which looks like a gcc encoding of an
1630 anonymous namespace, and replace it with a more user friendly
1632 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1633 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1634 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1638 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1639 if ((*s
== '.' || *s
== '_' || *s
== '$')
1642 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1643 return d_make_name (di
, "(anonymous namespace)",
1644 sizeof "(anonymous namespace)" - 1);
1648 return d_make_name (di
, name
, len
);
1651 /* operator_name ::= many different two character encodings.
1653 ::= v <digit> <source-name>
1655 This list is sorted for binary search. */
1657 #define NL(s) s, (sizeof s) - 1
1659 CP_STATIC_IF_GLIBCPP_V3
1660 const struct demangle_operator_info cplus_demangle_operators
[] =
1662 { "aN", NL ("&="), 2 },
1663 { "aS", NL ("="), 2 },
1664 { "aa", NL ("&&"), 2 },
1665 { "ad", NL ("&"), 1 },
1666 { "an", NL ("&"), 2 },
1667 { "at", NL ("alignof "), 1 },
1668 { "az", NL ("alignof "), 1 },
1669 { "cc", NL ("const_cast"), 2 },
1670 { "cl", NL ("()"), 2 },
1671 { "cm", NL (","), 2 },
1672 { "co", NL ("~"), 1 },
1673 { "dV", NL ("/="), 2 },
1674 { "da", NL ("delete[] "), 1 },
1675 { "dc", NL ("dynamic_cast"), 2 },
1676 { "de", NL ("*"), 1 },
1677 { "dl", NL ("delete "), 1 },
1678 { "ds", NL (".*"), 2 },
1679 { "dt", NL ("."), 2 },
1680 { "dv", NL ("/"), 2 },
1681 { "eO", NL ("^="), 2 },
1682 { "eo", NL ("^"), 2 },
1683 { "eq", NL ("=="), 2 },
1684 { "ge", NL (">="), 2 },
1685 { "gs", NL ("::"), 1 },
1686 { "gt", NL (">"), 2 },
1687 { "ix", NL ("[]"), 2 },
1688 { "lS", NL ("<<="), 2 },
1689 { "le", NL ("<="), 2 },
1690 { "li", NL ("operator\"\" "), 1 },
1691 { "ls", NL ("<<"), 2 },
1692 { "lt", NL ("<"), 2 },
1693 { "mI", NL ("-="), 2 },
1694 { "mL", NL ("*="), 2 },
1695 { "mi", NL ("-"), 2 },
1696 { "ml", NL ("*"), 2 },
1697 { "mm", NL ("--"), 1 },
1698 { "na", NL ("new[]"), 3 },
1699 { "ne", NL ("!="), 2 },
1700 { "ng", NL ("-"), 1 },
1701 { "nt", NL ("!"), 1 },
1702 { "nw", NL ("new"), 3 },
1703 { "oR", NL ("|="), 2 },
1704 { "oo", NL ("||"), 2 },
1705 { "or", NL ("|"), 2 },
1706 { "pL", NL ("+="), 2 },
1707 { "pl", NL ("+"), 2 },
1708 { "pm", NL ("->*"), 2 },
1709 { "pp", NL ("++"), 1 },
1710 { "ps", NL ("+"), 1 },
1711 { "pt", NL ("->"), 2 },
1712 { "qu", NL ("?"), 3 },
1713 { "rM", NL ("%="), 2 },
1714 { "rS", NL (">>="), 2 },
1715 { "rc", NL ("reinterpret_cast"), 2 },
1716 { "rm", NL ("%"), 2 },
1717 { "rs", NL (">>"), 2 },
1718 { "sc", NL ("static_cast"), 2 },
1719 { "st", NL ("sizeof "), 1 },
1720 { "sz", NL ("sizeof "), 1 },
1721 { "tr", NL ("throw"), 0 },
1722 { "tw", NL ("throw "), 1 },
1723 { NULL
, NULL
, 0, 0 }
1726 static struct demangle_component
*
1727 d_operator_name (struct d_info
*di
)
1732 c1
= d_next_char (di
);
1733 c2
= d_next_char (di
);
1734 if (c1
== 'v' && IS_DIGIT (c2
))
1735 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1736 else if (c1
== 'c' && c2
== 'v')
1737 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1738 cplus_demangle_type (di
), NULL
);
1741 /* LOW is the inclusive lower bound. */
1743 /* HIGH is the exclusive upper bound. We subtract one to ignore
1744 the sentinel at the end of the array. */
1745 int high
= ((sizeof (cplus_demangle_operators
)
1746 / sizeof (cplus_demangle_operators
[0]))
1752 const struct demangle_operator_info
*p
;
1754 i
= low
+ (high
- low
) / 2;
1755 p
= cplus_demangle_operators
+ i
;
1757 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1758 return d_make_operator (di
, p
);
1760 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1770 static struct demangle_component
*
1771 d_make_character (struct d_info
*di
, int c
)
1773 struct demangle_component
*p
;
1774 p
= d_make_empty (di
);
1777 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1778 p
->u
.s_character
.character
= c
;
1783 static struct demangle_component
*
1784 d_java_resource (struct d_info
*di
)
1786 struct demangle_component
*p
= NULL
;
1787 struct demangle_component
*next
= NULL
;
1792 len
= d_number (di
);
1796 /* Eat the leading '_'. */
1797 if (d_next_char (di
) != '_')
1810 /* Each chunk is either a '$' escape... */
1828 next
= d_make_character (di
, c
);
1836 /* ... or a sequence of characters. */
1839 while (i
< len
&& str
[i
] && str
[i
] != '$')
1842 next
= d_make_name (di
, str
, i
);
1855 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1861 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1866 /* <special-name> ::= TV <type>
1870 ::= GV <(object) name>
1871 ::= T <call-offset> <(base) encoding>
1872 ::= Tc <call-offset> <call-offset> <(base) encoding>
1873 Also g++ extensions:
1874 ::= TC <type> <(offset) number> _ <(base) type>
1879 ::= Gr <resource name>
1884 static struct demangle_component
*
1885 d_special_name (struct d_info
*di
)
1887 di
->expansion
+= 20;
1888 if (d_check_char (di
, 'T'))
1890 switch (d_next_char (di
))
1894 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1895 cplus_demangle_type (di
), NULL
);
1897 di
->expansion
-= 10;
1898 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1899 cplus_demangle_type (di
), NULL
);
1901 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1902 cplus_demangle_type (di
), NULL
);
1904 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1905 cplus_demangle_type (di
), NULL
);
1908 if (! d_call_offset (di
, 'h'))
1910 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1911 d_encoding (di
, 0), NULL
);
1914 if (! d_call_offset (di
, 'v'))
1916 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1917 d_encoding (di
, 0), NULL
);
1920 if (! d_call_offset (di
, '\0'))
1922 if (! d_call_offset (di
, '\0'))
1924 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1925 d_encoding (di
, 0), NULL
);
1929 struct demangle_component
*derived_type
;
1931 struct demangle_component
*base_type
;
1933 derived_type
= cplus_demangle_type (di
);
1934 offset
= d_number (di
);
1937 if (! d_check_char (di
, '_'))
1939 base_type
= cplus_demangle_type (di
);
1940 /* We don't display the offset. FIXME: We should display
1941 it in verbose mode. */
1943 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1944 base_type
, derived_type
);
1948 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1949 cplus_demangle_type (di
), NULL
);
1951 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1952 cplus_demangle_type (di
), NULL
);
1955 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
1959 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
1966 else if (d_check_char (di
, 'G'))
1968 switch (d_next_char (di
))
1971 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1975 struct demangle_component
*name
= d_name (di
);
1976 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
1977 d_number_component (di
));
1981 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1982 d_encoding (di
, 0), NULL
);
1985 switch (d_next_char (di
))
1988 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
1989 d_encoding (di
, 0), NULL
);
1991 /* ??? The proposal is that other letters (such as 'h') stand
1992 for different variants of transaction cloning, such as
1993 compiling directly for hardware transaction support. But
1994 they still should all be transactional clones of some sort
1995 so go ahead and call them that. */
1997 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
1998 d_encoding (di
, 0), NULL
);
2002 return d_java_resource (di
);
2012 /* <call-offset> ::= h <nv-offset> _
2015 <nv-offset> ::= <(offset) number>
2017 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2019 The C parameter, if not '\0', is a character we just read which is
2020 the start of the <call-offset>.
2022 We don't display the offset information anywhere. FIXME: We should
2023 display it in verbose mode. */
2026 d_call_offset (struct d_info
*di
, int c
)
2029 c
= d_next_char (di
);
2036 if (! d_check_char (di
, '_'))
2043 if (! d_check_char (di
, '_'))
2049 /* <ctor-dtor-name> ::= C1
2057 static struct demangle_component
*
2058 d_ctor_dtor_name (struct d_info
*di
)
2060 if (di
->last_name
!= NULL
)
2062 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2063 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2064 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2065 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2067 switch (d_peek_char (di
))
2071 enum gnu_v3_ctor_kinds kind
;
2073 switch (d_peek_next_char (di
))
2076 kind
= gnu_v3_complete_object_ctor
;
2079 kind
= gnu_v3_base_object_ctor
;
2082 kind
= gnu_v3_complete_object_allocating_ctor
;
2085 kind
= gnu_v3_object_ctor_group
;
2091 return d_make_ctor (di
, kind
, di
->last_name
);
2096 enum gnu_v3_dtor_kinds kind
;
2098 switch (d_peek_next_char (di
))
2101 kind
= gnu_v3_deleting_dtor
;
2104 kind
= gnu_v3_complete_object_dtor
;
2107 kind
= gnu_v3_base_object_dtor
;
2110 kind
= gnu_v3_object_dtor_group
;
2116 return d_make_dtor (di
, kind
, di
->last_name
);
2124 /* <type> ::= <builtin-type>
2126 ::= <class-enum-type>
2128 ::= <pointer-to-member-type>
2129 ::= <template-param>
2130 ::= <template-template-param> <template-args>
2132 ::= <CV-qualifiers> <type>
2135 ::= O <type> (C++0x)
2138 ::= U <source-name> <type>
2140 <builtin-type> ::= various one letter codes
2144 CP_STATIC_IF_GLIBCPP_V3
2145 const struct demangle_builtin_type_info
2146 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2148 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2149 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2150 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2151 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2152 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2153 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2154 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2155 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2156 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2157 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2158 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2159 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2160 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2161 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2162 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2164 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2165 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2166 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2167 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2168 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2169 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2170 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2171 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2172 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2173 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2174 D_PRINT_UNSIGNED_LONG_LONG
},
2175 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2176 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2177 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2178 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2179 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2180 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2181 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2182 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2186 CP_STATIC_IF_GLIBCPP_V3
2187 struct demangle_component
*
2188 cplus_demangle_type (struct d_info
*di
)
2191 struct demangle_component
*ret
;
2194 /* The ABI specifies that when CV-qualifiers are used, the base type
2195 is substitutable, and the fully qualified type is substitutable,
2196 but the base type with a strict subset of the CV-qualifiers is
2197 not substitutable. The natural recursive implementation of the
2198 CV-qualifiers would cause subsets to be substitutable, so instead
2199 we pull them all off now.
2201 FIXME: The ABI says that order-insensitive vendor qualifiers
2202 should be handled in the same way, but we have no way to tell
2203 which vendor qualifiers are order-insensitive and which are
2204 order-sensitive. So we just assume that they are all
2205 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2206 __vector, and it treats it as order-sensitive when mangling
2209 peek
= d_peek_char (di
);
2210 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2212 struct demangle_component
**pret
;
2214 pret
= d_cv_qualifiers (di
, &ret
, 0);
2217 if (d_peek_char (di
) == 'F')
2219 /* cv-qualifiers before a function type apply to 'this',
2220 so avoid adding the unqualified function type to
2221 the substitution list. */
2222 *pret
= d_function_type (di
);
2225 *pret
= cplus_demangle_type (di
);
2228 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2229 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2231 /* Move the ref-qualifier outside the cv-qualifiers so that
2232 they are printed in the right order. */
2233 struct demangle_component
*fn
= d_left (*pret
);
2234 d_left (*pret
) = ret
;
2238 if (! d_add_substitution (di
, ret
))
2247 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2248 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2249 case 'o': case 's': case 't':
2250 case 'v': case 'w': case 'x': case 'y': case 'z':
2251 ret
= d_make_builtin_type (di
,
2252 &cplus_demangle_builtin_types
[peek
- 'a']);
2253 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2260 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2261 d_source_name (di
), NULL
);
2265 ret
= d_function_type (di
);
2268 case '0': case '1': case '2': case '3': case '4':
2269 case '5': case '6': case '7': case '8': case '9':
2272 ret
= d_class_enum_type (di
);
2276 ret
= d_array_type (di
);
2280 ret
= d_pointer_to_member_type (di
);
2284 ret
= d_template_param (di
);
2285 if (d_peek_char (di
) == 'I')
2287 /* This is <template-template-param> <template-args>. The
2288 <template-template-param> part is a substitution
2290 if (! d_add_substitution (di
, ret
))
2292 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2293 d_template_args (di
));
2298 /* If this is a special substitution, then it is the start of
2299 <class-enum-type>. */
2303 peek_next
= d_peek_next_char (di
);
2304 if (IS_DIGIT (peek_next
)
2306 || IS_UPPER (peek_next
))
2308 ret
= d_substitution (di
, 0);
2309 /* The substituted name may have been a template name and
2310 may be followed by tepmlate args. */
2311 if (d_peek_char (di
) == 'I')
2312 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2313 d_template_args (di
));
2319 ret
= d_class_enum_type (di
);
2320 /* If the substitution was a complete type, then it is not
2321 a new substitution candidate. However, if the
2322 substitution was followed by template arguments, then
2323 the whole thing is a substitution candidate. */
2324 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2332 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2333 cplus_demangle_type (di
), NULL
);
2338 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2339 cplus_demangle_type (di
), NULL
);
2344 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2345 cplus_demangle_type (di
), NULL
);
2350 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2351 cplus_demangle_type (di
), NULL
);
2356 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2357 cplus_demangle_type (di
), NULL
);
2362 ret
= d_source_name (di
);
2363 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2364 cplus_demangle_type (di
), ret
);
2370 peek
= d_next_char (di
);
2375 /* decltype (expression) */
2376 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2377 d_expression (di
), NULL
);
2378 if (ret
&& d_next_char (di
) != 'E')
2384 /* Pack expansion. */
2385 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2386 cplus_demangle_type (di
), NULL
);
2392 ret
= d_make_name (di
, "auto", 4);
2396 /* 32-bit decimal floating point */
2397 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2398 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2402 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2403 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2407 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2408 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2411 /* 16-bit half-precision FP */
2412 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2413 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2417 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2418 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2422 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2423 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2427 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2428 ret
= d_make_empty (di
);
2429 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2430 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2431 /* For demangling we don't care about the bits. */
2433 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2434 if (ret
->u
.s_fixed
.length
== NULL
)
2437 peek
= d_next_char (di
);
2438 ret
->u
.s_fixed
.sat
= (peek
== 's');
2442 ret
= d_vector_type (di
);
2447 /* decltype(nullptr) */
2448 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2449 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2463 if (! d_add_substitution (di
, ret
))
2470 /* <CV-qualifiers> ::= [r] [V] [K] */
2472 static struct demangle_component
**
2473 d_cv_qualifiers (struct d_info
*di
,
2474 struct demangle_component
**pret
, int member_fn
)
2476 struct demangle_component
**pstart
;
2480 peek
= d_peek_char (di
);
2481 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2483 enum demangle_component_type t
;
2489 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2490 : DEMANGLE_COMPONENT_RESTRICT
);
2491 di
->expansion
+= sizeof "restrict";
2493 else if (peek
== 'V')
2496 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2497 : DEMANGLE_COMPONENT_VOLATILE
);
2498 di
->expansion
+= sizeof "volatile";
2503 ? DEMANGLE_COMPONENT_CONST_THIS
2504 : DEMANGLE_COMPONENT_CONST
);
2505 di
->expansion
+= sizeof "const";
2508 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2511 pret
= &d_left (*pret
);
2513 peek
= d_peek_char (di
);
2516 if (!member_fn
&& peek
== 'F')
2518 while (pstart
!= pret
)
2520 switch ((*pstart
)->type
)
2522 case DEMANGLE_COMPONENT_RESTRICT
:
2523 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2525 case DEMANGLE_COMPONENT_VOLATILE
:
2526 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2528 case DEMANGLE_COMPONENT_CONST
:
2529 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2534 pstart
= &d_left (*pstart
);
2541 /* <ref-qualifier> ::= R
2544 static struct demangle_component
*
2545 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2547 struct demangle_component
*ret
= sub
;
2550 peek
= d_peek_char (di
);
2551 if (peek
== 'R' || peek
== 'O')
2553 enum demangle_component_type t
;
2556 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2557 di
->expansion
+= sizeof "&";
2561 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2562 di
->expansion
+= sizeof "&&";
2566 ret
= d_make_comp (di
, t
, ret
, NULL
);
2572 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
2574 static struct demangle_component
*
2575 d_function_type (struct d_info
*di
)
2577 struct demangle_component
*ret
;
2579 if (! d_check_char (di
, 'F'))
2581 if (d_peek_char (di
) == 'Y')
2583 /* Function has C linkage. We don't print this information.
2584 FIXME: We should print it in verbose mode. */
2587 ret
= d_bare_function_type (di
, 1);
2588 ret
= d_ref_qualifier (di
, ret
);
2590 if (! d_check_char (di
, 'E'))
2597 static struct demangle_component
*
2598 d_parmlist (struct d_info
*di
)
2600 struct demangle_component
*tl
;
2601 struct demangle_component
**ptl
;
2607 struct demangle_component
*type
;
2609 char peek
= d_peek_char (di
);
2610 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2612 if ((peek
== 'R' || peek
== 'O')
2613 && d_peek_next_char (di
) == 'E')
2614 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2616 type
= cplus_demangle_type (di
);
2619 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2622 ptl
= &d_right (*ptl
);
2625 /* There should be at least one parameter type besides the optional
2626 return type. A function which takes no arguments will have a
2627 single parameter type void. */
2631 /* If we have a single parameter type void, omit it. */
2632 if (d_right (tl
) == NULL
2633 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2634 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2636 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2643 /* <bare-function-type> ::= [J]<type>+ */
2645 static struct demangle_component
*
2646 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2648 struct demangle_component
*return_type
;
2649 struct demangle_component
*tl
;
2652 /* Detect special qualifier indicating that the first argument
2653 is the return type. */
2654 peek
= d_peek_char (di
);
2658 has_return_type
= 1;
2661 if (has_return_type
)
2663 return_type
= cplus_demangle_type (di
);
2664 if (return_type
== NULL
)
2670 tl
= d_parmlist (di
);
2674 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2678 /* <class-enum-type> ::= <name> */
2680 static struct demangle_component
*
2681 d_class_enum_type (struct d_info
*di
)
2686 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2687 ::= A [<(dimension) expression>] _ <(element) type>
2690 static struct demangle_component
*
2691 d_array_type (struct d_info
*di
)
2694 struct demangle_component
*dim
;
2696 if (! d_check_char (di
, 'A'))
2699 peek
= d_peek_char (di
);
2702 else if (IS_DIGIT (peek
))
2710 peek
= d_peek_char (di
);
2712 while (IS_DIGIT (peek
));
2713 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2719 dim
= d_expression (di
);
2724 if (! d_check_char (di
, '_'))
2727 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2728 cplus_demangle_type (di
));
2731 /* <vector-type> ::= Dv <number> _ <type>
2732 ::= Dv _ <expression> _ <type> */
2734 static struct demangle_component
*
2735 d_vector_type (struct d_info
*di
)
2738 struct demangle_component
*dim
;
2740 peek
= d_peek_char (di
);
2744 dim
= d_expression (di
);
2747 dim
= d_number_component (di
);
2752 if (! d_check_char (di
, '_'))
2755 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2756 cplus_demangle_type (di
));
2759 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2761 static struct demangle_component
*
2762 d_pointer_to_member_type (struct d_info
*di
)
2764 struct demangle_component
*cl
;
2765 struct demangle_component
*mem
;
2767 if (! d_check_char (di
, 'M'))
2770 cl
= cplus_demangle_type (di
);
2774 /* The ABI says, "The type of a non-static member function is considered
2775 to be different, for the purposes of substitution, from the type of a
2776 namespace-scope or static member function whose type appears
2777 similar. The types of two non-static member functions are considered
2778 to be different, for the purposes of substitution, if the functions
2779 are members of different classes. In other words, for the purposes of
2780 substitution, the class of which the function is a member is
2781 considered part of the type of function."
2783 For a pointer to member function, this call to cplus_demangle_type
2784 will end up adding a (possibly qualified) non-member function type to
2785 the substitution table, which is not correct; however, the member
2786 function type will never be used in a substitution, so putting the
2787 wrong type in the substitution table is harmless. */
2789 mem
= cplus_demangle_type (di
);
2793 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2796 /* <non-negative number> _ */
2799 d_compact_number (struct d_info
*di
)
2802 if (d_peek_char (di
) == '_')
2804 else if (d_peek_char (di
) == 'n')
2807 num
= d_number (di
) + 1;
2809 if (! d_check_char (di
, '_'))
2814 /* <template-param> ::= T_
2815 ::= T <(parameter-2 non-negative) number> _
2818 static struct demangle_component
*
2819 d_template_param (struct d_info
*di
)
2823 if (! d_check_char (di
, 'T'))
2826 param
= d_compact_number (di
);
2832 return d_make_template_param (di
, param
);
2835 /* <template-args> ::= I <template-arg>+ E */
2837 static struct demangle_component
*
2838 d_template_args (struct d_info
*di
)
2840 struct demangle_component
*hold_last_name
;
2841 struct demangle_component
*al
;
2842 struct demangle_component
**pal
;
2844 /* Preserve the last name we saw--don't let the template arguments
2845 clobber it, as that would give us the wrong name for a subsequent
2846 constructor or destructor. */
2847 hold_last_name
= di
->last_name
;
2849 if (d_peek_char (di
) != 'I'
2850 && d_peek_char (di
) != 'J')
2854 if (d_peek_char (di
) == 'E')
2856 /* An argument pack can be empty. */
2858 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2865 struct demangle_component
*a
;
2867 a
= d_template_arg (di
);
2871 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2874 pal
= &d_right (*pal
);
2876 if (d_peek_char (di
) == 'E')
2883 di
->last_name
= hold_last_name
;
2888 /* <template-arg> ::= <type>
2889 ::= X <expression> E
2893 static struct demangle_component
*
2894 d_template_arg (struct d_info
*di
)
2896 struct demangle_component
*ret
;
2898 switch (d_peek_char (di
))
2902 ret
= d_expression (di
);
2903 if (! d_check_char (di
, 'E'))
2908 return d_expr_primary (di
);
2912 /* An argument pack. */
2913 return d_template_args (di
);
2916 return cplus_demangle_type (di
);
2920 /* Parse a sequence of expressions until we hit the terminator
2923 static struct demangle_component
*
2924 d_exprlist (struct d_info
*di
, char terminator
)
2926 struct demangle_component
*list
= NULL
;
2927 struct demangle_component
**p
= &list
;
2929 if (d_peek_char (di
) == terminator
)
2932 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2937 struct demangle_component
*arg
= d_expression (di
);
2941 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2946 if (d_peek_char (di
) == terminator
)
2956 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
2957 dynamic_cast, static_cast or reinterpret_cast. */
2960 op_is_new_cast (struct demangle_component
*op
)
2962 const char *code
= op
->u
.s_operator
.op
->code
;
2963 return (code
[1] == 'c'
2964 && (code
[0] == 's' || code
[0] == 'd'
2965 || code
[0] == 'c' || code
[0] == 'r'));
2968 /* <expression> ::= <(unary) operator-name> <expression>
2969 ::= <(binary) operator-name> <expression> <expression>
2970 ::= <(trinary) operator-name> <expression> <expression> <expression>
2971 ::= cl <expression>+ E
2973 ::= <template-param>
2974 ::= sr <type> <unqualified-name>
2975 ::= sr <type> <unqualified-name> <template-args>
2979 static struct demangle_component
*
2980 d_expression (struct d_info
*di
)
2984 peek
= d_peek_char (di
);
2986 return d_expr_primary (di
);
2987 else if (peek
== 'T')
2988 return d_template_param (di
);
2989 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2991 struct demangle_component
*type
;
2992 struct demangle_component
*name
;
2995 type
= cplus_demangle_type (di
);
2996 name
= d_unqualified_name (di
);
2997 if (d_peek_char (di
) != 'I')
2998 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3000 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3001 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3002 d_template_args (di
)));
3004 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3007 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3008 d_expression (di
), NULL
);
3010 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3012 /* Function parameter used in a late-specified return type. */
3015 if (d_peek_char (di
) == 'T')
3017 /* 'this' parameter. */
3023 index
= d_compact_number (di
) + 1;
3027 return d_make_function_param (di
, index
);
3029 else if (IS_DIGIT (peek
)
3030 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3032 /* We can get an unqualified name as an expression in the case of
3033 a dependent function call, i.e. decltype(f(t)). */
3034 struct demangle_component
*name
;
3037 /* operator-function-id, i.e. operator+(t). */
3040 name
= d_unqualified_name (di
);
3043 if (d_peek_char (di
) == 'I')
3044 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3045 d_template_args (di
));
3049 else if ((peek
== 'i' || peek
== 't')
3050 && d_peek_next_char (di
) == 'l')
3052 /* Brace-enclosed initializer list, untyped or typed. */
3053 struct demangle_component
*type
= NULL
;
3055 type
= cplus_demangle_type (di
);
3057 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3058 type
, d_exprlist (di
, 'E'));
3062 struct demangle_component
*op
;
3063 const char *code
= NULL
;
3066 op
= d_operator_name (di
);
3070 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3072 code
= op
->u
.s_operator
.op
->code
;
3073 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3074 if (strcmp (code
, "st") == 0)
3075 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3076 cplus_demangle_type (di
));
3083 case DEMANGLE_COMPONENT_OPERATOR
:
3084 args
= op
->u
.s_operator
.op
->args
;
3086 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3087 args
= op
->u
.s_extended_operator
.args
;
3089 case DEMANGLE_COMPONENT_CAST
:
3097 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3101 struct demangle_component
*operand
;
3104 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3105 && code
[1] == code
[0])
3106 /* pp_ and mm_ are the prefix variants. */
3107 suffix
= !d_check_char (di
, '_');
3109 if (op
->type
== DEMANGLE_COMPONENT_CAST
3110 && d_check_char (di
, '_'))
3111 operand
= d_exprlist (di
, 'E');
3113 operand
= d_expression (di
);
3116 /* Indicate the suffix variant for d_print_comp. */
3117 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3119 DEMANGLE_COMPONENT_BINARY_ARGS
,
3122 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3127 struct demangle_component
*left
;
3128 struct demangle_component
*right
;
3130 if (op_is_new_cast (op
))
3131 left
= cplus_demangle_type (di
);
3133 left
= d_expression (di
);
3134 if (!strcmp (code
, "cl"))
3135 right
= d_exprlist (di
, 'E');
3136 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3138 right
= d_unqualified_name (di
);
3139 if (d_peek_char (di
) == 'I')
3140 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3141 right
, d_template_args (di
));
3144 right
= d_expression (di
);
3146 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3148 DEMANGLE_COMPONENT_BINARY_ARGS
,
3153 struct demangle_component
*first
;
3154 struct demangle_component
*second
;
3155 struct demangle_component
*third
;
3157 if (!strcmp (code
, "qu"))
3159 /* ?: expression. */
3160 first
= d_expression (di
);
3161 second
= d_expression (di
);
3162 third
= d_expression (di
);
3164 else if (code
[0] == 'n')
3166 /* new-expression. */
3167 if (code
[1] != 'w' && code
[1] != 'a')
3169 first
= d_exprlist (di
, '_');
3170 second
= cplus_demangle_type (di
);
3171 if (d_peek_char (di
) == 'E')
3176 else if (d_peek_char (di
) == 'p'
3177 && d_peek_next_char (di
) == 'i')
3179 /* Parenthesized initializer. */
3181 third
= d_exprlist (di
, 'E');
3183 else if (d_peek_char (di
) == 'i'
3184 && d_peek_next_char (di
) == 'l')
3185 /* initializer-list. */
3186 third
= d_expression (di
);
3192 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3194 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3197 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3206 /* <expr-primary> ::= L <type> <(value) number> E
3207 ::= L <type> <(value) float> E
3208 ::= L <mangled-name> E
3211 static struct demangle_component
*
3212 d_expr_primary (struct d_info
*di
)
3214 struct demangle_component
*ret
;
3216 if (! d_check_char (di
, 'L'))
3218 if (d_peek_char (di
) == '_'
3219 /* Workaround for G++ bug; see comment in write_template_arg. */
3220 || d_peek_char (di
) == 'Z')
3221 ret
= cplus_demangle_mangled_name (di
, 0);
3224 struct demangle_component
*type
;
3225 enum demangle_component_type t
;
3228 type
= cplus_demangle_type (di
);
3232 /* If we have a type we know how to print, we aren't going to
3233 print the type name itself. */
3234 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3235 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3236 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3238 /* Rather than try to interpret the literal value, we just
3239 collect it as a string. Note that it's possible to have a
3240 floating point literal here. The ABI specifies that the
3241 format of such literals is machine independent. That's fine,
3242 but what's not fine is that versions of g++ up to 3.2 with
3243 -fabi-version=1 used upper case letters in the hex constant,
3244 and dumped out gcc's internal representation. That makes it
3245 hard to tell where the constant ends, and hard to dump the
3246 constant in any readable form anyhow. We don't attempt to
3247 handle these cases. */
3249 t
= DEMANGLE_COMPONENT_LITERAL
;
3250 if (d_peek_char (di
) == 'n')
3252 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3256 while (d_peek_char (di
) != 'E')
3258 if (d_peek_char (di
) == '\0')
3262 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3264 if (! d_check_char (di
, 'E'))
3269 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3270 ::= Z <(function) encoding> E s [<discriminator>]
3271 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3274 static struct demangle_component
*
3275 d_local_name (struct d_info
*di
)
3277 struct demangle_component
*function
;
3279 if (! d_check_char (di
, 'Z'))
3282 function
= d_encoding (di
, 0);
3284 if (! d_check_char (di
, 'E'))
3287 if (d_peek_char (di
) == 's')
3290 if (! d_discriminator (di
))
3292 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3293 d_make_name (di
, "string literal",
3294 sizeof "string literal" - 1));
3298 struct demangle_component
*name
;
3301 if (d_peek_char (di
) == 'd')
3303 /* Default argument scope: d <number> _. */
3305 num
= d_compact_number (di
);
3314 /* Lambdas and unnamed types have internal discriminators. */
3315 case DEMANGLE_COMPONENT_LAMBDA
:
3316 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3319 if (! d_discriminator (di
))
3323 name
= d_make_default_arg (di
, num
, name
);
3324 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3328 /* <discriminator> ::= _ <(non-negative) number>
3330 We demangle the discriminator, but we don't print it out. FIXME:
3331 We should print it out in verbose mode. */
3334 d_discriminator (struct d_info
*di
)
3338 if (d_peek_char (di
) != '_')
3341 discrim
= d_number (di
);
3347 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3349 static struct demangle_component
*
3350 d_lambda (struct d_info
*di
)
3352 struct demangle_component
*tl
;
3353 struct demangle_component
*ret
;
3356 if (! d_check_char (di
, 'U'))
3358 if (! d_check_char (di
, 'l'))
3361 tl
= d_parmlist (di
);
3365 if (! d_check_char (di
, 'E'))
3368 num
= d_compact_number (di
);
3372 ret
= d_make_empty (di
);
3375 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3376 ret
->u
.s_unary_num
.sub
= tl
;
3377 ret
->u
.s_unary_num
.num
= num
;
3380 if (! d_add_substitution (di
, ret
))
3386 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3388 static struct demangle_component
*
3389 d_unnamed_type (struct d_info
*di
)
3391 struct demangle_component
*ret
;
3394 if (! d_check_char (di
, 'U'))
3396 if (! d_check_char (di
, 't'))
3399 num
= d_compact_number (di
);
3403 ret
= d_make_empty (di
);
3406 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3407 ret
->u
.s_number
.number
= num
;
3410 if (! d_add_substitution (di
, ret
))
3416 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3419 static struct demangle_component
*
3420 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3422 const char *suffix
= d_str (di
);
3423 const char *pend
= suffix
;
3424 struct demangle_component
*n
;
3426 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3429 while (IS_LOWER (*pend
) || *pend
== '_')
3432 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3435 while (IS_DIGIT (*pend
))
3438 d_advance (di
, pend
- suffix
);
3439 n
= d_make_name (di
, suffix
, pend
- suffix
);
3440 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3443 /* Add a new substitution. */
3446 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3450 if (di
->next_sub
>= di
->num_subs
)
3452 di
->subs
[di
->next_sub
] = dc
;
3457 /* <substitution> ::= S <seq-id> _
3467 If PREFIX is non-zero, then this type is being used as a prefix in
3468 a qualified name. In this case, for the standard substitutions, we
3469 need to check whether we are being used as a prefix for a
3470 constructor or destructor, and return a full template name.
3471 Otherwise we will get something like std::iostream::~iostream()
3472 which does not correspond particularly well to any function which
3473 actually appears in the source.
3476 static const struct d_standard_sub_info standard_subs
[] =
3481 { 'a', NL ("std::allocator"),
3482 NL ("std::allocator"),
3484 { 'b', NL ("std::basic_string"),
3485 NL ("std::basic_string"),
3486 NL ("basic_string") },
3487 { 's', NL ("std::string"),
3488 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3489 NL ("basic_string") },
3490 { 'i', NL ("std::istream"),
3491 NL ("std::basic_istream<char, std::char_traits<char> >"),
3492 NL ("basic_istream") },
3493 { 'o', NL ("std::ostream"),
3494 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3495 NL ("basic_ostream") },
3496 { 'd', NL ("std::iostream"),
3497 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3498 NL ("basic_iostream") }
3501 static struct demangle_component
*
3502 d_substitution (struct d_info
*di
, int prefix
)
3506 if (! d_check_char (di
, 'S'))
3509 c
= d_next_char (di
);
3510 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3519 unsigned int new_id
;
3522 new_id
= id
* 36 + c
- '0';
3523 else if (IS_UPPER (c
))
3524 new_id
= id
* 36 + c
- 'A' + 10;
3530 c
= d_next_char (di
);
3537 if (id
>= (unsigned int) di
->next_sub
)
3542 return di
->subs
[id
];
3547 const struct d_standard_sub_info
*p
;
3548 const struct d_standard_sub_info
*pend
;
3550 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3551 if (! verbose
&& prefix
)
3555 peek
= d_peek_char (di
);
3556 if (peek
== 'C' || peek
== 'D')
3560 pend
= (&standard_subs
[0]
3561 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3562 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3569 if (p
->set_last_name
!= NULL
)
3570 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3571 p
->set_last_name_len
);
3574 s
= p
->full_expansion
;
3579 s
= p
->simple_expansion
;
3580 len
= p
->simple_len
;
3582 di
->expansion
+= len
;
3583 return d_make_sub (di
, s
, len
);
3591 /* Initialize a growable string. */
3594 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3599 dgs
->allocation_failure
= 0;
3602 d_growable_string_resize (dgs
, estimate
);
3605 /* Grow a growable string to a given size. */
3608 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3613 if (dgs
->allocation_failure
)
3616 /* Start allocation at two bytes to avoid any possibility of confusion
3617 with the special value of 1 used as a return in *palc to indicate
3618 allocation failures. */
3619 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3620 while (newalc
< need
)
3623 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3630 dgs
->allocation_failure
= 1;
3637 /* Append a buffer to a growable string. */
3640 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3641 const char *s
, size_t l
)
3645 need
= dgs
->len
+ l
+ 1;
3646 if (need
> dgs
->alc
)
3647 d_growable_string_resize (dgs
, need
);
3649 if (dgs
->allocation_failure
)
3652 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3653 dgs
->buf
[dgs
->len
+ l
] = '\0';
3657 /* Bridge growable strings to the callback mechanism. */
3660 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3662 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3664 d_growable_string_append_buffer (dgs
, s
, l
);
3667 /* Initialize a print information structure. */
3670 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
3674 dpi
->last_char
= '\0';
3675 dpi
->templates
= NULL
;
3676 dpi
->modifiers
= NULL
;
3677 dpi
->pack_index
= 0;
3678 dpi
->flush_count
= 0;
3680 dpi
->callback
= callback
;
3681 dpi
->opaque
= opaque
;
3683 dpi
->demangle_failure
= 0;
3685 dpi
->saved_scopes
= NULL
;
3686 dpi
->num_saved_scopes
= 0;
3689 /* Free a print information structure. */
3692 d_print_free (struct d_print_info
*dpi
)
3696 for (i
= 0; i
< dpi
->num_saved_scopes
; i
++)
3698 struct d_print_template
*ts
, *tn
;
3700 for (ts
= dpi
->saved_scopes
[i
].templates
; ts
!= NULL
; ts
= tn
)
3707 free (dpi
->saved_scopes
);
3710 /* Indicate that an error occurred during printing, and test for error. */
3713 d_print_error (struct d_print_info
*dpi
)
3715 dpi
->demangle_failure
= 1;
3719 d_print_saw_error (struct d_print_info
*dpi
)
3721 return dpi
->demangle_failure
!= 0;
3724 /* Flush buffered characters to the callback. */
3727 d_print_flush (struct d_print_info
*dpi
)
3729 dpi
->buf
[dpi
->len
] = '\0';
3730 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3735 /* Append characters and buffers for printing. */
3738 d_append_char (struct d_print_info
*dpi
, char c
)
3740 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3741 d_print_flush (dpi
);
3743 dpi
->buf
[dpi
->len
++] = c
;
3748 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3752 for (i
= 0; i
< l
; i
++)
3753 d_append_char (dpi
, s
[i
]);
3757 d_append_string (struct d_print_info
*dpi
, const char *s
)
3759 d_append_buffer (dpi
, s
, strlen (s
));
3763 d_append_num (struct d_print_info
*dpi
, long l
)
3766 sprintf (buf
,"%ld", l
);
3767 d_append_string (dpi
, buf
);
3771 d_last_char (struct d_print_info
*dpi
)
3773 return dpi
->last_char
;
3776 /* Turn components into a human readable string. OPTIONS is the
3777 options bits passed to the demangler. DC is the tree to print.
3778 CALLBACK is a function to call to flush demangled string segments
3779 as they fill the intermediate buffer, and OPAQUE is a generalized
3780 callback argument. On success, this returns 1. On failure,
3781 it returns 0, indicating a bad parse. It does not use heap
3782 memory to build an output string, so cannot encounter memory
3783 allocation failure. */
3785 CP_STATIC_IF_GLIBCPP_V3
3787 cplus_demangle_print_callback (int options
,
3788 const struct demangle_component
*dc
,
3789 demangle_callbackref callback
, void *opaque
)
3791 struct d_print_info dpi
;
3794 d_print_init (&dpi
, callback
, opaque
);
3796 d_print_comp (&dpi
, options
, dc
);
3798 d_print_flush (&dpi
);
3800 success
= ! d_print_saw_error (&dpi
);
3801 d_print_free (&dpi
);
3805 /* Turn components into a human readable string. OPTIONS is the
3806 options bits passed to the demangler. DC is the tree to print.
3807 ESTIMATE is a guess at the length of the result. This returns a
3808 string allocated by malloc, or NULL on error. On success, this
3809 sets *PALC to the size of the allocated buffer. On failure, this
3810 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3813 CP_STATIC_IF_GLIBCPP_V3
3815 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3816 int estimate
, size_t *palc
)
3818 struct d_growable_string dgs
;
3820 d_growable_string_init (&dgs
, estimate
);
3822 if (! cplus_demangle_print_callback (options
, dc
,
3823 d_growable_string_callback_adapter
,
3831 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3835 /* Returns the I'th element of the template arglist ARGS, or NULL on
3838 static struct demangle_component
*
3839 d_index_template_argument (struct demangle_component
*args
, int i
)
3841 struct demangle_component
*a
;
3847 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3853 if (i
!= 0 || a
== NULL
)
3859 /* Returns the template argument from the current context indicated by DC,
3860 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3862 static struct demangle_component
*
3863 d_lookup_template_argument (struct d_print_info
*dpi
,
3864 const struct demangle_component
*dc
)
3866 if (dpi
->templates
== NULL
)
3868 d_print_error (dpi
);
3872 return d_index_template_argument
3873 (d_right (dpi
->templates
->template_decl
),
3874 dc
->u
.s_number
.number
);
3877 /* Returns a template argument pack used in DC (any will do), or NULL. */
3879 static struct demangle_component
*
3880 d_find_pack (struct d_print_info
*dpi
,
3881 const struct demangle_component
*dc
)
3883 struct demangle_component
*a
;
3889 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3890 a
= d_lookup_template_argument (dpi
, dc
);
3891 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3895 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3898 case DEMANGLE_COMPONENT_LAMBDA
:
3899 case DEMANGLE_COMPONENT_NAME
:
3900 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3901 case DEMANGLE_COMPONENT_OPERATOR
:
3902 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3903 case DEMANGLE_COMPONENT_SUB_STD
:
3904 case DEMANGLE_COMPONENT_CHARACTER
:
3905 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3906 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3909 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3910 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3911 case DEMANGLE_COMPONENT_CTOR
:
3912 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3913 case DEMANGLE_COMPONENT_DTOR
:
3914 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3917 a
= d_find_pack (dpi
, d_left (dc
));
3920 return d_find_pack (dpi
, d_right (dc
));
3924 /* Returns the length of the template argument pack DC. */
3927 d_pack_length (const struct demangle_component
*dc
)
3930 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3931 && d_left (dc
) != NULL
)
3939 /* DC is a component of a mangled expression. Print it, wrapped in parens
3943 d_print_subexpr (struct d_print_info
*dpi
, int options
,
3944 const struct demangle_component
*dc
)
3947 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3948 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
3949 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
3950 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3953 d_append_char (dpi
, '(');
3954 d_print_comp (dpi
, options
, dc
);
3956 d_append_char (dpi
, ')');
3959 /* Return a shallow copy of the current list of templates.
3960 On error d_print_error is called and a partial list may
3961 be returned. Whatever is returned must be freed. */
3963 static struct d_print_template
*
3964 d_copy_templates (struct d_print_info
*dpi
)
3966 struct d_print_template
*src
, *result
, **link
= &result
;
3968 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
3970 struct d_print_template
*dst
=
3971 (struct d_print_template
*) malloc (sizeof (struct d_print_template
));
3975 d_print_error (dpi
);
3979 dst
->template_decl
= src
->template_decl
;
3989 /* Subroutine to handle components. */
3992 d_print_comp (struct d_print_info
*dpi
, int options
,
3993 const struct demangle_component
*dc
)
3995 /* Magic variable to let reference smashing skip over the next modifier
3996 without needing to modify *dc. */
3997 const struct demangle_component
*mod_inner
= NULL
;
3999 /* Variable used to store the current templates while a previously
4000 captured scope is used. */
4001 struct d_print_template
*saved_templates
;
4003 /* Nonzero if templates have been stored in the above variable. */
4004 int need_template_restore
= 0;
4008 d_print_error (dpi
);
4011 if (d_print_saw_error (dpi
))
4016 case DEMANGLE_COMPONENT_NAME
:
4017 if ((options
& DMGL_JAVA
) == 0)
4018 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4020 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4023 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4024 d_print_comp (dpi
, options
, d_left (dc
));
4025 d_append_string (dpi
, "[abi:");
4026 d_print_comp (dpi
, options
, d_right (dc
));
4027 d_append_char (dpi
, ']');
4030 case DEMANGLE_COMPONENT_QUAL_NAME
:
4031 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4032 d_print_comp (dpi
, options
, d_left (dc
));
4033 if ((options
& DMGL_JAVA
) == 0)
4034 d_append_string (dpi
, "::");
4036 d_append_char (dpi
, '.');
4038 struct demangle_component
*local_name
= d_right (dc
);
4039 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4041 d_append_string (dpi
, "{default arg#");
4042 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4043 d_append_string (dpi
, "}::");
4044 local_name
= local_name
->u
.s_unary_num
.sub
;
4046 d_print_comp (dpi
, options
, local_name
);
4050 case DEMANGLE_COMPONENT_TYPED_NAME
:
4052 struct d_print_mod
*hold_modifiers
;
4053 struct demangle_component
*typed_name
;
4054 struct d_print_mod adpm
[4];
4056 struct d_print_template dpt
;
4058 /* Pass the name down to the type so that it can be printed in
4059 the right place for the type. We also have to pass down
4060 any CV-qualifiers, which apply to the this parameter. */
4061 hold_modifiers
= dpi
->modifiers
;
4064 typed_name
= d_left (dc
);
4065 while (typed_name
!= NULL
)
4067 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4069 d_print_error (dpi
);
4073 adpm
[i
].next
= dpi
->modifiers
;
4074 dpi
->modifiers
= &adpm
[i
];
4075 adpm
[i
].mod
= typed_name
;
4076 adpm
[i
].printed
= 0;
4077 adpm
[i
].templates
= dpi
->templates
;
4080 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4081 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4082 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4083 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4084 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4087 typed_name
= d_left (typed_name
);
4090 if (typed_name
== NULL
)
4092 d_print_error (dpi
);
4096 /* If typed_name is a template, then it applies to the
4097 function type as well. */
4098 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4100 dpt
.next
= dpi
->templates
;
4101 dpi
->templates
= &dpt
;
4102 dpt
.template_decl
= typed_name
;
4105 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4106 there may be CV-qualifiers on its right argument which
4107 really apply here; this happens when parsing a class which
4108 is local to a function. */
4109 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4111 struct demangle_component
*local_name
;
4113 local_name
= d_right (typed_name
);
4114 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4115 local_name
= local_name
->u
.s_unary_num
.sub
;
4116 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4117 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4118 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4119 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4120 || (local_name
->type
4121 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4123 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4125 d_print_error (dpi
);
4129 adpm
[i
] = adpm
[i
- 1];
4130 adpm
[i
].next
= &adpm
[i
- 1];
4131 dpi
->modifiers
= &adpm
[i
];
4133 adpm
[i
- 1].mod
= local_name
;
4134 adpm
[i
- 1].printed
= 0;
4135 adpm
[i
- 1].templates
= dpi
->templates
;
4138 local_name
= d_left (local_name
);
4142 d_print_comp (dpi
, options
, d_right (dc
));
4144 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4145 dpi
->templates
= dpt
.next
;
4147 /* If the modifiers didn't get printed by the type, print them
4152 if (! adpm
[i
].printed
)
4154 d_append_char (dpi
, ' ');
4155 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4159 dpi
->modifiers
= hold_modifiers
;
4164 case DEMANGLE_COMPONENT_TEMPLATE
:
4166 struct d_print_mod
*hold_dpm
;
4167 struct demangle_component
*dcl
;
4169 /* Don't push modifiers into a template definition. Doing so
4170 could give the wrong definition for a template argument.
4171 Instead, treat the template essentially as a name. */
4173 hold_dpm
= dpi
->modifiers
;
4174 dpi
->modifiers
= NULL
;
4178 if ((options
& DMGL_JAVA
) != 0
4179 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4180 && dcl
->u
.s_name
.len
== 6
4181 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4183 /* Special-case Java arrays, so that JArray<TYPE> appears
4184 instead as TYPE[]. */
4186 d_print_comp (dpi
, options
, d_right (dc
));
4187 d_append_string (dpi
, "[]");
4191 d_print_comp (dpi
, options
, dcl
);
4192 if (d_last_char (dpi
) == '<')
4193 d_append_char (dpi
, ' ');
4194 d_append_char (dpi
, '<');
4195 d_print_comp (dpi
, options
, d_right (dc
));
4196 /* Avoid generating two consecutive '>' characters, to avoid
4197 the C++ syntactic ambiguity. */
4198 if (d_last_char (dpi
) == '>')
4199 d_append_char (dpi
, ' ');
4200 d_append_char (dpi
, '>');
4203 dpi
->modifiers
= hold_dpm
;
4208 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4210 struct d_print_template
*hold_dpt
;
4211 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4213 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4214 a
= d_index_template_argument (a
, dpi
->pack_index
);
4218 d_print_error (dpi
);
4222 /* While processing this parameter, we need to pop the list of
4223 templates. This is because the template parameter may
4224 itself be a reference to a parameter of an outer
4227 hold_dpt
= dpi
->templates
;
4228 dpi
->templates
= hold_dpt
->next
;
4230 d_print_comp (dpi
, options
, a
);
4232 dpi
->templates
= hold_dpt
;
4237 case DEMANGLE_COMPONENT_CTOR
:
4238 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4241 case DEMANGLE_COMPONENT_DTOR
:
4242 d_append_char (dpi
, '~');
4243 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4246 case DEMANGLE_COMPONENT_VTABLE
:
4247 d_append_string (dpi
, "vtable for ");
4248 d_print_comp (dpi
, options
, d_left (dc
));
4251 case DEMANGLE_COMPONENT_VTT
:
4252 d_append_string (dpi
, "VTT for ");
4253 d_print_comp (dpi
, options
, d_left (dc
));
4256 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4257 d_append_string (dpi
, "construction vtable for ");
4258 d_print_comp (dpi
, options
, d_left (dc
));
4259 d_append_string (dpi
, "-in-");
4260 d_print_comp (dpi
, options
, d_right (dc
));
4263 case DEMANGLE_COMPONENT_TYPEINFO
:
4264 d_append_string (dpi
, "typeinfo for ");
4265 d_print_comp (dpi
, options
, d_left (dc
));
4268 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4269 d_append_string (dpi
, "typeinfo name for ");
4270 d_print_comp (dpi
, options
, d_left (dc
));
4273 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4274 d_append_string (dpi
, "typeinfo fn for ");
4275 d_print_comp (dpi
, options
, d_left (dc
));
4278 case DEMANGLE_COMPONENT_THUNK
:
4279 d_append_string (dpi
, "non-virtual thunk to ");
4280 d_print_comp (dpi
, options
, d_left (dc
));
4283 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4284 d_append_string (dpi
, "virtual thunk to ");
4285 d_print_comp (dpi
, options
, d_left (dc
));
4288 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4289 d_append_string (dpi
, "covariant return thunk to ");
4290 d_print_comp (dpi
, options
, d_left (dc
));
4293 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4294 d_append_string (dpi
, "java Class for ");
4295 d_print_comp (dpi
, options
, d_left (dc
));
4298 case DEMANGLE_COMPONENT_GUARD
:
4299 d_append_string (dpi
, "guard variable for ");
4300 d_print_comp (dpi
, options
, d_left (dc
));
4303 case DEMANGLE_COMPONENT_TLS_INIT
:
4304 d_append_string (dpi
, "TLS init function for ");
4305 d_print_comp (dpi
, options
, d_left (dc
));
4308 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4309 d_append_string (dpi
, "TLS wrapper function for ");
4310 d_print_comp (dpi
, options
, d_left (dc
));
4313 case DEMANGLE_COMPONENT_REFTEMP
:
4314 d_append_string (dpi
, "reference temporary #");
4315 d_print_comp (dpi
, options
, d_right (dc
));
4316 d_append_string (dpi
, " for ");
4317 d_print_comp (dpi
, options
, d_left (dc
));
4320 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4321 d_append_string (dpi
, "hidden alias for ");
4322 d_print_comp (dpi
, options
, d_left (dc
));
4325 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4326 d_append_string (dpi
, "transaction clone for ");
4327 d_print_comp (dpi
, options
, d_left (dc
));
4330 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4331 d_append_string (dpi
, "non-transaction clone for ");
4332 d_print_comp (dpi
, options
, d_left (dc
));
4335 case DEMANGLE_COMPONENT_SUB_STD
:
4336 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4339 case DEMANGLE_COMPONENT_RESTRICT
:
4340 case DEMANGLE_COMPONENT_VOLATILE
:
4341 case DEMANGLE_COMPONENT_CONST
:
4343 struct d_print_mod
*pdpm
;
4345 /* When printing arrays, it's possible to have cases where the
4346 same CV-qualifier gets pushed on the stack multiple times.
4347 We only need to print it once. */
4349 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4351 if (! pdpm
->printed
)
4353 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4354 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4355 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4357 if (pdpm
->mod
->type
== dc
->type
)
4359 d_print_comp (dpi
, options
, d_left (dc
));
4367 case DEMANGLE_COMPONENT_REFERENCE
:
4368 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4370 /* Handle reference smashing: & + && = &. */
4371 const struct demangle_component
*sub
= d_left (dc
);
4372 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4374 struct demangle_component
*a
;
4375 struct d_saved_scope
*scope
= NULL
, *scopes
;
4378 for (i
= 0; i
< dpi
->num_saved_scopes
; i
++)
4379 if (dpi
->saved_scopes
[i
].container
== sub
)
4380 scope
= &dpi
->saved_scopes
[i
];
4386 /* This is the first time SUB has been traversed.
4387 We need to capture the current templates so
4388 they can be restored if SUB is reentered as a
4390 ++dpi
->num_saved_scopes
;
4391 size
= sizeof (struct d_saved_scope
) * dpi
->num_saved_scopes
;
4392 scopes
= (struct d_saved_scope
*) realloc (dpi
->saved_scopes
,
4396 d_print_error (dpi
);
4400 dpi
->saved_scopes
= scopes
;
4401 scope
= dpi
->saved_scopes
+ (dpi
->num_saved_scopes
- 1);
4403 scope
->container
= sub
;
4404 scope
->templates
= d_copy_templates (dpi
);
4405 if (d_print_saw_error (dpi
))
4410 /* This traversal is reentering SUB as a substition.
4411 Restore the original templates temporarily. */
4412 saved_templates
= dpi
->templates
;
4413 dpi
->templates
= scope
->templates
;
4414 need_template_restore
= 1;
4417 a
= d_lookup_template_argument (dpi
, sub
);
4418 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4419 a
= d_index_template_argument (a
, dpi
->pack_index
);
4423 if (need_template_restore
)
4424 dpi
->templates
= saved_templates
;
4426 d_print_error (dpi
);
4433 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4434 || sub
->type
== dc
->type
)
4436 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4437 mod_inner
= d_left (sub
);
4441 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4442 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4443 case DEMANGLE_COMPONENT_CONST_THIS
:
4444 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4445 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4446 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4447 case DEMANGLE_COMPONENT_POINTER
:
4448 case DEMANGLE_COMPONENT_COMPLEX
:
4449 case DEMANGLE_COMPONENT_IMAGINARY
:
4452 /* We keep a list of modifiers on the stack. */
4453 struct d_print_mod dpm
;
4455 dpm
.next
= dpi
->modifiers
;
4456 dpi
->modifiers
= &dpm
;
4459 dpm
.templates
= dpi
->templates
;
4462 mod_inner
= d_left (dc
);
4464 d_print_comp (dpi
, options
, mod_inner
);
4466 /* If the modifier didn't get printed by the type, print it
4469 d_print_mod (dpi
, options
, dc
);
4471 dpi
->modifiers
= dpm
.next
;
4473 if (need_template_restore
)
4474 dpi
->templates
= saved_templates
;
4479 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4480 if ((options
& DMGL_JAVA
) == 0)
4481 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4482 dc
->u
.s_builtin
.type
->len
);
4484 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4485 dc
->u
.s_builtin
.type
->java_len
);
4488 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4489 d_print_comp (dpi
, options
, d_left (dc
));
4492 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4494 if ((options
& DMGL_RET_POSTFIX
) != 0)
4495 d_print_function_type (dpi
,
4496 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4497 dc
, dpi
->modifiers
);
4499 /* Print return type if present */
4500 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4501 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4503 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4505 struct d_print_mod dpm
;
4507 /* We must pass this type down as a modifier in order to
4508 print it in the right location. */
4509 dpm
.next
= dpi
->modifiers
;
4510 dpi
->modifiers
= &dpm
;
4513 dpm
.templates
= dpi
->templates
;
4515 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4518 dpi
->modifiers
= dpm
.next
;
4523 /* In standard prefix notation, there is a space between the
4524 return type and the function signature. */
4525 if ((options
& DMGL_RET_POSTFIX
) == 0)
4526 d_append_char (dpi
, ' ');
4529 if ((options
& DMGL_RET_POSTFIX
) == 0)
4530 d_print_function_type (dpi
,
4531 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4532 dc
, dpi
->modifiers
);
4537 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4539 struct d_print_mod
*hold_modifiers
;
4540 struct d_print_mod adpm
[4];
4542 struct d_print_mod
*pdpm
;
4544 /* We must pass this type down as a modifier in order to print
4545 multi-dimensional arrays correctly. If the array itself is
4546 CV-qualified, we act as though the element type were
4547 CV-qualified. We do this by copying the modifiers down
4548 rather than fiddling pointers, so that we don't wind up
4549 with a d_print_mod higher on the stack pointing into our
4550 stack frame after we return. */
4552 hold_modifiers
= dpi
->modifiers
;
4554 adpm
[0].next
= hold_modifiers
;
4555 dpi
->modifiers
= &adpm
[0];
4557 adpm
[0].printed
= 0;
4558 adpm
[0].templates
= dpi
->templates
;
4561 pdpm
= hold_modifiers
;
4563 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4564 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4565 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4567 if (! pdpm
->printed
)
4569 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4571 d_print_error (dpi
);
4576 adpm
[i
].next
= dpi
->modifiers
;
4577 dpi
->modifiers
= &adpm
[i
];
4585 d_print_comp (dpi
, options
, d_right (dc
));
4587 dpi
->modifiers
= hold_modifiers
;
4589 if (adpm
[0].printed
)
4595 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4598 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4603 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4604 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4606 struct d_print_mod dpm
;
4608 dpm
.next
= dpi
->modifiers
;
4609 dpi
->modifiers
= &dpm
;
4612 dpm
.templates
= dpi
->templates
;
4614 d_print_comp (dpi
, options
, d_right (dc
));
4616 /* If the modifier didn't get printed by the type, print it
4619 d_print_mod (dpi
, options
, dc
);
4621 dpi
->modifiers
= dpm
.next
;
4626 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4627 if (dc
->u
.s_fixed
.sat
)
4628 d_append_string (dpi
, "_Sat ");
4629 /* Don't print "int _Accum". */
4630 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4631 != &cplus_demangle_builtin_types
['i'-'a'])
4633 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
4634 d_append_char (dpi
, ' ');
4636 if (dc
->u
.s_fixed
.accum
)
4637 d_append_string (dpi
, "_Accum");
4639 d_append_string (dpi
, "_Fract");
4642 case DEMANGLE_COMPONENT_ARGLIST
:
4643 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4644 if (d_left (dc
) != NULL
)
4645 d_print_comp (dpi
, options
, d_left (dc
));
4646 if (d_right (dc
) != NULL
)
4649 unsigned long int flush_count
;
4650 /* Make sure ", " isn't flushed by d_append_string, otherwise
4651 dpi->len -= 2 wouldn't work. */
4652 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4653 d_print_flush (dpi
);
4654 d_append_string (dpi
, ", ");
4656 flush_count
= dpi
->flush_count
;
4657 d_print_comp (dpi
, options
, d_right (dc
));
4658 /* If that didn't print anything (which can happen with empty
4659 template argument packs), remove the comma and space. */
4660 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4665 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4667 struct demangle_component
*type
= d_left (dc
);
4668 struct demangle_component
*list
= d_right (dc
);
4671 d_print_comp (dpi
, options
, type
);
4672 d_append_char (dpi
, '{');
4673 d_print_comp (dpi
, options
, list
);
4674 d_append_char (dpi
, '}');
4678 case DEMANGLE_COMPONENT_OPERATOR
:
4680 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
4683 d_append_string (dpi
, "operator");
4684 /* Add a space before new/delete. */
4685 if (IS_LOWER (op
->name
[0]))
4686 d_append_char (dpi
, ' ');
4687 /* Omit a trailing space. */
4688 if (op
->name
[len
-1] == ' ')
4690 d_append_buffer (dpi
, op
->name
, len
);
4694 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4695 d_append_string (dpi
, "operator ");
4696 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
4699 case DEMANGLE_COMPONENT_CAST
:
4700 d_append_string (dpi
, "operator ");
4701 d_print_cast (dpi
, options
, dc
);
4704 case DEMANGLE_COMPONENT_NULLARY
:
4705 d_print_expr_op (dpi
, options
, d_left (dc
));
4708 case DEMANGLE_COMPONENT_UNARY
:
4710 struct demangle_component
*op
= d_left (dc
);
4711 struct demangle_component
*operand
= d_right (dc
);
4712 const char *code
= NULL
;
4714 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4716 code
= op
->u
.s_operator
.op
->code
;
4717 if (!strcmp (code
, "ad"))
4719 /* Don't print the argument list for the address of a
4721 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
4722 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
4723 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4724 operand
= d_left (operand
);
4726 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
4728 /* This indicates a suffix operator. */
4729 operand
= d_left (operand
);
4730 d_print_subexpr (dpi
, options
, operand
);
4731 d_print_expr_op (dpi
, options
, op
);
4736 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
4737 d_print_expr_op (dpi
, options
, op
);
4740 d_append_char (dpi
, '(');
4741 d_print_cast (dpi
, options
, op
);
4742 d_append_char (dpi
, ')');
4744 if (code
&& !strcmp (code
, "gs"))
4745 /* Avoid parens after '::'. */
4746 d_print_comp (dpi
, options
, operand
);
4747 else if (code
&& !strcmp (code
, "st"))
4748 /* Always print parens for sizeof (type). */
4750 d_append_char (dpi
, '(');
4751 d_print_comp (dpi
, options
, operand
);
4752 d_append_char (dpi
, ')');
4755 d_print_subexpr (dpi
, options
, operand
);
4759 case DEMANGLE_COMPONENT_BINARY
:
4760 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4762 d_print_error (dpi
);
4766 if (op_is_new_cast (d_left (dc
)))
4768 d_print_expr_op (dpi
, options
, d_left (dc
));
4769 d_append_char (dpi
, '<');
4770 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
4771 d_append_string (dpi
, ">(");
4772 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
4773 d_append_char (dpi
, ')');
4777 /* We wrap an expression which uses the greater-than operator in
4778 an extra layer of parens so that it does not get confused
4779 with the '>' which ends the template parameters. */
4780 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4781 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4782 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4783 d_append_char (dpi
, '(');
4785 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
4786 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
4788 /* Function call used in an expression should not have printed types
4789 of the function arguments. Values of the function arguments still
4790 get printed below. */
4792 const struct demangle_component
*func
= d_left (d_right (dc
));
4794 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4795 d_print_error (dpi
);
4796 d_print_subexpr (dpi
, options
, d_left (func
));
4799 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
4800 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4802 d_append_char (dpi
, '[');
4803 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
4804 d_append_char (dpi
, ']');
4808 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4809 d_print_expr_op (dpi
, options
, d_left (dc
));
4810 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
4813 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4814 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4815 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4816 d_append_char (dpi
, ')');
4820 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4821 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4822 d_print_error (dpi
);
4825 case DEMANGLE_COMPONENT_TRINARY
:
4826 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4827 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4829 d_print_error (dpi
);
4833 struct demangle_component
*op
= d_left (dc
);
4834 struct demangle_component
*first
= d_left (d_right (dc
));
4835 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
4836 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
4838 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
4840 d_print_subexpr (dpi
, options
, first
);
4841 d_print_expr_op (dpi
, options
, op
);
4842 d_print_subexpr (dpi
, options
, second
);
4843 d_append_string (dpi
, " : ");
4844 d_print_subexpr (dpi
, options
, third
);
4848 d_append_string (dpi
, "new ");
4849 if (d_left (first
) != NULL
)
4851 d_print_subexpr (dpi
, options
, first
);
4852 d_append_char (dpi
, ' ');
4854 d_print_comp (dpi
, options
, second
);
4856 d_print_subexpr (dpi
, options
, third
);
4861 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4862 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4863 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4864 d_print_error (dpi
);
4867 case DEMANGLE_COMPONENT_LITERAL
:
4868 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4870 enum d_builtin_type_print tp
;
4872 /* For some builtin types, produce simpler output. */
4873 tp
= D_PRINT_DEFAULT
;
4874 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4876 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4880 case D_PRINT_UNSIGNED
:
4882 case D_PRINT_UNSIGNED_LONG
:
4883 case D_PRINT_LONG_LONG
:
4884 case D_PRINT_UNSIGNED_LONG_LONG
:
4885 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4887 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4888 d_append_char (dpi
, '-');
4889 d_print_comp (dpi
, options
, d_right (dc
));
4894 case D_PRINT_UNSIGNED
:
4895 d_append_char (dpi
, 'u');
4898 d_append_char (dpi
, 'l');
4900 case D_PRINT_UNSIGNED_LONG
:
4901 d_append_string (dpi
, "ul");
4903 case D_PRINT_LONG_LONG
:
4904 d_append_string (dpi
, "ll");
4906 case D_PRINT_UNSIGNED_LONG_LONG
:
4907 d_append_string (dpi
, "ull");
4915 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4916 && d_right (dc
)->u
.s_name
.len
== 1
4917 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4919 switch (d_right (dc
)->u
.s_name
.s
[0])
4922 d_append_string (dpi
, "false");
4925 d_append_string (dpi
, "true");
4938 d_append_char (dpi
, '(');
4939 d_print_comp (dpi
, options
, d_left (dc
));
4940 d_append_char (dpi
, ')');
4941 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4942 d_append_char (dpi
, '-');
4943 if (tp
== D_PRINT_FLOAT
)
4944 d_append_char (dpi
, '[');
4945 d_print_comp (dpi
, options
, d_right (dc
));
4946 if (tp
== D_PRINT_FLOAT
)
4947 d_append_char (dpi
, ']');
4951 case DEMANGLE_COMPONENT_NUMBER
:
4952 d_append_num (dpi
, dc
->u
.s_number
.number
);
4955 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4956 d_append_string (dpi
, "java resource ");
4957 d_print_comp (dpi
, options
, d_left (dc
));
4960 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4961 d_print_comp (dpi
, options
, d_left (dc
));
4962 d_print_comp (dpi
, options
, d_right (dc
));
4965 case DEMANGLE_COMPONENT_CHARACTER
:
4966 d_append_char (dpi
, dc
->u
.s_character
.character
);
4969 case DEMANGLE_COMPONENT_DECLTYPE
:
4970 d_append_string (dpi
, "decltype (");
4971 d_print_comp (dpi
, options
, d_left (dc
));
4972 d_append_char (dpi
, ')');
4975 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4979 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4982 /* d_find_pack won't find anything if the only packs involved
4983 in this expansion are function parameter packs; in that
4984 case, just print the pattern and "...". */
4985 d_print_subexpr (dpi
, options
, d_left (dc
));
4986 d_append_string (dpi
, "...");
4990 len
= d_pack_length (a
);
4992 for (i
= 0; i
< len
; ++i
)
4994 dpi
->pack_index
= i
;
4995 d_print_comp (dpi
, options
, dc
);
4997 d_append_string (dpi
, ", ");
5002 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5004 long num
= dc
->u
.s_number
.number
;
5006 d_append_string (dpi
, "this");
5009 d_append_string (dpi
, "{parm#");
5010 d_append_num (dpi
, num
);
5011 d_append_char (dpi
, '}');
5016 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5017 d_append_string (dpi
, "global constructors keyed to ");
5018 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5021 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5022 d_append_string (dpi
, "global destructors keyed to ");
5023 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5026 case DEMANGLE_COMPONENT_LAMBDA
:
5027 d_append_string (dpi
, "{lambda(");
5028 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5029 d_append_string (dpi
, ")#");
5030 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5031 d_append_char (dpi
, '}');
5034 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5035 d_append_string (dpi
, "{unnamed type#");
5036 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5037 d_append_char (dpi
, '}');
5040 case DEMANGLE_COMPONENT_CLONE
:
5041 d_print_comp (dpi
, options
, d_left (dc
));
5042 d_append_string (dpi
, " [clone ");
5043 d_print_comp (dpi
, options
, d_right (dc
));
5044 d_append_char (dpi
, ']');
5048 d_print_error (dpi
);
5053 /* Print a Java dentifier. For Java we try to handle encoded extended
5054 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5055 so we don't it for C++. Characters are encoded as
5059 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5065 for (p
= name
; p
< end
; ++p
)
5076 for (q
= p
+ 3; q
< end
; ++q
)
5082 else if (*q
>= 'A' && *q
<= 'F')
5083 dig
= *q
- 'A' + 10;
5084 else if (*q
>= 'a' && *q
<= 'f')
5085 dig
= *q
- 'a' + 10;
5091 /* If the Unicode character is larger than 256, we don't try
5092 to deal with it here. FIXME. */
5093 if (q
< end
&& *q
== '_' && c
< 256)
5095 d_append_char (dpi
, c
);
5101 d_append_char (dpi
, *p
);
5105 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5106 qualifiers on this after printing a function. */
5109 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5110 struct d_print_mod
*mods
, int suffix
)
5112 struct d_print_template
*hold_dpt
;
5114 if (mods
== NULL
|| d_print_saw_error (dpi
))
5119 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5120 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5121 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5122 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5124 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5126 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5132 hold_dpt
= dpi
->templates
;
5133 dpi
->templates
= mods
->templates
;
5135 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5137 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5138 dpi
->templates
= hold_dpt
;
5141 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5143 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5144 dpi
->templates
= hold_dpt
;
5147 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5149 struct d_print_mod
*hold_modifiers
;
5150 struct demangle_component
*dc
;
5152 /* When this is on the modifier stack, we have pulled any
5153 qualifiers off the right argument already. Otherwise, we
5154 print it as usual, but don't let the left argument see any
5157 hold_modifiers
= dpi
->modifiers
;
5158 dpi
->modifiers
= NULL
;
5159 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5160 dpi
->modifiers
= hold_modifiers
;
5162 if ((options
& DMGL_JAVA
) == 0)
5163 d_append_string (dpi
, "::");
5165 d_append_char (dpi
, '.');
5167 dc
= d_right (mods
->mod
);
5169 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5171 d_append_string (dpi
, "{default arg#");
5172 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5173 d_append_string (dpi
, "}::");
5174 dc
= dc
->u
.s_unary_num
.sub
;
5177 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5178 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5179 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5180 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5181 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5184 d_print_comp (dpi
, options
, dc
);
5186 dpi
->templates
= hold_dpt
;
5190 d_print_mod (dpi
, options
, mods
->mod
);
5192 dpi
->templates
= hold_dpt
;
5194 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5197 /* Print a modifier. */
5200 d_print_mod (struct d_print_info
*dpi
, int options
,
5201 const struct demangle_component
*mod
)
5205 case DEMANGLE_COMPONENT_RESTRICT
:
5206 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5207 d_append_string (dpi
, " restrict");
5209 case DEMANGLE_COMPONENT_VOLATILE
:
5210 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5211 d_append_string (dpi
, " volatile");
5213 case DEMANGLE_COMPONENT_CONST
:
5214 case DEMANGLE_COMPONENT_CONST_THIS
:
5215 d_append_string (dpi
, " const");
5217 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5218 d_append_char (dpi
, ' ');
5219 d_print_comp (dpi
, options
, d_right (mod
));
5221 case DEMANGLE_COMPONENT_POINTER
:
5222 /* There is no pointer symbol in Java. */
5223 if ((options
& DMGL_JAVA
) == 0)
5224 d_append_char (dpi
, '*');
5226 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5227 /* For the ref-qualifier, put a space before the &. */
5228 d_append_char (dpi
, ' ');
5229 case DEMANGLE_COMPONENT_REFERENCE
:
5230 d_append_char (dpi
, '&');
5232 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5233 d_append_char (dpi
, ' ');
5234 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5235 d_append_string (dpi
, "&&");
5237 case DEMANGLE_COMPONENT_COMPLEX
:
5238 d_append_string (dpi
, "complex ");
5240 case DEMANGLE_COMPONENT_IMAGINARY
:
5241 d_append_string (dpi
, "imaginary ");
5243 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5244 if (d_last_char (dpi
) != '(')
5245 d_append_char (dpi
, ' ');
5246 d_print_comp (dpi
, options
, d_left (mod
));
5247 d_append_string (dpi
, "::*");
5249 case DEMANGLE_COMPONENT_TYPED_NAME
:
5250 d_print_comp (dpi
, options
, d_left (mod
));
5252 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5253 d_append_string (dpi
, " __vector(");
5254 d_print_comp (dpi
, options
, d_left (mod
));
5255 d_append_char (dpi
, ')');
5259 /* Otherwise, we have something that won't go back on the
5260 modifier stack, so we can just print it. */
5261 d_print_comp (dpi
, options
, mod
);
5266 /* Print a function type, except for the return type. */
5269 d_print_function_type (struct d_print_info
*dpi
, int options
,
5270 const struct demangle_component
*dc
,
5271 struct d_print_mod
*mods
)
5275 struct d_print_mod
*p
;
5276 struct d_print_mod
*hold_modifiers
;
5280 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5285 switch (p
->mod
->type
)
5287 case DEMANGLE_COMPONENT_POINTER
:
5288 case DEMANGLE_COMPONENT_REFERENCE
:
5289 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5292 case DEMANGLE_COMPONENT_RESTRICT
:
5293 case DEMANGLE_COMPONENT_VOLATILE
:
5294 case DEMANGLE_COMPONENT_CONST
:
5295 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5296 case DEMANGLE_COMPONENT_COMPLEX
:
5297 case DEMANGLE_COMPONENT_IMAGINARY
:
5298 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5302 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5303 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5304 case DEMANGLE_COMPONENT_CONST_THIS
:
5305 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5306 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5319 if (d_last_char (dpi
) != '('
5320 && d_last_char (dpi
) != '*')
5323 if (need_space
&& d_last_char (dpi
) != ' ')
5324 d_append_char (dpi
, ' ');
5325 d_append_char (dpi
, '(');
5328 hold_modifiers
= dpi
->modifiers
;
5329 dpi
->modifiers
= NULL
;
5331 d_print_mod_list (dpi
, options
, mods
, 0);
5334 d_append_char (dpi
, ')');
5336 d_append_char (dpi
, '(');
5338 if (d_right (dc
) != NULL
)
5339 d_print_comp (dpi
, options
, d_right (dc
));
5341 d_append_char (dpi
, ')');
5343 d_print_mod_list (dpi
, options
, mods
, 1);
5345 dpi
->modifiers
= hold_modifiers
;
5348 /* Print an array type, except for the element type. */
5351 d_print_array_type (struct d_print_info
*dpi
, int options
,
5352 const struct demangle_component
*dc
,
5353 struct d_print_mod
*mods
)
5361 struct d_print_mod
*p
;
5364 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5368 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5383 d_append_string (dpi
, " (");
5385 d_print_mod_list (dpi
, options
, mods
, 0);
5388 d_append_char (dpi
, ')');
5392 d_append_char (dpi
, ' ');
5394 d_append_char (dpi
, '[');
5396 if (d_left (dc
) != NULL
)
5397 d_print_comp (dpi
, options
, d_left (dc
));
5399 d_append_char (dpi
, ']');
5402 /* Print an operator in an expression. */
5405 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5406 const struct demangle_component
*dc
)
5408 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5409 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5410 dc
->u
.s_operator
.op
->len
);
5412 d_print_comp (dpi
, options
, dc
);
5418 d_print_cast (struct d_print_info
*dpi
, int options
,
5419 const struct demangle_component
*dc
)
5421 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5422 d_print_comp (dpi
, options
, d_left (dc
));
5425 struct d_print_mod
*hold_dpm
;
5426 struct d_print_template dpt
;
5428 /* It appears that for a templated cast operator, we need to put
5429 the template parameters in scope for the operator name, but
5430 not for the parameters. The effect is that we need to handle
5431 the template printing here. */
5433 hold_dpm
= dpi
->modifiers
;
5434 dpi
->modifiers
= NULL
;
5436 dpt
.next
= dpi
->templates
;
5437 dpi
->templates
= &dpt
;
5438 dpt
.template_decl
= d_left (dc
);
5440 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5442 dpi
->templates
= dpt
.next
;
5444 if (d_last_char (dpi
) == '<')
5445 d_append_char (dpi
, ' ');
5446 d_append_char (dpi
, '<');
5447 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5448 /* Avoid generating two consecutive '>' characters, to avoid
5449 the C++ syntactic ambiguity. */
5450 if (d_last_char (dpi
) == '>')
5451 d_append_char (dpi
, ' ');
5452 d_append_char (dpi
, '>');
5454 dpi
->modifiers
= hold_dpm
;
5458 /* Initialize the information structure we use to pass around
5461 CP_STATIC_IF_GLIBCPP_V3
5463 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5467 di
->send
= mangled
+ len
;
5468 di
->options
= options
;
5472 /* We can not need more components than twice the number of chars in
5473 the mangled string. Most components correspond directly to
5474 chars, but the ARGLIST types are exceptions. */
5475 di
->num_comps
= 2 * len
;
5478 /* Similarly, we can not need more substitutions than there are
5479 chars in the mangled string. */
5484 di
->last_name
= NULL
;
5489 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5490 mangled name, return strings in repeated callback giving the demangled
5491 name. OPTIONS is the usual libiberty demangler options. On success,
5492 this returns 1. On failure, returns 0. */
5495 d_demangle_callback (const char *mangled
, int options
,
5496 demangle_callbackref callback
, void *opaque
)
5507 struct demangle_component
*dc
;
5510 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5512 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5513 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5514 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5515 && mangled
[10] == '_')
5516 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5519 if ((options
& DMGL_TYPES
) == 0)
5524 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5527 #ifdef CP_DYNAMIC_ARRAYS
5528 __extension__
struct demangle_component comps
[di
.num_comps
];
5529 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5534 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5535 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5541 dc
= cplus_demangle_type (&di
);
5544 dc
= cplus_demangle_mangled_name (&di
, 1);
5546 case DCT_GLOBAL_CTORS
:
5547 case DCT_GLOBAL_DTORS
:
5548 d_advance (&di
, 11);
5549 dc
= d_make_comp (&di
,
5550 (type
== DCT_GLOBAL_CTORS
5551 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5552 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5553 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5555 d_advance (&di
, strlen (d_str (&di
)));
5559 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5560 mangled string, then we didn't successfully demangle it. If
5561 DMGL_PARAMS is not set, we didn't look at the trailing
5563 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5566 #ifdef CP_DEMANGLE_DEBUG
5570 status
= (dc
!= NULL
)
5571 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
5578 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
5579 name, return a buffer allocated with malloc holding the demangled
5580 name. OPTIONS is the usual libiberty demangler options. On
5581 success, this sets *PALC to the allocated size of the returned
5582 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
5583 a memory allocation failure, and returns NULL. */
5586 d_demangle (const char *mangled
, int options
, size_t *palc
)
5588 struct d_growable_string dgs
;
5591 d_growable_string_init (&dgs
, 0);
5593 status
= d_demangle_callback (mangled
, options
,
5594 d_growable_string_callback_adapter
, &dgs
);
5602 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
5606 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5608 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5610 /* ia64 ABI-mandated entry point in the C++ runtime library for
5611 performing demangling. MANGLED_NAME is a NUL-terminated character
5612 string containing the name to be demangled.
5614 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5615 *LENGTH bytes, into which the demangled name is stored. If
5616 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5617 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5618 is placed in a region of memory allocated with malloc.
5620 If LENGTH is non-NULL, the length of the buffer containing the
5621 demangled name, is placed in *LENGTH.
5623 The return value is a pointer to the start of the NUL-terminated
5624 demangled name, or NULL if the demangling fails. The caller is
5625 responsible for deallocating this memory using free.
5627 *STATUS is set to one of the following values:
5628 0: The demangling operation succeeded.
5629 -1: A memory allocation failure occurred.
5630 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5631 -3: One of the arguments is invalid.
5633 The demangling is performed using the C++ ABI mangling rules, with
5637 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
5638 size_t *length
, int *status
)
5643 if (mangled_name
== NULL
)
5650 if (output_buffer
!= NULL
&& length
== NULL
)
5657 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
5659 if (demangled
== NULL
)
5671 if (output_buffer
== NULL
)
5678 if (strlen (demangled
) < *length
)
5680 strcpy (output_buffer
, demangled
);
5682 demangled
= output_buffer
;
5686 free (output_buffer
);
5697 extern int __gcclibcxx_demangle_callback (const char *,
5699 (const char *, size_t, void *),
5702 /* Alternative, allocationless entry point in the C++ runtime library
5703 for performing demangling. MANGLED_NAME is a NUL-terminated character
5704 string containing the name to be demangled.
5706 CALLBACK is a callback function, called with demangled string
5707 segments as demangling progresses; it is called at least once,
5708 but may be called more than once. OPAQUE is a generalized pointer
5709 used as a callback argument.
5711 The return code is one of the following values, equivalent to
5712 the STATUS values of __cxa_demangle() (excluding -1, since this
5713 function performs no memory allocations):
5714 0: The demangling operation succeeded.
5715 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5716 -3: One of the arguments is invalid.
5718 The demangling is performed using the C++ ABI mangling rules, with
5722 __gcclibcxx_demangle_callback (const char *mangled_name
,
5723 void (*callback
) (const char *, size_t, void *),
5728 if (mangled_name
== NULL
|| callback
== NULL
)
5731 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5739 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5741 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5742 mangled name, return a buffer allocated with malloc holding the
5743 demangled name. Otherwise, return NULL. */
5746 cplus_demangle_v3 (const char *mangled
, int options
)
5750 return d_demangle (mangled
, options
, &alc
);
5754 cplus_demangle_v3_callback (const char *mangled
, int options
,
5755 demangle_callbackref callback
, void *opaque
)
5757 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5760 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5761 conventions, but the output formatting is a little different.
5762 This instructs the C++ demangler not to emit pointer characters ("*"), to
5763 use Java's namespace separator symbol ("." instead of "::"), and to output
5764 JArray<TYPE> as TYPE[]. */
5767 java_demangle_v3 (const char *mangled
)
5771 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5775 java_demangle_v3_callback (const char *mangled
,
5776 demangle_callbackref callback
, void *opaque
)
5778 return d_demangle_callback (mangled
,
5779 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5783 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5785 #ifndef IN_GLIBCPP_V3
5787 /* Demangle a string in order to find out whether it is a constructor
5788 or destructor. Return non-zero on success. Set *CTOR_KIND and
5789 *DTOR_KIND appropriately. */
5792 is_ctor_or_dtor (const char *mangled
,
5793 enum gnu_v3_ctor_kinds
*ctor_kind
,
5794 enum gnu_v3_dtor_kinds
*dtor_kind
)
5797 struct demangle_component
*dc
;
5800 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5801 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5803 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5806 #ifdef CP_DYNAMIC_ARRAYS
5807 __extension__
struct demangle_component comps
[di
.num_comps
];
5808 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5813 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5814 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5817 dc
= cplus_demangle_mangled_name (&di
, 1);
5819 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5820 to demangle the entire string. */
5827 /* These cannot appear on a constructor or destructor. */
5828 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5829 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5830 case DEMANGLE_COMPONENT_CONST_THIS
:
5831 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5832 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5836 case DEMANGLE_COMPONENT_TYPED_NAME
:
5837 case DEMANGLE_COMPONENT_TEMPLATE
:
5840 case DEMANGLE_COMPONENT_QUAL_NAME
:
5841 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5844 case DEMANGLE_COMPONENT_CTOR
:
5845 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5849 case DEMANGLE_COMPONENT_DTOR
:
5850 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5861 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5862 name. A non-zero return indicates the type of constructor. */
5864 enum gnu_v3_ctor_kinds
5865 is_gnu_v3_mangled_ctor (const char *name
)
5867 enum gnu_v3_ctor_kinds ctor_kind
;
5868 enum gnu_v3_dtor_kinds dtor_kind
;
5870 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5871 return (enum gnu_v3_ctor_kinds
) 0;
5876 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5877 name. A non-zero return indicates the type of destructor. */
5879 enum gnu_v3_dtor_kinds
5880 is_gnu_v3_mangled_dtor (const char *name
)
5882 enum gnu_v3_ctor_kinds ctor_kind
;
5883 enum gnu_v3_dtor_kinds dtor_kind
;
5885 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5886 return (enum gnu_v3_dtor_kinds
) 0;
5890 #endif /* IN_GLIBCPP_V3 */
5892 #ifdef STANDALONE_DEMANGLER
5895 #include "dyn-string.h"
5897 static void print_usage (FILE* fp
, int exit_value
);
5899 #define IS_ALPHA(CHAR) \
5900 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5901 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5903 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5904 #define is_mangled_char(CHAR) \
5905 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5906 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5908 /* The name of this program, as invoked. */
5909 const char* program_name
;
5911 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5914 print_usage (FILE* fp
, int exit_value
)
5916 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5917 fprintf (fp
, "Options:\n");
5918 fprintf (fp
, " -h,--help Display this message.\n");
5919 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5920 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5921 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5926 /* Option specification for getopt_long. */
5927 static const struct option long_options
[] =
5929 { "help", no_argument
, NULL
, 'h' },
5930 { "no-params", no_argument
, NULL
, 'p' },
5931 { "verbose", no_argument
, NULL
, 'v' },
5932 { NULL
, no_argument
, NULL
, 0 },
5935 /* Main entry for a demangling filter executable. It will demangle
5936 its command line arguments, if any. If none are provided, it will
5937 filter stdin to stdout, replacing any recognized mangled C++ names
5938 with their demangled equivalents. */
5941 main (int argc
, char *argv
[])
5945 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5947 /* Use the program name of this program, as invoked. */
5948 program_name
= argv
[0];
5950 /* Parse options. */
5953 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5956 case '?': /* Unrecognized option. */
5957 print_usage (stderr
, 1);
5961 print_usage (stdout
, 0);
5965 options
&= ~ DMGL_PARAMS
;
5969 options
|= DMGL_VERBOSE
;
5973 while (opt_char
!= -1);
5976 /* No command line arguments were provided. Filter stdin. */
5978 dyn_string_t mangled
= dyn_string_new (3);
5981 /* Read all of input. */
5982 while (!feof (stdin
))
5986 /* Pile characters into mangled until we hit one that can't
5987 occur in a mangled name. */
5989 while (!feof (stdin
) && is_mangled_char (c
))
5991 dyn_string_append_char (mangled
, c
);
5997 if (dyn_string_length (mangled
) > 0)
5999 #ifdef IN_GLIBCPP_V3
6000 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6002 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6012 /* It might not have been a mangled name. Print the
6014 fputs (dyn_string_buf (mangled
), stdout
);
6017 dyn_string_clear (mangled
);
6020 /* If we haven't hit EOF yet, we've read one character that
6021 can't occur in a mangled name, so print it out. */
6026 dyn_string_delete (mangled
);
6029 /* Demangle command line arguments. */
6031 /* Loop over command line arguments. */
6032 for (i
= optind
; i
< argc
; ++i
)
6035 #ifdef IN_GLIBCPP_V3
6039 /* Attempt to demangle. */
6040 #ifdef IN_GLIBCPP_V3
6041 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6043 s
= cplus_demangle_v3 (argv
[i
], options
);
6046 /* If it worked, print the demangled name. */
6054 #ifdef IN_GLIBCPP_V3
6055 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6057 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6066 #endif /* STANDALONE_DEMANGLER */