1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003-2017 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 http://www.codesourcery.com/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
196 #define CP_DYNAMIC_ARRAYS
197 #endif /* __STDC__VERSION >= 199901L */
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 /* Non-zero if we're printing a lambda argument. A template
351 parameter reference actually means 'auto'. */
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
*);
430 static struct demangle_component
*d_nested_name (struct d_info
*);
432 static struct demangle_component
*d_prefix (struct d_info
*);
434 static struct demangle_component
*d_unqualified_name (struct d_info
*);
436 static struct demangle_component
*d_source_name (struct d_info
*);
438 static int d_number (struct d_info
*);
440 static struct demangle_component
*d_identifier (struct d_info
*, int);
442 static struct demangle_component
*d_operator_name (struct d_info
*);
444 static struct demangle_component
*d_special_name (struct d_info
*);
446 static struct demangle_component
*d_parmlist (struct d_info
*);
448 static int d_call_offset (struct d_info
*, int);
450 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
452 static struct demangle_component
**
453 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
455 static struct demangle_component
*
456 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
458 static struct demangle_component
*
459 d_function_type (struct d_info
*);
461 static struct demangle_component
*
462 d_bare_function_type (struct d_info
*, int);
464 static struct demangle_component
*
465 d_class_enum_type (struct d_info
*);
467 static struct demangle_component
*d_array_type (struct d_info
*);
469 static struct demangle_component
*d_vector_type (struct d_info
*);
471 static struct demangle_component
*
472 d_pointer_to_member_type (struct d_info
*);
474 static struct demangle_component
*
475 d_template_param (struct d_info
*);
477 static struct demangle_component
*d_template_args (struct d_info
*);
478 static struct demangle_component
*d_template_args_1 (struct d_info
*);
480 static struct demangle_component
*
481 d_template_arg (struct d_info
*);
483 static struct demangle_component
*d_expression (struct d_info
*);
485 static struct demangle_component
*d_expr_primary (struct d_info
*);
487 static struct demangle_component
*d_local_name (struct d_info
*);
489 static int d_discriminator (struct d_info
*);
491 static struct demangle_component
*d_lambda (struct d_info
*);
493 static struct demangle_component
*d_unnamed_type (struct d_info
*);
495 static struct demangle_component
*
496 d_clone_suffix (struct d_info
*, struct demangle_component
*);
499 d_add_substitution (struct d_info
*, struct demangle_component
*);
501 static struct demangle_component
*d_substitution (struct d_info
*, int);
503 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
505 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
507 static void d_growable_string_init (struct d_growable_string
*, size_t);
510 d_growable_string_resize (struct d_growable_string
*, size_t);
513 d_growable_string_append_buffer (struct d_growable_string
*,
514 const char *, size_t);
516 d_growable_string_callback_adapter (const char *, size_t, void *);
519 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
520 const struct demangle_component
*);
522 static inline void d_print_error (struct d_print_info
*);
524 static inline int d_print_saw_error (struct d_print_info
*);
526 static inline void d_print_flush (struct d_print_info
*);
528 static inline void d_append_char (struct d_print_info
*, char);
530 static inline void d_append_buffer (struct d_print_info
*,
531 const char *, size_t);
533 static inline void d_append_string (struct d_print_info
*, const char *);
535 static inline char d_last_char (struct d_print_info
*);
538 d_print_comp (struct d_print_info
*, int, struct demangle_component
*);
541 d_print_java_identifier (struct d_print_info
*, const char *, int);
544 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
547 d_print_mod (struct d_print_info
*, int, struct demangle_component
*);
550 d_print_function_type (struct d_print_info
*, int,
551 struct demangle_component
*,
552 struct d_print_mod
*);
555 d_print_array_type (struct d_print_info
*, int,
556 struct demangle_component
*,
557 struct d_print_mod
*);
560 d_print_expr_op (struct d_print_info
*, int, struct demangle_component
*);
562 static void d_print_cast (struct d_print_info
*, int,
563 struct demangle_component
*);
564 static void d_print_conversion (struct d_print_info
*, int,
565 struct demangle_component
*);
567 static int d_demangle_callback (const char *, int,
568 demangle_callbackref
, void *);
569 static char *d_demangle (const char *, int, size_t *);
571 /* True iff TYPE is a demangling component representing a
572 function-type-qualifier. */
575 is_fnqual_component_type (enum demangle_component_type type
)
577 return (type
== DEMANGLE_COMPONENT_RESTRICT_THIS
578 || type
== DEMANGLE_COMPONENT_VOLATILE_THIS
579 || type
== DEMANGLE_COMPONENT_CONST_THIS
580 || type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
581 || type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
582 || type
== DEMANGLE_COMPONENT_NOEXCEPT
583 || type
== DEMANGLE_COMPONENT_THROW_SPEC
584 || type
== DEMANGLE_COMPONENT_REFERENCE_THIS
);
587 #define FNQUAL_COMPONENT_CASE \
588 case DEMANGLE_COMPONENT_RESTRICT_THIS: \
589 case DEMANGLE_COMPONENT_VOLATILE_THIS: \
590 case DEMANGLE_COMPONENT_CONST_THIS: \
591 case DEMANGLE_COMPONENT_REFERENCE_THIS: \
592 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \
593 case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \
594 case DEMANGLE_COMPONENT_NOEXCEPT: \
595 case DEMANGLE_COMPONENT_THROW_SPEC
597 #ifdef CP_DEMANGLE_DEBUG
600 d_dump (struct demangle_component
*dc
, int indent
)
607 printf ("failed demangling\n");
611 for (i
= 0; i
< indent
; ++i
)
616 case DEMANGLE_COMPONENT_NAME
:
617 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
619 case DEMANGLE_COMPONENT_TAGGED_NAME
:
620 printf ("tagged name\n");
621 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
622 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
624 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
625 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
627 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
628 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
630 case DEMANGLE_COMPONENT_CTOR
:
631 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
632 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
634 case DEMANGLE_COMPONENT_DTOR
:
635 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
636 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
638 case DEMANGLE_COMPONENT_SUB_STD
:
639 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
641 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
642 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
644 case DEMANGLE_COMPONENT_OPERATOR
:
645 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
647 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
648 printf ("extended operator with %d args\n",
649 dc
->u
.s_extended_operator
.args
);
650 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
653 case DEMANGLE_COMPONENT_QUAL_NAME
:
654 printf ("qualified name\n");
656 case DEMANGLE_COMPONENT_LOCAL_NAME
:
657 printf ("local name\n");
659 case DEMANGLE_COMPONENT_TYPED_NAME
:
660 printf ("typed name\n");
662 case DEMANGLE_COMPONENT_TEMPLATE
:
663 printf ("template\n");
665 case DEMANGLE_COMPONENT_VTABLE
:
668 case DEMANGLE_COMPONENT_VTT
:
671 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
672 printf ("construction vtable\n");
674 case DEMANGLE_COMPONENT_TYPEINFO
:
675 printf ("typeinfo\n");
677 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
678 printf ("typeinfo name\n");
680 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
681 printf ("typeinfo function\n");
683 case DEMANGLE_COMPONENT_THUNK
:
686 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
687 printf ("virtual thunk\n");
689 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
690 printf ("covariant thunk\n");
692 case DEMANGLE_COMPONENT_JAVA_CLASS
:
693 printf ("java class\n");
695 case DEMANGLE_COMPONENT_GUARD
:
698 case DEMANGLE_COMPONENT_REFTEMP
:
699 printf ("reference temporary\n");
701 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
702 printf ("hidden alias\n");
704 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
705 printf ("transaction clone\n");
707 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
708 printf ("non-transaction clone\n");
710 case DEMANGLE_COMPONENT_RESTRICT
:
711 printf ("restrict\n");
713 case DEMANGLE_COMPONENT_VOLATILE
:
714 printf ("volatile\n");
716 case DEMANGLE_COMPONENT_CONST
:
719 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
720 printf ("restrict this\n");
722 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
723 printf ("volatile this\n");
725 case DEMANGLE_COMPONENT_CONST_THIS
:
726 printf ("const this\n");
728 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
729 printf ("reference this\n");
731 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
732 printf ("rvalue reference this\n");
734 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
735 printf ("transaction_safe this\n");
737 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
738 printf ("vendor type qualifier\n");
740 case DEMANGLE_COMPONENT_POINTER
:
741 printf ("pointer\n");
743 case DEMANGLE_COMPONENT_REFERENCE
:
744 printf ("reference\n");
746 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
747 printf ("rvalue reference\n");
749 case DEMANGLE_COMPONENT_COMPLEX
:
750 printf ("complex\n");
752 case DEMANGLE_COMPONENT_IMAGINARY
:
753 printf ("imaginary\n");
755 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
756 printf ("vendor type\n");
758 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
759 printf ("function type\n");
761 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
762 printf ("array type\n");
764 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
765 printf ("pointer to member type\n");
767 case DEMANGLE_COMPONENT_FIXED_TYPE
:
768 printf ("fixed-point type, accum? %d, sat? %d\n",
769 dc
->u
.s_fixed
.accum
, dc
->u
.s_fixed
.sat
);
770 d_dump (dc
->u
.s_fixed
.length
, indent
+ 2);
772 case DEMANGLE_COMPONENT_ARGLIST
:
773 printf ("argument list\n");
775 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
776 printf ("template argument list\n");
778 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
779 printf ("initializer list\n");
781 case DEMANGLE_COMPONENT_CAST
:
784 case DEMANGLE_COMPONENT_CONVERSION
:
785 printf ("conversion operator\n");
787 case DEMANGLE_COMPONENT_NULLARY
:
788 printf ("nullary operator\n");
790 case DEMANGLE_COMPONENT_UNARY
:
791 printf ("unary operator\n");
793 case DEMANGLE_COMPONENT_BINARY
:
794 printf ("binary operator\n");
796 case DEMANGLE_COMPONENT_BINARY_ARGS
:
797 printf ("binary operator arguments\n");
799 case DEMANGLE_COMPONENT_TRINARY
:
800 printf ("trinary operator\n");
802 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
803 printf ("trinary operator arguments 1\n");
805 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
806 printf ("trinary operator arguments 1\n");
808 case DEMANGLE_COMPONENT_LITERAL
:
809 printf ("literal\n");
811 case DEMANGLE_COMPONENT_LITERAL_NEG
:
812 printf ("negative literal\n");
814 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
815 printf ("java resource\n");
817 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
818 printf ("compound name\n");
820 case DEMANGLE_COMPONENT_CHARACTER
:
821 printf ("character '%c'\n", dc
->u
.s_character
.character
);
823 case DEMANGLE_COMPONENT_NUMBER
:
824 printf ("number %ld\n", dc
->u
.s_number
.number
);
826 case DEMANGLE_COMPONENT_DECLTYPE
:
827 printf ("decltype\n");
829 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
830 printf ("pack expansion\n");
832 case DEMANGLE_COMPONENT_TLS_INIT
:
833 printf ("tls init function\n");
835 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
836 printf ("tls wrapper function\n");
838 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
839 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
840 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
842 case DEMANGLE_COMPONENT_LAMBDA
:
843 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
844 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
848 d_dump (d_left (dc
), indent
+ 2);
849 d_dump (d_right (dc
), indent
+ 2);
852 #endif /* CP_DEMANGLE_DEBUG */
854 /* Fill in a DEMANGLE_COMPONENT_NAME. */
856 CP_STATIC_IF_GLIBCPP_V3
858 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
860 if (p
== NULL
|| s
== NULL
|| len
== 0)
863 p
->type
= DEMANGLE_COMPONENT_NAME
;
865 p
->u
.s_name
.len
= len
;
869 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
871 CP_STATIC_IF_GLIBCPP_V3
873 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
874 struct demangle_component
*name
)
876 if (p
== NULL
|| args
< 0 || name
== NULL
)
879 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
880 p
->u
.s_extended_operator
.args
= args
;
881 p
->u
.s_extended_operator
.name
= name
;
885 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
887 CP_STATIC_IF_GLIBCPP_V3
889 cplus_demangle_fill_ctor (struct demangle_component
*p
,
890 enum gnu_v3_ctor_kinds kind
,
891 struct demangle_component
*name
)
895 || (int) kind
< gnu_v3_complete_object_ctor
896 || (int) kind
> gnu_v3_object_ctor_group
)
899 p
->type
= DEMANGLE_COMPONENT_CTOR
;
900 p
->u
.s_ctor
.kind
= kind
;
901 p
->u
.s_ctor
.name
= name
;
905 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
907 CP_STATIC_IF_GLIBCPP_V3
909 cplus_demangle_fill_dtor (struct demangle_component
*p
,
910 enum gnu_v3_dtor_kinds kind
,
911 struct demangle_component
*name
)
915 || (int) kind
< gnu_v3_deleting_dtor
916 || (int) kind
> gnu_v3_object_dtor_group
)
919 p
->type
= DEMANGLE_COMPONENT_DTOR
;
920 p
->u
.s_dtor
.kind
= kind
;
921 p
->u
.s_dtor
.name
= name
;
925 /* Add a new component. */
927 static struct demangle_component
*
928 d_make_empty (struct d_info
*di
)
930 struct demangle_component
*p
;
932 if (di
->next_comp
>= di
->num_comps
)
934 p
= &di
->comps
[di
->next_comp
];
940 /* Add a new generic component. */
942 static struct demangle_component
*
943 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
944 struct demangle_component
*left
,
945 struct demangle_component
*right
)
947 struct demangle_component
*p
;
949 /* We check for errors here. A typical error would be a NULL return
950 from a subroutine. We catch those here, and return NULL
954 /* These types require two parameters. */
955 case DEMANGLE_COMPONENT_QUAL_NAME
:
956 case DEMANGLE_COMPONENT_LOCAL_NAME
:
957 case DEMANGLE_COMPONENT_TYPED_NAME
:
958 case DEMANGLE_COMPONENT_TAGGED_NAME
:
959 case DEMANGLE_COMPONENT_TEMPLATE
:
960 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
961 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
962 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
963 case DEMANGLE_COMPONENT_UNARY
:
964 case DEMANGLE_COMPONENT_BINARY
:
965 case DEMANGLE_COMPONENT_BINARY_ARGS
:
966 case DEMANGLE_COMPONENT_TRINARY
:
967 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
968 case DEMANGLE_COMPONENT_LITERAL
:
969 case DEMANGLE_COMPONENT_LITERAL_NEG
:
970 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
971 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
972 case DEMANGLE_COMPONENT_CLONE
:
973 if (left
== NULL
|| right
== NULL
)
977 /* These types only require one parameter. */
978 case DEMANGLE_COMPONENT_VTABLE
:
979 case DEMANGLE_COMPONENT_VTT
:
980 case DEMANGLE_COMPONENT_TYPEINFO
:
981 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
982 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
983 case DEMANGLE_COMPONENT_THUNK
:
984 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
985 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
986 case DEMANGLE_COMPONENT_JAVA_CLASS
:
987 case DEMANGLE_COMPONENT_GUARD
:
988 case DEMANGLE_COMPONENT_TLS_INIT
:
989 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
990 case DEMANGLE_COMPONENT_REFTEMP
:
991 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
992 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
993 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
994 case DEMANGLE_COMPONENT_POINTER
:
995 case DEMANGLE_COMPONENT_REFERENCE
:
996 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
997 case DEMANGLE_COMPONENT_COMPLEX
:
998 case DEMANGLE_COMPONENT_IMAGINARY
:
999 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
1000 case DEMANGLE_COMPONENT_CAST
:
1001 case DEMANGLE_COMPONENT_CONVERSION
:
1002 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
1003 case DEMANGLE_COMPONENT_DECLTYPE
:
1004 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
1005 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
1006 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
1007 case DEMANGLE_COMPONENT_NULLARY
:
1008 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
1013 /* This needs a right parameter, but the left parameter can be
1015 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
1016 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
1021 /* These are allowed to have no parameters--in some cases they
1022 will be filled in later. */
1023 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
1024 case DEMANGLE_COMPONENT_RESTRICT
:
1025 case DEMANGLE_COMPONENT_VOLATILE
:
1026 case DEMANGLE_COMPONENT_CONST
:
1027 case DEMANGLE_COMPONENT_ARGLIST
:
1028 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
1029 FNQUAL_COMPONENT_CASE
:
1032 /* Other types should not be seen here. */
1037 p
= d_make_empty (di
);
1041 p
->u
.s_binary
.left
= left
;
1042 p
->u
.s_binary
.right
= right
;
1047 /* Add a new demangle mangled name component. */
1049 static struct demangle_component
*
1050 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
1052 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1053 return d_make_name (di
, s
, strlen (s
));
1055 return d_encoding (di
, 0);
1058 /* Add a new name component. */
1060 static struct demangle_component
*
1061 d_make_name (struct d_info
*di
, const char *s
, int len
)
1063 struct demangle_component
*p
;
1065 p
= d_make_empty (di
);
1066 if (! cplus_demangle_fill_name (p
, s
, len
))
1071 /* Add a new builtin type component. */
1073 static struct demangle_component
*
1074 d_make_builtin_type (struct d_info
*di
,
1075 const struct demangle_builtin_type_info
*type
)
1077 struct demangle_component
*p
;
1081 p
= d_make_empty (di
);
1084 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1085 p
->u
.s_builtin
.type
= type
;
1090 /* Add a new operator component. */
1092 static struct demangle_component
*
1093 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1095 struct demangle_component
*p
;
1097 p
= d_make_empty (di
);
1100 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1101 p
->u
.s_operator
.op
= op
;
1106 /* Add a new extended operator component. */
1108 static struct demangle_component
*
1109 d_make_extended_operator (struct d_info
*di
, int args
,
1110 struct demangle_component
*name
)
1112 struct demangle_component
*p
;
1114 p
= d_make_empty (di
);
1115 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1120 static struct demangle_component
*
1121 d_make_default_arg (struct d_info
*di
, int num
,
1122 struct demangle_component
*sub
)
1124 struct demangle_component
*p
= d_make_empty (di
);
1127 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1128 p
->u
.s_unary_num
.num
= num
;
1129 p
->u
.s_unary_num
.sub
= sub
;
1134 /* Add a new constructor component. */
1136 static struct demangle_component
*
1137 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1138 struct demangle_component
*name
)
1140 struct demangle_component
*p
;
1142 p
= d_make_empty (di
);
1143 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1148 /* Add a new destructor component. */
1150 static struct demangle_component
*
1151 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1152 struct demangle_component
*name
)
1154 struct demangle_component
*p
;
1156 p
= d_make_empty (di
);
1157 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1162 /* Add a new template parameter. */
1164 static struct demangle_component
*
1165 d_make_template_param (struct d_info
*di
, int i
)
1167 struct demangle_component
*p
;
1169 p
= d_make_empty (di
);
1172 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1173 p
->u
.s_number
.number
= i
;
1178 /* Add a new function parameter. */
1180 static struct demangle_component
*
1181 d_make_function_param (struct d_info
*di
, int i
)
1183 struct demangle_component
*p
;
1185 p
= d_make_empty (di
);
1188 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1189 p
->u
.s_number
.number
= i
;
1194 /* Add a new standard substitution component. */
1196 static struct demangle_component
*
1197 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1199 struct demangle_component
*p
;
1201 p
= d_make_empty (di
);
1204 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1205 p
->u
.s_string
.string
= name
;
1206 p
->u
.s_string
.len
= len
;
1211 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1213 TOP_LEVEL is non-zero when called at the top level. */
1215 CP_STATIC_IF_GLIBCPP_V3
1216 struct demangle_component
*
1217 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1219 struct demangle_component
*p
;
1221 if (! d_check_char (di
, '_')
1222 /* Allow missing _ if not at toplevel to work around a
1223 bug in G++ abi-version=2 mangling; see the comment in
1224 write_template_arg. */
1227 if (! d_check_char (di
, 'Z'))
1229 p
= d_encoding (di
, top_level
);
1231 /* If at top level and parsing parameters, check for a clone
1233 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1234 while (d_peek_char (di
) == '.'
1235 && (IS_LOWER (d_peek_next_char (di
))
1236 || d_peek_next_char (di
) == '_'
1237 || IS_DIGIT (d_peek_next_char (di
))))
1238 p
= d_clone_suffix (di
, p
);
1243 /* Return whether a function should have a return type. The argument
1244 is the function name, which may be qualified in various ways. The
1245 rules are that template functions have return types with some
1246 exceptions, function types which are not part of a function name
1247 mangling have return types with some exceptions, and non-template
1248 function names do not have return types. The exceptions are that
1249 constructors, destructors, and conversion operators do not have
1253 has_return_type (struct demangle_component
*dc
)
1261 case DEMANGLE_COMPONENT_TEMPLATE
:
1262 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1263 FNQUAL_COMPONENT_CASE
:
1264 return has_return_type (d_left (dc
));
1268 /* Return whether a name is a constructor, a destructor, or a
1269 conversion operator. */
1272 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1280 case DEMANGLE_COMPONENT_QUAL_NAME
:
1281 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1282 return is_ctor_dtor_or_conversion (d_right (dc
));
1283 case DEMANGLE_COMPONENT_CTOR
:
1284 case DEMANGLE_COMPONENT_DTOR
:
1285 case DEMANGLE_COMPONENT_CONVERSION
:
1290 /* <encoding> ::= <(function) name> <bare-function-type>
1294 TOP_LEVEL is non-zero when called at the top level, in which case
1295 if DMGL_PARAMS is not set we do not demangle the function
1296 parameters. We only set this at the top level, because otherwise
1297 we would not correctly demangle names in local scopes. */
1299 static struct demangle_component
*
1300 d_encoding (struct d_info
*di
, int top_level
)
1302 char peek
= d_peek_char (di
);
1304 if (peek
== 'G' || peek
== 'T')
1305 return d_special_name (di
);
1308 struct demangle_component
*dc
;
1312 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1314 /* Strip off any initial CV-qualifiers, as they really apply
1315 to the `this' parameter, and they were not output by the
1316 v2 demangler without DMGL_PARAMS. */
1317 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1318 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1319 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1320 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1321 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1324 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1325 there may be function-qualifiers on its right argument which
1326 really apply here; this happens when parsing a class
1327 which is local to a function. */
1328 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1330 struct demangle_component
*dcr
;
1333 while (is_fnqual_component_type (dcr
->type
))
1335 dc
->u
.s_binary
.right
= dcr
;
1341 peek
= d_peek_char (di
);
1342 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1344 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1345 d_bare_function_type (di
, has_return_type (dc
)));
1349 /* <tagged-name> ::= <name> B <source-name> */
1351 static struct demangle_component
*
1352 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1354 struct demangle_component
*hold_last_name
;
1357 /* Preserve the last name, so the ABI tag doesn't clobber it. */
1358 hold_last_name
= di
->last_name
;
1360 while (peek
= d_peek_char (di
),
1363 struct demangle_component
*tag
;
1365 tag
= d_source_name (di
);
1366 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1369 di
->last_name
= hold_last_name
;
1374 /* <name> ::= <nested-name>
1376 ::= <unscoped-template-name> <template-args>
1379 <unscoped-name> ::= <unqualified-name>
1380 ::= St <unqualified-name>
1382 <unscoped-template-name> ::= <unscoped-name>
1386 static struct demangle_component
*
1387 d_name (struct d_info
*di
)
1389 char peek
= d_peek_char (di
);
1390 struct demangle_component
*dc
;
1395 return d_nested_name (di
);
1398 return d_local_name (di
);
1401 return d_unqualified_name (di
);
1407 if (d_peek_next_char (di
) != 't')
1409 dc
= d_substitution (di
, 0);
1415 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1416 d_make_name (di
, "std", 3),
1417 d_unqualified_name (di
));
1422 if (d_peek_char (di
) != 'I')
1424 /* The grammar does not permit this case to occur if we
1425 called d_substitution() above (i.e., subst == 1). We
1426 don't bother to check. */
1430 /* This is <template-args>, which means that we just saw
1431 <unscoped-template-name>, which is a substitution
1432 candidate if we didn't just get it from a
1436 if (! d_add_substitution (di
, dc
))
1439 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1440 d_template_args (di
));
1448 dc
= d_unqualified_name (di
);
1449 if (d_peek_char (di
) == 'I')
1451 /* This is <template-args>, which means that we just saw
1452 <unscoped-template-name>, which is a substitution
1454 if (! d_add_substitution (di
, dc
))
1456 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1457 d_template_args (di
));
1463 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1464 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1467 static struct demangle_component
*
1468 d_nested_name (struct d_info
*di
)
1470 struct demangle_component
*ret
;
1471 struct demangle_component
**pret
;
1472 struct demangle_component
*rqual
;
1474 if (! d_check_char (di
, 'N'))
1477 pret
= d_cv_qualifiers (di
, &ret
, 1);
1481 /* Parse the ref-qualifier now and then attach it
1482 once we have something to attach it to. */
1483 rqual
= d_ref_qualifier (di
, NULL
);
1485 *pret
= d_prefix (di
);
1491 d_left (rqual
) = ret
;
1495 if (! d_check_char (di
, 'E'))
1501 /* <prefix> ::= <prefix> <unqualified-name>
1502 ::= <template-prefix> <template-args>
1503 ::= <template-param>
1508 <template-prefix> ::= <prefix> <(template) unqualified-name>
1509 ::= <template-param>
1513 static struct demangle_component
*
1514 d_prefix (struct d_info
*di
)
1516 struct demangle_component
*ret
= NULL
;
1521 enum demangle_component_type comb_type
;
1522 struct demangle_component
*dc
;
1524 peek
= d_peek_char (di
);
1528 /* The older code accepts a <local-name> here, but I don't see
1529 that in the grammar. The older code does not accept a
1530 <template-param> here. */
1532 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1535 char peek2
= d_peek_next_char (di
);
1536 if (peek2
== 'T' || peek2
== 't')
1538 dc
= cplus_demangle_type (di
);
1540 /* Destructor name. */
1541 dc
= d_unqualified_name (di
);
1543 else if (IS_DIGIT (peek
)
1548 dc
= d_unqualified_name (di
);
1549 else if (peek
== 'S')
1550 dc
= d_substitution (di
, 1);
1551 else if (peek
== 'I')
1555 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1556 dc
= d_template_args (di
);
1558 else if (peek
== 'T')
1559 dc
= d_template_param (di
);
1560 else if (peek
== 'E')
1562 else if (peek
== 'M')
1564 /* Initializer scope for a lambda. We don't need to represent
1565 this; the normal code will just treat the variable as a type
1566 scope, which gives appropriate output. */
1578 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1580 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1582 if (! d_add_substitution (di
, ret
))
1588 /* <unqualified-name> ::= <operator-name>
1589 ::= <ctor-dtor-name>
1591 ::= <local-source-name>
1593 <local-source-name> ::= L <source-name> <discriminator>
1596 static struct demangle_component
*
1597 d_unqualified_name (struct d_info
*di
)
1599 struct demangle_component
*ret
;
1602 peek
= d_peek_char (di
);
1603 if (IS_DIGIT (peek
))
1604 ret
= d_source_name (di
);
1605 else if (IS_LOWER (peek
))
1607 if (peek
== 'o' && d_peek_next_char (di
) == 'n')
1609 ret
= d_operator_name (di
);
1610 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1612 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1613 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1614 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1615 d_source_name (di
));
1618 else if (peek
== 'C' || peek
== 'D')
1619 ret
= d_ctor_dtor_name (di
);
1620 else if (peek
== 'L')
1624 ret
= d_source_name (di
);
1627 if (! d_discriminator (di
))
1630 else if (peek
== 'U')
1632 switch (d_peek_next_char (di
))
1635 ret
= d_lambda (di
);
1638 ret
= d_unnamed_type (di
);
1647 if (d_peek_char (di
) == 'B')
1648 ret
= d_abi_tags (di
, ret
);
1652 /* <source-name> ::= <(positive length) number> <identifier> */
1654 static struct demangle_component
*
1655 d_source_name (struct d_info
*di
)
1658 struct demangle_component
*ret
;
1660 len
= d_number (di
);
1663 ret
= d_identifier (di
, len
);
1664 di
->last_name
= ret
;
1668 /* number ::= [n] <(non-negative decimal integer)> */
1671 d_number (struct d_info
*di
)
1678 peek
= d_peek_char (di
);
1683 peek
= d_peek_char (di
);
1689 if (! IS_DIGIT (peek
))
1695 ret
= ret
* 10 + peek
- '0';
1697 peek
= d_peek_char (di
);
1701 /* Like d_number, but returns a demangle_component. */
1703 static struct demangle_component
*
1704 d_number_component (struct d_info
*di
)
1706 struct demangle_component
*ret
= d_make_empty (di
);
1709 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1710 ret
->u
.s_number
.number
= d_number (di
);
1715 /* identifier ::= <(unqualified source code identifier)> */
1717 static struct demangle_component
*
1718 d_identifier (struct d_info
*di
, int len
)
1724 if (di
->send
- name
< len
)
1727 d_advance (di
, len
);
1729 /* A Java mangled name may have a trailing '$' if it is a C++
1730 keyword. This '$' is not included in the length count. We just
1732 if ((di
->options
& DMGL_JAVA
) != 0
1733 && d_peek_char (di
) == '$')
1736 /* Look for something which looks like a gcc encoding of an
1737 anonymous namespace, and replace it with a more user friendly
1739 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1740 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1741 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1745 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1746 if ((*s
== '.' || *s
== '_' || *s
== '$')
1749 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1750 return d_make_name (di
, "(anonymous namespace)",
1751 sizeof "(anonymous namespace)" - 1);
1755 return d_make_name (di
, name
, len
);
1758 /* operator_name ::= many different two character encodings.
1760 ::= v <digit> <source-name>
1762 This list is sorted for binary search. */
1764 #define NL(s) s, (sizeof s) - 1
1766 CP_STATIC_IF_GLIBCPP_V3
1767 const struct demangle_operator_info cplus_demangle_operators
[] =
1769 { "aN", NL ("&="), 2 },
1770 { "aS", NL ("="), 2 },
1771 { "aa", NL ("&&"), 2 },
1772 { "ad", NL ("&"), 1 },
1773 { "an", NL ("&"), 2 },
1774 { "at", NL ("alignof "), 1 },
1775 { "az", NL ("alignof "), 1 },
1776 { "cc", NL ("const_cast"), 2 },
1777 { "cl", NL ("()"), 2 },
1778 { "cm", NL (","), 2 },
1779 { "co", NL ("~"), 1 },
1780 { "dV", NL ("/="), 2 },
1781 { "da", NL ("delete[] "), 1 },
1782 { "dc", NL ("dynamic_cast"), 2 },
1783 { "de", NL ("*"), 1 },
1784 { "dl", NL ("delete "), 1 },
1785 { "ds", NL (".*"), 2 },
1786 { "dt", NL ("."), 2 },
1787 { "dv", NL ("/"), 2 },
1788 { "eO", NL ("^="), 2 },
1789 { "eo", NL ("^"), 2 },
1790 { "eq", NL ("=="), 2 },
1791 { "fL", NL ("..."), 3 },
1792 { "fR", NL ("..."), 3 },
1793 { "fl", NL ("..."), 2 },
1794 { "fr", NL ("..."), 2 },
1795 { "ge", NL (">="), 2 },
1796 { "gs", NL ("::"), 1 },
1797 { "gt", NL (">"), 2 },
1798 { "ix", NL ("[]"), 2 },
1799 { "lS", NL ("<<="), 2 },
1800 { "le", NL ("<="), 2 },
1801 { "li", NL ("operator\"\" "), 1 },
1802 { "ls", NL ("<<"), 2 },
1803 { "lt", NL ("<"), 2 },
1804 { "mI", NL ("-="), 2 },
1805 { "mL", NL ("*="), 2 },
1806 { "mi", NL ("-"), 2 },
1807 { "ml", NL ("*"), 2 },
1808 { "mm", NL ("--"), 1 },
1809 { "na", NL ("new[]"), 3 },
1810 { "ne", NL ("!="), 2 },
1811 { "ng", NL ("-"), 1 },
1812 { "nt", NL ("!"), 1 },
1813 { "nw", NL ("new"), 3 },
1814 { "oR", NL ("|="), 2 },
1815 { "oo", NL ("||"), 2 },
1816 { "or", NL ("|"), 2 },
1817 { "pL", NL ("+="), 2 },
1818 { "pl", NL ("+"), 2 },
1819 { "pm", NL ("->*"), 2 },
1820 { "pp", NL ("++"), 1 },
1821 { "ps", NL ("+"), 1 },
1822 { "pt", NL ("->"), 2 },
1823 { "qu", NL ("?"), 3 },
1824 { "rM", NL ("%="), 2 },
1825 { "rS", NL (">>="), 2 },
1826 { "rc", NL ("reinterpret_cast"), 2 },
1827 { "rm", NL ("%"), 2 },
1828 { "rs", NL (">>"), 2 },
1829 { "sP", NL ("sizeof..."), 1 },
1830 { "sZ", NL ("sizeof..."), 1 },
1831 { "sc", NL ("static_cast"), 2 },
1832 { "st", NL ("sizeof "), 1 },
1833 { "sz", NL ("sizeof "), 1 },
1834 { "tr", NL ("throw"), 0 },
1835 { "tw", NL ("throw "), 1 },
1836 { NULL
, NULL
, 0, 0 }
1839 static struct demangle_component
*
1840 d_operator_name (struct d_info
*di
)
1845 c1
= d_next_char (di
);
1846 c2
= d_next_char (di
);
1847 if (c1
== 'v' && IS_DIGIT (c2
))
1848 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1849 else if (c1
== 'c' && c2
== 'v')
1851 struct demangle_component
*type
;
1852 int was_conversion
= di
->is_conversion
;
1853 struct demangle_component
*res
;
1855 di
->is_conversion
= ! di
->is_expression
;
1856 type
= cplus_demangle_type (di
);
1857 if (di
->is_conversion
)
1858 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
1860 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1861 di
->is_conversion
= was_conversion
;
1866 /* LOW is the inclusive lower bound. */
1868 /* HIGH is the exclusive upper bound. We subtract one to ignore
1869 the sentinel at the end of the array. */
1870 int high
= ((sizeof (cplus_demangle_operators
)
1871 / sizeof (cplus_demangle_operators
[0]))
1877 const struct demangle_operator_info
*p
;
1879 i
= low
+ (high
- low
) / 2;
1880 p
= cplus_demangle_operators
+ i
;
1882 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1883 return d_make_operator (di
, p
);
1885 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1895 static struct demangle_component
*
1896 d_make_character (struct d_info
*di
, int c
)
1898 struct demangle_component
*p
;
1899 p
= d_make_empty (di
);
1902 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1903 p
->u
.s_character
.character
= c
;
1908 static struct demangle_component
*
1909 d_java_resource (struct d_info
*di
)
1911 struct demangle_component
*p
= NULL
;
1912 struct demangle_component
*next
= NULL
;
1917 len
= d_number (di
);
1921 /* Eat the leading '_'. */
1922 if (d_next_char (di
) != '_')
1935 /* Each chunk is either a '$' escape... */
1953 next
= d_make_character (di
, c
);
1961 /* ... or a sequence of characters. */
1964 while (i
< len
&& str
[i
] && str
[i
] != '$')
1967 next
= d_make_name (di
, str
, i
);
1980 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1986 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1991 /* <special-name> ::= TV <type>
1995 ::= GV <(object) name>
1996 ::= T <call-offset> <(base) encoding>
1997 ::= Tc <call-offset> <call-offset> <(base) encoding>
1998 Also g++ extensions:
1999 ::= TC <type> <(offset) number> _ <(base) type>
2004 ::= Gr <resource name>
2009 static struct demangle_component
*
2010 d_special_name (struct d_info
*di
)
2012 di
->expansion
+= 20;
2013 if (d_check_char (di
, 'T'))
2015 switch (d_next_char (di
))
2019 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
2020 cplus_demangle_type (di
), NULL
);
2022 di
->expansion
-= 10;
2023 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
2024 cplus_demangle_type (di
), NULL
);
2026 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
2027 cplus_demangle_type (di
), NULL
);
2029 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
2030 cplus_demangle_type (di
), NULL
);
2033 if (! d_call_offset (di
, 'h'))
2035 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
2036 d_encoding (di
, 0), NULL
);
2039 if (! d_call_offset (di
, 'v'))
2041 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
2042 d_encoding (di
, 0), NULL
);
2045 if (! d_call_offset (di
, '\0'))
2047 if (! d_call_offset (di
, '\0'))
2049 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
2050 d_encoding (di
, 0), NULL
);
2054 struct demangle_component
*derived_type
;
2056 struct demangle_component
*base_type
;
2058 derived_type
= cplus_demangle_type (di
);
2059 offset
= d_number (di
);
2062 if (! d_check_char (di
, '_'))
2064 base_type
= cplus_demangle_type (di
);
2065 /* We don't display the offset. FIXME: We should display
2066 it in verbose mode. */
2068 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2069 base_type
, derived_type
);
2073 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2074 cplus_demangle_type (di
), NULL
);
2076 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2077 cplus_demangle_type (di
), NULL
);
2080 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2084 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2091 else if (d_check_char (di
, 'G'))
2093 switch (d_next_char (di
))
2096 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2100 struct demangle_component
*name
= d_name (di
);
2101 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2102 d_number_component (di
));
2106 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2107 d_encoding (di
, 0), NULL
);
2110 switch (d_next_char (di
))
2113 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2114 d_encoding (di
, 0), NULL
);
2116 /* ??? The proposal is that other letters (such as 'h') stand
2117 for different variants of transaction cloning, such as
2118 compiling directly for hardware transaction support. But
2119 they still should all be transactional clones of some sort
2120 so go ahead and call them that. */
2122 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2123 d_encoding (di
, 0), NULL
);
2127 return d_java_resource (di
);
2137 /* <call-offset> ::= h <nv-offset> _
2140 <nv-offset> ::= <(offset) number>
2142 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2144 The C parameter, if not '\0', is a character we just read which is
2145 the start of the <call-offset>.
2147 We don't display the offset information anywhere. FIXME: We should
2148 display it in verbose mode. */
2151 d_call_offset (struct d_info
*di
, int c
)
2154 c
= d_next_char (di
);
2161 if (! d_check_char (di
, '_'))
2168 if (! d_check_char (di
, '_'))
2174 /* <ctor-dtor-name> ::= C1
2182 static struct demangle_component
*
2183 d_ctor_dtor_name (struct d_info
*di
)
2185 if (di
->last_name
!= NULL
)
2187 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2188 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2189 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2190 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2192 switch (d_peek_char (di
))
2196 enum gnu_v3_ctor_kinds kind
;
2199 if (d_peek_next_char (di
) == 'I')
2205 switch (d_peek_next_char (di
))
2208 kind
= gnu_v3_complete_object_ctor
;
2211 kind
= gnu_v3_base_object_ctor
;
2214 kind
= gnu_v3_complete_object_allocating_ctor
;
2217 kind
= gnu_v3_unified_ctor
;
2220 kind
= gnu_v3_object_ctor_group
;
2229 cplus_demangle_type (di
);
2231 return d_make_ctor (di
, kind
, di
->last_name
);
2236 enum gnu_v3_dtor_kinds kind
;
2238 switch (d_peek_next_char (di
))
2241 kind
= gnu_v3_deleting_dtor
;
2244 kind
= gnu_v3_complete_object_dtor
;
2247 kind
= gnu_v3_base_object_dtor
;
2249 /* digit '3' is not used */
2251 kind
= gnu_v3_unified_dtor
;
2254 kind
= gnu_v3_object_dtor_group
;
2260 return d_make_dtor (di
, kind
, di
->last_name
);
2268 /* True iff we're looking at an order-insensitive type-qualifier, including
2269 function-type-qualifiers. */
2272 next_is_type_qual (struct d_info
*di
)
2274 char peek
= d_peek_char (di
);
2275 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2279 peek
= d_peek_next_char (di
);
2280 if (peek
== 'x' || peek
== 'o' || peek
== 'O' || peek
== 'w')
2286 /* <type> ::= <builtin-type>
2288 ::= <class-enum-type>
2290 ::= <pointer-to-member-type>
2291 ::= <template-param>
2292 ::= <template-template-param> <template-args>
2294 ::= <CV-qualifiers> <type>
2297 ::= O <type> (C++0x)
2300 ::= U <source-name> <type>
2302 <builtin-type> ::= various one letter codes
2306 CP_STATIC_IF_GLIBCPP_V3
2307 const struct demangle_builtin_type_info
2308 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2310 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2311 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2312 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2313 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2314 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2315 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2316 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2317 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2318 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2319 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2320 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2321 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2322 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2323 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2324 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2326 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2327 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2328 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2329 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2330 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2331 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2332 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2333 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2334 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2335 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2336 D_PRINT_UNSIGNED_LONG_LONG
},
2337 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2338 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2339 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2340 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2341 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2342 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2343 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2344 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2348 CP_STATIC_IF_GLIBCPP_V3
2349 struct demangle_component
*
2350 cplus_demangle_type (struct d_info
*di
)
2353 struct demangle_component
*ret
;
2356 /* The ABI specifies that when CV-qualifiers are used, the base type
2357 is substitutable, and the fully qualified type is substitutable,
2358 but the base type with a strict subset of the CV-qualifiers is
2359 not substitutable. The natural recursive implementation of the
2360 CV-qualifiers would cause subsets to be substitutable, so instead
2361 we pull them all off now.
2363 FIXME: The ABI says that order-insensitive vendor qualifiers
2364 should be handled in the same way, but we have no way to tell
2365 which vendor qualifiers are order-insensitive and which are
2366 order-sensitive. So we just assume that they are all
2367 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2368 __vector, and it treats it as order-sensitive when mangling
2371 if (next_is_type_qual (di
))
2373 struct demangle_component
**pret
;
2375 pret
= d_cv_qualifiers (di
, &ret
, 0);
2378 if (d_peek_char (di
) == 'F')
2380 /* cv-qualifiers before a function type apply to 'this',
2381 so avoid adding the unqualified function type to
2382 the substitution list. */
2383 *pret
= d_function_type (di
);
2386 *pret
= cplus_demangle_type (di
);
2389 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2390 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2392 /* Move the ref-qualifier outside the cv-qualifiers so that
2393 they are printed in the right order. */
2394 struct demangle_component
*fn
= d_left (*pret
);
2395 d_left (*pret
) = ret
;
2399 if (! d_add_substitution (di
, ret
))
2406 peek
= d_peek_char (di
);
2409 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2410 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2411 case 'o': case 's': case 't':
2412 case 'v': case 'w': case 'x': case 'y': case 'z':
2413 ret
= d_make_builtin_type (di
,
2414 &cplus_demangle_builtin_types
[peek
- 'a']);
2415 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2422 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2423 d_source_name (di
), NULL
);
2427 ret
= d_function_type (di
);
2430 case '0': case '1': case '2': case '3': case '4':
2431 case '5': case '6': case '7': case '8': case '9':
2434 ret
= d_class_enum_type (di
);
2438 ret
= d_array_type (di
);
2442 ret
= d_pointer_to_member_type (di
);
2446 ret
= d_template_param (di
);
2447 if (d_peek_char (di
) == 'I')
2449 /* This may be <template-template-param> <template-args>.
2450 If this is the type for a conversion operator, we can
2451 have a <template-template-param> here only by following
2452 a derivation like this:
2455 -> <template-prefix> <template-args>
2456 -> <prefix> <template-unqualified-name> <template-args>
2457 -> <unqualified-name> <template-unqualified-name> <template-args>
2458 -> <source-name> <template-unqualified-name> <template-args>
2459 -> <source-name> <operator-name> <template-args>
2460 -> <source-name> cv <type> <template-args>
2461 -> <source-name> cv <template-template-param> <template-args> <template-args>
2463 where the <template-args> is followed by another.
2464 Otherwise, we must have a derivation like this:
2467 -> <template-prefix> <template-args>
2468 -> <prefix> <template-unqualified-name> <template-args>
2469 -> <unqualified-name> <template-unqualified-name> <template-args>
2470 -> <source-name> <template-unqualified-name> <template-args>
2471 -> <source-name> <operator-name> <template-args>
2472 -> <source-name> cv <type> <template-args>
2473 -> <source-name> cv <template-param> <template-args>
2475 where we need to leave the <template-args> to be processed
2476 by d_prefix (following the <template-prefix>).
2478 The <template-template-param> part is a substitution
2480 if (! di
->is_conversion
)
2482 if (! d_add_substitution (di
, ret
))
2484 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2485 d_template_args (di
));
2489 struct demangle_component
*args
;
2490 struct d_info_checkpoint checkpoint
;
2492 d_checkpoint (di
, &checkpoint
);
2493 args
= d_template_args (di
);
2494 if (d_peek_char (di
) == 'I')
2496 if (! d_add_substitution (di
, ret
))
2498 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2502 d_backtrack (di
, &checkpoint
);
2508 /* If this is a special substitution, then it is the start of
2509 <class-enum-type>. */
2513 peek_next
= d_peek_next_char (di
);
2514 if (IS_DIGIT (peek_next
)
2516 || IS_UPPER (peek_next
))
2518 ret
= d_substitution (di
, 0);
2519 /* The substituted name may have been a template name and
2520 may be followed by tepmlate args. */
2521 if (d_peek_char (di
) == 'I')
2522 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2523 d_template_args (di
));
2529 ret
= d_class_enum_type (di
);
2530 /* If the substitution was a complete type, then it is not
2531 a new substitution candidate. However, if the
2532 substitution was followed by template arguments, then
2533 the whole thing is a substitution candidate. */
2534 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2542 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2543 cplus_demangle_type (di
), NULL
);
2548 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2549 cplus_demangle_type (di
), NULL
);
2554 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2555 cplus_demangle_type (di
), NULL
);
2560 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2561 cplus_demangle_type (di
), NULL
);
2566 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2567 cplus_demangle_type (di
), NULL
);
2572 ret
= d_source_name (di
);
2573 if (d_peek_char (di
) == 'I')
2574 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2575 d_template_args (di
));
2576 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2577 cplus_demangle_type (di
), ret
);
2583 peek
= d_next_char (di
);
2588 /* decltype (expression) */
2589 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2590 d_expression (di
), NULL
);
2591 if (ret
&& d_next_char (di
) != 'E')
2597 /* Pack expansion. */
2598 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2599 cplus_demangle_type (di
), NULL
);
2605 ret
= d_make_name (di
, "auto", 4);
2608 /* decltype(auto) */
2609 ret
= d_make_name (di
, "decltype(auto)", 14);
2613 /* 32-bit decimal floating point */
2614 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2615 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2619 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2620 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2624 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2625 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2628 /* 16-bit half-precision FP */
2629 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2630 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2634 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2635 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2639 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2640 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2644 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2645 ret
= d_make_empty (di
);
2646 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2647 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2648 /* For demangling we don't care about the bits. */
2650 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2651 if (ret
->u
.s_fixed
.length
== NULL
)
2654 peek
= d_next_char (di
);
2655 ret
->u
.s_fixed
.sat
= (peek
== 's');
2659 ret
= d_vector_type (di
);
2664 /* decltype(nullptr) */
2665 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2666 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2680 if (! d_add_substitution (di
, ret
))
2687 /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */
2689 static struct demangle_component
**
2690 d_cv_qualifiers (struct d_info
*di
,
2691 struct demangle_component
**pret
, int member_fn
)
2693 struct demangle_component
**pstart
;
2697 peek
= d_peek_char (di
);
2698 while (next_is_type_qual (di
))
2700 enum demangle_component_type t
;
2701 struct demangle_component
*right
= NULL
;
2707 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2708 : DEMANGLE_COMPONENT_RESTRICT
);
2709 di
->expansion
+= sizeof "restrict";
2711 else if (peek
== 'V')
2714 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2715 : DEMANGLE_COMPONENT_VOLATILE
);
2716 di
->expansion
+= sizeof "volatile";
2718 else if (peek
== 'K')
2721 ? DEMANGLE_COMPONENT_CONST_THIS
2722 : DEMANGLE_COMPONENT_CONST
);
2723 di
->expansion
+= sizeof "const";
2727 peek
= d_next_char (di
);
2730 t
= DEMANGLE_COMPONENT_TRANSACTION_SAFE
;
2731 di
->expansion
+= sizeof "transaction_safe";
2733 else if (peek
== 'o'
2736 t
= DEMANGLE_COMPONENT_NOEXCEPT
;
2737 di
->expansion
+= sizeof "noexcept";
2740 right
= d_expression (di
);
2743 if (! d_check_char (di
, 'E'))
2747 else if (peek
== 'w')
2749 t
= DEMANGLE_COMPONENT_THROW_SPEC
;
2750 di
->expansion
+= sizeof "throw";
2751 right
= d_parmlist (di
);
2754 if (! d_check_char (di
, 'E'))
2761 *pret
= d_make_comp (di
, t
, NULL
, right
);
2764 pret
= &d_left (*pret
);
2766 peek
= d_peek_char (di
);
2769 if (!member_fn
&& peek
== 'F')
2771 while (pstart
!= pret
)
2773 switch ((*pstart
)->type
)
2775 case DEMANGLE_COMPONENT_RESTRICT
:
2776 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2778 case DEMANGLE_COMPONENT_VOLATILE
:
2779 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2781 case DEMANGLE_COMPONENT_CONST
:
2782 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2787 pstart
= &d_left (*pstart
);
2794 /* <ref-qualifier> ::= R
2797 static struct demangle_component
*
2798 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2800 struct demangle_component
*ret
= sub
;
2803 peek
= d_peek_char (di
);
2804 if (peek
== 'R' || peek
== 'O')
2806 enum demangle_component_type t
;
2809 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2810 di
->expansion
+= sizeof "&";
2814 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2815 di
->expansion
+= sizeof "&&";
2819 ret
= d_make_comp (di
, t
, ret
, NULL
);
2825 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */
2827 static struct demangle_component
*
2828 d_function_type (struct d_info
*di
)
2830 struct demangle_component
*ret
;
2832 if (! d_check_char (di
, 'F'))
2834 if (d_peek_char (di
) == 'Y')
2836 /* Function has C linkage. We don't print this information.
2837 FIXME: We should print it in verbose mode. */
2840 ret
= d_bare_function_type (di
, 1);
2841 ret
= d_ref_qualifier (di
, ret
);
2843 if (! d_check_char (di
, 'E'))
2850 static struct demangle_component
*
2851 d_parmlist (struct d_info
*di
)
2853 struct demangle_component
*tl
;
2854 struct demangle_component
**ptl
;
2860 struct demangle_component
*type
;
2862 char peek
= d_peek_char (di
);
2863 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2865 if ((peek
== 'R' || peek
== 'O')
2866 && d_peek_next_char (di
) == 'E')
2867 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2869 type
= cplus_demangle_type (di
);
2872 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2875 ptl
= &d_right (*ptl
);
2878 /* There should be at least one parameter type besides the optional
2879 return type. A function which takes no arguments will have a
2880 single parameter type void. */
2884 /* If we have a single parameter type void, omit it. */
2885 if (d_right (tl
) == NULL
2886 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2887 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2889 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2896 /* <bare-function-type> ::= [J]<type>+ */
2898 static struct demangle_component
*
2899 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2901 struct demangle_component
*return_type
;
2902 struct demangle_component
*tl
;
2905 /* Detect special qualifier indicating that the first argument
2906 is the return type. */
2907 peek
= d_peek_char (di
);
2911 has_return_type
= 1;
2914 if (has_return_type
)
2916 return_type
= cplus_demangle_type (di
);
2917 if (return_type
== NULL
)
2923 tl
= d_parmlist (di
);
2927 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2931 /* <class-enum-type> ::= <name> */
2933 static struct demangle_component
*
2934 d_class_enum_type (struct d_info
*di
)
2939 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2940 ::= A [<(dimension) expression>] _ <(element) type>
2943 static struct demangle_component
*
2944 d_array_type (struct d_info
*di
)
2947 struct demangle_component
*dim
;
2949 if (! d_check_char (di
, 'A'))
2952 peek
= d_peek_char (di
);
2955 else if (IS_DIGIT (peek
))
2963 peek
= d_peek_char (di
);
2965 while (IS_DIGIT (peek
));
2966 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2972 dim
= d_expression (di
);
2977 if (! d_check_char (di
, '_'))
2980 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2981 cplus_demangle_type (di
));
2984 /* <vector-type> ::= Dv <number> _ <type>
2985 ::= Dv _ <expression> _ <type> */
2987 static struct demangle_component
*
2988 d_vector_type (struct d_info
*di
)
2991 struct demangle_component
*dim
;
2993 peek
= d_peek_char (di
);
2997 dim
= d_expression (di
);
3000 dim
= d_number_component (di
);
3005 if (! d_check_char (di
, '_'))
3008 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
3009 cplus_demangle_type (di
));
3012 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
3014 static struct demangle_component
*
3015 d_pointer_to_member_type (struct d_info
*di
)
3017 struct demangle_component
*cl
;
3018 struct demangle_component
*mem
;
3020 if (! d_check_char (di
, 'M'))
3023 cl
= cplus_demangle_type (di
);
3027 /* The ABI says, "The type of a non-static member function is considered
3028 to be different, for the purposes of substitution, from the type of a
3029 namespace-scope or static member function whose type appears
3030 similar. The types of two non-static member functions are considered
3031 to be different, for the purposes of substitution, if the functions
3032 are members of different classes. In other words, for the purposes of
3033 substitution, the class of which the function is a member is
3034 considered part of the type of function."
3036 For a pointer to member function, this call to cplus_demangle_type
3037 will end up adding a (possibly qualified) non-member function type to
3038 the substitution table, which is not correct; however, the member
3039 function type will never be used in a substitution, so putting the
3040 wrong type in the substitution table is harmless. */
3042 mem
= cplus_demangle_type (di
);
3046 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
3049 /* <non-negative number> _ */
3052 d_compact_number (struct d_info
*di
)
3055 if (d_peek_char (di
) == '_')
3057 else if (d_peek_char (di
) == 'n')
3060 num
= d_number (di
) + 1;
3062 if (num
< 0 || ! d_check_char (di
, '_'))
3067 /* <template-param> ::= T_
3068 ::= T <(parameter-2 non-negative) number> _
3071 static struct demangle_component
*
3072 d_template_param (struct d_info
*di
)
3076 if (! d_check_char (di
, 'T'))
3079 param
= d_compact_number (di
);
3083 return d_make_template_param (di
, param
);
3086 /* <template-args> ::= I <template-arg>+ E */
3088 static struct demangle_component
*
3089 d_template_args (struct d_info
*di
)
3091 if (d_peek_char (di
) != 'I'
3092 && d_peek_char (di
) != 'J')
3096 return d_template_args_1 (di
);
3099 /* <template-arg>* E */
3101 static struct demangle_component
*
3102 d_template_args_1 (struct d_info
*di
)
3104 struct demangle_component
*hold_last_name
;
3105 struct demangle_component
*al
;
3106 struct demangle_component
**pal
;
3108 /* Preserve the last name we saw--don't let the template arguments
3109 clobber it, as that would give us the wrong name for a subsequent
3110 constructor or destructor. */
3111 hold_last_name
= di
->last_name
;
3113 if (d_peek_char (di
) == 'E')
3115 /* An argument pack can be empty. */
3117 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
3124 struct demangle_component
*a
;
3126 a
= d_template_arg (di
);
3130 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
3133 pal
= &d_right (*pal
);
3135 if (d_peek_char (di
) == 'E')
3142 di
->last_name
= hold_last_name
;
3147 /* <template-arg> ::= <type>
3148 ::= X <expression> E
3152 static struct demangle_component
*
3153 d_template_arg (struct d_info
*di
)
3155 struct demangle_component
*ret
;
3157 switch (d_peek_char (di
))
3161 ret
= d_expression (di
);
3162 if (! d_check_char (di
, 'E'))
3167 return d_expr_primary (di
);
3171 /* An argument pack. */
3172 return d_template_args (di
);
3175 return cplus_demangle_type (di
);
3179 /* Parse a sequence of expressions until we hit the terminator
3182 static struct demangle_component
*
3183 d_exprlist (struct d_info
*di
, char terminator
)
3185 struct demangle_component
*list
= NULL
;
3186 struct demangle_component
**p
= &list
;
3188 if (d_peek_char (di
) == terminator
)
3191 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3196 struct demangle_component
*arg
= d_expression (di
);
3200 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3205 if (d_peek_char (di
) == terminator
)
3215 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3216 dynamic_cast, static_cast or reinterpret_cast. */
3219 op_is_new_cast (struct demangle_component
*op
)
3221 const char *code
= op
->u
.s_operator
.op
->code
;
3222 return (code
[1] == 'c'
3223 && (code
[0] == 's' || code
[0] == 'd'
3224 || code
[0] == 'c' || code
[0] == 'r'));
3227 /* <expression> ::= <(unary) operator-name> <expression>
3228 ::= <(binary) operator-name> <expression> <expression>
3229 ::= <(trinary) operator-name> <expression> <expression> <expression>
3230 ::= cl <expression>+ E
3232 ::= <template-param>
3233 ::= sr <type> <unqualified-name>
3234 ::= sr <type> <unqualified-name> <template-args>
3238 static inline struct demangle_component
*
3239 d_expression_1 (struct d_info
*di
)
3243 peek
= d_peek_char (di
);
3245 return d_expr_primary (di
);
3246 else if (peek
== 'T')
3247 return d_template_param (di
);
3248 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3250 struct demangle_component
*type
;
3251 struct demangle_component
*name
;
3254 type
= cplus_demangle_type (di
);
3255 name
= d_unqualified_name (di
);
3256 if (d_peek_char (di
) != 'I')
3257 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3259 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3260 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3261 d_template_args (di
)));
3263 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3266 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3267 d_expression_1 (di
), NULL
);
3269 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3271 /* Function parameter used in a late-specified return type. */
3274 if (d_peek_char (di
) == 'T')
3276 /* 'this' parameter. */
3282 index
= d_compact_number (di
);
3283 if (index
== INT_MAX
|| index
== -1)
3287 return d_make_function_param (di
, index
);
3289 else if (IS_DIGIT (peek
)
3290 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3292 /* We can get an unqualified name as an expression in the case of
3293 a dependent function call, i.e. decltype(f(t)). */
3294 struct demangle_component
*name
;
3297 /* operator-function-id, i.e. operator+(t). */
3300 name
= d_unqualified_name (di
);
3303 if (d_peek_char (di
) == 'I')
3304 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3305 d_template_args (di
));
3309 else if ((peek
== 'i' || peek
== 't')
3310 && d_peek_next_char (di
) == 'l')
3312 /* Brace-enclosed initializer list, untyped or typed. */
3313 struct demangle_component
*type
= NULL
;
3315 type
= cplus_demangle_type (di
);
3316 if (!d_peek_next_char (di
))
3319 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3320 type
, d_exprlist (di
, 'E'));
3324 struct demangle_component
*op
;
3325 const char *code
= NULL
;
3328 op
= d_operator_name (di
);
3332 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3334 code
= op
->u
.s_operator
.op
->code
;
3335 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3336 if (strcmp (code
, "st") == 0)
3337 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3338 cplus_demangle_type (di
));
3345 case DEMANGLE_COMPONENT_OPERATOR
:
3346 args
= op
->u
.s_operator
.op
->args
;
3348 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3349 args
= op
->u
.s_extended_operator
.args
;
3351 case DEMANGLE_COMPONENT_CAST
:
3359 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3363 struct demangle_component
*operand
;
3366 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3367 && code
[1] == code
[0])
3368 /* pp_ and mm_ are the prefix variants. */
3369 suffix
= !d_check_char (di
, '_');
3371 if (op
->type
== DEMANGLE_COMPONENT_CAST
3372 && d_check_char (di
, '_'))
3373 operand
= d_exprlist (di
, 'E');
3374 else if (code
&& !strcmp (code
, "sP"))
3375 operand
= d_template_args_1 (di
);
3377 operand
= d_expression_1 (di
);
3380 /* Indicate the suffix variant for d_print_comp. */
3381 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3383 DEMANGLE_COMPONENT_BINARY_ARGS
,
3386 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3391 struct demangle_component
*left
;
3392 struct demangle_component
*right
;
3396 if (op_is_new_cast (op
))
3397 left
= cplus_demangle_type (di
);
3398 else if (code
[0] == 'f')
3399 /* fold-expression. */
3400 left
= d_operator_name (di
);
3402 left
= d_expression_1 (di
);
3403 if (!strcmp (code
, "cl"))
3404 right
= d_exprlist (di
, 'E');
3405 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3407 right
= d_unqualified_name (di
);
3408 if (d_peek_char (di
) == 'I')
3409 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3410 right
, d_template_args (di
));
3413 right
= d_expression_1 (di
);
3415 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3417 DEMANGLE_COMPONENT_BINARY_ARGS
,
3422 struct demangle_component
*first
;
3423 struct demangle_component
*second
;
3424 struct demangle_component
*third
;
3428 else if (!strcmp (code
, "qu"))
3430 /* ?: expression. */
3431 first
= d_expression_1 (di
);
3432 second
= d_expression_1 (di
);
3433 third
= d_expression_1 (di
);
3437 else if (code
[0] == 'f')
3439 /* fold-expression. */
3440 first
= d_operator_name (di
);
3441 second
= d_expression_1 (di
);
3442 third
= d_expression_1 (di
);
3446 else if (code
[0] == 'n')
3448 /* new-expression. */
3449 if (code
[1] != 'w' && code
[1] != 'a')
3451 first
= d_exprlist (di
, '_');
3452 second
= cplus_demangle_type (di
);
3453 if (d_peek_char (di
) == 'E')
3458 else if (d_peek_char (di
) == 'p'
3459 && d_peek_next_char (di
) == 'i')
3461 /* Parenthesized initializer. */
3463 third
= d_exprlist (di
, 'E');
3465 else if (d_peek_char (di
) == 'i'
3466 && d_peek_next_char (di
) == 'l')
3467 /* initializer-list. */
3468 third
= d_expression_1 (di
);
3474 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3476 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3479 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3488 static struct demangle_component
*
3489 d_expression (struct d_info
*di
)
3491 struct demangle_component
*ret
;
3492 int was_expression
= di
->is_expression
;
3494 di
->is_expression
= 1;
3495 ret
= d_expression_1 (di
);
3496 di
->is_expression
= was_expression
;
3500 /* <expr-primary> ::= L <type> <(value) number> E
3501 ::= L <type> <(value) float> E
3502 ::= L <mangled-name> E
3505 static struct demangle_component
*
3506 d_expr_primary (struct d_info
*di
)
3508 struct demangle_component
*ret
;
3510 if (! d_check_char (di
, 'L'))
3512 if (d_peek_char (di
) == '_'
3513 /* Workaround for G++ bug; see comment in write_template_arg. */
3514 || d_peek_char (di
) == 'Z')
3515 ret
= cplus_demangle_mangled_name (di
, 0);
3518 struct demangle_component
*type
;
3519 enum demangle_component_type t
;
3522 type
= cplus_demangle_type (di
);
3526 /* If we have a type we know how to print, we aren't going to
3527 print the type name itself. */
3528 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3529 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3530 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3532 /* Rather than try to interpret the literal value, we just
3533 collect it as a string. Note that it's possible to have a
3534 floating point literal here. The ABI specifies that the
3535 format of such literals is machine independent. That's fine,
3536 but what's not fine is that versions of g++ up to 3.2 with
3537 -fabi-version=1 used upper case letters in the hex constant,
3538 and dumped out gcc's internal representation. That makes it
3539 hard to tell where the constant ends, and hard to dump the
3540 constant in any readable form anyhow. We don't attempt to
3541 handle these cases. */
3543 t
= DEMANGLE_COMPONENT_LITERAL
;
3544 if (d_peek_char (di
) == 'n')
3546 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3550 while (d_peek_char (di
) != 'E')
3552 if (d_peek_char (di
) == '\0')
3556 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3558 if (! d_check_char (di
, 'E'))
3563 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3564 ::= Z <(function) encoding> E s [<discriminator>]
3565 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3568 static struct demangle_component
*
3569 d_local_name (struct d_info
*di
)
3571 struct demangle_component
*function
;
3573 if (! d_check_char (di
, 'Z'))
3576 function
= d_encoding (di
, 0);
3578 if (! d_check_char (di
, 'E'))
3581 if (d_peek_char (di
) == 's')
3584 if (! d_discriminator (di
))
3586 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3587 d_make_name (di
, "string literal",
3588 sizeof "string literal" - 1));
3592 struct demangle_component
*name
;
3595 if (d_peek_char (di
) == 'd')
3597 /* Default argument scope: d <number> _. */
3599 num
= d_compact_number (di
);
3608 /* Lambdas and unnamed types have internal discriminators. */
3609 case DEMANGLE_COMPONENT_LAMBDA
:
3610 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3613 if (! d_discriminator (di
))
3617 name
= d_make_default_arg (di
, num
, name
);
3618 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3622 /* <discriminator> ::= _ <number> # when number < 10
3623 ::= __ <number> _ # when number >= 10
3625 <discriminator> ::= _ <number> # when number >=10
3626 is also accepted to support gcc versions that wrongly mangled that way.
3628 We demangle the discriminator, but we don't print it out. FIXME:
3629 We should print it out in verbose mode. */
3632 d_discriminator (struct d_info
*di
)
3634 int discrim
, num_underscores
= 1;
3636 if (d_peek_char (di
) != '_')
3639 if (d_peek_char (di
) == '_')
3645 discrim
= d_number (di
);
3648 if (num_underscores
> 1 && discrim
>= 10)
3650 if (d_peek_char (di
) == '_')
3659 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3661 static struct demangle_component
*
3662 d_lambda (struct d_info
*di
)
3664 struct demangle_component
*tl
;
3665 struct demangle_component
*ret
;
3668 if (! d_check_char (di
, 'U'))
3670 if (! d_check_char (di
, 'l'))
3673 tl
= d_parmlist (di
);
3677 if (! d_check_char (di
, 'E'))
3680 num
= d_compact_number (di
);
3684 ret
= d_make_empty (di
);
3687 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3688 ret
->u
.s_unary_num
.sub
= tl
;
3689 ret
->u
.s_unary_num
.num
= num
;
3692 if (! d_add_substitution (di
, ret
))
3698 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3700 static struct demangle_component
*
3701 d_unnamed_type (struct d_info
*di
)
3703 struct demangle_component
*ret
;
3706 if (! d_check_char (di
, 'U'))
3708 if (! d_check_char (di
, 't'))
3711 num
= d_compact_number (di
);
3715 ret
= d_make_empty (di
);
3718 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3719 ret
->u
.s_number
.number
= num
;
3722 if (! d_add_substitution (di
, ret
))
3728 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3731 static struct demangle_component
*
3732 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3734 const char *suffix
= d_str (di
);
3735 const char *pend
= suffix
;
3736 struct demangle_component
*n
;
3738 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3741 while (IS_LOWER (*pend
) || *pend
== '_')
3744 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3747 while (IS_DIGIT (*pend
))
3750 d_advance (di
, pend
- suffix
);
3751 n
= d_make_name (di
, suffix
, pend
- suffix
);
3752 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3755 /* Add a new substitution. */
3758 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3762 if (di
->next_sub
>= di
->num_subs
)
3764 di
->subs
[di
->next_sub
] = dc
;
3769 /* <substitution> ::= S <seq-id> _
3779 If PREFIX is non-zero, then this type is being used as a prefix in
3780 a qualified name. In this case, for the standard substitutions, we
3781 need to check whether we are being used as a prefix for a
3782 constructor or destructor, and return a full template name.
3783 Otherwise we will get something like std::iostream::~iostream()
3784 which does not correspond particularly well to any function which
3785 actually appears in the source.
3788 static const struct d_standard_sub_info standard_subs
[] =
3793 { 'a', NL ("std::allocator"),
3794 NL ("std::allocator"),
3796 { 'b', NL ("std::basic_string"),
3797 NL ("std::basic_string"),
3798 NL ("basic_string") },
3799 { 's', NL ("std::string"),
3800 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3801 NL ("basic_string") },
3802 { 'i', NL ("std::istream"),
3803 NL ("std::basic_istream<char, std::char_traits<char> >"),
3804 NL ("basic_istream") },
3805 { 'o', NL ("std::ostream"),
3806 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3807 NL ("basic_ostream") },
3808 { 'd', NL ("std::iostream"),
3809 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3810 NL ("basic_iostream") }
3813 static struct demangle_component
*
3814 d_substitution (struct d_info
*di
, int prefix
)
3818 if (! d_check_char (di
, 'S'))
3821 c
= d_next_char (di
);
3822 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3831 unsigned int new_id
;
3834 new_id
= id
* 36 + c
- '0';
3835 else if (IS_UPPER (c
))
3836 new_id
= id
* 36 + c
- 'A' + 10;
3842 c
= d_next_char (di
);
3849 if (id
>= (unsigned int) di
->next_sub
)
3852 return di
->subs
[id
];
3857 const struct d_standard_sub_info
*p
;
3858 const struct d_standard_sub_info
*pend
;
3860 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3861 if (! verbose
&& prefix
)
3865 peek
= d_peek_char (di
);
3866 if (peek
== 'C' || peek
== 'D')
3870 pend
= (&standard_subs
[0]
3871 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3872 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3878 struct demangle_component
*dc
;
3880 if (p
->set_last_name
!= NULL
)
3881 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3882 p
->set_last_name_len
);
3885 s
= p
->full_expansion
;
3890 s
= p
->simple_expansion
;
3891 len
= p
->simple_len
;
3893 di
->expansion
+= len
;
3894 dc
= d_make_sub (di
, s
, len
);
3895 if (d_peek_char (di
) == 'B')
3897 /* If there are ABI tags on the abbreviation, it becomes
3898 a substitution candidate. */
3899 dc
= d_abi_tags (di
, dc
);
3900 if (! d_add_substitution (di
, dc
))
3912 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3914 checkpoint
->n
= di
->n
;
3915 checkpoint
->next_comp
= di
->next_comp
;
3916 checkpoint
->next_sub
= di
->next_sub
;
3917 checkpoint
->expansion
= di
->expansion
;
3921 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3923 di
->n
= checkpoint
->n
;
3924 di
->next_comp
= checkpoint
->next_comp
;
3925 di
->next_sub
= checkpoint
->next_sub
;
3926 di
->expansion
= checkpoint
->expansion
;
3929 /* Initialize a growable string. */
3932 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3937 dgs
->allocation_failure
= 0;
3940 d_growable_string_resize (dgs
, estimate
);
3943 /* Grow a growable string to a given size. */
3946 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3951 if (dgs
->allocation_failure
)
3954 /* Start allocation at two bytes to avoid any possibility of confusion
3955 with the special value of 1 used as a return in *palc to indicate
3956 allocation failures. */
3957 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3958 while (newalc
< need
)
3961 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3968 dgs
->allocation_failure
= 1;
3975 /* Append a buffer to a growable string. */
3978 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3979 const char *s
, size_t l
)
3983 need
= dgs
->len
+ l
+ 1;
3984 if (need
> dgs
->alc
)
3985 d_growable_string_resize (dgs
, need
);
3987 if (dgs
->allocation_failure
)
3990 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3991 dgs
->buf
[dgs
->len
+ l
] = '\0';
3995 /* Bridge growable strings to the callback mechanism. */
3998 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
4000 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
4002 d_growable_string_append_buffer (dgs
, s
, l
);
4005 /* Walk the tree, counting the number of templates encountered, and
4006 the number of times a scope might be saved. These counts will be
4007 used to allocate data structures for d_print_comp, so the logic
4008 here must mirror the logic d_print_comp will use. It is not
4009 important that the resulting numbers are exact, so long as they
4010 are larger than the actual numbers encountered. */
4013 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
4014 const struct demangle_component
*dc
)
4021 case DEMANGLE_COMPONENT_NAME
:
4022 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4023 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4024 case DEMANGLE_COMPONENT_SUB_STD
:
4025 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4026 case DEMANGLE_COMPONENT_OPERATOR
:
4027 case DEMANGLE_COMPONENT_CHARACTER
:
4028 case DEMANGLE_COMPONENT_NUMBER
:
4029 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4032 case DEMANGLE_COMPONENT_TEMPLATE
:
4034 goto recurse_left_right
;
4036 case DEMANGLE_COMPONENT_REFERENCE
:
4037 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4038 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4040 goto recurse_left_right
;
4042 case DEMANGLE_COMPONENT_QUAL_NAME
:
4043 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4044 case DEMANGLE_COMPONENT_TYPED_NAME
:
4045 case DEMANGLE_COMPONENT_VTABLE
:
4046 case DEMANGLE_COMPONENT_VTT
:
4047 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4048 case DEMANGLE_COMPONENT_TYPEINFO
:
4049 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4050 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4051 case DEMANGLE_COMPONENT_THUNK
:
4052 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4053 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4054 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4055 case DEMANGLE_COMPONENT_GUARD
:
4056 case DEMANGLE_COMPONENT_TLS_INIT
:
4057 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4058 case DEMANGLE_COMPONENT_REFTEMP
:
4059 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4060 case DEMANGLE_COMPONENT_RESTRICT
:
4061 case DEMANGLE_COMPONENT_VOLATILE
:
4062 case DEMANGLE_COMPONENT_CONST
:
4063 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4064 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4065 case DEMANGLE_COMPONENT_CONST_THIS
:
4066 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4067 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4068 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4069 case DEMANGLE_COMPONENT_NOEXCEPT
:
4070 case DEMANGLE_COMPONENT_THROW_SPEC
:
4071 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4072 case DEMANGLE_COMPONENT_POINTER
:
4073 case DEMANGLE_COMPONENT_COMPLEX
:
4074 case DEMANGLE_COMPONENT_IMAGINARY
:
4075 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4076 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4077 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4078 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4079 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4080 case DEMANGLE_COMPONENT_ARGLIST
:
4081 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4082 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4083 case DEMANGLE_COMPONENT_CAST
:
4084 case DEMANGLE_COMPONENT_CONVERSION
:
4085 case DEMANGLE_COMPONENT_NULLARY
:
4086 case DEMANGLE_COMPONENT_UNARY
:
4087 case DEMANGLE_COMPONENT_BINARY
:
4088 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4089 case DEMANGLE_COMPONENT_TRINARY
:
4090 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4091 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4092 case DEMANGLE_COMPONENT_LITERAL
:
4093 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4094 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4095 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4096 case DEMANGLE_COMPONENT_DECLTYPE
:
4097 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4098 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4099 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4100 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4101 case DEMANGLE_COMPONENT_CLONE
:
4103 d_count_templates_scopes (num_templates
, num_scopes
,
4105 d_count_templates_scopes (num_templates
, num_scopes
,
4109 case DEMANGLE_COMPONENT_CTOR
:
4110 d_count_templates_scopes (num_templates
, num_scopes
,
4114 case DEMANGLE_COMPONENT_DTOR
:
4115 d_count_templates_scopes (num_templates
, num_scopes
,
4119 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4120 d_count_templates_scopes (num_templates
, num_scopes
,
4121 dc
->u
.s_extended_operator
.name
);
4124 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4125 d_count_templates_scopes (num_templates
, num_scopes
,
4126 dc
->u
.s_fixed
.length
);
4129 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4130 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4131 d_count_templates_scopes (num_templates
, num_scopes
,
4135 case DEMANGLE_COMPONENT_LAMBDA
:
4136 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4137 d_count_templates_scopes (num_templates
, num_scopes
,
4138 dc
->u
.s_unary_num
.sub
);
4143 /* Initialize a print information structure. */
4146 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
4147 void *opaque
, const struct demangle_component
*dc
)
4150 dpi
->last_char
= '\0';
4151 dpi
->templates
= NULL
;
4152 dpi
->modifiers
= NULL
;
4153 dpi
->pack_index
= 0;
4154 dpi
->flush_count
= 0;
4156 dpi
->callback
= callback
;
4157 dpi
->opaque
= opaque
;
4159 dpi
->demangle_failure
= 0;
4161 dpi
->is_lambda_arg
= 0;
4163 dpi
->component_stack
= NULL
;
4165 dpi
->saved_scopes
= NULL
;
4166 dpi
->next_saved_scope
= 0;
4167 dpi
->num_saved_scopes
= 0;
4169 dpi
->copy_templates
= NULL
;
4170 dpi
->next_copy_template
= 0;
4171 dpi
->num_copy_templates
= 0;
4173 d_count_templates_scopes (&dpi
->num_copy_templates
,
4174 &dpi
->num_saved_scopes
, dc
);
4175 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
4177 dpi
->current_template
= NULL
;
4180 /* Indicate that an error occurred during printing, and test for error. */
4183 d_print_error (struct d_print_info
*dpi
)
4185 dpi
->demangle_failure
= 1;
4189 d_print_saw_error (struct d_print_info
*dpi
)
4191 return dpi
->demangle_failure
!= 0;
4194 /* Flush buffered characters to the callback. */
4197 d_print_flush (struct d_print_info
*dpi
)
4199 dpi
->buf
[dpi
->len
] = '\0';
4200 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4205 /* Append characters and buffers for printing. */
4208 d_append_char (struct d_print_info
*dpi
, char c
)
4210 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4211 d_print_flush (dpi
);
4213 dpi
->buf
[dpi
->len
++] = c
;
4218 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4222 for (i
= 0; i
< l
; i
++)
4223 d_append_char (dpi
, s
[i
]);
4227 d_append_string (struct d_print_info
*dpi
, const char *s
)
4229 d_append_buffer (dpi
, s
, strlen (s
));
4233 d_append_num (struct d_print_info
*dpi
, int l
)
4236 sprintf (buf
,"%d", l
);
4237 d_append_string (dpi
, buf
);
4241 d_last_char (struct d_print_info
*dpi
)
4243 return dpi
->last_char
;
4246 /* Turn components into a human readable string. OPTIONS is the
4247 options bits passed to the demangler. DC is the tree to print.
4248 CALLBACK is a function to call to flush demangled string segments
4249 as they fill the intermediate buffer, and OPAQUE is a generalized
4250 callback argument. On success, this returns 1. On failure,
4251 it returns 0, indicating a bad parse. It does not use heap
4252 memory to build an output string, so cannot encounter memory
4253 allocation failure. */
4255 CP_STATIC_IF_GLIBCPP_V3
4257 cplus_demangle_print_callback (int options
,
4258 struct demangle_component
*dc
,
4259 demangle_callbackref callback
, void *opaque
)
4261 struct d_print_info dpi
;
4263 d_print_init (&dpi
, callback
, opaque
, dc
);
4266 #ifdef CP_DYNAMIC_ARRAYS
4267 /* Avoid zero-length VLAs, which are prohibited by the C99 standard
4268 and flagged as errors by Address Sanitizer. */
4269 __extension__
struct d_saved_scope scopes
[(dpi
.num_saved_scopes
> 0)
4270 ? dpi
.num_saved_scopes
: 1];
4271 __extension__
struct d_print_template temps
[(dpi
.num_copy_templates
> 0)
4272 ? dpi
.num_copy_templates
: 1];
4274 dpi
.saved_scopes
= scopes
;
4275 dpi
.copy_templates
= temps
;
4277 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4278 * sizeof (*dpi
.saved_scopes
));
4279 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4280 * sizeof (*dpi
.copy_templates
));
4283 d_print_comp (&dpi
, options
, dc
);
4286 d_print_flush (&dpi
);
4288 return ! d_print_saw_error (&dpi
);
4291 /* Turn components into a human readable string. OPTIONS is the
4292 options bits passed to the demangler. DC is the tree to print.
4293 ESTIMATE is a guess at the length of the result. This returns a
4294 string allocated by malloc, or NULL on error. On success, this
4295 sets *PALC to the size of the allocated buffer. On failure, this
4296 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4299 CP_STATIC_IF_GLIBCPP_V3
4301 cplus_demangle_print (int options
, struct demangle_component
*dc
,
4302 int estimate
, size_t *palc
)
4304 struct d_growable_string dgs
;
4306 d_growable_string_init (&dgs
, estimate
);
4308 if (! cplus_demangle_print_callback (options
, dc
,
4309 d_growable_string_callback_adapter
,
4317 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4321 /* Returns the I'th element of the template arglist ARGS, or NULL on
4322 failure. If I is negative, return the entire arglist. */
4324 static struct demangle_component
*
4325 d_index_template_argument (struct demangle_component
*args
, int i
)
4327 struct demangle_component
*a
;
4330 /* Print the whole argument pack. */
4337 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4343 if (i
!= 0 || a
== NULL
)
4349 /* Returns the template argument from the current context indicated by DC,
4350 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4352 static struct demangle_component
*
4353 d_lookup_template_argument (struct d_print_info
*dpi
,
4354 const struct demangle_component
*dc
)
4356 if (dpi
->templates
== NULL
)
4358 d_print_error (dpi
);
4362 return d_index_template_argument
4363 (d_right (dpi
->templates
->template_decl
),
4364 dc
->u
.s_number
.number
);
4367 /* Returns a template argument pack used in DC (any will do), or NULL. */
4369 static struct demangle_component
*
4370 d_find_pack (struct d_print_info
*dpi
,
4371 const struct demangle_component
*dc
)
4373 struct demangle_component
*a
;
4379 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4380 a
= d_lookup_template_argument (dpi
, dc
);
4381 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4385 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4388 case DEMANGLE_COMPONENT_LAMBDA
:
4389 case DEMANGLE_COMPONENT_NAME
:
4390 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4391 case DEMANGLE_COMPONENT_OPERATOR
:
4392 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4393 case DEMANGLE_COMPONENT_SUB_STD
:
4394 case DEMANGLE_COMPONENT_CHARACTER
:
4395 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4396 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4397 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4398 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4399 case DEMANGLE_COMPONENT_NUMBER
:
4402 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4403 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4404 case DEMANGLE_COMPONENT_CTOR
:
4405 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4406 case DEMANGLE_COMPONENT_DTOR
:
4407 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4410 a
= d_find_pack (dpi
, d_left (dc
));
4413 return d_find_pack (dpi
, d_right (dc
));
4417 /* Returns the length of the template argument pack DC. */
4420 d_pack_length (const struct demangle_component
*dc
)
4423 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4424 && d_left (dc
) != NULL
)
4432 /* Returns the number of template args in DC, expanding any pack expansions
4436 d_args_length (struct d_print_info
*dpi
, const struct demangle_component
*dc
)
4439 for (; dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
;
4442 struct demangle_component
*elt
= d_left (dc
);
4445 if (elt
->type
== DEMANGLE_COMPONENT_PACK_EXPANSION
)
4447 struct demangle_component
*a
= d_find_pack (dpi
, d_left (elt
));
4448 count
+= d_pack_length (a
);
4456 /* DC is a component of a mangled expression. Print it, wrapped in parens
4460 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4461 struct demangle_component
*dc
)
4464 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4465 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4466 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4467 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4470 d_append_char (dpi
, '(');
4471 d_print_comp (dpi
, options
, dc
);
4473 d_append_char (dpi
, ')');
4476 /* Save the current scope. */
4479 d_save_scope (struct d_print_info
*dpi
,
4480 const struct demangle_component
*container
)
4482 struct d_saved_scope
*scope
;
4483 struct d_print_template
*src
, **link
;
4485 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4487 d_print_error (dpi
);
4490 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4491 dpi
->next_saved_scope
++;
4493 scope
->container
= container
;
4494 link
= &scope
->templates
;
4496 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4498 struct d_print_template
*dst
;
4500 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4502 d_print_error (dpi
);
4505 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4506 dpi
->next_copy_template
++;
4508 dst
->template_decl
= src
->template_decl
;
4516 /* Attempt to locate a previously saved scope. Returns NULL if no
4517 corresponding saved scope was found. */
4519 static struct d_saved_scope
*
4520 d_get_saved_scope (struct d_print_info
*dpi
,
4521 const struct demangle_component
*container
)
4525 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4526 if (dpi
->saved_scopes
[i
].container
== container
)
4527 return &dpi
->saved_scopes
[i
];
4532 /* If DC is a C++17 fold-expression, print it and return true; otherwise
4536 d_maybe_print_fold_expression (struct d_print_info
*dpi
, int options
,
4537 struct demangle_component
*dc
)
4539 struct demangle_component
*ops
, *operator_
, *op1
, *op2
;
4542 const char *fold_code
= d_left (dc
)->u
.s_operator
.op
->code
;
4543 if (fold_code
[0] != 'f')
4547 operator_
= d_left (ops
);
4548 op1
= d_right (ops
);
4550 if (op1
->type
== DEMANGLE_COMPONENT_TRINARY_ARG2
)
4552 op2
= d_right (op1
);
4556 /* Print the whole pack. */
4557 save_idx
= dpi
->pack_index
;
4558 dpi
->pack_index
= -1;
4560 switch (fold_code
[1])
4562 /* Unary left fold, (... + X). */
4564 d_append_string (dpi
, "(...");
4565 d_print_expr_op (dpi
, options
, operator_
);
4566 d_print_subexpr (dpi
, options
, op1
);
4567 d_append_char (dpi
, ')');
4570 /* Unary right fold, (X + ...). */
4572 d_append_char (dpi
, '(');
4573 d_print_subexpr (dpi
, options
, op1
);
4574 d_print_expr_op (dpi
, options
, operator_
);
4575 d_append_string (dpi
, "...)");
4578 /* Binary left fold, (42 + ... + X). */
4580 /* Binary right fold, (X + ... + 42). */
4582 d_append_char (dpi
, '(');
4583 d_print_subexpr (dpi
, options
, op1
);
4584 d_print_expr_op (dpi
, options
, operator_
);
4585 d_append_string (dpi
, "...");
4586 d_print_expr_op (dpi
, options
, operator_
);
4587 d_print_subexpr (dpi
, options
, op2
);
4588 d_append_char (dpi
, ')');
4592 dpi
->pack_index
= save_idx
;
4596 /* Subroutine to handle components. */
4599 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
4600 struct demangle_component
*dc
)
4602 /* Magic variable to let reference smashing skip over the next modifier
4603 without needing to modify *dc. */
4604 struct demangle_component
*mod_inner
= NULL
;
4606 /* Variable used to store the current templates while a previously
4607 captured scope is used. */
4608 struct d_print_template
*saved_templates
;
4610 /* Nonzero if templates have been stored in the above variable. */
4611 int need_template_restore
= 0;
4615 d_print_error (dpi
);
4618 if (d_print_saw_error (dpi
))
4623 case DEMANGLE_COMPONENT_NAME
:
4624 if ((options
& DMGL_JAVA
) == 0)
4625 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4627 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4630 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4631 d_print_comp (dpi
, options
, d_left (dc
));
4632 d_append_string (dpi
, "[abi:");
4633 d_print_comp (dpi
, options
, d_right (dc
));
4634 d_append_char (dpi
, ']');
4637 case DEMANGLE_COMPONENT_QUAL_NAME
:
4638 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4639 d_print_comp (dpi
, options
, d_left (dc
));
4640 if ((options
& DMGL_JAVA
) == 0)
4641 d_append_string (dpi
, "::");
4643 d_append_char (dpi
, '.');
4645 struct demangle_component
*local_name
= d_right (dc
);
4646 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4648 d_append_string (dpi
, "{default arg#");
4649 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4650 d_append_string (dpi
, "}::");
4651 local_name
= local_name
->u
.s_unary_num
.sub
;
4653 d_print_comp (dpi
, options
, local_name
);
4657 case DEMANGLE_COMPONENT_TYPED_NAME
:
4659 struct d_print_mod
*hold_modifiers
;
4660 struct demangle_component
*typed_name
;
4661 struct d_print_mod adpm
[4];
4663 struct d_print_template dpt
;
4665 /* Pass the name down to the type so that it can be printed in
4666 the right place for the type. We also have to pass down
4667 any CV-qualifiers, which apply to the this parameter. */
4668 hold_modifiers
= dpi
->modifiers
;
4671 typed_name
= d_left (dc
);
4672 while (typed_name
!= NULL
)
4674 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4676 d_print_error (dpi
);
4680 adpm
[i
].next
= dpi
->modifiers
;
4681 dpi
->modifiers
= &adpm
[i
];
4682 adpm
[i
].mod
= typed_name
;
4683 adpm
[i
].printed
= 0;
4684 adpm
[i
].templates
= dpi
->templates
;
4687 if (!is_fnqual_component_type (typed_name
->type
))
4690 typed_name
= d_left (typed_name
);
4693 if (typed_name
== NULL
)
4695 d_print_error (dpi
);
4699 /* If typed_name is a template, then it applies to the
4700 function type as well. */
4701 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4703 dpt
.next
= dpi
->templates
;
4704 dpi
->templates
= &dpt
;
4705 dpt
.template_decl
= typed_name
;
4708 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4709 there may be CV-qualifiers on its right argument which
4710 really apply here; this happens when parsing a class which
4711 is local to a function. */
4712 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4714 struct demangle_component
*local_name
;
4716 local_name
= d_right (typed_name
);
4717 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4718 local_name
= local_name
->u
.s_unary_num
.sub
;
4719 if (local_name
== NULL
)
4721 d_print_error (dpi
);
4724 while (is_fnqual_component_type (local_name
->type
))
4726 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4728 d_print_error (dpi
);
4732 adpm
[i
] = adpm
[i
- 1];
4733 adpm
[i
].next
= &adpm
[i
- 1];
4734 dpi
->modifiers
= &adpm
[i
];
4736 adpm
[i
- 1].mod
= local_name
;
4737 adpm
[i
- 1].printed
= 0;
4738 adpm
[i
- 1].templates
= dpi
->templates
;
4741 local_name
= d_left (local_name
);
4745 d_print_comp (dpi
, options
, d_right (dc
));
4747 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4748 dpi
->templates
= dpt
.next
;
4750 /* If the modifiers didn't get printed by the type, print them
4755 if (! adpm
[i
].printed
)
4757 d_append_char (dpi
, ' ');
4758 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4762 dpi
->modifiers
= hold_modifiers
;
4767 case DEMANGLE_COMPONENT_TEMPLATE
:
4769 struct d_print_mod
*hold_dpm
;
4770 struct demangle_component
*dcl
;
4771 const struct demangle_component
*hold_current
;
4773 /* This template may need to be referenced by a cast operator
4774 contained in its subtree. */
4775 hold_current
= dpi
->current_template
;
4776 dpi
->current_template
= dc
;
4778 /* Don't push modifiers into a template definition. Doing so
4779 could give the wrong definition for a template argument.
4780 Instead, treat the template essentially as a name. */
4782 hold_dpm
= dpi
->modifiers
;
4783 dpi
->modifiers
= NULL
;
4787 if ((options
& DMGL_JAVA
) != 0
4788 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4789 && dcl
->u
.s_name
.len
== 6
4790 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4792 /* Special-case Java arrays, so that JArray<TYPE> appears
4793 instead as TYPE[]. */
4795 d_print_comp (dpi
, options
, d_right (dc
));
4796 d_append_string (dpi
, "[]");
4800 d_print_comp (dpi
, options
, dcl
);
4801 if (d_last_char (dpi
) == '<')
4802 d_append_char (dpi
, ' ');
4803 d_append_char (dpi
, '<');
4804 d_print_comp (dpi
, options
, d_right (dc
));
4805 /* Avoid generating two consecutive '>' characters, to avoid
4806 the C++ syntactic ambiguity. */
4807 if (d_last_char (dpi
) == '>')
4808 d_append_char (dpi
, ' ');
4809 d_append_char (dpi
, '>');
4812 dpi
->modifiers
= hold_dpm
;
4813 dpi
->current_template
= hold_current
;
4818 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4819 if (dpi
->is_lambda_arg
)
4821 /* Show the template parm index, as that's how g++ displays
4822 these, and future proofs us against potential
4823 '[]<typename T> (T *a, T *b) {...}'. */
4824 d_append_buffer (dpi
, "auto:", 5);
4825 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4829 struct d_print_template
*hold_dpt
;
4830 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4832 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4833 a
= d_index_template_argument (a
, dpi
->pack_index
);
4837 d_print_error (dpi
);
4841 /* While processing this parameter, we need to pop the list
4842 of templates. This is because the template parameter may
4843 itself be a reference to a parameter of an outer
4846 hold_dpt
= dpi
->templates
;
4847 dpi
->templates
= hold_dpt
->next
;
4849 d_print_comp (dpi
, options
, a
);
4851 dpi
->templates
= hold_dpt
;
4855 case DEMANGLE_COMPONENT_CTOR
:
4856 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4859 case DEMANGLE_COMPONENT_DTOR
:
4860 d_append_char (dpi
, '~');
4861 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4864 case DEMANGLE_COMPONENT_VTABLE
:
4865 d_append_string (dpi
, "vtable for ");
4866 d_print_comp (dpi
, options
, d_left (dc
));
4869 case DEMANGLE_COMPONENT_VTT
:
4870 d_append_string (dpi
, "VTT for ");
4871 d_print_comp (dpi
, options
, d_left (dc
));
4874 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4875 d_append_string (dpi
, "construction vtable for ");
4876 d_print_comp (dpi
, options
, d_left (dc
));
4877 d_append_string (dpi
, "-in-");
4878 d_print_comp (dpi
, options
, d_right (dc
));
4881 case DEMANGLE_COMPONENT_TYPEINFO
:
4882 d_append_string (dpi
, "typeinfo for ");
4883 d_print_comp (dpi
, options
, d_left (dc
));
4886 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4887 d_append_string (dpi
, "typeinfo name for ");
4888 d_print_comp (dpi
, options
, d_left (dc
));
4891 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4892 d_append_string (dpi
, "typeinfo fn for ");
4893 d_print_comp (dpi
, options
, d_left (dc
));
4896 case DEMANGLE_COMPONENT_THUNK
:
4897 d_append_string (dpi
, "non-virtual thunk to ");
4898 d_print_comp (dpi
, options
, d_left (dc
));
4901 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4902 d_append_string (dpi
, "virtual thunk to ");
4903 d_print_comp (dpi
, options
, d_left (dc
));
4906 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4907 d_append_string (dpi
, "covariant return thunk to ");
4908 d_print_comp (dpi
, options
, d_left (dc
));
4911 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4912 d_append_string (dpi
, "java Class for ");
4913 d_print_comp (dpi
, options
, d_left (dc
));
4916 case DEMANGLE_COMPONENT_GUARD
:
4917 d_append_string (dpi
, "guard variable for ");
4918 d_print_comp (dpi
, options
, d_left (dc
));
4921 case DEMANGLE_COMPONENT_TLS_INIT
:
4922 d_append_string (dpi
, "TLS init function for ");
4923 d_print_comp (dpi
, options
, d_left (dc
));
4926 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4927 d_append_string (dpi
, "TLS wrapper function for ");
4928 d_print_comp (dpi
, options
, d_left (dc
));
4931 case DEMANGLE_COMPONENT_REFTEMP
:
4932 d_append_string (dpi
, "reference temporary #");
4933 d_print_comp (dpi
, options
, d_right (dc
));
4934 d_append_string (dpi
, " for ");
4935 d_print_comp (dpi
, options
, d_left (dc
));
4938 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4939 d_append_string (dpi
, "hidden alias for ");
4940 d_print_comp (dpi
, options
, d_left (dc
));
4943 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4944 d_append_string (dpi
, "transaction clone for ");
4945 d_print_comp (dpi
, options
, d_left (dc
));
4948 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4949 d_append_string (dpi
, "non-transaction clone for ");
4950 d_print_comp (dpi
, options
, d_left (dc
));
4953 case DEMANGLE_COMPONENT_SUB_STD
:
4954 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4957 case DEMANGLE_COMPONENT_RESTRICT
:
4958 case DEMANGLE_COMPONENT_VOLATILE
:
4959 case DEMANGLE_COMPONENT_CONST
:
4961 struct d_print_mod
*pdpm
;
4963 /* When printing arrays, it's possible to have cases where the
4964 same CV-qualifier gets pushed on the stack multiple times.
4965 We only need to print it once. */
4967 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4969 if (! pdpm
->printed
)
4971 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4972 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4973 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4975 if (pdpm
->mod
->type
== dc
->type
)
4977 d_print_comp (dpi
, options
, d_left (dc
));
4985 case DEMANGLE_COMPONENT_REFERENCE
:
4986 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4988 /* Handle reference smashing: & + && = &. */
4989 struct demangle_component
*sub
= d_left (dc
);
4990 if (!dpi
->is_lambda_arg
4991 && sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4993 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4994 struct demangle_component
*a
;
4998 /* This is the first time SUB has been traversed.
4999 We need to capture the current templates so
5000 they can be restored if SUB is reentered as a
5002 d_save_scope (dpi
, sub
);
5003 if (d_print_saw_error (dpi
))
5008 const struct d_component_stack
*dcse
;
5009 int found_self_or_parent
= 0;
5011 /* This traversal is reentering SUB as a substition.
5012 If we are not beneath SUB or DC in the tree then we
5013 need to restore SUB's template stack temporarily. */
5014 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
5015 dcse
= dcse
->parent
)
5019 && dcse
!= dpi
->component_stack
))
5021 found_self_or_parent
= 1;
5026 if (!found_self_or_parent
)
5028 saved_templates
= dpi
->templates
;
5029 dpi
->templates
= scope
->templates
;
5030 need_template_restore
= 1;
5034 a
= d_lookup_template_argument (dpi
, sub
);
5035 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
5036 a
= d_index_template_argument (a
, dpi
->pack_index
);
5040 if (need_template_restore
)
5041 dpi
->templates
= saved_templates
;
5043 d_print_error (dpi
);
5050 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
5051 || sub
->type
== dc
->type
)
5053 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
5054 mod_inner
= d_left (sub
);
5058 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5059 case DEMANGLE_COMPONENT_POINTER
:
5060 case DEMANGLE_COMPONENT_COMPLEX
:
5061 case DEMANGLE_COMPONENT_IMAGINARY
:
5062 FNQUAL_COMPONENT_CASE
:
5065 /* We keep a list of modifiers on the stack. */
5066 struct d_print_mod dpm
;
5068 dpm
.next
= dpi
->modifiers
;
5069 dpi
->modifiers
= &dpm
;
5072 dpm
.templates
= dpi
->templates
;
5075 mod_inner
= d_left (dc
);
5077 d_print_comp (dpi
, options
, mod_inner
);
5079 /* If the modifier didn't get printed by the type, print it
5082 d_print_mod (dpi
, options
, dc
);
5084 dpi
->modifiers
= dpm
.next
;
5086 if (need_template_restore
)
5087 dpi
->templates
= saved_templates
;
5092 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5093 if ((options
& DMGL_JAVA
) == 0)
5094 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
5095 dc
->u
.s_builtin
.type
->len
);
5097 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
5098 dc
->u
.s_builtin
.type
->java_len
);
5101 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5102 d_print_comp (dpi
, options
, d_left (dc
));
5105 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5107 if ((options
& DMGL_RET_POSTFIX
) != 0)
5108 d_print_function_type (dpi
,
5109 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5110 dc
, dpi
->modifiers
);
5112 /* Print return type if present */
5113 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
5114 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5116 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
5118 struct d_print_mod dpm
;
5120 /* We must pass this type down as a modifier in order to
5121 print it in the right location. */
5122 dpm
.next
= dpi
->modifiers
;
5123 dpi
->modifiers
= &dpm
;
5126 dpm
.templates
= dpi
->templates
;
5128 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5131 dpi
->modifiers
= dpm
.next
;
5136 /* In standard prefix notation, there is a space between the
5137 return type and the function signature. */
5138 if ((options
& DMGL_RET_POSTFIX
) == 0)
5139 d_append_char (dpi
, ' ');
5142 if ((options
& DMGL_RET_POSTFIX
) == 0)
5143 d_print_function_type (dpi
,
5144 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5145 dc
, dpi
->modifiers
);
5150 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5152 struct d_print_mod
*hold_modifiers
;
5153 struct d_print_mod adpm
[4];
5155 struct d_print_mod
*pdpm
;
5157 /* We must pass this type down as a modifier in order to print
5158 multi-dimensional arrays correctly. If the array itself is
5159 CV-qualified, we act as though the element type were
5160 CV-qualified. We do this by copying the modifiers down
5161 rather than fiddling pointers, so that we don't wind up
5162 with a d_print_mod higher on the stack pointing into our
5163 stack frame after we return. */
5165 hold_modifiers
= dpi
->modifiers
;
5167 adpm
[0].next
= hold_modifiers
;
5168 dpi
->modifiers
= &adpm
[0];
5170 adpm
[0].printed
= 0;
5171 adpm
[0].templates
= dpi
->templates
;
5174 pdpm
= hold_modifiers
;
5176 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
5177 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
5178 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
5180 if (! pdpm
->printed
)
5182 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5184 d_print_error (dpi
);
5189 adpm
[i
].next
= dpi
->modifiers
;
5190 dpi
->modifiers
= &adpm
[i
];
5198 d_print_comp (dpi
, options
, d_right (dc
));
5200 dpi
->modifiers
= hold_modifiers
;
5202 if (adpm
[0].printed
)
5208 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5211 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
5216 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5217 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5219 struct d_print_mod dpm
;
5221 dpm
.next
= dpi
->modifiers
;
5222 dpi
->modifiers
= &dpm
;
5225 dpm
.templates
= dpi
->templates
;
5227 d_print_comp (dpi
, options
, d_right (dc
));
5229 /* If the modifier didn't get printed by the type, print it
5232 d_print_mod (dpi
, options
, dc
);
5234 dpi
->modifiers
= dpm
.next
;
5239 case DEMANGLE_COMPONENT_FIXED_TYPE
:
5240 if (dc
->u
.s_fixed
.sat
)
5241 d_append_string (dpi
, "_Sat ");
5242 /* Don't print "int _Accum". */
5243 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
5244 != &cplus_demangle_builtin_types
['i'-'a'])
5246 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
5247 d_append_char (dpi
, ' ');
5249 if (dc
->u
.s_fixed
.accum
)
5250 d_append_string (dpi
, "_Accum");
5252 d_append_string (dpi
, "_Fract");
5255 case DEMANGLE_COMPONENT_ARGLIST
:
5256 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5257 if (d_left (dc
) != NULL
)
5258 d_print_comp (dpi
, options
, d_left (dc
));
5259 if (d_right (dc
) != NULL
)
5262 unsigned long int flush_count
;
5263 /* Make sure ", " isn't flushed by d_append_string, otherwise
5264 dpi->len -= 2 wouldn't work. */
5265 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5266 d_print_flush (dpi
);
5267 d_append_string (dpi
, ", ");
5269 flush_count
= dpi
->flush_count
;
5270 d_print_comp (dpi
, options
, d_right (dc
));
5271 /* If that didn't print anything (which can happen with empty
5272 template argument packs), remove the comma and space. */
5273 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5278 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5280 struct demangle_component
*type
= d_left (dc
);
5281 struct demangle_component
*list
= d_right (dc
);
5284 d_print_comp (dpi
, options
, type
);
5285 d_append_char (dpi
, '{');
5286 d_print_comp (dpi
, options
, list
);
5287 d_append_char (dpi
, '}');
5291 case DEMANGLE_COMPONENT_OPERATOR
:
5293 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5296 d_append_string (dpi
, "operator");
5297 /* Add a space before new/delete. */
5298 if (IS_LOWER (op
->name
[0]))
5299 d_append_char (dpi
, ' ');
5300 /* Omit a trailing space. */
5301 if (op
->name
[len
-1] == ' ')
5303 d_append_buffer (dpi
, op
->name
, len
);
5307 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5308 d_append_string (dpi
, "operator ");
5309 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5312 case DEMANGLE_COMPONENT_CONVERSION
:
5313 d_append_string (dpi
, "operator ");
5314 d_print_conversion (dpi
, options
, dc
);
5317 case DEMANGLE_COMPONENT_NULLARY
:
5318 d_print_expr_op (dpi
, options
, d_left (dc
));
5321 case DEMANGLE_COMPONENT_UNARY
:
5323 struct demangle_component
*op
= d_left (dc
);
5324 struct demangle_component
*operand
= d_right (dc
);
5325 const char *code
= NULL
;
5327 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5329 code
= op
->u
.s_operator
.op
->code
;
5330 if (!strcmp (code
, "ad"))
5332 /* Don't print the argument list for the address of a
5334 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5335 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5336 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5337 operand
= d_left (operand
);
5339 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5341 /* This indicates a suffix operator. */
5342 operand
= d_left (operand
);
5343 d_print_subexpr (dpi
, options
, operand
);
5344 d_print_expr_op (dpi
, options
, op
);
5349 /* For sizeof..., just print the pack length. */
5350 if (code
&& !strcmp (code
, "sZ"))
5352 struct demangle_component
*a
= d_find_pack (dpi
, operand
);
5353 int len
= d_pack_length (a
);
5354 d_append_num (dpi
, len
);
5357 else if (code
&& !strcmp (code
, "sP"))
5359 int len
= d_args_length (dpi
, operand
);
5360 d_append_num (dpi
, len
);
5364 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5365 d_print_expr_op (dpi
, options
, op
);
5368 d_append_char (dpi
, '(');
5369 d_print_cast (dpi
, options
, op
);
5370 d_append_char (dpi
, ')');
5372 if (code
&& !strcmp (code
, "gs"))
5373 /* Avoid parens after '::'. */
5374 d_print_comp (dpi
, options
, operand
);
5375 else if (code
&& !strcmp (code
, "st"))
5376 /* Always print parens for sizeof (type). */
5378 d_append_char (dpi
, '(');
5379 d_print_comp (dpi
, options
, operand
);
5380 d_append_char (dpi
, ')');
5383 d_print_subexpr (dpi
, options
, operand
);
5387 case DEMANGLE_COMPONENT_BINARY
:
5388 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5390 d_print_error (dpi
);
5394 if (op_is_new_cast (d_left (dc
)))
5396 d_print_expr_op (dpi
, options
, d_left (dc
));
5397 d_append_char (dpi
, '<');
5398 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5399 d_append_string (dpi
, ">(");
5400 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5401 d_append_char (dpi
, ')');
5405 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5408 /* We wrap an expression which uses the greater-than operator in
5409 an extra layer of parens so that it does not get confused
5410 with the '>' which ends the template parameters. */
5411 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5412 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5413 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5414 d_append_char (dpi
, '(');
5416 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5417 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5419 /* Function call used in an expression should not have printed types
5420 of the function arguments. Values of the function arguments still
5421 get printed below. */
5423 const struct demangle_component
*func
= d_left (d_right (dc
));
5425 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5426 d_print_error (dpi
);
5427 d_print_subexpr (dpi
, options
, d_left (func
));
5430 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5431 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5433 d_append_char (dpi
, '[');
5434 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5435 d_append_char (dpi
, ']');
5439 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5440 d_print_expr_op (dpi
, options
, d_left (dc
));
5441 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5444 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5445 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5446 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5447 d_append_char (dpi
, ')');
5451 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5452 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5453 d_print_error (dpi
);
5456 case DEMANGLE_COMPONENT_TRINARY
:
5457 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5458 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5460 d_print_error (dpi
);
5463 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5466 struct demangle_component
*op
= d_left (dc
);
5467 struct demangle_component
*first
= d_left (d_right (dc
));
5468 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5469 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5471 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5473 d_print_subexpr (dpi
, options
, first
);
5474 d_print_expr_op (dpi
, options
, op
);
5475 d_print_subexpr (dpi
, options
, second
);
5476 d_append_string (dpi
, " : ");
5477 d_print_subexpr (dpi
, options
, third
);
5481 d_append_string (dpi
, "new ");
5482 if (d_left (first
) != NULL
)
5484 d_print_subexpr (dpi
, options
, first
);
5485 d_append_char (dpi
, ' ');
5487 d_print_comp (dpi
, options
, second
);
5489 d_print_subexpr (dpi
, options
, third
);
5494 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5495 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5496 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5497 d_print_error (dpi
);
5500 case DEMANGLE_COMPONENT_LITERAL
:
5501 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5503 enum d_builtin_type_print tp
;
5505 /* For some builtin types, produce simpler output. */
5506 tp
= D_PRINT_DEFAULT
;
5507 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5509 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5513 case D_PRINT_UNSIGNED
:
5515 case D_PRINT_UNSIGNED_LONG
:
5516 case D_PRINT_LONG_LONG
:
5517 case D_PRINT_UNSIGNED_LONG_LONG
:
5518 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5520 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5521 d_append_char (dpi
, '-');
5522 d_print_comp (dpi
, options
, d_right (dc
));
5527 case D_PRINT_UNSIGNED
:
5528 d_append_char (dpi
, 'u');
5531 d_append_char (dpi
, 'l');
5533 case D_PRINT_UNSIGNED_LONG
:
5534 d_append_string (dpi
, "ul");
5536 case D_PRINT_LONG_LONG
:
5537 d_append_string (dpi
, "ll");
5539 case D_PRINT_UNSIGNED_LONG_LONG
:
5540 d_append_string (dpi
, "ull");
5548 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5549 && d_right (dc
)->u
.s_name
.len
== 1
5550 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5552 switch (d_right (dc
)->u
.s_name
.s
[0])
5555 d_append_string (dpi
, "false");
5558 d_append_string (dpi
, "true");
5571 d_append_char (dpi
, '(');
5572 d_print_comp (dpi
, options
, d_left (dc
));
5573 d_append_char (dpi
, ')');
5574 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5575 d_append_char (dpi
, '-');
5576 if (tp
== D_PRINT_FLOAT
)
5577 d_append_char (dpi
, '[');
5578 d_print_comp (dpi
, options
, d_right (dc
));
5579 if (tp
== D_PRINT_FLOAT
)
5580 d_append_char (dpi
, ']');
5584 case DEMANGLE_COMPONENT_NUMBER
:
5585 d_append_num (dpi
, dc
->u
.s_number
.number
);
5588 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5589 d_append_string (dpi
, "java resource ");
5590 d_print_comp (dpi
, options
, d_left (dc
));
5593 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5594 d_print_comp (dpi
, options
, d_left (dc
));
5595 d_print_comp (dpi
, options
, d_right (dc
));
5598 case DEMANGLE_COMPONENT_CHARACTER
:
5599 d_append_char (dpi
, dc
->u
.s_character
.character
);
5602 case DEMANGLE_COMPONENT_DECLTYPE
:
5603 d_append_string (dpi
, "decltype (");
5604 d_print_comp (dpi
, options
, d_left (dc
));
5605 d_append_char (dpi
, ')');
5608 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5612 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5615 /* d_find_pack won't find anything if the only packs involved
5616 in this expansion are function parameter packs; in that
5617 case, just print the pattern and "...". */
5618 d_print_subexpr (dpi
, options
, d_left (dc
));
5619 d_append_string (dpi
, "...");
5623 len
= d_pack_length (a
);
5625 for (i
= 0; i
< len
; ++i
)
5627 dpi
->pack_index
= i
;
5628 d_print_comp (dpi
, options
, dc
);
5630 d_append_string (dpi
, ", ");
5635 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5637 long num
= dc
->u
.s_number
.number
;
5639 d_append_string (dpi
, "this");
5642 d_append_string (dpi
, "{parm#");
5643 d_append_num (dpi
, num
);
5644 d_append_char (dpi
, '}');
5649 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5650 d_append_string (dpi
, "global constructors keyed to ");
5651 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5654 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5655 d_append_string (dpi
, "global destructors keyed to ");
5656 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5659 case DEMANGLE_COMPONENT_LAMBDA
:
5660 d_append_string (dpi
, "{lambda(");
5661 /* Generic lambda auto parms are mangled as the template type
5663 dpi
->is_lambda_arg
++;
5664 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5665 dpi
->is_lambda_arg
--;
5666 d_append_string (dpi
, ")#");
5667 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5668 d_append_char (dpi
, '}');
5671 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5672 d_append_string (dpi
, "{unnamed type#");
5673 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5674 d_append_char (dpi
, '}');
5677 case DEMANGLE_COMPONENT_CLONE
:
5678 d_print_comp (dpi
, options
, d_left (dc
));
5679 d_append_string (dpi
, " [clone ");
5680 d_print_comp (dpi
, options
, d_right (dc
));
5681 d_append_char (dpi
, ']');
5685 d_print_error (dpi
);
5691 d_print_comp (struct d_print_info
*dpi
, int options
,
5692 struct demangle_component
*dc
)
5694 struct d_component_stack self
;
5695 if (dc
== NULL
|| dc
->d_printing
> 1 || dpi
->recursion
> MAX_RECURSION_COUNT
)
5697 d_print_error (dpi
);
5705 self
.parent
= dpi
->component_stack
;
5706 dpi
->component_stack
= &self
;
5708 d_print_comp_inner (dpi
, options
, dc
);
5710 dpi
->component_stack
= self
.parent
;
5715 /* Print a Java dentifier. For Java we try to handle encoded extended
5716 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5717 so we don't it for C++. Characters are encoded as
5721 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5727 for (p
= name
; p
< end
; ++p
)
5738 for (q
= p
+ 3; q
< end
; ++q
)
5744 else if (*q
>= 'A' && *q
<= 'F')
5745 dig
= *q
- 'A' + 10;
5746 else if (*q
>= 'a' && *q
<= 'f')
5747 dig
= *q
- 'a' + 10;
5753 /* If the Unicode character is larger than 256, we don't try
5754 to deal with it here. FIXME. */
5755 if (q
< end
&& *q
== '_' && c
< 256)
5757 d_append_char (dpi
, c
);
5763 d_append_char (dpi
, *p
);
5767 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5768 qualifiers on this after printing a function. */
5771 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5772 struct d_print_mod
*mods
, int suffix
)
5774 struct d_print_template
*hold_dpt
;
5776 if (mods
== NULL
|| d_print_saw_error (dpi
))
5781 && (is_fnqual_component_type (mods
->mod
->type
))))
5783 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5789 hold_dpt
= dpi
->templates
;
5790 dpi
->templates
= mods
->templates
;
5792 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5794 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5795 dpi
->templates
= hold_dpt
;
5798 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5800 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5801 dpi
->templates
= hold_dpt
;
5804 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5806 struct d_print_mod
*hold_modifiers
;
5807 struct demangle_component
*dc
;
5809 /* When this is on the modifier stack, we have pulled any
5810 qualifiers off the right argument already. Otherwise, we
5811 print it as usual, but don't let the left argument see any
5814 hold_modifiers
= dpi
->modifiers
;
5815 dpi
->modifiers
= NULL
;
5816 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5817 dpi
->modifiers
= hold_modifiers
;
5819 if ((options
& DMGL_JAVA
) == 0)
5820 d_append_string (dpi
, "::");
5822 d_append_char (dpi
, '.');
5824 dc
= d_right (mods
->mod
);
5826 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5828 d_append_string (dpi
, "{default arg#");
5829 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5830 d_append_string (dpi
, "}::");
5831 dc
= dc
->u
.s_unary_num
.sub
;
5834 while (is_fnqual_component_type (dc
->type
))
5837 d_print_comp (dpi
, options
, dc
);
5839 dpi
->templates
= hold_dpt
;
5843 d_print_mod (dpi
, options
, mods
->mod
);
5845 dpi
->templates
= hold_dpt
;
5847 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5850 /* Print a modifier. */
5853 d_print_mod (struct d_print_info
*dpi
, int options
,
5854 struct demangle_component
*mod
)
5858 case DEMANGLE_COMPONENT_RESTRICT
:
5859 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5860 d_append_string (dpi
, " restrict");
5862 case DEMANGLE_COMPONENT_VOLATILE
:
5863 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5864 d_append_string (dpi
, " volatile");
5866 case DEMANGLE_COMPONENT_CONST
:
5867 case DEMANGLE_COMPONENT_CONST_THIS
:
5868 d_append_string (dpi
, " const");
5870 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5871 d_append_string (dpi
, " transaction_safe");
5873 case DEMANGLE_COMPONENT_NOEXCEPT
:
5874 d_append_string (dpi
, " noexcept");
5877 d_append_char (dpi
, '(');
5878 d_print_comp (dpi
, options
, d_right (mod
));
5879 d_append_char (dpi
, ')');
5882 case DEMANGLE_COMPONENT_THROW_SPEC
:
5883 d_append_string (dpi
, " throw");
5886 d_append_char (dpi
, '(');
5887 d_print_comp (dpi
, options
, d_right (mod
));
5888 d_append_char (dpi
, ')');
5891 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5892 d_append_char (dpi
, ' ');
5893 d_print_comp (dpi
, options
, d_right (mod
));
5895 case DEMANGLE_COMPONENT_POINTER
:
5896 /* There is no pointer symbol in Java. */
5897 if ((options
& DMGL_JAVA
) == 0)
5898 d_append_char (dpi
, '*');
5900 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5901 /* For the ref-qualifier, put a space before the &. */
5902 d_append_char (dpi
, ' ');
5904 case DEMANGLE_COMPONENT_REFERENCE
:
5905 d_append_char (dpi
, '&');
5907 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5908 d_append_char (dpi
, ' ');
5910 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5911 d_append_string (dpi
, "&&");
5913 case DEMANGLE_COMPONENT_COMPLEX
:
5914 d_append_string (dpi
, "complex ");
5916 case DEMANGLE_COMPONENT_IMAGINARY
:
5917 d_append_string (dpi
, "imaginary ");
5919 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5920 if (d_last_char (dpi
) != '(')
5921 d_append_char (dpi
, ' ');
5922 d_print_comp (dpi
, options
, d_left (mod
));
5923 d_append_string (dpi
, "::*");
5925 case DEMANGLE_COMPONENT_TYPED_NAME
:
5926 d_print_comp (dpi
, options
, d_left (mod
));
5928 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5929 d_append_string (dpi
, " __vector(");
5930 d_print_comp (dpi
, options
, d_left (mod
));
5931 d_append_char (dpi
, ')');
5935 /* Otherwise, we have something that won't go back on the
5936 modifier stack, so we can just print it. */
5937 d_print_comp (dpi
, options
, mod
);
5942 /* Print a function type, except for the return type. */
5945 d_print_function_type (struct d_print_info
*dpi
, int options
,
5946 struct demangle_component
*dc
,
5947 struct d_print_mod
*mods
)
5951 struct d_print_mod
*p
;
5952 struct d_print_mod
*hold_modifiers
;
5956 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5961 switch (p
->mod
->type
)
5963 case DEMANGLE_COMPONENT_POINTER
:
5964 case DEMANGLE_COMPONENT_REFERENCE
:
5965 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5968 case DEMANGLE_COMPONENT_RESTRICT
:
5969 case DEMANGLE_COMPONENT_VOLATILE
:
5970 case DEMANGLE_COMPONENT_CONST
:
5971 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5972 case DEMANGLE_COMPONENT_COMPLEX
:
5973 case DEMANGLE_COMPONENT_IMAGINARY
:
5974 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5978 FNQUAL_COMPONENT_CASE
:
5991 if (d_last_char (dpi
) != '('
5992 && d_last_char (dpi
) != '*')
5995 if (need_space
&& d_last_char (dpi
) != ' ')
5996 d_append_char (dpi
, ' ');
5997 d_append_char (dpi
, '(');
6000 hold_modifiers
= dpi
->modifiers
;
6001 dpi
->modifiers
= NULL
;
6003 d_print_mod_list (dpi
, options
, mods
, 0);
6006 d_append_char (dpi
, ')');
6008 d_append_char (dpi
, '(');
6010 if (d_right (dc
) != NULL
)
6011 d_print_comp (dpi
, options
, d_right (dc
));
6013 d_append_char (dpi
, ')');
6015 d_print_mod_list (dpi
, options
, mods
, 1);
6017 dpi
->modifiers
= hold_modifiers
;
6020 /* Print an array type, except for the element type. */
6023 d_print_array_type (struct d_print_info
*dpi
, int options
,
6024 struct demangle_component
*dc
,
6025 struct d_print_mod
*mods
)
6033 struct d_print_mod
*p
;
6036 for (p
= mods
; p
!= NULL
; p
= p
->next
)
6040 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
6055 d_append_string (dpi
, " (");
6057 d_print_mod_list (dpi
, options
, mods
, 0);
6060 d_append_char (dpi
, ')');
6064 d_append_char (dpi
, ' ');
6066 d_append_char (dpi
, '[');
6068 if (d_left (dc
) != NULL
)
6069 d_print_comp (dpi
, options
, d_left (dc
));
6071 d_append_char (dpi
, ']');
6074 /* Print an operator in an expression. */
6077 d_print_expr_op (struct d_print_info
*dpi
, int options
,
6078 struct demangle_component
*dc
)
6080 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
6081 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
6082 dc
->u
.s_operator
.op
->len
);
6084 d_print_comp (dpi
, options
, dc
);
6090 d_print_cast (struct d_print_info
*dpi
, int options
,
6091 struct demangle_component
*dc
)
6093 d_print_comp (dpi
, options
, d_left (dc
));
6096 /* Print a conversion operator. */
6099 d_print_conversion (struct d_print_info
*dpi
, int options
,
6100 struct demangle_component
*dc
)
6102 struct d_print_template dpt
;
6104 /* For a conversion operator, we need the template parameters from
6105 the enclosing template in scope for processing the type. */
6106 if (dpi
->current_template
!= NULL
)
6108 dpt
.next
= dpi
->templates
;
6109 dpi
->templates
= &dpt
;
6110 dpt
.template_decl
= dpi
->current_template
;
6113 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
6115 d_print_comp (dpi
, options
, d_left (dc
));
6116 if (dpi
->current_template
!= NULL
)
6117 dpi
->templates
= dpt
.next
;
6121 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
6123 /* For a templated cast operator, we need to remove the template
6124 parameters from scope after printing the operator name,
6125 so we need to handle the template printing here. */
6126 if (dpi
->current_template
!= NULL
)
6127 dpi
->templates
= dpt
.next
;
6129 if (d_last_char (dpi
) == '<')
6130 d_append_char (dpi
, ' ');
6131 d_append_char (dpi
, '<');
6132 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
6133 /* Avoid generating two consecutive '>' characters, to avoid
6134 the C++ syntactic ambiguity. */
6135 if (d_last_char (dpi
) == '>')
6136 d_append_char (dpi
, ' ');
6137 d_append_char (dpi
, '>');
6141 /* Initialize the information structure we use to pass around
6144 CP_STATIC_IF_GLIBCPP_V3
6146 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
6150 di
->send
= mangled
+ len
;
6151 di
->options
= options
;
6155 /* We can not need more components than twice the number of chars in
6156 the mangled string. Most components correspond directly to
6157 chars, but the ARGLIST types are exceptions. */
6158 di
->num_comps
= 2 * len
;
6161 /* Similarly, we can not need more substitutions than there are
6162 chars in the mangled string. */
6166 di
->last_name
= NULL
;
6169 di
->is_expression
= 0;
6170 di
->is_conversion
= 0;
6173 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
6174 mangled name, return strings in repeated callback giving the demangled
6175 name. OPTIONS is the usual libiberty demangler options. On success,
6176 this returns 1. On failure, returns 0. */
6179 d_demangle_callback (const char *mangled
, int options
,
6180 demangle_callbackref callback
, void *opaque
)
6191 struct demangle_component
*dc
;
6194 if (mangled
[0] == '_' && mangled
[1] == 'Z')
6196 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
6197 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
6198 && (mangled
[9] == 'D' || mangled
[9] == 'I')
6199 && mangled
[10] == '_')
6200 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
6203 if ((options
& DMGL_TYPES
) == 0)
6208 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
6211 #ifdef CP_DYNAMIC_ARRAYS
6212 __extension__
struct demangle_component comps
[di
.num_comps
];
6213 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6218 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6219 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6225 dc
= cplus_demangle_type (&di
);
6228 dc
= cplus_demangle_mangled_name (&di
, 1);
6230 case DCT_GLOBAL_CTORS
:
6231 case DCT_GLOBAL_DTORS
:
6232 d_advance (&di
, 11);
6233 dc
= d_make_comp (&di
,
6234 (type
== DCT_GLOBAL_CTORS
6235 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
6236 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
6237 d_make_demangle_mangled_name (&di
, d_str (&di
)),
6239 d_advance (&di
, strlen (d_str (&di
)));
6242 abort (); /* We have listed all the cases. */
6245 /* If DMGL_PARAMS is set, then if we didn't consume the entire
6246 mangled string, then we didn't successfully demangle it. If
6247 DMGL_PARAMS is not set, we didn't look at the trailing
6249 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
6252 #ifdef CP_DEMANGLE_DEBUG
6256 status
= (dc
!= NULL
)
6257 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6264 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6265 name, return a buffer allocated with malloc holding the demangled
6266 name. OPTIONS is the usual libiberty demangler options. On
6267 success, this sets *PALC to the allocated size of the returned
6268 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6269 a memory allocation failure, and returns NULL. */
6272 d_demangle (const char *mangled
, int options
, size_t *palc
)
6274 struct d_growable_string dgs
;
6277 d_growable_string_init (&dgs
, 0);
6279 status
= d_demangle_callback (mangled
, options
,
6280 d_growable_string_callback_adapter
, &dgs
);
6288 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6292 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6294 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6296 /* ia64 ABI-mandated entry point in the C++ runtime library for
6297 performing demangling. MANGLED_NAME is a NUL-terminated character
6298 string containing the name to be demangled.
6300 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6301 *LENGTH bytes, into which the demangled name is stored. If
6302 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6303 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6304 is placed in a region of memory allocated with malloc.
6306 If LENGTH is non-NULL, the length of the buffer containing the
6307 demangled name, is placed in *LENGTH.
6309 The return value is a pointer to the start of the NUL-terminated
6310 demangled name, or NULL if the demangling fails. The caller is
6311 responsible for deallocating this memory using free.
6313 *STATUS is set to one of the following values:
6314 0: The demangling operation succeeded.
6315 -1: A memory allocation failure occurred.
6316 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6317 -3: One of the arguments is invalid.
6319 The demangling is performed using the C++ ABI mangling rules, with
6323 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6324 size_t *length
, int *status
)
6329 if (mangled_name
== NULL
)
6336 if (output_buffer
!= NULL
&& length
== NULL
)
6343 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6345 if (demangled
== NULL
)
6357 if (output_buffer
== NULL
)
6364 if (strlen (demangled
) < *length
)
6366 strcpy (output_buffer
, demangled
);
6368 demangled
= output_buffer
;
6372 free (output_buffer
);
6383 extern int __gcclibcxx_demangle_callback (const char *,
6385 (const char *, size_t, void *),
6388 /* Alternative, allocationless entry point in the C++ runtime library
6389 for performing demangling. MANGLED_NAME is a NUL-terminated character
6390 string containing the name to be demangled.
6392 CALLBACK is a callback function, called with demangled string
6393 segments as demangling progresses; it is called at least once,
6394 but may be called more than once. OPAQUE is a generalized pointer
6395 used as a callback argument.
6397 The return code is one of the following values, equivalent to
6398 the STATUS values of __cxa_demangle() (excluding -1, since this
6399 function performs no memory allocations):
6400 0: The demangling operation succeeded.
6401 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6402 -3: One of the arguments is invalid.
6404 The demangling is performed using the C++ ABI mangling rules, with
6408 __gcclibcxx_demangle_callback (const char *mangled_name
,
6409 void (*callback
) (const char *, size_t, void *),
6414 if (mangled_name
== NULL
|| callback
== NULL
)
6417 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6425 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6427 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6428 mangled name, return a buffer allocated with malloc holding the
6429 demangled name. Otherwise, return NULL. */
6432 cplus_demangle_v3 (const char *mangled
, int options
)
6436 return d_demangle (mangled
, options
, &alc
);
6440 cplus_demangle_v3_callback (const char *mangled
, int options
,
6441 demangle_callbackref callback
, void *opaque
)
6443 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6446 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6447 conventions, but the output formatting is a little different.
6448 This instructs the C++ demangler not to emit pointer characters ("*"), to
6449 use Java's namespace separator symbol ("." instead of "::"), and to output
6450 JArray<TYPE> as TYPE[]. */
6453 java_demangle_v3 (const char *mangled
)
6457 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6461 java_demangle_v3_callback (const char *mangled
,
6462 demangle_callbackref callback
, void *opaque
)
6464 return d_demangle_callback (mangled
,
6465 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6469 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6471 #ifndef IN_GLIBCPP_V3
6473 /* Demangle a string in order to find out whether it is a constructor
6474 or destructor. Return non-zero on success. Set *CTOR_KIND and
6475 *DTOR_KIND appropriately. */
6478 is_ctor_or_dtor (const char *mangled
,
6479 enum gnu_v3_ctor_kinds
*ctor_kind
,
6480 enum gnu_v3_dtor_kinds
*dtor_kind
)
6483 struct demangle_component
*dc
;
6486 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6487 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6489 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6492 #ifdef CP_DYNAMIC_ARRAYS
6493 __extension__
struct demangle_component comps
[di
.num_comps
];
6494 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6499 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6500 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6503 dc
= cplus_demangle_mangled_name (&di
, 1);
6505 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6506 to demangle the entire string. */
6513 /* These cannot appear on a constructor or destructor. */
6514 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6515 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6516 case DEMANGLE_COMPONENT_CONST_THIS
:
6517 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6518 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6522 case DEMANGLE_COMPONENT_TYPED_NAME
:
6523 case DEMANGLE_COMPONENT_TEMPLATE
:
6526 case DEMANGLE_COMPONENT_QUAL_NAME
:
6527 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6530 case DEMANGLE_COMPONENT_CTOR
:
6531 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6535 case DEMANGLE_COMPONENT_DTOR
:
6536 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6547 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6548 name. A non-zero return indicates the type of constructor. */
6550 enum gnu_v3_ctor_kinds
6551 is_gnu_v3_mangled_ctor (const char *name
)
6553 enum gnu_v3_ctor_kinds ctor_kind
;
6554 enum gnu_v3_dtor_kinds dtor_kind
;
6556 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6557 return (enum gnu_v3_ctor_kinds
) 0;
6562 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6563 name. A non-zero return indicates the type of destructor. */
6565 enum gnu_v3_dtor_kinds
6566 is_gnu_v3_mangled_dtor (const char *name
)
6568 enum gnu_v3_ctor_kinds ctor_kind
;
6569 enum gnu_v3_dtor_kinds dtor_kind
;
6571 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6572 return (enum gnu_v3_dtor_kinds
) 0;
6576 #endif /* IN_GLIBCPP_V3 */
6578 #ifdef STANDALONE_DEMANGLER
6581 #include "dyn-string.h"
6583 static void print_usage (FILE* fp
, int exit_value
);
6585 #define IS_ALPHA(CHAR) \
6586 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6587 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6589 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6590 #define is_mangled_char(CHAR) \
6591 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6592 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6594 /* The name of this program, as invoked. */
6595 const char* program_name
;
6597 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6600 print_usage (FILE* fp
, int exit_value
)
6602 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6603 fprintf (fp
, "Options:\n");
6604 fprintf (fp
, " -h,--help Display this message.\n");
6605 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6606 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6607 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6612 /* Option specification for getopt_long. */
6613 static const struct option long_options
[] =
6615 { "help", no_argument
, NULL
, 'h' },
6616 { "no-params", no_argument
, NULL
, 'p' },
6617 { "verbose", no_argument
, NULL
, 'v' },
6618 { NULL
, no_argument
, NULL
, 0 },
6621 /* Main entry for a demangling filter executable. It will demangle
6622 its command line arguments, if any. If none are provided, it will
6623 filter stdin to stdout, replacing any recognized mangled C++ names
6624 with their demangled equivalents. */
6627 main (int argc
, char *argv
[])
6631 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6633 /* Use the program name of this program, as invoked. */
6634 program_name
= argv
[0];
6636 /* Parse options. */
6639 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6642 case '?': /* Unrecognized option. */
6643 print_usage (stderr
, 1);
6647 print_usage (stdout
, 0);
6651 options
&= ~ DMGL_PARAMS
;
6655 options
|= DMGL_VERBOSE
;
6659 while (opt_char
!= -1);
6662 /* No command line arguments were provided. Filter stdin. */
6664 dyn_string_t mangled
= dyn_string_new (3);
6667 /* Read all of input. */
6668 while (!feof (stdin
))
6672 /* Pile characters into mangled until we hit one that can't
6673 occur in a mangled name. */
6675 while (!feof (stdin
) && is_mangled_char (c
))
6677 dyn_string_append_char (mangled
, c
);
6683 if (dyn_string_length (mangled
) > 0)
6685 #ifdef IN_GLIBCPP_V3
6686 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6688 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6698 /* It might not have been a mangled name. Print the
6700 fputs (dyn_string_buf (mangled
), stdout
);
6703 dyn_string_clear (mangled
);
6706 /* If we haven't hit EOF yet, we've read one character that
6707 can't occur in a mangled name, so print it out. */
6712 dyn_string_delete (mangled
);
6715 /* Demangle command line arguments. */
6717 /* Loop over command line arguments. */
6718 for (i
= optind
; i
< argc
; ++i
)
6721 #ifdef IN_GLIBCPP_V3
6725 /* Attempt to demangle. */
6726 #ifdef IN_GLIBCPP_V3
6727 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6729 s
= cplus_demangle_v3 (argv
[i
], options
);
6732 /* If it worked, print the demangled name. */
6740 #ifdef IN_GLIBCPP_V3
6741 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6743 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6752 #endif /* STANDALONE_DEMANGLER */