1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@wasabisystems.com>.
5 This file is part of the libiberty library, which is part of GCC.
7 This file is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combined
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
31 /* This code implements a demangler for the g++ V3 ABI. The ABI is
32 described on this web page:
33 http://www.codesourcery.com/cxx-abi/abi.html#mangling
35 This code was written while looking at the demangler written by
36 Alex Samuel <samuel@codesourcery.com>.
38 This code first pulls the mangled name apart into a list of
39 components, and then walks the list generating the demangled
42 This file will normally define the following functions, q.v.:
43 char *cplus_demangle_v3(const char *mangled, int options)
44 char *java_demangle_v3(const char *mangled)
45 int cplus_demangle_v3_callback(const char *mangled, int options,
46 demangle_callbackref callback)
47 int java_demangle_v3_callback(const char *mangled,
48 demangle_callbackref callback)
49 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
50 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
52 Also, the interface to the component list is public, and defined in
53 demangle.h. The interface consists of these types, which are
54 defined in demangle.h:
55 enum demangle_component_type
56 struct demangle_component
58 and these functions defined in this file:
59 cplus_demangle_fill_name
60 cplus_demangle_fill_extended_operator
61 cplus_demangle_fill_ctor
62 cplus_demangle_fill_dtor
64 cplus_demangle_print_callback
65 and other functions defined in the file cp-demint.c.
67 This file also defines some other functions and variables which are
68 only to be used by the file cp-demint.c.
70 Preprocessor macros you can define while compiling this file:
73 If defined, this file defines the following functions, q.v.:
74 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
76 int __gcclibcxx_demangle_callback (const char *,
78 (const char *, size_t, void *),
80 instead of cplus_demangle_v3[_callback]() and
81 java_demangle_v3[_callback]().
84 If defined, this file defines only __cxa_demangle() and
85 __gcclibcxx_demangle_callback(), and no other publically visible
86 functions or variables.
89 If defined, this file defines a main() function which demangles
90 any arguments, or, if none, demangles stdin.
93 If defined, turns on debugging mode, which prints information on
94 stdout about the mangled string. This is not generally useful.
97 #if defined (_AIX) && !defined (__GNUC__)
119 # define alloca __builtin_alloca
121 extern char *alloca ();
122 # endif /* __GNUC__ */
124 #endif /* HAVE_ALLOCA_H */
126 #include "ansidecl.h"
127 #include "libiberty.h"
128 #include "demangle.h"
129 #include "cp-demangle.h"
131 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
132 also rename them via #define to avoid compiler errors when the
133 static definition conflicts with the extern declaration in a header
137 #define CP_STATIC_IF_GLIBCPP_V3 static
139 #define cplus_demangle_fill_name d_fill_name
140 static int d_fill_name (struct demangle_component
*, const char *, int);
142 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
144 d_fill_extended_operator (struct demangle_component
*, int,
145 struct demangle_component
*);
147 #define cplus_demangle_fill_ctor d_fill_ctor
149 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
150 struct demangle_component
*);
152 #define cplus_demangle_fill_dtor d_fill_dtor
154 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
155 struct demangle_component
*);
157 #define cplus_demangle_mangled_name d_mangled_name
158 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
160 #define cplus_demangle_type d_type
161 static struct demangle_component
*d_type (struct d_info
*);
163 #define cplus_demangle_print d_print
164 static char *d_print (int, const struct demangle_component
*, int, size_t *);
166 #define cplus_demangle_print_callback d_print_callback
167 static int d_print_callback (int, const struct demangle_component
*,
168 demangle_callbackref
, void *);
170 #define cplus_demangle_init_info d_init_info
171 static void d_init_info (const char *, int, size_t, struct d_info
*);
173 #else /* ! defined(IN_GLIBCPP_V3) */
174 #define CP_STATIC_IF_GLIBCPP_V3
175 #endif /* ! defined(IN_GLIBCPP_V3) */
177 /* See if the compiler supports dynamic arrays. */
180 #define CP_DYNAMIC_ARRAYS
183 #ifdef __STDC_VERSION__
184 #if __STDC_VERSION__ >= 199901L
185 #define CP_DYNAMIC_ARRAYS
186 #endif /* __STDC__VERSION >= 199901L */
187 #endif /* defined (__STDC_VERSION__) */
188 #endif /* defined (__STDC__) */
189 #endif /* ! defined (__GNUC__) */
191 /* We avoid pulling in the ctype tables, to prevent pulling in
192 additional unresolved symbols when this code is used in a library.
193 FIXME: Is this really a valid reason? This comes from the original
196 As of this writing this file has the following undefined references
197 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
200 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
201 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
202 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
204 /* The prefix prepended by GCC to an identifier represnting the
205 anonymous namespace. */
206 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
207 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
208 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
210 /* Information we keep for the standard substitutions. */
212 struct d_standard_sub_info
214 /* The code for this substitution. */
216 /* The simple string it expands to. */
217 const char *simple_expansion
;
218 /* The length of the simple expansion. */
220 /* The results of a full, verbose, expansion. This is used when
221 qualifying a constructor/destructor, or when in verbose mode. */
222 const char *full_expansion
;
223 /* The length of the full expansion. */
225 /* What to set the last_name field of d_info to; NULL if we should
226 not set it. This is only relevant when qualifying a
227 constructor/destructor. */
228 const char *set_last_name
;
229 /* The length of set_last_name. */
230 int set_last_name_len
;
233 /* Accessors for subtrees of struct demangle_component. */
235 #define d_left(dc) ((dc)->u.s_binary.left)
236 #define d_right(dc) ((dc)->u.s_binary.right)
238 /* A list of templates. This is used while printing. */
240 struct d_print_template
242 /* Next template on the list. */
243 struct d_print_template
*next
;
245 const struct demangle_component
*template_decl
;
248 /* A list of type modifiers. This is used while printing. */
252 /* Next modifier on the list. These are in the reverse of the order
253 in which they appeared in the mangled string. */
254 struct d_print_mod
*next
;
256 const struct demangle_component
*mod
;
257 /* Whether this modifier was printed. */
259 /* The list of templates which applies to this modifier. */
260 struct d_print_template
*templates
;
263 /* We use these structures to hold information during printing. */
265 struct d_growable_string
267 /* Buffer holding the result. */
269 /* Current length of data in buffer. */
271 /* Allocated size of buffer. */
273 /* Set to 1 if we had a memory allocation failure. */
274 int allocation_failure
;
277 enum { D_PRINT_BUFFER_LENGTH
= 256 };
280 /* The options passed to the demangler. */
282 /* Fixed-length allocated buffer for demangled data, flushed to the
283 callback with a NUL termination once full. */
284 char buf
[D_PRINT_BUFFER_LENGTH
];
285 /* Current length of data in buffer. */
287 /* The last character printed, saved individually so that it survives
290 /* Callback function to handle demangled buffer flush. */
291 demangle_callbackref callback
;
292 /* Opaque callback argument. */
294 /* The current list of templates, if any. */
295 struct d_print_template
*templates
;
296 /* The current list of modifiers (e.g., pointer, reference, etc.),
298 struct d_print_mod
*modifiers
;
299 /* Set to 1 if we saw a demangling error. */
300 int demangle_failure
;
303 #ifdef CP_DEMANGLE_DEBUG
304 static void d_dump (struct demangle_component
*, int);
307 static struct demangle_component
*
308 d_make_empty (struct d_info
*);
310 static struct demangle_component
*
311 d_make_comp (struct d_info
*, enum demangle_component_type
,
312 struct demangle_component
*,
313 struct demangle_component
*);
315 static struct demangle_component
*
316 d_make_name (struct d_info
*, const char *, int);
318 static struct demangle_component
*
319 d_make_builtin_type (struct d_info
*,
320 const struct demangle_builtin_type_info
*);
322 static struct demangle_component
*
323 d_make_operator (struct d_info
*,
324 const struct demangle_operator_info
*);
326 static struct demangle_component
*
327 d_make_extended_operator (struct d_info
*, int,
328 struct demangle_component
*);
330 static struct demangle_component
*
331 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
332 struct demangle_component
*);
334 static struct demangle_component
*
335 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
336 struct demangle_component
*);
338 static struct demangle_component
*
339 d_make_template_param (struct d_info
*, long);
341 static struct demangle_component
*
342 d_make_sub (struct d_info
*, const char *, int);
345 has_return_type (struct demangle_component
*);
348 is_ctor_dtor_or_conversion (struct demangle_component
*);
350 static struct demangle_component
*d_encoding (struct d_info
*, int);
352 static struct demangle_component
*d_name (struct d_info
*);
354 static struct demangle_component
*d_nested_name (struct d_info
*);
356 static struct demangle_component
*d_prefix (struct d_info
*);
358 static struct demangle_component
*d_unqualified_name (struct d_info
*);
360 static struct demangle_component
*d_source_name (struct d_info
*);
362 static long d_number (struct d_info
*);
364 static struct demangle_component
*d_identifier (struct d_info
*, int);
366 static struct demangle_component
*d_operator_name (struct d_info
*);
368 static struct demangle_component
*d_special_name (struct d_info
*);
370 static int d_call_offset (struct d_info
*, int);
372 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
374 static struct demangle_component
**
375 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
377 static struct demangle_component
*
378 d_function_type (struct d_info
*);
380 static struct demangle_component
*
381 d_bare_function_type (struct d_info
*, int);
383 static struct demangle_component
*
384 d_class_enum_type (struct d_info
*);
386 static struct demangle_component
*d_array_type (struct d_info
*);
388 static struct demangle_component
*
389 d_pointer_to_member_type (struct d_info
*);
391 static struct demangle_component
*
392 d_template_param (struct d_info
*);
394 static struct demangle_component
*d_template_args (struct d_info
*);
396 static struct demangle_component
*
397 d_template_arg (struct d_info
*);
399 static struct demangle_component
*d_expression (struct d_info
*);
401 static struct demangle_component
*d_expr_primary (struct d_info
*);
403 static struct demangle_component
*d_local_name (struct d_info
*);
405 static int d_discriminator (struct d_info
*);
408 d_add_substitution (struct d_info
*, struct demangle_component
*);
410 static struct demangle_component
*d_substitution (struct d_info
*, int);
412 static void d_growable_string_init (struct d_growable_string
*, size_t);
415 d_growable_string_resize (struct d_growable_string
*, size_t);
418 d_growable_string_append_buffer (struct d_growable_string
*,
419 const char *, size_t);
421 d_growable_string_callback_adapter (const char *, size_t, void *);
424 d_print_init (struct d_print_info
*, int, demangle_callbackref
, void *);
426 static inline void d_print_error (struct d_print_info
*);
428 static inline int d_print_saw_error (struct d_print_info
*);
430 static inline void d_print_flush (struct d_print_info
*);
432 static inline void d_append_char (struct d_print_info
*, char);
434 static inline void d_append_buffer (struct d_print_info
*,
435 const char *, size_t);
437 static inline void d_append_string (struct d_print_info
*, const char *);
439 static inline char d_last_char (struct d_print_info
*);
442 d_print_comp (struct d_print_info
*, const struct demangle_component
*);
445 d_print_java_identifier (struct d_print_info
*, const char *, int);
448 d_print_mod_list (struct d_print_info
*, struct d_print_mod
*, int);
451 d_print_mod (struct d_print_info
*, const struct demangle_component
*);
454 d_print_function_type (struct d_print_info
*,
455 const struct demangle_component
*,
456 struct d_print_mod
*);
459 d_print_array_type (struct d_print_info
*,
460 const struct demangle_component
*,
461 struct d_print_mod
*);
464 d_print_expr_op (struct d_print_info
*, const struct demangle_component
*);
467 d_print_cast (struct d_print_info
*, const struct demangle_component
*);
469 static int d_demangle_callback (const char *, int,
470 demangle_callbackref
, void *);
471 static char *d_demangle (const char *, int, size_t *);
473 #ifdef CP_DEMANGLE_DEBUG
476 d_dump (struct demangle_component
*dc
, int indent
)
483 printf ("failed demangling\n");
487 for (i
= 0; i
< indent
; ++i
)
492 case DEMANGLE_COMPONENT_NAME
:
493 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
495 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
496 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
498 case DEMANGLE_COMPONENT_CTOR
:
499 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
500 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
502 case DEMANGLE_COMPONENT_DTOR
:
503 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
504 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
506 case DEMANGLE_COMPONENT_SUB_STD
:
507 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
509 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
510 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
512 case DEMANGLE_COMPONENT_OPERATOR
:
513 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
515 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
516 printf ("extended operator with %d args\n",
517 dc
->u
.s_extended_operator
.args
);
518 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
521 case DEMANGLE_COMPONENT_QUAL_NAME
:
522 printf ("qualified name\n");
524 case DEMANGLE_COMPONENT_LOCAL_NAME
:
525 printf ("local name\n");
527 case DEMANGLE_COMPONENT_TYPED_NAME
:
528 printf ("typed name\n");
530 case DEMANGLE_COMPONENT_TEMPLATE
:
531 printf ("template\n");
533 case DEMANGLE_COMPONENT_VTABLE
:
536 case DEMANGLE_COMPONENT_VTT
:
539 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
540 printf ("construction vtable\n");
542 case DEMANGLE_COMPONENT_TYPEINFO
:
543 printf ("typeinfo\n");
545 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
546 printf ("typeinfo name\n");
548 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
549 printf ("typeinfo function\n");
551 case DEMANGLE_COMPONENT_THUNK
:
554 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
555 printf ("virtual thunk\n");
557 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
558 printf ("covariant thunk\n");
560 case DEMANGLE_COMPONENT_JAVA_CLASS
:
561 printf ("java class\n");
563 case DEMANGLE_COMPONENT_GUARD
:
566 case DEMANGLE_COMPONENT_REFTEMP
:
567 printf ("reference temporary\n");
569 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
570 printf ("hidden alias\n");
572 case DEMANGLE_COMPONENT_RESTRICT
:
573 printf ("restrict\n");
575 case DEMANGLE_COMPONENT_VOLATILE
:
576 printf ("volatile\n");
578 case DEMANGLE_COMPONENT_CONST
:
581 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
582 printf ("restrict this\n");
584 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
585 printf ("volatile this\n");
587 case DEMANGLE_COMPONENT_CONST_THIS
:
588 printf ("const this\n");
590 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
591 printf ("vendor type qualifier\n");
593 case DEMANGLE_COMPONENT_POINTER
:
594 printf ("pointer\n");
596 case DEMANGLE_COMPONENT_REFERENCE
:
597 printf ("reference\n");
599 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
600 printf ("rvalue reference\n");
602 case DEMANGLE_COMPONENT_COMPLEX
:
603 printf ("complex\n");
605 case DEMANGLE_COMPONENT_IMAGINARY
:
606 printf ("imaginary\n");
608 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
609 printf ("vendor type\n");
611 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
612 printf ("function type\n");
614 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
615 printf ("array type\n");
617 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
618 printf ("pointer to member type\n");
620 case DEMANGLE_COMPONENT_ARGLIST
:
621 printf ("argument list\n");
623 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
624 printf ("template argument list\n");
626 case DEMANGLE_COMPONENT_CAST
:
629 case DEMANGLE_COMPONENT_UNARY
:
630 printf ("unary operator\n");
632 case DEMANGLE_COMPONENT_BINARY
:
633 printf ("binary operator\n");
635 case DEMANGLE_COMPONENT_BINARY_ARGS
:
636 printf ("binary operator arguments\n");
638 case DEMANGLE_COMPONENT_TRINARY
:
639 printf ("trinary operator\n");
641 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
642 printf ("trinary operator arguments 1\n");
644 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
645 printf ("trinary operator arguments 1\n");
647 case DEMANGLE_COMPONENT_LITERAL
:
648 printf ("literal\n");
650 case DEMANGLE_COMPONENT_LITERAL_NEG
:
651 printf ("negative literal\n");
653 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
654 printf ("java resource\n");
656 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
657 printf ("compound name\n");
659 case DEMANGLE_COMPONENT_CHARACTER
:
660 printf ("character '%c'\n", dc
->u
.s_character
.character
);
664 d_dump (d_left (dc
), indent
+ 2);
665 d_dump (d_right (dc
), indent
+ 2);
668 #endif /* CP_DEMANGLE_DEBUG */
670 /* Fill in a DEMANGLE_COMPONENT_NAME. */
672 CP_STATIC_IF_GLIBCPP_V3
674 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
676 if (p
== NULL
|| s
== NULL
|| len
== 0)
678 p
->type
= DEMANGLE_COMPONENT_NAME
;
680 p
->u
.s_name
.len
= len
;
684 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
686 CP_STATIC_IF_GLIBCPP_V3
688 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
689 struct demangle_component
*name
)
691 if (p
== NULL
|| args
< 0 || name
== NULL
)
693 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
694 p
->u
.s_extended_operator
.args
= args
;
695 p
->u
.s_extended_operator
.name
= name
;
699 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
701 CP_STATIC_IF_GLIBCPP_V3
703 cplus_demangle_fill_ctor (struct demangle_component
*p
,
704 enum gnu_v3_ctor_kinds kind
,
705 struct demangle_component
*name
)
709 || (kind
< gnu_v3_complete_object_ctor
710 && kind
> gnu_v3_complete_object_allocating_ctor
))
712 p
->type
= DEMANGLE_COMPONENT_CTOR
;
713 p
->u
.s_ctor
.kind
= kind
;
714 p
->u
.s_ctor
.name
= name
;
718 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
720 CP_STATIC_IF_GLIBCPP_V3
722 cplus_demangle_fill_dtor (struct demangle_component
*p
,
723 enum gnu_v3_dtor_kinds kind
,
724 struct demangle_component
*name
)
728 || (kind
< gnu_v3_deleting_dtor
729 && kind
> gnu_v3_base_object_dtor
))
731 p
->type
= DEMANGLE_COMPONENT_DTOR
;
732 p
->u
.s_dtor
.kind
= kind
;
733 p
->u
.s_dtor
.name
= name
;
737 /* Add a new component. */
739 static struct demangle_component
*
740 d_make_empty (struct d_info
*di
)
742 struct demangle_component
*p
;
744 if (di
->next_comp
>= di
->num_comps
)
746 p
= &di
->comps
[di
->next_comp
];
751 /* Add a new generic component. */
753 static struct demangle_component
*
754 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
755 struct demangle_component
*left
,
756 struct demangle_component
*right
)
758 struct demangle_component
*p
;
760 /* We check for errors here. A typical error would be a NULL return
761 from a subroutine. We catch those here, and return NULL
765 /* These types require two parameters. */
766 case DEMANGLE_COMPONENT_QUAL_NAME
:
767 case DEMANGLE_COMPONENT_LOCAL_NAME
:
768 case DEMANGLE_COMPONENT_TYPED_NAME
:
769 case DEMANGLE_COMPONENT_TEMPLATE
:
770 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
771 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
772 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
773 case DEMANGLE_COMPONENT_UNARY
:
774 case DEMANGLE_COMPONENT_BINARY
:
775 case DEMANGLE_COMPONENT_BINARY_ARGS
:
776 case DEMANGLE_COMPONENT_TRINARY
:
777 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
778 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
779 case DEMANGLE_COMPONENT_LITERAL
:
780 case DEMANGLE_COMPONENT_LITERAL_NEG
:
781 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
782 if (left
== NULL
|| right
== NULL
)
786 /* These types only require one parameter. */
787 case DEMANGLE_COMPONENT_VTABLE
:
788 case DEMANGLE_COMPONENT_VTT
:
789 case DEMANGLE_COMPONENT_TYPEINFO
:
790 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
791 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
792 case DEMANGLE_COMPONENT_THUNK
:
793 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
794 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
795 case DEMANGLE_COMPONENT_JAVA_CLASS
:
796 case DEMANGLE_COMPONENT_GUARD
:
797 case DEMANGLE_COMPONENT_REFTEMP
:
798 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
799 case DEMANGLE_COMPONENT_POINTER
:
800 case DEMANGLE_COMPONENT_REFERENCE
:
801 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
802 case DEMANGLE_COMPONENT_COMPLEX
:
803 case DEMANGLE_COMPONENT_IMAGINARY
:
804 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
805 case DEMANGLE_COMPONENT_ARGLIST
:
806 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
807 case DEMANGLE_COMPONENT_CAST
:
808 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
813 /* This needs a right parameter, but the left parameter can be
815 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
820 /* These are allowed to have no parameters--in some cases they
821 will be filled in later. */
822 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
823 case DEMANGLE_COMPONENT_RESTRICT
:
824 case DEMANGLE_COMPONENT_VOLATILE
:
825 case DEMANGLE_COMPONENT_CONST
:
826 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
827 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
828 case DEMANGLE_COMPONENT_CONST_THIS
:
831 /* Other types should not be seen here. */
836 p
= d_make_empty (di
);
840 p
->u
.s_binary
.left
= left
;
841 p
->u
.s_binary
.right
= right
;
846 /* Add a new name component. */
848 static struct demangle_component
*
849 d_make_name (struct d_info
*di
, const char *s
, int len
)
851 struct demangle_component
*p
;
853 p
= d_make_empty (di
);
854 if (! cplus_demangle_fill_name (p
, s
, len
))
859 /* Add a new builtin type component. */
861 static struct demangle_component
*
862 d_make_builtin_type (struct d_info
*di
,
863 const struct demangle_builtin_type_info
*type
)
865 struct demangle_component
*p
;
869 p
= d_make_empty (di
);
872 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
873 p
->u
.s_builtin
.type
= type
;
878 /* Add a new operator component. */
880 static struct demangle_component
*
881 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
883 struct demangle_component
*p
;
885 p
= d_make_empty (di
);
888 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
889 p
->u
.s_operator
.op
= op
;
894 /* Add a new extended operator component. */
896 static struct demangle_component
*
897 d_make_extended_operator (struct d_info
*di
, int args
,
898 struct demangle_component
*name
)
900 struct demangle_component
*p
;
902 p
= d_make_empty (di
);
903 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
908 /* Add a new constructor component. */
910 static struct demangle_component
*
911 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
912 struct demangle_component
*name
)
914 struct demangle_component
*p
;
916 p
= d_make_empty (di
);
917 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
922 /* Add a new destructor component. */
924 static struct demangle_component
*
925 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
926 struct demangle_component
*name
)
928 struct demangle_component
*p
;
930 p
= d_make_empty (di
);
931 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
936 /* Add a new template parameter. */
938 static struct demangle_component
*
939 d_make_template_param (struct d_info
*di
, long i
)
941 struct demangle_component
*p
;
943 p
= d_make_empty (di
);
946 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
947 p
->u
.s_number
.number
= i
;
952 /* Add a new standard substitution component. */
954 static struct demangle_component
*
955 d_make_sub (struct d_info
*di
, const char *name
, int len
)
957 struct demangle_component
*p
;
959 p
= d_make_empty (di
);
962 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
963 p
->u
.s_string
.string
= name
;
964 p
->u
.s_string
.len
= len
;
969 /* <mangled-name> ::= _Z <encoding>
971 TOP_LEVEL is non-zero when called at the top level. */
973 CP_STATIC_IF_GLIBCPP_V3
974 struct demangle_component
*
975 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
977 if (! d_check_char (di
, '_'))
979 if (! d_check_char (di
, 'Z'))
981 return d_encoding (di
, top_level
);
984 /* Return whether a function should have a return type. The argument
985 is the function name, which may be qualified in various ways. The
986 rules are that template functions have return types with some
987 exceptions, function types which are not part of a function name
988 mangling have return types with some exceptions, and non-template
989 function names do not have return types. The exceptions are that
990 constructors, destructors, and conversion operators do not have
994 has_return_type (struct demangle_component
*dc
)
1002 case DEMANGLE_COMPONENT_TEMPLATE
:
1003 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1004 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1005 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1006 case DEMANGLE_COMPONENT_CONST_THIS
:
1007 return has_return_type (d_left (dc
));
1011 /* Return whether a name is a constructor, a destructor, or a
1012 conversion operator. */
1015 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1023 case DEMANGLE_COMPONENT_QUAL_NAME
:
1024 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1025 return is_ctor_dtor_or_conversion (d_right (dc
));
1026 case DEMANGLE_COMPONENT_CTOR
:
1027 case DEMANGLE_COMPONENT_DTOR
:
1028 case DEMANGLE_COMPONENT_CAST
:
1033 /* <encoding> ::= <(function) name> <bare-function-type>
1037 TOP_LEVEL is non-zero when called at the top level, in which case
1038 if DMGL_PARAMS is not set we do not demangle the function
1039 parameters. We only set this at the top level, because otherwise
1040 we would not correctly demangle names in local scopes. */
1042 static struct demangle_component
*
1043 d_encoding (struct d_info
*di
, int top_level
)
1045 char peek
= d_peek_char (di
);
1047 if (peek
== 'G' || peek
== 'T')
1048 return d_special_name (di
);
1051 struct demangle_component
*dc
;
1055 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1057 /* Strip off any initial CV-qualifiers, as they really apply
1058 to the `this' parameter, and they were not output by the
1059 v2 demangler without DMGL_PARAMS. */
1060 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1061 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1062 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1065 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1066 there may be CV-qualifiers on its right argument which
1067 really apply here; this happens when parsing a class
1068 which is local to a function. */
1069 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1071 struct demangle_component
*dcr
;
1074 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1075 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1076 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
1078 dc
->u
.s_binary
.right
= dcr
;
1084 peek
= d_peek_char (di
);
1085 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1087 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1088 d_bare_function_type (di
, has_return_type (dc
)));
1092 /* <name> ::= <nested-name>
1094 ::= <unscoped-template-name> <template-args>
1097 <unscoped-name> ::= <unqualified-name>
1098 ::= St <unqualified-name>
1100 <unscoped-template-name> ::= <unscoped-name>
1104 static struct demangle_component
*
1105 d_name (struct d_info
*di
)
1107 char peek
= d_peek_char (di
);
1108 struct demangle_component
*dc
;
1113 return d_nested_name (di
);
1116 return d_local_name (di
);
1119 return d_unqualified_name (di
);
1125 if (d_peek_next_char (di
) != 't')
1127 dc
= d_substitution (di
, 0);
1133 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1134 d_make_name (di
, "std", 3),
1135 d_unqualified_name (di
));
1140 if (d_peek_char (di
) != 'I')
1142 /* The grammar does not permit this case to occur if we
1143 called d_substitution() above (i.e., subst == 1). We
1144 don't bother to check. */
1148 /* This is <template-args>, which means that we just saw
1149 <unscoped-template-name>, which is a substitution
1150 candidate if we didn't just get it from a
1154 if (! d_add_substitution (di
, dc
))
1157 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1158 d_template_args (di
));
1165 dc
= d_unqualified_name (di
);
1166 if (d_peek_char (di
) == 'I')
1168 /* This is <template-args>, which means that we just saw
1169 <unscoped-template-name>, which is a substitution
1171 if (! d_add_substitution (di
, dc
))
1173 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1174 d_template_args (di
));
1180 /* <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
1181 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
1184 static struct demangle_component
*
1185 d_nested_name (struct d_info
*di
)
1187 struct demangle_component
*ret
;
1188 struct demangle_component
**pret
;
1190 if (! d_check_char (di
, 'N'))
1193 pret
= d_cv_qualifiers (di
, &ret
, 1);
1197 *pret
= d_prefix (di
);
1201 if (! d_check_char (di
, 'E'))
1207 /* <prefix> ::= <prefix> <unqualified-name>
1208 ::= <template-prefix> <template-args>
1209 ::= <template-param>
1213 <template-prefix> ::= <prefix> <(template) unqualified-name>
1214 ::= <template-param>
1218 static struct demangle_component
*
1219 d_prefix (struct d_info
*di
)
1221 struct demangle_component
*ret
= NULL
;
1226 enum demangle_component_type comb_type
;
1227 struct demangle_component
*dc
;
1229 peek
= d_peek_char (di
);
1233 /* The older code accepts a <local-name> here, but I don't see
1234 that in the grammar. The older code does not accept a
1235 <template-param> here. */
1237 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1243 dc
= d_unqualified_name (di
);
1244 else if (peek
== 'S')
1245 dc
= d_substitution (di
, 1);
1246 else if (peek
== 'I')
1250 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1251 dc
= d_template_args (di
);
1253 else if (peek
== 'T')
1254 dc
= d_template_param (di
);
1255 else if (peek
== 'E')
1263 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1265 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1267 if (! d_add_substitution (di
, ret
))
1273 /* <unqualified-name> ::= <operator-name>
1274 ::= <ctor-dtor-name>
1276 ::= <local-source-name>
1278 <local-source-name> ::= L <source-name> <discriminator>
1281 static struct demangle_component
*
1282 d_unqualified_name (struct d_info
*di
)
1286 peek
= d_peek_char (di
);
1287 if (IS_DIGIT (peek
))
1288 return d_source_name (di
);
1289 else if (IS_LOWER (peek
))
1291 struct demangle_component
*ret
;
1293 ret
= d_operator_name (di
);
1294 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1295 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1298 else if (peek
== 'C' || peek
== 'D')
1299 return d_ctor_dtor_name (di
);
1300 else if (peek
== 'L')
1302 struct demangle_component
* ret
;
1306 ret
= d_source_name (di
);
1309 if (! d_discriminator (di
))
1317 /* <source-name> ::= <(positive length) number> <identifier> */
1319 static struct demangle_component
*
1320 d_source_name (struct d_info
*di
)
1323 struct demangle_component
*ret
;
1325 len
= d_number (di
);
1328 ret
= d_identifier (di
, len
);
1329 di
->last_name
= ret
;
1333 /* number ::= [n] <(non-negative decimal integer)> */
1336 d_number (struct d_info
*di
)
1343 peek
= d_peek_char (di
);
1348 peek
= d_peek_char (di
);
1354 if (! IS_DIGIT (peek
))
1360 ret
= ret
* 10 + peek
- '0';
1362 peek
= d_peek_char (di
);
1366 /* identifier ::= <(unqualified source code identifier)> */
1368 static struct demangle_component
*
1369 d_identifier (struct d_info
*di
, int len
)
1375 if (di
->send
- name
< len
)
1378 d_advance (di
, len
);
1380 /* A Java mangled name may have a trailing '$' if it is a C++
1381 keyword. This '$' is not included in the length count. We just
1383 if ((di
->options
& DMGL_JAVA
) != 0
1384 && d_peek_char (di
) == '$')
1387 /* Look for something which looks like a gcc encoding of an
1388 anonymous namespace, and replace it with a more user friendly
1390 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1391 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1392 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1396 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1397 if ((*s
== '.' || *s
== '_' || *s
== '$')
1400 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1401 return d_make_name (di
, "(anonymous namespace)",
1402 sizeof "(anonymous namespace)" - 1);
1406 return d_make_name (di
, name
, len
);
1409 /* operator_name ::= many different two character encodings.
1411 ::= v <digit> <source-name>
1414 #define NL(s) s, (sizeof s) - 1
1416 CP_STATIC_IF_GLIBCPP_V3
1417 const struct demangle_operator_info cplus_demangle_operators
[] =
1419 { "aN", NL ("&="), 2 },
1420 { "aS", NL ("="), 2 },
1421 { "aa", NL ("&&"), 2 },
1422 { "ad", NL ("&"), 1 },
1423 { "an", NL ("&"), 2 },
1424 { "cl", NL ("()"), 0 },
1425 { "cm", NL (","), 2 },
1426 { "co", NL ("~"), 1 },
1427 { "dV", NL ("/="), 2 },
1428 { "da", NL ("delete[]"), 1 },
1429 { "de", NL ("*"), 1 },
1430 { "dl", NL ("delete"), 1 },
1431 { "dv", NL ("/"), 2 },
1432 { "eO", NL ("^="), 2 },
1433 { "eo", NL ("^"), 2 },
1434 { "eq", NL ("=="), 2 },
1435 { "ge", NL (">="), 2 },
1436 { "gt", NL (">"), 2 },
1437 { "ix", NL ("[]"), 2 },
1438 { "lS", NL ("<<="), 2 },
1439 { "le", NL ("<="), 2 },
1440 { "ls", NL ("<<"), 2 },
1441 { "lt", NL ("<"), 2 },
1442 { "mI", NL ("-="), 2 },
1443 { "mL", NL ("*="), 2 },
1444 { "mi", NL ("-"), 2 },
1445 { "ml", NL ("*"), 2 },
1446 { "mm", NL ("--"), 1 },
1447 { "na", NL ("new[]"), 1 },
1448 { "ne", NL ("!="), 2 },
1449 { "ng", NL ("-"), 1 },
1450 { "nt", NL ("!"), 1 },
1451 { "nw", NL ("new"), 1 },
1452 { "oR", NL ("|="), 2 },
1453 { "oo", NL ("||"), 2 },
1454 { "or", NL ("|"), 2 },
1455 { "pL", NL ("+="), 2 },
1456 { "pl", NL ("+"), 2 },
1457 { "pm", NL ("->*"), 2 },
1458 { "pp", NL ("++"), 1 },
1459 { "ps", NL ("+"), 1 },
1460 { "pt", NL ("->"), 2 },
1461 { "qu", NL ("?"), 3 },
1462 { "rM", NL ("%="), 2 },
1463 { "rS", NL (">>="), 2 },
1464 { "rm", NL ("%"), 2 },
1465 { "rs", NL (">>"), 2 },
1466 { "st", NL ("sizeof "), 1 },
1467 { "sz", NL ("sizeof "), 1 },
1468 { NULL
, NULL
, 0, 0 }
1471 static struct demangle_component
*
1472 d_operator_name (struct d_info
*di
)
1477 c1
= d_next_char (di
);
1478 c2
= d_next_char (di
);
1479 if (c1
== 'v' && IS_DIGIT (c2
))
1480 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1481 else if (c1
== 'c' && c2
== 'v')
1482 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
,
1483 cplus_demangle_type (di
), NULL
);
1486 /* LOW is the inclusive lower bound. */
1488 /* HIGH is the exclusive upper bound. We subtract one to ignore
1489 the sentinel at the end of the array. */
1490 int high
= ((sizeof (cplus_demangle_operators
)
1491 / sizeof (cplus_demangle_operators
[0]))
1497 const struct demangle_operator_info
*p
;
1499 i
= low
+ (high
- low
) / 2;
1500 p
= cplus_demangle_operators
+ i
;
1502 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1503 return d_make_operator (di
, p
);
1505 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1515 static struct demangle_component
*
1516 d_make_character (struct d_info
*di
, int c
)
1518 struct demangle_component
*p
;
1519 p
= d_make_empty (di
);
1522 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1523 p
->u
.s_character
.character
= c
;
1528 static struct demangle_component
*
1529 d_java_resource (struct d_info
*di
)
1531 struct demangle_component
*p
= NULL
;
1532 struct demangle_component
*next
= NULL
;
1537 len
= d_number (di
);
1541 /* Eat the leading '_'. */
1542 if (d_next_char (di
) != '_')
1555 /* Each chunk is either a '$' escape... */
1573 next
= d_make_character (di
, c
);
1581 /* ... or a sequence of characters. */
1584 while (i
< len
&& str
[i
] && str
[i
] != '$')
1587 next
= d_make_name (di
, str
, i
);
1600 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1606 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1611 /* <special-name> ::= TV <type>
1615 ::= GV <(object) name>
1616 ::= T <call-offset> <(base) encoding>
1617 ::= Tc <call-offset> <call-offset> <(base) encoding>
1618 Also g++ extensions:
1619 ::= TC <type> <(offset) number> _ <(base) type>
1624 ::= Gr <resource name>
1627 static struct demangle_component
*
1628 d_special_name (struct d_info
*di
)
1630 di
->expansion
+= 20;
1631 if (d_check_char (di
, 'T'))
1633 switch (d_next_char (di
))
1637 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1638 cplus_demangle_type (di
), NULL
);
1640 di
->expansion
-= 10;
1641 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1642 cplus_demangle_type (di
), NULL
);
1644 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1645 cplus_demangle_type (di
), NULL
);
1647 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1648 cplus_demangle_type (di
), NULL
);
1651 if (! d_call_offset (di
, 'h'))
1653 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1654 d_encoding (di
, 0), NULL
);
1657 if (! d_call_offset (di
, 'v'))
1659 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1660 d_encoding (di
, 0), NULL
);
1663 if (! d_call_offset (di
, '\0'))
1665 if (! d_call_offset (di
, '\0'))
1667 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1668 d_encoding (di
, 0), NULL
);
1672 struct demangle_component
*derived_type
;
1674 struct demangle_component
*base_type
;
1676 derived_type
= cplus_demangle_type (di
);
1677 offset
= d_number (di
);
1680 if (! d_check_char (di
, '_'))
1682 base_type
= cplus_demangle_type (di
);
1683 /* We don't display the offset. FIXME: We should display
1684 it in verbose mode. */
1686 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
1687 base_type
, derived_type
);
1691 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
1692 cplus_demangle_type (di
), NULL
);
1694 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
1695 cplus_demangle_type (di
), NULL
);
1701 else if (d_check_char (di
, 'G'))
1703 switch (d_next_char (di
))
1706 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
1709 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, d_name (di
),
1713 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
1714 d_encoding (di
, 0), NULL
);
1717 return d_java_resource (di
);
1727 /* <call-offset> ::= h <nv-offset> _
1730 <nv-offset> ::= <(offset) number>
1732 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
1734 The C parameter, if not '\0', is a character we just read which is
1735 the start of the <call-offset>.
1737 We don't display the offset information anywhere. FIXME: We should
1738 display it in verbose mode. */
1741 d_call_offset (struct d_info
*di
, int c
)
1744 c
= d_next_char (di
);
1751 if (! d_check_char (di
, '_'))
1758 if (! d_check_char (di
, '_'))
1764 /* <ctor-dtor-name> ::= C1
1772 static struct demangle_component
*
1773 d_ctor_dtor_name (struct d_info
*di
)
1775 if (di
->last_name
!= NULL
)
1777 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
1778 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
1779 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
1780 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
1782 switch (d_peek_char (di
))
1786 enum gnu_v3_ctor_kinds kind
;
1788 switch (d_peek_next_char (di
))
1791 kind
= gnu_v3_complete_object_ctor
;
1794 kind
= gnu_v3_base_object_ctor
;
1797 kind
= gnu_v3_complete_object_allocating_ctor
;
1803 return d_make_ctor (di
, kind
, di
->last_name
);
1808 enum gnu_v3_dtor_kinds kind
;
1810 switch (d_peek_next_char (di
))
1813 kind
= gnu_v3_deleting_dtor
;
1816 kind
= gnu_v3_complete_object_dtor
;
1819 kind
= gnu_v3_base_object_dtor
;
1825 return d_make_dtor (di
, kind
, di
->last_name
);
1833 /* <type> ::= <builtin-type>
1835 ::= <class-enum-type>
1837 ::= <pointer-to-member-type>
1838 ::= <template-param>
1839 ::= <template-template-param> <template-args>
1841 ::= <CV-qualifiers> <type>
1844 ::= O <type> (C++0x)
1847 ::= U <source-name> <type>
1849 <builtin-type> ::= various one letter codes
1853 CP_STATIC_IF_GLIBCPP_V3
1854 const struct demangle_builtin_type_info
1855 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
1857 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
1858 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
1859 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
1860 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
1861 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
1862 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
1863 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
1864 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
1865 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
1866 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
1867 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1868 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
1869 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
1870 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
1871 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
1873 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1874 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1875 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1876 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
1877 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
1878 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
1879 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
1880 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
1881 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
1882 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
1883 D_PRINT_UNSIGNED_LONG_LONG
},
1884 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
1887 CP_STATIC_IF_GLIBCPP_V3
1888 struct demangle_component
*
1889 cplus_demangle_type (struct d_info
*di
)
1892 struct demangle_component
*ret
;
1895 /* The ABI specifies that when CV-qualifiers are used, the base type
1896 is substitutable, and the fully qualified type is substitutable,
1897 but the base type with a strict subset of the CV-qualifiers is
1898 not substitutable. The natural recursive implementation of the
1899 CV-qualifiers would cause subsets to be substitutable, so instead
1900 we pull them all off now.
1902 FIXME: The ABI says that order-insensitive vendor qualifiers
1903 should be handled in the same way, but we have no way to tell
1904 which vendor qualifiers are order-insensitive and which are
1905 order-sensitive. So we just assume that they are all
1906 order-sensitive. g++ 3.4 supports only one vendor qualifier,
1907 __vector, and it treats it as order-sensitive when mangling
1910 peek
= d_peek_char (di
);
1911 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
1913 struct demangle_component
**pret
;
1915 pret
= d_cv_qualifiers (di
, &ret
, 0);
1918 *pret
= cplus_demangle_type (di
);
1919 if (! *pret
|| ! d_add_substitution (di
, ret
))
1928 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1929 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
1930 case 'o': case 's': case 't':
1931 case 'v': case 'w': case 'x': case 'y': case 'z':
1932 ret
= d_make_builtin_type (di
,
1933 &cplus_demangle_builtin_types
[peek
- 'a']);
1934 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
1941 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
1942 d_source_name (di
), NULL
);
1946 ret
= d_function_type (di
);
1949 case '0': case '1': case '2': case '3': case '4':
1950 case '5': case '6': case '7': case '8': case '9':
1953 ret
= d_class_enum_type (di
);
1957 ret
= d_array_type (di
);
1961 ret
= d_pointer_to_member_type (di
);
1965 ret
= d_template_param (di
);
1966 if (d_peek_char (di
) == 'I')
1968 /* This is <template-template-param> <template-args>. The
1969 <template-template-param> part is a substitution
1971 if (! d_add_substitution (di
, ret
))
1973 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
1974 d_template_args (di
));
1979 /* If this is a special substitution, then it is the start of
1980 <class-enum-type>. */
1984 peek_next
= d_peek_next_char (di
);
1985 if (IS_DIGIT (peek_next
)
1987 || IS_UPPER (peek_next
))
1989 ret
= d_substitution (di
, 0);
1990 /* The substituted name may have been a template name and
1991 may be followed by tepmlate args. */
1992 if (d_peek_char (di
) == 'I')
1993 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
1994 d_template_args (di
));
2000 ret
= d_class_enum_type (di
);
2001 /* If the substitution was a complete type, then it is not
2002 a new substitution candidate. However, if the
2003 substitution was followed by template arguments, then
2004 the whole thing is a substitution candidate. */
2005 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2013 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2014 cplus_demangle_type (di
), NULL
);
2019 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2020 cplus_demangle_type (di
), NULL
);
2025 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2026 cplus_demangle_type (di
), NULL
);
2031 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2032 cplus_demangle_type (di
), NULL
);
2037 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2038 cplus_demangle_type (di
), NULL
);
2043 ret
= d_source_name (di
);
2044 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2045 cplus_demangle_type (di
), ret
);
2054 if (! d_add_substitution (di
, ret
))
2061 /* <CV-qualifiers> ::= [r] [V] [K] */
2063 static struct demangle_component
**
2064 d_cv_qualifiers (struct d_info
*di
,
2065 struct demangle_component
**pret
, int member_fn
)
2069 peek
= d_peek_char (di
);
2070 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2072 enum demangle_component_type t
;
2078 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2079 : DEMANGLE_COMPONENT_RESTRICT
);
2080 di
->expansion
+= sizeof "restrict";
2082 else if (peek
== 'V')
2085 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2086 : DEMANGLE_COMPONENT_VOLATILE
);
2087 di
->expansion
+= sizeof "volatile";
2092 ? DEMANGLE_COMPONENT_CONST_THIS
2093 : DEMANGLE_COMPONENT_CONST
);
2094 di
->expansion
+= sizeof "const";
2097 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2100 pret
= &d_left (*pret
);
2102 peek
= d_peek_char (di
);
2108 /* <function-type> ::= F [Y] <bare-function-type> E */
2110 static struct demangle_component
*
2111 d_function_type (struct d_info
*di
)
2113 struct demangle_component
*ret
;
2115 if (! d_check_char (di
, 'F'))
2117 if (d_peek_char (di
) == 'Y')
2119 /* Function has C linkage. We don't print this information.
2120 FIXME: We should print it in verbose mode. */
2123 ret
= d_bare_function_type (di
, 1);
2124 if (! d_check_char (di
, 'E'))
2129 /* <bare-function-type> ::= [J]<type>+ */
2131 static struct demangle_component
*
2132 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2134 struct demangle_component
*return_type
;
2135 struct demangle_component
*tl
;
2136 struct demangle_component
**ptl
;
2139 /* Detect special qualifier indicating that the first argument
2140 is the return type. */
2141 peek
= d_peek_char (di
);
2145 has_return_type
= 1;
2153 struct demangle_component
*type
;
2155 peek
= d_peek_char (di
);
2156 if (peek
== '\0' || peek
== 'E')
2158 type
= cplus_demangle_type (di
);
2161 if (has_return_type
)
2164 has_return_type
= 0;
2168 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2171 ptl
= &d_right (*ptl
);
2175 /* There should be at least one parameter type besides the optional
2176 return type. A function which takes no arguments will have a
2177 single parameter type void. */
2181 /* If we have a single parameter type void, omit it. */
2182 if (d_right (tl
) == NULL
2183 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2184 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2186 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2190 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
, return_type
, tl
);
2193 /* <class-enum-type> ::= <name> */
2195 static struct demangle_component
*
2196 d_class_enum_type (struct d_info
*di
)
2201 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2202 ::= A [<(dimension) expression>] _ <(element) type>
2205 static struct demangle_component
*
2206 d_array_type (struct d_info
*di
)
2209 struct demangle_component
*dim
;
2211 if (! d_check_char (di
, 'A'))
2214 peek
= d_peek_char (di
);
2217 else if (IS_DIGIT (peek
))
2225 peek
= d_peek_char (di
);
2227 while (IS_DIGIT (peek
));
2228 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2234 dim
= d_expression (di
);
2239 if (! d_check_char (di
, '_'))
2242 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2243 cplus_demangle_type (di
));
2246 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2248 static struct demangle_component
*
2249 d_pointer_to_member_type (struct d_info
*di
)
2251 struct demangle_component
*cl
;
2252 struct demangle_component
*mem
;
2253 struct demangle_component
**pmem
;
2255 if (! d_check_char (di
, 'M'))
2258 cl
= cplus_demangle_type (di
);
2260 /* The ABI specifies that any type can be a substitution source, and
2261 that M is followed by two types, and that when a CV-qualified
2262 type is seen both the base type and the CV-qualified types are
2263 substitution sources. The ABI also specifies that for a pointer
2264 to a CV-qualified member function, the qualifiers are attached to
2265 the second type. Given the grammar, a plain reading of the ABI
2266 suggests that both the CV-qualified member function and the
2267 non-qualified member function are substitution sources. However,
2268 g++ does not work that way. g++ treats only the CV-qualified
2269 member function as a substitution source. FIXME. So to work
2270 with g++, we need to pull off the CV-qualifiers here, in order to
2271 avoid calling add_substitution() in cplus_demangle_type(). But
2272 for a CV-qualified member which is not a function, g++ does
2273 follow the ABI, so we need to handle that case here by calling
2274 d_add_substitution ourselves. */
2276 pmem
= d_cv_qualifiers (di
, &mem
, 1);
2279 *pmem
= cplus_demangle_type (di
);
2283 if (pmem
!= &mem
&& (*pmem
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
2285 if (! d_add_substitution (di
, mem
))
2289 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2292 /* <template-param> ::= T_
2293 ::= T <(parameter-2 non-negative) number> _
2296 static struct demangle_component
*
2297 d_template_param (struct d_info
*di
)
2301 if (! d_check_char (di
, 'T'))
2304 if (d_peek_char (di
) == '_')
2308 param
= d_number (di
);
2314 if (! d_check_char (di
, '_'))
2319 return d_make_template_param (di
, param
);
2322 /* <template-args> ::= I <template-arg>+ E */
2324 static struct demangle_component
*
2325 d_template_args (struct d_info
*di
)
2327 struct demangle_component
*hold_last_name
;
2328 struct demangle_component
*al
;
2329 struct demangle_component
**pal
;
2331 /* Preserve the last name we saw--don't let the template arguments
2332 clobber it, as that would give us the wrong name for a subsequent
2333 constructor or destructor. */
2334 hold_last_name
= di
->last_name
;
2336 if (! d_check_char (di
, 'I'))
2343 struct demangle_component
*a
;
2345 a
= d_template_arg (di
);
2349 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2352 pal
= &d_right (*pal
);
2354 if (d_peek_char (di
) == 'E')
2361 di
->last_name
= hold_last_name
;
2366 /* <template-arg> ::= <type>
2367 ::= X <expression> E
2371 static struct demangle_component
*
2372 d_template_arg (struct d_info
*di
)
2374 struct demangle_component
*ret
;
2376 switch (d_peek_char (di
))
2380 ret
= d_expression (di
);
2381 if (! d_check_char (di
, 'E'))
2386 return d_expr_primary (di
);
2389 return cplus_demangle_type (di
);
2393 /* <expression> ::= <(unary) operator-name> <expression>
2394 ::= <(binary) operator-name> <expression> <expression>
2395 ::= <(trinary) operator-name> <expression> <expression> <expression>
2397 ::= <template-param>
2398 ::= sr <type> <unqualified-name>
2399 ::= sr <type> <unqualified-name> <template-args>
2403 static struct demangle_component
*
2404 d_expression (struct d_info
*di
)
2408 peek
= d_peek_char (di
);
2410 return d_expr_primary (di
);
2411 else if (peek
== 'T')
2412 return d_template_param (di
);
2413 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
2415 struct demangle_component
*type
;
2416 struct demangle_component
*name
;
2419 type
= cplus_demangle_type (di
);
2420 name
= d_unqualified_name (di
);
2421 if (d_peek_char (di
) != 'I')
2422 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
2424 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
2425 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
2426 d_template_args (di
)));
2430 struct demangle_component
*op
;
2433 op
= d_operator_name (di
);
2437 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
2438 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
2440 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
2441 && strcmp (op
->u
.s_operator
.op
->code
, "st") == 0)
2442 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2443 cplus_demangle_type (di
));
2449 case DEMANGLE_COMPONENT_OPERATOR
:
2450 args
= op
->u
.s_operator
.op
->args
;
2452 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
2453 args
= op
->u
.s_extended_operator
.args
;
2455 case DEMANGLE_COMPONENT_CAST
:
2463 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
2467 struct demangle_component
*left
;
2469 left
= d_expression (di
);
2470 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
2472 DEMANGLE_COMPONENT_BINARY_ARGS
,
2474 d_expression (di
)));
2478 struct demangle_component
*first
;
2479 struct demangle_component
*second
;
2481 first
= d_expression (di
);
2482 second
= d_expression (di
);
2483 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
2485 DEMANGLE_COMPONENT_TRINARY_ARG1
,
2488 DEMANGLE_COMPONENT_TRINARY_ARG2
,
2490 d_expression (di
))));
2498 /* <expr-primary> ::= L <type> <(value) number> E
2499 ::= L <type> <(value) float> E
2500 ::= L <mangled-name> E
2503 static struct demangle_component
*
2504 d_expr_primary (struct d_info
*di
)
2506 struct demangle_component
*ret
;
2508 if (! d_check_char (di
, 'L'))
2510 if (d_peek_char (di
) == '_')
2511 ret
= cplus_demangle_mangled_name (di
, 0);
2514 struct demangle_component
*type
;
2515 enum demangle_component_type t
;
2518 type
= cplus_demangle_type (di
);
2522 /* If we have a type we know how to print, we aren't going to
2523 print the type name itself. */
2524 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2525 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
2526 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
2528 /* Rather than try to interpret the literal value, we just
2529 collect it as a string. Note that it's possible to have a
2530 floating point literal here. The ABI specifies that the
2531 format of such literals is machine independent. That's fine,
2532 but what's not fine is that versions of g++ up to 3.2 with
2533 -fabi-version=1 used upper case letters in the hex constant,
2534 and dumped out gcc's internal representation. That makes it
2535 hard to tell where the constant ends, and hard to dump the
2536 constant in any readable form anyhow. We don't attempt to
2537 handle these cases. */
2539 t
= DEMANGLE_COMPONENT_LITERAL
;
2540 if (d_peek_char (di
) == 'n')
2542 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
2546 while (d_peek_char (di
) != 'E')
2548 if (d_peek_char (di
) == '\0')
2552 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
2554 if (! d_check_char (di
, 'E'))
2559 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
2560 ::= Z <(function) encoding> E s [<discriminator>]
2563 static struct demangle_component
*
2564 d_local_name (struct d_info
*di
)
2566 struct demangle_component
*function
;
2568 if (! d_check_char (di
, 'Z'))
2571 function
= d_encoding (di
, 0);
2573 if (! d_check_char (di
, 'E'))
2576 if (d_peek_char (di
) == 's')
2579 if (! d_discriminator (di
))
2581 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
2582 d_make_name (di
, "string literal",
2583 sizeof "string literal" - 1));
2587 struct demangle_component
*name
;
2590 if (! d_discriminator (di
))
2592 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
2596 /* <discriminator> ::= _ <(non-negative) number>
2598 We demangle the discriminator, but we don't print it out. FIXME:
2599 We should print it out in verbose mode. */
2602 d_discriminator (struct d_info
*di
)
2606 if (d_peek_char (di
) != '_')
2609 discrim
= d_number (di
);
2615 /* Add a new substitution. */
2618 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
2622 if (di
->next_sub
>= di
->num_subs
)
2624 di
->subs
[di
->next_sub
] = dc
;
2629 /* <substitution> ::= S <seq-id> _
2639 If PREFIX is non-zero, then this type is being used as a prefix in
2640 a qualified name. In this case, for the standard substitutions, we
2641 need to check whether we are being used as a prefix for a
2642 constructor or destructor, and return a full template name.
2643 Otherwise we will get something like std::iostream::~iostream()
2644 which does not correspond particularly well to any function which
2645 actually appears in the source.
2648 static const struct d_standard_sub_info standard_subs
[] =
2653 { 'a', NL ("std::allocator"),
2654 NL ("std::allocator"),
2656 { 'b', NL ("std::basic_string"),
2657 NL ("std::basic_string"),
2658 NL ("basic_string") },
2659 { 's', NL ("std::string"),
2660 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
2661 NL ("basic_string") },
2662 { 'i', NL ("std::istream"),
2663 NL ("std::basic_istream<char, std::char_traits<char> >"),
2664 NL ("basic_istream") },
2665 { 'o', NL ("std::ostream"),
2666 NL ("std::basic_ostream<char, std::char_traits<char> >"),
2667 NL ("basic_ostream") },
2668 { 'd', NL ("std::iostream"),
2669 NL ("std::basic_iostream<char, std::char_traits<char> >"),
2670 NL ("basic_iostream") }
2673 static struct demangle_component
*
2674 d_substitution (struct d_info
*di
, int prefix
)
2678 if (! d_check_char (di
, 'S'))
2681 c
= d_next_char (di
);
2682 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
2692 id
= id
* 36 + c
- '0';
2693 else if (IS_UPPER (c
))
2694 id
= id
* 36 + c
- 'A' + 10;
2699 c
= d_next_char (di
);
2706 if (id
>= di
->next_sub
)
2711 return di
->subs
[id
];
2716 const struct d_standard_sub_info
*p
;
2717 const struct d_standard_sub_info
*pend
;
2719 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
2720 if (! verbose
&& prefix
)
2724 peek
= d_peek_char (di
);
2725 if (peek
== 'C' || peek
== 'D')
2729 pend
= (&standard_subs
[0]
2730 + sizeof standard_subs
/ sizeof standard_subs
[0]);
2731 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
2738 if (p
->set_last_name
!= NULL
)
2739 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
2740 p
->set_last_name_len
);
2743 s
= p
->full_expansion
;
2748 s
= p
->simple_expansion
;
2749 len
= p
->simple_len
;
2751 di
->expansion
+= len
;
2752 return d_make_sub (di
, s
, len
);
2760 /* Initialize a growable string. */
2763 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
2768 dgs
->allocation_failure
= 0;
2771 d_growable_string_resize (dgs
, estimate
);
2774 /* Grow a growable string to a given size. */
2777 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
2782 if (dgs
->allocation_failure
)
2785 /* Start allocation at two bytes to avoid any possibility of confusion
2786 with the special value of 1 used as a return in *palc to indicate
2787 allocation failures. */
2788 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
2789 while (newalc
< need
)
2792 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
2799 dgs
->allocation_failure
= 1;
2806 /* Append a buffer to a growable string. */
2809 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
2810 const char *s
, size_t l
)
2814 need
= dgs
->len
+ l
+ 1;
2815 if (need
> dgs
->alc
)
2816 d_growable_string_resize (dgs
, need
);
2818 if (dgs
->allocation_failure
)
2821 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
2822 dgs
->buf
[dgs
->len
+ l
] = '\0';
2826 /* Bridge growable strings to the callback mechanism. */
2829 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
2831 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
2833 d_growable_string_append_buffer (dgs
, s
, l
);
2836 /* Initialize a print information structure. */
2839 d_print_init (struct d_print_info
*dpi
, int options
,
2840 demangle_callbackref callback
, void *opaque
)
2842 dpi
->options
= options
;
2844 dpi
->last_char
= '\0';
2845 dpi
->templates
= NULL
;
2846 dpi
->modifiers
= NULL
;
2848 dpi
->callback
= callback
;
2849 dpi
->opaque
= opaque
;
2851 dpi
->demangle_failure
= 0;
2854 /* Indicate that an error occurred during printing, and test for error. */
2857 d_print_error (struct d_print_info
*dpi
)
2859 dpi
->demangle_failure
= 1;
2863 d_print_saw_error (struct d_print_info
*dpi
)
2865 return dpi
->demangle_failure
!= 0;
2868 /* Flush buffered characters to the callback. */
2871 d_print_flush (struct d_print_info
*dpi
)
2873 dpi
->buf
[dpi
->len
] = '\0';
2874 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
2878 /* Append characters and buffers for printing. */
2881 d_append_char (struct d_print_info
*dpi
, char c
)
2883 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
2884 d_print_flush (dpi
);
2886 dpi
->buf
[dpi
->len
++] = c
;
2891 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
2895 for (i
= 0; i
< l
; i
++)
2896 d_append_char (dpi
, s
[i
]);
2900 d_append_string (struct d_print_info
*dpi
, const char *s
)
2902 d_append_buffer (dpi
, s
, strlen (s
));
2906 d_last_char (struct d_print_info
*dpi
)
2908 return dpi
->last_char
;
2911 /* Turn components into a human readable string. OPTIONS is the
2912 options bits passed to the demangler. DC is the tree to print.
2913 CALLBACK is a function to call to flush demangled string segments
2914 as they fill the intermediate buffer, and OPAQUE is a generalized
2915 callback argument. On success, this returns 1. On failure,
2916 it returns 0, indicating a bad parse. It does not use heap
2917 memory to build an output string, so cannot encounter memory
2918 allocation failure. */
2920 CP_STATIC_IF_GLIBCPP_V3
2922 cplus_demangle_print_callback (int options
,
2923 const struct demangle_component
*dc
,
2924 demangle_callbackref callback
, void *opaque
)
2926 struct d_print_info dpi
;
2928 d_print_init (&dpi
, options
, callback
, opaque
);
2930 d_print_comp (&dpi
, dc
);
2932 d_print_flush (&dpi
);
2934 return ! d_print_saw_error (&dpi
);
2937 /* Turn components into a human readable string. OPTIONS is the
2938 options bits passed to the demangler. DC is the tree to print.
2939 ESTIMATE is a guess at the length of the result. This returns a
2940 string allocated by malloc, or NULL on error. On success, this
2941 sets *PALC to the size of the allocated buffer. On failure, this
2942 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
2945 CP_STATIC_IF_GLIBCPP_V3
2947 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
2948 int estimate
, size_t *palc
)
2950 struct d_growable_string dgs
;
2952 d_growable_string_init (&dgs
, estimate
);
2954 if (! cplus_demangle_print_callback (options
, dc
,
2955 d_growable_string_callback_adapter
,
2963 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
2967 /* Subroutine to handle components. */
2970 d_print_comp (struct d_print_info
*dpi
,
2971 const struct demangle_component
*dc
)
2975 d_print_error (dpi
);
2978 if (d_print_saw_error (dpi
))
2983 case DEMANGLE_COMPONENT_NAME
:
2984 if ((dpi
->options
& DMGL_JAVA
) == 0)
2985 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
2987 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
2990 case DEMANGLE_COMPONENT_QUAL_NAME
:
2991 case DEMANGLE_COMPONENT_LOCAL_NAME
:
2992 d_print_comp (dpi
, d_left (dc
));
2993 if ((dpi
->options
& DMGL_JAVA
) == 0)
2994 d_append_string (dpi
, "::");
2996 d_append_char (dpi
, '.');
2997 d_print_comp (dpi
, d_right (dc
));
3000 case DEMANGLE_COMPONENT_TYPED_NAME
:
3002 struct d_print_mod
*hold_modifiers
;
3003 struct demangle_component
*typed_name
;
3004 struct d_print_mod adpm
[4];
3006 struct d_print_template dpt
;
3008 /* Pass the name down to the type so that it can be printed in
3009 the right place for the type. We also have to pass down
3010 any CV-qualifiers, which apply to the this parameter. */
3011 hold_modifiers
= dpi
->modifiers
;
3013 typed_name
= d_left (dc
);
3014 while (typed_name
!= NULL
)
3016 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3018 d_print_error (dpi
);
3022 adpm
[i
].next
= dpi
->modifiers
;
3023 dpi
->modifiers
= &adpm
[i
];
3024 adpm
[i
].mod
= typed_name
;
3025 adpm
[i
].printed
= 0;
3026 adpm
[i
].templates
= dpi
->templates
;
3029 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
3030 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
3031 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
)
3034 typed_name
= d_left (typed_name
);
3037 if (typed_name
== NULL
)
3039 d_print_error (dpi
);
3043 /* If typed_name is a template, then it applies to the
3044 function type as well. */
3045 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3047 dpt
.next
= dpi
->templates
;
3048 dpi
->templates
= &dpt
;
3049 dpt
.template_decl
= typed_name
;
3052 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
3053 there may be CV-qualifiers on its right argument which
3054 really apply here; this happens when parsing a class which
3055 is local to a function. */
3056 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3058 struct demangle_component
*local_name
;
3060 local_name
= d_right (typed_name
);
3061 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3062 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3063 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3065 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3067 d_print_error (dpi
);
3071 adpm
[i
] = adpm
[i
- 1];
3072 adpm
[i
].next
= &adpm
[i
- 1];
3073 dpi
->modifiers
= &adpm
[i
];
3075 adpm
[i
- 1].mod
= local_name
;
3076 adpm
[i
- 1].printed
= 0;
3077 adpm
[i
- 1].templates
= dpi
->templates
;
3080 local_name
= d_left (local_name
);
3084 d_print_comp (dpi
, d_right (dc
));
3086 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
3087 dpi
->templates
= dpt
.next
;
3089 /* If the modifiers didn't get printed by the type, print them
3094 if (! adpm
[i
].printed
)
3096 d_append_char (dpi
, ' ');
3097 d_print_mod (dpi
, adpm
[i
].mod
);
3101 dpi
->modifiers
= hold_modifiers
;
3106 case DEMANGLE_COMPONENT_TEMPLATE
:
3108 struct d_print_mod
*hold_dpm
;
3109 struct demangle_component
*dcl
;
3111 /* Don't push modifiers into a template definition. Doing so
3112 could give the wrong definition for a template argument.
3113 Instead, treat the template essentially as a name. */
3115 hold_dpm
= dpi
->modifiers
;
3116 dpi
->modifiers
= NULL
;
3120 if ((dpi
->options
& DMGL_JAVA
) != 0
3121 && dcl
->type
== DEMANGLE_COMPONENT_NAME
3122 && dcl
->u
.s_name
.len
== 6
3123 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
3125 /* Special-case Java arrays, so that JArray<TYPE> appears
3126 instead as TYPE[]. */
3128 d_print_comp (dpi
, d_right (dc
));
3129 d_append_string (dpi
, "[]");
3133 d_print_comp (dpi
, dcl
);
3134 if (d_last_char (dpi
) == '<')
3135 d_append_char (dpi
, ' ');
3136 d_append_char (dpi
, '<');
3137 d_print_comp (dpi
, d_right (dc
));
3138 /* Avoid generating two consecutive '>' characters, to avoid
3139 the C++ syntactic ambiguity. */
3140 if (d_last_char (dpi
) == '>')
3141 d_append_char (dpi
, ' ');
3142 d_append_char (dpi
, '>');
3145 dpi
->modifiers
= hold_dpm
;
3150 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3153 struct demangle_component
*a
;
3154 struct d_print_template
*hold_dpt
;
3156 if (dpi
->templates
== NULL
)
3158 d_print_error (dpi
);
3161 i
= dc
->u
.s_number
.number
;
3162 for (a
= d_right (dpi
->templates
->template_decl
);
3166 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
3168 d_print_error (dpi
);
3175 if (i
!= 0 || a
== NULL
)
3177 d_print_error (dpi
);
3181 /* While processing this parameter, we need to pop the list of
3182 templates. This is because the template parameter may
3183 itself be a reference to a parameter of an outer
3186 hold_dpt
= dpi
->templates
;
3187 dpi
->templates
= hold_dpt
->next
;
3189 d_print_comp (dpi
, d_left (a
));
3191 dpi
->templates
= hold_dpt
;
3196 case DEMANGLE_COMPONENT_CTOR
:
3197 d_print_comp (dpi
, dc
->u
.s_ctor
.name
);
3200 case DEMANGLE_COMPONENT_DTOR
:
3201 d_append_char (dpi
, '~');
3202 d_print_comp (dpi
, dc
->u
.s_dtor
.name
);
3205 case DEMANGLE_COMPONENT_VTABLE
:
3206 d_append_string (dpi
, "vtable for ");
3207 d_print_comp (dpi
, d_left (dc
));
3210 case DEMANGLE_COMPONENT_VTT
:
3211 d_append_string (dpi
, "VTT for ");
3212 d_print_comp (dpi
, d_left (dc
));
3215 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3216 d_append_string (dpi
, "construction vtable for ");
3217 d_print_comp (dpi
, d_left (dc
));
3218 d_append_string (dpi
, "-in-");
3219 d_print_comp (dpi
, d_right (dc
));
3222 case DEMANGLE_COMPONENT_TYPEINFO
:
3223 d_append_string (dpi
, "typeinfo for ");
3224 d_print_comp (dpi
, d_left (dc
));
3227 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3228 d_append_string (dpi
, "typeinfo name for ");
3229 d_print_comp (dpi
, d_left (dc
));
3232 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3233 d_append_string (dpi
, "typeinfo fn for ");
3234 d_print_comp (dpi
, d_left (dc
));
3237 case DEMANGLE_COMPONENT_THUNK
:
3238 d_append_string (dpi
, "non-virtual thunk to ");
3239 d_print_comp (dpi
, d_left (dc
));
3242 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3243 d_append_string (dpi
, "virtual thunk to ");
3244 d_print_comp (dpi
, d_left (dc
));
3247 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3248 d_append_string (dpi
, "covariant return thunk to ");
3249 d_print_comp (dpi
, d_left (dc
));
3252 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3253 d_append_string (dpi
, "java Class for ");
3254 d_print_comp (dpi
, d_left (dc
));
3257 case DEMANGLE_COMPONENT_GUARD
:
3258 d_append_string (dpi
, "guard variable for ");
3259 d_print_comp (dpi
, d_left (dc
));
3262 case DEMANGLE_COMPONENT_REFTEMP
:
3263 d_append_string (dpi
, "reference temporary for ");
3264 d_print_comp (dpi
, d_left (dc
));
3267 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3268 d_append_string (dpi
, "hidden alias for ");
3269 d_print_comp (dpi
, d_left (dc
));
3272 case DEMANGLE_COMPONENT_SUB_STD
:
3273 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
3276 case DEMANGLE_COMPONENT_RESTRICT
:
3277 case DEMANGLE_COMPONENT_VOLATILE
:
3278 case DEMANGLE_COMPONENT_CONST
:
3280 struct d_print_mod
*pdpm
;
3282 /* When printing arrays, it's possible to have cases where the
3283 same CV-qualifier gets pushed on the stack multiple times.
3284 We only need to print it once. */
3286 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
3288 if (! pdpm
->printed
)
3290 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
3291 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
3292 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
3294 if (pdpm
->mod
->type
== dc
->type
)
3296 d_print_comp (dpi
, d_left (dc
));
3303 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3304 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3305 case DEMANGLE_COMPONENT_CONST_THIS
:
3306 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3307 case DEMANGLE_COMPONENT_POINTER
:
3308 case DEMANGLE_COMPONENT_REFERENCE
:
3309 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3310 case DEMANGLE_COMPONENT_COMPLEX
:
3311 case DEMANGLE_COMPONENT_IMAGINARY
:
3313 /* We keep a list of modifiers on the stack. */
3314 struct d_print_mod dpm
;
3316 dpm
.next
= dpi
->modifiers
;
3317 dpi
->modifiers
= &dpm
;
3320 dpm
.templates
= dpi
->templates
;
3322 d_print_comp (dpi
, d_left (dc
));
3324 /* If the modifier didn't get printed by the type, print it
3327 d_print_mod (dpi
, dc
);
3329 dpi
->modifiers
= dpm
.next
;
3334 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3335 if ((dpi
->options
& DMGL_JAVA
) == 0)
3336 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
3337 dc
->u
.s_builtin
.type
->len
);
3339 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
3340 dc
->u
.s_builtin
.type
->java_len
);
3343 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3344 d_print_comp (dpi
, d_left (dc
));
3347 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3349 if ((dpi
->options
& DMGL_RET_POSTFIX
) != 0)
3350 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3352 /* Print return type if present */
3353 if (d_left (dc
) != NULL
)
3355 struct d_print_mod dpm
;
3357 /* We must pass this type down as a modifier in order to
3358 print it in the right location. */
3359 dpm
.next
= dpi
->modifiers
;
3360 dpi
->modifiers
= &dpm
;
3363 dpm
.templates
= dpi
->templates
;
3365 d_print_comp (dpi
, d_left (dc
));
3367 dpi
->modifiers
= dpm
.next
;
3372 /* In standard prefix notation, there is a space between the
3373 return type and the function signature. */
3374 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3375 d_append_char (dpi
, ' ');
3378 if ((dpi
->options
& DMGL_RET_POSTFIX
) == 0)
3379 d_print_function_type (dpi
, dc
, dpi
->modifiers
);
3384 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3386 struct d_print_mod
*hold_modifiers
;
3387 struct d_print_mod adpm
[4];
3389 struct d_print_mod
*pdpm
;
3391 /* We must pass this type down as a modifier in order to print
3392 multi-dimensional arrays correctly. If the array itself is
3393 CV-qualified, we act as though the element type were
3394 CV-qualified. We do this by copying the modifiers down
3395 rather than fiddling pointers, so that we don't wind up
3396 with a d_print_mod higher on the stack pointing into our
3397 stack frame after we return. */
3399 hold_modifiers
= dpi
->modifiers
;
3401 adpm
[0].next
= hold_modifiers
;
3402 dpi
->modifiers
= &adpm
[0];
3404 adpm
[0].printed
= 0;
3405 adpm
[0].templates
= dpi
->templates
;
3408 pdpm
= hold_modifiers
;
3410 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
3411 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
3412 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
3414 if (! pdpm
->printed
)
3416 if (i
>= sizeof adpm
/ sizeof adpm
[0])
3418 d_print_error (dpi
);
3423 adpm
[i
].next
= dpi
->modifiers
;
3424 dpi
->modifiers
= &adpm
[i
];
3432 d_print_comp (dpi
, d_right (dc
));
3434 dpi
->modifiers
= hold_modifiers
;
3436 if (adpm
[0].printed
)
3442 d_print_mod (dpi
, adpm
[i
].mod
);
3445 d_print_array_type (dpi
, dc
, dpi
->modifiers
);
3450 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3452 struct d_print_mod dpm
;
3454 dpm
.next
= dpi
->modifiers
;
3455 dpi
->modifiers
= &dpm
;
3458 dpm
.templates
= dpi
->templates
;
3460 d_print_comp (dpi
, d_right (dc
));
3462 /* If the modifier didn't get printed by the type, print it
3466 d_append_char (dpi
, ' ');
3467 d_print_comp (dpi
, d_left (dc
));
3468 d_append_string (dpi
, "::*");
3471 dpi
->modifiers
= dpm
.next
;
3476 case DEMANGLE_COMPONENT_ARGLIST
:
3477 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3478 d_print_comp (dpi
, d_left (dc
));
3479 if (d_right (dc
) != NULL
)
3481 d_append_string (dpi
, ", ");
3482 d_print_comp (dpi
, d_right (dc
));
3486 case DEMANGLE_COMPONENT_OPERATOR
:
3490 d_append_string (dpi
, "operator");
3491 c
= dc
->u
.s_operator
.op
->name
[0];
3493 d_append_char (dpi
, ' ');
3494 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
3495 dc
->u
.s_operator
.op
->len
);
3499 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3500 d_append_string (dpi
, "operator ");
3501 d_print_comp (dpi
, dc
->u
.s_extended_operator
.name
);
3504 case DEMANGLE_COMPONENT_CAST
:
3505 d_append_string (dpi
, "operator ");
3506 d_print_cast (dpi
, dc
);
3509 case DEMANGLE_COMPONENT_UNARY
:
3510 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_CAST
)
3511 d_print_expr_op (dpi
, d_left (dc
));
3514 d_append_char (dpi
, '(');
3515 d_print_cast (dpi
, d_left (dc
));
3516 d_append_char (dpi
, ')');
3518 d_append_char (dpi
, '(');
3519 d_print_comp (dpi
, d_right (dc
));
3520 d_append_char (dpi
, ')');
3523 case DEMANGLE_COMPONENT_BINARY
:
3524 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
3526 d_print_error (dpi
);
3530 /* We wrap an expression which uses the greater-than operator in
3531 an extra layer of parens so that it does not get confused
3532 with the '>' which ends the template parameters. */
3533 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
3534 && d_left (dc
)->u
.s_operator
.op
->len
== 1
3535 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
3536 d_append_char (dpi
, '(');
3538 d_append_char (dpi
, '(');
3539 d_print_comp (dpi
, d_left (d_right (dc
)));
3540 d_append_string (dpi
, ") ");
3541 d_print_expr_op (dpi
, d_left (dc
));
3542 d_append_string (dpi
, " (");
3543 d_print_comp (dpi
, d_right (d_right (dc
)));
3544 d_append_char (dpi
, ')');
3546 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
3547 && d_left (dc
)->u
.s_operator
.op
->len
== 1
3548 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
3549 d_append_char (dpi
, ')');
3553 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3554 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
3555 d_print_error (dpi
);
3558 case DEMANGLE_COMPONENT_TRINARY
:
3559 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
3560 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
3562 d_print_error (dpi
);
3565 d_append_char (dpi
, '(');
3566 d_print_comp (dpi
, d_left (d_right (dc
)));
3567 d_append_string (dpi
, ") ");
3568 d_print_expr_op (dpi
, d_left (dc
));
3569 d_append_string (dpi
, " (");
3570 d_print_comp (dpi
, d_left (d_right (d_right (dc
))));
3571 d_append_string (dpi
, ") : (");
3572 d_print_comp (dpi
, d_right (d_right (d_right (dc
))));
3573 d_append_char (dpi
, ')');
3576 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3577 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3578 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
3579 d_print_error (dpi
);
3582 case DEMANGLE_COMPONENT_LITERAL
:
3583 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3585 enum d_builtin_type_print tp
;
3587 /* For some builtin types, produce simpler output. */
3588 tp
= D_PRINT_DEFAULT
;
3589 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
3591 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
3595 case D_PRINT_UNSIGNED
:
3597 case D_PRINT_UNSIGNED_LONG
:
3598 case D_PRINT_LONG_LONG
:
3599 case D_PRINT_UNSIGNED_LONG_LONG
:
3600 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
3602 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
3603 d_append_char (dpi
, '-');
3604 d_print_comp (dpi
, d_right (dc
));
3609 case D_PRINT_UNSIGNED
:
3610 d_append_char (dpi
, 'u');
3613 d_append_char (dpi
, 'l');
3615 case D_PRINT_UNSIGNED_LONG
:
3616 d_append_string (dpi
, "ul");
3618 case D_PRINT_LONG_LONG
:
3619 d_append_string (dpi
, "ll");
3621 case D_PRINT_UNSIGNED_LONG_LONG
:
3622 d_append_string (dpi
, "ull");
3630 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
3631 && d_right (dc
)->u
.s_name
.len
== 1
3632 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
3634 switch (d_right (dc
)->u
.s_name
.s
[0])
3637 d_append_string (dpi
, "false");
3640 d_append_string (dpi
, "true");
3653 d_append_char (dpi
, '(');
3654 d_print_comp (dpi
, d_left (dc
));
3655 d_append_char (dpi
, ')');
3656 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
3657 d_append_char (dpi
, '-');
3658 if (tp
== D_PRINT_FLOAT
)
3659 d_append_char (dpi
, '[');
3660 d_print_comp (dpi
, d_right (dc
));
3661 if (tp
== D_PRINT_FLOAT
)
3662 d_append_char (dpi
, ']');
3666 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
3667 d_append_string (dpi
, "java resource ");
3668 d_print_comp (dpi
, d_left (dc
));
3671 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
3672 d_print_comp (dpi
, d_left (dc
));
3673 d_print_comp (dpi
, d_right (dc
));
3676 case DEMANGLE_COMPONENT_CHARACTER
:
3677 d_append_char (dpi
, dc
->u
.s_character
.character
);
3681 d_print_error (dpi
);
3686 /* Print a Java dentifier. For Java we try to handle encoded extended
3687 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
3688 so we don't it for C++. Characters are encoded as
3692 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
3698 for (p
= name
; p
< end
; ++p
)
3709 for (q
= p
+ 3; q
< end
; ++q
)
3715 else if (*q
>= 'A' && *q
<= 'F')
3716 dig
= *q
- 'A' + 10;
3717 else if (*q
>= 'a' && *q
<= 'f')
3718 dig
= *q
- 'a' + 10;
3724 /* If the Unicode character is larger than 256, we don't try
3725 to deal with it here. FIXME. */
3726 if (q
< end
&& *q
== '_' && c
< 256)
3728 d_append_char (dpi
, c
);
3734 d_append_char (dpi
, *p
);
3738 /* Print a list of modifiers. SUFFIX is 1 if we are printing
3739 qualifiers on this after printing a function. */
3742 d_print_mod_list (struct d_print_info
*dpi
,
3743 struct d_print_mod
*mods
, int suffix
)
3745 struct d_print_template
*hold_dpt
;
3747 if (mods
== NULL
|| d_print_saw_error (dpi
))
3752 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3753 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3754 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
)))
3756 d_print_mod_list (dpi
, mods
->next
, suffix
);
3762 hold_dpt
= dpi
->templates
;
3763 dpi
->templates
= mods
->templates
;
3765 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
3767 d_print_function_type (dpi
, mods
->mod
, mods
->next
);
3768 dpi
->templates
= hold_dpt
;
3771 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
3773 d_print_array_type (dpi
, mods
->mod
, mods
->next
);
3774 dpi
->templates
= hold_dpt
;
3777 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
3779 struct d_print_mod
*hold_modifiers
;
3780 struct demangle_component
*dc
;
3782 /* When this is on the modifier stack, we have pulled any
3783 qualifiers off the right argument already. Otherwise, we
3784 print it as usual, but don't let the left argument see any
3787 hold_modifiers
= dpi
->modifiers
;
3788 dpi
->modifiers
= NULL
;
3789 d_print_comp (dpi
, d_left (mods
->mod
));
3790 dpi
->modifiers
= hold_modifiers
;
3792 if ((dpi
->options
& DMGL_JAVA
) == 0)
3793 d_append_string (dpi
, "::");
3795 d_append_char (dpi
, '.');
3797 dc
= d_right (mods
->mod
);
3798 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
3799 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
3800 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
)
3803 d_print_comp (dpi
, dc
);
3805 dpi
->templates
= hold_dpt
;
3809 d_print_mod (dpi
, mods
->mod
);
3811 dpi
->templates
= hold_dpt
;
3813 d_print_mod_list (dpi
, mods
->next
, suffix
);
3816 /* Print a modifier. */
3819 d_print_mod (struct d_print_info
*dpi
,
3820 const struct demangle_component
*mod
)
3824 case DEMANGLE_COMPONENT_RESTRICT
:
3825 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3826 d_append_string (dpi
, " restrict");
3828 case DEMANGLE_COMPONENT_VOLATILE
:
3829 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3830 d_append_string (dpi
, " volatile");
3832 case DEMANGLE_COMPONENT_CONST
:
3833 case DEMANGLE_COMPONENT_CONST_THIS
:
3834 d_append_string (dpi
, " const");
3836 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3837 d_append_char (dpi
, ' ');
3838 d_print_comp (dpi
, d_right (mod
));
3840 case DEMANGLE_COMPONENT_POINTER
:
3841 /* There is no pointer symbol in Java. */
3842 if ((dpi
->options
& DMGL_JAVA
) == 0)
3843 d_append_char (dpi
, '*');
3845 case DEMANGLE_COMPONENT_REFERENCE
:
3846 d_append_char (dpi
, '&');
3848 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3849 d_append_string (dpi
, "&&");
3851 case DEMANGLE_COMPONENT_COMPLEX
:
3852 d_append_string (dpi
, "complex ");
3854 case DEMANGLE_COMPONENT_IMAGINARY
:
3855 d_append_string (dpi
, "imaginary ");
3857 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3858 if (d_last_char (dpi
) != '(')
3859 d_append_char (dpi
, ' ');
3860 d_print_comp (dpi
, d_left (mod
));
3861 d_append_string (dpi
, "::*");
3863 case DEMANGLE_COMPONENT_TYPED_NAME
:
3864 d_print_comp (dpi
, d_left (mod
));
3867 /* Otherwise, we have something that won't go back on the
3868 modifier stack, so we can just print it. */
3869 d_print_comp (dpi
, mod
);
3874 /* Print a function type, except for the return type. */
3877 d_print_function_type (struct d_print_info
*dpi
,
3878 const struct demangle_component
*dc
,
3879 struct d_print_mod
*mods
)
3884 struct d_print_mod
*p
;
3885 struct d_print_mod
*hold_modifiers
;
3890 for (p
= mods
; p
!= NULL
; p
= p
->next
)
3896 switch (p
->mod
->type
)
3898 case DEMANGLE_COMPONENT_POINTER
:
3899 case DEMANGLE_COMPONENT_REFERENCE
:
3900 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3903 case DEMANGLE_COMPONENT_RESTRICT
:
3904 case DEMANGLE_COMPONENT_VOLATILE
:
3905 case DEMANGLE_COMPONENT_CONST
:
3906 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3907 case DEMANGLE_COMPONENT_COMPLEX
:
3908 case DEMANGLE_COMPONENT_IMAGINARY
:
3909 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3913 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3914 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3915 case DEMANGLE_COMPONENT_CONST_THIS
:
3924 if (d_left (dc
) != NULL
&& ! saw_mod
)
3931 if (d_last_char (dpi
) != '('
3932 && d_last_char (dpi
) != '*')
3935 if (need_space
&& d_last_char (dpi
) != ' ')
3936 d_append_char (dpi
, ' ');
3937 d_append_char (dpi
, '(');
3940 hold_modifiers
= dpi
->modifiers
;
3941 dpi
->modifiers
= NULL
;
3943 d_print_mod_list (dpi
, mods
, 0);
3946 d_append_char (dpi
, ')');
3948 d_append_char (dpi
, '(');
3950 if (d_right (dc
) != NULL
)
3951 d_print_comp (dpi
, d_right (dc
));
3953 d_append_char (dpi
, ')');
3955 d_print_mod_list (dpi
, mods
, 1);
3957 dpi
->modifiers
= hold_modifiers
;
3960 /* Print an array type, except for the element type. */
3963 d_print_array_type (struct d_print_info
*dpi
,
3964 const struct demangle_component
*dc
,
3965 struct d_print_mod
*mods
)
3973 struct d_print_mod
*p
;
3976 for (p
= mods
; p
!= NULL
; p
= p
->next
)
3980 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
3995 d_append_string (dpi
, " (");
3997 d_print_mod_list (dpi
, mods
, 0);
4000 d_append_char (dpi
, ')');
4004 d_append_char (dpi
, ' ');
4006 d_append_char (dpi
, '[');
4008 if (d_left (dc
) != NULL
)
4009 d_print_comp (dpi
, d_left (dc
));
4011 d_append_char (dpi
, ']');
4014 /* Print an operator in an expression. */
4017 d_print_expr_op (struct d_print_info
*dpi
,
4018 const struct demangle_component
*dc
)
4020 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
4021 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
4022 dc
->u
.s_operator
.op
->len
);
4024 d_print_comp (dpi
, dc
);
4030 d_print_cast (struct d_print_info
*dpi
,
4031 const struct demangle_component
*dc
)
4033 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
4034 d_print_comp (dpi
, d_left (dc
));
4037 struct d_print_mod
*hold_dpm
;
4038 struct d_print_template dpt
;
4040 /* It appears that for a templated cast operator, we need to put
4041 the template parameters in scope for the operator name, but
4042 not for the parameters. The effect is that we need to handle
4043 the template printing here. */
4045 hold_dpm
= dpi
->modifiers
;
4046 dpi
->modifiers
= NULL
;
4048 dpt
.next
= dpi
->templates
;
4049 dpi
->templates
= &dpt
;
4050 dpt
.template_decl
= d_left (dc
);
4052 d_print_comp (dpi
, d_left (d_left (dc
)));
4054 dpi
->templates
= dpt
.next
;
4056 if (d_last_char (dpi
) == '<')
4057 d_append_char (dpi
, ' ');
4058 d_append_char (dpi
, '<');
4059 d_print_comp (dpi
, d_right (d_left (dc
)));
4060 /* Avoid generating two consecutive '>' characters, to avoid
4061 the C++ syntactic ambiguity. */
4062 if (d_last_char (dpi
) == '>')
4063 d_append_char (dpi
, ' ');
4064 d_append_char (dpi
, '>');
4066 dpi
->modifiers
= hold_dpm
;
4070 /* Initialize the information structure we use to pass around
4073 CP_STATIC_IF_GLIBCPP_V3
4075 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
4079 di
->send
= mangled
+ len
;
4080 di
->options
= options
;
4084 /* We can not need more components than twice the number of chars in
4085 the mangled string. Most components correspond directly to
4086 chars, but the ARGLIST types are exceptions. */
4087 di
->num_comps
= 2 * len
;
4090 /* Similarly, we can not need more substitutions than there are
4091 chars in the mangled string. */
4096 di
->last_name
= NULL
;
4101 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
4102 mangled name, return strings in repeated callback giving the demangled
4103 name. OPTIONS is the usual libiberty demangler options. On success,
4104 this returns 1. On failure, returns 0. */
4107 d_demangle_callback (const char *mangled
, int options
,
4108 demangle_callbackref callback
, void *opaque
)
4112 struct demangle_component
*dc
;
4115 if (mangled
[0] == '_' && mangled
[1] == 'Z')
4117 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
4118 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
4119 && (mangled
[9] == 'D' || mangled
[9] == 'I')
4120 && mangled
[10] == '_')
4124 intro
= (mangled
[9] == 'I')
4125 ? "global constructors keyed to "
4126 : "global destructors keyed to ";
4128 callback (intro
, strlen (intro
), opaque
);
4129 callback (mangled
+ 11, strlen (mangled
+ 11), opaque
);
4134 if ((options
& DMGL_TYPES
) == 0)
4139 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
4142 #ifdef CP_DYNAMIC_ARRAYS
4143 __extension__
struct demangle_component comps
[di
.num_comps
];
4144 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4149 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4150 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4154 dc
= cplus_demangle_type (&di
);
4156 dc
= cplus_demangle_mangled_name (&di
, 1);
4158 /* If DMGL_PARAMS is set, then if we didn't consume the entire
4159 mangled string, then we didn't successfully demangle it. If
4160 DMGL_PARAMS is not set, we didn't look at the trailing
4162 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
4165 #ifdef CP_DEMANGLE_DEBUG
4169 status
= (dc
!= NULL
)
4170 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
4177 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
4178 name, return a buffer allocated with malloc holding the demangled
4179 name. OPTIONS is the usual libiberty demangler options. On
4180 success, this sets *PALC to the allocated size of the returned
4181 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
4182 a memory allocation failure, and returns NULL. */
4185 d_demangle (const char *mangled
, int options
, size_t *palc
)
4187 struct d_growable_string dgs
;
4190 d_growable_string_init (&dgs
, 0);
4192 status
= d_demangle_callback (mangled
, options
,
4193 d_growable_string_callback_adapter
, &dgs
);
4201 *palc
= dgs
.allocation_failure
? 1 : 0;
4205 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4207 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
4209 /* ia64 ABI-mandated entry point in the C++ runtime library for
4210 performing demangling. MANGLED_NAME is a NUL-terminated character
4211 string containing the name to be demangled.
4213 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
4214 *LENGTH bytes, into which the demangled name is stored. If
4215 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
4216 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
4217 is placed in a region of memory allocated with malloc.
4219 If LENGTH is non-NULL, the length of the buffer containing the
4220 demangled name, is placed in *LENGTH.
4222 The return value is a pointer to the start of the NUL-terminated
4223 demangled name, or NULL if the demangling fails. The caller is
4224 responsible for deallocating this memory using free.
4226 *STATUS is set to one of the following values:
4227 0: The demangling operation succeeded.
4228 -1: A memory allocation failure occurred.
4229 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4230 -3: One of the arguments is invalid.
4232 The demangling is performed using the C++ ABI mangling rules, with
4236 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
4237 size_t *length
, int *status
)
4242 if (mangled_name
== NULL
)
4249 if (output_buffer
!= NULL
&& length
== NULL
)
4256 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
4258 if (demangled
== NULL
)
4270 if (output_buffer
== NULL
)
4277 if (strlen (demangled
) < *length
)
4279 strcpy (output_buffer
, demangled
);
4281 demangled
= output_buffer
;
4285 free (output_buffer
);
4296 extern int __gcclibcxx_demangle_callback (const char *,
4298 (const char *, size_t, void *),
4301 /* Alternative, allocationless entry point in the C++ runtime library
4302 for performing demangling. MANGLED_NAME is a NUL-terminated character
4303 string containing the name to be demangled.
4305 CALLBACK is a callback function, called with demangled string
4306 segments as demangling progresses; it is called at least once,
4307 but may be called more than once. OPAQUE is a generalized pointer
4308 used as a callback argument.
4310 The return code is one of the following values, equivalent to
4311 the STATUS values of __cxa_demangle() (excluding -1, since this
4312 function performs no memory allocations):
4313 0: The demangling operation succeeded.
4314 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
4315 -3: One of the arguments is invalid.
4317 The demangling is performed using the C++ ABI mangling rules, with
4321 __gcclibcxx_demangle_callback (const char *mangled_name
,
4322 void (*callback
) (const char *, size_t, void *),
4327 if (mangled_name
== NULL
|| callback
== NULL
)
4330 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
4338 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
4340 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
4341 mangled name, return a buffer allocated with malloc holding the
4342 demangled name. Otherwise, return NULL. */
4345 cplus_demangle_v3 (const char *mangled
, int options
)
4349 return d_demangle (mangled
, options
, &alc
);
4353 cplus_demangle_v3_callback (const char *mangled
, int options
,
4354 demangle_callbackref callback
, void *opaque
)
4356 return d_demangle_callback (mangled
, options
, callback
, opaque
);
4359 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
4360 conventions, but the output formatting is a little different.
4361 This instructs the C++ demangler not to emit pointer characters ("*"), to
4362 use Java's namespace separator symbol ("." instead of "::"), and to output
4363 JArray<TYPE> as TYPE[]. */
4366 java_demangle_v3 (const char *mangled
)
4370 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
4374 java_demangle_v3_callback (const char *mangled
,
4375 demangle_callbackref callback
, void *opaque
)
4377 return d_demangle_callback (mangled
,
4378 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
4382 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
4384 #ifndef IN_GLIBCPP_V3
4386 /* Demangle a string in order to find out whether it is a constructor
4387 or destructor. Return non-zero on success. Set *CTOR_KIND and
4388 *DTOR_KIND appropriately. */
4391 is_ctor_or_dtor (const char *mangled
,
4392 enum gnu_v3_ctor_kinds
*ctor_kind
,
4393 enum gnu_v3_dtor_kinds
*dtor_kind
)
4396 struct demangle_component
*dc
;
4399 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
4400 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
4402 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
4405 #ifdef CP_DYNAMIC_ARRAYS
4406 __extension__
struct demangle_component comps
[di
.num_comps
];
4407 __extension__
struct demangle_component
*subs
[di
.num_subs
];
4412 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
4413 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
4416 dc
= cplus_demangle_mangled_name (&di
, 1);
4418 /* Note that because we did not pass DMGL_PARAMS, we don't expect
4419 to demangle the entire string. */
4429 case DEMANGLE_COMPONENT_TYPED_NAME
:
4430 case DEMANGLE_COMPONENT_TEMPLATE
:
4431 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4432 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4433 case DEMANGLE_COMPONENT_CONST_THIS
:
4436 case DEMANGLE_COMPONENT_QUAL_NAME
:
4437 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4440 case DEMANGLE_COMPONENT_CTOR
:
4441 *ctor_kind
= dc
->u
.s_ctor
.kind
;
4445 case DEMANGLE_COMPONENT_DTOR
:
4446 *dtor_kind
= dc
->u
.s_dtor
.kind
;
4457 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
4458 name. A non-zero return indicates the type of constructor. */
4460 enum gnu_v3_ctor_kinds
4461 is_gnu_v3_mangled_ctor (const char *name
)
4463 enum gnu_v3_ctor_kinds ctor_kind
;
4464 enum gnu_v3_dtor_kinds dtor_kind
;
4466 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
4467 return (enum gnu_v3_ctor_kinds
) 0;
4472 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
4473 name. A non-zero return indicates the type of destructor. */
4475 enum gnu_v3_dtor_kinds
4476 is_gnu_v3_mangled_dtor (const char *name
)
4478 enum gnu_v3_ctor_kinds ctor_kind
;
4479 enum gnu_v3_dtor_kinds dtor_kind
;
4481 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
4482 return (enum gnu_v3_dtor_kinds
) 0;
4486 #endif /* IN_GLIBCPP_V3 */
4488 #ifdef STANDALONE_DEMANGLER
4491 #include "dyn-string.h"
4493 static void print_usage (FILE* fp
, int exit_value
);
4495 #define IS_ALPHA(CHAR) \
4496 (((CHAR) >= 'a' && (CHAR) <= 'z') \
4497 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
4499 /* Non-zero if CHAR is a character than can occur in a mangled name. */
4500 #define is_mangled_char(CHAR) \
4501 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
4502 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
4504 /* The name of this program, as invoked. */
4505 const char* program_name
;
4507 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
4510 print_usage (FILE* fp
, int exit_value
)
4512 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
4513 fprintf (fp
, "Options:\n");
4514 fprintf (fp
, " -h,--help Display this message.\n");
4515 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
4516 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
4517 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
4522 /* Option specification for getopt_long. */
4523 static const struct option long_options
[] =
4525 { "help", no_argument
, NULL
, 'h' },
4526 { "no-params", no_argument
, NULL
, 'p' },
4527 { "verbose", no_argument
, NULL
, 'v' },
4528 { NULL
, no_argument
, NULL
, 0 },
4531 /* Main entry for a demangling filter executable. It will demangle
4532 its command line arguments, if any. If none are provided, it will
4533 filter stdin to stdout, replacing any recognized mangled C++ names
4534 with their demangled equivalents. */
4537 main (int argc
, char *argv
[])
4541 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
4543 /* Use the program name of this program, as invoked. */
4544 program_name
= argv
[0];
4546 /* Parse options. */
4549 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
4552 case '?': /* Unrecognized option. */
4553 print_usage (stderr
, 1);
4557 print_usage (stdout
, 0);
4561 options
&= ~ DMGL_PARAMS
;
4565 options
|= DMGL_VERBOSE
;
4569 while (opt_char
!= -1);
4572 /* No command line arguments were provided. Filter stdin. */
4574 dyn_string_t mangled
= dyn_string_new (3);
4577 /* Read all of input. */
4578 while (!feof (stdin
))
4582 /* Pile characters into mangled until we hit one that can't
4583 occur in a mangled name. */
4585 while (!feof (stdin
) && is_mangled_char (c
))
4587 dyn_string_append_char (mangled
, c
);
4593 if (dyn_string_length (mangled
) > 0)
4595 #ifdef IN_GLIBCPP_V3
4596 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
4598 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
4608 /* It might not have been a mangled name. Print the
4610 fputs (dyn_string_buf (mangled
), stdout
);
4613 dyn_string_clear (mangled
);
4616 /* If we haven't hit EOF yet, we've read one character that
4617 can't occur in a mangled name, so print it out. */
4622 dyn_string_delete (mangled
);
4625 /* Demangle command line arguments. */
4627 /* Loop over command line arguments. */
4628 for (i
= optind
; i
< argc
; ++i
)
4631 #ifdef IN_GLIBCPP_V3
4635 /* Attempt to demangle. */
4636 #ifdef IN_GLIBCPP_V3
4637 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
4639 s
= cplus_demangle_v3 (argv
[i
], options
);
4642 /* If it worked, print the demangled name. */
4650 #ifdef IN_GLIBCPP_V3
4651 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
4653 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
4662 #endif /* STANDALONE_DEMANGLER */