1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@wasabisystems.com>.
6 This file is part of the libiberty library, which is part of GCC.
8 This file is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combined
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 /* This code implements a demangler for the g++ V3 ABI. The ABI is
33 described on this web page:
34 http://www.codesourcery.com/cxx-abi/abi.html#mangling
36 This code was written while looking at the demangler written by
37 Alex Samuel <samuel@codesourcery.com>.
39 This code first pulls the mangled name apart into a list of
40 components, and then walks the list generating the demangled
43 This file will normally define the following functions, q.v.:
44 char *cplus_demangle_v3(const char *mangled, int options)
45 char *java_demangle_v3(const char *mangled)
46 int cplus_demangle_v3_callback(const char *mangled, int options,
47 demangle_callbackref callback)
48 int java_demangle_v3_callback(const char *mangled,
49 demangle_callbackref callback)
50 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
51 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
53 Also, the interface to the component list is public, and defined in
54 demangle.h. The interface consists of these types, which are
55 defined in demangle.h:
56 enum demangle_component_type
57 struct demangle_component
59 and these functions defined in this file:
60 cplus_demangle_fill_name
61 cplus_demangle_fill_extended_operator
62 cplus_demangle_fill_ctor
63 cplus_demangle_fill_dtor
65 cplus_demangle_print_callback
66 and other functions defined in the file cp-demint.c.
68 This file also defines some other functions and variables which are
69 only to be used by the file cp-demint.c.
71 Preprocessor macros you can define while compiling this file:
74 If defined, this file defines the following functions, q.v.:
75 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
77 int __gcclibcxx_demangle_callback (const char *,
79 (const char *, size_t, void *),
81 instead of cplus_demangle_v3[_callback]() and
82 java_demangle_v3[_callback]().
85 If defined, this file defines only __cxa_demangle() and
86 __gcclibcxx_demangle_callback(), and no other publically visible
87 functions or variables.
90 If defined, this file defines a main() function which demangles
91 any arguments, or, if none, demangles stdin.
94 If defined, turns on debugging mode, which prints information on
95 stdout about the mangled string. This is not generally useful.
98 If defined, additional sanity checks will be performed. It will
99 cause some slowdown, but will allow to catch out-of-bound access
100 errors earlier. This macro is intended for testing and debugging. */
102 #if defined (_AIX) && !defined (__GNUC__)
124 # define alloca __builtin_alloca
126 extern char *alloca ();
127 # endif /* __GNUC__ */
129 #endif /* HAVE_ALLOCA_H */
135 # define INT_MAX (int)(((unsigned int) ~0) >> 1) /* 0x7FFFFFFF */
138 #include "ansidecl.h"
139 #include "libiberty.h"
140 #include "demangle.h"
141 #include "cp-demangle.h"
143 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
144 also rename them via #define to avoid compiler errors when the
145 static definition conflicts with the extern declaration in a header
149 #define CP_STATIC_IF_GLIBCPP_V3 static
151 #define cplus_demangle_fill_name d_fill_name
152 static int d_fill_name (struct demangle_component
*, const char *, int);
154 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
156 d_fill_extended_operator (struct demangle_component
*, int,
157 struct demangle_component
*);
159 #define cplus_demangle_fill_ctor d_fill_ctor
161 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
162 struct demangle_component
*);
164 #define cplus_demangle_fill_dtor d_fill_dtor
166 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
167 struct demangle_component
*);
169 #define cplus_demangle_mangled_name d_mangled_name
170 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
172 #define cplus_demangle_type d_type
173 static struct demangle_component
*d_type (struct d_info
*);
175 #define cplus_demangle_print d_print
176 static char *d_print (int, const struct demangle_component
*, int, size_t *);
178 #define cplus_demangle_print_callback d_print_callback
179 static int d_print_callback (int, const struct demangle_component
*,
180 demangle_callbackref
, void *);
182 #define cplus_demangle_init_info d_init_info
183 static void d_init_info (const char *, int, size_t, struct d_info
*);
185 #else /* ! defined(IN_GLIBCPP_V3) */
186 #define CP_STATIC_IF_GLIBCPP_V3
187 #endif /* ! defined(IN_GLIBCPP_V3) */
189 /* See if the compiler supports dynamic arrays. */
192 #define CP_DYNAMIC_ARRAYS
195 #ifdef __STDC_VERSION__
196 #if __STDC_VERSION__ >= 199901L
197 #define CP_DYNAMIC_ARRAYS
198 #endif /* __STDC__VERSION >= 199901L */
199 #endif /* defined (__STDC_VERSION__) */
200 #endif /* defined (__STDC__) */
201 #endif /* ! defined (__GNUC__) */
203 /* We avoid pulling in the ctype tables, to prevent pulling in
204 additional unresolved symbols when this code is used in a library.
205 FIXME: Is this really a valid reason? This comes from the original
208 As of this writing this file has the following undefined references
209 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
212 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
213 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
214 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
216 /* The prefix prepended by GCC to an identifier represnting the
217 anonymous namespace. */
218 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
219 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
220 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
222 /* Information we keep for the standard substitutions. */
224 struct d_standard_sub_info
226 /* The code for this substitution. */
228 /* The simple string it expands to. */
229 const char *simple_expansion
;
230 /* The length of the simple expansion. */
232 /* The results of a full, verbose, expansion. This is used when
233 qualifying a constructor/destructor, or when in verbose mode. */
234 const char *full_expansion
;
235 /* The length of the full expansion. */
237 /* What to set the last_name field of d_info to; NULL if we should
238 not set it. This is only relevant when qualifying a
239 constructor/destructor. */
240 const char *set_last_name
;
241 /* The length of set_last_name. */
242 int set_last_name_len
;
245 /* Accessors for subtrees of struct demangle_component. */
247 #define d_left(dc) ((dc)->u.s_binary.left)
248 #define d_right(dc) ((dc)->u.s_binary.right)
250 /* A list of templates. This is used while printing. */
252 struct d_print_template
254 /* Next template on the list. */
255 struct d_print_template
*next
;
257 const struct demangle_component
*template_decl
;
260 /* A list of type modifiers. This is used while printing. */
264 /* Next modifier on the list. These are in the reverse of the order
265 in which they appeared in the mangled string. */
266 struct d_print_mod
*next
;
268 const struct demangle_component
*mod
;
269 /* Whether this modifier was printed. */
271 /* The list of templates which applies to this modifier. */
272 struct d_print_template
*templates
;
275 /* We use these structures to hold information during printing. */
277 struct d_growable_string
279 /* Buffer holding the result. */
281 /* Current length of data in buffer. */
283 /* Allocated size of buffer. */
285 /* Set to 1 if we had a memory allocation failure. */
286 int allocation_failure
;
289 /* Stack of components, innermost first, used to avoid loops. */
291 struct d_component_stack
293 /* This component. */
294 const struct demangle_component
*dc
;
295 /* This component's parent. */
296 const struct d_component_stack
*parent
;
299 /* A demangle component and some scope captured when it was first
304 /* The component whose scope this is. */
305 const struct demangle_component
*container
;
306 /* The list of templates, if any, that was current when this
307 scope was captured. */
308 struct d_print_template
*templates
;
311 /* Checkpoint structure to allow backtracking. This holds copies
312 of the fields of struct d_info that need to be restored
313 if a trial parse needs to be backtracked over. */
315 struct d_info_checkpoint
324 enum { D_PRINT_BUFFER_LENGTH
= 256 };
327 /* Fixed-length allocated buffer for demangled data, flushed to the
328 callback with a NUL termination once full. */
329 char buf
[D_PRINT_BUFFER_LENGTH
];
330 /* Current length of data in buffer. */
332 /* The last character printed, saved individually so that it survives
335 /* Callback function to handle demangled buffer flush. */
336 demangle_callbackref callback
;
337 /* Opaque callback argument. */
339 /* The current list of templates, if any. */
340 struct d_print_template
*templates
;
341 /* The current list of modifiers (e.g., pointer, reference, etc.),
343 struct d_print_mod
*modifiers
;
344 /* Set to 1 if we saw a demangling error. */
345 int demangle_failure
;
346 /* The current index into any template argument packs we are using
347 for printing, or -1 to print the whole pack. */
349 /* Number of d_print_flush calls so far. */
350 unsigned long int flush_count
;
351 /* Stack of components, innermost first, used to avoid loops. */
352 const struct d_component_stack
*component_stack
;
353 /* Array of saved scopes for evaluating substitutions. */
354 struct d_saved_scope
*saved_scopes
;
355 /* Index of the next unused saved scope in the above array. */
356 int next_saved_scope
;
357 /* Number of saved scopes in the above array. */
358 int num_saved_scopes
;
359 /* Array of templates for saving into scopes. */
360 struct d_print_template
*copy_templates
;
361 /* Index of the next unused copy template in the above array. */
362 int next_copy_template
;
363 /* Number of copy templates in the above array. */
364 int num_copy_templates
;
365 /* The nearest enclosing template, if any. */
366 const struct demangle_component
*current_template
;
369 #ifdef CP_DEMANGLE_DEBUG
370 static void d_dump (struct demangle_component
*, int);
373 static struct demangle_component
*
374 d_make_empty (struct d_info
*);
376 static struct demangle_component
*
377 d_make_comp (struct d_info
*, enum demangle_component_type
,
378 struct demangle_component
*,
379 struct demangle_component
*);
381 static struct demangle_component
*
382 d_make_name (struct d_info
*, const char *, int);
384 static struct demangle_component
*
385 d_make_demangle_mangled_name (struct d_info
*, const char *);
387 static struct demangle_component
*
388 d_make_builtin_type (struct d_info
*,
389 const struct demangle_builtin_type_info
*);
391 static struct demangle_component
*
392 d_make_operator (struct d_info
*,
393 const struct demangle_operator_info
*);
395 static struct demangle_component
*
396 d_make_extended_operator (struct d_info
*, int,
397 struct demangle_component
*);
399 static struct demangle_component
*
400 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
401 struct demangle_component
*);
403 static struct demangle_component
*
404 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
405 struct demangle_component
*);
407 static struct demangle_component
*
408 d_make_template_param (struct d_info
*, int);
410 static struct demangle_component
*
411 d_make_sub (struct d_info
*, const char *, int);
414 has_return_type (struct demangle_component
*);
417 is_ctor_dtor_or_conversion (struct demangle_component
*);
419 static struct demangle_component
*d_encoding (struct d_info
*, int);
421 static struct demangle_component
*d_name (struct d_info
*);
423 static struct demangle_component
*d_nested_name (struct d_info
*);
425 static struct demangle_component
*d_prefix (struct d_info
*);
427 static struct demangle_component
*d_unqualified_name (struct d_info
*);
429 static struct demangle_component
*d_source_name (struct d_info
*);
431 static int d_number (struct d_info
*);
433 static struct demangle_component
*d_identifier (struct d_info
*, int);
435 static struct demangle_component
*d_operator_name (struct d_info
*);
437 static struct demangle_component
*d_special_name (struct d_info
*);
439 static struct demangle_component
*d_parmlist (struct d_info
*);
441 static int d_call_offset (struct d_info
*, int);
443 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
445 static struct demangle_component
**
446 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
448 static struct demangle_component
*
449 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
451 static struct demangle_component
*
452 d_function_type (struct d_info
*);
454 static struct demangle_component
*
455 d_bare_function_type (struct d_info
*, int);
457 static struct demangle_component
*
458 d_class_enum_type (struct d_info
*);
460 static struct demangle_component
*d_array_type (struct d_info
*);
462 static struct demangle_component
*d_vector_type (struct d_info
*);
464 static struct demangle_component
*
465 d_pointer_to_member_type (struct d_info
*);
467 static struct demangle_component
*
468 d_template_param (struct d_info
*);
470 static struct demangle_component
*d_template_args (struct d_info
*);
471 static struct demangle_component
*d_template_args_1 (struct d_info
*);
473 static struct demangle_component
*
474 d_template_arg (struct d_info
*);
476 static struct demangle_component
*d_expression (struct d_info
*);
478 static struct demangle_component
*d_expr_primary (struct d_info
*);
480 static struct demangle_component
*d_local_name (struct d_info
*);
482 static int d_discriminator (struct d_info
*);
484 static struct demangle_component
*d_lambda (struct d_info
*);
486 static struct demangle_component
*d_unnamed_type (struct d_info
*);
488 static struct demangle_component
*
489 d_clone_suffix (struct d_info
*, struct demangle_component
*);
492 d_add_substitution (struct d_info
*, struct demangle_component
*);
494 static struct demangle_component
*d_substitution (struct d_info
*, int);
496 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
498 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
500 static void d_growable_string_init (struct d_growable_string
*, size_t);
503 d_growable_string_resize (struct d_growable_string
*, size_t);
506 d_growable_string_append_buffer (struct d_growable_string
*,
507 const char *, size_t);
509 d_growable_string_callback_adapter (const char *, size_t, void *);
512 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
513 const struct demangle_component
*);
515 static inline void d_print_error (struct d_print_info
*);
517 static inline int d_print_saw_error (struct d_print_info
*);
519 static inline void d_print_flush (struct d_print_info
*);
521 static inline void d_append_char (struct d_print_info
*, char);
523 static inline void d_append_buffer (struct d_print_info
*,
524 const char *, size_t);
526 static inline void d_append_string (struct d_print_info
*, const char *);
528 static inline char d_last_char (struct d_print_info
*);
531 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
534 d_print_java_identifier (struct d_print_info
*, const char *, int);
537 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
540 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
543 d_print_function_type (struct d_print_info
*, int,
544 const struct demangle_component
*,
545 struct d_print_mod
*);
548 d_print_array_type (struct d_print_info
*, int,
549 const struct demangle_component
*,
550 struct d_print_mod
*);
553 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
555 static void d_print_cast (struct d_print_info
*, int,
556 const struct demangle_component
*);
557 static void d_print_conversion (struct d_print_info
*, int,
558 const struct demangle_component
*);
560 static int d_demangle_callback (const char *, int,
561 demangle_callbackref
, void *);
562 static char *d_demangle (const char *, int, size_t *);
564 /* True iff TYPE is a demangling component representing a
565 function-type-qualifier. */
568 is_fnqual_component_type (enum demangle_component_type type
)
570 return (type
== DEMANGLE_COMPONENT_RESTRICT_THIS
571 || type
== DEMANGLE_COMPONENT_VOLATILE_THIS
572 || type
== DEMANGLE_COMPONENT_CONST_THIS
573 || type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
574 || type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
575 || type
== DEMANGLE_COMPONENT_NOEXCEPT
576 || type
== DEMANGLE_COMPONENT_THROW_SPEC
577 || type
== DEMANGLE_COMPONENT_REFERENCE_THIS
);
580 #define FNQUAL_COMPONENT_CASE \
581 case DEMANGLE_COMPONENT_RESTRICT_THIS: \
582 case DEMANGLE_COMPONENT_VOLATILE_THIS: \
583 case DEMANGLE_COMPONENT_CONST_THIS: \
584 case DEMANGLE_COMPONENT_REFERENCE_THIS: \
585 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \
586 case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \
587 case DEMANGLE_COMPONENT_NOEXCEPT: \
588 case DEMANGLE_COMPONENT_THROW_SPEC
590 #ifdef CP_DEMANGLE_DEBUG
593 d_dump (struct demangle_component
*dc
, int indent
)
600 printf ("failed demangling\n");
604 for (i
= 0; i
< indent
; ++i
)
609 case DEMANGLE_COMPONENT_NAME
:
610 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
612 case DEMANGLE_COMPONENT_TAGGED_NAME
:
613 printf ("tagged name\n");
614 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
615 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
617 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
618 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
620 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
621 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
623 case DEMANGLE_COMPONENT_CTOR
:
624 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
625 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
627 case DEMANGLE_COMPONENT_DTOR
:
628 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
629 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
631 case DEMANGLE_COMPONENT_SUB_STD
:
632 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
634 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
635 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
637 case DEMANGLE_COMPONENT_OPERATOR
:
638 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
640 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
641 printf ("extended operator with %d args\n",
642 dc
->u
.s_extended_operator
.args
);
643 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
646 case DEMANGLE_COMPONENT_QUAL_NAME
:
647 printf ("qualified name\n");
649 case DEMANGLE_COMPONENT_LOCAL_NAME
:
650 printf ("local name\n");
652 case DEMANGLE_COMPONENT_TYPED_NAME
:
653 printf ("typed name\n");
655 case DEMANGLE_COMPONENT_TEMPLATE
:
656 printf ("template\n");
658 case DEMANGLE_COMPONENT_VTABLE
:
661 case DEMANGLE_COMPONENT_VTT
:
664 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
665 printf ("construction vtable\n");
667 case DEMANGLE_COMPONENT_TYPEINFO
:
668 printf ("typeinfo\n");
670 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
671 printf ("typeinfo name\n");
673 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
674 printf ("typeinfo function\n");
676 case DEMANGLE_COMPONENT_THUNK
:
679 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
680 printf ("virtual thunk\n");
682 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
683 printf ("covariant thunk\n");
685 case DEMANGLE_COMPONENT_JAVA_CLASS
:
686 printf ("java class\n");
688 case DEMANGLE_COMPONENT_GUARD
:
691 case DEMANGLE_COMPONENT_REFTEMP
:
692 printf ("reference temporary\n");
694 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
695 printf ("hidden alias\n");
697 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
698 printf ("transaction clone\n");
700 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
701 printf ("non-transaction clone\n");
703 case DEMANGLE_COMPONENT_RESTRICT
:
704 printf ("restrict\n");
706 case DEMANGLE_COMPONENT_VOLATILE
:
707 printf ("volatile\n");
709 case DEMANGLE_COMPONENT_CONST
:
712 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
713 printf ("restrict this\n");
715 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
716 printf ("volatile this\n");
718 case DEMANGLE_COMPONENT_CONST_THIS
:
719 printf ("const this\n");
721 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
722 printf ("reference this\n");
724 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
725 printf ("rvalue reference this\n");
727 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
728 printf ("transaction_safe this\n");
730 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
731 printf ("vendor type qualifier\n");
733 case DEMANGLE_COMPONENT_POINTER
:
734 printf ("pointer\n");
736 case DEMANGLE_COMPONENT_REFERENCE
:
737 printf ("reference\n");
739 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
740 printf ("rvalue reference\n");
742 case DEMANGLE_COMPONENT_COMPLEX
:
743 printf ("complex\n");
745 case DEMANGLE_COMPONENT_IMAGINARY
:
746 printf ("imaginary\n");
748 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
749 printf ("vendor type\n");
751 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
752 printf ("function type\n");
754 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
755 printf ("array type\n");
757 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
758 printf ("pointer to member type\n");
760 case DEMANGLE_COMPONENT_FIXED_TYPE
:
761 printf ("fixed-point type, accum? %d, sat? %d\n",
762 dc
->u
.s_fixed
.accum
, dc
->u
.s_fixed
.sat
);
763 d_dump (dc
->u
.s_fixed
.length
, indent
+ 2);
765 case DEMANGLE_COMPONENT_ARGLIST
:
766 printf ("argument list\n");
768 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
769 printf ("template argument list\n");
771 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
772 printf ("initializer list\n");
774 case DEMANGLE_COMPONENT_CAST
:
777 case DEMANGLE_COMPONENT_CONVERSION
:
778 printf ("conversion operator\n");
780 case DEMANGLE_COMPONENT_NULLARY
:
781 printf ("nullary operator\n");
783 case DEMANGLE_COMPONENT_UNARY
:
784 printf ("unary operator\n");
786 case DEMANGLE_COMPONENT_BINARY
:
787 printf ("binary operator\n");
789 case DEMANGLE_COMPONENT_BINARY_ARGS
:
790 printf ("binary operator arguments\n");
792 case DEMANGLE_COMPONENT_TRINARY
:
793 printf ("trinary operator\n");
795 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
796 printf ("trinary operator arguments 1\n");
798 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
799 printf ("trinary operator arguments 1\n");
801 case DEMANGLE_COMPONENT_LITERAL
:
802 printf ("literal\n");
804 case DEMANGLE_COMPONENT_LITERAL_NEG
:
805 printf ("negative literal\n");
807 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
808 printf ("java resource\n");
810 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
811 printf ("compound name\n");
813 case DEMANGLE_COMPONENT_CHARACTER
:
814 printf ("character '%c'\n", dc
->u
.s_character
.character
);
816 case DEMANGLE_COMPONENT_NUMBER
:
817 printf ("number %ld\n", dc
->u
.s_number
.number
);
819 case DEMANGLE_COMPONENT_DECLTYPE
:
820 printf ("decltype\n");
822 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
823 printf ("pack expansion\n");
825 case DEMANGLE_COMPONENT_TLS_INIT
:
826 printf ("tls init function\n");
828 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
829 printf ("tls wrapper function\n");
831 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
832 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
833 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
835 case DEMANGLE_COMPONENT_LAMBDA
:
836 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
837 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
841 d_dump (d_left (dc
), indent
+ 2);
842 d_dump (d_right (dc
), indent
+ 2);
845 #endif /* CP_DEMANGLE_DEBUG */
847 /* Fill in a DEMANGLE_COMPONENT_NAME. */
849 CP_STATIC_IF_GLIBCPP_V3
851 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
853 if (p
== NULL
|| s
== NULL
|| len
== 0)
855 p
->type
= DEMANGLE_COMPONENT_NAME
;
857 p
->u
.s_name
.len
= len
;
861 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
863 CP_STATIC_IF_GLIBCPP_V3
865 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
866 struct demangle_component
*name
)
868 if (p
== NULL
|| args
< 0 || name
== NULL
)
870 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
871 p
->u
.s_extended_operator
.args
= args
;
872 p
->u
.s_extended_operator
.name
= name
;
876 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
878 CP_STATIC_IF_GLIBCPP_V3
880 cplus_demangle_fill_ctor (struct demangle_component
*p
,
881 enum gnu_v3_ctor_kinds kind
,
882 struct demangle_component
*name
)
886 || (int) kind
< gnu_v3_complete_object_ctor
887 || (int) kind
> gnu_v3_object_ctor_group
)
889 p
->type
= DEMANGLE_COMPONENT_CTOR
;
890 p
->u
.s_ctor
.kind
= kind
;
891 p
->u
.s_ctor
.name
= name
;
895 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
897 CP_STATIC_IF_GLIBCPP_V3
899 cplus_demangle_fill_dtor (struct demangle_component
*p
,
900 enum gnu_v3_dtor_kinds kind
,
901 struct demangle_component
*name
)
905 || (int) kind
< gnu_v3_deleting_dtor
906 || (int) kind
> gnu_v3_object_dtor_group
)
908 p
->type
= DEMANGLE_COMPONENT_DTOR
;
909 p
->u
.s_dtor
.kind
= kind
;
910 p
->u
.s_dtor
.name
= name
;
914 /* Add a new component. */
916 static struct demangle_component
*
917 d_make_empty (struct d_info
*di
)
919 struct demangle_component
*p
;
921 if (di
->next_comp
>= di
->num_comps
)
923 p
= &di
->comps
[di
->next_comp
];
928 /* Add a new generic component. */
930 static struct demangle_component
*
931 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
932 struct demangle_component
*left
,
933 struct demangle_component
*right
)
935 struct demangle_component
*p
;
937 /* We check for errors here. A typical error would be a NULL return
938 from a subroutine. We catch those here, and return NULL
942 /* These types require two parameters. */
943 case DEMANGLE_COMPONENT_QUAL_NAME
:
944 case DEMANGLE_COMPONENT_LOCAL_NAME
:
945 case DEMANGLE_COMPONENT_TYPED_NAME
:
946 case DEMANGLE_COMPONENT_TAGGED_NAME
:
947 case DEMANGLE_COMPONENT_TEMPLATE
:
948 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
949 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
950 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
951 case DEMANGLE_COMPONENT_UNARY
:
952 case DEMANGLE_COMPONENT_BINARY
:
953 case DEMANGLE_COMPONENT_BINARY_ARGS
:
954 case DEMANGLE_COMPONENT_TRINARY
:
955 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
956 case DEMANGLE_COMPONENT_LITERAL
:
957 case DEMANGLE_COMPONENT_LITERAL_NEG
:
958 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
959 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
960 case DEMANGLE_COMPONENT_CLONE
:
961 if (left
== NULL
|| right
== NULL
)
965 /* These types only require one parameter. */
966 case DEMANGLE_COMPONENT_VTABLE
:
967 case DEMANGLE_COMPONENT_VTT
:
968 case DEMANGLE_COMPONENT_TYPEINFO
:
969 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
970 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
971 case DEMANGLE_COMPONENT_THUNK
:
972 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
973 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
974 case DEMANGLE_COMPONENT_JAVA_CLASS
:
975 case DEMANGLE_COMPONENT_GUARD
:
976 case DEMANGLE_COMPONENT_TLS_INIT
:
977 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
978 case DEMANGLE_COMPONENT_REFTEMP
:
979 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
980 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
981 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
982 case DEMANGLE_COMPONENT_POINTER
:
983 case DEMANGLE_COMPONENT_REFERENCE
:
984 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
985 case DEMANGLE_COMPONENT_COMPLEX
:
986 case DEMANGLE_COMPONENT_IMAGINARY
:
987 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
988 case DEMANGLE_COMPONENT_CAST
:
989 case DEMANGLE_COMPONENT_CONVERSION
:
990 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
991 case DEMANGLE_COMPONENT_DECLTYPE
:
992 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
993 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
994 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
995 case DEMANGLE_COMPONENT_NULLARY
:
996 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
1001 /* This needs a right parameter, but the left parameter can be
1003 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
1004 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
1009 /* These are allowed to have no parameters--in some cases they
1010 will be filled in later. */
1011 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
1012 case DEMANGLE_COMPONENT_RESTRICT
:
1013 case DEMANGLE_COMPONENT_VOLATILE
:
1014 case DEMANGLE_COMPONENT_CONST
:
1015 case DEMANGLE_COMPONENT_ARGLIST
:
1016 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
1017 FNQUAL_COMPONENT_CASE
:
1020 /* Other types should not be seen here. */
1025 p
= d_make_empty (di
);
1029 p
->u
.s_binary
.left
= left
;
1030 p
->u
.s_binary
.right
= right
;
1035 /* Add a new demangle mangled name component. */
1037 static struct demangle_component
*
1038 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
1040 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1041 return d_make_name (di
, s
, strlen (s
));
1043 return d_encoding (di
, 0);
1046 /* Add a new name component. */
1048 static struct demangle_component
*
1049 d_make_name (struct d_info
*di
, const char *s
, int len
)
1051 struct demangle_component
*p
;
1053 p
= d_make_empty (di
);
1054 if (! cplus_demangle_fill_name (p
, s
, len
))
1059 /* Add a new builtin type component. */
1061 static struct demangle_component
*
1062 d_make_builtin_type (struct d_info
*di
,
1063 const struct demangle_builtin_type_info
*type
)
1065 struct demangle_component
*p
;
1069 p
= d_make_empty (di
);
1072 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1073 p
->u
.s_builtin
.type
= type
;
1078 /* Add a new operator component. */
1080 static struct demangle_component
*
1081 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1083 struct demangle_component
*p
;
1085 p
= d_make_empty (di
);
1088 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1089 p
->u
.s_operator
.op
= op
;
1094 /* Add a new extended operator component. */
1096 static struct demangle_component
*
1097 d_make_extended_operator (struct d_info
*di
, int args
,
1098 struct demangle_component
*name
)
1100 struct demangle_component
*p
;
1102 p
= d_make_empty (di
);
1103 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1108 static struct demangle_component
*
1109 d_make_default_arg (struct d_info
*di
, int num
,
1110 struct demangle_component
*sub
)
1112 struct demangle_component
*p
= d_make_empty (di
);
1115 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1116 p
->u
.s_unary_num
.num
= num
;
1117 p
->u
.s_unary_num
.sub
= sub
;
1122 /* Add a new constructor component. */
1124 static struct demangle_component
*
1125 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1126 struct demangle_component
*name
)
1128 struct demangle_component
*p
;
1130 p
= d_make_empty (di
);
1131 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1136 /* Add a new destructor component. */
1138 static struct demangle_component
*
1139 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1140 struct demangle_component
*name
)
1142 struct demangle_component
*p
;
1144 p
= d_make_empty (di
);
1145 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1150 /* Add a new template parameter. */
1152 static struct demangle_component
*
1153 d_make_template_param (struct d_info
*di
, int i
)
1155 struct demangle_component
*p
;
1157 p
= d_make_empty (di
);
1160 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1161 p
->u
.s_number
.number
= i
;
1166 /* Add a new function parameter. */
1168 static struct demangle_component
*
1169 d_make_function_param (struct d_info
*di
, int i
)
1171 struct demangle_component
*p
;
1173 p
= d_make_empty (di
);
1176 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1177 p
->u
.s_number
.number
= i
;
1182 /* Add a new standard substitution component. */
1184 static struct demangle_component
*
1185 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1187 struct demangle_component
*p
;
1189 p
= d_make_empty (di
);
1192 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1193 p
->u
.s_string
.string
= name
;
1194 p
->u
.s_string
.len
= len
;
1199 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1201 TOP_LEVEL is non-zero when called at the top level. */
1203 CP_STATIC_IF_GLIBCPP_V3
1204 struct demangle_component
*
1205 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1207 struct demangle_component
*p
;
1209 if (! d_check_char (di
, '_')
1210 /* Allow missing _ if not at toplevel to work around a
1211 bug in G++ abi-version=2 mangling; see the comment in
1212 write_template_arg. */
1215 if (! d_check_char (di
, 'Z'))
1217 p
= d_encoding (di
, top_level
);
1219 /* If at top level and parsing parameters, check for a clone
1221 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1222 while (d_peek_char (di
) == '.'
1223 && (IS_LOWER (d_peek_next_char (di
))
1224 || d_peek_next_char (di
) == '_'
1225 || IS_DIGIT (d_peek_next_char (di
))))
1226 p
= d_clone_suffix (di
, p
);
1231 /* Return whether a function should have a return type. The argument
1232 is the function name, which may be qualified in various ways. The
1233 rules are that template functions have return types with some
1234 exceptions, function types which are not part of a function name
1235 mangling have return types with some exceptions, and non-template
1236 function names do not have return types. The exceptions are that
1237 constructors, destructors, and conversion operators do not have
1241 has_return_type (struct demangle_component
*dc
)
1249 case DEMANGLE_COMPONENT_TEMPLATE
:
1250 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1251 FNQUAL_COMPONENT_CASE
:
1252 return has_return_type (d_left (dc
));
1256 /* Return whether a name is a constructor, a destructor, or a
1257 conversion operator. */
1260 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1268 case DEMANGLE_COMPONENT_QUAL_NAME
:
1269 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1270 return is_ctor_dtor_or_conversion (d_right (dc
));
1271 case DEMANGLE_COMPONENT_CTOR
:
1272 case DEMANGLE_COMPONENT_DTOR
:
1273 case DEMANGLE_COMPONENT_CONVERSION
:
1278 /* <encoding> ::= <(function) name> <bare-function-type>
1282 TOP_LEVEL is non-zero when called at the top level, in which case
1283 if DMGL_PARAMS is not set we do not demangle the function
1284 parameters. We only set this at the top level, because otherwise
1285 we would not correctly demangle names in local scopes. */
1287 static struct demangle_component
*
1288 d_encoding (struct d_info
*di
, int top_level
)
1290 char peek
= d_peek_char (di
);
1292 if (peek
== 'G' || peek
== 'T')
1293 return d_special_name (di
);
1296 struct demangle_component
*dc
;
1300 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1302 /* Strip off any initial CV-qualifiers, as they really apply
1303 to the `this' parameter, and they were not output by the
1304 v2 demangler without DMGL_PARAMS. */
1305 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1306 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1307 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1308 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1309 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1312 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1313 there may be function-qualifiers on its right argument which
1314 really apply here; this happens when parsing a class
1315 which is local to a function. */
1316 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1318 struct demangle_component
*dcr
;
1321 while (is_fnqual_component_type (dcr
->type
))
1323 dc
->u
.s_binary
.right
= dcr
;
1329 peek
= d_peek_char (di
);
1330 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1332 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1333 d_bare_function_type (di
, has_return_type (dc
)));
1337 /* <tagged-name> ::= <name> B <source-name> */
1339 static struct demangle_component
*
1340 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1342 struct demangle_component
*hold_last_name
;
1345 /* Preserve the last name, so the ABI tag doesn't clobber it. */
1346 hold_last_name
= di
->last_name
;
1348 while (peek
= d_peek_char (di
),
1351 struct demangle_component
*tag
;
1353 tag
= d_source_name (di
);
1354 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1357 di
->last_name
= hold_last_name
;
1362 /* <name> ::= <nested-name>
1364 ::= <unscoped-template-name> <template-args>
1367 <unscoped-name> ::= <unqualified-name>
1368 ::= St <unqualified-name>
1370 <unscoped-template-name> ::= <unscoped-name>
1374 static struct demangle_component
*
1375 d_name (struct d_info
*di
)
1377 char peek
= d_peek_char (di
);
1378 struct demangle_component
*dc
;
1383 return d_nested_name (di
);
1386 return d_local_name (di
);
1389 return d_unqualified_name (di
);
1395 if (d_peek_next_char (di
) != 't')
1397 dc
= d_substitution (di
, 0);
1403 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1404 d_make_name (di
, "std", 3),
1405 d_unqualified_name (di
));
1410 if (d_peek_char (di
) != 'I')
1412 /* The grammar does not permit this case to occur if we
1413 called d_substitution() above (i.e., subst == 1). We
1414 don't bother to check. */
1418 /* This is <template-args>, which means that we just saw
1419 <unscoped-template-name>, which is a substitution
1420 candidate if we didn't just get it from a
1424 if (! d_add_substitution (di
, dc
))
1427 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1428 d_template_args (di
));
1436 dc
= d_unqualified_name (di
);
1437 if (d_peek_char (di
) == 'I')
1439 /* This is <template-args>, which means that we just saw
1440 <unscoped-template-name>, which is a substitution
1442 if (! d_add_substitution (di
, dc
))
1444 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1445 d_template_args (di
));
1451 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1452 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1455 static struct demangle_component
*
1456 d_nested_name (struct d_info
*di
)
1458 struct demangle_component
*ret
;
1459 struct demangle_component
**pret
;
1460 struct demangle_component
*rqual
;
1462 if (! d_check_char (di
, 'N'))
1465 pret
= d_cv_qualifiers (di
, &ret
, 1);
1469 /* Parse the ref-qualifier now and then attach it
1470 once we have something to attach it to. */
1471 rqual
= d_ref_qualifier (di
, NULL
);
1473 *pret
= d_prefix (di
);
1479 d_left (rqual
) = ret
;
1483 if (! d_check_char (di
, 'E'))
1489 /* <prefix> ::= <prefix> <unqualified-name>
1490 ::= <template-prefix> <template-args>
1491 ::= <template-param>
1496 <template-prefix> ::= <prefix> <(template) unqualified-name>
1497 ::= <template-param>
1501 static struct demangle_component
*
1502 d_prefix (struct d_info
*di
)
1504 struct demangle_component
*ret
= NULL
;
1509 enum demangle_component_type comb_type
;
1510 struct demangle_component
*dc
;
1512 peek
= d_peek_char (di
);
1516 /* The older code accepts a <local-name> here, but I don't see
1517 that in the grammar. The older code does not accept a
1518 <template-param> here. */
1520 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1523 char peek2
= d_peek_next_char (di
);
1524 if (peek2
== 'T' || peek2
== 't')
1526 dc
= cplus_demangle_type (di
);
1528 /* Destructor name. */
1529 dc
= d_unqualified_name (di
);
1531 else if (IS_DIGIT (peek
)
1536 dc
= d_unqualified_name (di
);
1537 else if (peek
== 'S')
1538 dc
= d_substitution (di
, 1);
1539 else if (peek
== 'I')
1543 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1544 dc
= d_template_args (di
);
1546 else if (peek
== 'T')
1547 dc
= d_template_param (di
);
1548 else if (peek
== 'E')
1550 else if (peek
== 'M')
1552 /* Initializer scope for a lambda. We don't need to represent
1553 this; the normal code will just treat the variable as a type
1554 scope, which gives appropriate output. */
1566 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1568 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1570 if (! d_add_substitution (di
, ret
))
1576 /* <unqualified-name> ::= <operator-name>
1577 ::= <ctor-dtor-name>
1579 ::= <local-source-name>
1581 <local-source-name> ::= L <source-name> <discriminator>
1584 static struct demangle_component
*
1585 d_unqualified_name (struct d_info
*di
)
1587 struct demangle_component
*ret
;
1590 peek
= d_peek_char (di
);
1591 if (IS_DIGIT (peek
))
1592 ret
= d_source_name (di
);
1593 else if (IS_LOWER (peek
))
1595 ret
= d_operator_name (di
);
1596 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1598 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1599 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1600 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1601 d_source_name (di
));
1604 else if (peek
== 'C' || peek
== 'D')
1605 ret
= d_ctor_dtor_name (di
);
1606 else if (peek
== 'L')
1610 ret
= d_source_name (di
);
1613 if (! d_discriminator (di
))
1616 else if (peek
== 'U')
1618 switch (d_peek_next_char (di
))
1621 ret
= d_lambda (di
);
1624 ret
= d_unnamed_type (di
);
1633 if (d_peek_char (di
) == 'B')
1634 ret
= d_abi_tags (di
, ret
);
1638 /* <source-name> ::= <(positive length) number> <identifier> */
1640 static struct demangle_component
*
1641 d_source_name (struct d_info
*di
)
1644 struct demangle_component
*ret
;
1646 len
= d_number (di
);
1649 ret
= d_identifier (di
, len
);
1650 di
->last_name
= ret
;
1654 /* number ::= [n] <(non-negative decimal integer)> */
1657 d_number (struct d_info
*di
)
1664 peek
= d_peek_char (di
);
1669 peek
= d_peek_char (di
);
1675 if (! IS_DIGIT (peek
))
1681 ret
= ret
* 10 + peek
- '0';
1683 peek
= d_peek_char (di
);
1687 /* Like d_number, but returns a demangle_component. */
1689 static struct demangle_component
*
1690 d_number_component (struct d_info
*di
)
1692 struct demangle_component
*ret
= d_make_empty (di
);
1695 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1696 ret
->u
.s_number
.number
= d_number (di
);
1701 /* identifier ::= <(unqualified source code identifier)> */
1703 static struct demangle_component
*
1704 d_identifier (struct d_info
*di
, int len
)
1710 if (di
->send
- name
< len
)
1713 d_advance (di
, len
);
1715 /* A Java mangled name may have a trailing '$' if it is a C++
1716 keyword. This '$' is not included in the length count. We just
1718 if ((di
->options
& DMGL_JAVA
) != 0
1719 && d_peek_char (di
) == '$')
1722 /* Look for something which looks like a gcc encoding of an
1723 anonymous namespace, and replace it with a more user friendly
1725 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1726 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1727 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1731 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1732 if ((*s
== '.' || *s
== '_' || *s
== '$')
1735 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1736 return d_make_name (di
, "(anonymous namespace)",
1737 sizeof "(anonymous namespace)" - 1);
1741 return d_make_name (di
, name
, len
);
1744 /* operator_name ::= many different two character encodings.
1746 ::= v <digit> <source-name>
1748 This list is sorted for binary search. */
1750 #define NL(s) s, (sizeof s) - 1
1752 CP_STATIC_IF_GLIBCPP_V3
1753 const struct demangle_operator_info cplus_demangle_operators
[] =
1755 { "aN", NL ("&="), 2 },
1756 { "aS", NL ("="), 2 },
1757 { "aa", NL ("&&"), 2 },
1758 { "ad", NL ("&"), 1 },
1759 { "an", NL ("&"), 2 },
1760 { "at", NL ("alignof "), 1 },
1761 { "az", NL ("alignof "), 1 },
1762 { "cc", NL ("const_cast"), 2 },
1763 { "cl", NL ("()"), 2 },
1764 { "cm", NL (","), 2 },
1765 { "co", NL ("~"), 1 },
1766 { "dV", NL ("/="), 2 },
1767 { "da", NL ("delete[] "), 1 },
1768 { "dc", NL ("dynamic_cast"), 2 },
1769 { "de", NL ("*"), 1 },
1770 { "dl", NL ("delete "), 1 },
1771 { "ds", NL (".*"), 2 },
1772 { "dt", NL ("."), 2 },
1773 { "dv", NL ("/"), 2 },
1774 { "eO", NL ("^="), 2 },
1775 { "eo", NL ("^"), 2 },
1776 { "eq", NL ("=="), 2 },
1777 { "fL", NL ("..."), 3 },
1778 { "fR", NL ("..."), 3 },
1779 { "fl", NL ("..."), 2 },
1780 { "fr", NL ("..."), 2 },
1781 { "ge", NL (">="), 2 },
1782 { "gs", NL ("::"), 1 },
1783 { "gt", NL (">"), 2 },
1784 { "ix", NL ("[]"), 2 },
1785 { "lS", NL ("<<="), 2 },
1786 { "le", NL ("<="), 2 },
1787 { "li", NL ("operator\"\" "), 1 },
1788 { "ls", NL ("<<"), 2 },
1789 { "lt", NL ("<"), 2 },
1790 { "mI", NL ("-="), 2 },
1791 { "mL", NL ("*="), 2 },
1792 { "mi", NL ("-"), 2 },
1793 { "ml", NL ("*"), 2 },
1794 { "mm", NL ("--"), 1 },
1795 { "na", NL ("new[]"), 3 },
1796 { "ne", NL ("!="), 2 },
1797 { "ng", NL ("-"), 1 },
1798 { "nt", NL ("!"), 1 },
1799 { "nw", NL ("new"), 3 },
1800 { "oR", NL ("|="), 2 },
1801 { "oo", NL ("||"), 2 },
1802 { "or", NL ("|"), 2 },
1803 { "pL", NL ("+="), 2 },
1804 { "pl", NL ("+"), 2 },
1805 { "pm", NL ("->*"), 2 },
1806 { "pp", NL ("++"), 1 },
1807 { "ps", NL ("+"), 1 },
1808 { "pt", NL ("->"), 2 },
1809 { "qu", NL ("?"), 3 },
1810 { "rM", NL ("%="), 2 },
1811 { "rS", NL (">>="), 2 },
1812 { "rc", NL ("reinterpret_cast"), 2 },
1813 { "rm", NL ("%"), 2 },
1814 { "rs", NL (">>"), 2 },
1815 { "sP", NL ("sizeof..."), 1 },
1816 { "sZ", NL ("sizeof..."), 1 },
1817 { "sc", NL ("static_cast"), 2 },
1818 { "st", NL ("sizeof "), 1 },
1819 { "sz", NL ("sizeof "), 1 },
1820 { "tr", NL ("throw"), 0 },
1821 { "tw", NL ("throw "), 1 },
1822 { NULL
, NULL
, 0, 0 }
1825 static struct demangle_component
*
1826 d_operator_name (struct d_info
*di
)
1831 c1
= d_next_char (di
);
1832 c2
= d_next_char (di
);
1833 if (c1
== 'v' && IS_DIGIT (c2
))
1834 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1835 else if (c1
== 'c' && c2
== 'v')
1837 struct demangle_component
*type
;
1838 int was_conversion
= di
->is_conversion
;
1839 struct demangle_component
*res
;
1841 di
->is_conversion
= ! di
->is_expression
;
1842 type
= cplus_demangle_type (di
);
1843 if (di
->is_conversion
)
1844 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
1846 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1847 di
->is_conversion
= was_conversion
;
1852 /* LOW is the inclusive lower bound. */
1854 /* HIGH is the exclusive upper bound. We subtract one to ignore
1855 the sentinel at the end of the array. */
1856 int high
= ((sizeof (cplus_demangle_operators
)
1857 / sizeof (cplus_demangle_operators
[0]))
1863 const struct demangle_operator_info
*p
;
1865 i
= low
+ (high
- low
) / 2;
1866 p
= cplus_demangle_operators
+ i
;
1868 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1869 return d_make_operator (di
, p
);
1871 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1881 static struct demangle_component
*
1882 d_make_character (struct d_info
*di
, int c
)
1884 struct demangle_component
*p
;
1885 p
= d_make_empty (di
);
1888 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1889 p
->u
.s_character
.character
= c
;
1894 static struct demangle_component
*
1895 d_java_resource (struct d_info
*di
)
1897 struct demangle_component
*p
= NULL
;
1898 struct demangle_component
*next
= NULL
;
1903 len
= d_number (di
);
1907 /* Eat the leading '_'. */
1908 if (d_next_char (di
) != '_')
1921 /* Each chunk is either a '$' escape... */
1939 next
= d_make_character (di
, c
);
1947 /* ... or a sequence of characters. */
1950 while (i
< len
&& str
[i
] && str
[i
] != '$')
1953 next
= d_make_name (di
, str
, i
);
1966 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1972 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1977 /* <special-name> ::= TV <type>
1981 ::= GV <(object) name>
1982 ::= T <call-offset> <(base) encoding>
1983 ::= Tc <call-offset> <call-offset> <(base) encoding>
1984 Also g++ extensions:
1985 ::= TC <type> <(offset) number> _ <(base) type>
1990 ::= Gr <resource name>
1995 static struct demangle_component
*
1996 d_special_name (struct d_info
*di
)
1998 di
->expansion
+= 20;
1999 if (d_check_char (di
, 'T'))
2001 switch (d_next_char (di
))
2005 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
2006 cplus_demangle_type (di
), NULL
);
2008 di
->expansion
-= 10;
2009 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
2010 cplus_demangle_type (di
), NULL
);
2012 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
2013 cplus_demangle_type (di
), NULL
);
2015 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
2016 cplus_demangle_type (di
), NULL
);
2019 if (! d_call_offset (di
, 'h'))
2021 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
2022 d_encoding (di
, 0), NULL
);
2025 if (! d_call_offset (di
, 'v'))
2027 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
2028 d_encoding (di
, 0), NULL
);
2031 if (! d_call_offset (di
, '\0'))
2033 if (! d_call_offset (di
, '\0'))
2035 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
2036 d_encoding (di
, 0), NULL
);
2040 struct demangle_component
*derived_type
;
2042 struct demangle_component
*base_type
;
2044 derived_type
= cplus_demangle_type (di
);
2045 offset
= d_number (di
);
2048 if (! d_check_char (di
, '_'))
2050 base_type
= cplus_demangle_type (di
);
2051 /* We don't display the offset. FIXME: We should display
2052 it in verbose mode. */
2054 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2055 base_type
, derived_type
);
2059 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2060 cplus_demangle_type (di
), NULL
);
2062 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2063 cplus_demangle_type (di
), NULL
);
2066 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2070 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2077 else if (d_check_char (di
, 'G'))
2079 switch (d_next_char (di
))
2082 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2086 struct demangle_component
*name
= d_name (di
);
2087 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2088 d_number_component (di
));
2092 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2093 d_encoding (di
, 0), NULL
);
2096 switch (d_next_char (di
))
2099 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2100 d_encoding (di
, 0), NULL
);
2102 /* ??? The proposal is that other letters (such as 'h') stand
2103 for different variants of transaction cloning, such as
2104 compiling directly for hardware transaction support. But
2105 they still should all be transactional clones of some sort
2106 so go ahead and call them that. */
2108 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2109 d_encoding (di
, 0), NULL
);
2113 return d_java_resource (di
);
2123 /* <call-offset> ::= h <nv-offset> _
2126 <nv-offset> ::= <(offset) number>
2128 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2130 The C parameter, if not '\0', is a character we just read which is
2131 the start of the <call-offset>.
2133 We don't display the offset information anywhere. FIXME: We should
2134 display it in verbose mode. */
2137 d_call_offset (struct d_info
*di
, int c
)
2140 c
= d_next_char (di
);
2147 if (! d_check_char (di
, '_'))
2154 if (! d_check_char (di
, '_'))
2160 /* <ctor-dtor-name> ::= C1
2168 static struct demangle_component
*
2169 d_ctor_dtor_name (struct d_info
*di
)
2171 if (di
->last_name
!= NULL
)
2173 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2174 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2175 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2176 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2178 switch (d_peek_char (di
))
2182 enum gnu_v3_ctor_kinds kind
;
2185 if (d_peek_next_char (di
) == 'I')
2191 switch (d_peek_next_char (di
))
2194 kind
= gnu_v3_complete_object_ctor
;
2197 kind
= gnu_v3_base_object_ctor
;
2200 kind
= gnu_v3_complete_object_allocating_ctor
;
2203 kind
= gnu_v3_unified_ctor
;
2206 kind
= gnu_v3_object_ctor_group
;
2215 cplus_demangle_type (di
);
2217 return d_make_ctor (di
, kind
, di
->last_name
);
2222 enum gnu_v3_dtor_kinds kind
;
2224 switch (d_peek_next_char (di
))
2227 kind
= gnu_v3_deleting_dtor
;
2230 kind
= gnu_v3_complete_object_dtor
;
2233 kind
= gnu_v3_base_object_dtor
;
2235 /* digit '3' is not used */
2237 kind
= gnu_v3_unified_dtor
;
2240 kind
= gnu_v3_object_dtor_group
;
2246 return d_make_dtor (di
, kind
, di
->last_name
);
2254 /* True iff we're looking at an order-insensitive type-qualifier, including
2255 function-type-qualifiers. */
2258 next_is_type_qual (struct d_info
*di
)
2260 char peek
= d_peek_char (di
);
2261 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2265 peek
= d_peek_next_char (di
);
2266 if (peek
== 'x' || peek
== 'o' || peek
== 'O' || peek
== 'w')
2272 /* <type> ::= <builtin-type>
2274 ::= <class-enum-type>
2276 ::= <pointer-to-member-type>
2277 ::= <template-param>
2278 ::= <template-template-param> <template-args>
2280 ::= <CV-qualifiers> <type>
2283 ::= O <type> (C++0x)
2286 ::= U <source-name> <type>
2288 <builtin-type> ::= various one letter codes
2292 CP_STATIC_IF_GLIBCPP_V3
2293 const struct demangle_builtin_type_info
2294 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2296 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2297 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2298 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2299 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2300 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2301 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2302 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2303 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2304 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2305 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2306 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2307 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2308 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2309 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2310 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2312 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2313 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2314 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2315 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2316 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2317 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2318 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2319 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2320 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2321 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2322 D_PRINT_UNSIGNED_LONG_LONG
},
2323 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2324 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2325 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2326 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2327 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2328 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2329 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2330 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2334 CP_STATIC_IF_GLIBCPP_V3
2335 struct demangle_component
*
2336 cplus_demangle_type (struct d_info
*di
)
2339 struct demangle_component
*ret
;
2342 /* The ABI specifies that when CV-qualifiers are used, the base type
2343 is substitutable, and the fully qualified type is substitutable,
2344 but the base type with a strict subset of the CV-qualifiers is
2345 not substitutable. The natural recursive implementation of the
2346 CV-qualifiers would cause subsets to be substitutable, so instead
2347 we pull them all off now.
2349 FIXME: The ABI says that order-insensitive vendor qualifiers
2350 should be handled in the same way, but we have no way to tell
2351 which vendor qualifiers are order-insensitive and which are
2352 order-sensitive. So we just assume that they are all
2353 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2354 __vector, and it treats it as order-sensitive when mangling
2357 if (next_is_type_qual (di
))
2359 struct demangle_component
**pret
;
2361 pret
= d_cv_qualifiers (di
, &ret
, 0);
2364 if (d_peek_char (di
) == 'F')
2366 /* cv-qualifiers before a function type apply to 'this',
2367 so avoid adding the unqualified function type to
2368 the substitution list. */
2369 *pret
= d_function_type (di
);
2372 *pret
= cplus_demangle_type (di
);
2375 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2376 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2378 /* Move the ref-qualifier outside the cv-qualifiers so that
2379 they are printed in the right order. */
2380 struct demangle_component
*fn
= d_left (*pret
);
2381 d_left (*pret
) = ret
;
2385 if (! d_add_substitution (di
, ret
))
2392 peek
= d_peek_char (di
);
2395 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2396 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2397 case 'o': case 's': case 't':
2398 case 'v': case 'w': case 'x': case 'y': case 'z':
2399 ret
= d_make_builtin_type (di
,
2400 &cplus_demangle_builtin_types
[peek
- 'a']);
2401 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2408 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2409 d_source_name (di
), NULL
);
2413 ret
= d_function_type (di
);
2416 case '0': case '1': case '2': case '3': case '4':
2417 case '5': case '6': case '7': case '8': case '9':
2420 ret
= d_class_enum_type (di
);
2424 ret
= d_array_type (di
);
2428 ret
= d_pointer_to_member_type (di
);
2432 ret
= d_template_param (di
);
2433 if (d_peek_char (di
) == 'I')
2435 /* This may be <template-template-param> <template-args>.
2436 If this is the type for a conversion operator, we can
2437 have a <template-template-param> here only by following
2438 a derivation like this:
2441 -> <template-prefix> <template-args>
2442 -> <prefix> <template-unqualified-name> <template-args>
2443 -> <unqualified-name> <template-unqualified-name> <template-args>
2444 -> <source-name> <template-unqualified-name> <template-args>
2445 -> <source-name> <operator-name> <template-args>
2446 -> <source-name> cv <type> <template-args>
2447 -> <source-name> cv <template-template-param> <template-args> <template-args>
2449 where the <template-args> is followed by another.
2450 Otherwise, we must have a derivation like this:
2453 -> <template-prefix> <template-args>
2454 -> <prefix> <template-unqualified-name> <template-args>
2455 -> <unqualified-name> <template-unqualified-name> <template-args>
2456 -> <source-name> <template-unqualified-name> <template-args>
2457 -> <source-name> <operator-name> <template-args>
2458 -> <source-name> cv <type> <template-args>
2459 -> <source-name> cv <template-param> <template-args>
2461 where we need to leave the <template-args> to be processed
2462 by d_prefix (following the <template-prefix>).
2464 The <template-template-param> part is a substitution
2466 if (! di
->is_conversion
)
2468 if (! d_add_substitution (di
, ret
))
2470 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2471 d_template_args (di
));
2475 struct demangle_component
*args
;
2476 struct d_info_checkpoint checkpoint
;
2478 d_checkpoint (di
, &checkpoint
);
2479 args
= d_template_args (di
);
2480 if (d_peek_char (di
) == 'I')
2482 if (! d_add_substitution (di
, ret
))
2484 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2488 d_backtrack (di
, &checkpoint
);
2494 /* If this is a special substitution, then it is the start of
2495 <class-enum-type>. */
2499 peek_next
= d_peek_next_char (di
);
2500 if (IS_DIGIT (peek_next
)
2502 || IS_UPPER (peek_next
))
2504 ret
= d_substitution (di
, 0);
2505 /* The substituted name may have been a template name and
2506 may be followed by tepmlate args. */
2507 if (d_peek_char (di
) == 'I')
2508 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2509 d_template_args (di
));
2515 ret
= d_class_enum_type (di
);
2516 /* If the substitution was a complete type, then it is not
2517 a new substitution candidate. However, if the
2518 substitution was followed by template arguments, then
2519 the whole thing is a substitution candidate. */
2520 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2528 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2529 cplus_demangle_type (di
), NULL
);
2534 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2535 cplus_demangle_type (di
), NULL
);
2540 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2541 cplus_demangle_type (di
), NULL
);
2546 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2547 cplus_demangle_type (di
), NULL
);
2552 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2553 cplus_demangle_type (di
), NULL
);
2558 ret
= d_source_name (di
);
2559 if (d_peek_char (di
) == 'I')
2560 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2561 d_template_args (di
));
2562 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2563 cplus_demangle_type (di
), ret
);
2569 peek
= d_next_char (di
);
2574 /* decltype (expression) */
2575 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2576 d_expression (di
), NULL
);
2577 if (ret
&& d_next_char (di
) != 'E')
2583 /* Pack expansion. */
2584 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2585 cplus_demangle_type (di
), NULL
);
2591 ret
= d_make_name (di
, "auto", 4);
2595 /* 32-bit decimal floating point */
2596 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2597 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2601 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2602 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2606 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2607 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2610 /* 16-bit half-precision FP */
2611 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2612 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2616 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2617 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2621 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2622 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2626 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2627 ret
= d_make_empty (di
);
2628 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2629 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2630 /* For demangling we don't care about the bits. */
2632 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2633 if (ret
->u
.s_fixed
.length
== NULL
)
2636 peek
= d_next_char (di
);
2637 ret
->u
.s_fixed
.sat
= (peek
== 's');
2641 ret
= d_vector_type (di
);
2646 /* decltype(nullptr) */
2647 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2648 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2662 if (! d_add_substitution (di
, ret
))
2669 /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */
2671 static struct demangle_component
**
2672 d_cv_qualifiers (struct d_info
*di
,
2673 struct demangle_component
**pret
, int member_fn
)
2675 struct demangle_component
**pstart
;
2679 peek
= d_peek_char (di
);
2680 while (next_is_type_qual (di
))
2682 enum demangle_component_type t
;
2683 struct demangle_component
*right
= NULL
;
2689 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2690 : DEMANGLE_COMPONENT_RESTRICT
);
2691 di
->expansion
+= sizeof "restrict";
2693 else if (peek
== 'V')
2696 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2697 : DEMANGLE_COMPONENT_VOLATILE
);
2698 di
->expansion
+= sizeof "volatile";
2700 else if (peek
== 'K')
2703 ? DEMANGLE_COMPONENT_CONST_THIS
2704 : DEMANGLE_COMPONENT_CONST
);
2705 di
->expansion
+= sizeof "const";
2709 peek
= d_next_char (di
);
2712 t
= DEMANGLE_COMPONENT_TRANSACTION_SAFE
;
2713 di
->expansion
+= sizeof "transaction_safe";
2715 else if (peek
== 'o'
2718 t
= DEMANGLE_COMPONENT_NOEXCEPT
;
2719 di
->expansion
+= sizeof "noexcept";
2722 right
= d_expression (di
);
2725 if (! d_check_char (di
, 'E'))
2729 else if (peek
== 'w')
2731 t
= DEMANGLE_COMPONENT_THROW_SPEC
;
2732 di
->expansion
+= sizeof "throw";
2733 right
= d_parmlist (di
);
2736 if (! d_check_char (di
, 'E'))
2743 *pret
= d_make_comp (di
, t
, NULL
, right
);
2746 pret
= &d_left (*pret
);
2748 peek
= d_peek_char (di
);
2751 if (!member_fn
&& peek
== 'F')
2753 while (pstart
!= pret
)
2755 switch ((*pstart
)->type
)
2757 case DEMANGLE_COMPONENT_RESTRICT
:
2758 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2760 case DEMANGLE_COMPONENT_VOLATILE
:
2761 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2763 case DEMANGLE_COMPONENT_CONST
:
2764 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2769 pstart
= &d_left (*pstart
);
2776 /* <ref-qualifier> ::= R
2779 static struct demangle_component
*
2780 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2782 struct demangle_component
*ret
= sub
;
2785 peek
= d_peek_char (di
);
2786 if (peek
== 'R' || peek
== 'O')
2788 enum demangle_component_type t
;
2791 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2792 di
->expansion
+= sizeof "&";
2796 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2797 di
->expansion
+= sizeof "&&";
2801 ret
= d_make_comp (di
, t
, ret
, NULL
);
2807 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */
2809 static struct demangle_component
*
2810 d_function_type (struct d_info
*di
)
2812 struct demangle_component
*ret
;
2814 if (! d_check_char (di
, 'F'))
2816 if (d_peek_char (di
) == 'Y')
2818 /* Function has C linkage. We don't print this information.
2819 FIXME: We should print it in verbose mode. */
2822 ret
= d_bare_function_type (di
, 1);
2823 ret
= d_ref_qualifier (di
, ret
);
2825 if (! d_check_char (di
, 'E'))
2832 static struct demangle_component
*
2833 d_parmlist (struct d_info
*di
)
2835 struct demangle_component
*tl
;
2836 struct demangle_component
**ptl
;
2842 struct demangle_component
*type
;
2844 char peek
= d_peek_char (di
);
2845 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2847 if ((peek
== 'R' || peek
== 'O')
2848 && d_peek_next_char (di
) == 'E')
2849 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2851 type
= cplus_demangle_type (di
);
2854 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2857 ptl
= &d_right (*ptl
);
2860 /* There should be at least one parameter type besides the optional
2861 return type. A function which takes no arguments will have a
2862 single parameter type void. */
2866 /* If we have a single parameter type void, omit it. */
2867 if (d_right (tl
) == NULL
2868 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2869 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2871 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2878 /* <bare-function-type> ::= [J]<type>+ */
2880 static struct demangle_component
*
2881 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2883 struct demangle_component
*return_type
;
2884 struct demangle_component
*tl
;
2887 /* Detect special qualifier indicating that the first argument
2888 is the return type. */
2889 peek
= d_peek_char (di
);
2893 has_return_type
= 1;
2896 if (has_return_type
)
2898 return_type
= cplus_demangle_type (di
);
2899 if (return_type
== NULL
)
2905 tl
= d_parmlist (di
);
2909 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2913 /* <class-enum-type> ::= <name> */
2915 static struct demangle_component
*
2916 d_class_enum_type (struct d_info
*di
)
2921 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2922 ::= A [<(dimension) expression>] _ <(element) type>
2925 static struct demangle_component
*
2926 d_array_type (struct d_info
*di
)
2929 struct demangle_component
*dim
;
2931 if (! d_check_char (di
, 'A'))
2934 peek
= d_peek_char (di
);
2937 else if (IS_DIGIT (peek
))
2945 peek
= d_peek_char (di
);
2947 while (IS_DIGIT (peek
));
2948 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2954 dim
= d_expression (di
);
2959 if (! d_check_char (di
, '_'))
2962 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2963 cplus_demangle_type (di
));
2966 /* <vector-type> ::= Dv <number> _ <type>
2967 ::= Dv _ <expression> _ <type> */
2969 static struct demangle_component
*
2970 d_vector_type (struct d_info
*di
)
2973 struct demangle_component
*dim
;
2975 peek
= d_peek_char (di
);
2979 dim
= d_expression (di
);
2982 dim
= d_number_component (di
);
2987 if (! d_check_char (di
, '_'))
2990 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2991 cplus_demangle_type (di
));
2994 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2996 static struct demangle_component
*
2997 d_pointer_to_member_type (struct d_info
*di
)
2999 struct demangle_component
*cl
;
3000 struct demangle_component
*mem
;
3002 if (! d_check_char (di
, 'M'))
3005 cl
= cplus_demangle_type (di
);
3009 /* The ABI says, "The type of a non-static member function is considered
3010 to be different, for the purposes of substitution, from the type of a
3011 namespace-scope or static member function whose type appears
3012 similar. The types of two non-static member functions are considered
3013 to be different, for the purposes of substitution, if the functions
3014 are members of different classes. In other words, for the purposes of
3015 substitution, the class of which the function is a member is
3016 considered part of the type of function."
3018 For a pointer to member function, this call to cplus_demangle_type
3019 will end up adding a (possibly qualified) non-member function type to
3020 the substitution table, which is not correct; however, the member
3021 function type will never be used in a substitution, so putting the
3022 wrong type in the substitution table is harmless. */
3024 mem
= cplus_demangle_type (di
);
3028 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
3031 /* <non-negative number> _ */
3034 d_compact_number (struct d_info
*di
)
3037 if (d_peek_char (di
) == '_')
3039 else if (d_peek_char (di
) == 'n')
3042 num
= d_number (di
) + 1;
3044 if (num
< 0 || ! d_check_char (di
, '_'))
3049 /* <template-param> ::= T_
3050 ::= T <(parameter-2 non-negative) number> _
3053 static struct demangle_component
*
3054 d_template_param (struct d_info
*di
)
3058 if (! d_check_char (di
, 'T'))
3061 param
= d_compact_number (di
);
3067 return d_make_template_param (di
, param
);
3070 /* <template-args> ::= I <template-arg>+ E */
3072 static struct demangle_component
*
3073 d_template_args (struct d_info
*di
)
3075 if (d_peek_char (di
) != 'I'
3076 && d_peek_char (di
) != 'J')
3080 return d_template_args_1 (di
);
3083 /* <template-arg>* E */
3085 static struct demangle_component
*
3086 d_template_args_1 (struct d_info
*di
)
3088 struct demangle_component
*hold_last_name
;
3089 struct demangle_component
*al
;
3090 struct demangle_component
**pal
;
3092 /* Preserve the last name we saw--don't let the template arguments
3093 clobber it, as that would give us the wrong name for a subsequent
3094 constructor or destructor. */
3095 hold_last_name
= di
->last_name
;
3097 if (d_peek_char (di
) == 'E')
3099 /* An argument pack can be empty. */
3101 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
3108 struct demangle_component
*a
;
3110 a
= d_template_arg (di
);
3114 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
3117 pal
= &d_right (*pal
);
3119 if (d_peek_char (di
) == 'E')
3126 di
->last_name
= hold_last_name
;
3131 /* <template-arg> ::= <type>
3132 ::= X <expression> E
3136 static struct demangle_component
*
3137 d_template_arg (struct d_info
*di
)
3139 struct demangle_component
*ret
;
3141 switch (d_peek_char (di
))
3145 ret
= d_expression (di
);
3146 if (! d_check_char (di
, 'E'))
3151 return d_expr_primary (di
);
3155 /* An argument pack. */
3156 return d_template_args (di
);
3159 return cplus_demangle_type (di
);
3163 /* Parse a sequence of expressions until we hit the terminator
3166 static struct demangle_component
*
3167 d_exprlist (struct d_info
*di
, char terminator
)
3169 struct demangle_component
*list
= NULL
;
3170 struct demangle_component
**p
= &list
;
3172 if (d_peek_char (di
) == terminator
)
3175 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3180 struct demangle_component
*arg
= d_expression (di
);
3184 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3189 if (d_peek_char (di
) == terminator
)
3199 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3200 dynamic_cast, static_cast or reinterpret_cast. */
3203 op_is_new_cast (struct demangle_component
*op
)
3205 const char *code
= op
->u
.s_operator
.op
->code
;
3206 return (code
[1] == 'c'
3207 && (code
[0] == 's' || code
[0] == 'd'
3208 || code
[0] == 'c' || code
[0] == 'r'));
3211 /* <expression> ::= <(unary) operator-name> <expression>
3212 ::= <(binary) operator-name> <expression> <expression>
3213 ::= <(trinary) operator-name> <expression> <expression> <expression>
3214 ::= cl <expression>+ E
3216 ::= <template-param>
3217 ::= sr <type> <unqualified-name>
3218 ::= sr <type> <unqualified-name> <template-args>
3222 static inline struct demangle_component
*
3223 d_expression_1 (struct d_info
*di
)
3227 peek
= d_peek_char (di
);
3229 return d_expr_primary (di
);
3230 else if (peek
== 'T')
3231 return d_template_param (di
);
3232 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3234 struct demangle_component
*type
;
3235 struct demangle_component
*name
;
3238 type
= cplus_demangle_type (di
);
3239 name
= d_unqualified_name (di
);
3240 if (d_peek_char (di
) != 'I')
3241 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3243 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3244 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3245 d_template_args (di
)));
3247 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3250 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3251 d_expression_1 (di
), NULL
);
3253 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3255 /* Function parameter used in a late-specified return type. */
3258 if (d_peek_char (di
) == 'T')
3260 /* 'this' parameter. */
3266 index
= d_compact_number (di
);
3267 if (index
== INT_MAX
|| index
== -1)
3271 return d_make_function_param (di
, index
);
3273 else if (IS_DIGIT (peek
)
3274 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3276 /* We can get an unqualified name as an expression in the case of
3277 a dependent function call, i.e. decltype(f(t)). */
3278 struct demangle_component
*name
;
3281 /* operator-function-id, i.e. operator+(t). */
3284 name
= d_unqualified_name (di
);
3287 if (d_peek_char (di
) == 'I')
3288 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3289 d_template_args (di
));
3293 else if ((peek
== 'i' || peek
== 't')
3294 && d_peek_next_char (di
) == 'l')
3296 /* Brace-enclosed initializer list, untyped or typed. */
3297 struct demangle_component
*type
= NULL
;
3299 type
= cplus_demangle_type (di
);
3300 if (!d_peek_next_char (di
))
3303 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3304 type
, d_exprlist (di
, 'E'));
3308 struct demangle_component
*op
;
3309 const char *code
= NULL
;
3312 op
= d_operator_name (di
);
3316 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3318 code
= op
->u
.s_operator
.op
->code
;
3319 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3320 if (strcmp (code
, "st") == 0)
3321 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3322 cplus_demangle_type (di
));
3329 case DEMANGLE_COMPONENT_OPERATOR
:
3330 args
= op
->u
.s_operator
.op
->args
;
3332 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3333 args
= op
->u
.s_extended_operator
.args
;
3335 case DEMANGLE_COMPONENT_CAST
:
3343 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3347 struct demangle_component
*operand
;
3350 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3351 && code
[1] == code
[0])
3352 /* pp_ and mm_ are the prefix variants. */
3353 suffix
= !d_check_char (di
, '_');
3355 if (op
->type
== DEMANGLE_COMPONENT_CAST
3356 && d_check_char (di
, '_'))
3357 operand
= d_exprlist (di
, 'E');
3358 else if (code
&& !strcmp (code
, "sP"))
3359 operand
= d_template_args_1 (di
);
3361 operand
= d_expression_1 (di
);
3364 /* Indicate the suffix variant for d_print_comp. */
3365 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3367 DEMANGLE_COMPONENT_BINARY_ARGS
,
3370 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3375 struct demangle_component
*left
;
3376 struct demangle_component
*right
;
3380 if (op_is_new_cast (op
))
3381 left
= cplus_demangle_type (di
);
3382 else if (code
[0] == 'f')
3383 /* fold-expression. */
3384 left
= d_operator_name (di
);
3386 left
= d_expression_1 (di
);
3387 if (!strcmp (code
, "cl"))
3388 right
= d_exprlist (di
, 'E');
3389 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3391 right
= d_unqualified_name (di
);
3392 if (d_peek_char (di
) == 'I')
3393 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3394 right
, d_template_args (di
));
3397 right
= d_expression_1 (di
);
3399 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3401 DEMANGLE_COMPONENT_BINARY_ARGS
,
3406 struct demangle_component
*first
;
3407 struct demangle_component
*second
;
3408 struct demangle_component
*third
;
3412 else if (!strcmp (code
, "qu"))
3414 /* ?: expression. */
3415 first
= d_expression_1 (di
);
3416 second
= d_expression_1 (di
);
3417 third
= d_expression_1 (di
);
3421 else if (code
[0] == 'f')
3423 /* fold-expression. */
3424 first
= d_operator_name (di
);
3425 second
= d_expression_1 (di
);
3426 third
= d_expression_1 (di
);
3430 else if (code
[0] == 'n')
3432 /* new-expression. */
3433 if (code
[1] != 'w' && code
[1] != 'a')
3435 first
= d_exprlist (di
, '_');
3436 second
= cplus_demangle_type (di
);
3437 if (d_peek_char (di
) == 'E')
3442 else if (d_peek_char (di
) == 'p'
3443 && d_peek_next_char (di
) == 'i')
3445 /* Parenthesized initializer. */
3447 third
= d_exprlist (di
, 'E');
3449 else if (d_peek_char (di
) == 'i'
3450 && d_peek_next_char (di
) == 'l')
3451 /* initializer-list. */
3452 third
= d_expression_1 (di
);
3458 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3460 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3463 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3472 static struct demangle_component
*
3473 d_expression (struct d_info
*di
)
3475 struct demangle_component
*ret
;
3476 int was_expression
= di
->is_expression
;
3478 di
->is_expression
= 1;
3479 ret
= d_expression_1 (di
);
3480 di
->is_expression
= was_expression
;
3484 /* <expr-primary> ::= L <type> <(value) number> E
3485 ::= L <type> <(value) float> E
3486 ::= L <mangled-name> E
3489 static struct demangle_component
*
3490 d_expr_primary (struct d_info
*di
)
3492 struct demangle_component
*ret
;
3494 if (! d_check_char (di
, 'L'))
3496 if (d_peek_char (di
) == '_'
3497 /* Workaround for G++ bug; see comment in write_template_arg. */
3498 || d_peek_char (di
) == 'Z')
3499 ret
= cplus_demangle_mangled_name (di
, 0);
3502 struct demangle_component
*type
;
3503 enum demangle_component_type t
;
3506 type
= cplus_demangle_type (di
);
3510 /* If we have a type we know how to print, we aren't going to
3511 print the type name itself. */
3512 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3513 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3514 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3516 /* Rather than try to interpret the literal value, we just
3517 collect it as a string. Note that it's possible to have a
3518 floating point literal here. The ABI specifies that the
3519 format of such literals is machine independent. That's fine,
3520 but what's not fine is that versions of g++ up to 3.2 with
3521 -fabi-version=1 used upper case letters in the hex constant,
3522 and dumped out gcc's internal representation. That makes it
3523 hard to tell where the constant ends, and hard to dump the
3524 constant in any readable form anyhow. We don't attempt to
3525 handle these cases. */
3527 t
= DEMANGLE_COMPONENT_LITERAL
;
3528 if (d_peek_char (di
) == 'n')
3530 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3534 while (d_peek_char (di
) != 'E')
3536 if (d_peek_char (di
) == '\0')
3540 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3542 if (! d_check_char (di
, 'E'))
3547 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3548 ::= Z <(function) encoding> E s [<discriminator>]
3549 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3552 static struct demangle_component
*
3553 d_local_name (struct d_info
*di
)
3555 struct demangle_component
*function
;
3557 if (! d_check_char (di
, 'Z'))
3560 function
= d_encoding (di
, 0);
3562 if (! d_check_char (di
, 'E'))
3565 if (d_peek_char (di
) == 's')
3568 if (! d_discriminator (di
))
3570 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3571 d_make_name (di
, "string literal",
3572 sizeof "string literal" - 1));
3576 struct demangle_component
*name
;
3579 if (d_peek_char (di
) == 'd')
3581 /* Default argument scope: d <number> _. */
3583 num
= d_compact_number (di
);
3592 /* Lambdas and unnamed types have internal discriminators. */
3593 case DEMANGLE_COMPONENT_LAMBDA
:
3594 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3597 if (! d_discriminator (di
))
3601 name
= d_make_default_arg (di
, num
, name
);
3602 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3606 /* <discriminator> ::= _ <(non-negative) number>
3608 We demangle the discriminator, but we don't print it out. FIXME:
3609 We should print it out in verbose mode. */
3612 d_discriminator (struct d_info
*di
)
3616 if (d_peek_char (di
) != '_')
3619 discrim
= d_number (di
);
3625 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3627 static struct demangle_component
*
3628 d_lambda (struct d_info
*di
)
3630 struct demangle_component
*tl
;
3631 struct demangle_component
*ret
;
3634 if (! d_check_char (di
, 'U'))
3636 if (! d_check_char (di
, 'l'))
3639 tl
= d_parmlist (di
);
3643 if (! d_check_char (di
, 'E'))
3646 num
= d_compact_number (di
);
3650 ret
= d_make_empty (di
);
3653 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3654 ret
->u
.s_unary_num
.sub
= tl
;
3655 ret
->u
.s_unary_num
.num
= num
;
3658 if (! d_add_substitution (di
, ret
))
3664 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3666 static struct demangle_component
*
3667 d_unnamed_type (struct d_info
*di
)
3669 struct demangle_component
*ret
;
3672 if (! d_check_char (di
, 'U'))
3674 if (! d_check_char (di
, 't'))
3677 num
= d_compact_number (di
);
3681 ret
= d_make_empty (di
);
3684 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3685 ret
->u
.s_number
.number
= num
;
3688 if (! d_add_substitution (di
, ret
))
3694 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3697 static struct demangle_component
*
3698 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3700 const char *suffix
= d_str (di
);
3701 const char *pend
= suffix
;
3702 struct demangle_component
*n
;
3704 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3707 while (IS_LOWER (*pend
) || *pend
== '_')
3710 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3713 while (IS_DIGIT (*pend
))
3716 d_advance (di
, pend
- suffix
);
3717 n
= d_make_name (di
, suffix
, pend
- suffix
);
3718 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3721 /* Add a new substitution. */
3724 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3728 if (di
->next_sub
>= di
->num_subs
)
3730 di
->subs
[di
->next_sub
] = dc
;
3735 /* <substitution> ::= S <seq-id> _
3745 If PREFIX is non-zero, then this type is being used as a prefix in
3746 a qualified name. In this case, for the standard substitutions, we
3747 need to check whether we are being used as a prefix for a
3748 constructor or destructor, and return a full template name.
3749 Otherwise we will get something like std::iostream::~iostream()
3750 which does not correspond particularly well to any function which
3751 actually appears in the source.
3754 static const struct d_standard_sub_info standard_subs
[] =
3759 { 'a', NL ("std::allocator"),
3760 NL ("std::allocator"),
3762 { 'b', NL ("std::basic_string"),
3763 NL ("std::basic_string"),
3764 NL ("basic_string") },
3765 { 's', NL ("std::string"),
3766 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3767 NL ("basic_string") },
3768 { 'i', NL ("std::istream"),
3769 NL ("std::basic_istream<char, std::char_traits<char> >"),
3770 NL ("basic_istream") },
3771 { 'o', NL ("std::ostream"),
3772 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3773 NL ("basic_ostream") },
3774 { 'd', NL ("std::iostream"),
3775 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3776 NL ("basic_iostream") }
3779 static struct demangle_component
*
3780 d_substitution (struct d_info
*di
, int prefix
)
3784 if (! d_check_char (di
, 'S'))
3787 c
= d_next_char (di
);
3788 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3797 unsigned int new_id
;
3800 new_id
= id
* 36 + c
- '0';
3801 else if (IS_UPPER (c
))
3802 new_id
= id
* 36 + c
- 'A' + 10;
3808 c
= d_next_char (di
);
3815 if (id
>= (unsigned int) di
->next_sub
)
3820 return di
->subs
[id
];
3825 const struct d_standard_sub_info
*p
;
3826 const struct d_standard_sub_info
*pend
;
3828 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3829 if (! verbose
&& prefix
)
3833 peek
= d_peek_char (di
);
3834 if (peek
== 'C' || peek
== 'D')
3838 pend
= (&standard_subs
[0]
3839 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3840 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3846 struct demangle_component
*dc
;
3848 if (p
->set_last_name
!= NULL
)
3849 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3850 p
->set_last_name_len
);
3853 s
= p
->full_expansion
;
3858 s
= p
->simple_expansion
;
3859 len
= p
->simple_len
;
3861 di
->expansion
+= len
;
3862 dc
= d_make_sub (di
, s
, len
);
3863 if (d_peek_char (di
) == 'B')
3865 /* If there are ABI tags on the abbreviation, it becomes
3866 a substitution candidate. */
3867 dc
= d_abi_tags (di
, dc
);
3868 d_add_substitution (di
, dc
);
3879 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3881 checkpoint
->n
= di
->n
;
3882 checkpoint
->next_comp
= di
->next_comp
;
3883 checkpoint
->next_sub
= di
->next_sub
;
3884 checkpoint
->did_subs
= di
->did_subs
;
3885 checkpoint
->expansion
= di
->expansion
;
3889 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3891 di
->n
= checkpoint
->n
;
3892 di
->next_comp
= checkpoint
->next_comp
;
3893 di
->next_sub
= checkpoint
->next_sub
;
3894 di
->did_subs
= checkpoint
->did_subs
;
3895 di
->expansion
= checkpoint
->expansion
;
3898 /* Initialize a growable string. */
3901 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3906 dgs
->allocation_failure
= 0;
3909 d_growable_string_resize (dgs
, estimate
);
3912 /* Grow a growable string to a given size. */
3915 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3920 if (dgs
->allocation_failure
)
3923 /* Start allocation at two bytes to avoid any possibility of confusion
3924 with the special value of 1 used as a return in *palc to indicate
3925 allocation failures. */
3926 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3927 while (newalc
< need
)
3930 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3937 dgs
->allocation_failure
= 1;
3944 /* Append a buffer to a growable string. */
3947 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3948 const char *s
, size_t l
)
3952 need
= dgs
->len
+ l
+ 1;
3953 if (need
> dgs
->alc
)
3954 d_growable_string_resize (dgs
, need
);
3956 if (dgs
->allocation_failure
)
3959 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3960 dgs
->buf
[dgs
->len
+ l
] = '\0';
3964 /* Bridge growable strings to the callback mechanism. */
3967 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3969 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3971 d_growable_string_append_buffer (dgs
, s
, l
);
3974 /* Walk the tree, counting the number of templates encountered, and
3975 the number of times a scope might be saved. These counts will be
3976 used to allocate data structures for d_print_comp, so the logic
3977 here must mirror the logic d_print_comp will use. It is not
3978 important that the resulting numbers are exact, so long as they
3979 are larger than the actual numbers encountered. */
3982 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
3983 const struct demangle_component
*dc
)
3990 case DEMANGLE_COMPONENT_NAME
:
3991 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3992 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3993 case DEMANGLE_COMPONENT_SUB_STD
:
3994 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3995 case DEMANGLE_COMPONENT_OPERATOR
:
3996 case DEMANGLE_COMPONENT_CHARACTER
:
3997 case DEMANGLE_COMPONENT_NUMBER
:
3998 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4001 case DEMANGLE_COMPONENT_TEMPLATE
:
4003 goto recurse_left_right
;
4005 case DEMANGLE_COMPONENT_REFERENCE
:
4006 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4007 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4009 goto recurse_left_right
;
4011 case DEMANGLE_COMPONENT_QUAL_NAME
:
4012 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4013 case DEMANGLE_COMPONENT_TYPED_NAME
:
4014 case DEMANGLE_COMPONENT_VTABLE
:
4015 case DEMANGLE_COMPONENT_VTT
:
4016 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4017 case DEMANGLE_COMPONENT_TYPEINFO
:
4018 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4019 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4020 case DEMANGLE_COMPONENT_THUNK
:
4021 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4022 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4023 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4024 case DEMANGLE_COMPONENT_GUARD
:
4025 case DEMANGLE_COMPONENT_TLS_INIT
:
4026 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4027 case DEMANGLE_COMPONENT_REFTEMP
:
4028 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4029 case DEMANGLE_COMPONENT_RESTRICT
:
4030 case DEMANGLE_COMPONENT_VOLATILE
:
4031 case DEMANGLE_COMPONENT_CONST
:
4032 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4033 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4034 case DEMANGLE_COMPONENT_CONST_THIS
:
4035 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4036 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4037 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4038 case DEMANGLE_COMPONENT_NOEXCEPT
:
4039 case DEMANGLE_COMPONENT_THROW_SPEC
:
4040 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4041 case DEMANGLE_COMPONENT_POINTER
:
4042 case DEMANGLE_COMPONENT_COMPLEX
:
4043 case DEMANGLE_COMPONENT_IMAGINARY
:
4044 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4045 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4046 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4047 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4048 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4049 case DEMANGLE_COMPONENT_ARGLIST
:
4050 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4051 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4052 case DEMANGLE_COMPONENT_CAST
:
4053 case DEMANGLE_COMPONENT_CONVERSION
:
4054 case DEMANGLE_COMPONENT_NULLARY
:
4055 case DEMANGLE_COMPONENT_UNARY
:
4056 case DEMANGLE_COMPONENT_BINARY
:
4057 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4058 case DEMANGLE_COMPONENT_TRINARY
:
4059 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4060 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4061 case DEMANGLE_COMPONENT_LITERAL
:
4062 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4063 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4064 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4065 case DEMANGLE_COMPONENT_DECLTYPE
:
4066 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4067 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4068 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4069 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4070 case DEMANGLE_COMPONENT_CLONE
:
4072 d_count_templates_scopes (num_templates
, num_scopes
,
4074 d_count_templates_scopes (num_templates
, num_scopes
,
4078 case DEMANGLE_COMPONENT_CTOR
:
4079 d_count_templates_scopes (num_templates
, num_scopes
,
4083 case DEMANGLE_COMPONENT_DTOR
:
4084 d_count_templates_scopes (num_templates
, num_scopes
,
4088 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4089 d_count_templates_scopes (num_templates
, num_scopes
,
4090 dc
->u
.s_extended_operator
.name
);
4093 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4094 d_count_templates_scopes (num_templates
, num_scopes
,
4095 dc
->u
.s_fixed
.length
);
4098 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4099 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4100 d_count_templates_scopes (num_templates
, num_scopes
,
4104 case DEMANGLE_COMPONENT_LAMBDA
:
4105 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4106 d_count_templates_scopes (num_templates
, num_scopes
,
4107 dc
->u
.s_unary_num
.sub
);
4112 /* Initialize a print information structure. */
4115 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
4116 void *opaque
, const struct demangle_component
*dc
)
4119 dpi
->last_char
= '\0';
4120 dpi
->templates
= NULL
;
4121 dpi
->modifiers
= NULL
;
4122 dpi
->pack_index
= 0;
4123 dpi
->flush_count
= 0;
4125 dpi
->callback
= callback
;
4126 dpi
->opaque
= opaque
;
4128 dpi
->demangle_failure
= 0;
4130 dpi
->component_stack
= NULL
;
4132 dpi
->saved_scopes
= NULL
;
4133 dpi
->next_saved_scope
= 0;
4134 dpi
->num_saved_scopes
= 0;
4136 dpi
->copy_templates
= NULL
;
4137 dpi
->next_copy_template
= 0;
4138 dpi
->num_copy_templates
= 0;
4140 d_count_templates_scopes (&dpi
->num_copy_templates
,
4141 &dpi
->num_saved_scopes
, dc
);
4142 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
4144 dpi
->current_template
= NULL
;
4147 /* Indicate that an error occurred during printing, and test for error. */
4150 d_print_error (struct d_print_info
*dpi
)
4152 dpi
->demangle_failure
= 1;
4156 d_print_saw_error (struct d_print_info
*dpi
)
4158 return dpi
->demangle_failure
!= 0;
4161 /* Flush buffered characters to the callback. */
4164 d_print_flush (struct d_print_info
*dpi
)
4166 dpi
->buf
[dpi
->len
] = '\0';
4167 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4172 /* Append characters and buffers for printing. */
4175 d_append_char (struct d_print_info
*dpi
, char c
)
4177 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4178 d_print_flush (dpi
);
4180 dpi
->buf
[dpi
->len
++] = c
;
4185 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4189 for (i
= 0; i
< l
; i
++)
4190 d_append_char (dpi
, s
[i
]);
4194 d_append_string (struct d_print_info
*dpi
, const char *s
)
4196 d_append_buffer (dpi
, s
, strlen (s
));
4200 d_append_num (struct d_print_info
*dpi
, int l
)
4203 sprintf (buf
,"%d", l
);
4204 d_append_string (dpi
, buf
);
4208 d_last_char (struct d_print_info
*dpi
)
4210 return dpi
->last_char
;
4213 /* Turn components into a human readable string. OPTIONS is the
4214 options bits passed to the demangler. DC is the tree to print.
4215 CALLBACK is a function to call to flush demangled string segments
4216 as they fill the intermediate buffer, and OPAQUE is a generalized
4217 callback argument. On success, this returns 1. On failure,
4218 it returns 0, indicating a bad parse. It does not use heap
4219 memory to build an output string, so cannot encounter memory
4220 allocation failure. */
4222 CP_STATIC_IF_GLIBCPP_V3
4224 cplus_demangle_print_callback (int options
,
4225 const struct demangle_component
*dc
,
4226 demangle_callbackref callback
, void *opaque
)
4228 struct d_print_info dpi
;
4230 d_print_init (&dpi
, callback
, opaque
, dc
);
4233 #ifdef CP_DYNAMIC_ARRAYS
4234 /* Avoid zero-length VLAs, which are prohibited by the C99 standard
4235 and flagged as errors by Address Sanitizer. */
4236 __extension__
struct d_saved_scope scopes
[(dpi
.num_saved_scopes
> 0)
4237 ? dpi
.num_saved_scopes
: 1];
4238 __extension__
struct d_print_template temps
[(dpi
.num_copy_templates
> 0)
4239 ? dpi
.num_copy_templates
: 1];
4241 dpi
.saved_scopes
= scopes
;
4242 dpi
.copy_templates
= temps
;
4244 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4245 * sizeof (*dpi
.saved_scopes
));
4246 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4247 * sizeof (*dpi
.copy_templates
));
4250 d_print_comp (&dpi
, options
, dc
);
4253 d_print_flush (&dpi
);
4255 return ! d_print_saw_error (&dpi
);
4258 /* Turn components into a human readable string. OPTIONS is the
4259 options bits passed to the demangler. DC is the tree to print.
4260 ESTIMATE is a guess at the length of the result. This returns a
4261 string allocated by malloc, or NULL on error. On success, this
4262 sets *PALC to the size of the allocated buffer. On failure, this
4263 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4266 CP_STATIC_IF_GLIBCPP_V3
4268 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4269 int estimate
, size_t *palc
)
4271 struct d_growable_string dgs
;
4273 d_growable_string_init (&dgs
, estimate
);
4275 if (! cplus_demangle_print_callback (options
, dc
,
4276 d_growable_string_callback_adapter
,
4284 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4288 /* Returns the I'th element of the template arglist ARGS, or NULL on
4289 failure. If I is negative, return the entire arglist. */
4291 static struct demangle_component
*
4292 d_index_template_argument (struct demangle_component
*args
, int i
)
4294 struct demangle_component
*a
;
4297 /* Print the whole argument pack. */
4304 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4310 if (i
!= 0 || a
== NULL
)
4316 /* Returns the template argument from the current context indicated by DC,
4317 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4319 static struct demangle_component
*
4320 d_lookup_template_argument (struct d_print_info
*dpi
,
4321 const struct demangle_component
*dc
)
4323 if (dpi
->templates
== NULL
)
4325 d_print_error (dpi
);
4329 return d_index_template_argument
4330 (d_right (dpi
->templates
->template_decl
),
4331 dc
->u
.s_number
.number
);
4334 /* Returns a template argument pack used in DC (any will do), or NULL. */
4336 static struct demangle_component
*
4337 d_find_pack (struct d_print_info
*dpi
,
4338 const struct demangle_component
*dc
)
4340 struct demangle_component
*a
;
4346 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4347 a
= d_lookup_template_argument (dpi
, dc
);
4348 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4352 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4355 case DEMANGLE_COMPONENT_LAMBDA
:
4356 case DEMANGLE_COMPONENT_NAME
:
4357 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4358 case DEMANGLE_COMPONENT_OPERATOR
:
4359 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4360 case DEMANGLE_COMPONENT_SUB_STD
:
4361 case DEMANGLE_COMPONENT_CHARACTER
:
4362 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4363 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4364 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4365 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4366 case DEMANGLE_COMPONENT_NUMBER
:
4369 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4370 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4371 case DEMANGLE_COMPONENT_CTOR
:
4372 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4373 case DEMANGLE_COMPONENT_DTOR
:
4374 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4377 a
= d_find_pack (dpi
, d_left (dc
));
4380 return d_find_pack (dpi
, d_right (dc
));
4384 /* Returns the length of the template argument pack DC. */
4387 d_pack_length (const struct demangle_component
*dc
)
4390 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4391 && d_left (dc
) != NULL
)
4399 /* Returns the number of template args in DC, expanding any pack expansions
4403 d_args_length (struct d_print_info
*dpi
, const struct demangle_component
*dc
)
4406 for (; dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
;
4409 struct demangle_component
*elt
= d_left (dc
);
4412 if (elt
->type
== DEMANGLE_COMPONENT_PACK_EXPANSION
)
4414 struct demangle_component
*a
= d_find_pack (dpi
, d_left (elt
));
4415 count
+= d_pack_length (a
);
4423 /* DC is a component of a mangled expression. Print it, wrapped in parens
4427 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4428 const struct demangle_component
*dc
)
4431 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4432 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4433 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4434 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4437 d_append_char (dpi
, '(');
4438 d_print_comp (dpi
, options
, dc
);
4440 d_append_char (dpi
, ')');
4443 /* Save the current scope. */
4446 d_save_scope (struct d_print_info
*dpi
,
4447 const struct demangle_component
*container
)
4449 struct d_saved_scope
*scope
;
4450 struct d_print_template
*src
, **link
;
4452 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4454 d_print_error (dpi
);
4457 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4458 dpi
->next_saved_scope
++;
4460 scope
->container
= container
;
4461 link
= &scope
->templates
;
4463 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4465 struct d_print_template
*dst
;
4467 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4469 d_print_error (dpi
);
4472 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4473 dpi
->next_copy_template
++;
4475 dst
->template_decl
= src
->template_decl
;
4483 /* Attempt to locate a previously saved scope. Returns NULL if no
4484 corresponding saved scope was found. */
4486 static struct d_saved_scope
*
4487 d_get_saved_scope (struct d_print_info
*dpi
,
4488 const struct demangle_component
*container
)
4492 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4493 if (dpi
->saved_scopes
[i
].container
== container
)
4494 return &dpi
->saved_scopes
[i
];
4499 /* If DC is a C++17 fold-expression, print it and return true; otherwise
4503 d_maybe_print_fold_expression (struct d_print_info
*dpi
, int options
,
4504 const struct demangle_component
*dc
)
4506 const struct demangle_component
*ops
, *operator_
, *op1
, *op2
;
4509 const char *fold_code
= d_left (dc
)->u
.s_operator
.op
->code
;
4510 if (fold_code
[0] != 'f')
4514 operator_
= d_left (ops
);
4515 op1
= d_right (ops
);
4517 if (op1
->type
== DEMANGLE_COMPONENT_TRINARY_ARG2
)
4519 op2
= d_right (op1
);
4523 /* Print the whole pack. */
4524 save_idx
= dpi
->pack_index
;
4525 dpi
->pack_index
= -1;
4527 switch (fold_code
[1])
4529 /* Unary left fold, (... + X). */
4531 d_append_string (dpi
, "(...");
4532 d_print_expr_op (dpi
, options
, operator_
);
4533 d_print_subexpr (dpi
, options
, op1
);
4534 d_append_char (dpi
, ')');
4537 /* Unary right fold, (X + ...). */
4539 d_append_char (dpi
, '(');
4540 d_print_subexpr (dpi
, options
, op1
);
4541 d_print_expr_op (dpi
, options
, operator_
);
4542 d_append_string (dpi
, "...)");
4545 /* Binary left fold, (42 + ... + X). */
4547 /* Binary right fold, (X + ... + 42). */
4549 d_append_char (dpi
, '(');
4550 d_print_subexpr (dpi
, options
, op1
);
4551 d_print_expr_op (dpi
, options
, operator_
);
4552 d_append_string (dpi
, "...");
4553 d_print_expr_op (dpi
, options
, operator_
);
4554 d_print_subexpr (dpi
, options
, op2
);
4555 d_append_char (dpi
, ')');
4559 dpi
->pack_index
= save_idx
;
4563 /* Subroutine to handle components. */
4566 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
4567 const struct demangle_component
*dc
)
4569 /* Magic variable to let reference smashing skip over the next modifier
4570 without needing to modify *dc. */
4571 const struct demangle_component
*mod_inner
= NULL
;
4573 /* Variable used to store the current templates while a previously
4574 captured scope is used. */
4575 struct d_print_template
*saved_templates
;
4577 /* Nonzero if templates have been stored in the above variable. */
4578 int need_template_restore
= 0;
4582 d_print_error (dpi
);
4585 if (d_print_saw_error (dpi
))
4590 case DEMANGLE_COMPONENT_NAME
:
4591 if ((options
& DMGL_JAVA
) == 0)
4592 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4594 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4597 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4598 d_print_comp (dpi
, options
, d_left (dc
));
4599 d_append_string (dpi
, "[abi:");
4600 d_print_comp (dpi
, options
, d_right (dc
));
4601 d_append_char (dpi
, ']');
4604 case DEMANGLE_COMPONENT_QUAL_NAME
:
4605 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4606 d_print_comp (dpi
, options
, d_left (dc
));
4607 if ((options
& DMGL_JAVA
) == 0)
4608 d_append_string (dpi
, "::");
4610 d_append_char (dpi
, '.');
4612 struct demangle_component
*local_name
= d_right (dc
);
4613 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4615 d_append_string (dpi
, "{default arg#");
4616 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4617 d_append_string (dpi
, "}::");
4618 local_name
= local_name
->u
.s_unary_num
.sub
;
4620 d_print_comp (dpi
, options
, local_name
);
4624 case DEMANGLE_COMPONENT_TYPED_NAME
:
4626 struct d_print_mod
*hold_modifiers
;
4627 struct demangle_component
*typed_name
;
4628 struct d_print_mod adpm
[4];
4630 struct d_print_template dpt
;
4632 /* Pass the name down to the type so that it can be printed in
4633 the right place for the type. We also have to pass down
4634 any CV-qualifiers, which apply to the this parameter. */
4635 hold_modifiers
= dpi
->modifiers
;
4638 typed_name
= d_left (dc
);
4639 while (typed_name
!= NULL
)
4641 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4643 d_print_error (dpi
);
4647 adpm
[i
].next
= dpi
->modifiers
;
4648 dpi
->modifiers
= &adpm
[i
];
4649 adpm
[i
].mod
= typed_name
;
4650 adpm
[i
].printed
= 0;
4651 adpm
[i
].templates
= dpi
->templates
;
4654 if (!is_fnqual_component_type (typed_name
->type
))
4657 typed_name
= d_left (typed_name
);
4660 if (typed_name
== NULL
)
4662 d_print_error (dpi
);
4666 /* If typed_name is a template, then it applies to the
4667 function type as well. */
4668 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4670 dpt
.next
= dpi
->templates
;
4671 dpi
->templates
= &dpt
;
4672 dpt
.template_decl
= typed_name
;
4675 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4676 there may be CV-qualifiers on its right argument which
4677 really apply here; this happens when parsing a class which
4678 is local to a function. */
4679 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4681 struct demangle_component
*local_name
;
4683 local_name
= d_right (typed_name
);
4684 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4685 local_name
= local_name
->u
.s_unary_num
.sub
;
4686 if (local_name
== NULL
)
4688 d_print_error (dpi
);
4691 while (is_fnqual_component_type (local_name
->type
))
4693 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4695 d_print_error (dpi
);
4699 adpm
[i
] = adpm
[i
- 1];
4700 adpm
[i
].next
= &adpm
[i
- 1];
4701 dpi
->modifiers
= &adpm
[i
];
4703 adpm
[i
- 1].mod
= local_name
;
4704 adpm
[i
- 1].printed
= 0;
4705 adpm
[i
- 1].templates
= dpi
->templates
;
4708 local_name
= d_left (local_name
);
4712 d_print_comp (dpi
, options
, d_right (dc
));
4714 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4715 dpi
->templates
= dpt
.next
;
4717 /* If the modifiers didn't get printed by the type, print them
4722 if (! adpm
[i
].printed
)
4724 d_append_char (dpi
, ' ');
4725 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4729 dpi
->modifiers
= hold_modifiers
;
4734 case DEMANGLE_COMPONENT_TEMPLATE
:
4736 struct d_print_mod
*hold_dpm
;
4737 struct demangle_component
*dcl
;
4738 const struct demangle_component
*hold_current
;
4740 /* This template may need to be referenced by a cast operator
4741 contained in its subtree. */
4742 hold_current
= dpi
->current_template
;
4743 dpi
->current_template
= dc
;
4745 /* Don't push modifiers into a template definition. Doing so
4746 could give the wrong definition for a template argument.
4747 Instead, treat the template essentially as a name. */
4749 hold_dpm
= dpi
->modifiers
;
4750 dpi
->modifiers
= NULL
;
4754 if ((options
& DMGL_JAVA
) != 0
4755 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4756 && dcl
->u
.s_name
.len
== 6
4757 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4759 /* Special-case Java arrays, so that JArray<TYPE> appears
4760 instead as TYPE[]. */
4762 d_print_comp (dpi
, options
, d_right (dc
));
4763 d_append_string (dpi
, "[]");
4767 d_print_comp (dpi
, options
, dcl
);
4768 if (d_last_char (dpi
) == '<')
4769 d_append_char (dpi
, ' ');
4770 d_append_char (dpi
, '<');
4771 d_print_comp (dpi
, options
, d_right (dc
));
4772 /* Avoid generating two consecutive '>' characters, to avoid
4773 the C++ syntactic ambiguity. */
4774 if (d_last_char (dpi
) == '>')
4775 d_append_char (dpi
, ' ');
4776 d_append_char (dpi
, '>');
4779 dpi
->modifiers
= hold_dpm
;
4780 dpi
->current_template
= hold_current
;
4785 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4787 struct d_print_template
*hold_dpt
;
4788 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4790 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4791 a
= d_index_template_argument (a
, dpi
->pack_index
);
4795 d_print_error (dpi
);
4799 /* While processing this parameter, we need to pop the list of
4800 templates. This is because the template parameter may
4801 itself be a reference to a parameter of an outer
4804 hold_dpt
= dpi
->templates
;
4805 dpi
->templates
= hold_dpt
->next
;
4807 d_print_comp (dpi
, options
, a
);
4809 dpi
->templates
= hold_dpt
;
4814 case DEMANGLE_COMPONENT_CTOR
:
4815 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4818 case DEMANGLE_COMPONENT_DTOR
:
4819 d_append_char (dpi
, '~');
4820 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4823 case DEMANGLE_COMPONENT_VTABLE
:
4824 d_append_string (dpi
, "vtable for ");
4825 d_print_comp (dpi
, options
, d_left (dc
));
4828 case DEMANGLE_COMPONENT_VTT
:
4829 d_append_string (dpi
, "VTT for ");
4830 d_print_comp (dpi
, options
, d_left (dc
));
4833 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4834 d_append_string (dpi
, "construction vtable for ");
4835 d_print_comp (dpi
, options
, d_left (dc
));
4836 d_append_string (dpi
, "-in-");
4837 d_print_comp (dpi
, options
, d_right (dc
));
4840 case DEMANGLE_COMPONENT_TYPEINFO
:
4841 d_append_string (dpi
, "typeinfo for ");
4842 d_print_comp (dpi
, options
, d_left (dc
));
4845 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4846 d_append_string (dpi
, "typeinfo name for ");
4847 d_print_comp (dpi
, options
, d_left (dc
));
4850 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4851 d_append_string (dpi
, "typeinfo fn for ");
4852 d_print_comp (dpi
, options
, d_left (dc
));
4855 case DEMANGLE_COMPONENT_THUNK
:
4856 d_append_string (dpi
, "non-virtual thunk to ");
4857 d_print_comp (dpi
, options
, d_left (dc
));
4860 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4861 d_append_string (dpi
, "virtual thunk to ");
4862 d_print_comp (dpi
, options
, d_left (dc
));
4865 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4866 d_append_string (dpi
, "covariant return thunk to ");
4867 d_print_comp (dpi
, options
, d_left (dc
));
4870 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4871 d_append_string (dpi
, "java Class for ");
4872 d_print_comp (dpi
, options
, d_left (dc
));
4875 case DEMANGLE_COMPONENT_GUARD
:
4876 d_append_string (dpi
, "guard variable for ");
4877 d_print_comp (dpi
, options
, d_left (dc
));
4880 case DEMANGLE_COMPONENT_TLS_INIT
:
4881 d_append_string (dpi
, "TLS init function for ");
4882 d_print_comp (dpi
, options
, d_left (dc
));
4885 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4886 d_append_string (dpi
, "TLS wrapper function for ");
4887 d_print_comp (dpi
, options
, d_left (dc
));
4890 case DEMANGLE_COMPONENT_REFTEMP
:
4891 d_append_string (dpi
, "reference temporary #");
4892 d_print_comp (dpi
, options
, d_right (dc
));
4893 d_append_string (dpi
, " for ");
4894 d_print_comp (dpi
, options
, d_left (dc
));
4897 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4898 d_append_string (dpi
, "hidden alias for ");
4899 d_print_comp (dpi
, options
, d_left (dc
));
4902 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4903 d_append_string (dpi
, "transaction clone for ");
4904 d_print_comp (dpi
, options
, d_left (dc
));
4907 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4908 d_append_string (dpi
, "non-transaction clone for ");
4909 d_print_comp (dpi
, options
, d_left (dc
));
4912 case DEMANGLE_COMPONENT_SUB_STD
:
4913 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4916 case DEMANGLE_COMPONENT_RESTRICT
:
4917 case DEMANGLE_COMPONENT_VOLATILE
:
4918 case DEMANGLE_COMPONENT_CONST
:
4920 struct d_print_mod
*pdpm
;
4922 /* When printing arrays, it's possible to have cases where the
4923 same CV-qualifier gets pushed on the stack multiple times.
4924 We only need to print it once. */
4926 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4928 if (! pdpm
->printed
)
4930 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4931 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4932 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4934 if (pdpm
->mod
->type
== dc
->type
)
4936 d_print_comp (dpi
, options
, d_left (dc
));
4944 case DEMANGLE_COMPONENT_REFERENCE
:
4945 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4947 /* Handle reference smashing: & + && = &. */
4948 const struct demangle_component
*sub
= d_left (dc
);
4949 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4951 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4952 struct demangle_component
*a
;
4956 /* This is the first time SUB has been traversed.
4957 We need to capture the current templates so
4958 they can be restored if SUB is reentered as a
4960 d_save_scope (dpi
, sub
);
4961 if (d_print_saw_error (dpi
))
4966 const struct d_component_stack
*dcse
;
4967 int found_self_or_parent
= 0;
4969 /* This traversal is reentering SUB as a substition.
4970 If we are not beneath SUB or DC in the tree then we
4971 need to restore SUB's template stack temporarily. */
4972 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
4973 dcse
= dcse
->parent
)
4977 && dcse
!= dpi
->component_stack
))
4979 found_self_or_parent
= 1;
4984 if (!found_self_or_parent
)
4986 saved_templates
= dpi
->templates
;
4987 dpi
->templates
= scope
->templates
;
4988 need_template_restore
= 1;
4992 a
= d_lookup_template_argument (dpi
, sub
);
4993 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4994 a
= d_index_template_argument (a
, dpi
->pack_index
);
4998 if (need_template_restore
)
4999 dpi
->templates
= saved_templates
;
5001 d_print_error (dpi
);
5008 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
5009 || sub
->type
== dc
->type
)
5011 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
5012 mod_inner
= d_left (sub
);
5016 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5017 case DEMANGLE_COMPONENT_POINTER
:
5018 case DEMANGLE_COMPONENT_COMPLEX
:
5019 case DEMANGLE_COMPONENT_IMAGINARY
:
5020 FNQUAL_COMPONENT_CASE
:
5023 /* We keep a list of modifiers on the stack. */
5024 struct d_print_mod dpm
;
5026 dpm
.next
= dpi
->modifiers
;
5027 dpi
->modifiers
= &dpm
;
5030 dpm
.templates
= dpi
->templates
;
5033 mod_inner
= d_left (dc
);
5035 d_print_comp (dpi
, options
, mod_inner
);
5037 /* If the modifier didn't get printed by the type, print it
5040 d_print_mod (dpi
, options
, dc
);
5042 dpi
->modifiers
= dpm
.next
;
5044 if (need_template_restore
)
5045 dpi
->templates
= saved_templates
;
5050 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5051 if ((options
& DMGL_JAVA
) == 0)
5052 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
5053 dc
->u
.s_builtin
.type
->len
);
5055 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
5056 dc
->u
.s_builtin
.type
->java_len
);
5059 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5060 d_print_comp (dpi
, options
, d_left (dc
));
5063 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5065 if ((options
& DMGL_RET_POSTFIX
) != 0)
5066 d_print_function_type (dpi
,
5067 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5068 dc
, dpi
->modifiers
);
5070 /* Print return type if present */
5071 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
5072 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5074 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
5076 struct d_print_mod dpm
;
5078 /* We must pass this type down as a modifier in order to
5079 print it in the right location. */
5080 dpm
.next
= dpi
->modifiers
;
5081 dpi
->modifiers
= &dpm
;
5084 dpm
.templates
= dpi
->templates
;
5086 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5089 dpi
->modifiers
= dpm
.next
;
5094 /* In standard prefix notation, there is a space between the
5095 return type and the function signature. */
5096 if ((options
& DMGL_RET_POSTFIX
) == 0)
5097 d_append_char (dpi
, ' ');
5100 if ((options
& DMGL_RET_POSTFIX
) == 0)
5101 d_print_function_type (dpi
,
5102 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5103 dc
, dpi
->modifiers
);
5108 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5110 struct d_print_mod
*hold_modifiers
;
5111 struct d_print_mod adpm
[4];
5113 struct d_print_mod
*pdpm
;
5115 /* We must pass this type down as a modifier in order to print
5116 multi-dimensional arrays correctly. If the array itself is
5117 CV-qualified, we act as though the element type were
5118 CV-qualified. We do this by copying the modifiers down
5119 rather than fiddling pointers, so that we don't wind up
5120 with a d_print_mod higher on the stack pointing into our
5121 stack frame after we return. */
5123 hold_modifiers
= dpi
->modifiers
;
5125 adpm
[0].next
= hold_modifiers
;
5126 dpi
->modifiers
= &adpm
[0];
5128 adpm
[0].printed
= 0;
5129 adpm
[0].templates
= dpi
->templates
;
5132 pdpm
= hold_modifiers
;
5134 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
5135 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
5136 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
5138 if (! pdpm
->printed
)
5140 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5142 d_print_error (dpi
);
5147 adpm
[i
].next
= dpi
->modifiers
;
5148 dpi
->modifiers
= &adpm
[i
];
5156 d_print_comp (dpi
, options
, d_right (dc
));
5158 dpi
->modifiers
= hold_modifiers
;
5160 if (adpm
[0].printed
)
5166 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5169 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
5174 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5175 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5177 struct d_print_mod dpm
;
5179 dpm
.next
= dpi
->modifiers
;
5180 dpi
->modifiers
= &dpm
;
5183 dpm
.templates
= dpi
->templates
;
5185 d_print_comp (dpi
, options
, d_right (dc
));
5187 /* If the modifier didn't get printed by the type, print it
5190 d_print_mod (dpi
, options
, dc
);
5192 dpi
->modifiers
= dpm
.next
;
5197 case DEMANGLE_COMPONENT_FIXED_TYPE
:
5198 if (dc
->u
.s_fixed
.sat
)
5199 d_append_string (dpi
, "_Sat ");
5200 /* Don't print "int _Accum". */
5201 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
5202 != &cplus_demangle_builtin_types
['i'-'a'])
5204 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
5205 d_append_char (dpi
, ' ');
5207 if (dc
->u
.s_fixed
.accum
)
5208 d_append_string (dpi
, "_Accum");
5210 d_append_string (dpi
, "_Fract");
5213 case DEMANGLE_COMPONENT_ARGLIST
:
5214 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5215 if (d_left (dc
) != NULL
)
5216 d_print_comp (dpi
, options
, d_left (dc
));
5217 if (d_right (dc
) != NULL
)
5220 unsigned long int flush_count
;
5221 /* Make sure ", " isn't flushed by d_append_string, otherwise
5222 dpi->len -= 2 wouldn't work. */
5223 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5224 d_print_flush (dpi
);
5225 d_append_string (dpi
, ", ");
5227 flush_count
= dpi
->flush_count
;
5228 d_print_comp (dpi
, options
, d_right (dc
));
5229 /* If that didn't print anything (which can happen with empty
5230 template argument packs), remove the comma and space. */
5231 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5236 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5238 struct demangle_component
*type
= d_left (dc
);
5239 struct demangle_component
*list
= d_right (dc
);
5242 d_print_comp (dpi
, options
, type
);
5243 d_append_char (dpi
, '{');
5244 d_print_comp (dpi
, options
, list
);
5245 d_append_char (dpi
, '}');
5249 case DEMANGLE_COMPONENT_OPERATOR
:
5251 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5254 d_append_string (dpi
, "operator");
5255 /* Add a space before new/delete. */
5256 if (IS_LOWER (op
->name
[0]))
5257 d_append_char (dpi
, ' ');
5258 /* Omit a trailing space. */
5259 if (op
->name
[len
-1] == ' ')
5261 d_append_buffer (dpi
, op
->name
, len
);
5265 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5266 d_append_string (dpi
, "operator ");
5267 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5270 case DEMANGLE_COMPONENT_CONVERSION
:
5271 d_append_string (dpi
, "operator ");
5272 d_print_conversion (dpi
, options
, dc
);
5275 case DEMANGLE_COMPONENT_NULLARY
:
5276 d_print_expr_op (dpi
, options
, d_left (dc
));
5279 case DEMANGLE_COMPONENT_UNARY
:
5281 struct demangle_component
*op
= d_left (dc
);
5282 struct demangle_component
*operand
= d_right (dc
);
5283 const char *code
= NULL
;
5285 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5287 code
= op
->u
.s_operator
.op
->code
;
5288 if (!strcmp (code
, "ad"))
5290 /* Don't print the argument list for the address of a
5292 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5293 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5294 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5295 operand
= d_left (operand
);
5297 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5299 /* This indicates a suffix operator. */
5300 operand
= d_left (operand
);
5301 d_print_subexpr (dpi
, options
, operand
);
5302 d_print_expr_op (dpi
, options
, op
);
5307 /* For sizeof..., just print the pack length. */
5308 if (code
&& !strcmp (code
, "sZ"))
5310 struct demangle_component
*a
= d_find_pack (dpi
, operand
);
5311 int len
= d_pack_length (a
);
5312 d_append_num (dpi
, len
);
5315 else if (code
&& !strcmp (code
, "sP"))
5317 int len
= d_args_length (dpi
, operand
);
5318 d_append_num (dpi
, len
);
5322 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5323 d_print_expr_op (dpi
, options
, op
);
5326 d_append_char (dpi
, '(');
5327 d_print_cast (dpi
, options
, op
);
5328 d_append_char (dpi
, ')');
5330 if (code
&& !strcmp (code
, "gs"))
5331 /* Avoid parens after '::'. */
5332 d_print_comp (dpi
, options
, operand
);
5333 else if (code
&& !strcmp (code
, "st"))
5334 /* Always print parens for sizeof (type). */
5336 d_append_char (dpi
, '(');
5337 d_print_comp (dpi
, options
, operand
);
5338 d_append_char (dpi
, ')');
5341 d_print_subexpr (dpi
, options
, operand
);
5345 case DEMANGLE_COMPONENT_BINARY
:
5346 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5348 d_print_error (dpi
);
5352 if (op_is_new_cast (d_left (dc
)))
5354 d_print_expr_op (dpi
, options
, d_left (dc
));
5355 d_append_char (dpi
, '<');
5356 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5357 d_append_string (dpi
, ">(");
5358 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5359 d_append_char (dpi
, ')');
5363 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5366 /* We wrap an expression which uses the greater-than operator in
5367 an extra layer of parens so that it does not get confused
5368 with the '>' which ends the template parameters. */
5369 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5370 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5371 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5372 d_append_char (dpi
, '(');
5374 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5375 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5377 /* Function call used in an expression should not have printed types
5378 of the function arguments. Values of the function arguments still
5379 get printed below. */
5381 const struct demangle_component
*func
= d_left (d_right (dc
));
5383 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5384 d_print_error (dpi
);
5385 d_print_subexpr (dpi
, options
, d_left (func
));
5388 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5389 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5391 d_append_char (dpi
, '[');
5392 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5393 d_append_char (dpi
, ']');
5397 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5398 d_print_expr_op (dpi
, options
, d_left (dc
));
5399 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5402 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5403 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5404 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5405 d_append_char (dpi
, ')');
5409 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5410 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5411 d_print_error (dpi
);
5414 case DEMANGLE_COMPONENT_TRINARY
:
5415 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5416 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5418 d_print_error (dpi
);
5421 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5424 struct demangle_component
*op
= d_left (dc
);
5425 struct demangle_component
*first
= d_left (d_right (dc
));
5426 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5427 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5429 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5431 d_print_subexpr (dpi
, options
, first
);
5432 d_print_expr_op (dpi
, options
, op
);
5433 d_print_subexpr (dpi
, options
, second
);
5434 d_append_string (dpi
, " : ");
5435 d_print_subexpr (dpi
, options
, third
);
5439 d_append_string (dpi
, "new ");
5440 if (d_left (first
) != NULL
)
5442 d_print_subexpr (dpi
, options
, first
);
5443 d_append_char (dpi
, ' ');
5445 d_print_comp (dpi
, options
, second
);
5447 d_print_subexpr (dpi
, options
, third
);
5452 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5453 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5454 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5455 d_print_error (dpi
);
5458 case DEMANGLE_COMPONENT_LITERAL
:
5459 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5461 enum d_builtin_type_print tp
;
5463 /* For some builtin types, produce simpler output. */
5464 tp
= D_PRINT_DEFAULT
;
5465 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5467 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5471 case D_PRINT_UNSIGNED
:
5473 case D_PRINT_UNSIGNED_LONG
:
5474 case D_PRINT_LONG_LONG
:
5475 case D_PRINT_UNSIGNED_LONG_LONG
:
5476 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5478 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5479 d_append_char (dpi
, '-');
5480 d_print_comp (dpi
, options
, d_right (dc
));
5485 case D_PRINT_UNSIGNED
:
5486 d_append_char (dpi
, 'u');
5489 d_append_char (dpi
, 'l');
5491 case D_PRINT_UNSIGNED_LONG
:
5492 d_append_string (dpi
, "ul");
5494 case D_PRINT_LONG_LONG
:
5495 d_append_string (dpi
, "ll");
5497 case D_PRINT_UNSIGNED_LONG_LONG
:
5498 d_append_string (dpi
, "ull");
5506 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5507 && d_right (dc
)->u
.s_name
.len
== 1
5508 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5510 switch (d_right (dc
)->u
.s_name
.s
[0])
5513 d_append_string (dpi
, "false");
5516 d_append_string (dpi
, "true");
5529 d_append_char (dpi
, '(');
5530 d_print_comp (dpi
, options
, d_left (dc
));
5531 d_append_char (dpi
, ')');
5532 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5533 d_append_char (dpi
, '-');
5534 if (tp
== D_PRINT_FLOAT
)
5535 d_append_char (dpi
, '[');
5536 d_print_comp (dpi
, options
, d_right (dc
));
5537 if (tp
== D_PRINT_FLOAT
)
5538 d_append_char (dpi
, ']');
5542 case DEMANGLE_COMPONENT_NUMBER
:
5543 d_append_num (dpi
, dc
->u
.s_number
.number
);
5546 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5547 d_append_string (dpi
, "java resource ");
5548 d_print_comp (dpi
, options
, d_left (dc
));
5551 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5552 d_print_comp (dpi
, options
, d_left (dc
));
5553 d_print_comp (dpi
, options
, d_right (dc
));
5556 case DEMANGLE_COMPONENT_CHARACTER
:
5557 d_append_char (dpi
, dc
->u
.s_character
.character
);
5560 case DEMANGLE_COMPONENT_DECLTYPE
:
5561 d_append_string (dpi
, "decltype (");
5562 d_print_comp (dpi
, options
, d_left (dc
));
5563 d_append_char (dpi
, ')');
5566 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5570 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5573 /* d_find_pack won't find anything if the only packs involved
5574 in this expansion are function parameter packs; in that
5575 case, just print the pattern and "...". */
5576 d_print_subexpr (dpi
, options
, d_left (dc
));
5577 d_append_string (dpi
, "...");
5581 len
= d_pack_length (a
);
5583 for (i
= 0; i
< len
; ++i
)
5585 dpi
->pack_index
= i
;
5586 d_print_comp (dpi
, options
, dc
);
5588 d_append_string (dpi
, ", ");
5593 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5595 long num
= dc
->u
.s_number
.number
;
5597 d_append_string (dpi
, "this");
5600 d_append_string (dpi
, "{parm#");
5601 d_append_num (dpi
, num
);
5602 d_append_char (dpi
, '}');
5607 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5608 d_append_string (dpi
, "global constructors keyed to ");
5609 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5612 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5613 d_append_string (dpi
, "global destructors keyed to ");
5614 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5617 case DEMANGLE_COMPONENT_LAMBDA
:
5618 d_append_string (dpi
, "{lambda(");
5619 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5620 d_append_string (dpi
, ")#");
5621 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5622 d_append_char (dpi
, '}');
5625 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5626 d_append_string (dpi
, "{unnamed type#");
5627 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5628 d_append_char (dpi
, '}');
5631 case DEMANGLE_COMPONENT_CLONE
:
5632 d_print_comp (dpi
, options
, d_left (dc
));
5633 d_append_string (dpi
, " [clone ");
5634 d_print_comp (dpi
, options
, d_right (dc
));
5635 d_append_char (dpi
, ']');
5639 d_print_error (dpi
);
5645 d_print_comp (struct d_print_info
*dpi
, int options
,
5646 const struct demangle_component
*dc
)
5648 struct d_component_stack self
;
5651 self
.parent
= dpi
->component_stack
;
5652 dpi
->component_stack
= &self
;
5654 d_print_comp_inner (dpi
, options
, dc
);
5656 dpi
->component_stack
= self
.parent
;
5659 /* Print a Java dentifier. For Java we try to handle encoded extended
5660 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5661 so we don't it for C++. Characters are encoded as
5665 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5671 for (p
= name
; p
< end
; ++p
)
5682 for (q
= p
+ 3; q
< end
; ++q
)
5688 else if (*q
>= 'A' && *q
<= 'F')
5689 dig
= *q
- 'A' + 10;
5690 else if (*q
>= 'a' && *q
<= 'f')
5691 dig
= *q
- 'a' + 10;
5697 /* If the Unicode character is larger than 256, we don't try
5698 to deal with it here. FIXME. */
5699 if (q
< end
&& *q
== '_' && c
< 256)
5701 d_append_char (dpi
, c
);
5707 d_append_char (dpi
, *p
);
5711 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5712 qualifiers on this after printing a function. */
5715 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5716 struct d_print_mod
*mods
, int suffix
)
5718 struct d_print_template
*hold_dpt
;
5720 if (mods
== NULL
|| d_print_saw_error (dpi
))
5725 && (is_fnqual_component_type (mods
->mod
->type
))))
5727 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5733 hold_dpt
= dpi
->templates
;
5734 dpi
->templates
= mods
->templates
;
5736 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5738 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5739 dpi
->templates
= hold_dpt
;
5742 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5744 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5745 dpi
->templates
= hold_dpt
;
5748 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5750 struct d_print_mod
*hold_modifiers
;
5751 struct demangle_component
*dc
;
5753 /* When this is on the modifier stack, we have pulled any
5754 qualifiers off the right argument already. Otherwise, we
5755 print it as usual, but don't let the left argument see any
5758 hold_modifiers
= dpi
->modifiers
;
5759 dpi
->modifiers
= NULL
;
5760 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5761 dpi
->modifiers
= hold_modifiers
;
5763 if ((options
& DMGL_JAVA
) == 0)
5764 d_append_string (dpi
, "::");
5766 d_append_char (dpi
, '.');
5768 dc
= d_right (mods
->mod
);
5770 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5772 d_append_string (dpi
, "{default arg#");
5773 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5774 d_append_string (dpi
, "}::");
5775 dc
= dc
->u
.s_unary_num
.sub
;
5778 while (is_fnqual_component_type (dc
->type
))
5781 d_print_comp (dpi
, options
, dc
);
5783 dpi
->templates
= hold_dpt
;
5787 d_print_mod (dpi
, options
, mods
->mod
);
5789 dpi
->templates
= hold_dpt
;
5791 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5794 /* Print a modifier. */
5797 d_print_mod (struct d_print_info
*dpi
, int options
,
5798 const struct demangle_component
*mod
)
5802 case DEMANGLE_COMPONENT_RESTRICT
:
5803 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5804 d_append_string (dpi
, " restrict");
5806 case DEMANGLE_COMPONENT_VOLATILE
:
5807 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5808 d_append_string (dpi
, " volatile");
5810 case DEMANGLE_COMPONENT_CONST
:
5811 case DEMANGLE_COMPONENT_CONST_THIS
:
5812 d_append_string (dpi
, " const");
5814 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5815 d_append_string (dpi
, " transaction_safe");
5817 case DEMANGLE_COMPONENT_NOEXCEPT
:
5818 d_append_string (dpi
, " noexcept");
5821 d_append_char (dpi
, '(');
5822 d_print_comp (dpi
, options
, d_right (mod
));
5823 d_append_char (dpi
, ')');
5826 case DEMANGLE_COMPONENT_THROW_SPEC
:
5827 d_append_string (dpi
, " throw");
5830 d_append_char (dpi
, '(');
5831 d_print_comp (dpi
, options
, d_right (mod
));
5832 d_append_char (dpi
, ')');
5835 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5836 d_append_char (dpi
, ' ');
5837 d_print_comp (dpi
, options
, d_right (mod
));
5839 case DEMANGLE_COMPONENT_POINTER
:
5840 /* There is no pointer symbol in Java. */
5841 if ((options
& DMGL_JAVA
) == 0)
5842 d_append_char (dpi
, '*');
5844 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5845 /* For the ref-qualifier, put a space before the &. */
5846 d_append_char (dpi
, ' ');
5848 case DEMANGLE_COMPONENT_REFERENCE
:
5849 d_append_char (dpi
, '&');
5851 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5852 d_append_char (dpi
, ' ');
5854 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5855 d_append_string (dpi
, "&&");
5857 case DEMANGLE_COMPONENT_COMPLEX
:
5858 d_append_string (dpi
, "complex ");
5860 case DEMANGLE_COMPONENT_IMAGINARY
:
5861 d_append_string (dpi
, "imaginary ");
5863 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5864 if (d_last_char (dpi
) != '(')
5865 d_append_char (dpi
, ' ');
5866 d_print_comp (dpi
, options
, d_left (mod
));
5867 d_append_string (dpi
, "::*");
5869 case DEMANGLE_COMPONENT_TYPED_NAME
:
5870 d_print_comp (dpi
, options
, d_left (mod
));
5872 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5873 d_append_string (dpi
, " __vector(");
5874 d_print_comp (dpi
, options
, d_left (mod
));
5875 d_append_char (dpi
, ')');
5879 /* Otherwise, we have something that won't go back on the
5880 modifier stack, so we can just print it. */
5881 d_print_comp (dpi
, options
, mod
);
5886 /* Print a function type, except for the return type. */
5889 d_print_function_type (struct d_print_info
*dpi
, int options
,
5890 const struct demangle_component
*dc
,
5891 struct d_print_mod
*mods
)
5895 struct d_print_mod
*p
;
5896 struct d_print_mod
*hold_modifiers
;
5900 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5905 switch (p
->mod
->type
)
5907 case DEMANGLE_COMPONENT_POINTER
:
5908 case DEMANGLE_COMPONENT_REFERENCE
:
5909 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5912 case DEMANGLE_COMPONENT_RESTRICT
:
5913 case DEMANGLE_COMPONENT_VOLATILE
:
5914 case DEMANGLE_COMPONENT_CONST
:
5915 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5916 case DEMANGLE_COMPONENT_COMPLEX
:
5917 case DEMANGLE_COMPONENT_IMAGINARY
:
5918 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5922 FNQUAL_COMPONENT_CASE
:
5935 if (d_last_char (dpi
) != '('
5936 && d_last_char (dpi
) != '*')
5939 if (need_space
&& d_last_char (dpi
) != ' ')
5940 d_append_char (dpi
, ' ');
5941 d_append_char (dpi
, '(');
5944 hold_modifiers
= dpi
->modifiers
;
5945 dpi
->modifiers
= NULL
;
5947 d_print_mod_list (dpi
, options
, mods
, 0);
5950 d_append_char (dpi
, ')');
5952 d_append_char (dpi
, '(');
5954 if (d_right (dc
) != NULL
)
5955 d_print_comp (dpi
, options
, d_right (dc
));
5957 d_append_char (dpi
, ')');
5959 d_print_mod_list (dpi
, options
, mods
, 1);
5961 dpi
->modifiers
= hold_modifiers
;
5964 /* Print an array type, except for the element type. */
5967 d_print_array_type (struct d_print_info
*dpi
, int options
,
5968 const struct demangle_component
*dc
,
5969 struct d_print_mod
*mods
)
5977 struct d_print_mod
*p
;
5980 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5984 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5999 d_append_string (dpi
, " (");
6001 d_print_mod_list (dpi
, options
, mods
, 0);
6004 d_append_char (dpi
, ')');
6008 d_append_char (dpi
, ' ');
6010 d_append_char (dpi
, '[');
6012 if (d_left (dc
) != NULL
)
6013 d_print_comp (dpi
, options
, d_left (dc
));
6015 d_append_char (dpi
, ']');
6018 /* Print an operator in an expression. */
6021 d_print_expr_op (struct d_print_info
*dpi
, int options
,
6022 const struct demangle_component
*dc
)
6024 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
6025 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
6026 dc
->u
.s_operator
.op
->len
);
6028 d_print_comp (dpi
, options
, dc
);
6034 d_print_cast (struct d_print_info
*dpi
, int options
,
6035 const struct demangle_component
*dc
)
6037 d_print_comp (dpi
, options
, d_left (dc
));
6040 /* Print a conversion operator. */
6043 d_print_conversion (struct d_print_info
*dpi
, int options
,
6044 const struct demangle_component
*dc
)
6046 struct d_print_template dpt
;
6048 /* For a conversion operator, we need the template parameters from
6049 the enclosing template in scope for processing the type. */
6050 if (dpi
->current_template
!= NULL
)
6052 dpt
.next
= dpi
->templates
;
6053 dpi
->templates
= &dpt
;
6054 dpt
.template_decl
= dpi
->current_template
;
6057 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
6059 d_print_comp (dpi
, options
, d_left (dc
));
6060 if (dpi
->current_template
!= NULL
)
6061 dpi
->templates
= dpt
.next
;
6065 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
6067 /* For a templated cast operator, we need to remove the template
6068 parameters from scope after printing the operator name,
6069 so we need to handle the template printing here. */
6070 if (dpi
->current_template
!= NULL
)
6071 dpi
->templates
= dpt
.next
;
6073 if (d_last_char (dpi
) == '<')
6074 d_append_char (dpi
, ' ');
6075 d_append_char (dpi
, '<');
6076 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
6077 /* Avoid generating two consecutive '>' characters, to avoid
6078 the C++ syntactic ambiguity. */
6079 if (d_last_char (dpi
) == '>')
6080 d_append_char (dpi
, ' ');
6081 d_append_char (dpi
, '>');
6085 /* Initialize the information structure we use to pass around
6088 CP_STATIC_IF_GLIBCPP_V3
6090 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
6094 di
->send
= mangled
+ len
;
6095 di
->options
= options
;
6099 /* We can not need more components than twice the number of chars in
6100 the mangled string. Most components correspond directly to
6101 chars, but the ARGLIST types are exceptions. */
6102 di
->num_comps
= 2 * len
;
6105 /* Similarly, we can not need more substitutions than there are
6106 chars in the mangled string. */
6111 di
->last_name
= NULL
;
6114 di
->is_expression
= 0;
6115 di
->is_conversion
= 0;
6118 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
6119 mangled name, return strings in repeated callback giving the demangled
6120 name. OPTIONS is the usual libiberty demangler options. On success,
6121 this returns 1. On failure, returns 0. */
6124 d_demangle_callback (const char *mangled
, int options
,
6125 demangle_callbackref callback
, void *opaque
)
6136 struct demangle_component
*dc
;
6139 if (mangled
[0] == '_' && mangled
[1] == 'Z')
6141 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
6142 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
6143 && (mangled
[9] == 'D' || mangled
[9] == 'I')
6144 && mangled
[10] == '_')
6145 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
6148 if ((options
& DMGL_TYPES
) == 0)
6153 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
6156 #ifdef CP_DYNAMIC_ARRAYS
6157 __extension__
struct demangle_component comps
[di
.num_comps
];
6158 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6163 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6164 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6170 dc
= cplus_demangle_type (&di
);
6173 dc
= cplus_demangle_mangled_name (&di
, 1);
6175 case DCT_GLOBAL_CTORS
:
6176 case DCT_GLOBAL_DTORS
:
6177 d_advance (&di
, 11);
6178 dc
= d_make_comp (&di
,
6179 (type
== DCT_GLOBAL_CTORS
6180 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
6181 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
6182 d_make_demangle_mangled_name (&di
, d_str (&di
)),
6184 d_advance (&di
, strlen (d_str (&di
)));
6187 abort (); /* We have listed all the cases. */
6190 /* If DMGL_PARAMS is set, then if we didn't consume the entire
6191 mangled string, then we didn't successfully demangle it. If
6192 DMGL_PARAMS is not set, we didn't look at the trailing
6194 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
6197 #ifdef CP_DEMANGLE_DEBUG
6201 status
= (dc
!= NULL
)
6202 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6209 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6210 name, return a buffer allocated with malloc holding the demangled
6211 name. OPTIONS is the usual libiberty demangler options. On
6212 success, this sets *PALC to the allocated size of the returned
6213 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6214 a memory allocation failure, and returns NULL. */
6217 d_demangle (const char *mangled
, int options
, size_t *palc
)
6219 struct d_growable_string dgs
;
6222 d_growable_string_init (&dgs
, 0);
6224 status
= d_demangle_callback (mangled
, options
,
6225 d_growable_string_callback_adapter
, &dgs
);
6233 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6237 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6239 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6241 /* ia64 ABI-mandated entry point in the C++ runtime library for
6242 performing demangling. MANGLED_NAME is a NUL-terminated character
6243 string containing the name to be demangled.
6245 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6246 *LENGTH bytes, into which the demangled name is stored. If
6247 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6248 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6249 is placed in a region of memory allocated with malloc.
6251 If LENGTH is non-NULL, the length of the buffer containing the
6252 demangled name, is placed in *LENGTH.
6254 The return value is a pointer to the start of the NUL-terminated
6255 demangled name, or NULL if the demangling fails. The caller is
6256 responsible for deallocating this memory using free.
6258 *STATUS is set to one of the following values:
6259 0: The demangling operation succeeded.
6260 -1: A memory allocation failure occurred.
6261 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6262 -3: One of the arguments is invalid.
6264 The demangling is performed using the C++ ABI mangling rules, with
6268 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6269 size_t *length
, int *status
)
6274 if (mangled_name
== NULL
)
6281 if (output_buffer
!= NULL
&& length
== NULL
)
6288 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6290 if (demangled
== NULL
)
6302 if (output_buffer
== NULL
)
6309 if (strlen (demangled
) < *length
)
6311 strcpy (output_buffer
, demangled
);
6313 demangled
= output_buffer
;
6317 free (output_buffer
);
6328 extern int __gcclibcxx_demangle_callback (const char *,
6330 (const char *, size_t, void *),
6333 /* Alternative, allocationless entry point in the C++ runtime library
6334 for performing demangling. MANGLED_NAME is a NUL-terminated character
6335 string containing the name to be demangled.
6337 CALLBACK is a callback function, called with demangled string
6338 segments as demangling progresses; it is called at least once,
6339 but may be called more than once. OPAQUE is a generalized pointer
6340 used as a callback argument.
6342 The return code is one of the following values, equivalent to
6343 the STATUS values of __cxa_demangle() (excluding -1, since this
6344 function performs no memory allocations):
6345 0: The demangling operation succeeded.
6346 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6347 -3: One of the arguments is invalid.
6349 The demangling is performed using the C++ ABI mangling rules, with
6353 __gcclibcxx_demangle_callback (const char *mangled_name
,
6354 void (*callback
) (const char *, size_t, void *),
6359 if (mangled_name
== NULL
|| callback
== NULL
)
6362 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6370 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6372 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6373 mangled name, return a buffer allocated with malloc holding the
6374 demangled name. Otherwise, return NULL. */
6377 cplus_demangle_v3 (const char *mangled
, int options
)
6381 return d_demangle (mangled
, options
, &alc
);
6385 cplus_demangle_v3_callback (const char *mangled
, int options
,
6386 demangle_callbackref callback
, void *opaque
)
6388 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6391 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6392 conventions, but the output formatting is a little different.
6393 This instructs the C++ demangler not to emit pointer characters ("*"), to
6394 use Java's namespace separator symbol ("." instead of "::"), and to output
6395 JArray<TYPE> as TYPE[]. */
6398 java_demangle_v3 (const char *mangled
)
6402 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6406 java_demangle_v3_callback (const char *mangled
,
6407 demangle_callbackref callback
, void *opaque
)
6409 return d_demangle_callback (mangled
,
6410 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6414 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6416 #ifndef IN_GLIBCPP_V3
6418 /* Demangle a string in order to find out whether it is a constructor
6419 or destructor. Return non-zero on success. Set *CTOR_KIND and
6420 *DTOR_KIND appropriately. */
6423 is_ctor_or_dtor (const char *mangled
,
6424 enum gnu_v3_ctor_kinds
*ctor_kind
,
6425 enum gnu_v3_dtor_kinds
*dtor_kind
)
6428 struct demangle_component
*dc
;
6431 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6432 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6434 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6437 #ifdef CP_DYNAMIC_ARRAYS
6438 __extension__
struct demangle_component comps
[di
.num_comps
];
6439 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6444 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6445 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6448 dc
= cplus_demangle_mangled_name (&di
, 1);
6450 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6451 to demangle the entire string. */
6458 /* These cannot appear on a constructor or destructor. */
6459 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6460 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6461 case DEMANGLE_COMPONENT_CONST_THIS
:
6462 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6463 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6467 case DEMANGLE_COMPONENT_TYPED_NAME
:
6468 case DEMANGLE_COMPONENT_TEMPLATE
:
6471 case DEMANGLE_COMPONENT_QUAL_NAME
:
6472 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6475 case DEMANGLE_COMPONENT_CTOR
:
6476 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6480 case DEMANGLE_COMPONENT_DTOR
:
6481 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6492 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6493 name. A non-zero return indicates the type of constructor. */
6495 enum gnu_v3_ctor_kinds
6496 is_gnu_v3_mangled_ctor (const char *name
)
6498 enum gnu_v3_ctor_kinds ctor_kind
;
6499 enum gnu_v3_dtor_kinds dtor_kind
;
6501 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6502 return (enum gnu_v3_ctor_kinds
) 0;
6507 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6508 name. A non-zero return indicates the type of destructor. */
6510 enum gnu_v3_dtor_kinds
6511 is_gnu_v3_mangled_dtor (const char *name
)
6513 enum gnu_v3_ctor_kinds ctor_kind
;
6514 enum gnu_v3_dtor_kinds dtor_kind
;
6516 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6517 return (enum gnu_v3_dtor_kinds
) 0;
6521 #endif /* IN_GLIBCPP_V3 */
6523 #ifdef STANDALONE_DEMANGLER
6526 #include "dyn-string.h"
6528 static void print_usage (FILE* fp
, int exit_value
);
6530 #define IS_ALPHA(CHAR) \
6531 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6532 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6534 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6535 #define is_mangled_char(CHAR) \
6536 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6537 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6539 /* The name of this program, as invoked. */
6540 const char* program_name
;
6542 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6545 print_usage (FILE* fp
, int exit_value
)
6547 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6548 fprintf (fp
, "Options:\n");
6549 fprintf (fp
, " -h,--help Display this message.\n");
6550 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6551 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6552 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6557 /* Option specification for getopt_long. */
6558 static const struct option long_options
[] =
6560 { "help", no_argument
, NULL
, 'h' },
6561 { "no-params", no_argument
, NULL
, 'p' },
6562 { "verbose", no_argument
, NULL
, 'v' },
6563 { NULL
, no_argument
, NULL
, 0 },
6566 /* Main entry for a demangling filter executable. It will demangle
6567 its command line arguments, if any. If none are provided, it will
6568 filter stdin to stdout, replacing any recognized mangled C++ names
6569 with their demangled equivalents. */
6572 main (int argc
, char *argv
[])
6576 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6578 /* Use the program name of this program, as invoked. */
6579 program_name
= argv
[0];
6581 /* Parse options. */
6584 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6587 case '?': /* Unrecognized option. */
6588 print_usage (stderr
, 1);
6592 print_usage (stdout
, 0);
6596 options
&= ~ DMGL_PARAMS
;
6600 options
|= DMGL_VERBOSE
;
6604 while (opt_char
!= -1);
6607 /* No command line arguments were provided. Filter stdin. */
6609 dyn_string_t mangled
= dyn_string_new (3);
6612 /* Read all of input. */
6613 while (!feof (stdin
))
6617 /* Pile characters into mangled until we hit one that can't
6618 occur in a mangled name. */
6620 while (!feof (stdin
) && is_mangled_char (c
))
6622 dyn_string_append_char (mangled
, c
);
6628 if (dyn_string_length (mangled
) > 0)
6630 #ifdef IN_GLIBCPP_V3
6631 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6633 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6643 /* It might not have been a mangled name. Print the
6645 fputs (dyn_string_buf (mangled
), stdout
);
6648 dyn_string_clear (mangled
);
6651 /* If we haven't hit EOF yet, we've read one character that
6652 can't occur in a mangled name, so print it out. */
6657 dyn_string_delete (mangled
);
6660 /* Demangle command line arguments. */
6662 /* Loop over command line arguments. */
6663 for (i
= optind
; i
< argc
; ++i
)
6666 #ifdef IN_GLIBCPP_V3
6670 /* Attempt to demangle. */
6671 #ifdef IN_GLIBCPP_V3
6672 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6674 s
= cplus_demangle_v3 (argv
[i
], options
);
6677 /* If it worked, print the demangled name. */
6685 #ifdef IN_GLIBCPP_V3
6686 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6688 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6697 #endif /* STANDALONE_DEMANGLER */