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
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 int d_call_offset (struct d_info
*, int);
441 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
443 static struct demangle_component
**
444 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
446 static struct demangle_component
*
447 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
449 static struct demangle_component
*
450 d_function_type (struct d_info
*);
452 static struct demangle_component
*
453 d_bare_function_type (struct d_info
*, int);
455 static struct demangle_component
*
456 d_class_enum_type (struct d_info
*);
458 static struct demangle_component
*d_array_type (struct d_info
*);
460 static struct demangle_component
*d_vector_type (struct d_info
*);
462 static struct demangle_component
*
463 d_pointer_to_member_type (struct d_info
*);
465 static struct demangle_component
*
466 d_template_param (struct d_info
*);
468 static struct demangle_component
*d_template_args (struct d_info
*);
470 static struct demangle_component
*
471 d_template_arg (struct d_info
*);
473 static struct demangle_component
*d_expression (struct d_info
*);
475 static struct demangle_component
*d_expr_primary (struct d_info
*);
477 static struct demangle_component
*d_local_name (struct d_info
*);
479 static int d_discriminator (struct d_info
*);
481 static struct demangle_component
*d_lambda (struct d_info
*);
483 static struct demangle_component
*d_unnamed_type (struct d_info
*);
485 static struct demangle_component
*
486 d_clone_suffix (struct d_info
*, struct demangle_component
*);
489 d_add_substitution (struct d_info
*, struct demangle_component
*);
491 static struct demangle_component
*d_substitution (struct d_info
*, int);
493 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
495 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
497 static void d_growable_string_init (struct d_growable_string
*, size_t);
500 d_growable_string_resize (struct d_growable_string
*, size_t);
503 d_growable_string_append_buffer (struct d_growable_string
*,
504 const char *, size_t);
506 d_growable_string_callback_adapter (const char *, size_t, void *);
509 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
510 const struct demangle_component
*);
512 static inline void d_print_error (struct d_print_info
*);
514 static inline int d_print_saw_error (struct d_print_info
*);
516 static inline void d_print_flush (struct d_print_info
*);
518 static inline void d_append_char (struct d_print_info
*, char);
520 static inline void d_append_buffer (struct d_print_info
*,
521 const char *, size_t);
523 static inline void d_append_string (struct d_print_info
*, const char *);
525 static inline char d_last_char (struct d_print_info
*);
528 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
531 d_print_java_identifier (struct d_print_info
*, const char *, int);
534 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
537 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
540 d_print_function_type (struct d_print_info
*, int,
541 const struct demangle_component
*,
542 struct d_print_mod
*);
545 d_print_array_type (struct d_print_info
*, int,
546 const struct demangle_component
*,
547 struct d_print_mod
*);
550 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
552 static void d_print_cast (struct d_print_info
*, int,
553 const struct demangle_component
*);
554 static void d_print_conversion (struct d_print_info
*, int,
555 const struct demangle_component
*);
557 static int d_demangle_callback (const char *, int,
558 demangle_callbackref
, void *);
559 static char *d_demangle (const char *, int, size_t *);
561 #ifdef CP_DEMANGLE_DEBUG
564 d_dump (struct demangle_component
*dc
, int indent
)
571 printf ("failed demangling\n");
575 for (i
= 0; i
< indent
; ++i
)
580 case DEMANGLE_COMPONENT_NAME
:
581 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
583 case DEMANGLE_COMPONENT_TAGGED_NAME
:
584 printf ("tagged name\n");
585 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
586 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
588 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
589 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
591 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
592 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
594 case DEMANGLE_COMPONENT_CTOR
:
595 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
596 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
598 case DEMANGLE_COMPONENT_DTOR
:
599 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
600 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
602 case DEMANGLE_COMPONENT_SUB_STD
:
603 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
605 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
606 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
608 case DEMANGLE_COMPONENT_OPERATOR
:
609 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
611 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
612 printf ("extended operator with %d args\n",
613 dc
->u
.s_extended_operator
.args
);
614 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
617 case DEMANGLE_COMPONENT_QUAL_NAME
:
618 printf ("qualified name\n");
620 case DEMANGLE_COMPONENT_LOCAL_NAME
:
621 printf ("local name\n");
623 case DEMANGLE_COMPONENT_TYPED_NAME
:
624 printf ("typed name\n");
626 case DEMANGLE_COMPONENT_TEMPLATE
:
627 printf ("template\n");
629 case DEMANGLE_COMPONENT_VTABLE
:
632 case DEMANGLE_COMPONENT_VTT
:
635 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
636 printf ("construction vtable\n");
638 case DEMANGLE_COMPONENT_TYPEINFO
:
639 printf ("typeinfo\n");
641 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
642 printf ("typeinfo name\n");
644 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
645 printf ("typeinfo function\n");
647 case DEMANGLE_COMPONENT_THUNK
:
650 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
651 printf ("virtual thunk\n");
653 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
654 printf ("covariant thunk\n");
656 case DEMANGLE_COMPONENT_JAVA_CLASS
:
657 printf ("java class\n");
659 case DEMANGLE_COMPONENT_GUARD
:
662 case DEMANGLE_COMPONENT_REFTEMP
:
663 printf ("reference temporary\n");
665 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
666 printf ("hidden alias\n");
668 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
669 printf ("transaction clone\n");
671 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
672 printf ("non-transaction clone\n");
674 case DEMANGLE_COMPONENT_RESTRICT
:
675 printf ("restrict\n");
677 case DEMANGLE_COMPONENT_VOLATILE
:
678 printf ("volatile\n");
680 case DEMANGLE_COMPONENT_CONST
:
683 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
684 printf ("restrict this\n");
686 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
687 printf ("volatile this\n");
689 case DEMANGLE_COMPONENT_CONST_THIS
:
690 printf ("const this\n");
692 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
693 printf ("reference this\n");
695 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
696 printf ("rvalue reference this\n");
698 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
699 printf ("transaction_safe this\n");
701 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
702 printf ("vendor type qualifier\n");
704 case DEMANGLE_COMPONENT_POINTER
:
705 printf ("pointer\n");
707 case DEMANGLE_COMPONENT_REFERENCE
:
708 printf ("reference\n");
710 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
711 printf ("rvalue reference\n");
713 case DEMANGLE_COMPONENT_COMPLEX
:
714 printf ("complex\n");
716 case DEMANGLE_COMPONENT_IMAGINARY
:
717 printf ("imaginary\n");
719 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
720 printf ("vendor type\n");
722 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
723 printf ("function type\n");
725 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
726 printf ("array type\n");
728 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
729 printf ("pointer to member type\n");
731 case DEMANGLE_COMPONENT_FIXED_TYPE
:
732 printf ("fixed-point type, accum? %d, sat? %d\n",
733 dc
->u
.s_fixed
.accum
, dc
->u
.s_fixed
.sat
);
734 d_dump (dc
->u
.s_fixed
.length
, indent
+ 2);
736 case DEMANGLE_COMPONENT_ARGLIST
:
737 printf ("argument list\n");
739 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
740 printf ("template argument list\n");
742 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
743 printf ("initializer list\n");
745 case DEMANGLE_COMPONENT_CAST
:
748 case DEMANGLE_COMPONENT_CONVERSION
:
749 printf ("conversion operator\n");
751 case DEMANGLE_COMPONENT_NULLARY
:
752 printf ("nullary operator\n");
754 case DEMANGLE_COMPONENT_UNARY
:
755 printf ("unary operator\n");
757 case DEMANGLE_COMPONENT_BINARY
:
758 printf ("binary operator\n");
760 case DEMANGLE_COMPONENT_BINARY_ARGS
:
761 printf ("binary operator arguments\n");
763 case DEMANGLE_COMPONENT_TRINARY
:
764 printf ("trinary operator\n");
766 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
767 printf ("trinary operator arguments 1\n");
769 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
770 printf ("trinary operator arguments 1\n");
772 case DEMANGLE_COMPONENT_LITERAL
:
773 printf ("literal\n");
775 case DEMANGLE_COMPONENT_LITERAL_NEG
:
776 printf ("negative literal\n");
778 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
779 printf ("java resource\n");
781 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
782 printf ("compound name\n");
784 case DEMANGLE_COMPONENT_CHARACTER
:
785 printf ("character '%c'\n", dc
->u
.s_character
.character
);
787 case DEMANGLE_COMPONENT_NUMBER
:
788 printf ("number %ld\n", dc
->u
.s_number
.number
);
790 case DEMANGLE_COMPONENT_DECLTYPE
:
791 printf ("decltype\n");
793 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
794 printf ("pack expansion\n");
796 case DEMANGLE_COMPONENT_TLS_INIT
:
797 printf ("tls init function\n");
799 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
800 printf ("tls wrapper function\n");
802 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
803 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
804 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
806 case DEMANGLE_COMPONENT_LAMBDA
:
807 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
808 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
812 d_dump (d_left (dc
), indent
+ 2);
813 d_dump (d_right (dc
), indent
+ 2);
816 #endif /* CP_DEMANGLE_DEBUG */
818 /* Fill in a DEMANGLE_COMPONENT_NAME. */
820 CP_STATIC_IF_GLIBCPP_V3
822 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
824 if (p
== NULL
|| s
== NULL
|| len
== 0)
826 p
->type
= DEMANGLE_COMPONENT_NAME
;
828 p
->u
.s_name
.len
= len
;
832 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
834 CP_STATIC_IF_GLIBCPP_V3
836 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
837 struct demangle_component
*name
)
839 if (p
== NULL
|| args
< 0 || name
== NULL
)
841 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
842 p
->u
.s_extended_operator
.args
= args
;
843 p
->u
.s_extended_operator
.name
= name
;
847 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
849 CP_STATIC_IF_GLIBCPP_V3
851 cplus_demangle_fill_ctor (struct demangle_component
*p
,
852 enum gnu_v3_ctor_kinds kind
,
853 struct demangle_component
*name
)
857 || (int) kind
< gnu_v3_complete_object_ctor
858 || (int) kind
> gnu_v3_object_ctor_group
)
860 p
->type
= DEMANGLE_COMPONENT_CTOR
;
861 p
->u
.s_ctor
.kind
= kind
;
862 p
->u
.s_ctor
.name
= name
;
866 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
868 CP_STATIC_IF_GLIBCPP_V3
870 cplus_demangle_fill_dtor (struct demangle_component
*p
,
871 enum gnu_v3_dtor_kinds kind
,
872 struct demangle_component
*name
)
876 || (int) kind
< gnu_v3_deleting_dtor
877 || (int) kind
> gnu_v3_object_dtor_group
)
879 p
->type
= DEMANGLE_COMPONENT_DTOR
;
880 p
->u
.s_dtor
.kind
= kind
;
881 p
->u
.s_dtor
.name
= name
;
885 /* Add a new component. */
887 static struct demangle_component
*
888 d_make_empty (struct d_info
*di
)
890 struct demangle_component
*p
;
892 if (di
->next_comp
>= di
->num_comps
)
894 p
= &di
->comps
[di
->next_comp
];
899 /* Add a new generic component. */
901 static struct demangle_component
*
902 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
903 struct demangle_component
*left
,
904 struct demangle_component
*right
)
906 struct demangle_component
*p
;
908 /* We check for errors here. A typical error would be a NULL return
909 from a subroutine. We catch those here, and return NULL
913 /* These types require two parameters. */
914 case DEMANGLE_COMPONENT_QUAL_NAME
:
915 case DEMANGLE_COMPONENT_LOCAL_NAME
:
916 case DEMANGLE_COMPONENT_TYPED_NAME
:
917 case DEMANGLE_COMPONENT_TAGGED_NAME
:
918 case DEMANGLE_COMPONENT_TEMPLATE
:
919 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
920 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
921 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
922 case DEMANGLE_COMPONENT_UNARY
:
923 case DEMANGLE_COMPONENT_BINARY
:
924 case DEMANGLE_COMPONENT_BINARY_ARGS
:
925 case DEMANGLE_COMPONENT_TRINARY
:
926 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
927 case DEMANGLE_COMPONENT_LITERAL
:
928 case DEMANGLE_COMPONENT_LITERAL_NEG
:
929 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
930 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
931 case DEMANGLE_COMPONENT_CLONE
:
932 if (left
== NULL
|| right
== NULL
)
936 /* These types only require one parameter. */
937 case DEMANGLE_COMPONENT_VTABLE
:
938 case DEMANGLE_COMPONENT_VTT
:
939 case DEMANGLE_COMPONENT_TYPEINFO
:
940 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
941 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
942 case DEMANGLE_COMPONENT_THUNK
:
943 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
944 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
945 case DEMANGLE_COMPONENT_JAVA_CLASS
:
946 case DEMANGLE_COMPONENT_GUARD
:
947 case DEMANGLE_COMPONENT_TLS_INIT
:
948 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
949 case DEMANGLE_COMPONENT_REFTEMP
:
950 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
951 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
952 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
953 case DEMANGLE_COMPONENT_POINTER
:
954 case DEMANGLE_COMPONENT_REFERENCE
:
955 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
956 case DEMANGLE_COMPONENT_COMPLEX
:
957 case DEMANGLE_COMPONENT_IMAGINARY
:
958 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
959 case DEMANGLE_COMPONENT_CAST
:
960 case DEMANGLE_COMPONENT_CONVERSION
:
961 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
962 case DEMANGLE_COMPONENT_DECLTYPE
:
963 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
964 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
965 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
966 case DEMANGLE_COMPONENT_NULLARY
:
967 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
972 /* This needs a right parameter, but the left parameter can be
974 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
975 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
980 /* These are allowed to have no parameters--in some cases they
981 will be filled in later. */
982 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
983 case DEMANGLE_COMPONENT_RESTRICT
:
984 case DEMANGLE_COMPONENT_VOLATILE
:
985 case DEMANGLE_COMPONENT_CONST
:
986 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
987 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
988 case DEMANGLE_COMPONENT_CONST_THIS
:
989 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
990 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
991 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
992 case DEMANGLE_COMPONENT_ARGLIST
:
993 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
996 /* Other types should not be seen here. */
1001 p
= d_make_empty (di
);
1005 p
->u
.s_binary
.left
= left
;
1006 p
->u
.s_binary
.right
= right
;
1011 /* Add a new demangle mangled name component. */
1013 static struct demangle_component
*
1014 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
1016 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1017 return d_make_name (di
, s
, strlen (s
));
1019 return d_encoding (di
, 0);
1022 /* Add a new name component. */
1024 static struct demangle_component
*
1025 d_make_name (struct d_info
*di
, const char *s
, int len
)
1027 struct demangle_component
*p
;
1029 p
= d_make_empty (di
);
1030 if (! cplus_demangle_fill_name (p
, s
, len
))
1035 /* Add a new builtin type component. */
1037 static struct demangle_component
*
1038 d_make_builtin_type (struct d_info
*di
,
1039 const struct demangle_builtin_type_info
*type
)
1041 struct demangle_component
*p
;
1045 p
= d_make_empty (di
);
1048 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1049 p
->u
.s_builtin
.type
= type
;
1054 /* Add a new operator component. */
1056 static struct demangle_component
*
1057 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1059 struct demangle_component
*p
;
1061 p
= d_make_empty (di
);
1064 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1065 p
->u
.s_operator
.op
= op
;
1070 /* Add a new extended operator component. */
1072 static struct demangle_component
*
1073 d_make_extended_operator (struct d_info
*di
, int args
,
1074 struct demangle_component
*name
)
1076 struct demangle_component
*p
;
1078 p
= d_make_empty (di
);
1079 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1084 static struct demangle_component
*
1085 d_make_default_arg (struct d_info
*di
, int num
,
1086 struct demangle_component
*sub
)
1088 struct demangle_component
*p
= d_make_empty (di
);
1091 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1092 p
->u
.s_unary_num
.num
= num
;
1093 p
->u
.s_unary_num
.sub
= sub
;
1098 /* Add a new constructor component. */
1100 static struct demangle_component
*
1101 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1102 struct demangle_component
*name
)
1104 struct demangle_component
*p
;
1106 p
= d_make_empty (di
);
1107 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1112 /* Add a new destructor component. */
1114 static struct demangle_component
*
1115 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1116 struct demangle_component
*name
)
1118 struct demangle_component
*p
;
1120 p
= d_make_empty (di
);
1121 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1126 /* Add a new template parameter. */
1128 static struct demangle_component
*
1129 d_make_template_param (struct d_info
*di
, int i
)
1131 struct demangle_component
*p
;
1133 p
= d_make_empty (di
);
1136 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1137 p
->u
.s_number
.number
= i
;
1142 /* Add a new function parameter. */
1144 static struct demangle_component
*
1145 d_make_function_param (struct d_info
*di
, int i
)
1147 struct demangle_component
*p
;
1149 p
= d_make_empty (di
);
1152 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1153 p
->u
.s_number
.number
= i
;
1158 /* Add a new standard substitution component. */
1160 static struct demangle_component
*
1161 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1163 struct demangle_component
*p
;
1165 p
= d_make_empty (di
);
1168 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1169 p
->u
.s_string
.string
= name
;
1170 p
->u
.s_string
.len
= len
;
1175 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1177 TOP_LEVEL is non-zero when called at the top level. */
1179 CP_STATIC_IF_GLIBCPP_V3
1180 struct demangle_component
*
1181 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1183 struct demangle_component
*p
;
1185 if (! d_check_char (di
, '_')
1186 /* Allow missing _ if not at toplevel to work around a
1187 bug in G++ abi-version=2 mangling; see the comment in
1188 write_template_arg. */
1191 if (! d_check_char (di
, 'Z'))
1193 p
= d_encoding (di
, top_level
);
1195 /* If at top level and parsing parameters, check for a clone
1197 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1198 while (d_peek_char (di
) == '.'
1199 && (IS_LOWER (d_peek_next_char (di
))
1200 || d_peek_next_char (di
) == '_'
1201 || IS_DIGIT (d_peek_next_char (di
))))
1202 p
= d_clone_suffix (di
, p
);
1207 /* Return whether a function should have a return type. The argument
1208 is the function name, which may be qualified in various ways. The
1209 rules are that template functions have return types with some
1210 exceptions, function types which are not part of a function name
1211 mangling have return types with some exceptions, and non-template
1212 function names do not have return types. The exceptions are that
1213 constructors, destructors, and conversion operators do not have
1217 has_return_type (struct demangle_component
*dc
)
1225 case DEMANGLE_COMPONENT_TEMPLATE
:
1226 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1227 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1228 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1229 case DEMANGLE_COMPONENT_CONST_THIS
:
1230 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1231 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1232 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
1233 return has_return_type (d_left (dc
));
1237 /* Return whether a name is a constructor, a destructor, or a
1238 conversion operator. */
1241 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1249 case DEMANGLE_COMPONENT_QUAL_NAME
:
1250 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1251 return is_ctor_dtor_or_conversion (d_right (dc
));
1252 case DEMANGLE_COMPONENT_CTOR
:
1253 case DEMANGLE_COMPONENT_DTOR
:
1254 case DEMANGLE_COMPONENT_CONVERSION
:
1259 /* <encoding> ::= <(function) name> <bare-function-type>
1263 TOP_LEVEL is non-zero when called at the top level, in which case
1264 if DMGL_PARAMS is not set we do not demangle the function
1265 parameters. We only set this at the top level, because otherwise
1266 we would not correctly demangle names in local scopes. */
1268 static struct demangle_component
*
1269 d_encoding (struct d_info
*di
, int top_level
)
1271 char peek
= d_peek_char (di
);
1273 if (peek
== 'G' || peek
== 'T')
1274 return d_special_name (di
);
1277 struct demangle_component
*dc
;
1281 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1283 /* Strip off any initial CV-qualifiers, as they really apply
1284 to the `this' parameter, and they were not output by the
1285 v2 demangler without DMGL_PARAMS. */
1286 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1287 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1288 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1289 || dc
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
1290 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1291 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1294 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1295 there may be CV-qualifiers on its right argument which
1296 really apply here; this happens when parsing a class
1297 which is local to a function. */
1298 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1300 struct demangle_component
*dcr
;
1303 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1304 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1305 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1306 || dcr
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
1307 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1308 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1310 dc
->u
.s_binary
.right
= dcr
;
1316 peek
= d_peek_char (di
);
1317 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1319 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1320 d_bare_function_type (di
, has_return_type (dc
)));
1324 /* <tagged-name> ::= <name> B <source-name> */
1326 static struct demangle_component
*
1327 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1329 struct demangle_component
*hold_last_name
;
1332 /* Preserve the last name, so the ABI tag doesn't clobber it. */
1333 hold_last_name
= di
->last_name
;
1335 while (peek
= d_peek_char (di
),
1338 struct demangle_component
*tag
;
1340 tag
= d_source_name (di
);
1341 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1344 di
->last_name
= hold_last_name
;
1349 /* <name> ::= <nested-name>
1351 ::= <unscoped-template-name> <template-args>
1354 <unscoped-name> ::= <unqualified-name>
1355 ::= St <unqualified-name>
1357 <unscoped-template-name> ::= <unscoped-name>
1361 static struct demangle_component
*
1362 d_name (struct d_info
*di
)
1364 char peek
= d_peek_char (di
);
1365 struct demangle_component
*dc
;
1370 return d_nested_name (di
);
1373 return d_local_name (di
);
1376 return d_unqualified_name (di
);
1382 if (d_peek_next_char (di
) != 't')
1384 dc
= d_substitution (di
, 0);
1390 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1391 d_make_name (di
, "std", 3),
1392 d_unqualified_name (di
));
1397 if (d_peek_char (di
) != 'I')
1399 /* The grammar does not permit this case to occur if we
1400 called d_substitution() above (i.e., subst == 1). We
1401 don't bother to check. */
1405 /* This is <template-args>, which means that we just saw
1406 <unscoped-template-name>, which is a substitution
1407 candidate if we didn't just get it from a
1411 if (! d_add_substitution (di
, dc
))
1414 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1415 d_template_args (di
));
1423 dc
= d_unqualified_name (di
);
1424 if (d_peek_char (di
) == 'I')
1426 /* This is <template-args>, which means that we just saw
1427 <unscoped-template-name>, which is a substitution
1429 if (! d_add_substitution (di
, dc
))
1431 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1432 d_template_args (di
));
1438 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1439 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1442 static struct demangle_component
*
1443 d_nested_name (struct d_info
*di
)
1445 struct demangle_component
*ret
;
1446 struct demangle_component
**pret
;
1447 struct demangle_component
*rqual
;
1449 if (! d_check_char (di
, 'N'))
1452 pret
= d_cv_qualifiers (di
, &ret
, 1);
1456 /* Parse the ref-qualifier now and then attach it
1457 once we have something to attach it to. */
1458 rqual
= d_ref_qualifier (di
, NULL
);
1460 *pret
= d_prefix (di
);
1466 d_left (rqual
) = ret
;
1470 if (! d_check_char (di
, 'E'))
1476 /* <prefix> ::= <prefix> <unqualified-name>
1477 ::= <template-prefix> <template-args>
1478 ::= <template-param>
1483 <template-prefix> ::= <prefix> <(template) unqualified-name>
1484 ::= <template-param>
1488 static struct demangle_component
*
1489 d_prefix (struct d_info
*di
)
1491 struct demangle_component
*ret
= NULL
;
1496 enum demangle_component_type comb_type
;
1497 struct demangle_component
*dc
;
1499 peek
= d_peek_char (di
);
1503 /* The older code accepts a <local-name> here, but I don't see
1504 that in the grammar. The older code does not accept a
1505 <template-param> here. */
1507 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1510 char peek2
= d_peek_next_char (di
);
1511 if (peek2
== 'T' || peek2
== 't')
1513 dc
= cplus_demangle_type (di
);
1515 /* Destructor name. */
1516 dc
= d_unqualified_name (di
);
1518 else if (IS_DIGIT (peek
)
1523 dc
= d_unqualified_name (di
);
1524 else if (peek
== 'S')
1525 dc
= d_substitution (di
, 1);
1526 else if (peek
== 'I')
1530 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1531 dc
= d_template_args (di
);
1533 else if (peek
== 'T')
1534 dc
= d_template_param (di
);
1535 else if (peek
== 'E')
1537 else if (peek
== 'M')
1539 /* Initializer scope for a lambda. We don't need to represent
1540 this; the normal code will just treat the variable as a type
1541 scope, which gives appropriate output. */
1553 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1555 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1557 if (! d_add_substitution (di
, ret
))
1563 /* <unqualified-name> ::= <operator-name>
1564 ::= <ctor-dtor-name>
1566 ::= <local-source-name>
1568 <local-source-name> ::= L <source-name> <discriminator>
1571 static struct demangle_component
*
1572 d_unqualified_name (struct d_info
*di
)
1574 struct demangle_component
*ret
;
1577 peek
= d_peek_char (di
);
1578 if (IS_DIGIT (peek
))
1579 ret
= d_source_name (di
);
1580 else if (IS_LOWER (peek
))
1582 ret
= d_operator_name (di
);
1583 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1585 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1586 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1587 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1588 d_source_name (di
));
1591 else if (peek
== 'C' || peek
== 'D')
1592 ret
= d_ctor_dtor_name (di
);
1593 else if (peek
== 'L')
1597 ret
= d_source_name (di
);
1600 if (! d_discriminator (di
))
1603 else if (peek
== 'U')
1605 switch (d_peek_next_char (di
))
1608 ret
= d_lambda (di
);
1611 ret
= d_unnamed_type (di
);
1620 if (d_peek_char (di
) == 'B')
1621 ret
= d_abi_tags (di
, ret
);
1625 /* <source-name> ::= <(positive length) number> <identifier> */
1627 static struct demangle_component
*
1628 d_source_name (struct d_info
*di
)
1631 struct demangle_component
*ret
;
1633 len
= d_number (di
);
1636 ret
= d_identifier (di
, len
);
1637 di
->last_name
= ret
;
1641 /* number ::= [n] <(non-negative decimal integer)> */
1644 d_number (struct d_info
*di
)
1651 peek
= d_peek_char (di
);
1656 peek
= d_peek_char (di
);
1662 if (! IS_DIGIT (peek
))
1668 ret
= ret
* 10 + peek
- '0';
1670 peek
= d_peek_char (di
);
1674 /* Like d_number, but returns a demangle_component. */
1676 static struct demangle_component
*
1677 d_number_component (struct d_info
*di
)
1679 struct demangle_component
*ret
= d_make_empty (di
);
1682 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1683 ret
->u
.s_number
.number
= d_number (di
);
1688 /* identifier ::= <(unqualified source code identifier)> */
1690 static struct demangle_component
*
1691 d_identifier (struct d_info
*di
, int len
)
1697 if (di
->send
- name
< len
)
1700 d_advance (di
, len
);
1702 /* A Java mangled name may have a trailing '$' if it is a C++
1703 keyword. This '$' is not included in the length count. We just
1705 if ((di
->options
& DMGL_JAVA
) != 0
1706 && d_peek_char (di
) == '$')
1709 /* Look for something which looks like a gcc encoding of an
1710 anonymous namespace, and replace it with a more user friendly
1712 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1713 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1714 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1718 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1719 if ((*s
== '.' || *s
== '_' || *s
== '$')
1722 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1723 return d_make_name (di
, "(anonymous namespace)",
1724 sizeof "(anonymous namespace)" - 1);
1728 return d_make_name (di
, name
, len
);
1731 /* operator_name ::= many different two character encodings.
1733 ::= v <digit> <source-name>
1735 This list is sorted for binary search. */
1737 #define NL(s) s, (sizeof s) - 1
1739 CP_STATIC_IF_GLIBCPP_V3
1740 const struct demangle_operator_info cplus_demangle_operators
[] =
1742 { "aN", NL ("&="), 2 },
1743 { "aS", NL ("="), 2 },
1744 { "aa", NL ("&&"), 2 },
1745 { "ad", NL ("&"), 1 },
1746 { "an", NL ("&"), 2 },
1747 { "at", NL ("alignof "), 1 },
1748 { "az", NL ("alignof "), 1 },
1749 { "cc", NL ("const_cast"), 2 },
1750 { "cl", NL ("()"), 2 },
1751 { "cm", NL (","), 2 },
1752 { "co", NL ("~"), 1 },
1753 { "dV", NL ("/="), 2 },
1754 { "da", NL ("delete[] "), 1 },
1755 { "dc", NL ("dynamic_cast"), 2 },
1756 { "de", NL ("*"), 1 },
1757 { "dl", NL ("delete "), 1 },
1758 { "ds", NL (".*"), 2 },
1759 { "dt", NL ("."), 2 },
1760 { "dv", NL ("/"), 2 },
1761 { "eO", NL ("^="), 2 },
1762 { "eo", NL ("^"), 2 },
1763 { "eq", NL ("=="), 2 },
1764 { "ge", NL (">="), 2 },
1765 { "gs", NL ("::"), 1 },
1766 { "gt", NL (">"), 2 },
1767 { "ix", NL ("[]"), 2 },
1768 { "lS", NL ("<<="), 2 },
1769 { "le", NL ("<="), 2 },
1770 { "li", NL ("operator\"\" "), 1 },
1771 { "ls", NL ("<<"), 2 },
1772 { "lt", NL ("<"), 2 },
1773 { "mI", NL ("-="), 2 },
1774 { "mL", NL ("*="), 2 },
1775 { "mi", NL ("-"), 2 },
1776 { "ml", NL ("*"), 2 },
1777 { "mm", NL ("--"), 1 },
1778 { "na", NL ("new[]"), 3 },
1779 { "ne", NL ("!="), 2 },
1780 { "ng", NL ("-"), 1 },
1781 { "nt", NL ("!"), 1 },
1782 { "nw", NL ("new"), 3 },
1783 { "oR", NL ("|="), 2 },
1784 { "oo", NL ("||"), 2 },
1785 { "or", NL ("|"), 2 },
1786 { "pL", NL ("+="), 2 },
1787 { "pl", NL ("+"), 2 },
1788 { "pm", NL ("->*"), 2 },
1789 { "pp", NL ("++"), 1 },
1790 { "ps", NL ("+"), 1 },
1791 { "pt", NL ("->"), 2 },
1792 { "qu", NL ("?"), 3 },
1793 { "rM", NL ("%="), 2 },
1794 { "rS", NL (">>="), 2 },
1795 { "rc", NL ("reinterpret_cast"), 2 },
1796 { "rm", NL ("%"), 2 },
1797 { "rs", NL (">>"), 2 },
1798 { "sc", NL ("static_cast"), 2 },
1799 { "st", NL ("sizeof "), 1 },
1800 { "sz", NL ("sizeof "), 1 },
1801 { "tr", NL ("throw"), 0 },
1802 { "tw", NL ("throw "), 1 },
1803 { NULL
, NULL
, 0, 0 }
1806 static struct demangle_component
*
1807 d_operator_name (struct d_info
*di
)
1812 c1
= d_next_char (di
);
1813 c2
= d_next_char (di
);
1814 if (c1
== 'v' && IS_DIGIT (c2
))
1815 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1816 else if (c1
== 'c' && c2
== 'v')
1818 struct demangle_component
*type
;
1819 int was_conversion
= di
->is_conversion
;
1820 struct demangle_component
*res
;
1822 di
->is_conversion
= ! di
->is_expression
;
1823 type
= cplus_demangle_type (di
);
1824 if (di
->is_conversion
)
1825 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
1827 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1828 di
->is_conversion
= was_conversion
;
1833 /* LOW is the inclusive lower bound. */
1835 /* HIGH is the exclusive upper bound. We subtract one to ignore
1836 the sentinel at the end of the array. */
1837 int high
= ((sizeof (cplus_demangle_operators
)
1838 / sizeof (cplus_demangle_operators
[0]))
1844 const struct demangle_operator_info
*p
;
1846 i
= low
+ (high
- low
) / 2;
1847 p
= cplus_demangle_operators
+ i
;
1849 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1850 return d_make_operator (di
, p
);
1852 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1862 static struct demangle_component
*
1863 d_make_character (struct d_info
*di
, int c
)
1865 struct demangle_component
*p
;
1866 p
= d_make_empty (di
);
1869 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1870 p
->u
.s_character
.character
= c
;
1875 static struct demangle_component
*
1876 d_java_resource (struct d_info
*di
)
1878 struct demangle_component
*p
= NULL
;
1879 struct demangle_component
*next
= NULL
;
1884 len
= d_number (di
);
1888 /* Eat the leading '_'. */
1889 if (d_next_char (di
) != '_')
1902 /* Each chunk is either a '$' escape... */
1920 next
= d_make_character (di
, c
);
1928 /* ... or a sequence of characters. */
1931 while (i
< len
&& str
[i
] && str
[i
] != '$')
1934 next
= d_make_name (di
, str
, i
);
1947 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1953 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1958 /* <special-name> ::= TV <type>
1962 ::= GV <(object) name>
1963 ::= T <call-offset> <(base) encoding>
1964 ::= Tc <call-offset> <call-offset> <(base) encoding>
1965 Also g++ extensions:
1966 ::= TC <type> <(offset) number> _ <(base) type>
1971 ::= Gr <resource name>
1976 static struct demangle_component
*
1977 d_special_name (struct d_info
*di
)
1979 di
->expansion
+= 20;
1980 if (d_check_char (di
, 'T'))
1982 switch (d_next_char (di
))
1986 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1987 cplus_demangle_type (di
), NULL
);
1989 di
->expansion
-= 10;
1990 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1991 cplus_demangle_type (di
), NULL
);
1993 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1994 cplus_demangle_type (di
), NULL
);
1996 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1997 cplus_demangle_type (di
), NULL
);
2000 if (! d_call_offset (di
, 'h'))
2002 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
2003 d_encoding (di
, 0), NULL
);
2006 if (! d_call_offset (di
, 'v'))
2008 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
2009 d_encoding (di
, 0), NULL
);
2012 if (! d_call_offset (di
, '\0'))
2014 if (! d_call_offset (di
, '\0'))
2016 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
2017 d_encoding (di
, 0), NULL
);
2021 struct demangle_component
*derived_type
;
2023 struct demangle_component
*base_type
;
2025 derived_type
= cplus_demangle_type (di
);
2026 offset
= d_number (di
);
2029 if (! d_check_char (di
, '_'))
2031 base_type
= cplus_demangle_type (di
);
2032 /* We don't display the offset. FIXME: We should display
2033 it in verbose mode. */
2035 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2036 base_type
, derived_type
);
2040 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2041 cplus_demangle_type (di
), NULL
);
2043 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2044 cplus_demangle_type (di
), NULL
);
2047 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2051 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2058 else if (d_check_char (di
, 'G'))
2060 switch (d_next_char (di
))
2063 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2067 struct demangle_component
*name
= d_name (di
);
2068 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2069 d_number_component (di
));
2073 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2074 d_encoding (di
, 0), NULL
);
2077 switch (d_next_char (di
))
2080 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2081 d_encoding (di
, 0), NULL
);
2083 /* ??? The proposal is that other letters (such as 'h') stand
2084 for different variants of transaction cloning, such as
2085 compiling directly for hardware transaction support. But
2086 they still should all be transactional clones of some sort
2087 so go ahead and call them that. */
2089 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2090 d_encoding (di
, 0), NULL
);
2094 return d_java_resource (di
);
2104 /* <call-offset> ::= h <nv-offset> _
2107 <nv-offset> ::= <(offset) number>
2109 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2111 The C parameter, if not '\0', is a character we just read which is
2112 the start of the <call-offset>.
2114 We don't display the offset information anywhere. FIXME: We should
2115 display it in verbose mode. */
2118 d_call_offset (struct d_info
*di
, int c
)
2121 c
= d_next_char (di
);
2128 if (! d_check_char (di
, '_'))
2135 if (! d_check_char (di
, '_'))
2141 /* <ctor-dtor-name> ::= C1
2149 static struct demangle_component
*
2150 d_ctor_dtor_name (struct d_info
*di
)
2152 if (di
->last_name
!= NULL
)
2154 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2155 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2156 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2157 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2159 switch (d_peek_char (di
))
2163 enum gnu_v3_ctor_kinds kind
;
2165 switch (d_peek_next_char (di
))
2168 kind
= gnu_v3_complete_object_ctor
;
2171 kind
= gnu_v3_base_object_ctor
;
2174 kind
= gnu_v3_complete_object_allocating_ctor
;
2177 kind
= gnu_v3_unified_ctor
;
2180 kind
= gnu_v3_object_ctor_group
;
2186 return d_make_ctor (di
, kind
, di
->last_name
);
2191 enum gnu_v3_dtor_kinds kind
;
2193 switch (d_peek_next_char (di
))
2196 kind
= gnu_v3_deleting_dtor
;
2199 kind
= gnu_v3_complete_object_dtor
;
2202 kind
= gnu_v3_base_object_dtor
;
2204 /* digit '3' is not used */
2206 kind
= gnu_v3_unified_dtor
;
2209 kind
= gnu_v3_object_dtor_group
;
2215 return d_make_dtor (di
, kind
, di
->last_name
);
2223 /* <type> ::= <builtin-type>
2225 ::= <class-enum-type>
2227 ::= <pointer-to-member-type>
2228 ::= <template-param>
2229 ::= <template-template-param> <template-args>
2231 ::= <CV-qualifiers> <type>
2234 ::= O <type> (C++0x)
2237 ::= U <source-name> <type>
2239 <builtin-type> ::= various one letter codes
2243 CP_STATIC_IF_GLIBCPP_V3
2244 const struct demangle_builtin_type_info
2245 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2247 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2248 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2249 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2250 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2251 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2252 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2253 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2254 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2255 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2256 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2257 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2258 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2259 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2260 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2261 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2263 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2264 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2265 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2266 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2267 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2268 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2269 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2270 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2271 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2272 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2273 D_PRINT_UNSIGNED_LONG_LONG
},
2274 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2275 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2276 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2277 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2278 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2279 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2280 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2281 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2285 CP_STATIC_IF_GLIBCPP_V3
2286 struct demangle_component
*
2287 cplus_demangle_type (struct d_info
*di
)
2290 struct demangle_component
*ret
;
2293 /* The ABI specifies that when CV-qualifiers are used, the base type
2294 is substitutable, and the fully qualified type is substitutable,
2295 but the base type with a strict subset of the CV-qualifiers is
2296 not substitutable. The natural recursive implementation of the
2297 CV-qualifiers would cause subsets to be substitutable, so instead
2298 we pull them all off now.
2300 FIXME: The ABI says that order-insensitive vendor qualifiers
2301 should be handled in the same way, but we have no way to tell
2302 which vendor qualifiers are order-insensitive and which are
2303 order-sensitive. So we just assume that they are all
2304 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2305 __vector, and it treats it as order-sensitive when mangling
2308 peek
= d_peek_char (di
);
2309 if (peek
== 'r' || peek
== 'V' || peek
== 'K'
2310 || (peek
== 'D' && d_peek_next_char (di
) == 'x'))
2312 struct demangle_component
**pret
;
2314 pret
= d_cv_qualifiers (di
, &ret
, 0);
2317 if (d_peek_char (di
) == 'F')
2319 /* cv-qualifiers before a function type apply to 'this',
2320 so avoid adding the unqualified function type to
2321 the substitution list. */
2322 *pret
= d_function_type (di
);
2325 *pret
= cplus_demangle_type (di
);
2328 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2329 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2331 /* Move the ref-qualifier outside the cv-qualifiers so that
2332 they are printed in the right order. */
2333 struct demangle_component
*fn
= d_left (*pret
);
2334 d_left (*pret
) = ret
;
2338 if (! d_add_substitution (di
, ret
))
2347 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2348 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2349 case 'o': case 's': case 't':
2350 case 'v': case 'w': case 'x': case 'y': case 'z':
2351 ret
= d_make_builtin_type (di
,
2352 &cplus_demangle_builtin_types
[peek
- 'a']);
2353 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2360 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2361 d_source_name (di
), NULL
);
2365 ret
= d_function_type (di
);
2368 case '0': case '1': case '2': case '3': case '4':
2369 case '5': case '6': case '7': case '8': case '9':
2372 ret
= d_class_enum_type (di
);
2376 ret
= d_array_type (di
);
2380 ret
= d_pointer_to_member_type (di
);
2384 ret
= d_template_param (di
);
2385 if (d_peek_char (di
) == 'I')
2387 /* This may be <template-template-param> <template-args>.
2388 If this is the type for a conversion operator, we can
2389 have a <template-template-param> here only by following
2390 a derivation like this:
2393 -> <template-prefix> <template-args>
2394 -> <prefix> <template-unqualified-name> <template-args>
2395 -> <unqualified-name> <template-unqualified-name> <template-args>
2396 -> <source-name> <template-unqualified-name> <template-args>
2397 -> <source-name> <operator-name> <template-args>
2398 -> <source-name> cv <type> <template-args>
2399 -> <source-name> cv <template-template-param> <template-args> <template-args>
2401 where the <template-args> is followed by another.
2402 Otherwise, we must have a derivation like this:
2405 -> <template-prefix> <template-args>
2406 -> <prefix> <template-unqualified-name> <template-args>
2407 -> <unqualified-name> <template-unqualified-name> <template-args>
2408 -> <source-name> <template-unqualified-name> <template-args>
2409 -> <source-name> <operator-name> <template-args>
2410 -> <source-name> cv <type> <template-args>
2411 -> <source-name> cv <template-param> <template-args>
2413 where we need to leave the <template-args> to be processed
2414 by d_prefix (following the <template-prefix>).
2416 The <template-template-param> part is a substitution
2418 if (! di
->is_conversion
)
2420 if (! d_add_substitution (di
, ret
))
2422 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2423 d_template_args (di
));
2427 struct demangle_component
*args
;
2428 struct d_info_checkpoint checkpoint
;
2430 d_checkpoint (di
, &checkpoint
);
2431 args
= d_template_args (di
);
2432 if (d_peek_char (di
) == 'I')
2434 if (! d_add_substitution (di
, ret
))
2436 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2440 d_backtrack (di
, &checkpoint
);
2446 /* If this is a special substitution, then it is the start of
2447 <class-enum-type>. */
2451 peek_next
= d_peek_next_char (di
);
2452 if (IS_DIGIT (peek_next
)
2454 || IS_UPPER (peek_next
))
2456 ret
= d_substitution (di
, 0);
2457 /* The substituted name may have been a template name and
2458 may be followed by tepmlate args. */
2459 if (d_peek_char (di
) == 'I')
2460 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2461 d_template_args (di
));
2467 ret
= d_class_enum_type (di
);
2468 /* If the substitution was a complete type, then it is not
2469 a new substitution candidate. However, if the
2470 substitution was followed by template arguments, then
2471 the whole thing is a substitution candidate. */
2472 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2480 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2481 cplus_demangle_type (di
), NULL
);
2486 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2487 cplus_demangle_type (di
), NULL
);
2492 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2493 cplus_demangle_type (di
), NULL
);
2498 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2499 cplus_demangle_type (di
), NULL
);
2504 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2505 cplus_demangle_type (di
), NULL
);
2510 ret
= d_source_name (di
);
2511 if (d_peek_char (di
) == 'I')
2512 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2513 d_template_args (di
));
2514 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2515 cplus_demangle_type (di
), ret
);
2521 peek
= d_next_char (di
);
2526 /* decltype (expression) */
2527 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2528 d_expression (di
), NULL
);
2529 if (ret
&& d_next_char (di
) != 'E')
2535 /* Pack expansion. */
2536 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2537 cplus_demangle_type (di
), NULL
);
2543 ret
= d_make_name (di
, "auto", 4);
2547 /* 32-bit decimal floating point */
2548 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2549 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2553 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2554 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2558 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2559 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2562 /* 16-bit half-precision FP */
2563 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2564 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2568 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2569 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2573 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2574 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2578 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2579 ret
= d_make_empty (di
);
2580 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2581 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2582 /* For demangling we don't care about the bits. */
2584 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2585 if (ret
->u
.s_fixed
.length
== NULL
)
2588 peek
= d_next_char (di
);
2589 ret
->u
.s_fixed
.sat
= (peek
== 's');
2593 ret
= d_vector_type (di
);
2598 /* decltype(nullptr) */
2599 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2600 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2614 if (! d_add_substitution (di
, ret
))
2621 /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */
2623 static struct demangle_component
**
2624 d_cv_qualifiers (struct d_info
*di
,
2625 struct demangle_component
**pret
, int member_fn
)
2627 struct demangle_component
**pstart
;
2631 peek
= d_peek_char (di
);
2632 while (peek
== 'r' || peek
== 'V' || peek
== 'K'
2633 || (peek
== 'D' && d_peek_next_char (di
) == 'x'))
2635 enum demangle_component_type t
;
2641 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2642 : DEMANGLE_COMPONENT_RESTRICT
);
2643 di
->expansion
+= sizeof "restrict";
2645 else if (peek
== 'V')
2648 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2649 : DEMANGLE_COMPONENT_VOLATILE
);
2650 di
->expansion
+= sizeof "volatile";
2652 else if (peek
== 'K')
2655 ? DEMANGLE_COMPONENT_CONST_THIS
2656 : DEMANGLE_COMPONENT_CONST
);
2657 di
->expansion
+= sizeof "const";
2661 t
= DEMANGLE_COMPONENT_TRANSACTION_SAFE
;
2662 di
->expansion
+= sizeof "transaction_safe";
2666 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2669 pret
= &d_left (*pret
);
2671 peek
= d_peek_char (di
);
2674 if (!member_fn
&& peek
== 'F')
2676 while (pstart
!= pret
)
2678 switch ((*pstart
)->type
)
2680 case DEMANGLE_COMPONENT_RESTRICT
:
2681 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2683 case DEMANGLE_COMPONENT_VOLATILE
:
2684 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2686 case DEMANGLE_COMPONENT_CONST
:
2687 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2692 pstart
= &d_left (*pstart
);
2699 /* <ref-qualifier> ::= R
2702 static struct demangle_component
*
2703 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2705 struct demangle_component
*ret
= sub
;
2708 peek
= d_peek_char (di
);
2709 if (peek
== 'R' || peek
== 'O')
2711 enum demangle_component_type t
;
2714 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2715 di
->expansion
+= sizeof "&";
2719 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2720 di
->expansion
+= sizeof "&&";
2724 ret
= d_make_comp (di
, t
, ret
, NULL
);
2730 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */
2732 static struct demangle_component
*
2733 d_function_type (struct d_info
*di
)
2735 struct demangle_component
*ret
;
2737 if (! d_check_char (di
, 'F'))
2739 if (d_peek_char (di
) == 'Y')
2741 /* Function has C linkage. We don't print this information.
2742 FIXME: We should print it in verbose mode. */
2745 ret
= d_bare_function_type (di
, 1);
2746 ret
= d_ref_qualifier (di
, ret
);
2748 if (! d_check_char (di
, 'E'))
2755 static struct demangle_component
*
2756 d_parmlist (struct d_info
*di
)
2758 struct demangle_component
*tl
;
2759 struct demangle_component
**ptl
;
2765 struct demangle_component
*type
;
2767 char peek
= d_peek_char (di
);
2768 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2770 if ((peek
== 'R' || peek
== 'O')
2771 && d_peek_next_char (di
) == 'E')
2772 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2774 type
= cplus_demangle_type (di
);
2777 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2780 ptl
= &d_right (*ptl
);
2783 /* There should be at least one parameter type besides the optional
2784 return type. A function which takes no arguments will have a
2785 single parameter type void. */
2789 /* If we have a single parameter type void, omit it. */
2790 if (d_right (tl
) == NULL
2791 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2792 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2794 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2801 /* <bare-function-type> ::= [J]<type>+ */
2803 static struct demangle_component
*
2804 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2806 struct demangle_component
*return_type
;
2807 struct demangle_component
*tl
;
2810 /* Detect special qualifier indicating that the first argument
2811 is the return type. */
2812 peek
= d_peek_char (di
);
2816 has_return_type
= 1;
2819 if (has_return_type
)
2821 return_type
= cplus_demangle_type (di
);
2822 if (return_type
== NULL
)
2828 tl
= d_parmlist (di
);
2832 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2836 /* <class-enum-type> ::= <name> */
2838 static struct demangle_component
*
2839 d_class_enum_type (struct d_info
*di
)
2844 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2845 ::= A [<(dimension) expression>] _ <(element) type>
2848 static struct demangle_component
*
2849 d_array_type (struct d_info
*di
)
2852 struct demangle_component
*dim
;
2854 if (! d_check_char (di
, 'A'))
2857 peek
= d_peek_char (di
);
2860 else if (IS_DIGIT (peek
))
2868 peek
= d_peek_char (di
);
2870 while (IS_DIGIT (peek
));
2871 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2877 dim
= d_expression (di
);
2882 if (! d_check_char (di
, '_'))
2885 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2886 cplus_demangle_type (di
));
2889 /* <vector-type> ::= Dv <number> _ <type>
2890 ::= Dv _ <expression> _ <type> */
2892 static struct demangle_component
*
2893 d_vector_type (struct d_info
*di
)
2896 struct demangle_component
*dim
;
2898 peek
= d_peek_char (di
);
2902 dim
= d_expression (di
);
2905 dim
= d_number_component (di
);
2910 if (! d_check_char (di
, '_'))
2913 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2914 cplus_demangle_type (di
));
2917 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2919 static struct demangle_component
*
2920 d_pointer_to_member_type (struct d_info
*di
)
2922 struct demangle_component
*cl
;
2923 struct demangle_component
*mem
;
2925 if (! d_check_char (di
, 'M'))
2928 cl
= cplus_demangle_type (di
);
2932 /* The ABI says, "The type of a non-static member function is considered
2933 to be different, for the purposes of substitution, from the type of a
2934 namespace-scope or static member function whose type appears
2935 similar. The types of two non-static member functions are considered
2936 to be different, for the purposes of substitution, if the functions
2937 are members of different classes. In other words, for the purposes of
2938 substitution, the class of which the function is a member is
2939 considered part of the type of function."
2941 For a pointer to member function, this call to cplus_demangle_type
2942 will end up adding a (possibly qualified) non-member function type to
2943 the substitution table, which is not correct; however, the member
2944 function type will never be used in a substitution, so putting the
2945 wrong type in the substitution table is harmless. */
2947 mem
= cplus_demangle_type (di
);
2951 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2954 /* <non-negative number> _ */
2957 d_compact_number (struct d_info
*di
)
2960 if (d_peek_char (di
) == '_')
2962 else if (d_peek_char (di
) == 'n')
2965 num
= d_number (di
) + 1;
2967 if (num
< 0 || ! d_check_char (di
, '_'))
2972 /* <template-param> ::= T_
2973 ::= T <(parameter-2 non-negative) number> _
2976 static struct demangle_component
*
2977 d_template_param (struct d_info
*di
)
2981 if (! d_check_char (di
, 'T'))
2984 param
= d_compact_number (di
);
2990 return d_make_template_param (di
, param
);
2993 /* <template-args> ::= I <template-arg>+ E */
2995 static struct demangle_component
*
2996 d_template_args (struct d_info
*di
)
2998 struct demangle_component
*hold_last_name
;
2999 struct demangle_component
*al
;
3000 struct demangle_component
**pal
;
3002 /* Preserve the last name we saw--don't let the template arguments
3003 clobber it, as that would give us the wrong name for a subsequent
3004 constructor or destructor. */
3005 hold_last_name
= di
->last_name
;
3007 if (d_peek_char (di
) != 'I'
3008 && d_peek_char (di
) != 'J')
3012 if (d_peek_char (di
) == 'E')
3014 /* An argument pack can be empty. */
3016 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
3023 struct demangle_component
*a
;
3025 a
= d_template_arg (di
);
3029 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
3032 pal
= &d_right (*pal
);
3034 if (d_peek_char (di
) == 'E')
3041 di
->last_name
= hold_last_name
;
3046 /* <template-arg> ::= <type>
3047 ::= X <expression> E
3051 static struct demangle_component
*
3052 d_template_arg (struct d_info
*di
)
3054 struct demangle_component
*ret
;
3056 switch (d_peek_char (di
))
3060 ret
= d_expression (di
);
3061 if (! d_check_char (di
, 'E'))
3066 return d_expr_primary (di
);
3070 /* An argument pack. */
3071 return d_template_args (di
);
3074 return cplus_demangle_type (di
);
3078 /* Parse a sequence of expressions until we hit the terminator
3081 static struct demangle_component
*
3082 d_exprlist (struct d_info
*di
, char terminator
)
3084 struct demangle_component
*list
= NULL
;
3085 struct demangle_component
**p
= &list
;
3087 if (d_peek_char (di
) == terminator
)
3090 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3095 struct demangle_component
*arg
= d_expression (di
);
3099 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3104 if (d_peek_char (di
) == terminator
)
3114 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3115 dynamic_cast, static_cast or reinterpret_cast. */
3118 op_is_new_cast (struct demangle_component
*op
)
3120 const char *code
= op
->u
.s_operator
.op
->code
;
3121 return (code
[1] == 'c'
3122 && (code
[0] == 's' || code
[0] == 'd'
3123 || code
[0] == 'c' || code
[0] == 'r'));
3126 /* <expression> ::= <(unary) operator-name> <expression>
3127 ::= <(binary) operator-name> <expression> <expression>
3128 ::= <(trinary) operator-name> <expression> <expression> <expression>
3129 ::= cl <expression>+ E
3131 ::= <template-param>
3132 ::= sr <type> <unqualified-name>
3133 ::= sr <type> <unqualified-name> <template-args>
3137 static inline struct demangle_component
*
3138 d_expression_1 (struct d_info
*di
)
3142 peek
= d_peek_char (di
);
3144 return d_expr_primary (di
);
3145 else if (peek
== 'T')
3146 return d_template_param (di
);
3147 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3149 struct demangle_component
*type
;
3150 struct demangle_component
*name
;
3153 type
= cplus_demangle_type (di
);
3154 name
= d_unqualified_name (di
);
3155 if (d_peek_char (di
) != 'I')
3156 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3158 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3159 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3160 d_template_args (di
)));
3162 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3165 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3166 d_expression_1 (di
), NULL
);
3168 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3170 /* Function parameter used in a late-specified return type. */
3173 if (d_peek_char (di
) == 'T')
3175 /* 'this' parameter. */
3181 index
= d_compact_number (di
);
3182 if (index
== INT_MAX
|| index
== -1)
3186 return d_make_function_param (di
, index
);
3188 else if (IS_DIGIT (peek
)
3189 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3191 /* We can get an unqualified name as an expression in the case of
3192 a dependent function call, i.e. decltype(f(t)). */
3193 struct demangle_component
*name
;
3196 /* operator-function-id, i.e. operator+(t). */
3199 name
= d_unqualified_name (di
);
3202 if (d_peek_char (di
) == 'I')
3203 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3204 d_template_args (di
));
3208 else if ((peek
== 'i' || peek
== 't')
3209 && d_peek_next_char (di
) == 'l')
3211 /* Brace-enclosed initializer list, untyped or typed. */
3212 struct demangle_component
*type
= NULL
;
3214 type
= cplus_demangle_type (di
);
3215 if (!d_peek_next_char (di
))
3218 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3219 type
, d_exprlist (di
, 'E'));
3223 struct demangle_component
*op
;
3224 const char *code
= NULL
;
3227 op
= d_operator_name (di
);
3231 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3233 code
= op
->u
.s_operator
.op
->code
;
3234 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3235 if (strcmp (code
, "st") == 0)
3236 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3237 cplus_demangle_type (di
));
3244 case DEMANGLE_COMPONENT_OPERATOR
:
3245 args
= op
->u
.s_operator
.op
->args
;
3247 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3248 args
= op
->u
.s_extended_operator
.args
;
3250 case DEMANGLE_COMPONENT_CAST
:
3258 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3262 struct demangle_component
*operand
;
3265 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3266 && code
[1] == code
[0])
3267 /* pp_ and mm_ are the prefix variants. */
3268 suffix
= !d_check_char (di
, '_');
3270 if (op
->type
== DEMANGLE_COMPONENT_CAST
3271 && d_check_char (di
, '_'))
3272 operand
= d_exprlist (di
, 'E');
3274 operand
= d_expression_1 (di
);
3277 /* Indicate the suffix variant for d_print_comp. */
3278 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3280 DEMANGLE_COMPONENT_BINARY_ARGS
,
3283 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3288 struct demangle_component
*left
;
3289 struct demangle_component
*right
;
3293 if (op_is_new_cast (op
))
3294 left
= cplus_demangle_type (di
);
3296 left
= d_expression_1 (di
);
3297 if (!strcmp (code
, "cl"))
3298 right
= d_exprlist (di
, 'E');
3299 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3301 right
= d_unqualified_name (di
);
3302 if (d_peek_char (di
) == 'I')
3303 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3304 right
, d_template_args (di
));
3307 right
= d_expression_1 (di
);
3309 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3311 DEMANGLE_COMPONENT_BINARY_ARGS
,
3316 struct demangle_component
*first
;
3317 struct demangle_component
*second
;
3318 struct demangle_component
*third
;
3322 else if (!strcmp (code
, "qu"))
3324 /* ?: expression. */
3325 first
= d_expression_1 (di
);
3326 second
= d_expression_1 (di
);
3327 third
= d_expression_1 (di
);
3329 else if (code
[0] == 'n')
3331 /* new-expression. */
3332 if (code
[1] != 'w' && code
[1] != 'a')
3334 first
= d_exprlist (di
, '_');
3335 second
= cplus_demangle_type (di
);
3336 if (d_peek_char (di
) == 'E')
3341 else if (d_peek_char (di
) == 'p'
3342 && d_peek_next_char (di
) == 'i')
3344 /* Parenthesized initializer. */
3346 third
= d_exprlist (di
, 'E');
3348 else if (d_peek_char (di
) == 'i'
3349 && d_peek_next_char (di
) == 'l')
3350 /* initializer-list. */
3351 third
= d_expression_1 (di
);
3357 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3359 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3362 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3371 static struct demangle_component
*
3372 d_expression (struct d_info
*di
)
3374 struct demangle_component
*ret
;
3375 int was_expression
= di
->is_expression
;
3377 di
->is_expression
= 1;
3378 ret
= d_expression_1 (di
);
3379 di
->is_expression
= was_expression
;
3383 /* <expr-primary> ::= L <type> <(value) number> E
3384 ::= L <type> <(value) float> E
3385 ::= L <mangled-name> E
3388 static struct demangle_component
*
3389 d_expr_primary (struct d_info
*di
)
3391 struct demangle_component
*ret
;
3393 if (! d_check_char (di
, 'L'))
3395 if (d_peek_char (di
) == '_'
3396 /* Workaround for G++ bug; see comment in write_template_arg. */
3397 || d_peek_char (di
) == 'Z')
3398 ret
= cplus_demangle_mangled_name (di
, 0);
3401 struct demangle_component
*type
;
3402 enum demangle_component_type t
;
3405 type
= cplus_demangle_type (di
);
3409 /* If we have a type we know how to print, we aren't going to
3410 print the type name itself. */
3411 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3412 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3413 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3415 /* Rather than try to interpret the literal value, we just
3416 collect it as a string. Note that it's possible to have a
3417 floating point literal here. The ABI specifies that the
3418 format of such literals is machine independent. That's fine,
3419 but what's not fine is that versions of g++ up to 3.2 with
3420 -fabi-version=1 used upper case letters in the hex constant,
3421 and dumped out gcc's internal representation. That makes it
3422 hard to tell where the constant ends, and hard to dump the
3423 constant in any readable form anyhow. We don't attempt to
3424 handle these cases. */
3426 t
= DEMANGLE_COMPONENT_LITERAL
;
3427 if (d_peek_char (di
) == 'n')
3429 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3433 while (d_peek_char (di
) != 'E')
3435 if (d_peek_char (di
) == '\0')
3439 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3441 if (! d_check_char (di
, 'E'))
3446 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3447 ::= Z <(function) encoding> E s [<discriminator>]
3448 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3451 static struct demangle_component
*
3452 d_local_name (struct d_info
*di
)
3454 struct demangle_component
*function
;
3456 if (! d_check_char (di
, 'Z'))
3459 function
= d_encoding (di
, 0);
3461 if (! d_check_char (di
, 'E'))
3464 if (d_peek_char (di
) == 's')
3467 if (! d_discriminator (di
))
3469 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3470 d_make_name (di
, "string literal",
3471 sizeof "string literal" - 1));
3475 struct demangle_component
*name
;
3478 if (d_peek_char (di
) == 'd')
3480 /* Default argument scope: d <number> _. */
3482 num
= d_compact_number (di
);
3491 /* Lambdas and unnamed types have internal discriminators. */
3492 case DEMANGLE_COMPONENT_LAMBDA
:
3493 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3496 if (! d_discriminator (di
))
3500 name
= d_make_default_arg (di
, num
, name
);
3501 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3505 /* <discriminator> ::= _ <(non-negative) number>
3507 We demangle the discriminator, but we don't print it out. FIXME:
3508 We should print it out in verbose mode. */
3511 d_discriminator (struct d_info
*di
)
3515 if (d_peek_char (di
) != '_')
3518 discrim
= d_number (di
);
3524 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3526 static struct demangle_component
*
3527 d_lambda (struct d_info
*di
)
3529 struct demangle_component
*tl
;
3530 struct demangle_component
*ret
;
3533 if (! d_check_char (di
, 'U'))
3535 if (! d_check_char (di
, 'l'))
3538 tl
= d_parmlist (di
);
3542 if (! d_check_char (di
, 'E'))
3545 num
= d_compact_number (di
);
3549 ret
= d_make_empty (di
);
3552 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3553 ret
->u
.s_unary_num
.sub
= tl
;
3554 ret
->u
.s_unary_num
.num
= num
;
3557 if (! d_add_substitution (di
, ret
))
3563 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3565 static struct demangle_component
*
3566 d_unnamed_type (struct d_info
*di
)
3568 struct demangle_component
*ret
;
3571 if (! d_check_char (di
, 'U'))
3573 if (! d_check_char (di
, 't'))
3576 num
= d_compact_number (di
);
3580 ret
= d_make_empty (di
);
3583 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3584 ret
->u
.s_number
.number
= num
;
3587 if (! d_add_substitution (di
, ret
))
3593 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3596 static struct demangle_component
*
3597 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3599 const char *suffix
= d_str (di
);
3600 const char *pend
= suffix
;
3601 struct demangle_component
*n
;
3603 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3606 while (IS_LOWER (*pend
) || *pend
== '_')
3609 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3612 while (IS_DIGIT (*pend
))
3615 d_advance (di
, pend
- suffix
);
3616 n
= d_make_name (di
, suffix
, pend
- suffix
);
3617 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3620 /* Add a new substitution. */
3623 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3627 if (di
->next_sub
>= di
->num_subs
)
3629 di
->subs
[di
->next_sub
] = dc
;
3634 /* <substitution> ::= S <seq-id> _
3644 If PREFIX is non-zero, then this type is being used as a prefix in
3645 a qualified name. In this case, for the standard substitutions, we
3646 need to check whether we are being used as a prefix for a
3647 constructor or destructor, and return a full template name.
3648 Otherwise we will get something like std::iostream::~iostream()
3649 which does not correspond particularly well to any function which
3650 actually appears in the source.
3653 static const struct d_standard_sub_info standard_subs
[] =
3658 { 'a', NL ("std::allocator"),
3659 NL ("std::allocator"),
3661 { 'b', NL ("std::basic_string"),
3662 NL ("std::basic_string"),
3663 NL ("basic_string") },
3664 { 's', NL ("std::string"),
3665 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3666 NL ("basic_string") },
3667 { 'i', NL ("std::istream"),
3668 NL ("std::basic_istream<char, std::char_traits<char> >"),
3669 NL ("basic_istream") },
3670 { 'o', NL ("std::ostream"),
3671 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3672 NL ("basic_ostream") },
3673 { 'd', NL ("std::iostream"),
3674 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3675 NL ("basic_iostream") }
3678 static struct demangle_component
*
3679 d_substitution (struct d_info
*di
, int prefix
)
3683 if (! d_check_char (di
, 'S'))
3686 c
= d_next_char (di
);
3687 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3696 unsigned int new_id
;
3699 new_id
= id
* 36 + c
- '0';
3700 else if (IS_UPPER (c
))
3701 new_id
= id
* 36 + c
- 'A' + 10;
3707 c
= d_next_char (di
);
3714 if (id
>= (unsigned int) di
->next_sub
)
3719 return di
->subs
[id
];
3724 const struct d_standard_sub_info
*p
;
3725 const struct d_standard_sub_info
*pend
;
3727 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3728 if (! verbose
&& prefix
)
3732 peek
= d_peek_char (di
);
3733 if (peek
== 'C' || peek
== 'D')
3737 pend
= (&standard_subs
[0]
3738 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3739 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3745 struct demangle_component
*c
;
3747 if (p
->set_last_name
!= NULL
)
3748 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3749 p
->set_last_name_len
);
3752 s
= p
->full_expansion
;
3757 s
= p
->simple_expansion
;
3758 len
= p
->simple_len
;
3760 di
->expansion
+= len
;
3761 c
= d_make_sub (di
, s
, len
);
3762 if (d_peek_char (di
) == 'B')
3764 /* If there are ABI tags on the abbreviation, it becomes
3765 a substitution candidate. */
3766 c
= d_abi_tags (di
, c
);
3767 d_add_substitution (di
, c
);
3778 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3780 checkpoint
->n
= di
->n
;
3781 checkpoint
->next_comp
= di
->next_comp
;
3782 checkpoint
->next_sub
= di
->next_sub
;
3783 checkpoint
->did_subs
= di
->did_subs
;
3784 checkpoint
->expansion
= di
->expansion
;
3788 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3790 di
->n
= checkpoint
->n
;
3791 di
->next_comp
= checkpoint
->next_comp
;
3792 di
->next_sub
= checkpoint
->next_sub
;
3793 di
->did_subs
= checkpoint
->did_subs
;
3794 di
->expansion
= checkpoint
->expansion
;
3797 /* Initialize a growable string. */
3800 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3805 dgs
->allocation_failure
= 0;
3808 d_growable_string_resize (dgs
, estimate
);
3811 /* Grow a growable string to a given size. */
3814 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3819 if (dgs
->allocation_failure
)
3822 /* Start allocation at two bytes to avoid any possibility of confusion
3823 with the special value of 1 used as a return in *palc to indicate
3824 allocation failures. */
3825 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3826 while (newalc
< need
)
3829 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3836 dgs
->allocation_failure
= 1;
3843 /* Append a buffer to a growable string. */
3846 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3847 const char *s
, size_t l
)
3851 need
= dgs
->len
+ l
+ 1;
3852 if (need
> dgs
->alc
)
3853 d_growable_string_resize (dgs
, need
);
3855 if (dgs
->allocation_failure
)
3858 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3859 dgs
->buf
[dgs
->len
+ l
] = '\0';
3863 /* Bridge growable strings to the callback mechanism. */
3866 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3868 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3870 d_growable_string_append_buffer (dgs
, s
, l
);
3873 /* Walk the tree, counting the number of templates encountered, and
3874 the number of times a scope might be saved. These counts will be
3875 used to allocate data structures for d_print_comp, so the logic
3876 here must mirror the logic d_print_comp will use. It is not
3877 important that the resulting numbers are exact, so long as they
3878 are larger than the actual numbers encountered. */
3881 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
3882 const struct demangle_component
*dc
)
3889 case DEMANGLE_COMPONENT_NAME
:
3890 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3891 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3892 case DEMANGLE_COMPONENT_SUB_STD
:
3893 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3894 case DEMANGLE_COMPONENT_OPERATOR
:
3895 case DEMANGLE_COMPONENT_CHARACTER
:
3896 case DEMANGLE_COMPONENT_NUMBER
:
3897 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3900 case DEMANGLE_COMPONENT_TEMPLATE
:
3902 goto recurse_left_right
;
3904 case DEMANGLE_COMPONENT_REFERENCE
:
3905 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3906 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
3908 goto recurse_left_right
;
3910 case DEMANGLE_COMPONENT_QUAL_NAME
:
3911 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3912 case DEMANGLE_COMPONENT_TYPED_NAME
:
3913 case DEMANGLE_COMPONENT_VTABLE
:
3914 case DEMANGLE_COMPONENT_VTT
:
3915 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3916 case DEMANGLE_COMPONENT_TYPEINFO
:
3917 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3918 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3919 case DEMANGLE_COMPONENT_THUNK
:
3920 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3921 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3922 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3923 case DEMANGLE_COMPONENT_GUARD
:
3924 case DEMANGLE_COMPONENT_TLS_INIT
:
3925 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
3926 case DEMANGLE_COMPONENT_REFTEMP
:
3927 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3928 case DEMANGLE_COMPONENT_RESTRICT
:
3929 case DEMANGLE_COMPONENT_VOLATILE
:
3930 case DEMANGLE_COMPONENT_CONST
:
3931 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3932 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3933 case DEMANGLE_COMPONENT_CONST_THIS
:
3934 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
3935 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
3936 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
3937 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3938 case DEMANGLE_COMPONENT_POINTER
:
3939 case DEMANGLE_COMPONENT_COMPLEX
:
3940 case DEMANGLE_COMPONENT_IMAGINARY
:
3941 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3942 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3943 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3944 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3945 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
3946 case DEMANGLE_COMPONENT_ARGLIST
:
3947 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3948 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
3949 case DEMANGLE_COMPONENT_CAST
:
3950 case DEMANGLE_COMPONENT_CONVERSION
:
3951 case DEMANGLE_COMPONENT_NULLARY
:
3952 case DEMANGLE_COMPONENT_UNARY
:
3953 case DEMANGLE_COMPONENT_BINARY
:
3954 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3955 case DEMANGLE_COMPONENT_TRINARY
:
3956 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3957 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3958 case DEMANGLE_COMPONENT_LITERAL
:
3959 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3960 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
3961 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
3962 case DEMANGLE_COMPONENT_DECLTYPE
:
3963 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
3964 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
3965 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3966 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3967 case DEMANGLE_COMPONENT_CLONE
:
3969 d_count_templates_scopes (num_templates
, num_scopes
,
3971 d_count_templates_scopes (num_templates
, num_scopes
,
3975 case DEMANGLE_COMPONENT_CTOR
:
3976 d_count_templates_scopes (num_templates
, num_scopes
,
3980 case DEMANGLE_COMPONENT_DTOR
:
3981 d_count_templates_scopes (num_templates
, num_scopes
,
3985 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3986 d_count_templates_scopes (num_templates
, num_scopes
,
3987 dc
->u
.s_extended_operator
.name
);
3990 case DEMANGLE_COMPONENT_FIXED_TYPE
:
3991 d_count_templates_scopes (num_templates
, num_scopes
,
3992 dc
->u
.s_fixed
.length
);
3995 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
3996 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
3997 d_count_templates_scopes (num_templates
, num_scopes
,
4001 case DEMANGLE_COMPONENT_LAMBDA
:
4002 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4003 d_count_templates_scopes (num_templates
, num_scopes
,
4004 dc
->u
.s_unary_num
.sub
);
4009 /* Initialize a print information structure. */
4012 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
4013 void *opaque
, const struct demangle_component
*dc
)
4016 dpi
->last_char
= '\0';
4017 dpi
->templates
= NULL
;
4018 dpi
->modifiers
= NULL
;
4019 dpi
->pack_index
= 0;
4020 dpi
->flush_count
= 0;
4022 dpi
->callback
= callback
;
4023 dpi
->opaque
= opaque
;
4025 dpi
->demangle_failure
= 0;
4027 dpi
->component_stack
= NULL
;
4029 dpi
->saved_scopes
= NULL
;
4030 dpi
->next_saved_scope
= 0;
4031 dpi
->num_saved_scopes
= 0;
4033 dpi
->copy_templates
= NULL
;
4034 dpi
->next_copy_template
= 0;
4035 dpi
->num_copy_templates
= 0;
4037 d_count_templates_scopes (&dpi
->num_copy_templates
,
4038 &dpi
->num_saved_scopes
, dc
);
4039 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
4041 dpi
->current_template
= NULL
;
4044 /* Indicate that an error occurred during printing, and test for error. */
4047 d_print_error (struct d_print_info
*dpi
)
4049 dpi
->demangle_failure
= 1;
4053 d_print_saw_error (struct d_print_info
*dpi
)
4055 return dpi
->demangle_failure
!= 0;
4058 /* Flush buffered characters to the callback. */
4061 d_print_flush (struct d_print_info
*dpi
)
4063 dpi
->buf
[dpi
->len
] = '\0';
4064 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4069 /* Append characters and buffers for printing. */
4072 d_append_char (struct d_print_info
*dpi
, char c
)
4074 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4075 d_print_flush (dpi
);
4077 dpi
->buf
[dpi
->len
++] = c
;
4082 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4086 for (i
= 0; i
< l
; i
++)
4087 d_append_char (dpi
, s
[i
]);
4091 d_append_string (struct d_print_info
*dpi
, const char *s
)
4093 d_append_buffer (dpi
, s
, strlen (s
));
4097 d_append_num (struct d_print_info
*dpi
, int l
)
4100 sprintf (buf
,"%d", l
);
4101 d_append_string (dpi
, buf
);
4105 d_last_char (struct d_print_info
*dpi
)
4107 return dpi
->last_char
;
4110 /* Turn components into a human readable string. OPTIONS is the
4111 options bits passed to the demangler. DC is the tree to print.
4112 CALLBACK is a function to call to flush demangled string segments
4113 as they fill the intermediate buffer, and OPAQUE is a generalized
4114 callback argument. On success, this returns 1. On failure,
4115 it returns 0, indicating a bad parse. It does not use heap
4116 memory to build an output string, so cannot encounter memory
4117 allocation failure. */
4119 CP_STATIC_IF_GLIBCPP_V3
4121 cplus_demangle_print_callback (int options
,
4122 const struct demangle_component
*dc
,
4123 demangle_callbackref callback
, void *opaque
)
4125 struct d_print_info dpi
;
4127 d_print_init (&dpi
, callback
, opaque
, dc
);
4130 #ifdef CP_DYNAMIC_ARRAYS
4131 /* Avoid zero-length VLAs, which are prohibited by the C99 standard
4132 and flagged as errors by Address Sanitizer. */
4133 __extension__
struct d_saved_scope scopes
[(dpi
.num_saved_scopes
> 0)
4134 ? dpi
.num_saved_scopes
: 1];
4135 __extension__
struct d_print_template temps
[(dpi
.num_copy_templates
> 0)
4136 ? dpi
.num_copy_templates
: 1];
4138 dpi
.saved_scopes
= scopes
;
4139 dpi
.copy_templates
= temps
;
4141 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4142 * sizeof (*dpi
.saved_scopes
));
4143 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4144 * sizeof (*dpi
.copy_templates
));
4147 d_print_comp (&dpi
, options
, dc
);
4150 d_print_flush (&dpi
);
4152 return ! d_print_saw_error (&dpi
);
4155 /* Turn components into a human readable string. OPTIONS is the
4156 options bits passed to the demangler. DC is the tree to print.
4157 ESTIMATE is a guess at the length of the result. This returns a
4158 string allocated by malloc, or NULL on error. On success, this
4159 sets *PALC to the size of the allocated buffer. On failure, this
4160 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4163 CP_STATIC_IF_GLIBCPP_V3
4165 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4166 int estimate
, size_t *palc
)
4168 struct d_growable_string dgs
;
4170 d_growable_string_init (&dgs
, estimate
);
4172 if (! cplus_demangle_print_callback (options
, dc
,
4173 d_growable_string_callback_adapter
,
4181 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4185 /* Returns the I'th element of the template arglist ARGS, or NULL on
4188 static struct demangle_component
*
4189 d_index_template_argument (struct demangle_component
*args
, int i
)
4191 struct demangle_component
*a
;
4197 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4203 if (i
!= 0 || a
== NULL
)
4209 /* Returns the template argument from the current context indicated by DC,
4210 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4212 static struct demangle_component
*
4213 d_lookup_template_argument (struct d_print_info
*dpi
,
4214 const struct demangle_component
*dc
)
4216 if (dpi
->templates
== NULL
)
4218 d_print_error (dpi
);
4222 return d_index_template_argument
4223 (d_right (dpi
->templates
->template_decl
),
4224 dc
->u
.s_number
.number
);
4227 /* Returns a template argument pack used in DC (any will do), or NULL. */
4229 static struct demangle_component
*
4230 d_find_pack (struct d_print_info
*dpi
,
4231 const struct demangle_component
*dc
)
4233 struct demangle_component
*a
;
4239 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4240 a
= d_lookup_template_argument (dpi
, dc
);
4241 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4245 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4248 case DEMANGLE_COMPONENT_LAMBDA
:
4249 case DEMANGLE_COMPONENT_NAME
:
4250 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4251 case DEMANGLE_COMPONENT_OPERATOR
:
4252 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4253 case DEMANGLE_COMPONENT_SUB_STD
:
4254 case DEMANGLE_COMPONENT_CHARACTER
:
4255 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4256 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4257 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4258 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4259 case DEMANGLE_COMPONENT_NUMBER
:
4262 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4263 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4264 case DEMANGLE_COMPONENT_CTOR
:
4265 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4266 case DEMANGLE_COMPONENT_DTOR
:
4267 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4270 a
= d_find_pack (dpi
, d_left (dc
));
4273 return d_find_pack (dpi
, d_right (dc
));
4277 /* Returns the length of the template argument pack DC. */
4280 d_pack_length (const struct demangle_component
*dc
)
4283 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4284 && d_left (dc
) != NULL
)
4292 /* DC is a component of a mangled expression. Print it, wrapped in parens
4296 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4297 const struct demangle_component
*dc
)
4300 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4301 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4302 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4303 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4306 d_append_char (dpi
, '(');
4307 d_print_comp (dpi
, options
, dc
);
4309 d_append_char (dpi
, ')');
4312 /* Save the current scope. */
4315 d_save_scope (struct d_print_info
*dpi
,
4316 const struct demangle_component
*container
)
4318 struct d_saved_scope
*scope
;
4319 struct d_print_template
*src
, **link
;
4321 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4323 d_print_error (dpi
);
4326 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4327 dpi
->next_saved_scope
++;
4329 scope
->container
= container
;
4330 link
= &scope
->templates
;
4332 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4334 struct d_print_template
*dst
;
4336 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4338 d_print_error (dpi
);
4341 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4342 dpi
->next_copy_template
++;
4344 dst
->template_decl
= src
->template_decl
;
4352 /* Attempt to locate a previously saved scope. Returns NULL if no
4353 corresponding saved scope was found. */
4355 static struct d_saved_scope
*
4356 d_get_saved_scope (struct d_print_info
*dpi
,
4357 const struct demangle_component
*container
)
4361 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4362 if (dpi
->saved_scopes
[i
].container
== container
)
4363 return &dpi
->saved_scopes
[i
];
4368 /* Subroutine to handle components. */
4371 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
4372 const struct demangle_component
*dc
)
4374 /* Magic variable to let reference smashing skip over the next modifier
4375 without needing to modify *dc. */
4376 const struct demangle_component
*mod_inner
= NULL
;
4378 /* Variable used to store the current templates while a previously
4379 captured scope is used. */
4380 struct d_print_template
*saved_templates
;
4382 /* Nonzero if templates have been stored in the above variable. */
4383 int need_template_restore
= 0;
4387 d_print_error (dpi
);
4390 if (d_print_saw_error (dpi
))
4395 case DEMANGLE_COMPONENT_NAME
:
4396 if ((options
& DMGL_JAVA
) == 0)
4397 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4399 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4402 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4403 d_print_comp (dpi
, options
, d_left (dc
));
4404 d_append_string (dpi
, "[abi:");
4405 d_print_comp (dpi
, options
, d_right (dc
));
4406 d_append_char (dpi
, ']');
4409 case DEMANGLE_COMPONENT_QUAL_NAME
:
4410 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4411 d_print_comp (dpi
, options
, d_left (dc
));
4412 if ((options
& DMGL_JAVA
) == 0)
4413 d_append_string (dpi
, "::");
4415 d_append_char (dpi
, '.');
4417 struct demangle_component
*local_name
= d_right (dc
);
4418 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4420 d_append_string (dpi
, "{default arg#");
4421 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4422 d_append_string (dpi
, "}::");
4423 local_name
= local_name
->u
.s_unary_num
.sub
;
4425 d_print_comp (dpi
, options
, local_name
);
4429 case DEMANGLE_COMPONENT_TYPED_NAME
:
4431 struct d_print_mod
*hold_modifiers
;
4432 struct demangle_component
*typed_name
;
4433 struct d_print_mod adpm
[4];
4435 struct d_print_template dpt
;
4437 /* Pass the name down to the type so that it can be printed in
4438 the right place for the type. We also have to pass down
4439 any CV-qualifiers, which apply to the this parameter. */
4440 hold_modifiers
= dpi
->modifiers
;
4443 typed_name
= d_left (dc
);
4444 while (typed_name
!= NULL
)
4446 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4448 d_print_error (dpi
);
4452 adpm
[i
].next
= dpi
->modifiers
;
4453 dpi
->modifiers
= &adpm
[i
];
4454 adpm
[i
].mod
= typed_name
;
4455 adpm
[i
].printed
= 0;
4456 adpm
[i
].templates
= dpi
->templates
;
4459 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4460 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4461 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4462 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4463 && typed_name
->type
!= DEMANGLE_COMPONENT_TRANSACTION_SAFE
4464 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4467 typed_name
= d_left (typed_name
);
4470 if (typed_name
== NULL
)
4472 d_print_error (dpi
);
4476 /* If typed_name is a template, then it applies to the
4477 function type as well. */
4478 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4480 dpt
.next
= dpi
->templates
;
4481 dpi
->templates
= &dpt
;
4482 dpt
.template_decl
= typed_name
;
4485 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4486 there may be CV-qualifiers on its right argument which
4487 really apply here; this happens when parsing a class which
4488 is local to a function. */
4489 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4491 struct demangle_component
*local_name
;
4493 local_name
= d_right (typed_name
);
4494 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4495 local_name
= local_name
->u
.s_unary_num
.sub
;
4496 if (local_name
== NULL
)
4498 d_print_error (dpi
);
4501 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4502 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4503 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4504 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4505 || local_name
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
4506 || (local_name
->type
4507 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4509 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4511 d_print_error (dpi
);
4515 adpm
[i
] = adpm
[i
- 1];
4516 adpm
[i
].next
= &adpm
[i
- 1];
4517 dpi
->modifiers
= &adpm
[i
];
4519 adpm
[i
- 1].mod
= local_name
;
4520 adpm
[i
- 1].printed
= 0;
4521 adpm
[i
- 1].templates
= dpi
->templates
;
4524 local_name
= d_left (local_name
);
4528 d_print_comp (dpi
, options
, d_right (dc
));
4530 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4531 dpi
->templates
= dpt
.next
;
4533 /* If the modifiers didn't get printed by the type, print them
4538 if (! adpm
[i
].printed
)
4540 d_append_char (dpi
, ' ');
4541 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4545 dpi
->modifiers
= hold_modifiers
;
4550 case DEMANGLE_COMPONENT_TEMPLATE
:
4552 struct d_print_mod
*hold_dpm
;
4553 struct demangle_component
*dcl
;
4554 const struct demangle_component
*hold_current
;
4556 /* This template may need to be referenced by a cast operator
4557 contained in its subtree. */
4558 hold_current
= dpi
->current_template
;
4559 dpi
->current_template
= dc
;
4561 /* Don't push modifiers into a template definition. Doing so
4562 could give the wrong definition for a template argument.
4563 Instead, treat the template essentially as a name. */
4565 hold_dpm
= dpi
->modifiers
;
4566 dpi
->modifiers
= NULL
;
4570 if ((options
& DMGL_JAVA
) != 0
4571 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4572 && dcl
->u
.s_name
.len
== 6
4573 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4575 /* Special-case Java arrays, so that JArray<TYPE> appears
4576 instead as TYPE[]. */
4578 d_print_comp (dpi
, options
, d_right (dc
));
4579 d_append_string (dpi
, "[]");
4583 d_print_comp (dpi
, options
, dcl
);
4584 if (d_last_char (dpi
) == '<')
4585 d_append_char (dpi
, ' ');
4586 d_append_char (dpi
, '<');
4587 d_print_comp (dpi
, options
, d_right (dc
));
4588 /* Avoid generating two consecutive '>' characters, to avoid
4589 the C++ syntactic ambiguity. */
4590 if (d_last_char (dpi
) == '>')
4591 d_append_char (dpi
, ' ');
4592 d_append_char (dpi
, '>');
4595 dpi
->modifiers
= hold_dpm
;
4596 dpi
->current_template
= hold_current
;
4601 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4603 struct d_print_template
*hold_dpt
;
4604 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4606 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4607 a
= d_index_template_argument (a
, dpi
->pack_index
);
4611 d_print_error (dpi
);
4615 /* While processing this parameter, we need to pop the list of
4616 templates. This is because the template parameter may
4617 itself be a reference to a parameter of an outer
4620 hold_dpt
= dpi
->templates
;
4621 dpi
->templates
= hold_dpt
->next
;
4623 d_print_comp (dpi
, options
, a
);
4625 dpi
->templates
= hold_dpt
;
4630 case DEMANGLE_COMPONENT_CTOR
:
4631 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4634 case DEMANGLE_COMPONENT_DTOR
:
4635 d_append_char (dpi
, '~');
4636 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4639 case DEMANGLE_COMPONENT_VTABLE
:
4640 d_append_string (dpi
, "vtable for ");
4641 d_print_comp (dpi
, options
, d_left (dc
));
4644 case DEMANGLE_COMPONENT_VTT
:
4645 d_append_string (dpi
, "VTT for ");
4646 d_print_comp (dpi
, options
, d_left (dc
));
4649 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4650 d_append_string (dpi
, "construction vtable for ");
4651 d_print_comp (dpi
, options
, d_left (dc
));
4652 d_append_string (dpi
, "-in-");
4653 d_print_comp (dpi
, options
, d_right (dc
));
4656 case DEMANGLE_COMPONENT_TYPEINFO
:
4657 d_append_string (dpi
, "typeinfo for ");
4658 d_print_comp (dpi
, options
, d_left (dc
));
4661 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4662 d_append_string (dpi
, "typeinfo name for ");
4663 d_print_comp (dpi
, options
, d_left (dc
));
4666 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4667 d_append_string (dpi
, "typeinfo fn for ");
4668 d_print_comp (dpi
, options
, d_left (dc
));
4671 case DEMANGLE_COMPONENT_THUNK
:
4672 d_append_string (dpi
, "non-virtual thunk to ");
4673 d_print_comp (dpi
, options
, d_left (dc
));
4676 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4677 d_append_string (dpi
, "virtual thunk to ");
4678 d_print_comp (dpi
, options
, d_left (dc
));
4681 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4682 d_append_string (dpi
, "covariant return thunk to ");
4683 d_print_comp (dpi
, options
, d_left (dc
));
4686 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4687 d_append_string (dpi
, "java Class for ");
4688 d_print_comp (dpi
, options
, d_left (dc
));
4691 case DEMANGLE_COMPONENT_GUARD
:
4692 d_append_string (dpi
, "guard variable for ");
4693 d_print_comp (dpi
, options
, d_left (dc
));
4696 case DEMANGLE_COMPONENT_TLS_INIT
:
4697 d_append_string (dpi
, "TLS init function for ");
4698 d_print_comp (dpi
, options
, d_left (dc
));
4701 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4702 d_append_string (dpi
, "TLS wrapper function for ");
4703 d_print_comp (dpi
, options
, d_left (dc
));
4706 case DEMANGLE_COMPONENT_REFTEMP
:
4707 d_append_string (dpi
, "reference temporary #");
4708 d_print_comp (dpi
, options
, d_right (dc
));
4709 d_append_string (dpi
, " for ");
4710 d_print_comp (dpi
, options
, d_left (dc
));
4713 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4714 d_append_string (dpi
, "hidden alias for ");
4715 d_print_comp (dpi
, options
, d_left (dc
));
4718 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4719 d_append_string (dpi
, "transaction clone for ");
4720 d_print_comp (dpi
, options
, d_left (dc
));
4723 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4724 d_append_string (dpi
, "non-transaction clone for ");
4725 d_print_comp (dpi
, options
, d_left (dc
));
4728 case DEMANGLE_COMPONENT_SUB_STD
:
4729 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4732 case DEMANGLE_COMPONENT_RESTRICT
:
4733 case DEMANGLE_COMPONENT_VOLATILE
:
4734 case DEMANGLE_COMPONENT_CONST
:
4736 struct d_print_mod
*pdpm
;
4738 /* When printing arrays, it's possible to have cases where the
4739 same CV-qualifier gets pushed on the stack multiple times.
4740 We only need to print it once. */
4742 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4744 if (! pdpm
->printed
)
4746 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4747 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4748 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4750 if (pdpm
->mod
->type
== dc
->type
)
4752 d_print_comp (dpi
, options
, d_left (dc
));
4760 case DEMANGLE_COMPONENT_REFERENCE
:
4761 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4763 /* Handle reference smashing: & + && = &. */
4764 const struct demangle_component
*sub
= d_left (dc
);
4765 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4767 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4768 struct demangle_component
*a
;
4772 /* This is the first time SUB has been traversed.
4773 We need to capture the current templates so
4774 they can be restored if SUB is reentered as a
4776 d_save_scope (dpi
, sub
);
4777 if (d_print_saw_error (dpi
))
4782 const struct d_component_stack
*dcse
;
4783 int found_self_or_parent
= 0;
4785 /* This traversal is reentering SUB as a substition.
4786 If we are not beneath SUB or DC in the tree then we
4787 need to restore SUB's template stack temporarily. */
4788 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
4789 dcse
= dcse
->parent
)
4793 && dcse
!= dpi
->component_stack
))
4795 found_self_or_parent
= 1;
4800 if (!found_self_or_parent
)
4802 saved_templates
= dpi
->templates
;
4803 dpi
->templates
= scope
->templates
;
4804 need_template_restore
= 1;
4808 a
= d_lookup_template_argument (dpi
, sub
);
4809 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4810 a
= d_index_template_argument (a
, dpi
->pack_index
);
4814 if (need_template_restore
)
4815 dpi
->templates
= saved_templates
;
4817 d_print_error (dpi
);
4824 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4825 || sub
->type
== dc
->type
)
4827 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4828 mod_inner
= d_left (sub
);
4832 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4833 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4834 case DEMANGLE_COMPONENT_CONST_THIS
:
4835 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4836 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4837 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4838 case DEMANGLE_COMPONENT_POINTER
:
4839 case DEMANGLE_COMPONENT_COMPLEX
:
4840 case DEMANGLE_COMPONENT_IMAGINARY
:
4841 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4844 /* We keep a list of modifiers on the stack. */
4845 struct d_print_mod dpm
;
4847 dpm
.next
= dpi
->modifiers
;
4848 dpi
->modifiers
= &dpm
;
4851 dpm
.templates
= dpi
->templates
;
4854 mod_inner
= d_left (dc
);
4856 d_print_comp (dpi
, options
, mod_inner
);
4858 /* If the modifier didn't get printed by the type, print it
4861 d_print_mod (dpi
, options
, dc
);
4863 dpi
->modifiers
= dpm
.next
;
4865 if (need_template_restore
)
4866 dpi
->templates
= saved_templates
;
4871 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4872 if ((options
& DMGL_JAVA
) == 0)
4873 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4874 dc
->u
.s_builtin
.type
->len
);
4876 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4877 dc
->u
.s_builtin
.type
->java_len
);
4880 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4881 d_print_comp (dpi
, options
, d_left (dc
));
4884 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4886 if ((options
& DMGL_RET_POSTFIX
) != 0)
4887 d_print_function_type (dpi
,
4888 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4889 dc
, dpi
->modifiers
);
4891 /* Print return type if present */
4892 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4893 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4895 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4897 struct d_print_mod dpm
;
4899 /* We must pass this type down as a modifier in order to
4900 print it in the right location. */
4901 dpm
.next
= dpi
->modifiers
;
4902 dpi
->modifiers
= &dpm
;
4905 dpm
.templates
= dpi
->templates
;
4907 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4910 dpi
->modifiers
= dpm
.next
;
4915 /* In standard prefix notation, there is a space between the
4916 return type and the function signature. */
4917 if ((options
& DMGL_RET_POSTFIX
) == 0)
4918 d_append_char (dpi
, ' ');
4921 if ((options
& DMGL_RET_POSTFIX
) == 0)
4922 d_print_function_type (dpi
,
4923 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4924 dc
, dpi
->modifiers
);
4929 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4931 struct d_print_mod
*hold_modifiers
;
4932 struct d_print_mod adpm
[4];
4934 struct d_print_mod
*pdpm
;
4936 /* We must pass this type down as a modifier in order to print
4937 multi-dimensional arrays correctly. If the array itself is
4938 CV-qualified, we act as though the element type were
4939 CV-qualified. We do this by copying the modifiers down
4940 rather than fiddling pointers, so that we don't wind up
4941 with a d_print_mod higher on the stack pointing into our
4942 stack frame after we return. */
4944 hold_modifiers
= dpi
->modifiers
;
4946 adpm
[0].next
= hold_modifiers
;
4947 dpi
->modifiers
= &adpm
[0];
4949 adpm
[0].printed
= 0;
4950 adpm
[0].templates
= dpi
->templates
;
4953 pdpm
= hold_modifiers
;
4955 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4956 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4957 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4959 if (! pdpm
->printed
)
4961 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4963 d_print_error (dpi
);
4968 adpm
[i
].next
= dpi
->modifiers
;
4969 dpi
->modifiers
= &adpm
[i
];
4977 d_print_comp (dpi
, options
, d_right (dc
));
4979 dpi
->modifiers
= hold_modifiers
;
4981 if (adpm
[0].printed
)
4987 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4990 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4995 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4996 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4998 struct d_print_mod dpm
;
5000 dpm
.next
= dpi
->modifiers
;
5001 dpi
->modifiers
= &dpm
;
5004 dpm
.templates
= dpi
->templates
;
5006 d_print_comp (dpi
, options
, d_right (dc
));
5008 /* If the modifier didn't get printed by the type, print it
5011 d_print_mod (dpi
, options
, dc
);
5013 dpi
->modifiers
= dpm
.next
;
5018 case DEMANGLE_COMPONENT_FIXED_TYPE
:
5019 if (dc
->u
.s_fixed
.sat
)
5020 d_append_string (dpi
, "_Sat ");
5021 /* Don't print "int _Accum". */
5022 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
5023 != &cplus_demangle_builtin_types
['i'-'a'])
5025 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
5026 d_append_char (dpi
, ' ');
5028 if (dc
->u
.s_fixed
.accum
)
5029 d_append_string (dpi
, "_Accum");
5031 d_append_string (dpi
, "_Fract");
5034 case DEMANGLE_COMPONENT_ARGLIST
:
5035 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5036 if (d_left (dc
) != NULL
)
5037 d_print_comp (dpi
, options
, d_left (dc
));
5038 if (d_right (dc
) != NULL
)
5041 unsigned long int flush_count
;
5042 /* Make sure ", " isn't flushed by d_append_string, otherwise
5043 dpi->len -= 2 wouldn't work. */
5044 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5045 d_print_flush (dpi
);
5046 d_append_string (dpi
, ", ");
5048 flush_count
= dpi
->flush_count
;
5049 d_print_comp (dpi
, options
, d_right (dc
));
5050 /* If that didn't print anything (which can happen with empty
5051 template argument packs), remove the comma and space. */
5052 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5057 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5059 struct demangle_component
*type
= d_left (dc
);
5060 struct demangle_component
*list
= d_right (dc
);
5063 d_print_comp (dpi
, options
, type
);
5064 d_append_char (dpi
, '{');
5065 d_print_comp (dpi
, options
, list
);
5066 d_append_char (dpi
, '}');
5070 case DEMANGLE_COMPONENT_OPERATOR
:
5072 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5075 d_append_string (dpi
, "operator");
5076 /* Add a space before new/delete. */
5077 if (IS_LOWER (op
->name
[0]))
5078 d_append_char (dpi
, ' ');
5079 /* Omit a trailing space. */
5080 if (op
->name
[len
-1] == ' ')
5082 d_append_buffer (dpi
, op
->name
, len
);
5086 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5087 d_append_string (dpi
, "operator ");
5088 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5091 case DEMANGLE_COMPONENT_CONVERSION
:
5092 d_append_string (dpi
, "operator ");
5093 d_print_conversion (dpi
, options
, dc
);
5096 case DEMANGLE_COMPONENT_NULLARY
:
5097 d_print_expr_op (dpi
, options
, d_left (dc
));
5100 case DEMANGLE_COMPONENT_UNARY
:
5102 struct demangle_component
*op
= d_left (dc
);
5103 struct demangle_component
*operand
= d_right (dc
);
5104 const char *code
= NULL
;
5106 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5108 code
= op
->u
.s_operator
.op
->code
;
5109 if (!strcmp (code
, "ad"))
5111 /* Don't print the argument list for the address of a
5113 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5114 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5115 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5116 operand
= d_left (operand
);
5118 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5120 /* This indicates a suffix operator. */
5121 operand
= d_left (operand
);
5122 d_print_subexpr (dpi
, options
, operand
);
5123 d_print_expr_op (dpi
, options
, op
);
5128 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5129 d_print_expr_op (dpi
, options
, op
);
5132 d_append_char (dpi
, '(');
5133 d_print_cast (dpi
, options
, op
);
5134 d_append_char (dpi
, ')');
5136 if (code
&& !strcmp (code
, "gs"))
5137 /* Avoid parens after '::'. */
5138 d_print_comp (dpi
, options
, operand
);
5139 else if (code
&& !strcmp (code
, "st"))
5140 /* Always print parens for sizeof (type). */
5142 d_append_char (dpi
, '(');
5143 d_print_comp (dpi
, options
, operand
);
5144 d_append_char (dpi
, ')');
5147 d_print_subexpr (dpi
, options
, operand
);
5151 case DEMANGLE_COMPONENT_BINARY
:
5152 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5154 d_print_error (dpi
);
5158 if (op_is_new_cast (d_left (dc
)))
5160 d_print_expr_op (dpi
, options
, d_left (dc
));
5161 d_append_char (dpi
, '<');
5162 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5163 d_append_string (dpi
, ">(");
5164 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5165 d_append_char (dpi
, ')');
5169 /* We wrap an expression which uses the greater-than operator in
5170 an extra layer of parens so that it does not get confused
5171 with the '>' which ends the template parameters. */
5172 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5173 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5174 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5175 d_append_char (dpi
, '(');
5177 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5178 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5180 /* Function call used in an expression should not have printed types
5181 of the function arguments. Values of the function arguments still
5182 get printed below. */
5184 const struct demangle_component
*func
= d_left (d_right (dc
));
5186 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5187 d_print_error (dpi
);
5188 d_print_subexpr (dpi
, options
, d_left (func
));
5191 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5192 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5194 d_append_char (dpi
, '[');
5195 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5196 d_append_char (dpi
, ']');
5200 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5201 d_print_expr_op (dpi
, options
, d_left (dc
));
5202 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5205 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5206 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5207 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5208 d_append_char (dpi
, ')');
5212 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5213 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5214 d_print_error (dpi
);
5217 case DEMANGLE_COMPONENT_TRINARY
:
5218 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5219 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5221 d_print_error (dpi
);
5225 struct demangle_component
*op
= d_left (dc
);
5226 struct demangle_component
*first
= d_left (d_right (dc
));
5227 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5228 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5230 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5232 d_print_subexpr (dpi
, options
, first
);
5233 d_print_expr_op (dpi
, options
, op
);
5234 d_print_subexpr (dpi
, options
, second
);
5235 d_append_string (dpi
, " : ");
5236 d_print_subexpr (dpi
, options
, third
);
5240 d_append_string (dpi
, "new ");
5241 if (d_left (first
) != NULL
)
5243 d_print_subexpr (dpi
, options
, first
);
5244 d_append_char (dpi
, ' ');
5246 d_print_comp (dpi
, options
, second
);
5248 d_print_subexpr (dpi
, options
, third
);
5253 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5254 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5255 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5256 d_print_error (dpi
);
5259 case DEMANGLE_COMPONENT_LITERAL
:
5260 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5262 enum d_builtin_type_print tp
;
5264 /* For some builtin types, produce simpler output. */
5265 tp
= D_PRINT_DEFAULT
;
5266 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5268 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5272 case D_PRINT_UNSIGNED
:
5274 case D_PRINT_UNSIGNED_LONG
:
5275 case D_PRINT_LONG_LONG
:
5276 case D_PRINT_UNSIGNED_LONG_LONG
:
5277 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5279 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5280 d_append_char (dpi
, '-');
5281 d_print_comp (dpi
, options
, d_right (dc
));
5286 case D_PRINT_UNSIGNED
:
5287 d_append_char (dpi
, 'u');
5290 d_append_char (dpi
, 'l');
5292 case D_PRINT_UNSIGNED_LONG
:
5293 d_append_string (dpi
, "ul");
5295 case D_PRINT_LONG_LONG
:
5296 d_append_string (dpi
, "ll");
5298 case D_PRINT_UNSIGNED_LONG_LONG
:
5299 d_append_string (dpi
, "ull");
5307 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5308 && d_right (dc
)->u
.s_name
.len
== 1
5309 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5311 switch (d_right (dc
)->u
.s_name
.s
[0])
5314 d_append_string (dpi
, "false");
5317 d_append_string (dpi
, "true");
5330 d_append_char (dpi
, '(');
5331 d_print_comp (dpi
, options
, d_left (dc
));
5332 d_append_char (dpi
, ')');
5333 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5334 d_append_char (dpi
, '-');
5335 if (tp
== D_PRINT_FLOAT
)
5336 d_append_char (dpi
, '[');
5337 d_print_comp (dpi
, options
, d_right (dc
));
5338 if (tp
== D_PRINT_FLOAT
)
5339 d_append_char (dpi
, ']');
5343 case DEMANGLE_COMPONENT_NUMBER
:
5344 d_append_num (dpi
, dc
->u
.s_number
.number
);
5347 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5348 d_append_string (dpi
, "java resource ");
5349 d_print_comp (dpi
, options
, d_left (dc
));
5352 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5353 d_print_comp (dpi
, options
, d_left (dc
));
5354 d_print_comp (dpi
, options
, d_right (dc
));
5357 case DEMANGLE_COMPONENT_CHARACTER
:
5358 d_append_char (dpi
, dc
->u
.s_character
.character
);
5361 case DEMANGLE_COMPONENT_DECLTYPE
:
5362 d_append_string (dpi
, "decltype (");
5363 d_print_comp (dpi
, options
, d_left (dc
));
5364 d_append_char (dpi
, ')');
5367 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5371 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5374 /* d_find_pack won't find anything if the only packs involved
5375 in this expansion are function parameter packs; in that
5376 case, just print the pattern and "...". */
5377 d_print_subexpr (dpi
, options
, d_left (dc
));
5378 d_append_string (dpi
, "...");
5382 len
= d_pack_length (a
);
5384 for (i
= 0; i
< len
; ++i
)
5386 dpi
->pack_index
= i
;
5387 d_print_comp (dpi
, options
, dc
);
5389 d_append_string (dpi
, ", ");
5394 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5396 long num
= dc
->u
.s_number
.number
;
5398 d_append_string (dpi
, "this");
5401 d_append_string (dpi
, "{parm#");
5402 d_append_num (dpi
, num
);
5403 d_append_char (dpi
, '}');
5408 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5409 d_append_string (dpi
, "global constructors keyed to ");
5410 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5413 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5414 d_append_string (dpi
, "global destructors keyed to ");
5415 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5418 case DEMANGLE_COMPONENT_LAMBDA
:
5419 d_append_string (dpi
, "{lambda(");
5420 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5421 d_append_string (dpi
, ")#");
5422 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5423 d_append_char (dpi
, '}');
5426 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5427 d_append_string (dpi
, "{unnamed type#");
5428 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5429 d_append_char (dpi
, '}');
5432 case DEMANGLE_COMPONENT_CLONE
:
5433 d_print_comp (dpi
, options
, d_left (dc
));
5434 d_append_string (dpi
, " [clone ");
5435 d_print_comp (dpi
, options
, d_right (dc
));
5436 d_append_char (dpi
, ']');
5440 d_print_error (dpi
);
5446 d_print_comp (struct d_print_info
*dpi
, int options
,
5447 const struct demangle_component
*dc
)
5449 struct d_component_stack self
;
5452 self
.parent
= dpi
->component_stack
;
5453 dpi
->component_stack
= &self
;
5455 d_print_comp_inner (dpi
, options
, dc
);
5457 dpi
->component_stack
= self
.parent
;
5460 /* Print a Java dentifier. For Java we try to handle encoded extended
5461 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5462 so we don't it for C++. Characters are encoded as
5466 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5472 for (p
= name
; p
< end
; ++p
)
5483 for (q
= p
+ 3; q
< end
; ++q
)
5489 else if (*q
>= 'A' && *q
<= 'F')
5490 dig
= *q
- 'A' + 10;
5491 else if (*q
>= 'a' && *q
<= 'f')
5492 dig
= *q
- 'a' + 10;
5498 /* If the Unicode character is larger than 256, we don't try
5499 to deal with it here. FIXME. */
5500 if (q
< end
&& *q
== '_' && c
< 256)
5502 d_append_char (dpi
, c
);
5508 d_append_char (dpi
, *p
);
5512 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5513 qualifiers on this after printing a function. */
5516 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5517 struct d_print_mod
*mods
, int suffix
)
5519 struct d_print_template
*hold_dpt
;
5521 if (mods
== NULL
|| d_print_saw_error (dpi
))
5526 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5527 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5528 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5529 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5530 || mods
->mod
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
5532 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5534 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5540 hold_dpt
= dpi
->templates
;
5541 dpi
->templates
= mods
->templates
;
5543 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5545 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5546 dpi
->templates
= hold_dpt
;
5549 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5551 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5552 dpi
->templates
= hold_dpt
;
5555 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5557 struct d_print_mod
*hold_modifiers
;
5558 struct demangle_component
*dc
;
5560 /* When this is on the modifier stack, we have pulled any
5561 qualifiers off the right argument already. Otherwise, we
5562 print it as usual, but don't let the left argument see any
5565 hold_modifiers
= dpi
->modifiers
;
5566 dpi
->modifiers
= NULL
;
5567 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5568 dpi
->modifiers
= hold_modifiers
;
5570 if ((options
& DMGL_JAVA
) == 0)
5571 d_append_string (dpi
, "::");
5573 d_append_char (dpi
, '.');
5575 dc
= d_right (mods
->mod
);
5577 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5579 d_append_string (dpi
, "{default arg#");
5580 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5581 d_append_string (dpi
, "}::");
5582 dc
= dc
->u
.s_unary_num
.sub
;
5585 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5586 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5587 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5588 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5589 || dc
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
5590 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5593 d_print_comp (dpi
, options
, dc
);
5595 dpi
->templates
= hold_dpt
;
5599 d_print_mod (dpi
, options
, mods
->mod
);
5601 dpi
->templates
= hold_dpt
;
5603 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5606 /* Print a modifier. */
5609 d_print_mod (struct d_print_info
*dpi
, int options
,
5610 const struct demangle_component
*mod
)
5614 case DEMANGLE_COMPONENT_RESTRICT
:
5615 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5616 d_append_string (dpi
, " restrict");
5618 case DEMANGLE_COMPONENT_VOLATILE
:
5619 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5620 d_append_string (dpi
, " volatile");
5622 case DEMANGLE_COMPONENT_CONST
:
5623 case DEMANGLE_COMPONENT_CONST_THIS
:
5624 d_append_string (dpi
, " const");
5626 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5627 d_append_string (dpi
, " transaction_safe");
5629 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5630 d_append_char (dpi
, ' ');
5631 d_print_comp (dpi
, options
, d_right (mod
));
5633 case DEMANGLE_COMPONENT_POINTER
:
5634 /* There is no pointer symbol in Java. */
5635 if ((options
& DMGL_JAVA
) == 0)
5636 d_append_char (dpi
, '*');
5638 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5639 /* For the ref-qualifier, put a space before the &. */
5640 d_append_char (dpi
, ' ');
5641 case DEMANGLE_COMPONENT_REFERENCE
:
5642 d_append_char (dpi
, '&');
5644 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5645 d_append_char (dpi
, ' ');
5646 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5647 d_append_string (dpi
, "&&");
5649 case DEMANGLE_COMPONENT_COMPLEX
:
5650 d_append_string (dpi
, "complex ");
5652 case DEMANGLE_COMPONENT_IMAGINARY
:
5653 d_append_string (dpi
, "imaginary ");
5655 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5656 if (d_last_char (dpi
) != '(')
5657 d_append_char (dpi
, ' ');
5658 d_print_comp (dpi
, options
, d_left (mod
));
5659 d_append_string (dpi
, "::*");
5661 case DEMANGLE_COMPONENT_TYPED_NAME
:
5662 d_print_comp (dpi
, options
, d_left (mod
));
5664 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5665 d_append_string (dpi
, " __vector(");
5666 d_print_comp (dpi
, options
, d_left (mod
));
5667 d_append_char (dpi
, ')');
5671 /* Otherwise, we have something that won't go back on the
5672 modifier stack, so we can just print it. */
5673 d_print_comp (dpi
, options
, mod
);
5678 /* Print a function type, except for the return type. */
5681 d_print_function_type (struct d_print_info
*dpi
, int options
,
5682 const struct demangle_component
*dc
,
5683 struct d_print_mod
*mods
)
5687 struct d_print_mod
*p
;
5688 struct d_print_mod
*hold_modifiers
;
5692 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5697 switch (p
->mod
->type
)
5699 case DEMANGLE_COMPONENT_POINTER
:
5700 case DEMANGLE_COMPONENT_REFERENCE
:
5701 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5704 case DEMANGLE_COMPONENT_RESTRICT
:
5705 case DEMANGLE_COMPONENT_VOLATILE
:
5706 case DEMANGLE_COMPONENT_CONST
:
5707 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5708 case DEMANGLE_COMPONENT_COMPLEX
:
5709 case DEMANGLE_COMPONENT_IMAGINARY
:
5710 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5714 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5715 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5716 case DEMANGLE_COMPONENT_CONST_THIS
:
5717 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5718 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5719 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5732 if (d_last_char (dpi
) != '('
5733 && d_last_char (dpi
) != '*')
5736 if (need_space
&& d_last_char (dpi
) != ' ')
5737 d_append_char (dpi
, ' ');
5738 d_append_char (dpi
, '(');
5741 hold_modifiers
= dpi
->modifiers
;
5742 dpi
->modifiers
= NULL
;
5744 d_print_mod_list (dpi
, options
, mods
, 0);
5747 d_append_char (dpi
, ')');
5749 d_append_char (dpi
, '(');
5751 if (d_right (dc
) != NULL
)
5752 d_print_comp (dpi
, options
, d_right (dc
));
5754 d_append_char (dpi
, ')');
5756 d_print_mod_list (dpi
, options
, mods
, 1);
5758 dpi
->modifiers
= hold_modifiers
;
5761 /* Print an array type, except for the element type. */
5764 d_print_array_type (struct d_print_info
*dpi
, int options
,
5765 const struct demangle_component
*dc
,
5766 struct d_print_mod
*mods
)
5774 struct d_print_mod
*p
;
5777 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5781 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5796 d_append_string (dpi
, " (");
5798 d_print_mod_list (dpi
, options
, mods
, 0);
5801 d_append_char (dpi
, ')');
5805 d_append_char (dpi
, ' ');
5807 d_append_char (dpi
, '[');
5809 if (d_left (dc
) != NULL
)
5810 d_print_comp (dpi
, options
, d_left (dc
));
5812 d_append_char (dpi
, ']');
5815 /* Print an operator in an expression. */
5818 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5819 const struct demangle_component
*dc
)
5821 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5822 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5823 dc
->u
.s_operator
.op
->len
);
5825 d_print_comp (dpi
, options
, dc
);
5831 d_print_cast (struct d_print_info
*dpi
, int options
,
5832 const struct demangle_component
*dc
)
5834 d_print_comp (dpi
, options
, d_left (dc
));
5837 /* Print a conversion operator. */
5840 d_print_conversion (struct d_print_info
*dpi
, int options
,
5841 const struct demangle_component
*dc
)
5843 struct d_print_template dpt
;
5845 /* For a conversion operator, we need the template parameters from
5846 the enclosing template in scope for processing the type. */
5847 if (dpi
->current_template
!= NULL
)
5849 dpt
.next
= dpi
->templates
;
5850 dpi
->templates
= &dpt
;
5851 dpt
.template_decl
= dpi
->current_template
;
5854 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5856 d_print_comp (dpi
, options
, d_left (dc
));
5857 if (dpi
->current_template
!= NULL
)
5858 dpi
->templates
= dpt
.next
;
5862 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5864 /* For a templated cast operator, we need to remove the template
5865 parameters from scope after printing the operator name,
5866 so we need to handle the template printing here. */
5867 if (dpi
->current_template
!= NULL
)
5868 dpi
->templates
= dpt
.next
;
5870 if (d_last_char (dpi
) == '<')
5871 d_append_char (dpi
, ' ');
5872 d_append_char (dpi
, '<');
5873 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5874 /* Avoid generating two consecutive '>' characters, to avoid
5875 the C++ syntactic ambiguity. */
5876 if (d_last_char (dpi
) == '>')
5877 d_append_char (dpi
, ' ');
5878 d_append_char (dpi
, '>');
5882 /* Initialize the information structure we use to pass around
5885 CP_STATIC_IF_GLIBCPP_V3
5887 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5891 di
->send
= mangled
+ len
;
5892 di
->options
= options
;
5896 /* We can not need more components than twice the number of chars in
5897 the mangled string. Most components correspond directly to
5898 chars, but the ARGLIST types are exceptions. */
5899 di
->num_comps
= 2 * len
;
5902 /* Similarly, we can not need more substitutions than there are
5903 chars in the mangled string. */
5908 di
->last_name
= NULL
;
5911 di
->is_expression
= 0;
5912 di
->is_conversion
= 0;
5915 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5916 mangled name, return strings in repeated callback giving the demangled
5917 name. OPTIONS is the usual libiberty demangler options. On success,
5918 this returns 1. On failure, returns 0. */
5921 d_demangle_callback (const char *mangled
, int options
,
5922 demangle_callbackref callback
, void *opaque
)
5933 struct demangle_component
*dc
;
5936 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5938 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5939 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5940 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5941 && mangled
[10] == '_')
5942 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5945 if ((options
& DMGL_TYPES
) == 0)
5950 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5953 #ifdef CP_DYNAMIC_ARRAYS
5954 __extension__
struct demangle_component comps
[di
.num_comps
];
5955 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5960 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5961 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5967 dc
= cplus_demangle_type (&di
);
5970 dc
= cplus_demangle_mangled_name (&di
, 1);
5972 case DCT_GLOBAL_CTORS
:
5973 case DCT_GLOBAL_DTORS
:
5974 d_advance (&di
, 11);
5975 dc
= d_make_comp (&di
,
5976 (type
== DCT_GLOBAL_CTORS
5977 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5978 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5979 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5981 d_advance (&di
, strlen (d_str (&di
)));
5984 abort (); /* We have listed all the cases. */
5987 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5988 mangled string, then we didn't successfully demangle it. If
5989 DMGL_PARAMS is not set, we didn't look at the trailing
5991 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5994 #ifdef CP_DEMANGLE_DEBUG
5998 status
= (dc
!= NULL
)
5999 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6006 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6007 name, return a buffer allocated with malloc holding the demangled
6008 name. OPTIONS is the usual libiberty demangler options. On
6009 success, this sets *PALC to the allocated size of the returned
6010 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6011 a memory allocation failure, and returns NULL. */
6014 d_demangle (const char *mangled
, int options
, size_t *palc
)
6016 struct d_growable_string dgs
;
6019 d_growable_string_init (&dgs
, 0);
6021 status
= d_demangle_callback (mangled
, options
,
6022 d_growable_string_callback_adapter
, &dgs
);
6030 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6034 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6036 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6038 /* ia64 ABI-mandated entry point in the C++ runtime library for
6039 performing demangling. MANGLED_NAME is a NUL-terminated character
6040 string containing the name to be demangled.
6042 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6043 *LENGTH bytes, into which the demangled name is stored. If
6044 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6045 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6046 is placed in a region of memory allocated with malloc.
6048 If LENGTH is non-NULL, the length of the buffer containing the
6049 demangled name, is placed in *LENGTH.
6051 The return value is a pointer to the start of the NUL-terminated
6052 demangled name, or NULL if the demangling fails. The caller is
6053 responsible for deallocating this memory using free.
6055 *STATUS is set to one of the following values:
6056 0: The demangling operation succeeded.
6057 -1: A memory allocation failure occurred.
6058 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6059 -3: One of the arguments is invalid.
6061 The demangling is performed using the C++ ABI mangling rules, with
6065 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6066 size_t *length
, int *status
)
6071 if (mangled_name
== NULL
)
6078 if (output_buffer
!= NULL
&& length
== NULL
)
6085 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6087 if (demangled
== NULL
)
6099 if (output_buffer
== NULL
)
6106 if (strlen (demangled
) < *length
)
6108 strcpy (output_buffer
, demangled
);
6110 demangled
= output_buffer
;
6114 free (output_buffer
);
6125 extern int __gcclibcxx_demangle_callback (const char *,
6127 (const char *, size_t, void *),
6130 /* Alternative, allocationless entry point in the C++ runtime library
6131 for performing demangling. MANGLED_NAME is a NUL-terminated character
6132 string containing the name to be demangled.
6134 CALLBACK is a callback function, called with demangled string
6135 segments as demangling progresses; it is called at least once,
6136 but may be called more than once. OPAQUE is a generalized pointer
6137 used as a callback argument.
6139 The return code is one of the following values, equivalent to
6140 the STATUS values of __cxa_demangle() (excluding -1, since this
6141 function performs no memory allocations):
6142 0: The demangling operation succeeded.
6143 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6144 -3: One of the arguments is invalid.
6146 The demangling is performed using the C++ ABI mangling rules, with
6150 __gcclibcxx_demangle_callback (const char *mangled_name
,
6151 void (*callback
) (const char *, size_t, void *),
6156 if (mangled_name
== NULL
|| callback
== NULL
)
6159 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6167 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6169 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6170 mangled name, return a buffer allocated with malloc holding the
6171 demangled name. Otherwise, return NULL. */
6174 cplus_demangle_v3 (const char *mangled
, int options
)
6178 return d_demangle (mangled
, options
, &alc
);
6182 cplus_demangle_v3_callback (const char *mangled
, int options
,
6183 demangle_callbackref callback
, void *opaque
)
6185 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6188 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6189 conventions, but the output formatting is a little different.
6190 This instructs the C++ demangler not to emit pointer characters ("*"), to
6191 use Java's namespace separator symbol ("." instead of "::"), and to output
6192 JArray<TYPE> as TYPE[]. */
6195 java_demangle_v3 (const char *mangled
)
6199 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6203 java_demangle_v3_callback (const char *mangled
,
6204 demangle_callbackref callback
, void *opaque
)
6206 return d_demangle_callback (mangled
,
6207 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6211 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6213 #ifndef IN_GLIBCPP_V3
6215 /* Demangle a string in order to find out whether it is a constructor
6216 or destructor. Return non-zero on success. Set *CTOR_KIND and
6217 *DTOR_KIND appropriately. */
6220 is_ctor_or_dtor (const char *mangled
,
6221 enum gnu_v3_ctor_kinds
*ctor_kind
,
6222 enum gnu_v3_dtor_kinds
*dtor_kind
)
6225 struct demangle_component
*dc
;
6228 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6229 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6231 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6234 #ifdef CP_DYNAMIC_ARRAYS
6235 __extension__
struct demangle_component comps
[di
.num_comps
];
6236 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6241 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6242 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6245 dc
= cplus_demangle_mangled_name (&di
, 1);
6247 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6248 to demangle the entire string. */
6255 /* These cannot appear on a constructor or destructor. */
6256 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6257 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6258 case DEMANGLE_COMPONENT_CONST_THIS
:
6259 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6260 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6261 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
6265 case DEMANGLE_COMPONENT_TYPED_NAME
:
6266 case DEMANGLE_COMPONENT_TEMPLATE
:
6269 case DEMANGLE_COMPONENT_QUAL_NAME
:
6270 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6273 case DEMANGLE_COMPONENT_CTOR
:
6274 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6278 case DEMANGLE_COMPONENT_DTOR
:
6279 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6290 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6291 name. A non-zero return indicates the type of constructor. */
6293 enum gnu_v3_ctor_kinds
6294 is_gnu_v3_mangled_ctor (const char *name
)
6296 enum gnu_v3_ctor_kinds ctor_kind
;
6297 enum gnu_v3_dtor_kinds dtor_kind
;
6299 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6300 return (enum gnu_v3_ctor_kinds
) 0;
6305 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6306 name. A non-zero return indicates the type of destructor. */
6308 enum gnu_v3_dtor_kinds
6309 is_gnu_v3_mangled_dtor (const char *name
)
6311 enum gnu_v3_ctor_kinds ctor_kind
;
6312 enum gnu_v3_dtor_kinds dtor_kind
;
6314 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6315 return (enum gnu_v3_dtor_kinds
) 0;
6319 #endif /* IN_GLIBCPP_V3 */
6321 #ifdef STANDALONE_DEMANGLER
6324 #include "dyn-string.h"
6326 static void print_usage (FILE* fp
, int exit_value
);
6328 #define IS_ALPHA(CHAR) \
6329 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6330 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6332 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6333 #define is_mangled_char(CHAR) \
6334 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6335 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6337 /* The name of this program, as invoked. */
6338 const char* program_name
;
6340 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6343 print_usage (FILE* fp
, int exit_value
)
6345 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6346 fprintf (fp
, "Options:\n");
6347 fprintf (fp
, " -h,--help Display this message.\n");
6348 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6349 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6350 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6355 /* Option specification for getopt_long. */
6356 static const struct option long_options
[] =
6358 { "help", no_argument
, NULL
, 'h' },
6359 { "no-params", no_argument
, NULL
, 'p' },
6360 { "verbose", no_argument
, NULL
, 'v' },
6361 { NULL
, no_argument
, NULL
, 0 },
6364 /* Main entry for a demangling filter executable. It will demangle
6365 its command line arguments, if any. If none are provided, it will
6366 filter stdin to stdout, replacing any recognized mangled C++ names
6367 with their demangled equivalents. */
6370 main (int argc
, char *argv
[])
6374 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6376 /* Use the program name of this program, as invoked. */
6377 program_name
= argv
[0];
6379 /* Parse options. */
6382 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6385 case '?': /* Unrecognized option. */
6386 print_usage (stderr
, 1);
6390 print_usage (stdout
, 0);
6394 options
&= ~ DMGL_PARAMS
;
6398 options
|= DMGL_VERBOSE
;
6402 while (opt_char
!= -1);
6405 /* No command line arguments were provided. Filter stdin. */
6407 dyn_string_t mangled
= dyn_string_new (3);
6410 /* Read all of input. */
6411 while (!feof (stdin
))
6415 /* Pile characters into mangled until we hit one that can't
6416 occur in a mangled name. */
6418 while (!feof (stdin
) && is_mangled_char (c
))
6420 dyn_string_append_char (mangled
, c
);
6426 if (dyn_string_length (mangled
) > 0)
6428 #ifdef IN_GLIBCPP_V3
6429 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6431 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6441 /* It might not have been a mangled name. Print the
6443 fputs (dyn_string_buf (mangled
), stdout
);
6446 dyn_string_clear (mangled
);
6449 /* If we haven't hit EOF yet, we've read one character that
6450 can't occur in a mangled name, so print it out. */
6455 dyn_string_delete (mangled
);
6458 /* Demangle command line arguments. */
6460 /* Loop over command line arguments. */
6461 for (i
= optind
; i
< argc
; ++i
)
6464 #ifdef IN_GLIBCPP_V3
6468 /* Attempt to demangle. */
6469 #ifdef IN_GLIBCPP_V3
6470 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6472 s
= cplus_demangle_v3 (argv
[i
], options
);
6475 /* If it worked, print the demangled name. */
6483 #ifdef IN_GLIBCPP_V3
6484 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6486 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6495 #endif /* STANDALONE_DEMANGLER */