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 (_AIX) && !defined (__GNUC__)
120 # define alloca __builtin_alloca
122 extern char *alloca ();
123 # endif /* __GNUC__ */
125 #endif /* HAVE_ALLOCA_H */
127 #include "ansidecl.h"
128 #include "libiberty.h"
129 #include "demangle.h"
130 #include "cp-demangle.h"
132 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
133 also rename them via #define to avoid compiler errors when the
134 static definition conflicts with the extern declaration in a header
138 #define CP_STATIC_IF_GLIBCPP_V3 static
140 #define cplus_demangle_fill_name d_fill_name
141 static int d_fill_name (struct demangle_component
*, const char *, int);
143 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
145 d_fill_extended_operator (struct demangle_component
*, int,
146 struct demangle_component
*);
148 #define cplus_demangle_fill_ctor d_fill_ctor
150 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
151 struct demangle_component
*);
153 #define cplus_demangle_fill_dtor d_fill_dtor
155 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
156 struct demangle_component
*);
158 #define cplus_demangle_mangled_name d_mangled_name
159 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
161 #define cplus_demangle_type d_type
162 static struct demangle_component
*d_type (struct d_info
*);
164 #define cplus_demangle_print d_print
165 static char *d_print (int, const struct demangle_component
*, int, size_t *);
167 #define cplus_demangle_print_callback d_print_callback
168 static int d_print_callback (int, const struct demangle_component
*,
169 demangle_callbackref
, void *);
171 #define cplus_demangle_init_info d_init_info
172 static void d_init_info (const char *, int, size_t, struct d_info
*);
174 #else /* ! defined(IN_GLIBCPP_V3) */
175 #define CP_STATIC_IF_GLIBCPP_V3
176 #endif /* ! defined(IN_GLIBCPP_V3) */
178 /* See if the compiler supports dynamic arrays. */
181 #define CP_DYNAMIC_ARRAYS
184 #ifdef __STDC_VERSION__
185 #if __STDC_VERSION__ >= 199901L
186 #define CP_DYNAMIC_ARRAYS
187 #endif /* __STDC__VERSION >= 199901L */
188 #endif /* defined (__STDC_VERSION__) */
189 #endif /* defined (__STDC__) */
190 #endif /* ! defined (__GNUC__) */
192 /* We avoid pulling in the ctype tables, to prevent pulling in
193 additional unresolved symbols when this code is used in a library.
194 FIXME: Is this really a valid reason? This comes from the original
197 As of this writing this file has the following undefined references
198 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
201 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
202 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
203 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
205 /* The prefix prepended by GCC to an identifier represnting the
206 anonymous namespace. */
207 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
208 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
209 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
211 /* Information we keep for the standard substitutions. */
213 struct d_standard_sub_info
215 /* The code for this substitution. */
217 /* The simple string it expands to. */
218 const char *simple_expansion
;
219 /* The length of the simple expansion. */
221 /* The results of a full, verbose, expansion. This is used when
222 qualifying a constructor/destructor, or when in verbose mode. */
223 const char *full_expansion
;
224 /* The length of the full expansion. */
226 /* What to set the last_name field of d_info to; NULL if we should
227 not set it. This is only relevant when qualifying a
228 constructor/destructor. */
229 const char *set_last_name
;
230 /* The length of set_last_name. */
231 int set_last_name_len
;
234 /* Accessors for subtrees of struct demangle_component. */
236 #define d_left(dc) ((dc)->u.s_binary.left)
237 #define d_right(dc) ((dc)->u.s_binary.right)
239 /* A list of templates. This is used while printing. */
241 struct d_print_template
243 /* Next template on the list. */
244 struct d_print_template
*next
;
246 const struct demangle_component
*template_decl
;
249 /* A list of type modifiers. This is used while printing. */
253 /* Next modifier on the list. These are in the reverse of the order
254 in which they appeared in the mangled string. */
255 struct d_print_mod
*next
;
257 const struct demangle_component
*mod
;
258 /* Whether this modifier was printed. */
260 /* The list of templates which applies to this modifier. */
261 struct d_print_template
*templates
;
264 /* We use these structures to hold information during printing. */
266 struct d_growable_string
268 /* Buffer holding the result. */
270 /* Current length of data in buffer. */
272 /* Allocated size of buffer. */
274 /* Set to 1 if we had a memory allocation failure. */
275 int allocation_failure
;
278 /* A demangle component and some scope captured when it was first
283 /* The component whose scope this is. */
284 const struct demangle_component
*container
;
285 /* The list of templates, if any, that was current when this
286 scope was captured. */
287 struct d_print_template
*templates
;
290 /* Checkpoint structure to allow backtracking. This holds copies
291 of the fields of struct d_info that need to be restored
292 if a trial parse needs to be backtracked over. */
294 struct d_info_checkpoint
303 enum { D_PRINT_BUFFER_LENGTH
= 256 };
306 /* Fixed-length allocated buffer for demangled data, flushed to the
307 callback with a NUL termination once full. */
308 char buf
[D_PRINT_BUFFER_LENGTH
];
309 /* Current length of data in buffer. */
311 /* The last character printed, saved individually so that it survives
314 /* Callback function to handle demangled buffer flush. */
315 demangle_callbackref callback
;
316 /* Opaque callback argument. */
318 /* The current list of templates, if any. */
319 struct d_print_template
*templates
;
320 /* The current list of modifiers (e.g., pointer, reference, etc.),
322 struct d_print_mod
*modifiers
;
323 /* Set to 1 if we saw a demangling error. */
324 int demangle_failure
;
325 /* The current index into any template argument packs we are using
328 /* Number of d_print_flush calls so far. */
329 unsigned long int flush_count
;
330 /* Array of saved scopes for evaluating substitutions. */
331 struct d_saved_scope
*saved_scopes
;
332 /* Index of the next unused saved scope in the above array. */
333 int next_saved_scope
;
334 /* Number of saved scopes in the above array. */
335 int num_saved_scopes
;
336 /* Array of templates for saving into scopes. */
337 struct d_print_template
*copy_templates
;
338 /* Index of the next unused copy template in the above array. */
339 int next_copy_template
;
340 /* Number of copy templates in the above array. */
341 int num_copy_templates
;
342 /* The nearest enclosing template, if any. */
343 const struct demangle_component
*current_template
;
346 #ifdef CP_DEMANGLE_DEBUG
347 static void d_dump (struct demangle_component
*, int);
350 static struct demangle_component
*
351 d_make_empty (struct d_info
*);
353 static struct demangle_component
*
354 d_make_comp (struct d_info
*, enum demangle_component_type
,
355 struct demangle_component
*,
356 struct demangle_component
*);
358 static struct demangle_component
*
359 d_make_name (struct d_info
*, const char *, int);
361 static struct demangle_component
*
362 d_make_demangle_mangled_name (struct d_info
*, const char *);
364 static struct demangle_component
*
365 d_make_builtin_type (struct d_info
*,
366 const struct demangle_builtin_type_info
*);
368 static struct demangle_component
*
369 d_make_operator (struct d_info
*,
370 const struct demangle_operator_info
*);
372 static struct demangle_component
*
373 d_make_extended_operator (struct d_info
*, int,
374 struct demangle_component
*);
376 static struct demangle_component
*
377 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
378 struct demangle_component
*);
380 static struct demangle_component
*
381 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
382 struct demangle_component
*);
384 static struct demangle_component
*
385 d_make_template_param (struct d_info
*, long);
387 static struct demangle_component
*
388 d_make_sub (struct d_info
*, const char *, int);
391 has_return_type (struct demangle_component
*);
394 is_ctor_dtor_or_conversion (struct demangle_component
*);
396 static struct demangle_component
*d_encoding (struct d_info
*, int);
398 static struct demangle_component
*d_name (struct d_info
*);
400 static struct demangle_component
*d_nested_name (struct d_info
*);
402 static struct demangle_component
*d_prefix (struct d_info
*);
404 static struct demangle_component
*d_unqualified_name (struct d_info
*);
406 static struct demangle_component
*d_source_name (struct d_info
*);
408 static long d_number (struct d_info
*);
410 static struct demangle_component
*d_identifier (struct d_info
*, int);
412 static struct demangle_component
*d_operator_name (struct d_info
*);
414 static struct demangle_component
*d_special_name (struct d_info
*);
416 static int d_call_offset (struct d_info
*, int);
418 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
420 static struct demangle_component
**
421 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
423 static struct demangle_component
*
424 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
426 static struct demangle_component
*
427 d_function_type (struct d_info
*);
429 static struct demangle_component
*
430 d_bare_function_type (struct d_info
*, int);
432 static struct demangle_component
*
433 d_class_enum_type (struct d_info
*);
435 static struct demangle_component
*d_array_type (struct d_info
*);
437 static struct demangle_component
*d_vector_type (struct d_info
*);
439 static struct demangle_component
*
440 d_pointer_to_member_type (struct d_info
*);
442 static struct demangle_component
*
443 d_template_param (struct d_info
*);
445 static struct demangle_component
*d_template_args (struct d_info
*);
447 static struct demangle_component
*
448 d_template_arg (struct d_info
*);
450 static struct demangle_component
*d_expression (struct d_info
*);
452 static struct demangle_component
*d_expr_primary (struct d_info
*);
454 static struct demangle_component
*d_local_name (struct d_info
*);
456 static int d_discriminator (struct d_info
*);
458 static struct demangle_component
*d_lambda (struct d_info
*);
460 static struct demangle_component
*d_unnamed_type (struct d_info
*);
462 static struct demangle_component
*
463 d_clone_suffix (struct d_info
*, struct demangle_component
*);
466 d_add_substitution (struct d_info
*, struct demangle_component
*);
468 static struct demangle_component
*d_substitution (struct d_info
*, int);
470 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
472 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
474 static void d_growable_string_init (struct d_growable_string
*, size_t);
477 d_growable_string_resize (struct d_growable_string
*, size_t);
480 d_growable_string_append_buffer (struct d_growable_string
*,
481 const char *, size_t);
483 d_growable_string_callback_adapter (const char *, size_t, void *);
486 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
487 const struct demangle_component
*);
489 static inline void d_print_error (struct d_print_info
*);
491 static inline int d_print_saw_error (struct d_print_info
*);
493 static inline void d_print_flush (struct d_print_info
*);
495 static inline void d_append_char (struct d_print_info
*, char);
497 static inline void d_append_buffer (struct d_print_info
*,
498 const char *, size_t);
500 static inline void d_append_string (struct d_print_info
*, const char *);
502 static inline char d_last_char (struct d_print_info
*);
505 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
508 d_print_java_identifier (struct d_print_info
*, const char *, int);
511 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
514 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
517 d_print_function_type (struct d_print_info
*, int,
518 const struct demangle_component
*,
519 struct d_print_mod
*);
522 d_print_array_type (struct d_print_info
*, int,
523 const struct demangle_component
*,
524 struct d_print_mod
*);
527 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
530 d_print_cast (struct d_print_info
*, int, const struct demangle_component
*);
532 static int d_demangle_callback (const char *, int,
533 demangle_callbackref
, void *);
534 static char *d_demangle (const char *, int, size_t *);
536 #ifdef CP_DEMANGLE_DEBUG
539 d_dump (struct demangle_component
*dc
, int indent
)
546 printf ("failed demangling\n");
550 for (i
= 0; i
< indent
; ++i
)
555 case DEMANGLE_COMPONENT_NAME
:
556 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
558 case DEMANGLE_COMPONENT_TAGGED_NAME
:
559 printf ("tagged name\n");
560 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
561 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
563 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
564 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
566 case DEMANGLE_COMPONENT_CTOR
:
567 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
568 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
570 case DEMANGLE_COMPONENT_DTOR
:
571 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
572 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
574 case DEMANGLE_COMPONENT_SUB_STD
:
575 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
577 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
578 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
580 case DEMANGLE_COMPONENT_OPERATOR
:
581 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
583 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
584 printf ("extended operator with %d args\n",
585 dc
->u
.s_extended_operator
.args
);
586 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
589 case DEMANGLE_COMPONENT_QUAL_NAME
:
590 printf ("qualified name\n");
592 case DEMANGLE_COMPONENT_LOCAL_NAME
:
593 printf ("local name\n");
595 case DEMANGLE_COMPONENT_TYPED_NAME
:
596 printf ("typed name\n");
598 case DEMANGLE_COMPONENT_TEMPLATE
:
599 printf ("template\n");
601 case DEMANGLE_COMPONENT_VTABLE
:
604 case DEMANGLE_COMPONENT_VTT
:
607 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
608 printf ("construction vtable\n");
610 case DEMANGLE_COMPONENT_TYPEINFO
:
611 printf ("typeinfo\n");
613 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
614 printf ("typeinfo name\n");
616 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
617 printf ("typeinfo function\n");
619 case DEMANGLE_COMPONENT_THUNK
:
622 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
623 printf ("virtual thunk\n");
625 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
626 printf ("covariant thunk\n");
628 case DEMANGLE_COMPONENT_JAVA_CLASS
:
629 printf ("java class\n");
631 case DEMANGLE_COMPONENT_GUARD
:
634 case DEMANGLE_COMPONENT_REFTEMP
:
635 printf ("reference temporary\n");
637 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
638 printf ("hidden alias\n");
640 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
641 printf ("transaction clone\n");
643 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
644 printf ("non-transaction clone\n");
646 case DEMANGLE_COMPONENT_RESTRICT
:
647 printf ("restrict\n");
649 case DEMANGLE_COMPONENT_VOLATILE
:
650 printf ("volatile\n");
652 case DEMANGLE_COMPONENT_CONST
:
655 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
656 printf ("restrict this\n");
658 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
659 printf ("volatile this\n");
661 case DEMANGLE_COMPONENT_CONST_THIS
:
662 printf ("const this\n");
664 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
665 printf ("reference this\n");
667 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
668 printf ("rvalue reference this\n");
670 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
671 printf ("vendor type qualifier\n");
673 case DEMANGLE_COMPONENT_POINTER
:
674 printf ("pointer\n");
676 case DEMANGLE_COMPONENT_REFERENCE
:
677 printf ("reference\n");
679 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
680 printf ("rvalue reference\n");
682 case DEMANGLE_COMPONENT_COMPLEX
:
683 printf ("complex\n");
685 case DEMANGLE_COMPONENT_IMAGINARY
:
686 printf ("imaginary\n");
688 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
689 printf ("vendor type\n");
691 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
692 printf ("function type\n");
694 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
695 printf ("array type\n");
697 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
698 printf ("pointer to member type\n");
700 case DEMANGLE_COMPONENT_FIXED_TYPE
:
701 printf ("fixed-point type\n");
703 case DEMANGLE_COMPONENT_ARGLIST
:
704 printf ("argument list\n");
706 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
707 printf ("template argument list\n");
709 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
710 printf ("initializer list\n");
712 case DEMANGLE_COMPONENT_CAST
:
715 case DEMANGLE_COMPONENT_NULLARY
:
716 printf ("nullary operator\n");
718 case DEMANGLE_COMPONENT_UNARY
:
719 printf ("unary operator\n");
721 case DEMANGLE_COMPONENT_BINARY
:
722 printf ("binary operator\n");
724 case DEMANGLE_COMPONENT_BINARY_ARGS
:
725 printf ("binary operator arguments\n");
727 case DEMANGLE_COMPONENT_TRINARY
:
728 printf ("trinary operator\n");
730 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
731 printf ("trinary operator arguments 1\n");
733 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
734 printf ("trinary operator arguments 1\n");
736 case DEMANGLE_COMPONENT_LITERAL
:
737 printf ("literal\n");
739 case DEMANGLE_COMPONENT_LITERAL_NEG
:
740 printf ("negative literal\n");
742 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
743 printf ("java resource\n");
745 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
746 printf ("compound name\n");
748 case DEMANGLE_COMPONENT_CHARACTER
:
749 printf ("character '%c'\n", dc
->u
.s_character
.character
);
751 case DEMANGLE_COMPONENT_DECLTYPE
:
752 printf ("decltype\n");
754 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
755 printf ("pack expansion\n");
757 case DEMANGLE_COMPONENT_TLS_INIT
:
758 printf ("tls init function\n");
760 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
761 printf ("tls wrapper function\n");
763 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
764 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
765 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
767 case DEMANGLE_COMPONENT_LAMBDA
:
768 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
769 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
773 d_dump (d_left (dc
), indent
+ 2);
774 d_dump (d_right (dc
), indent
+ 2);
777 #endif /* CP_DEMANGLE_DEBUG */
779 /* Fill in a DEMANGLE_COMPONENT_NAME. */
781 CP_STATIC_IF_GLIBCPP_V3
783 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
785 if (p
== NULL
|| s
== NULL
|| len
== 0)
787 p
->type
= DEMANGLE_COMPONENT_NAME
;
789 p
->u
.s_name
.len
= len
;
793 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
795 CP_STATIC_IF_GLIBCPP_V3
797 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
798 struct demangle_component
*name
)
800 if (p
== NULL
|| args
< 0 || name
== NULL
)
802 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
803 p
->u
.s_extended_operator
.args
= args
;
804 p
->u
.s_extended_operator
.name
= name
;
808 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
810 CP_STATIC_IF_GLIBCPP_V3
812 cplus_demangle_fill_ctor (struct demangle_component
*p
,
813 enum gnu_v3_ctor_kinds kind
,
814 struct demangle_component
*name
)
818 || (int) kind
< gnu_v3_complete_object_ctor
819 || (int) kind
> gnu_v3_object_ctor_group
)
821 p
->type
= DEMANGLE_COMPONENT_CTOR
;
822 p
->u
.s_ctor
.kind
= kind
;
823 p
->u
.s_ctor
.name
= name
;
827 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
829 CP_STATIC_IF_GLIBCPP_V3
831 cplus_demangle_fill_dtor (struct demangle_component
*p
,
832 enum gnu_v3_dtor_kinds kind
,
833 struct demangle_component
*name
)
837 || (int) kind
< gnu_v3_deleting_dtor
838 || (int) kind
> gnu_v3_object_dtor_group
)
840 p
->type
= DEMANGLE_COMPONENT_DTOR
;
841 p
->u
.s_dtor
.kind
= kind
;
842 p
->u
.s_dtor
.name
= name
;
846 /* Add a new component. */
848 static struct demangle_component
*
849 d_make_empty (struct d_info
*di
)
851 struct demangle_component
*p
;
853 if (di
->next_comp
>= di
->num_comps
)
855 p
= &di
->comps
[di
->next_comp
];
860 /* Add a new generic component. */
862 static struct demangle_component
*
863 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
864 struct demangle_component
*left
,
865 struct demangle_component
*right
)
867 struct demangle_component
*p
;
869 /* We check for errors here. A typical error would be a NULL return
870 from a subroutine. We catch those here, and return NULL
874 /* These types require two parameters. */
875 case DEMANGLE_COMPONENT_QUAL_NAME
:
876 case DEMANGLE_COMPONENT_LOCAL_NAME
:
877 case DEMANGLE_COMPONENT_TYPED_NAME
:
878 case DEMANGLE_COMPONENT_TAGGED_NAME
:
879 case DEMANGLE_COMPONENT_TEMPLATE
:
880 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
881 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
882 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
883 case DEMANGLE_COMPONENT_UNARY
:
884 case DEMANGLE_COMPONENT_BINARY
:
885 case DEMANGLE_COMPONENT_BINARY_ARGS
:
886 case DEMANGLE_COMPONENT_TRINARY
:
887 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
888 case DEMANGLE_COMPONENT_LITERAL
:
889 case DEMANGLE_COMPONENT_LITERAL_NEG
:
890 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
891 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
892 case DEMANGLE_COMPONENT_CLONE
:
893 if (left
== NULL
|| right
== NULL
)
897 /* These types only require one parameter. */
898 case DEMANGLE_COMPONENT_VTABLE
:
899 case DEMANGLE_COMPONENT_VTT
:
900 case DEMANGLE_COMPONENT_TYPEINFO
:
901 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
902 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
903 case DEMANGLE_COMPONENT_THUNK
:
904 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
905 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
906 case DEMANGLE_COMPONENT_JAVA_CLASS
:
907 case DEMANGLE_COMPONENT_GUARD
:
908 case DEMANGLE_COMPONENT_TLS_INIT
:
909 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
910 case DEMANGLE_COMPONENT_REFTEMP
:
911 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
912 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
913 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
914 case DEMANGLE_COMPONENT_POINTER
:
915 case DEMANGLE_COMPONENT_REFERENCE
:
916 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
917 case DEMANGLE_COMPONENT_COMPLEX
:
918 case DEMANGLE_COMPONENT_IMAGINARY
:
919 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
920 case DEMANGLE_COMPONENT_CAST
:
921 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
922 case DEMANGLE_COMPONENT_DECLTYPE
:
923 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
924 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
925 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
926 case DEMANGLE_COMPONENT_NULLARY
:
927 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
932 /* This needs a right parameter, but the left parameter can be
934 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
935 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
940 /* These are allowed to have no parameters--in some cases they
941 will be filled in later. */
942 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
943 case DEMANGLE_COMPONENT_RESTRICT
:
944 case DEMANGLE_COMPONENT_VOLATILE
:
945 case DEMANGLE_COMPONENT_CONST
:
946 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
947 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
948 case DEMANGLE_COMPONENT_CONST_THIS
:
949 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
950 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
951 case DEMANGLE_COMPONENT_ARGLIST
:
952 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
955 /* Other types should not be seen here. */
960 p
= d_make_empty (di
);
964 p
->u
.s_binary
.left
= left
;
965 p
->u
.s_binary
.right
= right
;
970 /* Add a new demangle mangled name component. */
972 static struct demangle_component
*
973 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
975 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
976 return d_make_name (di
, s
, strlen (s
));
978 return d_encoding (di
, 0);
981 /* Add a new name component. */
983 static struct demangle_component
*
984 d_make_name (struct d_info
*di
, const char *s
, int len
)
986 struct demangle_component
*p
;
988 p
= d_make_empty (di
);
989 if (! cplus_demangle_fill_name (p
, s
, len
))
994 /* Add a new builtin type component. */
996 static struct demangle_component
*
997 d_make_builtin_type (struct d_info
*di
,
998 const struct demangle_builtin_type_info
*type
)
1000 struct demangle_component
*p
;
1004 p
= d_make_empty (di
);
1007 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1008 p
->u
.s_builtin
.type
= type
;
1013 /* Add a new operator component. */
1015 static struct demangle_component
*
1016 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1018 struct demangle_component
*p
;
1020 p
= d_make_empty (di
);
1023 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1024 p
->u
.s_operator
.op
= op
;
1029 /* Add a new extended operator component. */
1031 static struct demangle_component
*
1032 d_make_extended_operator (struct d_info
*di
, int args
,
1033 struct demangle_component
*name
)
1035 struct demangle_component
*p
;
1037 p
= d_make_empty (di
);
1038 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1043 static struct demangle_component
*
1044 d_make_default_arg (struct d_info
*di
, int num
,
1045 struct demangle_component
*sub
)
1047 struct demangle_component
*p
= d_make_empty (di
);
1050 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1051 p
->u
.s_unary_num
.num
= num
;
1052 p
->u
.s_unary_num
.sub
= sub
;
1057 /* Add a new constructor component. */
1059 static struct demangle_component
*
1060 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1061 struct demangle_component
*name
)
1063 struct demangle_component
*p
;
1065 p
= d_make_empty (di
);
1066 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1071 /* Add a new destructor component. */
1073 static struct demangle_component
*
1074 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1075 struct demangle_component
*name
)
1077 struct demangle_component
*p
;
1079 p
= d_make_empty (di
);
1080 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1085 /* Add a new template parameter. */
1087 static struct demangle_component
*
1088 d_make_template_param (struct d_info
*di
, long i
)
1090 struct demangle_component
*p
;
1092 p
= d_make_empty (di
);
1095 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1096 p
->u
.s_number
.number
= i
;
1101 /* Add a new function parameter. */
1103 static struct demangle_component
*
1104 d_make_function_param (struct d_info
*di
, long i
)
1106 struct demangle_component
*p
;
1108 p
= d_make_empty (di
);
1111 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1112 p
->u
.s_number
.number
= i
;
1117 /* Add a new standard substitution component. */
1119 static struct demangle_component
*
1120 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1122 struct demangle_component
*p
;
1124 p
= d_make_empty (di
);
1127 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1128 p
->u
.s_string
.string
= name
;
1129 p
->u
.s_string
.len
= len
;
1134 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1136 TOP_LEVEL is non-zero when called at the top level. */
1138 CP_STATIC_IF_GLIBCPP_V3
1139 struct demangle_component
*
1140 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1142 struct demangle_component
*p
;
1144 if (! d_check_char (di
, '_')
1145 /* Allow missing _ if not at toplevel to work around a
1146 bug in G++ abi-version=2 mangling; see the comment in
1147 write_template_arg. */
1150 if (! d_check_char (di
, 'Z'))
1152 p
= d_encoding (di
, top_level
);
1154 /* If at top level and parsing parameters, check for a clone
1156 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1157 while (d_peek_char (di
) == '.'
1158 && (IS_LOWER (d_peek_next_char (di
))
1159 || d_peek_next_char (di
) == '_'
1160 || IS_DIGIT (d_peek_next_char (di
))))
1161 p
= d_clone_suffix (di
, p
);
1166 /* Return whether a function should have a return type. The argument
1167 is the function name, which may be qualified in various ways. The
1168 rules are that template functions have return types with some
1169 exceptions, function types which are not part of a function name
1170 mangling have return types with some exceptions, and non-template
1171 function names do not have return types. The exceptions are that
1172 constructors, destructors, and conversion operators do not have
1176 has_return_type (struct demangle_component
*dc
)
1184 case DEMANGLE_COMPONENT_TEMPLATE
:
1185 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1186 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1187 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1188 case DEMANGLE_COMPONENT_CONST_THIS
:
1189 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1190 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1191 return has_return_type (d_left (dc
));
1195 /* Return whether a name is a constructor, a destructor, or a
1196 conversion operator. */
1199 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1207 case DEMANGLE_COMPONENT_QUAL_NAME
:
1208 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1209 return is_ctor_dtor_or_conversion (d_right (dc
));
1210 case DEMANGLE_COMPONENT_CTOR
:
1211 case DEMANGLE_COMPONENT_DTOR
:
1212 case DEMANGLE_COMPONENT_CAST
:
1217 /* <encoding> ::= <(function) name> <bare-function-type>
1221 TOP_LEVEL is non-zero when called at the top level, in which case
1222 if DMGL_PARAMS is not set we do not demangle the function
1223 parameters. We only set this at the top level, because otherwise
1224 we would not correctly demangle names in local scopes. */
1226 static struct demangle_component
*
1227 d_encoding (struct d_info
*di
, int top_level
)
1229 char peek
= d_peek_char (di
);
1231 if (peek
== 'G' || peek
== 'T')
1232 return d_special_name (di
);
1235 struct demangle_component
*dc
;
1239 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1241 /* Strip off any initial CV-qualifiers, as they really apply
1242 to the `this' parameter, and they were not output by the
1243 v2 demangler without DMGL_PARAMS. */
1244 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1245 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1246 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1247 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1248 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1251 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1252 there may be CV-qualifiers on its right argument which
1253 really apply here; this happens when parsing a class
1254 which is local to a function. */
1255 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1257 struct demangle_component
*dcr
;
1260 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1261 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1262 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1263 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1264 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1266 dc
->u
.s_binary
.right
= dcr
;
1272 peek
= d_peek_char (di
);
1273 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1275 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1276 d_bare_function_type (di
, has_return_type (dc
)));
1280 /* <tagged-name> ::= <name> B <source-name> */
1282 static struct demangle_component
*
1283 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1286 while (peek
= d_peek_char (di
),
1289 struct demangle_component
*tag
;
1291 tag
= d_source_name (di
);
1292 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1297 /* <name> ::= <nested-name>
1299 ::= <unscoped-template-name> <template-args>
1302 <unscoped-name> ::= <unqualified-name>
1303 ::= St <unqualified-name>
1305 <unscoped-template-name> ::= <unscoped-name>
1309 static struct demangle_component
*
1310 d_name (struct d_info
*di
)
1312 char peek
= d_peek_char (di
);
1313 struct demangle_component
*dc
;
1318 return d_nested_name (di
);
1321 return d_local_name (di
);
1324 return d_unqualified_name (di
);
1330 if (d_peek_next_char (di
) != 't')
1332 dc
= d_substitution (di
, 0);
1338 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1339 d_make_name (di
, "std", 3),
1340 d_unqualified_name (di
));
1345 if (d_peek_char (di
) != 'I')
1347 /* The grammar does not permit this case to occur if we
1348 called d_substitution() above (i.e., subst == 1). We
1349 don't bother to check. */
1353 /* This is <template-args>, which means that we just saw
1354 <unscoped-template-name>, which is a substitution
1355 candidate if we didn't just get it from a
1359 if (! d_add_substitution (di
, dc
))
1362 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1363 d_template_args (di
));
1371 dc
= d_unqualified_name (di
);
1372 if (d_peek_char (di
) == 'I')
1374 /* This is <template-args>, which means that we just saw
1375 <unscoped-template-name>, which is a substitution
1377 if (! d_add_substitution (di
, dc
))
1379 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1380 d_template_args (di
));
1386 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1387 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1390 static struct demangle_component
*
1391 d_nested_name (struct d_info
*di
)
1393 struct demangle_component
*ret
;
1394 struct demangle_component
**pret
;
1395 struct demangle_component
*rqual
;
1397 if (! d_check_char (di
, 'N'))
1400 pret
= d_cv_qualifiers (di
, &ret
, 1);
1404 /* Parse the ref-qualifier now and then attach it
1405 once we have something to attach it to. */
1406 rqual
= d_ref_qualifier (di
, NULL
);
1408 *pret
= d_prefix (di
);
1414 d_left (rqual
) = ret
;
1418 if (! d_check_char (di
, 'E'))
1424 /* <prefix> ::= <prefix> <unqualified-name>
1425 ::= <template-prefix> <template-args>
1426 ::= <template-param>
1431 <template-prefix> ::= <prefix> <(template) unqualified-name>
1432 ::= <template-param>
1436 static struct demangle_component
*
1437 d_prefix (struct d_info
*di
)
1439 struct demangle_component
*ret
= NULL
;
1444 enum demangle_component_type comb_type
;
1445 struct demangle_component
*dc
;
1447 peek
= d_peek_char (di
);
1451 /* The older code accepts a <local-name> here, but I don't see
1452 that in the grammar. The older code does not accept a
1453 <template-param> here. */
1455 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1458 char peek2
= d_peek_next_char (di
);
1459 if (peek2
== 'T' || peek2
== 't')
1461 dc
= cplus_demangle_type (di
);
1463 /* Destructor name. */
1464 dc
= d_unqualified_name (di
);
1466 else if (IS_DIGIT (peek
)
1471 dc
= d_unqualified_name (di
);
1472 else if (peek
== 'S')
1473 dc
= d_substitution (di
, 1);
1474 else if (peek
== 'I')
1478 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1479 dc
= d_template_args (di
);
1481 else if (peek
== 'T')
1482 dc
= d_template_param (di
);
1483 else if (peek
== 'E')
1485 else if (peek
== 'M')
1487 /* Initializer scope for a lambda. We don't need to represent
1488 this; the normal code will just treat the variable as a type
1489 scope, which gives appropriate output. */
1501 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1503 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1505 if (! d_add_substitution (di
, ret
))
1511 /* <unqualified-name> ::= <operator-name>
1512 ::= <ctor-dtor-name>
1514 ::= <local-source-name>
1516 <local-source-name> ::= L <source-name> <discriminator>
1519 static struct demangle_component
*
1520 d_unqualified_name (struct d_info
*di
)
1522 struct demangle_component
*ret
;
1525 peek
= d_peek_char (di
);
1526 if (IS_DIGIT (peek
))
1527 ret
= d_source_name (di
);
1528 else if (IS_LOWER (peek
))
1530 ret
= d_operator_name (di
);
1531 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1533 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1534 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1535 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1536 d_source_name (di
));
1539 else if (peek
== 'C' || peek
== 'D')
1540 ret
= d_ctor_dtor_name (di
);
1541 else if (peek
== 'L')
1545 ret
= d_source_name (di
);
1548 if (! d_discriminator (di
))
1551 else if (peek
== 'U')
1553 switch (d_peek_next_char (di
))
1556 ret
= d_lambda (di
);
1559 ret
= d_unnamed_type (di
);
1568 if (d_peek_char (di
) == 'B')
1569 ret
= d_abi_tags (di
, ret
);
1573 /* <source-name> ::= <(positive length) number> <identifier> */
1575 static struct demangle_component
*
1576 d_source_name (struct d_info
*di
)
1579 struct demangle_component
*ret
;
1581 len
= d_number (di
);
1584 ret
= d_identifier (di
, len
);
1585 di
->last_name
= ret
;
1589 /* number ::= [n] <(non-negative decimal integer)> */
1592 d_number (struct d_info
*di
)
1599 peek
= d_peek_char (di
);
1604 peek
= d_peek_char (di
);
1610 if (! IS_DIGIT (peek
))
1616 ret
= ret
* 10 + peek
- '0';
1618 peek
= d_peek_char (di
);
1622 /* Like d_number, but returns a demangle_component. */
1624 static struct demangle_component
*
1625 d_number_component (struct d_info
*di
)
1627 struct demangle_component
*ret
= d_make_empty (di
);
1630 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1631 ret
->u
.s_number
.number
= d_number (di
);
1636 /* identifier ::= <(unqualified source code identifier)> */
1638 static struct demangle_component
*
1639 d_identifier (struct d_info
*di
, int len
)
1645 if (di
->send
- name
< len
)
1648 d_advance (di
, len
);
1650 /* A Java mangled name may have a trailing '$' if it is a C++
1651 keyword. This '$' is not included in the length count. We just
1653 if ((di
->options
& DMGL_JAVA
) != 0
1654 && d_peek_char (di
) == '$')
1657 /* Look for something which looks like a gcc encoding of an
1658 anonymous namespace, and replace it with a more user friendly
1660 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1661 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1662 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1666 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1667 if ((*s
== '.' || *s
== '_' || *s
== '$')
1670 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1671 return d_make_name (di
, "(anonymous namespace)",
1672 sizeof "(anonymous namespace)" - 1);
1676 return d_make_name (di
, name
, len
);
1679 /* operator_name ::= many different two character encodings.
1681 ::= v <digit> <source-name>
1683 This list is sorted for binary search. */
1685 #define NL(s) s, (sizeof s) - 1
1687 CP_STATIC_IF_GLIBCPP_V3
1688 const struct demangle_operator_info cplus_demangle_operators
[] =
1690 { "aN", NL ("&="), 2 },
1691 { "aS", NL ("="), 2 },
1692 { "aa", NL ("&&"), 2 },
1693 { "ad", NL ("&"), 1 },
1694 { "an", NL ("&"), 2 },
1695 { "at", NL ("alignof "), 1 },
1696 { "az", NL ("alignof "), 1 },
1697 { "cc", NL ("const_cast"), 2 },
1698 { "cl", NL ("()"), 2 },
1699 { "cm", NL (","), 2 },
1700 { "co", NL ("~"), 1 },
1701 { "dV", NL ("/="), 2 },
1702 { "da", NL ("delete[] "), 1 },
1703 { "dc", NL ("dynamic_cast"), 2 },
1704 { "de", NL ("*"), 1 },
1705 { "dl", NL ("delete "), 1 },
1706 { "ds", NL (".*"), 2 },
1707 { "dt", NL ("."), 2 },
1708 { "dv", NL ("/"), 2 },
1709 { "eO", NL ("^="), 2 },
1710 { "eo", NL ("^"), 2 },
1711 { "eq", NL ("=="), 2 },
1712 { "ge", NL (">="), 2 },
1713 { "gs", NL ("::"), 1 },
1714 { "gt", NL (">"), 2 },
1715 { "ix", NL ("[]"), 2 },
1716 { "lS", NL ("<<="), 2 },
1717 { "le", NL ("<="), 2 },
1718 { "li", NL ("operator\"\" "), 1 },
1719 { "ls", NL ("<<"), 2 },
1720 { "lt", NL ("<"), 2 },
1721 { "mI", NL ("-="), 2 },
1722 { "mL", NL ("*="), 2 },
1723 { "mi", NL ("-"), 2 },
1724 { "ml", NL ("*"), 2 },
1725 { "mm", NL ("--"), 1 },
1726 { "na", NL ("new[]"), 3 },
1727 { "ne", NL ("!="), 2 },
1728 { "ng", NL ("-"), 1 },
1729 { "nt", NL ("!"), 1 },
1730 { "nw", NL ("new"), 3 },
1731 { "oR", NL ("|="), 2 },
1732 { "oo", NL ("||"), 2 },
1733 { "or", NL ("|"), 2 },
1734 { "pL", NL ("+="), 2 },
1735 { "pl", NL ("+"), 2 },
1736 { "pm", NL ("->*"), 2 },
1737 { "pp", NL ("++"), 1 },
1738 { "ps", NL ("+"), 1 },
1739 { "pt", NL ("->"), 2 },
1740 { "qu", NL ("?"), 3 },
1741 { "rM", NL ("%="), 2 },
1742 { "rS", NL (">>="), 2 },
1743 { "rc", NL ("reinterpret_cast"), 2 },
1744 { "rm", NL ("%"), 2 },
1745 { "rs", NL (">>"), 2 },
1746 { "sc", NL ("static_cast"), 2 },
1747 { "st", NL ("sizeof "), 1 },
1748 { "sz", NL ("sizeof "), 1 },
1749 { "tr", NL ("throw"), 0 },
1750 { "tw", NL ("throw "), 1 },
1751 { NULL
, NULL
, 0, 0 }
1754 static struct demangle_component
*
1755 d_operator_name (struct d_info
*di
)
1760 c1
= d_next_char (di
);
1761 c2
= d_next_char (di
);
1762 if (c1
== 'v' && IS_DIGIT (c2
))
1763 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1764 else if (c1
== 'c' && c2
== 'v')
1766 struct demangle_component
*type
;
1767 int was_conversion
= di
->is_conversion
;
1769 di
->is_conversion
= ! di
->is_expression
;
1770 type
= cplus_demangle_type (di
);
1771 di
->is_conversion
= was_conversion
;
1772 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1776 /* LOW is the inclusive lower bound. */
1778 /* HIGH is the exclusive upper bound. We subtract one to ignore
1779 the sentinel at the end of the array. */
1780 int high
= ((sizeof (cplus_demangle_operators
)
1781 / sizeof (cplus_demangle_operators
[0]))
1787 const struct demangle_operator_info
*p
;
1789 i
= low
+ (high
- low
) / 2;
1790 p
= cplus_demangle_operators
+ i
;
1792 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1793 return d_make_operator (di
, p
);
1795 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1805 static struct demangle_component
*
1806 d_make_character (struct d_info
*di
, int c
)
1808 struct demangle_component
*p
;
1809 p
= d_make_empty (di
);
1812 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1813 p
->u
.s_character
.character
= c
;
1818 static struct demangle_component
*
1819 d_java_resource (struct d_info
*di
)
1821 struct demangle_component
*p
= NULL
;
1822 struct demangle_component
*next
= NULL
;
1827 len
= d_number (di
);
1831 /* Eat the leading '_'. */
1832 if (d_next_char (di
) != '_')
1845 /* Each chunk is either a '$' escape... */
1863 next
= d_make_character (di
, c
);
1871 /* ... or a sequence of characters. */
1874 while (i
< len
&& str
[i
] && str
[i
] != '$')
1877 next
= d_make_name (di
, str
, i
);
1890 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1896 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1901 /* <special-name> ::= TV <type>
1905 ::= GV <(object) name>
1906 ::= T <call-offset> <(base) encoding>
1907 ::= Tc <call-offset> <call-offset> <(base) encoding>
1908 Also g++ extensions:
1909 ::= TC <type> <(offset) number> _ <(base) type>
1914 ::= Gr <resource name>
1919 static struct demangle_component
*
1920 d_special_name (struct d_info
*di
)
1922 di
->expansion
+= 20;
1923 if (d_check_char (di
, 'T'))
1925 switch (d_next_char (di
))
1929 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1930 cplus_demangle_type (di
), NULL
);
1932 di
->expansion
-= 10;
1933 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1934 cplus_demangle_type (di
), NULL
);
1936 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1937 cplus_demangle_type (di
), NULL
);
1939 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1940 cplus_demangle_type (di
), NULL
);
1943 if (! d_call_offset (di
, 'h'))
1945 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1946 d_encoding (di
, 0), NULL
);
1949 if (! d_call_offset (di
, 'v'))
1951 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1952 d_encoding (di
, 0), NULL
);
1955 if (! d_call_offset (di
, '\0'))
1957 if (! d_call_offset (di
, '\0'))
1959 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1960 d_encoding (di
, 0), NULL
);
1964 struct demangle_component
*derived_type
;
1966 struct demangle_component
*base_type
;
1968 derived_type
= cplus_demangle_type (di
);
1969 offset
= d_number (di
);
1972 if (! d_check_char (di
, '_'))
1974 base_type
= cplus_demangle_type (di
);
1975 /* We don't display the offset. FIXME: We should display
1976 it in verbose mode. */
1978 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1979 base_type
, derived_type
);
1983 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1984 cplus_demangle_type (di
), NULL
);
1986 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1987 cplus_demangle_type (di
), NULL
);
1990 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
1994 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2001 else if (d_check_char (di
, 'G'))
2003 switch (d_next_char (di
))
2006 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2010 struct demangle_component
*name
= d_name (di
);
2011 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2012 d_number_component (di
));
2016 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2017 d_encoding (di
, 0), NULL
);
2020 switch (d_next_char (di
))
2023 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2024 d_encoding (di
, 0), NULL
);
2026 /* ??? The proposal is that other letters (such as 'h') stand
2027 for different variants of transaction cloning, such as
2028 compiling directly for hardware transaction support. But
2029 they still should all be transactional clones of some sort
2030 so go ahead and call them that. */
2032 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2033 d_encoding (di
, 0), NULL
);
2037 return d_java_resource (di
);
2047 /* <call-offset> ::= h <nv-offset> _
2050 <nv-offset> ::= <(offset) number>
2052 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2054 The C parameter, if not '\0', is a character we just read which is
2055 the start of the <call-offset>.
2057 We don't display the offset information anywhere. FIXME: We should
2058 display it in verbose mode. */
2061 d_call_offset (struct d_info
*di
, int c
)
2064 c
= d_next_char (di
);
2071 if (! d_check_char (di
, '_'))
2078 if (! d_check_char (di
, '_'))
2084 /* <ctor-dtor-name> ::= C1
2092 static struct demangle_component
*
2093 d_ctor_dtor_name (struct d_info
*di
)
2095 if (di
->last_name
!= NULL
)
2097 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2098 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2099 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2100 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2102 switch (d_peek_char (di
))
2106 enum gnu_v3_ctor_kinds kind
;
2108 switch (d_peek_next_char (di
))
2111 kind
= gnu_v3_complete_object_ctor
;
2114 kind
= gnu_v3_base_object_ctor
;
2117 kind
= gnu_v3_complete_object_allocating_ctor
;
2120 kind
= gnu_v3_unified_ctor
;
2123 kind
= gnu_v3_object_ctor_group
;
2129 return d_make_ctor (di
, kind
, di
->last_name
);
2134 enum gnu_v3_dtor_kinds kind
;
2136 switch (d_peek_next_char (di
))
2139 kind
= gnu_v3_deleting_dtor
;
2142 kind
= gnu_v3_complete_object_dtor
;
2145 kind
= gnu_v3_base_object_dtor
;
2147 /* digit '3' is not used */
2149 kind
= gnu_v3_unified_dtor
;
2152 kind
= gnu_v3_object_dtor_group
;
2158 return d_make_dtor (di
, kind
, di
->last_name
);
2166 /* <type> ::= <builtin-type>
2168 ::= <class-enum-type>
2170 ::= <pointer-to-member-type>
2171 ::= <template-param>
2172 ::= <template-template-param> <template-args>
2174 ::= <CV-qualifiers> <type>
2177 ::= O <type> (C++0x)
2180 ::= U <source-name> <type>
2182 <builtin-type> ::= various one letter codes
2186 CP_STATIC_IF_GLIBCPP_V3
2187 const struct demangle_builtin_type_info
2188 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2190 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2191 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2192 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2193 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2194 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2195 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2196 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2197 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2198 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2199 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2200 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2201 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2202 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2203 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2204 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2206 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2207 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2208 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2209 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2210 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2211 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2212 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2213 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2214 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2215 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2216 D_PRINT_UNSIGNED_LONG_LONG
},
2217 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2218 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2219 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2220 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2221 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2222 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2223 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2224 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2228 CP_STATIC_IF_GLIBCPP_V3
2229 struct demangle_component
*
2230 cplus_demangle_type (struct d_info
*di
)
2233 struct demangle_component
*ret
;
2236 /* The ABI specifies that when CV-qualifiers are used, the base type
2237 is substitutable, and the fully qualified type is substitutable,
2238 but the base type with a strict subset of the CV-qualifiers is
2239 not substitutable. The natural recursive implementation of the
2240 CV-qualifiers would cause subsets to be substitutable, so instead
2241 we pull them all off now.
2243 FIXME: The ABI says that order-insensitive vendor qualifiers
2244 should be handled in the same way, but we have no way to tell
2245 which vendor qualifiers are order-insensitive and which are
2246 order-sensitive. So we just assume that they are all
2247 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2248 __vector, and it treats it as order-sensitive when mangling
2251 peek
= d_peek_char (di
);
2252 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2254 struct demangle_component
**pret
;
2256 pret
= d_cv_qualifiers (di
, &ret
, 0);
2259 if (d_peek_char (di
) == 'F')
2261 /* cv-qualifiers before a function type apply to 'this',
2262 so avoid adding the unqualified function type to
2263 the substitution list. */
2264 *pret
= d_function_type (di
);
2267 *pret
= cplus_demangle_type (di
);
2270 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2271 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2273 /* Move the ref-qualifier outside the cv-qualifiers so that
2274 they are printed in the right order. */
2275 struct demangle_component
*fn
= d_left (*pret
);
2276 d_left (*pret
) = ret
;
2280 if (! d_add_substitution (di
, ret
))
2289 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2290 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2291 case 'o': case 's': case 't':
2292 case 'v': case 'w': case 'x': case 'y': case 'z':
2293 ret
= d_make_builtin_type (di
,
2294 &cplus_demangle_builtin_types
[peek
- 'a']);
2295 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2302 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2303 d_source_name (di
), NULL
);
2307 ret
= d_function_type (di
);
2310 case '0': case '1': case '2': case '3': case '4':
2311 case '5': case '6': case '7': case '8': case '9':
2314 ret
= d_class_enum_type (di
);
2318 ret
= d_array_type (di
);
2322 ret
= d_pointer_to_member_type (di
);
2326 ret
= d_template_param (di
);
2327 if (d_peek_char (di
) == 'I')
2329 /* This may be <template-template-param> <template-args>.
2330 If this is the type for a conversion operator, we can
2331 have a <template-template-param> here only by following
2332 a derivation like this:
2335 -> <template-prefix> <template-args>
2336 -> <prefix> <template-unqualified-name> <template-args>
2337 -> <unqualified-name> <template-unqualified-name> <template-args>
2338 -> <source-name> <template-unqualified-name> <template-args>
2339 -> <source-name> <operator-name> <template-args>
2340 -> <source-name> cv <type> <template-args>
2341 -> <source-name> cv <template-template-param> <template-args> <template-args>
2343 where the <template-args> is followed by another.
2344 Otherwise, we must have a derivation like this:
2347 -> <template-prefix> <template-args>
2348 -> <prefix> <template-unqualified-name> <template-args>
2349 -> <unqualified-name> <template-unqualified-name> <template-args>
2350 -> <source-name> <template-unqualified-name> <template-args>
2351 -> <source-name> <operator-name> <template-args>
2352 -> <source-name> cv <type> <template-args>
2353 -> <source-name> cv <template-param> <template-args>
2355 where we need to leave the <template-args> to be processed
2356 by d_prefix (following the <template-prefix>).
2358 The <template-template-param> part is a substitution
2360 if (! di
->is_conversion
)
2362 if (! d_add_substitution (di
, ret
))
2364 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2365 d_template_args (di
));
2369 struct demangle_component
*args
;
2370 struct d_info_checkpoint checkpoint
;
2372 d_checkpoint (di
, &checkpoint
);
2373 args
= d_template_args (di
);
2374 if (d_peek_char (di
) == 'I')
2376 if (! d_add_substitution (di
, ret
))
2378 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2382 d_backtrack (di
, &checkpoint
);
2388 /* If this is a special substitution, then it is the start of
2389 <class-enum-type>. */
2393 peek_next
= d_peek_next_char (di
);
2394 if (IS_DIGIT (peek_next
)
2396 || IS_UPPER (peek_next
))
2398 ret
= d_substitution (di
, 0);
2399 /* The substituted name may have been a template name and
2400 may be followed by tepmlate args. */
2401 if (d_peek_char (di
) == 'I')
2402 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2403 d_template_args (di
));
2409 ret
= d_class_enum_type (di
);
2410 /* If the substitution was a complete type, then it is not
2411 a new substitution candidate. However, if the
2412 substitution was followed by template arguments, then
2413 the whole thing is a substitution candidate. */
2414 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2422 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2423 cplus_demangle_type (di
), NULL
);
2428 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2429 cplus_demangle_type (di
), NULL
);
2434 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2435 cplus_demangle_type (di
), NULL
);
2440 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2441 cplus_demangle_type (di
), NULL
);
2446 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2447 cplus_demangle_type (di
), NULL
);
2452 ret
= d_source_name (di
);
2453 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2454 cplus_demangle_type (di
), ret
);
2460 peek
= d_next_char (di
);
2465 /* decltype (expression) */
2466 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2467 d_expression (di
), NULL
);
2468 if (ret
&& d_next_char (di
) != 'E')
2474 /* Pack expansion. */
2475 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2476 cplus_demangle_type (di
), NULL
);
2482 ret
= d_make_name (di
, "auto", 4);
2486 /* 32-bit decimal floating point */
2487 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2488 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2492 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2493 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2497 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2498 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2501 /* 16-bit half-precision FP */
2502 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2503 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2507 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2508 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2512 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2513 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2517 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2518 ret
= d_make_empty (di
);
2519 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2520 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2521 /* For demangling we don't care about the bits. */
2523 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2524 if (ret
->u
.s_fixed
.length
== NULL
)
2527 peek
= d_next_char (di
);
2528 ret
->u
.s_fixed
.sat
= (peek
== 's');
2532 ret
= d_vector_type (di
);
2537 /* decltype(nullptr) */
2538 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2539 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2553 if (! d_add_substitution (di
, ret
))
2560 /* <CV-qualifiers> ::= [r] [V] [K] */
2562 static struct demangle_component
**
2563 d_cv_qualifiers (struct d_info
*di
,
2564 struct demangle_component
**pret
, int member_fn
)
2566 struct demangle_component
**pstart
;
2570 peek
= d_peek_char (di
);
2571 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2573 enum demangle_component_type t
;
2579 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2580 : DEMANGLE_COMPONENT_RESTRICT
);
2581 di
->expansion
+= sizeof "restrict";
2583 else if (peek
== 'V')
2586 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2587 : DEMANGLE_COMPONENT_VOLATILE
);
2588 di
->expansion
+= sizeof "volatile";
2593 ? DEMANGLE_COMPONENT_CONST_THIS
2594 : DEMANGLE_COMPONENT_CONST
);
2595 di
->expansion
+= sizeof "const";
2598 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2601 pret
= &d_left (*pret
);
2603 peek
= d_peek_char (di
);
2606 if (!member_fn
&& peek
== 'F')
2608 while (pstart
!= pret
)
2610 switch ((*pstart
)->type
)
2612 case DEMANGLE_COMPONENT_RESTRICT
:
2613 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2615 case DEMANGLE_COMPONENT_VOLATILE
:
2616 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2618 case DEMANGLE_COMPONENT_CONST
:
2619 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2624 pstart
= &d_left (*pstart
);
2631 /* <ref-qualifier> ::= R
2634 static struct demangle_component
*
2635 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2637 struct demangle_component
*ret
= sub
;
2640 peek
= d_peek_char (di
);
2641 if (peek
== 'R' || peek
== 'O')
2643 enum demangle_component_type t
;
2646 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2647 di
->expansion
+= sizeof "&";
2651 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2652 di
->expansion
+= sizeof "&&";
2656 ret
= d_make_comp (di
, t
, ret
, NULL
);
2662 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
2664 static struct demangle_component
*
2665 d_function_type (struct d_info
*di
)
2667 struct demangle_component
*ret
;
2669 if (! d_check_char (di
, 'F'))
2671 if (d_peek_char (di
) == 'Y')
2673 /* Function has C linkage. We don't print this information.
2674 FIXME: We should print it in verbose mode. */
2677 ret
= d_bare_function_type (di
, 1);
2678 ret
= d_ref_qualifier (di
, ret
);
2680 if (! d_check_char (di
, 'E'))
2687 static struct demangle_component
*
2688 d_parmlist (struct d_info
*di
)
2690 struct demangle_component
*tl
;
2691 struct demangle_component
**ptl
;
2697 struct demangle_component
*type
;
2699 char peek
= d_peek_char (di
);
2700 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2702 if ((peek
== 'R' || peek
== 'O')
2703 && d_peek_next_char (di
) == 'E')
2704 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2706 type
= cplus_demangle_type (di
);
2709 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2712 ptl
= &d_right (*ptl
);
2715 /* There should be at least one parameter type besides the optional
2716 return type. A function which takes no arguments will have a
2717 single parameter type void. */
2721 /* If we have a single parameter type void, omit it. */
2722 if (d_right (tl
) == NULL
2723 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2724 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2726 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2733 /* <bare-function-type> ::= [J]<type>+ */
2735 static struct demangle_component
*
2736 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2738 struct demangle_component
*return_type
;
2739 struct demangle_component
*tl
;
2742 /* Detect special qualifier indicating that the first argument
2743 is the return type. */
2744 peek
= d_peek_char (di
);
2748 has_return_type
= 1;
2751 if (has_return_type
)
2753 return_type
= cplus_demangle_type (di
);
2754 if (return_type
== NULL
)
2760 tl
= d_parmlist (di
);
2764 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2768 /* <class-enum-type> ::= <name> */
2770 static struct demangle_component
*
2771 d_class_enum_type (struct d_info
*di
)
2776 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2777 ::= A [<(dimension) expression>] _ <(element) type>
2780 static struct demangle_component
*
2781 d_array_type (struct d_info
*di
)
2784 struct demangle_component
*dim
;
2786 if (! d_check_char (di
, 'A'))
2789 peek
= d_peek_char (di
);
2792 else if (IS_DIGIT (peek
))
2800 peek
= d_peek_char (di
);
2802 while (IS_DIGIT (peek
));
2803 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2809 dim
= d_expression (di
);
2814 if (! d_check_char (di
, '_'))
2817 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2818 cplus_demangle_type (di
));
2821 /* <vector-type> ::= Dv <number> _ <type>
2822 ::= Dv _ <expression> _ <type> */
2824 static struct demangle_component
*
2825 d_vector_type (struct d_info
*di
)
2828 struct demangle_component
*dim
;
2830 peek
= d_peek_char (di
);
2834 dim
= d_expression (di
);
2837 dim
= d_number_component (di
);
2842 if (! d_check_char (di
, '_'))
2845 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2846 cplus_demangle_type (di
));
2849 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2851 static struct demangle_component
*
2852 d_pointer_to_member_type (struct d_info
*di
)
2854 struct demangle_component
*cl
;
2855 struct demangle_component
*mem
;
2857 if (! d_check_char (di
, 'M'))
2860 cl
= cplus_demangle_type (di
);
2864 /* The ABI says, "The type of a non-static member function is considered
2865 to be different, for the purposes of substitution, from the type of a
2866 namespace-scope or static member function whose type appears
2867 similar. The types of two non-static member functions are considered
2868 to be different, for the purposes of substitution, if the functions
2869 are members of different classes. In other words, for the purposes of
2870 substitution, the class of which the function is a member is
2871 considered part of the type of function."
2873 For a pointer to member function, this call to cplus_demangle_type
2874 will end up adding a (possibly qualified) non-member function type to
2875 the substitution table, which is not correct; however, the member
2876 function type will never be used in a substitution, so putting the
2877 wrong type in the substitution table is harmless. */
2879 mem
= cplus_demangle_type (di
);
2883 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2886 /* <non-negative number> _ */
2889 d_compact_number (struct d_info
*di
)
2892 if (d_peek_char (di
) == '_')
2894 else if (d_peek_char (di
) == 'n')
2897 num
= d_number (di
) + 1;
2899 if (! d_check_char (di
, '_'))
2904 /* <template-param> ::= T_
2905 ::= T <(parameter-2 non-negative) number> _
2908 static struct demangle_component
*
2909 d_template_param (struct d_info
*di
)
2913 if (! d_check_char (di
, 'T'))
2916 param
= d_compact_number (di
);
2922 return d_make_template_param (di
, param
);
2925 /* <template-args> ::= I <template-arg>+ E */
2927 static struct demangle_component
*
2928 d_template_args (struct d_info
*di
)
2930 struct demangle_component
*hold_last_name
;
2931 struct demangle_component
*al
;
2932 struct demangle_component
**pal
;
2934 /* Preserve the last name we saw--don't let the template arguments
2935 clobber it, as that would give us the wrong name for a subsequent
2936 constructor or destructor. */
2937 hold_last_name
= di
->last_name
;
2939 if (d_peek_char (di
) != 'I'
2940 && d_peek_char (di
) != 'J')
2944 if (d_peek_char (di
) == 'E')
2946 /* An argument pack can be empty. */
2948 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2955 struct demangle_component
*a
;
2957 a
= d_template_arg (di
);
2961 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2964 pal
= &d_right (*pal
);
2966 if (d_peek_char (di
) == 'E')
2973 di
->last_name
= hold_last_name
;
2978 /* <template-arg> ::= <type>
2979 ::= X <expression> E
2983 static struct demangle_component
*
2984 d_template_arg (struct d_info
*di
)
2986 struct demangle_component
*ret
;
2988 switch (d_peek_char (di
))
2992 ret
= d_expression (di
);
2993 if (! d_check_char (di
, 'E'))
2998 return d_expr_primary (di
);
3002 /* An argument pack. */
3003 return d_template_args (di
);
3006 return cplus_demangle_type (di
);
3010 /* Parse a sequence of expressions until we hit the terminator
3013 static struct demangle_component
*
3014 d_exprlist (struct d_info
*di
, char terminator
)
3016 struct demangle_component
*list
= NULL
;
3017 struct demangle_component
**p
= &list
;
3019 if (d_peek_char (di
) == terminator
)
3022 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3027 struct demangle_component
*arg
= d_expression (di
);
3031 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3036 if (d_peek_char (di
) == terminator
)
3046 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3047 dynamic_cast, static_cast or reinterpret_cast. */
3050 op_is_new_cast (struct demangle_component
*op
)
3052 const char *code
= op
->u
.s_operator
.op
->code
;
3053 return (code
[1] == 'c'
3054 && (code
[0] == 's' || code
[0] == 'd'
3055 || code
[0] == 'c' || code
[0] == 'r'));
3058 /* <expression> ::= <(unary) operator-name> <expression>
3059 ::= <(binary) operator-name> <expression> <expression>
3060 ::= <(trinary) operator-name> <expression> <expression> <expression>
3061 ::= cl <expression>+ E
3063 ::= <template-param>
3064 ::= sr <type> <unqualified-name>
3065 ::= sr <type> <unqualified-name> <template-args>
3069 static inline struct demangle_component
*
3070 d_expression_1 (struct d_info
*di
)
3074 peek
= d_peek_char (di
);
3076 return d_expr_primary (di
);
3077 else if (peek
== 'T')
3078 return d_template_param (di
);
3079 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3081 struct demangle_component
*type
;
3082 struct demangle_component
*name
;
3085 type
= cplus_demangle_type (di
);
3086 name
= d_unqualified_name (di
);
3087 if (d_peek_char (di
) != 'I')
3088 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3090 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3091 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3092 d_template_args (di
)));
3094 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3097 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3098 d_expression_1 (di
), NULL
);
3100 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3102 /* Function parameter used in a late-specified return type. */
3105 if (d_peek_char (di
) == 'T')
3107 /* 'this' parameter. */
3113 index
= d_compact_number (di
) + 1;
3117 return d_make_function_param (di
, index
);
3119 else if (IS_DIGIT (peek
)
3120 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3122 /* We can get an unqualified name as an expression in the case of
3123 a dependent function call, i.e. decltype(f(t)). */
3124 struct demangle_component
*name
;
3127 /* operator-function-id, i.e. operator+(t). */
3130 name
= d_unqualified_name (di
);
3133 if (d_peek_char (di
) == 'I')
3134 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3135 d_template_args (di
));
3139 else if ((peek
== 'i' || peek
== 't')
3140 && d_peek_next_char (di
) == 'l')
3142 /* Brace-enclosed initializer list, untyped or typed. */
3143 struct demangle_component
*type
= NULL
;
3145 type
= cplus_demangle_type (di
);
3147 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3148 type
, d_exprlist (di
, 'E'));
3152 struct demangle_component
*op
;
3153 const char *code
= NULL
;
3156 op
= d_operator_name (di
);
3160 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3162 code
= op
->u
.s_operator
.op
->code
;
3163 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3164 if (strcmp (code
, "st") == 0)
3165 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3166 cplus_demangle_type (di
));
3173 case DEMANGLE_COMPONENT_OPERATOR
:
3174 args
= op
->u
.s_operator
.op
->args
;
3176 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3177 args
= op
->u
.s_extended_operator
.args
;
3179 case DEMANGLE_COMPONENT_CAST
:
3187 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3191 struct demangle_component
*operand
;
3194 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3195 && code
[1] == code
[0])
3196 /* pp_ and mm_ are the prefix variants. */
3197 suffix
= !d_check_char (di
, '_');
3199 if (op
->type
== DEMANGLE_COMPONENT_CAST
3200 && d_check_char (di
, '_'))
3201 operand
= d_exprlist (di
, 'E');
3203 operand
= d_expression_1 (di
);
3206 /* Indicate the suffix variant for d_print_comp. */
3207 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3209 DEMANGLE_COMPONENT_BINARY_ARGS
,
3212 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3217 struct demangle_component
*left
;
3218 struct demangle_component
*right
;
3220 if (op_is_new_cast (op
))
3221 left
= cplus_demangle_type (di
);
3223 left
= d_expression_1 (di
);
3224 if (!strcmp (code
, "cl"))
3225 right
= d_exprlist (di
, 'E');
3226 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3228 right
= d_unqualified_name (di
);
3229 if (d_peek_char (di
) == 'I')
3230 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3231 right
, d_template_args (di
));
3234 right
= d_expression_1 (di
);
3236 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3238 DEMANGLE_COMPONENT_BINARY_ARGS
,
3243 struct demangle_component
*first
;
3244 struct demangle_component
*second
;
3245 struct demangle_component
*third
;
3247 if (!strcmp (code
, "qu"))
3249 /* ?: expression. */
3250 first
= d_expression_1 (di
);
3251 second
= d_expression_1 (di
);
3252 third
= d_expression_1 (di
);
3254 else if (code
[0] == 'n')
3256 /* new-expression. */
3257 if (code
[1] != 'w' && code
[1] != 'a')
3259 first
= d_exprlist (di
, '_');
3260 second
= cplus_demangle_type (di
);
3261 if (d_peek_char (di
) == 'E')
3266 else if (d_peek_char (di
) == 'p'
3267 && d_peek_next_char (di
) == 'i')
3269 /* Parenthesized initializer. */
3271 third
= d_exprlist (di
, 'E');
3273 else if (d_peek_char (di
) == 'i'
3274 && d_peek_next_char (di
) == 'l')
3275 /* initializer-list. */
3276 third
= d_expression_1 (di
);
3282 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3284 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3287 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3296 static struct demangle_component
*
3297 d_expression (struct d_info
*di
)
3299 struct demangle_component
*ret
;
3300 int was_expression
= di
->is_expression
;
3302 di
->is_expression
= 1;
3303 ret
= d_expression_1 (di
);
3304 di
->is_expression
= was_expression
;
3308 /* <expr-primary> ::= L <type> <(value) number> E
3309 ::= L <type> <(value) float> E
3310 ::= L <mangled-name> E
3313 static struct demangle_component
*
3314 d_expr_primary (struct d_info
*di
)
3316 struct demangle_component
*ret
;
3318 if (! d_check_char (di
, 'L'))
3320 if (d_peek_char (di
) == '_'
3321 /* Workaround for G++ bug; see comment in write_template_arg. */
3322 || d_peek_char (di
) == 'Z')
3323 ret
= cplus_demangle_mangled_name (di
, 0);
3326 struct demangle_component
*type
;
3327 enum demangle_component_type t
;
3330 type
= cplus_demangle_type (di
);
3334 /* If we have a type we know how to print, we aren't going to
3335 print the type name itself. */
3336 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3337 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3338 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3340 /* Rather than try to interpret the literal value, we just
3341 collect it as a string. Note that it's possible to have a
3342 floating point literal here. The ABI specifies that the
3343 format of such literals is machine independent. That's fine,
3344 but what's not fine is that versions of g++ up to 3.2 with
3345 -fabi-version=1 used upper case letters in the hex constant,
3346 and dumped out gcc's internal representation. That makes it
3347 hard to tell where the constant ends, and hard to dump the
3348 constant in any readable form anyhow. We don't attempt to
3349 handle these cases. */
3351 t
= DEMANGLE_COMPONENT_LITERAL
;
3352 if (d_peek_char (di
) == 'n')
3354 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3358 while (d_peek_char (di
) != 'E')
3360 if (d_peek_char (di
) == '\0')
3364 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3366 if (! d_check_char (di
, 'E'))
3371 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3372 ::= Z <(function) encoding> E s [<discriminator>]
3373 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3376 static struct demangle_component
*
3377 d_local_name (struct d_info
*di
)
3379 struct demangle_component
*function
;
3381 if (! d_check_char (di
, 'Z'))
3384 function
= d_encoding (di
, 0);
3386 if (! d_check_char (di
, 'E'))
3389 if (d_peek_char (di
) == 's')
3392 if (! d_discriminator (di
))
3394 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3395 d_make_name (di
, "string literal",
3396 sizeof "string literal" - 1));
3400 struct demangle_component
*name
;
3403 if (d_peek_char (di
) == 'd')
3405 /* Default argument scope: d <number> _. */
3407 num
= d_compact_number (di
);
3416 /* Lambdas and unnamed types have internal discriminators. */
3417 case DEMANGLE_COMPONENT_LAMBDA
:
3418 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3421 if (! d_discriminator (di
))
3425 name
= d_make_default_arg (di
, num
, name
);
3426 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3430 /* <discriminator> ::= _ <(non-negative) number>
3432 We demangle the discriminator, but we don't print it out. FIXME:
3433 We should print it out in verbose mode. */
3436 d_discriminator (struct d_info
*di
)
3440 if (d_peek_char (di
) != '_')
3443 discrim
= d_number (di
);
3449 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3451 static struct demangle_component
*
3452 d_lambda (struct d_info
*di
)
3454 struct demangle_component
*tl
;
3455 struct demangle_component
*ret
;
3458 if (! d_check_char (di
, 'U'))
3460 if (! d_check_char (di
, 'l'))
3463 tl
= d_parmlist (di
);
3467 if (! d_check_char (di
, 'E'))
3470 num
= d_compact_number (di
);
3474 ret
= d_make_empty (di
);
3477 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3478 ret
->u
.s_unary_num
.sub
= tl
;
3479 ret
->u
.s_unary_num
.num
= num
;
3482 if (! d_add_substitution (di
, ret
))
3488 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3490 static struct demangle_component
*
3491 d_unnamed_type (struct d_info
*di
)
3493 struct demangle_component
*ret
;
3496 if (! d_check_char (di
, 'U'))
3498 if (! d_check_char (di
, 't'))
3501 num
= d_compact_number (di
);
3505 ret
= d_make_empty (di
);
3508 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3509 ret
->u
.s_number
.number
= num
;
3512 if (! d_add_substitution (di
, ret
))
3518 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3521 static struct demangle_component
*
3522 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3524 const char *suffix
= d_str (di
);
3525 const char *pend
= suffix
;
3526 struct demangle_component
*n
;
3528 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3531 while (IS_LOWER (*pend
) || *pend
== '_')
3534 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3537 while (IS_DIGIT (*pend
))
3540 d_advance (di
, pend
- suffix
);
3541 n
= d_make_name (di
, suffix
, pend
- suffix
);
3542 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3545 /* Add a new substitution. */
3548 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3552 if (di
->next_sub
>= di
->num_subs
)
3554 di
->subs
[di
->next_sub
] = dc
;
3559 /* <substitution> ::= S <seq-id> _
3569 If PREFIX is non-zero, then this type is being used as a prefix in
3570 a qualified name. In this case, for the standard substitutions, we
3571 need to check whether we are being used as a prefix for a
3572 constructor or destructor, and return a full template name.
3573 Otherwise we will get something like std::iostream::~iostream()
3574 which does not correspond particularly well to any function which
3575 actually appears in the source.
3578 static const struct d_standard_sub_info standard_subs
[] =
3583 { 'a', NL ("std::allocator"),
3584 NL ("std::allocator"),
3586 { 'b', NL ("std::basic_string"),
3587 NL ("std::basic_string"),
3588 NL ("basic_string") },
3589 { 's', NL ("std::string"),
3590 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3591 NL ("basic_string") },
3592 { 'i', NL ("std::istream"),
3593 NL ("std::basic_istream<char, std::char_traits<char> >"),
3594 NL ("basic_istream") },
3595 { 'o', NL ("std::ostream"),
3596 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3597 NL ("basic_ostream") },
3598 { 'd', NL ("std::iostream"),
3599 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3600 NL ("basic_iostream") }
3603 static struct demangle_component
*
3604 d_substitution (struct d_info
*di
, int prefix
)
3608 if (! d_check_char (di
, 'S'))
3611 c
= d_next_char (di
);
3612 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3621 unsigned int new_id
;
3624 new_id
= id
* 36 + c
- '0';
3625 else if (IS_UPPER (c
))
3626 new_id
= id
* 36 + c
- 'A' + 10;
3632 c
= d_next_char (di
);
3639 if (id
>= (unsigned int) di
->next_sub
)
3644 return di
->subs
[id
];
3649 const struct d_standard_sub_info
*p
;
3650 const struct d_standard_sub_info
*pend
;
3652 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3653 if (! verbose
&& prefix
)
3657 peek
= d_peek_char (di
);
3658 if (peek
== 'C' || peek
== 'D')
3662 pend
= (&standard_subs
[0]
3663 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3664 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3671 if (p
->set_last_name
!= NULL
)
3672 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3673 p
->set_last_name_len
);
3676 s
= p
->full_expansion
;
3681 s
= p
->simple_expansion
;
3682 len
= p
->simple_len
;
3684 di
->expansion
+= len
;
3685 return d_make_sub (di
, s
, len
);
3694 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3696 checkpoint
->n
= di
->n
;
3697 checkpoint
->next_comp
= di
->next_comp
;
3698 checkpoint
->next_sub
= di
->next_sub
;
3699 checkpoint
->did_subs
= di
->did_subs
;
3700 checkpoint
->expansion
= di
->expansion
;
3704 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3706 di
->n
= checkpoint
->n
;
3707 di
->next_comp
= checkpoint
->next_comp
;
3708 di
->next_sub
= checkpoint
->next_sub
;
3709 di
->did_subs
= checkpoint
->did_subs
;
3710 di
->expansion
= checkpoint
->expansion
;
3713 /* Initialize a growable string. */
3716 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3721 dgs
->allocation_failure
= 0;
3724 d_growable_string_resize (dgs
, estimate
);
3727 /* Grow a growable string to a given size. */
3730 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3735 if (dgs
->allocation_failure
)
3738 /* Start allocation at two bytes to avoid any possibility of confusion
3739 with the special value of 1 used as a return in *palc to indicate
3740 allocation failures. */
3741 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3742 while (newalc
< need
)
3745 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3752 dgs
->allocation_failure
= 1;
3759 /* Append a buffer to a growable string. */
3762 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3763 const char *s
, size_t l
)
3767 need
= dgs
->len
+ l
+ 1;
3768 if (need
> dgs
->alc
)
3769 d_growable_string_resize (dgs
, need
);
3771 if (dgs
->allocation_failure
)
3774 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3775 dgs
->buf
[dgs
->len
+ l
] = '\0';
3779 /* Bridge growable strings to the callback mechanism. */
3782 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3784 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3786 d_growable_string_append_buffer (dgs
, s
, l
);
3789 /* Walk the tree, counting the number of templates encountered, and
3790 the number of times a scope might be saved. These counts will be
3791 used to allocate data structures for d_print_comp, so the logic
3792 here must mirror the logic d_print_comp will use. It is not
3793 important that the resulting numbers are exact, so long as they
3794 are larger than the actual numbers encountered. */
3797 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
3798 const struct demangle_component
*dc
)
3805 case DEMANGLE_COMPONENT_NAME
:
3806 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3807 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3808 case DEMANGLE_COMPONENT_SUB_STD
:
3809 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3810 case DEMANGLE_COMPONENT_OPERATOR
:
3811 case DEMANGLE_COMPONENT_CHARACTER
:
3812 case DEMANGLE_COMPONENT_NUMBER
:
3813 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3816 case DEMANGLE_COMPONENT_TEMPLATE
:
3818 goto recurse_left_right
;
3820 case DEMANGLE_COMPONENT_REFERENCE
:
3821 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3822 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
3824 goto recurse_left_right
;
3826 case DEMANGLE_COMPONENT_QUAL_NAME
:
3827 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3828 case DEMANGLE_COMPONENT_TYPED_NAME
:
3829 case DEMANGLE_COMPONENT_VTABLE
:
3830 case DEMANGLE_COMPONENT_VTT
:
3831 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3832 case DEMANGLE_COMPONENT_TYPEINFO
:
3833 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3834 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3835 case DEMANGLE_COMPONENT_THUNK
:
3836 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3837 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3838 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3839 case DEMANGLE_COMPONENT_GUARD
:
3840 case DEMANGLE_COMPONENT_TLS_INIT
:
3841 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
3842 case DEMANGLE_COMPONENT_REFTEMP
:
3843 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3844 case DEMANGLE_COMPONENT_RESTRICT
:
3845 case DEMANGLE_COMPONENT_VOLATILE
:
3846 case DEMANGLE_COMPONENT_CONST
:
3847 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3848 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3849 case DEMANGLE_COMPONENT_CONST_THIS
:
3850 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
3851 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
3852 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3853 case DEMANGLE_COMPONENT_POINTER
:
3854 case DEMANGLE_COMPONENT_COMPLEX
:
3855 case DEMANGLE_COMPONENT_IMAGINARY
:
3856 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3857 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3858 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3859 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3860 case DEMANGLE_COMPONENT_FIXED_TYPE
:
3861 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
3862 case DEMANGLE_COMPONENT_ARGLIST
:
3863 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3864 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
3865 case DEMANGLE_COMPONENT_CAST
:
3866 case DEMANGLE_COMPONENT_NULLARY
:
3867 case DEMANGLE_COMPONENT_UNARY
:
3868 case DEMANGLE_COMPONENT_BINARY
:
3869 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3870 case DEMANGLE_COMPONENT_TRINARY
:
3871 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3872 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3873 case DEMANGLE_COMPONENT_LITERAL
:
3874 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3875 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
3876 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
3877 case DEMANGLE_COMPONENT_DECLTYPE
:
3878 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
3879 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
3880 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3881 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3882 case DEMANGLE_COMPONENT_CLONE
:
3884 d_count_templates_scopes (num_templates
, num_scopes
,
3886 d_count_templates_scopes (num_templates
, num_scopes
,
3890 case DEMANGLE_COMPONENT_CTOR
:
3891 d_count_templates_scopes (num_templates
, num_scopes
,
3895 case DEMANGLE_COMPONENT_DTOR
:
3896 d_count_templates_scopes (num_templates
, num_scopes
,
3900 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3901 d_count_templates_scopes (num_templates
, num_scopes
,
3902 dc
->u
.s_extended_operator
.name
);
3905 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
3906 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
3907 d_count_templates_scopes (num_templates
, num_scopes
,
3911 case DEMANGLE_COMPONENT_LAMBDA
:
3912 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
3913 d_count_templates_scopes (num_templates
, num_scopes
,
3914 dc
->u
.s_unary_num
.sub
);
3919 /* Initialize a print information structure. */
3922 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
3923 void *opaque
, const struct demangle_component
*dc
)
3926 dpi
->last_char
= '\0';
3927 dpi
->templates
= NULL
;
3928 dpi
->modifiers
= NULL
;
3929 dpi
->pack_index
= 0;
3930 dpi
->flush_count
= 0;
3932 dpi
->callback
= callback
;
3933 dpi
->opaque
= opaque
;
3935 dpi
->demangle_failure
= 0;
3937 dpi
->saved_scopes
= NULL
;
3938 dpi
->next_saved_scope
= 0;
3939 dpi
->num_saved_scopes
= 0;
3941 dpi
->copy_templates
= NULL
;
3942 dpi
->next_copy_template
= 0;
3943 dpi
->num_copy_templates
= 0;
3945 d_count_templates_scopes (&dpi
->num_copy_templates
,
3946 &dpi
->num_saved_scopes
, dc
);
3947 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
3949 dpi
->current_template
= NULL
;
3952 /* Indicate that an error occurred during printing, and test for error. */
3955 d_print_error (struct d_print_info
*dpi
)
3957 dpi
->demangle_failure
= 1;
3961 d_print_saw_error (struct d_print_info
*dpi
)
3963 return dpi
->demangle_failure
!= 0;
3966 /* Flush buffered characters to the callback. */
3969 d_print_flush (struct d_print_info
*dpi
)
3971 dpi
->buf
[dpi
->len
] = '\0';
3972 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3977 /* Append characters and buffers for printing. */
3980 d_append_char (struct d_print_info
*dpi
, char c
)
3982 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3983 d_print_flush (dpi
);
3985 dpi
->buf
[dpi
->len
++] = c
;
3990 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3994 for (i
= 0; i
< l
; i
++)
3995 d_append_char (dpi
, s
[i
]);
3999 d_append_string (struct d_print_info
*dpi
, const char *s
)
4001 d_append_buffer (dpi
, s
, strlen (s
));
4005 d_append_num (struct d_print_info
*dpi
, long l
)
4008 sprintf (buf
,"%ld", l
);
4009 d_append_string (dpi
, buf
);
4013 d_last_char (struct d_print_info
*dpi
)
4015 return dpi
->last_char
;
4018 /* Turn components into a human readable string. OPTIONS is the
4019 options bits passed to the demangler. DC is the tree to print.
4020 CALLBACK is a function to call to flush demangled string segments
4021 as they fill the intermediate buffer, and OPAQUE is a generalized
4022 callback argument. On success, this returns 1. On failure,
4023 it returns 0, indicating a bad parse. It does not use heap
4024 memory to build an output string, so cannot encounter memory
4025 allocation failure. */
4027 CP_STATIC_IF_GLIBCPP_V3
4029 cplus_demangle_print_callback (int options
,
4030 const struct demangle_component
*dc
,
4031 demangle_callbackref callback
, void *opaque
)
4033 struct d_print_info dpi
;
4035 d_print_init (&dpi
, callback
, opaque
, dc
);
4038 #ifdef CP_DYNAMIC_ARRAYS
4039 __extension__
struct d_saved_scope scopes
[dpi
.num_saved_scopes
];
4040 __extension__
struct d_print_template temps
[dpi
.num_copy_templates
];
4042 dpi
.saved_scopes
= scopes
;
4043 dpi
.copy_templates
= temps
;
4045 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4046 * sizeof (*dpi
.saved_scopes
));
4047 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4048 * sizeof (*dpi
.copy_templates
));
4051 d_print_comp (&dpi
, options
, dc
);
4054 d_print_flush (&dpi
);
4056 return ! d_print_saw_error (&dpi
);
4059 /* Turn components into a human readable string. OPTIONS is the
4060 options bits passed to the demangler. DC is the tree to print.
4061 ESTIMATE is a guess at the length of the result. This returns a
4062 string allocated by malloc, or NULL on error. On success, this
4063 sets *PALC to the size of the allocated buffer. On failure, this
4064 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4067 CP_STATIC_IF_GLIBCPP_V3
4069 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4070 int estimate
, size_t *palc
)
4072 struct d_growable_string dgs
;
4074 d_growable_string_init (&dgs
, estimate
);
4076 if (! cplus_demangle_print_callback (options
, dc
,
4077 d_growable_string_callback_adapter
,
4085 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4089 /* Returns the I'th element of the template arglist ARGS, or NULL on
4092 static struct demangle_component
*
4093 d_index_template_argument (struct demangle_component
*args
, int i
)
4095 struct demangle_component
*a
;
4101 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4107 if (i
!= 0 || a
== NULL
)
4113 /* Returns the template argument from the current context indicated by DC,
4114 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4116 static struct demangle_component
*
4117 d_lookup_template_argument (struct d_print_info
*dpi
,
4118 const struct demangle_component
*dc
)
4120 if (dpi
->templates
== NULL
)
4122 d_print_error (dpi
);
4126 return d_index_template_argument
4127 (d_right (dpi
->templates
->template_decl
),
4128 dc
->u
.s_number
.number
);
4131 /* Returns a template argument pack used in DC (any will do), or NULL. */
4133 static struct demangle_component
*
4134 d_find_pack (struct d_print_info
*dpi
,
4135 const struct demangle_component
*dc
)
4137 struct demangle_component
*a
;
4143 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4144 a
= d_lookup_template_argument (dpi
, dc
);
4145 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4149 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4152 case DEMANGLE_COMPONENT_LAMBDA
:
4153 case DEMANGLE_COMPONENT_NAME
:
4154 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4155 case DEMANGLE_COMPONENT_OPERATOR
:
4156 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4157 case DEMANGLE_COMPONENT_SUB_STD
:
4158 case DEMANGLE_COMPONENT_CHARACTER
:
4159 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4160 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4163 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4164 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4165 case DEMANGLE_COMPONENT_CTOR
:
4166 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4167 case DEMANGLE_COMPONENT_DTOR
:
4168 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4171 a
= d_find_pack (dpi
, d_left (dc
));
4174 return d_find_pack (dpi
, d_right (dc
));
4178 /* Returns the length of the template argument pack DC. */
4181 d_pack_length (const struct demangle_component
*dc
)
4184 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4185 && d_left (dc
) != NULL
)
4193 /* DC is a component of a mangled expression. Print it, wrapped in parens
4197 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4198 const struct demangle_component
*dc
)
4201 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4202 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4203 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4204 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4207 d_append_char (dpi
, '(');
4208 d_print_comp (dpi
, options
, dc
);
4210 d_append_char (dpi
, ')');
4213 /* Save the current scope. */
4216 d_save_scope (struct d_print_info
*dpi
,
4217 const struct demangle_component
*container
)
4219 struct d_saved_scope
*scope
;
4220 struct d_print_template
*src
, **link
;
4222 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4224 d_print_error (dpi
);
4227 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4228 dpi
->next_saved_scope
++;
4230 scope
->container
= container
;
4231 link
= &scope
->templates
;
4233 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4235 struct d_print_template
*dst
;
4237 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4239 d_print_error (dpi
);
4242 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4243 dpi
->next_copy_template
++;
4245 dst
->template_decl
= src
->template_decl
;
4253 /* Attempt to locate a previously saved scope. Returns NULL if no
4254 corresponding saved scope was found. */
4256 static struct d_saved_scope
*
4257 d_get_saved_scope (struct d_print_info
*dpi
,
4258 const struct demangle_component
*container
)
4262 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4263 if (dpi
->saved_scopes
[i
].container
== container
)
4264 return &dpi
->saved_scopes
[i
];
4269 /* Subroutine to handle components. */
4272 d_print_comp (struct d_print_info
*dpi
, int options
,
4273 const struct demangle_component
*dc
)
4275 /* Magic variable to let reference smashing skip over the next modifier
4276 without needing to modify *dc. */
4277 const struct demangle_component
*mod_inner
= NULL
;
4279 /* Variable used to store the current templates while a previously
4280 captured scope is used. */
4281 struct d_print_template
*saved_templates
;
4283 /* Nonzero if templates have been stored in the above variable. */
4284 int need_template_restore
= 0;
4288 d_print_error (dpi
);
4291 if (d_print_saw_error (dpi
))
4296 case DEMANGLE_COMPONENT_NAME
:
4297 if ((options
& DMGL_JAVA
) == 0)
4298 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4300 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4303 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4304 d_print_comp (dpi
, options
, d_left (dc
));
4305 d_append_string (dpi
, "[abi:");
4306 d_print_comp (dpi
, options
, d_right (dc
));
4307 d_append_char (dpi
, ']');
4310 case DEMANGLE_COMPONENT_QUAL_NAME
:
4311 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4312 d_print_comp (dpi
, options
, d_left (dc
));
4313 if ((options
& DMGL_JAVA
) == 0)
4314 d_append_string (dpi
, "::");
4316 d_append_char (dpi
, '.');
4318 struct demangle_component
*local_name
= d_right (dc
);
4319 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4321 d_append_string (dpi
, "{default arg#");
4322 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4323 d_append_string (dpi
, "}::");
4324 local_name
= local_name
->u
.s_unary_num
.sub
;
4326 d_print_comp (dpi
, options
, local_name
);
4330 case DEMANGLE_COMPONENT_TYPED_NAME
:
4332 struct d_print_mod
*hold_modifiers
;
4333 struct demangle_component
*typed_name
;
4334 struct d_print_mod adpm
[4];
4336 struct d_print_template dpt
;
4338 /* Pass the name down to the type so that it can be printed in
4339 the right place for the type. We also have to pass down
4340 any CV-qualifiers, which apply to the this parameter. */
4341 hold_modifiers
= dpi
->modifiers
;
4344 typed_name
= d_left (dc
);
4345 while (typed_name
!= NULL
)
4347 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4349 d_print_error (dpi
);
4353 adpm
[i
].next
= dpi
->modifiers
;
4354 dpi
->modifiers
= &adpm
[i
];
4355 adpm
[i
].mod
= typed_name
;
4356 adpm
[i
].printed
= 0;
4357 adpm
[i
].templates
= dpi
->templates
;
4360 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4361 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4362 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4363 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4364 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4367 typed_name
= d_left (typed_name
);
4370 if (typed_name
== NULL
)
4372 d_print_error (dpi
);
4376 /* If typed_name is a template, then it applies to the
4377 function type as well. */
4378 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4380 dpt
.next
= dpi
->templates
;
4381 dpi
->templates
= &dpt
;
4382 dpt
.template_decl
= typed_name
;
4385 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4386 there may be CV-qualifiers on its right argument which
4387 really apply here; this happens when parsing a class which
4388 is local to a function. */
4389 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4391 struct demangle_component
*local_name
;
4393 local_name
= d_right (typed_name
);
4394 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4395 local_name
= local_name
->u
.s_unary_num
.sub
;
4396 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4397 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4398 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4399 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4400 || (local_name
->type
4401 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4403 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4405 d_print_error (dpi
);
4409 adpm
[i
] = adpm
[i
- 1];
4410 adpm
[i
].next
= &adpm
[i
- 1];
4411 dpi
->modifiers
= &adpm
[i
];
4413 adpm
[i
- 1].mod
= local_name
;
4414 adpm
[i
- 1].printed
= 0;
4415 adpm
[i
- 1].templates
= dpi
->templates
;
4418 local_name
= d_left (local_name
);
4422 d_print_comp (dpi
, options
, d_right (dc
));
4424 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4425 dpi
->templates
= dpt
.next
;
4427 /* If the modifiers didn't get printed by the type, print them
4432 if (! adpm
[i
].printed
)
4434 d_append_char (dpi
, ' ');
4435 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4439 dpi
->modifiers
= hold_modifiers
;
4444 case DEMANGLE_COMPONENT_TEMPLATE
:
4446 struct d_print_mod
*hold_dpm
;
4447 struct demangle_component
*dcl
;
4448 const struct demangle_component
*hold_current
;
4450 /* This template may need to be referenced by a cast operator
4451 contained in its subtree. */
4452 hold_current
= dpi
->current_template
;
4453 dpi
->current_template
= dc
;
4455 /* Don't push modifiers into a template definition. Doing so
4456 could give the wrong definition for a template argument.
4457 Instead, treat the template essentially as a name. */
4459 hold_dpm
= dpi
->modifiers
;
4460 dpi
->modifiers
= NULL
;
4464 if ((options
& DMGL_JAVA
) != 0
4465 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4466 && dcl
->u
.s_name
.len
== 6
4467 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4469 /* Special-case Java arrays, so that JArray<TYPE> appears
4470 instead as TYPE[]. */
4472 d_print_comp (dpi
, options
, d_right (dc
));
4473 d_append_string (dpi
, "[]");
4477 d_print_comp (dpi
, options
, dcl
);
4478 if (d_last_char (dpi
) == '<')
4479 d_append_char (dpi
, ' ');
4480 d_append_char (dpi
, '<');
4481 d_print_comp (dpi
, options
, d_right (dc
));
4482 /* Avoid generating two consecutive '>' characters, to avoid
4483 the C++ syntactic ambiguity. */
4484 if (d_last_char (dpi
) == '>')
4485 d_append_char (dpi
, ' ');
4486 d_append_char (dpi
, '>');
4489 dpi
->modifiers
= hold_dpm
;
4490 dpi
->current_template
= hold_current
;
4495 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4497 struct d_print_template
*hold_dpt
;
4498 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4500 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4501 a
= d_index_template_argument (a
, dpi
->pack_index
);
4505 d_print_error (dpi
);
4509 /* While processing this parameter, we need to pop the list of
4510 templates. This is because the template parameter may
4511 itself be a reference to a parameter of an outer
4514 hold_dpt
= dpi
->templates
;
4515 dpi
->templates
= hold_dpt
->next
;
4517 d_print_comp (dpi
, options
, a
);
4519 dpi
->templates
= hold_dpt
;
4524 case DEMANGLE_COMPONENT_CTOR
:
4525 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4528 case DEMANGLE_COMPONENT_DTOR
:
4529 d_append_char (dpi
, '~');
4530 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4533 case DEMANGLE_COMPONENT_VTABLE
:
4534 d_append_string (dpi
, "vtable for ");
4535 d_print_comp (dpi
, options
, d_left (dc
));
4538 case DEMANGLE_COMPONENT_VTT
:
4539 d_append_string (dpi
, "VTT for ");
4540 d_print_comp (dpi
, options
, d_left (dc
));
4543 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4544 d_append_string (dpi
, "construction vtable for ");
4545 d_print_comp (dpi
, options
, d_left (dc
));
4546 d_append_string (dpi
, "-in-");
4547 d_print_comp (dpi
, options
, d_right (dc
));
4550 case DEMANGLE_COMPONENT_TYPEINFO
:
4551 d_append_string (dpi
, "typeinfo for ");
4552 d_print_comp (dpi
, options
, d_left (dc
));
4555 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4556 d_append_string (dpi
, "typeinfo name for ");
4557 d_print_comp (dpi
, options
, d_left (dc
));
4560 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4561 d_append_string (dpi
, "typeinfo fn for ");
4562 d_print_comp (dpi
, options
, d_left (dc
));
4565 case DEMANGLE_COMPONENT_THUNK
:
4566 d_append_string (dpi
, "non-virtual thunk to ");
4567 d_print_comp (dpi
, options
, d_left (dc
));
4570 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4571 d_append_string (dpi
, "virtual thunk to ");
4572 d_print_comp (dpi
, options
, d_left (dc
));
4575 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4576 d_append_string (dpi
, "covariant return thunk to ");
4577 d_print_comp (dpi
, options
, d_left (dc
));
4580 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4581 d_append_string (dpi
, "java Class for ");
4582 d_print_comp (dpi
, options
, d_left (dc
));
4585 case DEMANGLE_COMPONENT_GUARD
:
4586 d_append_string (dpi
, "guard variable for ");
4587 d_print_comp (dpi
, options
, d_left (dc
));
4590 case DEMANGLE_COMPONENT_TLS_INIT
:
4591 d_append_string (dpi
, "TLS init function for ");
4592 d_print_comp (dpi
, options
, d_left (dc
));
4595 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4596 d_append_string (dpi
, "TLS wrapper function for ");
4597 d_print_comp (dpi
, options
, d_left (dc
));
4600 case DEMANGLE_COMPONENT_REFTEMP
:
4601 d_append_string (dpi
, "reference temporary #");
4602 d_print_comp (dpi
, options
, d_right (dc
));
4603 d_append_string (dpi
, " for ");
4604 d_print_comp (dpi
, options
, d_left (dc
));
4607 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4608 d_append_string (dpi
, "hidden alias for ");
4609 d_print_comp (dpi
, options
, d_left (dc
));
4612 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4613 d_append_string (dpi
, "transaction clone for ");
4614 d_print_comp (dpi
, options
, d_left (dc
));
4617 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4618 d_append_string (dpi
, "non-transaction clone for ");
4619 d_print_comp (dpi
, options
, d_left (dc
));
4622 case DEMANGLE_COMPONENT_SUB_STD
:
4623 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4626 case DEMANGLE_COMPONENT_RESTRICT
:
4627 case DEMANGLE_COMPONENT_VOLATILE
:
4628 case DEMANGLE_COMPONENT_CONST
:
4630 struct d_print_mod
*pdpm
;
4632 /* When printing arrays, it's possible to have cases where the
4633 same CV-qualifier gets pushed on the stack multiple times.
4634 We only need to print it once. */
4636 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4638 if (! pdpm
->printed
)
4640 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4641 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4642 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4644 if (pdpm
->mod
->type
== dc
->type
)
4646 d_print_comp (dpi
, options
, d_left (dc
));
4654 case DEMANGLE_COMPONENT_REFERENCE
:
4655 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4657 /* Handle reference smashing: & + && = &. */
4658 const struct demangle_component
*sub
= d_left (dc
);
4659 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4661 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4662 struct demangle_component
*a
;
4666 /* This is the first time SUB has been traversed.
4667 We need to capture the current templates so
4668 they can be restored if SUB is reentered as a
4670 d_save_scope (dpi
, sub
);
4671 if (d_print_saw_error (dpi
))
4676 /* This traversal is reentering SUB as a substition.
4677 Restore the original templates temporarily. */
4678 saved_templates
= dpi
->templates
;
4679 dpi
->templates
= scope
->templates
;
4680 need_template_restore
= 1;
4683 a
= d_lookup_template_argument (dpi
, sub
);
4684 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4685 a
= d_index_template_argument (a
, dpi
->pack_index
);
4689 if (need_template_restore
)
4690 dpi
->templates
= saved_templates
;
4692 d_print_error (dpi
);
4699 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4700 || sub
->type
== dc
->type
)
4702 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4703 mod_inner
= d_left (sub
);
4707 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4708 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4709 case DEMANGLE_COMPONENT_CONST_THIS
:
4710 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4711 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4712 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4713 case DEMANGLE_COMPONENT_POINTER
:
4714 case DEMANGLE_COMPONENT_COMPLEX
:
4715 case DEMANGLE_COMPONENT_IMAGINARY
:
4718 /* We keep a list of modifiers on the stack. */
4719 struct d_print_mod dpm
;
4721 dpm
.next
= dpi
->modifiers
;
4722 dpi
->modifiers
= &dpm
;
4725 dpm
.templates
= dpi
->templates
;
4728 mod_inner
= d_left (dc
);
4730 d_print_comp (dpi
, options
, mod_inner
);
4732 /* If the modifier didn't get printed by the type, print it
4735 d_print_mod (dpi
, options
, dc
);
4737 dpi
->modifiers
= dpm
.next
;
4739 if (need_template_restore
)
4740 dpi
->templates
= saved_templates
;
4745 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4746 if ((options
& DMGL_JAVA
) == 0)
4747 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4748 dc
->u
.s_builtin
.type
->len
);
4750 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4751 dc
->u
.s_builtin
.type
->java_len
);
4754 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4755 d_print_comp (dpi
, options
, d_left (dc
));
4758 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4760 if ((options
& DMGL_RET_POSTFIX
) != 0)
4761 d_print_function_type (dpi
,
4762 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4763 dc
, dpi
->modifiers
);
4765 /* Print return type if present */
4766 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4767 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4769 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4771 struct d_print_mod dpm
;
4773 /* We must pass this type down as a modifier in order to
4774 print it in the right location. */
4775 dpm
.next
= dpi
->modifiers
;
4776 dpi
->modifiers
= &dpm
;
4779 dpm
.templates
= dpi
->templates
;
4781 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4784 dpi
->modifiers
= dpm
.next
;
4789 /* In standard prefix notation, there is a space between the
4790 return type and the function signature. */
4791 if ((options
& DMGL_RET_POSTFIX
) == 0)
4792 d_append_char (dpi
, ' ');
4795 if ((options
& DMGL_RET_POSTFIX
) == 0)
4796 d_print_function_type (dpi
,
4797 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4798 dc
, dpi
->modifiers
);
4803 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4805 struct d_print_mod
*hold_modifiers
;
4806 struct d_print_mod adpm
[4];
4808 struct d_print_mod
*pdpm
;
4810 /* We must pass this type down as a modifier in order to print
4811 multi-dimensional arrays correctly. If the array itself is
4812 CV-qualified, we act as though the element type were
4813 CV-qualified. We do this by copying the modifiers down
4814 rather than fiddling pointers, so that we don't wind up
4815 with a d_print_mod higher on the stack pointing into our
4816 stack frame after we return. */
4818 hold_modifiers
= dpi
->modifiers
;
4820 adpm
[0].next
= hold_modifiers
;
4821 dpi
->modifiers
= &adpm
[0];
4823 adpm
[0].printed
= 0;
4824 adpm
[0].templates
= dpi
->templates
;
4827 pdpm
= hold_modifiers
;
4829 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4830 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4831 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4833 if (! pdpm
->printed
)
4835 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4837 d_print_error (dpi
);
4842 adpm
[i
].next
= dpi
->modifiers
;
4843 dpi
->modifiers
= &adpm
[i
];
4851 d_print_comp (dpi
, options
, d_right (dc
));
4853 dpi
->modifiers
= hold_modifiers
;
4855 if (adpm
[0].printed
)
4861 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4864 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4869 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4870 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4872 struct d_print_mod dpm
;
4874 dpm
.next
= dpi
->modifiers
;
4875 dpi
->modifiers
= &dpm
;
4878 dpm
.templates
= dpi
->templates
;
4880 d_print_comp (dpi
, options
, d_right (dc
));
4882 /* If the modifier didn't get printed by the type, print it
4885 d_print_mod (dpi
, options
, dc
);
4887 dpi
->modifiers
= dpm
.next
;
4892 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4893 if (dc
->u
.s_fixed
.sat
)
4894 d_append_string (dpi
, "_Sat ");
4895 /* Don't print "int _Accum". */
4896 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4897 != &cplus_demangle_builtin_types
['i'-'a'])
4899 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
4900 d_append_char (dpi
, ' ');
4902 if (dc
->u
.s_fixed
.accum
)
4903 d_append_string (dpi
, "_Accum");
4905 d_append_string (dpi
, "_Fract");
4908 case DEMANGLE_COMPONENT_ARGLIST
:
4909 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4910 if (d_left (dc
) != NULL
)
4911 d_print_comp (dpi
, options
, d_left (dc
));
4912 if (d_right (dc
) != NULL
)
4915 unsigned long int flush_count
;
4916 /* Make sure ", " isn't flushed by d_append_string, otherwise
4917 dpi->len -= 2 wouldn't work. */
4918 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4919 d_print_flush (dpi
);
4920 d_append_string (dpi
, ", ");
4922 flush_count
= dpi
->flush_count
;
4923 d_print_comp (dpi
, options
, d_right (dc
));
4924 /* If that didn't print anything (which can happen with empty
4925 template argument packs), remove the comma and space. */
4926 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4931 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4933 struct demangle_component
*type
= d_left (dc
);
4934 struct demangle_component
*list
= d_right (dc
);
4937 d_print_comp (dpi
, options
, type
);
4938 d_append_char (dpi
, '{');
4939 d_print_comp (dpi
, options
, list
);
4940 d_append_char (dpi
, '}');
4944 case DEMANGLE_COMPONENT_OPERATOR
:
4946 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
4949 d_append_string (dpi
, "operator");
4950 /* Add a space before new/delete. */
4951 if (IS_LOWER (op
->name
[0]))
4952 d_append_char (dpi
, ' ');
4953 /* Omit a trailing space. */
4954 if (op
->name
[len
-1] == ' ')
4956 d_append_buffer (dpi
, op
->name
, len
);
4960 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4961 d_append_string (dpi
, "operator ");
4962 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
4965 case DEMANGLE_COMPONENT_CAST
:
4966 d_append_string (dpi
, "operator ");
4967 d_print_cast (dpi
, options
, dc
);
4970 case DEMANGLE_COMPONENT_NULLARY
:
4971 d_print_expr_op (dpi
, options
, d_left (dc
));
4974 case DEMANGLE_COMPONENT_UNARY
:
4976 struct demangle_component
*op
= d_left (dc
);
4977 struct demangle_component
*operand
= d_right (dc
);
4978 const char *code
= NULL
;
4980 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4982 code
= op
->u
.s_operator
.op
->code
;
4983 if (!strcmp (code
, "ad"))
4985 /* Don't print the argument list for the address of a
4987 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
4988 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
4989 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4990 operand
= d_left (operand
);
4992 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
4994 /* This indicates a suffix operator. */
4995 operand
= d_left (operand
);
4996 d_print_subexpr (dpi
, options
, operand
);
4997 d_print_expr_op (dpi
, options
, op
);
5002 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5003 d_print_expr_op (dpi
, options
, op
);
5006 d_append_char (dpi
, '(');
5007 d_print_cast (dpi
, options
, op
);
5008 d_append_char (dpi
, ')');
5010 if (code
&& !strcmp (code
, "gs"))
5011 /* Avoid parens after '::'. */
5012 d_print_comp (dpi
, options
, operand
);
5013 else if (code
&& !strcmp (code
, "st"))
5014 /* Always print parens for sizeof (type). */
5016 d_append_char (dpi
, '(');
5017 d_print_comp (dpi
, options
, operand
);
5018 d_append_char (dpi
, ')');
5021 d_print_subexpr (dpi
, options
, operand
);
5025 case DEMANGLE_COMPONENT_BINARY
:
5026 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5028 d_print_error (dpi
);
5032 if (op_is_new_cast (d_left (dc
)))
5034 d_print_expr_op (dpi
, options
, d_left (dc
));
5035 d_append_char (dpi
, '<');
5036 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5037 d_append_string (dpi
, ">(");
5038 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5039 d_append_char (dpi
, ')');
5043 /* We wrap an expression which uses the greater-than operator in
5044 an extra layer of parens so that it does not get confused
5045 with the '>' which ends the template parameters. */
5046 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5047 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5048 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5049 d_append_char (dpi
, '(');
5051 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5052 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5054 /* Function call used in an expression should not have printed types
5055 of the function arguments. Values of the function arguments still
5056 get printed below. */
5058 const struct demangle_component
*func
= d_left (d_right (dc
));
5060 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5061 d_print_error (dpi
);
5062 d_print_subexpr (dpi
, options
, d_left (func
));
5065 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5066 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5068 d_append_char (dpi
, '[');
5069 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5070 d_append_char (dpi
, ']');
5074 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5075 d_print_expr_op (dpi
, options
, d_left (dc
));
5076 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5079 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5080 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5081 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5082 d_append_char (dpi
, ')');
5086 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5087 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5088 d_print_error (dpi
);
5091 case DEMANGLE_COMPONENT_TRINARY
:
5092 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5093 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5095 d_print_error (dpi
);
5099 struct demangle_component
*op
= d_left (dc
);
5100 struct demangle_component
*first
= d_left (d_right (dc
));
5101 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5102 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5104 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5106 d_print_subexpr (dpi
, options
, first
);
5107 d_print_expr_op (dpi
, options
, op
);
5108 d_print_subexpr (dpi
, options
, second
);
5109 d_append_string (dpi
, " : ");
5110 d_print_subexpr (dpi
, options
, third
);
5114 d_append_string (dpi
, "new ");
5115 if (d_left (first
) != NULL
)
5117 d_print_subexpr (dpi
, options
, first
);
5118 d_append_char (dpi
, ' ');
5120 d_print_comp (dpi
, options
, second
);
5122 d_print_subexpr (dpi
, options
, third
);
5127 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5128 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5129 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5130 d_print_error (dpi
);
5133 case DEMANGLE_COMPONENT_LITERAL
:
5134 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5136 enum d_builtin_type_print tp
;
5138 /* For some builtin types, produce simpler output. */
5139 tp
= D_PRINT_DEFAULT
;
5140 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5142 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5146 case D_PRINT_UNSIGNED
:
5148 case D_PRINT_UNSIGNED_LONG
:
5149 case D_PRINT_LONG_LONG
:
5150 case D_PRINT_UNSIGNED_LONG_LONG
:
5151 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5153 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5154 d_append_char (dpi
, '-');
5155 d_print_comp (dpi
, options
, d_right (dc
));
5160 case D_PRINT_UNSIGNED
:
5161 d_append_char (dpi
, 'u');
5164 d_append_char (dpi
, 'l');
5166 case D_PRINT_UNSIGNED_LONG
:
5167 d_append_string (dpi
, "ul");
5169 case D_PRINT_LONG_LONG
:
5170 d_append_string (dpi
, "ll");
5172 case D_PRINT_UNSIGNED_LONG_LONG
:
5173 d_append_string (dpi
, "ull");
5181 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5182 && d_right (dc
)->u
.s_name
.len
== 1
5183 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5185 switch (d_right (dc
)->u
.s_name
.s
[0])
5188 d_append_string (dpi
, "false");
5191 d_append_string (dpi
, "true");
5204 d_append_char (dpi
, '(');
5205 d_print_comp (dpi
, options
, d_left (dc
));
5206 d_append_char (dpi
, ')');
5207 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5208 d_append_char (dpi
, '-');
5209 if (tp
== D_PRINT_FLOAT
)
5210 d_append_char (dpi
, '[');
5211 d_print_comp (dpi
, options
, d_right (dc
));
5212 if (tp
== D_PRINT_FLOAT
)
5213 d_append_char (dpi
, ']');
5217 case DEMANGLE_COMPONENT_NUMBER
:
5218 d_append_num (dpi
, dc
->u
.s_number
.number
);
5221 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5222 d_append_string (dpi
, "java resource ");
5223 d_print_comp (dpi
, options
, d_left (dc
));
5226 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5227 d_print_comp (dpi
, options
, d_left (dc
));
5228 d_print_comp (dpi
, options
, d_right (dc
));
5231 case DEMANGLE_COMPONENT_CHARACTER
:
5232 d_append_char (dpi
, dc
->u
.s_character
.character
);
5235 case DEMANGLE_COMPONENT_DECLTYPE
:
5236 d_append_string (dpi
, "decltype (");
5237 d_print_comp (dpi
, options
, d_left (dc
));
5238 d_append_char (dpi
, ')');
5241 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5245 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5248 /* d_find_pack won't find anything if the only packs involved
5249 in this expansion are function parameter packs; in that
5250 case, just print the pattern and "...". */
5251 d_print_subexpr (dpi
, options
, d_left (dc
));
5252 d_append_string (dpi
, "...");
5256 len
= d_pack_length (a
);
5258 for (i
= 0; i
< len
; ++i
)
5260 dpi
->pack_index
= i
;
5261 d_print_comp (dpi
, options
, dc
);
5263 d_append_string (dpi
, ", ");
5268 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5270 long num
= dc
->u
.s_number
.number
;
5272 d_append_string (dpi
, "this");
5275 d_append_string (dpi
, "{parm#");
5276 d_append_num (dpi
, num
);
5277 d_append_char (dpi
, '}');
5282 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5283 d_append_string (dpi
, "global constructors keyed to ");
5284 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5287 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5288 d_append_string (dpi
, "global destructors keyed to ");
5289 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5292 case DEMANGLE_COMPONENT_LAMBDA
:
5293 d_append_string (dpi
, "{lambda(");
5294 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5295 d_append_string (dpi
, ")#");
5296 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5297 d_append_char (dpi
, '}');
5300 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5301 d_append_string (dpi
, "{unnamed type#");
5302 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5303 d_append_char (dpi
, '}');
5306 case DEMANGLE_COMPONENT_CLONE
:
5307 d_print_comp (dpi
, options
, d_left (dc
));
5308 d_append_string (dpi
, " [clone ");
5309 d_print_comp (dpi
, options
, d_right (dc
));
5310 d_append_char (dpi
, ']');
5314 d_print_error (dpi
);
5319 /* Print a Java dentifier. For Java we try to handle encoded extended
5320 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5321 so we don't it for C++. Characters are encoded as
5325 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5331 for (p
= name
; p
< end
; ++p
)
5342 for (q
= p
+ 3; q
< end
; ++q
)
5348 else if (*q
>= 'A' && *q
<= 'F')
5349 dig
= *q
- 'A' + 10;
5350 else if (*q
>= 'a' && *q
<= 'f')
5351 dig
= *q
- 'a' + 10;
5357 /* If the Unicode character is larger than 256, we don't try
5358 to deal with it here. FIXME. */
5359 if (q
< end
&& *q
== '_' && c
< 256)
5361 d_append_char (dpi
, c
);
5367 d_append_char (dpi
, *p
);
5371 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5372 qualifiers on this after printing a function. */
5375 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5376 struct d_print_mod
*mods
, int suffix
)
5378 struct d_print_template
*hold_dpt
;
5380 if (mods
== NULL
|| d_print_saw_error (dpi
))
5385 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5386 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5387 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5388 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5390 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5392 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5398 hold_dpt
= dpi
->templates
;
5399 dpi
->templates
= mods
->templates
;
5401 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5403 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5404 dpi
->templates
= hold_dpt
;
5407 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5409 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5410 dpi
->templates
= hold_dpt
;
5413 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5415 struct d_print_mod
*hold_modifiers
;
5416 struct demangle_component
*dc
;
5418 /* When this is on the modifier stack, we have pulled any
5419 qualifiers off the right argument already. Otherwise, we
5420 print it as usual, but don't let the left argument see any
5423 hold_modifiers
= dpi
->modifiers
;
5424 dpi
->modifiers
= NULL
;
5425 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5426 dpi
->modifiers
= hold_modifiers
;
5428 if ((options
& DMGL_JAVA
) == 0)
5429 d_append_string (dpi
, "::");
5431 d_append_char (dpi
, '.');
5433 dc
= d_right (mods
->mod
);
5435 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5437 d_append_string (dpi
, "{default arg#");
5438 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5439 d_append_string (dpi
, "}::");
5440 dc
= dc
->u
.s_unary_num
.sub
;
5443 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5444 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5445 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5446 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5447 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5450 d_print_comp (dpi
, options
, dc
);
5452 dpi
->templates
= hold_dpt
;
5456 d_print_mod (dpi
, options
, mods
->mod
);
5458 dpi
->templates
= hold_dpt
;
5460 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5463 /* Print a modifier. */
5466 d_print_mod (struct d_print_info
*dpi
, int options
,
5467 const struct demangle_component
*mod
)
5471 case DEMANGLE_COMPONENT_RESTRICT
:
5472 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5473 d_append_string (dpi
, " restrict");
5475 case DEMANGLE_COMPONENT_VOLATILE
:
5476 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5477 d_append_string (dpi
, " volatile");
5479 case DEMANGLE_COMPONENT_CONST
:
5480 case DEMANGLE_COMPONENT_CONST_THIS
:
5481 d_append_string (dpi
, " const");
5483 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5484 d_append_char (dpi
, ' ');
5485 d_print_comp (dpi
, options
, d_right (mod
));
5487 case DEMANGLE_COMPONENT_POINTER
:
5488 /* There is no pointer symbol in Java. */
5489 if ((options
& DMGL_JAVA
) == 0)
5490 d_append_char (dpi
, '*');
5492 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5493 /* For the ref-qualifier, put a space before the &. */
5494 d_append_char (dpi
, ' ');
5495 case DEMANGLE_COMPONENT_REFERENCE
:
5496 d_append_char (dpi
, '&');
5498 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5499 d_append_char (dpi
, ' ');
5500 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5501 d_append_string (dpi
, "&&");
5503 case DEMANGLE_COMPONENT_COMPLEX
:
5504 d_append_string (dpi
, "complex ");
5506 case DEMANGLE_COMPONENT_IMAGINARY
:
5507 d_append_string (dpi
, "imaginary ");
5509 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5510 if (d_last_char (dpi
) != '(')
5511 d_append_char (dpi
, ' ');
5512 d_print_comp (dpi
, options
, d_left (mod
));
5513 d_append_string (dpi
, "::*");
5515 case DEMANGLE_COMPONENT_TYPED_NAME
:
5516 d_print_comp (dpi
, options
, d_left (mod
));
5518 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5519 d_append_string (dpi
, " __vector(");
5520 d_print_comp (dpi
, options
, d_left (mod
));
5521 d_append_char (dpi
, ')');
5525 /* Otherwise, we have something that won't go back on the
5526 modifier stack, so we can just print it. */
5527 d_print_comp (dpi
, options
, mod
);
5532 /* Print a function type, except for the return type. */
5535 d_print_function_type (struct d_print_info
*dpi
, int options
,
5536 const struct demangle_component
*dc
,
5537 struct d_print_mod
*mods
)
5541 struct d_print_mod
*p
;
5542 struct d_print_mod
*hold_modifiers
;
5546 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5551 switch (p
->mod
->type
)
5553 case DEMANGLE_COMPONENT_POINTER
:
5554 case DEMANGLE_COMPONENT_REFERENCE
:
5555 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5558 case DEMANGLE_COMPONENT_RESTRICT
:
5559 case DEMANGLE_COMPONENT_VOLATILE
:
5560 case DEMANGLE_COMPONENT_CONST
:
5561 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5562 case DEMANGLE_COMPONENT_COMPLEX
:
5563 case DEMANGLE_COMPONENT_IMAGINARY
:
5564 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5568 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5569 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5570 case DEMANGLE_COMPONENT_CONST_THIS
:
5571 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5572 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5585 if (d_last_char (dpi
) != '('
5586 && d_last_char (dpi
) != '*')
5589 if (need_space
&& d_last_char (dpi
) != ' ')
5590 d_append_char (dpi
, ' ');
5591 d_append_char (dpi
, '(');
5594 hold_modifiers
= dpi
->modifiers
;
5595 dpi
->modifiers
= NULL
;
5597 d_print_mod_list (dpi
, options
, mods
, 0);
5600 d_append_char (dpi
, ')');
5602 d_append_char (dpi
, '(');
5604 if (d_right (dc
) != NULL
)
5605 d_print_comp (dpi
, options
, d_right (dc
));
5607 d_append_char (dpi
, ')');
5609 d_print_mod_list (dpi
, options
, mods
, 1);
5611 dpi
->modifiers
= hold_modifiers
;
5614 /* Print an array type, except for the element type. */
5617 d_print_array_type (struct d_print_info
*dpi
, int options
,
5618 const struct demangle_component
*dc
,
5619 struct d_print_mod
*mods
)
5627 struct d_print_mod
*p
;
5630 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5634 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5649 d_append_string (dpi
, " (");
5651 d_print_mod_list (dpi
, options
, mods
, 0);
5654 d_append_char (dpi
, ')');
5658 d_append_char (dpi
, ' ');
5660 d_append_char (dpi
, '[');
5662 if (d_left (dc
) != NULL
)
5663 d_print_comp (dpi
, options
, d_left (dc
));
5665 d_append_char (dpi
, ']');
5668 /* Print an operator in an expression. */
5671 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5672 const struct demangle_component
*dc
)
5674 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5675 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5676 dc
->u
.s_operator
.op
->len
);
5678 d_print_comp (dpi
, options
, dc
);
5684 d_print_cast (struct d_print_info
*dpi
, int options
,
5685 const struct demangle_component
*dc
)
5687 struct d_print_template dpt
;
5689 /* For a cast operator, we need the template parameters from
5690 the enclosing template in scope for processing the type. */
5691 if (dpi
->current_template
!= NULL
)
5693 dpt
.next
= dpi
->templates
;
5694 dpi
->templates
= &dpt
;
5695 dpt
.template_decl
= dpi
->current_template
;
5698 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5700 d_print_comp (dpi
, options
, d_left (dc
));
5701 if (dpi
->current_template
!= NULL
)
5702 dpi
->templates
= dpt
.next
;
5706 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5708 /* For a templated cast operator, we need to remove the template
5709 parameters from scope after printing the operator name,
5710 so we need to handle the template printing here. */
5711 if (dpi
->current_template
!= NULL
)
5712 dpi
->templates
= dpt
.next
;
5714 if (d_last_char (dpi
) == '<')
5715 d_append_char (dpi
, ' ');
5716 d_append_char (dpi
, '<');
5717 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5718 /* Avoid generating two consecutive '>' characters, to avoid
5719 the C++ syntactic ambiguity. */
5720 if (d_last_char (dpi
) == '>')
5721 d_append_char (dpi
, ' ');
5722 d_append_char (dpi
, '>');
5726 /* Initialize the information structure we use to pass around
5729 CP_STATIC_IF_GLIBCPP_V3
5731 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5735 di
->send
= mangled
+ len
;
5736 di
->options
= options
;
5740 /* We can not need more components than twice the number of chars in
5741 the mangled string. Most components correspond directly to
5742 chars, but the ARGLIST types are exceptions. */
5743 di
->num_comps
= 2 * len
;
5746 /* Similarly, we can not need more substitutions than there are
5747 chars in the mangled string. */
5752 di
->last_name
= NULL
;
5755 di
->is_expression
= 0;
5756 di
->is_conversion
= 0;
5759 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5760 mangled name, return strings in repeated callback giving the demangled
5761 name. OPTIONS is the usual libiberty demangler options. On success,
5762 this returns 1. On failure, returns 0. */
5765 d_demangle_callback (const char *mangled
, int options
,
5766 demangle_callbackref callback
, void *opaque
)
5777 struct demangle_component
*dc
;
5780 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5782 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5783 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5784 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5785 && mangled
[10] == '_')
5786 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5789 if ((options
& DMGL_TYPES
) == 0)
5794 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5797 #ifdef CP_DYNAMIC_ARRAYS
5798 __extension__
struct demangle_component comps
[di
.num_comps
];
5799 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5804 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5805 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5811 dc
= cplus_demangle_type (&di
);
5814 dc
= cplus_demangle_mangled_name (&di
, 1);
5816 case DCT_GLOBAL_CTORS
:
5817 case DCT_GLOBAL_DTORS
:
5818 d_advance (&di
, 11);
5819 dc
= d_make_comp (&di
,
5820 (type
== DCT_GLOBAL_CTORS
5821 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5822 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5823 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5825 d_advance (&di
, strlen (d_str (&di
)));
5828 abort (); /* We have listed all the cases. */
5831 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5832 mangled string, then we didn't successfully demangle it. If
5833 DMGL_PARAMS is not set, we didn't look at the trailing
5835 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5838 #ifdef CP_DEMANGLE_DEBUG
5842 status
= (dc
!= NULL
)
5843 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
5850 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
5851 name, return a buffer allocated with malloc holding the demangled
5852 name. OPTIONS is the usual libiberty demangler options. On
5853 success, this sets *PALC to the allocated size of the returned
5854 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
5855 a memory allocation failure, and returns NULL. */
5858 d_demangle (const char *mangled
, int options
, size_t *palc
)
5860 struct d_growable_string dgs
;
5863 d_growable_string_init (&dgs
, 0);
5865 status
= d_demangle_callback (mangled
, options
,
5866 d_growable_string_callback_adapter
, &dgs
);
5874 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
5878 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5880 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5882 /* ia64 ABI-mandated entry point in the C++ runtime library for
5883 performing demangling. MANGLED_NAME is a NUL-terminated character
5884 string containing the name to be demangled.
5886 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5887 *LENGTH bytes, into which the demangled name is stored. If
5888 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5889 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5890 is placed in a region of memory allocated with malloc.
5892 If LENGTH is non-NULL, the length of the buffer containing the
5893 demangled name, is placed in *LENGTH.
5895 The return value is a pointer to the start of the NUL-terminated
5896 demangled name, or NULL if the demangling fails. The caller is
5897 responsible for deallocating this memory using free.
5899 *STATUS is set to one of the following values:
5900 0: The demangling operation succeeded.
5901 -1: A memory allocation failure occurred.
5902 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5903 -3: One of the arguments is invalid.
5905 The demangling is performed using the C++ ABI mangling rules, with
5909 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
5910 size_t *length
, int *status
)
5915 if (mangled_name
== NULL
)
5922 if (output_buffer
!= NULL
&& length
== NULL
)
5929 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
5931 if (demangled
== NULL
)
5943 if (output_buffer
== NULL
)
5950 if (strlen (demangled
) < *length
)
5952 strcpy (output_buffer
, demangled
);
5954 demangled
= output_buffer
;
5958 free (output_buffer
);
5969 extern int __gcclibcxx_demangle_callback (const char *,
5971 (const char *, size_t, void *),
5974 /* Alternative, allocationless entry point in the C++ runtime library
5975 for performing demangling. MANGLED_NAME is a NUL-terminated character
5976 string containing the name to be demangled.
5978 CALLBACK is a callback function, called with demangled string
5979 segments as demangling progresses; it is called at least once,
5980 but may be called more than once. OPAQUE is a generalized pointer
5981 used as a callback argument.
5983 The return code is one of the following values, equivalent to
5984 the STATUS values of __cxa_demangle() (excluding -1, since this
5985 function performs no memory allocations):
5986 0: The demangling operation succeeded.
5987 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5988 -3: One of the arguments is invalid.
5990 The demangling is performed using the C++ ABI mangling rules, with
5994 __gcclibcxx_demangle_callback (const char *mangled_name
,
5995 void (*callback
) (const char *, size_t, void *),
6000 if (mangled_name
== NULL
|| callback
== NULL
)
6003 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6011 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6013 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6014 mangled name, return a buffer allocated with malloc holding the
6015 demangled name. Otherwise, return NULL. */
6018 cplus_demangle_v3 (const char *mangled
, int options
)
6022 return d_demangle (mangled
, options
, &alc
);
6026 cplus_demangle_v3_callback (const char *mangled
, int options
,
6027 demangle_callbackref callback
, void *opaque
)
6029 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6032 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6033 conventions, but the output formatting is a little different.
6034 This instructs the C++ demangler not to emit pointer characters ("*"), to
6035 use Java's namespace separator symbol ("." instead of "::"), and to output
6036 JArray<TYPE> as TYPE[]. */
6039 java_demangle_v3 (const char *mangled
)
6043 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6047 java_demangle_v3_callback (const char *mangled
,
6048 demangle_callbackref callback
, void *opaque
)
6050 return d_demangle_callback (mangled
,
6051 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6055 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6057 #ifndef IN_GLIBCPP_V3
6059 /* Demangle a string in order to find out whether it is a constructor
6060 or destructor. Return non-zero on success. Set *CTOR_KIND and
6061 *DTOR_KIND appropriately. */
6064 is_ctor_or_dtor (const char *mangled
,
6065 enum gnu_v3_ctor_kinds
*ctor_kind
,
6066 enum gnu_v3_dtor_kinds
*dtor_kind
)
6069 struct demangle_component
*dc
;
6072 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6073 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6075 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6078 #ifdef CP_DYNAMIC_ARRAYS
6079 __extension__
struct demangle_component comps
[di
.num_comps
];
6080 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6085 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6086 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6089 dc
= cplus_demangle_mangled_name (&di
, 1);
6091 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6092 to demangle the entire string. */
6099 /* These cannot appear on a constructor or destructor. */
6100 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6101 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6102 case DEMANGLE_COMPONENT_CONST_THIS
:
6103 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6104 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6108 case DEMANGLE_COMPONENT_TYPED_NAME
:
6109 case DEMANGLE_COMPONENT_TEMPLATE
:
6112 case DEMANGLE_COMPONENT_QUAL_NAME
:
6113 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6116 case DEMANGLE_COMPONENT_CTOR
:
6117 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6121 case DEMANGLE_COMPONENT_DTOR
:
6122 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6133 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6134 name. A non-zero return indicates the type of constructor. */
6136 enum gnu_v3_ctor_kinds
6137 is_gnu_v3_mangled_ctor (const char *name
)
6139 enum gnu_v3_ctor_kinds ctor_kind
;
6140 enum gnu_v3_dtor_kinds dtor_kind
;
6142 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6143 return (enum gnu_v3_ctor_kinds
) 0;
6148 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6149 name. A non-zero return indicates the type of destructor. */
6151 enum gnu_v3_dtor_kinds
6152 is_gnu_v3_mangled_dtor (const char *name
)
6154 enum gnu_v3_ctor_kinds ctor_kind
;
6155 enum gnu_v3_dtor_kinds dtor_kind
;
6157 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6158 return (enum gnu_v3_dtor_kinds
) 0;
6162 #endif /* IN_GLIBCPP_V3 */
6164 #ifdef STANDALONE_DEMANGLER
6167 #include "dyn-string.h"
6169 static void print_usage (FILE* fp
, int exit_value
);
6171 #define IS_ALPHA(CHAR) \
6172 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6173 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6175 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6176 #define is_mangled_char(CHAR) \
6177 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6178 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6180 /* The name of this program, as invoked. */
6181 const char* program_name
;
6183 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6186 print_usage (FILE* fp
, int exit_value
)
6188 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6189 fprintf (fp
, "Options:\n");
6190 fprintf (fp
, " -h,--help Display this message.\n");
6191 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6192 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6193 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6198 /* Option specification for getopt_long. */
6199 static const struct option long_options
[] =
6201 { "help", no_argument
, NULL
, 'h' },
6202 { "no-params", no_argument
, NULL
, 'p' },
6203 { "verbose", no_argument
, NULL
, 'v' },
6204 { NULL
, no_argument
, NULL
, 0 },
6207 /* Main entry for a demangling filter executable. It will demangle
6208 its command line arguments, if any. If none are provided, it will
6209 filter stdin to stdout, replacing any recognized mangled C++ names
6210 with their demangled equivalents. */
6213 main (int argc
, char *argv
[])
6217 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6219 /* Use the program name of this program, as invoked. */
6220 program_name
= argv
[0];
6222 /* Parse options. */
6225 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6228 case '?': /* Unrecognized option. */
6229 print_usage (stderr
, 1);
6233 print_usage (stdout
, 0);
6237 options
&= ~ DMGL_PARAMS
;
6241 options
|= DMGL_VERBOSE
;
6245 while (opt_char
!= -1);
6248 /* No command line arguments were provided. Filter stdin. */
6250 dyn_string_t mangled
= dyn_string_new (3);
6253 /* Read all of input. */
6254 while (!feof (stdin
))
6258 /* Pile characters into mangled until we hit one that can't
6259 occur in a mangled name. */
6261 while (!feof (stdin
) && is_mangled_char (c
))
6263 dyn_string_append_char (mangled
, c
);
6269 if (dyn_string_length (mangled
) > 0)
6271 #ifdef IN_GLIBCPP_V3
6272 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6274 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6284 /* It might not have been a mangled name. Print the
6286 fputs (dyn_string_buf (mangled
), stdout
);
6289 dyn_string_clear (mangled
);
6292 /* If we haven't hit EOF yet, we've read one character that
6293 can't occur in a mangled name, so print it out. */
6298 dyn_string_delete (mangled
);
6301 /* Demangle command line arguments. */
6303 /* Loop over command line arguments. */
6304 for (i
= optind
; i
< argc
; ++i
)
6307 #ifdef IN_GLIBCPP_V3
6311 /* Attempt to demangle. */
6312 #ifdef IN_GLIBCPP_V3
6313 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6315 s
= cplus_demangle_v3 (argv
[i
], options
);
6318 /* If it worked, print the demangled name. */
6326 #ifdef IN_GLIBCPP_V3
6327 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6329 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6338 #endif /* STANDALONE_DEMANGLER */