1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@wasabisystems.com>.
5 This file is part of the libiberty library, which is part of GCC.
7 This file is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combined
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
31 /* This code implements a demangler for the g++ V3 ABI. The ABI is
32 described on this web page:
33 https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
35 This code was written while looking at the demangler written by
36 Alex Samuel <samuel@codesourcery.com>.
38 This code first pulls the mangled name apart into a list of
39 components, and then walks the list generating the demangled
42 This file will normally define the following functions, q.v.:
43 char *cplus_demangle_v3(const char *mangled, int options)
44 char *java_demangle_v3(const char *mangled)
45 int cplus_demangle_v3_callback(const char *mangled, int options,
46 demangle_callbackref callback)
47 int java_demangle_v3_callback(const char *mangled,
48 demangle_callbackref callback)
49 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
50 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
52 Also, the interface to the component list is public, and defined in
53 demangle.h. The interface consists of these types, which are
54 defined in demangle.h:
55 enum demangle_component_type
56 struct demangle_component
58 and these functions defined in this file:
59 cplus_demangle_fill_name
60 cplus_demangle_fill_extended_operator
61 cplus_demangle_fill_ctor
62 cplus_demangle_fill_dtor
64 cplus_demangle_print_callback
65 and other functions defined in the file cp-demint.c.
67 This file also defines some other functions and variables which are
68 only to be used by the file cp-demint.c.
70 Preprocessor macros you can define while compiling this file:
73 If defined, this file defines the following functions, q.v.:
74 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
76 int __gcclibcxx_demangle_callback (const char *,
78 (const char *, size_t, void *),
80 instead of cplus_demangle_v3[_callback]() and
81 java_demangle_v3[_callback]().
84 If defined, this file defines only __cxa_demangle() and
85 __gcclibcxx_demangle_callback(), and no other publically visible
86 functions or variables.
89 If defined, this file defines a main() function which demangles
90 any arguments, or, if none, demangles stdin.
93 If defined, turns on debugging mode, which prints information on
94 stdout about the mangled string. This is not generally useful.
97 If defined, additional sanity checks will be performed. It will
98 cause some slowdown, but will allow to catch out-of-bound access
99 errors earlier. This macro is intended for testing and debugging. */
101 #if 0 /* in valgrind */
102 #if defined (_AIX) && !defined (__GNUC__)
105 #endif /* ! in valgrind */
107 #if 0 /* in valgrind */
111 #endif /* ! in valgrind */
113 #if 0 /* in valgrind */
115 #endif /* ! in valgrind */
117 #if 0 /* in valgrind */
124 #endif /* ! in valgrind */
126 #if 0 /* in valgrind */
132 # define alloca __builtin_alloca
134 extern char *alloca ();
135 # endif /* __GNUC__ */
137 #endif /* HAVE_ALLOCA_H */
138 #endif /* ! in valgrind */
140 #if 0 /* in valgrind */
144 #endif /* ! in valgrind */
146 # define INT_MAX (int)(((unsigned int) ~0) >> 1) /* 0x7FFFFFFF */
149 #if 0 /* in valgrind */
150 #include "ansidecl.h"
151 #include "libiberty.h"
152 #endif /* ! in valgrind */
154 #include "vg_libciface.h"
156 #include "demangle.h"
157 #include "cp-demangle.h"
159 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
160 also rename them via #define to avoid compiler errors when the
161 static definition conflicts with the extern declaration in a header
165 #define CP_STATIC_IF_GLIBCPP_V3 static
167 #define cplus_demangle_fill_name d_fill_name
168 static int d_fill_name (struct demangle_component
*, const char *, int);
170 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
172 d_fill_extended_operator (struct demangle_component
*, int,
173 struct demangle_component
*);
175 #define cplus_demangle_fill_ctor d_fill_ctor
177 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
178 struct demangle_component
*);
180 #define cplus_demangle_fill_dtor d_fill_dtor
182 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
183 struct demangle_component
*);
185 #define cplus_demangle_mangled_name d_mangled_name
186 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
188 #define cplus_demangle_type d_type
189 static struct demangle_component
*d_type (struct d_info
*);
191 #define cplus_demangle_print d_print
192 static char *d_print (int, struct demangle_component
*, int, size_t *);
194 #define cplus_demangle_print_callback d_print_callback
195 static int d_print_callback (int, struct demangle_component
*,
196 demangle_callbackref
, void *);
198 #define cplus_demangle_init_info d_init_info
199 static void d_init_info (const char *, int, size_t, struct d_info
*);
201 #else /* ! defined(IN_GLIBCPP_V3) */
202 #define CP_STATIC_IF_GLIBCPP_V3
203 #endif /* ! defined(IN_GLIBCPP_V3) */
205 /* See if the compiler supports dynamic arrays. */
208 #define CP_DYNAMIC_ARRAYS
211 #ifdef __STDC_VERSION__
212 #if __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__
213 #define CP_DYNAMIC_ARRAYS
214 #endif /* __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ */
215 #endif /* defined (__STDC_VERSION__) */
216 #endif /* defined (__STDC__) */
217 #endif /* ! defined (__GNUC__) */
219 /* We avoid pulling in the ctype tables, to prevent pulling in
220 additional unresolved symbols when this code is used in a library.
221 FIXME: Is this really a valid reason? This comes from the original
224 As of this writing this file has the following undefined references
225 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
228 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
229 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
230 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
232 /* The prefix prepended by GCC to an identifier represnting the
233 anonymous namespace. */
234 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
235 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
236 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
238 /* Information we keep for the standard substitutions. */
240 struct d_standard_sub_info
242 /* The code for this substitution. */
244 /* The simple string it expands to. */
245 const char *simple_expansion
;
246 /* The length of the simple expansion. */
248 /* The results of a full, verbose, expansion. This is used when
249 qualifying a constructor/destructor, or when in verbose mode. */
250 const char *full_expansion
;
251 /* The length of the full expansion. */
253 /* What to set the last_name field of d_info to; NULL if we should
254 not set it. This is only relevant when qualifying a
255 constructor/destructor. */
256 const char *set_last_name
;
257 /* The length of set_last_name. */
258 int set_last_name_len
;
261 /* Accessors for subtrees of struct demangle_component. */
263 #define d_left(dc) ((dc)->u.s_binary.left)
264 #define d_right(dc) ((dc)->u.s_binary.right)
266 /* A list of templates. This is used while printing. */
268 struct d_print_template
270 /* Next template on the list. */
271 struct d_print_template
*next
;
273 const struct demangle_component
*template_decl
;
276 /* A list of type modifiers. This is used while printing. */
280 /* Next modifier on the list. These are in the reverse of the order
281 in which they appeared in the mangled string. */
282 struct d_print_mod
*next
;
284 struct demangle_component
*mod
;
285 /* Whether this modifier was printed. */
287 /* The list of templates which applies to this modifier. */
288 struct d_print_template
*templates
;
291 /* We use these structures to hold information during printing. */
293 struct d_growable_string
295 /* Buffer holding the result. */
297 /* Current length of data in buffer. */
299 /* Allocated size of buffer. */
301 /* Set to 1 if we had a memory allocation failure. */
302 int allocation_failure
;
305 /* Stack of components, innermost first, used to avoid loops. */
307 struct d_component_stack
309 /* This component. */
310 const struct demangle_component
*dc
;
311 /* This component's parent. */
312 const struct d_component_stack
*parent
;
315 /* A demangle component and some scope captured when it was first
320 /* The component whose scope this is. */
321 const struct demangle_component
*container
;
322 /* The list of templates, if any, that was current when this
323 scope was captured. */
324 struct d_print_template
*templates
;
327 /* Checkpoint structure to allow backtracking. This holds copies
328 of the fields of struct d_info that need to be restored
329 if a trial parse needs to be backtracked over. */
331 struct d_info_checkpoint
339 /* Maximum number of times d_print_comp may be called recursively. */
340 #define MAX_RECURSION_COUNT 1024
342 enum { D_PRINT_BUFFER_LENGTH
= 256 };
345 /* Fixed-length allocated buffer for demangled data, flushed to the
346 callback with a NUL termination once full. */
347 char buf
[D_PRINT_BUFFER_LENGTH
];
348 /* Current length of data in buffer. */
350 /* The last character printed, saved individually so that it survives
353 /* Callback function to handle demangled buffer flush. */
354 demangle_callbackref callback
;
355 /* Opaque callback argument. */
357 /* The current list of templates, if any. */
358 struct d_print_template
*templates
;
359 /* The current list of modifiers (e.g., pointer, reference, etc.),
361 struct d_print_mod
*modifiers
;
362 /* Set to 1 if we saw a demangling error. */
363 int demangle_failure
;
364 /* Number of times d_print_comp was recursively called. Should not
365 be bigger than MAX_RECURSION_COUNT. */
367 /* 1 more than the number of explicit template parms of a lambda. Template
368 parm references >= are actually 'auto'. */
369 int lambda_tpl_parms
;
370 /* The current index into any template argument packs we are using
371 for printing, or -1 to print the whole pack. */
373 /* Number of d_print_flush calls so far. */
374 unsigned long int flush_count
;
375 /* Stack of components, innermost first, used to avoid loops. */
376 const struct d_component_stack
*component_stack
;
377 /* Array of saved scopes for evaluating substitutions. */
378 struct d_saved_scope
*saved_scopes
;
379 /* Index of the next unused saved scope in the above array. */
380 int next_saved_scope
;
381 /* Number of saved scopes in the above array. */
382 int num_saved_scopes
;
383 /* Array of templates for saving into scopes. */
384 struct d_print_template
*copy_templates
;
385 /* Index of the next unused copy template in the above array. */
386 int next_copy_template
;
387 /* Number of copy templates in the above array. */
388 int num_copy_templates
;
389 /* The nearest enclosing template, if any. */
390 const struct demangle_component
*current_template
;
393 #ifdef CP_DEMANGLE_DEBUG
394 static void d_dump (struct demangle_component
*, int);
397 static struct demangle_component
*
398 d_make_empty (struct d_info
*);
400 static struct demangle_component
*
401 d_make_comp (struct d_info
*, enum demangle_component_type
,
402 struct demangle_component
*,
403 struct demangle_component
*);
405 static struct demangle_component
*
406 d_make_name (struct d_info
*, const char *, int);
408 static struct demangle_component
*
409 d_make_demangle_mangled_name (struct d_info
*, const char *);
411 static struct demangle_component
*
412 d_make_builtin_type (struct d_info
*,
413 const struct demangle_builtin_type_info
*);
415 static struct demangle_component
*
416 d_make_operator (struct d_info
*,
417 const struct demangle_operator_info
*);
419 static struct demangle_component
*
420 d_make_extended_operator (struct d_info
*, int,
421 struct demangle_component
*);
423 static struct demangle_component
*
424 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
425 struct demangle_component
*);
427 static struct demangle_component
*
428 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
429 struct demangle_component
*);
431 static struct demangle_component
*
432 d_make_template_param (struct d_info
*, int);
434 static struct demangle_component
*
435 d_make_sub (struct d_info
*, const char *, int);
438 has_return_type (struct demangle_component
*);
441 is_ctor_dtor_or_conversion (struct demangle_component
*);
443 static struct demangle_component
*d_encoding (struct d_info
*, int);
445 static struct demangle_component
*d_name (struct d_info
*, int substable
);
447 static struct demangle_component
*d_nested_name (struct d_info
*);
449 static int d_maybe_module_name (struct d_info
*, struct demangle_component
**);
451 static struct demangle_component
*d_prefix (struct d_info
*, int);
453 static struct demangle_component
*d_unqualified_name (struct d_info
*,
454 struct demangle_component
*scope
, struct demangle_component
*module
);
456 static struct demangle_component
*d_source_name (struct d_info
*);
458 static int d_number (struct d_info
*);
460 static struct demangle_component
*d_identifier (struct d_info
*, int);
462 static struct demangle_component
*d_operator_name (struct d_info
*);
464 static struct demangle_component
*d_special_name (struct d_info
*);
466 static struct demangle_component
*d_parmlist (struct d_info
*);
468 static int d_call_offset (struct d_info
*, int);
470 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
472 static struct demangle_component
**
473 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
475 static struct demangle_component
*
476 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
478 static struct demangle_component
*
479 d_function_type (struct d_info
*);
481 static struct demangle_component
*
482 d_bare_function_type (struct d_info
*, int);
484 static struct demangle_component
*
485 d_class_enum_type (struct d_info
*, int);
487 static struct demangle_component
*d_array_type (struct d_info
*);
489 static struct demangle_component
*d_vector_type (struct d_info
*);
491 static struct demangle_component
*
492 d_pointer_to_member_type (struct d_info
*);
494 static struct demangle_component
*
495 d_template_param (struct d_info
*);
497 static struct demangle_component
*d_template_args (struct d_info
*);
498 static struct demangle_component
*d_template_args_1 (struct d_info
*);
500 static struct demangle_component
*
501 d_template_arg (struct d_info
*);
503 static struct demangle_component
*d_expression (struct d_info
*);
505 static struct demangle_component
*d_expr_primary (struct d_info
*);
507 static struct demangle_component
*d_local_name (struct d_info
*);
509 static int d_discriminator (struct d_info
*);
511 static struct demangle_component
*d_template_parm (struct d_info
*, int *bad
);
513 static struct demangle_component
*d_template_head (struct d_info
*, int *bad
);
515 static struct demangle_component
*d_lambda (struct d_info
*);
517 static struct demangle_component
*d_unnamed_type (struct d_info
*);
519 static struct demangle_component
*
520 d_clone_suffix (struct d_info
*, struct demangle_component
*);
523 d_add_substitution (struct d_info
*, struct demangle_component
*);
525 static struct demangle_component
*d_substitution (struct d_info
*, int);
527 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
529 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
531 static void d_growable_string_init (struct d_growable_string
*, size_t);
534 d_growable_string_resize (struct d_growable_string
*, size_t);
537 d_growable_string_append_buffer (struct d_growable_string
*,
538 const char *, size_t);
540 d_growable_string_callback_adapter (const char *, size_t, void *);
543 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
544 struct demangle_component
*);
546 static inline void d_print_error (struct d_print_info
*);
548 static inline int d_print_saw_error (struct d_print_info
*);
550 static inline void d_print_flush (struct d_print_info
*);
552 static inline void d_append_char (struct d_print_info
*, char);
554 static inline void d_append_buffer (struct d_print_info
*,
555 const char *, size_t);
557 static inline void d_append_string (struct d_print_info
*, const char *);
559 static inline char d_last_char (struct d_print_info
*);
562 d_print_comp (struct d_print_info
*, int, struct demangle_component
*);
565 d_print_java_identifier (struct d_print_info
*, const char *, int);
568 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
571 d_print_mod (struct d_print_info
*, int, struct demangle_component
*);
574 d_print_function_type (struct d_print_info
*, int,
575 struct demangle_component
*,
576 struct d_print_mod
*);
579 d_print_array_type (struct d_print_info
*, int,
580 struct demangle_component
*,
581 struct d_print_mod
*);
584 d_print_expr_op (struct d_print_info
*, int, struct demangle_component
*);
586 static void d_print_cast (struct d_print_info
*, int,
587 struct demangle_component
*);
588 static void d_print_conversion (struct d_print_info
*, int,
589 struct demangle_component
*);
591 static int d_demangle_callback (const char *, int,
592 demangle_callbackref
, void *);
593 static char *d_demangle (const char *, int, size_t *);
595 #define FNQUAL_COMPONENT_CASE \
596 case DEMANGLE_COMPONENT_RESTRICT_THIS: \
597 case DEMANGLE_COMPONENT_VOLATILE_THIS: \
598 case DEMANGLE_COMPONENT_CONST_THIS: \
599 case DEMANGLE_COMPONENT_REFERENCE_THIS: \
600 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \
601 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: \
602 case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \
603 case DEMANGLE_COMPONENT_NOEXCEPT: \
604 case DEMANGLE_COMPONENT_THROW_SPEC
606 /* True iff TYPE is a demangling component representing a
607 function-type-qualifier. */
610 is_fnqual_component_type (enum demangle_component_type type
)
614 FNQUAL_COMPONENT_CASE
:
623 #ifdef CP_DEMANGLE_DEBUG
626 d_dump (struct demangle_component
*dc
, int indent
)
633 printf ("failed demangling\n");
637 for (i
= 0; i
< indent
; ++i
)
642 case DEMANGLE_COMPONENT_NAME
:
643 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
645 case DEMANGLE_COMPONENT_TAGGED_NAME
:
646 printf ("tagged name\n");
647 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
648 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
650 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
651 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
653 case DEMANGLE_COMPONENT_TPARM_OBJ
:
654 printf ("template parameter object\n");
656 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
657 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
659 case DEMANGLE_COMPONENT_CTOR
:
660 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
661 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
663 case DEMANGLE_COMPONENT_DTOR
:
664 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
665 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
667 case DEMANGLE_COMPONENT_SUB_STD
:
668 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
670 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
671 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
673 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
675 char suffix
[2] = { dc
->u
.s_extended_builtin
.type
->suffix
, 0 };
676 printf ("builtin type %s%d%s\n", dc
->u
.s_extended_builtin
.type
->name
,
677 dc
->u
.s_extended_builtin
.type
->arg
, suffix
);
680 case DEMANGLE_COMPONENT_OPERATOR
:
681 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
683 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
684 printf ("extended operator with %d args\n",
685 dc
->u
.s_extended_operator
.args
);
686 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
689 case DEMANGLE_COMPONENT_QUAL_NAME
:
690 printf ("qualified name\n");
692 case DEMANGLE_COMPONENT_LOCAL_NAME
:
693 printf ("local name\n");
695 case DEMANGLE_COMPONENT_TYPED_NAME
:
696 printf ("typed name\n");
698 case DEMANGLE_COMPONENT_TEMPLATE
:
699 printf ("template\n");
701 case DEMANGLE_COMPONENT_VTABLE
:
704 case DEMANGLE_COMPONENT_VTT
:
707 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
708 printf ("construction vtable\n");
710 case DEMANGLE_COMPONENT_TYPEINFO
:
711 printf ("typeinfo\n");
713 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
714 printf ("typeinfo name\n");
716 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
717 printf ("typeinfo function\n");
719 case DEMANGLE_COMPONENT_THUNK
:
722 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
723 printf ("virtual thunk\n");
725 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
726 printf ("covariant thunk\n");
728 case DEMANGLE_COMPONENT_JAVA_CLASS
:
729 printf ("java class\n");
731 case DEMANGLE_COMPONENT_GUARD
:
734 case DEMANGLE_COMPONENT_REFTEMP
:
735 printf ("reference temporary\n");
737 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
738 printf ("hidden alias\n");
740 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
741 printf ("transaction clone\n");
743 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
744 printf ("non-transaction clone\n");
746 case DEMANGLE_COMPONENT_RESTRICT
:
747 printf ("restrict\n");
749 case DEMANGLE_COMPONENT_VOLATILE
:
750 printf ("volatile\n");
752 case DEMANGLE_COMPONENT_CONST
:
755 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
756 printf ("restrict this\n");
758 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
759 printf ("volatile this\n");
761 case DEMANGLE_COMPONENT_CONST_THIS
:
762 printf ("const this\n");
764 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
765 printf ("reference this\n");
767 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
768 printf ("rvalue reference this\n");
770 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
771 printf ("explicit object parameter\n");
773 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
774 printf ("transaction_safe this\n");
776 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
777 printf ("vendor type qualifier\n");
779 case DEMANGLE_COMPONENT_POINTER
:
780 printf ("pointer\n");
782 case DEMANGLE_COMPONENT_REFERENCE
:
783 printf ("reference\n");
785 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
786 printf ("rvalue reference\n");
788 case DEMANGLE_COMPONENT_COMPLEX
:
789 printf ("complex\n");
791 case DEMANGLE_COMPONENT_IMAGINARY
:
792 printf ("imaginary\n");
794 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
795 printf ("vendor type\n");
797 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
798 printf ("function type\n");
800 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
801 printf ("array type\n");
803 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
804 printf ("pointer to member type\n");
806 case DEMANGLE_COMPONENT_ARGLIST
:
807 printf ("argument list\n");
809 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
810 printf ("template argument list\n");
812 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
813 printf ("initializer list\n");
815 case DEMANGLE_COMPONENT_CAST
:
818 case DEMANGLE_COMPONENT_CONVERSION
:
819 printf ("conversion operator\n");
821 case DEMANGLE_COMPONENT_NULLARY
:
822 printf ("nullary operator\n");
824 case DEMANGLE_COMPONENT_UNARY
:
825 printf ("unary operator\n");
827 case DEMANGLE_COMPONENT_BINARY
:
828 printf ("binary operator\n");
830 case DEMANGLE_COMPONENT_BINARY_ARGS
:
831 printf ("binary operator arguments\n");
833 case DEMANGLE_COMPONENT_TRINARY
:
834 printf ("trinary operator\n");
836 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
837 printf ("trinary operator arguments 1\n");
839 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
840 printf ("trinary operator arguments 1\n");
842 case DEMANGLE_COMPONENT_LITERAL
:
843 printf ("literal\n");
845 case DEMANGLE_COMPONENT_LITERAL_NEG
:
846 printf ("negative literal\n");
848 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
849 printf ("vendor expression\n");
851 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
852 printf ("java resource\n");
854 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
855 printf ("compound name\n");
857 case DEMANGLE_COMPONENT_CHARACTER
:
858 printf ("character '%c'\n", dc
->u
.s_character
.character
);
860 case DEMANGLE_COMPONENT_NUMBER
:
861 printf ("number %ld\n", dc
->u
.s_number
.number
);
863 case DEMANGLE_COMPONENT_DECLTYPE
:
864 printf ("decltype\n");
866 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
867 printf ("pack expansion\n");
869 case DEMANGLE_COMPONENT_TLS_INIT
:
870 printf ("tls init function\n");
872 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
873 printf ("tls wrapper function\n");
875 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
876 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
877 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
879 case DEMANGLE_COMPONENT_LAMBDA
:
880 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
881 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
885 d_dump (d_left (dc
), indent
+ 2);
886 d_dump (d_right (dc
), indent
+ 2);
889 #endif /* CP_DEMANGLE_DEBUG */
891 /* Fill in a DEMANGLE_COMPONENT_NAME. */
893 CP_STATIC_IF_GLIBCPP_V3
895 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
897 if (p
== NULL
|| s
== NULL
|| len
<= 0)
901 p
->type
= DEMANGLE_COMPONENT_NAME
;
903 p
->u
.s_name
.len
= len
;
907 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
909 CP_STATIC_IF_GLIBCPP_V3
911 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
912 struct demangle_component
*name
)
914 if (p
== NULL
|| args
< 0 || name
== NULL
)
918 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
919 p
->u
.s_extended_operator
.args
= args
;
920 p
->u
.s_extended_operator
.name
= name
;
924 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
926 CP_STATIC_IF_GLIBCPP_V3
928 cplus_demangle_fill_ctor (struct demangle_component
*p
,
929 enum gnu_v3_ctor_kinds kind
,
930 struct demangle_component
*name
)
934 || (int) kind
< gnu_v3_complete_object_ctor
935 || (int) kind
> gnu_v3_object_ctor_group
)
939 p
->type
= DEMANGLE_COMPONENT_CTOR
;
940 p
->u
.s_ctor
.kind
= kind
;
941 p
->u
.s_ctor
.name
= name
;
945 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
947 CP_STATIC_IF_GLIBCPP_V3
949 cplus_demangle_fill_dtor (struct demangle_component
*p
,
950 enum gnu_v3_dtor_kinds kind
,
951 struct demangle_component
*name
)
955 || (int) kind
< gnu_v3_deleting_dtor
956 || (int) kind
> gnu_v3_object_dtor_group
)
960 p
->type
= DEMANGLE_COMPONENT_DTOR
;
961 p
->u
.s_dtor
.kind
= kind
;
962 p
->u
.s_dtor
.name
= name
;
966 /* Add a new component. */
968 static struct demangle_component
*
969 d_make_empty (struct d_info
*di
)
971 struct demangle_component
*p
;
973 if (di
->next_comp
>= di
->num_comps
)
975 p
= &di
->comps
[di
->next_comp
];
982 /* Add a new generic component. */
984 static struct demangle_component
*
985 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
986 struct demangle_component
*left
,
987 struct demangle_component
*right
)
989 struct demangle_component
*p
;
991 /* We check for errors here. A typical error would be a NULL return
992 from a subroutine. We catch those here, and return NULL
996 /* These types require two parameters. */
997 case DEMANGLE_COMPONENT_QUAL_NAME
:
998 case DEMANGLE_COMPONENT_LOCAL_NAME
:
999 case DEMANGLE_COMPONENT_TYPED_NAME
:
1000 case DEMANGLE_COMPONENT_TAGGED_NAME
:
1001 case DEMANGLE_COMPONENT_TEMPLATE
:
1002 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
1003 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
1004 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
1005 case DEMANGLE_COMPONENT_UNARY
:
1006 case DEMANGLE_COMPONENT_BINARY
:
1007 case DEMANGLE_COMPONENT_BINARY_ARGS
:
1008 case DEMANGLE_COMPONENT_TRINARY
:
1009 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
1010 case DEMANGLE_COMPONENT_LITERAL
:
1011 case DEMANGLE_COMPONENT_LITERAL_NEG
:
1012 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
1013 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
1014 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
1015 case DEMANGLE_COMPONENT_CLONE
:
1016 case DEMANGLE_COMPONENT_MODULE_ENTITY
:
1017 case DEMANGLE_COMPONENT_CONSTRAINTS
:
1018 if (left
== NULL
|| right
== NULL
)
1022 /* These types only require one parameter. */
1023 case DEMANGLE_COMPONENT_VTABLE
:
1024 case DEMANGLE_COMPONENT_VTT
:
1025 case DEMANGLE_COMPONENT_TYPEINFO
:
1026 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
1027 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
1028 case DEMANGLE_COMPONENT_THUNK
:
1029 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
1030 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
1031 case DEMANGLE_COMPONENT_JAVA_CLASS
:
1032 case DEMANGLE_COMPONENT_GUARD
:
1033 case DEMANGLE_COMPONENT_TLS_INIT
:
1034 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
1035 case DEMANGLE_COMPONENT_REFTEMP
:
1036 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
1037 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
1038 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
1039 case DEMANGLE_COMPONENT_POINTER
:
1040 case DEMANGLE_COMPONENT_REFERENCE
:
1041 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
1042 case DEMANGLE_COMPONENT_COMPLEX
:
1043 case DEMANGLE_COMPONENT_IMAGINARY
:
1044 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
1045 case DEMANGLE_COMPONENT_CAST
:
1046 case DEMANGLE_COMPONENT_CONVERSION
:
1047 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
1048 case DEMANGLE_COMPONENT_DECLTYPE
:
1049 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
1050 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
1051 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
1052 case DEMANGLE_COMPONENT_NULLARY
:
1053 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
1054 case DEMANGLE_COMPONENT_TPARM_OBJ
:
1055 case DEMANGLE_COMPONENT_STRUCTURED_BINDING
:
1056 case DEMANGLE_COMPONENT_MODULE_INIT
:
1057 case DEMANGLE_COMPONENT_TEMPLATE_HEAD
:
1058 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
1059 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
1060 case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
:
1061 case DEMANGLE_COMPONENT_FRIEND
:
1066 /* This needs a right parameter, but the left parameter can be
1068 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
1069 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
1070 case DEMANGLE_COMPONENT_MODULE_NAME
:
1071 case DEMANGLE_COMPONENT_MODULE_PARTITION
:
1076 /* These are allowed to have no parameters--in some cases they
1077 will be filled in later. */
1078 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
1079 case DEMANGLE_COMPONENT_RESTRICT
:
1080 case DEMANGLE_COMPONENT_VOLATILE
:
1081 case DEMANGLE_COMPONENT_CONST
:
1082 case DEMANGLE_COMPONENT_ARGLIST
:
1083 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
1084 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
1085 FNQUAL_COMPONENT_CASE
:
1088 /* Other types should not be seen here. */
1093 p
= d_make_empty (di
);
1097 p
->u
.s_binary
.left
= left
;
1098 p
->u
.s_binary
.right
= right
;
1103 /* Add a new demangle mangled name component. */
1105 static struct demangle_component
*
1106 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
1108 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1109 return d_make_name (di
, s
, strlen (s
));
1111 return d_encoding (di
, 0);
1114 /* Add a new name component. */
1116 static struct demangle_component
*
1117 d_make_name (struct d_info
*di
, const char *s
, int len
)
1119 struct demangle_component
*p
;
1121 p
= d_make_empty (di
);
1122 if (! cplus_demangle_fill_name (p
, s
, len
))
1127 /* Add a new builtin type component. */
1129 static struct demangle_component
*
1130 d_make_builtin_type (struct d_info
*di
,
1131 const struct demangle_builtin_type_info
*type
)
1133 struct demangle_component
*p
;
1137 p
= d_make_empty (di
);
1140 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1141 p
->u
.s_builtin
.type
= type
;
1146 /* Add a new extended builtin type component. */
1148 static struct demangle_component
*
1149 d_make_extended_builtin_type (struct d_info
*di
,
1150 const struct demangle_builtin_type_info
*type
,
1151 short arg
, char suffix
)
1153 struct demangle_component
*p
;
1157 p
= d_make_empty (di
);
1160 p
->type
= DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
;
1161 p
->u
.s_extended_builtin
.type
= type
;
1162 p
->u
.s_extended_builtin
.arg
= arg
;
1163 p
->u
.s_extended_builtin
.suffix
= suffix
;
1168 /* Add a new operator component. */
1170 static struct demangle_component
*
1171 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1173 struct demangle_component
*p
;
1175 p
= d_make_empty (di
);
1178 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1179 p
->u
.s_operator
.op
= op
;
1184 /* Add a new extended operator component. */
1186 static struct demangle_component
*
1187 d_make_extended_operator (struct d_info
*di
, int args
,
1188 struct demangle_component
*name
)
1190 struct demangle_component
*p
;
1192 p
= d_make_empty (di
);
1193 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1198 static struct demangle_component
*
1199 d_make_default_arg (struct d_info
*di
, int num
,
1200 struct demangle_component
*sub
)
1202 struct demangle_component
*p
= d_make_empty (di
);
1205 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1206 p
->u
.s_unary_num
.num
= num
;
1207 p
->u
.s_unary_num
.sub
= sub
;
1212 /* Add a new constructor component. */
1214 static struct demangle_component
*
1215 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1216 struct demangle_component
*name
)
1218 struct demangle_component
*p
;
1220 p
= d_make_empty (di
);
1221 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1226 /* Add a new destructor component. */
1228 static struct demangle_component
*
1229 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1230 struct demangle_component
*name
)
1232 struct demangle_component
*p
;
1234 p
= d_make_empty (di
);
1235 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1240 /* Add a new template parameter. */
1242 static struct demangle_component
*
1243 d_make_template_param (struct d_info
*di
, int i
)
1245 struct demangle_component
*p
;
1247 p
= d_make_empty (di
);
1250 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1251 p
->u
.s_number
.number
= i
;
1256 /* Add a new function parameter. */
1258 static struct demangle_component
*
1259 d_make_function_param (struct d_info
*di
, int i
)
1261 struct demangle_component
*p
;
1263 p
= d_make_empty (di
);
1266 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1267 p
->u
.s_number
.number
= i
;
1272 /* Add a new standard substitution component. */
1274 static struct demangle_component
*
1275 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1277 struct demangle_component
*p
;
1279 p
= d_make_empty (di
);
1282 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1283 p
->u
.s_string
.string
= name
;
1284 p
->u
.s_string
.len
= len
;
1289 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1291 TOP_LEVEL is non-zero when called at the top level. */
1293 CP_STATIC_IF_GLIBCPP_V3
1294 struct demangle_component
*
1295 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1297 struct demangle_component
*p
;
1299 if (! d_check_char (di
, '_')
1300 /* Allow missing _ if not at toplevel to work around a
1301 bug in G++ abi-version=2 mangling; see the comment in
1302 write_template_arg. */
1305 if (! d_check_char (di
, 'Z'))
1307 p
= d_encoding (di
, top_level
);
1309 /* If at top level and parsing parameters, check for a clone
1311 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1312 while (d_peek_char (di
) == '.'
1313 && (IS_LOWER (d_peek_next_char (di
))
1314 || d_peek_next_char (di
) == '_'
1315 || IS_DIGIT (d_peek_next_char (di
))))
1316 p
= d_clone_suffix (di
, p
);
1321 /* Return whether a function should have a return type. The argument
1322 is the function name, which may be qualified in various ways. The
1323 rules are that template functions have return types with some
1324 exceptions, function types which are not part of a function name
1325 mangling have return types with some exceptions, and non-template
1326 function names do not have return types. The exceptions are that
1327 constructors, destructors, and conversion operators do not have
1331 has_return_type (struct demangle_component
*dc
)
1339 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1340 return has_return_type (d_right (dc
));
1341 case DEMANGLE_COMPONENT_TEMPLATE
:
1342 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1343 FNQUAL_COMPONENT_CASE
:
1344 return has_return_type (d_left (dc
));
1348 /* Return whether a name is a constructor, a destructor, or a
1349 conversion operator. */
1352 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1360 case DEMANGLE_COMPONENT_QUAL_NAME
:
1361 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1362 return is_ctor_dtor_or_conversion (d_right (dc
));
1363 case DEMANGLE_COMPONENT_CTOR
:
1364 case DEMANGLE_COMPONENT_DTOR
:
1365 case DEMANGLE_COMPONENT_CONVERSION
:
1370 /* [ Q <constraint-expression> ] */
1372 static struct demangle_component
*
1373 d_maybe_constraints (struct d_info
*di
, struct demangle_component
*dc
)
1375 if (d_peek_char (di
) == 'Q')
1378 struct demangle_component
*expr
= d_expression (di
);
1381 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRAINTS
, dc
, expr
);
1386 /* <encoding> ::= <(function) name> <bare-function-type>
1390 TOP_LEVEL is non-zero when called at the top level, in which case
1391 if DMGL_PARAMS is not set we do not demangle the function
1392 parameters. We only set this at the top level, because otherwise
1393 we would not correctly demangle names in local scopes. */
1395 static struct demangle_component
*
1396 d_encoding (struct d_info
*di
, int top_level
)
1398 char peek
= d_peek_char (di
);
1399 struct demangle_component
*dc
;
1401 if (peek
== 'G' || peek
== 'T')
1402 dc
= d_special_name (di
);
1405 dc
= d_name (di
, 0);
1408 /* Failed already. */;
1409 else if (top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1411 /* Strip off any initial CV-qualifiers, as they really apply
1412 to the `this' parameter, and they were not output by the
1413 v2 demangler without DMGL_PARAMS. */
1414 while (is_fnqual_component_type (dc
->type
))
1417 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1418 there may be function-qualifiers on its right argument which
1419 really apply here; this happens when parsing a class
1420 which is local to a function. */
1421 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1423 while (d_right (dc
) != NULL
1424 && is_fnqual_component_type (d_right (dc
)->type
))
1425 d_right (dc
) = d_left (d_right (dc
));
1427 if (d_right (dc
) == NULL
)
1433 peek
= d_peek_char (di
);
1434 if (peek
!= '\0' && peek
!= 'E')
1436 struct demangle_component
*ftype
;
1438 ftype
= d_bare_function_type (di
, has_return_type (dc
));
1442 /* If this is a non-top-level local-name, clear the
1443 return type, so it doesn't confuse the user by
1444 being confused with the return type of whaever
1445 this is nested within. */
1446 if (!top_level
&& dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
1447 && ftype
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
1448 d_left (ftype
) = NULL
;
1450 ftype
= d_maybe_constraints (di
, ftype
);
1452 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
,
1461 /* <tagged-name> ::= <name> B <source-name> */
1463 static struct demangle_component
*
1464 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1466 struct demangle_component
*hold_last_name
;
1469 /* Preserve the last name, so the ABI tag doesn't clobber it. */
1470 hold_last_name
= di
->last_name
;
1472 while (peek
= d_peek_char (di
),
1475 struct demangle_component
*tag
;
1477 tag
= d_source_name (di
);
1478 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1481 di
->last_name
= hold_last_name
;
1486 /* <name> ::= <nested-name>
1488 ::= <unscoped-template-name> <template-args>
1491 <unscoped-name> ::= <unqualified-name>
1492 ::= St <unqualified-name>
1494 <unscoped-template-name> ::= <unscoped-name>
1498 static struct demangle_component
*
1499 d_name (struct d_info
*di
, int substable
)
1501 char peek
= d_peek_char (di
);
1502 struct demangle_component
*dc
= NULL
;
1503 struct demangle_component
*module
= NULL
;
1509 dc
= d_nested_name (di
);
1513 dc
= d_local_name (di
);
1517 dc
= d_unqualified_name (di
, NULL
, NULL
);
1522 if (d_peek_next_char (di
) == 't')
1525 dc
= d_make_name (di
, "std", 3);
1529 if (d_peek_char (di
) == 'S')
1531 module
= d_substitution (di
, 0);
1534 if (!(module
->type
== DEMANGLE_COMPONENT_MODULE_NAME
1535 || module
->type
== DEMANGLE_COMPONENT_MODULE_PARTITION
))
1550 dc
= d_unqualified_name (di
, dc
, module
);
1551 if (d_peek_char (di
) == 'I')
1553 /* This is <template-args>, which means that we just saw
1554 <unscoped-template-name>, which is a substitution
1556 if (!subst
&& !d_add_substitution (di
, dc
))
1558 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1559 d_template_args (di
));
1564 if (substable
&& !subst
&& !d_add_substitution (di
, dc
))
1569 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1570 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1571 ::= N H <prefix> <unqualified-name> E
1572 ::= N H <template-prefix> <template-args> E
1575 static struct demangle_component
*
1576 d_nested_name (struct d_info
*di
)
1578 struct demangle_component
*ret
;
1579 struct demangle_component
**pret
;
1580 struct demangle_component
*rqual
;
1582 if (! d_check_char (di
, 'N'))
1585 if (d_peek_char (di
) == 'H')
1588 di
->expansion
+= sizeof "this";
1590 rqual
= d_make_comp (di
, DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
,
1595 pret
= d_cv_qualifiers (di
, &ret
, 1);
1599 /* Parse the ref-qualifier now and then attach it
1600 once we have something to attach it to. */
1601 rqual
= d_ref_qualifier (di
, NULL
);
1604 *pret
= d_prefix (di
, 1);
1610 d_left (rqual
) = ret
;
1614 if (! d_check_char (di
, 'E'))
1620 /* <prefix> ::= <prefix> <unqualified-name>
1621 ::= <template-prefix> <template-args>
1622 ::= <template-param>
1627 <template-prefix> ::= <prefix> <(template) unqualified-name>
1628 ::= <template-param>
1631 SUBST is true if we should add substitutions (as normal), false
1632 if not (in an unresolved-name). */
1634 static struct demangle_component
*
1635 d_prefix (struct d_info
*di
, int substable
)
1637 struct demangle_component
*ret
= NULL
;
1641 char peek
= d_peek_char (di
);
1643 /* The older code accepts a <local-name> here, but I don't see
1644 that in the grammar. The older code does not accept a
1645 <template-param> here. */
1648 && (d_peek_next_char (di
) == 'T'
1649 || d_peek_next_char (di
) == 't'))
1654 ret
= cplus_demangle_type (di
);
1656 else if (peek
== 'I')
1660 struct demangle_component
*dc
= d_template_args (di
);
1663 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
, dc
);
1665 else if (peek
== 'T')
1669 ret
= d_template_param (di
);
1671 else if (peek
== 'M')
1673 /* Initializer scope for a lambda. We already added it as a
1674 substitution candidate, don't do that again. */
1680 struct demangle_component
*module
= NULL
;
1683 module
= d_substitution (di
, 1);
1686 if (!(module
->type
== DEMANGLE_COMPONENT_MODULE_NAME
1687 || module
->type
== DEMANGLE_COMPONENT_MODULE_PARTITION
))
1695 ret
= d_unqualified_name (di
, ret
, module
);
1701 if (d_peek_char (di
) == 'E')
1704 if (substable
&& !d_add_substitution (di
, ret
))
1712 d_maybe_module_name (struct d_info
*di
, struct demangle_component
**name
)
1714 while (d_peek_char (di
) == 'W')
1717 enum demangle_component_type code
= DEMANGLE_COMPONENT_MODULE_NAME
;
1718 if (d_peek_char (di
) == 'P')
1720 code
= DEMANGLE_COMPONENT_MODULE_PARTITION
;
1724 *name
= d_make_comp (di
, code
, *name
, d_source_name (di
));
1727 if (!d_add_substitution (di
, *name
))
1733 /* <unqualified-name> ::= [<module-name>] <operator-name> [<abi-tags>]
1734 ::= [<module-name>] <ctor-dtor-name> [<abi-tags>]
1735 ::= [<module-name>] <source-name> [<abi-tags>]
1736 ::= [<module-name>] F <source-name> [<abi-tags>]
1737 ::= [<module-name>] <local-source-name> [<abi-tags>]
1738 ::= [<module-name>] DC <source-name>+ E [<abi-tags>]
1739 <local-source-name> ::= L <source-name> <discriminator> [<abi-tags>]
1742 static struct demangle_component
*
1743 d_unqualified_name (struct d_info
*di
, struct demangle_component
*scope
,
1744 struct demangle_component
*module
)
1746 struct demangle_component
*ret
;
1748 int member_like_friend
= 0;
1750 if (!d_maybe_module_name (di
, &module
))
1753 peek
= d_peek_char (di
);
1756 member_like_friend
= 1;
1758 peek
= d_peek_char (di
);
1760 if (IS_DIGIT (peek
))
1761 ret
= d_source_name (di
);
1762 else if (IS_LOWER (peek
))
1764 int was_expr
= di
->is_expression
;
1765 if (peek
== 'o' && d_peek_next_char (di
) == 'n')
1768 /* Treat cv as naming a conversion operator. */
1769 di
->is_expression
= 0;
1771 ret
= d_operator_name (di
);
1772 di
->is_expression
= was_expr
;
1773 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1775 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1776 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1777 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1778 d_source_name (di
));
1781 else if (peek
== 'D' && d_peek_next_char (di
) == 'C')
1783 // structured binding
1785 struct demangle_component
*prev
= NULL
;
1788 struct demangle_component
*next
=
1789 d_make_comp (di
, DEMANGLE_COMPONENT_STRUCTURED_BINDING
,
1790 d_source_name (di
), NULL
);
1792 d_right (prev
) = next
;
1797 while (prev
&& d_peek_char (di
) != 'E');
1803 else if (peek
== 'C' || peek
== 'D')
1804 ret
= d_ctor_dtor_name (di
);
1805 else if (peek
== 'L')
1809 ret
= d_source_name (di
);
1812 if (! d_discriminator (di
))
1815 else if (peek
== 'U')
1817 switch (d_peek_next_char (di
))
1820 ret
= d_lambda (di
);
1823 ret
= d_unnamed_type (di
);
1833 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_MODULE_ENTITY
, ret
, module
);
1834 if (d_peek_char (di
) == 'B')
1835 ret
= d_abi_tags (di
, ret
);
1836 if (member_like_friend
)
1837 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_FRIEND
, ret
, NULL
);
1839 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, scope
, ret
);
1844 /* <source-name> ::= <(positive length) number> <identifier> */
1846 static struct demangle_component
*
1847 d_source_name (struct d_info
*di
)
1850 struct demangle_component
*ret
;
1852 len
= d_number (di
);
1855 ret
= d_identifier (di
, len
);
1856 di
->last_name
= ret
;
1860 /* number ::= [n] <(non-negative decimal integer)> */
1863 d_number (struct d_info
*di
)
1870 peek
= d_peek_char (di
);
1875 peek
= d_peek_char (di
);
1881 if (! IS_DIGIT (peek
))
1887 if (ret
> ((INT_MAX
- (peek
- '0')) / 10))
1889 ret
= ret
* 10 + (peek
- '0');
1891 peek
= d_peek_char (di
);
1895 /* Like d_number, but returns a demangle_component. */
1897 static struct demangle_component
*
1898 d_number_component (struct d_info
*di
)
1900 struct demangle_component
*ret
= d_make_empty (di
);
1903 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1904 ret
->u
.s_number
.number
= d_number (di
);
1909 /* identifier ::= <(unqualified source code identifier)> */
1911 static struct demangle_component
*
1912 d_identifier (struct d_info
*di
, int len
)
1918 if (di
->send
- name
< len
)
1921 d_advance (di
, len
);
1923 /* A Java mangled name may have a trailing '$' if it is a C++
1924 keyword. This '$' is not included in the length count. We just
1926 if ((di
->options
& DMGL_JAVA
) != 0
1927 && d_peek_char (di
) == '$')
1930 /* Look for something which looks like a gcc encoding of an
1931 anonymous namespace, and replace it with a more user friendly
1933 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1934 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1935 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1939 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1940 if ((*s
== '.' || *s
== '_' || *s
== '$')
1943 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1944 return d_make_name (di
, "(anonymous namespace)",
1945 sizeof "(anonymous namespace)" - 1);
1949 return d_make_name (di
, name
, len
);
1952 /* operator_name ::= many different two character encodings.
1954 ::= v <digit> <source-name>
1956 This list is sorted for binary search. */
1958 #define NL(s) s, (sizeof s) - 1
1960 CP_STATIC_IF_GLIBCPP_V3
1961 const struct demangle_operator_info cplus_demangle_operators
[] =
1963 { "aN", NL ("&="), 2 },
1964 { "aS", NL ("="), 2 },
1965 { "aa", NL ("&&"), 2 },
1966 { "ad", NL ("&"), 1 },
1967 { "an", NL ("&"), 2 },
1968 { "at", NL ("alignof "), 1 },
1969 { "aw", NL ("co_await "), 1 },
1970 { "az", NL ("alignof "), 1 },
1971 { "cc", NL ("const_cast"), 2 },
1972 { "cl", NL ("()"), 2 },
1973 { "cm", NL (","), 2 },
1974 { "co", NL ("~"), 1 },
1975 { "dV", NL ("/="), 2 },
1976 { "dX", NL ("[...]="), 3 }, /* [expr...expr] = expr */
1977 { "da", NL ("delete[] "), 1 },
1978 { "dc", NL ("dynamic_cast"), 2 },
1979 { "de", NL ("*"), 1 },
1980 { "di", NL ("="), 2 }, /* .name = expr */
1981 { "dl", NL ("delete "), 1 },
1982 { "ds", NL (".*"), 2 },
1983 { "dt", NL ("."), 2 },
1984 { "dv", NL ("/"), 2 },
1985 { "dx", NL ("]="), 2 }, /* [expr] = expr */
1986 { "eO", NL ("^="), 2 },
1987 { "eo", NL ("^"), 2 },
1988 { "eq", NL ("=="), 2 },
1989 { "fL", NL ("..."), 3 },
1990 { "fR", NL ("..."), 3 },
1991 { "fl", NL ("..."), 2 },
1992 { "fr", NL ("..."), 2 },
1993 { "ge", NL (">="), 2 },
1994 { "gs", NL ("::"), 1 },
1995 { "gt", NL (">"), 2 },
1996 { "ix", NL ("[]"), 2 },
1997 { "lS", NL ("<<="), 2 },
1998 { "le", NL ("<="), 2 },
1999 { "li", NL ("operator\"\" "), 1 },
2000 { "ls", NL ("<<"), 2 },
2001 { "lt", NL ("<"), 2 },
2002 { "mI", NL ("-="), 2 },
2003 { "mL", NL ("*="), 2 },
2004 { "mi", NL ("-"), 2 },
2005 { "ml", NL ("*"), 2 },
2006 { "mm", NL ("--"), 1 },
2007 { "na", NL ("new[]"), 3 },
2008 { "ne", NL ("!="), 2 },
2009 { "ng", NL ("-"), 1 },
2010 { "nt", NL ("!"), 1 },
2011 { "nw", NL ("new"), 3 },
2012 { "nx", NL ("noexcept"), 1 },
2013 { "oR", NL ("|="), 2 },
2014 { "oo", NL ("||"), 2 },
2015 { "or", NL ("|"), 2 },
2016 { "pL", NL ("+="), 2 },
2017 { "pl", NL ("+"), 2 },
2018 { "pm", NL ("->*"), 2 },
2019 { "pp", NL ("++"), 1 },
2020 { "ps", NL ("+"), 1 },
2021 { "pt", NL ("->"), 2 },
2022 { "qu", NL ("?"), 3 },
2023 { "rM", NL ("%="), 2 },
2024 { "rS", NL (">>="), 2 },
2025 { "rc", NL ("reinterpret_cast"), 2 },
2026 { "rm", NL ("%"), 2 },
2027 { "rs", NL (">>"), 2 },
2028 { "sP", NL ("sizeof..."), 1 },
2029 { "sZ", NL ("sizeof..."), 1 },
2030 { "sc", NL ("static_cast"), 2 },
2031 { "ss", NL ("<=>"), 2 },
2032 { "st", NL ("sizeof "), 1 },
2033 { "sz", NL ("sizeof "), 1 },
2034 { "tr", NL ("throw"), 0 },
2035 { "tw", NL ("throw "), 1 },
2036 { NULL
, NULL
, 0, 0 }
2039 static struct demangle_component
*
2040 d_operator_name (struct d_info
*di
)
2045 c1
= d_next_char (di
);
2046 c2
= d_next_char (di
);
2047 if (c1
== 'v' && IS_DIGIT (c2
))
2048 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
2049 else if (c1
== 'c' && c2
== 'v')
2051 struct demangle_component
*type
;
2052 int was_conversion
= di
->is_conversion
;
2053 struct demangle_component
*res
;
2055 di
->is_conversion
= ! di
->is_expression
;
2056 type
= cplus_demangle_type (di
);
2057 if (di
->is_conversion
)
2058 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
2060 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
2061 di
->is_conversion
= was_conversion
;
2066 /* LOW is the inclusive lower bound. */
2068 /* HIGH is the exclusive upper bound. We subtract one to ignore
2069 the sentinel at the end of the array. */
2070 int high
= ((sizeof (cplus_demangle_operators
)
2071 / sizeof (cplus_demangle_operators
[0]))
2077 const struct demangle_operator_info
*p
;
2079 i
= low
+ (high
- low
) / 2;
2080 p
= cplus_demangle_operators
+ i
;
2082 if (c1
== p
->code
[0] && c2
== p
->code
[1])
2083 return d_make_operator (di
, p
);
2085 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
2095 static struct demangle_component
*
2096 d_make_character (struct d_info
*di
, int c
)
2098 struct demangle_component
*p
;
2099 p
= d_make_empty (di
);
2102 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
2103 p
->u
.s_character
.character
= c
;
2108 static struct demangle_component
*
2109 d_java_resource (struct d_info
*di
)
2111 struct demangle_component
*p
= NULL
;
2112 struct demangle_component
*next
= NULL
;
2117 len
= d_number (di
);
2121 /* Eat the leading '_'. */
2122 if (d_next_char (di
) != '_')
2135 /* Each chunk is either a '$' escape... */
2153 next
= d_make_character (di
, c
);
2161 /* ... or a sequence of characters. */
2164 while (i
< len
&& str
[i
] && str
[i
] != '$')
2167 next
= d_make_name (di
, str
, i
);
2180 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
2186 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
2191 /* <special-name> ::= TV <type>
2195 ::= TA <template-arg>
2196 ::= GV <(object) name>
2197 ::= T <call-offset> <(base) encoding>
2198 ::= Tc <call-offset> <call-offset> <(base) encoding>
2199 Also g++ extensions:
2200 ::= TC <type> <(offset) number> _ <(base) type>
2205 ::= Gr <resource name>
2210 static struct demangle_component
*
2211 d_special_name (struct d_info
*di
)
2213 di
->expansion
+= 20;
2214 if (d_check_char (di
, 'T'))
2216 switch (d_next_char (di
))
2220 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
2221 cplus_demangle_type (di
), NULL
);
2223 di
->expansion
-= 10;
2224 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
2225 cplus_demangle_type (di
), NULL
);
2227 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
2228 cplus_demangle_type (di
), NULL
);
2230 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
2231 cplus_demangle_type (di
), NULL
);
2234 if (! d_call_offset (di
, 'h'))
2236 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
2237 d_encoding (di
, 0), NULL
);
2240 if (! d_call_offset (di
, 'v'))
2242 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
2243 d_encoding (di
, 0), NULL
);
2246 if (! d_call_offset (di
, '\0'))
2248 if (! d_call_offset (di
, '\0'))
2250 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
2251 d_encoding (di
, 0), NULL
);
2255 struct demangle_component
*derived_type
;
2257 struct demangle_component
*base_type
;
2259 derived_type
= cplus_demangle_type (di
);
2260 offset
= d_number (di
);
2263 if (! d_check_char (di
, '_'))
2265 base_type
= cplus_demangle_type (di
);
2266 /* We don't display the offset. FIXME: We should display
2267 it in verbose mode. */
2269 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2270 base_type
, derived_type
);
2274 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2275 cplus_demangle_type (di
), NULL
);
2277 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2278 cplus_demangle_type (di
), NULL
);
2281 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2282 d_name (di
, 0), NULL
);
2285 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2286 d_name (di
, 0), NULL
);
2289 return d_make_comp (di
, DEMANGLE_COMPONENT_TPARM_OBJ
,
2290 d_template_arg (di
), NULL
);
2296 else if (d_check_char (di
, 'G'))
2298 switch (d_next_char (di
))
2301 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
,
2302 d_name (di
, 0), NULL
);
2306 struct demangle_component
*name
= d_name (di
, 0);
2307 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2308 d_number_component (di
));
2312 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2313 d_encoding (di
, 0), NULL
);
2317 struct demangle_component
*module
= NULL
;
2318 if (!d_maybe_module_name (di
, &module
) || !module
)
2320 return d_make_comp (di
, DEMANGLE_COMPONENT_MODULE_INIT
,
2324 switch (d_next_char (di
))
2327 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2328 d_encoding (di
, 0), NULL
);
2330 /* ??? The proposal is that other letters (such as 'h') stand
2331 for different variants of transaction cloning, such as
2332 compiling directly for hardware transaction support. But
2333 they still should all be transactional clones of some sort
2334 so go ahead and call them that. */
2336 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2337 d_encoding (di
, 0), NULL
);
2341 return d_java_resource (di
);
2351 /* <call-offset> ::= h <nv-offset> _
2354 <nv-offset> ::= <(offset) number>
2356 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2358 The C parameter, if not '\0', is a character we just read which is
2359 the start of the <call-offset>.
2361 We don't display the offset information anywhere. FIXME: We should
2362 display it in verbose mode. */
2365 d_call_offset (struct d_info
*di
, int c
)
2368 c
= d_next_char (di
);
2375 if (! d_check_char (di
, '_'))
2382 if (! d_check_char (di
, '_'))
2388 /* <ctor-dtor-name> ::= C1
2396 static struct demangle_component
*
2397 d_ctor_dtor_name (struct d_info
*di
)
2399 if (di
->last_name
!= NULL
)
2401 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2402 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2403 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2404 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2406 switch (d_peek_char (di
))
2410 enum gnu_v3_ctor_kinds kind
;
2413 if (d_peek_next_char (di
) == 'I')
2419 switch (d_peek_next_char (di
))
2422 kind
= gnu_v3_complete_object_ctor
;
2425 kind
= gnu_v3_base_object_ctor
;
2428 kind
= gnu_v3_complete_object_allocating_ctor
;
2431 kind
= gnu_v3_unified_ctor
;
2434 kind
= gnu_v3_object_ctor_group
;
2443 cplus_demangle_type (di
);
2445 return d_make_ctor (di
, kind
, di
->last_name
);
2450 enum gnu_v3_dtor_kinds kind
;
2452 switch (d_peek_next_char (di
))
2455 kind
= gnu_v3_deleting_dtor
;
2458 kind
= gnu_v3_complete_object_dtor
;
2461 kind
= gnu_v3_base_object_dtor
;
2463 /* digit '3' is not used */
2465 kind
= gnu_v3_unified_dtor
;
2468 kind
= gnu_v3_object_dtor_group
;
2474 return d_make_dtor (di
, kind
, di
->last_name
);
2482 /* True iff we're looking at an order-insensitive type-qualifier, including
2483 function-type-qualifiers. */
2486 next_is_type_qual (struct d_info
*di
)
2488 char peek
= d_peek_char (di
);
2489 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2493 peek
= d_peek_next_char (di
);
2494 if (peek
== 'x' || peek
== 'o' || peek
== 'O' || peek
== 'w')
2500 /* <type> ::= <builtin-type>
2502 ::= <class-enum-type>
2504 ::= <pointer-to-member-type>
2505 ::= <template-param>
2506 ::= <template-template-param> <template-args>
2508 ::= <CV-qualifiers> <type>
2511 ::= O <type> (C++0x)
2514 ::= U <source-name> <type>
2516 <builtin-type> ::= various one letter codes
2520 CP_STATIC_IF_GLIBCPP_V3
2521 const struct demangle_builtin_type_info
2522 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2524 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2525 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2526 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2527 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2528 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2529 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2530 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2531 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2532 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2533 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2534 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2535 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2536 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2537 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2538 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2540 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2541 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2542 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2543 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2544 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2545 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2546 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2547 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2548 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2549 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2550 D_PRINT_UNSIGNED_LONG_LONG
},
2551 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2552 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2553 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2554 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2555 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2556 /* 30 */ { NL ("char8_t"), NL ("char8_t"), D_PRINT_DEFAULT
},
2557 /* 31 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2558 /* 32 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2559 /* 33 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2561 /* 34 */ { NL ("_Float"), NL ("_Float"), D_PRINT_FLOAT
},
2562 /* 35 */ { NL ("std::bfloat16_t"), NL ("std::bfloat16_t"), D_PRINT_FLOAT
},
2565 CP_STATIC_IF_GLIBCPP_V3
2566 struct demangle_component
*
2567 cplus_demangle_type (struct d_info
*di
)
2570 struct demangle_component
*ret
= NULL
;
2573 /* The ABI specifies that when CV-qualifiers are used, the base type
2574 is substitutable, and the fully qualified type is substitutable,
2575 but the base type with a strict subset of the CV-qualifiers is
2576 not substitutable. The natural recursive implementation of the
2577 CV-qualifiers would cause subsets to be substitutable, so instead
2578 we pull them all off now.
2580 FIXME: The ABI says that order-insensitive vendor qualifiers
2581 should be handled in the same way, but we have no way to tell
2582 which vendor qualifiers are order-insensitive and which are
2583 order-sensitive. So we just assume that they are all
2584 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2585 __vector, and it treats it as order-sensitive when mangling
2588 if (next_is_type_qual (di
))
2590 struct demangle_component
**pret
;
2592 pret
= d_cv_qualifiers (di
, &ret
, 0);
2595 if (d_peek_char (di
) == 'F')
2597 /* cv-qualifiers before a function type apply to 'this',
2598 so avoid adding the unqualified function type to
2599 the substitution list. */
2600 *pret
= d_function_type (di
);
2603 *pret
= cplus_demangle_type (di
);
2606 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2607 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2609 /* Move the ref-qualifier outside the cv-qualifiers so that
2610 they are printed in the right order. */
2611 struct demangle_component
*fn
= d_left (*pret
);
2612 d_left (*pret
) = ret
;
2616 if (! d_add_substitution (di
, ret
))
2623 peek
= d_peek_char (di
);
2626 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2627 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2628 case 'o': case 's': case 't':
2629 case 'v': case 'w': case 'x': case 'y': case 'z':
2630 ret
= d_make_builtin_type (di
,
2631 &cplus_demangle_builtin_types
[peek
- 'a']);
2632 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2639 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2640 d_source_name (di
), NULL
);
2644 ret
= d_function_type (di
);
2648 ret
= d_array_type (di
);
2652 ret
= d_pointer_to_member_type (di
);
2656 ret
= d_template_param (di
);
2657 if (d_peek_char (di
) == 'I')
2659 /* This may be <template-template-param> <template-args>.
2660 If this is the type for a conversion operator, we can
2661 have a <template-template-param> here only by following
2662 a derivation like this:
2665 -> <template-prefix> <template-args>
2666 -> <prefix> <template-unqualified-name> <template-args>
2667 -> <unqualified-name> <template-unqualified-name> <template-args>
2668 -> <source-name> <template-unqualified-name> <template-args>
2669 -> <source-name> <operator-name> <template-args>
2670 -> <source-name> cv <type> <template-args>
2671 -> <source-name> cv <template-template-param> <template-args> <template-args>
2673 where the <template-args> is followed by another.
2674 Otherwise, we must have a derivation like this:
2677 -> <template-prefix> <template-args>
2678 -> <prefix> <template-unqualified-name> <template-args>
2679 -> <unqualified-name> <template-unqualified-name> <template-args>
2680 -> <source-name> <template-unqualified-name> <template-args>
2681 -> <source-name> <operator-name> <template-args>
2682 -> <source-name> cv <type> <template-args>
2683 -> <source-name> cv <template-param> <template-args>
2685 where we need to leave the <template-args> to be processed
2686 by d_prefix (following the <template-prefix>).
2688 The <template-template-param> part is a substitution
2690 if (! di
->is_conversion
)
2692 if (! d_add_substitution (di
, ret
))
2694 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2695 d_template_args (di
));
2699 struct demangle_component
*args
;
2700 struct d_info_checkpoint checkpoint
;
2702 d_checkpoint (di
, &checkpoint
);
2703 args
= d_template_args (di
);
2704 if (d_peek_char (di
) == 'I')
2706 if (! d_add_substitution (di
, ret
))
2708 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2712 d_backtrack (di
, &checkpoint
);
2719 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2720 cplus_demangle_type (di
), NULL
);
2725 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2726 cplus_demangle_type (di
), NULL
);
2731 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2732 cplus_demangle_type (di
), NULL
);
2737 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2738 cplus_demangle_type (di
), NULL
);
2743 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2744 cplus_demangle_type (di
), NULL
);
2749 ret
= d_source_name (di
);
2750 if (d_peek_char (di
) == 'I')
2751 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2752 d_template_args (di
));
2753 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2754 cplus_demangle_type (di
), ret
);
2760 peek
= d_next_char (di
);
2765 /* decltype (expression) */
2766 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2767 d_expression (di
), NULL
);
2768 if (ret
&& d_next_char (di
) != 'E')
2774 /* Pack expansion. */
2775 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2776 cplus_demangle_type (di
), NULL
);
2782 ret
= d_make_name (di
, "auto", 4);
2785 /* decltype(auto) */
2786 ret
= d_make_name (di
, "decltype(auto)", 14);
2790 /* 32-bit decimal floating point */
2791 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2792 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2796 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2797 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2801 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2802 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2805 /* 16-bit half-precision FP */
2806 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2807 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2811 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2812 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2816 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2817 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2821 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2822 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2826 /* DF<number>_ - _Float<number>.
2827 DF<number>x - _Float<number>x
2828 DF16b - std::bfloat16_t. */
2830 int arg
= d_number (di
);
2833 if (d_peek_char (di
) == 'b')
2838 ret
= d_make_builtin_type (di
,
2839 &cplus_demangle_builtin_types
[35]);
2840 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2843 if (d_peek_char (di
) == 'x')
2845 if (!suffix
&& d_peek_char (di
) != '_')
2848 = d_make_extended_builtin_type (di
,
2849 &cplus_demangle_builtin_types
[34],
2852 sprintf (buf
, "%d", arg
);
2853 di
->expansion
+= ret
->u
.s_extended_builtin
.type
->len
2854 + strlen (buf
) + (suffix
!= 0);
2859 ret
= d_vector_type (di
);
2864 /* decltype(nullptr) */
2865 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[33]);
2866 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2875 return d_class_enum_type (di
, 1);
2880 if (! d_add_substitution (di
, ret
))
2887 /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */
2889 static struct demangle_component
**
2890 d_cv_qualifiers (struct d_info
*di
,
2891 struct demangle_component
**pret
, int member_fn
)
2893 struct demangle_component
**pstart
;
2897 peek
= d_peek_char (di
);
2898 while (next_is_type_qual (di
))
2900 enum demangle_component_type t
;
2901 struct demangle_component
*right
= NULL
;
2907 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2908 : DEMANGLE_COMPONENT_RESTRICT
);
2909 di
->expansion
+= sizeof "restrict";
2911 else if (peek
== 'V')
2914 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2915 : DEMANGLE_COMPONENT_VOLATILE
);
2916 di
->expansion
+= sizeof "volatile";
2918 else if (peek
== 'K')
2921 ? DEMANGLE_COMPONENT_CONST_THIS
2922 : DEMANGLE_COMPONENT_CONST
);
2923 di
->expansion
+= sizeof "const";
2927 peek
= d_next_char (di
);
2930 t
= DEMANGLE_COMPONENT_TRANSACTION_SAFE
;
2931 di
->expansion
+= sizeof "transaction_safe";
2933 else if (peek
== 'o'
2936 t
= DEMANGLE_COMPONENT_NOEXCEPT
;
2937 di
->expansion
+= sizeof "noexcept";
2940 right
= d_expression (di
);
2943 if (! d_check_char (di
, 'E'))
2947 else if (peek
== 'w')
2949 t
= DEMANGLE_COMPONENT_THROW_SPEC
;
2950 di
->expansion
+= sizeof "throw";
2951 right
= d_parmlist (di
);
2954 if (! d_check_char (di
, 'E'))
2961 *pret
= d_make_comp (di
, t
, NULL
, right
);
2964 pret
= &d_left (*pret
);
2966 peek
= d_peek_char (di
);
2969 if (!member_fn
&& peek
== 'F')
2971 while (pstart
!= pret
)
2973 switch ((*pstart
)->type
)
2975 case DEMANGLE_COMPONENT_RESTRICT
:
2976 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2978 case DEMANGLE_COMPONENT_VOLATILE
:
2979 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2981 case DEMANGLE_COMPONENT_CONST
:
2982 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2987 pstart
= &d_left (*pstart
);
2994 /* <ref-qualifier> ::= R
2997 static struct demangle_component
*
2998 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
3000 struct demangle_component
*ret
= sub
;
3003 peek
= d_peek_char (di
);
3004 if (peek
== 'R' || peek
== 'O')
3006 enum demangle_component_type t
;
3009 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
3010 di
->expansion
+= sizeof "&";
3014 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
3015 di
->expansion
+= sizeof "&&";
3019 ret
= d_make_comp (di
, t
, ret
, NULL
);
3025 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */
3027 static struct demangle_component
*
3028 d_function_type (struct d_info
*di
)
3030 struct demangle_component
*ret
= NULL
;
3032 if ((di
->options
& DMGL_NO_RECURSE_LIMIT
) == 0)
3034 if (di
->recursion_level
> DEMANGLE_RECURSION_LIMIT
)
3035 /* FIXME: There ought to be a way to report
3036 that the recursion limit has been reached. */
3039 di
->recursion_level
++;
3042 if (d_check_char (di
, 'F'))
3044 if (d_peek_char (di
) == 'Y')
3046 /* Function has C linkage. We don't print this information.
3047 FIXME: We should print it in verbose mode. */
3050 ret
= d_bare_function_type (di
, 1);
3051 ret
= d_ref_qualifier (di
, ret
);
3053 if (! d_check_char (di
, 'E'))
3057 if ((di
->options
& DMGL_NO_RECURSE_LIMIT
) == 0)
3058 di
->recursion_level
--;
3064 static struct demangle_component
*
3065 d_parmlist (struct d_info
*di
)
3067 struct demangle_component
*tl
;
3068 struct demangle_component
**ptl
;
3074 struct demangle_component
*type
;
3076 char peek
= d_peek_char (di
);
3077 if (peek
== '\0' || peek
== 'E' || peek
== '.' || peek
== 'Q')
3079 if ((peek
== 'R' || peek
== 'O')
3080 && d_peek_next_char (di
) == 'E')
3081 /* Function ref-qualifier, not a ref prefix for a parameter type. */
3083 type
= cplus_demangle_type (di
);
3086 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
3089 ptl
= &d_right (*ptl
);
3092 /* There should be at least one parameter type besides the optional
3093 return type. A function which takes no arguments will have a
3094 single parameter type void. */
3098 /* If we have a single parameter type void, omit it. */
3099 if (d_right (tl
) == NULL
3100 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3101 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
3103 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
3110 /* <bare-function-type> ::= [J]<type>+ */
3112 static struct demangle_component
*
3113 d_bare_function_type (struct d_info
*di
, int has_return_type
)
3115 struct demangle_component
*return_type
;
3116 struct demangle_component
*tl
;
3119 /* Detect special qualifier indicating that the first argument
3120 is the return type. */
3121 peek
= d_peek_char (di
);
3125 has_return_type
= 1;
3128 if (has_return_type
)
3130 return_type
= cplus_demangle_type (di
);
3131 if (return_type
== NULL
)
3137 tl
= d_parmlist (di
);
3141 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
3145 /* <class-enum-type> ::= <name> */
3147 static struct demangle_component
*
3148 d_class_enum_type (struct d_info
*di
, int substable
)
3150 return d_name (di
, substable
);
3153 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
3154 ::= A [<(dimension) expression>] _ <(element) type>
3157 static struct demangle_component
*
3158 d_array_type (struct d_info
*di
)
3161 struct demangle_component
*dim
;
3163 if (! d_check_char (di
, 'A'))
3166 peek
= d_peek_char (di
);
3169 else if (IS_DIGIT (peek
))
3177 peek
= d_peek_char (di
);
3179 while (IS_DIGIT (peek
));
3180 dim
= d_make_name (di
, s
, d_str (di
) - s
);
3186 dim
= d_expression (di
);
3191 if (! d_check_char (di
, '_'))
3194 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
3195 cplus_demangle_type (di
));
3198 /* <vector-type> ::= Dv <number> _ <type>
3199 ::= Dv _ <expression> _ <type> */
3201 static struct demangle_component
*
3202 d_vector_type (struct d_info
*di
)
3205 struct demangle_component
*dim
;
3207 peek
= d_peek_char (di
);
3211 dim
= d_expression (di
);
3214 dim
= d_number_component (di
);
3219 if (! d_check_char (di
, '_'))
3222 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
3223 cplus_demangle_type (di
));
3226 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
3228 static struct demangle_component
*
3229 d_pointer_to_member_type (struct d_info
*di
)
3231 struct demangle_component
*cl
;
3232 struct demangle_component
*mem
;
3234 if (! d_check_char (di
, 'M'))
3237 cl
= cplus_demangle_type (di
);
3241 /* The ABI says, "The type of a non-static member function is considered
3242 to be different, for the purposes of substitution, from the type of a
3243 namespace-scope or static member function whose type appears
3244 similar. The types of two non-static member functions are considered
3245 to be different, for the purposes of substitution, if the functions
3246 are members of different classes. In other words, for the purposes of
3247 substitution, the class of which the function is a member is
3248 considered part of the type of function."
3250 For a pointer to member function, this call to cplus_demangle_type
3251 will end up adding a (possibly qualified) non-member function type to
3252 the substitution table, which is not correct; however, the member
3253 function type will never be used in a substitution, so putting the
3254 wrong type in the substitution table is harmless. */
3256 mem
= cplus_demangle_type (di
);
3260 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
3263 /* <non-negative number> _ */
3266 d_compact_number (struct d_info
*di
)
3269 if (d_peek_char (di
) == '_')
3271 else if (d_peek_char (di
) == 'n')
3274 num
= d_number (di
) + 1;
3276 if (num
< 0 || ! d_check_char (di
, '_'))
3281 /* <template-param> ::= T_
3282 ::= T <(parameter-2 non-negative) number> _
3285 static struct demangle_component
*
3286 d_template_param (struct d_info
*di
)
3290 if (! d_check_char (di
, 'T'))
3293 param
= d_compact_number (di
);
3297 return d_make_template_param (di
, param
);
3300 /* <template-args> ::= I <template-arg>+ E */
3302 static struct demangle_component
*
3303 d_template_args (struct d_info
*di
)
3305 if (d_peek_char (di
) != 'I'
3306 && d_peek_char (di
) != 'J')
3310 return d_template_args_1 (di
);
3313 /* <template-arg>* [Q <constraint-expression>] E */
3315 static struct demangle_component
*
3316 d_template_args_1 (struct d_info
*di
)
3318 struct demangle_component
*hold_last_name
;
3319 struct demangle_component
*al
;
3320 struct demangle_component
**pal
;
3322 /* Preserve the last name we saw--don't let the template arguments
3323 clobber it, as that would give us the wrong name for a subsequent
3324 constructor or destructor. */
3325 hold_last_name
= di
->last_name
;
3327 if (d_peek_char (di
) == 'E')
3329 /* An argument pack can be empty. */
3331 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
3338 struct demangle_component
*a
;
3340 a
= d_template_arg (di
);
3344 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
3347 pal
= &d_right (*pal
);
3349 char peek
= d_peek_char (di
);
3350 if (peek
== 'E' || peek
== 'Q')
3354 al
= d_maybe_constraints (di
, al
);
3356 if (d_peek_char (di
) != 'E')
3360 di
->last_name
= hold_last_name
;
3365 /* <template-arg> ::= <type>
3366 ::= X <expression> E
3370 static struct demangle_component
*
3371 d_template_arg (struct d_info
*di
)
3373 struct demangle_component
*ret
;
3375 switch (d_peek_char (di
))
3379 ret
= d_expression (di
);
3380 if (! d_check_char (di
, 'E'))
3385 return d_expr_primary (di
);
3389 /* An argument pack. */
3390 return d_template_args (di
);
3393 return cplus_demangle_type (di
);
3397 /* Parse a sequence of expressions until we hit the terminator
3400 static struct demangle_component
*
3401 d_exprlist (struct d_info
*di
, char terminator
)
3403 struct demangle_component
*list
= NULL
;
3404 struct demangle_component
**p
= &list
;
3406 if (d_peek_char (di
) == terminator
)
3409 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3414 struct demangle_component
*arg
= d_expression (di
);
3418 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3423 if (d_peek_char (di
) == terminator
)
3433 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3434 dynamic_cast, static_cast or reinterpret_cast. */
3437 op_is_new_cast (struct demangle_component
*op
)
3439 const char *code
= op
->u
.s_operator
.op
->code
;
3440 return (code
[1] == 'c'
3441 && (code
[0] == 's' || code
[0] == 'd'
3442 || code
[0] == 'c' || code
[0] == 'r'));
3445 /* <unresolved-name> ::= [gs] <base-unresolved-name> # x or (with "gs") ::x
3446 ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x
3447 # T::N::x /decltype(p)::N::x
3448 ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name>
3449 # A::x, N::y, A<T>::z; "gs" means leading "::"
3450 ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
3452 "gs" is handled elsewhere, as a unary operator. */
3454 static struct demangle_component
*
3455 d_unresolved_name (struct d_info
*di
)
3457 struct demangle_component
*type
;
3458 struct demangle_component
*name
;
3461 /* Consume the "sr". */
3464 peek
= d_peek_char (di
);
3465 if (di
->unresolved_name_state
3472 /* The third production is ambiguous with the old unresolved-name syntax
3473 of <type> <base-unresolved-name>; in the old mangling, A::x was mangled
3474 as sr1A1x, now sr1AE1x. So we first try to demangle using the new
3475 mangling, then with the old if that fails. */
3476 di
->unresolved_name_state
= -1;
3477 type
= d_prefix (di
, 0);
3478 if (d_peek_char (di
) == 'E')
3482 type
= cplus_demangle_type (di
);
3483 name
= d_unqualified_name (di
, type
, NULL
);
3484 if (d_peek_char (di
) == 'I')
3485 name
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3486 d_template_args (di
));
3490 /* <expression> ::= <(unary) operator-name> <expression>
3491 ::= <(binary) operator-name> <expression> <expression>
3492 ::= <(trinary) operator-name> <expression> <expression> <expression>
3493 ::= cl <expression>+ E
3495 ::= <template-param>
3496 ::= u <source-name> <template-arg>* E # vendor extended expression
3497 ::= <unresolved-name>
3500 <braced-expression> ::= <expression>
3501 ::= di <field source-name> <braced-expression> # .name = expr
3502 ::= dx <index expression> <braced-expression> # [expr] = expr
3503 ::= dX <range begin expression> <range end expression> <braced-expression>
3504 # [expr ... expr] = expr
3507 static struct demangle_component
*
3508 d_expression_1 (struct d_info
*di
)
3512 peek
= d_peek_char (di
);
3514 return d_expr_primary (di
);
3515 else if (peek
== 'T')
3516 return d_template_param (di
);
3517 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3518 return d_unresolved_name (di
);
3519 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3522 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3523 d_expression_1 (di
), NULL
);
3525 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3527 /* Function parameter used in a late-specified return type. */
3530 if (d_peek_char (di
) == 'T')
3532 /* 'this' parameter. */
3538 index
= d_compact_number (di
);
3539 if (index
== INT_MAX
|| index
== -1)
3543 return d_make_function_param (di
, index
);
3545 else if (IS_DIGIT (peek
)
3546 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3548 /* We can get an unqualified name as an expression in the case of
3549 a dependent function call, i.e. decltype(f(t)). */
3550 struct demangle_component
*name
;
3553 /* operator-function-id, i.e. operator+(t). */
3556 name
= d_unqualified_name (di
, NULL
, NULL
);
3559 if (d_peek_char (di
) == 'I')
3560 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3561 d_template_args (di
));
3565 else if ((peek
== 'i' || peek
== 't')
3566 && d_peek_next_char (di
) == 'l')
3568 /* Brace-enclosed initializer list, untyped or typed. */
3569 struct demangle_component
*type
= NULL
;
3572 type
= cplus_demangle_type (di
);
3573 if (!d_peek_char (di
) || !d_peek_next_char (di
))
3575 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3576 type
, d_exprlist (di
, 'E'));
3578 else if (peek
== 'u')
3580 /* A vendor extended expression. */
3581 struct demangle_component
*name
, *args
;
3583 name
= d_source_name (di
);
3584 args
= d_template_args_1 (di
);
3585 return d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_EXPR
, name
, args
);
3589 struct demangle_component
*op
;
3590 const char *code
= NULL
;
3593 op
= d_operator_name (di
);
3597 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3599 code
= op
->u
.s_operator
.op
->code
;
3600 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3601 if (strcmp (code
, "st") == 0)
3602 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3603 cplus_demangle_type (di
));
3610 case DEMANGLE_COMPONENT_OPERATOR
:
3611 args
= op
->u
.s_operator
.op
->args
;
3613 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3614 args
= op
->u
.s_extended_operator
.args
;
3616 case DEMANGLE_COMPONENT_CAST
:
3624 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3628 struct demangle_component
*operand
;
3631 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3632 && code
[1] == code
[0])
3633 /* pp_ and mm_ are the prefix variants. */
3634 suffix
= !d_check_char (di
, '_');
3636 if (op
->type
== DEMANGLE_COMPONENT_CAST
3637 && d_check_char (di
, '_'))
3638 operand
= d_exprlist (di
, 'E');
3639 else if (code
&& !strcmp (code
, "sP"))
3640 operand
= d_template_args_1 (di
);
3642 operand
= d_expression_1 (di
);
3645 /* Indicate the suffix variant for d_print_comp. */
3646 operand
= d_make_comp (di
, DEMANGLE_COMPONENT_BINARY_ARGS
,
3649 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
, operand
);
3653 struct demangle_component
*left
;
3654 struct demangle_component
*right
;
3658 if (op_is_new_cast (op
))
3659 left
= cplus_demangle_type (di
);
3660 else if (code
[0] == 'f')
3661 /* fold-expression. */
3662 left
= d_operator_name (di
);
3663 else if (!strcmp (code
, "di"))
3664 left
= d_unqualified_name (di
, NULL
, NULL
);
3666 left
= d_expression_1 (di
);
3667 if (!strcmp (code
, "cl"))
3668 right
= d_exprlist (di
, 'E');
3669 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3671 peek
= d_peek_char (di
);
3672 /* These codes start a qualified name. */
3673 if ((peek
== 'g' && d_peek_next_char (di
) == 's')
3674 || (peek
== 's' && d_peek_next_char (di
) == 'r'))
3675 right
= d_expression_1 (di
);
3678 /* Otherwise it's an unqualified name. We use
3679 d_unqualified_name rather than d_expression_1 here for
3680 old mangled names that didn't add 'on' before operator
3682 right
= d_unqualified_name (di
, NULL
, NULL
);
3683 if (d_peek_char (di
) == 'I')
3684 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3685 right
, d_template_args (di
));
3689 right
= d_expression_1 (di
);
3691 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3693 DEMANGLE_COMPONENT_BINARY_ARGS
,
3698 struct demangle_component
*first
;
3699 struct demangle_component
*second
;
3700 struct demangle_component
*third
;
3704 else if (!strcmp (code
, "qu")
3705 || !strcmp (code
, "dX"))
3707 /* ?: expression. */
3708 first
= d_expression_1 (di
);
3709 second
= d_expression_1 (di
);
3710 third
= d_expression_1 (di
);
3714 else if (code
[0] == 'f')
3716 /* fold-expression. */
3717 first
= d_operator_name (di
);
3718 second
= d_expression_1 (di
);
3719 third
= d_expression_1 (di
);
3723 else if (code
[0] == 'n')
3725 /* new-expression. */
3726 if (code
[1] != 'w' && code
[1] != 'a')
3728 first
= d_exprlist (di
, '_');
3729 second
= cplus_demangle_type (di
);
3730 if (d_peek_char (di
) == 'E')
3735 else if (d_peek_char (di
) == 'p'
3736 && d_peek_next_char (di
) == 'i')
3738 /* Parenthesized initializer. */
3740 third
= d_exprlist (di
, 'E');
3742 else if (d_peek_char (di
) == 'i'
3743 && d_peek_next_char (di
) == 'l')
3744 /* initializer-list. */
3745 third
= d_expression_1 (di
);
3751 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3753 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3756 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3765 static struct demangle_component
*
3766 d_expression (struct d_info
*di
)
3768 struct demangle_component
*ret
;
3769 int was_expression
= di
->is_expression
;
3771 di
->is_expression
= 1;
3772 ret
= d_expression_1 (di
);
3773 di
->is_expression
= was_expression
;
3777 /* <expr-primary> ::= L <type> <(value) number> E
3778 ::= L <type> <(value) float> E
3779 ::= L <mangled-name> E
3782 static struct demangle_component
*
3783 d_expr_primary (struct d_info
*di
)
3785 struct demangle_component
*ret
;
3787 if (! d_check_char (di
, 'L'))
3789 if (d_peek_char (di
) == '_'
3790 /* Workaround for G++ bug; see comment in write_template_arg. */
3791 || d_peek_char (di
) == 'Z')
3792 ret
= cplus_demangle_mangled_name (di
, 0);
3795 struct demangle_component
*type
;
3796 enum demangle_component_type t
;
3799 type
= cplus_demangle_type (di
);
3803 /* If we have a type we know how to print, we aren't going to
3804 print the type name itself. */
3805 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3806 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3807 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3809 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3810 && strcmp (type
->u
.s_builtin
.type
->name
,
3811 cplus_demangle_builtin_types
[33].name
) == 0)
3813 if (d_peek_char (di
) == 'E')
3820 /* Rather than try to interpret the literal value, we just
3821 collect it as a string. Note that it's possible to have a
3822 floating point literal here. The ABI specifies that the
3823 format of such literals is machine independent. That's fine,
3824 but what's not fine is that versions of g++ up to 3.2 with
3825 -fabi-version=1 used upper case letters in the hex constant,
3826 and dumped out gcc's internal representation. That makes it
3827 hard to tell where the constant ends, and hard to dump the
3828 constant in any readable form anyhow. We don't attempt to
3829 handle these cases. */
3831 t
= DEMANGLE_COMPONENT_LITERAL
;
3832 if (d_peek_char (di
) == 'n')
3834 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3838 while (d_peek_char (di
) != 'E')
3840 if (d_peek_char (di
) == '\0')
3844 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3846 if (! d_check_char (di
, 'E'))
3851 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3852 ::= Z <(function) encoding> E s [<discriminator>]
3853 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3856 static struct demangle_component
*
3857 d_local_name (struct d_info
*di
)
3859 struct demangle_component
*function
;
3860 struct demangle_component
*name
;
3862 if (! d_check_char (di
, 'Z'))
3865 function
= d_encoding (di
, 0);
3869 if (! d_check_char (di
, 'E'))
3872 if (d_peek_char (di
) == 's')
3875 if (! d_discriminator (di
))
3877 name
= d_make_name (di
, "string literal", sizeof "string literal" - 1);
3883 if (d_peek_char (di
) == 'd')
3885 /* Default argument scope: d <number> _. */
3887 num
= d_compact_number (di
);
3892 name
= d_name (di
, 0);
3895 /* Lambdas and unnamed types have internal discriminators
3896 and are not functions. */
3897 && name
->type
!= DEMANGLE_COMPONENT_LAMBDA
3898 && name
->type
!= DEMANGLE_COMPONENT_UNNAMED_TYPE
)
3900 /* Read and ignore an optional discriminator. */
3901 if (! d_discriminator (di
))
3906 name
= d_make_default_arg (di
, num
, name
);
3909 /* Elide the return type of the containing function so as to not
3910 confuse the user thinking it is the return type of whatever local
3911 function we might be containing. */
3912 if (function
->type
== DEMANGLE_COMPONENT_TYPED_NAME
3913 && d_right (function
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
3914 d_left (d_right (function
)) = NULL
;
3916 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3919 /* <discriminator> ::= _ <number> # when number < 10
3920 ::= __ <number> _ # when number >= 10
3922 <discriminator> ::= _ <number> # when number >=10
3923 is also accepted to support gcc versions that wrongly mangled that way.
3925 We demangle the discriminator, but we don't print it out. FIXME:
3926 We should print it out in verbose mode. */
3929 d_discriminator (struct d_info
*di
)
3931 int discrim
, num_underscores
= 1;
3933 if (d_peek_char (di
) != '_')
3936 if (d_peek_char (di
) == '_')
3942 discrim
= d_number (di
);
3945 if (num_underscores
> 1 && discrim
>= 10)
3947 if (d_peek_char (di
) == '_')
3956 /* <template-parm> ::= Ty
3958 ::= Tt <template-head> E
3959 ::= Tp <template-parm> */
3961 static struct demangle_component
*
3962 d_template_parm (struct d_info
*di
, int *bad
)
3964 if (d_peek_char (di
) != 'T')
3967 struct demangle_component
*op
;
3968 enum demangle_component_type kind
;
3969 switch (d_peek_next_char (di
))
3974 case 'p': /* Pack */
3976 op
= d_template_parm (di
, bad
);
3977 kind
= DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
;
3985 case 'y': /* Typename */
3988 kind
= DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
;
3991 case 'n': /* Non-Type */
3993 op
= cplus_demangle_type (di
);
3994 kind
= DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
;
4002 case 't': /* Template */
4004 op
= d_template_head (di
, bad
);
4005 kind
= DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
;
4006 if (!op
|| !d_check_char (di
, 'E'))
4013 return d_make_comp (di
, kind
, op
, NULL
);
4016 /* <template-head> ::= <template-head>? <template-parm> */
4018 static struct demangle_component
*
4019 d_template_head (struct d_info
*di
, int *bad
)
4021 struct demangle_component
*res
= NULL
, **slot
= &res
;
4022 struct demangle_component
*op
;
4024 while ((op
= d_template_parm (di
, bad
)))
4027 slot
= &d_right (op
);
4030 /* Wrap it in a template head, to make concatenating with any parm list, and
4031 printing simpler. */
4033 res
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_HEAD
, res
, NULL
);
4038 /* <closure-type-name> ::= Ul <template-head>? <lambda-sig> E [ <nonnegative number> ] _ */
4040 static struct demangle_component
*
4041 d_lambda (struct d_info
*di
)
4043 if (! d_check_char (di
, 'U'))
4045 if (! d_check_char (di
, 'l'))
4049 struct demangle_component
*head
= d_template_head (di
, &bad
);
4053 struct demangle_component
*tl
= d_parmlist (di
);
4058 d_right (head
) = tl
;
4062 if (! d_check_char (di
, 'E'))
4065 int num
= d_compact_number (di
);
4069 struct demangle_component
*ret
= d_make_empty (di
);
4072 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
4073 ret
->u
.s_unary_num
.sub
= tl
;
4074 ret
->u
.s_unary_num
.num
= num
;
4080 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
4082 static struct demangle_component
*
4083 d_unnamed_type (struct d_info
*di
)
4085 struct demangle_component
*ret
;
4088 if (! d_check_char (di
, 'U'))
4090 if (! d_check_char (di
, 't'))
4093 num
= d_compact_number (di
);
4097 ret
= d_make_empty (di
);
4100 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
4101 ret
->u
.s_number
.number
= num
;
4104 if (! d_add_substitution (di
, ret
))
4110 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
4113 static struct demangle_component
*
4114 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
4116 const char *suffix
= d_str (di
);
4117 const char *pend
= suffix
;
4118 struct demangle_component
*n
;
4120 if (*pend
== '.' && (IS_LOWER (pend
[1]) || IS_DIGIT (pend
[1])
4124 while (IS_LOWER (*pend
) || IS_DIGIT (*pend
) || *pend
== '_')
4127 while (*pend
== '.' && IS_DIGIT (pend
[1]))
4130 while (IS_DIGIT (*pend
))
4133 d_advance (di
, pend
- suffix
);
4134 n
= d_make_name (di
, suffix
, pend
- suffix
);
4135 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
4138 /* Add a new substitution. */
4141 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
4145 if (di
->next_sub
>= di
->num_subs
)
4147 di
->subs
[di
->next_sub
] = dc
;
4152 /* <substitution> ::= S <seq-id> _
4162 If PREFIX is non-zero, then this type is being used as a prefix in
4163 a qualified name. In this case, for the standard substitutions, we
4164 need to check whether we are being used as a prefix for a
4165 constructor or destructor, and return a full template name.
4166 Otherwise we will get something like std::iostream::~iostream()
4167 which does not correspond particularly well to any function which
4168 actually appears in the source.
4171 static const struct d_standard_sub_info standard_subs
[] =
4176 { 'a', NL ("std::allocator"),
4177 NL ("std::allocator"),
4179 { 'b', NL ("std::basic_string"),
4180 NL ("std::basic_string"),
4181 NL ("basic_string") },
4182 { 's', NL ("std::string"),
4183 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
4184 NL ("basic_string") },
4185 { 'i', NL ("std::istream"),
4186 NL ("std::basic_istream<char, std::char_traits<char> >"),
4187 NL ("basic_istream") },
4188 { 'o', NL ("std::ostream"),
4189 NL ("std::basic_ostream<char, std::char_traits<char> >"),
4190 NL ("basic_ostream") },
4191 { 'd', NL ("std::iostream"),
4192 NL ("std::basic_iostream<char, std::char_traits<char> >"),
4193 NL ("basic_iostream") }
4196 static struct demangle_component
*
4197 d_substitution (struct d_info
*di
, int prefix
)
4201 if (! d_check_char (di
, 'S'))
4204 c
= d_next_char (di
);
4205 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
4214 unsigned int new_id
;
4217 new_id
= id
* 36 + c
- '0';
4218 else if (IS_UPPER (c
))
4219 new_id
= id
* 36 + c
- 'A' + 10;
4225 c
= d_next_char (di
);
4232 if (id
>= (unsigned int) di
->next_sub
)
4235 return di
->subs
[id
];
4240 const struct d_standard_sub_info
*p
;
4241 const struct d_standard_sub_info
*pend
;
4243 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
4244 if (! verbose
&& prefix
)
4248 peek
= d_peek_char (di
);
4249 if (peek
== 'C' || peek
== 'D')
4253 pend
= (&standard_subs
[0]
4254 + sizeof standard_subs
/ sizeof standard_subs
[0]);
4255 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
4261 struct demangle_component
*dc
;
4263 if (p
->set_last_name
!= NULL
)
4264 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
4265 p
->set_last_name_len
);
4268 s
= p
->full_expansion
;
4273 s
= p
->simple_expansion
;
4274 len
= p
->simple_len
;
4276 di
->expansion
+= len
;
4277 dc
= d_make_sub (di
, s
, len
);
4278 if (d_peek_char (di
) == 'B')
4280 /* If there are ABI tags on the abbreviation, it becomes
4281 a substitution candidate. */
4282 dc
= d_abi_tags (di
, dc
);
4283 if (! d_add_substitution (di
, dc
))
4295 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
4297 checkpoint
->n
= di
->n
;
4298 checkpoint
->next_comp
= di
->next_comp
;
4299 checkpoint
->next_sub
= di
->next_sub
;
4300 checkpoint
->expansion
= di
->expansion
;
4304 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
4306 di
->n
= checkpoint
->n
;
4307 di
->next_comp
= checkpoint
->next_comp
;
4308 di
->next_sub
= checkpoint
->next_sub
;
4309 di
->expansion
= checkpoint
->expansion
;
4312 /* Initialize a growable string. */
4315 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
4320 dgs
->allocation_failure
= 0;
4323 d_growable_string_resize (dgs
, estimate
);
4326 /* Grow a growable string to a given size. */
4329 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
4334 if (dgs
->allocation_failure
)
4337 /* Start allocation at two bytes to avoid any possibility of confusion
4338 with the special value of 1 used as a return in *palc to indicate
4339 allocation failures. */
4340 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
4341 while (newalc
< need
)
4344 newbuf
= (char *) realloc ("demangle.dgsr.1", dgs
->buf
, newalc
);
4351 dgs
->allocation_failure
= 1;
4358 /* Append a buffer to a growable string. */
4361 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
4362 const char *s
, size_t l
)
4366 need
= dgs
->len
+ l
+ 1;
4367 if (need
> dgs
->alc
)
4368 d_growable_string_resize (dgs
, need
);
4370 if (dgs
->allocation_failure
)
4373 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
4374 dgs
->buf
[dgs
->len
+ l
] = '\0';
4378 /* Bridge growable strings to the callback mechanism. */
4381 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
4383 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
4385 d_growable_string_append_buffer (dgs
, s
, l
);
4388 /* Walk the tree, counting the number of templates encountered, and
4389 the number of times a scope might be saved. These counts will be
4390 used to allocate data structures for d_print_comp, so the logic
4391 here must mirror the logic d_print_comp will use. It is not
4392 important that the resulting numbers are exact, so long as they
4393 are larger than the actual numbers encountered. */
4396 d_count_templates_scopes (struct d_print_info
*dpi
,
4397 struct demangle_component
*dc
)
4399 if (dc
== NULL
|| dc
->d_counting
> 1 || dpi
->recursion
> MAX_RECURSION_COUNT
)
4406 case DEMANGLE_COMPONENT_NAME
:
4407 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4408 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4409 case DEMANGLE_COMPONENT_SUB_STD
:
4410 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4411 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
4412 case DEMANGLE_COMPONENT_OPERATOR
:
4413 case DEMANGLE_COMPONENT_CHARACTER
:
4414 case DEMANGLE_COMPONENT_NUMBER
:
4415 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4416 case DEMANGLE_COMPONENT_STRUCTURED_BINDING
:
4417 case DEMANGLE_COMPONENT_MODULE_NAME
:
4418 case DEMANGLE_COMPONENT_MODULE_PARTITION
:
4419 case DEMANGLE_COMPONENT_MODULE_INIT
:
4420 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4421 case DEMANGLE_COMPONENT_TEMPLATE_HEAD
:
4422 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
4423 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
4424 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
4425 case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
:
4428 case DEMANGLE_COMPONENT_TEMPLATE
:
4429 dpi
->num_copy_templates
++;
4430 goto recurse_left_right
;
4432 case DEMANGLE_COMPONENT_REFERENCE
:
4433 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4434 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4435 dpi
->num_saved_scopes
++;
4436 goto recurse_left_right
;
4438 case DEMANGLE_COMPONENT_QUAL_NAME
:
4439 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4440 case DEMANGLE_COMPONENT_TYPED_NAME
:
4441 case DEMANGLE_COMPONENT_VTABLE
:
4442 case DEMANGLE_COMPONENT_VTT
:
4443 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4444 case DEMANGLE_COMPONENT_TYPEINFO
:
4445 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4446 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4447 case DEMANGLE_COMPONENT_THUNK
:
4448 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4449 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4450 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4451 case DEMANGLE_COMPONENT_GUARD
:
4452 case DEMANGLE_COMPONENT_TLS_INIT
:
4453 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4454 case DEMANGLE_COMPONENT_REFTEMP
:
4455 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4456 case DEMANGLE_COMPONENT_RESTRICT
:
4457 case DEMANGLE_COMPONENT_VOLATILE
:
4458 case DEMANGLE_COMPONENT_CONST
:
4459 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4460 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4461 case DEMANGLE_COMPONENT_CONST_THIS
:
4462 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4463 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4464 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
4465 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4466 case DEMANGLE_COMPONENT_NOEXCEPT
:
4467 case DEMANGLE_COMPONENT_THROW_SPEC
:
4468 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4469 case DEMANGLE_COMPONENT_POINTER
:
4470 case DEMANGLE_COMPONENT_COMPLEX
:
4471 case DEMANGLE_COMPONENT_IMAGINARY
:
4472 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4473 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4474 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4475 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4476 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4477 case DEMANGLE_COMPONENT_ARGLIST
:
4478 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4479 case DEMANGLE_COMPONENT_TPARM_OBJ
:
4480 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4481 case DEMANGLE_COMPONENT_CAST
:
4482 case DEMANGLE_COMPONENT_CONVERSION
:
4483 case DEMANGLE_COMPONENT_NULLARY
:
4484 case DEMANGLE_COMPONENT_UNARY
:
4485 case DEMANGLE_COMPONENT_BINARY
:
4486 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4487 case DEMANGLE_COMPONENT_TRINARY
:
4488 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4489 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4490 case DEMANGLE_COMPONENT_LITERAL
:
4491 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4492 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
4493 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4494 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4495 case DEMANGLE_COMPONENT_DECLTYPE
:
4496 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4497 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4498 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4499 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4500 case DEMANGLE_COMPONENT_CLONE
:
4501 case DEMANGLE_COMPONENT_CONSTRAINTS
:
4503 /* PR 89394 - Check for too much recursion. */
4504 if (dpi
->recursion
> DEMANGLE_RECURSION_LIMIT
)
4505 /* FIXME: There ought to be a way to report to the
4506 user that the recursion limit has been reached. */
4510 d_count_templates_scopes (dpi
, d_left (dc
));
4511 d_count_templates_scopes (dpi
, d_right (dc
));
4515 case DEMANGLE_COMPONENT_CTOR
:
4516 d_count_templates_scopes (dpi
, dc
->u
.s_ctor
.name
);
4519 case DEMANGLE_COMPONENT_DTOR
:
4520 d_count_templates_scopes (dpi
, dc
->u
.s_dtor
.name
);
4523 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4524 d_count_templates_scopes (dpi
, dc
->u
.s_extended_operator
.name
);
4527 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4528 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4529 case DEMANGLE_COMPONENT_MODULE_ENTITY
:
4530 case DEMANGLE_COMPONENT_FRIEND
:
4531 d_count_templates_scopes (dpi
, d_left (dc
));
4534 case DEMANGLE_COMPONENT_LAMBDA
:
4535 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4536 d_count_templates_scopes (dpi
, dc
->u
.s_unary_num
.sub
);
4541 /* Initialize a print information structure. */
4544 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
4545 void *opaque
, struct demangle_component
*dc
)
4548 dpi
->last_char
= '\0';
4549 dpi
->templates
= NULL
;
4550 dpi
->modifiers
= NULL
;
4551 dpi
->pack_index
= 0;
4552 dpi
->flush_count
= 0;
4554 dpi
->callback
= callback
;
4555 dpi
->opaque
= opaque
;
4557 dpi
->demangle_failure
= 0;
4559 dpi
->lambda_tpl_parms
= 0;
4561 dpi
->component_stack
= NULL
;
4563 dpi
->saved_scopes
= NULL
;
4564 dpi
->next_saved_scope
= 0;
4565 dpi
->num_saved_scopes
= 0;
4567 dpi
->copy_templates
= NULL
;
4568 dpi
->next_copy_template
= 0;
4569 dpi
->num_copy_templates
= 0;
4571 d_count_templates_scopes (dpi
, dc
);
4572 /* If we did not reach the recursion limit, then reset the
4573 current recursion value back to 0, so that we can print
4575 if (dpi
->recursion
< DEMANGLE_RECURSION_LIMIT
)
4577 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
4579 dpi
->current_template
= NULL
;
4582 /* Indicate that an error occurred during printing, and test for error. */
4585 d_print_error (struct d_print_info
*dpi
)
4587 dpi
->demangle_failure
= 1;
4591 d_print_saw_error (struct d_print_info
*dpi
)
4593 return dpi
->demangle_failure
!= 0;
4596 /* Flush buffered characters to the callback. */
4599 d_print_flush (struct d_print_info
*dpi
)
4601 dpi
->buf
[dpi
->len
] = '\0';
4602 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4607 /* Append characters and buffers for printing. */
4610 d_append_char (struct d_print_info
*dpi
, char c
)
4612 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4613 d_print_flush (dpi
);
4615 dpi
->buf
[dpi
->len
++] = c
;
4620 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4624 for (i
= 0; i
< l
; i
++)
4625 d_append_char (dpi
, s
[i
]);
4629 d_append_string (struct d_print_info
*dpi
, const char *s
)
4631 d_append_buffer (dpi
, s
, strlen (s
));
4635 d_append_num (struct d_print_info
*dpi
, int l
)
4638 sprintf (buf
,"%d", l
);
4639 d_append_string (dpi
, buf
);
4643 d_last_char (struct d_print_info
*dpi
)
4645 return dpi
->last_char
;
4648 /* Turn components into a human readable string. OPTIONS is the
4649 options bits passed to the demangler. DC is the tree to print.
4650 CALLBACK is a function to call to flush demangled string segments
4651 as they fill the intermediate buffer, and OPAQUE is a generalized
4652 callback argument. On success, this returns 1. On failure,
4653 it returns 0, indicating a bad parse. It does not use heap
4654 memory to build an output string, so cannot encounter memory
4655 allocation failure. */
4657 CP_STATIC_IF_GLIBCPP_V3
4659 cplus_demangle_print_callback (int options
,
4660 struct demangle_component
*dc
,
4661 demangle_callbackref callback
, void *opaque
)
4663 struct d_print_info dpi
;
4665 d_print_init (&dpi
, callback
, opaque
, dc
);
4668 #if 0 /* in valgrind */
4669 #ifdef CP_DYNAMIC_ARRAYS
4670 /* Avoid zero-length VLAs, which are prohibited by the C99 standard
4671 and flagged as errors by Address Sanitizer. */
4672 __extension__
struct d_saved_scope scopes
[(dpi
.num_saved_scopes
> 0)
4673 ? dpi
.num_saved_scopes
: 1];
4674 __extension__
struct d_print_template temps
[(dpi
.num_copy_templates
> 0)
4675 ? dpi
.num_copy_templates
: 1];
4677 dpi
.saved_scopes
= scopes
;
4678 dpi
.copy_templates
= temps
;
4680 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4681 * sizeof (*dpi
.saved_scopes
));
4682 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4683 * sizeof (*dpi
.copy_templates
));
4686 /* Allocate memory dynamically to avoid VLAs as valgrind stack
4687 is a scarce resource */
4688 dpi
.saved_scopes
= xmalloc(dpi
.num_saved_scopes
4689 * sizeof (*dpi
.saved_scopes
));
4690 dpi
.copy_templates
= xmalloc (dpi
.num_copy_templates
4691 * sizeof (*dpi
.copy_templates
));
4692 #endif /* ! in valgrind */
4693 d_print_comp (&dpi
, options
, dc
);
4696 d_print_flush (&dpi
);
4698 int status
= ! d_print_saw_error (&dpi
);
4700 #if 0 /* in valgrind */
4702 free (dpi
.saved_scopes
);
4703 free (dpi
.copy_templates
);
4704 #endif /* in valgrind */
4709 /* Turn components into a human readable string. OPTIONS is the
4710 options bits passed to the demangler. DC is the tree to print.
4711 ESTIMATE is a guess at the length of the result. This returns a
4712 string allocated by malloc, or NULL on error. On success, this
4713 sets *PALC to the size of the allocated buffer. On failure, this
4714 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4717 CP_STATIC_IF_GLIBCPP_V3
4719 cplus_demangle_print (int options
, struct demangle_component
*dc
,
4720 int estimate
, size_t *palc
)
4722 struct d_growable_string dgs
;
4724 d_growable_string_init (&dgs
, estimate
);
4726 if (! cplus_demangle_print_callback (options
, dc
,
4727 d_growable_string_callback_adapter
,
4735 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4739 /* Returns the I'th element of the template arglist ARGS, or NULL on
4740 failure. If I is negative, return the entire arglist. */
4742 static struct demangle_component
*
4743 d_index_template_argument (struct demangle_component
*args
, int i
)
4745 struct demangle_component
*a
;
4748 /* Print the whole argument pack. */
4755 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4761 if (i
!= 0 || a
== NULL
)
4767 /* Returns the template argument from the current context indicated by DC,
4768 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4770 static struct demangle_component
*
4771 d_lookup_template_argument (struct d_print_info
*dpi
,
4772 const struct demangle_component
*dc
)
4774 if (dpi
->templates
== NULL
)
4776 d_print_error (dpi
);
4780 return d_index_template_argument
4781 (d_right (dpi
->templates
->template_decl
),
4782 dc
->u
.s_number
.number
);
4785 /* Returns a template argument pack used in DC (any will do), or NULL. */
4787 static struct demangle_component
*
4788 d_find_pack (struct d_print_info
*dpi
,
4789 const struct demangle_component
*dc
)
4791 struct demangle_component
*a
;
4797 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4798 a
= d_lookup_template_argument (dpi
, dc
);
4799 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4803 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4806 case DEMANGLE_COMPONENT_LAMBDA
:
4807 case DEMANGLE_COMPONENT_NAME
:
4808 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4809 case DEMANGLE_COMPONENT_OPERATOR
:
4810 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4811 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
4812 case DEMANGLE_COMPONENT_SUB_STD
:
4813 case DEMANGLE_COMPONENT_CHARACTER
:
4814 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4815 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4816 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4817 case DEMANGLE_COMPONENT_NUMBER
:
4820 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4821 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4822 case DEMANGLE_COMPONENT_CTOR
:
4823 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4824 case DEMANGLE_COMPONENT_DTOR
:
4825 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4828 a
= d_find_pack (dpi
, d_left (dc
));
4831 return d_find_pack (dpi
, d_right (dc
));
4835 /* Returns the length of the template argument pack DC. */
4838 d_pack_length (const struct demangle_component
*dc
)
4841 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4842 && d_left (dc
) != NULL
)
4850 /* Returns the number of template args in DC, expanding any pack expansions
4854 d_args_length (struct d_print_info
*dpi
, const struct demangle_component
*dc
)
4857 for (; dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
;
4860 struct demangle_component
*elt
= d_left (dc
);
4863 if (elt
->type
== DEMANGLE_COMPONENT_PACK_EXPANSION
)
4865 struct demangle_component
*a
= d_find_pack (dpi
, d_left (elt
));
4866 count
+= d_pack_length (a
);
4874 /* DC is a component of a mangled expression. Print it, wrapped in parens
4878 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4879 struct demangle_component
*dc
)
4882 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4883 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4884 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4885 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4888 d_append_char (dpi
, '(');
4889 d_print_comp (dpi
, options
, dc
);
4891 d_append_char (dpi
, ')');
4894 /* Save the current scope. */
4897 d_save_scope (struct d_print_info
*dpi
,
4898 const struct demangle_component
*container
)
4900 struct d_saved_scope
*scope
;
4901 struct d_print_template
*src
, **link
;
4903 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4905 d_print_error (dpi
);
4908 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4909 dpi
->next_saved_scope
++;
4911 scope
->container
= container
;
4912 link
= &scope
->templates
;
4914 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4916 struct d_print_template
*dst
;
4918 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4920 d_print_error (dpi
);
4923 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4924 dpi
->next_copy_template
++;
4926 dst
->template_decl
= src
->template_decl
;
4934 /* Attempt to locate a previously saved scope. Returns NULL if no
4935 corresponding saved scope was found. */
4937 static struct d_saved_scope
*
4938 d_get_saved_scope (struct d_print_info
*dpi
,
4939 const struct demangle_component
*container
)
4943 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4944 if (dpi
->saved_scopes
[i
].container
== container
)
4945 return &dpi
->saved_scopes
[i
];
4950 /* If DC is a C++17 fold-expression, print it and return true; otherwise
4954 d_maybe_print_fold_expression (struct d_print_info
*dpi
, int options
,
4955 struct demangle_component
*dc
)
4957 struct demangle_component
*ops
, *operator_
, *op1
, *op2
;
4960 const char *fold_code
= d_left (dc
)->u
.s_operator
.op
->code
;
4961 if (fold_code
[0] != 'f')
4965 operator_
= d_left (ops
);
4966 op1
= d_right (ops
);
4968 if (op1
->type
== DEMANGLE_COMPONENT_TRINARY_ARG2
)
4970 op2
= d_right (op1
);
4974 /* Print the whole pack. */
4975 save_idx
= dpi
->pack_index
;
4976 dpi
->pack_index
= -1;
4978 switch (fold_code
[1])
4980 /* Unary left fold, (... + X). */
4982 d_append_string (dpi
, "(...");
4983 d_print_expr_op (dpi
, options
, operator_
);
4984 d_print_subexpr (dpi
, options
, op1
);
4985 d_append_char (dpi
, ')');
4988 /* Unary right fold, (X + ...). */
4990 d_append_char (dpi
, '(');
4991 d_print_subexpr (dpi
, options
, op1
);
4992 d_print_expr_op (dpi
, options
, operator_
);
4993 d_append_string (dpi
, "...)");
4996 /* Binary left fold, (42 + ... + X). */
4998 /* Binary right fold, (X + ... + 42). */
5000 d_append_char (dpi
, '(');
5001 d_print_subexpr (dpi
, options
, op1
);
5002 d_print_expr_op (dpi
, options
, operator_
);
5003 d_append_string (dpi
, "...");
5004 d_print_expr_op (dpi
, options
, operator_
);
5005 d_print_subexpr (dpi
, options
, op2
);
5006 d_append_char (dpi
, ')');
5010 dpi
->pack_index
= save_idx
;
5014 /* True iff DC represents a C99-style designated initializer. */
5017 is_designated_init (struct demangle_component
*dc
)
5019 if (dc
->type
!= DEMANGLE_COMPONENT_BINARY
5020 && dc
->type
!= DEMANGLE_COMPONENT_TRINARY
)
5023 struct demangle_component
*op
= d_left (dc
);
5024 const char *code
= op
->u
.s_operator
.op
->code
;
5025 return (code
[0] == 'd'
5026 && (code
[1] == 'i' || code
[1] == 'x' || code
[1] == 'X'));
5029 /* If DC represents a C99-style designated initializer, print it and return
5030 true; otherwise, return false. */
5033 d_maybe_print_designated_init (struct d_print_info
*dpi
, int options
,
5034 struct demangle_component
*dc
)
5036 if (!is_designated_init (dc
))
5039 const char *code
= d_left (dc
)->u
.s_operator
.op
->code
;
5041 struct demangle_component
*operands
= d_right (dc
);
5042 struct demangle_component
*op1
= d_left (operands
);
5043 struct demangle_component
*op2
= d_right (operands
);
5046 d_append_char (dpi
, '.');
5048 d_append_char (dpi
, '[');
5050 d_print_comp (dpi
, options
, op1
);
5053 d_append_string (dpi
, " ... ");
5054 d_print_comp (dpi
, options
, d_left (op2
));
5055 op2
= d_right (op2
);
5058 d_append_char (dpi
, ']');
5059 if (is_designated_init (op2
))
5061 /* Don't put '=' or '(' between chained designators. */
5062 d_print_comp (dpi
, options
, op2
);
5066 d_append_char (dpi
, '=');
5067 d_print_subexpr (dpi
, options
, op2
);
5073 d_print_lambda_parm_name (struct d_print_info
*dpi
, int type
, unsigned index
)
5079 dpi
->demangle_failure
= 1;
5083 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
5087 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
5091 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
5095 d_append_string (dpi
, str
);
5096 d_append_num (dpi
, index
);
5099 /* Subroutine to handle components. */
5102 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
5103 struct demangle_component
*dc
)
5105 /* Magic variable to let reference smashing skip over the next modifier
5106 without needing to modify *dc. */
5107 struct demangle_component
*mod_inner
= NULL
;
5109 /* Variable used to store the current templates while a previously
5110 captured scope is used. */
5111 struct d_print_template
*saved_templates
= NULL
; /* silence GCC */
5113 /* Nonzero if templates have been stored in the above variable. */
5114 int need_template_restore
= 0;
5118 d_print_error (dpi
);
5121 if (d_print_saw_error (dpi
))
5126 case DEMANGLE_COMPONENT_NAME
:
5127 if ((options
& DMGL_JAVA
) == 0)
5128 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
5130 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
5133 case DEMANGLE_COMPONENT_TAGGED_NAME
:
5134 d_print_comp (dpi
, options
, d_left (dc
));
5135 d_append_string (dpi
, "[abi:");
5136 d_print_comp (dpi
, options
, d_right (dc
));
5137 d_append_char (dpi
, ']');
5140 case DEMANGLE_COMPONENT_STRUCTURED_BINDING
:
5141 d_append_char (dpi
, '[');
5144 d_print_comp (dpi
, options
, d_left (dc
));
5148 d_append_string (dpi
, ", ");
5150 d_append_char (dpi
, ']');
5153 case DEMANGLE_COMPONENT_MODULE_ENTITY
:
5154 d_print_comp (dpi
, options
, d_left (dc
));
5155 d_append_char (dpi
, '@');
5156 d_print_comp (dpi
, options
, d_right (dc
));
5159 case DEMANGLE_COMPONENT_MODULE_NAME
:
5160 case DEMANGLE_COMPONENT_MODULE_PARTITION
:
5163 d_print_comp (dpi
, options
, d_left (dc
));
5164 char c
= dc
->type
== DEMANGLE_COMPONENT_MODULE_PARTITION
5165 ? ':' : d_left (dc
) ? '.' : 0;
5167 d_append_char (dpi
, c
);
5168 d_print_comp (dpi
, options
, d_right (dc
));
5172 case DEMANGLE_COMPONENT_QUAL_NAME
:
5173 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5174 d_print_comp (dpi
, options
, d_left (dc
));
5175 if ((options
& DMGL_JAVA
) == 0)
5176 d_append_string (dpi
, "::");
5178 d_append_char (dpi
, '.');
5180 struct demangle_component
*local_name
= d_right (dc
);
5181 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5183 d_append_string (dpi
, "{default arg#");
5184 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
5185 d_append_string (dpi
, "}::");
5186 local_name
= local_name
->u
.s_unary_num
.sub
;
5188 d_print_comp (dpi
, options
, local_name
);
5192 case DEMANGLE_COMPONENT_TYPED_NAME
:
5194 struct d_print_mod
*hold_modifiers
;
5195 struct demangle_component
*typed_name
;
5196 struct d_print_mod adpm
[4];
5198 struct d_print_template dpt
;
5200 /* Pass the name down to the type so that it can be printed in
5201 the right place for the type. We also have to pass down
5202 any CV-qualifiers, which apply to the this parameter. */
5203 hold_modifiers
= dpi
->modifiers
;
5206 typed_name
= d_left (dc
);
5207 while (typed_name
!= NULL
)
5209 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5211 d_print_error (dpi
);
5215 adpm
[i
].next
= dpi
->modifiers
;
5216 dpi
->modifiers
= &adpm
[i
];
5217 adpm
[i
].mod
= typed_name
;
5218 adpm
[i
].printed
= 0;
5219 adpm
[i
].templates
= dpi
->templates
;
5222 if (!is_fnqual_component_type (typed_name
->type
))
5225 typed_name
= d_left (typed_name
);
5228 if (typed_name
== NULL
)
5230 d_print_error (dpi
);
5234 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
5235 there may be CV-qualifiers on its right argument which
5236 really apply here; this happens when parsing a class that
5237 is local to a function. */
5238 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5240 typed_name
= d_right (typed_name
);
5241 if (typed_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5242 typed_name
= typed_name
->u
.s_unary_num
.sub
;
5243 while (typed_name
!= NULL
5244 && is_fnqual_component_type (typed_name
->type
))
5246 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5248 d_print_error (dpi
);
5252 adpm
[i
] = adpm
[i
- 1];
5253 adpm
[i
].next
= &adpm
[i
- 1];
5254 dpi
->modifiers
= &adpm
[i
];
5256 adpm
[i
- 1].mod
= typed_name
;
5257 adpm
[i
- 1].printed
= 0;
5258 adpm
[i
- 1].templates
= dpi
->templates
;
5261 typed_name
= d_left (typed_name
);
5263 if (typed_name
== NULL
)
5265 d_print_error (dpi
);
5270 /* If typed_name is a template, then it applies to the
5271 function type as well. */
5272 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
5274 dpt
.next
= dpi
->templates
;
5275 dpi
->templates
= &dpt
;
5276 dpt
.template_decl
= typed_name
;
5278 /* Constraints are mangled as part of the template argument list,
5279 so they wrap the _TEMPLATE_ARGLIST. But
5280 d_lookup_template_argument expects the RHS of _TEMPLATE to be
5281 the _ARGLIST, and constraints need to refer to these args. So
5282 move the _CONSTRAINTS out of the _TEMPLATE and onto the type.
5283 This will result in them being printed after the () like a
5284 trailing requires-clause, but that seems like our best option
5285 given that we aren't printing a template-head. */
5286 struct demangle_component
*tnr
= d_right (typed_name
);
5287 if (tnr
->type
== DEMANGLE_COMPONENT_CONSTRAINTS
)
5289 d_right (typed_name
) = d_left (tnr
);
5290 d_left (tnr
) = d_right (dc
);
5295 d_print_comp (dpi
, options
, d_right (dc
));
5297 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
5298 dpi
->templates
= dpt
.next
;
5300 /* If the modifiers didn't get printed by the type, print them
5305 if (! adpm
[i
].printed
)
5307 d_append_char (dpi
, ' ');
5308 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5312 dpi
->modifiers
= hold_modifiers
;
5317 case DEMANGLE_COMPONENT_TEMPLATE
:
5319 struct d_print_mod
*hold_dpm
;
5320 struct demangle_component
*dcl
;
5321 const struct demangle_component
*hold_current
;
5323 /* This template may need to be referenced by a cast operator
5324 contained in its subtree. */
5325 hold_current
= dpi
->current_template
;
5326 dpi
->current_template
= dc
;
5328 /* Don't push modifiers into a template definition. Doing so
5329 could give the wrong definition for a template argument.
5330 Instead, treat the template essentially as a name. */
5332 hold_dpm
= dpi
->modifiers
;
5333 dpi
->modifiers
= NULL
;
5337 if ((options
& DMGL_JAVA
) != 0
5338 && dcl
->type
== DEMANGLE_COMPONENT_NAME
5339 && dcl
->u
.s_name
.len
== 6
5340 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
5342 /* Special-case Java arrays, so that JArray<TYPE> appears
5343 instead as TYPE[]. */
5345 d_print_comp (dpi
, options
, d_right (dc
));
5346 d_append_string (dpi
, "[]");
5350 d_print_comp (dpi
, options
, dcl
);
5351 if (d_last_char (dpi
) == '<')
5352 d_append_char (dpi
, ' ');
5353 d_append_char (dpi
, '<');
5354 d_print_comp (dpi
, options
, d_right (dc
));
5355 /* Avoid generating two consecutive '>' characters, to avoid
5356 the C++ syntactic ambiguity. */
5357 if (d_last_char (dpi
) == '>')
5358 d_append_char (dpi
, ' ');
5359 d_append_char (dpi
, '>');
5362 dpi
->modifiers
= hold_dpm
;
5363 dpi
->current_template
= hold_current
;
5368 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
5369 if (dpi
->lambda_tpl_parms
> dc
->u
.s_number
.number
+ 1)
5371 const struct demangle_component
*a
5372 = d_left (dpi
->templates
->template_decl
);
5374 for (c
= dc
->u
.s_number
.number
; a
&& c
; c
--)
5376 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
)
5379 dpi
->demangle_failure
= 1;
5381 d_print_lambda_parm_name (dpi
, a
->type
, dc
->u
.s_number
.number
);
5383 else if (dpi
->lambda_tpl_parms
)
5385 /* Show the template parm index, as that's how g++ displays
5386 these, and future proofs us against potential
5387 '[]<typename T> (T *a, T *b) {...}'. */
5388 d_append_buffer (dpi
, "auto:", 5);
5389 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5393 struct d_print_template
*hold_dpt
;
5394 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
5396 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
5397 a
= d_index_template_argument (a
, dpi
->pack_index
);
5401 d_print_error (dpi
);
5405 /* While processing this parameter, we need to pop the list
5406 of templates. This is because the template parameter may
5407 itself be a reference to a parameter of an outer
5410 hold_dpt
= dpi
->templates
;
5411 dpi
->templates
= hold_dpt
->next
;
5413 d_print_comp (dpi
, options
, a
);
5415 dpi
->templates
= hold_dpt
;
5419 case DEMANGLE_COMPONENT_TPARM_OBJ
:
5420 d_append_string (dpi
, "template parameter object for ");
5421 d_print_comp (dpi
, options
, d_left (dc
));
5424 case DEMANGLE_COMPONENT_CTOR
:
5425 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
5428 case DEMANGLE_COMPONENT_DTOR
:
5429 d_append_char (dpi
, '~');
5430 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
5433 case DEMANGLE_COMPONENT_MODULE_INIT
:
5434 d_append_string (dpi
, "initializer for module ");
5435 d_print_comp (dpi
, options
, d_left (dc
));
5438 case DEMANGLE_COMPONENT_VTABLE
:
5439 d_append_string (dpi
, "vtable for ");
5440 d_print_comp (dpi
, options
, d_left (dc
));
5443 case DEMANGLE_COMPONENT_VTT
:
5444 d_append_string (dpi
, "VTT for ");
5445 d_print_comp (dpi
, options
, d_left (dc
));
5448 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
5449 d_append_string (dpi
, "construction vtable for ");
5450 d_print_comp (dpi
, options
, d_left (dc
));
5451 d_append_string (dpi
, "-in-");
5452 d_print_comp (dpi
, options
, d_right (dc
));
5455 case DEMANGLE_COMPONENT_TYPEINFO
:
5456 d_append_string (dpi
, "typeinfo for ");
5457 d_print_comp (dpi
, options
, d_left (dc
));
5460 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
5461 d_append_string (dpi
, "typeinfo name for ");
5462 d_print_comp (dpi
, options
, d_left (dc
));
5465 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
5466 d_append_string (dpi
, "typeinfo fn for ");
5467 d_print_comp (dpi
, options
, d_left (dc
));
5470 case DEMANGLE_COMPONENT_THUNK
:
5471 d_append_string (dpi
, "non-virtual thunk to ");
5472 d_print_comp (dpi
, options
, d_left (dc
));
5475 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
5476 d_append_string (dpi
, "virtual thunk to ");
5477 d_print_comp (dpi
, options
, d_left (dc
));
5480 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
5481 d_append_string (dpi
, "covariant return thunk to ");
5482 d_print_comp (dpi
, options
, d_left (dc
));
5485 case DEMANGLE_COMPONENT_JAVA_CLASS
:
5486 d_append_string (dpi
, "java Class for ");
5487 d_print_comp (dpi
, options
, d_left (dc
));
5490 case DEMANGLE_COMPONENT_GUARD
:
5491 d_append_string (dpi
, "guard variable for ");
5492 d_print_comp (dpi
, options
, d_left (dc
));
5495 case DEMANGLE_COMPONENT_TLS_INIT
:
5496 d_append_string (dpi
, "TLS init function for ");
5497 d_print_comp (dpi
, options
, d_left (dc
));
5500 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
5501 d_append_string (dpi
, "TLS wrapper function for ");
5502 d_print_comp (dpi
, options
, d_left (dc
));
5505 case DEMANGLE_COMPONENT_REFTEMP
:
5506 d_append_string (dpi
, "reference temporary #");
5507 d_print_comp (dpi
, options
, d_right (dc
));
5508 d_append_string (dpi
, " for ");
5509 d_print_comp (dpi
, options
, d_left (dc
));
5512 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
5513 d_append_string (dpi
, "hidden alias for ");
5514 d_print_comp (dpi
, options
, d_left (dc
));
5517 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
5518 d_append_string (dpi
, "transaction clone for ");
5519 d_print_comp (dpi
, options
, d_left (dc
));
5522 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
5523 d_append_string (dpi
, "non-transaction clone for ");
5524 d_print_comp (dpi
, options
, d_left (dc
));
5527 case DEMANGLE_COMPONENT_SUB_STD
:
5528 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
5531 case DEMANGLE_COMPONENT_RESTRICT
:
5532 case DEMANGLE_COMPONENT_VOLATILE
:
5533 case DEMANGLE_COMPONENT_CONST
:
5535 struct d_print_mod
*pdpm
;
5537 /* When printing arrays, it's possible to have cases where the
5538 same CV-qualifier gets pushed on the stack multiple times.
5539 We only need to print it once. */
5541 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
5543 if (! pdpm
->printed
)
5545 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
5546 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
5547 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
5549 if (pdpm
->mod
->type
== dc
->type
)
5551 d_print_comp (dpi
, options
, d_left (dc
));
5559 case DEMANGLE_COMPONENT_REFERENCE
:
5560 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5562 /* Handle reference smashing: & + && = &. */
5563 struct demangle_component
*sub
= d_left (dc
);
5564 if (!dpi
->lambda_tpl_parms
5565 && sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
5567 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
5568 struct demangle_component
*a
;
5572 /* This is the first time SUB has been traversed.
5573 We need to capture the current templates so
5574 they can be restored if SUB is reentered as a
5576 d_save_scope (dpi
, sub
);
5577 if (d_print_saw_error (dpi
))
5582 const struct d_component_stack
*dcse
;
5583 int found_self_or_parent
= 0;
5585 /* This traversal is reentering SUB as a substition.
5586 If we are not beneath SUB or DC in the tree then we
5587 need to restore SUB's template stack temporarily. */
5588 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
5589 dcse
= dcse
->parent
)
5593 && dcse
!= dpi
->component_stack
))
5595 found_self_or_parent
= 1;
5600 if (!found_self_or_parent
)
5602 saved_templates
= dpi
->templates
;
5603 dpi
->templates
= scope
->templates
;
5604 need_template_restore
= 1;
5608 a
= d_lookup_template_argument (dpi
, sub
);
5609 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
5610 a
= d_index_template_argument (a
, dpi
->pack_index
);
5614 if (need_template_restore
)
5615 dpi
->templates
= saved_templates
;
5617 d_print_error (dpi
);
5624 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
5625 || sub
->type
== dc
->type
)
5627 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
5628 mod_inner
= d_left (sub
);
5632 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5633 case DEMANGLE_COMPONENT_POINTER
:
5634 case DEMANGLE_COMPONENT_COMPLEX
:
5635 case DEMANGLE_COMPONENT_IMAGINARY
:
5636 FNQUAL_COMPONENT_CASE
:
5639 /* We keep a list of modifiers on the stack. */
5640 struct d_print_mod dpm
;
5642 dpm
.next
= dpi
->modifiers
;
5643 dpi
->modifiers
= &dpm
;
5646 dpm
.templates
= dpi
->templates
;
5649 mod_inner
= d_left (dc
);
5651 d_print_comp (dpi
, options
, mod_inner
);
5653 /* If the modifier didn't get printed by the type, print it
5656 d_print_mod (dpi
, options
, dc
);
5658 dpi
->modifiers
= dpm
.next
;
5660 if (need_template_restore
)
5661 dpi
->templates
= saved_templates
;
5666 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5667 if ((options
& DMGL_JAVA
) == 0)
5668 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
5669 dc
->u
.s_builtin
.type
->len
);
5671 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
5672 dc
->u
.s_builtin
.type
->java_len
);
5675 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
5676 d_append_buffer (dpi
, dc
->u
.s_extended_builtin
.type
->name
,
5677 dc
->u
.s_extended_builtin
.type
->len
);
5678 d_append_num (dpi
, dc
->u
.s_extended_builtin
.arg
);
5679 if (dc
->u
.s_extended_builtin
.suffix
)
5680 d_append_buffer (dpi
, &dc
->u
.s_extended_builtin
.suffix
, 1);
5683 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5684 d_print_comp (dpi
, options
, d_left (dc
));
5687 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5689 if ((options
& DMGL_RET_POSTFIX
) != 0)
5690 d_print_function_type (dpi
,
5691 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5692 dc
, dpi
->modifiers
);
5694 /* Print return type if present */
5695 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
5696 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5698 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
5700 struct d_print_mod dpm
;
5702 /* We must pass this type down as a modifier in order to
5703 print it in the right location. */
5704 dpm
.next
= dpi
->modifiers
;
5705 dpi
->modifiers
= &dpm
;
5708 dpm
.templates
= dpi
->templates
;
5710 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5713 dpi
->modifiers
= dpm
.next
;
5718 /* In standard prefix notation, there is a space between the
5719 return type and the function signature. */
5720 if ((options
& DMGL_RET_POSTFIX
) == 0)
5721 d_append_char (dpi
, ' ');
5724 if ((options
& DMGL_RET_POSTFIX
) == 0)
5725 d_print_function_type (dpi
,
5726 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5727 dc
, dpi
->modifiers
);
5732 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5734 struct d_print_mod
*hold_modifiers
;
5735 struct d_print_mod adpm
[4];
5737 struct d_print_mod
*pdpm
;
5739 /* We must pass this type down as a modifier in order to print
5740 multi-dimensional arrays correctly. If the array itself is
5741 CV-qualified, we act as though the element type were
5742 CV-qualified. We do this by copying the modifiers down
5743 rather than fiddling pointers, so that we don't wind up
5744 with a d_print_mod higher on the stack pointing into our
5745 stack frame after we return. */
5747 hold_modifiers
= dpi
->modifiers
;
5749 adpm
[0].next
= hold_modifiers
;
5750 dpi
->modifiers
= &adpm
[0];
5752 adpm
[0].printed
= 0;
5753 adpm
[0].templates
= dpi
->templates
;
5756 pdpm
= hold_modifiers
;
5758 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
5759 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
5760 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
5762 if (! pdpm
->printed
)
5764 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5766 d_print_error (dpi
);
5771 adpm
[i
].next
= dpi
->modifiers
;
5772 dpi
->modifiers
= &adpm
[i
];
5780 d_print_comp (dpi
, options
, d_right (dc
));
5782 dpi
->modifiers
= hold_modifiers
;
5784 if (adpm
[0].printed
)
5790 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5793 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
5798 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5799 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5801 struct d_print_mod dpm
;
5803 dpm
.next
= dpi
->modifiers
;
5804 dpi
->modifiers
= &dpm
;
5807 dpm
.templates
= dpi
->templates
;
5809 d_print_comp (dpi
, options
, d_right (dc
));
5811 /* If the modifier didn't get printed by the type, print it
5814 d_print_mod (dpi
, options
, dc
);
5816 dpi
->modifiers
= dpm
.next
;
5821 case DEMANGLE_COMPONENT_ARGLIST
:
5822 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5823 if (d_left (dc
) != NULL
)
5824 d_print_comp (dpi
, options
, d_left (dc
));
5825 if (d_right (dc
) != NULL
)
5828 unsigned long int flush_count
;
5829 /* Make sure ", " isn't flushed by d_append_string, otherwise
5830 dpi->len -= 2 wouldn't work. */
5831 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5832 d_print_flush (dpi
);
5833 d_append_string (dpi
, ", ");
5835 flush_count
= dpi
->flush_count
;
5836 d_print_comp (dpi
, options
, d_right (dc
));
5837 /* If that didn't print anything (which can happen with empty
5838 template argument packs), remove the comma and space. */
5839 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5844 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5846 struct demangle_component
*type
= d_left (dc
);
5847 struct demangle_component
*list
= d_right (dc
);
5850 d_print_comp (dpi
, options
, type
);
5851 d_append_char (dpi
, '{');
5852 d_print_comp (dpi
, options
, list
);
5853 d_append_char (dpi
, '}');
5857 case DEMANGLE_COMPONENT_OPERATOR
:
5859 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5862 d_append_string (dpi
, "operator");
5863 /* Add a space before new/delete. */
5864 if (IS_LOWER (op
->name
[0]))
5865 d_append_char (dpi
, ' ');
5866 /* Omit a trailing space. */
5867 if (op
->name
[len
-1] == ' ')
5869 d_append_buffer (dpi
, op
->name
, len
);
5873 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5874 d_append_string (dpi
, "operator ");
5875 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5878 case DEMANGLE_COMPONENT_CONVERSION
:
5879 d_append_string (dpi
, "operator ");
5880 d_print_conversion (dpi
, options
, dc
);
5883 case DEMANGLE_COMPONENT_NULLARY
:
5884 d_print_expr_op (dpi
, options
, d_left (dc
));
5887 case DEMANGLE_COMPONENT_UNARY
:
5889 struct demangle_component
*op
= d_left (dc
);
5890 struct demangle_component
*operand
= d_right (dc
);
5891 const char *code
= NULL
;
5893 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5895 code
= op
->u
.s_operator
.op
->code
;
5896 if (!strcmp (code
, "ad"))
5898 /* Don't print the argument list for the address of a
5900 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5901 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5902 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5903 operand
= d_left (operand
);
5905 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5907 /* This indicates a suffix operator. */
5908 operand
= d_left (operand
);
5909 d_print_subexpr (dpi
, options
, operand
);
5910 d_print_expr_op (dpi
, options
, op
);
5915 /* For sizeof..., just print the pack length. */
5916 if (code
&& !strcmp (code
, "sZ"))
5918 struct demangle_component
*a
= d_find_pack (dpi
, operand
);
5919 int len
= d_pack_length (a
);
5920 d_append_num (dpi
, len
);
5923 else if (code
&& !strcmp (code
, "sP"))
5925 int len
= d_args_length (dpi
, operand
);
5926 d_append_num (dpi
, len
);
5930 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5931 d_print_expr_op (dpi
, options
, op
);
5934 d_append_char (dpi
, '(');
5935 d_print_cast (dpi
, options
, op
);
5936 d_append_char (dpi
, ')');
5938 if (code
&& !strcmp (code
, "gs"))
5939 /* Avoid parens after '::'. */
5940 d_print_comp (dpi
, options
, operand
);
5941 else if (code
&& (!strcmp (code
, "st") || !strcmp (code
, "nx")))
5942 /* Always print parens for sizeof (type) and noexcept(expr). */
5944 d_append_char (dpi
, '(');
5945 d_print_comp (dpi
, options
, operand
);
5946 d_append_char (dpi
, ')');
5949 d_print_subexpr (dpi
, options
, operand
);
5953 case DEMANGLE_COMPONENT_BINARY
:
5954 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5956 d_print_error (dpi
);
5960 if (op_is_new_cast (d_left (dc
)))
5962 d_print_expr_op (dpi
, options
, d_left (dc
));
5963 d_append_char (dpi
, '<');
5964 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5965 d_append_string (dpi
, ">(");
5966 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5967 d_append_char (dpi
, ')');
5971 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5974 if (d_maybe_print_designated_init (dpi
, options
, dc
))
5977 /* We wrap an expression which uses the greater-than operator in
5978 an extra layer of parens so that it does not get confused
5979 with the '>' which ends the template parameters. */
5980 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5981 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5982 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5983 d_append_char (dpi
, '(');
5985 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5986 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5988 /* Function call used in an expression should not have printed types
5989 of the function arguments. Values of the function arguments still
5990 get printed below. */
5992 const struct demangle_component
*func
= d_left (d_right (dc
));
5994 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5995 d_print_error (dpi
);
5996 d_print_subexpr (dpi
, options
, d_left (func
));
5999 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
6000 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
6002 d_append_char (dpi
, '[');
6003 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
6004 d_append_char (dpi
, ']');
6008 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
6009 d_print_expr_op (dpi
, options
, d_left (dc
));
6010 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
6013 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
6014 && d_left (dc
)->u
.s_operator
.op
->len
== 1
6015 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
6016 d_append_char (dpi
, ')');
6020 case DEMANGLE_COMPONENT_BINARY_ARGS
:
6021 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
6022 d_print_error (dpi
);
6025 case DEMANGLE_COMPONENT_TRINARY
:
6026 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
6027 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
6029 d_print_error (dpi
);
6032 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
6034 if (d_maybe_print_designated_init (dpi
, options
, dc
))
6037 struct demangle_component
*op
= d_left (dc
);
6038 struct demangle_component
*first
= d_left (d_right (dc
));
6039 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
6040 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
6042 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
6044 d_print_subexpr (dpi
, options
, first
);
6045 d_print_expr_op (dpi
, options
, op
);
6046 d_print_subexpr (dpi
, options
, second
);
6047 d_append_string (dpi
, " : ");
6048 d_print_subexpr (dpi
, options
, third
);
6052 d_append_string (dpi
, "new ");
6053 if (d_left (first
) != NULL
)
6055 d_print_subexpr (dpi
, options
, first
);
6056 d_append_char (dpi
, ' ');
6058 d_print_comp (dpi
, options
, second
);
6060 d_print_subexpr (dpi
, options
, third
);
6065 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
6066 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
6067 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
6068 d_print_error (dpi
);
6071 case DEMANGLE_COMPONENT_LITERAL
:
6072 case DEMANGLE_COMPONENT_LITERAL_NEG
:
6074 enum d_builtin_type_print tp
;
6076 /* For some builtin types, produce simpler output. */
6077 tp
= D_PRINT_DEFAULT
;
6078 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
6080 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
6084 case D_PRINT_UNSIGNED
:
6086 case D_PRINT_UNSIGNED_LONG
:
6087 case D_PRINT_LONG_LONG
:
6088 case D_PRINT_UNSIGNED_LONG_LONG
:
6089 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
6091 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
6092 d_append_char (dpi
, '-');
6093 d_print_comp (dpi
, options
, d_right (dc
));
6098 case D_PRINT_UNSIGNED
:
6099 d_append_char (dpi
, 'u');
6102 d_append_char (dpi
, 'l');
6104 case D_PRINT_UNSIGNED_LONG
:
6105 d_append_string (dpi
, "ul");
6107 case D_PRINT_LONG_LONG
:
6108 d_append_string (dpi
, "ll");
6110 case D_PRINT_UNSIGNED_LONG_LONG
:
6111 d_append_string (dpi
, "ull");
6119 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
6120 && d_right (dc
)->u
.s_name
.len
== 1
6121 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
6123 switch (d_right (dc
)->u
.s_name
.s
[0])
6126 d_append_string (dpi
, "false");
6129 d_append_string (dpi
, "true");
6142 d_append_char (dpi
, '(');
6143 d_print_comp (dpi
, options
, d_left (dc
));
6144 d_append_char (dpi
, ')');
6145 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
6146 d_append_char (dpi
, '-');
6147 if (tp
== D_PRINT_FLOAT
)
6148 d_append_char (dpi
, '[');
6149 d_print_comp (dpi
, options
, d_right (dc
));
6150 if (tp
== D_PRINT_FLOAT
)
6151 d_append_char (dpi
, ']');
6155 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
6156 d_print_comp (dpi
, options
, d_left (dc
));
6157 d_append_char (dpi
, '(');
6158 d_print_comp (dpi
, options
, d_right (dc
));
6159 d_append_char (dpi
, ')');
6162 case DEMANGLE_COMPONENT_NUMBER
:
6163 d_append_num (dpi
, dc
->u
.s_number
.number
);
6166 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
6167 d_append_string (dpi
, "java resource ");
6168 d_print_comp (dpi
, options
, d_left (dc
));
6171 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
6172 d_print_comp (dpi
, options
, d_left (dc
));
6173 d_print_comp (dpi
, options
, d_right (dc
));
6176 case DEMANGLE_COMPONENT_CHARACTER
:
6177 d_append_char (dpi
, dc
->u
.s_character
.character
);
6180 case DEMANGLE_COMPONENT_DECLTYPE
:
6181 d_append_string (dpi
, "decltype (");
6182 d_print_comp (dpi
, options
, d_left (dc
));
6183 d_append_char (dpi
, ')');
6186 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
6188 struct demangle_component
*a
= NULL
;
6190 if (!dpi
->lambda_tpl_parms
)
6191 a
= d_find_pack (dpi
, d_left (dc
));
6194 /* d_find_pack won't find anything if the only packs involved
6195 in this expansion are function parameter packs; in that
6196 case, just print the pattern and "...". */
6197 d_print_subexpr (dpi
, options
, d_left (dc
));
6198 d_append_string (dpi
, "...");
6202 int len
= d_pack_length (a
);
6206 for (i
= 0; i
< len
; ++i
)
6209 d_append_string (dpi
, ", ");
6210 dpi
->pack_index
= i
;
6211 d_print_comp (dpi
, options
, dc
);
6217 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
6219 long num
= dc
->u
.s_number
.number
;
6221 d_append_string (dpi
, "this");
6224 d_append_string (dpi
, "{parm#");
6225 d_append_num (dpi
, num
);
6226 d_append_char (dpi
, '}');
6231 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
6232 d_append_string (dpi
, "global constructors keyed to ");
6233 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
6236 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
6237 d_append_string (dpi
, "global destructors keyed to ");
6238 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
6241 case DEMANGLE_COMPONENT_LAMBDA
:
6243 d_append_string (dpi
, "{lambda");
6244 struct demangle_component
*parms
= dc
->u
.s_unary_num
.sub
;
6245 struct d_print_template dpt
;
6246 /* Generic lambda auto parms are mangled as the (synthedic) template
6247 type parm they are. We need to tell the printer that (a) we're in
6248 a lambda, and (b) the number of synthetic parms. */
6249 int saved_tpl_parms
= dpi
->lambda_tpl_parms
;
6250 dpi
->lambda_tpl_parms
= 0;
6251 /* Hang any lambda head as-if template args. */
6252 dpt
.template_decl
= NULL
;
6253 dpt
.next
= dpi
->templates
;
6254 dpi
->templates
= &dpt
;
6255 if (parms
&& parms
->type
== DEMANGLE_COMPONENT_TEMPLATE_HEAD
)
6257 dpt
.template_decl
= parms
;
6259 d_append_char (dpi
, '<');
6260 struct demangle_component
*parm
;
6261 for (parm
= d_left (parms
); parm
; parm
= d_right (parm
))
6263 if (dpi
->lambda_tpl_parms
++)
6264 d_append_string (dpi
, ", ");
6265 d_print_comp (dpi
, options
, parm
);
6266 d_append_char (dpi
, ' ');
6267 if (parm
->type
== DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
)
6268 parm
= d_left (parm
);
6269 d_print_lambda_parm_name (dpi
, parm
->type
,
6270 dpi
->lambda_tpl_parms
- 1);
6272 d_append_char (dpi
, '>');
6274 parms
= d_right (parms
);
6276 dpi
->lambda_tpl_parms
++;
6278 d_append_char (dpi
, '(');
6279 d_print_comp (dpi
, options
, parms
);
6280 dpi
->lambda_tpl_parms
= saved_tpl_parms
;
6281 dpi
->templates
= dpt
.next
;
6282 d_append_string (dpi
, ")#");
6283 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
6284 d_append_char (dpi
, '}');
6288 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
6289 d_append_string (dpi
, "{unnamed type#");
6290 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
6291 d_append_char (dpi
, '}');
6294 case DEMANGLE_COMPONENT_CLONE
:
6295 d_print_comp (dpi
, options
, d_left (dc
));
6296 d_append_string (dpi
, " [clone ");
6297 d_print_comp (dpi
, options
, d_right (dc
));
6298 d_append_char (dpi
, ']');
6301 case DEMANGLE_COMPONENT_FRIEND
:
6302 d_print_comp (dpi
, options
, d_left (dc
));
6303 d_append_string (dpi
, "[friend]");
6306 case DEMANGLE_COMPONENT_TEMPLATE_HEAD
:
6308 d_append_char (dpi
, '<');
6310 struct demangle_component
*parm
;
6311 for (parm
= d_left (dc
); parm
; parm
= d_right (parm
))
6314 d_append_string (dpi
, ", ");
6315 d_print_comp (dpi
, options
, parm
);
6317 d_append_char (dpi
, '>');
6321 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
6322 d_append_string (dpi
, "typename");
6325 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
6326 d_print_comp (dpi
, options
, d_left (dc
));
6329 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
6330 d_append_string (dpi
, "template");
6331 d_print_comp (dpi
, options
, d_left (dc
));
6332 d_append_string (dpi
, " class");
6335 case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
:
6336 d_print_comp (dpi
, options
, d_left (dc
));
6337 d_append_string (dpi
, "...");
6340 case DEMANGLE_COMPONENT_CONSTRAINTS
:
6341 d_print_comp (dpi
, options
, d_left (dc
));
6342 d_append_string (dpi
, " requires ");
6343 d_print_comp (dpi
, options
, d_right (dc
));
6347 d_print_error (dpi
);
6353 d_print_comp (struct d_print_info
*dpi
, int options
,
6354 struct demangle_component
*dc
)
6356 struct d_component_stack self
;
6357 if (dc
== NULL
|| dc
->d_printing
> 1 || dpi
->recursion
> MAX_RECURSION_COUNT
)
6359 d_print_error (dpi
);
6367 self
.parent
= dpi
->component_stack
;
6368 dpi
->component_stack
= &self
;
6370 d_print_comp_inner (dpi
, options
, dc
);
6372 dpi
->component_stack
= self
.parent
;
6377 /* Print a Java dentifier. For Java we try to handle encoded extended
6378 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
6379 so we don't it for C++. Characters are encoded as
6383 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
6389 for (p
= name
; p
< end
; ++p
)
6400 for (q
= p
+ 3; q
< end
; ++q
)
6406 else if (*q
>= 'A' && *q
<= 'F')
6407 dig
= *q
- 'A' + 10;
6408 else if (*q
>= 'a' && *q
<= 'f')
6409 dig
= *q
- 'a' + 10;
6415 /* If the Unicode character is larger than 256, we don't try
6416 to deal with it here. FIXME. */
6417 if (q
< end
&& *q
== '_' && c
< 256)
6419 d_append_char (dpi
, c
);
6425 d_append_char (dpi
, *p
);
6429 /* Print a list of modifiers. SUFFIX is 1 if we are printing
6430 qualifiers on this after printing a function. */
6433 d_print_mod_list (struct d_print_info
*dpi
, int options
,
6434 struct d_print_mod
*mods
, int suffix
)
6436 struct d_print_template
*hold_dpt
;
6438 if (mods
== NULL
|| d_print_saw_error (dpi
))
6443 && (is_fnqual_component_type (mods
->mod
->type
))))
6445 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
6451 hold_dpt
= dpi
->templates
;
6452 dpi
->templates
= mods
->templates
;
6454 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
6456 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
6457 dpi
->templates
= hold_dpt
;
6460 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
6462 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
6463 dpi
->templates
= hold_dpt
;
6466 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
6468 struct d_print_mod
*hold_modifiers
;
6469 struct demangle_component
*dc
;
6471 /* When this is on the modifier stack, we have pulled any
6472 qualifiers off the right argument already. Otherwise, we
6473 print it as usual, but don't let the left argument see any
6476 hold_modifiers
= dpi
->modifiers
;
6477 dpi
->modifiers
= NULL
;
6478 d_print_comp (dpi
, options
, d_left (mods
->mod
));
6479 dpi
->modifiers
= hold_modifiers
;
6481 if ((options
& DMGL_JAVA
) == 0)
6482 d_append_string (dpi
, "::");
6484 d_append_char (dpi
, '.');
6486 dc
= d_right (mods
->mod
);
6488 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
6490 d_append_string (dpi
, "{default arg#");
6491 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
6492 d_append_string (dpi
, "}::");
6493 dc
= dc
->u
.s_unary_num
.sub
;
6496 while (is_fnqual_component_type (dc
->type
))
6499 d_print_comp (dpi
, options
, dc
);
6501 dpi
->templates
= hold_dpt
;
6505 d_print_mod (dpi
, options
, mods
->mod
);
6507 dpi
->templates
= hold_dpt
;
6509 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
6512 /* Print a modifier. */
6515 d_print_mod (struct d_print_info
*dpi
, int options
,
6516 struct demangle_component
*mod
)
6520 case DEMANGLE_COMPONENT_RESTRICT
:
6521 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6522 d_append_string (dpi
, " restrict");
6524 case DEMANGLE_COMPONENT_VOLATILE
:
6525 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6526 d_append_string (dpi
, " volatile");
6528 case DEMANGLE_COMPONENT_CONST
:
6529 case DEMANGLE_COMPONENT_CONST_THIS
:
6530 d_append_string (dpi
, " const");
6532 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
6533 d_append_string (dpi
, " transaction_safe");
6535 case DEMANGLE_COMPONENT_NOEXCEPT
:
6536 d_append_string (dpi
, " noexcept");
6539 d_append_char (dpi
, '(');
6540 d_print_comp (dpi
, options
, d_right (mod
));
6541 d_append_char (dpi
, ')');
6544 case DEMANGLE_COMPONENT_THROW_SPEC
:
6545 d_append_string (dpi
, " throw");
6548 d_append_char (dpi
, '(');
6549 d_print_comp (dpi
, options
, d_right (mod
));
6550 d_append_char (dpi
, ')');
6553 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
6554 d_append_char (dpi
, ' ');
6555 d_print_comp (dpi
, options
, d_right (mod
));
6557 case DEMANGLE_COMPONENT_POINTER
:
6558 /* There is no pointer symbol in Java. */
6559 if ((options
& DMGL_JAVA
) == 0)
6560 d_append_char (dpi
, '*');
6562 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6563 /* For the ref-qualifier, put a space before the &. */
6564 d_append_char (dpi
, ' ');
6566 case DEMANGLE_COMPONENT_REFERENCE
:
6567 d_append_char (dpi
, '&');
6569 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6570 d_append_char (dpi
, ' ');
6572 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
6573 d_append_string (dpi
, "&&");
6575 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
6577 case DEMANGLE_COMPONENT_COMPLEX
:
6578 d_append_string (dpi
, " _Complex");
6580 case DEMANGLE_COMPONENT_IMAGINARY
:
6581 d_append_string (dpi
, " _Imaginary");
6583 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
6584 if (d_last_char (dpi
) != '(')
6585 d_append_char (dpi
, ' ');
6586 d_print_comp (dpi
, options
, d_left (mod
));
6587 d_append_string (dpi
, "::*");
6589 case DEMANGLE_COMPONENT_TYPED_NAME
:
6590 d_print_comp (dpi
, options
, d_left (mod
));
6592 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
6593 d_append_string (dpi
, " __vector(");
6594 d_print_comp (dpi
, options
, d_left (mod
));
6595 d_append_char (dpi
, ')');
6599 /* Otherwise, we have something that won't go back on the
6600 modifier stack, so we can just print it. */
6601 d_print_comp (dpi
, options
, mod
);
6606 /* Print a function type, except for the return type. */
6609 d_print_function_type (struct d_print_info
*dpi
, int options
,
6610 struct demangle_component
*dc
,
6611 struct d_print_mod
*mods
)
6616 struct d_print_mod
*p
;
6617 struct d_print_mod
*hold_modifiers
;
6622 for (p
= mods
; p
!= NULL
; p
= p
->next
)
6627 switch (p
->mod
->type
)
6629 case DEMANGLE_COMPONENT_POINTER
:
6630 case DEMANGLE_COMPONENT_REFERENCE
:
6631 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
6634 case DEMANGLE_COMPONENT_RESTRICT
:
6635 case DEMANGLE_COMPONENT_VOLATILE
:
6636 case DEMANGLE_COMPONENT_CONST
:
6637 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
6638 case DEMANGLE_COMPONENT_COMPLEX
:
6639 case DEMANGLE_COMPONENT_IMAGINARY
:
6640 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
6644 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
6658 if (d_last_char (dpi
) != '('
6659 && d_last_char (dpi
) != '*')
6662 if (need_space
&& d_last_char (dpi
) != ' ')
6663 d_append_char (dpi
, ' ');
6664 d_append_char (dpi
, '(');
6667 hold_modifiers
= dpi
->modifiers
;
6668 dpi
->modifiers
= NULL
;
6670 d_print_mod_list (dpi
, options
, mods
, 0);
6673 d_append_char (dpi
, ')');
6675 d_append_char (dpi
, '(');
6677 d_append_string (dpi
, "this ");
6679 if (d_right (dc
) != NULL
)
6680 d_print_comp (dpi
, options
, d_right (dc
));
6682 d_append_char (dpi
, ')');
6684 d_print_mod_list (dpi
, options
, mods
, 1);
6686 dpi
->modifiers
= hold_modifiers
;
6689 /* Print an array type, except for the element type. */
6692 d_print_array_type (struct d_print_info
*dpi
, int options
,
6693 struct demangle_component
*dc
,
6694 struct d_print_mod
*mods
)
6702 struct d_print_mod
*p
;
6705 for (p
= mods
; p
!= NULL
; p
= p
->next
)
6709 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
6724 d_append_string (dpi
, " (");
6726 d_print_mod_list (dpi
, options
, mods
, 0);
6729 d_append_char (dpi
, ')');
6733 d_append_char (dpi
, ' ');
6735 d_append_char (dpi
, '[');
6737 if (d_left (dc
) != NULL
)
6738 d_print_comp (dpi
, options
, d_left (dc
));
6740 d_append_char (dpi
, ']');
6743 /* Print an operator in an expression. */
6746 d_print_expr_op (struct d_print_info
*dpi
, int options
,
6747 struct demangle_component
*dc
)
6749 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
6750 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
6751 dc
->u
.s_operator
.op
->len
);
6753 d_print_comp (dpi
, options
, dc
);
6759 d_print_cast (struct d_print_info
*dpi
, int options
,
6760 struct demangle_component
*dc
)
6762 d_print_comp (dpi
, options
, d_left (dc
));
6765 /* Print a conversion operator. */
6768 d_print_conversion (struct d_print_info
*dpi
, int options
,
6769 struct demangle_component
*dc
)
6771 struct d_print_template dpt
;
6773 /* For a conversion operator, we need the template parameters from
6774 the enclosing template in scope for processing the type. */
6775 if (dpi
->current_template
!= NULL
)
6777 dpt
.next
= dpi
->templates
;
6778 dpi
->templates
= &dpt
;
6779 dpt
.template_decl
= dpi
->current_template
;
6782 d_print_comp (dpi
, options
, d_left (dc
));
6784 if (dpi
->current_template
!= NULL
)
6785 dpi
->templates
= dpt
.next
;
6788 /* Initialize the information structure we use to pass around
6791 CP_STATIC_IF_GLIBCPP_V3
6793 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
6797 di
->send
= mangled
+ len
;
6798 di
->options
= options
;
6802 /* We cannot need more components than twice the number of chars in
6803 the mangled string. Most components correspond directly to
6804 chars, but the ARGLIST types are exceptions. */
6805 di
->num_comps
= 2 * len
;
6808 /* Similarly, we cannot need more substitutions than there are
6809 chars in the mangled string. */
6813 di
->last_name
= NULL
;
6816 di
->is_expression
= 0;
6817 di
->is_conversion
= 0;
6818 di
->recursion_level
= 0;
6821 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
6822 mangled name, return strings in repeated callback giving the demangled
6823 name. OPTIONS is the usual libiberty demangler options. On success,
6824 this returns 1. On failure, returns 0. */
6827 d_demangle_callback (const char *mangled
, int options
,
6828 demangle_callbackref callback
, void *opaque
)
6839 struct demangle_component
*dc
;
6842 if (mangled
[0] == '_' && mangled
[1] == 'Z')
6844 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
6845 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
6846 && (mangled
[9] == 'D' || mangled
[9] == 'I')
6847 && mangled
[10] == '_')
6848 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
6851 if ((options
& DMGL_TYPES
) == 0)
6856 di
.unresolved_name_state
= 1;
6859 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
6861 /* PR 87675 - Check for a mangled string that is so long
6862 that we do not have enough stack space to demangle it. */
6863 if (((options
& DMGL_NO_RECURSE_LIMIT
) == 0)
6864 /* This check is a bit arbitrary, since what we really want to do is to
6865 compare the sizes of the di.comps and di.subs arrays against the
6866 amount of stack space remaining. But there is no portable way to do
6867 this, so instead we use the recursion limit as a guide to the maximum
6868 size of the arrays. */
6869 && (unsigned long) di
.num_comps
> DEMANGLE_RECURSION_LIMIT
)
6871 /* FIXME: We need a way to indicate that a stack limit has been reached. */
6876 #if 0 /* in valgrind */
6877 #ifdef CP_DYNAMIC_ARRAYS
6878 __extension__
struct demangle_component comps
[di
.num_comps
];
6879 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6884 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6885 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6888 /* Allocate memory dynamically to avoid VLAs as valgrind stack
6889 is a scarce resource */
6890 di
.comps
= xmalloc (di
.num_comps
* sizeof (*di
.comps
));
6891 di
.subs
= xmalloc (di
.num_subs
* sizeof (*di
.subs
));
6892 #endif /* ! in valgrind */
6897 dc
= cplus_demangle_type (&di
);
6900 dc
= cplus_demangle_mangled_name (&di
, 1);
6902 case DCT_GLOBAL_CTORS
:
6903 case DCT_GLOBAL_DTORS
:
6904 d_advance (&di
, 11);
6905 dc
= d_make_comp (&di
,
6906 (type
== DCT_GLOBAL_CTORS
6907 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
6908 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
6909 d_make_demangle_mangled_name (&di
, d_str (&di
)),
6911 d_advance (&di
, strlen (d_str (&di
)));
6914 abort (); /* We have listed all the cases. */
6917 /* If DMGL_PARAMS is set, then if we didn't consume the entire
6918 mangled string, then we didn't successfully demangle it. If
6919 DMGL_PARAMS is not set, we didn't look at the trailing
6921 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
6924 /* See discussion in d_unresolved_name. */
6925 if (dc
== NULL
&& di
.unresolved_name_state
== -1)
6927 di
.unresolved_name_state
= 0;
6931 #ifdef CP_DEMANGLE_DEBUG
6935 status
= (dc
!= NULL
)
6936 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6940 #if 0 /* in valgrind */
6944 #endif /* in valgrind */
6949 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6950 name, return a buffer allocated with malloc holding the demangled
6951 name. OPTIONS is the usual libiberty demangler options. On
6952 success, this sets *PALC to the allocated size of the returned
6953 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6954 a memory allocation failure, and returns NULL. */
6957 d_demangle (const char *mangled
, int options
, size_t *palc
)
6959 struct d_growable_string dgs
;
6962 d_growable_string_init (&dgs
, 0);
6964 status
= d_demangle_callback (mangled
, options
,
6965 d_growable_string_callback_adapter
, &dgs
);
6973 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6977 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6979 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6981 /* ia64 ABI-mandated entry point in the C++ runtime library for
6982 performing demangling. MANGLED_NAME is a NUL-terminated character
6983 string containing the name to be demangled.
6985 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6986 *LENGTH bytes, into which the demangled name is stored. If
6987 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6988 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6989 is placed in a region of memory allocated with malloc.
6991 If LENGTH is non-NULL, the length of the buffer containing the
6992 demangled name, is placed in *LENGTH.
6994 The return value is a pointer to the start of the NUL-terminated
6995 demangled name, or NULL if the demangling fails. The caller is
6996 responsible for deallocating this memory using free.
6998 *STATUS is set to one of the following values:
6999 0: The demangling operation succeeded.
7000 -1: A memory allocation failure occurred.
7001 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
7002 -3: One of the arguments is invalid.
7004 The demangling is performed using the C++ ABI mangling rules, with
7008 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
7009 size_t *length
, int *status
)
7014 if (mangled_name
== NULL
)
7021 if (output_buffer
!= NULL
&& length
== NULL
)
7028 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
7030 if (demangled
== NULL
)
7042 if (output_buffer
== NULL
)
7049 if (strlen (demangled
) < *length
)
7051 strcpy (output_buffer
, demangled
);
7053 demangled
= output_buffer
;
7057 free (output_buffer
);
7068 extern int __gcclibcxx_demangle_callback (const char *,
7070 (const char *, size_t, void *),
7073 /* Alternative, allocationless entry point in the C++ runtime library
7074 for performing demangling. MANGLED_NAME is a NUL-terminated character
7075 string containing the name to be demangled.
7077 CALLBACK is a callback function, called with demangled string
7078 segments as demangling progresses; it is called at least once,
7079 but may be called more than once. OPAQUE is a generalized pointer
7080 used as a callback argument.
7082 The return code is one of the following values, equivalent to
7083 the STATUS values of __cxa_demangle() (excluding -1, since this
7084 function performs no memory allocations):
7085 0: The demangling operation succeeded.
7086 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
7087 -3: One of the arguments is invalid.
7089 The demangling is performed using the C++ ABI mangling rules, with
7093 __gcclibcxx_demangle_callback (const char *mangled_name
,
7094 void (*callback
) (const char *, size_t, void *),
7099 if (mangled_name
== NULL
|| callback
== NULL
)
7102 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
7110 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
7112 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
7113 mangled name, return a buffer allocated with malloc holding the
7114 demangled name. Otherwise, return NULL. */
7117 cplus_demangle_v3 (const char *mangled
, int options
)
7121 return d_demangle (mangled
, options
, &alc
);
7125 cplus_demangle_v3_callback (const char *mangled
, int options
,
7126 demangle_callbackref callback
, void *opaque
)
7128 return d_demangle_callback (mangled
, options
, callback
, opaque
);
7131 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
7132 conventions, but the output formatting is a little different.
7133 This instructs the C++ demangler not to emit pointer characters ("*"), to
7134 use Java's namespace separator symbol ("." instead of "::"), and to output
7135 JArray<TYPE> as TYPE[]. */
7138 java_demangle_v3 (const char *mangled
)
7142 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
7146 java_demangle_v3_callback (const char *mangled
,
7147 demangle_callbackref callback
, void *opaque
)
7149 return d_demangle_callback (mangled
,
7150 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
7154 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
7156 #ifndef IN_GLIBCPP_V3
7158 /* Demangle a string in order to find out whether it is a constructor
7159 or destructor. Return non-zero on success. Set *CTOR_KIND and
7160 *DTOR_KIND appropriately. */
7163 is_ctor_or_dtor (const char *mangled
,
7164 enum gnu_v3_ctor_kinds
*ctor_kind
,
7165 enum gnu_v3_dtor_kinds
*dtor_kind
)
7168 struct demangle_component
*dc
;
7171 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
7172 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
7174 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
7177 #if 0 /* in valgrind */
7178 #ifdef CP_DYNAMIC_ARRAYS
7179 __extension__
struct demangle_component comps
[di
.num_comps
];
7180 __extension__
struct demangle_component
*subs
[di
.num_subs
];
7185 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
7186 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
7189 /* Allocate memory dynamically to avoid VLAs as valgrind stack
7190 is a scarce resource */
7191 di
.comps
= xmalloc (di
.num_comps
* sizeof (*di
.comps
));
7192 di
.subs
= xmalloc (di
.num_subs
* sizeof (*di
.subs
));
7193 #endif /* ! in valgrind */
7194 dc
= cplus_demangle_mangled_name (&di
, 1);
7196 /* Note that because we did not pass DMGL_PARAMS, we don't expect
7197 to demangle the entire string. */
7204 /* These cannot appear on a constructor or destructor. */
7205 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
7206 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
7207 case DEMANGLE_COMPONENT_CONST_THIS
:
7208 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
7209 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
7213 case DEMANGLE_COMPONENT_TYPED_NAME
:
7214 case DEMANGLE_COMPONENT_TEMPLATE
:
7217 case DEMANGLE_COMPONENT_QUAL_NAME
:
7218 case DEMANGLE_COMPONENT_LOCAL_NAME
:
7221 case DEMANGLE_COMPONENT_CTOR
:
7222 *ctor_kind
= dc
->u
.s_ctor
.kind
;
7226 case DEMANGLE_COMPONENT_DTOR
:
7227 *dtor_kind
= dc
->u
.s_dtor
.kind
;
7235 #if 0 /* in valgrind */
7239 #endif /* in valgrind */
7244 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
7245 name. A non-zero return indicates the type of constructor. */
7247 enum gnu_v3_ctor_kinds
7248 is_gnu_v3_mangled_ctor (const char *name
)
7250 enum gnu_v3_ctor_kinds ctor_kind
;
7251 enum gnu_v3_dtor_kinds dtor_kind
;
7253 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
7254 return (enum gnu_v3_ctor_kinds
) 0;
7259 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
7260 name. A non-zero return indicates the type of destructor. */
7262 enum gnu_v3_dtor_kinds
7263 is_gnu_v3_mangled_dtor (const char *name
)
7265 enum gnu_v3_ctor_kinds ctor_kind
;
7266 enum gnu_v3_dtor_kinds dtor_kind
;
7268 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
7269 return (enum gnu_v3_dtor_kinds
) 0;
7273 #endif /* IN_GLIBCPP_V3 */
7275 #ifdef STANDALONE_DEMANGLER
7277 #if 0 /* in valgrind */
7279 #include "dyn-string.h"
7280 #endif /* ! in valgrind */
7282 static void print_usage (FILE* fp
, int exit_value
);
7284 #define IS_ALPHA(CHAR) \
7285 (((CHAR) >= 'a' && (CHAR) <= 'z') \
7286 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
7288 /* Non-zero if CHAR is a character than can occur in a mangled name. */
7289 #define is_mangled_char(CHAR) \
7290 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
7291 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
7293 /* The name of this program, as invoked. */
7294 const char* program_name
;
7296 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
7299 print_usage (FILE* fp
, int exit_value
)
7301 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
7302 fprintf (fp
, "Options:\n");
7303 fprintf (fp
, " -h,--help Display this message.\n");
7304 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
7305 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
7306 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
7311 /* Option specification for getopt_long. */
7312 static const struct option long_options
[] =
7314 { "help", no_argument
, NULL
, 'h' },
7315 { "no-params", no_argument
, NULL
, 'p' },
7316 { "verbose", no_argument
, NULL
, 'v' },
7317 { NULL
, no_argument
, NULL
, 0 },
7320 /* Main entry for a demangling filter executable. It will demangle
7321 its command line arguments, if any. If none are provided, it will
7322 filter stdin to stdout, replacing any recognized mangled C++ names
7323 with their demangled equivalents. */
7326 main (int argc
, char *argv
[])
7330 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
7332 /* Use the program name of this program, as invoked. */
7333 program_name
= argv
[0];
7335 /* Parse options. */
7338 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
7341 case '?': /* Unrecognized option. */
7342 print_usage (stderr
, 1);
7346 print_usage (stdout
, 0);
7350 options
&= ~ DMGL_PARAMS
;
7354 options
|= DMGL_VERBOSE
;
7358 while (opt_char
!= -1);
7361 /* No command line arguments were provided. Filter stdin. */
7363 dyn_string_t mangled
= dyn_string_new (3);
7366 /* Read all of input. */
7367 while (!feof (stdin
))
7371 /* Pile characters into mangled until we hit one that can't
7372 occur in a mangled name. */
7374 while (!feof (stdin
) && is_mangled_char (c
))
7376 dyn_string_append_char (mangled
, c
);
7382 if (dyn_string_length (mangled
) > 0)
7384 #ifdef IN_GLIBCPP_V3
7385 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
7387 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
7397 /* It might not have been a mangled name. Print the
7399 fputs (dyn_string_buf (mangled
), stdout
);
7402 dyn_string_clear (mangled
);
7405 /* If we haven't hit EOF yet, we've read one character that
7406 can't occur in a mangled name, so print it out. */
7411 dyn_string_delete (mangled
);
7414 /* Demangle command line arguments. */
7416 /* Loop over command line arguments. */
7417 for (i
= optind
; i
< argc
; ++i
)
7420 #ifdef IN_GLIBCPP_V3
7424 /* Attempt to demangle. */
7425 #ifdef IN_GLIBCPP_V3
7426 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
7428 s
= cplus_demangle_v3 (argv
[i
], options
);
7431 /* If it worked, print the demangled name. */
7439 #ifdef IN_GLIBCPP_V3
7440 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
7442 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
7451 #endif /* STANDALONE_DEMANGLER */