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 __extension__
struct d_saved_scope scopes
[dpi
.num_saved_scopes
];
4132 __extension__
struct d_print_template temps
[dpi
.num_copy_templates
];
4134 dpi
.saved_scopes
= scopes
;
4135 dpi
.copy_templates
= temps
;
4137 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4138 * sizeof (*dpi
.saved_scopes
));
4139 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4140 * sizeof (*dpi
.copy_templates
));
4143 d_print_comp (&dpi
, options
, dc
);
4146 d_print_flush (&dpi
);
4148 return ! d_print_saw_error (&dpi
);
4151 /* Turn components into a human readable string. OPTIONS is the
4152 options bits passed to the demangler. DC is the tree to print.
4153 ESTIMATE is a guess at the length of the result. This returns a
4154 string allocated by malloc, or NULL on error. On success, this
4155 sets *PALC to the size of the allocated buffer. On failure, this
4156 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4159 CP_STATIC_IF_GLIBCPP_V3
4161 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4162 int estimate
, size_t *palc
)
4164 struct d_growable_string dgs
;
4166 d_growable_string_init (&dgs
, estimate
);
4168 if (! cplus_demangle_print_callback (options
, dc
,
4169 d_growable_string_callback_adapter
,
4177 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4181 /* Returns the I'th element of the template arglist ARGS, or NULL on
4184 static struct demangle_component
*
4185 d_index_template_argument (struct demangle_component
*args
, int i
)
4187 struct demangle_component
*a
;
4193 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4199 if (i
!= 0 || a
== NULL
)
4205 /* Returns the template argument from the current context indicated by DC,
4206 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4208 static struct demangle_component
*
4209 d_lookup_template_argument (struct d_print_info
*dpi
,
4210 const struct demangle_component
*dc
)
4212 if (dpi
->templates
== NULL
)
4214 d_print_error (dpi
);
4218 return d_index_template_argument
4219 (d_right (dpi
->templates
->template_decl
),
4220 dc
->u
.s_number
.number
);
4223 /* Returns a template argument pack used in DC (any will do), or NULL. */
4225 static struct demangle_component
*
4226 d_find_pack (struct d_print_info
*dpi
,
4227 const struct demangle_component
*dc
)
4229 struct demangle_component
*a
;
4235 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4236 a
= d_lookup_template_argument (dpi
, dc
);
4237 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4241 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4244 case DEMANGLE_COMPONENT_LAMBDA
:
4245 case DEMANGLE_COMPONENT_NAME
:
4246 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4247 case DEMANGLE_COMPONENT_OPERATOR
:
4248 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4249 case DEMANGLE_COMPONENT_SUB_STD
:
4250 case DEMANGLE_COMPONENT_CHARACTER
:
4251 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4252 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4253 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4254 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4255 case DEMANGLE_COMPONENT_NUMBER
:
4258 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4259 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4260 case DEMANGLE_COMPONENT_CTOR
:
4261 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4262 case DEMANGLE_COMPONENT_DTOR
:
4263 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4266 a
= d_find_pack (dpi
, d_left (dc
));
4269 return d_find_pack (dpi
, d_right (dc
));
4273 /* Returns the length of the template argument pack DC. */
4276 d_pack_length (const struct demangle_component
*dc
)
4279 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4280 && d_left (dc
) != NULL
)
4288 /* DC is a component of a mangled expression. Print it, wrapped in parens
4292 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4293 const struct demangle_component
*dc
)
4296 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4297 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4298 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4299 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4302 d_append_char (dpi
, '(');
4303 d_print_comp (dpi
, options
, dc
);
4305 d_append_char (dpi
, ')');
4308 /* Save the current scope. */
4311 d_save_scope (struct d_print_info
*dpi
,
4312 const struct demangle_component
*container
)
4314 struct d_saved_scope
*scope
;
4315 struct d_print_template
*src
, **link
;
4317 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4319 d_print_error (dpi
);
4322 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4323 dpi
->next_saved_scope
++;
4325 scope
->container
= container
;
4326 link
= &scope
->templates
;
4328 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4330 struct d_print_template
*dst
;
4332 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4334 d_print_error (dpi
);
4337 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4338 dpi
->next_copy_template
++;
4340 dst
->template_decl
= src
->template_decl
;
4348 /* Attempt to locate a previously saved scope. Returns NULL if no
4349 corresponding saved scope was found. */
4351 static struct d_saved_scope
*
4352 d_get_saved_scope (struct d_print_info
*dpi
,
4353 const struct demangle_component
*container
)
4357 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4358 if (dpi
->saved_scopes
[i
].container
== container
)
4359 return &dpi
->saved_scopes
[i
];
4364 /* Subroutine to handle components. */
4367 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
4368 const struct demangle_component
*dc
)
4370 /* Magic variable to let reference smashing skip over the next modifier
4371 without needing to modify *dc. */
4372 const struct demangle_component
*mod_inner
= NULL
;
4374 /* Variable used to store the current templates while a previously
4375 captured scope is used. */
4376 struct d_print_template
*saved_templates
;
4378 /* Nonzero if templates have been stored in the above variable. */
4379 int need_template_restore
= 0;
4383 d_print_error (dpi
);
4386 if (d_print_saw_error (dpi
))
4391 case DEMANGLE_COMPONENT_NAME
:
4392 if ((options
& DMGL_JAVA
) == 0)
4393 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4395 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4398 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4399 d_print_comp (dpi
, options
, d_left (dc
));
4400 d_append_string (dpi
, "[abi:");
4401 d_print_comp (dpi
, options
, d_right (dc
));
4402 d_append_char (dpi
, ']');
4405 case DEMANGLE_COMPONENT_QUAL_NAME
:
4406 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4407 d_print_comp (dpi
, options
, d_left (dc
));
4408 if ((options
& DMGL_JAVA
) == 0)
4409 d_append_string (dpi
, "::");
4411 d_append_char (dpi
, '.');
4413 struct demangle_component
*local_name
= d_right (dc
);
4414 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4416 d_append_string (dpi
, "{default arg#");
4417 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4418 d_append_string (dpi
, "}::");
4419 local_name
= local_name
->u
.s_unary_num
.sub
;
4421 d_print_comp (dpi
, options
, local_name
);
4425 case DEMANGLE_COMPONENT_TYPED_NAME
:
4427 struct d_print_mod
*hold_modifiers
;
4428 struct demangle_component
*typed_name
;
4429 struct d_print_mod adpm
[4];
4431 struct d_print_template dpt
;
4433 /* Pass the name down to the type so that it can be printed in
4434 the right place for the type. We also have to pass down
4435 any CV-qualifiers, which apply to the this parameter. */
4436 hold_modifiers
= dpi
->modifiers
;
4439 typed_name
= d_left (dc
);
4440 while (typed_name
!= NULL
)
4442 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4444 d_print_error (dpi
);
4448 adpm
[i
].next
= dpi
->modifiers
;
4449 dpi
->modifiers
= &adpm
[i
];
4450 adpm
[i
].mod
= typed_name
;
4451 adpm
[i
].printed
= 0;
4452 adpm
[i
].templates
= dpi
->templates
;
4455 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4456 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4457 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4458 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4459 && typed_name
->type
!= DEMANGLE_COMPONENT_TRANSACTION_SAFE
4460 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4463 typed_name
= d_left (typed_name
);
4466 if (typed_name
== NULL
)
4468 d_print_error (dpi
);
4472 /* If typed_name is a template, then it applies to the
4473 function type as well. */
4474 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4476 dpt
.next
= dpi
->templates
;
4477 dpi
->templates
= &dpt
;
4478 dpt
.template_decl
= typed_name
;
4481 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4482 there may be CV-qualifiers on its right argument which
4483 really apply here; this happens when parsing a class which
4484 is local to a function. */
4485 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4487 struct demangle_component
*local_name
;
4489 local_name
= d_right (typed_name
);
4490 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4491 local_name
= local_name
->u
.s_unary_num
.sub
;
4492 if (local_name
== NULL
)
4494 d_print_error (dpi
);
4497 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4498 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4499 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4500 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4501 || local_name
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
4502 || (local_name
->type
4503 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4505 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4507 d_print_error (dpi
);
4511 adpm
[i
] = adpm
[i
- 1];
4512 adpm
[i
].next
= &adpm
[i
- 1];
4513 dpi
->modifiers
= &adpm
[i
];
4515 adpm
[i
- 1].mod
= local_name
;
4516 adpm
[i
- 1].printed
= 0;
4517 adpm
[i
- 1].templates
= dpi
->templates
;
4520 local_name
= d_left (local_name
);
4524 d_print_comp (dpi
, options
, d_right (dc
));
4526 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4527 dpi
->templates
= dpt
.next
;
4529 /* If the modifiers didn't get printed by the type, print them
4534 if (! adpm
[i
].printed
)
4536 d_append_char (dpi
, ' ');
4537 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4541 dpi
->modifiers
= hold_modifiers
;
4546 case DEMANGLE_COMPONENT_TEMPLATE
:
4548 struct d_print_mod
*hold_dpm
;
4549 struct demangle_component
*dcl
;
4550 const struct demangle_component
*hold_current
;
4552 /* This template may need to be referenced by a cast operator
4553 contained in its subtree. */
4554 hold_current
= dpi
->current_template
;
4555 dpi
->current_template
= dc
;
4557 /* Don't push modifiers into a template definition. Doing so
4558 could give the wrong definition for a template argument.
4559 Instead, treat the template essentially as a name. */
4561 hold_dpm
= dpi
->modifiers
;
4562 dpi
->modifiers
= NULL
;
4566 if ((options
& DMGL_JAVA
) != 0
4567 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4568 && dcl
->u
.s_name
.len
== 6
4569 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4571 /* Special-case Java arrays, so that JArray<TYPE> appears
4572 instead as TYPE[]. */
4574 d_print_comp (dpi
, options
, d_right (dc
));
4575 d_append_string (dpi
, "[]");
4579 d_print_comp (dpi
, options
, dcl
);
4580 if (d_last_char (dpi
) == '<')
4581 d_append_char (dpi
, ' ');
4582 d_append_char (dpi
, '<');
4583 d_print_comp (dpi
, options
, d_right (dc
));
4584 /* Avoid generating two consecutive '>' characters, to avoid
4585 the C++ syntactic ambiguity. */
4586 if (d_last_char (dpi
) == '>')
4587 d_append_char (dpi
, ' ');
4588 d_append_char (dpi
, '>');
4591 dpi
->modifiers
= hold_dpm
;
4592 dpi
->current_template
= hold_current
;
4597 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4599 struct d_print_template
*hold_dpt
;
4600 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4602 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4603 a
= d_index_template_argument (a
, dpi
->pack_index
);
4607 d_print_error (dpi
);
4611 /* While processing this parameter, we need to pop the list of
4612 templates. This is because the template parameter may
4613 itself be a reference to a parameter of an outer
4616 hold_dpt
= dpi
->templates
;
4617 dpi
->templates
= hold_dpt
->next
;
4619 d_print_comp (dpi
, options
, a
);
4621 dpi
->templates
= hold_dpt
;
4626 case DEMANGLE_COMPONENT_CTOR
:
4627 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4630 case DEMANGLE_COMPONENT_DTOR
:
4631 d_append_char (dpi
, '~');
4632 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4635 case DEMANGLE_COMPONENT_VTABLE
:
4636 d_append_string (dpi
, "vtable for ");
4637 d_print_comp (dpi
, options
, d_left (dc
));
4640 case DEMANGLE_COMPONENT_VTT
:
4641 d_append_string (dpi
, "VTT for ");
4642 d_print_comp (dpi
, options
, d_left (dc
));
4645 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4646 d_append_string (dpi
, "construction vtable for ");
4647 d_print_comp (dpi
, options
, d_left (dc
));
4648 d_append_string (dpi
, "-in-");
4649 d_print_comp (dpi
, options
, d_right (dc
));
4652 case DEMANGLE_COMPONENT_TYPEINFO
:
4653 d_append_string (dpi
, "typeinfo for ");
4654 d_print_comp (dpi
, options
, d_left (dc
));
4657 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4658 d_append_string (dpi
, "typeinfo name for ");
4659 d_print_comp (dpi
, options
, d_left (dc
));
4662 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4663 d_append_string (dpi
, "typeinfo fn for ");
4664 d_print_comp (dpi
, options
, d_left (dc
));
4667 case DEMANGLE_COMPONENT_THUNK
:
4668 d_append_string (dpi
, "non-virtual thunk to ");
4669 d_print_comp (dpi
, options
, d_left (dc
));
4672 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4673 d_append_string (dpi
, "virtual thunk to ");
4674 d_print_comp (dpi
, options
, d_left (dc
));
4677 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4678 d_append_string (dpi
, "covariant return thunk to ");
4679 d_print_comp (dpi
, options
, d_left (dc
));
4682 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4683 d_append_string (dpi
, "java Class for ");
4684 d_print_comp (dpi
, options
, d_left (dc
));
4687 case DEMANGLE_COMPONENT_GUARD
:
4688 d_append_string (dpi
, "guard variable for ");
4689 d_print_comp (dpi
, options
, d_left (dc
));
4692 case DEMANGLE_COMPONENT_TLS_INIT
:
4693 d_append_string (dpi
, "TLS init function for ");
4694 d_print_comp (dpi
, options
, d_left (dc
));
4697 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4698 d_append_string (dpi
, "TLS wrapper function for ");
4699 d_print_comp (dpi
, options
, d_left (dc
));
4702 case DEMANGLE_COMPONENT_REFTEMP
:
4703 d_append_string (dpi
, "reference temporary #");
4704 d_print_comp (dpi
, options
, d_right (dc
));
4705 d_append_string (dpi
, " for ");
4706 d_print_comp (dpi
, options
, d_left (dc
));
4709 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4710 d_append_string (dpi
, "hidden alias for ");
4711 d_print_comp (dpi
, options
, d_left (dc
));
4714 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4715 d_append_string (dpi
, "transaction clone for ");
4716 d_print_comp (dpi
, options
, d_left (dc
));
4719 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4720 d_append_string (dpi
, "non-transaction clone for ");
4721 d_print_comp (dpi
, options
, d_left (dc
));
4724 case DEMANGLE_COMPONENT_SUB_STD
:
4725 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4728 case DEMANGLE_COMPONENT_RESTRICT
:
4729 case DEMANGLE_COMPONENT_VOLATILE
:
4730 case DEMANGLE_COMPONENT_CONST
:
4732 struct d_print_mod
*pdpm
;
4734 /* When printing arrays, it's possible to have cases where the
4735 same CV-qualifier gets pushed on the stack multiple times.
4736 We only need to print it once. */
4738 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4740 if (! pdpm
->printed
)
4742 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4743 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4744 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4746 if (pdpm
->mod
->type
== dc
->type
)
4748 d_print_comp (dpi
, options
, d_left (dc
));
4756 case DEMANGLE_COMPONENT_REFERENCE
:
4757 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4759 /* Handle reference smashing: & + && = &. */
4760 const struct demangle_component
*sub
= d_left (dc
);
4761 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4763 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4764 struct demangle_component
*a
;
4768 /* This is the first time SUB has been traversed.
4769 We need to capture the current templates so
4770 they can be restored if SUB is reentered as a
4772 d_save_scope (dpi
, sub
);
4773 if (d_print_saw_error (dpi
))
4778 const struct d_component_stack
*dcse
;
4779 int found_self_or_parent
= 0;
4781 /* This traversal is reentering SUB as a substition.
4782 If we are not beneath SUB or DC in the tree then we
4783 need to restore SUB's template stack temporarily. */
4784 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
4785 dcse
= dcse
->parent
)
4789 && dcse
!= dpi
->component_stack
))
4791 found_self_or_parent
= 1;
4796 if (!found_self_or_parent
)
4798 saved_templates
= dpi
->templates
;
4799 dpi
->templates
= scope
->templates
;
4800 need_template_restore
= 1;
4804 a
= d_lookup_template_argument (dpi
, sub
);
4805 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4806 a
= d_index_template_argument (a
, dpi
->pack_index
);
4810 if (need_template_restore
)
4811 dpi
->templates
= saved_templates
;
4813 d_print_error (dpi
);
4820 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4821 || sub
->type
== dc
->type
)
4823 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4824 mod_inner
= d_left (sub
);
4828 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4829 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4830 case DEMANGLE_COMPONENT_CONST_THIS
:
4831 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4832 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4833 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4834 case DEMANGLE_COMPONENT_POINTER
:
4835 case DEMANGLE_COMPONENT_COMPLEX
:
4836 case DEMANGLE_COMPONENT_IMAGINARY
:
4837 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4840 /* We keep a list of modifiers on the stack. */
4841 struct d_print_mod dpm
;
4843 dpm
.next
= dpi
->modifiers
;
4844 dpi
->modifiers
= &dpm
;
4847 dpm
.templates
= dpi
->templates
;
4850 mod_inner
= d_left (dc
);
4852 d_print_comp (dpi
, options
, mod_inner
);
4854 /* If the modifier didn't get printed by the type, print it
4857 d_print_mod (dpi
, options
, dc
);
4859 dpi
->modifiers
= dpm
.next
;
4861 if (need_template_restore
)
4862 dpi
->templates
= saved_templates
;
4867 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4868 if ((options
& DMGL_JAVA
) == 0)
4869 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4870 dc
->u
.s_builtin
.type
->len
);
4872 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4873 dc
->u
.s_builtin
.type
->java_len
);
4876 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4877 d_print_comp (dpi
, options
, d_left (dc
));
4880 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4882 if ((options
& DMGL_RET_POSTFIX
) != 0)
4883 d_print_function_type (dpi
,
4884 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4885 dc
, dpi
->modifiers
);
4887 /* Print return type if present */
4888 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4889 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4891 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4893 struct d_print_mod dpm
;
4895 /* We must pass this type down as a modifier in order to
4896 print it in the right location. */
4897 dpm
.next
= dpi
->modifiers
;
4898 dpi
->modifiers
= &dpm
;
4901 dpm
.templates
= dpi
->templates
;
4903 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4906 dpi
->modifiers
= dpm
.next
;
4911 /* In standard prefix notation, there is a space between the
4912 return type and the function signature. */
4913 if ((options
& DMGL_RET_POSTFIX
) == 0)
4914 d_append_char (dpi
, ' ');
4917 if ((options
& DMGL_RET_POSTFIX
) == 0)
4918 d_print_function_type (dpi
,
4919 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4920 dc
, dpi
->modifiers
);
4925 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4927 struct d_print_mod
*hold_modifiers
;
4928 struct d_print_mod adpm
[4];
4930 struct d_print_mod
*pdpm
;
4932 /* We must pass this type down as a modifier in order to print
4933 multi-dimensional arrays correctly. If the array itself is
4934 CV-qualified, we act as though the element type were
4935 CV-qualified. We do this by copying the modifiers down
4936 rather than fiddling pointers, so that we don't wind up
4937 with a d_print_mod higher on the stack pointing into our
4938 stack frame after we return. */
4940 hold_modifiers
= dpi
->modifiers
;
4942 adpm
[0].next
= hold_modifiers
;
4943 dpi
->modifiers
= &adpm
[0];
4945 adpm
[0].printed
= 0;
4946 adpm
[0].templates
= dpi
->templates
;
4949 pdpm
= hold_modifiers
;
4951 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4952 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4953 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4955 if (! pdpm
->printed
)
4957 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4959 d_print_error (dpi
);
4964 adpm
[i
].next
= dpi
->modifiers
;
4965 dpi
->modifiers
= &adpm
[i
];
4973 d_print_comp (dpi
, options
, d_right (dc
));
4975 dpi
->modifiers
= hold_modifiers
;
4977 if (adpm
[0].printed
)
4983 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4986 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4991 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4992 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4994 struct d_print_mod dpm
;
4996 dpm
.next
= dpi
->modifiers
;
4997 dpi
->modifiers
= &dpm
;
5000 dpm
.templates
= dpi
->templates
;
5002 d_print_comp (dpi
, options
, d_right (dc
));
5004 /* If the modifier didn't get printed by the type, print it
5007 d_print_mod (dpi
, options
, dc
);
5009 dpi
->modifiers
= dpm
.next
;
5014 case DEMANGLE_COMPONENT_FIXED_TYPE
:
5015 if (dc
->u
.s_fixed
.sat
)
5016 d_append_string (dpi
, "_Sat ");
5017 /* Don't print "int _Accum". */
5018 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
5019 != &cplus_demangle_builtin_types
['i'-'a'])
5021 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
5022 d_append_char (dpi
, ' ');
5024 if (dc
->u
.s_fixed
.accum
)
5025 d_append_string (dpi
, "_Accum");
5027 d_append_string (dpi
, "_Fract");
5030 case DEMANGLE_COMPONENT_ARGLIST
:
5031 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5032 if (d_left (dc
) != NULL
)
5033 d_print_comp (dpi
, options
, d_left (dc
));
5034 if (d_right (dc
) != NULL
)
5037 unsigned long int flush_count
;
5038 /* Make sure ", " isn't flushed by d_append_string, otherwise
5039 dpi->len -= 2 wouldn't work. */
5040 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5041 d_print_flush (dpi
);
5042 d_append_string (dpi
, ", ");
5044 flush_count
= dpi
->flush_count
;
5045 d_print_comp (dpi
, options
, d_right (dc
));
5046 /* If that didn't print anything (which can happen with empty
5047 template argument packs), remove the comma and space. */
5048 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5053 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5055 struct demangle_component
*type
= d_left (dc
);
5056 struct demangle_component
*list
= d_right (dc
);
5059 d_print_comp (dpi
, options
, type
);
5060 d_append_char (dpi
, '{');
5061 d_print_comp (dpi
, options
, list
);
5062 d_append_char (dpi
, '}');
5066 case DEMANGLE_COMPONENT_OPERATOR
:
5068 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5071 d_append_string (dpi
, "operator");
5072 /* Add a space before new/delete. */
5073 if (IS_LOWER (op
->name
[0]))
5074 d_append_char (dpi
, ' ');
5075 /* Omit a trailing space. */
5076 if (op
->name
[len
-1] == ' ')
5078 d_append_buffer (dpi
, op
->name
, len
);
5082 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5083 d_append_string (dpi
, "operator ");
5084 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5087 case DEMANGLE_COMPONENT_CONVERSION
:
5088 d_append_string (dpi
, "operator ");
5089 d_print_conversion (dpi
, options
, dc
);
5092 case DEMANGLE_COMPONENT_NULLARY
:
5093 d_print_expr_op (dpi
, options
, d_left (dc
));
5096 case DEMANGLE_COMPONENT_UNARY
:
5098 struct demangle_component
*op
= d_left (dc
);
5099 struct demangle_component
*operand
= d_right (dc
);
5100 const char *code
= NULL
;
5102 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5104 code
= op
->u
.s_operator
.op
->code
;
5105 if (!strcmp (code
, "ad"))
5107 /* Don't print the argument list for the address of a
5109 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5110 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5111 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5112 operand
= d_left (operand
);
5114 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5116 /* This indicates a suffix operator. */
5117 operand
= d_left (operand
);
5118 d_print_subexpr (dpi
, options
, operand
);
5119 d_print_expr_op (dpi
, options
, op
);
5124 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5125 d_print_expr_op (dpi
, options
, op
);
5128 d_append_char (dpi
, '(');
5129 d_print_cast (dpi
, options
, op
);
5130 d_append_char (dpi
, ')');
5132 if (code
&& !strcmp (code
, "gs"))
5133 /* Avoid parens after '::'. */
5134 d_print_comp (dpi
, options
, operand
);
5135 else if (code
&& !strcmp (code
, "st"))
5136 /* Always print parens for sizeof (type). */
5138 d_append_char (dpi
, '(');
5139 d_print_comp (dpi
, options
, operand
);
5140 d_append_char (dpi
, ')');
5143 d_print_subexpr (dpi
, options
, operand
);
5147 case DEMANGLE_COMPONENT_BINARY
:
5148 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5150 d_print_error (dpi
);
5154 if (op_is_new_cast (d_left (dc
)))
5156 d_print_expr_op (dpi
, options
, d_left (dc
));
5157 d_append_char (dpi
, '<');
5158 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5159 d_append_string (dpi
, ">(");
5160 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5161 d_append_char (dpi
, ')');
5165 /* We wrap an expression which uses the greater-than operator in
5166 an extra layer of parens so that it does not get confused
5167 with the '>' which ends the template parameters. */
5168 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5169 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5170 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5171 d_append_char (dpi
, '(');
5173 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5174 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5176 /* Function call used in an expression should not have printed types
5177 of the function arguments. Values of the function arguments still
5178 get printed below. */
5180 const struct demangle_component
*func
= d_left (d_right (dc
));
5182 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5183 d_print_error (dpi
);
5184 d_print_subexpr (dpi
, options
, d_left (func
));
5187 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5188 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5190 d_append_char (dpi
, '[');
5191 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5192 d_append_char (dpi
, ']');
5196 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5197 d_print_expr_op (dpi
, options
, d_left (dc
));
5198 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5201 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5202 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5203 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5204 d_append_char (dpi
, ')');
5208 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5209 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5210 d_print_error (dpi
);
5213 case DEMANGLE_COMPONENT_TRINARY
:
5214 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5215 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5217 d_print_error (dpi
);
5221 struct demangle_component
*op
= d_left (dc
);
5222 struct demangle_component
*first
= d_left (d_right (dc
));
5223 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5224 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5226 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5228 d_print_subexpr (dpi
, options
, first
);
5229 d_print_expr_op (dpi
, options
, op
);
5230 d_print_subexpr (dpi
, options
, second
);
5231 d_append_string (dpi
, " : ");
5232 d_print_subexpr (dpi
, options
, third
);
5236 d_append_string (dpi
, "new ");
5237 if (d_left (first
) != NULL
)
5239 d_print_subexpr (dpi
, options
, first
);
5240 d_append_char (dpi
, ' ');
5242 d_print_comp (dpi
, options
, second
);
5244 d_print_subexpr (dpi
, options
, third
);
5249 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5250 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5251 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5252 d_print_error (dpi
);
5255 case DEMANGLE_COMPONENT_LITERAL
:
5256 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5258 enum d_builtin_type_print tp
;
5260 /* For some builtin types, produce simpler output. */
5261 tp
= D_PRINT_DEFAULT
;
5262 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5264 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5268 case D_PRINT_UNSIGNED
:
5270 case D_PRINT_UNSIGNED_LONG
:
5271 case D_PRINT_LONG_LONG
:
5272 case D_PRINT_UNSIGNED_LONG_LONG
:
5273 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5275 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5276 d_append_char (dpi
, '-');
5277 d_print_comp (dpi
, options
, d_right (dc
));
5282 case D_PRINT_UNSIGNED
:
5283 d_append_char (dpi
, 'u');
5286 d_append_char (dpi
, 'l');
5288 case D_PRINT_UNSIGNED_LONG
:
5289 d_append_string (dpi
, "ul");
5291 case D_PRINT_LONG_LONG
:
5292 d_append_string (dpi
, "ll");
5294 case D_PRINT_UNSIGNED_LONG_LONG
:
5295 d_append_string (dpi
, "ull");
5303 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5304 && d_right (dc
)->u
.s_name
.len
== 1
5305 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5307 switch (d_right (dc
)->u
.s_name
.s
[0])
5310 d_append_string (dpi
, "false");
5313 d_append_string (dpi
, "true");
5326 d_append_char (dpi
, '(');
5327 d_print_comp (dpi
, options
, d_left (dc
));
5328 d_append_char (dpi
, ')');
5329 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5330 d_append_char (dpi
, '-');
5331 if (tp
== D_PRINT_FLOAT
)
5332 d_append_char (dpi
, '[');
5333 d_print_comp (dpi
, options
, d_right (dc
));
5334 if (tp
== D_PRINT_FLOAT
)
5335 d_append_char (dpi
, ']');
5339 case DEMANGLE_COMPONENT_NUMBER
:
5340 d_append_num (dpi
, dc
->u
.s_number
.number
);
5343 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5344 d_append_string (dpi
, "java resource ");
5345 d_print_comp (dpi
, options
, d_left (dc
));
5348 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5349 d_print_comp (dpi
, options
, d_left (dc
));
5350 d_print_comp (dpi
, options
, d_right (dc
));
5353 case DEMANGLE_COMPONENT_CHARACTER
:
5354 d_append_char (dpi
, dc
->u
.s_character
.character
);
5357 case DEMANGLE_COMPONENT_DECLTYPE
:
5358 d_append_string (dpi
, "decltype (");
5359 d_print_comp (dpi
, options
, d_left (dc
));
5360 d_append_char (dpi
, ')');
5363 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5367 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5370 /* d_find_pack won't find anything if the only packs involved
5371 in this expansion are function parameter packs; in that
5372 case, just print the pattern and "...". */
5373 d_print_subexpr (dpi
, options
, d_left (dc
));
5374 d_append_string (dpi
, "...");
5378 len
= d_pack_length (a
);
5380 for (i
= 0; i
< len
; ++i
)
5382 dpi
->pack_index
= i
;
5383 d_print_comp (dpi
, options
, dc
);
5385 d_append_string (dpi
, ", ");
5390 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5392 long num
= dc
->u
.s_number
.number
;
5394 d_append_string (dpi
, "this");
5397 d_append_string (dpi
, "{parm#");
5398 d_append_num (dpi
, num
);
5399 d_append_char (dpi
, '}');
5404 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5405 d_append_string (dpi
, "global constructors keyed to ");
5406 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5409 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5410 d_append_string (dpi
, "global destructors keyed to ");
5411 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5414 case DEMANGLE_COMPONENT_LAMBDA
:
5415 d_append_string (dpi
, "{lambda(");
5416 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5417 d_append_string (dpi
, ")#");
5418 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5419 d_append_char (dpi
, '}');
5422 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5423 d_append_string (dpi
, "{unnamed type#");
5424 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5425 d_append_char (dpi
, '}');
5428 case DEMANGLE_COMPONENT_CLONE
:
5429 d_print_comp (dpi
, options
, d_left (dc
));
5430 d_append_string (dpi
, " [clone ");
5431 d_print_comp (dpi
, options
, d_right (dc
));
5432 d_append_char (dpi
, ']');
5436 d_print_error (dpi
);
5442 d_print_comp (struct d_print_info
*dpi
, int options
,
5443 const struct demangle_component
*dc
)
5445 struct d_component_stack self
;
5448 self
.parent
= dpi
->component_stack
;
5449 dpi
->component_stack
= &self
;
5451 d_print_comp_inner (dpi
, options
, dc
);
5453 dpi
->component_stack
= self
.parent
;
5456 /* Print a Java dentifier. For Java we try to handle encoded extended
5457 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5458 so we don't it for C++. Characters are encoded as
5462 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5468 for (p
= name
; p
< end
; ++p
)
5479 for (q
= p
+ 3; q
< end
; ++q
)
5485 else if (*q
>= 'A' && *q
<= 'F')
5486 dig
= *q
- 'A' + 10;
5487 else if (*q
>= 'a' && *q
<= 'f')
5488 dig
= *q
- 'a' + 10;
5494 /* If the Unicode character is larger than 256, we don't try
5495 to deal with it here. FIXME. */
5496 if (q
< end
&& *q
== '_' && c
< 256)
5498 d_append_char (dpi
, c
);
5504 d_append_char (dpi
, *p
);
5508 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5509 qualifiers on this after printing a function. */
5512 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5513 struct d_print_mod
*mods
, int suffix
)
5515 struct d_print_template
*hold_dpt
;
5517 if (mods
== NULL
|| d_print_saw_error (dpi
))
5522 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5523 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5524 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5525 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5526 || mods
->mod
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
5528 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5530 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5536 hold_dpt
= dpi
->templates
;
5537 dpi
->templates
= mods
->templates
;
5539 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5541 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5542 dpi
->templates
= hold_dpt
;
5545 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5547 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5548 dpi
->templates
= hold_dpt
;
5551 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5553 struct d_print_mod
*hold_modifiers
;
5554 struct demangle_component
*dc
;
5556 /* When this is on the modifier stack, we have pulled any
5557 qualifiers off the right argument already. Otherwise, we
5558 print it as usual, but don't let the left argument see any
5561 hold_modifiers
= dpi
->modifiers
;
5562 dpi
->modifiers
= NULL
;
5563 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5564 dpi
->modifiers
= hold_modifiers
;
5566 if ((options
& DMGL_JAVA
) == 0)
5567 d_append_string (dpi
, "::");
5569 d_append_char (dpi
, '.');
5571 dc
= d_right (mods
->mod
);
5573 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5575 d_append_string (dpi
, "{default arg#");
5576 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5577 d_append_string (dpi
, "}::");
5578 dc
= dc
->u
.s_unary_num
.sub
;
5581 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5582 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5583 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5584 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5585 || dc
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
5586 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5589 d_print_comp (dpi
, options
, dc
);
5591 dpi
->templates
= hold_dpt
;
5595 d_print_mod (dpi
, options
, mods
->mod
);
5597 dpi
->templates
= hold_dpt
;
5599 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5602 /* Print a modifier. */
5605 d_print_mod (struct d_print_info
*dpi
, int options
,
5606 const struct demangle_component
*mod
)
5610 case DEMANGLE_COMPONENT_RESTRICT
:
5611 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5612 d_append_string (dpi
, " restrict");
5614 case DEMANGLE_COMPONENT_VOLATILE
:
5615 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5616 d_append_string (dpi
, " volatile");
5618 case DEMANGLE_COMPONENT_CONST
:
5619 case DEMANGLE_COMPONENT_CONST_THIS
:
5620 d_append_string (dpi
, " const");
5622 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5623 d_append_string (dpi
, " transaction_safe");
5625 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5626 d_append_char (dpi
, ' ');
5627 d_print_comp (dpi
, options
, d_right (mod
));
5629 case DEMANGLE_COMPONENT_POINTER
:
5630 /* There is no pointer symbol in Java. */
5631 if ((options
& DMGL_JAVA
) == 0)
5632 d_append_char (dpi
, '*');
5634 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5635 /* For the ref-qualifier, put a space before the &. */
5636 d_append_char (dpi
, ' ');
5637 case DEMANGLE_COMPONENT_REFERENCE
:
5638 d_append_char (dpi
, '&');
5640 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5641 d_append_char (dpi
, ' ');
5642 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5643 d_append_string (dpi
, "&&");
5645 case DEMANGLE_COMPONENT_COMPLEX
:
5646 d_append_string (dpi
, "complex ");
5648 case DEMANGLE_COMPONENT_IMAGINARY
:
5649 d_append_string (dpi
, "imaginary ");
5651 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5652 if (d_last_char (dpi
) != '(')
5653 d_append_char (dpi
, ' ');
5654 d_print_comp (dpi
, options
, d_left (mod
));
5655 d_append_string (dpi
, "::*");
5657 case DEMANGLE_COMPONENT_TYPED_NAME
:
5658 d_print_comp (dpi
, options
, d_left (mod
));
5660 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5661 d_append_string (dpi
, " __vector(");
5662 d_print_comp (dpi
, options
, d_left (mod
));
5663 d_append_char (dpi
, ')');
5667 /* Otherwise, we have something that won't go back on the
5668 modifier stack, so we can just print it. */
5669 d_print_comp (dpi
, options
, mod
);
5674 /* Print a function type, except for the return type. */
5677 d_print_function_type (struct d_print_info
*dpi
, int options
,
5678 const struct demangle_component
*dc
,
5679 struct d_print_mod
*mods
)
5683 struct d_print_mod
*p
;
5684 struct d_print_mod
*hold_modifiers
;
5688 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5693 switch (p
->mod
->type
)
5695 case DEMANGLE_COMPONENT_POINTER
:
5696 case DEMANGLE_COMPONENT_REFERENCE
:
5697 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5700 case DEMANGLE_COMPONENT_RESTRICT
:
5701 case DEMANGLE_COMPONENT_VOLATILE
:
5702 case DEMANGLE_COMPONENT_CONST
:
5703 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5704 case DEMANGLE_COMPONENT_COMPLEX
:
5705 case DEMANGLE_COMPONENT_IMAGINARY
:
5706 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5710 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5711 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5712 case DEMANGLE_COMPONENT_CONST_THIS
:
5713 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5714 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5715 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5728 if (d_last_char (dpi
) != '('
5729 && d_last_char (dpi
) != '*')
5732 if (need_space
&& d_last_char (dpi
) != ' ')
5733 d_append_char (dpi
, ' ');
5734 d_append_char (dpi
, '(');
5737 hold_modifiers
= dpi
->modifiers
;
5738 dpi
->modifiers
= NULL
;
5740 d_print_mod_list (dpi
, options
, mods
, 0);
5743 d_append_char (dpi
, ')');
5745 d_append_char (dpi
, '(');
5747 if (d_right (dc
) != NULL
)
5748 d_print_comp (dpi
, options
, d_right (dc
));
5750 d_append_char (dpi
, ')');
5752 d_print_mod_list (dpi
, options
, mods
, 1);
5754 dpi
->modifiers
= hold_modifiers
;
5757 /* Print an array type, except for the element type. */
5760 d_print_array_type (struct d_print_info
*dpi
, int options
,
5761 const struct demangle_component
*dc
,
5762 struct d_print_mod
*mods
)
5770 struct d_print_mod
*p
;
5773 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5777 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5792 d_append_string (dpi
, " (");
5794 d_print_mod_list (dpi
, options
, mods
, 0);
5797 d_append_char (dpi
, ')');
5801 d_append_char (dpi
, ' ');
5803 d_append_char (dpi
, '[');
5805 if (d_left (dc
) != NULL
)
5806 d_print_comp (dpi
, options
, d_left (dc
));
5808 d_append_char (dpi
, ']');
5811 /* Print an operator in an expression. */
5814 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5815 const struct demangle_component
*dc
)
5817 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5818 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5819 dc
->u
.s_operator
.op
->len
);
5821 d_print_comp (dpi
, options
, dc
);
5827 d_print_cast (struct d_print_info
*dpi
, int options
,
5828 const struct demangle_component
*dc
)
5830 d_print_comp (dpi
, options
, d_left (dc
));
5833 /* Print a conversion operator. */
5836 d_print_conversion (struct d_print_info
*dpi
, int options
,
5837 const struct demangle_component
*dc
)
5839 struct d_print_template dpt
;
5841 /* For a conversion operator, we need the template parameters from
5842 the enclosing template in scope for processing the type. */
5843 if (dpi
->current_template
!= NULL
)
5845 dpt
.next
= dpi
->templates
;
5846 dpi
->templates
= &dpt
;
5847 dpt
.template_decl
= dpi
->current_template
;
5850 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5852 d_print_comp (dpi
, options
, d_left (dc
));
5853 if (dpi
->current_template
!= NULL
)
5854 dpi
->templates
= dpt
.next
;
5858 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5860 /* For a templated cast operator, we need to remove the template
5861 parameters from scope after printing the operator name,
5862 so we need to handle the template printing here. */
5863 if (dpi
->current_template
!= NULL
)
5864 dpi
->templates
= dpt
.next
;
5866 if (d_last_char (dpi
) == '<')
5867 d_append_char (dpi
, ' ');
5868 d_append_char (dpi
, '<');
5869 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5870 /* Avoid generating two consecutive '>' characters, to avoid
5871 the C++ syntactic ambiguity. */
5872 if (d_last_char (dpi
) == '>')
5873 d_append_char (dpi
, ' ');
5874 d_append_char (dpi
, '>');
5878 /* Initialize the information structure we use to pass around
5881 CP_STATIC_IF_GLIBCPP_V3
5883 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5887 di
->send
= mangled
+ len
;
5888 di
->options
= options
;
5892 /* We can not need more components than twice the number of chars in
5893 the mangled string. Most components correspond directly to
5894 chars, but the ARGLIST types are exceptions. */
5895 di
->num_comps
= 2 * len
;
5898 /* Similarly, we can not need more substitutions than there are
5899 chars in the mangled string. */
5904 di
->last_name
= NULL
;
5907 di
->is_expression
= 0;
5908 di
->is_conversion
= 0;
5911 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5912 mangled name, return strings in repeated callback giving the demangled
5913 name. OPTIONS is the usual libiberty demangler options. On success,
5914 this returns 1. On failure, returns 0. */
5917 d_demangle_callback (const char *mangled
, int options
,
5918 demangle_callbackref callback
, void *opaque
)
5929 struct demangle_component
*dc
;
5932 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5934 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5935 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5936 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5937 && mangled
[10] == '_')
5938 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5941 if ((options
& DMGL_TYPES
) == 0)
5946 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5949 #ifdef CP_DYNAMIC_ARRAYS
5950 __extension__
struct demangle_component comps
[di
.num_comps
];
5951 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5956 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5957 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5963 dc
= cplus_demangle_type (&di
);
5966 dc
= cplus_demangle_mangled_name (&di
, 1);
5968 case DCT_GLOBAL_CTORS
:
5969 case DCT_GLOBAL_DTORS
:
5970 d_advance (&di
, 11);
5971 dc
= d_make_comp (&di
,
5972 (type
== DCT_GLOBAL_CTORS
5973 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5974 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5975 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5977 d_advance (&di
, strlen (d_str (&di
)));
5980 abort (); /* We have listed all the cases. */
5983 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5984 mangled string, then we didn't successfully demangle it. If
5985 DMGL_PARAMS is not set, we didn't look at the trailing
5987 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5990 #ifdef CP_DEMANGLE_DEBUG
5994 status
= (dc
!= NULL
)
5995 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6002 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6003 name, return a buffer allocated with malloc holding the demangled
6004 name. OPTIONS is the usual libiberty demangler options. On
6005 success, this sets *PALC to the allocated size of the returned
6006 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6007 a memory allocation failure, and returns NULL. */
6010 d_demangle (const char *mangled
, int options
, size_t *palc
)
6012 struct d_growable_string dgs
;
6015 d_growable_string_init (&dgs
, 0);
6017 status
= d_demangle_callback (mangled
, options
,
6018 d_growable_string_callback_adapter
, &dgs
);
6026 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6030 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6032 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6034 /* ia64 ABI-mandated entry point in the C++ runtime library for
6035 performing demangling. MANGLED_NAME is a NUL-terminated character
6036 string containing the name to be demangled.
6038 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6039 *LENGTH bytes, into which the demangled name is stored. If
6040 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6041 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6042 is placed in a region of memory allocated with malloc.
6044 If LENGTH is non-NULL, the length of the buffer containing the
6045 demangled name, is placed in *LENGTH.
6047 The return value is a pointer to the start of the NUL-terminated
6048 demangled name, or NULL if the demangling fails. The caller is
6049 responsible for deallocating this memory using free.
6051 *STATUS is set to one of the following values:
6052 0: The demangling operation succeeded.
6053 -1: A memory allocation failure occurred.
6054 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6055 -3: One of the arguments is invalid.
6057 The demangling is performed using the C++ ABI mangling rules, with
6061 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6062 size_t *length
, int *status
)
6067 if (mangled_name
== NULL
)
6074 if (output_buffer
!= NULL
&& length
== NULL
)
6081 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6083 if (demangled
== NULL
)
6095 if (output_buffer
== NULL
)
6102 if (strlen (demangled
) < *length
)
6104 strcpy (output_buffer
, demangled
);
6106 demangled
= output_buffer
;
6110 free (output_buffer
);
6121 extern int __gcclibcxx_demangle_callback (const char *,
6123 (const char *, size_t, void *),
6126 /* Alternative, allocationless entry point in the C++ runtime library
6127 for performing demangling. MANGLED_NAME is a NUL-terminated character
6128 string containing the name to be demangled.
6130 CALLBACK is a callback function, called with demangled string
6131 segments as demangling progresses; it is called at least once,
6132 but may be called more than once. OPAQUE is a generalized pointer
6133 used as a callback argument.
6135 The return code is one of the following values, equivalent to
6136 the STATUS values of __cxa_demangle() (excluding -1, since this
6137 function performs no memory allocations):
6138 0: The demangling operation succeeded.
6139 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6140 -3: One of the arguments is invalid.
6142 The demangling is performed using the C++ ABI mangling rules, with
6146 __gcclibcxx_demangle_callback (const char *mangled_name
,
6147 void (*callback
) (const char *, size_t, void *),
6152 if (mangled_name
== NULL
|| callback
== NULL
)
6155 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6163 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6165 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6166 mangled name, return a buffer allocated with malloc holding the
6167 demangled name. Otherwise, return NULL. */
6170 cplus_demangle_v3 (const char *mangled
, int options
)
6174 return d_demangle (mangled
, options
, &alc
);
6178 cplus_demangle_v3_callback (const char *mangled
, int options
,
6179 demangle_callbackref callback
, void *opaque
)
6181 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6184 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6185 conventions, but the output formatting is a little different.
6186 This instructs the C++ demangler not to emit pointer characters ("*"), to
6187 use Java's namespace separator symbol ("." instead of "::"), and to output
6188 JArray<TYPE> as TYPE[]. */
6191 java_demangle_v3 (const char *mangled
)
6195 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6199 java_demangle_v3_callback (const char *mangled
,
6200 demangle_callbackref callback
, void *opaque
)
6202 return d_demangle_callback (mangled
,
6203 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6207 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6209 #ifndef IN_GLIBCPP_V3
6211 /* Demangle a string in order to find out whether it is a constructor
6212 or destructor. Return non-zero on success. Set *CTOR_KIND and
6213 *DTOR_KIND appropriately. */
6216 is_ctor_or_dtor (const char *mangled
,
6217 enum gnu_v3_ctor_kinds
*ctor_kind
,
6218 enum gnu_v3_dtor_kinds
*dtor_kind
)
6221 struct demangle_component
*dc
;
6224 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6225 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6227 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6230 #ifdef CP_DYNAMIC_ARRAYS
6231 __extension__
struct demangle_component comps
[di
.num_comps
];
6232 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6237 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6238 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6241 dc
= cplus_demangle_mangled_name (&di
, 1);
6243 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6244 to demangle the entire string. */
6251 /* These cannot appear on a constructor or destructor. */
6252 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6253 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6254 case DEMANGLE_COMPONENT_CONST_THIS
:
6255 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6256 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6257 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
6261 case DEMANGLE_COMPONENT_TYPED_NAME
:
6262 case DEMANGLE_COMPONENT_TEMPLATE
:
6265 case DEMANGLE_COMPONENT_QUAL_NAME
:
6266 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6269 case DEMANGLE_COMPONENT_CTOR
:
6270 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6274 case DEMANGLE_COMPONENT_DTOR
:
6275 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6286 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6287 name. A non-zero return indicates the type of constructor. */
6289 enum gnu_v3_ctor_kinds
6290 is_gnu_v3_mangled_ctor (const char *name
)
6292 enum gnu_v3_ctor_kinds ctor_kind
;
6293 enum gnu_v3_dtor_kinds dtor_kind
;
6295 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6296 return (enum gnu_v3_ctor_kinds
) 0;
6301 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6302 name. A non-zero return indicates the type of destructor. */
6304 enum gnu_v3_dtor_kinds
6305 is_gnu_v3_mangled_dtor (const char *name
)
6307 enum gnu_v3_ctor_kinds ctor_kind
;
6308 enum gnu_v3_dtor_kinds dtor_kind
;
6310 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6311 return (enum gnu_v3_dtor_kinds
) 0;
6315 #endif /* IN_GLIBCPP_V3 */
6317 #ifdef STANDALONE_DEMANGLER
6320 #include "dyn-string.h"
6322 static void print_usage (FILE* fp
, int exit_value
);
6324 #define IS_ALPHA(CHAR) \
6325 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6326 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6328 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6329 #define is_mangled_char(CHAR) \
6330 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6331 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6333 /* The name of this program, as invoked. */
6334 const char* program_name
;
6336 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6339 print_usage (FILE* fp
, int exit_value
)
6341 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6342 fprintf (fp
, "Options:\n");
6343 fprintf (fp
, " -h,--help Display this message.\n");
6344 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6345 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6346 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6351 /* Option specification for getopt_long. */
6352 static const struct option long_options
[] =
6354 { "help", no_argument
, NULL
, 'h' },
6355 { "no-params", no_argument
, NULL
, 'p' },
6356 { "verbose", no_argument
, NULL
, 'v' },
6357 { NULL
, no_argument
, NULL
, 0 },
6360 /* Main entry for a demangling filter executable. It will demangle
6361 its command line arguments, if any. If none are provided, it will
6362 filter stdin to stdout, replacing any recognized mangled C++ names
6363 with their demangled equivalents. */
6366 main (int argc
, char *argv
[])
6370 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6372 /* Use the program name of this program, as invoked. */
6373 program_name
= argv
[0];
6375 /* Parse options. */
6378 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6381 case '?': /* Unrecognized option. */
6382 print_usage (stderr
, 1);
6386 print_usage (stdout
, 0);
6390 options
&= ~ DMGL_PARAMS
;
6394 options
|= DMGL_VERBOSE
;
6398 while (opt_char
!= -1);
6401 /* No command line arguments were provided. Filter stdin. */
6403 dyn_string_t mangled
= dyn_string_new (3);
6406 /* Read all of input. */
6407 while (!feof (stdin
))
6411 /* Pile characters into mangled until we hit one that can't
6412 occur in a mangled name. */
6414 while (!feof (stdin
) && is_mangled_char (c
))
6416 dyn_string_append_char (mangled
, c
);
6422 if (dyn_string_length (mangled
) > 0)
6424 #ifdef IN_GLIBCPP_V3
6425 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6427 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6437 /* It might not have been a mangled name. Print the
6439 fputs (dyn_string_buf (mangled
), stdout
);
6442 dyn_string_clear (mangled
);
6445 /* If we haven't hit EOF yet, we've read one character that
6446 can't occur in a mangled name, so print it out. */
6451 dyn_string_delete (mangled
);
6454 /* Demangle command line arguments. */
6456 /* Loop over command line arguments. */
6457 for (i
= optind
; i
< argc
; ++i
)
6460 #ifdef IN_GLIBCPP_V3
6464 /* Attempt to demangle. */
6465 #ifdef IN_GLIBCPP_V3
6466 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6468 s
= cplus_demangle_v3 (argv
[i
], options
);
6471 /* If it worked, print the demangled name. */
6479 #ifdef IN_GLIBCPP_V3
6480 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6482 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6491 #endif /* STANDALONE_DEMANGLER */