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
*);
529 static void d_print_cast (struct d_print_info
*, int,
530 const struct demangle_component
*);
531 static void d_print_conversion (struct d_print_info
*, int,
532 const struct demangle_component
*);
534 static int d_demangle_callback (const char *, int,
535 demangle_callbackref
, void *);
536 static char *d_demangle (const char *, int, size_t *);
538 #ifdef CP_DEMANGLE_DEBUG
541 d_dump (struct demangle_component
*dc
, int indent
)
548 printf ("failed demangling\n");
552 for (i
= 0; i
< indent
; ++i
)
557 case DEMANGLE_COMPONENT_NAME
:
558 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
560 case DEMANGLE_COMPONENT_TAGGED_NAME
:
561 printf ("tagged name\n");
562 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
563 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
565 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
566 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
568 case DEMANGLE_COMPONENT_CTOR
:
569 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
570 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
572 case DEMANGLE_COMPONENT_DTOR
:
573 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
574 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
576 case DEMANGLE_COMPONENT_SUB_STD
:
577 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
579 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
580 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
582 case DEMANGLE_COMPONENT_OPERATOR
:
583 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
585 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
586 printf ("extended operator with %d args\n",
587 dc
->u
.s_extended_operator
.args
);
588 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
591 case DEMANGLE_COMPONENT_QUAL_NAME
:
592 printf ("qualified name\n");
594 case DEMANGLE_COMPONENT_LOCAL_NAME
:
595 printf ("local name\n");
597 case DEMANGLE_COMPONENT_TYPED_NAME
:
598 printf ("typed name\n");
600 case DEMANGLE_COMPONENT_TEMPLATE
:
601 printf ("template\n");
603 case DEMANGLE_COMPONENT_VTABLE
:
606 case DEMANGLE_COMPONENT_VTT
:
609 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
610 printf ("construction vtable\n");
612 case DEMANGLE_COMPONENT_TYPEINFO
:
613 printf ("typeinfo\n");
615 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
616 printf ("typeinfo name\n");
618 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
619 printf ("typeinfo function\n");
621 case DEMANGLE_COMPONENT_THUNK
:
624 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
625 printf ("virtual thunk\n");
627 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
628 printf ("covariant thunk\n");
630 case DEMANGLE_COMPONENT_JAVA_CLASS
:
631 printf ("java class\n");
633 case DEMANGLE_COMPONENT_GUARD
:
636 case DEMANGLE_COMPONENT_REFTEMP
:
637 printf ("reference temporary\n");
639 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
640 printf ("hidden alias\n");
642 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
643 printf ("transaction clone\n");
645 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
646 printf ("non-transaction clone\n");
648 case DEMANGLE_COMPONENT_RESTRICT
:
649 printf ("restrict\n");
651 case DEMANGLE_COMPONENT_VOLATILE
:
652 printf ("volatile\n");
654 case DEMANGLE_COMPONENT_CONST
:
657 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
658 printf ("restrict this\n");
660 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
661 printf ("volatile this\n");
663 case DEMANGLE_COMPONENT_CONST_THIS
:
664 printf ("const this\n");
666 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
667 printf ("reference this\n");
669 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
670 printf ("rvalue reference this\n");
672 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
673 printf ("vendor type qualifier\n");
675 case DEMANGLE_COMPONENT_POINTER
:
676 printf ("pointer\n");
678 case DEMANGLE_COMPONENT_REFERENCE
:
679 printf ("reference\n");
681 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
682 printf ("rvalue reference\n");
684 case DEMANGLE_COMPONENT_COMPLEX
:
685 printf ("complex\n");
687 case DEMANGLE_COMPONENT_IMAGINARY
:
688 printf ("imaginary\n");
690 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
691 printf ("vendor type\n");
693 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
694 printf ("function type\n");
696 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
697 printf ("array type\n");
699 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
700 printf ("pointer to member type\n");
702 case DEMANGLE_COMPONENT_FIXED_TYPE
:
703 printf ("fixed-point type\n");
705 case DEMANGLE_COMPONENT_ARGLIST
:
706 printf ("argument list\n");
708 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
709 printf ("template argument list\n");
711 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
712 printf ("initializer list\n");
714 case DEMANGLE_COMPONENT_CAST
:
717 case DEMANGLE_COMPONENT_CONVERSION
:
718 printf ("conversion operator\n");
720 case DEMANGLE_COMPONENT_NULLARY
:
721 printf ("nullary operator\n");
723 case DEMANGLE_COMPONENT_UNARY
:
724 printf ("unary operator\n");
726 case DEMANGLE_COMPONENT_BINARY
:
727 printf ("binary operator\n");
729 case DEMANGLE_COMPONENT_BINARY_ARGS
:
730 printf ("binary operator arguments\n");
732 case DEMANGLE_COMPONENT_TRINARY
:
733 printf ("trinary operator\n");
735 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
736 printf ("trinary operator arguments 1\n");
738 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
739 printf ("trinary operator arguments 1\n");
741 case DEMANGLE_COMPONENT_LITERAL
:
742 printf ("literal\n");
744 case DEMANGLE_COMPONENT_LITERAL_NEG
:
745 printf ("negative literal\n");
747 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
748 printf ("java resource\n");
750 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
751 printf ("compound name\n");
753 case DEMANGLE_COMPONENT_CHARACTER
:
754 printf ("character '%c'\n", dc
->u
.s_character
.character
);
756 case DEMANGLE_COMPONENT_DECLTYPE
:
757 printf ("decltype\n");
759 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
760 printf ("pack expansion\n");
762 case DEMANGLE_COMPONENT_TLS_INIT
:
763 printf ("tls init function\n");
765 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
766 printf ("tls wrapper function\n");
768 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
769 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
770 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
772 case DEMANGLE_COMPONENT_LAMBDA
:
773 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
774 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
778 d_dump (d_left (dc
), indent
+ 2);
779 d_dump (d_right (dc
), indent
+ 2);
782 #endif /* CP_DEMANGLE_DEBUG */
784 /* Fill in a DEMANGLE_COMPONENT_NAME. */
786 CP_STATIC_IF_GLIBCPP_V3
788 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
790 if (p
== NULL
|| s
== NULL
|| len
== 0)
792 p
->type
= DEMANGLE_COMPONENT_NAME
;
794 p
->u
.s_name
.len
= len
;
798 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
800 CP_STATIC_IF_GLIBCPP_V3
802 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
803 struct demangle_component
*name
)
805 if (p
== NULL
|| args
< 0 || name
== NULL
)
807 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
808 p
->u
.s_extended_operator
.args
= args
;
809 p
->u
.s_extended_operator
.name
= name
;
813 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
815 CP_STATIC_IF_GLIBCPP_V3
817 cplus_demangle_fill_ctor (struct demangle_component
*p
,
818 enum gnu_v3_ctor_kinds kind
,
819 struct demangle_component
*name
)
823 || (int) kind
< gnu_v3_complete_object_ctor
824 || (int) kind
> gnu_v3_object_ctor_group
)
826 p
->type
= DEMANGLE_COMPONENT_CTOR
;
827 p
->u
.s_ctor
.kind
= kind
;
828 p
->u
.s_ctor
.name
= name
;
832 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
834 CP_STATIC_IF_GLIBCPP_V3
836 cplus_demangle_fill_dtor (struct demangle_component
*p
,
837 enum gnu_v3_dtor_kinds kind
,
838 struct demangle_component
*name
)
842 || (int) kind
< gnu_v3_deleting_dtor
843 || (int) kind
> gnu_v3_object_dtor_group
)
845 p
->type
= DEMANGLE_COMPONENT_DTOR
;
846 p
->u
.s_dtor
.kind
= kind
;
847 p
->u
.s_dtor
.name
= name
;
851 /* Add a new component. */
853 static struct demangle_component
*
854 d_make_empty (struct d_info
*di
)
856 struct demangle_component
*p
;
858 if (di
->next_comp
>= di
->num_comps
)
860 p
= &di
->comps
[di
->next_comp
];
865 /* Add a new generic component. */
867 static struct demangle_component
*
868 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
869 struct demangle_component
*left
,
870 struct demangle_component
*right
)
872 struct demangle_component
*p
;
874 /* We check for errors here. A typical error would be a NULL return
875 from a subroutine. We catch those here, and return NULL
879 /* These types require two parameters. */
880 case DEMANGLE_COMPONENT_QUAL_NAME
:
881 case DEMANGLE_COMPONENT_LOCAL_NAME
:
882 case DEMANGLE_COMPONENT_TYPED_NAME
:
883 case DEMANGLE_COMPONENT_TAGGED_NAME
:
884 case DEMANGLE_COMPONENT_TEMPLATE
:
885 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
886 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
887 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
888 case DEMANGLE_COMPONENT_UNARY
:
889 case DEMANGLE_COMPONENT_BINARY
:
890 case DEMANGLE_COMPONENT_BINARY_ARGS
:
891 case DEMANGLE_COMPONENT_TRINARY
:
892 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
893 case DEMANGLE_COMPONENT_LITERAL
:
894 case DEMANGLE_COMPONENT_LITERAL_NEG
:
895 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
896 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
897 case DEMANGLE_COMPONENT_CLONE
:
898 if (left
== NULL
|| right
== NULL
)
902 /* These types only require one parameter. */
903 case DEMANGLE_COMPONENT_VTABLE
:
904 case DEMANGLE_COMPONENT_VTT
:
905 case DEMANGLE_COMPONENT_TYPEINFO
:
906 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
907 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
908 case DEMANGLE_COMPONENT_THUNK
:
909 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
910 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
911 case DEMANGLE_COMPONENT_JAVA_CLASS
:
912 case DEMANGLE_COMPONENT_GUARD
:
913 case DEMANGLE_COMPONENT_TLS_INIT
:
914 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
915 case DEMANGLE_COMPONENT_REFTEMP
:
916 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
917 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
918 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
919 case DEMANGLE_COMPONENT_POINTER
:
920 case DEMANGLE_COMPONENT_REFERENCE
:
921 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
922 case DEMANGLE_COMPONENT_COMPLEX
:
923 case DEMANGLE_COMPONENT_IMAGINARY
:
924 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
925 case DEMANGLE_COMPONENT_CAST
:
926 case DEMANGLE_COMPONENT_CONVERSION
:
927 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
928 case DEMANGLE_COMPONENT_DECLTYPE
:
929 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
930 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
931 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
932 case DEMANGLE_COMPONENT_NULLARY
:
933 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
938 /* This needs a right parameter, but the left parameter can be
940 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
941 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
946 /* These are allowed to have no parameters--in some cases they
947 will be filled in later. */
948 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
949 case DEMANGLE_COMPONENT_RESTRICT
:
950 case DEMANGLE_COMPONENT_VOLATILE
:
951 case DEMANGLE_COMPONENT_CONST
:
952 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
953 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
954 case DEMANGLE_COMPONENT_CONST_THIS
:
955 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
956 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
957 case DEMANGLE_COMPONENT_ARGLIST
:
958 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
961 /* Other types should not be seen here. */
966 p
= d_make_empty (di
);
970 p
->u
.s_binary
.left
= left
;
971 p
->u
.s_binary
.right
= right
;
976 /* Add a new demangle mangled name component. */
978 static struct demangle_component
*
979 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
981 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
982 return d_make_name (di
, s
, strlen (s
));
984 return d_encoding (di
, 0);
987 /* Add a new name component. */
989 static struct demangle_component
*
990 d_make_name (struct d_info
*di
, const char *s
, int len
)
992 struct demangle_component
*p
;
994 p
= d_make_empty (di
);
995 if (! cplus_demangle_fill_name (p
, s
, len
))
1000 /* Add a new builtin type component. */
1002 static struct demangle_component
*
1003 d_make_builtin_type (struct d_info
*di
,
1004 const struct demangle_builtin_type_info
*type
)
1006 struct demangle_component
*p
;
1010 p
= d_make_empty (di
);
1013 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1014 p
->u
.s_builtin
.type
= type
;
1019 /* Add a new operator component. */
1021 static struct demangle_component
*
1022 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1024 struct demangle_component
*p
;
1026 p
= d_make_empty (di
);
1029 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1030 p
->u
.s_operator
.op
= op
;
1035 /* Add a new extended operator component. */
1037 static struct demangle_component
*
1038 d_make_extended_operator (struct d_info
*di
, int args
,
1039 struct demangle_component
*name
)
1041 struct demangle_component
*p
;
1043 p
= d_make_empty (di
);
1044 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1049 static struct demangle_component
*
1050 d_make_default_arg (struct d_info
*di
, int num
,
1051 struct demangle_component
*sub
)
1053 struct demangle_component
*p
= d_make_empty (di
);
1056 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1057 p
->u
.s_unary_num
.num
= num
;
1058 p
->u
.s_unary_num
.sub
= sub
;
1063 /* Add a new constructor component. */
1065 static struct demangle_component
*
1066 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1067 struct demangle_component
*name
)
1069 struct demangle_component
*p
;
1071 p
= d_make_empty (di
);
1072 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1077 /* Add a new destructor component. */
1079 static struct demangle_component
*
1080 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1081 struct demangle_component
*name
)
1083 struct demangle_component
*p
;
1085 p
= d_make_empty (di
);
1086 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1091 /* Add a new template parameter. */
1093 static struct demangle_component
*
1094 d_make_template_param (struct d_info
*di
, long i
)
1096 struct demangle_component
*p
;
1098 p
= d_make_empty (di
);
1101 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1102 p
->u
.s_number
.number
= i
;
1107 /* Add a new function parameter. */
1109 static struct demangle_component
*
1110 d_make_function_param (struct d_info
*di
, long i
)
1112 struct demangle_component
*p
;
1114 p
= d_make_empty (di
);
1117 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1118 p
->u
.s_number
.number
= i
;
1123 /* Add a new standard substitution component. */
1125 static struct demangle_component
*
1126 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1128 struct demangle_component
*p
;
1130 p
= d_make_empty (di
);
1133 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1134 p
->u
.s_string
.string
= name
;
1135 p
->u
.s_string
.len
= len
;
1140 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1142 TOP_LEVEL is non-zero when called at the top level. */
1144 CP_STATIC_IF_GLIBCPP_V3
1145 struct demangle_component
*
1146 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1148 struct demangle_component
*p
;
1150 if (! d_check_char (di
, '_')
1151 /* Allow missing _ if not at toplevel to work around a
1152 bug in G++ abi-version=2 mangling; see the comment in
1153 write_template_arg. */
1156 if (! d_check_char (di
, 'Z'))
1158 p
= d_encoding (di
, top_level
);
1160 /* If at top level and parsing parameters, check for a clone
1162 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1163 while (d_peek_char (di
) == '.'
1164 && (IS_LOWER (d_peek_next_char (di
))
1165 || d_peek_next_char (di
) == '_'
1166 || IS_DIGIT (d_peek_next_char (di
))))
1167 p
= d_clone_suffix (di
, p
);
1172 /* Return whether a function should have a return type. The argument
1173 is the function name, which may be qualified in various ways. The
1174 rules are that template functions have return types with some
1175 exceptions, function types which are not part of a function name
1176 mangling have return types with some exceptions, and non-template
1177 function names do not have return types. The exceptions are that
1178 constructors, destructors, and conversion operators do not have
1182 has_return_type (struct demangle_component
*dc
)
1190 case DEMANGLE_COMPONENT_TEMPLATE
:
1191 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1192 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1193 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1194 case DEMANGLE_COMPONENT_CONST_THIS
:
1195 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1196 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1197 return has_return_type (d_left (dc
));
1201 /* Return whether a name is a constructor, a destructor, or a
1202 conversion operator. */
1205 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1213 case DEMANGLE_COMPONENT_QUAL_NAME
:
1214 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1215 return is_ctor_dtor_or_conversion (d_right (dc
));
1216 case DEMANGLE_COMPONENT_CTOR
:
1217 case DEMANGLE_COMPONENT_DTOR
:
1218 case DEMANGLE_COMPONENT_CONVERSION
:
1223 /* <encoding> ::= <(function) name> <bare-function-type>
1227 TOP_LEVEL is non-zero when called at the top level, in which case
1228 if DMGL_PARAMS is not set we do not demangle the function
1229 parameters. We only set this at the top level, because otherwise
1230 we would not correctly demangle names in local scopes. */
1232 static struct demangle_component
*
1233 d_encoding (struct d_info
*di
, int top_level
)
1235 char peek
= d_peek_char (di
);
1237 if (peek
== 'G' || peek
== 'T')
1238 return d_special_name (di
);
1241 struct demangle_component
*dc
;
1245 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1247 /* Strip off any initial CV-qualifiers, as they really apply
1248 to the `this' parameter, and they were not output by the
1249 v2 demangler without DMGL_PARAMS. */
1250 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1251 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1252 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1253 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1254 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1257 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1258 there may be CV-qualifiers on its right argument which
1259 really apply here; this happens when parsing a class
1260 which is local to a function. */
1261 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1263 struct demangle_component
*dcr
;
1266 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1267 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1268 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1269 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1270 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1272 dc
->u
.s_binary
.right
= dcr
;
1278 peek
= d_peek_char (di
);
1279 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1281 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1282 d_bare_function_type (di
, has_return_type (dc
)));
1286 /* <tagged-name> ::= <name> B <source-name> */
1288 static struct demangle_component
*
1289 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1292 while (peek
= d_peek_char (di
),
1295 struct demangle_component
*tag
;
1297 tag
= d_source_name (di
);
1298 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1303 /* <name> ::= <nested-name>
1305 ::= <unscoped-template-name> <template-args>
1308 <unscoped-name> ::= <unqualified-name>
1309 ::= St <unqualified-name>
1311 <unscoped-template-name> ::= <unscoped-name>
1315 static struct demangle_component
*
1316 d_name (struct d_info
*di
)
1318 char peek
= d_peek_char (di
);
1319 struct demangle_component
*dc
;
1324 return d_nested_name (di
);
1327 return d_local_name (di
);
1330 return d_unqualified_name (di
);
1336 if (d_peek_next_char (di
) != 't')
1338 dc
= d_substitution (di
, 0);
1344 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1345 d_make_name (di
, "std", 3),
1346 d_unqualified_name (di
));
1351 if (d_peek_char (di
) != 'I')
1353 /* The grammar does not permit this case to occur if we
1354 called d_substitution() above (i.e., subst == 1). We
1355 don't bother to check. */
1359 /* This is <template-args>, which means that we just saw
1360 <unscoped-template-name>, which is a substitution
1361 candidate if we didn't just get it from a
1365 if (! d_add_substitution (di
, dc
))
1368 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1369 d_template_args (di
));
1377 dc
= d_unqualified_name (di
);
1378 if (d_peek_char (di
) == 'I')
1380 /* This is <template-args>, which means that we just saw
1381 <unscoped-template-name>, which is a substitution
1383 if (! d_add_substitution (di
, dc
))
1385 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1386 d_template_args (di
));
1392 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1393 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1396 static struct demangle_component
*
1397 d_nested_name (struct d_info
*di
)
1399 struct demangle_component
*ret
;
1400 struct demangle_component
**pret
;
1401 struct demangle_component
*rqual
;
1403 if (! d_check_char (di
, 'N'))
1406 pret
= d_cv_qualifiers (di
, &ret
, 1);
1410 /* Parse the ref-qualifier now and then attach it
1411 once we have something to attach it to. */
1412 rqual
= d_ref_qualifier (di
, NULL
);
1414 *pret
= d_prefix (di
);
1420 d_left (rqual
) = ret
;
1424 if (! d_check_char (di
, 'E'))
1430 /* <prefix> ::= <prefix> <unqualified-name>
1431 ::= <template-prefix> <template-args>
1432 ::= <template-param>
1437 <template-prefix> ::= <prefix> <(template) unqualified-name>
1438 ::= <template-param>
1442 static struct demangle_component
*
1443 d_prefix (struct d_info
*di
)
1445 struct demangle_component
*ret
= NULL
;
1450 enum demangle_component_type comb_type
;
1451 struct demangle_component
*dc
;
1453 peek
= d_peek_char (di
);
1457 /* The older code accepts a <local-name> here, but I don't see
1458 that in the grammar. The older code does not accept a
1459 <template-param> here. */
1461 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1464 char peek2
= d_peek_next_char (di
);
1465 if (peek2
== 'T' || peek2
== 't')
1467 dc
= cplus_demangle_type (di
);
1469 /* Destructor name. */
1470 dc
= d_unqualified_name (di
);
1472 else if (IS_DIGIT (peek
)
1477 dc
= d_unqualified_name (di
);
1478 else if (peek
== 'S')
1479 dc
= d_substitution (di
, 1);
1480 else if (peek
== 'I')
1484 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1485 dc
= d_template_args (di
);
1487 else if (peek
== 'T')
1488 dc
= d_template_param (di
);
1489 else if (peek
== 'E')
1491 else if (peek
== 'M')
1493 /* Initializer scope for a lambda. We don't need to represent
1494 this; the normal code will just treat the variable as a type
1495 scope, which gives appropriate output. */
1507 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1509 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1511 if (! d_add_substitution (di
, ret
))
1517 /* <unqualified-name> ::= <operator-name>
1518 ::= <ctor-dtor-name>
1520 ::= <local-source-name>
1522 <local-source-name> ::= L <source-name> <discriminator>
1525 static struct demangle_component
*
1526 d_unqualified_name (struct d_info
*di
)
1528 struct demangle_component
*ret
;
1531 peek
= d_peek_char (di
);
1532 if (IS_DIGIT (peek
))
1533 ret
= d_source_name (di
);
1534 else if (IS_LOWER (peek
))
1536 ret
= d_operator_name (di
);
1537 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1539 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1540 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1541 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1542 d_source_name (di
));
1545 else if (peek
== 'C' || peek
== 'D')
1546 ret
= d_ctor_dtor_name (di
);
1547 else if (peek
== 'L')
1551 ret
= d_source_name (di
);
1554 if (! d_discriminator (di
))
1557 else if (peek
== 'U')
1559 switch (d_peek_next_char (di
))
1562 ret
= d_lambda (di
);
1565 ret
= d_unnamed_type (di
);
1574 if (d_peek_char (di
) == 'B')
1575 ret
= d_abi_tags (di
, ret
);
1579 /* <source-name> ::= <(positive length) number> <identifier> */
1581 static struct demangle_component
*
1582 d_source_name (struct d_info
*di
)
1585 struct demangle_component
*ret
;
1587 len
= d_number (di
);
1590 ret
= d_identifier (di
, len
);
1591 di
->last_name
= ret
;
1595 /* number ::= [n] <(non-negative decimal integer)> */
1598 d_number (struct d_info
*di
)
1605 peek
= d_peek_char (di
);
1610 peek
= d_peek_char (di
);
1616 if (! IS_DIGIT (peek
))
1622 ret
= ret
* 10 + peek
- '0';
1624 peek
= d_peek_char (di
);
1628 /* Like d_number, but returns a demangle_component. */
1630 static struct demangle_component
*
1631 d_number_component (struct d_info
*di
)
1633 struct demangle_component
*ret
= d_make_empty (di
);
1636 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1637 ret
->u
.s_number
.number
= d_number (di
);
1642 /* identifier ::= <(unqualified source code identifier)> */
1644 static struct demangle_component
*
1645 d_identifier (struct d_info
*di
, int len
)
1651 if (di
->send
- name
< len
)
1654 d_advance (di
, len
);
1656 /* A Java mangled name may have a trailing '$' if it is a C++
1657 keyword. This '$' is not included in the length count. We just
1659 if ((di
->options
& DMGL_JAVA
) != 0
1660 && d_peek_char (di
) == '$')
1663 /* Look for something which looks like a gcc encoding of an
1664 anonymous namespace, and replace it with a more user friendly
1666 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1667 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1668 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1672 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1673 if ((*s
== '.' || *s
== '_' || *s
== '$')
1676 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1677 return d_make_name (di
, "(anonymous namespace)",
1678 sizeof "(anonymous namespace)" - 1);
1682 return d_make_name (di
, name
, len
);
1685 /* operator_name ::= many different two character encodings.
1687 ::= v <digit> <source-name>
1689 This list is sorted for binary search. */
1691 #define NL(s) s, (sizeof s) - 1
1693 CP_STATIC_IF_GLIBCPP_V3
1694 const struct demangle_operator_info cplus_demangle_operators
[] =
1696 { "aN", NL ("&="), 2 },
1697 { "aS", NL ("="), 2 },
1698 { "aa", NL ("&&"), 2 },
1699 { "ad", NL ("&"), 1 },
1700 { "an", NL ("&"), 2 },
1701 { "at", NL ("alignof "), 1 },
1702 { "az", NL ("alignof "), 1 },
1703 { "cc", NL ("const_cast"), 2 },
1704 { "cl", NL ("()"), 2 },
1705 { "cm", NL (","), 2 },
1706 { "co", NL ("~"), 1 },
1707 { "dV", NL ("/="), 2 },
1708 { "da", NL ("delete[] "), 1 },
1709 { "dc", NL ("dynamic_cast"), 2 },
1710 { "de", NL ("*"), 1 },
1711 { "dl", NL ("delete "), 1 },
1712 { "ds", NL (".*"), 2 },
1713 { "dt", NL ("."), 2 },
1714 { "dv", NL ("/"), 2 },
1715 { "eO", NL ("^="), 2 },
1716 { "eo", NL ("^"), 2 },
1717 { "eq", NL ("=="), 2 },
1718 { "ge", NL (">="), 2 },
1719 { "gs", NL ("::"), 1 },
1720 { "gt", NL (">"), 2 },
1721 { "ix", NL ("[]"), 2 },
1722 { "lS", NL ("<<="), 2 },
1723 { "le", NL ("<="), 2 },
1724 { "li", NL ("operator\"\" "), 1 },
1725 { "ls", NL ("<<"), 2 },
1726 { "lt", NL ("<"), 2 },
1727 { "mI", NL ("-="), 2 },
1728 { "mL", NL ("*="), 2 },
1729 { "mi", NL ("-"), 2 },
1730 { "ml", NL ("*"), 2 },
1731 { "mm", NL ("--"), 1 },
1732 { "na", NL ("new[]"), 3 },
1733 { "ne", NL ("!="), 2 },
1734 { "ng", NL ("-"), 1 },
1735 { "nt", NL ("!"), 1 },
1736 { "nw", NL ("new"), 3 },
1737 { "oR", NL ("|="), 2 },
1738 { "oo", NL ("||"), 2 },
1739 { "or", NL ("|"), 2 },
1740 { "pL", NL ("+="), 2 },
1741 { "pl", NL ("+"), 2 },
1742 { "pm", NL ("->*"), 2 },
1743 { "pp", NL ("++"), 1 },
1744 { "ps", NL ("+"), 1 },
1745 { "pt", NL ("->"), 2 },
1746 { "qu", NL ("?"), 3 },
1747 { "rM", NL ("%="), 2 },
1748 { "rS", NL (">>="), 2 },
1749 { "rc", NL ("reinterpret_cast"), 2 },
1750 { "rm", NL ("%"), 2 },
1751 { "rs", NL (">>"), 2 },
1752 { "sc", NL ("static_cast"), 2 },
1753 { "st", NL ("sizeof "), 1 },
1754 { "sz", NL ("sizeof "), 1 },
1755 { "tr", NL ("throw"), 0 },
1756 { "tw", NL ("throw "), 1 },
1757 { NULL
, NULL
, 0, 0 }
1760 static struct demangle_component
*
1761 d_operator_name (struct d_info
*di
)
1766 c1
= d_next_char (di
);
1767 c2
= d_next_char (di
);
1768 if (c1
== 'v' && IS_DIGIT (c2
))
1769 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1770 else if (c1
== 'c' && c2
== 'v')
1772 struct demangle_component
*type
;
1773 int was_conversion
= di
->is_conversion
;
1774 struct demangle_component
*res
;
1776 di
->is_conversion
= ! di
->is_expression
;
1777 type
= cplus_demangle_type (di
);
1778 if (di
->is_conversion
)
1779 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
1781 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1782 di
->is_conversion
= was_conversion
;
1787 /* LOW is the inclusive lower bound. */
1789 /* HIGH is the exclusive upper bound. We subtract one to ignore
1790 the sentinel at the end of the array. */
1791 int high
= ((sizeof (cplus_demangle_operators
)
1792 / sizeof (cplus_demangle_operators
[0]))
1798 const struct demangle_operator_info
*p
;
1800 i
= low
+ (high
- low
) / 2;
1801 p
= cplus_demangle_operators
+ i
;
1803 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1804 return d_make_operator (di
, p
);
1806 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1816 static struct demangle_component
*
1817 d_make_character (struct d_info
*di
, int c
)
1819 struct demangle_component
*p
;
1820 p
= d_make_empty (di
);
1823 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1824 p
->u
.s_character
.character
= c
;
1829 static struct demangle_component
*
1830 d_java_resource (struct d_info
*di
)
1832 struct demangle_component
*p
= NULL
;
1833 struct demangle_component
*next
= NULL
;
1838 len
= d_number (di
);
1842 /* Eat the leading '_'. */
1843 if (d_next_char (di
) != '_')
1856 /* Each chunk is either a '$' escape... */
1874 next
= d_make_character (di
, c
);
1882 /* ... or a sequence of characters. */
1885 while (i
< len
&& str
[i
] && str
[i
] != '$')
1888 next
= d_make_name (di
, str
, i
);
1901 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1907 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1912 /* <special-name> ::= TV <type>
1916 ::= GV <(object) name>
1917 ::= T <call-offset> <(base) encoding>
1918 ::= Tc <call-offset> <call-offset> <(base) encoding>
1919 Also g++ extensions:
1920 ::= TC <type> <(offset) number> _ <(base) type>
1925 ::= Gr <resource name>
1930 static struct demangle_component
*
1931 d_special_name (struct d_info
*di
)
1933 di
->expansion
+= 20;
1934 if (d_check_char (di
, 'T'))
1936 switch (d_next_char (di
))
1940 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1941 cplus_demangle_type (di
), NULL
);
1943 di
->expansion
-= 10;
1944 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1945 cplus_demangle_type (di
), NULL
);
1947 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1948 cplus_demangle_type (di
), NULL
);
1950 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1951 cplus_demangle_type (di
), NULL
);
1954 if (! d_call_offset (di
, 'h'))
1956 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1957 d_encoding (di
, 0), NULL
);
1960 if (! d_call_offset (di
, 'v'))
1962 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1963 d_encoding (di
, 0), NULL
);
1966 if (! d_call_offset (di
, '\0'))
1968 if (! d_call_offset (di
, '\0'))
1970 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1971 d_encoding (di
, 0), NULL
);
1975 struct demangle_component
*derived_type
;
1977 struct demangle_component
*base_type
;
1979 derived_type
= cplus_demangle_type (di
);
1980 offset
= d_number (di
);
1983 if (! d_check_char (di
, '_'))
1985 base_type
= cplus_demangle_type (di
);
1986 /* We don't display the offset. FIXME: We should display
1987 it in verbose mode. */
1989 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1990 base_type
, derived_type
);
1994 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1995 cplus_demangle_type (di
), NULL
);
1997 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1998 cplus_demangle_type (di
), NULL
);
2001 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2005 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2012 else if (d_check_char (di
, 'G'))
2014 switch (d_next_char (di
))
2017 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2021 struct demangle_component
*name
= d_name (di
);
2022 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2023 d_number_component (di
));
2027 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2028 d_encoding (di
, 0), NULL
);
2031 switch (d_next_char (di
))
2034 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2035 d_encoding (di
, 0), NULL
);
2037 /* ??? The proposal is that other letters (such as 'h') stand
2038 for different variants of transaction cloning, such as
2039 compiling directly for hardware transaction support. But
2040 they still should all be transactional clones of some sort
2041 so go ahead and call them that. */
2043 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2044 d_encoding (di
, 0), NULL
);
2048 return d_java_resource (di
);
2058 /* <call-offset> ::= h <nv-offset> _
2061 <nv-offset> ::= <(offset) number>
2063 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2065 The C parameter, if not '\0', is a character we just read which is
2066 the start of the <call-offset>.
2068 We don't display the offset information anywhere. FIXME: We should
2069 display it in verbose mode. */
2072 d_call_offset (struct d_info
*di
, int c
)
2075 c
= d_next_char (di
);
2082 if (! d_check_char (di
, '_'))
2089 if (! d_check_char (di
, '_'))
2095 /* <ctor-dtor-name> ::= C1
2103 static struct demangle_component
*
2104 d_ctor_dtor_name (struct d_info
*di
)
2106 if (di
->last_name
!= NULL
)
2108 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2109 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2110 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2111 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2113 switch (d_peek_char (di
))
2117 enum gnu_v3_ctor_kinds kind
;
2119 switch (d_peek_next_char (di
))
2122 kind
= gnu_v3_complete_object_ctor
;
2125 kind
= gnu_v3_base_object_ctor
;
2128 kind
= gnu_v3_complete_object_allocating_ctor
;
2131 kind
= gnu_v3_unified_ctor
;
2134 kind
= gnu_v3_object_ctor_group
;
2140 return d_make_ctor (di
, kind
, di
->last_name
);
2145 enum gnu_v3_dtor_kinds kind
;
2147 switch (d_peek_next_char (di
))
2150 kind
= gnu_v3_deleting_dtor
;
2153 kind
= gnu_v3_complete_object_dtor
;
2156 kind
= gnu_v3_base_object_dtor
;
2158 /* digit '3' is not used */
2160 kind
= gnu_v3_unified_dtor
;
2163 kind
= gnu_v3_object_dtor_group
;
2169 return d_make_dtor (di
, kind
, di
->last_name
);
2177 /* <type> ::= <builtin-type>
2179 ::= <class-enum-type>
2181 ::= <pointer-to-member-type>
2182 ::= <template-param>
2183 ::= <template-template-param> <template-args>
2185 ::= <CV-qualifiers> <type>
2188 ::= O <type> (C++0x)
2191 ::= U <source-name> <type>
2193 <builtin-type> ::= various one letter codes
2197 CP_STATIC_IF_GLIBCPP_V3
2198 const struct demangle_builtin_type_info
2199 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2201 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2202 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2203 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2204 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2205 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2206 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2207 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2208 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2209 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2210 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2211 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2212 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2213 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2214 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2215 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2217 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2218 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2219 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2220 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2221 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2222 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2223 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2224 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2225 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2226 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2227 D_PRINT_UNSIGNED_LONG_LONG
},
2228 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2229 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2230 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2231 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2232 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2233 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2234 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2235 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2239 CP_STATIC_IF_GLIBCPP_V3
2240 struct demangle_component
*
2241 cplus_demangle_type (struct d_info
*di
)
2244 struct demangle_component
*ret
;
2247 /* The ABI specifies that when CV-qualifiers are used, the base type
2248 is substitutable, and the fully qualified type is substitutable,
2249 but the base type with a strict subset of the CV-qualifiers is
2250 not substitutable. The natural recursive implementation of the
2251 CV-qualifiers would cause subsets to be substitutable, so instead
2252 we pull them all off now.
2254 FIXME: The ABI says that order-insensitive vendor qualifiers
2255 should be handled in the same way, but we have no way to tell
2256 which vendor qualifiers are order-insensitive and which are
2257 order-sensitive. So we just assume that they are all
2258 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2259 __vector, and it treats it as order-sensitive when mangling
2262 peek
= d_peek_char (di
);
2263 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2265 struct demangle_component
**pret
;
2267 pret
= d_cv_qualifiers (di
, &ret
, 0);
2270 if (d_peek_char (di
) == 'F')
2272 /* cv-qualifiers before a function type apply to 'this',
2273 so avoid adding the unqualified function type to
2274 the substitution list. */
2275 *pret
= d_function_type (di
);
2278 *pret
= cplus_demangle_type (di
);
2281 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2282 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2284 /* Move the ref-qualifier outside the cv-qualifiers so that
2285 they are printed in the right order. */
2286 struct demangle_component
*fn
= d_left (*pret
);
2287 d_left (*pret
) = ret
;
2291 if (! d_add_substitution (di
, ret
))
2300 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2301 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2302 case 'o': case 's': case 't':
2303 case 'v': case 'w': case 'x': case 'y': case 'z':
2304 ret
= d_make_builtin_type (di
,
2305 &cplus_demangle_builtin_types
[peek
- 'a']);
2306 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2313 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2314 d_source_name (di
), NULL
);
2318 ret
= d_function_type (di
);
2321 case '0': case '1': case '2': case '3': case '4':
2322 case '5': case '6': case '7': case '8': case '9':
2325 ret
= d_class_enum_type (di
);
2329 ret
= d_array_type (di
);
2333 ret
= d_pointer_to_member_type (di
);
2337 ret
= d_template_param (di
);
2338 if (d_peek_char (di
) == 'I')
2340 /* This may be <template-template-param> <template-args>.
2341 If this is the type for a conversion operator, we can
2342 have a <template-template-param> here only by following
2343 a derivation like this:
2346 -> <template-prefix> <template-args>
2347 -> <prefix> <template-unqualified-name> <template-args>
2348 -> <unqualified-name> <template-unqualified-name> <template-args>
2349 -> <source-name> <template-unqualified-name> <template-args>
2350 -> <source-name> <operator-name> <template-args>
2351 -> <source-name> cv <type> <template-args>
2352 -> <source-name> cv <template-template-param> <template-args> <template-args>
2354 where the <template-args> is followed by another.
2355 Otherwise, we must have a derivation like this:
2358 -> <template-prefix> <template-args>
2359 -> <prefix> <template-unqualified-name> <template-args>
2360 -> <unqualified-name> <template-unqualified-name> <template-args>
2361 -> <source-name> <template-unqualified-name> <template-args>
2362 -> <source-name> <operator-name> <template-args>
2363 -> <source-name> cv <type> <template-args>
2364 -> <source-name> cv <template-param> <template-args>
2366 where we need to leave the <template-args> to be processed
2367 by d_prefix (following the <template-prefix>).
2369 The <template-template-param> part is a substitution
2371 if (! di
->is_conversion
)
2373 if (! d_add_substitution (di
, ret
))
2375 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2376 d_template_args (di
));
2380 struct demangle_component
*args
;
2381 struct d_info_checkpoint checkpoint
;
2383 d_checkpoint (di
, &checkpoint
);
2384 args
= d_template_args (di
);
2385 if (d_peek_char (di
) == 'I')
2387 if (! d_add_substitution (di
, ret
))
2389 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2393 d_backtrack (di
, &checkpoint
);
2399 /* If this is a special substitution, then it is the start of
2400 <class-enum-type>. */
2404 peek_next
= d_peek_next_char (di
);
2405 if (IS_DIGIT (peek_next
)
2407 || IS_UPPER (peek_next
))
2409 ret
= d_substitution (di
, 0);
2410 /* The substituted name may have been a template name and
2411 may be followed by tepmlate args. */
2412 if (d_peek_char (di
) == 'I')
2413 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2414 d_template_args (di
));
2420 ret
= d_class_enum_type (di
);
2421 /* If the substitution was a complete type, then it is not
2422 a new substitution candidate. However, if the
2423 substitution was followed by template arguments, then
2424 the whole thing is a substitution candidate. */
2425 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2433 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2434 cplus_demangle_type (di
), NULL
);
2439 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2440 cplus_demangle_type (di
), NULL
);
2445 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2446 cplus_demangle_type (di
), NULL
);
2451 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2452 cplus_demangle_type (di
), NULL
);
2457 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2458 cplus_demangle_type (di
), NULL
);
2463 ret
= d_source_name (di
);
2464 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2465 cplus_demangle_type (di
), ret
);
2471 peek
= d_next_char (di
);
2476 /* decltype (expression) */
2477 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2478 d_expression (di
), NULL
);
2479 if (ret
&& d_next_char (di
) != 'E')
2485 /* Pack expansion. */
2486 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2487 cplus_demangle_type (di
), NULL
);
2493 ret
= d_make_name (di
, "auto", 4);
2497 /* 32-bit decimal floating point */
2498 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2499 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2503 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2504 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2508 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2509 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2512 /* 16-bit half-precision FP */
2513 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2514 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2518 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2519 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2523 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2524 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2528 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2529 ret
= d_make_empty (di
);
2530 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2531 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2532 /* For demangling we don't care about the bits. */
2534 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2535 if (ret
->u
.s_fixed
.length
== NULL
)
2538 peek
= d_next_char (di
);
2539 ret
->u
.s_fixed
.sat
= (peek
== 's');
2543 ret
= d_vector_type (di
);
2548 /* decltype(nullptr) */
2549 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2550 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2564 if (! d_add_substitution (di
, ret
))
2571 /* <CV-qualifiers> ::= [r] [V] [K] */
2573 static struct demangle_component
**
2574 d_cv_qualifiers (struct d_info
*di
,
2575 struct demangle_component
**pret
, int member_fn
)
2577 struct demangle_component
**pstart
;
2581 peek
= d_peek_char (di
);
2582 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2584 enum demangle_component_type t
;
2590 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2591 : DEMANGLE_COMPONENT_RESTRICT
);
2592 di
->expansion
+= sizeof "restrict";
2594 else if (peek
== 'V')
2597 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2598 : DEMANGLE_COMPONENT_VOLATILE
);
2599 di
->expansion
+= sizeof "volatile";
2604 ? DEMANGLE_COMPONENT_CONST_THIS
2605 : DEMANGLE_COMPONENT_CONST
);
2606 di
->expansion
+= sizeof "const";
2609 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2612 pret
= &d_left (*pret
);
2614 peek
= d_peek_char (di
);
2617 if (!member_fn
&& peek
== 'F')
2619 while (pstart
!= pret
)
2621 switch ((*pstart
)->type
)
2623 case DEMANGLE_COMPONENT_RESTRICT
:
2624 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2626 case DEMANGLE_COMPONENT_VOLATILE
:
2627 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2629 case DEMANGLE_COMPONENT_CONST
:
2630 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2635 pstart
= &d_left (*pstart
);
2642 /* <ref-qualifier> ::= R
2645 static struct demangle_component
*
2646 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2648 struct demangle_component
*ret
= sub
;
2651 peek
= d_peek_char (di
);
2652 if (peek
== 'R' || peek
== 'O')
2654 enum demangle_component_type t
;
2657 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2658 di
->expansion
+= sizeof "&";
2662 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2663 di
->expansion
+= sizeof "&&";
2667 ret
= d_make_comp (di
, t
, ret
, NULL
);
2673 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
2675 static struct demangle_component
*
2676 d_function_type (struct d_info
*di
)
2678 struct demangle_component
*ret
;
2680 if (! d_check_char (di
, 'F'))
2682 if (d_peek_char (di
) == 'Y')
2684 /* Function has C linkage. We don't print this information.
2685 FIXME: We should print it in verbose mode. */
2688 ret
= d_bare_function_type (di
, 1);
2689 ret
= d_ref_qualifier (di
, ret
);
2691 if (! d_check_char (di
, 'E'))
2698 static struct demangle_component
*
2699 d_parmlist (struct d_info
*di
)
2701 struct demangle_component
*tl
;
2702 struct demangle_component
**ptl
;
2708 struct demangle_component
*type
;
2710 char peek
= d_peek_char (di
);
2711 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2713 if ((peek
== 'R' || peek
== 'O')
2714 && d_peek_next_char (di
) == 'E')
2715 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2717 type
= cplus_demangle_type (di
);
2720 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2723 ptl
= &d_right (*ptl
);
2726 /* There should be at least one parameter type besides the optional
2727 return type. A function which takes no arguments will have a
2728 single parameter type void. */
2732 /* If we have a single parameter type void, omit it. */
2733 if (d_right (tl
) == NULL
2734 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2735 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2737 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2744 /* <bare-function-type> ::= [J]<type>+ */
2746 static struct demangle_component
*
2747 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2749 struct demangle_component
*return_type
;
2750 struct demangle_component
*tl
;
2753 /* Detect special qualifier indicating that the first argument
2754 is the return type. */
2755 peek
= d_peek_char (di
);
2759 has_return_type
= 1;
2762 if (has_return_type
)
2764 return_type
= cplus_demangle_type (di
);
2765 if (return_type
== NULL
)
2771 tl
= d_parmlist (di
);
2775 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2779 /* <class-enum-type> ::= <name> */
2781 static struct demangle_component
*
2782 d_class_enum_type (struct d_info
*di
)
2787 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2788 ::= A [<(dimension) expression>] _ <(element) type>
2791 static struct demangle_component
*
2792 d_array_type (struct d_info
*di
)
2795 struct demangle_component
*dim
;
2797 if (! d_check_char (di
, 'A'))
2800 peek
= d_peek_char (di
);
2803 else if (IS_DIGIT (peek
))
2811 peek
= d_peek_char (di
);
2813 while (IS_DIGIT (peek
));
2814 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2820 dim
= d_expression (di
);
2825 if (! d_check_char (di
, '_'))
2828 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2829 cplus_demangle_type (di
));
2832 /* <vector-type> ::= Dv <number> _ <type>
2833 ::= Dv _ <expression> _ <type> */
2835 static struct demangle_component
*
2836 d_vector_type (struct d_info
*di
)
2839 struct demangle_component
*dim
;
2841 peek
= d_peek_char (di
);
2845 dim
= d_expression (di
);
2848 dim
= d_number_component (di
);
2853 if (! d_check_char (di
, '_'))
2856 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2857 cplus_demangle_type (di
));
2860 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2862 static struct demangle_component
*
2863 d_pointer_to_member_type (struct d_info
*di
)
2865 struct demangle_component
*cl
;
2866 struct demangle_component
*mem
;
2868 if (! d_check_char (di
, 'M'))
2871 cl
= cplus_demangle_type (di
);
2875 /* The ABI says, "The type of a non-static member function is considered
2876 to be different, for the purposes of substitution, from the type of a
2877 namespace-scope or static member function whose type appears
2878 similar. The types of two non-static member functions are considered
2879 to be different, for the purposes of substitution, if the functions
2880 are members of different classes. In other words, for the purposes of
2881 substitution, the class of which the function is a member is
2882 considered part of the type of function."
2884 For a pointer to member function, this call to cplus_demangle_type
2885 will end up adding a (possibly qualified) non-member function type to
2886 the substitution table, which is not correct; however, the member
2887 function type will never be used in a substitution, so putting the
2888 wrong type in the substitution table is harmless. */
2890 mem
= cplus_demangle_type (di
);
2894 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2897 /* <non-negative number> _ */
2900 d_compact_number (struct d_info
*di
)
2903 if (d_peek_char (di
) == '_')
2905 else if (d_peek_char (di
) == 'n')
2908 num
= d_number (di
) + 1;
2910 if (! d_check_char (di
, '_'))
2915 /* <template-param> ::= T_
2916 ::= T <(parameter-2 non-negative) number> _
2919 static struct demangle_component
*
2920 d_template_param (struct d_info
*di
)
2924 if (! d_check_char (di
, 'T'))
2927 param
= d_compact_number (di
);
2933 return d_make_template_param (di
, param
);
2936 /* <template-args> ::= I <template-arg>+ E */
2938 static struct demangle_component
*
2939 d_template_args (struct d_info
*di
)
2941 struct demangle_component
*hold_last_name
;
2942 struct demangle_component
*al
;
2943 struct demangle_component
**pal
;
2945 /* Preserve the last name we saw--don't let the template arguments
2946 clobber it, as that would give us the wrong name for a subsequent
2947 constructor or destructor. */
2948 hold_last_name
= di
->last_name
;
2950 if (d_peek_char (di
) != 'I'
2951 && d_peek_char (di
) != 'J')
2955 if (d_peek_char (di
) == 'E')
2957 /* An argument pack can be empty. */
2959 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2966 struct demangle_component
*a
;
2968 a
= d_template_arg (di
);
2972 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2975 pal
= &d_right (*pal
);
2977 if (d_peek_char (di
) == 'E')
2984 di
->last_name
= hold_last_name
;
2989 /* <template-arg> ::= <type>
2990 ::= X <expression> E
2994 static struct demangle_component
*
2995 d_template_arg (struct d_info
*di
)
2997 struct demangle_component
*ret
;
2999 switch (d_peek_char (di
))
3003 ret
= d_expression (di
);
3004 if (! d_check_char (di
, 'E'))
3009 return d_expr_primary (di
);
3013 /* An argument pack. */
3014 return d_template_args (di
);
3017 return cplus_demangle_type (di
);
3021 /* Parse a sequence of expressions until we hit the terminator
3024 static struct demangle_component
*
3025 d_exprlist (struct d_info
*di
, char terminator
)
3027 struct demangle_component
*list
= NULL
;
3028 struct demangle_component
**p
= &list
;
3030 if (d_peek_char (di
) == terminator
)
3033 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3038 struct demangle_component
*arg
= d_expression (di
);
3042 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3047 if (d_peek_char (di
) == terminator
)
3057 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3058 dynamic_cast, static_cast or reinterpret_cast. */
3061 op_is_new_cast (struct demangle_component
*op
)
3063 const char *code
= op
->u
.s_operator
.op
->code
;
3064 return (code
[1] == 'c'
3065 && (code
[0] == 's' || code
[0] == 'd'
3066 || code
[0] == 'c' || code
[0] == 'r'));
3069 /* <expression> ::= <(unary) operator-name> <expression>
3070 ::= <(binary) operator-name> <expression> <expression>
3071 ::= <(trinary) operator-name> <expression> <expression> <expression>
3072 ::= cl <expression>+ E
3074 ::= <template-param>
3075 ::= sr <type> <unqualified-name>
3076 ::= sr <type> <unqualified-name> <template-args>
3080 static inline struct demangle_component
*
3081 d_expression_1 (struct d_info
*di
)
3085 peek
= d_peek_char (di
);
3087 return d_expr_primary (di
);
3088 else if (peek
== 'T')
3089 return d_template_param (di
);
3090 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3092 struct demangle_component
*type
;
3093 struct demangle_component
*name
;
3096 type
= cplus_demangle_type (di
);
3097 name
= d_unqualified_name (di
);
3098 if (d_peek_char (di
) != 'I')
3099 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3101 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3102 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3103 d_template_args (di
)));
3105 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3108 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3109 d_expression_1 (di
), NULL
);
3111 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3113 /* Function parameter used in a late-specified return type. */
3116 if (d_peek_char (di
) == 'T')
3118 /* 'this' parameter. */
3124 index
= d_compact_number (di
) + 1;
3128 return d_make_function_param (di
, index
);
3130 else if (IS_DIGIT (peek
)
3131 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3133 /* We can get an unqualified name as an expression in the case of
3134 a dependent function call, i.e. decltype(f(t)). */
3135 struct demangle_component
*name
;
3138 /* operator-function-id, i.e. operator+(t). */
3141 name
= d_unqualified_name (di
);
3144 if (d_peek_char (di
) == 'I')
3145 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3146 d_template_args (di
));
3150 else if ((peek
== 'i' || peek
== 't')
3151 && d_peek_next_char (di
) == 'l')
3153 /* Brace-enclosed initializer list, untyped or typed. */
3154 struct demangle_component
*type
= NULL
;
3156 type
= cplus_demangle_type (di
);
3158 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3159 type
, d_exprlist (di
, 'E'));
3163 struct demangle_component
*op
;
3164 const char *code
= NULL
;
3167 op
= d_operator_name (di
);
3171 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3173 code
= op
->u
.s_operator
.op
->code
;
3174 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3175 if (strcmp (code
, "st") == 0)
3176 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3177 cplus_demangle_type (di
));
3184 case DEMANGLE_COMPONENT_OPERATOR
:
3185 args
= op
->u
.s_operator
.op
->args
;
3187 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3188 args
= op
->u
.s_extended_operator
.args
;
3190 case DEMANGLE_COMPONENT_CAST
:
3198 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3202 struct demangle_component
*operand
;
3205 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3206 && code
[1] == code
[0])
3207 /* pp_ and mm_ are the prefix variants. */
3208 suffix
= !d_check_char (di
, '_');
3210 if (op
->type
== DEMANGLE_COMPONENT_CAST
3211 && d_check_char (di
, '_'))
3212 operand
= d_exprlist (di
, 'E');
3214 operand
= d_expression_1 (di
);
3217 /* Indicate the suffix variant for d_print_comp. */
3218 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3220 DEMANGLE_COMPONENT_BINARY_ARGS
,
3223 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3228 struct demangle_component
*left
;
3229 struct demangle_component
*right
;
3231 if (op_is_new_cast (op
))
3232 left
= cplus_demangle_type (di
);
3234 left
= d_expression_1 (di
);
3235 if (!strcmp (code
, "cl"))
3236 right
= d_exprlist (di
, 'E');
3237 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3239 right
= d_unqualified_name (di
);
3240 if (d_peek_char (di
) == 'I')
3241 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3242 right
, d_template_args (di
));
3245 right
= d_expression_1 (di
);
3247 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3249 DEMANGLE_COMPONENT_BINARY_ARGS
,
3254 struct demangle_component
*first
;
3255 struct demangle_component
*second
;
3256 struct demangle_component
*third
;
3258 if (!strcmp (code
, "qu"))
3260 /* ?: expression. */
3261 first
= d_expression_1 (di
);
3262 second
= d_expression_1 (di
);
3263 third
= d_expression_1 (di
);
3265 else if (code
[0] == 'n')
3267 /* new-expression. */
3268 if (code
[1] != 'w' && code
[1] != 'a')
3270 first
= d_exprlist (di
, '_');
3271 second
= cplus_demangle_type (di
);
3272 if (d_peek_char (di
) == 'E')
3277 else if (d_peek_char (di
) == 'p'
3278 && d_peek_next_char (di
) == 'i')
3280 /* Parenthesized initializer. */
3282 third
= d_exprlist (di
, 'E');
3284 else if (d_peek_char (di
) == 'i'
3285 && d_peek_next_char (di
) == 'l')
3286 /* initializer-list. */
3287 third
= d_expression_1 (di
);
3293 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3295 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3298 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3307 static struct demangle_component
*
3308 d_expression (struct d_info
*di
)
3310 struct demangle_component
*ret
;
3311 int was_expression
= di
->is_expression
;
3313 di
->is_expression
= 1;
3314 ret
= d_expression_1 (di
);
3315 di
->is_expression
= was_expression
;
3319 /* <expr-primary> ::= L <type> <(value) number> E
3320 ::= L <type> <(value) float> E
3321 ::= L <mangled-name> E
3324 static struct demangle_component
*
3325 d_expr_primary (struct d_info
*di
)
3327 struct demangle_component
*ret
;
3329 if (! d_check_char (di
, 'L'))
3331 if (d_peek_char (di
) == '_'
3332 /* Workaround for G++ bug; see comment in write_template_arg. */
3333 || d_peek_char (di
) == 'Z')
3334 ret
= cplus_demangle_mangled_name (di
, 0);
3337 struct demangle_component
*type
;
3338 enum demangle_component_type t
;
3341 type
= cplus_demangle_type (di
);
3345 /* If we have a type we know how to print, we aren't going to
3346 print the type name itself. */
3347 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3348 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3349 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3351 /* Rather than try to interpret the literal value, we just
3352 collect it as a string. Note that it's possible to have a
3353 floating point literal here. The ABI specifies that the
3354 format of such literals is machine independent. That's fine,
3355 but what's not fine is that versions of g++ up to 3.2 with
3356 -fabi-version=1 used upper case letters in the hex constant,
3357 and dumped out gcc's internal representation. That makes it
3358 hard to tell where the constant ends, and hard to dump the
3359 constant in any readable form anyhow. We don't attempt to
3360 handle these cases. */
3362 t
= DEMANGLE_COMPONENT_LITERAL
;
3363 if (d_peek_char (di
) == 'n')
3365 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3369 while (d_peek_char (di
) != 'E')
3371 if (d_peek_char (di
) == '\0')
3375 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3377 if (! d_check_char (di
, 'E'))
3382 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3383 ::= Z <(function) encoding> E s [<discriminator>]
3384 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3387 static struct demangle_component
*
3388 d_local_name (struct d_info
*di
)
3390 struct demangle_component
*function
;
3392 if (! d_check_char (di
, 'Z'))
3395 function
= d_encoding (di
, 0);
3397 if (! d_check_char (di
, 'E'))
3400 if (d_peek_char (di
) == 's')
3403 if (! d_discriminator (di
))
3405 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3406 d_make_name (di
, "string literal",
3407 sizeof "string literal" - 1));
3411 struct demangle_component
*name
;
3414 if (d_peek_char (di
) == 'd')
3416 /* Default argument scope: d <number> _. */
3418 num
= d_compact_number (di
);
3427 /* Lambdas and unnamed types have internal discriminators. */
3428 case DEMANGLE_COMPONENT_LAMBDA
:
3429 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3432 if (! d_discriminator (di
))
3436 name
= d_make_default_arg (di
, num
, name
);
3437 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3441 /* <discriminator> ::= _ <(non-negative) number>
3443 We demangle the discriminator, but we don't print it out. FIXME:
3444 We should print it out in verbose mode. */
3447 d_discriminator (struct d_info
*di
)
3451 if (d_peek_char (di
) != '_')
3454 discrim
= d_number (di
);
3460 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3462 static struct demangle_component
*
3463 d_lambda (struct d_info
*di
)
3465 struct demangle_component
*tl
;
3466 struct demangle_component
*ret
;
3469 if (! d_check_char (di
, 'U'))
3471 if (! d_check_char (di
, 'l'))
3474 tl
= d_parmlist (di
);
3478 if (! d_check_char (di
, 'E'))
3481 num
= d_compact_number (di
);
3485 ret
= d_make_empty (di
);
3488 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3489 ret
->u
.s_unary_num
.sub
= tl
;
3490 ret
->u
.s_unary_num
.num
= num
;
3493 if (! d_add_substitution (di
, ret
))
3499 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3501 static struct demangle_component
*
3502 d_unnamed_type (struct d_info
*di
)
3504 struct demangle_component
*ret
;
3507 if (! d_check_char (di
, 'U'))
3509 if (! d_check_char (di
, 't'))
3512 num
= d_compact_number (di
);
3516 ret
= d_make_empty (di
);
3519 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3520 ret
->u
.s_number
.number
= num
;
3523 if (! d_add_substitution (di
, ret
))
3529 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3532 static struct demangle_component
*
3533 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3535 const char *suffix
= d_str (di
);
3536 const char *pend
= suffix
;
3537 struct demangle_component
*n
;
3539 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3542 while (IS_LOWER (*pend
) || *pend
== '_')
3545 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3548 while (IS_DIGIT (*pend
))
3551 d_advance (di
, pend
- suffix
);
3552 n
= d_make_name (di
, suffix
, pend
- suffix
);
3553 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3556 /* Add a new substitution. */
3559 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3563 if (di
->next_sub
>= di
->num_subs
)
3565 di
->subs
[di
->next_sub
] = dc
;
3570 /* <substitution> ::= S <seq-id> _
3580 If PREFIX is non-zero, then this type is being used as a prefix in
3581 a qualified name. In this case, for the standard substitutions, we
3582 need to check whether we are being used as a prefix for a
3583 constructor or destructor, and return a full template name.
3584 Otherwise we will get something like std::iostream::~iostream()
3585 which does not correspond particularly well to any function which
3586 actually appears in the source.
3589 static const struct d_standard_sub_info standard_subs
[] =
3594 { 'a', NL ("std::allocator"),
3595 NL ("std::allocator"),
3597 { 'b', NL ("std::basic_string"),
3598 NL ("std::basic_string"),
3599 NL ("basic_string") },
3600 { 's', NL ("std::string"),
3601 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3602 NL ("basic_string") },
3603 { 'i', NL ("std::istream"),
3604 NL ("std::basic_istream<char, std::char_traits<char> >"),
3605 NL ("basic_istream") },
3606 { 'o', NL ("std::ostream"),
3607 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3608 NL ("basic_ostream") },
3609 { 'd', NL ("std::iostream"),
3610 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3611 NL ("basic_iostream") }
3614 static struct demangle_component
*
3615 d_substitution (struct d_info
*di
, int prefix
)
3619 if (! d_check_char (di
, 'S'))
3622 c
= d_next_char (di
);
3623 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3632 unsigned int new_id
;
3635 new_id
= id
* 36 + c
- '0';
3636 else if (IS_UPPER (c
))
3637 new_id
= id
* 36 + c
- 'A' + 10;
3643 c
= d_next_char (di
);
3650 if (id
>= (unsigned int) di
->next_sub
)
3655 return di
->subs
[id
];
3660 const struct d_standard_sub_info
*p
;
3661 const struct d_standard_sub_info
*pend
;
3663 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3664 if (! verbose
&& prefix
)
3668 peek
= d_peek_char (di
);
3669 if (peek
== 'C' || peek
== 'D')
3673 pend
= (&standard_subs
[0]
3674 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3675 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3682 if (p
->set_last_name
!= NULL
)
3683 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3684 p
->set_last_name_len
);
3687 s
= p
->full_expansion
;
3692 s
= p
->simple_expansion
;
3693 len
= p
->simple_len
;
3695 di
->expansion
+= len
;
3696 return d_make_sub (di
, s
, len
);
3705 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3707 checkpoint
->n
= di
->n
;
3708 checkpoint
->next_comp
= di
->next_comp
;
3709 checkpoint
->next_sub
= di
->next_sub
;
3710 checkpoint
->did_subs
= di
->did_subs
;
3711 checkpoint
->expansion
= di
->expansion
;
3715 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3717 di
->n
= checkpoint
->n
;
3718 di
->next_comp
= checkpoint
->next_comp
;
3719 di
->next_sub
= checkpoint
->next_sub
;
3720 di
->did_subs
= checkpoint
->did_subs
;
3721 di
->expansion
= checkpoint
->expansion
;
3724 /* Initialize a growable string. */
3727 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3732 dgs
->allocation_failure
= 0;
3735 d_growable_string_resize (dgs
, estimate
);
3738 /* Grow a growable string to a given size. */
3741 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3746 if (dgs
->allocation_failure
)
3749 /* Start allocation at two bytes to avoid any possibility of confusion
3750 with the special value of 1 used as a return in *palc to indicate
3751 allocation failures. */
3752 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3753 while (newalc
< need
)
3756 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3763 dgs
->allocation_failure
= 1;
3770 /* Append a buffer to a growable string. */
3773 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3774 const char *s
, size_t l
)
3778 need
= dgs
->len
+ l
+ 1;
3779 if (need
> dgs
->alc
)
3780 d_growable_string_resize (dgs
, need
);
3782 if (dgs
->allocation_failure
)
3785 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3786 dgs
->buf
[dgs
->len
+ l
] = '\0';
3790 /* Bridge growable strings to the callback mechanism. */
3793 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3795 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3797 d_growable_string_append_buffer (dgs
, s
, l
);
3800 /* Walk the tree, counting the number of templates encountered, and
3801 the number of times a scope might be saved. These counts will be
3802 used to allocate data structures for d_print_comp, so the logic
3803 here must mirror the logic d_print_comp will use. It is not
3804 important that the resulting numbers are exact, so long as they
3805 are larger than the actual numbers encountered. */
3808 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
3809 const struct demangle_component
*dc
)
3816 case DEMANGLE_COMPONENT_NAME
:
3817 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3818 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3819 case DEMANGLE_COMPONENT_SUB_STD
:
3820 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3821 case DEMANGLE_COMPONENT_OPERATOR
:
3822 case DEMANGLE_COMPONENT_CHARACTER
:
3823 case DEMANGLE_COMPONENT_NUMBER
:
3824 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3827 case DEMANGLE_COMPONENT_TEMPLATE
:
3829 goto recurse_left_right
;
3831 case DEMANGLE_COMPONENT_REFERENCE
:
3832 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3833 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
3835 goto recurse_left_right
;
3837 case DEMANGLE_COMPONENT_QUAL_NAME
:
3838 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3839 case DEMANGLE_COMPONENT_TYPED_NAME
:
3840 case DEMANGLE_COMPONENT_VTABLE
:
3841 case DEMANGLE_COMPONENT_VTT
:
3842 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3843 case DEMANGLE_COMPONENT_TYPEINFO
:
3844 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3845 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3846 case DEMANGLE_COMPONENT_THUNK
:
3847 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3848 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3849 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3850 case DEMANGLE_COMPONENT_GUARD
:
3851 case DEMANGLE_COMPONENT_TLS_INIT
:
3852 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
3853 case DEMANGLE_COMPONENT_REFTEMP
:
3854 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3855 case DEMANGLE_COMPONENT_RESTRICT
:
3856 case DEMANGLE_COMPONENT_VOLATILE
:
3857 case DEMANGLE_COMPONENT_CONST
:
3858 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3859 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3860 case DEMANGLE_COMPONENT_CONST_THIS
:
3861 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
3862 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
3863 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3864 case DEMANGLE_COMPONENT_POINTER
:
3865 case DEMANGLE_COMPONENT_COMPLEX
:
3866 case DEMANGLE_COMPONENT_IMAGINARY
:
3867 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3868 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3869 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3870 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3871 case DEMANGLE_COMPONENT_FIXED_TYPE
:
3872 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
3873 case DEMANGLE_COMPONENT_ARGLIST
:
3874 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3875 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
3876 case DEMANGLE_COMPONENT_CAST
:
3877 case DEMANGLE_COMPONENT_CONVERSION
:
3878 case DEMANGLE_COMPONENT_NULLARY
:
3879 case DEMANGLE_COMPONENT_UNARY
:
3880 case DEMANGLE_COMPONENT_BINARY
:
3881 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3882 case DEMANGLE_COMPONENT_TRINARY
:
3883 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3884 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3885 case DEMANGLE_COMPONENT_LITERAL
:
3886 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3887 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
3888 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
3889 case DEMANGLE_COMPONENT_DECLTYPE
:
3890 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
3891 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
3892 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3893 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3894 case DEMANGLE_COMPONENT_CLONE
:
3896 d_count_templates_scopes (num_templates
, num_scopes
,
3898 d_count_templates_scopes (num_templates
, num_scopes
,
3902 case DEMANGLE_COMPONENT_CTOR
:
3903 d_count_templates_scopes (num_templates
, num_scopes
,
3907 case DEMANGLE_COMPONENT_DTOR
:
3908 d_count_templates_scopes (num_templates
, num_scopes
,
3912 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3913 d_count_templates_scopes (num_templates
, num_scopes
,
3914 dc
->u
.s_extended_operator
.name
);
3917 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
3918 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
3919 d_count_templates_scopes (num_templates
, num_scopes
,
3923 case DEMANGLE_COMPONENT_LAMBDA
:
3924 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
3925 d_count_templates_scopes (num_templates
, num_scopes
,
3926 dc
->u
.s_unary_num
.sub
);
3931 /* Initialize a print information structure. */
3934 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
3935 void *opaque
, const struct demangle_component
*dc
)
3938 dpi
->last_char
= '\0';
3939 dpi
->templates
= NULL
;
3940 dpi
->modifiers
= NULL
;
3941 dpi
->pack_index
= 0;
3942 dpi
->flush_count
= 0;
3944 dpi
->callback
= callback
;
3945 dpi
->opaque
= opaque
;
3947 dpi
->demangle_failure
= 0;
3949 dpi
->saved_scopes
= NULL
;
3950 dpi
->next_saved_scope
= 0;
3951 dpi
->num_saved_scopes
= 0;
3953 dpi
->copy_templates
= NULL
;
3954 dpi
->next_copy_template
= 0;
3955 dpi
->num_copy_templates
= 0;
3957 d_count_templates_scopes (&dpi
->num_copy_templates
,
3958 &dpi
->num_saved_scopes
, dc
);
3959 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
3961 dpi
->current_template
= NULL
;
3964 /* Indicate that an error occurred during printing, and test for error. */
3967 d_print_error (struct d_print_info
*dpi
)
3969 dpi
->demangle_failure
= 1;
3973 d_print_saw_error (struct d_print_info
*dpi
)
3975 return dpi
->demangle_failure
!= 0;
3978 /* Flush buffered characters to the callback. */
3981 d_print_flush (struct d_print_info
*dpi
)
3983 dpi
->buf
[dpi
->len
] = '\0';
3984 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3989 /* Append characters and buffers for printing. */
3992 d_append_char (struct d_print_info
*dpi
, char c
)
3994 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3995 d_print_flush (dpi
);
3997 dpi
->buf
[dpi
->len
++] = c
;
4002 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4006 for (i
= 0; i
< l
; i
++)
4007 d_append_char (dpi
, s
[i
]);
4011 d_append_string (struct d_print_info
*dpi
, const char *s
)
4013 d_append_buffer (dpi
, s
, strlen (s
));
4017 d_append_num (struct d_print_info
*dpi
, long l
)
4020 sprintf (buf
,"%ld", l
);
4021 d_append_string (dpi
, buf
);
4025 d_last_char (struct d_print_info
*dpi
)
4027 return dpi
->last_char
;
4030 /* Turn components into a human readable string. OPTIONS is the
4031 options bits passed to the demangler. DC is the tree to print.
4032 CALLBACK is a function to call to flush demangled string segments
4033 as they fill the intermediate buffer, and OPAQUE is a generalized
4034 callback argument. On success, this returns 1. On failure,
4035 it returns 0, indicating a bad parse. It does not use heap
4036 memory to build an output string, so cannot encounter memory
4037 allocation failure. */
4039 CP_STATIC_IF_GLIBCPP_V3
4041 cplus_demangle_print_callback (int options
,
4042 const struct demangle_component
*dc
,
4043 demangle_callbackref callback
, void *opaque
)
4045 struct d_print_info dpi
;
4047 d_print_init (&dpi
, callback
, opaque
, dc
);
4050 #ifdef CP_DYNAMIC_ARRAYS
4051 __extension__
struct d_saved_scope scopes
[dpi
.num_saved_scopes
];
4052 __extension__
struct d_print_template temps
[dpi
.num_copy_templates
];
4054 dpi
.saved_scopes
= scopes
;
4055 dpi
.copy_templates
= temps
;
4057 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4058 * sizeof (*dpi
.saved_scopes
));
4059 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4060 * sizeof (*dpi
.copy_templates
));
4063 d_print_comp (&dpi
, options
, dc
);
4066 d_print_flush (&dpi
);
4068 return ! d_print_saw_error (&dpi
);
4071 /* Turn components into a human readable string. OPTIONS is the
4072 options bits passed to the demangler. DC is the tree to print.
4073 ESTIMATE is a guess at the length of the result. This returns a
4074 string allocated by malloc, or NULL on error. On success, this
4075 sets *PALC to the size of the allocated buffer. On failure, this
4076 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4079 CP_STATIC_IF_GLIBCPP_V3
4081 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4082 int estimate
, size_t *palc
)
4084 struct d_growable_string dgs
;
4086 d_growable_string_init (&dgs
, estimate
);
4088 if (! cplus_demangle_print_callback (options
, dc
,
4089 d_growable_string_callback_adapter
,
4097 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4101 /* Returns the I'th element of the template arglist ARGS, or NULL on
4104 static struct demangle_component
*
4105 d_index_template_argument (struct demangle_component
*args
, int i
)
4107 struct demangle_component
*a
;
4113 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4119 if (i
!= 0 || a
== NULL
)
4125 /* Returns the template argument from the current context indicated by DC,
4126 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4128 static struct demangle_component
*
4129 d_lookup_template_argument (struct d_print_info
*dpi
,
4130 const struct demangle_component
*dc
)
4132 if (dpi
->templates
== NULL
)
4134 d_print_error (dpi
);
4138 return d_index_template_argument
4139 (d_right (dpi
->templates
->template_decl
),
4140 dc
->u
.s_number
.number
);
4143 /* Returns a template argument pack used in DC (any will do), or NULL. */
4145 static struct demangle_component
*
4146 d_find_pack (struct d_print_info
*dpi
,
4147 const struct demangle_component
*dc
)
4149 struct demangle_component
*a
;
4155 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4156 a
= d_lookup_template_argument (dpi
, dc
);
4157 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4161 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4164 case DEMANGLE_COMPONENT_LAMBDA
:
4165 case DEMANGLE_COMPONENT_NAME
:
4166 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4167 case DEMANGLE_COMPONENT_OPERATOR
:
4168 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4169 case DEMANGLE_COMPONENT_SUB_STD
:
4170 case DEMANGLE_COMPONENT_CHARACTER
:
4171 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4172 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4175 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4176 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4177 case DEMANGLE_COMPONENT_CTOR
:
4178 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4179 case DEMANGLE_COMPONENT_DTOR
:
4180 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4183 a
= d_find_pack (dpi
, d_left (dc
));
4186 return d_find_pack (dpi
, d_right (dc
));
4190 /* Returns the length of the template argument pack DC. */
4193 d_pack_length (const struct demangle_component
*dc
)
4196 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4197 && d_left (dc
) != NULL
)
4205 /* DC is a component of a mangled expression. Print it, wrapped in parens
4209 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4210 const struct demangle_component
*dc
)
4213 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4214 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4215 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4216 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4219 d_append_char (dpi
, '(');
4220 d_print_comp (dpi
, options
, dc
);
4222 d_append_char (dpi
, ')');
4225 /* Save the current scope. */
4228 d_save_scope (struct d_print_info
*dpi
,
4229 const struct demangle_component
*container
)
4231 struct d_saved_scope
*scope
;
4232 struct d_print_template
*src
, **link
;
4234 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4236 d_print_error (dpi
);
4239 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4240 dpi
->next_saved_scope
++;
4242 scope
->container
= container
;
4243 link
= &scope
->templates
;
4245 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4247 struct d_print_template
*dst
;
4249 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4251 d_print_error (dpi
);
4254 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4255 dpi
->next_copy_template
++;
4257 dst
->template_decl
= src
->template_decl
;
4265 /* Attempt to locate a previously saved scope. Returns NULL if no
4266 corresponding saved scope was found. */
4268 static struct d_saved_scope
*
4269 d_get_saved_scope (struct d_print_info
*dpi
,
4270 const struct demangle_component
*container
)
4274 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4275 if (dpi
->saved_scopes
[i
].container
== container
)
4276 return &dpi
->saved_scopes
[i
];
4281 /* Subroutine to handle components. */
4284 d_print_comp (struct d_print_info
*dpi
, int options
,
4285 const struct demangle_component
*dc
)
4287 /* Magic variable to let reference smashing skip over the next modifier
4288 without needing to modify *dc. */
4289 const struct demangle_component
*mod_inner
= NULL
;
4291 /* Variable used to store the current templates while a previously
4292 captured scope is used. */
4293 struct d_print_template
*saved_templates
;
4295 /* Nonzero if templates have been stored in the above variable. */
4296 int need_template_restore
= 0;
4300 d_print_error (dpi
);
4303 if (d_print_saw_error (dpi
))
4308 case DEMANGLE_COMPONENT_NAME
:
4309 if ((options
& DMGL_JAVA
) == 0)
4310 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4312 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4315 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4316 d_print_comp (dpi
, options
, d_left (dc
));
4317 d_append_string (dpi
, "[abi:");
4318 d_print_comp (dpi
, options
, d_right (dc
));
4319 d_append_char (dpi
, ']');
4322 case DEMANGLE_COMPONENT_QUAL_NAME
:
4323 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4324 d_print_comp (dpi
, options
, d_left (dc
));
4325 if ((options
& DMGL_JAVA
) == 0)
4326 d_append_string (dpi
, "::");
4328 d_append_char (dpi
, '.');
4330 struct demangle_component
*local_name
= d_right (dc
);
4331 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4333 d_append_string (dpi
, "{default arg#");
4334 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4335 d_append_string (dpi
, "}::");
4336 local_name
= local_name
->u
.s_unary_num
.sub
;
4338 d_print_comp (dpi
, options
, local_name
);
4342 case DEMANGLE_COMPONENT_TYPED_NAME
:
4344 struct d_print_mod
*hold_modifiers
;
4345 struct demangle_component
*typed_name
;
4346 struct d_print_mod adpm
[4];
4348 struct d_print_template dpt
;
4350 /* Pass the name down to the type so that it can be printed in
4351 the right place for the type. We also have to pass down
4352 any CV-qualifiers, which apply to the this parameter. */
4353 hold_modifiers
= dpi
->modifiers
;
4356 typed_name
= d_left (dc
);
4357 while (typed_name
!= NULL
)
4359 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4361 d_print_error (dpi
);
4365 adpm
[i
].next
= dpi
->modifiers
;
4366 dpi
->modifiers
= &adpm
[i
];
4367 adpm
[i
].mod
= typed_name
;
4368 adpm
[i
].printed
= 0;
4369 adpm
[i
].templates
= dpi
->templates
;
4372 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4373 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4374 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4375 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4376 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4379 typed_name
= d_left (typed_name
);
4382 if (typed_name
== NULL
)
4384 d_print_error (dpi
);
4388 /* If typed_name is a template, then it applies to the
4389 function type as well. */
4390 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4392 dpt
.next
= dpi
->templates
;
4393 dpi
->templates
= &dpt
;
4394 dpt
.template_decl
= typed_name
;
4397 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4398 there may be CV-qualifiers on its right argument which
4399 really apply here; this happens when parsing a class which
4400 is local to a function. */
4401 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4403 struct demangle_component
*local_name
;
4405 local_name
= d_right (typed_name
);
4406 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4407 local_name
= local_name
->u
.s_unary_num
.sub
;
4408 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4409 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4410 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4411 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4412 || (local_name
->type
4413 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4415 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4417 d_print_error (dpi
);
4421 adpm
[i
] = adpm
[i
- 1];
4422 adpm
[i
].next
= &adpm
[i
- 1];
4423 dpi
->modifiers
= &adpm
[i
];
4425 adpm
[i
- 1].mod
= local_name
;
4426 adpm
[i
- 1].printed
= 0;
4427 adpm
[i
- 1].templates
= dpi
->templates
;
4430 local_name
= d_left (local_name
);
4434 d_print_comp (dpi
, options
, d_right (dc
));
4436 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4437 dpi
->templates
= dpt
.next
;
4439 /* If the modifiers didn't get printed by the type, print them
4444 if (! adpm
[i
].printed
)
4446 d_append_char (dpi
, ' ');
4447 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4451 dpi
->modifiers
= hold_modifiers
;
4456 case DEMANGLE_COMPONENT_TEMPLATE
:
4458 struct d_print_mod
*hold_dpm
;
4459 struct demangle_component
*dcl
;
4460 const struct demangle_component
*hold_current
;
4462 /* This template may need to be referenced by a cast operator
4463 contained in its subtree. */
4464 hold_current
= dpi
->current_template
;
4465 dpi
->current_template
= dc
;
4467 /* Don't push modifiers into a template definition. Doing so
4468 could give the wrong definition for a template argument.
4469 Instead, treat the template essentially as a name. */
4471 hold_dpm
= dpi
->modifiers
;
4472 dpi
->modifiers
= NULL
;
4476 if ((options
& DMGL_JAVA
) != 0
4477 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4478 && dcl
->u
.s_name
.len
== 6
4479 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4481 /* Special-case Java arrays, so that JArray<TYPE> appears
4482 instead as TYPE[]. */
4484 d_print_comp (dpi
, options
, d_right (dc
));
4485 d_append_string (dpi
, "[]");
4489 d_print_comp (dpi
, options
, dcl
);
4490 if (d_last_char (dpi
) == '<')
4491 d_append_char (dpi
, ' ');
4492 d_append_char (dpi
, '<');
4493 d_print_comp (dpi
, options
, d_right (dc
));
4494 /* Avoid generating two consecutive '>' characters, to avoid
4495 the C++ syntactic ambiguity. */
4496 if (d_last_char (dpi
) == '>')
4497 d_append_char (dpi
, ' ');
4498 d_append_char (dpi
, '>');
4501 dpi
->modifiers
= hold_dpm
;
4502 dpi
->current_template
= hold_current
;
4507 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4509 struct d_print_template
*hold_dpt
;
4510 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4512 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4513 a
= d_index_template_argument (a
, dpi
->pack_index
);
4517 d_print_error (dpi
);
4521 /* While processing this parameter, we need to pop the list of
4522 templates. This is because the template parameter may
4523 itself be a reference to a parameter of an outer
4526 hold_dpt
= dpi
->templates
;
4527 dpi
->templates
= hold_dpt
->next
;
4529 d_print_comp (dpi
, options
, a
);
4531 dpi
->templates
= hold_dpt
;
4536 case DEMANGLE_COMPONENT_CTOR
:
4537 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4540 case DEMANGLE_COMPONENT_DTOR
:
4541 d_append_char (dpi
, '~');
4542 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4545 case DEMANGLE_COMPONENT_VTABLE
:
4546 d_append_string (dpi
, "vtable for ");
4547 d_print_comp (dpi
, options
, d_left (dc
));
4550 case DEMANGLE_COMPONENT_VTT
:
4551 d_append_string (dpi
, "VTT for ");
4552 d_print_comp (dpi
, options
, d_left (dc
));
4555 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4556 d_append_string (dpi
, "construction vtable for ");
4557 d_print_comp (dpi
, options
, d_left (dc
));
4558 d_append_string (dpi
, "-in-");
4559 d_print_comp (dpi
, options
, d_right (dc
));
4562 case DEMANGLE_COMPONENT_TYPEINFO
:
4563 d_append_string (dpi
, "typeinfo for ");
4564 d_print_comp (dpi
, options
, d_left (dc
));
4567 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4568 d_append_string (dpi
, "typeinfo name for ");
4569 d_print_comp (dpi
, options
, d_left (dc
));
4572 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4573 d_append_string (dpi
, "typeinfo fn for ");
4574 d_print_comp (dpi
, options
, d_left (dc
));
4577 case DEMANGLE_COMPONENT_THUNK
:
4578 d_append_string (dpi
, "non-virtual thunk to ");
4579 d_print_comp (dpi
, options
, d_left (dc
));
4582 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4583 d_append_string (dpi
, "virtual thunk to ");
4584 d_print_comp (dpi
, options
, d_left (dc
));
4587 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4588 d_append_string (dpi
, "covariant return thunk to ");
4589 d_print_comp (dpi
, options
, d_left (dc
));
4592 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4593 d_append_string (dpi
, "java Class for ");
4594 d_print_comp (dpi
, options
, d_left (dc
));
4597 case DEMANGLE_COMPONENT_GUARD
:
4598 d_append_string (dpi
, "guard variable for ");
4599 d_print_comp (dpi
, options
, d_left (dc
));
4602 case DEMANGLE_COMPONENT_TLS_INIT
:
4603 d_append_string (dpi
, "TLS init function for ");
4604 d_print_comp (dpi
, options
, d_left (dc
));
4607 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4608 d_append_string (dpi
, "TLS wrapper function for ");
4609 d_print_comp (dpi
, options
, d_left (dc
));
4612 case DEMANGLE_COMPONENT_REFTEMP
:
4613 d_append_string (dpi
, "reference temporary #");
4614 d_print_comp (dpi
, options
, d_right (dc
));
4615 d_append_string (dpi
, " for ");
4616 d_print_comp (dpi
, options
, d_left (dc
));
4619 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4620 d_append_string (dpi
, "hidden alias for ");
4621 d_print_comp (dpi
, options
, d_left (dc
));
4624 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4625 d_append_string (dpi
, "transaction clone for ");
4626 d_print_comp (dpi
, options
, d_left (dc
));
4629 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4630 d_append_string (dpi
, "non-transaction clone for ");
4631 d_print_comp (dpi
, options
, d_left (dc
));
4634 case DEMANGLE_COMPONENT_SUB_STD
:
4635 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4638 case DEMANGLE_COMPONENT_RESTRICT
:
4639 case DEMANGLE_COMPONENT_VOLATILE
:
4640 case DEMANGLE_COMPONENT_CONST
:
4642 struct d_print_mod
*pdpm
;
4644 /* When printing arrays, it's possible to have cases where the
4645 same CV-qualifier gets pushed on the stack multiple times.
4646 We only need to print it once. */
4648 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4650 if (! pdpm
->printed
)
4652 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4653 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4654 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4656 if (pdpm
->mod
->type
== dc
->type
)
4658 d_print_comp (dpi
, options
, d_left (dc
));
4666 case DEMANGLE_COMPONENT_REFERENCE
:
4667 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4669 /* Handle reference smashing: & + && = &. */
4670 const struct demangle_component
*sub
= d_left (dc
);
4671 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4673 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4674 struct demangle_component
*a
;
4678 /* This is the first time SUB has been traversed.
4679 We need to capture the current templates so
4680 they can be restored if SUB is reentered as a
4682 d_save_scope (dpi
, sub
);
4683 if (d_print_saw_error (dpi
))
4688 /* This traversal is reentering SUB as a substition.
4689 Restore the original templates temporarily. */
4690 saved_templates
= dpi
->templates
;
4691 dpi
->templates
= scope
->templates
;
4692 need_template_restore
= 1;
4695 a
= d_lookup_template_argument (dpi
, sub
);
4696 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4697 a
= d_index_template_argument (a
, dpi
->pack_index
);
4701 if (need_template_restore
)
4702 dpi
->templates
= saved_templates
;
4704 d_print_error (dpi
);
4711 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4712 || sub
->type
== dc
->type
)
4714 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4715 mod_inner
= d_left (sub
);
4719 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4720 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4721 case DEMANGLE_COMPONENT_CONST_THIS
:
4722 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4723 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4724 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4725 case DEMANGLE_COMPONENT_POINTER
:
4726 case DEMANGLE_COMPONENT_COMPLEX
:
4727 case DEMANGLE_COMPONENT_IMAGINARY
:
4730 /* We keep a list of modifiers on the stack. */
4731 struct d_print_mod dpm
;
4733 dpm
.next
= dpi
->modifiers
;
4734 dpi
->modifiers
= &dpm
;
4737 dpm
.templates
= dpi
->templates
;
4740 mod_inner
= d_left (dc
);
4742 d_print_comp (dpi
, options
, mod_inner
);
4744 /* If the modifier didn't get printed by the type, print it
4747 d_print_mod (dpi
, options
, dc
);
4749 dpi
->modifiers
= dpm
.next
;
4751 if (need_template_restore
)
4752 dpi
->templates
= saved_templates
;
4757 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4758 if ((options
& DMGL_JAVA
) == 0)
4759 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4760 dc
->u
.s_builtin
.type
->len
);
4762 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4763 dc
->u
.s_builtin
.type
->java_len
);
4766 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4767 d_print_comp (dpi
, options
, d_left (dc
));
4770 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4772 if ((options
& DMGL_RET_POSTFIX
) != 0)
4773 d_print_function_type (dpi
,
4774 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4775 dc
, dpi
->modifiers
);
4777 /* Print return type if present */
4778 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4779 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4781 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4783 struct d_print_mod dpm
;
4785 /* We must pass this type down as a modifier in order to
4786 print it in the right location. */
4787 dpm
.next
= dpi
->modifiers
;
4788 dpi
->modifiers
= &dpm
;
4791 dpm
.templates
= dpi
->templates
;
4793 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4796 dpi
->modifiers
= dpm
.next
;
4801 /* In standard prefix notation, there is a space between the
4802 return type and the function signature. */
4803 if ((options
& DMGL_RET_POSTFIX
) == 0)
4804 d_append_char (dpi
, ' ');
4807 if ((options
& DMGL_RET_POSTFIX
) == 0)
4808 d_print_function_type (dpi
,
4809 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4810 dc
, dpi
->modifiers
);
4815 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4817 struct d_print_mod
*hold_modifiers
;
4818 struct d_print_mod adpm
[4];
4820 struct d_print_mod
*pdpm
;
4822 /* We must pass this type down as a modifier in order to print
4823 multi-dimensional arrays correctly. If the array itself is
4824 CV-qualified, we act as though the element type were
4825 CV-qualified. We do this by copying the modifiers down
4826 rather than fiddling pointers, so that we don't wind up
4827 with a d_print_mod higher on the stack pointing into our
4828 stack frame after we return. */
4830 hold_modifiers
= dpi
->modifiers
;
4832 adpm
[0].next
= hold_modifiers
;
4833 dpi
->modifiers
= &adpm
[0];
4835 adpm
[0].printed
= 0;
4836 adpm
[0].templates
= dpi
->templates
;
4839 pdpm
= hold_modifiers
;
4841 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4842 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4843 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4845 if (! pdpm
->printed
)
4847 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4849 d_print_error (dpi
);
4854 adpm
[i
].next
= dpi
->modifiers
;
4855 dpi
->modifiers
= &adpm
[i
];
4863 d_print_comp (dpi
, options
, d_right (dc
));
4865 dpi
->modifiers
= hold_modifiers
;
4867 if (adpm
[0].printed
)
4873 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4876 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4881 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4882 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4884 struct d_print_mod dpm
;
4886 dpm
.next
= dpi
->modifiers
;
4887 dpi
->modifiers
= &dpm
;
4890 dpm
.templates
= dpi
->templates
;
4892 d_print_comp (dpi
, options
, d_right (dc
));
4894 /* If the modifier didn't get printed by the type, print it
4897 d_print_mod (dpi
, options
, dc
);
4899 dpi
->modifiers
= dpm
.next
;
4904 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4905 if (dc
->u
.s_fixed
.sat
)
4906 d_append_string (dpi
, "_Sat ");
4907 /* Don't print "int _Accum". */
4908 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4909 != &cplus_demangle_builtin_types
['i'-'a'])
4911 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
4912 d_append_char (dpi
, ' ');
4914 if (dc
->u
.s_fixed
.accum
)
4915 d_append_string (dpi
, "_Accum");
4917 d_append_string (dpi
, "_Fract");
4920 case DEMANGLE_COMPONENT_ARGLIST
:
4921 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4922 if (d_left (dc
) != NULL
)
4923 d_print_comp (dpi
, options
, d_left (dc
));
4924 if (d_right (dc
) != NULL
)
4927 unsigned long int flush_count
;
4928 /* Make sure ", " isn't flushed by d_append_string, otherwise
4929 dpi->len -= 2 wouldn't work. */
4930 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4931 d_print_flush (dpi
);
4932 d_append_string (dpi
, ", ");
4934 flush_count
= dpi
->flush_count
;
4935 d_print_comp (dpi
, options
, d_right (dc
));
4936 /* If that didn't print anything (which can happen with empty
4937 template argument packs), remove the comma and space. */
4938 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4943 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4945 struct demangle_component
*type
= d_left (dc
);
4946 struct demangle_component
*list
= d_right (dc
);
4949 d_print_comp (dpi
, options
, type
);
4950 d_append_char (dpi
, '{');
4951 d_print_comp (dpi
, options
, list
);
4952 d_append_char (dpi
, '}');
4956 case DEMANGLE_COMPONENT_OPERATOR
:
4958 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
4961 d_append_string (dpi
, "operator");
4962 /* Add a space before new/delete. */
4963 if (IS_LOWER (op
->name
[0]))
4964 d_append_char (dpi
, ' ');
4965 /* Omit a trailing space. */
4966 if (op
->name
[len
-1] == ' ')
4968 d_append_buffer (dpi
, op
->name
, len
);
4972 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4973 d_append_string (dpi
, "operator ");
4974 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
4977 case DEMANGLE_COMPONENT_CONVERSION
:
4978 d_append_string (dpi
, "operator ");
4979 d_print_conversion (dpi
, options
, dc
);
4982 case DEMANGLE_COMPONENT_NULLARY
:
4983 d_print_expr_op (dpi
, options
, d_left (dc
));
4986 case DEMANGLE_COMPONENT_UNARY
:
4988 struct demangle_component
*op
= d_left (dc
);
4989 struct demangle_component
*operand
= d_right (dc
);
4990 const char *code
= NULL
;
4992 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4994 code
= op
->u
.s_operator
.op
->code
;
4995 if (!strcmp (code
, "ad"))
4997 /* Don't print the argument list for the address of a
4999 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5000 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5001 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5002 operand
= d_left (operand
);
5004 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5006 /* This indicates a suffix operator. */
5007 operand
= d_left (operand
);
5008 d_print_subexpr (dpi
, options
, operand
);
5009 d_print_expr_op (dpi
, options
, op
);
5014 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5015 d_print_expr_op (dpi
, options
, op
);
5018 d_append_char (dpi
, '(');
5019 d_print_cast (dpi
, options
, op
);
5020 d_append_char (dpi
, ')');
5022 if (code
&& !strcmp (code
, "gs"))
5023 /* Avoid parens after '::'. */
5024 d_print_comp (dpi
, options
, operand
);
5025 else if (code
&& !strcmp (code
, "st"))
5026 /* Always print parens for sizeof (type). */
5028 d_append_char (dpi
, '(');
5029 d_print_comp (dpi
, options
, operand
);
5030 d_append_char (dpi
, ')');
5033 d_print_subexpr (dpi
, options
, operand
);
5037 case DEMANGLE_COMPONENT_BINARY
:
5038 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5040 d_print_error (dpi
);
5044 if (op_is_new_cast (d_left (dc
)))
5046 d_print_expr_op (dpi
, options
, d_left (dc
));
5047 d_append_char (dpi
, '<');
5048 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5049 d_append_string (dpi
, ">(");
5050 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5051 d_append_char (dpi
, ')');
5055 /* We wrap an expression which uses the greater-than operator in
5056 an extra layer of parens so that it does not get confused
5057 with the '>' which ends the template parameters. */
5058 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5059 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5060 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5061 d_append_char (dpi
, '(');
5063 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5064 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5066 /* Function call used in an expression should not have printed types
5067 of the function arguments. Values of the function arguments still
5068 get printed below. */
5070 const struct demangle_component
*func
= d_left (d_right (dc
));
5072 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5073 d_print_error (dpi
);
5074 d_print_subexpr (dpi
, options
, d_left (func
));
5077 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5078 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5080 d_append_char (dpi
, '[');
5081 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5082 d_append_char (dpi
, ']');
5086 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5087 d_print_expr_op (dpi
, options
, d_left (dc
));
5088 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5091 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5092 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5093 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5094 d_append_char (dpi
, ')');
5098 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5099 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5100 d_print_error (dpi
);
5103 case DEMANGLE_COMPONENT_TRINARY
:
5104 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5105 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5107 d_print_error (dpi
);
5111 struct demangle_component
*op
= d_left (dc
);
5112 struct demangle_component
*first
= d_left (d_right (dc
));
5113 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5114 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5116 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5118 d_print_subexpr (dpi
, options
, first
);
5119 d_print_expr_op (dpi
, options
, op
);
5120 d_print_subexpr (dpi
, options
, second
);
5121 d_append_string (dpi
, " : ");
5122 d_print_subexpr (dpi
, options
, third
);
5126 d_append_string (dpi
, "new ");
5127 if (d_left (first
) != NULL
)
5129 d_print_subexpr (dpi
, options
, first
);
5130 d_append_char (dpi
, ' ');
5132 d_print_comp (dpi
, options
, second
);
5134 d_print_subexpr (dpi
, options
, third
);
5139 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5140 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5141 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5142 d_print_error (dpi
);
5145 case DEMANGLE_COMPONENT_LITERAL
:
5146 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5148 enum d_builtin_type_print tp
;
5150 /* For some builtin types, produce simpler output. */
5151 tp
= D_PRINT_DEFAULT
;
5152 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5154 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5158 case D_PRINT_UNSIGNED
:
5160 case D_PRINT_UNSIGNED_LONG
:
5161 case D_PRINT_LONG_LONG
:
5162 case D_PRINT_UNSIGNED_LONG_LONG
:
5163 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5165 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5166 d_append_char (dpi
, '-');
5167 d_print_comp (dpi
, options
, d_right (dc
));
5172 case D_PRINT_UNSIGNED
:
5173 d_append_char (dpi
, 'u');
5176 d_append_char (dpi
, 'l');
5178 case D_PRINT_UNSIGNED_LONG
:
5179 d_append_string (dpi
, "ul");
5181 case D_PRINT_LONG_LONG
:
5182 d_append_string (dpi
, "ll");
5184 case D_PRINT_UNSIGNED_LONG_LONG
:
5185 d_append_string (dpi
, "ull");
5193 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5194 && d_right (dc
)->u
.s_name
.len
== 1
5195 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5197 switch (d_right (dc
)->u
.s_name
.s
[0])
5200 d_append_string (dpi
, "false");
5203 d_append_string (dpi
, "true");
5216 d_append_char (dpi
, '(');
5217 d_print_comp (dpi
, options
, d_left (dc
));
5218 d_append_char (dpi
, ')');
5219 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5220 d_append_char (dpi
, '-');
5221 if (tp
== D_PRINT_FLOAT
)
5222 d_append_char (dpi
, '[');
5223 d_print_comp (dpi
, options
, d_right (dc
));
5224 if (tp
== D_PRINT_FLOAT
)
5225 d_append_char (dpi
, ']');
5229 case DEMANGLE_COMPONENT_NUMBER
:
5230 d_append_num (dpi
, dc
->u
.s_number
.number
);
5233 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5234 d_append_string (dpi
, "java resource ");
5235 d_print_comp (dpi
, options
, d_left (dc
));
5238 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5239 d_print_comp (dpi
, options
, d_left (dc
));
5240 d_print_comp (dpi
, options
, d_right (dc
));
5243 case DEMANGLE_COMPONENT_CHARACTER
:
5244 d_append_char (dpi
, dc
->u
.s_character
.character
);
5247 case DEMANGLE_COMPONENT_DECLTYPE
:
5248 d_append_string (dpi
, "decltype (");
5249 d_print_comp (dpi
, options
, d_left (dc
));
5250 d_append_char (dpi
, ')');
5253 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5257 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5260 /* d_find_pack won't find anything if the only packs involved
5261 in this expansion are function parameter packs; in that
5262 case, just print the pattern and "...". */
5263 d_print_subexpr (dpi
, options
, d_left (dc
));
5264 d_append_string (dpi
, "...");
5268 len
= d_pack_length (a
);
5270 for (i
= 0; i
< len
; ++i
)
5272 dpi
->pack_index
= i
;
5273 d_print_comp (dpi
, options
, dc
);
5275 d_append_string (dpi
, ", ");
5280 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5282 long num
= dc
->u
.s_number
.number
;
5284 d_append_string (dpi
, "this");
5287 d_append_string (dpi
, "{parm#");
5288 d_append_num (dpi
, num
);
5289 d_append_char (dpi
, '}');
5294 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5295 d_append_string (dpi
, "global constructors keyed to ");
5296 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5299 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5300 d_append_string (dpi
, "global destructors keyed to ");
5301 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5304 case DEMANGLE_COMPONENT_LAMBDA
:
5305 d_append_string (dpi
, "{lambda(");
5306 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5307 d_append_string (dpi
, ")#");
5308 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5309 d_append_char (dpi
, '}');
5312 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5313 d_append_string (dpi
, "{unnamed type#");
5314 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5315 d_append_char (dpi
, '}');
5318 case DEMANGLE_COMPONENT_CLONE
:
5319 d_print_comp (dpi
, options
, d_left (dc
));
5320 d_append_string (dpi
, " [clone ");
5321 d_print_comp (dpi
, options
, d_right (dc
));
5322 d_append_char (dpi
, ']');
5326 d_print_error (dpi
);
5331 /* Print a Java dentifier. For Java we try to handle encoded extended
5332 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5333 so we don't it for C++. Characters are encoded as
5337 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5343 for (p
= name
; p
< end
; ++p
)
5354 for (q
= p
+ 3; q
< end
; ++q
)
5360 else if (*q
>= 'A' && *q
<= 'F')
5361 dig
= *q
- 'A' + 10;
5362 else if (*q
>= 'a' && *q
<= 'f')
5363 dig
= *q
- 'a' + 10;
5369 /* If the Unicode character is larger than 256, we don't try
5370 to deal with it here. FIXME. */
5371 if (q
< end
&& *q
== '_' && c
< 256)
5373 d_append_char (dpi
, c
);
5379 d_append_char (dpi
, *p
);
5383 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5384 qualifiers on this after printing a function. */
5387 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5388 struct d_print_mod
*mods
, int suffix
)
5390 struct d_print_template
*hold_dpt
;
5392 if (mods
== NULL
|| d_print_saw_error (dpi
))
5397 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5398 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5399 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5400 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5402 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5404 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5410 hold_dpt
= dpi
->templates
;
5411 dpi
->templates
= mods
->templates
;
5413 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5415 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5416 dpi
->templates
= hold_dpt
;
5419 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5421 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5422 dpi
->templates
= hold_dpt
;
5425 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5427 struct d_print_mod
*hold_modifiers
;
5428 struct demangle_component
*dc
;
5430 /* When this is on the modifier stack, we have pulled any
5431 qualifiers off the right argument already. Otherwise, we
5432 print it as usual, but don't let the left argument see any
5435 hold_modifiers
= dpi
->modifiers
;
5436 dpi
->modifiers
= NULL
;
5437 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5438 dpi
->modifiers
= hold_modifiers
;
5440 if ((options
& DMGL_JAVA
) == 0)
5441 d_append_string (dpi
, "::");
5443 d_append_char (dpi
, '.');
5445 dc
= d_right (mods
->mod
);
5447 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5449 d_append_string (dpi
, "{default arg#");
5450 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5451 d_append_string (dpi
, "}::");
5452 dc
= dc
->u
.s_unary_num
.sub
;
5455 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5456 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5457 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5458 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5459 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5462 d_print_comp (dpi
, options
, dc
);
5464 dpi
->templates
= hold_dpt
;
5468 d_print_mod (dpi
, options
, mods
->mod
);
5470 dpi
->templates
= hold_dpt
;
5472 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5475 /* Print a modifier. */
5478 d_print_mod (struct d_print_info
*dpi
, int options
,
5479 const struct demangle_component
*mod
)
5483 case DEMANGLE_COMPONENT_RESTRICT
:
5484 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5485 d_append_string (dpi
, " restrict");
5487 case DEMANGLE_COMPONENT_VOLATILE
:
5488 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5489 d_append_string (dpi
, " volatile");
5491 case DEMANGLE_COMPONENT_CONST
:
5492 case DEMANGLE_COMPONENT_CONST_THIS
:
5493 d_append_string (dpi
, " const");
5495 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5496 d_append_char (dpi
, ' ');
5497 d_print_comp (dpi
, options
, d_right (mod
));
5499 case DEMANGLE_COMPONENT_POINTER
:
5500 /* There is no pointer symbol in Java. */
5501 if ((options
& DMGL_JAVA
) == 0)
5502 d_append_char (dpi
, '*');
5504 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5505 /* For the ref-qualifier, put a space before the &. */
5506 d_append_char (dpi
, ' ');
5507 case DEMANGLE_COMPONENT_REFERENCE
:
5508 d_append_char (dpi
, '&');
5510 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5511 d_append_char (dpi
, ' ');
5512 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5513 d_append_string (dpi
, "&&");
5515 case DEMANGLE_COMPONENT_COMPLEX
:
5516 d_append_string (dpi
, "complex ");
5518 case DEMANGLE_COMPONENT_IMAGINARY
:
5519 d_append_string (dpi
, "imaginary ");
5521 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5522 if (d_last_char (dpi
) != '(')
5523 d_append_char (dpi
, ' ');
5524 d_print_comp (dpi
, options
, d_left (mod
));
5525 d_append_string (dpi
, "::*");
5527 case DEMANGLE_COMPONENT_TYPED_NAME
:
5528 d_print_comp (dpi
, options
, d_left (mod
));
5530 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5531 d_append_string (dpi
, " __vector(");
5532 d_print_comp (dpi
, options
, d_left (mod
));
5533 d_append_char (dpi
, ')');
5537 /* Otherwise, we have something that won't go back on the
5538 modifier stack, so we can just print it. */
5539 d_print_comp (dpi
, options
, mod
);
5544 /* Print a function type, except for the return type. */
5547 d_print_function_type (struct d_print_info
*dpi
, int options
,
5548 const struct demangle_component
*dc
,
5549 struct d_print_mod
*mods
)
5553 struct d_print_mod
*p
;
5554 struct d_print_mod
*hold_modifiers
;
5558 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5563 switch (p
->mod
->type
)
5565 case DEMANGLE_COMPONENT_POINTER
:
5566 case DEMANGLE_COMPONENT_REFERENCE
:
5567 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5570 case DEMANGLE_COMPONENT_RESTRICT
:
5571 case DEMANGLE_COMPONENT_VOLATILE
:
5572 case DEMANGLE_COMPONENT_CONST
:
5573 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5574 case DEMANGLE_COMPONENT_COMPLEX
:
5575 case DEMANGLE_COMPONENT_IMAGINARY
:
5576 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5580 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5581 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5582 case DEMANGLE_COMPONENT_CONST_THIS
:
5583 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5584 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5597 if (d_last_char (dpi
) != '('
5598 && d_last_char (dpi
) != '*')
5601 if (need_space
&& d_last_char (dpi
) != ' ')
5602 d_append_char (dpi
, ' ');
5603 d_append_char (dpi
, '(');
5606 hold_modifiers
= dpi
->modifiers
;
5607 dpi
->modifiers
= NULL
;
5609 d_print_mod_list (dpi
, options
, mods
, 0);
5612 d_append_char (dpi
, ')');
5614 d_append_char (dpi
, '(');
5616 if (d_right (dc
) != NULL
)
5617 d_print_comp (dpi
, options
, d_right (dc
));
5619 d_append_char (dpi
, ')');
5621 d_print_mod_list (dpi
, options
, mods
, 1);
5623 dpi
->modifiers
= hold_modifiers
;
5626 /* Print an array type, except for the element type. */
5629 d_print_array_type (struct d_print_info
*dpi
, int options
,
5630 const struct demangle_component
*dc
,
5631 struct d_print_mod
*mods
)
5639 struct d_print_mod
*p
;
5642 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5646 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5661 d_append_string (dpi
, " (");
5663 d_print_mod_list (dpi
, options
, mods
, 0);
5666 d_append_char (dpi
, ')');
5670 d_append_char (dpi
, ' ');
5672 d_append_char (dpi
, '[');
5674 if (d_left (dc
) != NULL
)
5675 d_print_comp (dpi
, options
, d_left (dc
));
5677 d_append_char (dpi
, ']');
5680 /* Print an operator in an expression. */
5683 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5684 const struct demangle_component
*dc
)
5686 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5687 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5688 dc
->u
.s_operator
.op
->len
);
5690 d_print_comp (dpi
, options
, dc
);
5696 d_print_cast (struct d_print_info
*dpi
, int options
,
5697 const struct demangle_component
*dc
)
5699 d_print_comp (dpi
, options
, d_left (dc
));
5702 /* Print a conversion operator. */
5705 d_print_conversion (struct d_print_info
*dpi
, int options
,
5706 const struct demangle_component
*dc
)
5708 struct d_print_template dpt
;
5710 /* For a conversion operator, we need the template parameters from
5711 the enclosing template in scope for processing the type. */
5712 if (dpi
->current_template
!= NULL
)
5714 dpt
.next
= dpi
->templates
;
5715 dpi
->templates
= &dpt
;
5716 dpt
.template_decl
= dpi
->current_template
;
5719 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5721 d_print_comp (dpi
, options
, d_left (dc
));
5722 if (dpi
->current_template
!= NULL
)
5723 dpi
->templates
= dpt
.next
;
5727 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5729 /* For a templated cast operator, we need to remove the template
5730 parameters from scope after printing the operator name,
5731 so we need to handle the template printing here. */
5732 if (dpi
->current_template
!= NULL
)
5733 dpi
->templates
= dpt
.next
;
5735 if (d_last_char (dpi
) == '<')
5736 d_append_char (dpi
, ' ');
5737 d_append_char (dpi
, '<');
5738 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5739 /* Avoid generating two consecutive '>' characters, to avoid
5740 the C++ syntactic ambiguity. */
5741 if (d_last_char (dpi
) == '>')
5742 d_append_char (dpi
, ' ');
5743 d_append_char (dpi
, '>');
5747 /* Initialize the information structure we use to pass around
5750 CP_STATIC_IF_GLIBCPP_V3
5752 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5756 di
->send
= mangled
+ len
;
5757 di
->options
= options
;
5761 /* We can not need more components than twice the number of chars in
5762 the mangled string. Most components correspond directly to
5763 chars, but the ARGLIST types are exceptions. */
5764 di
->num_comps
= 2 * len
;
5767 /* Similarly, we can not need more substitutions than there are
5768 chars in the mangled string. */
5773 di
->last_name
= NULL
;
5776 di
->is_expression
= 0;
5777 di
->is_conversion
= 0;
5780 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5781 mangled name, return strings in repeated callback giving the demangled
5782 name. OPTIONS is the usual libiberty demangler options. On success,
5783 this returns 1. On failure, returns 0. */
5786 d_demangle_callback (const char *mangled
, int options
,
5787 demangle_callbackref callback
, void *opaque
)
5798 struct demangle_component
*dc
;
5801 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5803 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5804 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5805 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5806 && mangled
[10] == '_')
5807 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5810 if ((options
& DMGL_TYPES
) == 0)
5815 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5818 #ifdef CP_DYNAMIC_ARRAYS
5819 __extension__
struct demangle_component comps
[di
.num_comps
];
5820 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5825 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5826 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5832 dc
= cplus_demangle_type (&di
);
5835 dc
= cplus_demangle_mangled_name (&di
, 1);
5837 case DCT_GLOBAL_CTORS
:
5838 case DCT_GLOBAL_DTORS
:
5839 d_advance (&di
, 11);
5840 dc
= d_make_comp (&di
,
5841 (type
== DCT_GLOBAL_CTORS
5842 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5843 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5844 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5846 d_advance (&di
, strlen (d_str (&di
)));
5849 abort (); /* We have listed all the cases. */
5852 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5853 mangled string, then we didn't successfully demangle it. If
5854 DMGL_PARAMS is not set, we didn't look at the trailing
5856 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5859 #ifdef CP_DEMANGLE_DEBUG
5863 status
= (dc
!= NULL
)
5864 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
5871 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
5872 name, return a buffer allocated with malloc holding the demangled
5873 name. OPTIONS is the usual libiberty demangler options. On
5874 success, this sets *PALC to the allocated size of the returned
5875 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
5876 a memory allocation failure, and returns NULL. */
5879 d_demangle (const char *mangled
, int options
, size_t *palc
)
5881 struct d_growable_string dgs
;
5884 d_growable_string_init (&dgs
, 0);
5886 status
= d_demangle_callback (mangled
, options
,
5887 d_growable_string_callback_adapter
, &dgs
);
5895 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
5899 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5901 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5903 /* ia64 ABI-mandated entry point in the C++ runtime library for
5904 performing demangling. MANGLED_NAME is a NUL-terminated character
5905 string containing the name to be demangled.
5907 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5908 *LENGTH bytes, into which the demangled name is stored. If
5909 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5910 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5911 is placed in a region of memory allocated with malloc.
5913 If LENGTH is non-NULL, the length of the buffer containing the
5914 demangled name, is placed in *LENGTH.
5916 The return value is a pointer to the start of the NUL-terminated
5917 demangled name, or NULL if the demangling fails. The caller is
5918 responsible for deallocating this memory using free.
5920 *STATUS is set to one of the following values:
5921 0: The demangling operation succeeded.
5922 -1: A memory allocation failure occurred.
5923 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5924 -3: One of the arguments is invalid.
5926 The demangling is performed using the C++ ABI mangling rules, with
5930 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
5931 size_t *length
, int *status
)
5936 if (mangled_name
== NULL
)
5943 if (output_buffer
!= NULL
&& length
== NULL
)
5950 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
5952 if (demangled
== NULL
)
5964 if (output_buffer
== NULL
)
5971 if (strlen (demangled
) < *length
)
5973 strcpy (output_buffer
, demangled
);
5975 demangled
= output_buffer
;
5979 free (output_buffer
);
5990 extern int __gcclibcxx_demangle_callback (const char *,
5992 (const char *, size_t, void *),
5995 /* Alternative, allocationless entry point in the C++ runtime library
5996 for performing demangling. MANGLED_NAME is a NUL-terminated character
5997 string containing the name to be demangled.
5999 CALLBACK is a callback function, called with demangled string
6000 segments as demangling progresses; it is called at least once,
6001 but may be called more than once. OPAQUE is a generalized pointer
6002 used as a callback argument.
6004 The return code is one of the following values, equivalent to
6005 the STATUS values of __cxa_demangle() (excluding -1, since this
6006 function performs no memory allocations):
6007 0: The demangling operation succeeded.
6008 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6009 -3: One of the arguments is invalid.
6011 The demangling is performed using the C++ ABI mangling rules, with
6015 __gcclibcxx_demangle_callback (const char *mangled_name
,
6016 void (*callback
) (const char *, size_t, void *),
6021 if (mangled_name
== NULL
|| callback
== NULL
)
6024 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6032 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6034 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6035 mangled name, return a buffer allocated with malloc holding the
6036 demangled name. Otherwise, return NULL. */
6039 cplus_demangle_v3 (const char *mangled
, int options
)
6043 return d_demangle (mangled
, options
, &alc
);
6047 cplus_demangle_v3_callback (const char *mangled
, int options
,
6048 demangle_callbackref callback
, void *opaque
)
6050 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6053 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6054 conventions, but the output formatting is a little different.
6055 This instructs the C++ demangler not to emit pointer characters ("*"), to
6056 use Java's namespace separator symbol ("." instead of "::"), and to output
6057 JArray<TYPE> as TYPE[]. */
6060 java_demangle_v3 (const char *mangled
)
6064 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6068 java_demangle_v3_callback (const char *mangled
,
6069 demangle_callbackref callback
, void *opaque
)
6071 return d_demangle_callback (mangled
,
6072 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6076 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6078 #ifndef IN_GLIBCPP_V3
6080 /* Demangle a string in order to find out whether it is a constructor
6081 or destructor. Return non-zero on success. Set *CTOR_KIND and
6082 *DTOR_KIND appropriately. */
6085 is_ctor_or_dtor (const char *mangled
,
6086 enum gnu_v3_ctor_kinds
*ctor_kind
,
6087 enum gnu_v3_dtor_kinds
*dtor_kind
)
6090 struct demangle_component
*dc
;
6093 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6094 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6096 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6099 #ifdef CP_DYNAMIC_ARRAYS
6100 __extension__
struct demangle_component comps
[di
.num_comps
];
6101 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6106 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6107 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6110 dc
= cplus_demangle_mangled_name (&di
, 1);
6112 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6113 to demangle the entire string. */
6120 /* These cannot appear on a constructor or destructor. */
6121 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6122 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6123 case DEMANGLE_COMPONENT_CONST_THIS
:
6124 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6125 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6129 case DEMANGLE_COMPONENT_TYPED_NAME
:
6130 case DEMANGLE_COMPONENT_TEMPLATE
:
6133 case DEMANGLE_COMPONENT_QUAL_NAME
:
6134 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6137 case DEMANGLE_COMPONENT_CTOR
:
6138 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6142 case DEMANGLE_COMPONENT_DTOR
:
6143 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6154 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6155 name. A non-zero return indicates the type of constructor. */
6157 enum gnu_v3_ctor_kinds
6158 is_gnu_v3_mangled_ctor (const char *name
)
6160 enum gnu_v3_ctor_kinds ctor_kind
;
6161 enum gnu_v3_dtor_kinds dtor_kind
;
6163 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6164 return (enum gnu_v3_ctor_kinds
) 0;
6169 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6170 name. A non-zero return indicates the type of destructor. */
6172 enum gnu_v3_dtor_kinds
6173 is_gnu_v3_mangled_dtor (const char *name
)
6175 enum gnu_v3_ctor_kinds ctor_kind
;
6176 enum gnu_v3_dtor_kinds dtor_kind
;
6178 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6179 return (enum gnu_v3_dtor_kinds
) 0;
6183 #endif /* IN_GLIBCPP_V3 */
6185 #ifdef STANDALONE_DEMANGLER
6188 #include "dyn-string.h"
6190 static void print_usage (FILE* fp
, int exit_value
);
6192 #define IS_ALPHA(CHAR) \
6193 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6194 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6196 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6197 #define is_mangled_char(CHAR) \
6198 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6199 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6201 /* The name of this program, as invoked. */
6202 const char* program_name
;
6204 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6207 print_usage (FILE* fp
, int exit_value
)
6209 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6210 fprintf (fp
, "Options:\n");
6211 fprintf (fp
, " -h,--help Display this message.\n");
6212 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6213 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6214 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6219 /* Option specification for getopt_long. */
6220 static const struct option long_options
[] =
6222 { "help", no_argument
, NULL
, 'h' },
6223 { "no-params", no_argument
, NULL
, 'p' },
6224 { "verbose", no_argument
, NULL
, 'v' },
6225 { NULL
, no_argument
, NULL
, 0 },
6228 /* Main entry for a demangling filter executable. It will demangle
6229 its command line arguments, if any. If none are provided, it will
6230 filter stdin to stdout, replacing any recognized mangled C++ names
6231 with their demangled equivalents. */
6234 main (int argc
, char *argv
[])
6238 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6240 /* Use the program name of this program, as invoked. */
6241 program_name
= argv
[0];
6243 /* Parse options. */
6246 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6249 case '?': /* Unrecognized option. */
6250 print_usage (stderr
, 1);
6254 print_usage (stdout
, 0);
6258 options
&= ~ DMGL_PARAMS
;
6262 options
|= DMGL_VERBOSE
;
6266 while (opt_char
!= -1);
6269 /* No command line arguments were provided. Filter stdin. */
6271 dyn_string_t mangled
= dyn_string_new (3);
6274 /* Read all of input. */
6275 while (!feof (stdin
))
6279 /* Pile characters into mangled until we hit one that can't
6280 occur in a mangled name. */
6282 while (!feof (stdin
) && is_mangled_char (c
))
6284 dyn_string_append_char (mangled
, c
);
6290 if (dyn_string_length (mangled
) > 0)
6292 #ifdef IN_GLIBCPP_V3
6293 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6295 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6305 /* It might not have been a mangled name. Print the
6307 fputs (dyn_string_buf (mangled
), stdout
);
6310 dyn_string_clear (mangled
);
6313 /* If we haven't hit EOF yet, we've read one character that
6314 can't occur in a mangled name, so print it out. */
6319 dyn_string_delete (mangled
);
6322 /* Demangle command line arguments. */
6324 /* Loop over command line arguments. */
6325 for (i
= optind
; i
< argc
; ++i
)
6328 #ifdef IN_GLIBCPP_V3
6332 /* Attempt to demangle. */
6333 #ifdef IN_GLIBCPP_V3
6334 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6336 s
= cplus_demangle_v3 (argv
[i
], options
);
6339 /* If it worked, print the demangled name. */
6347 #ifdef IN_GLIBCPP_V3
6348 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6350 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6359 #endif /* STANDALONE_DEMANGLER */