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_function_type (struct d_info
*);
387 static struct demangle_component
*
388 d_bare_function_type (struct d_info
*, int);
390 static struct demangle_component
*
391 d_class_enum_type (struct d_info
*);
393 static struct demangle_component
*d_array_type (struct d_info
*);
395 static struct demangle_component
*d_vector_type (struct d_info
*);
397 static struct demangle_component
*
398 d_pointer_to_member_type (struct d_info
*);
400 static struct demangle_component
*
401 d_template_param (struct d_info
*);
403 static struct demangle_component
*d_template_args (struct d_info
*);
405 static struct demangle_component
*
406 d_template_arg (struct d_info
*);
408 static struct demangle_component
*d_expression (struct d_info
*);
410 static struct demangle_component
*d_expr_primary (struct d_info
*);
412 static struct demangle_component
*d_local_name (struct d_info
*);
414 static int d_discriminator (struct d_info
*);
416 static struct demangle_component
*d_lambda (struct d_info
*);
418 static struct demangle_component
*d_unnamed_type (struct d_info
*);
420 static struct demangle_component
*
421 d_clone_suffix (struct d_info
*, struct demangle_component
*);
424 d_add_substitution (struct d_info
*, struct demangle_component
*);
426 static struct demangle_component
*d_substitution (struct d_info
*, int);
428 static void d_growable_string_init (struct d_growable_string
*, size_t);
431 d_growable_string_resize (struct d_growable_string
*, size_t);
434 d_growable_string_append_buffer (struct d_growable_string
*,
435 const char *, size_t);
437 d_growable_string_callback_adapter (const char *, size_t, void *);
440 d_print_init (struct d_print_info
*, demangle_callbackref
, void *);
442 static inline void d_print_error (struct d_print_info
*);
444 static inline int d_print_saw_error (struct d_print_info
*);
446 static inline void d_print_flush (struct d_print_info
*);
448 static inline void d_append_char (struct d_print_info
*, char);
450 static inline void d_append_buffer (struct d_print_info
*,
451 const char *, size_t);
453 static inline void d_append_string (struct d_print_info
*, const char *);
455 static inline char d_last_char (struct d_print_info
*);
458 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
461 d_print_java_identifier (struct d_print_info
*, const char *, int);
464 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
467 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
470 d_print_function_type (struct d_print_info
*, int,
471 const struct demangle_component
*,
472 struct d_print_mod
*);
475 d_print_array_type (struct d_print_info
*, int,
476 const struct demangle_component
*,
477 struct d_print_mod
*);
480 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
483 d_print_cast (struct d_print_info
*, int, const struct demangle_component
*);
485 static int d_demangle_callback (const char *, int,
486 demangle_callbackref
, void *);
487 static char *d_demangle (const char *, int, size_t *);
489 #ifdef CP_DEMANGLE_DEBUG
492 d_dump (struct demangle_component
*dc
, int indent
)
499 printf ("failed demangling\n");
503 for (i
= 0; i
< indent
; ++i
)
508 case DEMANGLE_COMPONENT_NAME
:
509 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
511 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
512 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
514 case DEMANGLE_COMPONENT_CTOR
:
515 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
516 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
518 case DEMANGLE_COMPONENT_DTOR
:
519 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
520 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
522 case DEMANGLE_COMPONENT_SUB_STD
:
523 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
525 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
526 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
528 case DEMANGLE_COMPONENT_OPERATOR
:
529 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
531 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
532 printf ("extended operator with %d args\n",
533 dc
->u
.s_extended_operator
.args
);
534 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
537 case DEMANGLE_COMPONENT_QUAL_NAME
:
538 printf ("qualified name\n");
540 case DEMANGLE_COMPONENT_LOCAL_NAME
:
541 printf ("local name\n");
543 case DEMANGLE_COMPONENT_TYPED_NAME
:
544 printf ("typed name\n");
546 case DEMANGLE_COMPONENT_TEMPLATE
:
547 printf ("template\n");
549 case DEMANGLE_COMPONENT_VTABLE
:
552 case DEMANGLE_COMPONENT_VTT
:
555 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
556 printf ("construction vtable\n");
558 case DEMANGLE_COMPONENT_TYPEINFO
:
559 printf ("typeinfo\n");
561 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
562 printf ("typeinfo name\n");
564 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
565 printf ("typeinfo function\n");
567 case DEMANGLE_COMPONENT_THUNK
:
570 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
571 printf ("virtual thunk\n");
573 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
574 printf ("covariant thunk\n");
576 case DEMANGLE_COMPONENT_JAVA_CLASS
:
577 printf ("java class\n");
579 case DEMANGLE_COMPONENT_GUARD
:
582 case DEMANGLE_COMPONENT_REFTEMP
:
583 printf ("reference temporary\n");
585 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
586 printf ("hidden alias\n");
588 case DEMANGLE_COMPONENT_RESTRICT
:
589 printf ("restrict\n");
591 case DEMANGLE_COMPONENT_VOLATILE
:
592 printf ("volatile\n");
594 case DEMANGLE_COMPONENT_CONST
:
597 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
598 printf ("restrict this\n");
600 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
601 printf ("volatile this\n");
603 case DEMANGLE_COMPONENT_CONST_THIS
:
604 printf ("const this\n");
606 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
607 printf ("vendor type qualifier\n");
609 case DEMANGLE_COMPONENT_POINTER
:
610 printf ("pointer\n");
612 case DEMANGLE_COMPONENT_REFERENCE
:
613 printf ("reference\n");
615 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
616 printf ("rvalue reference\n");
618 case DEMANGLE_COMPONENT_COMPLEX
:
619 printf ("complex\n");
621 case DEMANGLE_COMPONENT_IMAGINARY
:
622 printf ("imaginary\n");
624 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
625 printf ("vendor type\n");
627 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
628 printf ("function type\n");
630 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
631 printf ("array type\n");
633 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
634 printf ("pointer to member type\n");
636 case DEMANGLE_COMPONENT_FIXED_TYPE
:
637 printf ("fixed-point type\n");
639 case DEMANGLE_COMPONENT_ARGLIST
:
640 printf ("argument list\n");
642 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
643 printf ("template argument list\n");
645 case DEMANGLE_COMPONENT_CAST
:
648 case DEMANGLE_COMPONENT_UNARY
:
649 printf ("unary operator\n");
651 case DEMANGLE_COMPONENT_BINARY
:
652 printf ("binary operator\n");
654 case DEMANGLE_COMPONENT_BINARY_ARGS
:
655 printf ("binary operator arguments\n");
657 case DEMANGLE_COMPONENT_TRINARY
:
658 printf ("trinary operator\n");
660 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
661 printf ("trinary operator arguments 1\n");
663 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
664 printf ("trinary operator arguments 1\n");
666 case DEMANGLE_COMPONENT_LITERAL
:
667 printf ("literal\n");
669 case DEMANGLE_COMPONENT_LITERAL_NEG
:
670 printf ("negative literal\n");
672 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
673 printf ("java resource\n");
675 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
676 printf ("compound name\n");
678 case DEMANGLE_COMPONENT_CHARACTER
:
679 printf ("character '%c'\n", dc
->u
.s_character
.character
);
681 case DEMANGLE_COMPONENT_DECLTYPE
:
682 printf ("decltype\n");
684 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
685 printf ("pack expansion\n");
689 d_dump (d_left (dc
), indent
+ 2);
690 d_dump (d_right (dc
), indent
+ 2);
693 #endif /* CP_DEMANGLE_DEBUG */
695 /* Fill in a DEMANGLE_COMPONENT_NAME. */
697 CP_STATIC_IF_GLIBCPP_V3
699 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
701 if (p
== NULL
|| s
== NULL
|| len
== 0)
703 p
->type
= DEMANGLE_COMPONENT_NAME
;
705 p
->u
.s_name
.len
= len
;
709 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
711 CP_STATIC_IF_GLIBCPP_V3
713 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
714 struct demangle_component
*name
)
716 if (p
== NULL
|| args
< 0 || name
== NULL
)
718 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
719 p
->u
.s_extended_operator
.args
= args
;
720 p
->u
.s_extended_operator
.name
= name
;
724 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
726 CP_STATIC_IF_GLIBCPP_V3
728 cplus_demangle_fill_ctor (struct demangle_component
*p
,
729 enum gnu_v3_ctor_kinds kind
,
730 struct demangle_component
*name
)
734 || (int) kind
< gnu_v3_complete_object_ctor
735 || (int) kind
> gnu_v3_complete_object_allocating_ctor
)
737 p
->type
= DEMANGLE_COMPONENT_CTOR
;
738 p
->u
.s_ctor
.kind
= kind
;
739 p
->u
.s_ctor
.name
= name
;
743 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
745 CP_STATIC_IF_GLIBCPP_V3
747 cplus_demangle_fill_dtor (struct demangle_component
*p
,
748 enum gnu_v3_dtor_kinds kind
,
749 struct demangle_component
*name
)
753 || (int) kind
< gnu_v3_deleting_dtor
754 || (int) kind
> gnu_v3_base_object_dtor
)
756 p
->type
= DEMANGLE_COMPONENT_DTOR
;
757 p
->u
.s_dtor
.kind
= kind
;
758 p
->u
.s_dtor
.name
= name
;
762 /* Add a new component. */
764 static struct demangle_component
*
765 d_make_empty (struct d_info
*di
)
767 struct demangle_component
*p
;
769 if (di
->next_comp
>= di
->num_comps
)
771 p
= &di
->comps
[di
->next_comp
];
776 /* Add a new generic component. */
778 static struct demangle_component
*
779 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
780 struct demangle_component
*left
,
781 struct demangle_component
*right
)
783 struct demangle_component
*p
;
785 /* We check for errors here. A typical error would be a NULL return
786 from a subroutine. We catch those here, and return NULL
790 /* These types require two parameters. */
791 case DEMANGLE_COMPONENT_QUAL_NAME
:
792 case DEMANGLE_COMPONENT_LOCAL_NAME
:
793 case DEMANGLE_COMPONENT_TYPED_NAME
:
794 case DEMANGLE_COMPONENT_TEMPLATE
:
795 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
796 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
797 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
798 case DEMANGLE_COMPONENT_UNARY
:
799 case DEMANGLE_COMPONENT_BINARY
:
800 case DEMANGLE_COMPONENT_BINARY_ARGS
:
801 case DEMANGLE_COMPONENT_TRINARY
:
802 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
803 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
804 case DEMANGLE_COMPONENT_LITERAL
:
805 case DEMANGLE_COMPONENT_LITERAL_NEG
:
806 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
807 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
808 case DEMANGLE_COMPONENT_CLONE
:
809 if (left
== NULL
|| right
== NULL
)
813 /* These types only require one parameter. */
814 case DEMANGLE_COMPONENT_VTABLE
:
815 case DEMANGLE_COMPONENT_VTT
:
816 case DEMANGLE_COMPONENT_TYPEINFO
:
817 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
818 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
819 case DEMANGLE_COMPONENT_THUNK
:
820 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
821 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
822 case DEMANGLE_COMPONENT_JAVA_CLASS
:
823 case DEMANGLE_COMPONENT_GUARD
:
824 case DEMANGLE_COMPONENT_REFTEMP
:
825 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
826 case DEMANGLE_COMPONENT_POINTER
:
827 case DEMANGLE_COMPONENT_REFERENCE
:
828 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
829 case DEMANGLE_COMPONENT_COMPLEX
:
830 case DEMANGLE_COMPONENT_IMAGINARY
:
831 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
832 case DEMANGLE_COMPONENT_CAST
:
833 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
834 case DEMANGLE_COMPONENT_DECLTYPE
:
835 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
836 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
837 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
842 /* This needs a right parameter, but the left parameter can be
844 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
849 /* These are allowed to have no parameters--in some cases they
850 will be filled in later. */
851 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
852 case DEMANGLE_COMPONENT_RESTRICT
:
853 case DEMANGLE_COMPONENT_VOLATILE
:
854 case DEMANGLE_COMPONENT_CONST
:
855 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
856 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
857 case DEMANGLE_COMPONENT_CONST_THIS
:
858 case DEMANGLE_COMPONENT_ARGLIST
:
859 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
862 /* Other types should not be seen here. */
867 p
= d_make_empty (di
);
871 p
->u
.s_binary
.left
= left
;
872 p
->u
.s_binary
.right
= right
;
877 /* Add a new demangle mangled name component. */
879 static struct demangle_component
*
880 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
882 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
883 return d_make_name (di
, s
, strlen (s
));
885 return d_encoding (di
, 0);
888 /* Add a new name component. */
890 static struct demangle_component
*
891 d_make_name (struct d_info
*di
, const char *s
, int len
)
893 struct demangle_component
*p
;
895 p
= d_make_empty (di
);
896 if (! cplus_demangle_fill_name (p
, s
, len
))
901 /* Add a new builtin type component. */
903 static struct demangle_component
*
904 d_make_builtin_type (struct d_info
*di
,
905 const struct demangle_builtin_type_info
*type
)
907 struct demangle_component
*p
;
911 p
= d_make_empty (di
);
914 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
915 p
->u
.s_builtin
.type
= type
;
920 /* Add a new operator component. */
922 static struct demangle_component
*
923 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
925 struct demangle_component
*p
;
927 p
= d_make_empty (di
);
930 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
931 p
->u
.s_operator
.op
= op
;
936 /* Add a new extended operator component. */
938 static struct demangle_component
*
939 d_make_extended_operator (struct d_info
*di
, int args
,
940 struct demangle_component
*name
)
942 struct demangle_component
*p
;
944 p
= d_make_empty (di
);
945 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
950 static struct demangle_component
*
951 d_make_default_arg (struct d_info
*di
, int num
,
952 struct demangle_component
*sub
)
954 struct demangle_component
*p
= d_make_empty (di
);
957 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
958 p
->u
.s_unary_num
.num
= num
;
959 p
->u
.s_unary_num
.sub
= sub
;
964 /* Add a new constructor component. */
966 static struct demangle_component
*
967 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
968 struct demangle_component
*name
)
970 struct demangle_component
*p
;
972 p
= d_make_empty (di
);
973 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
978 /* Add a new destructor component. */
980 static struct demangle_component
*
981 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
982 struct demangle_component
*name
)
984 struct demangle_component
*p
;
986 p
= d_make_empty (di
);
987 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
992 /* Add a new template parameter. */
994 static struct demangle_component
*
995 d_make_template_param (struct d_info
*di
, long i
)
997 struct demangle_component
*p
;
999 p
= d_make_empty (di
);
1002 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1003 p
->u
.s_number
.number
= i
;
1008 /* Add a new function parameter. */
1010 static struct demangle_component
*
1011 d_make_function_param (struct d_info
*di
, long i
)
1013 struct demangle_component
*p
;
1015 p
= d_make_empty (di
);
1018 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1019 p
->u
.s_number
.number
= i
;
1024 /* Add a new standard substitution component. */
1026 static struct demangle_component
*
1027 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1029 struct demangle_component
*p
;
1031 p
= d_make_empty (di
);
1034 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1035 p
->u
.s_string
.string
= name
;
1036 p
->u
.s_string
.len
= len
;
1041 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1043 TOP_LEVEL is non-zero when called at the top level. */
1045 CP_STATIC_IF_GLIBCPP_V3
1046 struct demangle_component
*
1047 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1049 struct demangle_component
*p
;
1051 if (! d_check_char (di
, '_')
1052 /* Allow missing _ if not at toplevel to work around a
1053 bug in G++ abi-version=2 mangling; see the comment in
1054 write_template_arg. */
1057 if (! d_check_char (di
, 'Z'))
1059 p
= d_encoding (di
, top_level
);
1061 /* If at top level and parsing parameters, check for a clone
1063 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1064 while (d_peek_char (di
) == '.'
1065 && (IS_LOWER (d_peek_next_char (di
))
1066 || d_peek_next_char (di
) == '_'
1067 || IS_DIGIT (d_peek_next_char (di
))))
1068 p
= d_clone_suffix (di
, p
);
1073 /* Return whether a function should have a return type. The argument
1074 is the function name, which may be qualified in various ways. The
1075 rules are that template functions have return types with some
1076 exceptions, function types which are not part of a function name
1077 mangling have return types with some exceptions, and non-template
1078 function names do not have return types. The exceptions are that
1079 constructors, destructors, and conversion operators do not have
1083 has_return_type (struct demangle_component
*dc
)
1091 case DEMANGLE_COMPONENT_TEMPLATE
:
1092 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1093 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1094 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1095 case DEMANGLE_COMPONENT_CONST_THIS
:
1096 return has_return_type (d_left (dc
));
1100 /* Return whether a name is a constructor, a destructor, or a
1101 conversion operator. */
1104 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1112 case DEMANGLE_COMPONENT_QUAL_NAME
:
1113 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1114 return is_ctor_dtor_or_conversion (d_right (dc
));
1115 case DEMANGLE_COMPONENT_CTOR
:
1116 case DEMANGLE_COMPONENT_DTOR
:
1117 case DEMANGLE_COMPONENT_CAST
:
1122 /* <encoding> ::= <(function) name> <bare-function-type>
1126 TOP_LEVEL is non-zero when called at the top level, in which case
1127 if DMGL_PARAMS is not set we do not demangle the function
1128 parameters. We only set this at the top level, because otherwise
1129 we would not correctly demangle names in local scopes. */
1131 static struct demangle_component
*
1132 d_encoding (struct d_info
*di
, int top_level
)
1134 char peek
= d_peek_char (di
);
1136 if (peek
== 'G' || peek
== 'T')
1137 return d_special_name (di
);
1140 struct demangle_component
*dc
;
1144 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1146 /* Strip off any initial CV-qualifiers, as they really apply
1147 to the `this' parameter, and they were not output by the
1148 v2 demangler without DMGL_PARAMS. */
1149 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1150 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1151 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1154 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1155 there may be CV-qualifiers on its right argument which
1156 really apply here; this happens when parsing a class
1157 which is local to a function. */
1158 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1160 struct demangle_component
*dcr
;
1163 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1164 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1165 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1167 dc
->u
.s_binary
.right
= dcr
;
1173 peek
= d_peek_char (di
);
1174 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1176 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1177 d_bare_function_type (di
, has_return_type (dc
)));
1181 /* <name> ::= <nested-name>
1183 ::= <unscoped-template-name> <template-args>
1186 <unscoped-name> ::= <unqualified-name>
1187 ::= St <unqualified-name>
1189 <unscoped-template-name> ::= <unscoped-name>
1193 static struct demangle_component
*
1194 d_name (struct d_info
*di
)
1196 char peek
= d_peek_char (di
);
1197 struct demangle_component
*dc
;
1202 return d_nested_name (di
);
1205 return d_local_name (di
);
1209 return d_unqualified_name (di
);
1215 if (d_peek_next_char (di
) != 't')
1217 dc
= d_substitution (di
, 0);
1223 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1224 d_make_name (di
, "std", 3),
1225 d_unqualified_name (di
));
1230 if (d_peek_char (di
) != 'I')
1232 /* The grammar does not permit this case to occur if we
1233 called d_substitution() above (i.e., subst == 1). We
1234 don't bother to check. */
1238 /* This is <template-args>, which means that we just saw
1239 <unscoped-template-name>, which is a substitution
1240 candidate if we didn't just get it from a
1244 if (! d_add_substitution (di
, dc
))
1247 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1248 d_template_args (di
));
1255 dc
= d_unqualified_name (di
);
1256 if (d_peek_char (di
) == 'I')
1258 /* This is <template-args>, which means that we just saw
1259 <unscoped-template-name>, which is a substitution
1261 if (! d_add_substitution (di
, dc
))
1263 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1264 d_template_args (di
));
1270 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1271 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1274 static struct demangle_component
*
1275 d_nested_name (struct d_info
*di
)
1277 struct demangle_component
*ret
;
1278 struct demangle_component
**pret
;
1280 if (! d_check_char (di
, 'N'))
1283 pret
= d_cv_qualifiers (di
, &ret
, 1);
1287 *pret
= d_prefix (di
);
1291 if (! d_check_char (di
, 'E'))
1297 /* <prefix> ::= <prefix> <unqualified-name>
1298 ::= <template-prefix> <template-args>
1299 ::= <template-param>
1304 <template-prefix> ::= <prefix> <(template) unqualified-name>
1305 ::= <template-param>
1309 static struct demangle_component
*
1310 d_prefix (struct d_info
*di
)
1312 struct demangle_component
*ret
= NULL
;
1317 enum demangle_component_type comb_type
;
1318 struct demangle_component
*dc
;
1320 peek
= d_peek_char (di
);
1324 /* The older code accepts a <local-name> here, but I don't see
1325 that in the grammar. The older code does not accept a
1326 <template-param> here. */
1328 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1331 char peek2
= d_peek_next_char (di
);
1332 if (peek2
== 'T' || peek2
== 't')
1334 dc
= cplus_demangle_type (di
);
1336 /* Destructor name. */
1337 dc
= d_unqualified_name (di
);
1339 else if (IS_DIGIT (peek
)
1344 dc
= d_unqualified_name (di
);
1345 else if (peek
== 'S')
1346 dc
= d_substitution (di
, 1);
1347 else if (peek
== 'I')
1351 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1352 dc
= d_template_args (di
);
1354 else if (peek
== 'T')
1355 dc
= d_template_param (di
);
1356 else if (peek
== 'E')
1358 else if (peek
== 'M')
1360 /* Initializer scope for a lambda. We don't need to represent
1361 this; the normal code will just treat the variable as a type
1362 scope, which gives appropriate output. */
1374 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1376 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1378 if (! d_add_substitution (di
, ret
))
1384 /* <unqualified-name> ::= <operator-name>
1385 ::= <ctor-dtor-name>
1387 ::= <local-source-name>
1389 <local-source-name> ::= L <source-name> <discriminator>
1392 static struct demangle_component
*
1393 d_unqualified_name (struct d_info
*di
)
1397 peek
= d_peek_char (di
);
1398 if (IS_DIGIT (peek
))
1399 return d_source_name (di
);
1400 else if (IS_LOWER (peek
))
1402 struct demangle_component
*ret
;
1404 ret
= d_operator_name (di
);
1405 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1406 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1409 else if (peek
== 'C' || peek
== 'D')
1410 return d_ctor_dtor_name (di
);
1411 else if (peek
== 'L')
1413 struct demangle_component
* ret
;
1417 ret
= d_source_name (di
);
1420 if (! d_discriminator (di
))
1424 else if (peek
== 'U')
1426 switch (d_peek_next_char (di
))
1429 return d_lambda (di
);
1431 return d_unnamed_type (di
);
1440 /* <source-name> ::= <(positive length) number> <identifier> */
1442 static struct demangle_component
*
1443 d_source_name (struct d_info
*di
)
1446 struct demangle_component
*ret
;
1448 len
= d_number (di
);
1451 ret
= d_identifier (di
, len
);
1452 di
->last_name
= ret
;
1456 /* number ::= [n] <(non-negative decimal integer)> */
1459 d_number (struct d_info
*di
)
1466 peek
= d_peek_char (di
);
1471 peek
= d_peek_char (di
);
1477 if (! IS_DIGIT (peek
))
1483 ret
= ret
* 10 + peek
- '0';
1485 peek
= d_peek_char (di
);
1489 /* Like d_number, but returns a demangle_component. */
1491 static struct demangle_component
*
1492 d_number_component (struct d_info
*di
)
1494 struct demangle_component
*ret
= d_make_empty (di
);
1497 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1498 ret
->u
.s_number
.number
= d_number (di
);
1503 /* identifier ::= <(unqualified source code identifier)> */
1505 static struct demangle_component
*
1506 d_identifier (struct d_info
*di
, int len
)
1512 if (di
->send
- name
< len
)
1515 d_advance (di
, len
);
1517 /* A Java mangled name may have a trailing '$' if it is a C++
1518 keyword. This '$' is not included in the length count. We just
1520 if ((di
->options
& DMGL_JAVA
) != 0
1521 && d_peek_char (di
) == '$')
1524 /* Look for something which looks like a gcc encoding of an
1525 anonymous namespace, and replace it with a more user friendly
1527 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1528 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1529 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1533 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1534 if ((*s
== '.' || *s
== '_' || *s
== '$')
1537 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1538 return d_make_name (di
, "(anonymous namespace)",
1539 sizeof "(anonymous namespace)" - 1);
1543 return d_make_name (di
, name
, len
);
1546 /* operator_name ::= many different two character encodings.
1548 ::= v <digit> <source-name>
1551 #define NL(s) s, (sizeof s) - 1
1553 CP_STATIC_IF_GLIBCPP_V3
1554 const struct demangle_operator_info cplus_demangle_operators
[] =
1556 { "aN", NL ("&="), 2 },
1557 { "aS", NL ("="), 2 },
1558 { "aa", NL ("&&"), 2 },
1559 { "ad", NL ("&"), 1 },
1560 { "an", NL ("&"), 2 },
1561 { "cl", NL ("()"), 2 },
1562 { "cm", NL (","), 2 },
1563 { "co", NL ("~"), 1 },
1564 { "dV", NL ("/="), 2 },
1565 { "da", NL ("delete[]"), 1 },
1566 { "de", NL ("*"), 1 },
1567 { "dl", NL ("delete"), 1 },
1568 { "dt", NL ("."), 2 },
1569 { "dv", NL ("/"), 2 },
1570 { "eO", NL ("^="), 2 },
1571 { "eo", NL ("^"), 2 },
1572 { "eq", NL ("=="), 2 },
1573 { "ge", NL (">="), 2 },
1574 { "gt", NL (">"), 2 },
1575 { "ix", NL ("[]"), 2 },
1576 { "lS", NL ("<<="), 2 },
1577 { "le", NL ("<="), 2 },
1578 { "ls", NL ("<<"), 2 },
1579 { "lt", NL ("<"), 2 },
1580 { "mI", NL ("-="), 2 },
1581 { "mL", NL ("*="), 2 },
1582 { "mi", NL ("-"), 2 },
1583 { "ml", NL ("*"), 2 },
1584 { "mm", NL ("--"), 1 },
1585 { "na", NL ("new[]"), 1 },
1586 { "ne", NL ("!="), 2 },
1587 { "ng", NL ("-"), 1 },
1588 { "nt", NL ("!"), 1 },
1589 { "nw", NL ("new"), 1 },
1590 { "oR", NL ("|="), 2 },
1591 { "oo", NL ("||"), 2 },
1592 { "or", NL ("|"), 2 },
1593 { "pL", NL ("+="), 2 },
1594 { "pl", NL ("+"), 2 },
1595 { "pm", NL ("->*"), 2 },
1596 { "pp", NL ("++"), 1 },
1597 { "ps", NL ("+"), 1 },
1598 { "pt", NL ("->"), 2 },
1599 { "qu", NL ("?"), 3 },
1600 { "rM", NL ("%="), 2 },
1601 { "rS", NL (">>="), 2 },
1602 { "rm", NL ("%"), 2 },
1603 { "rs", NL (">>"), 2 },
1604 { "st", NL ("sizeof "), 1 },
1605 { "sz", NL ("sizeof "), 1 },
1606 { "at", NL ("alignof "), 1 },
1607 { "az", NL ("alignof "), 1 },
1608 { NULL
, NULL
, 0, 0 }
1611 static struct demangle_component
*
1612 d_operator_name (struct d_info
*di
)
1617 c1
= d_next_char (di
);
1618 c2
= d_next_char (di
);
1619 if (c1
== 'v' && IS_DIGIT (c2
))
1620 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1621 else if (c1
== 'c' && c2
== 'v')
1622 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1623 cplus_demangle_type (di
), NULL
);
1626 /* LOW is the inclusive lower bound. */
1628 /* HIGH is the exclusive upper bound. We subtract one to ignore
1629 the sentinel at the end of the array. */
1630 int high
= ((sizeof (cplus_demangle_operators
)
1631 / sizeof (cplus_demangle_operators
[0]))
1637 const struct demangle_operator_info
*p
;
1639 i
= low
+ (high
- low
) / 2;
1640 p
= cplus_demangle_operators
+ i
;
1642 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1643 return d_make_operator (di
, p
);
1645 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1655 static struct demangle_component
*
1656 d_make_character (struct d_info
*di
, int c
)
1658 struct demangle_component
*p
;
1659 p
= d_make_empty (di
);
1662 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1663 p
->u
.s_character
.character
= c
;
1668 static struct demangle_component
*
1669 d_java_resource (struct d_info
*di
)
1671 struct demangle_component
*p
= NULL
;
1672 struct demangle_component
*next
= NULL
;
1677 len
= d_number (di
);
1681 /* Eat the leading '_'. */
1682 if (d_next_char (di
) != '_')
1695 /* Each chunk is either a '$' escape... */
1713 next
= d_make_character (di
, c
);
1721 /* ... or a sequence of characters. */
1724 while (i
< len
&& str
[i
] && str
[i
] != '$')
1727 next
= d_make_name (di
, str
, i
);
1740 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1746 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1751 /* <special-name> ::= TV <type>
1755 ::= GV <(object) name>
1756 ::= T <call-offset> <(base) encoding>
1757 ::= Tc <call-offset> <call-offset> <(base) encoding>
1758 Also g++ extensions:
1759 ::= TC <type> <(offset) number> _ <(base) type>
1764 ::= Gr <resource name>
1767 static struct demangle_component
*
1768 d_special_name (struct d_info
*di
)
1770 di
->expansion
+= 20;
1771 if (d_check_char (di
, 'T'))
1773 switch (d_next_char (di
))
1777 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1778 cplus_demangle_type (di
), NULL
);
1780 di
->expansion
-= 10;
1781 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1782 cplus_demangle_type (di
), NULL
);
1784 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1785 cplus_demangle_type (di
), NULL
);
1787 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1788 cplus_demangle_type (di
), NULL
);
1791 if (! d_call_offset (di
, 'h'))
1793 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1794 d_encoding (di
, 0), NULL
);
1797 if (! d_call_offset (di
, 'v'))
1799 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1800 d_encoding (di
, 0), NULL
);
1803 if (! d_call_offset (di
, '\0'))
1805 if (! d_call_offset (di
, '\0'))
1807 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1808 d_encoding (di
, 0), NULL
);
1812 struct demangle_component
*derived_type
;
1814 struct demangle_component
*base_type
;
1816 derived_type
= cplus_demangle_type (di
);
1817 offset
= d_number (di
);
1820 if (! d_check_char (di
, '_'))
1822 base_type
= cplus_demangle_type (di
);
1823 /* We don't display the offset. FIXME: We should display
1824 it in verbose mode. */
1826 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1827 base_type
, derived_type
);
1831 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1832 cplus_demangle_type (di
), NULL
);
1834 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1835 cplus_demangle_type (di
), NULL
);
1841 else if (d_check_char (di
, 'G'))
1843 switch (d_next_char (di
))
1846 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1850 struct demangle_component
*name
= d_name (di
);
1851 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
1852 d_number_component (di
));
1856 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1857 d_encoding (di
, 0), NULL
);
1860 return d_java_resource (di
);
1870 /* <call-offset> ::= h <nv-offset> _
1873 <nv-offset> ::= <(offset) number>
1875 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1877 The C parameter, if not '\0', is a character we just read which is
1878 the start of the <call-offset>.
1880 We don't display the offset information anywhere. FIXME: We should
1881 display it in verbose mode. */
1884 d_call_offset (struct d_info
*di
, int c
)
1887 c
= d_next_char (di
);
1894 if (! d_check_char (di
, '_'))
1901 if (! d_check_char (di
, '_'))
1907 /* <ctor-dtor-name> ::= C1
1915 static struct demangle_component
*
1916 d_ctor_dtor_name (struct d_info
*di
)
1918 if (di
->last_name
!= NULL
)
1920 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1921 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1922 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1923 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1925 switch (d_peek_char (di
))
1929 enum gnu_v3_ctor_kinds kind
;
1931 switch (d_peek_next_char (di
))
1934 kind
= gnu_v3_complete_object_ctor
;
1937 kind
= gnu_v3_base_object_ctor
;
1940 kind
= gnu_v3_complete_object_allocating_ctor
;
1946 return d_make_ctor (di
, kind
, di
->last_name
);
1951 enum gnu_v3_dtor_kinds kind
;
1953 switch (d_peek_next_char (di
))
1956 kind
= gnu_v3_deleting_dtor
;
1959 kind
= gnu_v3_complete_object_dtor
;
1962 kind
= gnu_v3_base_object_dtor
;
1968 return d_make_dtor (di
, kind
, di
->last_name
);
1976 /* <type> ::= <builtin-type>
1978 ::= <class-enum-type>
1980 ::= <pointer-to-member-type>
1981 ::= <template-param>
1982 ::= <template-template-param> <template-args>
1984 ::= <CV-qualifiers> <type>
1987 ::= O <type> (C++0x)
1990 ::= U <source-name> <type>
1992 <builtin-type> ::= various one letter codes
1996 CP_STATIC_IF_GLIBCPP_V3
1997 const struct demangle_builtin_type_info
1998 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2000 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2001 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2002 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2003 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2004 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2005 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2006 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2007 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2008 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2009 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2010 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2011 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2012 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2013 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2014 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2016 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2017 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2018 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2019 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2020 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2021 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2022 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2023 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2024 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2025 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2026 D_PRINT_UNSIGNED_LONG_LONG
},
2027 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2028 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2029 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2030 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2031 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2032 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2033 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2034 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2038 CP_STATIC_IF_GLIBCPP_V3
2039 struct demangle_component
*
2040 cplus_demangle_type (struct d_info
*di
)
2043 struct demangle_component
*ret
;
2046 /* The ABI specifies that when CV-qualifiers are used, the base type
2047 is substitutable, and the fully qualified type is substitutable,
2048 but the base type with a strict subset of the CV-qualifiers is
2049 not substitutable. The natural recursive implementation of the
2050 CV-qualifiers would cause subsets to be substitutable, so instead
2051 we pull them all off now.
2053 FIXME: The ABI says that order-insensitive vendor qualifiers
2054 should be handled in the same way, but we have no way to tell
2055 which vendor qualifiers are order-insensitive and which are
2056 order-sensitive. So we just assume that they are all
2057 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2058 __vector, and it treats it as order-sensitive when mangling
2061 peek
= d_peek_char (di
);
2062 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2064 struct demangle_component
**pret
;
2066 pret
= d_cv_qualifiers (di
, &ret
, 0);
2069 *pret
= cplus_demangle_type (di
);
2070 if (! *pret
|| ! d_add_substitution (di
, ret
))
2079 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2080 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2081 case 'o': case 's': case 't':
2082 case 'v': case 'w': case 'x': case 'y': case 'z':
2083 ret
= d_make_builtin_type (di
,
2084 &cplus_demangle_builtin_types
[peek
- 'a']);
2085 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2092 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2093 d_source_name (di
), NULL
);
2097 ret
= d_function_type (di
);
2100 case '0': case '1': case '2': case '3': case '4':
2101 case '5': case '6': case '7': case '8': case '9':
2104 ret
= d_class_enum_type (di
);
2108 ret
= d_array_type (di
);
2112 ret
= d_pointer_to_member_type (di
);
2116 ret
= d_template_param (di
);
2117 if (d_peek_char (di
) == 'I')
2119 /* This is <template-template-param> <template-args>. The
2120 <template-template-param> part is a substitution
2122 if (! d_add_substitution (di
, ret
))
2124 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2125 d_template_args (di
));
2130 /* If this is a special substitution, then it is the start of
2131 <class-enum-type>. */
2135 peek_next
= d_peek_next_char (di
);
2136 if (IS_DIGIT (peek_next
)
2138 || IS_UPPER (peek_next
))
2140 ret
= d_substitution (di
, 0);
2141 /* The substituted name may have been a template name and
2142 may be followed by tepmlate args. */
2143 if (d_peek_char (di
) == 'I')
2144 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2145 d_template_args (di
));
2151 ret
= d_class_enum_type (di
);
2152 /* If the substitution was a complete type, then it is not
2153 a new substitution candidate. However, if the
2154 substitution was followed by template arguments, then
2155 the whole thing is a substitution candidate. */
2156 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2164 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2165 cplus_demangle_type (di
), NULL
);
2170 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2171 cplus_demangle_type (di
), NULL
);
2176 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2177 cplus_demangle_type (di
), NULL
);
2182 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2183 cplus_demangle_type (di
), NULL
);
2188 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2189 cplus_demangle_type (di
), NULL
);
2194 ret
= d_source_name (di
);
2195 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2196 cplus_demangle_type (di
), ret
);
2202 peek
= d_next_char (di
);
2207 /* decltype (expression) */
2208 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2209 d_expression (di
), NULL
);
2210 if (ret
&& d_next_char (di
) != 'E')
2215 /* Pack expansion. */
2216 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2217 cplus_demangle_type (di
), NULL
);
2221 /* 32-bit decimal floating point */
2222 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2223 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2227 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2228 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2232 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2233 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2236 /* 16-bit half-precision FP */
2237 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2238 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2242 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2243 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2247 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2248 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2252 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2253 ret
= d_make_empty (di
);
2254 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2255 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2256 /* For demangling we don't care about the bits. */
2258 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2259 if (ret
->u
.s_fixed
.length
== NULL
)
2262 peek
= d_next_char (di
);
2263 ret
->u
.s_fixed
.sat
= (peek
== 's');
2267 ret
= d_vector_type (di
);
2271 /* decltype(nullptr) */
2272 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2273 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2287 if (! d_add_substitution (di
, ret
))
2294 /* <CV-qualifiers> ::= [r] [V] [K] */
2296 static struct demangle_component
**
2297 d_cv_qualifiers (struct d_info
*di
,
2298 struct demangle_component
**pret
, int member_fn
)
2300 struct demangle_component
**pstart
;
2304 peek
= d_peek_char (di
);
2305 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2307 enum demangle_component_type t
;
2313 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2314 : DEMANGLE_COMPONENT_RESTRICT
);
2315 di
->expansion
+= sizeof "restrict";
2317 else if (peek
== 'V')
2320 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2321 : DEMANGLE_COMPONENT_VOLATILE
);
2322 di
->expansion
+= sizeof "volatile";
2327 ? DEMANGLE_COMPONENT_CONST_THIS
2328 : DEMANGLE_COMPONENT_CONST
);
2329 di
->expansion
+= sizeof "const";
2332 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2335 pret
= &d_left (*pret
);
2337 peek
= d_peek_char (di
);
2340 if (!member_fn
&& peek
== 'F')
2342 while (pstart
!= pret
)
2344 switch ((*pstart
)->type
)
2346 case DEMANGLE_COMPONENT_RESTRICT
:
2347 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2349 case DEMANGLE_COMPONENT_VOLATILE
:
2350 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2352 case DEMANGLE_COMPONENT_CONST
:
2353 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2358 pstart
= &d_left (*pstart
);
2365 /* <function-type> ::= F [Y] <bare-function-type> E */
2367 static struct demangle_component
*
2368 d_function_type (struct d_info
*di
)
2370 struct demangle_component
*ret
;
2372 if (! d_check_char (di
, 'F'))
2374 if (d_peek_char (di
) == 'Y')
2376 /* Function has C linkage. We don't print this information.
2377 FIXME: We should print it in verbose mode. */
2380 ret
= d_bare_function_type (di
, 1);
2381 if (! d_check_char (di
, 'E'))
2388 static struct demangle_component
*
2389 d_parmlist (struct d_info
*di
)
2391 struct demangle_component
*tl
;
2392 struct demangle_component
**ptl
;
2398 struct demangle_component
*type
;
2400 char peek
= d_peek_char (di
);
2401 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2403 type
= cplus_demangle_type (di
);
2406 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2409 ptl
= &d_right (*ptl
);
2412 /* There should be at least one parameter type besides the optional
2413 return type. A function which takes no arguments will have a
2414 single parameter type void. */
2418 /* If we have a single parameter type void, omit it. */
2419 if (d_right (tl
) == NULL
2420 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2421 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2423 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2430 /* <bare-function-type> ::= [J]<type>+ */
2432 static struct demangle_component
*
2433 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2435 struct demangle_component
*return_type
;
2436 struct demangle_component
*tl
;
2439 /* Detect special qualifier indicating that the first argument
2440 is the return type. */
2441 peek
= d_peek_char (di
);
2445 has_return_type
= 1;
2448 if (has_return_type
)
2450 return_type
= cplus_demangle_type (di
);
2451 if (return_type
== NULL
)
2457 tl
= d_parmlist (di
);
2461 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2465 /* <class-enum-type> ::= <name> */
2467 static struct demangle_component
*
2468 d_class_enum_type (struct d_info
*di
)
2473 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2474 ::= A [<(dimension) expression>] _ <(element) type>
2477 static struct demangle_component
*
2478 d_array_type (struct d_info
*di
)
2481 struct demangle_component
*dim
;
2483 if (! d_check_char (di
, 'A'))
2486 peek
= d_peek_char (di
);
2489 else if (IS_DIGIT (peek
))
2497 peek
= d_peek_char (di
);
2499 while (IS_DIGIT (peek
));
2500 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2506 dim
= d_expression (di
);
2511 if (! d_check_char (di
, '_'))
2514 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2515 cplus_demangle_type (di
));
2518 /* <vector-type> ::= Dv <number> _ <type>
2519 ::= Dv _ <expression> _ <type> */
2521 static struct demangle_component
*
2522 d_vector_type (struct d_info
*di
)
2525 struct demangle_component
*dim
;
2527 peek
= d_peek_char (di
);
2531 dim
= d_expression (di
);
2534 dim
= d_number_component (di
);
2539 if (! d_check_char (di
, '_'))
2542 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2543 cplus_demangle_type (di
));
2546 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2548 static struct demangle_component
*
2549 d_pointer_to_member_type (struct d_info
*di
)
2551 struct demangle_component
*cl
;
2552 struct demangle_component
*mem
;
2553 struct demangle_component
**pmem
;
2555 if (! d_check_char (di
, 'M'))
2558 cl
= cplus_demangle_type (di
);
2560 /* The ABI specifies that any type can be a substitution source, and
2561 that M is followed by two types, and that when a CV-qualified
2562 type is seen both the base type and the CV-qualified types are
2563 substitution sources. The ABI also specifies that for a pointer
2564 to a CV-qualified member function, the qualifiers are attached to
2565 the second type. Given the grammar, a plain reading of the ABI
2566 suggests that both the CV-qualified member function and the
2567 non-qualified member function are substitution sources. However,
2568 g++ does not work that way. g++ treats only the CV-qualified
2569 member function as a substitution source. FIXME. So to work
2570 with g++, we need to pull off the CV-qualifiers here, in order to
2571 avoid calling add_substitution() in cplus_demangle_type(). But
2572 for a CV-qualified member which is not a function, g++ does
2573 follow the ABI, so we need to handle that case here by calling
2574 d_add_substitution ourselves. */
2576 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2579 *pmem
= cplus_demangle_type (di
);
2583 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2585 if (! d_add_substitution (di
, mem
))
2589 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2592 /* <non-negative number> _ */
2595 d_compact_number (struct d_info
*di
)
2598 if (d_peek_char (di
) == '_')
2600 else if (d_peek_char (di
) == 'n')
2603 num
= d_number (di
) + 1;
2605 if (! d_check_char (di
, '_'))
2610 /* <template-param> ::= T_
2611 ::= T <(parameter-2 non-negative) number> _
2614 static struct demangle_component
*
2615 d_template_param (struct d_info
*di
)
2619 if (! d_check_char (di
, 'T'))
2622 param
= d_compact_number (di
);
2628 return d_make_template_param (di
, param
);
2631 /* <template-args> ::= I <template-arg>+ E */
2633 static struct demangle_component
*
2634 d_template_args (struct d_info
*di
)
2636 struct demangle_component
*hold_last_name
;
2637 struct demangle_component
*al
;
2638 struct demangle_component
**pal
;
2640 /* Preserve the last name we saw--don't let the template arguments
2641 clobber it, as that would give us the wrong name for a subsequent
2642 constructor or destructor. */
2643 hold_last_name
= di
->last_name
;
2645 if (! d_check_char (di
, 'I'))
2648 if (d_peek_char (di
) == 'E')
2650 /* An argument pack can be empty. */
2652 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2659 struct demangle_component
*a
;
2661 a
= d_template_arg (di
);
2665 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2668 pal
= &d_right (*pal
);
2670 if (d_peek_char (di
) == 'E')
2677 di
->last_name
= hold_last_name
;
2682 /* <template-arg> ::= <type>
2683 ::= X <expression> E
2687 static struct demangle_component
*
2688 d_template_arg (struct d_info
*di
)
2690 struct demangle_component
*ret
;
2692 switch (d_peek_char (di
))
2696 ret
= d_expression (di
);
2697 if (! d_check_char (di
, 'E'))
2702 return d_expr_primary (di
);
2705 /* An argument pack. */
2706 return d_template_args (di
);
2709 return cplus_demangle_type (di
);
2713 /* Subroutine of <expression> ::= cl <expression>+ E */
2715 static struct demangle_component
*
2716 d_exprlist (struct d_info
*di
)
2718 struct demangle_component
*list
= NULL
;
2719 struct demangle_component
**p
= &list
;
2721 if (d_peek_char (di
) == 'E')
2724 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
2729 struct demangle_component
*arg
= d_expression (di
);
2733 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
2738 if (d_peek_char (di
) == 'E')
2748 /* <expression> ::= <(unary) operator-name> <expression>
2749 ::= <(binary) operator-name> <expression> <expression>
2750 ::= <(trinary) operator-name> <expression> <expression> <expression>
2751 ::= cl <expression>+ E
2753 ::= <template-param>
2754 ::= sr <type> <unqualified-name>
2755 ::= sr <type> <unqualified-name> <template-args>
2759 static struct demangle_component
*
2760 d_expression (struct d_info
*di
)
2764 peek
= d_peek_char (di
);
2766 return d_expr_primary (di
);
2767 else if (peek
== 'T')
2768 return d_template_param (di
);
2769 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2771 struct demangle_component
*type
;
2772 struct demangle_component
*name
;
2775 type
= cplus_demangle_type (di
);
2776 name
= d_unqualified_name (di
);
2777 if (d_peek_char (di
) != 'I')
2778 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2780 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2781 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2782 d_template_args (di
)));
2784 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
2787 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2788 d_expression (di
), NULL
);
2790 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
2792 /* Function parameter used in a late-specified return type. */
2795 if (d_peek_char (di
) == 'T')
2797 /* 'this' parameter. */
2803 index
= d_compact_number (di
) + 1;
2807 return d_make_function_param (di
, index
);
2809 else if (IS_DIGIT (peek
)
2810 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
2812 /* We can get an unqualified name as an expression in the case of
2813 a dependent function call, i.e. decltype(f(t)). */
2814 struct demangle_component
*name
;
2817 /* operator-function-id, i.e. operator+(t). */
2820 name
= d_unqualified_name (di
);
2823 if (d_peek_char (di
) == 'I')
2824 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2825 d_template_args (di
));
2831 struct demangle_component
*op
;
2834 op
= d_operator_name (di
);
2838 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2839 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2841 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2842 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2843 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2844 cplus_demangle_type (di
));
2850 case DEMANGLE_COMPONENT_OPERATOR
:
2851 args
= op
->u
.s_operator
.op
->args
;
2853 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2854 args
= op
->u
.s_extended_operator
.args
;
2856 case DEMANGLE_COMPONENT_CAST
:
2865 struct demangle_component
*operand
;
2866 if (op
->type
== DEMANGLE_COMPONENT_CAST
2867 && d_check_char (di
, '_'))
2868 operand
= d_exprlist (di
);
2870 operand
= d_expression (di
);
2871 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2876 struct demangle_component
*left
;
2877 struct demangle_component
*right
;
2878 const char *code
= op
->u
.s_operator
.op
->code
;
2880 left
= d_expression (di
);
2881 if (!strcmp (code
, "cl"))
2882 right
= d_exprlist (di
);
2883 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
2885 right
= d_unqualified_name (di
);
2886 if (d_peek_char (di
) == 'I')
2887 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
2888 right
, d_template_args (di
));
2891 right
= d_expression (di
);
2893 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2895 DEMANGLE_COMPONENT_BINARY_ARGS
,
2900 struct demangle_component
*first
;
2901 struct demangle_component
*second
;
2903 first
= d_expression (di
);
2904 second
= d_expression (di
);
2905 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2907 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2910 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2912 d_expression (di
))));
2920 /* <expr-primary> ::= L <type> <(value) number> E
2921 ::= L <type> <(value) float> E
2922 ::= L <mangled-name> E
2925 static struct demangle_component
*
2926 d_expr_primary (struct d_info
*di
)
2928 struct demangle_component
*ret
;
2930 if (! d_check_char (di
, 'L'))
2932 if (d_peek_char (di
) == '_'
2933 /* Workaround for G++ bug; see comment in write_template_arg. */
2934 || d_peek_char (di
) == 'Z')
2935 ret
= cplus_demangle_mangled_name (di
, 0);
2938 struct demangle_component
*type
;
2939 enum demangle_component_type t
;
2942 type
= cplus_demangle_type (di
);
2946 /* If we have a type we know how to print, we aren't going to
2947 print the type name itself. */
2948 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2949 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2950 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2952 /* Rather than try to interpret the literal value, we just
2953 collect it as a string. Note that it's possible to have a
2954 floating point literal here. The ABI specifies that the
2955 format of such literals is machine independent. That's fine,
2956 but what's not fine is that versions of g++ up to 3.2 with
2957 -fabi-version=1 used upper case letters in the hex constant,
2958 and dumped out gcc's internal representation. That makes it
2959 hard to tell where the constant ends, and hard to dump the
2960 constant in any readable form anyhow. We don't attempt to
2961 handle these cases. */
2963 t
= DEMANGLE_COMPONENT_LITERAL
;
2964 if (d_peek_char (di
) == 'n')
2966 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2970 while (d_peek_char (di
) != 'E')
2972 if (d_peek_char (di
) == '\0')
2976 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2978 if (! d_check_char (di
, 'E'))
2983 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2984 ::= Z <(function) encoding> E s [<discriminator>]
2987 static struct demangle_component
*
2988 d_local_name (struct d_info
*di
)
2990 struct demangle_component
*function
;
2992 if (! d_check_char (di
, 'Z'))
2995 function
= d_encoding (di
, 0);
2997 if (! d_check_char (di
, 'E'))
3000 if (d_peek_char (di
) == 's')
3003 if (! d_discriminator (di
))
3005 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3006 d_make_name (di
, "string literal",
3007 sizeof "string literal" - 1));
3011 struct demangle_component
*name
;
3014 if (d_peek_char (di
) == 'd')
3016 /* Default argument scope: d <number> _. */
3018 num
= d_compact_number (di
);
3027 /* Lambdas and unnamed types have internal discriminators. */
3028 case DEMANGLE_COMPONENT_LAMBDA
:
3029 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3032 if (! d_discriminator (di
))
3036 name
= d_make_default_arg (di
, num
, name
);
3037 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3041 /* <discriminator> ::= _ <(non-negative) number>
3043 We demangle the discriminator, but we don't print it out. FIXME:
3044 We should print it out in verbose mode. */
3047 d_discriminator (struct d_info
*di
)
3051 if (d_peek_char (di
) != '_')
3054 discrim
= d_number (di
);
3060 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3062 static struct demangle_component
*
3063 d_lambda (struct d_info
*di
)
3065 struct demangle_component
*tl
;
3066 struct demangle_component
*ret
;
3069 if (! d_check_char (di
, 'U'))
3071 if (! d_check_char (di
, 'l'))
3074 tl
= d_parmlist (di
);
3078 if (! d_check_char (di
, 'E'))
3081 num
= d_compact_number (di
);
3085 ret
= d_make_empty (di
);
3088 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3089 ret
->u
.s_unary_num
.sub
= tl
;
3090 ret
->u
.s_unary_num
.num
= num
;
3093 if (! d_add_substitution (di
, ret
))
3099 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3101 static struct demangle_component
*
3102 d_unnamed_type (struct d_info
*di
)
3104 struct demangle_component
*ret
;
3107 if (! d_check_char (di
, 'U'))
3109 if (! d_check_char (di
, 't'))
3112 num
= d_compact_number (di
);
3116 ret
= d_make_empty (di
);
3119 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3120 ret
->u
.s_number
.number
= num
;
3123 if (! d_add_substitution (di
, ret
))
3129 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3132 static struct demangle_component
*
3133 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3135 const char *suffix
= d_str (di
);
3136 const char *pend
= suffix
;
3137 struct demangle_component
*n
;
3139 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3142 while (IS_LOWER (*pend
) || *pend
== '_')
3145 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3148 while (IS_DIGIT (*pend
))
3151 d_advance (di
, pend
- suffix
);
3152 n
= d_make_name (di
, suffix
, pend
- suffix
);
3153 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3156 /* Add a new substitution. */
3159 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3163 if (di
->next_sub
>= di
->num_subs
)
3165 di
->subs
[di
->next_sub
] = dc
;
3170 /* <substitution> ::= S <seq-id> _
3180 If PREFIX is non-zero, then this type is being used as a prefix in
3181 a qualified name. In this case, for the standard substitutions, we
3182 need to check whether we are being used as a prefix for a
3183 constructor or destructor, and return a full template name.
3184 Otherwise we will get something like std::iostream::~iostream()
3185 which does not correspond particularly well to any function which
3186 actually appears in the source.
3189 static const struct d_standard_sub_info standard_subs
[] =
3194 { 'a', NL ("std::allocator"),
3195 NL ("std::allocator"),
3197 { 'b', NL ("std::basic_string"),
3198 NL ("std::basic_string"),
3199 NL ("basic_string") },
3200 { 's', NL ("std::string"),
3201 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3202 NL ("basic_string") },
3203 { 'i', NL ("std::istream"),
3204 NL ("std::basic_istream<char, std::char_traits<char> >"),
3205 NL ("basic_istream") },
3206 { 'o', NL ("std::ostream"),
3207 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3208 NL ("basic_ostream") },
3209 { 'd', NL ("std::iostream"),
3210 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3211 NL ("basic_iostream") }
3214 static struct demangle_component
*
3215 d_substitution (struct d_info
*di
, int prefix
)
3219 if (! d_check_char (di
, 'S'))
3222 c
= d_next_char (di
);
3223 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3232 unsigned int new_id
;
3235 new_id
= id
* 36 + c
- '0';
3236 else if (IS_UPPER (c
))
3237 new_id
= id
* 36 + c
- 'A' + 10;
3243 c
= d_next_char (di
);
3250 if (id
>= (unsigned int) di
->next_sub
)
3255 return di
->subs
[id
];
3260 const struct d_standard_sub_info
*p
;
3261 const struct d_standard_sub_info
*pend
;
3263 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3264 if (! verbose
&& prefix
)
3268 peek
= d_peek_char (di
);
3269 if (peek
== 'C' || peek
== 'D')
3273 pend
= (&standard_subs
[0]
3274 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3275 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3282 if (p
->set_last_name
!= NULL
)
3283 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3284 p
->set_last_name_len
);
3287 s
= p
->full_expansion
;
3292 s
= p
->simple_expansion
;
3293 len
= p
->simple_len
;
3295 di
->expansion
+= len
;
3296 return d_make_sub (di
, s
, len
);
3304 /* Initialize a growable string. */
3307 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3312 dgs
->allocation_failure
= 0;
3315 d_growable_string_resize (dgs
, estimate
);
3318 /* Grow a growable string to a given size. */
3321 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3326 if (dgs
->allocation_failure
)
3329 /* Start allocation at two bytes to avoid any possibility of confusion
3330 with the special value of 1 used as a return in *palc to indicate
3331 allocation failures. */
3332 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3333 while (newalc
< need
)
3336 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3343 dgs
->allocation_failure
= 1;
3350 /* Append a buffer to a growable string. */
3353 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3354 const char *s
, size_t l
)
3358 need
= dgs
->len
+ l
+ 1;
3359 if (need
> dgs
->alc
)
3360 d_growable_string_resize (dgs
, need
);
3362 if (dgs
->allocation_failure
)
3365 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3366 dgs
->buf
[dgs
->len
+ l
] = '\0';
3370 /* Bridge growable strings to the callback mechanism. */
3373 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3375 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3377 d_growable_string_append_buffer (dgs
, s
, l
);
3380 /* Initialize a print information structure. */
3383 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
3387 dpi
->last_char
= '\0';
3388 dpi
->templates
= NULL
;
3389 dpi
->modifiers
= NULL
;
3390 dpi
->pack_index
= 0;
3391 dpi
->flush_count
= 0;
3393 dpi
->callback
= callback
;
3394 dpi
->opaque
= opaque
;
3396 dpi
->demangle_failure
= 0;
3399 /* Indicate that an error occurred during printing, and test for error. */
3402 d_print_error (struct d_print_info
*dpi
)
3404 dpi
->demangle_failure
= 1;
3408 d_print_saw_error (struct d_print_info
*dpi
)
3410 return dpi
->demangle_failure
!= 0;
3413 /* Flush buffered characters to the callback. */
3416 d_print_flush (struct d_print_info
*dpi
)
3418 dpi
->buf
[dpi
->len
] = '\0';
3419 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
3424 /* Append characters and buffers for printing. */
3427 d_append_char (struct d_print_info
*dpi
, char c
)
3429 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
3430 d_print_flush (dpi
);
3432 dpi
->buf
[dpi
->len
++] = c
;
3437 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
3441 for (i
= 0; i
< l
; i
++)
3442 d_append_char (dpi
, s
[i
]);
3446 d_append_string (struct d_print_info
*dpi
, const char *s
)
3448 d_append_buffer (dpi
, s
, strlen (s
));
3452 d_append_num (struct d_print_info
*dpi
, long l
)
3455 sprintf (buf
,"%ld", l
);
3456 d_append_string (dpi
, buf
);
3460 d_last_char (struct d_print_info
*dpi
)
3462 return dpi
->last_char
;
3465 /* Turn components into a human readable string. OPTIONS is the
3466 options bits passed to the demangler. DC is the tree to print.
3467 CALLBACK is a function to call to flush demangled string segments
3468 as they fill the intermediate buffer, and OPAQUE is a generalized
3469 callback argument. On success, this returns 1. On failure,
3470 it returns 0, indicating a bad parse. It does not use heap
3471 memory to build an output string, so cannot encounter memory
3472 allocation failure. */
3474 CP_STATIC_IF_GLIBCPP_V3
3476 cplus_demangle_print_callback (int options
,
3477 const struct demangle_component
*dc
,
3478 demangle_callbackref callback
, void *opaque
)
3480 struct d_print_info dpi
;
3482 d_print_init (&dpi
, callback
, opaque
);
3484 d_print_comp (&dpi
, options
, dc
);
3486 d_print_flush (&dpi
);
3488 return ! d_print_saw_error (&dpi
);
3491 /* Turn components into a human readable string. OPTIONS is the
3492 options bits passed to the demangler. DC is the tree to print.
3493 ESTIMATE is a guess at the length of the result. This returns a
3494 string allocated by malloc, or NULL on error. On success, this
3495 sets *PALC to the size of the allocated buffer. On failure, this
3496 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
3499 CP_STATIC_IF_GLIBCPP_V3
3501 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
3502 int estimate
, size_t *palc
)
3504 struct d_growable_string dgs
;
3506 d_growable_string_init (&dgs
, estimate
);
3508 if (! cplus_demangle_print_callback (options
, dc
,
3509 d_growable_string_callback_adapter
,
3517 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
3521 /* Returns the I'th element of the template arglist ARGS, or NULL on
3524 static struct demangle_component
*
3525 d_index_template_argument (struct demangle_component
*args
, int i
)
3527 struct demangle_component
*a
;
3533 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3539 if (i
!= 0 || a
== NULL
)
3545 /* Returns the template argument from the current context indicated by DC,
3546 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
3548 static struct demangle_component
*
3549 d_lookup_template_argument (struct d_print_info
*dpi
,
3550 const struct demangle_component
*dc
)
3552 if (dpi
->templates
== NULL
)
3554 d_print_error (dpi
);
3558 return d_index_template_argument
3559 (d_right (dpi
->templates
->template_decl
),
3560 dc
->u
.s_number
.number
);
3563 /* Returns a template argument pack used in DC (any will do), or NULL. */
3565 static struct demangle_component
*
3566 d_find_pack (struct d_print_info
*dpi
,
3567 const struct demangle_component
*dc
)
3569 struct demangle_component
*a
;
3575 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3576 a
= d_lookup_template_argument (dpi
, dc
);
3577 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3581 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3584 case DEMANGLE_COMPONENT_LAMBDA
:
3585 case DEMANGLE_COMPONENT_NAME
:
3586 case DEMANGLE_COMPONENT_OPERATOR
:
3587 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3588 case DEMANGLE_COMPONENT_SUB_STD
:
3589 case DEMANGLE_COMPONENT_CHARACTER
:
3590 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3593 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3594 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
3595 case DEMANGLE_COMPONENT_CTOR
:
3596 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
3597 case DEMANGLE_COMPONENT_DTOR
:
3598 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
3601 a
= d_find_pack (dpi
, d_left (dc
));
3604 return d_find_pack (dpi
, d_right (dc
));
3608 /* Returns the length of the template argument pack DC. */
3611 d_pack_length (const struct demangle_component
*dc
)
3614 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
3615 && d_left (dc
) != NULL
)
3623 /* DC is a component of a mangled expression. Print it, wrapped in parens
3627 d_print_subexpr (struct d_print_info
*dpi
, int options
,
3628 const struct demangle_component
*dc
)
3631 if (dc
->type
== DEMANGLE_COMPONENT_NAME
3632 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
3635 d_append_char (dpi
, '(');
3636 d_print_comp (dpi
, options
, dc
);
3638 d_append_char (dpi
, ')');
3641 /* Subroutine to handle components. */
3644 d_print_comp (struct d_print_info
*dpi
, int options
,
3645 const struct demangle_component
*dc
)
3647 /* Magic variable to let reference smashing skip over the next modifier
3648 without needing to modify *dc. */
3649 const struct demangle_component
*mod_inner
= NULL
;
3653 d_print_error (dpi
);
3656 if (d_print_saw_error (dpi
))
3661 case DEMANGLE_COMPONENT_NAME
:
3662 if ((options
& DMGL_JAVA
) == 0)
3663 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3665 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
3668 case DEMANGLE_COMPONENT_QUAL_NAME
:
3669 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3670 d_print_comp (dpi
, options
, d_left (dc
));
3671 if ((options
& DMGL_JAVA
) == 0)
3672 d_append_string (dpi
, "::");
3674 d_append_char (dpi
, '.');
3675 d_print_comp (dpi
, options
, d_right (dc
));
3678 case DEMANGLE_COMPONENT_TYPED_NAME
:
3680 struct d_print_mod
*hold_modifiers
;
3681 struct demangle_component
*typed_name
;
3682 struct d_print_mod adpm
[4];
3684 struct d_print_template dpt
;
3686 /* Pass the name down to the type so that it can be printed in
3687 the right place for the type. We also have to pass down
3688 any CV-qualifiers, which apply to the this parameter. */
3689 hold_modifiers
= dpi
->modifiers
;
3692 typed_name
= d_left (dc
);
3693 while (typed_name
!= NULL
)
3695 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3697 d_print_error (dpi
);
3701 adpm
[i
].next
= dpi
->modifiers
;
3702 dpi
->modifiers
= &adpm
[i
];
3703 adpm
[i
].mod
= typed_name
;
3704 adpm
[i
].printed
= 0;
3705 adpm
[i
].templates
= dpi
->templates
;
3708 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3709 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3710 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3713 typed_name
= d_left (typed_name
);
3716 if (typed_name
== NULL
)
3718 d_print_error (dpi
);
3722 /* If typed_name is a template, then it applies to the
3723 function type as well. */
3724 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3726 dpt
.next
= dpi
->templates
;
3727 dpi
->templates
= &dpt
;
3728 dpt
.template_decl
= typed_name
;
3731 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3732 there may be CV-qualifiers on its right argument which
3733 really apply here; this happens when parsing a class which
3734 is local to a function. */
3735 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3737 struct demangle_component
*local_name
;
3739 local_name
= d_right (typed_name
);
3740 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
3741 local_name
= local_name
->u
.s_unary_num
.sub
;
3742 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3743 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3744 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3746 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3748 d_print_error (dpi
);
3752 adpm
[i
] = adpm
[i
- 1];
3753 adpm
[i
].next
= &adpm
[i
- 1];
3754 dpi
->modifiers
= &adpm
[i
];
3756 adpm
[i
- 1].mod
= local_name
;
3757 adpm
[i
- 1].printed
= 0;
3758 adpm
[i
- 1].templates
= dpi
->templates
;
3761 local_name
= d_left (local_name
);
3765 d_print_comp (dpi
, options
, d_right (dc
));
3767 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3768 dpi
->templates
= dpt
.next
;
3770 /* If the modifiers didn't get printed by the type, print them
3775 if (! adpm
[i
].printed
)
3777 d_append_char (dpi
, ' ');
3778 d_print_mod (dpi
, options
, adpm
[i
].mod
);
3782 dpi
->modifiers
= hold_modifiers
;
3787 case DEMANGLE_COMPONENT_TEMPLATE
:
3789 struct d_print_mod
*hold_dpm
;
3790 struct demangle_component
*dcl
;
3792 /* Don't push modifiers into a template definition. Doing so
3793 could give the wrong definition for a template argument.
3794 Instead, treat the template essentially as a name. */
3796 hold_dpm
= dpi
->modifiers
;
3797 dpi
->modifiers
= NULL
;
3801 if ((options
& DMGL_JAVA
) != 0
3802 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3803 && dcl
->u
.s_name
.len
== 6
3804 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3806 /* Special-case Java arrays, so that JArray<TYPE> appears
3807 instead as TYPE[]. */
3809 d_print_comp (dpi
, options
, d_right (dc
));
3810 d_append_string (dpi
, "[]");
3814 d_print_comp (dpi
, options
, dcl
);
3815 if (d_last_char (dpi
) == '<')
3816 d_append_char (dpi
, ' ');
3817 d_append_char (dpi
, '<');
3818 d_print_comp (dpi
, options
, d_right (dc
));
3819 /* Avoid generating two consecutive '>' characters, to avoid
3820 the C++ syntactic ambiguity. */
3821 if (d_last_char (dpi
) == '>')
3822 d_append_char (dpi
, ' ');
3823 d_append_char (dpi
, '>');
3826 dpi
->modifiers
= hold_dpm
;
3831 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3833 struct d_print_template
*hold_dpt
;
3834 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
3836 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3837 a
= d_index_template_argument (a
, dpi
->pack_index
);
3841 d_print_error (dpi
);
3845 /* While processing this parameter, we need to pop the list of
3846 templates. This is because the template parameter may
3847 itself be a reference to a parameter of an outer
3850 hold_dpt
= dpi
->templates
;
3851 dpi
->templates
= hold_dpt
->next
;
3853 d_print_comp (dpi
, options
, a
);
3855 dpi
->templates
= hold_dpt
;
3860 case DEMANGLE_COMPONENT_CTOR
:
3861 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
3864 case DEMANGLE_COMPONENT_DTOR
:
3865 d_append_char (dpi
, '~');
3866 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
3869 case DEMANGLE_COMPONENT_VTABLE
:
3870 d_append_string (dpi
, "vtable for ");
3871 d_print_comp (dpi
, options
, d_left (dc
));
3874 case DEMANGLE_COMPONENT_VTT
:
3875 d_append_string (dpi
, "VTT for ");
3876 d_print_comp (dpi
, options
, d_left (dc
));
3879 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3880 d_append_string (dpi
, "construction vtable for ");
3881 d_print_comp (dpi
, options
, d_left (dc
));
3882 d_append_string (dpi
, "-in-");
3883 d_print_comp (dpi
, options
, d_right (dc
));
3886 case DEMANGLE_COMPONENT_TYPEINFO
:
3887 d_append_string (dpi
, "typeinfo for ");
3888 d_print_comp (dpi
, options
, d_left (dc
));
3891 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3892 d_append_string (dpi
, "typeinfo name for ");
3893 d_print_comp (dpi
, options
, d_left (dc
));
3896 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3897 d_append_string (dpi
, "typeinfo fn for ");
3898 d_print_comp (dpi
, options
, d_left (dc
));
3901 case DEMANGLE_COMPONENT_THUNK
:
3902 d_append_string (dpi
, "non-virtual thunk to ");
3903 d_print_comp (dpi
, options
, d_left (dc
));
3906 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3907 d_append_string (dpi
, "virtual thunk to ");
3908 d_print_comp (dpi
, options
, d_left (dc
));
3911 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3912 d_append_string (dpi
, "covariant return thunk to ");
3913 d_print_comp (dpi
, options
, d_left (dc
));
3916 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3917 d_append_string (dpi
, "java Class for ");
3918 d_print_comp (dpi
, options
, d_left (dc
));
3921 case DEMANGLE_COMPONENT_GUARD
:
3922 d_append_string (dpi
, "guard variable for ");
3923 d_print_comp (dpi
, options
, d_left (dc
));
3926 case DEMANGLE_COMPONENT_REFTEMP
:
3927 d_append_string (dpi
, "reference temporary #");
3928 d_print_comp (dpi
, options
, d_right (dc
));
3929 d_append_string (dpi
, " for ");
3930 d_print_comp (dpi
, options
, d_left (dc
));
3933 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3934 d_append_string (dpi
, "hidden alias for ");
3935 d_print_comp (dpi
, options
, d_left (dc
));
3938 case DEMANGLE_COMPONENT_SUB_STD
:
3939 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3942 case DEMANGLE_COMPONENT_RESTRICT
:
3943 case DEMANGLE_COMPONENT_VOLATILE
:
3944 case DEMANGLE_COMPONENT_CONST
:
3946 struct d_print_mod
*pdpm
;
3948 /* When printing arrays, it's possible to have cases where the
3949 same CV-qualifier gets pushed on the stack multiple times.
3950 We only need to print it once. */
3952 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3954 if (! pdpm
->printed
)
3956 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3957 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3958 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3960 if (pdpm
->mod
->type
== dc
->type
)
3962 d_print_comp (dpi
, options
, d_left (dc
));
3970 case DEMANGLE_COMPONENT_REFERENCE
:
3971 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3973 /* Handle reference smashing: & + && = &. */
3974 const struct demangle_component
*sub
= d_left (dc
);
3975 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
3977 struct demangle_component
*a
= d_lookup_template_argument (dpi
, sub
);
3978 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3979 a
= d_index_template_argument (a
, dpi
->pack_index
);
3983 d_print_error (dpi
);
3990 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
3991 || sub
->type
== dc
->type
)
3993 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
3994 mod_inner
= d_left (sub
);
3998 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3999 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4000 case DEMANGLE_COMPONENT_CONST_THIS
:
4001 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4002 case DEMANGLE_COMPONENT_POINTER
:
4003 case DEMANGLE_COMPONENT_COMPLEX
:
4004 case DEMANGLE_COMPONENT_IMAGINARY
:
4007 /* We keep a list of modifiers on the stack. */
4008 struct d_print_mod dpm
;
4010 dpm
.next
= dpi
->modifiers
;
4011 dpi
->modifiers
= &dpm
;
4014 dpm
.templates
= dpi
->templates
;
4017 mod_inner
= d_left (dc
);
4019 d_print_comp (dpi
, options
, mod_inner
);
4021 /* If the modifier didn't get printed by the type, print it
4024 d_print_mod (dpi
, options
, dc
);
4026 dpi
->modifiers
= dpm
.next
;
4031 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4032 if ((options
& DMGL_JAVA
) == 0)
4033 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4034 dc
->u
.s_builtin
.type
->len
);
4036 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4037 dc
->u
.s_builtin
.type
->java_len
);
4040 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4041 d_print_comp (dpi
, options
, d_left (dc
));
4044 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4046 if ((options
& DMGL_RET_POSTFIX
) != 0)
4047 d_print_function_type (dpi
,
4048 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4049 dc
, dpi
->modifiers
);
4051 /* Print return type if present */
4052 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4053 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4055 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4057 struct d_print_mod dpm
;
4059 /* We must pass this type down as a modifier in order to
4060 print it in the right location. */
4061 dpm
.next
= dpi
->modifiers
;
4062 dpi
->modifiers
= &dpm
;
4065 dpm
.templates
= dpi
->templates
;
4067 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4070 dpi
->modifiers
= dpm
.next
;
4075 /* In standard prefix notation, there is a space between the
4076 return type and the function signature. */
4077 if ((options
& DMGL_RET_POSTFIX
) == 0)
4078 d_append_char (dpi
, ' ');
4081 if ((options
& DMGL_RET_POSTFIX
) == 0)
4082 d_print_function_type (dpi
,
4083 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4084 dc
, dpi
->modifiers
);
4089 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4091 struct d_print_mod
*hold_modifiers
;
4092 struct d_print_mod adpm
[4];
4094 struct d_print_mod
*pdpm
;
4096 /* We must pass this type down as a modifier in order to print
4097 multi-dimensional arrays correctly. If the array itself is
4098 CV-qualified, we act as though the element type were
4099 CV-qualified. We do this by copying the modifiers down
4100 rather than fiddling pointers, so that we don't wind up
4101 with a d_print_mod higher on the stack pointing into our
4102 stack frame after we return. */
4104 hold_modifiers
= dpi
->modifiers
;
4106 adpm
[0].next
= hold_modifiers
;
4107 dpi
->modifiers
= &adpm
[0];
4109 adpm
[0].printed
= 0;
4110 adpm
[0].templates
= dpi
->templates
;
4113 pdpm
= hold_modifiers
;
4115 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4116 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4117 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4119 if (! pdpm
->printed
)
4121 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4123 d_print_error (dpi
);
4128 adpm
[i
].next
= dpi
->modifiers
;
4129 dpi
->modifiers
= &adpm
[i
];
4137 d_print_comp (dpi
, options
, d_right (dc
));
4139 dpi
->modifiers
= hold_modifiers
;
4141 if (adpm
[0].printed
)
4147 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4150 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4155 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4156 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4158 struct d_print_mod dpm
;
4160 dpm
.next
= dpi
->modifiers
;
4161 dpi
->modifiers
= &dpm
;
4164 dpm
.templates
= dpi
->templates
;
4166 d_print_comp (dpi
, options
, d_right (dc
));
4168 /* If the modifier didn't get printed by the type, print it
4171 d_print_mod (dpi
, options
, dc
);
4173 dpi
->modifiers
= dpm
.next
;
4178 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4179 if (dc
->u
.s_fixed
.sat
)
4180 d_append_string (dpi
, "_Sat ");
4181 /* Don't print "int _Accum". */
4182 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4183 != &cplus_demangle_builtin_types
['i'-'a'])
4185 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
4186 d_append_char (dpi
, ' ');
4188 if (dc
->u
.s_fixed
.accum
)
4189 d_append_string (dpi
, "_Accum");
4191 d_append_string (dpi
, "_Fract");
4194 case DEMANGLE_COMPONENT_ARGLIST
:
4195 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4196 if (d_left (dc
) != NULL
)
4197 d_print_comp (dpi
, options
, d_left (dc
));
4198 if (d_right (dc
) != NULL
)
4201 unsigned long int flush_count
;
4202 /* Make sure ", " isn't flushed by d_append_string, otherwise
4203 dpi->len -= 2 wouldn't work. */
4204 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4205 d_print_flush (dpi
);
4206 d_append_string (dpi
, ", ");
4208 flush_count
= dpi
->flush_count
;
4209 d_print_comp (dpi
, options
, d_right (dc
));
4210 /* If that didn't print anything (which can happen with empty
4211 template argument packs), remove the comma and space. */
4212 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
4217 case DEMANGLE_COMPONENT_OPERATOR
:
4221 d_append_string (dpi
, "operator");
4222 c
= dc
->u
.s_operator
.op
->name
[0];
4224 d_append_char (dpi
, ' ');
4225 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4226 dc
->u
.s_operator
.op
->len
);
4230 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4231 d_append_string (dpi
, "operator ");
4232 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
4235 case DEMANGLE_COMPONENT_CAST
:
4236 d_append_string (dpi
, "operator ");
4237 d_print_cast (dpi
, options
, dc
);
4240 case DEMANGLE_COMPONENT_UNARY
:
4241 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4242 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4243 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '&'
4244 && d_right (dc
)->type
== DEMANGLE_COMPONENT_TYPED_NAME
4245 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_QUAL_NAME
4246 && d_right (d_right (dc
))->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4248 /* Address of a function (therefore in an expression context) must
4249 have its argument list suppressed.
4251 unary operator ... dc
4252 operator & ... d_left (dc)
4253 typed name ... d_right (dc)
4254 qualified name ... d_left (d_right (dc))
4256 function type ... d_right (d_right (dc))
4260 d_print_expr_op (dpi
, options
, d_left (dc
));
4261 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
4264 else if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4265 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4266 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '&'
4267 && d_right (dc
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
)
4269 /* Keep also already processed variant without the argument list.
4271 unary operator ... dc
4272 operator & ... d_left (dc)
4273 qualified name ... d_right (dc)
4276 d_print_expr_op (dpi
, options
, d_left (dc
));
4277 d_print_comp (dpi
, options
, d_right (dc
));
4280 else if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
4281 d_print_expr_op (dpi
, options
, d_left (dc
));
4284 d_append_char (dpi
, '(');
4285 d_print_cast (dpi
, options
, d_left (dc
));
4286 d_append_char (dpi
, ')');
4288 d_print_subexpr (dpi
, options
, d_right (dc
));
4291 case DEMANGLE_COMPONENT_BINARY
:
4292 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
4294 d_print_error (dpi
);
4298 /* We wrap an expression which uses the greater-than operator in
4299 an extra layer of parens so that it does not get confused
4300 with the '>' which ends the template parameters. */
4301 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4302 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4303 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4304 d_append_char (dpi
, '(');
4306 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
4307 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
4309 /* Function call used in an expression should not have printed types
4310 of the function arguments. Values of the function arguments still
4311 get printed below. */
4313 const struct demangle_component
*func
= d_left (d_right (dc
));
4315 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4316 d_print_error (dpi
);
4317 d_print_subexpr (dpi
, options
, d_left (func
));
4320 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
4321 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
4323 d_append_char (dpi
, '[');
4324 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
4325 d_append_char (dpi
, ']');
4329 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
4330 d_print_expr_op (dpi
, options
, d_left (dc
));
4331 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
4334 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
4335 && d_left (dc
)->u
.s_operator
.op
->len
== 1
4336 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
4337 d_append_char (dpi
, ')');
4341 case DEMANGLE_COMPONENT_BINARY_ARGS
:
4342 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
4343 d_print_error (dpi
);
4346 case DEMANGLE_COMPONENT_TRINARY
:
4347 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
4348 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
4350 d_print_error (dpi
);
4353 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
4354 d_print_expr_op (dpi
, options
, d_left (dc
));
4355 d_print_subexpr (dpi
, options
, d_left (d_right (d_right (dc
))));
4356 d_append_string (dpi
, " : ");
4357 d_print_subexpr (dpi
, options
, d_right (d_right (d_right (dc
))));
4360 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
4361 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
4362 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
4363 d_print_error (dpi
);
4366 case DEMANGLE_COMPONENT_LITERAL
:
4367 case DEMANGLE_COMPONENT_LITERAL_NEG
:
4369 enum d_builtin_type_print tp
;
4371 /* For some builtin types, produce simpler output. */
4372 tp
= D_PRINT_DEFAULT
;
4373 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
4375 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
4379 case D_PRINT_UNSIGNED
:
4381 case D_PRINT_UNSIGNED_LONG
:
4382 case D_PRINT_LONG_LONG
:
4383 case D_PRINT_UNSIGNED_LONG_LONG
:
4384 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
4386 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4387 d_append_char (dpi
, '-');
4388 d_print_comp (dpi
, options
, d_right (dc
));
4393 case D_PRINT_UNSIGNED
:
4394 d_append_char (dpi
, 'u');
4397 d_append_char (dpi
, 'l');
4399 case D_PRINT_UNSIGNED_LONG
:
4400 d_append_string (dpi
, "ul");
4402 case D_PRINT_LONG_LONG
:
4403 d_append_string (dpi
, "ll");
4405 case D_PRINT_UNSIGNED_LONG_LONG
:
4406 d_append_string (dpi
, "ull");
4414 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
4415 && d_right (dc
)->u
.s_name
.len
== 1
4416 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
4418 switch (d_right (dc
)->u
.s_name
.s
[0])
4421 d_append_string (dpi
, "false");
4424 d_append_string (dpi
, "true");
4437 d_append_char (dpi
, '(');
4438 d_print_comp (dpi
, options
, d_left (dc
));
4439 d_append_char (dpi
, ')');
4440 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
4441 d_append_char (dpi
, '-');
4442 if (tp
== D_PRINT_FLOAT
)
4443 d_append_char (dpi
, '[');
4444 d_print_comp (dpi
, options
, d_right (dc
));
4445 if (tp
== D_PRINT_FLOAT
)
4446 d_append_char (dpi
, ']');
4450 case DEMANGLE_COMPONENT_NUMBER
:
4451 d_append_num (dpi
, dc
->u
.s_number
.number
);
4454 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4455 d_append_string (dpi
, "java resource ");
4456 d_print_comp (dpi
, options
, d_left (dc
));
4459 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4460 d_print_comp (dpi
, options
, d_left (dc
));
4461 d_print_comp (dpi
, options
, d_right (dc
));
4464 case DEMANGLE_COMPONENT_CHARACTER
:
4465 d_append_char (dpi
, dc
->u
.s_character
.character
);
4468 case DEMANGLE_COMPONENT_DECLTYPE
:
4469 d_append_string (dpi
, "decltype (");
4470 d_print_comp (dpi
, options
, d_left (dc
));
4471 d_append_char (dpi
, ')');
4474 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4478 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
4481 /* d_find_pack won't find anything if the only packs involved
4482 in this expansion are function parameter packs; in that
4483 case, just print the pattern and "...". */
4484 d_print_subexpr (dpi
, options
, d_left (dc
));
4485 d_append_string (dpi
, "...");
4489 len
= d_pack_length (a
);
4491 for (i
= 0; i
< len
; ++i
)
4493 dpi
->pack_index
= i
;
4494 d_print_comp (dpi
, options
, dc
);
4496 d_append_string (dpi
, ", ");
4501 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4503 long num
= dc
->u
.s_number
.number
;
4505 d_append_string (dpi
, "this");
4508 d_append_string (dpi
, "{parm#");
4509 d_append_num (dpi
, num
);
4510 d_append_char (dpi
, '}');
4515 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4516 d_append_string (dpi
, "global constructors keyed to ");
4517 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
4520 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4521 d_append_string (dpi
, "global destructors keyed to ");
4522 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
4525 case DEMANGLE_COMPONENT_LAMBDA
:
4526 d_append_string (dpi
, "{lambda(");
4527 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
4528 d_append_string (dpi
, ")#");
4529 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4530 d_append_char (dpi
, '}');
4533 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4534 d_append_string (dpi
, "{unnamed type#");
4535 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
4536 d_append_char (dpi
, '}');
4539 case DEMANGLE_COMPONENT_CLONE
:
4540 d_print_comp (dpi
, options
, d_left (dc
));
4541 d_append_string (dpi
, " [clone ");
4542 d_print_comp (dpi
, options
, d_right (dc
));
4543 d_append_char (dpi
, ']');
4547 d_print_error (dpi
);
4552 /* Print a Java dentifier. For Java we try to handle encoded extended
4553 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
4554 so we don't it for C++. Characters are encoded as
4558 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
4564 for (p
= name
; p
< end
; ++p
)
4575 for (q
= p
+ 3; q
< end
; ++q
)
4581 else if (*q
>= 'A' && *q
<= 'F')
4582 dig
= *q
- 'A' + 10;
4583 else if (*q
>= 'a' && *q
<= 'f')
4584 dig
= *q
- 'a' + 10;
4590 /* If the Unicode character is larger than 256, we don't try
4591 to deal with it here. FIXME. */
4592 if (q
< end
&& *q
== '_' && c
< 256)
4594 d_append_char (dpi
, c
);
4600 d_append_char (dpi
, *p
);
4604 /* Print a list of modifiers. SUFFIX is 1 if we are printing
4605 qualifiers on this after printing a function. */
4608 d_print_mod_list (struct d_print_info
*dpi
, int options
,
4609 struct d_print_mod
*mods
, int suffix
)
4611 struct d_print_template
*hold_dpt
;
4613 if (mods
== NULL
|| d_print_saw_error (dpi
))
4618 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4619 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4620 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
4622 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
4628 hold_dpt
= dpi
->templates
;
4629 dpi
->templates
= mods
->templates
;
4631 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
4633 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
4634 dpi
->templates
= hold_dpt
;
4637 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4639 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
4640 dpi
->templates
= hold_dpt
;
4643 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4645 struct d_print_mod
*hold_modifiers
;
4646 struct demangle_component
*dc
;
4648 /* When this is on the modifier stack, we have pulled any
4649 qualifiers off the right argument already. Otherwise, we
4650 print it as usual, but don't let the left argument see any
4653 hold_modifiers
= dpi
->modifiers
;
4654 dpi
->modifiers
= NULL
;
4655 d_print_comp (dpi
, options
, d_left (mods
->mod
));
4656 dpi
->modifiers
= hold_modifiers
;
4658 if ((options
& DMGL_JAVA
) == 0)
4659 d_append_string (dpi
, "::");
4661 d_append_char (dpi
, '.');
4663 dc
= d_right (mods
->mod
);
4665 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4667 d_append_string (dpi
, "{default arg#");
4668 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
4669 d_append_string (dpi
, "}::");
4670 dc
= dc
->u
.s_unary_num
.sub
;
4673 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4674 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4675 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
4678 d_print_comp (dpi
, options
, dc
);
4680 dpi
->templates
= hold_dpt
;
4684 d_print_mod (dpi
, options
, mods
->mod
);
4686 dpi
->templates
= hold_dpt
;
4688 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
4691 /* Print a modifier. */
4694 d_print_mod (struct d_print_info
*dpi
, int options
,
4695 const struct demangle_component
*mod
)
4699 case DEMANGLE_COMPONENT_RESTRICT
:
4700 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4701 d_append_string (dpi
, " restrict");
4703 case DEMANGLE_COMPONENT_VOLATILE
:
4704 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4705 d_append_string (dpi
, " volatile");
4707 case DEMANGLE_COMPONENT_CONST
:
4708 case DEMANGLE_COMPONENT_CONST_THIS
:
4709 d_append_string (dpi
, " const");
4711 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4712 d_append_char (dpi
, ' ');
4713 d_print_comp (dpi
, options
, d_right (mod
));
4715 case DEMANGLE_COMPONENT_POINTER
:
4716 /* There is no pointer symbol in Java. */
4717 if ((options
& DMGL_JAVA
) == 0)
4718 d_append_char (dpi
, '*');
4720 case DEMANGLE_COMPONENT_REFERENCE
:
4721 d_append_char (dpi
, '&');
4723 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4724 d_append_string (dpi
, "&&");
4726 case DEMANGLE_COMPONENT_COMPLEX
:
4727 d_append_string (dpi
, "complex ");
4729 case DEMANGLE_COMPONENT_IMAGINARY
:
4730 d_append_string (dpi
, "imaginary ");
4732 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4733 if (d_last_char (dpi
) != '(')
4734 d_append_char (dpi
, ' ');
4735 d_print_comp (dpi
, options
, d_left (mod
));
4736 d_append_string (dpi
, "::*");
4738 case DEMANGLE_COMPONENT_TYPED_NAME
:
4739 d_print_comp (dpi
, options
, d_left (mod
));
4741 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4742 d_append_string (dpi
, " __vector(");
4743 d_print_comp (dpi
, options
, d_left (mod
));
4744 d_append_char (dpi
, ')');
4748 /* Otherwise, we have something that won't go back on the
4749 modifier stack, so we can just print it. */
4750 d_print_comp (dpi
, options
, mod
);
4755 /* Print a function type, except for the return type. */
4758 d_print_function_type (struct d_print_info
*dpi
, int options
,
4759 const struct demangle_component
*dc
,
4760 struct d_print_mod
*mods
)
4764 struct d_print_mod
*p
;
4765 struct d_print_mod
*hold_modifiers
;
4769 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4774 switch (p
->mod
->type
)
4776 case DEMANGLE_COMPONENT_POINTER
:
4777 case DEMANGLE_COMPONENT_REFERENCE
:
4778 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4781 case DEMANGLE_COMPONENT_RESTRICT
:
4782 case DEMANGLE_COMPONENT_VOLATILE
:
4783 case DEMANGLE_COMPONENT_CONST
:
4784 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4785 case DEMANGLE_COMPONENT_COMPLEX
:
4786 case DEMANGLE_COMPONENT_IMAGINARY
:
4787 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4791 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4792 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4793 case DEMANGLE_COMPONENT_CONST_THIS
:
4806 if (d_last_char (dpi
) != '('
4807 && d_last_char (dpi
) != '*')
4810 if (need_space
&& d_last_char (dpi
) != ' ')
4811 d_append_char (dpi
, ' ');
4812 d_append_char (dpi
, '(');
4815 hold_modifiers
= dpi
->modifiers
;
4816 dpi
->modifiers
= NULL
;
4818 d_print_mod_list (dpi
, options
, mods
, 0);
4821 d_append_char (dpi
, ')');
4823 d_append_char (dpi
, '(');
4825 if (d_right (dc
) != NULL
)
4826 d_print_comp (dpi
, options
, d_right (dc
));
4828 d_append_char (dpi
, ')');
4830 d_print_mod_list (dpi
, options
, mods
, 1);
4832 dpi
->modifiers
= hold_modifiers
;
4835 /* Print an array type, except for the element type. */
4838 d_print_array_type (struct d_print_info
*dpi
, int options
,
4839 const struct demangle_component
*dc
,
4840 struct d_print_mod
*mods
)
4848 struct d_print_mod
*p
;
4851 for (p
= mods
; p
!= NULL
; p
= p
->next
)
4855 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
4870 d_append_string (dpi
, " (");
4872 d_print_mod_list (dpi
, options
, mods
, 0);
4875 d_append_char (dpi
, ')');
4879 d_append_char (dpi
, ' ');
4881 d_append_char (dpi
, '[');
4883 if (d_left (dc
) != NULL
)
4884 d_print_comp (dpi
, options
, d_left (dc
));
4886 d_append_char (dpi
, ']');
4889 /* Print an operator in an expression. */
4892 d_print_expr_op (struct d_print_info
*dpi
, int options
,
4893 const struct demangle_component
*dc
)
4895 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4896 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4897 dc
->u
.s_operator
.op
->len
);
4899 d_print_comp (dpi
, options
, dc
);
4905 d_print_cast (struct d_print_info
*dpi
, int options
,
4906 const struct demangle_component
*dc
)
4908 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4909 d_print_comp (dpi
, options
, d_left (dc
));
4912 struct d_print_mod
*hold_dpm
;
4913 struct d_print_template dpt
;
4915 /* It appears that for a templated cast operator, we need to put
4916 the template parameters in scope for the operator name, but
4917 not for the parameters. The effect is that we need to handle
4918 the template printing here. */
4920 hold_dpm
= dpi
->modifiers
;
4921 dpi
->modifiers
= NULL
;
4923 dpt
.next
= dpi
->templates
;
4924 dpi
->templates
= &dpt
;
4925 dpt
.template_decl
= d_left (dc
);
4927 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
4929 dpi
->templates
= dpt
.next
;
4931 if (d_last_char (dpi
) == '<')
4932 d_append_char (dpi
, ' ');
4933 d_append_char (dpi
, '<');
4934 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
4935 /* Avoid generating two consecutive '>' characters, to avoid
4936 the C++ syntactic ambiguity. */
4937 if (d_last_char (dpi
) == '>')
4938 d_append_char (dpi
, ' ');
4939 d_append_char (dpi
, '>');
4941 dpi
->modifiers
= hold_dpm
;
4945 /* Initialize the information structure we use to pass around
4948 CP_STATIC_IF_GLIBCPP_V3
4950 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4954 di
->send
= mangled
+ len
;
4955 di
->options
= options
;
4959 /* We can not need more components than twice the number of chars in
4960 the mangled string. Most components correspond directly to
4961 chars, but the ARGLIST types are exceptions. */
4962 di
->num_comps
= 2 * len
;
4965 /* Similarly, we can not need more substitutions than there are
4966 chars in the mangled string. */
4971 di
->last_name
= NULL
;
4976 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4977 mangled name, return strings in repeated callback giving the demangled
4978 name. OPTIONS is the usual libiberty demangler options. On success,
4979 this returns 1. On failure, returns 0. */
4982 d_demangle_callback (const char *mangled
, int options
,
4983 demangle_callbackref callback
, void *opaque
)
4994 struct demangle_component
*dc
;
4997 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4999 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5000 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5001 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5002 && mangled
[10] == '_')
5003 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5006 if ((options
& DMGL_TYPES
) == 0)
5011 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5014 #ifdef CP_DYNAMIC_ARRAYS
5015 __extension__
struct demangle_component comps
[di
.num_comps
];
5016 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5021 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5022 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5028 dc
= cplus_demangle_type (&di
);
5031 dc
= cplus_demangle_mangled_name (&di
, 1);
5033 case DCT_GLOBAL_CTORS
:
5034 case DCT_GLOBAL_DTORS
:
5035 d_advance (&di
, 11);
5036 dc
= d_make_comp (&di
,
5037 (type
== DCT_GLOBAL_CTORS
5038 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5039 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5040 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5042 d_advance (&di
, strlen (d_str (&di
)));
5046 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5047 mangled string, then we didn't successfully demangle it. If
5048 DMGL_PARAMS is not set, we didn't look at the trailing
5050 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5053 #ifdef CP_DEMANGLE_DEBUG
5057 status
= (dc
!= NULL
)
5058 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
5065 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
5066 name, return a buffer allocated with malloc holding the demangled
5067 name. OPTIONS is the usual libiberty demangler options. On
5068 success, this sets *PALC to the allocated size of the returned
5069 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
5070 a memory allocation failure, and returns NULL. */
5073 d_demangle (const char *mangled
, int options
, size_t *palc
)
5075 struct d_growable_string dgs
;
5078 d_growable_string_init (&dgs
, 0);
5080 status
= d_demangle_callback (mangled
, options
,
5081 d_growable_string_callback_adapter
, &dgs
);
5089 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
5093 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5095 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5097 /* ia64 ABI-mandated entry point in the C++ runtime library for
5098 performing demangling. MANGLED_NAME is a NUL-terminated character
5099 string containing the name to be demangled.
5101 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5102 *LENGTH bytes, into which the demangled name is stored. If
5103 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5104 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5105 is placed in a region of memory allocated with malloc.
5107 If LENGTH is non-NULL, the length of the buffer containing the
5108 demangled name, is placed in *LENGTH.
5110 The return value is a pointer to the start of the NUL-terminated
5111 demangled name, or NULL if the demangling fails. The caller is
5112 responsible for deallocating this memory using free.
5114 *STATUS is set to one of the following values:
5115 0: The demangling operation succeeded.
5116 -1: A memory allocation failure occurred.
5117 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5118 -3: One of the arguments is invalid.
5120 The demangling is performed using the C++ ABI mangling rules, with
5124 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
5125 size_t *length
, int *status
)
5130 if (mangled_name
== NULL
)
5137 if (output_buffer
!= NULL
&& length
== NULL
)
5144 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
5146 if (demangled
== NULL
)
5158 if (output_buffer
== NULL
)
5165 if (strlen (demangled
) < *length
)
5167 strcpy (output_buffer
, demangled
);
5169 demangled
= output_buffer
;
5173 free (output_buffer
);
5184 extern int __gcclibcxx_demangle_callback (const char *,
5186 (const char *, size_t, void *),
5189 /* Alternative, allocationless entry point in the C++ runtime library
5190 for performing demangling. MANGLED_NAME is a NUL-terminated character
5191 string containing the name to be demangled.
5193 CALLBACK is a callback function, called with demangled string
5194 segments as demangling progresses; it is called at least once,
5195 but may be called more than once. OPAQUE is a generalized pointer
5196 used as a callback argument.
5198 The return code is one of the following values, equivalent to
5199 the STATUS values of __cxa_demangle() (excluding -1, since this
5200 function performs no memory allocations):
5201 0: The demangling operation succeeded.
5202 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5203 -3: One of the arguments is invalid.
5205 The demangling is performed using the C++ ABI mangling rules, with
5209 __gcclibcxx_demangle_callback (const char *mangled_name
,
5210 void (*callback
) (const char *, size_t, void *),
5215 if (mangled_name
== NULL
|| callback
== NULL
)
5218 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
5226 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
5228 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
5229 mangled name, return a buffer allocated with malloc holding the
5230 demangled name. Otherwise, return NULL. */
5233 cplus_demangle_v3 (const char *mangled
, int options
)
5237 return d_demangle (mangled
, options
, &alc
);
5241 cplus_demangle_v3_callback (const char *mangled
, int options
,
5242 demangle_callbackref callback
, void *opaque
)
5244 return d_demangle_callback (mangled
, options
, callback
, opaque
);
5247 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
5248 conventions, but the output formatting is a little different.
5249 This instructs the C++ demangler not to emit pointer characters ("*"), to
5250 use Java's namespace separator symbol ("." instead of "::"), and to output
5251 JArray<TYPE> as TYPE[]. */
5254 java_demangle_v3 (const char *mangled
)
5258 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
5262 java_demangle_v3_callback (const char *mangled
,
5263 demangle_callbackref callback
, void *opaque
)
5265 return d_demangle_callback (mangled
,
5266 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
5270 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
5272 #ifndef IN_GLIBCPP_V3
5274 /* Demangle a string in order to find out whether it is a constructor
5275 or destructor. Return non-zero on success. Set *CTOR_KIND and
5276 *DTOR_KIND appropriately. */
5279 is_ctor_or_dtor (const char *mangled
,
5280 enum gnu_v3_ctor_kinds
*ctor_kind
,
5281 enum gnu_v3_dtor_kinds
*dtor_kind
)
5284 struct demangle_component
*dc
;
5287 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
5288 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
5290 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
5293 #ifdef CP_DYNAMIC_ARRAYS
5294 __extension__
struct demangle_component comps
[di
.num_comps
];
5295 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5300 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5301 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5304 dc
= cplus_demangle_mangled_name (&di
, 1);
5306 /* Note that because we did not pass DMGL_PARAMS, we don't expect
5307 to demangle the entire string. */
5317 case DEMANGLE_COMPONENT_TYPED_NAME
:
5318 case DEMANGLE_COMPONENT_TEMPLATE
:
5319 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5320 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5321 case DEMANGLE_COMPONENT_CONST_THIS
:
5324 case DEMANGLE_COMPONENT_QUAL_NAME
:
5325 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5328 case DEMANGLE_COMPONENT_CTOR
:
5329 *ctor_kind
= dc
->u
.s_ctor
.kind
;
5333 case DEMANGLE_COMPONENT_DTOR
:
5334 *dtor_kind
= dc
->u
.s_dtor
.kind
;
5345 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
5346 name. A non-zero return indicates the type of constructor. */
5348 enum gnu_v3_ctor_kinds
5349 is_gnu_v3_mangled_ctor (const char *name
)
5351 enum gnu_v3_ctor_kinds ctor_kind
;
5352 enum gnu_v3_dtor_kinds dtor_kind
;
5354 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5355 return (enum gnu_v3_ctor_kinds
) 0;
5360 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
5361 name. A non-zero return indicates the type of destructor. */
5363 enum gnu_v3_dtor_kinds
5364 is_gnu_v3_mangled_dtor (const char *name
)
5366 enum gnu_v3_ctor_kinds ctor_kind
;
5367 enum gnu_v3_dtor_kinds dtor_kind
;
5369 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
5370 return (enum gnu_v3_dtor_kinds
) 0;
5374 #endif /* IN_GLIBCPP_V3 */
5376 #ifdef STANDALONE_DEMANGLER
5379 #include "dyn-string.h"
5381 static void print_usage (FILE* fp
, int exit_value
);
5383 #define IS_ALPHA(CHAR) \
5384 (((CHAR) >= 'a' && (CHAR) <= 'z') \
5385 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
5387 /* Non-zero if CHAR is a character than can occur in a mangled name. */
5388 #define is_mangled_char(CHAR) \
5389 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
5390 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
5392 /* The name of this program, as invoked. */
5393 const char* program_name
;
5395 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
5398 print_usage (FILE* fp
, int exit_value
)
5400 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
5401 fprintf (fp
, "Options:\n");
5402 fprintf (fp
, " -h,--help Display this message.\n");
5403 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
5404 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
5405 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
5410 /* Option specification for getopt_long. */
5411 static const struct option long_options
[] =
5413 { "help", no_argument
, NULL
, 'h' },
5414 { "no-params", no_argument
, NULL
, 'p' },
5415 { "verbose", no_argument
, NULL
, 'v' },
5416 { NULL
, no_argument
, NULL
, 0 },
5419 /* Main entry for a demangling filter executable. It will demangle
5420 its command line arguments, if any. If none are provided, it will
5421 filter stdin to stdout, replacing any recognized mangled C++ names
5422 with their demangled equivalents. */
5425 main (int argc
, char *argv
[])
5429 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
5431 /* Use the program name of this program, as invoked. */
5432 program_name
= argv
[0];
5434 /* Parse options. */
5437 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
5440 case '?': /* Unrecognized option. */
5441 print_usage (stderr
, 1);
5445 print_usage (stdout
, 0);
5449 options
&= ~ DMGL_PARAMS
;
5453 options
|= DMGL_VERBOSE
;
5457 while (opt_char
!= -1);
5460 /* No command line arguments were provided. Filter stdin. */
5462 dyn_string_t mangled
= dyn_string_new (3);
5465 /* Read all of input. */
5466 while (!feof (stdin
))
5470 /* Pile characters into mangled until we hit one that can't
5471 occur in a mangled name. */
5473 while (!feof (stdin
) && is_mangled_char (c
))
5475 dyn_string_append_char (mangled
, c
);
5481 if (dyn_string_length (mangled
) > 0)
5483 #ifdef IN_GLIBCPP_V3
5484 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
5486 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
5496 /* It might not have been a mangled name. Print the
5498 fputs (dyn_string_buf (mangled
), stdout
);
5501 dyn_string_clear (mangled
);
5504 /* If we haven't hit EOF yet, we've read one character that
5505 can't occur in a mangled name, so print it out. */
5510 dyn_string_delete (mangled
);
5513 /* Demangle command line arguments. */
5515 /* Loop over command line arguments. */
5516 for (i
= optind
; i
< argc
; ++i
)
5519 #ifdef IN_GLIBCPP_V3
5523 /* Attempt to demangle. */
5524 #ifdef IN_GLIBCPP_V3
5525 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
5527 s
= cplus_demangle_v3 (argv
[i
], options
);
5530 /* If it worked, print the demangled name. */
5538 #ifdef IN_GLIBCPP_V3
5539 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
5541 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
5550 #endif /* STANDALONE_DEMANGLER */