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 defined (_AIX) && !defined (__GNUC__)
123 # define alloca __builtin_alloca
125 extern char *alloca ();
126 # endif /* __GNUC__ */
128 #endif /* HAVE_ALLOCA_H */
134 # define INT_MAX (int)(((unsigned int) ~0) >> 1) /* 0x7FFFFFFF */
137 #include "ansidecl.h"
138 #include "libiberty.h"
139 #include "demangle.h"
140 #include "cp-demangle.h"
142 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
143 also rename them via #define to avoid compiler errors when the
144 static definition conflicts with the extern declaration in a header
148 #define CP_STATIC_IF_GLIBCPP_V3 static
150 #define cplus_demangle_fill_name d_fill_name
151 static int d_fill_name (struct demangle_component
*, const char *, int);
153 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
155 d_fill_extended_operator (struct demangle_component
*, int,
156 struct demangle_component
*);
158 #define cplus_demangle_fill_ctor d_fill_ctor
160 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
161 struct demangle_component
*);
163 #define cplus_demangle_fill_dtor d_fill_dtor
165 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
166 struct demangle_component
*);
168 #define cplus_demangle_mangled_name d_mangled_name
169 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
171 #define cplus_demangle_type d_type
172 static struct demangle_component
*d_type (struct d_info
*);
174 #define cplus_demangle_print d_print
175 static char *d_print (int, struct demangle_component
*, int, size_t *);
177 #define cplus_demangle_print_callback d_print_callback
178 static int d_print_callback (int, struct demangle_component
*,
179 demangle_callbackref
, void *);
181 #define cplus_demangle_init_info d_init_info
182 static void d_init_info (const char *, int, size_t, struct d_info
*);
184 #else /* ! defined(IN_GLIBCPP_V3) */
185 #define CP_STATIC_IF_GLIBCPP_V3
186 #endif /* ! defined(IN_GLIBCPP_V3) */
188 /* See if the compiler supports dynamic arrays. */
191 #define CP_DYNAMIC_ARRAYS
194 #ifdef __STDC_VERSION__
195 #if __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__
196 #define CP_DYNAMIC_ARRAYS
197 #endif /* __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ */
198 #endif /* defined (__STDC_VERSION__) */
199 #endif /* defined (__STDC__) */
200 #endif /* ! defined (__GNUC__) */
202 /* We avoid pulling in the ctype tables, to prevent pulling in
203 additional unresolved symbols when this code is used in a library.
204 FIXME: Is this really a valid reason? This comes from the original
207 As of this writing this file has the following undefined references
208 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
211 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
212 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
213 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
215 /* The prefix prepended by GCC to an identifier represnting the
216 anonymous namespace. */
217 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
218 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
219 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
221 /* Information we keep for the standard substitutions. */
223 struct d_standard_sub_info
225 /* The code for this substitution. */
227 /* The simple string it expands to. */
228 const char *simple_expansion
;
229 /* The length of the simple expansion. */
231 /* The results of a full, verbose, expansion. This is used when
232 qualifying a constructor/destructor, or when in verbose mode. */
233 const char *full_expansion
;
234 /* The length of the full expansion. */
236 /* What to set the last_name field of d_info to; NULL if we should
237 not set it. This is only relevant when qualifying a
238 constructor/destructor. */
239 const char *set_last_name
;
240 /* The length of set_last_name. */
241 int set_last_name_len
;
244 /* Accessors for subtrees of struct demangle_component. */
246 #define d_left(dc) ((dc)->u.s_binary.left)
247 #define d_right(dc) ((dc)->u.s_binary.right)
249 /* A list of templates. This is used while printing. */
251 struct d_print_template
253 /* Next template on the list. */
254 struct d_print_template
*next
;
256 const struct demangle_component
*template_decl
;
259 /* A list of type modifiers. This is used while printing. */
263 /* Next modifier on the list. These are in the reverse of the order
264 in which they appeared in the mangled string. */
265 struct d_print_mod
*next
;
267 struct demangle_component
*mod
;
268 /* Whether this modifier was printed. */
270 /* The list of templates which applies to this modifier. */
271 struct d_print_template
*templates
;
274 /* We use these structures to hold information during printing. */
276 struct d_growable_string
278 /* Buffer holding the result. */
280 /* Current length of data in buffer. */
282 /* Allocated size of buffer. */
284 /* Set to 1 if we had a memory allocation failure. */
285 int allocation_failure
;
288 /* Stack of components, innermost first, used to avoid loops. */
290 struct d_component_stack
292 /* This component. */
293 const struct demangle_component
*dc
;
294 /* This component's parent. */
295 const struct d_component_stack
*parent
;
298 /* A demangle component and some scope captured when it was first
303 /* The component whose scope this is. */
304 const struct demangle_component
*container
;
305 /* The list of templates, if any, that was current when this
306 scope was captured. */
307 struct d_print_template
*templates
;
310 /* Checkpoint structure to allow backtracking. This holds copies
311 of the fields of struct d_info that need to be restored
312 if a trial parse needs to be backtracked over. */
314 struct d_info_checkpoint
322 /* Maximum number of times d_print_comp may be called recursively. */
323 #define MAX_RECURSION_COUNT 1024
325 enum { D_PRINT_BUFFER_LENGTH
= 256 };
328 /* Fixed-length allocated buffer for demangled data, flushed to the
329 callback with a NUL termination once full. */
330 char buf
[D_PRINT_BUFFER_LENGTH
];
331 /* Current length of data in buffer. */
333 /* The last character printed, saved individually so that it survives
336 /* Callback function to handle demangled buffer flush. */
337 demangle_callbackref callback
;
338 /* Opaque callback argument. */
340 /* The current list of templates, if any. */
341 struct d_print_template
*templates
;
342 /* The current list of modifiers (e.g., pointer, reference, etc.),
344 struct d_print_mod
*modifiers
;
345 /* Set to 1 if we saw a demangling error. */
346 int demangle_failure
;
347 /* Number of times d_print_comp was recursively called. Should not
348 be bigger than MAX_RECURSION_COUNT. */
350 /* 1 more than the number of explicit template parms of a lambda. Template
351 parm references >= are actually 'auto'. */
352 int lambda_tpl_parms
;
353 /* The current index into any template argument packs we are using
354 for printing, or -1 to print the whole pack. */
356 /* Number of d_print_flush calls so far. */
357 unsigned long int flush_count
;
358 /* Stack of components, innermost first, used to avoid loops. */
359 const struct d_component_stack
*component_stack
;
360 /* Array of saved scopes for evaluating substitutions. */
361 struct d_saved_scope
*saved_scopes
;
362 /* Index of the next unused saved scope in the above array. */
363 int next_saved_scope
;
364 /* Number of saved scopes in the above array. */
365 int num_saved_scopes
;
366 /* Array of templates for saving into scopes. */
367 struct d_print_template
*copy_templates
;
368 /* Index of the next unused copy template in the above array. */
369 int next_copy_template
;
370 /* Number of copy templates in the above array. */
371 int num_copy_templates
;
372 /* The nearest enclosing template, if any. */
373 const struct demangle_component
*current_template
;
376 #ifdef CP_DEMANGLE_DEBUG
377 static void d_dump (struct demangle_component
*, int);
380 static struct demangle_component
*
381 d_make_empty (struct d_info
*);
383 static struct demangle_component
*
384 d_make_comp (struct d_info
*, enum demangle_component_type
,
385 struct demangle_component
*,
386 struct demangle_component
*);
388 static struct demangle_component
*
389 d_make_name (struct d_info
*, const char *, int);
391 static struct demangle_component
*
392 d_make_demangle_mangled_name (struct d_info
*, const char *);
394 static struct demangle_component
*
395 d_make_builtin_type (struct d_info
*,
396 const struct demangle_builtin_type_info
*);
398 static struct demangle_component
*
399 d_make_operator (struct d_info
*,
400 const struct demangle_operator_info
*);
402 static struct demangle_component
*
403 d_make_extended_operator (struct d_info
*, int,
404 struct demangle_component
*);
406 static struct demangle_component
*
407 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
408 struct demangle_component
*);
410 static struct demangle_component
*
411 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
412 struct demangle_component
*);
414 static struct demangle_component
*
415 d_make_template_param (struct d_info
*, int);
417 static struct demangle_component
*
418 d_make_sub (struct d_info
*, const char *, int);
421 has_return_type (struct demangle_component
*);
424 is_ctor_dtor_or_conversion (struct demangle_component
*);
426 static struct demangle_component
*d_encoding (struct d_info
*, int);
428 static struct demangle_component
*d_name (struct d_info
*, int substable
);
430 static struct demangle_component
*d_nested_name (struct d_info
*);
432 static int d_maybe_module_name (struct d_info
*, struct demangle_component
**);
434 static struct demangle_component
*d_prefix (struct d_info
*, int);
436 static struct demangle_component
*d_unqualified_name (struct d_info
*,
437 struct demangle_component
*scope
, struct demangle_component
*module
);
439 static struct demangle_component
*d_source_name (struct d_info
*);
441 static int d_number (struct d_info
*);
443 static struct demangle_component
*d_identifier (struct d_info
*, int);
445 static struct demangle_component
*d_operator_name (struct d_info
*);
447 static struct demangle_component
*d_special_name (struct d_info
*);
449 static struct demangle_component
*d_parmlist (struct d_info
*);
451 static int d_call_offset (struct d_info
*, int);
453 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
455 static struct demangle_component
**
456 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
458 static struct demangle_component
*
459 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
461 static struct demangle_component
*
462 d_function_type (struct d_info
*);
464 static struct demangle_component
*
465 d_bare_function_type (struct d_info
*, int);
467 static struct demangle_component
*
468 d_class_enum_type (struct d_info
*, int);
470 static struct demangle_component
*d_array_type (struct d_info
*);
472 static struct demangle_component
*d_vector_type (struct d_info
*);
474 static struct demangle_component
*
475 d_pointer_to_member_type (struct d_info
*);
477 static struct demangle_component
*
478 d_template_param (struct d_info
*);
480 static struct demangle_component
*d_template_args (struct d_info
*);
481 static struct demangle_component
*d_template_args_1 (struct d_info
*);
483 static struct demangle_component
*
484 d_template_arg (struct d_info
*);
486 static struct demangle_component
*d_expression (struct d_info
*);
488 static struct demangle_component
*d_expr_primary (struct d_info
*);
490 static struct demangle_component
*d_local_name (struct d_info
*);
492 static int d_discriminator (struct d_info
*);
494 static struct demangle_component
*d_template_parm (struct d_info
*, int *bad
);
496 static struct demangle_component
*d_template_head (struct d_info
*, int *bad
);
498 static struct demangle_component
*d_lambda (struct d_info
*);
500 static struct demangle_component
*d_unnamed_type (struct d_info
*);
502 static struct demangle_component
*
503 d_clone_suffix (struct d_info
*, struct demangle_component
*);
506 d_add_substitution (struct d_info
*, struct demangle_component
*);
508 static struct demangle_component
*d_substitution (struct d_info
*, int);
510 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
512 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
514 static void d_growable_string_init (struct d_growable_string
*, size_t);
517 d_growable_string_resize (struct d_growable_string
*, size_t);
520 d_growable_string_append_buffer (struct d_growable_string
*,
521 const char *, size_t);
523 d_growable_string_callback_adapter (const char *, size_t, void *);
526 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
527 struct demangle_component
*);
529 static inline void d_print_error (struct d_print_info
*);
531 static inline int d_print_saw_error (struct d_print_info
*);
533 static inline void d_print_flush (struct d_print_info
*);
535 static inline void d_append_char (struct d_print_info
*, char);
537 static inline void d_append_buffer (struct d_print_info
*,
538 const char *, size_t);
540 static inline void d_append_string (struct d_print_info
*, const char *);
542 static inline char d_last_char (struct d_print_info
*);
545 d_print_comp (struct d_print_info
*, int, struct demangle_component
*);
548 d_print_java_identifier (struct d_print_info
*, const char *, int);
551 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
554 d_print_mod (struct d_print_info
*, int, struct demangle_component
*);
557 d_print_function_type (struct d_print_info
*, int,
558 struct demangle_component
*,
559 struct d_print_mod
*);
562 d_print_array_type (struct d_print_info
*, int,
563 struct demangle_component
*,
564 struct d_print_mod
*);
567 d_print_expr_op (struct d_print_info
*, int, struct demangle_component
*);
569 static void d_print_cast (struct d_print_info
*, int,
570 struct demangle_component
*);
571 static void d_print_conversion (struct d_print_info
*, int,
572 struct demangle_component
*);
574 static int d_demangle_callback (const char *, int,
575 demangle_callbackref
, void *);
576 static char *d_demangle (const char *, int, size_t *);
578 #define FNQUAL_COMPONENT_CASE \
579 case DEMANGLE_COMPONENT_RESTRICT_THIS: \
580 case DEMANGLE_COMPONENT_VOLATILE_THIS: \
581 case DEMANGLE_COMPONENT_CONST_THIS: \
582 case DEMANGLE_COMPONENT_REFERENCE_THIS: \
583 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \
584 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: \
585 case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \
586 case DEMANGLE_COMPONENT_NOEXCEPT: \
587 case DEMANGLE_COMPONENT_THROW_SPEC
589 /* True iff TYPE is a demangling component representing a
590 function-type-qualifier. */
593 is_fnqual_component_type (enum demangle_component_type type
)
597 FNQUAL_COMPONENT_CASE
:
606 #ifdef CP_DEMANGLE_DEBUG
609 d_dump (struct demangle_component
*dc
, int indent
)
616 printf ("failed demangling\n");
620 for (i
= 0; i
< indent
; ++i
)
625 case DEMANGLE_COMPONENT_NAME
:
626 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
628 case DEMANGLE_COMPONENT_TAGGED_NAME
:
629 printf ("tagged name\n");
630 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
631 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
633 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
634 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
636 case DEMANGLE_COMPONENT_TPARM_OBJ
:
637 printf ("template parameter object\n");
639 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
640 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
642 case DEMANGLE_COMPONENT_CTOR
:
643 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
644 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
646 case DEMANGLE_COMPONENT_DTOR
:
647 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
648 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
650 case DEMANGLE_COMPONENT_SUB_STD
:
651 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
653 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
654 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
656 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
658 char suffix
[2] = { dc
->u
.s_extended_builtin
.type
->suffix
, 0 };
659 printf ("builtin type %s%d%s\n", dc
->u
.s_extended_builtin
.type
->name
,
660 dc
->u
.s_extended_builtin
.type
->arg
, suffix
);
663 case DEMANGLE_COMPONENT_OPERATOR
:
664 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
666 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
667 printf ("extended operator with %d args\n",
668 dc
->u
.s_extended_operator
.args
);
669 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
672 case DEMANGLE_COMPONENT_QUAL_NAME
:
673 printf ("qualified name\n");
675 case DEMANGLE_COMPONENT_LOCAL_NAME
:
676 printf ("local name\n");
678 case DEMANGLE_COMPONENT_TYPED_NAME
:
679 printf ("typed name\n");
681 case DEMANGLE_COMPONENT_TEMPLATE
:
682 printf ("template\n");
684 case DEMANGLE_COMPONENT_VTABLE
:
687 case DEMANGLE_COMPONENT_VTT
:
690 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
691 printf ("construction vtable\n");
693 case DEMANGLE_COMPONENT_TYPEINFO
:
694 printf ("typeinfo\n");
696 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
697 printf ("typeinfo name\n");
699 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
700 printf ("typeinfo function\n");
702 case DEMANGLE_COMPONENT_THUNK
:
705 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
706 printf ("virtual thunk\n");
708 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
709 printf ("covariant thunk\n");
711 case DEMANGLE_COMPONENT_JAVA_CLASS
:
712 printf ("java class\n");
714 case DEMANGLE_COMPONENT_GUARD
:
717 case DEMANGLE_COMPONENT_REFTEMP
:
718 printf ("reference temporary\n");
720 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
721 printf ("hidden alias\n");
723 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
724 printf ("transaction clone\n");
726 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
727 printf ("non-transaction clone\n");
729 case DEMANGLE_COMPONENT_RESTRICT
:
730 printf ("restrict\n");
732 case DEMANGLE_COMPONENT_VOLATILE
:
733 printf ("volatile\n");
735 case DEMANGLE_COMPONENT_CONST
:
738 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
739 printf ("restrict this\n");
741 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
742 printf ("volatile this\n");
744 case DEMANGLE_COMPONENT_CONST_THIS
:
745 printf ("const this\n");
747 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
748 printf ("reference this\n");
750 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
751 printf ("rvalue reference this\n");
753 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
754 printf ("explicit object parameter\n");
756 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
757 printf ("transaction_safe this\n");
759 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
760 printf ("vendor type qualifier\n");
762 case DEMANGLE_COMPONENT_POINTER
:
763 printf ("pointer\n");
765 case DEMANGLE_COMPONENT_REFERENCE
:
766 printf ("reference\n");
768 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
769 printf ("rvalue reference\n");
771 case DEMANGLE_COMPONENT_COMPLEX
:
772 printf ("complex\n");
774 case DEMANGLE_COMPONENT_IMAGINARY
:
775 printf ("imaginary\n");
777 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
778 printf ("vendor type\n");
780 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
781 printf ("function type\n");
783 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
784 printf ("array type\n");
786 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
787 printf ("pointer to member type\n");
789 case DEMANGLE_COMPONENT_ARGLIST
:
790 printf ("argument list\n");
792 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
793 printf ("template argument list\n");
795 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
796 printf ("initializer list\n");
798 case DEMANGLE_COMPONENT_CAST
:
801 case DEMANGLE_COMPONENT_CONVERSION
:
802 printf ("conversion operator\n");
804 case DEMANGLE_COMPONENT_NULLARY
:
805 printf ("nullary operator\n");
807 case DEMANGLE_COMPONENT_UNARY
:
808 printf ("unary operator\n");
810 case DEMANGLE_COMPONENT_BINARY
:
811 printf ("binary operator\n");
813 case DEMANGLE_COMPONENT_BINARY_ARGS
:
814 printf ("binary operator arguments\n");
816 case DEMANGLE_COMPONENT_TRINARY
:
817 printf ("trinary operator\n");
819 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
820 printf ("trinary operator arguments 1\n");
822 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
823 printf ("trinary operator arguments 1\n");
825 case DEMANGLE_COMPONENT_LITERAL
:
826 printf ("literal\n");
828 case DEMANGLE_COMPONENT_LITERAL_NEG
:
829 printf ("negative literal\n");
831 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
832 printf ("vendor expression\n");
834 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
835 printf ("java resource\n");
837 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
838 printf ("compound name\n");
840 case DEMANGLE_COMPONENT_CHARACTER
:
841 printf ("character '%c'\n", dc
->u
.s_character
.character
);
843 case DEMANGLE_COMPONENT_NUMBER
:
844 printf ("number %ld\n", dc
->u
.s_number
.number
);
846 case DEMANGLE_COMPONENT_DECLTYPE
:
847 printf ("decltype\n");
849 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
850 printf ("pack expansion\n");
852 case DEMANGLE_COMPONENT_TLS_INIT
:
853 printf ("tls init function\n");
855 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
856 printf ("tls wrapper function\n");
858 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
859 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
860 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
862 case DEMANGLE_COMPONENT_LAMBDA
:
863 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
864 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
868 d_dump (d_left (dc
), indent
+ 2);
869 d_dump (d_right (dc
), indent
+ 2);
872 #endif /* CP_DEMANGLE_DEBUG */
874 /* Fill in a DEMANGLE_COMPONENT_NAME. */
876 CP_STATIC_IF_GLIBCPP_V3
878 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
880 if (p
== NULL
|| s
== NULL
|| len
<= 0)
884 p
->type
= DEMANGLE_COMPONENT_NAME
;
886 p
->u
.s_name
.len
= len
;
890 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
892 CP_STATIC_IF_GLIBCPP_V3
894 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
895 struct demangle_component
*name
)
897 if (p
== NULL
|| args
< 0 || name
== NULL
)
901 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
902 p
->u
.s_extended_operator
.args
= args
;
903 p
->u
.s_extended_operator
.name
= name
;
907 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
909 CP_STATIC_IF_GLIBCPP_V3
911 cplus_demangle_fill_ctor (struct demangle_component
*p
,
912 enum gnu_v3_ctor_kinds kind
,
913 struct demangle_component
*name
)
917 || (int) kind
< gnu_v3_complete_object_ctor
918 || (int) kind
> gnu_v3_object_ctor_group
)
922 p
->type
= DEMANGLE_COMPONENT_CTOR
;
923 p
->u
.s_ctor
.kind
= kind
;
924 p
->u
.s_ctor
.name
= name
;
928 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
930 CP_STATIC_IF_GLIBCPP_V3
932 cplus_demangle_fill_dtor (struct demangle_component
*p
,
933 enum gnu_v3_dtor_kinds kind
,
934 struct demangle_component
*name
)
938 || (int) kind
< gnu_v3_deleting_dtor
939 || (int) kind
> gnu_v3_object_dtor_group
)
943 p
->type
= DEMANGLE_COMPONENT_DTOR
;
944 p
->u
.s_dtor
.kind
= kind
;
945 p
->u
.s_dtor
.name
= name
;
949 /* Add a new component. */
951 static struct demangle_component
*
952 d_make_empty (struct d_info
*di
)
954 struct demangle_component
*p
;
956 if (di
->next_comp
>= di
->num_comps
)
958 p
= &di
->comps
[di
->next_comp
];
965 /* Add a new generic component. */
967 static struct demangle_component
*
968 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
969 struct demangle_component
*left
,
970 struct demangle_component
*right
)
972 struct demangle_component
*p
;
974 /* We check for errors here. A typical error would be a NULL return
975 from a subroutine. We catch those here, and return NULL
979 /* These types require two parameters. */
980 case DEMANGLE_COMPONENT_QUAL_NAME
:
981 case DEMANGLE_COMPONENT_LOCAL_NAME
:
982 case DEMANGLE_COMPONENT_TYPED_NAME
:
983 case DEMANGLE_COMPONENT_TAGGED_NAME
:
984 case DEMANGLE_COMPONENT_TEMPLATE
:
985 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
986 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
987 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
988 case DEMANGLE_COMPONENT_UNARY
:
989 case DEMANGLE_COMPONENT_BINARY
:
990 case DEMANGLE_COMPONENT_BINARY_ARGS
:
991 case DEMANGLE_COMPONENT_TRINARY
:
992 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
993 case DEMANGLE_COMPONENT_LITERAL
:
994 case DEMANGLE_COMPONENT_LITERAL_NEG
:
995 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
996 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
997 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
998 case DEMANGLE_COMPONENT_CLONE
:
999 case DEMANGLE_COMPONENT_MODULE_ENTITY
:
1000 case DEMANGLE_COMPONENT_CONSTRAINTS
:
1001 if (left
== NULL
|| right
== NULL
)
1005 /* These types only require one parameter. */
1006 case DEMANGLE_COMPONENT_VTABLE
:
1007 case DEMANGLE_COMPONENT_VTT
:
1008 case DEMANGLE_COMPONENT_TYPEINFO
:
1009 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
1010 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
1011 case DEMANGLE_COMPONENT_THUNK
:
1012 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
1013 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
1014 case DEMANGLE_COMPONENT_JAVA_CLASS
:
1015 case DEMANGLE_COMPONENT_GUARD
:
1016 case DEMANGLE_COMPONENT_TLS_INIT
:
1017 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
1018 case DEMANGLE_COMPONENT_REFTEMP
:
1019 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
1020 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
1021 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
1022 case DEMANGLE_COMPONENT_POINTER
:
1023 case DEMANGLE_COMPONENT_REFERENCE
:
1024 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
1025 case DEMANGLE_COMPONENT_COMPLEX
:
1026 case DEMANGLE_COMPONENT_IMAGINARY
:
1027 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
1028 case DEMANGLE_COMPONENT_CAST
:
1029 case DEMANGLE_COMPONENT_CONVERSION
:
1030 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
1031 case DEMANGLE_COMPONENT_DECLTYPE
:
1032 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
1033 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
1034 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
1035 case DEMANGLE_COMPONENT_NULLARY
:
1036 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
1037 case DEMANGLE_COMPONENT_TPARM_OBJ
:
1038 case DEMANGLE_COMPONENT_STRUCTURED_BINDING
:
1039 case DEMANGLE_COMPONENT_MODULE_INIT
:
1040 case DEMANGLE_COMPONENT_TEMPLATE_HEAD
:
1041 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
1042 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
1043 case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
:
1044 case DEMANGLE_COMPONENT_FRIEND
:
1049 /* This needs a right parameter, but the left parameter can be
1051 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
1052 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
1053 case DEMANGLE_COMPONENT_MODULE_NAME
:
1054 case DEMANGLE_COMPONENT_MODULE_PARTITION
:
1059 /* These are allowed to have no parameters--in some cases they
1060 will be filled in later. */
1061 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
1062 case DEMANGLE_COMPONENT_RESTRICT
:
1063 case DEMANGLE_COMPONENT_VOLATILE
:
1064 case DEMANGLE_COMPONENT_CONST
:
1065 case DEMANGLE_COMPONENT_ARGLIST
:
1066 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
1067 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
1068 FNQUAL_COMPONENT_CASE
:
1071 /* Other types should not be seen here. */
1076 p
= d_make_empty (di
);
1080 p
->u
.s_binary
.left
= left
;
1081 p
->u
.s_binary
.right
= right
;
1086 /* Add a new demangle mangled name component. */
1088 static struct demangle_component
*
1089 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
1091 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1092 return d_make_name (di
, s
, strlen (s
));
1094 return d_encoding (di
, 0);
1097 /* Add a new name component. */
1099 static struct demangle_component
*
1100 d_make_name (struct d_info
*di
, const char *s
, int len
)
1102 struct demangle_component
*p
;
1104 p
= d_make_empty (di
);
1105 if (! cplus_demangle_fill_name (p
, s
, len
))
1110 /* Add a new builtin type component. */
1112 static struct demangle_component
*
1113 d_make_builtin_type (struct d_info
*di
,
1114 const struct demangle_builtin_type_info
*type
)
1116 struct demangle_component
*p
;
1120 p
= d_make_empty (di
);
1123 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1124 p
->u
.s_builtin
.type
= type
;
1129 /* Add a new extended builtin type component. */
1131 static struct demangle_component
*
1132 d_make_extended_builtin_type (struct d_info
*di
,
1133 const struct demangle_builtin_type_info
*type
,
1134 short arg
, char suffix
)
1136 struct demangle_component
*p
;
1140 p
= d_make_empty (di
);
1143 p
->type
= DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
;
1144 p
->u
.s_extended_builtin
.type
= type
;
1145 p
->u
.s_extended_builtin
.arg
= arg
;
1146 p
->u
.s_extended_builtin
.suffix
= suffix
;
1151 /* Add a new operator component. */
1153 static struct demangle_component
*
1154 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1156 struct demangle_component
*p
;
1158 p
= d_make_empty (di
);
1161 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1162 p
->u
.s_operator
.op
= op
;
1167 /* Add a new extended operator component. */
1169 static struct demangle_component
*
1170 d_make_extended_operator (struct d_info
*di
, int args
,
1171 struct demangle_component
*name
)
1173 struct demangle_component
*p
;
1175 p
= d_make_empty (di
);
1176 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1181 static struct demangle_component
*
1182 d_make_default_arg (struct d_info
*di
, int num
,
1183 struct demangle_component
*sub
)
1185 struct demangle_component
*p
= d_make_empty (di
);
1188 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1189 p
->u
.s_unary_num
.num
= num
;
1190 p
->u
.s_unary_num
.sub
= sub
;
1195 /* Add a new constructor component. */
1197 static struct demangle_component
*
1198 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1199 struct demangle_component
*name
)
1201 struct demangle_component
*p
;
1203 p
= d_make_empty (di
);
1204 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1209 /* Add a new destructor component. */
1211 static struct demangle_component
*
1212 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1213 struct demangle_component
*name
)
1215 struct demangle_component
*p
;
1217 p
= d_make_empty (di
);
1218 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1223 /* Add a new template parameter. */
1225 static struct demangle_component
*
1226 d_make_template_param (struct d_info
*di
, int i
)
1228 struct demangle_component
*p
;
1230 p
= d_make_empty (di
);
1233 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1234 p
->u
.s_number
.number
= i
;
1239 /* Add a new function parameter. */
1241 static struct demangle_component
*
1242 d_make_function_param (struct d_info
*di
, int i
)
1244 struct demangle_component
*p
;
1246 p
= d_make_empty (di
);
1249 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1250 p
->u
.s_number
.number
= i
;
1255 /* Add a new standard substitution component. */
1257 static struct demangle_component
*
1258 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1260 struct demangle_component
*p
;
1262 p
= d_make_empty (di
);
1265 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1266 p
->u
.s_string
.string
= name
;
1267 p
->u
.s_string
.len
= len
;
1272 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1274 TOP_LEVEL is non-zero when called at the top level. */
1276 CP_STATIC_IF_GLIBCPP_V3
1277 struct demangle_component
*
1278 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1280 struct demangle_component
*p
;
1282 if (! d_check_char (di
, '_')
1283 /* Allow missing _ if not at toplevel to work around a
1284 bug in G++ abi-version=2 mangling; see the comment in
1285 write_template_arg. */
1288 if (! d_check_char (di
, 'Z'))
1290 p
= d_encoding (di
, top_level
);
1292 /* If at top level and parsing parameters, check for a clone
1294 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1295 while (d_peek_char (di
) == '.'
1296 && (IS_LOWER (d_peek_next_char (di
))
1297 || d_peek_next_char (di
) == '_'
1298 || IS_DIGIT (d_peek_next_char (di
))))
1299 p
= d_clone_suffix (di
, p
);
1304 /* Return whether a function should have a return type. The argument
1305 is the function name, which may be qualified in various ways. The
1306 rules are that template functions have return types with some
1307 exceptions, function types which are not part of a function name
1308 mangling have return types with some exceptions, and non-template
1309 function names do not have return types. The exceptions are that
1310 constructors, destructors, and conversion operators do not have
1314 has_return_type (struct demangle_component
*dc
)
1322 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1323 return has_return_type (d_right (dc
));
1324 case DEMANGLE_COMPONENT_TEMPLATE
:
1325 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1326 FNQUAL_COMPONENT_CASE
:
1327 return has_return_type (d_left (dc
));
1331 /* Return whether a name is a constructor, a destructor, or a
1332 conversion operator. */
1335 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1343 case DEMANGLE_COMPONENT_QUAL_NAME
:
1344 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1345 return is_ctor_dtor_or_conversion (d_right (dc
));
1346 case DEMANGLE_COMPONENT_CTOR
:
1347 case DEMANGLE_COMPONENT_DTOR
:
1348 case DEMANGLE_COMPONENT_CONVERSION
:
1353 /* [ Q <constraint-expression> ] */
1355 static struct demangle_component
*
1356 d_maybe_constraints (struct d_info
*di
, struct demangle_component
*dc
)
1358 if (d_peek_char (di
) == 'Q')
1361 struct demangle_component
*expr
= d_expression (di
);
1364 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRAINTS
, dc
, expr
);
1369 /* <encoding> ::= <(function) name> <bare-function-type>
1373 TOP_LEVEL is non-zero when called at the top level, in which case
1374 if DMGL_PARAMS is not set we do not demangle the function
1375 parameters. We only set this at the top level, because otherwise
1376 we would not correctly demangle names in local scopes. */
1378 static struct demangle_component
*
1379 d_encoding (struct d_info
*di
, int top_level
)
1381 char peek
= d_peek_char (di
);
1382 struct demangle_component
*dc
;
1384 if (peek
== 'G' || peek
== 'T')
1385 dc
= d_special_name (di
);
1388 dc
= d_name (di
, 0);
1391 /* Failed already. */;
1392 else if (top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1394 /* Strip off any initial CV-qualifiers, as they really apply
1395 to the `this' parameter, and they were not output by the
1396 v2 demangler without DMGL_PARAMS. */
1397 while (is_fnqual_component_type (dc
->type
))
1400 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1401 there may be function-qualifiers on its right argument which
1402 really apply here; this happens when parsing a class
1403 which is local to a function. */
1404 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1406 while (d_right (dc
) != NULL
1407 && is_fnqual_component_type (d_right (dc
)->type
))
1408 d_right (dc
) = d_left (d_right (dc
));
1410 if (d_right (dc
) == NULL
)
1416 peek
= d_peek_char (di
);
1417 if (peek
!= '\0' && peek
!= 'E')
1419 struct demangle_component
*ftype
;
1421 ftype
= d_bare_function_type (di
, has_return_type (dc
));
1425 /* If this is a non-top-level local-name, clear the
1426 return type, so it doesn't confuse the user by
1427 being confused with the return type of whaever
1428 this is nested within. */
1429 if (!top_level
&& dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
1430 && ftype
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
1431 d_left (ftype
) = NULL
;
1433 ftype
= d_maybe_constraints (di
, ftype
);
1435 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
,
1444 /* <tagged-name> ::= <name> B <source-name> */
1446 static struct demangle_component
*
1447 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1449 struct demangle_component
*hold_last_name
;
1452 /* Preserve the last name, so the ABI tag doesn't clobber it. */
1453 hold_last_name
= di
->last_name
;
1455 while (peek
= d_peek_char (di
),
1458 struct demangle_component
*tag
;
1460 tag
= d_source_name (di
);
1461 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1464 di
->last_name
= hold_last_name
;
1469 /* <name> ::= <nested-name>
1471 ::= <unscoped-template-name> <template-args>
1474 <unscoped-name> ::= <unqualified-name>
1475 ::= St <unqualified-name>
1477 <unscoped-template-name> ::= <unscoped-name>
1481 static struct demangle_component
*
1482 d_name (struct d_info
*di
, int substable
)
1484 char peek
= d_peek_char (di
);
1485 struct demangle_component
*dc
= NULL
;
1486 struct demangle_component
*module
= NULL
;
1492 dc
= d_nested_name (di
);
1496 dc
= d_local_name (di
);
1500 dc
= d_unqualified_name (di
, NULL
, NULL
);
1505 if (d_peek_next_char (di
) == 't')
1508 dc
= d_make_name (di
, "std", 3);
1512 if (d_peek_char (di
) == 'S')
1514 module
= d_substitution (di
, 0);
1517 if (!(module
->type
== DEMANGLE_COMPONENT_MODULE_NAME
1518 || module
->type
== DEMANGLE_COMPONENT_MODULE_PARTITION
))
1533 dc
= d_unqualified_name (di
, dc
, module
);
1534 if (d_peek_char (di
) == 'I')
1536 /* This is <template-args>, which means that we just saw
1537 <unscoped-template-name>, which is a substitution
1539 if (!subst
&& !d_add_substitution (di
, dc
))
1541 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1542 d_template_args (di
));
1547 if (substable
&& !subst
&& !d_add_substitution (di
, dc
))
1552 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1553 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1554 ::= N H <prefix> <unqualified-name> E
1555 ::= N H <template-prefix> <template-args> E
1558 static struct demangle_component
*
1559 d_nested_name (struct d_info
*di
)
1561 struct demangle_component
*ret
;
1562 struct demangle_component
**pret
;
1563 struct demangle_component
*rqual
;
1565 if (! d_check_char (di
, 'N'))
1568 if (d_peek_char (di
) == 'H')
1571 di
->expansion
+= sizeof "this";
1573 rqual
= d_make_comp (di
, DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
,
1578 pret
= d_cv_qualifiers (di
, &ret
, 1);
1582 /* Parse the ref-qualifier now and then attach it
1583 once we have something to attach it to. */
1584 rqual
= d_ref_qualifier (di
, NULL
);
1587 *pret
= d_prefix (di
, 1);
1593 d_left (rqual
) = ret
;
1597 if (! d_check_char (di
, 'E'))
1603 /* <prefix> ::= <prefix> <unqualified-name>
1604 ::= <template-prefix> <template-args>
1605 ::= <template-param>
1610 <template-prefix> ::= <prefix> <(template) unqualified-name>
1611 ::= <template-param>
1614 SUBST is true if we should add substitutions (as normal), false
1615 if not (in an unresolved-name). */
1617 static struct demangle_component
*
1618 d_prefix (struct d_info
*di
, int substable
)
1620 struct demangle_component
*ret
= NULL
;
1624 char peek
= d_peek_char (di
);
1626 /* The older code accepts a <local-name> here, but I don't see
1627 that in the grammar. The older code does not accept a
1628 <template-param> here. */
1631 && (d_peek_next_char (di
) == 'T'
1632 || d_peek_next_char (di
) == 't'))
1637 ret
= cplus_demangle_type (di
);
1639 else if (peek
== 'I')
1643 struct demangle_component
*dc
= d_template_args (di
);
1646 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
, dc
);
1648 else if (peek
== 'T')
1652 ret
= d_template_param (di
);
1654 else if (peek
== 'M')
1656 /* Initializer scope for a lambda. We already added it as a
1657 substitution candidate, don't do that again. */
1663 struct demangle_component
*module
= NULL
;
1666 module
= d_substitution (di
, 1);
1669 if (!(module
->type
== DEMANGLE_COMPONENT_MODULE_NAME
1670 || module
->type
== DEMANGLE_COMPONENT_MODULE_PARTITION
))
1678 ret
= d_unqualified_name (di
, ret
, module
);
1684 if (d_peek_char (di
) == 'E')
1687 if (substable
&& !d_add_substitution (di
, ret
))
1695 d_maybe_module_name (struct d_info
*di
, struct demangle_component
**name
)
1697 while (d_peek_char (di
) == 'W')
1700 enum demangle_component_type code
= DEMANGLE_COMPONENT_MODULE_NAME
;
1701 if (d_peek_char (di
) == 'P')
1703 code
= DEMANGLE_COMPONENT_MODULE_PARTITION
;
1707 *name
= d_make_comp (di
, code
, *name
, d_source_name (di
));
1710 if (!d_add_substitution (di
, *name
))
1716 /* <unqualified-name> ::= [<module-name>] <operator-name> [<abi-tags>]
1717 ::= [<module-name>] <ctor-dtor-name> [<abi-tags>]
1718 ::= [<module-name>] <source-name> [<abi-tags>]
1719 ::= [<module-name>] F <source-name> [<abi-tags>]
1720 ::= [<module-name>] <local-source-name> [<abi-tags>]
1721 ::= [<module-name>] DC <source-name>+ E [<abi-tags>]
1722 <local-source-name> ::= L <source-name> <discriminator> [<abi-tags>]
1725 static struct demangle_component
*
1726 d_unqualified_name (struct d_info
*di
, struct demangle_component
*scope
,
1727 struct demangle_component
*module
)
1729 struct demangle_component
*ret
;
1731 int member_like_friend
= 0;
1733 if (!d_maybe_module_name (di
, &module
))
1736 peek
= d_peek_char (di
);
1739 member_like_friend
= 1;
1741 peek
= d_peek_char (di
);
1743 if (IS_DIGIT (peek
))
1744 ret
= d_source_name (di
);
1745 else if (IS_LOWER (peek
))
1747 int was_expr
= di
->is_expression
;
1748 if (peek
== 'o' && d_peek_next_char (di
) == 'n')
1751 /* Treat cv as naming a conversion operator. */
1752 di
->is_expression
= 0;
1754 ret
= d_operator_name (di
);
1755 di
->is_expression
= was_expr
;
1756 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1758 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1759 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1760 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1761 d_source_name (di
));
1764 else if (peek
== 'D' && d_peek_next_char (di
) == 'C')
1766 // structured binding
1768 struct demangle_component
*prev
= NULL
;
1771 struct demangle_component
*next
=
1772 d_make_comp (di
, DEMANGLE_COMPONENT_STRUCTURED_BINDING
,
1773 d_source_name (di
), NULL
);
1775 d_right (prev
) = next
;
1780 while (prev
&& d_peek_char (di
) != 'E');
1786 else if (peek
== 'C' || peek
== 'D')
1787 ret
= d_ctor_dtor_name (di
);
1788 else if (peek
== 'L')
1792 ret
= d_source_name (di
);
1795 if (! d_discriminator (di
))
1798 else if (peek
== 'U')
1800 switch (d_peek_next_char (di
))
1803 ret
= d_lambda (di
);
1806 ret
= d_unnamed_type (di
);
1816 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_MODULE_ENTITY
, ret
, module
);
1817 if (d_peek_char (di
) == 'B')
1818 ret
= d_abi_tags (di
, ret
);
1819 if (member_like_friend
)
1820 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_FRIEND
, ret
, NULL
);
1822 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, scope
, ret
);
1827 /* <source-name> ::= <(positive length) number> <identifier> */
1829 static struct demangle_component
*
1830 d_source_name (struct d_info
*di
)
1833 struct demangle_component
*ret
;
1835 len
= d_number (di
);
1838 ret
= d_identifier (di
, len
);
1839 di
->last_name
= ret
;
1843 /* number ::= [n] <(non-negative decimal integer)> */
1846 d_number (struct d_info
*di
)
1853 peek
= d_peek_char (di
);
1858 peek
= d_peek_char (di
);
1864 if (! IS_DIGIT (peek
))
1870 if (ret
> ((INT_MAX
- (peek
- '0')) / 10))
1872 ret
= ret
* 10 + (peek
- '0');
1874 peek
= d_peek_char (di
);
1878 /* Like d_number, but returns a demangle_component. */
1880 static struct demangle_component
*
1881 d_number_component (struct d_info
*di
)
1883 struct demangle_component
*ret
= d_make_empty (di
);
1886 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1887 ret
->u
.s_number
.number
= d_number (di
);
1892 /* identifier ::= <(unqualified source code identifier)> */
1894 static struct demangle_component
*
1895 d_identifier (struct d_info
*di
, int len
)
1901 if (di
->send
- name
< len
)
1904 d_advance (di
, len
);
1906 /* A Java mangled name may have a trailing '$' if it is a C++
1907 keyword. This '$' is not included in the length count. We just
1909 if ((di
->options
& DMGL_JAVA
) != 0
1910 && d_peek_char (di
) == '$')
1913 /* Look for something which looks like a gcc encoding of an
1914 anonymous namespace, and replace it with a more user friendly
1916 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1917 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1918 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1922 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1923 if ((*s
== '.' || *s
== '_' || *s
== '$')
1926 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1927 return d_make_name (di
, "(anonymous namespace)",
1928 sizeof "(anonymous namespace)" - 1);
1932 return d_make_name (di
, name
, len
);
1935 /* operator_name ::= many different two character encodings.
1937 ::= v <digit> <source-name>
1939 This list is sorted for binary search. */
1941 #define NL(s) s, (sizeof s) - 1
1943 CP_STATIC_IF_GLIBCPP_V3
1944 const struct demangle_operator_info cplus_demangle_operators
[] =
1946 { "aN", NL ("&="), 2 },
1947 { "aS", NL ("="), 2 },
1948 { "aa", NL ("&&"), 2 },
1949 { "ad", NL ("&"), 1 },
1950 { "an", NL ("&"), 2 },
1951 { "at", NL ("alignof "), 1 },
1952 { "aw", NL ("co_await "), 1 },
1953 { "az", NL ("alignof "), 1 },
1954 { "cc", NL ("const_cast"), 2 },
1955 { "cl", NL ("()"), 2 },
1956 { "cm", NL (","), 2 },
1957 { "co", NL ("~"), 1 },
1958 { "dV", NL ("/="), 2 },
1959 { "dX", NL ("[...]="), 3 }, /* [expr...expr] = expr */
1960 { "da", NL ("delete[] "), 1 },
1961 { "dc", NL ("dynamic_cast"), 2 },
1962 { "de", NL ("*"), 1 },
1963 { "di", NL ("="), 2 }, /* .name = expr */
1964 { "dl", NL ("delete "), 1 },
1965 { "ds", NL (".*"), 2 },
1966 { "dt", NL ("."), 2 },
1967 { "dv", NL ("/"), 2 },
1968 { "dx", NL ("]="), 2 }, /* [expr] = expr */
1969 { "eO", NL ("^="), 2 },
1970 { "eo", NL ("^"), 2 },
1971 { "eq", NL ("=="), 2 },
1972 { "fL", NL ("..."), 3 },
1973 { "fR", NL ("..."), 3 },
1974 { "fl", NL ("..."), 2 },
1975 { "fr", NL ("..."), 2 },
1976 { "ge", NL (">="), 2 },
1977 { "gs", NL ("::"), 1 },
1978 { "gt", NL (">"), 2 },
1979 { "ix", NL ("[]"), 2 },
1980 { "lS", NL ("<<="), 2 },
1981 { "le", NL ("<="), 2 },
1982 { "li", NL ("operator\"\" "), 1 },
1983 { "ls", NL ("<<"), 2 },
1984 { "lt", NL ("<"), 2 },
1985 { "mI", NL ("-="), 2 },
1986 { "mL", NL ("*="), 2 },
1987 { "mi", NL ("-"), 2 },
1988 { "ml", NL ("*"), 2 },
1989 { "mm", NL ("--"), 1 },
1990 { "na", NL ("new[]"), 3 },
1991 { "ne", NL ("!="), 2 },
1992 { "ng", NL ("-"), 1 },
1993 { "nt", NL ("!"), 1 },
1994 { "nw", NL ("new"), 3 },
1995 { "nx", NL ("noexcept"), 1 },
1996 { "oR", NL ("|="), 2 },
1997 { "oo", NL ("||"), 2 },
1998 { "or", NL ("|"), 2 },
1999 { "pL", NL ("+="), 2 },
2000 { "pl", NL ("+"), 2 },
2001 { "pm", NL ("->*"), 2 },
2002 { "pp", NL ("++"), 1 },
2003 { "ps", NL ("+"), 1 },
2004 { "pt", NL ("->"), 2 },
2005 { "qu", NL ("?"), 3 },
2006 { "rM", NL ("%="), 2 },
2007 { "rS", NL (">>="), 2 },
2008 { "rc", NL ("reinterpret_cast"), 2 },
2009 { "rm", NL ("%"), 2 },
2010 { "rs", NL (">>"), 2 },
2011 { "sP", NL ("sizeof..."), 1 },
2012 { "sZ", NL ("sizeof..."), 1 },
2013 { "sc", NL ("static_cast"), 2 },
2014 { "ss", NL ("<=>"), 2 },
2015 { "st", NL ("sizeof "), 1 },
2016 { "sz", NL ("sizeof "), 1 },
2017 { "tr", NL ("throw"), 0 },
2018 { "tw", NL ("throw "), 1 },
2019 { NULL
, NULL
, 0, 0 }
2022 static struct demangle_component
*
2023 d_operator_name (struct d_info
*di
)
2028 c1
= d_next_char (di
);
2029 c2
= d_next_char (di
);
2030 if (c1
== 'v' && IS_DIGIT (c2
))
2031 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
2032 else if (c1
== 'c' && c2
== 'v')
2034 struct demangle_component
*type
;
2035 int was_conversion
= di
->is_conversion
;
2036 struct demangle_component
*res
;
2038 di
->is_conversion
= ! di
->is_expression
;
2039 type
= cplus_demangle_type (di
);
2040 if (di
->is_conversion
)
2041 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
2043 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
2044 di
->is_conversion
= was_conversion
;
2049 /* LOW is the inclusive lower bound. */
2051 /* HIGH is the exclusive upper bound. We subtract one to ignore
2052 the sentinel at the end of the array. */
2053 int high
= ((sizeof (cplus_demangle_operators
)
2054 / sizeof (cplus_demangle_operators
[0]))
2060 const struct demangle_operator_info
*p
;
2062 i
= low
+ (high
- low
) / 2;
2063 p
= cplus_demangle_operators
+ i
;
2065 if (c1
== p
->code
[0] && c2
== p
->code
[1])
2066 return d_make_operator (di
, p
);
2068 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
2078 static struct demangle_component
*
2079 d_make_character (struct d_info
*di
, int c
)
2081 struct demangle_component
*p
;
2082 p
= d_make_empty (di
);
2085 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
2086 p
->u
.s_character
.character
= c
;
2091 static struct demangle_component
*
2092 d_java_resource (struct d_info
*di
)
2094 struct demangle_component
*p
= NULL
;
2095 struct demangle_component
*next
= NULL
;
2100 len
= d_number (di
);
2104 /* Eat the leading '_'. */
2105 if (d_next_char (di
) != '_')
2118 /* Each chunk is either a '$' escape... */
2136 next
= d_make_character (di
, c
);
2144 /* ... or a sequence of characters. */
2147 while (i
< len
&& str
[i
] && str
[i
] != '$')
2150 next
= d_make_name (di
, str
, i
);
2163 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
2169 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
2174 /* <special-name> ::= TV <type>
2178 ::= TA <template-arg>
2179 ::= GV <(object) name>
2180 ::= T <call-offset> <(base) encoding>
2181 ::= Tc <call-offset> <call-offset> <(base) encoding>
2182 Also g++ extensions:
2183 ::= TC <type> <(offset) number> _ <(base) type>
2188 ::= Gr <resource name>
2193 static struct demangle_component
*
2194 d_special_name (struct d_info
*di
)
2196 di
->expansion
+= 20;
2197 if (d_check_char (di
, 'T'))
2199 switch (d_next_char (di
))
2203 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
2204 cplus_demangle_type (di
), NULL
);
2206 di
->expansion
-= 10;
2207 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
2208 cplus_demangle_type (di
), NULL
);
2210 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
2211 cplus_demangle_type (di
), NULL
);
2213 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
2214 cplus_demangle_type (di
), NULL
);
2217 if (! d_call_offset (di
, 'h'))
2219 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
2220 d_encoding (di
, 0), NULL
);
2223 if (! d_call_offset (di
, 'v'))
2225 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
2226 d_encoding (di
, 0), NULL
);
2229 if (! d_call_offset (di
, '\0'))
2231 if (! d_call_offset (di
, '\0'))
2233 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
2234 d_encoding (di
, 0), NULL
);
2238 struct demangle_component
*derived_type
;
2240 struct demangle_component
*base_type
;
2242 derived_type
= cplus_demangle_type (di
);
2243 offset
= d_number (di
);
2246 if (! d_check_char (di
, '_'))
2248 base_type
= cplus_demangle_type (di
);
2249 /* We don't display the offset. FIXME: We should display
2250 it in verbose mode. */
2252 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2253 base_type
, derived_type
);
2257 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2258 cplus_demangle_type (di
), NULL
);
2260 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2261 cplus_demangle_type (di
), NULL
);
2264 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2265 d_name (di
, 0), NULL
);
2268 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2269 d_name (di
, 0), NULL
);
2272 return d_make_comp (di
, DEMANGLE_COMPONENT_TPARM_OBJ
,
2273 d_template_arg (di
), NULL
);
2279 else if (d_check_char (di
, 'G'))
2281 switch (d_next_char (di
))
2284 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
,
2285 d_name (di
, 0), NULL
);
2289 struct demangle_component
*name
= d_name (di
, 0);
2290 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2291 d_number_component (di
));
2295 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2296 d_encoding (di
, 0), NULL
);
2300 struct demangle_component
*module
= NULL
;
2301 if (!d_maybe_module_name (di
, &module
) || !module
)
2303 return d_make_comp (di
, DEMANGLE_COMPONENT_MODULE_INIT
,
2307 switch (d_next_char (di
))
2310 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2311 d_encoding (di
, 0), NULL
);
2313 /* ??? The proposal is that other letters (such as 'h') stand
2314 for different variants of transaction cloning, such as
2315 compiling directly for hardware transaction support. But
2316 they still should all be transactional clones of some sort
2317 so go ahead and call them that. */
2319 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2320 d_encoding (di
, 0), NULL
);
2324 return d_java_resource (di
);
2334 /* <call-offset> ::= h <nv-offset> _
2337 <nv-offset> ::= <(offset) number>
2339 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2341 The C parameter, if not '\0', is a character we just read which is
2342 the start of the <call-offset>.
2344 We don't display the offset information anywhere. FIXME: We should
2345 display it in verbose mode. */
2348 d_call_offset (struct d_info
*di
, int c
)
2351 c
= d_next_char (di
);
2358 if (! d_check_char (di
, '_'))
2365 if (! d_check_char (di
, '_'))
2371 /* <ctor-dtor-name> ::= C1
2379 static struct demangle_component
*
2380 d_ctor_dtor_name (struct d_info
*di
)
2382 if (di
->last_name
!= NULL
)
2384 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2385 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2386 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2387 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2389 switch (d_peek_char (di
))
2393 enum gnu_v3_ctor_kinds kind
;
2396 if (d_peek_next_char (di
) == 'I')
2402 switch (d_peek_next_char (di
))
2405 kind
= gnu_v3_complete_object_ctor
;
2408 kind
= gnu_v3_base_object_ctor
;
2411 kind
= gnu_v3_complete_object_allocating_ctor
;
2414 kind
= gnu_v3_unified_ctor
;
2417 kind
= gnu_v3_object_ctor_group
;
2426 cplus_demangle_type (di
);
2428 return d_make_ctor (di
, kind
, di
->last_name
);
2433 enum gnu_v3_dtor_kinds kind
;
2435 switch (d_peek_next_char (di
))
2438 kind
= gnu_v3_deleting_dtor
;
2441 kind
= gnu_v3_complete_object_dtor
;
2444 kind
= gnu_v3_base_object_dtor
;
2446 /* digit '3' is not used */
2448 kind
= gnu_v3_unified_dtor
;
2451 kind
= gnu_v3_object_dtor_group
;
2457 return d_make_dtor (di
, kind
, di
->last_name
);
2465 /* True iff we're looking at an order-insensitive type-qualifier, including
2466 function-type-qualifiers. */
2469 next_is_type_qual (struct d_info
*di
)
2471 char peek
= d_peek_char (di
);
2472 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2476 peek
= d_peek_next_char (di
);
2477 if (peek
== 'x' || peek
== 'o' || peek
== 'O' || peek
== 'w')
2483 /* <type> ::= <builtin-type>
2485 ::= <class-enum-type>
2487 ::= <pointer-to-member-type>
2488 ::= <template-param>
2489 ::= <template-template-param> <template-args>
2491 ::= <CV-qualifiers> <type>
2494 ::= O <type> (C++0x)
2497 ::= U <source-name> <type>
2499 <builtin-type> ::= various one letter codes
2503 CP_STATIC_IF_GLIBCPP_V3
2504 const struct demangle_builtin_type_info
2505 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2507 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2508 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2509 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2510 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2511 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2512 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2513 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2514 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2515 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2516 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2517 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2518 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2519 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2520 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2521 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2523 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2524 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2525 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2526 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2527 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2528 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2529 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2530 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2531 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2532 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2533 D_PRINT_UNSIGNED_LONG_LONG
},
2534 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2535 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2536 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2537 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2538 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2539 /* 30 */ { NL ("char8_t"), NL ("char8_t"), D_PRINT_DEFAULT
},
2540 /* 31 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2541 /* 32 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2542 /* 33 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2544 /* 34 */ { NL ("_Float"), NL ("_Float"), D_PRINT_FLOAT
},
2545 /* 35 */ { NL ("std::bfloat16_t"), NL ("std::bfloat16_t"), D_PRINT_FLOAT
},
2548 CP_STATIC_IF_GLIBCPP_V3
2549 struct demangle_component
*
2550 cplus_demangle_type (struct d_info
*di
)
2553 struct demangle_component
*ret
;
2556 /* The ABI specifies that when CV-qualifiers are used, the base type
2557 is substitutable, and the fully qualified type is substitutable,
2558 but the base type with a strict subset of the CV-qualifiers is
2559 not substitutable. The natural recursive implementation of the
2560 CV-qualifiers would cause subsets to be substitutable, so instead
2561 we pull them all off now.
2563 FIXME: The ABI says that order-insensitive vendor qualifiers
2564 should be handled in the same way, but we have no way to tell
2565 which vendor qualifiers are order-insensitive and which are
2566 order-sensitive. So we just assume that they are all
2567 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2568 __vector, and it treats it as order-sensitive when mangling
2571 if (next_is_type_qual (di
))
2573 struct demangle_component
**pret
;
2575 pret
= d_cv_qualifiers (di
, &ret
, 0);
2578 if (d_peek_char (di
) == 'F')
2580 /* cv-qualifiers before a function type apply to 'this',
2581 so avoid adding the unqualified function type to
2582 the substitution list. */
2583 *pret
= d_function_type (di
);
2586 *pret
= cplus_demangle_type (di
);
2589 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2590 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2592 /* Move the ref-qualifier outside the cv-qualifiers so that
2593 they are printed in the right order. */
2594 struct demangle_component
*fn
= d_left (*pret
);
2595 d_left (*pret
) = ret
;
2599 if (! d_add_substitution (di
, ret
))
2606 peek
= d_peek_char (di
);
2609 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2610 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2611 case 'o': case 's': case 't':
2612 case 'v': case 'w': case 'x': case 'y': case 'z':
2613 ret
= d_make_builtin_type (di
,
2614 &cplus_demangle_builtin_types
[peek
- 'a']);
2615 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2622 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2623 d_source_name (di
), NULL
);
2627 ret
= d_function_type (di
);
2631 ret
= d_array_type (di
);
2635 ret
= d_pointer_to_member_type (di
);
2639 ret
= d_template_param (di
);
2640 if (d_peek_char (di
) == 'I')
2642 /* This may be <template-template-param> <template-args>.
2643 If this is the type for a conversion operator, we can
2644 have a <template-template-param> here only by following
2645 a derivation like this:
2648 -> <template-prefix> <template-args>
2649 -> <prefix> <template-unqualified-name> <template-args>
2650 -> <unqualified-name> <template-unqualified-name> <template-args>
2651 -> <source-name> <template-unqualified-name> <template-args>
2652 -> <source-name> <operator-name> <template-args>
2653 -> <source-name> cv <type> <template-args>
2654 -> <source-name> cv <template-template-param> <template-args> <template-args>
2656 where the <template-args> is followed by another.
2657 Otherwise, we must have a derivation like this:
2660 -> <template-prefix> <template-args>
2661 -> <prefix> <template-unqualified-name> <template-args>
2662 -> <unqualified-name> <template-unqualified-name> <template-args>
2663 -> <source-name> <template-unqualified-name> <template-args>
2664 -> <source-name> <operator-name> <template-args>
2665 -> <source-name> cv <type> <template-args>
2666 -> <source-name> cv <template-param> <template-args>
2668 where we need to leave the <template-args> to be processed
2669 by d_prefix (following the <template-prefix>).
2671 The <template-template-param> part is a substitution
2673 if (! di
->is_conversion
)
2675 if (! d_add_substitution (di
, ret
))
2677 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2678 d_template_args (di
));
2682 struct demangle_component
*args
;
2683 struct d_info_checkpoint checkpoint
;
2685 d_checkpoint (di
, &checkpoint
);
2686 args
= d_template_args (di
);
2687 if (d_peek_char (di
) == 'I')
2689 if (! d_add_substitution (di
, ret
))
2691 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2695 d_backtrack (di
, &checkpoint
);
2702 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2703 cplus_demangle_type (di
), NULL
);
2708 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2709 cplus_demangle_type (di
), NULL
);
2714 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2715 cplus_demangle_type (di
), NULL
);
2720 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2721 cplus_demangle_type (di
), NULL
);
2726 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2727 cplus_demangle_type (di
), NULL
);
2732 ret
= d_source_name (di
);
2733 if (d_peek_char (di
) == 'I')
2734 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2735 d_template_args (di
));
2736 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2737 cplus_demangle_type (di
), ret
);
2743 peek
= d_next_char (di
);
2748 /* decltype (expression) */
2749 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2750 d_expression (di
), NULL
);
2751 if (ret
&& d_next_char (di
) != 'E')
2757 /* Pack expansion. */
2758 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2759 cplus_demangle_type (di
), NULL
);
2765 ret
= d_make_name (di
, "auto", 4);
2768 /* decltype(auto) */
2769 ret
= d_make_name (di
, "decltype(auto)", 14);
2773 /* 32-bit decimal floating point */
2774 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2775 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2779 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2780 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2784 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2785 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2788 /* 16-bit half-precision FP */
2789 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2790 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2794 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2795 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2799 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2800 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2804 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2805 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2809 /* DF<number>_ - _Float<number>.
2810 DF<number>x - _Float<number>x
2811 DF16b - std::bfloat16_t. */
2813 int arg
= d_number (di
);
2816 if (d_peek_char (di
) == 'b')
2821 ret
= d_make_builtin_type (di
,
2822 &cplus_demangle_builtin_types
[35]);
2823 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2826 if (d_peek_char (di
) == 'x')
2828 if (!suffix
&& d_peek_char (di
) != '_')
2831 = d_make_extended_builtin_type (di
,
2832 &cplus_demangle_builtin_types
[34],
2835 sprintf (buf
, "%d", arg
);
2836 di
->expansion
+= ret
->u
.s_extended_builtin
.type
->len
2837 + strlen (buf
) + (suffix
!= 0);
2842 ret
= d_vector_type (di
);
2847 /* decltype(nullptr) */
2848 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[33]);
2849 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2858 return d_class_enum_type (di
, 1);
2863 if (! d_add_substitution (di
, ret
))
2870 /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */
2872 static struct demangle_component
**
2873 d_cv_qualifiers (struct d_info
*di
,
2874 struct demangle_component
**pret
, int member_fn
)
2876 struct demangle_component
**pstart
;
2880 peek
= d_peek_char (di
);
2881 while (next_is_type_qual (di
))
2883 enum demangle_component_type t
;
2884 struct demangle_component
*right
= NULL
;
2890 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2891 : DEMANGLE_COMPONENT_RESTRICT
);
2892 di
->expansion
+= sizeof "restrict";
2894 else if (peek
== 'V')
2897 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2898 : DEMANGLE_COMPONENT_VOLATILE
);
2899 di
->expansion
+= sizeof "volatile";
2901 else if (peek
== 'K')
2904 ? DEMANGLE_COMPONENT_CONST_THIS
2905 : DEMANGLE_COMPONENT_CONST
);
2906 di
->expansion
+= sizeof "const";
2910 peek
= d_next_char (di
);
2913 t
= DEMANGLE_COMPONENT_TRANSACTION_SAFE
;
2914 di
->expansion
+= sizeof "transaction_safe";
2916 else if (peek
== 'o'
2919 t
= DEMANGLE_COMPONENT_NOEXCEPT
;
2920 di
->expansion
+= sizeof "noexcept";
2923 right
= d_expression (di
);
2926 if (! d_check_char (di
, 'E'))
2930 else if (peek
== 'w')
2932 t
= DEMANGLE_COMPONENT_THROW_SPEC
;
2933 di
->expansion
+= sizeof "throw";
2934 right
= d_parmlist (di
);
2937 if (! d_check_char (di
, 'E'))
2944 *pret
= d_make_comp (di
, t
, NULL
, right
);
2947 pret
= &d_left (*pret
);
2949 peek
= d_peek_char (di
);
2952 if (!member_fn
&& peek
== 'F')
2954 while (pstart
!= pret
)
2956 switch ((*pstart
)->type
)
2958 case DEMANGLE_COMPONENT_RESTRICT
:
2959 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2961 case DEMANGLE_COMPONENT_VOLATILE
:
2962 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2964 case DEMANGLE_COMPONENT_CONST
:
2965 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2970 pstart
= &d_left (*pstart
);
2977 /* <ref-qualifier> ::= R
2980 static struct demangle_component
*
2981 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2983 struct demangle_component
*ret
= sub
;
2986 peek
= d_peek_char (di
);
2987 if (peek
== 'R' || peek
== 'O')
2989 enum demangle_component_type t
;
2992 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2993 di
->expansion
+= sizeof "&";
2997 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2998 di
->expansion
+= sizeof "&&";
3002 ret
= d_make_comp (di
, t
, ret
, NULL
);
3008 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */
3010 static struct demangle_component
*
3011 d_function_type (struct d_info
*di
)
3013 struct demangle_component
*ret
= NULL
;
3015 if ((di
->options
& DMGL_NO_RECURSE_LIMIT
) == 0)
3017 if (di
->recursion_level
> DEMANGLE_RECURSION_LIMIT
)
3018 /* FIXME: There ought to be a way to report
3019 that the recursion limit has been reached. */
3022 di
->recursion_level
++;
3025 if (d_check_char (di
, 'F'))
3027 if (d_peek_char (di
) == 'Y')
3029 /* Function has C linkage. We don't print this information.
3030 FIXME: We should print it in verbose mode. */
3033 ret
= d_bare_function_type (di
, 1);
3034 ret
= d_ref_qualifier (di
, ret
);
3036 if (! d_check_char (di
, 'E'))
3040 if ((di
->options
& DMGL_NO_RECURSE_LIMIT
) == 0)
3041 di
->recursion_level
--;
3047 static struct demangle_component
*
3048 d_parmlist (struct d_info
*di
)
3050 struct demangle_component
*tl
;
3051 struct demangle_component
**ptl
;
3057 struct demangle_component
*type
;
3059 char peek
= d_peek_char (di
);
3060 if (peek
== '\0' || peek
== 'E' || peek
== '.' || peek
== 'Q')
3062 if ((peek
== 'R' || peek
== 'O')
3063 && d_peek_next_char (di
) == 'E')
3064 /* Function ref-qualifier, not a ref prefix for a parameter type. */
3066 type
= cplus_demangle_type (di
);
3069 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
3072 ptl
= &d_right (*ptl
);
3075 /* There should be at least one parameter type besides the optional
3076 return type. A function which takes no arguments will have a
3077 single parameter type void. */
3081 /* If we have a single parameter type void, omit it. */
3082 if (d_right (tl
) == NULL
3083 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3084 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
3086 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
3093 /* <bare-function-type> ::= [J]<type>+ */
3095 static struct demangle_component
*
3096 d_bare_function_type (struct d_info
*di
, int has_return_type
)
3098 struct demangle_component
*return_type
;
3099 struct demangle_component
*tl
;
3102 /* Detect special qualifier indicating that the first argument
3103 is the return type. */
3104 peek
= d_peek_char (di
);
3108 has_return_type
= 1;
3111 if (has_return_type
)
3113 return_type
= cplus_demangle_type (di
);
3114 if (return_type
== NULL
)
3120 tl
= d_parmlist (di
);
3124 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
3128 /* <class-enum-type> ::= <name> */
3130 static struct demangle_component
*
3131 d_class_enum_type (struct d_info
*di
, int substable
)
3133 return d_name (di
, substable
);
3136 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
3137 ::= A [<(dimension) expression>] _ <(element) type>
3140 static struct demangle_component
*
3141 d_array_type (struct d_info
*di
)
3144 struct demangle_component
*dim
;
3146 if (! d_check_char (di
, 'A'))
3149 peek
= d_peek_char (di
);
3152 else if (IS_DIGIT (peek
))
3160 peek
= d_peek_char (di
);
3162 while (IS_DIGIT (peek
));
3163 dim
= d_make_name (di
, s
, d_str (di
) - s
);
3169 dim
= d_expression (di
);
3174 if (! d_check_char (di
, '_'))
3177 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
3178 cplus_demangle_type (di
));
3181 /* <vector-type> ::= Dv <number> _ <type>
3182 ::= Dv _ <expression> _ <type> */
3184 static struct demangle_component
*
3185 d_vector_type (struct d_info
*di
)
3188 struct demangle_component
*dim
;
3190 peek
= d_peek_char (di
);
3194 dim
= d_expression (di
);
3197 dim
= d_number_component (di
);
3202 if (! d_check_char (di
, '_'))
3205 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
3206 cplus_demangle_type (di
));
3209 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
3211 static struct demangle_component
*
3212 d_pointer_to_member_type (struct d_info
*di
)
3214 struct demangle_component
*cl
;
3215 struct demangle_component
*mem
;
3217 if (! d_check_char (di
, 'M'))
3220 cl
= cplus_demangle_type (di
);
3224 /* The ABI says, "The type of a non-static member function is considered
3225 to be different, for the purposes of substitution, from the type of a
3226 namespace-scope or static member function whose type appears
3227 similar. The types of two non-static member functions are considered
3228 to be different, for the purposes of substitution, if the functions
3229 are members of different classes. In other words, for the purposes of
3230 substitution, the class of which the function is a member is
3231 considered part of the type of function."
3233 For a pointer to member function, this call to cplus_demangle_type
3234 will end up adding a (possibly qualified) non-member function type to
3235 the substitution table, which is not correct; however, the member
3236 function type will never be used in a substitution, so putting the
3237 wrong type in the substitution table is harmless. */
3239 mem
= cplus_demangle_type (di
);
3243 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
3246 /* <non-negative number> _ */
3249 d_compact_number (struct d_info
*di
)
3252 if (d_peek_char (di
) == '_')
3254 else if (d_peek_char (di
) == 'n')
3257 num
= d_number (di
) + 1;
3259 if (num
< 0 || ! d_check_char (di
, '_'))
3264 /* <template-param> ::= T_
3265 ::= T <(parameter-2 non-negative) number> _
3268 static struct demangle_component
*
3269 d_template_param (struct d_info
*di
)
3273 if (! d_check_char (di
, 'T'))
3276 param
= d_compact_number (di
);
3280 return d_make_template_param (di
, param
);
3283 /* <template-args> ::= I <template-arg>+ E */
3285 static struct demangle_component
*
3286 d_template_args (struct d_info
*di
)
3288 if (d_peek_char (di
) != 'I'
3289 && d_peek_char (di
) != 'J')
3293 return d_template_args_1 (di
);
3296 /* <template-arg>* [Q <constraint-expression>] E */
3298 static struct demangle_component
*
3299 d_template_args_1 (struct d_info
*di
)
3301 struct demangle_component
*hold_last_name
;
3302 struct demangle_component
*al
;
3303 struct demangle_component
**pal
;
3305 /* Preserve the last name we saw--don't let the template arguments
3306 clobber it, as that would give us the wrong name for a subsequent
3307 constructor or destructor. */
3308 hold_last_name
= di
->last_name
;
3310 if (d_peek_char (di
) == 'E')
3312 /* An argument pack can be empty. */
3314 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
3321 struct demangle_component
*a
;
3323 a
= d_template_arg (di
);
3327 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
3330 pal
= &d_right (*pal
);
3332 char peek
= d_peek_char (di
);
3333 if (peek
== 'E' || peek
== 'Q')
3337 al
= d_maybe_constraints (di
, al
);
3339 if (d_peek_char (di
) != 'E')
3343 di
->last_name
= hold_last_name
;
3348 /* <template-arg> ::= <type>
3349 ::= X <expression> E
3353 static struct demangle_component
*
3354 d_template_arg (struct d_info
*di
)
3356 struct demangle_component
*ret
;
3358 switch (d_peek_char (di
))
3362 ret
= d_expression (di
);
3363 if (! d_check_char (di
, 'E'))
3368 return d_expr_primary (di
);
3372 /* An argument pack. */
3373 return d_template_args (di
);
3376 return cplus_demangle_type (di
);
3380 /* Parse a sequence of expressions until we hit the terminator
3383 static struct demangle_component
*
3384 d_exprlist (struct d_info
*di
, char terminator
)
3386 struct demangle_component
*list
= NULL
;
3387 struct demangle_component
**p
= &list
;
3389 if (d_peek_char (di
) == terminator
)
3392 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3397 struct demangle_component
*arg
= d_expression (di
);
3401 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3406 if (d_peek_char (di
) == terminator
)
3416 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3417 dynamic_cast, static_cast or reinterpret_cast. */
3420 op_is_new_cast (struct demangle_component
*op
)
3422 const char *code
= op
->u
.s_operator
.op
->code
;
3423 return (code
[1] == 'c'
3424 && (code
[0] == 's' || code
[0] == 'd'
3425 || code
[0] == 'c' || code
[0] == 'r'));
3428 /* <unresolved-name> ::= [gs] <base-unresolved-name> # x or (with "gs") ::x
3429 ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x
3430 # T::N::x /decltype(p)::N::x
3431 ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name>
3432 # A::x, N::y, A<T>::z; "gs" means leading "::"
3433 ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
3435 "gs" is handled elsewhere, as a unary operator. */
3437 static struct demangle_component
*
3438 d_unresolved_name (struct d_info
*di
)
3440 struct demangle_component
*type
;
3441 struct demangle_component
*name
;
3444 /* Consume the "sr". */
3447 peek
= d_peek_char (di
);
3448 if (di
->unresolved_name_state
3455 /* The third production is ambiguous with the old unresolved-name syntax
3456 of <type> <base-unresolved-name>; in the old mangling, A::x was mangled
3457 as sr1A1x, now sr1AE1x. So we first try to demangle using the new
3458 mangling, then with the old if that fails. */
3459 di
->unresolved_name_state
= -1;
3460 type
= d_prefix (di
, 0);
3461 if (d_peek_char (di
) == 'E')
3465 type
= cplus_demangle_type (di
);
3466 name
= d_unqualified_name (di
, type
, NULL
);
3467 if (d_peek_char (di
) == 'I')
3468 name
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3469 d_template_args (di
));
3473 /* <expression> ::= <(unary) operator-name> <expression>
3474 ::= <(binary) operator-name> <expression> <expression>
3475 ::= <(trinary) operator-name> <expression> <expression> <expression>
3476 ::= cl <expression>+ E
3478 ::= <template-param>
3479 ::= u <source-name> <template-arg>* E # vendor extended expression
3480 ::= <unresolved-name>
3483 <braced-expression> ::= <expression>
3484 ::= di <field source-name> <braced-expression> # .name = expr
3485 ::= dx <index expression> <braced-expression> # [expr] = expr
3486 ::= dX <range begin expression> <range end expression> <braced-expression>
3487 # [expr ... expr] = expr
3490 static struct demangle_component
*
3491 d_expression_1 (struct d_info
*di
)
3495 peek
= d_peek_char (di
);
3497 return d_expr_primary (di
);
3498 else if (peek
== 'T')
3499 return d_template_param (di
);
3500 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3501 return d_unresolved_name (di
);
3502 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3505 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3506 d_expression_1 (di
), NULL
);
3508 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3510 /* Function parameter used in a late-specified return type. */
3513 if (d_peek_char (di
) == 'T')
3515 /* 'this' parameter. */
3521 index
= d_compact_number (di
);
3522 if (index
== INT_MAX
|| index
== -1)
3526 return d_make_function_param (di
, index
);
3528 else if (IS_DIGIT (peek
)
3529 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3531 /* We can get an unqualified name as an expression in the case of
3532 a dependent function call, i.e. decltype(f(t)). */
3533 struct demangle_component
*name
;
3536 /* operator-function-id, i.e. operator+(t). */
3539 name
= d_unqualified_name (di
, NULL
, NULL
);
3542 if (d_peek_char (di
) == 'I')
3543 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3544 d_template_args (di
));
3548 else if ((peek
== 'i' || peek
== 't')
3549 && d_peek_next_char (di
) == 'l')
3551 /* Brace-enclosed initializer list, untyped or typed. */
3552 struct demangle_component
*type
= NULL
;
3555 type
= cplus_demangle_type (di
);
3556 if (!d_peek_char (di
) || !d_peek_next_char (di
))
3558 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3559 type
, d_exprlist (di
, 'E'));
3561 else if (peek
== 'u')
3563 /* A vendor extended expression. */
3564 struct demangle_component
*name
, *args
;
3566 name
= d_source_name (di
);
3567 args
= d_template_args_1 (di
);
3568 return d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_EXPR
, name
, args
);
3572 struct demangle_component
*op
;
3573 const char *code
= NULL
;
3576 op
= d_operator_name (di
);
3580 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3582 code
= op
->u
.s_operator
.op
->code
;
3583 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3584 if (strcmp (code
, "st") == 0)
3585 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3586 cplus_demangle_type (di
));
3593 case DEMANGLE_COMPONENT_OPERATOR
:
3594 args
= op
->u
.s_operator
.op
->args
;
3596 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3597 args
= op
->u
.s_extended_operator
.args
;
3599 case DEMANGLE_COMPONENT_CAST
:
3607 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3611 struct demangle_component
*operand
;
3614 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3615 && code
[1] == code
[0])
3616 /* pp_ and mm_ are the prefix variants. */
3617 suffix
= !d_check_char (di
, '_');
3619 if (op
->type
== DEMANGLE_COMPONENT_CAST
3620 && d_check_char (di
, '_'))
3621 operand
= d_exprlist (di
, 'E');
3622 else if (code
&& !strcmp (code
, "sP"))
3623 operand
= d_template_args_1 (di
);
3625 operand
= d_expression_1 (di
);
3628 /* Indicate the suffix variant for d_print_comp. */
3629 operand
= d_make_comp (di
, DEMANGLE_COMPONENT_BINARY_ARGS
,
3632 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
, operand
);
3636 struct demangle_component
*left
;
3637 struct demangle_component
*right
;
3641 if (op_is_new_cast (op
))
3642 left
= cplus_demangle_type (di
);
3643 else if (code
[0] == 'f')
3644 /* fold-expression. */
3645 left
= d_operator_name (di
);
3646 else if (!strcmp (code
, "di"))
3647 left
= d_unqualified_name (di
, NULL
, NULL
);
3649 left
= d_expression_1 (di
);
3650 if (!strcmp (code
, "cl"))
3651 right
= d_exprlist (di
, 'E');
3652 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3654 peek
= d_peek_char (di
);
3655 /* These codes start a qualified name. */
3656 if ((peek
== 'g' && d_peek_next_char (di
) == 's')
3657 || (peek
== 's' && d_peek_next_char (di
) == 'r'))
3658 right
= d_expression_1 (di
);
3661 /* Otherwise it's an unqualified name. We use
3662 d_unqualified_name rather than d_expression_1 here for
3663 old mangled names that didn't add 'on' before operator
3665 right
= d_unqualified_name (di
, NULL
, NULL
);
3666 if (d_peek_char (di
) == 'I')
3667 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3668 right
, d_template_args (di
));
3672 right
= d_expression_1 (di
);
3674 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3676 DEMANGLE_COMPONENT_BINARY_ARGS
,
3681 struct demangle_component
*first
;
3682 struct demangle_component
*second
;
3683 struct demangle_component
*third
;
3687 else if (!strcmp (code
, "qu")
3688 || !strcmp (code
, "dX"))
3690 /* ?: expression. */
3691 first
= d_expression_1 (di
);
3692 second
= d_expression_1 (di
);
3693 third
= d_expression_1 (di
);
3697 else if (code
[0] == 'f')
3699 /* fold-expression. */
3700 first
= d_operator_name (di
);
3701 second
= d_expression_1 (di
);
3702 third
= d_expression_1 (di
);
3706 else if (code
[0] == 'n')
3708 /* new-expression. */
3709 if (code
[1] != 'w' && code
[1] != 'a')
3711 first
= d_exprlist (di
, '_');
3712 second
= cplus_demangle_type (di
);
3713 if (d_peek_char (di
) == 'E')
3718 else if (d_peek_char (di
) == 'p'
3719 && d_peek_next_char (di
) == 'i')
3721 /* Parenthesized initializer. */
3723 third
= d_exprlist (di
, 'E');
3725 else if (d_peek_char (di
) == 'i'
3726 && d_peek_next_char (di
) == 'l')
3727 /* initializer-list. */
3728 third
= d_expression_1 (di
);
3734 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3736 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3739 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3748 static struct demangle_component
*
3749 d_expression (struct d_info
*di
)
3751 struct demangle_component
*ret
;
3752 int was_expression
= di
->is_expression
;
3754 di
->is_expression
= 1;
3755 ret
= d_expression_1 (di
);
3756 di
->is_expression
= was_expression
;
3760 /* <expr-primary> ::= L <type> <(value) number> E
3761 ::= L <type> <(value) float> E
3762 ::= L <mangled-name> E
3765 static struct demangle_component
*
3766 d_expr_primary (struct d_info
*di
)
3768 struct demangle_component
*ret
;
3770 if (! d_check_char (di
, 'L'))
3772 if (d_peek_char (di
) == '_'
3773 /* Workaround for G++ bug; see comment in write_template_arg. */
3774 || d_peek_char (di
) == 'Z')
3775 ret
= cplus_demangle_mangled_name (di
, 0);
3778 struct demangle_component
*type
;
3779 enum demangle_component_type t
;
3782 type
= cplus_demangle_type (di
);
3786 /* If we have a type we know how to print, we aren't going to
3787 print the type name itself. */
3788 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3789 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3790 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3792 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3793 && strcmp (type
->u
.s_builtin
.type
->name
,
3794 cplus_demangle_builtin_types
[33].name
) == 0)
3796 if (d_peek_char (di
) == 'E')
3803 /* Rather than try to interpret the literal value, we just
3804 collect it as a string. Note that it's possible to have a
3805 floating point literal here. The ABI specifies that the
3806 format of such literals is machine independent. That's fine,
3807 but what's not fine is that versions of g++ up to 3.2 with
3808 -fabi-version=1 used upper case letters in the hex constant,
3809 and dumped out gcc's internal representation. That makes it
3810 hard to tell where the constant ends, and hard to dump the
3811 constant in any readable form anyhow. We don't attempt to
3812 handle these cases. */
3814 t
= DEMANGLE_COMPONENT_LITERAL
;
3815 if (d_peek_char (di
) == 'n')
3817 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3821 while (d_peek_char (di
) != 'E')
3823 if (d_peek_char (di
) == '\0')
3827 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3829 if (! d_check_char (di
, 'E'))
3834 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3835 ::= Z <(function) encoding> E s [<discriminator>]
3836 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3839 static struct demangle_component
*
3840 d_local_name (struct d_info
*di
)
3842 struct demangle_component
*function
;
3843 struct demangle_component
*name
;
3845 if (! d_check_char (di
, 'Z'))
3848 function
= d_encoding (di
, 0);
3852 if (! d_check_char (di
, 'E'))
3855 if (d_peek_char (di
) == 's')
3858 if (! d_discriminator (di
))
3860 name
= d_make_name (di
, "string literal", sizeof "string literal" - 1);
3866 if (d_peek_char (di
) == 'd')
3868 /* Default argument scope: d <number> _. */
3870 num
= d_compact_number (di
);
3875 name
= d_name (di
, 0);
3878 /* Lambdas and unnamed types have internal discriminators
3879 and are not functions. */
3880 && name
->type
!= DEMANGLE_COMPONENT_LAMBDA
3881 && name
->type
!= DEMANGLE_COMPONENT_UNNAMED_TYPE
)
3883 /* Read and ignore an optional discriminator. */
3884 if (! d_discriminator (di
))
3889 name
= d_make_default_arg (di
, num
, name
);
3892 /* Elide the return type of the containing function so as to not
3893 confuse the user thinking it is the return type of whatever local
3894 function we might be containing. */
3895 if (function
->type
== DEMANGLE_COMPONENT_TYPED_NAME
3896 && d_right (function
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
3897 d_left (d_right (function
)) = NULL
;
3899 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3902 /* <discriminator> ::= _ <number> # when number < 10
3903 ::= __ <number> _ # when number >= 10
3905 <discriminator> ::= _ <number> # when number >=10
3906 is also accepted to support gcc versions that wrongly mangled that way.
3908 We demangle the discriminator, but we don't print it out. FIXME:
3909 We should print it out in verbose mode. */
3912 d_discriminator (struct d_info
*di
)
3914 int discrim
, num_underscores
= 1;
3916 if (d_peek_char (di
) != '_')
3919 if (d_peek_char (di
) == '_')
3925 discrim
= d_number (di
);
3928 if (num_underscores
> 1 && discrim
>= 10)
3930 if (d_peek_char (di
) == '_')
3939 /* <template-parm> ::= Ty
3941 ::= Tt <template-head> E
3942 ::= Tp <template-parm> */
3944 static struct demangle_component
*
3945 d_template_parm (struct d_info
*di
, int *bad
)
3947 if (d_peek_char (di
) != 'T')
3950 struct demangle_component
*op
;
3951 enum demangle_component_type kind
;
3952 switch (d_peek_next_char (di
))
3957 case 'p': /* Pack */
3959 op
= d_template_parm (di
, bad
);
3960 kind
= DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
;
3968 case 'y': /* Typename */
3971 kind
= DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
;
3974 case 'n': /* Non-Type */
3976 op
= cplus_demangle_type (di
);
3977 kind
= DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
;
3985 case 't': /* Template */
3987 op
= d_template_head (di
, bad
);
3988 kind
= DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
;
3989 if (!op
|| !d_check_char (di
, 'E'))
3996 return d_make_comp (di
, kind
, op
, NULL
);
3999 /* <template-head> ::= <template-head>? <template-parm> */
4001 static struct demangle_component
*
4002 d_template_head (struct d_info
*di
, int *bad
)
4004 struct demangle_component
*res
= NULL
, **slot
= &res
;
4005 struct demangle_component
*op
;
4007 while ((op
= d_template_parm (di
, bad
)))
4010 slot
= &d_right (op
);
4013 /* Wrap it in a template head, to make concatenating with any parm list, and
4014 printing simpler. */
4016 res
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_HEAD
, res
, NULL
);
4021 /* <closure-type-name> ::= Ul <template-head>? <lambda-sig> E [ <nonnegative number> ] _ */
4023 static struct demangle_component
*
4024 d_lambda (struct d_info
*di
)
4026 if (! d_check_char (di
, 'U'))
4028 if (! d_check_char (di
, 'l'))
4032 struct demangle_component
*head
= d_template_head (di
, &bad
);
4036 struct demangle_component
*tl
= d_parmlist (di
);
4041 d_right (head
) = tl
;
4045 if (! d_check_char (di
, 'E'))
4048 int num
= d_compact_number (di
);
4052 struct demangle_component
*ret
= d_make_empty (di
);
4055 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
4056 ret
->u
.s_unary_num
.sub
= tl
;
4057 ret
->u
.s_unary_num
.num
= num
;
4063 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
4065 static struct demangle_component
*
4066 d_unnamed_type (struct d_info
*di
)
4068 struct demangle_component
*ret
;
4071 if (! d_check_char (di
, 'U'))
4073 if (! d_check_char (di
, 't'))
4076 num
= d_compact_number (di
);
4080 ret
= d_make_empty (di
);
4083 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
4084 ret
->u
.s_number
.number
= num
;
4087 if (! d_add_substitution (di
, ret
))
4093 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
4096 static struct demangle_component
*
4097 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
4099 const char *suffix
= d_str (di
);
4100 const char *pend
= suffix
;
4101 struct demangle_component
*n
;
4103 if (*pend
== '.' && (IS_LOWER (pend
[1]) || IS_DIGIT (pend
[1])
4107 while (IS_LOWER (*pend
) || IS_DIGIT (*pend
) || *pend
== '_')
4110 while (*pend
== '.' && IS_DIGIT (pend
[1]))
4113 while (IS_DIGIT (*pend
))
4116 d_advance (di
, pend
- suffix
);
4117 n
= d_make_name (di
, suffix
, pend
- suffix
);
4118 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
4121 /* Add a new substitution. */
4124 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
4128 if (di
->next_sub
>= di
->num_subs
)
4130 di
->subs
[di
->next_sub
] = dc
;
4135 /* <substitution> ::= S <seq-id> _
4145 If PREFIX is non-zero, then this type is being used as a prefix in
4146 a qualified name. In this case, for the standard substitutions, we
4147 need to check whether we are being used as a prefix for a
4148 constructor or destructor, and return a full template name.
4149 Otherwise we will get something like std::iostream::~iostream()
4150 which does not correspond particularly well to any function which
4151 actually appears in the source.
4154 static const struct d_standard_sub_info standard_subs
[] =
4159 { 'a', NL ("std::allocator"),
4160 NL ("std::allocator"),
4162 { 'b', NL ("std::basic_string"),
4163 NL ("std::basic_string"),
4164 NL ("basic_string") },
4165 { 's', NL ("std::string"),
4166 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
4167 NL ("basic_string") },
4168 { 'i', NL ("std::istream"),
4169 NL ("std::basic_istream<char, std::char_traits<char> >"),
4170 NL ("basic_istream") },
4171 { 'o', NL ("std::ostream"),
4172 NL ("std::basic_ostream<char, std::char_traits<char> >"),
4173 NL ("basic_ostream") },
4174 { 'd', NL ("std::iostream"),
4175 NL ("std::basic_iostream<char, std::char_traits<char> >"),
4176 NL ("basic_iostream") }
4179 static struct demangle_component
*
4180 d_substitution (struct d_info
*di
, int prefix
)
4184 if (! d_check_char (di
, 'S'))
4187 c
= d_next_char (di
);
4188 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
4197 unsigned int new_id
;
4200 new_id
= id
* 36 + c
- '0';
4201 else if (IS_UPPER (c
))
4202 new_id
= id
* 36 + c
- 'A' + 10;
4208 c
= d_next_char (di
);
4215 if (id
>= (unsigned int) di
->next_sub
)
4218 return di
->subs
[id
];
4223 const struct d_standard_sub_info
*p
;
4224 const struct d_standard_sub_info
*pend
;
4226 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
4227 if (! verbose
&& prefix
)
4231 peek
= d_peek_char (di
);
4232 if (peek
== 'C' || peek
== 'D')
4236 pend
= (&standard_subs
[0]
4237 + sizeof standard_subs
/ sizeof standard_subs
[0]);
4238 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
4244 struct demangle_component
*dc
;
4246 if (p
->set_last_name
!= NULL
)
4247 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
4248 p
->set_last_name_len
);
4251 s
= p
->full_expansion
;
4256 s
= p
->simple_expansion
;
4257 len
= p
->simple_len
;
4259 di
->expansion
+= len
;
4260 dc
= d_make_sub (di
, s
, len
);
4261 if (d_peek_char (di
) == 'B')
4263 /* If there are ABI tags on the abbreviation, it becomes
4264 a substitution candidate. */
4265 dc
= d_abi_tags (di
, dc
);
4266 if (! d_add_substitution (di
, dc
))
4278 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
4280 checkpoint
->n
= di
->n
;
4281 checkpoint
->next_comp
= di
->next_comp
;
4282 checkpoint
->next_sub
= di
->next_sub
;
4283 checkpoint
->expansion
= di
->expansion
;
4287 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
4289 di
->n
= checkpoint
->n
;
4290 di
->next_comp
= checkpoint
->next_comp
;
4291 di
->next_sub
= checkpoint
->next_sub
;
4292 di
->expansion
= checkpoint
->expansion
;
4295 /* Initialize a growable string. */
4298 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
4303 dgs
->allocation_failure
= 0;
4306 d_growable_string_resize (dgs
, estimate
);
4309 /* Grow a growable string to a given size. */
4312 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
4317 if (dgs
->allocation_failure
)
4320 /* Start allocation at two bytes to avoid any possibility of confusion
4321 with the special value of 1 used as a return in *palc to indicate
4322 allocation failures. */
4323 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
4324 while (newalc
< need
)
4327 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
4334 dgs
->allocation_failure
= 1;
4341 /* Append a buffer to a growable string. */
4344 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
4345 const char *s
, size_t l
)
4349 need
= dgs
->len
+ l
+ 1;
4350 if (need
> dgs
->alc
)
4351 d_growable_string_resize (dgs
, need
);
4353 if (dgs
->allocation_failure
)
4356 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
4357 dgs
->buf
[dgs
->len
+ l
] = '\0';
4361 /* Bridge growable strings to the callback mechanism. */
4364 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
4366 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
4368 d_growable_string_append_buffer (dgs
, s
, l
);
4371 /* Walk the tree, counting the number of templates encountered, and
4372 the number of times a scope might be saved. These counts will be
4373 used to allocate data structures for d_print_comp, so the logic
4374 here must mirror the logic d_print_comp will use. It is not
4375 important that the resulting numbers are exact, so long as they
4376 are larger than the actual numbers encountered. */
4379 d_count_templates_scopes (struct d_print_info
*dpi
,
4380 struct demangle_component
*dc
)
4382 if (dc
== NULL
|| dc
->d_counting
> 1 || dpi
->recursion
> MAX_RECURSION_COUNT
)
4389 case DEMANGLE_COMPONENT_NAME
:
4390 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4391 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4392 case DEMANGLE_COMPONENT_SUB_STD
:
4393 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4394 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
4395 case DEMANGLE_COMPONENT_OPERATOR
:
4396 case DEMANGLE_COMPONENT_CHARACTER
:
4397 case DEMANGLE_COMPONENT_NUMBER
:
4398 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4399 case DEMANGLE_COMPONENT_STRUCTURED_BINDING
:
4400 case DEMANGLE_COMPONENT_MODULE_NAME
:
4401 case DEMANGLE_COMPONENT_MODULE_PARTITION
:
4402 case DEMANGLE_COMPONENT_MODULE_INIT
:
4403 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4404 case DEMANGLE_COMPONENT_TEMPLATE_HEAD
:
4405 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
4406 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
4407 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
4408 case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
:
4411 case DEMANGLE_COMPONENT_TEMPLATE
:
4412 dpi
->num_copy_templates
++;
4413 goto recurse_left_right
;
4415 case DEMANGLE_COMPONENT_REFERENCE
:
4416 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4417 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4418 dpi
->num_saved_scopes
++;
4419 goto recurse_left_right
;
4421 case DEMANGLE_COMPONENT_QUAL_NAME
:
4422 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4423 case DEMANGLE_COMPONENT_TYPED_NAME
:
4424 case DEMANGLE_COMPONENT_VTABLE
:
4425 case DEMANGLE_COMPONENT_VTT
:
4426 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4427 case DEMANGLE_COMPONENT_TYPEINFO
:
4428 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4429 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4430 case DEMANGLE_COMPONENT_THUNK
:
4431 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4432 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4433 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4434 case DEMANGLE_COMPONENT_GUARD
:
4435 case DEMANGLE_COMPONENT_TLS_INIT
:
4436 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4437 case DEMANGLE_COMPONENT_REFTEMP
:
4438 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4439 case DEMANGLE_COMPONENT_RESTRICT
:
4440 case DEMANGLE_COMPONENT_VOLATILE
:
4441 case DEMANGLE_COMPONENT_CONST
:
4442 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4443 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4444 case DEMANGLE_COMPONENT_CONST_THIS
:
4445 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4446 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4447 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
4448 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4449 case DEMANGLE_COMPONENT_NOEXCEPT
:
4450 case DEMANGLE_COMPONENT_THROW_SPEC
:
4451 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4452 case DEMANGLE_COMPONENT_POINTER
:
4453 case DEMANGLE_COMPONENT_COMPLEX
:
4454 case DEMANGLE_COMPONENT_IMAGINARY
:
4455 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4456 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4457 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4458 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4459 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4460 case DEMANGLE_COMPONENT_ARGLIST
:
4461 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4462 case DEMANGLE_COMPONENT_TPARM_OBJ
:
4463 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4464 case DEMANGLE_COMPONENT_CAST
:
4465 case DEMANGLE_COMPONENT_CONVERSION
:
4466 case DEMANGLE_COMPONENT_NULLARY
:
4467 case DEMANGLE_COMPONENT_UNARY
:
4468 case DEMANGLE_COMPONENT_BINARY
:
4469 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4470 case DEMANGLE_COMPONENT_TRINARY
:
4471 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4472 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4473 case DEMANGLE_COMPONENT_LITERAL
:
4474 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4475 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
4476 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4477 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4478 case DEMANGLE_COMPONENT_DECLTYPE
:
4479 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4480 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4481 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4482 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4483 case DEMANGLE_COMPONENT_CLONE
:
4484 case DEMANGLE_COMPONENT_CONSTRAINTS
:
4486 /* PR 89394 - Check for too much recursion. */
4487 if (dpi
->recursion
> DEMANGLE_RECURSION_LIMIT
)
4488 /* FIXME: There ought to be a way to report to the
4489 user that the recursion limit has been reached. */
4493 d_count_templates_scopes (dpi
, d_left (dc
));
4494 d_count_templates_scopes (dpi
, d_right (dc
));
4498 case DEMANGLE_COMPONENT_CTOR
:
4499 d_count_templates_scopes (dpi
, dc
->u
.s_ctor
.name
);
4502 case DEMANGLE_COMPONENT_DTOR
:
4503 d_count_templates_scopes (dpi
, dc
->u
.s_dtor
.name
);
4506 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4507 d_count_templates_scopes (dpi
, dc
->u
.s_extended_operator
.name
);
4510 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4511 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4512 case DEMANGLE_COMPONENT_MODULE_ENTITY
:
4513 case DEMANGLE_COMPONENT_FRIEND
:
4514 d_count_templates_scopes (dpi
, d_left (dc
));
4517 case DEMANGLE_COMPONENT_LAMBDA
:
4518 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4519 d_count_templates_scopes (dpi
, dc
->u
.s_unary_num
.sub
);
4524 /* Initialize a print information structure. */
4527 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
4528 void *opaque
, struct demangle_component
*dc
)
4531 dpi
->last_char
= '\0';
4532 dpi
->templates
= NULL
;
4533 dpi
->modifiers
= NULL
;
4534 dpi
->pack_index
= 0;
4535 dpi
->flush_count
= 0;
4537 dpi
->callback
= callback
;
4538 dpi
->opaque
= opaque
;
4540 dpi
->demangle_failure
= 0;
4542 dpi
->lambda_tpl_parms
= 0;
4544 dpi
->component_stack
= NULL
;
4546 dpi
->saved_scopes
= NULL
;
4547 dpi
->next_saved_scope
= 0;
4548 dpi
->num_saved_scopes
= 0;
4550 dpi
->copy_templates
= NULL
;
4551 dpi
->next_copy_template
= 0;
4552 dpi
->num_copy_templates
= 0;
4554 d_count_templates_scopes (dpi
, dc
);
4555 /* If we did not reach the recursion limit, then reset the
4556 current recursion value back to 0, so that we can print
4558 if (dpi
->recursion
< DEMANGLE_RECURSION_LIMIT
)
4560 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
4562 dpi
->current_template
= NULL
;
4565 /* Indicate that an error occurred during printing, and test for error. */
4568 d_print_error (struct d_print_info
*dpi
)
4570 dpi
->demangle_failure
= 1;
4574 d_print_saw_error (struct d_print_info
*dpi
)
4576 return dpi
->demangle_failure
!= 0;
4579 /* Flush buffered characters to the callback. */
4582 d_print_flush (struct d_print_info
*dpi
)
4584 dpi
->buf
[dpi
->len
] = '\0';
4585 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4590 /* Append characters and buffers for printing. */
4593 d_append_char (struct d_print_info
*dpi
, char c
)
4595 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4596 d_print_flush (dpi
);
4598 dpi
->buf
[dpi
->len
++] = c
;
4603 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4607 for (i
= 0; i
< l
; i
++)
4608 d_append_char (dpi
, s
[i
]);
4612 d_append_string (struct d_print_info
*dpi
, const char *s
)
4614 d_append_buffer (dpi
, s
, strlen (s
));
4618 d_append_num (struct d_print_info
*dpi
, int l
)
4621 sprintf (buf
,"%d", l
);
4622 d_append_string (dpi
, buf
);
4626 d_last_char (struct d_print_info
*dpi
)
4628 return dpi
->last_char
;
4631 /* Turn components into a human readable string. OPTIONS is the
4632 options bits passed to the demangler. DC is the tree to print.
4633 CALLBACK is a function to call to flush demangled string segments
4634 as they fill the intermediate buffer, and OPAQUE is a generalized
4635 callback argument. On success, this returns 1. On failure,
4636 it returns 0, indicating a bad parse. It does not use heap
4637 memory to build an output string, so cannot encounter memory
4638 allocation failure. */
4640 CP_STATIC_IF_GLIBCPP_V3
4642 cplus_demangle_print_callback (int options
,
4643 struct demangle_component
*dc
,
4644 demangle_callbackref callback
, void *opaque
)
4646 struct d_print_info dpi
;
4648 d_print_init (&dpi
, callback
, opaque
, dc
);
4651 #ifdef CP_DYNAMIC_ARRAYS
4652 /* Avoid zero-length VLAs, which are prohibited by the C99 standard
4653 and flagged as errors by Address Sanitizer. */
4654 __extension__
struct d_saved_scope scopes
[(dpi
.num_saved_scopes
> 0)
4655 ? dpi
.num_saved_scopes
: 1];
4656 __extension__
struct d_print_template temps
[(dpi
.num_copy_templates
> 0)
4657 ? dpi
.num_copy_templates
: 1];
4659 dpi
.saved_scopes
= scopes
;
4660 dpi
.copy_templates
= temps
;
4662 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4663 * sizeof (*dpi
.saved_scopes
));
4664 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4665 * sizeof (*dpi
.copy_templates
));
4668 d_print_comp (&dpi
, options
, dc
);
4671 d_print_flush (&dpi
);
4673 return ! d_print_saw_error (&dpi
);
4676 /* Turn components into a human readable string. OPTIONS is the
4677 options bits passed to the demangler. DC is the tree to print.
4678 ESTIMATE is a guess at the length of the result. This returns a
4679 string allocated by malloc, or NULL on error. On success, this
4680 sets *PALC to the size of the allocated buffer. On failure, this
4681 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4684 CP_STATIC_IF_GLIBCPP_V3
4686 cplus_demangle_print (int options
, struct demangle_component
*dc
,
4687 int estimate
, size_t *palc
)
4689 struct d_growable_string dgs
;
4691 d_growable_string_init (&dgs
, estimate
);
4693 if (! cplus_demangle_print_callback (options
, dc
,
4694 d_growable_string_callback_adapter
,
4702 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4706 /* Returns the I'th element of the template arglist ARGS, or NULL on
4707 failure. If I is negative, return the entire arglist. */
4709 static struct demangle_component
*
4710 d_index_template_argument (struct demangle_component
*args
, int i
)
4712 struct demangle_component
*a
;
4715 /* Print the whole argument pack. */
4722 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4728 if (i
!= 0 || a
== NULL
)
4734 /* Returns the template argument from the current context indicated by DC,
4735 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4737 static struct demangle_component
*
4738 d_lookup_template_argument (struct d_print_info
*dpi
,
4739 const struct demangle_component
*dc
)
4741 if (dpi
->templates
== NULL
)
4743 d_print_error (dpi
);
4747 return d_index_template_argument
4748 (d_right (dpi
->templates
->template_decl
),
4749 dc
->u
.s_number
.number
);
4752 /* Returns a template argument pack used in DC (any will do), or NULL. */
4754 static struct demangle_component
*
4755 d_find_pack (struct d_print_info
*dpi
,
4756 const struct demangle_component
*dc
)
4758 struct demangle_component
*a
;
4764 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4765 a
= d_lookup_template_argument (dpi
, dc
);
4766 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4770 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4773 case DEMANGLE_COMPONENT_LAMBDA
:
4774 case DEMANGLE_COMPONENT_NAME
:
4775 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4776 case DEMANGLE_COMPONENT_OPERATOR
:
4777 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4778 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
4779 case DEMANGLE_COMPONENT_SUB_STD
:
4780 case DEMANGLE_COMPONENT_CHARACTER
:
4781 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4782 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4783 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4784 case DEMANGLE_COMPONENT_NUMBER
:
4787 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4788 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4789 case DEMANGLE_COMPONENT_CTOR
:
4790 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4791 case DEMANGLE_COMPONENT_DTOR
:
4792 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4795 a
= d_find_pack (dpi
, d_left (dc
));
4798 return d_find_pack (dpi
, d_right (dc
));
4802 /* Returns the length of the template argument pack DC. */
4805 d_pack_length (const struct demangle_component
*dc
)
4808 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4809 && d_left (dc
) != NULL
)
4817 /* Returns the number of template args in DC, expanding any pack expansions
4821 d_args_length (struct d_print_info
*dpi
, const struct demangle_component
*dc
)
4824 for (; dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
;
4827 struct demangle_component
*elt
= d_left (dc
);
4830 if (elt
->type
== DEMANGLE_COMPONENT_PACK_EXPANSION
)
4832 struct demangle_component
*a
= d_find_pack (dpi
, d_left (elt
));
4833 count
+= d_pack_length (a
);
4841 /* DC is a component of a mangled expression. Print it, wrapped in parens
4845 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4846 struct demangle_component
*dc
)
4849 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4850 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4851 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4852 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4855 d_append_char (dpi
, '(');
4856 d_print_comp (dpi
, options
, dc
);
4858 d_append_char (dpi
, ')');
4861 /* Save the current scope. */
4864 d_save_scope (struct d_print_info
*dpi
,
4865 const struct demangle_component
*container
)
4867 struct d_saved_scope
*scope
;
4868 struct d_print_template
*src
, **link
;
4870 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4872 d_print_error (dpi
);
4875 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4876 dpi
->next_saved_scope
++;
4878 scope
->container
= container
;
4879 link
= &scope
->templates
;
4881 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4883 struct d_print_template
*dst
;
4885 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4887 d_print_error (dpi
);
4890 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4891 dpi
->next_copy_template
++;
4893 dst
->template_decl
= src
->template_decl
;
4901 /* Attempt to locate a previously saved scope. Returns NULL if no
4902 corresponding saved scope was found. */
4904 static struct d_saved_scope
*
4905 d_get_saved_scope (struct d_print_info
*dpi
,
4906 const struct demangle_component
*container
)
4910 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4911 if (dpi
->saved_scopes
[i
].container
== container
)
4912 return &dpi
->saved_scopes
[i
];
4917 /* If DC is a C++17 fold-expression, print it and return true; otherwise
4921 d_maybe_print_fold_expression (struct d_print_info
*dpi
, int options
,
4922 struct demangle_component
*dc
)
4924 struct demangle_component
*ops
, *operator_
, *op1
, *op2
;
4927 const char *fold_code
= d_left (dc
)->u
.s_operator
.op
->code
;
4928 if (fold_code
[0] != 'f')
4932 operator_
= d_left (ops
);
4933 op1
= d_right (ops
);
4935 if (op1
->type
== DEMANGLE_COMPONENT_TRINARY_ARG2
)
4937 op2
= d_right (op1
);
4941 /* Print the whole pack. */
4942 save_idx
= dpi
->pack_index
;
4943 dpi
->pack_index
= -1;
4945 switch (fold_code
[1])
4947 /* Unary left fold, (... + X). */
4949 d_append_string (dpi
, "(...");
4950 d_print_expr_op (dpi
, options
, operator_
);
4951 d_print_subexpr (dpi
, options
, op1
);
4952 d_append_char (dpi
, ')');
4955 /* Unary right fold, (X + ...). */
4957 d_append_char (dpi
, '(');
4958 d_print_subexpr (dpi
, options
, op1
);
4959 d_print_expr_op (dpi
, options
, operator_
);
4960 d_append_string (dpi
, "...)");
4963 /* Binary left fold, (42 + ... + X). */
4965 /* Binary right fold, (X + ... + 42). */
4967 d_append_char (dpi
, '(');
4968 d_print_subexpr (dpi
, options
, op1
);
4969 d_print_expr_op (dpi
, options
, operator_
);
4970 d_append_string (dpi
, "...");
4971 d_print_expr_op (dpi
, options
, operator_
);
4972 d_print_subexpr (dpi
, options
, op2
);
4973 d_append_char (dpi
, ')');
4977 dpi
->pack_index
= save_idx
;
4981 /* True iff DC represents a C99-style designated initializer. */
4984 is_designated_init (struct demangle_component
*dc
)
4986 if (dc
->type
!= DEMANGLE_COMPONENT_BINARY
4987 && dc
->type
!= DEMANGLE_COMPONENT_TRINARY
)
4990 struct demangle_component
*op
= d_left (dc
);
4991 const char *code
= op
->u
.s_operator
.op
->code
;
4992 return (code
[0] == 'd'
4993 && (code
[1] == 'i' || code
[1] == 'x' || code
[1] == 'X'));
4996 /* If DC represents a C99-style designated initializer, print it and return
4997 true; otherwise, return false. */
5000 d_maybe_print_designated_init (struct d_print_info
*dpi
, int options
,
5001 struct demangle_component
*dc
)
5003 if (!is_designated_init (dc
))
5006 const char *code
= d_left (dc
)->u
.s_operator
.op
->code
;
5008 struct demangle_component
*operands
= d_right (dc
);
5009 struct demangle_component
*op1
= d_left (operands
);
5010 struct demangle_component
*op2
= d_right (operands
);
5013 d_append_char (dpi
, '.');
5015 d_append_char (dpi
, '[');
5017 d_print_comp (dpi
, options
, op1
);
5020 d_append_string (dpi
, " ... ");
5021 d_print_comp (dpi
, options
, d_left (op2
));
5022 op2
= d_right (op2
);
5025 d_append_char (dpi
, ']');
5026 if (is_designated_init (op2
))
5028 /* Don't put '=' or '(' between chained designators. */
5029 d_print_comp (dpi
, options
, op2
);
5033 d_append_char (dpi
, '=');
5034 d_print_subexpr (dpi
, options
, op2
);
5040 d_print_lambda_parm_name (struct d_print_info
*dpi
, int type
, unsigned index
)
5046 dpi
->demangle_failure
= 1;
5050 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
5054 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
5058 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
5062 d_append_string (dpi
, str
);
5063 d_append_num (dpi
, index
);
5066 /* Subroutine to handle components. */
5069 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
5070 struct demangle_component
*dc
)
5072 /* Magic variable to let reference smashing skip over the next modifier
5073 without needing to modify *dc. */
5074 struct demangle_component
*mod_inner
= NULL
;
5076 /* Variable used to store the current templates while a previously
5077 captured scope is used. */
5078 struct d_print_template
*saved_templates
;
5080 /* Nonzero if templates have been stored in the above variable. */
5081 int need_template_restore
= 0;
5085 d_print_error (dpi
);
5088 if (d_print_saw_error (dpi
))
5093 case DEMANGLE_COMPONENT_NAME
:
5094 if ((options
& DMGL_JAVA
) == 0)
5095 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
5097 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
5100 case DEMANGLE_COMPONENT_TAGGED_NAME
:
5101 d_print_comp (dpi
, options
, d_left (dc
));
5102 d_append_string (dpi
, "[abi:");
5103 d_print_comp (dpi
, options
, d_right (dc
));
5104 d_append_char (dpi
, ']');
5107 case DEMANGLE_COMPONENT_STRUCTURED_BINDING
:
5108 d_append_char (dpi
, '[');
5111 d_print_comp (dpi
, options
, d_left (dc
));
5115 d_append_string (dpi
, ", ");
5117 d_append_char (dpi
, ']');
5120 case DEMANGLE_COMPONENT_MODULE_ENTITY
:
5121 d_print_comp (dpi
, options
, d_left (dc
));
5122 d_append_char (dpi
, '@');
5123 d_print_comp (dpi
, options
, d_right (dc
));
5126 case DEMANGLE_COMPONENT_MODULE_NAME
:
5127 case DEMANGLE_COMPONENT_MODULE_PARTITION
:
5130 d_print_comp (dpi
, options
, d_left (dc
));
5131 char c
= dc
->type
== DEMANGLE_COMPONENT_MODULE_PARTITION
5132 ? ':' : d_left (dc
) ? '.' : 0;
5134 d_append_char (dpi
, c
);
5135 d_print_comp (dpi
, options
, d_right (dc
));
5139 case DEMANGLE_COMPONENT_QUAL_NAME
:
5140 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5141 d_print_comp (dpi
, options
, d_left (dc
));
5142 if ((options
& DMGL_JAVA
) == 0)
5143 d_append_string (dpi
, "::");
5145 d_append_char (dpi
, '.');
5147 struct demangle_component
*local_name
= d_right (dc
);
5148 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5150 d_append_string (dpi
, "{default arg#");
5151 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
5152 d_append_string (dpi
, "}::");
5153 local_name
= local_name
->u
.s_unary_num
.sub
;
5155 d_print_comp (dpi
, options
, local_name
);
5159 case DEMANGLE_COMPONENT_TYPED_NAME
:
5161 struct d_print_mod
*hold_modifiers
;
5162 struct demangle_component
*typed_name
;
5163 struct d_print_mod adpm
[4];
5165 struct d_print_template dpt
;
5167 /* Pass the name down to the type so that it can be printed in
5168 the right place for the type. We also have to pass down
5169 any CV-qualifiers, which apply to the this parameter. */
5170 hold_modifiers
= dpi
->modifiers
;
5173 typed_name
= d_left (dc
);
5174 while (typed_name
!= NULL
)
5176 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5178 d_print_error (dpi
);
5182 adpm
[i
].next
= dpi
->modifiers
;
5183 dpi
->modifiers
= &adpm
[i
];
5184 adpm
[i
].mod
= typed_name
;
5185 adpm
[i
].printed
= 0;
5186 adpm
[i
].templates
= dpi
->templates
;
5189 if (!is_fnqual_component_type (typed_name
->type
))
5192 typed_name
= d_left (typed_name
);
5195 if (typed_name
== NULL
)
5197 d_print_error (dpi
);
5201 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
5202 there may be CV-qualifiers on its right argument which
5203 really apply here; this happens when parsing a class that
5204 is local to a function. */
5205 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5207 typed_name
= d_right (typed_name
);
5208 if (typed_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5209 typed_name
= typed_name
->u
.s_unary_num
.sub
;
5210 while (typed_name
!= NULL
5211 && is_fnqual_component_type (typed_name
->type
))
5213 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5215 d_print_error (dpi
);
5219 adpm
[i
] = adpm
[i
- 1];
5220 adpm
[i
].next
= &adpm
[i
- 1];
5221 dpi
->modifiers
= &adpm
[i
];
5223 adpm
[i
- 1].mod
= typed_name
;
5224 adpm
[i
- 1].printed
= 0;
5225 adpm
[i
- 1].templates
= dpi
->templates
;
5228 typed_name
= d_left (typed_name
);
5230 if (typed_name
== NULL
)
5232 d_print_error (dpi
);
5237 /* If typed_name is a template, then it applies to the
5238 function type as well. */
5239 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
5241 dpt
.next
= dpi
->templates
;
5242 dpi
->templates
= &dpt
;
5243 dpt
.template_decl
= typed_name
;
5245 /* Constraints are mangled as part of the template argument list,
5246 so they wrap the _TEMPLATE_ARGLIST. But
5247 d_lookup_template_argument expects the RHS of _TEMPLATE to be
5248 the _ARGLIST, and constraints need to refer to these args. So
5249 move the _CONSTRAINTS out of the _TEMPLATE and onto the type.
5250 This will result in them being printed after the () like a
5251 trailing requires-clause, but that seems like our best option
5252 given that we aren't printing a template-head. */
5253 struct demangle_component
*tnr
= d_right (typed_name
);
5254 if (tnr
->type
== DEMANGLE_COMPONENT_CONSTRAINTS
)
5256 d_right (typed_name
) = d_left (tnr
);
5257 d_left (tnr
) = d_right (dc
);
5262 d_print_comp (dpi
, options
, d_right (dc
));
5264 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
5265 dpi
->templates
= dpt
.next
;
5267 /* If the modifiers didn't get printed by the type, print them
5272 if (! adpm
[i
].printed
)
5274 d_append_char (dpi
, ' ');
5275 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5279 dpi
->modifiers
= hold_modifiers
;
5284 case DEMANGLE_COMPONENT_TEMPLATE
:
5286 struct d_print_mod
*hold_dpm
;
5287 struct demangle_component
*dcl
;
5288 const struct demangle_component
*hold_current
;
5290 /* This template may need to be referenced by a cast operator
5291 contained in its subtree. */
5292 hold_current
= dpi
->current_template
;
5293 dpi
->current_template
= dc
;
5295 /* Don't push modifiers into a template definition. Doing so
5296 could give the wrong definition for a template argument.
5297 Instead, treat the template essentially as a name. */
5299 hold_dpm
= dpi
->modifiers
;
5300 dpi
->modifiers
= NULL
;
5304 if ((options
& DMGL_JAVA
) != 0
5305 && dcl
->type
== DEMANGLE_COMPONENT_NAME
5306 && dcl
->u
.s_name
.len
== 6
5307 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
5309 /* Special-case Java arrays, so that JArray<TYPE> appears
5310 instead as TYPE[]. */
5312 d_print_comp (dpi
, options
, d_right (dc
));
5313 d_append_string (dpi
, "[]");
5317 d_print_comp (dpi
, options
, dcl
);
5318 if (d_last_char (dpi
) == '<')
5319 d_append_char (dpi
, ' ');
5320 d_append_char (dpi
, '<');
5321 d_print_comp (dpi
, options
, d_right (dc
));
5322 /* Avoid generating two consecutive '>' characters, to avoid
5323 the C++ syntactic ambiguity. */
5324 if (d_last_char (dpi
) == '>')
5325 d_append_char (dpi
, ' ');
5326 d_append_char (dpi
, '>');
5329 dpi
->modifiers
= hold_dpm
;
5330 dpi
->current_template
= hold_current
;
5335 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
5336 if (dpi
->lambda_tpl_parms
> dc
->u
.s_number
.number
+ 1)
5338 const struct demangle_component
*a
5339 = d_left (dpi
->templates
->template_decl
);
5341 for (c
= dc
->u
.s_number
.number
; a
&& c
; c
--)
5343 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
)
5346 dpi
->demangle_failure
= 1;
5348 d_print_lambda_parm_name (dpi
, a
->type
, dc
->u
.s_number
.number
);
5350 else if (dpi
->lambda_tpl_parms
)
5352 /* Show the template parm index, as that's how g++ displays
5353 these, and future proofs us against potential
5354 '[]<typename T> (T *a, T *b) {...}'. */
5355 d_append_buffer (dpi
, "auto:", 5);
5356 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5360 struct d_print_template
*hold_dpt
;
5361 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
5363 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
5364 a
= d_index_template_argument (a
, dpi
->pack_index
);
5368 d_print_error (dpi
);
5372 /* While processing this parameter, we need to pop the list
5373 of templates. This is because the template parameter may
5374 itself be a reference to a parameter of an outer
5377 hold_dpt
= dpi
->templates
;
5378 dpi
->templates
= hold_dpt
->next
;
5380 d_print_comp (dpi
, options
, a
);
5382 dpi
->templates
= hold_dpt
;
5386 case DEMANGLE_COMPONENT_TPARM_OBJ
:
5387 d_append_string (dpi
, "template parameter object for ");
5388 d_print_comp (dpi
, options
, d_left (dc
));
5391 case DEMANGLE_COMPONENT_CTOR
:
5392 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
5395 case DEMANGLE_COMPONENT_DTOR
:
5396 d_append_char (dpi
, '~');
5397 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
5400 case DEMANGLE_COMPONENT_MODULE_INIT
:
5401 d_append_string (dpi
, "initializer for module ");
5402 d_print_comp (dpi
, options
, d_left (dc
));
5405 case DEMANGLE_COMPONENT_VTABLE
:
5406 d_append_string (dpi
, "vtable for ");
5407 d_print_comp (dpi
, options
, d_left (dc
));
5410 case DEMANGLE_COMPONENT_VTT
:
5411 d_append_string (dpi
, "VTT for ");
5412 d_print_comp (dpi
, options
, d_left (dc
));
5415 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
5416 d_append_string (dpi
, "construction vtable for ");
5417 d_print_comp (dpi
, options
, d_left (dc
));
5418 d_append_string (dpi
, "-in-");
5419 d_print_comp (dpi
, options
, d_right (dc
));
5422 case DEMANGLE_COMPONENT_TYPEINFO
:
5423 d_append_string (dpi
, "typeinfo for ");
5424 d_print_comp (dpi
, options
, d_left (dc
));
5427 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
5428 d_append_string (dpi
, "typeinfo name for ");
5429 d_print_comp (dpi
, options
, d_left (dc
));
5432 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
5433 d_append_string (dpi
, "typeinfo fn for ");
5434 d_print_comp (dpi
, options
, d_left (dc
));
5437 case DEMANGLE_COMPONENT_THUNK
:
5438 d_append_string (dpi
, "non-virtual thunk to ");
5439 d_print_comp (dpi
, options
, d_left (dc
));
5442 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
5443 d_append_string (dpi
, "virtual thunk to ");
5444 d_print_comp (dpi
, options
, d_left (dc
));
5447 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
5448 d_append_string (dpi
, "covariant return thunk to ");
5449 d_print_comp (dpi
, options
, d_left (dc
));
5452 case DEMANGLE_COMPONENT_JAVA_CLASS
:
5453 d_append_string (dpi
, "java Class for ");
5454 d_print_comp (dpi
, options
, d_left (dc
));
5457 case DEMANGLE_COMPONENT_GUARD
:
5458 d_append_string (dpi
, "guard variable for ");
5459 d_print_comp (dpi
, options
, d_left (dc
));
5462 case DEMANGLE_COMPONENT_TLS_INIT
:
5463 d_append_string (dpi
, "TLS init function for ");
5464 d_print_comp (dpi
, options
, d_left (dc
));
5467 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
5468 d_append_string (dpi
, "TLS wrapper function for ");
5469 d_print_comp (dpi
, options
, d_left (dc
));
5472 case DEMANGLE_COMPONENT_REFTEMP
:
5473 d_append_string (dpi
, "reference temporary #");
5474 d_print_comp (dpi
, options
, d_right (dc
));
5475 d_append_string (dpi
, " for ");
5476 d_print_comp (dpi
, options
, d_left (dc
));
5479 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
5480 d_append_string (dpi
, "hidden alias for ");
5481 d_print_comp (dpi
, options
, d_left (dc
));
5484 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
5485 d_append_string (dpi
, "transaction clone for ");
5486 d_print_comp (dpi
, options
, d_left (dc
));
5489 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
5490 d_append_string (dpi
, "non-transaction clone for ");
5491 d_print_comp (dpi
, options
, d_left (dc
));
5494 case DEMANGLE_COMPONENT_SUB_STD
:
5495 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
5498 case DEMANGLE_COMPONENT_RESTRICT
:
5499 case DEMANGLE_COMPONENT_VOLATILE
:
5500 case DEMANGLE_COMPONENT_CONST
:
5502 struct d_print_mod
*pdpm
;
5504 /* When printing arrays, it's possible to have cases where the
5505 same CV-qualifier gets pushed on the stack multiple times.
5506 We only need to print it once. */
5508 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
5510 if (! pdpm
->printed
)
5512 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
5513 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
5514 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
5516 if (pdpm
->mod
->type
== dc
->type
)
5518 d_print_comp (dpi
, options
, d_left (dc
));
5526 case DEMANGLE_COMPONENT_REFERENCE
:
5527 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5529 /* Handle reference smashing: & + && = &. */
5530 struct demangle_component
*sub
= d_left (dc
);
5531 if (!dpi
->lambda_tpl_parms
5532 && sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
5534 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
5535 struct demangle_component
*a
;
5539 /* This is the first time SUB has been traversed.
5540 We need to capture the current templates so
5541 they can be restored if SUB is reentered as a
5543 d_save_scope (dpi
, sub
);
5544 if (d_print_saw_error (dpi
))
5549 const struct d_component_stack
*dcse
;
5550 int found_self_or_parent
= 0;
5552 /* This traversal is reentering SUB as a substition.
5553 If we are not beneath SUB or DC in the tree then we
5554 need to restore SUB's template stack temporarily. */
5555 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
5556 dcse
= dcse
->parent
)
5560 && dcse
!= dpi
->component_stack
))
5562 found_self_or_parent
= 1;
5567 if (!found_self_or_parent
)
5569 saved_templates
= dpi
->templates
;
5570 dpi
->templates
= scope
->templates
;
5571 need_template_restore
= 1;
5575 a
= d_lookup_template_argument (dpi
, sub
);
5576 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
5577 a
= d_index_template_argument (a
, dpi
->pack_index
);
5581 if (need_template_restore
)
5582 dpi
->templates
= saved_templates
;
5584 d_print_error (dpi
);
5591 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
5592 || sub
->type
== dc
->type
)
5594 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
5595 mod_inner
= d_left (sub
);
5599 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5600 case DEMANGLE_COMPONENT_POINTER
:
5601 case DEMANGLE_COMPONENT_COMPLEX
:
5602 case DEMANGLE_COMPONENT_IMAGINARY
:
5603 FNQUAL_COMPONENT_CASE
:
5606 /* We keep a list of modifiers on the stack. */
5607 struct d_print_mod dpm
;
5609 dpm
.next
= dpi
->modifiers
;
5610 dpi
->modifiers
= &dpm
;
5613 dpm
.templates
= dpi
->templates
;
5616 mod_inner
= d_left (dc
);
5618 d_print_comp (dpi
, options
, mod_inner
);
5620 /* If the modifier didn't get printed by the type, print it
5623 d_print_mod (dpi
, options
, dc
);
5625 dpi
->modifiers
= dpm
.next
;
5627 if (need_template_restore
)
5628 dpi
->templates
= saved_templates
;
5633 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5634 if ((options
& DMGL_JAVA
) == 0)
5635 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
5636 dc
->u
.s_builtin
.type
->len
);
5638 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
5639 dc
->u
.s_builtin
.type
->java_len
);
5642 case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE
:
5643 d_append_buffer (dpi
, dc
->u
.s_extended_builtin
.type
->name
,
5644 dc
->u
.s_extended_builtin
.type
->len
);
5645 d_append_num (dpi
, dc
->u
.s_extended_builtin
.arg
);
5646 if (dc
->u
.s_extended_builtin
.suffix
)
5647 d_append_buffer (dpi
, &dc
->u
.s_extended_builtin
.suffix
, 1);
5650 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5651 d_print_comp (dpi
, options
, d_left (dc
));
5654 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5656 if ((options
& DMGL_RET_POSTFIX
) != 0)
5657 d_print_function_type (dpi
,
5658 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5659 dc
, dpi
->modifiers
);
5661 /* Print return type if present */
5662 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
5663 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5665 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
5667 struct d_print_mod dpm
;
5669 /* We must pass this type down as a modifier in order to
5670 print it in the right location. */
5671 dpm
.next
= dpi
->modifiers
;
5672 dpi
->modifiers
= &dpm
;
5675 dpm
.templates
= dpi
->templates
;
5677 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5680 dpi
->modifiers
= dpm
.next
;
5685 /* In standard prefix notation, there is a space between the
5686 return type and the function signature. */
5687 if ((options
& DMGL_RET_POSTFIX
) == 0)
5688 d_append_char (dpi
, ' ');
5691 if ((options
& DMGL_RET_POSTFIX
) == 0)
5692 d_print_function_type (dpi
,
5693 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5694 dc
, dpi
->modifiers
);
5699 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5701 struct d_print_mod
*hold_modifiers
;
5702 struct d_print_mod adpm
[4];
5704 struct d_print_mod
*pdpm
;
5706 /* We must pass this type down as a modifier in order to print
5707 multi-dimensional arrays correctly. If the array itself is
5708 CV-qualified, we act as though the element type were
5709 CV-qualified. We do this by copying the modifiers down
5710 rather than fiddling pointers, so that we don't wind up
5711 with a d_print_mod higher on the stack pointing into our
5712 stack frame after we return. */
5714 hold_modifiers
= dpi
->modifiers
;
5716 adpm
[0].next
= hold_modifiers
;
5717 dpi
->modifiers
= &adpm
[0];
5719 adpm
[0].printed
= 0;
5720 adpm
[0].templates
= dpi
->templates
;
5723 pdpm
= hold_modifiers
;
5725 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
5726 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
5727 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
5729 if (! pdpm
->printed
)
5731 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5733 d_print_error (dpi
);
5738 adpm
[i
].next
= dpi
->modifiers
;
5739 dpi
->modifiers
= &adpm
[i
];
5747 d_print_comp (dpi
, options
, d_right (dc
));
5749 dpi
->modifiers
= hold_modifiers
;
5751 if (adpm
[0].printed
)
5757 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5760 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
5765 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5766 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5768 struct d_print_mod dpm
;
5770 dpm
.next
= dpi
->modifiers
;
5771 dpi
->modifiers
= &dpm
;
5774 dpm
.templates
= dpi
->templates
;
5776 d_print_comp (dpi
, options
, d_right (dc
));
5778 /* If the modifier didn't get printed by the type, print it
5781 d_print_mod (dpi
, options
, dc
);
5783 dpi
->modifiers
= dpm
.next
;
5788 case DEMANGLE_COMPONENT_ARGLIST
:
5789 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5790 if (d_left (dc
) != NULL
)
5791 d_print_comp (dpi
, options
, d_left (dc
));
5792 if (d_right (dc
) != NULL
)
5795 unsigned long int flush_count
;
5796 /* Make sure ", " isn't flushed by d_append_string, otherwise
5797 dpi->len -= 2 wouldn't work. */
5798 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5799 d_print_flush (dpi
);
5800 d_append_string (dpi
, ", ");
5802 flush_count
= dpi
->flush_count
;
5803 d_print_comp (dpi
, options
, d_right (dc
));
5804 /* If that didn't print anything (which can happen with empty
5805 template argument packs), remove the comma and space. */
5806 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5811 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5813 struct demangle_component
*type
= d_left (dc
);
5814 struct demangle_component
*list
= d_right (dc
);
5817 d_print_comp (dpi
, options
, type
);
5818 d_append_char (dpi
, '{');
5819 d_print_comp (dpi
, options
, list
);
5820 d_append_char (dpi
, '}');
5824 case DEMANGLE_COMPONENT_OPERATOR
:
5826 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5829 d_append_string (dpi
, "operator");
5830 /* Add a space before new/delete. */
5831 if (IS_LOWER (op
->name
[0]))
5832 d_append_char (dpi
, ' ');
5833 /* Omit a trailing space. */
5834 if (op
->name
[len
-1] == ' ')
5836 d_append_buffer (dpi
, op
->name
, len
);
5840 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5841 d_append_string (dpi
, "operator ");
5842 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5845 case DEMANGLE_COMPONENT_CONVERSION
:
5846 d_append_string (dpi
, "operator ");
5847 d_print_conversion (dpi
, options
, dc
);
5850 case DEMANGLE_COMPONENT_NULLARY
:
5851 d_print_expr_op (dpi
, options
, d_left (dc
));
5854 case DEMANGLE_COMPONENT_UNARY
:
5856 struct demangle_component
*op
= d_left (dc
);
5857 struct demangle_component
*operand
= d_right (dc
);
5858 const char *code
= NULL
;
5860 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5862 code
= op
->u
.s_operator
.op
->code
;
5863 if (!strcmp (code
, "ad"))
5865 /* Don't print the argument list for the address of a
5867 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5868 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5869 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5870 operand
= d_left (operand
);
5872 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5874 /* This indicates a suffix operator. */
5875 operand
= d_left (operand
);
5876 d_print_subexpr (dpi
, options
, operand
);
5877 d_print_expr_op (dpi
, options
, op
);
5882 /* For sizeof..., just print the pack length. */
5883 if (code
&& !strcmp (code
, "sZ"))
5885 struct demangle_component
*a
= d_find_pack (dpi
, operand
);
5886 int len
= d_pack_length (a
);
5887 d_append_num (dpi
, len
);
5890 else if (code
&& !strcmp (code
, "sP"))
5892 int len
= d_args_length (dpi
, operand
);
5893 d_append_num (dpi
, len
);
5897 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5898 d_print_expr_op (dpi
, options
, op
);
5901 d_append_char (dpi
, '(');
5902 d_print_cast (dpi
, options
, op
);
5903 d_append_char (dpi
, ')');
5905 if (code
&& !strcmp (code
, "gs"))
5906 /* Avoid parens after '::'. */
5907 d_print_comp (dpi
, options
, operand
);
5908 else if (code
&& (!strcmp (code
, "st") || !strcmp (code
, "nx")))
5909 /* Always print parens for sizeof (type) and noexcept(expr). */
5911 d_append_char (dpi
, '(');
5912 d_print_comp (dpi
, options
, operand
);
5913 d_append_char (dpi
, ')');
5916 d_print_subexpr (dpi
, options
, operand
);
5920 case DEMANGLE_COMPONENT_BINARY
:
5921 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5923 d_print_error (dpi
);
5927 if (op_is_new_cast (d_left (dc
)))
5929 d_print_expr_op (dpi
, options
, d_left (dc
));
5930 d_append_char (dpi
, '<');
5931 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5932 d_append_string (dpi
, ">(");
5933 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5934 d_append_char (dpi
, ')');
5938 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5941 if (d_maybe_print_designated_init (dpi
, options
, dc
))
5944 /* We wrap an expression which uses the greater-than operator in
5945 an extra layer of parens so that it does not get confused
5946 with the '>' which ends the template parameters. */
5947 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5948 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5949 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5950 d_append_char (dpi
, '(');
5952 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5953 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5955 /* Function call used in an expression should not have printed types
5956 of the function arguments. Values of the function arguments still
5957 get printed below. */
5959 const struct demangle_component
*func
= d_left (d_right (dc
));
5961 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5962 d_print_error (dpi
);
5963 d_print_subexpr (dpi
, options
, d_left (func
));
5966 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5967 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5969 d_append_char (dpi
, '[');
5970 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5971 d_append_char (dpi
, ']');
5975 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5976 d_print_expr_op (dpi
, options
, d_left (dc
));
5977 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
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
, ')');
5987 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5988 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5989 d_print_error (dpi
);
5992 case DEMANGLE_COMPONENT_TRINARY
:
5993 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5994 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5996 d_print_error (dpi
);
5999 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
6001 if (d_maybe_print_designated_init (dpi
, options
, dc
))
6004 struct demangle_component
*op
= d_left (dc
);
6005 struct demangle_component
*first
= d_left (d_right (dc
));
6006 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
6007 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
6009 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
6011 d_print_subexpr (dpi
, options
, first
);
6012 d_print_expr_op (dpi
, options
, op
);
6013 d_print_subexpr (dpi
, options
, second
);
6014 d_append_string (dpi
, " : ");
6015 d_print_subexpr (dpi
, options
, third
);
6019 d_append_string (dpi
, "new ");
6020 if (d_left (first
) != NULL
)
6022 d_print_subexpr (dpi
, options
, first
);
6023 d_append_char (dpi
, ' ');
6025 d_print_comp (dpi
, options
, second
);
6027 d_print_subexpr (dpi
, options
, third
);
6032 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
6033 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
6034 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
6035 d_print_error (dpi
);
6038 case DEMANGLE_COMPONENT_LITERAL
:
6039 case DEMANGLE_COMPONENT_LITERAL_NEG
:
6041 enum d_builtin_type_print tp
;
6043 /* For some builtin types, produce simpler output. */
6044 tp
= D_PRINT_DEFAULT
;
6045 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
6047 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
6051 case D_PRINT_UNSIGNED
:
6053 case D_PRINT_UNSIGNED_LONG
:
6054 case D_PRINT_LONG_LONG
:
6055 case D_PRINT_UNSIGNED_LONG_LONG
:
6056 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
6058 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
6059 d_append_char (dpi
, '-');
6060 d_print_comp (dpi
, options
, d_right (dc
));
6065 case D_PRINT_UNSIGNED
:
6066 d_append_char (dpi
, 'u');
6069 d_append_char (dpi
, 'l');
6071 case D_PRINT_UNSIGNED_LONG
:
6072 d_append_string (dpi
, "ul");
6074 case D_PRINT_LONG_LONG
:
6075 d_append_string (dpi
, "ll");
6077 case D_PRINT_UNSIGNED_LONG_LONG
:
6078 d_append_string (dpi
, "ull");
6086 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
6087 && d_right (dc
)->u
.s_name
.len
== 1
6088 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
6090 switch (d_right (dc
)->u
.s_name
.s
[0])
6093 d_append_string (dpi
, "false");
6096 d_append_string (dpi
, "true");
6109 d_append_char (dpi
, '(');
6110 d_print_comp (dpi
, options
, d_left (dc
));
6111 d_append_char (dpi
, ')');
6112 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
6113 d_append_char (dpi
, '-');
6114 if (tp
== D_PRINT_FLOAT
)
6115 d_append_char (dpi
, '[');
6116 d_print_comp (dpi
, options
, d_right (dc
));
6117 if (tp
== D_PRINT_FLOAT
)
6118 d_append_char (dpi
, ']');
6122 case DEMANGLE_COMPONENT_VENDOR_EXPR
:
6123 d_print_comp (dpi
, options
, d_left (dc
));
6124 d_append_char (dpi
, '(');
6125 d_print_comp (dpi
, options
, d_right (dc
));
6126 d_append_char (dpi
, ')');
6129 case DEMANGLE_COMPONENT_NUMBER
:
6130 d_append_num (dpi
, dc
->u
.s_number
.number
);
6133 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
6134 d_append_string (dpi
, "java resource ");
6135 d_print_comp (dpi
, options
, d_left (dc
));
6138 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
6139 d_print_comp (dpi
, options
, d_left (dc
));
6140 d_print_comp (dpi
, options
, d_right (dc
));
6143 case DEMANGLE_COMPONENT_CHARACTER
:
6144 d_append_char (dpi
, dc
->u
.s_character
.character
);
6147 case DEMANGLE_COMPONENT_DECLTYPE
:
6148 d_append_string (dpi
, "decltype (");
6149 d_print_comp (dpi
, options
, d_left (dc
));
6150 d_append_char (dpi
, ')');
6153 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
6155 struct demangle_component
*a
= NULL
;
6157 if (!dpi
->lambda_tpl_parms
)
6158 a
= d_find_pack (dpi
, d_left (dc
));
6161 /* d_find_pack won't find anything if the only packs involved
6162 in this expansion are function parameter packs; in that
6163 case, just print the pattern and "...". */
6164 d_print_subexpr (dpi
, options
, d_left (dc
));
6165 d_append_string (dpi
, "...");
6169 int len
= d_pack_length (a
);
6173 for (i
= 0; i
< len
; ++i
)
6176 d_append_string (dpi
, ", ");
6177 dpi
->pack_index
= i
;
6178 d_print_comp (dpi
, options
, dc
);
6184 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
6186 long num
= dc
->u
.s_number
.number
;
6188 d_append_string (dpi
, "this");
6191 d_append_string (dpi
, "{parm#");
6192 d_append_num (dpi
, num
);
6193 d_append_char (dpi
, '}');
6198 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
6199 d_append_string (dpi
, "global constructors keyed to ");
6200 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
6203 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
6204 d_append_string (dpi
, "global destructors keyed to ");
6205 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
6208 case DEMANGLE_COMPONENT_LAMBDA
:
6210 d_append_string (dpi
, "{lambda");
6211 struct demangle_component
*parms
= dc
->u
.s_unary_num
.sub
;
6212 struct d_print_template dpt
;
6213 /* Generic lambda auto parms are mangled as the (synthedic) template
6214 type parm they are. We need to tell the printer that (a) we're in
6215 a lambda, and (b) the number of synthetic parms. */
6216 int saved_tpl_parms
= dpi
->lambda_tpl_parms
;
6217 dpi
->lambda_tpl_parms
= 0;
6218 /* Hang any lambda head as-if template args. */
6219 dpt
.template_decl
= NULL
;
6220 dpt
.next
= dpi
->templates
;
6221 dpi
->templates
= &dpt
;
6222 if (parms
&& parms
->type
== DEMANGLE_COMPONENT_TEMPLATE_HEAD
)
6224 dpt
.template_decl
= parms
;
6226 d_append_char (dpi
, '<');
6227 struct demangle_component
*parm
;
6228 for (parm
= d_left (parms
); parm
; parm
= d_right (parm
))
6230 if (dpi
->lambda_tpl_parms
++)
6231 d_append_string (dpi
, ", ");
6232 d_print_comp (dpi
, options
, parm
);
6233 d_append_char (dpi
, ' ');
6234 if (parm
->type
== DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
)
6235 parm
= d_left (parm
);
6236 d_print_lambda_parm_name (dpi
, parm
->type
,
6237 dpi
->lambda_tpl_parms
- 1);
6239 d_append_char (dpi
, '>');
6241 parms
= d_right (parms
);
6243 dpi
->lambda_tpl_parms
++;
6245 d_append_char (dpi
, '(');
6246 d_print_comp (dpi
, options
, parms
);
6247 dpi
->lambda_tpl_parms
= saved_tpl_parms
;
6248 dpi
->templates
= dpt
.next
;
6249 d_append_string (dpi
, ")#");
6250 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
6251 d_append_char (dpi
, '}');
6255 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
6256 d_append_string (dpi
, "{unnamed type#");
6257 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
6258 d_append_char (dpi
, '}');
6261 case DEMANGLE_COMPONENT_CLONE
:
6262 d_print_comp (dpi
, options
, d_left (dc
));
6263 d_append_string (dpi
, " [clone ");
6264 d_print_comp (dpi
, options
, d_right (dc
));
6265 d_append_char (dpi
, ']');
6268 case DEMANGLE_COMPONENT_FRIEND
:
6269 d_print_comp (dpi
, options
, d_left (dc
));
6270 d_append_string (dpi
, "[friend]");
6273 case DEMANGLE_COMPONENT_TEMPLATE_HEAD
:
6275 d_append_char (dpi
, '<');
6277 struct demangle_component
*parm
;
6278 for (parm
= d_left (dc
); parm
; parm
= d_right (parm
))
6281 d_append_string (dpi
, ", ");
6282 d_print_comp (dpi
, options
, parm
);
6284 d_append_char (dpi
, '>');
6288 case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM
:
6289 d_append_string (dpi
, "typename");
6292 case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM
:
6293 d_print_comp (dpi
, options
, d_left (dc
));
6296 case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM
:
6297 d_append_string (dpi
, "template");
6298 d_print_comp (dpi
, options
, d_left (dc
));
6299 d_append_string (dpi
, " class");
6302 case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM
:
6303 d_print_comp (dpi
, options
, d_left (dc
));
6304 d_append_string (dpi
, "...");
6307 case DEMANGLE_COMPONENT_CONSTRAINTS
:
6308 d_print_comp (dpi
, options
, d_left (dc
));
6309 d_append_string (dpi
, " requires ");
6310 d_print_comp (dpi
, options
, d_right (dc
));
6314 d_print_error (dpi
);
6320 d_print_comp (struct d_print_info
*dpi
, int options
,
6321 struct demangle_component
*dc
)
6323 struct d_component_stack self
;
6324 if (dc
== NULL
|| dc
->d_printing
> 1 || dpi
->recursion
> MAX_RECURSION_COUNT
)
6326 d_print_error (dpi
);
6334 self
.parent
= dpi
->component_stack
;
6335 dpi
->component_stack
= &self
;
6337 d_print_comp_inner (dpi
, options
, dc
);
6339 dpi
->component_stack
= self
.parent
;
6344 /* Print a Java dentifier. For Java we try to handle encoded extended
6345 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
6346 so we don't it for C++. Characters are encoded as
6350 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
6356 for (p
= name
; p
< end
; ++p
)
6367 for (q
= p
+ 3; q
< end
; ++q
)
6373 else if (*q
>= 'A' && *q
<= 'F')
6374 dig
= *q
- 'A' + 10;
6375 else if (*q
>= 'a' && *q
<= 'f')
6376 dig
= *q
- 'a' + 10;
6382 /* If the Unicode character is larger than 256, we don't try
6383 to deal with it here. FIXME. */
6384 if (q
< end
&& *q
== '_' && c
< 256)
6386 d_append_char (dpi
, c
);
6392 d_append_char (dpi
, *p
);
6396 /* Print a list of modifiers. SUFFIX is 1 if we are printing
6397 qualifiers on this after printing a function. */
6400 d_print_mod_list (struct d_print_info
*dpi
, int options
,
6401 struct d_print_mod
*mods
, int suffix
)
6403 struct d_print_template
*hold_dpt
;
6405 if (mods
== NULL
|| d_print_saw_error (dpi
))
6410 && (is_fnqual_component_type (mods
->mod
->type
))))
6412 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
6418 hold_dpt
= dpi
->templates
;
6419 dpi
->templates
= mods
->templates
;
6421 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
6423 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
6424 dpi
->templates
= hold_dpt
;
6427 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
6429 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
6430 dpi
->templates
= hold_dpt
;
6433 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
6435 struct d_print_mod
*hold_modifiers
;
6436 struct demangle_component
*dc
;
6438 /* When this is on the modifier stack, we have pulled any
6439 qualifiers off the right argument already. Otherwise, we
6440 print it as usual, but don't let the left argument see any
6443 hold_modifiers
= dpi
->modifiers
;
6444 dpi
->modifiers
= NULL
;
6445 d_print_comp (dpi
, options
, d_left (mods
->mod
));
6446 dpi
->modifiers
= hold_modifiers
;
6448 if ((options
& DMGL_JAVA
) == 0)
6449 d_append_string (dpi
, "::");
6451 d_append_char (dpi
, '.');
6453 dc
= d_right (mods
->mod
);
6455 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
6457 d_append_string (dpi
, "{default arg#");
6458 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
6459 d_append_string (dpi
, "}::");
6460 dc
= dc
->u
.s_unary_num
.sub
;
6463 while (is_fnqual_component_type (dc
->type
))
6466 d_print_comp (dpi
, options
, dc
);
6468 dpi
->templates
= hold_dpt
;
6472 d_print_mod (dpi
, options
, mods
->mod
);
6474 dpi
->templates
= hold_dpt
;
6476 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
6479 /* Print a modifier. */
6482 d_print_mod (struct d_print_info
*dpi
, int options
,
6483 struct demangle_component
*mod
)
6487 case DEMANGLE_COMPONENT_RESTRICT
:
6488 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6489 d_append_string (dpi
, " restrict");
6491 case DEMANGLE_COMPONENT_VOLATILE
:
6492 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6493 d_append_string (dpi
, " volatile");
6495 case DEMANGLE_COMPONENT_CONST
:
6496 case DEMANGLE_COMPONENT_CONST_THIS
:
6497 d_append_string (dpi
, " const");
6499 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
6500 d_append_string (dpi
, " transaction_safe");
6502 case DEMANGLE_COMPONENT_NOEXCEPT
:
6503 d_append_string (dpi
, " noexcept");
6506 d_append_char (dpi
, '(');
6507 d_print_comp (dpi
, options
, d_right (mod
));
6508 d_append_char (dpi
, ')');
6511 case DEMANGLE_COMPONENT_THROW_SPEC
:
6512 d_append_string (dpi
, " throw");
6515 d_append_char (dpi
, '(');
6516 d_print_comp (dpi
, options
, d_right (mod
));
6517 d_append_char (dpi
, ')');
6520 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
6521 d_append_char (dpi
, ' ');
6522 d_print_comp (dpi
, options
, d_right (mod
));
6524 case DEMANGLE_COMPONENT_POINTER
:
6525 /* There is no pointer symbol in Java. */
6526 if ((options
& DMGL_JAVA
) == 0)
6527 d_append_char (dpi
, '*');
6529 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6530 /* For the ref-qualifier, put a space before the &. */
6531 d_append_char (dpi
, ' ');
6533 case DEMANGLE_COMPONENT_REFERENCE
:
6534 d_append_char (dpi
, '&');
6536 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6537 d_append_char (dpi
, ' ');
6539 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
6540 d_append_string (dpi
, "&&");
6542 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
6544 case DEMANGLE_COMPONENT_COMPLEX
:
6545 d_append_string (dpi
, " _Complex");
6547 case DEMANGLE_COMPONENT_IMAGINARY
:
6548 d_append_string (dpi
, " _Imaginary");
6550 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
6551 if (d_last_char (dpi
) != '(')
6552 d_append_char (dpi
, ' ');
6553 d_print_comp (dpi
, options
, d_left (mod
));
6554 d_append_string (dpi
, "::*");
6556 case DEMANGLE_COMPONENT_TYPED_NAME
:
6557 d_print_comp (dpi
, options
, d_left (mod
));
6559 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
6560 d_append_string (dpi
, " __vector(");
6561 d_print_comp (dpi
, options
, d_left (mod
));
6562 d_append_char (dpi
, ')');
6566 /* Otherwise, we have something that won't go back on the
6567 modifier stack, so we can just print it. */
6568 d_print_comp (dpi
, options
, mod
);
6573 /* Print a function type, except for the return type. */
6576 d_print_function_type (struct d_print_info
*dpi
, int options
,
6577 struct demangle_component
*dc
,
6578 struct d_print_mod
*mods
)
6583 struct d_print_mod
*p
;
6584 struct d_print_mod
*hold_modifiers
;
6589 for (p
= mods
; p
!= NULL
; p
= p
->next
)
6594 switch (p
->mod
->type
)
6596 case DEMANGLE_COMPONENT_POINTER
:
6597 case DEMANGLE_COMPONENT_REFERENCE
:
6598 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
6601 case DEMANGLE_COMPONENT_RESTRICT
:
6602 case DEMANGLE_COMPONENT_VOLATILE
:
6603 case DEMANGLE_COMPONENT_CONST
:
6604 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
6605 case DEMANGLE_COMPONENT_COMPLEX
:
6606 case DEMANGLE_COMPONENT_IMAGINARY
:
6607 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
6611 case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION
:
6625 if (d_last_char (dpi
) != '('
6626 && d_last_char (dpi
) != '*')
6629 if (need_space
&& d_last_char (dpi
) != ' ')
6630 d_append_char (dpi
, ' ');
6631 d_append_char (dpi
, '(');
6634 hold_modifiers
= dpi
->modifiers
;
6635 dpi
->modifiers
= NULL
;
6637 d_print_mod_list (dpi
, options
, mods
, 0);
6640 d_append_char (dpi
, ')');
6642 d_append_char (dpi
, '(');
6644 d_append_string (dpi
, "this ");
6646 if (d_right (dc
) != NULL
)
6647 d_print_comp (dpi
, options
, d_right (dc
));
6649 d_append_char (dpi
, ')');
6651 d_print_mod_list (dpi
, options
, mods
, 1);
6653 dpi
->modifiers
= hold_modifiers
;
6656 /* Print an array type, except for the element type. */
6659 d_print_array_type (struct d_print_info
*dpi
, int options
,
6660 struct demangle_component
*dc
,
6661 struct d_print_mod
*mods
)
6669 struct d_print_mod
*p
;
6672 for (p
= mods
; p
!= NULL
; p
= p
->next
)
6676 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
6691 d_append_string (dpi
, " (");
6693 d_print_mod_list (dpi
, options
, mods
, 0);
6696 d_append_char (dpi
, ')');
6700 d_append_char (dpi
, ' ');
6702 d_append_char (dpi
, '[');
6704 if (d_left (dc
) != NULL
)
6705 d_print_comp (dpi
, options
, d_left (dc
));
6707 d_append_char (dpi
, ']');
6710 /* Print an operator in an expression. */
6713 d_print_expr_op (struct d_print_info
*dpi
, int options
,
6714 struct demangle_component
*dc
)
6716 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
6717 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
6718 dc
->u
.s_operator
.op
->len
);
6720 d_print_comp (dpi
, options
, dc
);
6726 d_print_cast (struct d_print_info
*dpi
, int options
,
6727 struct demangle_component
*dc
)
6729 d_print_comp (dpi
, options
, d_left (dc
));
6732 /* Print a conversion operator. */
6735 d_print_conversion (struct d_print_info
*dpi
, int options
,
6736 struct demangle_component
*dc
)
6738 struct d_print_template dpt
;
6740 /* For a conversion operator, we need the template parameters from
6741 the enclosing template in scope for processing the type. */
6742 if (dpi
->current_template
!= NULL
)
6744 dpt
.next
= dpi
->templates
;
6745 dpi
->templates
= &dpt
;
6746 dpt
.template_decl
= dpi
->current_template
;
6749 d_print_comp (dpi
, options
, d_left (dc
));
6751 if (dpi
->current_template
!= NULL
)
6752 dpi
->templates
= dpt
.next
;
6755 /* Initialize the information structure we use to pass around
6758 CP_STATIC_IF_GLIBCPP_V3
6760 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
6764 di
->send
= mangled
+ len
;
6765 di
->options
= options
;
6769 /* We cannot need more components than twice the number of chars in
6770 the mangled string. Most components correspond directly to
6771 chars, but the ARGLIST types are exceptions. */
6772 di
->num_comps
= 2 * len
;
6775 /* Similarly, we cannot need more substitutions than there are
6776 chars in the mangled string. */
6780 di
->last_name
= NULL
;
6783 di
->is_expression
= 0;
6784 di
->is_conversion
= 0;
6785 di
->recursion_level
= 0;
6788 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
6789 mangled name, return strings in repeated callback giving the demangled
6790 name. OPTIONS is the usual libiberty demangler options. On success,
6791 this returns 1. On failure, returns 0. */
6794 d_demangle_callback (const char *mangled
, int options
,
6795 demangle_callbackref callback
, void *opaque
)
6806 struct demangle_component
*dc
;
6809 if (mangled
[0] == '_' && mangled
[1] == 'Z')
6811 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
6812 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
6813 && (mangled
[9] == 'D' || mangled
[9] == 'I')
6814 && mangled
[10] == '_')
6815 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
6818 if ((options
& DMGL_TYPES
) == 0)
6823 di
.unresolved_name_state
= 1;
6826 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
6828 /* PR 87675 - Check for a mangled string that is so long
6829 that we do not have enough stack space to demangle it. */
6830 if (((options
& DMGL_NO_RECURSE_LIMIT
) == 0)
6831 /* This check is a bit arbitrary, since what we really want to do is to
6832 compare the sizes of the di.comps and di.subs arrays against the
6833 amount of stack space remaining. But there is no portable way to do
6834 this, so instead we use the recursion limit as a guide to the maximum
6835 size of the arrays. */
6836 && (unsigned long) di
.num_comps
> DEMANGLE_RECURSION_LIMIT
)
6838 /* FIXME: We need a way to indicate that a stack limit has been reached. */
6843 #ifdef CP_DYNAMIC_ARRAYS
6844 __extension__
struct demangle_component comps
[di
.num_comps
];
6845 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6850 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6851 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6857 dc
= cplus_demangle_type (&di
);
6860 dc
= cplus_demangle_mangled_name (&di
, 1);
6862 case DCT_GLOBAL_CTORS
:
6863 case DCT_GLOBAL_DTORS
:
6864 d_advance (&di
, 11);
6865 dc
= d_make_comp (&di
,
6866 (type
== DCT_GLOBAL_CTORS
6867 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
6868 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
6869 d_make_demangle_mangled_name (&di
, d_str (&di
)),
6871 d_advance (&di
, strlen (d_str (&di
)));
6874 abort (); /* We have listed all the cases. */
6877 /* If DMGL_PARAMS is set, then if we didn't consume the entire
6878 mangled string, then we didn't successfully demangle it. If
6879 DMGL_PARAMS is not set, we didn't look at the trailing
6881 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
6884 /* See discussion in d_unresolved_name. */
6885 if (dc
== NULL
&& di
.unresolved_name_state
== -1)
6887 di
.unresolved_name_state
= 0;
6891 #ifdef CP_DEMANGLE_DEBUG
6895 status
= (dc
!= NULL
)
6896 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6903 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6904 name, return a buffer allocated with malloc holding the demangled
6905 name. OPTIONS is the usual libiberty demangler options. On
6906 success, this sets *PALC to the allocated size of the returned
6907 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6908 a memory allocation failure, and returns NULL. */
6911 d_demangle (const char *mangled
, int options
, size_t *palc
)
6913 struct d_growable_string dgs
;
6916 d_growable_string_init (&dgs
, 0);
6918 status
= d_demangle_callback (mangled
, options
,
6919 d_growable_string_callback_adapter
, &dgs
);
6927 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6931 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6933 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6935 /* ia64 ABI-mandated entry point in the C++ runtime library for
6936 performing demangling. MANGLED_NAME is a NUL-terminated character
6937 string containing the name to be demangled.
6939 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6940 *LENGTH bytes, into which the demangled name is stored. If
6941 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6942 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6943 is placed in a region of memory allocated with malloc.
6945 If LENGTH is non-NULL, the length of the buffer containing the
6946 demangled name, is placed in *LENGTH.
6948 The return value is a pointer to the start of the NUL-terminated
6949 demangled name, or NULL if the demangling fails. The caller is
6950 responsible for deallocating this memory using free.
6952 *STATUS is set to one of the following values:
6953 0: The demangling operation succeeded.
6954 -1: A memory allocation failure occurred.
6955 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6956 -3: One of the arguments is invalid.
6958 The demangling is performed using the C++ ABI mangling rules, with
6962 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6963 size_t *length
, int *status
)
6968 if (mangled_name
== NULL
)
6975 if (output_buffer
!= NULL
&& length
== NULL
)
6982 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6984 if (demangled
== NULL
)
6996 if (output_buffer
== NULL
)
7003 if (strlen (demangled
) < *length
)
7005 strcpy (output_buffer
, demangled
);
7007 demangled
= output_buffer
;
7011 free (output_buffer
);
7022 extern int __gcclibcxx_demangle_callback (const char *,
7024 (const char *, size_t, void *),
7027 /* Alternative, allocationless entry point in the C++ runtime library
7028 for performing demangling. MANGLED_NAME is a NUL-terminated character
7029 string containing the name to be demangled.
7031 CALLBACK is a callback function, called with demangled string
7032 segments as demangling progresses; it is called at least once,
7033 but may be called more than once. OPAQUE is a generalized pointer
7034 used as a callback argument.
7036 The return code is one of the following values, equivalent to
7037 the STATUS values of __cxa_demangle() (excluding -1, since this
7038 function performs no memory allocations):
7039 0: The demangling operation succeeded.
7040 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
7041 -3: One of the arguments is invalid.
7043 The demangling is performed using the C++ ABI mangling rules, with
7047 __gcclibcxx_demangle_callback (const char *mangled_name
,
7048 void (*callback
) (const char *, size_t, void *),
7053 if (mangled_name
== NULL
|| callback
== NULL
)
7056 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
7064 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
7066 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
7067 mangled name, return a buffer allocated with malloc holding the
7068 demangled name. Otherwise, return NULL. */
7071 cplus_demangle_v3 (const char *mangled
, int options
)
7075 return d_demangle (mangled
, options
, &alc
);
7079 cplus_demangle_v3_callback (const char *mangled
, int options
,
7080 demangle_callbackref callback
, void *opaque
)
7082 return d_demangle_callback (mangled
, options
, callback
, opaque
);
7085 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
7086 conventions, but the output formatting is a little different.
7087 This instructs the C++ demangler not to emit pointer characters ("*"), to
7088 use Java's namespace separator symbol ("." instead of "::"), and to output
7089 JArray<TYPE> as TYPE[]. */
7092 java_demangle_v3 (const char *mangled
)
7096 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
7100 java_demangle_v3_callback (const char *mangled
,
7101 demangle_callbackref callback
, void *opaque
)
7103 return d_demangle_callback (mangled
,
7104 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
7108 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
7110 #ifndef IN_GLIBCPP_V3
7112 /* Demangle a string in order to find out whether it is a constructor
7113 or destructor. Return non-zero on success. Set *CTOR_KIND and
7114 *DTOR_KIND appropriately. */
7117 is_ctor_or_dtor (const char *mangled
,
7118 enum gnu_v3_ctor_kinds
*ctor_kind
,
7119 enum gnu_v3_dtor_kinds
*dtor_kind
)
7122 struct demangle_component
*dc
;
7125 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
7126 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
7128 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
7131 #ifdef CP_DYNAMIC_ARRAYS
7132 __extension__
struct demangle_component comps
[di
.num_comps
];
7133 __extension__
struct demangle_component
*subs
[di
.num_subs
];
7138 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
7139 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
7142 dc
= cplus_demangle_mangled_name (&di
, 1);
7144 /* Note that because we did not pass DMGL_PARAMS, we don't expect
7145 to demangle the entire string. */
7152 /* These cannot appear on a constructor or destructor. */
7153 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
7154 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
7155 case DEMANGLE_COMPONENT_CONST_THIS
:
7156 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
7157 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
7161 case DEMANGLE_COMPONENT_TYPED_NAME
:
7162 case DEMANGLE_COMPONENT_TEMPLATE
:
7165 case DEMANGLE_COMPONENT_QUAL_NAME
:
7166 case DEMANGLE_COMPONENT_LOCAL_NAME
:
7169 case DEMANGLE_COMPONENT_CTOR
:
7170 *ctor_kind
= dc
->u
.s_ctor
.kind
;
7174 case DEMANGLE_COMPONENT_DTOR
:
7175 *dtor_kind
= dc
->u
.s_dtor
.kind
;
7186 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
7187 name. A non-zero return indicates the type of constructor. */
7189 enum gnu_v3_ctor_kinds
7190 is_gnu_v3_mangled_ctor (const char *name
)
7192 enum gnu_v3_ctor_kinds ctor_kind
;
7193 enum gnu_v3_dtor_kinds dtor_kind
;
7195 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
7196 return (enum gnu_v3_ctor_kinds
) 0;
7201 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
7202 name. A non-zero return indicates the type of destructor. */
7204 enum gnu_v3_dtor_kinds
7205 is_gnu_v3_mangled_dtor (const char *name
)
7207 enum gnu_v3_ctor_kinds ctor_kind
;
7208 enum gnu_v3_dtor_kinds dtor_kind
;
7210 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
7211 return (enum gnu_v3_dtor_kinds
) 0;
7215 #endif /* IN_GLIBCPP_V3 */
7217 #ifdef STANDALONE_DEMANGLER
7220 #include "dyn-string.h"
7222 static void print_usage (FILE* fp
, int exit_value
);
7224 #define IS_ALPHA(CHAR) \
7225 (((CHAR) >= 'a' && (CHAR) <= 'z') \
7226 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
7228 /* Non-zero if CHAR is a character than can occur in a mangled name. */
7229 #define is_mangled_char(CHAR) \
7230 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
7231 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
7233 /* The name of this program, as invoked. */
7234 const char* program_name
;
7236 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
7239 print_usage (FILE* fp
, int exit_value
)
7241 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
7242 fprintf (fp
, "Options:\n");
7243 fprintf (fp
, " -h,--help Display this message.\n");
7244 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
7245 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
7246 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
7251 /* Option specification for getopt_long. */
7252 static const struct option long_options
[] =
7254 { "help", no_argument
, NULL
, 'h' },
7255 { "no-params", no_argument
, NULL
, 'p' },
7256 { "verbose", no_argument
, NULL
, 'v' },
7257 { NULL
, no_argument
, NULL
, 0 },
7260 /* Main entry for a demangling filter executable. It will demangle
7261 its command line arguments, if any. If none are provided, it will
7262 filter stdin to stdout, replacing any recognized mangled C++ names
7263 with their demangled equivalents. */
7266 main (int argc
, char *argv
[])
7270 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
7272 /* Use the program name of this program, as invoked. */
7273 program_name
= argv
[0];
7275 /* Parse options. */
7278 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
7281 case '?': /* Unrecognized option. */
7282 print_usage (stderr
, 1);
7286 print_usage (stdout
, 0);
7290 options
&= ~ DMGL_PARAMS
;
7294 options
|= DMGL_VERBOSE
;
7298 while (opt_char
!= -1);
7301 /* No command line arguments were provided. Filter stdin. */
7303 dyn_string_t mangled
= dyn_string_new (3);
7306 /* Read all of input. */
7307 while (!feof (stdin
))
7311 /* Pile characters into mangled until we hit one that can't
7312 occur in a mangled name. */
7314 while (!feof (stdin
) && is_mangled_char (c
))
7316 dyn_string_append_char (mangled
, c
);
7322 if (dyn_string_length (mangled
) > 0)
7324 #ifdef IN_GLIBCPP_V3
7325 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
7327 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
7337 /* It might not have been a mangled name. Print the
7339 fputs (dyn_string_buf (mangled
), stdout
);
7342 dyn_string_clear (mangled
);
7345 /* If we haven't hit EOF yet, we've read one character that
7346 can't occur in a mangled name, so print it out. */
7351 dyn_string_delete (mangled
);
7354 /* Demangle command line arguments. */
7356 /* Loop over command line arguments. */
7357 for (i
= optind
; i
< argc
; ++i
)
7360 #ifdef IN_GLIBCPP_V3
7364 /* Attempt to demangle. */
7365 #ifdef IN_GLIBCPP_V3
7366 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
7368 s
= cplus_demangle_v3 (argv
[i
], options
);
7371 /* If it worked, print the demangled name. */
7379 #ifdef IN_GLIBCPP_V3
7380 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
7382 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
7391 #endif /* STANDALONE_DEMANGLER */