1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 enum { D_PRINT_BUFFER_LENGTH
= 256 };
281 /* Fixed-length allocated buffer for demangled data, flushed to the
282 callback with a NUL termination once full. */
283 char buf
[D_PRINT_BUFFER_LENGTH
];
284 /* Current length of data in buffer. */
286 /* The last character printed, saved individually so that it survives
289 /* Callback function to handle demangled buffer flush. */
290 demangle_callbackref callback
;
291 /* Opaque callback argument. */
293 /* The current list of templates, if any. */
294 struct d_print_template
*templates
;
295 /* The current list of modifiers (e.g., pointer, reference, etc.),
297 struct d_print_mod
*modifiers
;
298 /* Set to 1 if we saw a demangling error. */
299 int demangle_failure
;
300 /* The current index into any template argument packs we are using
303 /* Number of d_print_flush calls so far. */
304 unsigned long int flush_count
;
307 #ifdef CP_DEMANGLE_DEBUG
308 static void d_dump (struct demangle_component
*, int);
311 static struct demangle_component
*
312 d_make_empty (struct d_info
*);
314 static struct demangle_component
*
315 d_make_comp (struct d_info
*, enum demangle_component_type
,
316 struct demangle_component
*,
317 struct demangle_component
*);
319 static struct demangle_component
*
320 d_make_name (struct d_info
*, const char *, int);
322 static struct demangle_component
*
323 d_make_demangle_mangled_name (struct d_info
*, const char *);
325 static struct demangle_component
*
326 d_make_builtin_type (struct d_info
*,
327 const struct demangle_builtin_type_info
*);
329 static struct demangle_component
*
330 d_make_operator (struct d_info
*,
331 const struct demangle_operator_info
*);
333 static struct demangle_component
*
334 d_make_extended_operator (struct d_info
*, int,
335 struct demangle_component
*);
337 static struct demangle_component
*
338 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
339 struct demangle_component
*);
341 static struct demangle_component
*
342 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
343 struct demangle_component
*);
345 static struct demangle_component
*
346 d_make_template_param (struct d_info
*, long);
348 static struct demangle_component
*
349 d_make_sub (struct d_info
*, const char *, int);
352 has_return_type (struct demangle_component
*);
355 is_ctor_dtor_or_conversion (struct demangle_component
*);
357 static struct demangle_component
*d_encoding (struct d_info
*, int);
359 static struct demangle_component
*d_name (struct d_info
*);
361 static struct demangle_component
*d_nested_name (struct d_info
*);
363 static struct demangle_component
*d_prefix (struct d_info
*);
365 static struct demangle_component
*d_unqualified_name (struct d_info
*);
367 static struct demangle_component
*d_source_name (struct d_info
*);
369 static long d_number (struct d_info
*);
371 static struct demangle_component
*d_identifier (struct d_info
*, int);
373 static struct demangle_component
*d_operator_name (struct d_info
*);
375 static struct demangle_component
*d_special_name (struct d_info
*);
377 static int d_call_offset (struct d_info
*, int);
379 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
381 static struct demangle_component
**
382 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
384 static struct demangle_component
*
385 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
387 static struct demangle_component
*
388 d_function_type (struct d_info
*);
390 static struct demangle_component
*
391 d_bare_function_type (struct d_info
*, int);
393 static struct demangle_component
*
394 d_class_enum_type (struct d_info
*);
396 static struct demangle_component
*d_array_type (struct d_info
*);
398 static struct demangle_component
*d_vector_type (struct d_info
*);
400 static struct demangle_component
*
401 d_pointer_to_member_type (struct d_info
*);
403 static struct demangle_component
*
404 d_template_param (struct d_info
*);
406 static struct demangle_component
*d_template_args (struct d_info
*);
408 static struct demangle_component
*
409 d_template_arg (struct d_info
*);
411 static struct demangle_component
*d_expression (struct d_info
*);
413 static struct demangle_component
*d_expr_primary (struct d_info
*);
415 static struct demangle_component
*d_local_name (struct d_info
*);
417 static int d_discriminator (struct d_info
*);
419 static struct demangle_component
*d_lambda (struct d_info
*);
421 static struct demangle_component
*d_unnamed_type (struct d_info
*);
423 static struct demangle_component
*
424 d_clone_suffix (struct d_info
*, struct demangle_component
*);
427 d_add_substitution (struct d_info
*, struct demangle_component
*);
429 static struct demangle_component
*d_substitution (struct d_info
*, int);
431 static void d_growable_string_init (struct d_growable_string
*, size_t);
434 d_growable_string_resize (struct d_growable_string
*, size_t);
437 d_growable_string_append_buffer (struct d_growable_string
*,
438 const char *, size_t);
440 d_growable_string_callback_adapter (const char *, size_t, void *);
443 d_print_init (struct d_print_info
*, demangle_callbackref
, void *);
445 static inline void d_print_error (struct d_print_info
*);
447 static inline int d_print_saw_error (struct d_print_info
*);
449 static inline void d_print_flush (struct d_print_info
*);
451 static inline void d_append_char (struct d_print_info
*, char);
453 static inline void d_append_buffer (struct d_print_info
*,
454 const char *, size_t);
456 static inline void d_append_string (struct d_print_info
*, const char *);
458 static inline char d_last_char (struct d_print_info
*);
461 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
464 d_print_java_identifier (struct d_print_info
*, const char *, int);
467 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
470 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
473 d_print_function_type (struct d_print_info
*, int,
474 const struct demangle_component
*,
475 struct d_print_mod
*);
478 d_print_array_type (struct d_print_info
*, int,
479 const struct demangle_component
*,
480 struct d_print_mod
*);
483 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
486 d_print_cast (struct d_print_info
*, int, const struct demangle_component
*);
488 static int d_demangle_callback (const char *, int,
489 demangle_callbackref
, void *);
490 static char *d_demangle (const char *, int, size_t *);
492 #ifdef CP_DEMANGLE_DEBUG
495 d_dump (struct demangle_component
*dc
, int indent
)
502 printf ("failed demangling\n");
506 for (i
= 0; i
< indent
; ++i
)
511 case DEMANGLE_COMPONENT_NAME
:
512 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
514 case DEMANGLE_COMPONENT_TAGGED_NAME
:
515 printf ("tagged name\n");
516 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
517 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
519 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
520 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
522 case DEMANGLE_COMPONENT_CTOR
:
523 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
524 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
526 case DEMANGLE_COMPONENT_DTOR
:
527 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
528 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
530 case DEMANGLE_COMPONENT_SUB_STD
:
531 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
533 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
534 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
536 case DEMANGLE_COMPONENT_OPERATOR
:
537 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
539 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
540 printf ("extended operator with %d args\n",
541 dc
->u
.s_extended_operator
.args
);
542 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
545 case DEMANGLE_COMPONENT_QUAL_NAME
:
546 printf ("qualified name\n");
548 case DEMANGLE_COMPONENT_LOCAL_NAME
:
549 printf ("local name\n");
551 case DEMANGLE_COMPONENT_TYPED_NAME
:
552 printf ("typed name\n");
554 case DEMANGLE_COMPONENT_TEMPLATE
:
555 printf ("template\n");
557 case DEMANGLE_COMPONENT_VTABLE
:
560 case DEMANGLE_COMPONENT_VTT
:
563 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
564 printf ("construction vtable\n");
566 case DEMANGLE_COMPONENT_TYPEINFO
:
567 printf ("typeinfo\n");
569 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
570 printf ("typeinfo name\n");
572 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
573 printf ("typeinfo function\n");
575 case DEMANGLE_COMPONENT_THUNK
:
578 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
579 printf ("virtual thunk\n");
581 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
582 printf ("covariant thunk\n");
584 case DEMANGLE_COMPONENT_JAVA_CLASS
:
585 printf ("java class\n");
587 case DEMANGLE_COMPONENT_GUARD
:
590 case DEMANGLE_COMPONENT_REFTEMP
:
591 printf ("reference temporary\n");
593 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
594 printf ("hidden alias\n");
596 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
597 printf ("transaction clone\n");
599 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
600 printf ("non-transaction clone\n");
602 case DEMANGLE_COMPONENT_RESTRICT
:
603 printf ("restrict\n");
605 case DEMANGLE_COMPONENT_VOLATILE
:
606 printf ("volatile\n");
608 case DEMANGLE_COMPONENT_CONST
:
611 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
612 printf ("restrict this\n");
614 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
615 printf ("volatile this\n");
617 case DEMANGLE_COMPONENT_CONST_THIS
:
618 printf ("const this\n");
620 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
621 printf ("reference this\n");
623 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
624 printf ("rvalue reference this\n");
626 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
627 printf ("vendor type qualifier\n");
629 case DEMANGLE_COMPONENT_POINTER
:
630 printf ("pointer\n");
632 case DEMANGLE_COMPONENT_REFERENCE
:
633 printf ("reference\n");
635 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
636 printf ("rvalue reference\n");
638 case DEMANGLE_COMPONENT_COMPLEX
:
639 printf ("complex\n");
641 case DEMANGLE_COMPONENT_IMAGINARY
:
642 printf ("imaginary\n");
644 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
645 printf ("vendor type\n");
647 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
648 printf ("function type\n");
650 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
651 printf ("array type\n");
653 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
654 printf ("pointer to member type\n");
656 case DEMANGLE_COMPONENT_FIXED_TYPE
:
657 printf ("fixed-point type\n");
659 case DEMANGLE_COMPONENT_ARGLIST
:
660 printf ("argument list\n");
662 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
663 printf ("template argument list\n");
665 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
666 printf ("initializer list\n");
668 case DEMANGLE_COMPONENT_CAST
:
671 case DEMANGLE_COMPONENT_NULLARY
:
672 printf ("nullary operator\n");
674 case DEMANGLE_COMPONENT_UNARY
:
675 printf ("unary operator\n");
677 case DEMANGLE_COMPONENT_BINARY
:
678 printf ("binary operator\n");
680 case DEMANGLE_COMPONENT_BINARY_ARGS
:
681 printf ("binary operator arguments\n");
683 case DEMANGLE_COMPONENT_TRINARY
:
684 printf ("trinary operator\n");
686 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
687 printf ("trinary operator arguments 1\n");
689 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
690 printf ("trinary operator arguments 1\n");
692 case DEMANGLE_COMPONENT_LITERAL
:
693 printf ("literal\n");
695 case DEMANGLE_COMPONENT_LITERAL_NEG
:
696 printf ("negative literal\n");
698 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
699 printf ("java resource\n");
701 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
702 printf ("compound name\n");
704 case DEMANGLE_COMPONENT_CHARACTER
:
705 printf ("character '%c'\n", dc
->u
.s_character
.character
);
707 case DEMANGLE_COMPONENT_DECLTYPE
:
708 printf ("decltype\n");
710 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
711 printf ("pack expansion\n");
713 case DEMANGLE_COMPONENT_TLS_INIT
:
714 printf ("tls init function\n");
716 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
717 printf ("tls wrapper function\n");
719 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
720 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
721 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
723 case DEMANGLE_COMPONENT_LAMBDA
:
724 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
725 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
729 d_dump (d_left (dc
), indent
+ 2);
730 d_dump (d_right (dc
), indent
+ 2);
733 #endif /* CP_DEMANGLE_DEBUG */
735 /* Fill in a DEMANGLE_COMPONENT_NAME. */
737 CP_STATIC_IF_GLIBCPP_V3
739 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
741 if (p
== NULL
|| s
== NULL
|| len
== 0)
743 p
->type
= DEMANGLE_COMPONENT_NAME
;
745 p
->u
.s_name
.len
= len
;
749 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
751 CP_STATIC_IF_GLIBCPP_V3
753 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
754 struct demangle_component
*name
)
756 if (p
== NULL
|| args
< 0 || name
== NULL
)
758 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
759 p
->u
.s_extended_operator
.args
= args
;
760 p
->u
.s_extended_operator
.name
= name
;
764 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
766 CP_STATIC_IF_GLIBCPP_V3
768 cplus_demangle_fill_ctor (struct demangle_component
*p
,
769 enum gnu_v3_ctor_kinds kind
,
770 struct demangle_component
*name
)
774 || (int) kind
< gnu_v3_complete_object_ctor
775 || (int) kind
> gnu_v3_object_ctor_group
)
777 p
->type
= DEMANGLE_COMPONENT_CTOR
;
778 p
->u
.s_ctor
.kind
= kind
;
779 p
->u
.s_ctor
.name
= name
;
783 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
785 CP_STATIC_IF_GLIBCPP_V3
787 cplus_demangle_fill_dtor (struct demangle_component
*p
,
788 enum gnu_v3_dtor_kinds kind
,
789 struct demangle_component
*name
)
793 || (int) kind
< gnu_v3_deleting_dtor
794 || (int) kind
> gnu_v3_object_dtor_group
)
796 p
->type
= DEMANGLE_COMPONENT_DTOR
;
797 p
->u
.s_dtor
.kind
= kind
;
798 p
->u
.s_dtor
.name
= name
;
802 /* Add a new component. */
804 static struct demangle_component
*
805 d_make_empty (struct d_info
*di
)
807 struct demangle_component
*p
;
809 if (di
->next_comp
>= di
->num_comps
)
811 p
= &di
->comps
[di
->next_comp
];
816 /* Add a new generic component. */
818 static struct demangle_component
*
819 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
820 struct demangle_component
*left
,
821 struct demangle_component
*right
)
823 struct demangle_component
*p
;
825 /* We check for errors here. A typical error would be a NULL return
826 from a subroutine. We catch those here, and return NULL
830 /* These types require two parameters. */
831 case DEMANGLE_COMPONENT_QUAL_NAME
:
832 case DEMANGLE_COMPONENT_LOCAL_NAME
:
833 case DEMANGLE_COMPONENT_TYPED_NAME
:
834 case DEMANGLE_COMPONENT_TAGGED_NAME
:
835 case DEMANGLE_COMPONENT_TEMPLATE
:
836 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
837 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
838 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
839 case DEMANGLE_COMPONENT_UNARY
:
840 case DEMANGLE_COMPONENT_BINARY
:
841 case DEMANGLE_COMPONENT_BINARY_ARGS
:
842 case DEMANGLE_COMPONENT_TRINARY
:
843 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
844 case DEMANGLE_COMPONENT_LITERAL
:
845 case DEMANGLE_COMPONENT_LITERAL_NEG
:
846 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
847 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
848 case DEMANGLE_COMPONENT_CLONE
:
849 if (left
== NULL
|| right
== NULL
)
853 /* These types only require one parameter. */
854 case DEMANGLE_COMPONENT_VTABLE
:
855 case DEMANGLE_COMPONENT_VTT
:
856 case DEMANGLE_COMPONENT_TYPEINFO
:
857 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
858 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
859 case DEMANGLE_COMPONENT_THUNK
:
860 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
861 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
862 case DEMANGLE_COMPONENT_JAVA_CLASS
:
863 case DEMANGLE_COMPONENT_GUARD
:
864 case DEMANGLE_COMPONENT_TLS_INIT
:
865 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
866 case DEMANGLE_COMPONENT_REFTEMP
:
867 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
868 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
869 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
870 case DEMANGLE_COMPONENT_POINTER
:
871 case DEMANGLE_COMPONENT_REFERENCE
:
872 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
873 case DEMANGLE_COMPONENT_COMPLEX
:
874 case DEMANGLE_COMPONENT_IMAGINARY
:
875 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
876 case DEMANGLE_COMPONENT_CAST
:
877 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
878 case DEMANGLE_COMPONENT_DECLTYPE
:
879 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
880 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
881 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
882 case DEMANGLE_COMPONENT_NULLARY
:
883 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
888 /* This needs a right parameter, but the left parameter can be
890 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
891 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
896 /* These are allowed to have no parameters--in some cases they
897 will be filled in later. */
898 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
899 case DEMANGLE_COMPONENT_RESTRICT
:
900 case DEMANGLE_COMPONENT_VOLATILE
:
901 case DEMANGLE_COMPONENT_CONST
:
902 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
903 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
904 case DEMANGLE_COMPONENT_CONST_THIS
:
905 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
906 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
907 case DEMANGLE_COMPONENT_ARGLIST
:
908 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
911 /* Other types should not be seen here. */
916 p
= d_make_empty (di
);
920 p
->u
.s_binary
.left
= left
;
921 p
->u
.s_binary
.right
= right
;
926 /* Add a new demangle mangled name component. */
928 static struct demangle_component
*
929 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
931 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
932 return d_make_name (di
, s
, strlen (s
));
934 return d_encoding (di
, 0);
937 /* Add a new name component. */
939 static struct demangle_component
*
940 d_make_name (struct d_info
*di
, const char *s
, int len
)
942 struct demangle_component
*p
;
944 p
= d_make_empty (di
);
945 if (! cplus_demangle_fill_name (p
, s
, len
))
950 /* Add a new builtin type component. */
952 static struct demangle_component
*
953 d_make_builtin_type (struct d_info
*di
,
954 const struct demangle_builtin_type_info
*type
)
956 struct demangle_component
*p
;
960 p
= d_make_empty (di
);
963 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
964 p
->u
.s_builtin
.type
= type
;
969 /* Add a new operator component. */
971 static struct demangle_component
*
972 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
974 struct demangle_component
*p
;
976 p
= d_make_empty (di
);
979 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
980 p
->u
.s_operator
.op
= op
;
985 /* Add a new extended operator component. */
987 static struct demangle_component
*
988 d_make_extended_operator (struct d_info
*di
, int args
,
989 struct demangle_component
*name
)
991 struct demangle_component
*p
;
993 p
= d_make_empty (di
);
994 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
999 static struct demangle_component
*
1000 d_make_default_arg (struct d_info
*di
, int num
,
1001 struct demangle_component
*sub
)
1003 struct demangle_component
*p
= d_make_empty (di
);
1006 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1007 p
->u
.s_unary_num
.num
= num
;
1008 p
->u
.s_unary_num
.sub
= sub
;
1013 /* Add a new constructor component. */
1015 static struct demangle_component
*
1016 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1017 struct demangle_component
*name
)
1019 struct demangle_component
*p
;
1021 p
= d_make_empty (di
);
1022 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1027 /* Add a new destructor component. */
1029 static struct demangle_component
*
1030 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1031 struct demangle_component
*name
)
1033 struct demangle_component
*p
;
1035 p
= d_make_empty (di
);
1036 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1041 /* Add a new template parameter. */
1043 static struct demangle_component
*
1044 d_make_template_param (struct d_info
*di
, long i
)
1046 struct demangle_component
*p
;
1048 p
= d_make_empty (di
);
1051 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1052 p
->u
.s_number
.number
= i
;
1057 /* Add a new function parameter. */
1059 static struct demangle_component
*
1060 d_make_function_param (struct d_info
*di
, long i
)
1062 struct demangle_component
*p
;
1064 p
= d_make_empty (di
);
1067 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1068 p
->u
.s_number
.number
= i
;
1073 /* Add a new standard substitution component. */
1075 static struct demangle_component
*
1076 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1078 struct demangle_component
*p
;
1080 p
= d_make_empty (di
);
1083 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1084 p
->u
.s_string
.string
= name
;
1085 p
->u
.s_string
.len
= len
;
1090 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1092 TOP_LEVEL is non-zero when called at the top level. */
1094 CP_STATIC_IF_GLIBCPP_V3
1095 struct demangle_component
*
1096 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1098 struct demangle_component
*p
;
1100 if (! d_check_char (di
, '_')
1101 /* Allow missing _ if not at toplevel to work around a
1102 bug in G++ abi-version=2 mangling; see the comment in
1103 write_template_arg. */
1106 if (! d_check_char (di
, 'Z'))
1108 p
= d_encoding (di
, top_level
);
1110 /* If at top level and parsing parameters, check for a clone
1112 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1113 while (d_peek_char (di
) == '.'
1114 && (IS_LOWER (d_peek_next_char (di
))
1115 || d_peek_next_char (di
) == '_'
1116 || IS_DIGIT (d_peek_next_char (di
))))
1117 p
= d_clone_suffix (di
, p
);
1122 /* Return whether a function should have a return type. The argument
1123 is the function name, which may be qualified in various ways. The
1124 rules are that template functions have return types with some
1125 exceptions, function types which are not part of a function name
1126 mangling have return types with some exceptions, and non-template
1127 function names do not have return types. The exceptions are that
1128 constructors, destructors, and conversion operators do not have
1132 has_return_type (struct demangle_component
*dc
)
1140 case DEMANGLE_COMPONENT_TEMPLATE
:
1141 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1142 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1143 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1144 case DEMANGLE_COMPONENT_CONST_THIS
:
1145 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1146 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1147 return has_return_type (d_left (dc
));
1151 /* Return whether a name is a constructor, a destructor, or a
1152 conversion operator. */
1155 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1163 case DEMANGLE_COMPONENT_QUAL_NAME
:
1164 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1165 return is_ctor_dtor_or_conversion (d_right (dc
));
1166 case DEMANGLE_COMPONENT_CTOR
:
1167 case DEMANGLE_COMPONENT_DTOR
:
1168 case DEMANGLE_COMPONENT_CAST
:
1173 /* <encoding> ::= <(function) name> <bare-function-type>
1177 TOP_LEVEL is non-zero when called at the top level, in which case
1178 if DMGL_PARAMS is not set we do not demangle the function
1179 parameters. We only set this at the top level, because otherwise
1180 we would not correctly demangle names in local scopes. */
1182 static struct demangle_component
*
1183 d_encoding (struct d_info
*di
, int top_level
)
1185 char peek
= d_peek_char (di
);
1187 if (peek
== 'G' || peek
== 'T')
1188 return d_special_name (di
);
1191 struct demangle_component
*dc
;
1195 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1197 /* Strip off any initial CV-qualifiers, as they really apply
1198 to the `this' parameter, and they were not output by the
1199 v2 demangler without DMGL_PARAMS. */
1200 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1201 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1202 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1203 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1204 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1207 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1208 there may be CV-qualifiers on its right argument which
1209 really apply here; this happens when parsing a class
1210 which is local to a function. */
1211 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1213 struct demangle_component
*dcr
;
1216 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1217 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1218 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1219 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1220 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1222 dc
->u
.s_binary
.right
= dcr
;
1228 peek
= d_peek_char (di
);
1229 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1231 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1232 d_bare_function_type (di
, has_return_type (dc
)));
1236 /* <tagged-name> ::= <name> B <source-name> */
1238 static struct demangle_component
*
1239 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1242 while (peek
= d_peek_char (di
),
1245 struct demangle_component
*tag
;
1247 tag
= d_source_name (di
);
1248 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1253 /* <name> ::= <nested-name>
1255 ::= <unscoped-template-name> <template-args>
1258 <unscoped-name> ::= <unqualified-name>
1259 ::= St <unqualified-name>
1261 <unscoped-template-name> ::= <unscoped-name>
1265 static struct demangle_component
*
1266 d_name (struct d_info
*di
)
1268 char peek
= d_peek_char (di
);
1269 struct demangle_component
*dc
;
1274 return d_nested_name (di
);
1277 return d_local_name (di
);
1281 return d_unqualified_name (di
);
1287 if (d_peek_next_char (di
) != 't')
1289 dc
= d_substitution (di
, 0);
1295 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1296 d_make_name (di
, "std", 3),
1297 d_unqualified_name (di
));
1302 if (d_peek_char (di
) != 'I')
1304 /* The grammar does not permit this case to occur if we
1305 called d_substitution() above (i.e., subst == 1). We
1306 don't bother to check. */
1310 /* This is <template-args>, which means that we just saw
1311 <unscoped-template-name>, which is a substitution
1312 candidate if we didn't just get it from a
1316 if (! d_add_substitution (di
, dc
))
1319 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1320 d_template_args (di
));
1327 dc
= d_unqualified_name (di
);
1328 if (d_peek_char (di
) == 'I')
1330 /* This is <template-args>, which means that we just saw
1331 <unscoped-template-name>, which is a substitution
1333 if (! d_add_substitution (di
, dc
))
1335 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1336 d_template_args (di
));
1342 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1343 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1346 static struct demangle_component
*
1347 d_nested_name (struct d_info
*di
)
1349 struct demangle_component
*ret
;
1350 struct demangle_component
**pret
;
1351 struct demangle_component
*rqual
;
1353 if (! d_check_char (di
, 'N'))
1356 pret
= d_cv_qualifiers (di
, &ret
, 1);
1360 /* Parse the ref-qualifier now and then attach it
1361 once we have something to attach it to. */
1362 rqual
= d_ref_qualifier (di
, NULL
);
1364 *pret
= d_prefix (di
);
1370 d_left (rqual
) = ret
;
1374 if (! d_check_char (di
, 'E'))
1380 /* <prefix> ::= <prefix> <unqualified-name>
1381 ::= <template-prefix> <template-args>
1382 ::= <template-param>
1387 <template-prefix> ::= <prefix> <(template) unqualified-name>
1388 ::= <template-param>
1392 static struct demangle_component
*
1393 d_prefix (struct d_info
*di
)
1395 struct demangle_component
*ret
= NULL
;
1400 enum demangle_component_type comb_type
;
1401 struct demangle_component
*dc
;
1403 peek
= d_peek_char (di
);
1407 /* The older code accepts a <local-name> here, but I don't see
1408 that in the grammar. The older code does not accept a
1409 <template-param> here. */
1411 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1414 char peek2
= d_peek_next_char (di
);
1415 if (peek2
== 'T' || peek2
== 't')
1417 dc
= cplus_demangle_type (di
);
1419 /* Destructor name. */
1420 dc
= d_unqualified_name (di
);
1422 else if (IS_DIGIT (peek
)
1427 dc
= d_unqualified_name (di
);
1428 else if (peek
== 'S')
1429 dc
= d_substitution (di
, 1);
1430 else if (peek
== 'I')
1434 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1435 dc
= d_template_args (di
);
1437 else if (peek
== 'T')
1438 dc
= d_template_param (di
);
1439 else if (peek
== 'E')
1441 else if (peek
== 'M')
1443 /* Initializer scope for a lambda. We don't need to represent
1444 this; the normal code will just treat the variable as a type
1445 scope, which gives appropriate output. */
1457 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1459 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1461 if (! d_add_substitution (di
, ret
))
1467 /* <unqualified-name> ::= <operator-name>
1468 ::= <ctor-dtor-name>
1470 ::= <local-source-name>
1472 <local-source-name> ::= L <source-name> <discriminator>
1475 static struct demangle_component
*
1476 d_unqualified_name (struct d_info
*di
)
1478 struct demangle_component
*ret
;
1481 peek
= d_peek_char (di
);
1482 if (IS_DIGIT (peek
))
1483 ret
= d_source_name (di
);
1484 else if (IS_LOWER (peek
))
1486 ret
= d_operator_name (di
);
1487 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1489 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1490 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1491 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1492 d_source_name (di
));
1495 else if (peek
== 'C' || peek
== 'D')
1496 ret
= d_ctor_dtor_name (di
);
1497 else if (peek
== 'L')
1501 ret
= d_source_name (di
);
1504 if (! d_discriminator (di
))
1507 else if (peek
== 'U')
1509 switch (d_peek_next_char (di
))
1512 ret
= d_lambda (di
);
1515 ret
= d_unnamed_type (di
);
1524 if (d_peek_char (di
) == 'B')
1525 ret
= d_abi_tags (di
, ret
);
1529 /* <source-name> ::= <(positive length) number> <identifier> */
1531 static struct demangle_component
*
1532 d_source_name (struct d_info
*di
)
1535 struct demangle_component
*ret
;
1537 len
= d_number (di
);
1540 ret
= d_identifier (di
, len
);
1541 di
->last_name
= ret
;
1545 /* number ::= [n] <(non-negative decimal integer)> */
1548 d_number (struct d_info
*di
)
1555 peek
= d_peek_char (di
);
1560 peek
= d_peek_char (di
);
1566 if (! IS_DIGIT (peek
))
1572 ret
= ret
* 10 + peek
- '0';
1574 peek
= d_peek_char (di
);
1578 /* Like d_number, but returns a demangle_component. */
1580 static struct demangle_component
*
1581 d_number_component (struct d_info
*di
)
1583 struct demangle_component
*ret
= d_make_empty (di
);
1586 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1587 ret
->u
.s_number
.number
= d_number (di
);
1592 /* identifier ::= <(unqualified source code identifier)> */
1594 static struct demangle_component
*
1595 d_identifier (struct d_info
*di
, int len
)
1601 if (di
->send
- name
< len
)
1604 d_advance (di
, len
);
1606 /* A Java mangled name may have a trailing '$' if it is a C++
1607 keyword. This '$' is not included in the length count. We just
1609 if ((di
->options
& DMGL_JAVA
) != 0
1610 && d_peek_char (di
) == '$')
1613 /* Look for something which looks like a gcc encoding of an
1614 anonymous namespace, and replace it with a more user friendly
1616 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1617 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1618 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1622 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1623 if ((*s
== '.' || *s
== '_' || *s
== '$')
1626 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1627 return d_make_name (di
, "(anonymous namespace)",
1628 sizeof "(anonymous namespace)" - 1);
1632 return d_make_name (di
, name
, len
);
1635 /* operator_name ::= many different two character encodings.
1637 ::= v <digit> <source-name>
1639 This list is sorted for binary search. */
1641 #define NL(s) s, (sizeof s) - 1
1643 CP_STATIC_IF_GLIBCPP_V3
1644 const struct demangle_operator_info cplus_demangle_operators
[] =
1646 { "aN", NL ("&="), 2 },
1647 { "aS", NL ("="), 2 },
1648 { "aa", NL ("&&"), 2 },
1649 { "ad", NL ("&"), 1 },
1650 { "an", NL ("&"), 2 },
1651 { "at", NL ("alignof "), 1 },
1652 { "az", NL ("alignof "), 1 },
1653 { "cc", NL ("const_cast"), 2 },
1654 { "cl", NL ("()"), 2 },
1655 { "cm", NL (","), 2 },
1656 { "co", NL ("~"), 1 },
1657 { "dV", NL ("/="), 2 },
1658 { "da", NL ("delete[] "), 1 },
1659 { "dc", NL ("dynamic_cast"), 2 },
1660 { "de", NL ("*"), 1 },
1661 { "dl", NL ("delete "), 1 },
1662 { "ds", NL (".*"), 2 },
1663 { "dt", NL ("."), 2 },
1664 { "dv", NL ("/"), 2 },
1665 { "eO", NL ("^="), 2 },
1666 { "eo", NL ("^"), 2 },
1667 { "eq", NL ("=="), 2 },
1668 { "ge", NL (">="), 2 },
1669 { "gs", NL ("::"), 1 },
1670 { "gt", NL (">"), 2 },
1671 { "ix", NL ("[]"), 2 },
1672 { "lS", NL ("<<="), 2 },
1673 { "le", NL ("<="), 2 },
1674 { "li", NL ("operator\"\" "), 1 },
1675 { "ls", NL ("<<"), 2 },
1676 { "lt", NL ("<"), 2 },
1677 { "mI", NL ("-="), 2 },
1678 { "mL", NL ("*="), 2 },
1679 { "mi", NL ("-"), 2 },
1680 { "ml", NL ("*"), 2 },
1681 { "mm", NL ("--"), 1 },
1682 { "na", NL ("new[]"), 3 },
1683 { "ne", NL ("!="), 2 },
1684 { "ng", NL ("-"), 1 },
1685 { "nt", NL ("!"), 1 },
1686 { "nw", NL ("new"), 3 },
1687 { "oR", NL ("|="), 2 },
1688 { "oo", NL ("||"), 2 },
1689 { "or", NL ("|"), 2 },
1690 { "pL", NL ("+="), 2 },
1691 { "pl", NL ("+"), 2 },
1692 { "pm", NL ("->*"), 2 },
1693 { "pp", NL ("++"), 1 },
1694 { "ps", NL ("+"), 1 },
1695 { "pt", NL ("->"), 2 },
1696 { "qu", NL ("?"), 3 },
1697 { "rM", NL ("%="), 2 },
1698 { "rS", NL (">>="), 2 },
1699 { "rc", NL ("reinterpret_cast"), 2 },
1700 { "rm", NL ("%"), 2 },
1701 { "rs", NL (">>"), 2 },
1702 { "sc", NL ("static_cast"), 2 },
1703 { "st", NL ("sizeof "), 1 },
1704 { "sz", NL ("sizeof "), 1 },
1705 { "tr", NL ("throw"), 0 },
1706 { "tw", NL ("throw "), 1 },
1707 { NULL
, NULL
, 0, 0 }
1710 static struct demangle_component
*
1711 d_operator_name (struct d_info
*di
)
1716 c1
= d_next_char (di
);
1717 c2
= d_next_char (di
);
1718 if (c1
== 'v' && IS_DIGIT (c2
))
1719 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1720 else if (c1
== 'c' && c2
== 'v')
1721 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1722 cplus_demangle_type (di
), NULL
);
1725 /* LOW is the inclusive lower bound. */
1727 /* HIGH is the exclusive upper bound. We subtract one to ignore
1728 the sentinel at the end of the array. */
1729 int high
= ((sizeof (cplus_demangle_operators
)
1730 / sizeof (cplus_demangle_operators
[0]))
1736 const struct demangle_operator_info
*p
;
1738 i
= low
+ (high
- low
) / 2;
1739 p
= cplus_demangle_operators
+ i
;
1741 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1742 return d_make_operator (di
, p
);
1744 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1754 static struct demangle_component
*
1755 d_make_character (struct d_info
*di
, int c
)
1757 struct demangle_component
*p
;
1758 p
= d_make_empty (di
);
1761 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1762 p
->u
.s_character
.character
= c
;
1767 static struct demangle_component
*
1768 d_java_resource (struct d_info
*di
)
1770 struct demangle_component
*p
= NULL
;
1771 struct demangle_component
*next
= NULL
;
1776 len
= d_number (di
);
1780 /* Eat the leading '_'. */
1781 if (d_next_char (di
) != '_')
1794 /* Each chunk is either a '$' escape... */
1812 next
= d_make_character (di
, c
);
1820 /* ... or a sequence of characters. */
1823 while (i
< len
&& str
[i
] && str
[i
] != '$')
1826 next
= d_make_name (di
, str
, i
);
1839 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1845 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1850 /* <special-name> ::= TV <type>
1854 ::= GV <(object) name>
1855 ::= T <call-offset> <(base) encoding>
1856 ::= Tc <call-offset> <call-offset> <(base) encoding>
1857 Also g++ extensions:
1858 ::= TC <type> <(offset) number> _ <(base) type>
1863 ::= Gr <resource name>
1868 static struct demangle_component
*
1869 d_special_name (struct d_info
*di
)
1871 di
->expansion
+= 20;
1872 if (d_check_char (di
, 'T'))
1874 switch (d_next_char (di
))
1878 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1879 cplus_demangle_type (di
), NULL
);
1881 di
->expansion
-= 10;
1882 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1883 cplus_demangle_type (di
), NULL
);
1885 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1886 cplus_demangle_type (di
), NULL
);
1888 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1889 cplus_demangle_type (di
), NULL
);
1892 if (! d_call_offset (di
, 'h'))
1894 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1895 d_encoding (di
, 0), NULL
);
1898 if (! d_call_offset (di
, 'v'))
1900 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1901 d_encoding (di
, 0), NULL
);
1904 if (! d_call_offset (di
, '\0'))
1906 if (! d_call_offset (di
, '\0'))
1908 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1909 d_encoding (di
, 0), NULL
);
1913 struct demangle_component
*derived_type
;
1915 struct demangle_component
*base_type
;
1917 derived_type
= cplus_demangle_type (di
);
1918 offset
= d_number (di
);
1921 if (! d_check_char (di
, '_'))
1923 base_type
= cplus_demangle_type (di
);
1924 /* We don't display the offset. FIXME: We should display
1925 it in verbose mode. */
1927 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1928 base_type
, derived_type
);
1932 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1933 cplus_demangle_type (di
), NULL
);
1935 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1936 cplus_demangle_type (di
), NULL
);
1939 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
1943 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
1950 else if (d_check_char (di
, 'G'))
1952 switch (d_next_char (di
))
1955 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1959 struct demangle_component
*name
= d_name (di
);
1960 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
1961 d_number_component (di
));
1965 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1966 d_encoding (di
, 0), NULL
);
1969 switch (d_next_char (di
))
1972 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
1973 d_encoding (di
, 0), NULL
);
1975 /* ??? The proposal is that other letters (such as 'h') stand
1976 for different variants of transaction cloning, such as
1977 compiling directly for hardware transaction support. But
1978 they still should all be transactional clones of some sort
1979 so go ahead and call them that. */
1981 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
1982 d_encoding (di
, 0), NULL
);
1986 return d_java_resource (di
);
1996 /* <call-offset> ::= h <nv-offset> _
1999 <nv-offset> ::= <(offset) number>
2001 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2003 The C parameter, if not '\0', is a character we just read which is
2004 the start of the <call-offset>.
2006 We don't display the offset information anywhere. FIXME: We should
2007 display it in verbose mode. */
2010 d_call_offset (struct d_info
*di
, int c
)
2013 c
= d_next_char (di
);
2020 if (! d_check_char (di
, '_'))
2027 if (! d_check_char (di
, '_'))
2033 /* <ctor-dtor-name> ::= C1
2041 static struct demangle_component
*
2042 d_ctor_dtor_name (struct d_info
*di
)
2044 if (di
->last_name
!= NULL
)
2046 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2047 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2048 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2049 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2051 switch (d_peek_char (di
))
2055 enum gnu_v3_ctor_kinds kind
;
2057 switch (d_peek_next_char (di
))
2060 kind
= gnu_v3_complete_object_ctor
;
2063 kind
= gnu_v3_base_object_ctor
;
2066 kind
= gnu_v3_complete_object_allocating_ctor
;
2069 kind
= gnu_v3_object_ctor_group
;
2075 return d_make_ctor (di
, kind
, di
->last_name
);
2080 enum gnu_v3_dtor_kinds kind
;
2082 switch (d_peek_next_char (di
))
2085 kind
= gnu_v3_deleting_dtor
;
2088 kind
= gnu_v3_complete_object_dtor
;
2091 kind
= gnu_v3_base_object_dtor
;
2094 kind
= gnu_v3_object_dtor_group
;
2100 return d_make_dtor (di
, kind
, di
->last_name
);
2108 /* <type> ::= <builtin-type>
2110 ::= <class-enum-type>
2112 ::= <pointer-to-member-type>
2113 ::= <template-param>
2114 ::= <template-template-param> <template-args>
2116 ::= <CV-qualifiers> <type>
2119 ::= O <type> (C++0x)
2122 ::= U <source-name> <type>
2124 <builtin-type> ::= various one letter codes
2128 CP_STATIC_IF_GLIBCPP_V3
2129 const struct demangle_builtin_type_info
2130 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2132 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2133 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2134 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2135 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2136 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2137 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2138 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2139 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2140 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2141 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2142 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2143 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2144 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2145 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2146 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2148 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2149 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2150 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2151 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2152 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2153 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2154 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2155 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2156 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2157 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2158 D_PRINT_UNSIGNED_LONG_LONG
},
2159 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2160 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2161 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2162 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2163 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2164 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2165 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2166 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2170 CP_STATIC_IF_GLIBCPP_V3
2171 struct demangle_component
*
2172 cplus_demangle_type (struct d_info
*di
)
2175 struct demangle_component
*ret
;
2178 /* The ABI specifies that when CV-qualifiers are used, the base type
2179 is substitutable, and the fully qualified type is substitutable,
2180 but the base type with a strict subset of the CV-qualifiers is
2181 not substitutable. The natural recursive implementation of the
2182 CV-qualifiers would cause subsets to be substitutable, so instead
2183 we pull them all off now.
2185 FIXME: The ABI says that order-insensitive vendor qualifiers
2186 should be handled in the same way, but we have no way to tell
2187 which vendor qualifiers are order-insensitive and which are
2188 order-sensitive. So we just assume that they are all
2189 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2190 __vector, and it treats it as order-sensitive when mangling
2193 peek
= d_peek_char (di
);
2194 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2196 struct demangle_component
**pret
;
2198 pret
= d_cv_qualifiers (di
, &ret
, 0);
2201 if (d_peek_char (di
) == 'F')
2203 /* cv-qualifiers before a function type apply to 'this',
2204 so avoid adding the unqualified function type to
2205 the substitution list. */
2206 *pret
= d_function_type (di
);
2209 *pret
= cplus_demangle_type (di
);
2212 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2213 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2215 /* Move the ref-qualifier outside the cv-qualifiers so that
2216 they are printed in the right order. */
2217 struct demangle_component
*fn
= d_left (*pret
);
2218 d_left (*pret
) = ret
;
2222 if (! d_add_substitution (di
, ret
))
2231 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2232 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2233 case 'o': case 's': case 't':
2234 case 'v': case 'w': case 'x': case 'y': case 'z':
2235 ret
= d_make_builtin_type (di
,
2236 &cplus_demangle_builtin_types
[peek
- 'a']);
2237 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2244 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2245 d_source_name (di
), NULL
);
2249 ret
= d_function_type (di
);
2252 case '0': case '1': case '2': case '3': case '4':
2253 case '5': case '6': case '7': case '8': case '9':
2256 ret
= d_class_enum_type (di
);
2260 ret
= d_array_type (di
);
2264 ret
= d_pointer_to_member_type (di
);
2268 ret
= d_template_param (di
);
2269 if (d_peek_char (di
) == 'I')
2271 /* This is <template-template-param> <template-args>. The
2272 <template-template-param> part is a substitution
2274 if (! d_add_substitution (di
, ret
))
2276 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2277 d_template_args (di
));
2282 /* If this is a special substitution, then it is the start of
2283 <class-enum-type>. */
2287 peek_next
= d_peek_next_char (di
);
2288 if (IS_DIGIT (peek_next
)
2290 || IS_UPPER (peek_next
))
2292 ret
= d_substitution (di
, 0);
2293 /* The substituted name may have been a template name and
2294 may be followed by tepmlate args. */
2295 if (d_peek_char (di
) == 'I')
2296 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2297 d_template_args (di
));
2303 ret
= d_class_enum_type (di
);
2304 /* If the substitution was a complete type, then it is not
2305 a new substitution candidate. However, if the
2306 substitution was followed by template arguments, then
2307 the whole thing is a substitution candidate. */
2308 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2316 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2317 cplus_demangle_type (di
), NULL
);
2322 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2323 cplus_demangle_type (di
), NULL
);
2328 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2329 cplus_demangle_type (di
), NULL
);
2334 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2335 cplus_demangle_type (di
), NULL
);
2340 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2341 cplus_demangle_type (di
), NULL
);
2346 ret
= d_source_name (di
);
2347 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2348 cplus_demangle_type (di
), ret
);
2354 peek
= d_next_char (di
);
2359 /* decltype (expression) */
2360 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2361 d_expression (di
), NULL
);
2362 if (ret
&& d_next_char (di
) != 'E')
2368 /* Pack expansion. */
2369 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2370 cplus_demangle_type (di
), NULL
);
2376 ret
= d_make_name (di
, "auto", 4);
2380 /* 32-bit decimal floating point */
2381 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2382 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2386 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2387 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2391 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2392 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2395 /* 16-bit half-precision FP */
2396 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2397 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2401 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2402 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2406 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2407 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2411 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2412 ret
= d_make_empty (di
);
2413 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2414 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2415 /* For demangling we don't care about the bits. */
2417 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2418 if (ret
->u
.s_fixed
.length
== NULL
)
2421 peek
= d_next_char (di
);
2422 ret
->u
.s_fixed
.sat
= (peek
== 's');
2426 ret
= d_vector_type (di
);
2431 /* decltype(nullptr) */
2432 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2433 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2447 if (! d_add_substitution (di
, ret
))
2454 /* <CV-qualifiers> ::= [r] [V] [K] */
2456 static struct demangle_component
**
2457 d_cv_qualifiers (struct d_info
*di
,
2458 struct demangle_component
**pret
, int member_fn
)
2460 struct demangle_component
**pstart
;
2464 peek
= d_peek_char (di
);
2465 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2467 enum demangle_component_type t
;
2473 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2474 : DEMANGLE_COMPONENT_RESTRICT
);
2475 di
->expansion
+= sizeof "restrict";
2477 else if (peek
== 'V')
2480 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2481 : DEMANGLE_COMPONENT_VOLATILE
);
2482 di
->expansion
+= sizeof "volatile";
2487 ? DEMANGLE_COMPONENT_CONST_THIS
2488 : DEMANGLE_COMPONENT_CONST
);
2489 di
->expansion
+= sizeof "const";
2492 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2495 pret
= &d_left (*pret
);
2497 peek
= d_peek_char (di
);
2500 if (!member_fn
&& peek
== 'F')
2502 while (pstart
!= pret
)
2504 switch ((*pstart
)->type
)
2506 case DEMANGLE_COMPONENT_RESTRICT
:
2507 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2509 case DEMANGLE_COMPONENT_VOLATILE
:
2510 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2512 case DEMANGLE_COMPONENT_CONST
:
2513 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2518 pstart
= &d_left (*pstart
);
2525 /* <ref-qualifier> ::= R
2528 static struct demangle_component
*
2529 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2531 struct demangle_component
*ret
= sub
;
2534 peek
= d_peek_char (di
);
2535 if (peek
== 'R' || peek
== 'O')
2537 enum demangle_component_type t
;
2540 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2541 di
->expansion
+= sizeof "&";
2545 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2546 di
->expansion
+= sizeof "&&";
2550 ret
= d_make_comp (di
, t
, ret
, NULL
);
2556 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
2558 static struct demangle_component
*
2559 d_function_type (struct d_info
*di
)
2561 struct demangle_component
*ret
;
2563 if (! d_check_char (di
, 'F'))
2565 if (d_peek_char (di
) == 'Y')
2567 /* Function has C linkage. We don't print this information.
2568 FIXME: We should print it in verbose mode. */
2571 ret
= d_bare_function_type (di
, 1);
2572 ret
= d_ref_qualifier (di
, ret
);
2574 if (! d_check_char (di
, 'E'))
2581 static struct demangle_component
*
2582 d_parmlist (struct d_info
*di
)
2584 struct demangle_component
*tl
;
2585 struct demangle_component
**ptl
;
2591 struct demangle_component
*type
;
2593 char peek
= d_peek_char (di
);
2594 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2596 if ((peek
== 'R' || peek
== 'O')
2597 && d_peek_next_char (di
) == 'E')
2598 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2600 type
= cplus_demangle_type (di
);
2603 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2606 ptl
= &d_right (*ptl
);
2609 /* There should be at least one parameter type besides the optional
2610 return type. A function which takes no arguments will have a
2611 single parameter type void. */
2615 /* If we have a single parameter type void, omit it. */
2616 if (d_right (tl
) == NULL
2617 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2618 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2620 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2627 /* <bare-function-type> ::= [J]<type>+ */
2629 static struct demangle_component
*
2630 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2632 struct demangle_component
*return_type
;
2633 struct demangle_component
*tl
;
2636 /* Detect special qualifier indicating that the first argument
2637 is the return type. */
2638 peek
= d_peek_char (di
);
2642 has_return_type
= 1;
2645 if (has_return_type
)
2647 return_type
= cplus_demangle_type (di
);
2648 if (return_type
== NULL
)
2654 tl
= d_parmlist (di
);
2658 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2662 /* <class-enum-type> ::= <name> */
2664 static struct demangle_component
*
2665 d_class_enum_type (struct d_info
*di
)
2670 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2671 ::= A [<(dimension) expression>] _ <(element) type>
2674 static struct demangle_component
*
2675 d_array_type (struct d_info
*di
)
2678 struct demangle_component
*dim
;
2680 if (! d_check_char (di
, 'A'))
2683 peek
= d_peek_char (di
);
2686 else if (IS_DIGIT (peek
))
2694 peek
= d_peek_char (di
);
2696 while (IS_DIGIT (peek
));
2697 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2703 dim
= d_expression (di
);
2708 if (! d_check_char (di
, '_'))
2711 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2712 cplus_demangle_type (di
));
2715 /* <vector-type> ::= Dv <number> _ <type>
2716 ::= Dv _ <expression> _ <type> */
2718 static struct demangle_component
*
2719 d_vector_type (struct d_info
*di
)
2722 struct demangle_component
*dim
;
2724 peek
= d_peek_char (di
);
2728 dim
= d_expression (di
);
2731 dim
= d_number_component (di
);
2736 if (! d_check_char (di
, '_'))
2739 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2740 cplus_demangle_type (di
));
2743 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2745 static struct demangle_component
*
2746 d_pointer_to_member_type (struct d_info
*di
)
2748 struct demangle_component
*cl
;
2749 struct demangle_component
*mem
;
2751 if (! d_check_char (di
, 'M'))
2754 cl
= cplus_demangle_type (di
);
2758 /* The ABI says, "The type of a non-static member function is considered
2759 to be different, for the purposes of substitution, from the type of a
2760 namespace-scope or static member function whose type appears
2761 similar. The types of two non-static member functions are considered
2762 to be different, for the purposes of substitution, if the functions
2763 are members of different classes. In other words, for the purposes of
2764 substitution, the class of which the function is a member is
2765 considered part of the type of function."
2767 For a pointer to member function, this call to cplus_demangle_type
2768 will end up adding a (possibly qualified) non-member function type to
2769 the substitution table, which is not correct; however, the member
2770 function type will never be used in a substitution, so putting the
2771 wrong type in the substitution table is harmless. */
2773 mem
= cplus_demangle_type (di
);
2777 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2780 /* <non-negative number> _ */
2783 d_compact_number (struct d_info
*di
)
2786 if (d_peek_char (di
) == '_')
2788 else if (d_peek_char (di
) == 'n')
2791 num
= d_number (di
) + 1;
2793 if (! d_check_char (di
, '_'))
2798 /* <template-param> ::= T_
2799 ::= T <(parameter-2 non-negative) number> _
2802 static struct demangle_component
*
2803 d_template_param (struct d_info
*di
)
2807 if (! d_check_char (di
, 'T'))
2810 param
= d_compact_number (di
);
2816 return d_make_template_param (di
, param
);
2819 /* <template-args> ::= I <template-arg>+ E */
2821 static struct demangle_component
*
2822 d_template_args (struct d_info
*di
)
2824 struct demangle_component
*hold_last_name
;
2825 struct demangle_component
*al
;
2826 struct demangle_component
**pal
;
2828 /* Preserve the last name we saw--don't let the template arguments
2829 clobber it, as that would give us the wrong name for a subsequent
2830 constructor or destructor. */
2831 hold_last_name
= di
->last_name
;
2833 if (d_peek_char (di
) != 'I'
2834 && d_peek_char (di
) != 'J')
2838 if (d_peek_char (di
) == 'E')
2840 /* An argument pack can be empty. */
2842 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2849 struct demangle_component
*a
;
2851 a
= d_template_arg (di
);
2855 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2858 pal
= &d_right (*pal
);
2860 if (d_peek_char (di
) == 'E')
2867 di
->last_name
= hold_last_name
;
2872 /* <template-arg> ::= <type>
2873 ::= X <expression> E
2877 static struct demangle_component
*
2878 d_template_arg (struct d_info
*di
)
2880 struct demangle_component
*ret
;
2882 switch (d_peek_char (di
))
2886 ret
= d_expression (di
);
2887 if (! d_check_char (di
, 'E'))
2892 return d_expr_primary (di
);
2896 /* An argument pack. */
2897 return d_template_args (di
);
2900 return cplus_demangle_type (di
);
2904 /* Parse a sequence of expressions until we hit the terminator
2907 static struct demangle_component
*
2908 d_exprlist (struct d_info
*di
, char terminator
)
2910 struct demangle_component
*list
= NULL
;
2911 struct demangle_component
**p
= &list
;
2913 if (d_peek_char (di
) == terminator
)
2916 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2921 struct demangle_component
*arg
= d_expression (di
);
2925 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2930 if (d_peek_char (di
) == terminator
)
2940 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
2941 dynamic_cast, static_cast or reinterpret_cast. */
2944 op_is_new_cast (struct demangle_component
*op
)
2946 const char *code
= op
->u
.s_operator
.op
->code
;
2947 return (code
[1] == 'c'
2948 && (code
[0] == 's' || code
[0] == 'd'
2949 || code
[0] == 'c' || code
[0] == 'r'));
2952 /* <expression> ::= <(unary) operator-name> <expression>
2953 ::= <(binary) operator-name> <expression> <expression>
2954 ::= <(trinary) operator-name> <expression> <expression> <expression>
2955 ::= cl <expression>+ E
2957 ::= <template-param>
2958 ::= sr <type> <unqualified-name>
2959 ::= sr <type> <unqualified-name> <template-args>
2963 static struct demangle_component
*
2964 d_expression (struct d_info
*di
)
2968 peek
= d_peek_char (di
);
2970 return d_expr_primary (di
);
2971 else if (peek
== 'T')
2972 return d_template_param (di
);
2973 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2975 struct demangle_component
*type
;
2976 struct demangle_component
*name
;
2979 type
= cplus_demangle_type (di
);
2980 name
= d_unqualified_name (di
);
2981 if (d_peek_char (di
) != 'I')
2982 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2984 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2985 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2986 d_template_args (di
)));
2988 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
2991 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2992 d_expression (di
), NULL
);
2994 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
2996 /* Function parameter used in a late-specified return type. */
2999 if (d_peek_char (di
) == 'T')
3001 /* 'this' parameter. */
3007 index
= d_compact_number (di
) + 1;
3011 return d_make_function_param (di
, index
);
3013 else if (IS_DIGIT (peek
)
3014 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3016 /* We can get an unqualified name as an expression in the case of
3017 a dependent function call, i.e. decltype(f(t)). */
3018 struct demangle_component
*name
;
3021 /* operator-function-id, i.e. operator+(t). */
3024 name
= d_unqualified_name (di
);
3027 if (d_peek_char (di
) == 'I')
3028 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3029 d_template_args (di
));
3033 else if ((peek
== 'i' || peek
== 't')
3034 && d_peek_next_char (di
) == 'l')
3036 /* Brace-enclosed initializer list, untyped or typed. */
3037 struct demangle_component
*type
= NULL
;
3039 type
= cplus_demangle_type (di
);
3041 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3042 type
, d_exprlist (di
, 'E'));
3046 struct demangle_component
*op
;
3047 const char *code
= NULL
;
3050 op
= d_operator_name (di
);
3054 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3056 code
= op
->u
.s_operator
.op
->code
;
3057 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3058 if (strcmp (code
, "st") == 0)
3059 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3060 cplus_demangle_type (di
));
3067 case DEMANGLE_COMPONENT_OPERATOR
:
3068 args
= op
->u
.s_operator
.op
->args
;
3070 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3071 args
= op
->u
.s_extended_operator
.args
;
3073 case DEMANGLE_COMPONENT_CAST
:
3081 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3085 struct demangle_component
*operand
;
3088 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3089 && code
[1] == code
[0])
3090 /* pp_ and mm_ are the prefix variants. */
3091 suffix
= !d_check_char (di
, '_');
3093 if (op
->type
== DEMANGLE_COMPONENT_CAST
3094 && d_check_char (di
, '_'))
3095 operand
= d_exprlist (di
, 'E');
3097 operand
= d_expression (di
);
3100 /* Indicate the suffix variant for d_print_comp. */
3101 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3103 DEMANGLE_COMPONENT_BINARY_ARGS
,
3106 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3111 struct demangle_component
*left
;
3112 struct demangle_component
*right
;
3114 if (op_is_new_cast (op
))
3115 left
= cplus_demangle_type (di
);
3117 left
= d_expression (di
);
3118 if (!strcmp (code
, "cl"))
3119 right
= d_exprlist (di
, 'E');
3120 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3122 right
= d_unqualified_name (di
);
3123 if (d_peek_char (di
) == 'I')
3124 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3125 right
, d_template_args (di
));
3128 right
= d_expression (di
);
3130 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3132 DEMANGLE_COMPONENT_BINARY_ARGS
,
3137 struct demangle_component
*first
;
3138 struct demangle_component
*second
;
3139 struct demangle_component
*third
;
3141 if (!strcmp (code
, "qu"))
3143 /* ?: expression. */
3144 first
= d_expression (di
);
3145 second
= d_expression (di
);
3146 third
= d_expression (di
);
3148 else if (code
[0] == 'n')
3150 /* new-expression. */
3151 if (code
[1] != 'w' && code
[1] != 'a')
3153 first
= d_exprlist (di
, '_');
3154 second
= cplus_demangle_type (di
);
3155 if (d_peek_char (di
) == 'E')
3160 else if (d_peek_char (di
) == 'p'
3161 && d_peek_next_char (di
) == 'i')
3163 /* Parenthesized initializer. */
3165 third
= d_exprlist (di
, 'E');
3167 else if (d_peek_char (di
) == 'i'
3168 && d_peek_next_char (di
) == 'l')
3169 /* initializer-list. */
3170 third
= d_expression (di
);
3176 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3178 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3181 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3190 /* <expr-primary> ::= L <type> <(value) number> E
3191 ::= L <type> <(value) float> E
3192 ::= L <mangled-name> E
3195 static struct demangle_component
*
3196 d_expr_primary (struct d_info
*di
)
3198 struct demangle_component
*ret
;
3200 if (! d_check_char (di
, 'L'))
3202 if (d_peek_char (di
) == '_'
3203 /* Workaround for G++ bug; see comment in write_template_arg. */
3204 || d_peek_char (di
) == 'Z')
3205 ret
= cplus_demangle_mangled_name (di
, 0);
3208 struct demangle_component
*type
;
3209 enum demangle_component_type t
;
3212 type
= cplus_demangle_type (di
);
3216 /* If we have a type we know how to print, we aren't going to
3217 print the type name itself. */
3218 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3219 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3220 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3222 /* Rather than try to interpret the literal value, we just
3223 collect it as a string. Note that it's possible to have a
3224 floating point literal here. The ABI specifies that the
3225 format of such literals is machine independent. That's fine,
3226 but what's not fine is that versions of g++ up to 3.2 with
3227 -fabi-version=1 used upper case letters in the hex constant,
3228 and dumped out gcc's internal representation. That makes it
3229 hard to tell where the constant ends, and hard to dump the
3230 constant in any readable form anyhow. We don't attempt to
3231 handle these cases. */
3233 t
= DEMANGLE_COMPONENT_LITERAL
;
3234 if (d_peek_char (di
) == 'n')
3236 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3240 while (d_peek_char (di
) != 'E')
3242 if (d_peek_char (di
) == '\0')
3246 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3248 if (! d_check_char (di
, 'E'))
3253 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3254 ::= Z <(function) encoding> E s [<discriminator>]
3255 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3258 static struct demangle_component
*
3259 d_local_name (struct d_info
*di
)
3261 struct demangle_component
*function
;
3263 if (! d_check_char (di
, 'Z'))
3266 function
= d_encoding (di
, 0);
3268 if (! d_check_char (di
, 'E'))
3271 if (d_peek_char (di
) == 's')
3274 if (! d_discriminator (di
))
3276 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3277 d_make_name (di
, "string literal",
3278 sizeof "string literal" - 1));
3282 struct demangle_component
*name
;
3285 if (d_peek_char (di
) == 'd')
3287 /* Default argument scope: d <number> _. */
3289 num
= d_compact_number (di
);
3298 /* Lambdas and unnamed types have internal discriminators. */
3299 case DEMANGLE_COMPONENT_LAMBDA
:
3300 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3303 if (! d_discriminator (di
))
3307 name
= d_make_default_arg (di
, num
, name
);
3308 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3312 /* <discriminator> ::= _ <(non-negative) number>
3314 We demangle the discriminator, but we don't print it out. FIXME:
3315 We should print it out in verbose mode. */
3318 d_discriminator (struct d_info
*di
)
3322 if (d_peek_char (di
) != '_')
3325 discrim
= d_number (di
);
3331 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3333 static struct demangle_component
*
3334 d_lambda (struct d_info
*di
)
3336 struct demangle_component
*tl
;
3337 struct demangle_component
*ret
;
3340 if (! d_check_char (di
, 'U'))
3342 if (! d_check_char (di
, 'l'))
3345 tl
= d_parmlist (di
);
3349 if (! d_check_char (di
, 'E'))
3352 num
= d_compact_number (di
);
3356 ret
= d_make_empty (di
);
3359 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3360 ret
->u
.s_unary_num
.sub
= tl
;
3361 ret
->u
.s_unary_num
.num
= num
;
3364 if (! d_add_substitution (di
, ret
))
3370 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3372 static struct demangle_component
*
3373 d_unnamed_type (struct d_info
*di
)
3375 struct demangle_component
*ret
;
3378 if (! d_check_char (di
, 'U'))
3380 if (! d_check_char (di
, 't'))
3383 num
= d_compact_number (di
);
3387 ret
= d_make_empty (di
);
3390 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3391 ret
->u
.s_number
.number
= num
;
3394 if (! d_add_substitution (di
, ret
))
3400 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3403 static struct demangle_component
*
3404 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3406 const char *suffix
= d_str (di
);
3407 const char *pend
= suffix
;
3408 struct demangle_component
*n
;
3410 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3413 while (IS_LOWER (*pend
) || *pend
== '_')
3416 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3419 while (IS_DIGIT (*pend
))
3422 d_advance (di
, pend
- suffix
);
3423 n
= d_make_name (di
, suffix
, pend
- suffix
);
3424 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3427 /* Add a new substitution. */
3430 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3434 if (di
->next_sub
>= di
->num_subs
)
3436 di
->subs
[di
->next_sub
] = dc
;
3441 /* <substitution> ::= S <seq-id> _
3451 If PREFIX is non-zero, then this type is being used as a prefix in
3452 a qualified name. In this case, for the standard substitutions, we
3453 need to check whether we are being used as a prefix for a
3454 constructor or destructor, and return a full template name.
3455 Otherwise we will get something like std::iostream::~iostream()
3456 which does not correspond particularly well to any function which
3457 actually appears in the source.
3460 static const struct d_standard_sub_info standard_subs
[] =
3465 { 'a', NL ("std::allocator"),
3466 NL ("std::allocator"),
3468 { 'b', NL ("std::basic_string"),
3469 NL ("std::basic_string"),
3470 NL ("basic_string") },
3471 { 's', NL ("std::string"),
3472 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3473 NL ("basic_string") },
3474 { 'i', NL ("std::istream"),
3475 NL ("std::basic_istream<char, std::char_traits<char> >"),
3476 NL ("basic_istream") },
3477 { 'o', NL ("std::ostream"),
3478 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3479 NL ("basic_ostream") },
3480 { 'd', NL ("std::iostream"),
3481 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3482 NL ("basic_iostream") }
3485 static struct demangle_component
*
3486 d_substitution (struct d_info
*di
, int prefix
)
3490 if (! d_check_char (di
, 'S'))
3493 c
= d_next_char (di
);
3494 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3503 unsigned int new_id
;
3506 new_id
= id
* 36 + c
- '0';
3507 else if (IS_UPPER (c
))
3508 new_id
= id
* 36 + c
- 'A' + 10;
3514 c
= d_next_char (di
);
3521 if (id
>= (unsigned int) di
->next_sub
)
3526 return di
->subs
[id
];
3531 const struct d_standard_sub_info
*p
;
3532 const struct d_standard_sub_info
*pend
;
3534 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3535 if (! verbose
&& prefix
)
3539 peek
= d_peek_char (di
);
3540 if (peek
== 'C' || peek
== 'D')
3544 pend
= (&standard_subs
[0]
3545 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3546 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3553 if (p
->set_last_name
!= NULL
)
3554 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3555 p
->set_last_name_len
);
3558 s
= p
->full_expansion
;
3563 s
= p
->simple_expansion
;
3564 len
= p
->simple_len
;
3566 di
->expansion
+= len
;
3567 return d_make_sub (di
, s
, len
);
3575 /* Initialize a growable string. */
3578 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3583 dgs
->allocation_failure
= 0;
3586 d_growable_string_resize (dgs
, estimate
);
3589 /* Grow a growable string to a given size. */
3592 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3597 if (dgs
->allocation_failure
)
3600 /* Start allocation at two bytes to avoid any possibility of confusion
3601 with the special value of 1 used as a return in *palc to indicate
3602 allocation failures. */
3603 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3604 while (newalc
< need
)
3607 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3614 dgs
->allocation_failure
= 1;
3621 /* Append a buffer to a growable string. */
3624 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3625 const char *s
, size_t l
)
3629 need
= dgs
->len
+ l
+ 1;
3630 if (need
> dgs
->alc
)
3631 d_growable_string_resize (dgs
, need
);
3633 if (dgs
->allocation_failure
)
3636 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3637 dgs
->buf
[dgs
->len
+ l
] = '\0';
3641 /* Bridge growable strings to the callback mechanism. */
3644 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3646 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3648 d_growable_string_append_buffer (dgs
, s
, l
);
3651 /* Initialize a print information structure. */
3654 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
3658 dpi
->last_char
= '\0';
3659 dpi
->templates
= NULL
;
3660 dpi
->modifiers
= NULL
;
3661 dpi
->pack_index
= 0;
3662 dpi
->flush_count
= 0;
3664 dpi
->callback
= callback
;
3665 dpi
->opaque
= opaque
;
3667 dpi
->demangle_failure
= 0;
3670 /* Indicate that an error occurred during printing, and test for error. */
3673 d_print_error (struct d_print_info
*dpi
)
3675 dpi
->demangle_failure
= 1;
3679 d_print_saw_error (struct d_print_info
*dpi
)
3681 return dpi
->demangle_failure
!= 0;
3684 /* Flush buffered characters to the callback. */
3687 d_print_flush (struct d_print_info
*dpi
)
3689 dpi
->buf
[dpi
->len
] = '\0';
3690 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3695 /* Append characters and buffers for printing. */
3698 d_append_char (struct d_print_info
*dpi
, char c
)
3700 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3701 d_print_flush (dpi
);
3703 dpi
->buf
[dpi
->len
++] = c
;
3708 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3712 for (i
= 0; i
< l
; i
++)
3713 d_append_char (dpi
, s
[i
]);
3717 d_append_string (struct d_print_info
*dpi
, const char *s
)
3719 d_append_buffer (dpi
, s
, strlen (s
));
3723 d_append_num (struct d_print_info
*dpi
, long l
)
3726 sprintf (buf
,"%ld", l
);
3727 d_append_string (dpi
, buf
);
3731 d_last_char (struct d_print_info
*dpi
)
3733 return dpi
->last_char
;
3736 /* Turn components into a human readable string. OPTIONS is the
3737 options bits passed to the demangler. DC is the tree to print.
3738 CALLBACK is a function to call to flush demangled string segments
3739 as they fill the intermediate buffer, and OPAQUE is a generalized
3740 callback argument. On success, this returns 1. On failure,
3741 it returns 0, indicating a bad parse. It does not use heap
3742 memory to build an output string, so cannot encounter memory
3743 allocation failure. */
3745 CP_STATIC_IF_GLIBCPP_V3
3747 cplus_demangle_print_callback (int options
,
3748 const struct demangle_component
*dc
,
3749 demangle_callbackref callback
, void *opaque
)
3751 struct d_print_info dpi
;
3753 d_print_init (&dpi
, callback
, opaque
);
3755 d_print_comp (&dpi
, options
, dc
);
3757 d_print_flush (&dpi
);
3759 return ! d_print_saw_error (&dpi
);
3762 /* Turn components into a human readable string. OPTIONS is the
3763 options bits passed to the demangler. DC is the tree to print.
3764 ESTIMATE is a guess at the length of the result. This returns a
3765 string allocated by malloc, or NULL on error. On success, this
3766 sets *PALC to the size of the allocated buffer. On failure, this
3767 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3770 CP_STATIC_IF_GLIBCPP_V3
3772 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3773 int estimate
, size_t *palc
)
3775 struct d_growable_string dgs
;
3777 d_growable_string_init (&dgs
, estimate
);
3779 if (! cplus_demangle_print_callback (options
, dc
,
3780 d_growable_string_callback_adapter
,
3788 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3792 /* Returns the I'th element of the template arglist ARGS, or NULL on
3795 static struct demangle_component
*
3796 d_index_template_argument (struct demangle_component
*args
, int i
)
3798 struct demangle_component
*a
;
3804 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3810 if (i
!= 0 || a
== NULL
)
3816 /* Returns the template argument from the current context indicated by DC,
3817 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3819 static struct demangle_component
*
3820 d_lookup_template_argument (struct d_print_info
*dpi
,
3821 const struct demangle_component
*dc
)
3823 if (dpi
->templates
== NULL
)
3825 d_print_error (dpi
);
3829 return d_index_template_argument
3830 (d_right (dpi
->templates
->template_decl
),
3831 dc
->u
.s_number
.number
);
3834 /* Returns a template argument pack used in DC (any will do), or NULL. */
3836 static struct demangle_component
*
3837 d_find_pack (struct d_print_info
*dpi
,
3838 const struct demangle_component
*dc
)
3840 struct demangle_component
*a
;
3846 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3847 a
= d_lookup_template_argument (dpi
, dc
);
3848 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3852 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3855 case DEMANGLE_COMPONENT_LAMBDA
:
3856 case DEMANGLE_COMPONENT_NAME
:
3857 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3858 case DEMANGLE_COMPONENT_OPERATOR
:
3859 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3860 case DEMANGLE_COMPONENT_SUB_STD
:
3861 case DEMANGLE_COMPONENT_CHARACTER
:
3862 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3863 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3866 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3867 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3868 case DEMANGLE_COMPONENT_CTOR
:
3869 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3870 case DEMANGLE_COMPONENT_DTOR
:
3871 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3874 a
= d_find_pack (dpi
, d_left (dc
));
3877 return d_find_pack (dpi
, d_right (dc
));
3881 /* Returns the length of the template argument pack DC. */
3884 d_pack_length (const struct demangle_component
*dc
)
3887 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3888 && d_left (dc
) != NULL
)
3896 /* DC is a component of a mangled expression. Print it, wrapped in parens
3900 d_print_subexpr (struct d_print_info
*dpi
, int options
,
3901 const struct demangle_component
*dc
)
3904 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3905 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
3906 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
3907 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3910 d_append_char (dpi
, '(');
3911 d_print_comp (dpi
, options
, dc
);
3913 d_append_char (dpi
, ')');
3916 /* Subroutine to handle components. */
3919 d_print_comp (struct d_print_info
*dpi
, int options
,
3920 const struct demangle_component
*dc
)
3922 /* Magic variable to let reference smashing skip over the next modifier
3923 without needing to modify *dc. */
3924 const struct demangle_component
*mod_inner
= NULL
;
3928 d_print_error (dpi
);
3931 if (d_print_saw_error (dpi
))
3936 case DEMANGLE_COMPONENT_NAME
:
3937 if ((options
& DMGL_JAVA
) == 0)
3938 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3940 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3943 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3944 d_print_comp (dpi
, options
, d_left (dc
));
3945 d_append_string (dpi
, "[abi:");
3946 d_print_comp (dpi
, options
, d_right (dc
));
3947 d_append_char (dpi
, ']');
3950 case DEMANGLE_COMPONENT_QUAL_NAME
:
3951 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3952 d_print_comp (dpi
, options
, d_left (dc
));
3953 if ((options
& DMGL_JAVA
) == 0)
3954 d_append_string (dpi
, "::");
3956 d_append_char (dpi
, '.');
3958 struct demangle_component
*local_name
= d_right (dc
);
3959 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
3961 d_append_string (dpi
, "{default arg#");
3962 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
3963 d_append_string (dpi
, "}::");
3964 local_name
= local_name
->u
.s_unary_num
.sub
;
3966 d_print_comp (dpi
, options
, local_name
);
3970 case DEMANGLE_COMPONENT_TYPED_NAME
:
3972 struct d_print_mod
*hold_modifiers
;
3973 struct demangle_component
*typed_name
;
3974 struct d_print_mod adpm
[4];
3976 struct d_print_template dpt
;
3978 /* Pass the name down to the type so that it can be printed in
3979 the right place for the type. We also have to pass down
3980 any CV-qualifiers, which apply to the this parameter. */
3981 hold_modifiers
= dpi
->modifiers
;
3984 typed_name
= d_left (dc
);
3985 while (typed_name
!= NULL
)
3987 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3989 d_print_error (dpi
);
3993 adpm
[i
].next
= dpi
->modifiers
;
3994 dpi
->modifiers
= &adpm
[i
];
3995 adpm
[i
].mod
= typed_name
;
3996 adpm
[i
].printed
= 0;
3997 adpm
[i
].templates
= dpi
->templates
;
4000 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4001 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4002 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4003 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4004 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4007 typed_name
= d_left (typed_name
);
4010 if (typed_name
== NULL
)
4012 d_print_error (dpi
);
4016 /* If typed_name is a template, then it applies to the
4017 function type as well. */
4018 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4020 dpt
.next
= dpi
->templates
;
4021 dpi
->templates
= &dpt
;
4022 dpt
.template_decl
= typed_name
;
4025 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4026 there may be CV-qualifiers on its right argument which
4027 really apply here; this happens when parsing a class which
4028 is local to a function. */
4029 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4031 struct demangle_component
*local_name
;
4033 local_name
= d_right (typed_name
);
4034 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4035 local_name
= local_name
->u
.s_unary_num
.sub
;
4036 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4037 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4038 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4039 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4040 || (local_name
->type
4041 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4043 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4045 d_print_error (dpi
);
4049 adpm
[i
] = adpm
[i
- 1];
4050 adpm
[i
].next
= &adpm
[i
- 1];
4051 dpi
->modifiers
= &adpm
[i
];
4053 adpm
[i
- 1].mod
= local_name
;
4054 adpm
[i
- 1].printed
= 0;
4055 adpm
[i
- 1].templates
= dpi
->templates
;
4058 local_name
= d_left (local_name
);
4062 d_print_comp (dpi
, options
, d_right (dc
));
4064 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4065 dpi
->templates
= dpt
.next
;
4067 /* If the modifiers didn't get printed by the type, print them
4072 if (! adpm
[i
].printed
)
4074 d_append_char (dpi
, ' ');
4075 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4079 dpi
->modifiers
= hold_modifiers
;
4084 case DEMANGLE_COMPONENT_TEMPLATE
:
4086 struct d_print_mod
*hold_dpm
;
4087 struct demangle_component
*dcl
;
4089 /* Don't push modifiers into a template definition. Doing so
4090 could give the wrong definition for a template argument.
4091 Instead, treat the template essentially as a name. */
4093 hold_dpm
= dpi
->modifiers
;
4094 dpi
->modifiers
= NULL
;
4098 if ((options
& DMGL_JAVA
) != 0
4099 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4100 && dcl
->u
.s_name
.len
== 6
4101 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4103 /* Special-case Java arrays, so that JArray<TYPE> appears
4104 instead as TYPE[]. */
4106 d_print_comp (dpi
, options
, d_right (dc
));
4107 d_append_string (dpi
, "[]");
4111 d_print_comp (dpi
, options
, dcl
);
4112 if (d_last_char (dpi
) == '<')
4113 d_append_char (dpi
, ' ');
4114 d_append_char (dpi
, '<');
4115 d_print_comp (dpi
, options
, d_right (dc
));
4116 /* Avoid generating two consecutive '>' characters, to avoid
4117 the C++ syntactic ambiguity. */
4118 if (d_last_char (dpi
) == '>')
4119 d_append_char (dpi
, ' ');
4120 d_append_char (dpi
, '>');
4123 dpi
->modifiers
= hold_dpm
;
4128 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4130 struct d_print_template
*hold_dpt
;
4131 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4133 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4134 a
= d_index_template_argument (a
, dpi
->pack_index
);
4138 d_print_error (dpi
);
4142 /* While processing this parameter, we need to pop the list of
4143 templates. This is because the template parameter may
4144 itself be a reference to a parameter of an outer
4147 hold_dpt
= dpi
->templates
;
4148 dpi
->templates
= hold_dpt
->next
;
4150 d_print_comp (dpi
, options
, a
);
4152 dpi
->templates
= hold_dpt
;
4157 case DEMANGLE_COMPONENT_CTOR
:
4158 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4161 case DEMANGLE_COMPONENT_DTOR
:
4162 d_append_char (dpi
, '~');
4163 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4166 case DEMANGLE_COMPONENT_VTABLE
:
4167 d_append_string (dpi
, "vtable for ");
4168 d_print_comp (dpi
, options
, d_left (dc
));
4171 case DEMANGLE_COMPONENT_VTT
:
4172 d_append_string (dpi
, "VTT for ");
4173 d_print_comp (dpi
, options
, d_left (dc
));
4176 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4177 d_append_string (dpi
, "construction vtable for ");
4178 d_print_comp (dpi
, options
, d_left (dc
));
4179 d_append_string (dpi
, "-in-");
4180 d_print_comp (dpi
, options
, d_right (dc
));
4183 case DEMANGLE_COMPONENT_TYPEINFO
:
4184 d_append_string (dpi
, "typeinfo for ");
4185 d_print_comp (dpi
, options
, d_left (dc
));
4188 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4189 d_append_string (dpi
, "typeinfo name for ");
4190 d_print_comp (dpi
, options
, d_left (dc
));
4193 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4194 d_append_string (dpi
, "typeinfo fn for ");
4195 d_print_comp (dpi
, options
, d_left (dc
));
4198 case DEMANGLE_COMPONENT_THUNK
:
4199 d_append_string (dpi
, "non-virtual thunk to ");
4200 d_print_comp (dpi
, options
, d_left (dc
));
4203 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4204 d_append_string (dpi
, "virtual thunk to ");
4205 d_print_comp (dpi
, options
, d_left (dc
));
4208 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4209 d_append_string (dpi
, "covariant return thunk to ");
4210 d_print_comp (dpi
, options
, d_left (dc
));
4213 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4214 d_append_string (dpi
, "java Class for ");
4215 d_print_comp (dpi
, options
, d_left (dc
));
4218 case DEMANGLE_COMPONENT_GUARD
:
4219 d_append_string (dpi
, "guard variable for ");
4220 d_print_comp (dpi
, options
, d_left (dc
));
4223 case DEMANGLE_COMPONENT_TLS_INIT
:
4224 d_append_string (dpi
, "TLS init function for ");
4225 d_print_comp (dpi
, options
, d_left (dc
));
4228 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4229 d_append_string (dpi
, "TLS wrapper function for ");
4230 d_print_comp (dpi
, options
, d_left (dc
));
4233 case DEMANGLE_COMPONENT_REFTEMP
:
4234 d_append_string (dpi
, "reference temporary #");
4235 d_print_comp (dpi
, options
, d_right (dc
));
4236 d_append_string (dpi
, " for ");
4237 d_print_comp (dpi
, options
, d_left (dc
));
4240 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4241 d_append_string (dpi
, "hidden alias for ");
4242 d_print_comp (dpi
, options
, d_left (dc
));
4245 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4246 d_append_string (dpi
, "transaction clone for ");
4247 d_print_comp (dpi
, options
, d_left (dc
));
4250 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4251 d_append_string (dpi
, "non-transaction clone for ");
4252 d_print_comp (dpi
, options
, d_left (dc
));
4255 case DEMANGLE_COMPONENT_SUB_STD
:
4256 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4259 case DEMANGLE_COMPONENT_RESTRICT
:
4260 case DEMANGLE_COMPONENT_VOLATILE
:
4261 case DEMANGLE_COMPONENT_CONST
:
4263 struct d_print_mod
*pdpm
;
4265 /* When printing arrays, it's possible to have cases where the
4266 same CV-qualifier gets pushed on the stack multiple times.
4267 We only need to print it once. */
4269 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4271 if (! pdpm
->printed
)
4273 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4274 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4275 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4277 if (pdpm
->mod
->type
== dc
->type
)
4279 d_print_comp (dpi
, options
, d_left (dc
));
4287 case DEMANGLE_COMPONENT_REFERENCE
:
4288 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4290 /* Handle reference smashing: & + && = &. */
4291 const struct demangle_component
*sub
= d_left (dc
);
4292 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4294 struct demangle_component
*a
= d_lookup_template_argument (dpi
, sub
);
4295 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4296 a
= d_index_template_argument (a
, dpi
->pack_index
);
4300 d_print_error (dpi
);
4307 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4308 || sub
->type
== dc
->type
)
4310 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4311 mod_inner
= d_left (sub
);
4315 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4316 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4317 case DEMANGLE_COMPONENT_CONST_THIS
:
4318 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4319 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4320 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4321 case DEMANGLE_COMPONENT_POINTER
:
4322 case DEMANGLE_COMPONENT_COMPLEX
:
4323 case DEMANGLE_COMPONENT_IMAGINARY
:
4326 /* We keep a list of modifiers on the stack. */
4327 struct d_print_mod dpm
;
4329 dpm
.next
= dpi
->modifiers
;
4330 dpi
->modifiers
= &dpm
;
4333 dpm
.templates
= dpi
->templates
;
4336 mod_inner
= d_left (dc
);
4338 d_print_comp (dpi
, options
, mod_inner
);
4340 /* If the modifier didn't get printed by the type, print it
4343 d_print_mod (dpi
, options
, dc
);
4345 dpi
->modifiers
= dpm
.next
;
4350 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4351 if ((options
& DMGL_JAVA
) == 0)
4352 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4353 dc
->u
.s_builtin
.type
->len
);
4355 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4356 dc
->u
.s_builtin
.type
->java_len
);
4359 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4360 d_print_comp (dpi
, options
, d_left (dc
));
4363 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4365 if ((options
& DMGL_RET_POSTFIX
) != 0)
4366 d_print_function_type (dpi
,
4367 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4368 dc
, dpi
->modifiers
);
4370 /* Print return type if present */
4371 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4372 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4374 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4376 struct d_print_mod dpm
;
4378 /* We must pass this type down as a modifier in order to
4379 print it in the right location. */
4380 dpm
.next
= dpi
->modifiers
;
4381 dpi
->modifiers
= &dpm
;
4384 dpm
.templates
= dpi
->templates
;
4386 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4389 dpi
->modifiers
= dpm
.next
;
4394 /* In standard prefix notation, there is a space between the
4395 return type and the function signature. */
4396 if ((options
& DMGL_RET_POSTFIX
) == 0)
4397 d_append_char (dpi
, ' ');
4400 if ((options
& DMGL_RET_POSTFIX
) == 0)
4401 d_print_function_type (dpi
,
4402 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4403 dc
, dpi
->modifiers
);
4408 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4410 struct d_print_mod
*hold_modifiers
;
4411 struct d_print_mod adpm
[4];
4413 struct d_print_mod
*pdpm
;
4415 /* We must pass this type down as a modifier in order to print
4416 multi-dimensional arrays correctly. If the array itself is
4417 CV-qualified, we act as though the element type were
4418 CV-qualified. We do this by copying the modifiers down
4419 rather than fiddling pointers, so that we don't wind up
4420 with a d_print_mod higher on the stack pointing into our
4421 stack frame after we return. */
4423 hold_modifiers
= dpi
->modifiers
;
4425 adpm
[0].next
= hold_modifiers
;
4426 dpi
->modifiers
= &adpm
[0];
4428 adpm
[0].printed
= 0;
4429 adpm
[0].templates
= dpi
->templates
;
4432 pdpm
= hold_modifiers
;
4434 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4435 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4436 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4438 if (! pdpm
->printed
)
4440 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4442 d_print_error (dpi
);
4447 adpm
[i
].next
= dpi
->modifiers
;
4448 dpi
->modifiers
= &adpm
[i
];
4456 d_print_comp (dpi
, options
, d_right (dc
));
4458 dpi
->modifiers
= hold_modifiers
;
4460 if (adpm
[0].printed
)
4466 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4469 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4474 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4475 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4477 struct d_print_mod dpm
;
4479 dpm
.next
= dpi
->modifiers
;
4480 dpi
->modifiers
= &dpm
;
4483 dpm
.templates
= dpi
->templates
;
4485 d_print_comp (dpi
, options
, d_right (dc
));
4487 /* If the modifier didn't get printed by the type, print it
4490 d_print_mod (dpi
, options
, dc
);
4492 dpi
->modifiers
= dpm
.next
;
4497 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4498 if (dc
->u
.s_fixed
.sat
)
4499 d_append_string (dpi
, "_Sat ");
4500 /* Don't print "int _Accum". */
4501 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4502 != &cplus_demangle_builtin_types
['i'-'a'])
4504 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
4505 d_append_char (dpi
, ' ');
4507 if (dc
->u
.s_fixed
.accum
)
4508 d_append_string (dpi
, "_Accum");
4510 d_append_string (dpi
, "_Fract");
4513 case DEMANGLE_COMPONENT_ARGLIST
:
4514 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4515 if (d_left (dc
) != NULL
)
4516 d_print_comp (dpi
, options
, d_left (dc
));
4517 if (d_right (dc
) != NULL
)
4520 unsigned long int flush_count
;
4521 /* Make sure ", " isn't flushed by d_append_string, otherwise
4522 dpi->len -= 2 wouldn't work. */
4523 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4524 d_print_flush (dpi
);
4525 d_append_string (dpi
, ", ");
4527 flush_count
= dpi
->flush_count
;
4528 d_print_comp (dpi
, options
, d_right (dc
));
4529 /* If that didn't print anything (which can happen with empty
4530 template argument packs), remove the comma and space. */
4531 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4536 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
4538 struct demangle_component
*type
= d_left (dc
);
4539 struct demangle_component
*list
= d_right (dc
);
4542 d_print_comp (dpi
, options
, type
);
4543 d_append_char (dpi
, '{');
4544 d_print_comp (dpi
, options
, list
);
4545 d_append_char (dpi
, '}');
4549 case DEMANGLE_COMPONENT_OPERATOR
:
4551 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
4554 d_append_string (dpi
, "operator");
4555 /* Add a space before new/delete. */
4556 if (IS_LOWER (op
->name
[0]))
4557 d_append_char (dpi
, ' ');
4558 /* Omit a trailing space. */
4559 if (op
->name
[len
-1] == ' ')
4561 d_append_buffer (dpi
, op
->name
, len
);
4565 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4566 d_append_string (dpi
, "operator ");
4567 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
4570 case DEMANGLE_COMPONENT_CAST
:
4571 d_append_string (dpi
, "operator ");
4572 d_print_cast (dpi
, options
, dc
);
4575 case DEMANGLE_COMPONENT_NULLARY
:
4576 d_print_expr_op (dpi
, options
, d_left (dc
));
4579 case DEMANGLE_COMPONENT_UNARY
:
4581 struct demangle_component
*op
= d_left (dc
);
4582 struct demangle_component
*operand
= d_right (dc
);
4583 const char *code
= NULL
;
4585 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4587 code
= op
->u
.s_operator
.op
->code
;
4588 if (!strcmp (code
, "ad"))
4590 /* Don't print the argument list for the address of a
4592 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
4593 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
4594 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4595 operand
= d_left (operand
);
4597 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
4599 /* This indicates a suffix operator. */
4600 operand
= d_left (operand
);
4601 d_print_subexpr (dpi
, options
, operand
);
4602 d_print_expr_op (dpi
, options
, op
);
4607 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
4608 d_print_expr_op (dpi
, options
, op
);
4611 d_append_char (dpi
, '(');
4612 d_print_cast (dpi
, options
, op
);
4613 d_append_char (dpi
, ')');
4615 if (code
&& !strcmp (code
, "gs"))
4616 /* Avoid parens after '::'. */
4617 d_print_comp (dpi
, options
, operand
);
4618 else if (code
&& !strcmp (code
, "st"))
4619 /* Always print parens for sizeof (type). */
4621 d_append_char (dpi
, '(');
4622 d_print_comp (dpi
, options
, operand
);
4623 d_append_char (dpi
, ')');
4626 d_print_subexpr (dpi
, options
, operand
);
4630 case DEMANGLE_COMPONENT_BINARY
:
4631 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4633 d_print_error (dpi
);
4637 if (op_is_new_cast (d_left (dc
)))
4639 d_print_expr_op (dpi
, options
, d_left (dc
));
4640 d_append_char (dpi
, '<');
4641 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
4642 d_append_string (dpi
, ">(");
4643 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
4644 d_append_char (dpi
, ')');
4648 /* We wrap an expression which uses the greater-than operator in
4649 an extra layer of parens so that it does not get confused
4650 with the '>' which ends the template parameters. */
4651 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4652 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4653 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4654 d_append_char (dpi
, '(');
4656 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
4657 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
4659 /* Function call used in an expression should not have printed types
4660 of the function arguments. Values of the function arguments still
4661 get printed below. */
4663 const struct demangle_component
*func
= d_left (d_right (dc
));
4665 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4666 d_print_error (dpi
);
4667 d_print_subexpr (dpi
, options
, d_left (func
));
4670 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
4671 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4673 d_append_char (dpi
, '[');
4674 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
4675 d_append_char (dpi
, ']');
4679 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4680 d_print_expr_op (dpi
, options
, d_left (dc
));
4681 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
4684 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4685 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4686 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4687 d_append_char (dpi
, ')');
4691 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4692 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4693 d_print_error (dpi
);
4696 case DEMANGLE_COMPONENT_TRINARY
:
4697 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4698 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4700 d_print_error (dpi
);
4704 struct demangle_component
*op
= d_left (dc
);
4705 struct demangle_component
*first
= d_left (d_right (dc
));
4706 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
4707 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
4709 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
4711 d_print_subexpr (dpi
, options
, first
);
4712 d_print_expr_op (dpi
, options
, op
);
4713 d_print_subexpr (dpi
, options
, second
);
4714 d_append_string (dpi
, " : ");
4715 d_print_subexpr (dpi
, options
, third
);
4719 d_append_string (dpi
, "new ");
4720 if (d_left (first
) != NULL
)
4722 d_print_subexpr (dpi
, options
, first
);
4723 d_append_char (dpi
, ' ');
4725 d_print_comp (dpi
, options
, second
);
4727 d_print_subexpr (dpi
, options
, third
);
4732 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4733 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4734 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4735 d_print_error (dpi
);
4738 case DEMANGLE_COMPONENT_LITERAL
:
4739 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4741 enum d_builtin_type_print tp
;
4743 /* For some builtin types, produce simpler output. */
4744 tp
= D_PRINT_DEFAULT
;
4745 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4747 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4751 case D_PRINT_UNSIGNED
:
4753 case D_PRINT_UNSIGNED_LONG
:
4754 case D_PRINT_LONG_LONG
:
4755 case D_PRINT_UNSIGNED_LONG_LONG
:
4756 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4758 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4759 d_append_char (dpi
, '-');
4760 d_print_comp (dpi
, options
, d_right (dc
));
4765 case D_PRINT_UNSIGNED
:
4766 d_append_char (dpi
, 'u');
4769 d_append_char (dpi
, 'l');
4771 case D_PRINT_UNSIGNED_LONG
:
4772 d_append_string (dpi
, "ul");
4774 case D_PRINT_LONG_LONG
:
4775 d_append_string (dpi
, "ll");
4777 case D_PRINT_UNSIGNED_LONG_LONG
:
4778 d_append_string (dpi
, "ull");
4786 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4787 && d_right (dc
)->u
.s_name
.len
== 1
4788 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4790 switch (d_right (dc
)->u
.s_name
.s
[0])
4793 d_append_string (dpi
, "false");
4796 d_append_string (dpi
, "true");
4809 d_append_char (dpi
, '(');
4810 d_print_comp (dpi
, options
, d_left (dc
));
4811 d_append_char (dpi
, ')');
4812 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4813 d_append_char (dpi
, '-');
4814 if (tp
== D_PRINT_FLOAT
)
4815 d_append_char (dpi
, '[');
4816 d_print_comp (dpi
, options
, d_right (dc
));
4817 if (tp
== D_PRINT_FLOAT
)
4818 d_append_char (dpi
, ']');
4822 case DEMANGLE_COMPONENT_NUMBER
:
4823 d_append_num (dpi
, dc
->u
.s_number
.number
);
4826 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4827 d_append_string (dpi
, "java resource ");
4828 d_print_comp (dpi
, options
, d_left (dc
));
4831 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4832 d_print_comp (dpi
, options
, d_left (dc
));
4833 d_print_comp (dpi
, options
, d_right (dc
));
4836 case DEMANGLE_COMPONENT_CHARACTER
:
4837 d_append_char (dpi
, dc
->u
.s_character
.character
);
4840 case DEMANGLE_COMPONENT_DECLTYPE
:
4841 d_append_string (dpi
, "decltype (");
4842 d_print_comp (dpi
, options
, d_left (dc
));
4843 d_append_char (dpi
, ')');
4846 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4850 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4853 /* d_find_pack won't find anything if the only packs involved
4854 in this expansion are function parameter packs; in that
4855 case, just print the pattern and "...". */
4856 d_print_subexpr (dpi
, options
, d_left (dc
));
4857 d_append_string (dpi
, "...");
4861 len
= d_pack_length (a
);
4863 for (i
= 0; i
< len
; ++i
)
4865 dpi
->pack_index
= i
;
4866 d_print_comp (dpi
, options
, dc
);
4868 d_append_string (dpi
, ", ");
4873 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4875 long num
= dc
->u
.s_number
.number
;
4877 d_append_string (dpi
, "this");
4880 d_append_string (dpi
, "{parm#");
4881 d_append_num (dpi
, num
);
4882 d_append_char (dpi
, '}');
4887 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4888 d_append_string (dpi
, "global constructors keyed to ");
4889 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
4892 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4893 d_append_string (dpi
, "global destructors keyed to ");
4894 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
4897 case DEMANGLE_COMPONENT_LAMBDA
:
4898 d_append_string (dpi
, "{lambda(");
4899 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
4900 d_append_string (dpi
, ")#");
4901 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4902 d_append_char (dpi
, '}');
4905 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4906 d_append_string (dpi
, "{unnamed type#");
4907 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4908 d_append_char (dpi
, '}');
4911 case DEMANGLE_COMPONENT_CLONE
:
4912 d_print_comp (dpi
, options
, d_left (dc
));
4913 d_append_string (dpi
, " [clone ");
4914 d_print_comp (dpi
, options
, d_right (dc
));
4915 d_append_char (dpi
, ']');
4919 d_print_error (dpi
);
4924 /* Print a Java dentifier. For Java we try to handle encoded extended
4925 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4926 so we don't it for C++. Characters are encoded as
4930 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
4936 for (p
= name
; p
< end
; ++p
)
4947 for (q
= p
+ 3; q
< end
; ++q
)
4953 else if (*q
>= 'A' && *q
<= 'F')
4954 dig
= *q
- 'A' + 10;
4955 else if (*q
>= 'a' && *q
<= 'f')
4956 dig
= *q
- 'a' + 10;
4962 /* If the Unicode character is larger than 256, we don't try
4963 to deal with it here. FIXME. */
4964 if (q
< end
&& *q
== '_' && c
< 256)
4966 d_append_char (dpi
, c
);
4972 d_append_char (dpi
, *p
);
4976 /* Print a list of modifiers. SUFFIX is 1 if we are printing
4977 qualifiers on this after printing a function. */
4980 d_print_mod_list (struct d_print_info
*dpi
, int options
,
4981 struct d_print_mod
*mods
, int suffix
)
4983 struct d_print_template
*hold_dpt
;
4985 if (mods
== NULL
|| d_print_saw_error (dpi
))
4990 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4991 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4992 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
4993 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4995 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
4997 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5003 hold_dpt
= dpi
->templates
;
5004 dpi
->templates
= mods
->templates
;
5006 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5008 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5009 dpi
->templates
= hold_dpt
;
5012 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5014 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5015 dpi
->templates
= hold_dpt
;
5018 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5020 struct d_print_mod
*hold_modifiers
;
5021 struct demangle_component
*dc
;
5023 /* When this is on the modifier stack, we have pulled any
5024 qualifiers off the right argument already. Otherwise, we
5025 print it as usual, but don't let the left argument see any
5028 hold_modifiers
= dpi
->modifiers
;
5029 dpi
->modifiers
= NULL
;
5030 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5031 dpi
->modifiers
= hold_modifiers
;
5033 if ((options
& DMGL_JAVA
) == 0)
5034 d_append_string (dpi
, "::");
5036 d_append_char (dpi
, '.');
5038 dc
= d_right (mods
->mod
);
5040 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5042 d_append_string (dpi
, "{default arg#");
5043 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5044 d_append_string (dpi
, "}::");
5045 dc
= dc
->u
.s_unary_num
.sub
;
5048 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5049 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5050 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5051 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5052 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5055 d_print_comp (dpi
, options
, dc
);
5057 dpi
->templates
= hold_dpt
;
5061 d_print_mod (dpi
, options
, mods
->mod
);
5063 dpi
->templates
= hold_dpt
;
5065 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5068 /* Print a modifier. */
5071 d_print_mod (struct d_print_info
*dpi
, int options
,
5072 const struct demangle_component
*mod
)
5076 case DEMANGLE_COMPONENT_RESTRICT
:
5077 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5078 d_append_string (dpi
, " restrict");
5080 case DEMANGLE_COMPONENT_VOLATILE
:
5081 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5082 d_append_string (dpi
, " volatile");
5084 case DEMANGLE_COMPONENT_CONST
:
5085 case DEMANGLE_COMPONENT_CONST_THIS
:
5086 d_append_string (dpi
, " const");
5088 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5089 d_append_char (dpi
, ' ');
5090 d_print_comp (dpi
, options
, d_right (mod
));
5092 case DEMANGLE_COMPONENT_POINTER
:
5093 /* There is no pointer symbol in Java. */
5094 if ((options
& DMGL_JAVA
) == 0)
5095 d_append_char (dpi
, '*');
5097 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5098 /* For the ref-qualifier, put a space before the &. */
5099 d_append_char (dpi
, ' ');
5100 case DEMANGLE_COMPONENT_REFERENCE
:
5101 d_append_char (dpi
, '&');
5103 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5104 d_append_char (dpi
, ' ');
5105 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5106 d_append_string (dpi
, "&&");
5108 case DEMANGLE_COMPONENT_COMPLEX
:
5109 d_append_string (dpi
, "complex ");
5111 case DEMANGLE_COMPONENT_IMAGINARY
:
5112 d_append_string (dpi
, "imaginary ");
5114 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5115 if (d_last_char (dpi
) != '(')
5116 d_append_char (dpi
, ' ');
5117 d_print_comp (dpi
, options
, d_left (mod
));
5118 d_append_string (dpi
, "::*");
5120 case DEMANGLE_COMPONENT_TYPED_NAME
:
5121 d_print_comp (dpi
, options
, d_left (mod
));
5123 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5124 d_append_string (dpi
, " __vector(");
5125 d_print_comp (dpi
, options
, d_left (mod
));
5126 d_append_char (dpi
, ')');
5130 /* Otherwise, we have something that won't go back on the
5131 modifier stack, so we can just print it. */
5132 d_print_comp (dpi
, options
, mod
);
5137 /* Print a function type, except for the return type. */
5140 d_print_function_type (struct d_print_info
*dpi
, int options
,
5141 const struct demangle_component
*dc
,
5142 struct d_print_mod
*mods
)
5146 struct d_print_mod
*p
;
5147 struct d_print_mod
*hold_modifiers
;
5151 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5156 switch (p
->mod
->type
)
5158 case DEMANGLE_COMPONENT_POINTER
:
5159 case DEMANGLE_COMPONENT_REFERENCE
:
5160 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5163 case DEMANGLE_COMPONENT_RESTRICT
:
5164 case DEMANGLE_COMPONENT_VOLATILE
:
5165 case DEMANGLE_COMPONENT_CONST
:
5166 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5167 case DEMANGLE_COMPONENT_COMPLEX
:
5168 case DEMANGLE_COMPONENT_IMAGINARY
:
5169 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5173 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5174 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5175 case DEMANGLE_COMPONENT_CONST_THIS
:
5176 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5177 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5190 if (d_last_char (dpi
) != '('
5191 && d_last_char (dpi
) != '*')
5194 if (need_space
&& d_last_char (dpi
) != ' ')
5195 d_append_char (dpi
, ' ');
5196 d_append_char (dpi
, '(');
5199 hold_modifiers
= dpi
->modifiers
;
5200 dpi
->modifiers
= NULL
;
5202 d_print_mod_list (dpi
, options
, mods
, 0);
5205 d_append_char (dpi
, ')');
5207 d_append_char (dpi
, '(');
5209 if (d_right (dc
) != NULL
)
5210 d_print_comp (dpi
, options
, d_right (dc
));
5212 d_append_char (dpi
, ')');
5214 d_print_mod_list (dpi
, options
, mods
, 1);
5216 dpi
->modifiers
= hold_modifiers
;
5219 /* Print an array type, except for the element type. */
5222 d_print_array_type (struct d_print_info
*dpi
, int options
,
5223 const struct demangle_component
*dc
,
5224 struct d_print_mod
*mods
)
5232 struct d_print_mod
*p
;
5235 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5239 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5254 d_append_string (dpi
, " (");
5256 d_print_mod_list (dpi
, options
, mods
, 0);
5259 d_append_char (dpi
, ')');
5263 d_append_char (dpi
, ' ');
5265 d_append_char (dpi
, '[');
5267 if (d_left (dc
) != NULL
)
5268 d_print_comp (dpi
, options
, d_left (dc
));
5270 d_append_char (dpi
, ']');
5273 /* Print an operator in an expression. */
5276 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5277 const struct demangle_component
*dc
)
5279 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5280 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5281 dc
->u
.s_operator
.op
->len
);
5283 d_print_comp (dpi
, options
, dc
);
5289 d_print_cast (struct d_print_info
*dpi
, int options
,
5290 const struct demangle_component
*dc
)
5292 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5293 d_print_comp (dpi
, options
, d_left (dc
));
5296 struct d_print_mod
*hold_dpm
;
5297 struct d_print_template dpt
;
5299 /* It appears that for a templated cast operator, we need to put
5300 the template parameters in scope for the operator name, but
5301 not for the parameters. The effect is that we need to handle
5302 the template printing here. */
5304 hold_dpm
= dpi
->modifiers
;
5305 dpi
->modifiers
= NULL
;
5307 dpt
.next
= dpi
->templates
;
5308 dpi
->templates
= &dpt
;
5309 dpt
.template_decl
= d_left (dc
);
5311 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5313 dpi
->templates
= dpt
.next
;
5315 if (d_last_char (dpi
) == '<')
5316 d_append_char (dpi
, ' ');
5317 d_append_char (dpi
, '<');
5318 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5319 /* Avoid generating two consecutive '>' characters, to avoid
5320 the C++ syntactic ambiguity. */
5321 if (d_last_char (dpi
) == '>')
5322 d_append_char (dpi
, ' ');
5323 d_append_char (dpi
, '>');
5325 dpi
->modifiers
= hold_dpm
;
5329 /* Initialize the information structure we use to pass around
5332 CP_STATIC_IF_GLIBCPP_V3
5334 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5338 di
->send
= mangled
+ len
;
5339 di
->options
= options
;
5343 /* We can not need more components than twice the number of chars in
5344 the mangled string. Most components correspond directly to
5345 chars, but the ARGLIST types are exceptions. */
5346 di
->num_comps
= 2 * len
;
5349 /* Similarly, we can not need more substitutions than there are
5350 chars in the mangled string. */
5355 di
->last_name
= NULL
;
5360 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5361 mangled name, return strings in repeated callback giving the demangled
5362 name. OPTIONS is the usual libiberty demangler options. On success,
5363 this returns 1. On failure, returns 0. */
5366 d_demangle_callback (const char *mangled
, int options
,
5367 demangle_callbackref callback
, void *opaque
)
5378 struct demangle_component
*dc
;
5381 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5383 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5384 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5385 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5386 && mangled
[10] == '_')
5387 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5390 if ((options
& DMGL_TYPES
) == 0)
5395 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5398 #ifdef CP_DYNAMIC_ARRAYS
5399 __extension__
struct demangle_component comps
[di
.num_comps
];
5400 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5405 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5406 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5412 dc
= cplus_demangle_type (&di
);
5415 dc
= cplus_demangle_mangled_name (&di
, 1);
5417 case DCT_GLOBAL_CTORS
:
5418 case DCT_GLOBAL_DTORS
:
5419 d_advance (&di
, 11);
5420 dc
= d_make_comp (&di
,
5421 (type
== DCT_GLOBAL_CTORS
5422 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5423 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5424 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5426 d_advance (&di
, strlen (d_str (&di
)));
5430 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5431 mangled string, then we didn't successfully demangle it. If
5432 DMGL_PARAMS is not set, we didn't look at the trailing
5434 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5437 #ifdef CP_DEMANGLE_DEBUG
5441 status
= (dc
!= NULL
)
5442 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
5449 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
5450 name, return a buffer allocated with malloc holding the demangled
5451 name. OPTIONS is the usual libiberty demangler options. On
5452 success, this sets *PALC to the allocated size of the returned
5453 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
5454 a memory allocation failure, and returns NULL. */
5457 d_demangle (const char *mangled
, int options
, size_t *palc
)
5459 struct d_growable_string dgs
;
5462 d_growable_string_init (&dgs
, 0);
5464 status
= d_demangle_callback (mangled
, options
,
5465 d_growable_string_callback_adapter
, &dgs
);
5473 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
5477 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5479 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5481 /* ia64 ABI-mandated entry point in the C++ runtime library for
5482 performing demangling. MANGLED_NAME is a NUL-terminated character
5483 string containing the name to be demangled.
5485 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5486 *LENGTH bytes, into which the demangled name is stored. If
5487 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5488 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5489 is placed in a region of memory allocated with malloc.
5491 If LENGTH is non-NULL, the length of the buffer containing the
5492 demangled name, is placed in *LENGTH.
5494 The return value is a pointer to the start of the NUL-terminated
5495 demangled name, or NULL if the demangling fails. The caller is
5496 responsible for deallocating this memory using free.
5498 *STATUS is set to one of the following values:
5499 0: The demangling operation succeeded.
5500 -1: A memory allocation failure occurred.
5501 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5502 -3: One of the arguments is invalid.
5504 The demangling is performed using the C++ ABI mangling rules, with
5508 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
5509 size_t *length
, int *status
)
5514 if (mangled_name
== NULL
)
5521 if (output_buffer
!= NULL
&& length
== NULL
)
5528 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
5530 if (demangled
== NULL
)
5542 if (output_buffer
== NULL
)
5549 if (strlen (demangled
) < *length
)
5551 strcpy (output_buffer
, demangled
);
5553 demangled
= output_buffer
;
5557 free (output_buffer
);
5568 extern int __gcclibcxx_demangle_callback (const char *,
5570 (const char *, size_t, void *),
5573 /* Alternative, allocationless entry point in the C++ runtime library
5574 for performing demangling. MANGLED_NAME is a NUL-terminated character
5575 string containing the name to be demangled.
5577 CALLBACK is a callback function, called with demangled string
5578 segments as demangling progresses; it is called at least once,
5579 but may be called more than once. OPAQUE is a generalized pointer
5580 used as a callback argument.
5582 The return code is one of the following values, equivalent to
5583 the STATUS values of __cxa_demangle() (excluding -1, since this
5584 function performs no memory allocations):
5585 0: The demangling operation succeeded.
5586 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5587 -3: One of the arguments is invalid.
5589 The demangling is performed using the C++ ABI mangling rules, with
5593 __gcclibcxx_demangle_callback (const char *mangled_name
,
5594 void (*callback
) (const char *, size_t, void *),
5599 if (mangled_name
== NULL
|| callback
== NULL
)
5602 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5610 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5612 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5613 mangled name, return a buffer allocated with malloc holding the
5614 demangled name. Otherwise, return NULL. */
5617 cplus_demangle_v3 (const char *mangled
, int options
)
5621 return d_demangle (mangled
, options
, &alc
);
5625 cplus_demangle_v3_callback (const char *mangled
, int options
,
5626 demangle_callbackref callback
, void *opaque
)
5628 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5631 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5632 conventions, but the output formatting is a little different.
5633 This instructs the C++ demangler not to emit pointer characters ("*"), to
5634 use Java's namespace separator symbol ("." instead of "::"), and to output
5635 JArray<TYPE> as TYPE[]. */
5638 java_demangle_v3 (const char *mangled
)
5642 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5646 java_demangle_v3_callback (const char *mangled
,
5647 demangle_callbackref callback
, void *opaque
)
5649 return d_demangle_callback (mangled
,
5650 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5654 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5656 #ifndef IN_GLIBCPP_V3
5658 /* Demangle a string in order to find out whether it is a constructor
5659 or destructor. Return non-zero on success. Set *CTOR_KIND and
5660 *DTOR_KIND appropriately. */
5663 is_ctor_or_dtor (const char *mangled
,
5664 enum gnu_v3_ctor_kinds
*ctor_kind
,
5665 enum gnu_v3_dtor_kinds
*dtor_kind
)
5668 struct demangle_component
*dc
;
5671 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5672 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5674 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5677 #ifdef CP_DYNAMIC_ARRAYS
5678 __extension__
struct demangle_component comps
[di
.num_comps
];
5679 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5684 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5685 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5688 dc
= cplus_demangle_mangled_name (&di
, 1);
5690 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5691 to demangle the entire string. */
5698 /* These cannot appear on a constructor or destructor. */
5699 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5700 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5701 case DEMANGLE_COMPONENT_CONST_THIS
:
5702 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5703 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5707 case DEMANGLE_COMPONENT_TYPED_NAME
:
5708 case DEMANGLE_COMPONENT_TEMPLATE
:
5711 case DEMANGLE_COMPONENT_QUAL_NAME
:
5712 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5715 case DEMANGLE_COMPONENT_CTOR
:
5716 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5720 case DEMANGLE_COMPONENT_DTOR
:
5721 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5732 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5733 name. A non-zero return indicates the type of constructor. */
5735 enum gnu_v3_ctor_kinds
5736 is_gnu_v3_mangled_ctor (const char *name
)
5738 enum gnu_v3_ctor_kinds ctor_kind
;
5739 enum gnu_v3_dtor_kinds dtor_kind
;
5741 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5742 return (enum gnu_v3_ctor_kinds
) 0;
5747 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5748 name. A non-zero return indicates the type of destructor. */
5750 enum gnu_v3_dtor_kinds
5751 is_gnu_v3_mangled_dtor (const char *name
)
5753 enum gnu_v3_ctor_kinds ctor_kind
;
5754 enum gnu_v3_dtor_kinds dtor_kind
;
5756 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5757 return (enum gnu_v3_dtor_kinds
) 0;
5761 #endif /* IN_GLIBCPP_V3 */
5763 #ifdef STANDALONE_DEMANGLER
5766 #include "dyn-string.h"
5768 static void print_usage (FILE* fp
, int exit_value
);
5770 #define IS_ALPHA(CHAR) \
5771 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5772 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5774 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5775 #define is_mangled_char(CHAR) \
5776 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5777 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5779 /* The name of this program, as invoked. */
5780 const char* program_name
;
5782 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5785 print_usage (FILE* fp
, int exit_value
)
5787 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5788 fprintf (fp
, "Options:\n");
5789 fprintf (fp
, " -h,--help Display this message.\n");
5790 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5791 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5792 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5797 /* Option specification for getopt_long. */
5798 static const struct option long_options
[] =
5800 { "help", no_argument
, NULL
, 'h' },
5801 { "no-params", no_argument
, NULL
, 'p' },
5802 { "verbose", no_argument
, NULL
, 'v' },
5803 { NULL
, no_argument
, NULL
, 0 },
5806 /* Main entry for a demangling filter executable. It will demangle
5807 its command line arguments, if any. If none are provided, it will
5808 filter stdin to stdout, replacing any recognized mangled C++ names
5809 with their demangled equivalents. */
5812 main (int argc
, char *argv
[])
5816 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5818 /* Use the program name of this program, as invoked. */
5819 program_name
= argv
[0];
5821 /* Parse options. */
5824 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5827 case '?': /* Unrecognized option. */
5828 print_usage (stderr
, 1);
5832 print_usage (stdout
, 0);
5836 options
&= ~ DMGL_PARAMS
;
5840 options
|= DMGL_VERBOSE
;
5844 while (opt_char
!= -1);
5847 /* No command line arguments were provided. Filter stdin. */
5849 dyn_string_t mangled
= dyn_string_new (3);
5852 /* Read all of input. */
5853 while (!feof (stdin
))
5857 /* Pile characters into mangled until we hit one that can't
5858 occur in a mangled name. */
5860 while (!feof (stdin
) && is_mangled_char (c
))
5862 dyn_string_append_char (mangled
, c
);
5868 if (dyn_string_length (mangled
) > 0)
5870 #ifdef IN_GLIBCPP_V3
5871 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
5873 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
5883 /* It might not have been a mangled name. Print the
5885 fputs (dyn_string_buf (mangled
), stdout
);
5888 dyn_string_clear (mangled
);
5891 /* If we haven't hit EOF yet, we've read one character that
5892 can't occur in a mangled name, so print it out. */
5897 dyn_string_delete (mangled
);
5900 /* Demangle command line arguments. */
5902 /* Loop over command line arguments. */
5903 for (i
= optind
; i
< argc
; ++i
)
5906 #ifdef IN_GLIBCPP_V3
5910 /* Attempt to demangle. */
5911 #ifdef IN_GLIBCPP_V3
5912 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
5914 s
= cplus_demangle_v3 (argv
[i
], options
);
5917 /* If it worked, print the demangled name. */
5925 #ifdef IN_GLIBCPP_V3
5926 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
5928 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
5937 #endif /* STANDALONE_DEMANGLER */