1 /* Demangler for g++ V3 ABI.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@wasabisystems.com>.
6 This file is part of the libiberty library, which is part of GCC.
8 This file is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combined
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 /* This code implements a demangler for the g++ V3 ABI. The ABI is
33 described on this web page:
34 http://www.codesourcery.com/cxx-abi/abi.html#mangling
36 This code was written while looking at the demangler written by
37 Alex Samuel <samuel@codesourcery.com>.
39 This code first pulls the mangled name apart into a list of
40 components, and then walks the list generating the demangled
43 This file will normally define the following functions, q.v.:
44 char *cplus_demangle_v3(const char *mangled, int options)
45 char *java_demangle_v3(const char *mangled)
46 int cplus_demangle_v3_callback(const char *mangled, int options,
47 demangle_callbackref callback)
48 int java_demangle_v3_callback(const char *mangled,
49 demangle_callbackref callback)
50 enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
51 enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
53 Also, the interface to the component list is public, and defined in
54 demangle.h. The interface consists of these types, which are
55 defined in demangle.h:
56 enum demangle_component_type
57 struct demangle_component
59 and these functions defined in this file:
60 cplus_demangle_fill_name
61 cplus_demangle_fill_extended_operator
62 cplus_demangle_fill_ctor
63 cplus_demangle_fill_dtor
65 cplus_demangle_print_callback
66 and other functions defined in the file cp-demint.c.
68 This file also defines some other functions and variables which are
69 only to be used by the file cp-demint.c.
71 Preprocessor macros you can define while compiling this file:
74 If defined, this file defines the following functions, q.v.:
75 char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
77 int __gcclibcxx_demangle_callback (const char *,
79 (const char *, size_t, void *),
81 instead of cplus_demangle_v3[_callback]() and
82 java_demangle_v3[_callback]().
85 If defined, this file defines only __cxa_demangle() and
86 __gcclibcxx_demangle_callback(), and no other publically visible
87 functions or variables.
90 If defined, this file defines a main() function which demangles
91 any arguments, or, if none, demangles stdin.
94 If defined, turns on debugging mode, which prints information on
95 stdout about the mangled string. This is not generally useful.
98 If defined, additional sanity checks will be performed. It will
99 cause some slowdown, but will allow to catch out-of-bound access
100 errors earlier. This macro is intended for testing and debugging. */
102 #if defined (_AIX) && !defined (__GNUC__)
124 # define alloca __builtin_alloca
126 extern char *alloca ();
127 # endif /* __GNUC__ */
129 #endif /* HAVE_ALLOCA_H */
131 #include "ansidecl.h"
132 #include "libiberty.h"
133 #include "demangle.h"
134 #include "cp-demangle.h"
136 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
137 also rename them via #define to avoid compiler errors when the
138 static definition conflicts with the extern declaration in a header
142 #define CP_STATIC_IF_GLIBCPP_V3 static
144 #define cplus_demangle_fill_name d_fill_name
145 static int d_fill_name (struct demangle_component
*, const char *, int);
147 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
149 d_fill_extended_operator (struct demangle_component
*, int,
150 struct demangle_component
*);
152 #define cplus_demangle_fill_ctor d_fill_ctor
154 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
155 struct demangle_component
*);
157 #define cplus_demangle_fill_dtor d_fill_dtor
159 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
160 struct demangle_component
*);
162 #define cplus_demangle_mangled_name d_mangled_name
163 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
165 #define cplus_demangle_type d_type
166 static struct demangle_component
*d_type (struct d_info
*);
168 #define cplus_demangle_print d_print
169 static char *d_print (int, const struct demangle_component
*, int, size_t *);
171 #define cplus_demangle_print_callback d_print_callback
172 static int d_print_callback (int, const struct demangle_component
*,
173 demangle_callbackref
, void *);
175 #define cplus_demangle_init_info d_init_info
176 static void d_init_info (const char *, int, size_t, struct d_info
*);
178 #else /* ! defined(IN_GLIBCPP_V3) */
179 #define CP_STATIC_IF_GLIBCPP_V3
180 #endif /* ! defined(IN_GLIBCPP_V3) */
182 /* See if the compiler supports dynamic arrays. */
185 #define CP_DYNAMIC_ARRAYS
188 #ifdef __STDC_VERSION__
189 #if __STDC_VERSION__ >= 199901L
190 #define CP_DYNAMIC_ARRAYS
191 #endif /* __STDC__VERSION >= 199901L */
192 #endif /* defined (__STDC_VERSION__) */
193 #endif /* defined (__STDC__) */
194 #endif /* ! defined (__GNUC__) */
196 /* We avoid pulling in the ctype tables, to prevent pulling in
197 additional unresolved symbols when this code is used in a library.
198 FIXME: Is this really a valid reason? This comes from the original
201 As of this writing this file has the following undefined references
202 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
205 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
206 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
207 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
209 /* The prefix prepended by GCC to an identifier represnting the
210 anonymous namespace. */
211 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
212 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
213 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
215 /* Information we keep for the standard substitutions. */
217 struct d_standard_sub_info
219 /* The code for this substitution. */
221 /* The simple string it expands to. */
222 const char *simple_expansion
;
223 /* The length of the simple expansion. */
225 /* The results of a full, verbose, expansion. This is used when
226 qualifying a constructor/destructor, or when in verbose mode. */
227 const char *full_expansion
;
228 /* The length of the full expansion. */
230 /* What to set the last_name field of d_info to; NULL if we should
231 not set it. This is only relevant when qualifying a
232 constructor/destructor. */
233 const char *set_last_name
;
234 /* The length of set_last_name. */
235 int set_last_name_len
;
238 /* Accessors for subtrees of struct demangle_component. */
240 #define d_left(dc) ((dc)->u.s_binary.left)
241 #define d_right(dc) ((dc)->u.s_binary.right)
243 /* A list of templates. This is used while printing. */
245 struct d_print_template
247 /* Next template on the list. */
248 struct d_print_template
*next
;
250 const struct demangle_component
*template_decl
;
253 /* A list of type modifiers. This is used while printing. */
257 /* Next modifier on the list. These are in the reverse of the order
258 in which they appeared in the mangled string. */
259 struct d_print_mod
*next
;
261 const struct demangle_component
*mod
;
262 /* Whether this modifier was printed. */
264 /* The list of templates which applies to this modifier. */
265 struct d_print_template
*templates
;
268 /* We use these structures to hold information during printing. */
270 struct d_growable_string
272 /* Buffer holding the result. */
274 /* Current length of data in buffer. */
276 /* Allocated size of buffer. */
278 /* Set to 1 if we had a memory allocation failure. */
279 int allocation_failure
;
282 /* Stack of components, innermost first, used to avoid loops. */
284 struct d_component_stack
286 /* This component. */
287 const struct demangle_component
*dc
;
288 /* This component's parent. */
289 const struct d_component_stack
*parent
;
292 /* A demangle component and some scope captured when it was first
297 /* The component whose scope this is. */
298 const struct demangle_component
*container
;
299 /* The list of templates, if any, that was current when this
300 scope was captured. */
301 struct d_print_template
*templates
;
304 /* Checkpoint structure to allow backtracking. This holds copies
305 of the fields of struct d_info that need to be restored
306 if a trial parse needs to be backtracked over. */
308 struct d_info_checkpoint
317 enum { D_PRINT_BUFFER_LENGTH
= 256 };
320 /* Fixed-length allocated buffer for demangled data, flushed to the
321 callback with a NUL termination once full. */
322 char buf
[D_PRINT_BUFFER_LENGTH
];
323 /* Current length of data in buffer. */
325 /* The last character printed, saved individually so that it survives
328 /* Callback function to handle demangled buffer flush. */
329 demangle_callbackref callback
;
330 /* Opaque callback argument. */
332 /* The current list of templates, if any. */
333 struct d_print_template
*templates
;
334 /* The current list of modifiers (e.g., pointer, reference, etc.),
336 struct d_print_mod
*modifiers
;
337 /* Set to 1 if we saw a demangling error. */
338 int demangle_failure
;
339 /* The current index into any template argument packs we are using
342 /* Number of d_print_flush calls so far. */
343 unsigned long int flush_count
;
344 /* Stack of components, innermost first, used to avoid loops. */
345 const struct d_component_stack
*component_stack
;
346 /* Array of saved scopes for evaluating substitutions. */
347 struct d_saved_scope
*saved_scopes
;
348 /* Index of the next unused saved scope in the above array. */
349 int next_saved_scope
;
350 /* Number of saved scopes in the above array. */
351 int num_saved_scopes
;
352 /* Array of templates for saving into scopes. */
353 struct d_print_template
*copy_templates
;
354 /* Index of the next unused copy template in the above array. */
355 int next_copy_template
;
356 /* Number of copy templates in the above array. */
357 int num_copy_templates
;
358 /* The nearest enclosing template, if any. */
359 const struct demangle_component
*current_template
;
362 #ifdef CP_DEMANGLE_DEBUG
363 static void d_dump (struct demangle_component
*, int);
366 static struct demangle_component
*
367 d_make_empty (struct d_info
*);
369 static struct demangle_component
*
370 d_make_comp (struct d_info
*, enum demangle_component_type
,
371 struct demangle_component
*,
372 struct demangle_component
*);
374 static struct demangle_component
*
375 d_make_name (struct d_info
*, const char *, int);
377 static struct demangle_component
*
378 d_make_demangle_mangled_name (struct d_info
*, const char *);
380 static struct demangle_component
*
381 d_make_builtin_type (struct d_info
*,
382 const struct demangle_builtin_type_info
*);
384 static struct demangle_component
*
385 d_make_operator (struct d_info
*,
386 const struct demangle_operator_info
*);
388 static struct demangle_component
*
389 d_make_extended_operator (struct d_info
*, int,
390 struct demangle_component
*);
392 static struct demangle_component
*
393 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
394 struct demangle_component
*);
396 static struct demangle_component
*
397 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
398 struct demangle_component
*);
400 static struct demangle_component
*
401 d_make_template_param (struct d_info
*, long);
403 static struct demangle_component
*
404 d_make_sub (struct d_info
*, const char *, int);
407 has_return_type (struct demangle_component
*);
410 is_ctor_dtor_or_conversion (struct demangle_component
*);
412 static struct demangle_component
*d_encoding (struct d_info
*, int);
414 static struct demangle_component
*d_name (struct d_info
*);
416 static struct demangle_component
*d_nested_name (struct d_info
*);
418 static struct demangle_component
*d_prefix (struct d_info
*);
420 static struct demangle_component
*d_unqualified_name (struct d_info
*);
422 static struct demangle_component
*d_source_name (struct d_info
*);
424 static long d_number (struct d_info
*);
426 static struct demangle_component
*d_identifier (struct d_info
*, long);
428 static struct demangle_component
*d_operator_name (struct d_info
*);
430 static struct demangle_component
*d_special_name (struct d_info
*);
432 static int d_call_offset (struct d_info
*, int);
434 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
436 static struct demangle_component
**
437 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
439 static struct demangle_component
*
440 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
442 static struct demangle_component
*
443 d_function_type (struct d_info
*);
445 static struct demangle_component
*
446 d_bare_function_type (struct d_info
*, int);
448 static struct demangle_component
*
449 d_class_enum_type (struct d_info
*);
451 static struct demangle_component
*d_array_type (struct d_info
*);
453 static struct demangle_component
*d_vector_type (struct d_info
*);
455 static struct demangle_component
*
456 d_pointer_to_member_type (struct d_info
*);
458 static struct demangle_component
*
459 d_template_param (struct d_info
*);
461 static struct demangle_component
*d_template_args (struct d_info
*);
463 static struct demangle_component
*
464 d_template_arg (struct d_info
*);
466 static struct demangle_component
*d_expression (struct d_info
*);
468 static struct demangle_component
*d_expr_primary (struct d_info
*);
470 static struct demangle_component
*d_local_name (struct d_info
*);
472 static int d_discriminator (struct d_info
*);
474 static struct demangle_component
*d_lambda (struct d_info
*);
476 static struct demangle_component
*d_unnamed_type (struct d_info
*);
478 static struct demangle_component
*
479 d_clone_suffix (struct d_info
*, struct demangle_component
*);
482 d_add_substitution (struct d_info
*, struct demangle_component
*);
484 static struct demangle_component
*d_substitution (struct d_info
*, int);
486 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
488 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
490 static void d_growable_string_init (struct d_growable_string
*, size_t);
493 d_growable_string_resize (struct d_growable_string
*, size_t);
496 d_growable_string_append_buffer (struct d_growable_string
*,
497 const char *, size_t);
499 d_growable_string_callback_adapter (const char *, size_t, void *);
502 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
503 const struct demangle_component
*);
505 static inline void d_print_error (struct d_print_info
*);
507 static inline int d_print_saw_error (struct d_print_info
*);
509 static inline void d_print_flush (struct d_print_info
*);
511 static inline void d_append_char (struct d_print_info
*, char);
513 static inline void d_append_buffer (struct d_print_info
*,
514 const char *, size_t);
516 static inline void d_append_string (struct d_print_info
*, const char *);
518 static inline char d_last_char (struct d_print_info
*);
521 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
524 d_print_java_identifier (struct d_print_info
*, const char *, int);
527 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
530 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
533 d_print_function_type (struct d_print_info
*, int,
534 const struct demangle_component
*,
535 struct d_print_mod
*);
538 d_print_array_type (struct d_print_info
*, int,
539 const struct demangle_component
*,
540 struct d_print_mod
*);
543 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
546 d_print_cast (struct d_print_info
*, int, const struct demangle_component
*);
548 static int d_demangle_callback (const char *, int,
549 demangle_callbackref
, void *);
550 static char *d_demangle (const char *, int, size_t *);
552 #ifdef CP_DEMANGLE_DEBUG
555 d_dump (struct demangle_component
*dc
, int indent
)
562 printf ("failed demangling\n");
566 for (i
= 0; i
< indent
; ++i
)
571 case DEMANGLE_COMPONENT_NAME
:
572 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
574 case DEMANGLE_COMPONENT_TAGGED_NAME
:
575 printf ("tagged name\n");
576 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
577 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
579 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
580 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
582 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
583 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
585 case DEMANGLE_COMPONENT_CTOR
:
586 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
587 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
589 case DEMANGLE_COMPONENT_DTOR
:
590 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
591 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
593 case DEMANGLE_COMPONENT_SUB_STD
:
594 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
596 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
597 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
599 case DEMANGLE_COMPONENT_OPERATOR
:
600 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
602 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
603 printf ("extended operator with %d args\n",
604 dc
->u
.s_extended_operator
.args
);
605 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
608 case DEMANGLE_COMPONENT_QUAL_NAME
:
609 printf ("qualified name\n");
611 case DEMANGLE_COMPONENT_LOCAL_NAME
:
612 printf ("local name\n");
614 case DEMANGLE_COMPONENT_TYPED_NAME
:
615 printf ("typed name\n");
617 case DEMANGLE_COMPONENT_TEMPLATE
:
618 printf ("template\n");
620 case DEMANGLE_COMPONENT_VTABLE
:
623 case DEMANGLE_COMPONENT_VTT
:
626 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
627 printf ("construction vtable\n");
629 case DEMANGLE_COMPONENT_TYPEINFO
:
630 printf ("typeinfo\n");
632 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
633 printf ("typeinfo name\n");
635 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
636 printf ("typeinfo function\n");
638 case DEMANGLE_COMPONENT_THUNK
:
641 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
642 printf ("virtual thunk\n");
644 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
645 printf ("covariant thunk\n");
647 case DEMANGLE_COMPONENT_JAVA_CLASS
:
648 printf ("java class\n");
650 case DEMANGLE_COMPONENT_GUARD
:
653 case DEMANGLE_COMPONENT_REFTEMP
:
654 printf ("reference temporary\n");
656 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
657 printf ("hidden alias\n");
659 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
660 printf ("transaction clone\n");
662 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
663 printf ("non-transaction clone\n");
665 case DEMANGLE_COMPONENT_RESTRICT
:
666 printf ("restrict\n");
668 case DEMANGLE_COMPONENT_VOLATILE
:
669 printf ("volatile\n");
671 case DEMANGLE_COMPONENT_CONST
:
674 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
675 printf ("restrict this\n");
677 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
678 printf ("volatile this\n");
680 case DEMANGLE_COMPONENT_CONST_THIS
:
681 printf ("const this\n");
683 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
684 printf ("reference this\n");
686 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
687 printf ("rvalue reference this\n");
689 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
690 printf ("vendor type qualifier\n");
692 case DEMANGLE_COMPONENT_POINTER
:
693 printf ("pointer\n");
695 case DEMANGLE_COMPONENT_REFERENCE
:
696 printf ("reference\n");
698 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
699 printf ("rvalue reference\n");
701 case DEMANGLE_COMPONENT_COMPLEX
:
702 printf ("complex\n");
704 case DEMANGLE_COMPONENT_IMAGINARY
:
705 printf ("imaginary\n");
707 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
708 printf ("vendor type\n");
710 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
711 printf ("function type\n");
713 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
714 printf ("array type\n");
716 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
717 printf ("pointer to member type\n");
719 case DEMANGLE_COMPONENT_FIXED_TYPE
:
720 printf ("fixed-point type, accum? %d, sat? %d\n",
721 dc
->u
.s_fixed
.accum
, dc
->u
.s_fixed
.sat
);
722 d_dump (dc
->u
.s_fixed
.length
, indent
+ 2);
724 case DEMANGLE_COMPONENT_ARGLIST
:
725 printf ("argument list\n");
727 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
728 printf ("template argument list\n");
730 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
731 printf ("initializer list\n");
733 case DEMANGLE_COMPONENT_CAST
:
736 case DEMANGLE_COMPONENT_NULLARY
:
737 printf ("nullary operator\n");
739 case DEMANGLE_COMPONENT_UNARY
:
740 printf ("unary operator\n");
742 case DEMANGLE_COMPONENT_BINARY
:
743 printf ("binary operator\n");
745 case DEMANGLE_COMPONENT_BINARY_ARGS
:
746 printf ("binary operator arguments\n");
748 case DEMANGLE_COMPONENT_TRINARY
:
749 printf ("trinary operator\n");
751 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
752 printf ("trinary operator arguments 1\n");
754 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
755 printf ("trinary operator arguments 1\n");
757 case DEMANGLE_COMPONENT_LITERAL
:
758 printf ("literal\n");
760 case DEMANGLE_COMPONENT_LITERAL_NEG
:
761 printf ("negative literal\n");
763 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
764 printf ("java resource\n");
766 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
767 printf ("compound name\n");
769 case DEMANGLE_COMPONENT_CHARACTER
:
770 printf ("character '%c'\n", dc
->u
.s_character
.character
);
772 case DEMANGLE_COMPONENT_NUMBER
:
773 printf ("number %ld\n", dc
->u
.s_number
.number
);
775 case DEMANGLE_COMPONENT_DECLTYPE
:
776 printf ("decltype\n");
778 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
779 printf ("pack expansion\n");
781 case DEMANGLE_COMPONENT_TLS_INIT
:
782 printf ("tls init function\n");
784 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
785 printf ("tls wrapper function\n");
787 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
788 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
789 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
791 case DEMANGLE_COMPONENT_LAMBDA
:
792 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
793 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
797 d_dump (d_left (dc
), indent
+ 2);
798 d_dump (d_right (dc
), indent
+ 2);
801 #endif /* CP_DEMANGLE_DEBUG */
803 /* Fill in a DEMANGLE_COMPONENT_NAME. */
805 CP_STATIC_IF_GLIBCPP_V3
807 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
809 if (p
== NULL
|| s
== NULL
|| len
== 0)
811 p
->type
= DEMANGLE_COMPONENT_NAME
;
813 p
->u
.s_name
.len
= len
;
817 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
819 CP_STATIC_IF_GLIBCPP_V3
821 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
822 struct demangle_component
*name
)
824 if (p
== NULL
|| args
< 0 || name
== NULL
)
826 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
827 p
->u
.s_extended_operator
.args
= args
;
828 p
->u
.s_extended_operator
.name
= name
;
832 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
834 CP_STATIC_IF_GLIBCPP_V3
836 cplus_demangle_fill_ctor (struct demangle_component
*p
,
837 enum gnu_v3_ctor_kinds kind
,
838 struct demangle_component
*name
)
842 || (int) kind
< gnu_v3_complete_object_ctor
843 || (int) kind
> gnu_v3_object_ctor_group
)
845 p
->type
= DEMANGLE_COMPONENT_CTOR
;
846 p
->u
.s_ctor
.kind
= kind
;
847 p
->u
.s_ctor
.name
= name
;
851 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
853 CP_STATIC_IF_GLIBCPP_V3
855 cplus_demangle_fill_dtor (struct demangle_component
*p
,
856 enum gnu_v3_dtor_kinds kind
,
857 struct demangle_component
*name
)
861 || (int) kind
< gnu_v3_deleting_dtor
862 || (int) kind
> gnu_v3_object_dtor_group
)
864 p
->type
= DEMANGLE_COMPONENT_DTOR
;
865 p
->u
.s_dtor
.kind
= kind
;
866 p
->u
.s_dtor
.name
= name
;
870 /* Add a new component. */
872 static struct demangle_component
*
873 d_make_empty (struct d_info
*di
)
875 struct demangle_component
*p
;
877 if (di
->next_comp
>= di
->num_comps
)
879 p
= &di
->comps
[di
->next_comp
];
884 /* Add a new generic component. */
886 static struct demangle_component
*
887 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
888 struct demangle_component
*left
,
889 struct demangle_component
*right
)
891 struct demangle_component
*p
;
893 /* We check for errors here. A typical error would be a NULL return
894 from a subroutine. We catch those here, and return NULL
898 /* These types require two parameters. */
899 case DEMANGLE_COMPONENT_QUAL_NAME
:
900 case DEMANGLE_COMPONENT_LOCAL_NAME
:
901 case DEMANGLE_COMPONENT_TYPED_NAME
:
902 case DEMANGLE_COMPONENT_TAGGED_NAME
:
903 case DEMANGLE_COMPONENT_TEMPLATE
:
904 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
905 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
906 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
907 case DEMANGLE_COMPONENT_UNARY
:
908 case DEMANGLE_COMPONENT_BINARY
:
909 case DEMANGLE_COMPONENT_BINARY_ARGS
:
910 case DEMANGLE_COMPONENT_TRINARY
:
911 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
912 case DEMANGLE_COMPONENT_LITERAL
:
913 case DEMANGLE_COMPONENT_LITERAL_NEG
:
914 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
915 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
916 case DEMANGLE_COMPONENT_CLONE
:
917 if (left
== NULL
|| right
== NULL
)
921 /* These types only require one parameter. */
922 case DEMANGLE_COMPONENT_VTABLE
:
923 case DEMANGLE_COMPONENT_VTT
:
924 case DEMANGLE_COMPONENT_TYPEINFO
:
925 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
926 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
927 case DEMANGLE_COMPONENT_THUNK
:
928 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
929 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
930 case DEMANGLE_COMPONENT_JAVA_CLASS
:
931 case DEMANGLE_COMPONENT_GUARD
:
932 case DEMANGLE_COMPONENT_TLS_INIT
:
933 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
934 case DEMANGLE_COMPONENT_REFTEMP
:
935 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
936 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
937 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
938 case DEMANGLE_COMPONENT_POINTER
:
939 case DEMANGLE_COMPONENT_REFERENCE
:
940 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
941 case DEMANGLE_COMPONENT_COMPLEX
:
942 case DEMANGLE_COMPONENT_IMAGINARY
:
943 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
944 case DEMANGLE_COMPONENT_CAST
:
945 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
946 case DEMANGLE_COMPONENT_DECLTYPE
:
947 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
948 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
949 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
950 case DEMANGLE_COMPONENT_NULLARY
:
951 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
956 /* This needs a right parameter, but the left parameter can be
958 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
959 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
964 /* These are allowed to have no parameters--in some cases they
965 will be filled in later. */
966 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
967 case DEMANGLE_COMPONENT_RESTRICT
:
968 case DEMANGLE_COMPONENT_VOLATILE
:
969 case DEMANGLE_COMPONENT_CONST
:
970 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
971 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
972 case DEMANGLE_COMPONENT_CONST_THIS
:
973 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
974 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
975 case DEMANGLE_COMPONENT_ARGLIST
:
976 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
979 /* Other types should not be seen here. */
984 p
= d_make_empty (di
);
988 p
->u
.s_binary
.left
= left
;
989 p
->u
.s_binary
.right
= right
;
994 /* Add a new demangle mangled name component. */
996 static struct demangle_component
*
997 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
999 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1000 return d_make_name (di
, s
, strlen (s
));
1002 return d_encoding (di
, 0);
1005 /* Add a new name component. */
1007 static struct demangle_component
*
1008 d_make_name (struct d_info
*di
, const char *s
, int len
)
1010 struct demangle_component
*p
;
1012 p
= d_make_empty (di
);
1013 if (! cplus_demangle_fill_name (p
, s
, len
))
1018 /* Add a new builtin type component. */
1020 static struct demangle_component
*
1021 d_make_builtin_type (struct d_info
*di
,
1022 const struct demangle_builtin_type_info
*type
)
1024 struct demangle_component
*p
;
1028 p
= d_make_empty (di
);
1031 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1032 p
->u
.s_builtin
.type
= type
;
1037 /* Add a new operator component. */
1039 static struct demangle_component
*
1040 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1042 struct demangle_component
*p
;
1044 p
= d_make_empty (di
);
1047 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1048 p
->u
.s_operator
.op
= op
;
1053 /* Add a new extended operator component. */
1055 static struct demangle_component
*
1056 d_make_extended_operator (struct d_info
*di
, int args
,
1057 struct demangle_component
*name
)
1059 struct demangle_component
*p
;
1061 p
= d_make_empty (di
);
1062 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1067 static struct demangle_component
*
1068 d_make_default_arg (struct d_info
*di
, int num
,
1069 struct demangle_component
*sub
)
1071 struct demangle_component
*p
= d_make_empty (di
);
1074 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1075 p
->u
.s_unary_num
.num
= num
;
1076 p
->u
.s_unary_num
.sub
= sub
;
1081 /* Add a new constructor component. */
1083 static struct demangle_component
*
1084 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1085 struct demangle_component
*name
)
1087 struct demangle_component
*p
;
1089 p
= d_make_empty (di
);
1090 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1095 /* Add a new destructor component. */
1097 static struct demangle_component
*
1098 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1099 struct demangle_component
*name
)
1101 struct demangle_component
*p
;
1103 p
= d_make_empty (di
);
1104 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1109 /* Add a new template parameter. */
1111 static struct demangle_component
*
1112 d_make_template_param (struct d_info
*di
, long i
)
1114 struct demangle_component
*p
;
1116 p
= d_make_empty (di
);
1119 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1120 p
->u
.s_number
.number
= i
;
1125 /* Add a new function parameter. */
1127 static struct demangle_component
*
1128 d_make_function_param (struct d_info
*di
, long i
)
1130 struct demangle_component
*p
;
1132 p
= d_make_empty (di
);
1135 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1136 p
->u
.s_number
.number
= i
;
1141 /* Add a new standard substitution component. */
1143 static struct demangle_component
*
1144 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1146 struct demangle_component
*p
;
1148 p
= d_make_empty (di
);
1151 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1152 p
->u
.s_string
.string
= name
;
1153 p
->u
.s_string
.len
= len
;
1158 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1160 TOP_LEVEL is non-zero when called at the top level. */
1162 CP_STATIC_IF_GLIBCPP_V3
1163 struct demangle_component
*
1164 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1166 struct demangle_component
*p
;
1168 if (! d_check_char (di
, '_')
1169 /* Allow missing _ if not at toplevel to work around a
1170 bug in G++ abi-version=2 mangling; see the comment in
1171 write_template_arg. */
1174 if (! d_check_char (di
, 'Z'))
1176 p
= d_encoding (di
, top_level
);
1178 /* If at top level and parsing parameters, check for a clone
1180 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1181 while (d_peek_char (di
) == '.'
1182 && (IS_LOWER (d_peek_next_char (di
))
1183 || d_peek_next_char (di
) == '_'
1184 || IS_DIGIT (d_peek_next_char (di
))))
1185 p
= d_clone_suffix (di
, p
);
1190 /* Return whether a function should have a return type. The argument
1191 is the function name, which may be qualified in various ways. The
1192 rules are that template functions have return types with some
1193 exceptions, function types which are not part of a function name
1194 mangling have return types with some exceptions, and non-template
1195 function names do not have return types. The exceptions are that
1196 constructors, destructors, and conversion operators do not have
1200 has_return_type (struct demangle_component
*dc
)
1208 case DEMANGLE_COMPONENT_TEMPLATE
:
1209 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1210 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1211 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1212 case DEMANGLE_COMPONENT_CONST_THIS
:
1213 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1214 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1215 return has_return_type (d_left (dc
));
1219 /* Return whether a name is a constructor, a destructor, or a
1220 conversion operator. */
1223 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1231 case DEMANGLE_COMPONENT_QUAL_NAME
:
1232 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1233 return is_ctor_dtor_or_conversion (d_right (dc
));
1234 case DEMANGLE_COMPONENT_CTOR
:
1235 case DEMANGLE_COMPONENT_DTOR
:
1236 case DEMANGLE_COMPONENT_CAST
:
1241 /* <encoding> ::= <(function) name> <bare-function-type>
1245 TOP_LEVEL is non-zero when called at the top level, in which case
1246 if DMGL_PARAMS is not set we do not demangle the function
1247 parameters. We only set this at the top level, because otherwise
1248 we would not correctly demangle names in local scopes. */
1250 static struct demangle_component
*
1251 d_encoding (struct d_info
*di
, int top_level
)
1253 char peek
= d_peek_char (di
);
1255 if (peek
== 'G' || peek
== 'T')
1256 return d_special_name (di
);
1259 struct demangle_component
*dc
;
1263 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1265 /* Strip off any initial CV-qualifiers, as they really apply
1266 to the `this' parameter, and they were not output by the
1267 v2 demangler without DMGL_PARAMS. */
1268 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1269 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1270 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1271 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1272 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1275 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1276 there may be CV-qualifiers on its right argument which
1277 really apply here; this happens when parsing a class
1278 which is local to a function. */
1279 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1281 struct demangle_component
*dcr
;
1284 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1285 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1286 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1287 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1288 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1290 dc
->u
.s_binary
.right
= dcr
;
1296 peek
= d_peek_char (di
);
1297 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1299 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1300 d_bare_function_type (di
, has_return_type (dc
)));
1304 /* <tagged-name> ::= <name> B <source-name> */
1306 static struct demangle_component
*
1307 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1310 while (peek
= d_peek_char (di
),
1313 struct demangle_component
*tag
;
1315 tag
= d_source_name (di
);
1316 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1321 /* <name> ::= <nested-name>
1323 ::= <unscoped-template-name> <template-args>
1326 <unscoped-name> ::= <unqualified-name>
1327 ::= St <unqualified-name>
1329 <unscoped-template-name> ::= <unscoped-name>
1333 static struct demangle_component
*
1334 d_name (struct d_info
*di
)
1336 char peek
= d_peek_char (di
);
1337 struct demangle_component
*dc
;
1342 return d_nested_name (di
);
1345 return d_local_name (di
);
1348 return d_unqualified_name (di
);
1354 if (d_peek_next_char (di
) != 't')
1356 dc
= d_substitution (di
, 0);
1362 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1363 d_make_name (di
, "std", 3),
1364 d_unqualified_name (di
));
1369 if (d_peek_char (di
) != 'I')
1371 /* The grammar does not permit this case to occur if we
1372 called d_substitution() above (i.e., subst == 1). We
1373 don't bother to check. */
1377 /* This is <template-args>, which means that we just saw
1378 <unscoped-template-name>, which is a substitution
1379 candidate if we didn't just get it from a
1383 if (! d_add_substitution (di
, dc
))
1386 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1387 d_template_args (di
));
1395 dc
= d_unqualified_name (di
);
1396 if (d_peek_char (di
) == 'I')
1398 /* This is <template-args>, which means that we just saw
1399 <unscoped-template-name>, which is a substitution
1401 if (! d_add_substitution (di
, dc
))
1403 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1404 d_template_args (di
));
1410 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1411 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1414 static struct demangle_component
*
1415 d_nested_name (struct d_info
*di
)
1417 struct demangle_component
*ret
;
1418 struct demangle_component
**pret
;
1419 struct demangle_component
*rqual
;
1421 if (! d_check_char (di
, 'N'))
1424 pret
= d_cv_qualifiers (di
, &ret
, 1);
1428 /* Parse the ref-qualifier now and then attach it
1429 once we have something to attach it to. */
1430 rqual
= d_ref_qualifier (di
, NULL
);
1432 *pret
= d_prefix (di
);
1438 d_left (rqual
) = ret
;
1442 if (! d_check_char (di
, 'E'))
1448 /* <prefix> ::= <prefix> <unqualified-name>
1449 ::= <template-prefix> <template-args>
1450 ::= <template-param>
1455 <template-prefix> ::= <prefix> <(template) unqualified-name>
1456 ::= <template-param>
1460 static struct demangle_component
*
1461 d_prefix (struct d_info
*di
)
1463 struct demangle_component
*ret
= NULL
;
1468 enum demangle_component_type comb_type
;
1469 struct demangle_component
*dc
;
1471 peek
= d_peek_char (di
);
1475 /* The older code accepts a <local-name> here, but I don't see
1476 that in the grammar. The older code does not accept a
1477 <template-param> here. */
1479 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1482 char peek2
= d_peek_next_char (di
);
1483 if (peek2
== 'T' || peek2
== 't')
1485 dc
= cplus_demangle_type (di
);
1487 /* Destructor name. */
1488 dc
= d_unqualified_name (di
);
1490 else if (IS_DIGIT (peek
)
1495 dc
= d_unqualified_name (di
);
1496 else if (peek
== 'S')
1497 dc
= d_substitution (di
, 1);
1498 else if (peek
== 'I')
1502 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1503 dc
= d_template_args (di
);
1505 else if (peek
== 'T')
1506 dc
= d_template_param (di
);
1507 else if (peek
== 'E')
1509 else if (peek
== 'M')
1511 /* Initializer scope for a lambda. We don't need to represent
1512 this; the normal code will just treat the variable as a type
1513 scope, which gives appropriate output. */
1525 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1527 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1529 if (! d_add_substitution (di
, ret
))
1535 /* <unqualified-name> ::= <operator-name>
1536 ::= <ctor-dtor-name>
1538 ::= <local-source-name>
1540 <local-source-name> ::= L <source-name> <discriminator>
1543 static struct demangle_component
*
1544 d_unqualified_name (struct d_info
*di
)
1546 struct demangle_component
*ret
;
1549 peek
= d_peek_char (di
);
1550 if (IS_DIGIT (peek
))
1551 ret
= d_source_name (di
);
1552 else if (IS_LOWER (peek
))
1554 ret
= d_operator_name (di
);
1555 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1557 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1558 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1559 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1560 d_source_name (di
));
1563 else if (peek
== 'C' || peek
== 'D')
1564 ret
= d_ctor_dtor_name (di
);
1565 else if (peek
== 'L')
1569 ret
= d_source_name (di
);
1572 if (! d_discriminator (di
))
1575 else if (peek
== 'U')
1577 switch (d_peek_next_char (di
))
1580 ret
= d_lambda (di
);
1583 ret
= d_unnamed_type (di
);
1592 if (d_peek_char (di
) == 'B')
1593 ret
= d_abi_tags (di
, ret
);
1597 /* <source-name> ::= <(positive length) number> <identifier> */
1599 static struct demangle_component
*
1600 d_source_name (struct d_info
*di
)
1603 struct demangle_component
*ret
;
1605 len
= d_number (di
);
1608 ret
= d_identifier (di
, len
);
1609 di
->last_name
= ret
;
1613 /* number ::= [n] <(non-negative decimal integer)> */
1616 d_number (struct d_info
*di
)
1623 peek
= d_peek_char (di
);
1628 peek
= d_peek_char (di
);
1634 if (! IS_DIGIT (peek
))
1640 ret
= ret
* 10 + peek
- '0';
1642 peek
= d_peek_char (di
);
1646 /* Like d_number, but returns a demangle_component. */
1648 static struct demangle_component
*
1649 d_number_component (struct d_info
*di
)
1651 struct demangle_component
*ret
= d_make_empty (di
);
1654 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1655 ret
->u
.s_number
.number
= d_number (di
);
1660 /* identifier ::= <(unqualified source code identifier)> */
1662 static struct demangle_component
*
1663 d_identifier (struct d_info
*di
, long len
)
1669 if (di
->send
- name
< len
)
1672 d_advance (di
, len
);
1674 /* A Java mangled name may have a trailing '$' if it is a C++
1675 keyword. This '$' is not included in the length count. We just
1677 if ((di
->options
& DMGL_JAVA
) != 0
1678 && d_peek_char (di
) == '$')
1681 /* Look for something which looks like a gcc encoding of an
1682 anonymous namespace, and replace it with a more user friendly
1684 if (len
>= (long) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1685 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1686 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1690 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1691 if ((*s
== '.' || *s
== '_' || *s
== '$')
1694 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1695 return d_make_name (di
, "(anonymous namespace)",
1696 sizeof "(anonymous namespace)" - 1);
1700 return d_make_name (di
, name
, len
);
1703 /* operator_name ::= many different two character encodings.
1705 ::= v <digit> <source-name>
1707 This list is sorted for binary search. */
1709 #define NL(s) s, (sizeof s) - 1
1711 CP_STATIC_IF_GLIBCPP_V3
1712 const struct demangle_operator_info cplus_demangle_operators
[] =
1714 { "aN", NL ("&="), 2 },
1715 { "aS", NL ("="), 2 },
1716 { "aa", NL ("&&"), 2 },
1717 { "ad", NL ("&"), 1 },
1718 { "an", NL ("&"), 2 },
1719 { "at", NL ("alignof "), 1 },
1720 { "az", NL ("alignof "), 1 },
1721 { "cc", NL ("const_cast"), 2 },
1722 { "cl", NL ("()"), 2 },
1723 { "cm", NL (","), 2 },
1724 { "co", NL ("~"), 1 },
1725 { "dV", NL ("/="), 2 },
1726 { "da", NL ("delete[] "), 1 },
1727 { "dc", NL ("dynamic_cast"), 2 },
1728 { "de", NL ("*"), 1 },
1729 { "dl", NL ("delete "), 1 },
1730 { "ds", NL (".*"), 2 },
1731 { "dt", NL ("."), 2 },
1732 { "dv", NL ("/"), 2 },
1733 { "eO", NL ("^="), 2 },
1734 { "eo", NL ("^"), 2 },
1735 { "eq", NL ("=="), 2 },
1736 { "ge", NL (">="), 2 },
1737 { "gs", NL ("::"), 1 },
1738 { "gt", NL (">"), 2 },
1739 { "ix", NL ("[]"), 2 },
1740 { "lS", NL ("<<="), 2 },
1741 { "le", NL ("<="), 2 },
1742 { "li", NL ("operator\"\" "), 1 },
1743 { "ls", NL ("<<"), 2 },
1744 { "lt", NL ("<"), 2 },
1745 { "mI", NL ("-="), 2 },
1746 { "mL", NL ("*="), 2 },
1747 { "mi", NL ("-"), 2 },
1748 { "ml", NL ("*"), 2 },
1749 { "mm", NL ("--"), 1 },
1750 { "na", NL ("new[]"), 3 },
1751 { "ne", NL ("!="), 2 },
1752 { "ng", NL ("-"), 1 },
1753 { "nt", NL ("!"), 1 },
1754 { "nw", NL ("new"), 3 },
1755 { "oR", NL ("|="), 2 },
1756 { "oo", NL ("||"), 2 },
1757 { "or", NL ("|"), 2 },
1758 { "pL", NL ("+="), 2 },
1759 { "pl", NL ("+"), 2 },
1760 { "pm", NL ("->*"), 2 },
1761 { "pp", NL ("++"), 1 },
1762 { "ps", NL ("+"), 1 },
1763 { "pt", NL ("->"), 2 },
1764 { "qu", NL ("?"), 3 },
1765 { "rM", NL ("%="), 2 },
1766 { "rS", NL (">>="), 2 },
1767 { "rc", NL ("reinterpret_cast"), 2 },
1768 { "rm", NL ("%"), 2 },
1769 { "rs", NL (">>"), 2 },
1770 { "sc", NL ("static_cast"), 2 },
1771 { "st", NL ("sizeof "), 1 },
1772 { "sz", NL ("sizeof "), 1 },
1773 { "tr", NL ("throw"), 0 },
1774 { "tw", NL ("throw "), 1 },
1775 { NULL
, NULL
, 0, 0 }
1778 static struct demangle_component
*
1779 d_operator_name (struct d_info
*di
)
1784 c1
= d_next_char (di
);
1785 c2
= d_next_char (di
);
1786 if (c1
== 'v' && IS_DIGIT (c2
))
1787 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1788 else if (c1
== 'c' && c2
== 'v')
1790 struct demangle_component
*type
;
1791 int was_conversion
= di
->is_conversion
;
1793 di
->is_conversion
= ! di
->is_expression
;
1794 type
= cplus_demangle_type (di
);
1795 di
->is_conversion
= was_conversion
;
1796 return d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1800 /* LOW is the inclusive lower bound. */
1802 /* HIGH is the exclusive upper bound. We subtract one to ignore
1803 the sentinel at the end of the array. */
1804 int high
= ((sizeof (cplus_demangle_operators
)
1805 / sizeof (cplus_demangle_operators
[0]))
1811 const struct demangle_operator_info
*p
;
1813 i
= low
+ (high
- low
) / 2;
1814 p
= cplus_demangle_operators
+ i
;
1816 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1817 return d_make_operator (di
, p
);
1819 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1829 static struct demangle_component
*
1830 d_make_character (struct d_info
*di
, int c
)
1832 struct demangle_component
*p
;
1833 p
= d_make_empty (di
);
1836 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1837 p
->u
.s_character
.character
= c
;
1842 static struct demangle_component
*
1843 d_java_resource (struct d_info
*di
)
1845 struct demangle_component
*p
= NULL
;
1846 struct demangle_component
*next
= NULL
;
1851 len
= d_number (di
);
1855 /* Eat the leading '_'. */
1856 if (d_next_char (di
) != '_')
1869 /* Each chunk is either a '$' escape... */
1887 next
= d_make_character (di
, c
);
1895 /* ... or a sequence of characters. */
1898 while (i
< len
&& str
[i
] && str
[i
] != '$')
1901 next
= d_make_name (di
, str
, i
);
1914 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1920 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1925 /* <special-name> ::= TV <type>
1929 ::= GV <(object) name>
1930 ::= T <call-offset> <(base) encoding>
1931 ::= Tc <call-offset> <call-offset> <(base) encoding>
1932 Also g++ extensions:
1933 ::= TC <type> <(offset) number> _ <(base) type>
1938 ::= Gr <resource name>
1943 static struct demangle_component
*
1944 d_special_name (struct d_info
*di
)
1946 di
->expansion
+= 20;
1947 if (d_check_char (di
, 'T'))
1949 switch (d_next_char (di
))
1953 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1954 cplus_demangle_type (di
), NULL
);
1956 di
->expansion
-= 10;
1957 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1958 cplus_demangle_type (di
), NULL
);
1960 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
1961 cplus_demangle_type (di
), NULL
);
1963 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
1964 cplus_demangle_type (di
), NULL
);
1967 if (! d_call_offset (di
, 'h'))
1969 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
1970 d_encoding (di
, 0), NULL
);
1973 if (! d_call_offset (di
, 'v'))
1975 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
1976 d_encoding (di
, 0), NULL
);
1979 if (! d_call_offset (di
, '\0'))
1981 if (! d_call_offset (di
, '\0'))
1983 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
1984 d_encoding (di
, 0), NULL
);
1988 struct demangle_component
*derived_type
;
1990 struct demangle_component
*base_type
;
1992 derived_type
= cplus_demangle_type (di
);
1993 offset
= d_number (di
);
1996 if (! d_check_char (di
, '_'))
1998 base_type
= cplus_demangle_type (di
);
1999 /* We don't display the offset. FIXME: We should display
2000 it in verbose mode. */
2002 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2003 base_type
, derived_type
);
2007 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2008 cplus_demangle_type (di
), NULL
);
2010 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2011 cplus_demangle_type (di
), NULL
);
2014 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2018 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2025 else if (d_check_char (di
, 'G'))
2027 switch (d_next_char (di
))
2030 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2034 struct demangle_component
*name
= d_name (di
);
2035 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2036 d_number_component (di
));
2040 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2041 d_encoding (di
, 0), NULL
);
2044 switch (d_next_char (di
))
2047 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2048 d_encoding (di
, 0), NULL
);
2050 /* ??? The proposal is that other letters (such as 'h') stand
2051 for different variants of transaction cloning, such as
2052 compiling directly for hardware transaction support. But
2053 they still should all be transactional clones of some sort
2054 so go ahead and call them that. */
2056 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2057 d_encoding (di
, 0), NULL
);
2061 return d_java_resource (di
);
2071 /* <call-offset> ::= h <nv-offset> _
2074 <nv-offset> ::= <(offset) number>
2076 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2078 The C parameter, if not '\0', is a character we just read which is
2079 the start of the <call-offset>.
2081 We don't display the offset information anywhere. FIXME: We should
2082 display it in verbose mode. */
2085 d_call_offset (struct d_info
*di
, int c
)
2088 c
= d_next_char (di
);
2095 if (! d_check_char (di
, '_'))
2102 if (! d_check_char (di
, '_'))
2108 /* <ctor-dtor-name> ::= C1
2116 static struct demangle_component
*
2117 d_ctor_dtor_name (struct d_info
*di
)
2119 if (di
->last_name
!= NULL
)
2121 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2122 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2123 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2124 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2126 switch (d_peek_char (di
))
2130 enum gnu_v3_ctor_kinds kind
;
2132 switch (d_peek_next_char (di
))
2135 kind
= gnu_v3_complete_object_ctor
;
2138 kind
= gnu_v3_base_object_ctor
;
2141 kind
= gnu_v3_complete_object_allocating_ctor
;
2144 kind
= gnu_v3_unified_ctor
;
2147 kind
= gnu_v3_object_ctor_group
;
2153 return d_make_ctor (di
, kind
, di
->last_name
);
2158 enum gnu_v3_dtor_kinds kind
;
2160 switch (d_peek_next_char (di
))
2163 kind
= gnu_v3_deleting_dtor
;
2166 kind
= gnu_v3_complete_object_dtor
;
2169 kind
= gnu_v3_base_object_dtor
;
2171 /* digit '3' is not used */
2173 kind
= gnu_v3_unified_dtor
;
2176 kind
= gnu_v3_object_dtor_group
;
2182 return d_make_dtor (di
, kind
, di
->last_name
);
2190 /* <type> ::= <builtin-type>
2192 ::= <class-enum-type>
2194 ::= <pointer-to-member-type>
2195 ::= <template-param>
2196 ::= <template-template-param> <template-args>
2198 ::= <CV-qualifiers> <type>
2201 ::= O <type> (C++0x)
2204 ::= U <source-name> <type>
2206 <builtin-type> ::= various one letter codes
2210 CP_STATIC_IF_GLIBCPP_V3
2211 const struct demangle_builtin_type_info
2212 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2214 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2215 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2216 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2217 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2218 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2219 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2220 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2221 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2222 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2223 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2224 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2225 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2226 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2227 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2228 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2230 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2231 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2232 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2233 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2234 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2235 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2236 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2237 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2238 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2239 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2240 D_PRINT_UNSIGNED_LONG_LONG
},
2241 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2242 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2243 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2244 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2245 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2246 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2247 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2248 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2252 CP_STATIC_IF_GLIBCPP_V3
2253 struct demangle_component
*
2254 cplus_demangle_type (struct d_info
*di
)
2257 struct demangle_component
*ret
;
2260 /* The ABI specifies that when CV-qualifiers are used, the base type
2261 is substitutable, and the fully qualified type is substitutable,
2262 but the base type with a strict subset of the CV-qualifiers is
2263 not substitutable. The natural recursive implementation of the
2264 CV-qualifiers would cause subsets to be substitutable, so instead
2265 we pull them all off now.
2267 FIXME: The ABI says that order-insensitive vendor qualifiers
2268 should be handled in the same way, but we have no way to tell
2269 which vendor qualifiers are order-insensitive and which are
2270 order-sensitive. So we just assume that they are all
2271 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2272 __vector, and it treats it as order-sensitive when mangling
2275 peek
= d_peek_char (di
);
2276 if (peek
== 'r' || peek
== 'V' || peek
== 'K')
2278 struct demangle_component
**pret
;
2280 pret
= d_cv_qualifiers (di
, &ret
, 0);
2283 if (d_peek_char (di
) == 'F')
2285 /* cv-qualifiers before a function type apply to 'this',
2286 so avoid adding the unqualified function type to
2287 the substitution list. */
2288 *pret
= d_function_type (di
);
2291 *pret
= cplus_demangle_type (di
);
2294 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2295 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2297 /* Move the ref-qualifier outside the cv-qualifiers so that
2298 they are printed in the right order. */
2299 struct demangle_component
*fn
= d_left (*pret
);
2300 d_left (*pret
) = ret
;
2304 if (! d_add_substitution (di
, ret
))
2313 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2314 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2315 case 'o': case 's': case 't':
2316 case 'v': case 'w': case 'x': case 'y': case 'z':
2317 ret
= d_make_builtin_type (di
,
2318 &cplus_demangle_builtin_types
[peek
- 'a']);
2319 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2326 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2327 d_source_name (di
), NULL
);
2331 ret
= d_function_type (di
);
2334 case '0': case '1': case '2': case '3': case '4':
2335 case '5': case '6': case '7': case '8': case '9':
2338 ret
= d_class_enum_type (di
);
2342 ret
= d_array_type (di
);
2346 ret
= d_pointer_to_member_type (di
);
2350 ret
= d_template_param (di
);
2351 if (d_peek_char (di
) == 'I')
2353 /* This may be <template-template-param> <template-args>.
2354 If this is the type for a conversion operator, we can
2355 have a <template-template-param> here only by following
2356 a derivation like this:
2359 -> <template-prefix> <template-args>
2360 -> <prefix> <template-unqualified-name> <template-args>
2361 -> <unqualified-name> <template-unqualified-name> <template-args>
2362 -> <source-name> <template-unqualified-name> <template-args>
2363 -> <source-name> <operator-name> <template-args>
2364 -> <source-name> cv <type> <template-args>
2365 -> <source-name> cv <template-template-param> <template-args> <template-args>
2367 where the <template-args> is followed by another.
2368 Otherwise, we must have a derivation like this:
2371 -> <template-prefix> <template-args>
2372 -> <prefix> <template-unqualified-name> <template-args>
2373 -> <unqualified-name> <template-unqualified-name> <template-args>
2374 -> <source-name> <template-unqualified-name> <template-args>
2375 -> <source-name> <operator-name> <template-args>
2376 -> <source-name> cv <type> <template-args>
2377 -> <source-name> cv <template-param> <template-args>
2379 where we need to leave the <template-args> to be processed
2380 by d_prefix (following the <template-prefix>).
2382 The <template-template-param> part is a substitution
2384 if (! di
->is_conversion
)
2386 if (! d_add_substitution (di
, ret
))
2388 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2389 d_template_args (di
));
2393 struct demangle_component
*args
;
2394 struct d_info_checkpoint checkpoint
;
2396 d_checkpoint (di
, &checkpoint
);
2397 args
= d_template_args (di
);
2398 if (d_peek_char (di
) == 'I')
2400 if (! d_add_substitution (di
, ret
))
2402 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2406 d_backtrack (di
, &checkpoint
);
2412 /* If this is a special substitution, then it is the start of
2413 <class-enum-type>. */
2417 peek_next
= d_peek_next_char (di
);
2418 if (IS_DIGIT (peek_next
)
2420 || IS_UPPER (peek_next
))
2422 ret
= d_substitution (di
, 0);
2423 /* The substituted name may have been a template name and
2424 may be followed by tepmlate args. */
2425 if (d_peek_char (di
) == 'I')
2426 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2427 d_template_args (di
));
2433 ret
= d_class_enum_type (di
);
2434 /* If the substitution was a complete type, then it is not
2435 a new substitution candidate. However, if the
2436 substitution was followed by template arguments, then
2437 the whole thing is a substitution candidate. */
2438 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2446 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2447 cplus_demangle_type (di
), NULL
);
2452 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2453 cplus_demangle_type (di
), NULL
);
2458 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2459 cplus_demangle_type (di
), NULL
);
2464 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2465 cplus_demangle_type (di
), NULL
);
2470 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2471 cplus_demangle_type (di
), NULL
);
2476 ret
= d_source_name (di
);
2477 if (d_peek_char (di
) == 'I')
2478 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2479 d_template_args (di
));
2480 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2481 cplus_demangle_type (di
), ret
);
2487 peek
= d_next_char (di
);
2492 /* decltype (expression) */
2493 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2494 d_expression (di
), NULL
);
2495 if (ret
&& d_next_char (di
) != 'E')
2501 /* Pack expansion. */
2502 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2503 cplus_demangle_type (di
), NULL
);
2509 ret
= d_make_name (di
, "auto", 4);
2513 /* 32-bit decimal floating point */
2514 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2515 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2519 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2520 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2524 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2525 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2528 /* 16-bit half-precision FP */
2529 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2530 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2534 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2535 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2539 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2540 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2544 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2545 ret
= d_make_empty (di
);
2546 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2547 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2548 /* For demangling we don't care about the bits. */
2550 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2551 if (ret
->u
.s_fixed
.length
== NULL
)
2554 peek
= d_next_char (di
);
2555 ret
->u
.s_fixed
.sat
= (peek
== 's');
2559 ret
= d_vector_type (di
);
2564 /* decltype(nullptr) */
2565 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2566 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2580 if (! d_add_substitution (di
, ret
))
2587 /* <CV-qualifiers> ::= [r] [V] [K] */
2589 static struct demangle_component
**
2590 d_cv_qualifiers (struct d_info
*di
,
2591 struct demangle_component
**pret
, int member_fn
)
2593 struct demangle_component
**pstart
;
2597 peek
= d_peek_char (di
);
2598 while (peek
== 'r' || peek
== 'V' || peek
== 'K')
2600 enum demangle_component_type t
;
2606 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2607 : DEMANGLE_COMPONENT_RESTRICT
);
2608 di
->expansion
+= sizeof "restrict";
2610 else if (peek
== 'V')
2613 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2614 : DEMANGLE_COMPONENT_VOLATILE
);
2615 di
->expansion
+= sizeof "volatile";
2620 ? DEMANGLE_COMPONENT_CONST_THIS
2621 : DEMANGLE_COMPONENT_CONST
);
2622 di
->expansion
+= sizeof "const";
2625 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2628 pret
= &d_left (*pret
);
2630 peek
= d_peek_char (di
);
2633 if (!member_fn
&& peek
== 'F')
2635 while (pstart
!= pret
)
2637 switch ((*pstart
)->type
)
2639 case DEMANGLE_COMPONENT_RESTRICT
:
2640 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2642 case DEMANGLE_COMPONENT_VOLATILE
:
2643 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2645 case DEMANGLE_COMPONENT_CONST
:
2646 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2651 pstart
= &d_left (*pstart
);
2658 /* <ref-qualifier> ::= R
2661 static struct demangle_component
*
2662 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2664 struct demangle_component
*ret
= sub
;
2667 peek
= d_peek_char (di
);
2668 if (peek
== 'R' || peek
== 'O')
2670 enum demangle_component_type t
;
2673 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2674 di
->expansion
+= sizeof "&";
2678 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2679 di
->expansion
+= sizeof "&&";
2683 ret
= d_make_comp (di
, t
, ret
, NULL
);
2689 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
2691 static struct demangle_component
*
2692 d_function_type (struct d_info
*di
)
2694 struct demangle_component
*ret
;
2696 if (! d_check_char (di
, 'F'))
2698 if (d_peek_char (di
) == 'Y')
2700 /* Function has C linkage. We don't print this information.
2701 FIXME: We should print it in verbose mode. */
2704 ret
= d_bare_function_type (di
, 1);
2705 ret
= d_ref_qualifier (di
, ret
);
2707 if (! d_check_char (di
, 'E'))
2714 static struct demangle_component
*
2715 d_parmlist (struct d_info
*di
)
2717 struct demangle_component
*tl
;
2718 struct demangle_component
**ptl
;
2724 struct demangle_component
*type
;
2726 char peek
= d_peek_char (di
);
2727 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2729 if ((peek
== 'R' || peek
== 'O')
2730 && d_peek_next_char (di
) == 'E')
2731 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2733 type
= cplus_demangle_type (di
);
2736 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2739 ptl
= &d_right (*ptl
);
2742 /* There should be at least one parameter type besides the optional
2743 return type. A function which takes no arguments will have a
2744 single parameter type void. */
2748 /* If we have a single parameter type void, omit it. */
2749 if (d_right (tl
) == NULL
2750 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2751 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2753 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2760 /* <bare-function-type> ::= [J]<type>+ */
2762 static struct demangle_component
*
2763 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2765 struct demangle_component
*return_type
;
2766 struct demangle_component
*tl
;
2769 /* Detect special qualifier indicating that the first argument
2770 is the return type. */
2771 peek
= d_peek_char (di
);
2775 has_return_type
= 1;
2778 if (has_return_type
)
2780 return_type
= cplus_demangle_type (di
);
2781 if (return_type
== NULL
)
2787 tl
= d_parmlist (di
);
2791 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2795 /* <class-enum-type> ::= <name> */
2797 static struct demangle_component
*
2798 d_class_enum_type (struct d_info
*di
)
2803 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2804 ::= A [<(dimension) expression>] _ <(element) type>
2807 static struct demangle_component
*
2808 d_array_type (struct d_info
*di
)
2811 struct demangle_component
*dim
;
2813 if (! d_check_char (di
, 'A'))
2816 peek
= d_peek_char (di
);
2819 else if (IS_DIGIT (peek
))
2827 peek
= d_peek_char (di
);
2829 while (IS_DIGIT (peek
));
2830 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2836 dim
= d_expression (di
);
2841 if (! d_check_char (di
, '_'))
2844 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2845 cplus_demangle_type (di
));
2848 /* <vector-type> ::= Dv <number> _ <type>
2849 ::= Dv _ <expression> _ <type> */
2851 static struct demangle_component
*
2852 d_vector_type (struct d_info
*di
)
2855 struct demangle_component
*dim
;
2857 peek
= d_peek_char (di
);
2861 dim
= d_expression (di
);
2864 dim
= d_number_component (di
);
2869 if (! d_check_char (di
, '_'))
2872 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2873 cplus_demangle_type (di
));
2876 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2878 static struct demangle_component
*
2879 d_pointer_to_member_type (struct d_info
*di
)
2881 struct demangle_component
*cl
;
2882 struct demangle_component
*mem
;
2884 if (! d_check_char (di
, 'M'))
2887 cl
= cplus_demangle_type (di
);
2891 /* The ABI says, "The type of a non-static member function is considered
2892 to be different, for the purposes of substitution, from the type of a
2893 namespace-scope or static member function whose type appears
2894 similar. The types of two non-static member functions are considered
2895 to be different, for the purposes of substitution, if the functions
2896 are members of different classes. In other words, for the purposes of
2897 substitution, the class of which the function is a member is
2898 considered part of the type of function."
2900 For a pointer to member function, this call to cplus_demangle_type
2901 will end up adding a (possibly qualified) non-member function type to
2902 the substitution table, which is not correct; however, the member
2903 function type will never be used in a substitution, so putting the
2904 wrong type in the substitution table is harmless. */
2906 mem
= cplus_demangle_type (di
);
2910 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2913 /* <non-negative number> _ */
2916 d_compact_number (struct d_info
*di
)
2919 if (d_peek_char (di
) == '_')
2921 else if (d_peek_char (di
) == 'n')
2924 num
= d_number (di
) + 1;
2926 if (! d_check_char (di
, '_'))
2931 /* <template-param> ::= T_
2932 ::= T <(parameter-2 non-negative) number> _
2935 static struct demangle_component
*
2936 d_template_param (struct d_info
*di
)
2940 if (! d_check_char (di
, 'T'))
2943 param
= d_compact_number (di
);
2949 return d_make_template_param (di
, param
);
2952 /* <template-args> ::= I <template-arg>+ E */
2954 static struct demangle_component
*
2955 d_template_args (struct d_info
*di
)
2957 struct demangle_component
*hold_last_name
;
2958 struct demangle_component
*al
;
2959 struct demangle_component
**pal
;
2961 /* Preserve the last name we saw--don't let the template arguments
2962 clobber it, as that would give us the wrong name for a subsequent
2963 constructor or destructor. */
2964 hold_last_name
= di
->last_name
;
2966 if (d_peek_char (di
) != 'I'
2967 && d_peek_char (di
) != 'J')
2971 if (d_peek_char (di
) == 'E')
2973 /* An argument pack can be empty. */
2975 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
2982 struct demangle_component
*a
;
2984 a
= d_template_arg (di
);
2988 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
2991 pal
= &d_right (*pal
);
2993 if (d_peek_char (di
) == 'E')
3000 di
->last_name
= hold_last_name
;
3005 /* <template-arg> ::= <type>
3006 ::= X <expression> E
3010 static struct demangle_component
*
3011 d_template_arg (struct d_info
*di
)
3013 struct demangle_component
*ret
;
3015 switch (d_peek_char (di
))
3019 ret
= d_expression (di
);
3020 if (! d_check_char (di
, 'E'))
3025 return d_expr_primary (di
);
3029 /* An argument pack. */
3030 return d_template_args (di
);
3033 return cplus_demangle_type (di
);
3037 /* Parse a sequence of expressions until we hit the terminator
3040 static struct demangle_component
*
3041 d_exprlist (struct d_info
*di
, char terminator
)
3043 struct demangle_component
*list
= NULL
;
3044 struct demangle_component
**p
= &list
;
3046 if (d_peek_char (di
) == terminator
)
3049 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3054 struct demangle_component
*arg
= d_expression (di
);
3058 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3063 if (d_peek_char (di
) == terminator
)
3073 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3074 dynamic_cast, static_cast or reinterpret_cast. */
3077 op_is_new_cast (struct demangle_component
*op
)
3079 const char *code
= op
->u
.s_operator
.op
->code
;
3080 return (code
[1] == 'c'
3081 && (code
[0] == 's' || code
[0] == 'd'
3082 || code
[0] == 'c' || code
[0] == 'r'));
3085 /* <expression> ::= <(unary) operator-name> <expression>
3086 ::= <(binary) operator-name> <expression> <expression>
3087 ::= <(trinary) operator-name> <expression> <expression> <expression>
3088 ::= cl <expression>+ E
3090 ::= <template-param>
3091 ::= sr <type> <unqualified-name>
3092 ::= sr <type> <unqualified-name> <template-args>
3096 static inline struct demangle_component
*
3097 d_expression_1 (struct d_info
*di
)
3101 peek
= d_peek_char (di
);
3103 return d_expr_primary (di
);
3104 else if (peek
== 'T')
3105 return d_template_param (di
);
3106 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3108 struct demangle_component
*type
;
3109 struct demangle_component
*name
;
3112 type
= cplus_demangle_type (di
);
3113 name
= d_unqualified_name (di
);
3114 if (d_peek_char (di
) != 'I')
3115 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3117 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3118 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3119 d_template_args (di
)));
3121 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3124 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3125 d_expression_1 (di
), NULL
);
3127 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3129 /* Function parameter used in a late-specified return type. */
3132 if (d_peek_char (di
) == 'T')
3134 /* 'this' parameter. */
3140 index
= d_compact_number (di
) + 1;
3144 return d_make_function_param (di
, index
);
3146 else if (IS_DIGIT (peek
)
3147 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3149 /* We can get an unqualified name as an expression in the case of
3150 a dependent function call, i.e. decltype(f(t)). */
3151 struct demangle_component
*name
;
3154 /* operator-function-id, i.e. operator+(t). */
3157 name
= d_unqualified_name (di
);
3160 if (d_peek_char (di
) == 'I')
3161 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3162 d_template_args (di
));
3166 else if ((peek
== 'i' || peek
== 't')
3167 && d_peek_next_char (di
) == 'l')
3169 /* Brace-enclosed initializer list, untyped or typed. */
3170 struct demangle_component
*type
= NULL
;
3172 type
= cplus_demangle_type (di
);
3173 if (!d_peek_next_char (di
))
3176 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3177 type
, d_exprlist (di
, 'E'));
3181 struct demangle_component
*op
;
3182 const char *code
= NULL
;
3185 op
= d_operator_name (di
);
3189 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3191 code
= op
->u
.s_operator
.op
->code
;
3192 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3193 if (strcmp (code
, "st") == 0)
3194 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3195 cplus_demangle_type (di
));
3202 case DEMANGLE_COMPONENT_OPERATOR
:
3203 args
= op
->u
.s_operator
.op
->args
;
3205 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3206 args
= op
->u
.s_extended_operator
.args
;
3208 case DEMANGLE_COMPONENT_CAST
:
3216 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3220 struct demangle_component
*operand
;
3223 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3224 && code
[1] == code
[0])
3225 /* pp_ and mm_ are the prefix variants. */
3226 suffix
= !d_check_char (di
, '_');
3228 if (op
->type
== DEMANGLE_COMPONENT_CAST
3229 && d_check_char (di
, '_'))
3230 operand
= d_exprlist (di
, 'E');
3232 operand
= d_expression_1 (di
);
3235 /* Indicate the suffix variant for d_print_comp. */
3236 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3238 DEMANGLE_COMPONENT_BINARY_ARGS
,
3241 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3246 struct demangle_component
*left
;
3247 struct demangle_component
*right
;
3251 if (op_is_new_cast (op
))
3252 left
= cplus_demangle_type (di
);
3254 left
= d_expression_1 (di
);
3255 if (!strcmp (code
, "cl"))
3256 right
= d_exprlist (di
, 'E');
3257 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3259 right
= d_unqualified_name (di
);
3260 if (d_peek_char (di
) == 'I')
3261 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3262 right
, d_template_args (di
));
3265 right
= d_expression_1 (di
);
3267 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3269 DEMANGLE_COMPONENT_BINARY_ARGS
,
3274 struct demangle_component
*first
;
3275 struct demangle_component
*second
;
3276 struct demangle_component
*third
;
3280 else if (!strcmp (code
, "qu"))
3282 /* ?: expression. */
3283 first
= d_expression_1 (di
);
3284 second
= d_expression_1 (di
);
3285 third
= d_expression_1 (di
);
3287 else if (code
[0] == 'n')
3289 /* new-expression. */
3290 if (code
[1] != 'w' && code
[1] != 'a')
3292 first
= d_exprlist (di
, '_');
3293 second
= cplus_demangle_type (di
);
3294 if (d_peek_char (di
) == 'E')
3299 else if (d_peek_char (di
) == 'p'
3300 && d_peek_next_char (di
) == 'i')
3302 /* Parenthesized initializer. */
3304 third
= d_exprlist (di
, 'E');
3306 else if (d_peek_char (di
) == 'i'
3307 && d_peek_next_char (di
) == 'l')
3308 /* initializer-list. */
3309 third
= d_expression_1 (di
);
3315 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3317 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3320 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3329 static struct demangle_component
*
3330 d_expression (struct d_info
*di
)
3332 struct demangle_component
*ret
;
3333 int was_expression
= di
->is_expression
;
3335 di
->is_expression
= 1;
3336 ret
= d_expression_1 (di
);
3337 di
->is_expression
= was_expression
;
3341 /* <expr-primary> ::= L <type> <(value) number> E
3342 ::= L <type> <(value) float> E
3343 ::= L <mangled-name> E
3346 static struct demangle_component
*
3347 d_expr_primary (struct d_info
*di
)
3349 struct demangle_component
*ret
;
3351 if (! d_check_char (di
, 'L'))
3353 if (d_peek_char (di
) == '_'
3354 /* Workaround for G++ bug; see comment in write_template_arg. */
3355 || d_peek_char (di
) == 'Z')
3356 ret
= cplus_demangle_mangled_name (di
, 0);
3359 struct demangle_component
*type
;
3360 enum demangle_component_type t
;
3363 type
= cplus_demangle_type (di
);
3367 /* If we have a type we know how to print, we aren't going to
3368 print the type name itself. */
3369 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3370 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3371 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3373 /* Rather than try to interpret the literal value, we just
3374 collect it as a string. Note that it's possible to have a
3375 floating point literal here. The ABI specifies that the
3376 format of such literals is machine independent. That's fine,
3377 but what's not fine is that versions of g++ up to 3.2 with
3378 -fabi-version=1 used upper case letters in the hex constant,
3379 and dumped out gcc's internal representation. That makes it
3380 hard to tell where the constant ends, and hard to dump the
3381 constant in any readable form anyhow. We don't attempt to
3382 handle these cases. */
3384 t
= DEMANGLE_COMPONENT_LITERAL
;
3385 if (d_peek_char (di
) == 'n')
3387 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3391 while (d_peek_char (di
) != 'E')
3393 if (d_peek_char (di
) == '\0')
3397 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3399 if (! d_check_char (di
, 'E'))
3404 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3405 ::= Z <(function) encoding> E s [<discriminator>]
3406 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3409 static struct demangle_component
*
3410 d_local_name (struct d_info
*di
)
3412 struct demangle_component
*function
;
3414 if (! d_check_char (di
, 'Z'))
3417 function
= d_encoding (di
, 0);
3419 if (! d_check_char (di
, 'E'))
3422 if (d_peek_char (di
) == 's')
3425 if (! d_discriminator (di
))
3427 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3428 d_make_name (di
, "string literal",
3429 sizeof "string literal" - 1));
3433 struct demangle_component
*name
;
3436 if (d_peek_char (di
) == 'd')
3438 /* Default argument scope: d <number> _. */
3440 num
= d_compact_number (di
);
3449 /* Lambdas and unnamed types have internal discriminators. */
3450 case DEMANGLE_COMPONENT_LAMBDA
:
3451 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3454 if (! d_discriminator (di
))
3458 name
= d_make_default_arg (di
, num
, name
);
3459 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3463 /* <discriminator> ::= _ <(non-negative) number>
3465 We demangle the discriminator, but we don't print it out. FIXME:
3466 We should print it out in verbose mode. */
3469 d_discriminator (struct d_info
*di
)
3473 if (d_peek_char (di
) != '_')
3476 discrim
= d_number (di
);
3482 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3484 static struct demangle_component
*
3485 d_lambda (struct d_info
*di
)
3487 struct demangle_component
*tl
;
3488 struct demangle_component
*ret
;
3491 if (! d_check_char (di
, 'U'))
3493 if (! d_check_char (di
, 'l'))
3496 tl
= d_parmlist (di
);
3500 if (! d_check_char (di
, 'E'))
3503 num
= d_compact_number (di
);
3507 ret
= d_make_empty (di
);
3510 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3511 ret
->u
.s_unary_num
.sub
= tl
;
3512 ret
->u
.s_unary_num
.num
= num
;
3515 if (! d_add_substitution (di
, ret
))
3521 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3523 static struct demangle_component
*
3524 d_unnamed_type (struct d_info
*di
)
3526 struct demangle_component
*ret
;
3529 if (! d_check_char (di
, 'U'))
3531 if (! d_check_char (di
, 't'))
3534 num
= d_compact_number (di
);
3538 ret
= d_make_empty (di
);
3541 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3542 ret
->u
.s_number
.number
= num
;
3545 if (! d_add_substitution (di
, ret
))
3551 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3554 static struct demangle_component
*
3555 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3557 const char *suffix
= d_str (di
);
3558 const char *pend
= suffix
;
3559 struct demangle_component
*n
;
3561 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3564 while (IS_LOWER (*pend
) || *pend
== '_')
3567 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3570 while (IS_DIGIT (*pend
))
3573 d_advance (di
, pend
- suffix
);
3574 n
= d_make_name (di
, suffix
, pend
- suffix
);
3575 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3578 /* Add a new substitution. */
3581 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3585 if (di
->next_sub
>= di
->num_subs
)
3587 di
->subs
[di
->next_sub
] = dc
;
3592 /* <substitution> ::= S <seq-id> _
3602 If PREFIX is non-zero, then this type is being used as a prefix in
3603 a qualified name. In this case, for the standard substitutions, we
3604 need to check whether we are being used as a prefix for a
3605 constructor or destructor, and return a full template name.
3606 Otherwise we will get something like std::iostream::~iostream()
3607 which does not correspond particularly well to any function which
3608 actually appears in the source.
3611 static const struct d_standard_sub_info standard_subs
[] =
3616 { 'a', NL ("std::allocator"),
3617 NL ("std::allocator"),
3619 { 'b', NL ("std::basic_string"),
3620 NL ("std::basic_string"),
3621 NL ("basic_string") },
3622 { 's', NL ("std::string"),
3623 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3624 NL ("basic_string") },
3625 { 'i', NL ("std::istream"),
3626 NL ("std::basic_istream<char, std::char_traits<char> >"),
3627 NL ("basic_istream") },
3628 { 'o', NL ("std::ostream"),
3629 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3630 NL ("basic_ostream") },
3631 { 'd', NL ("std::iostream"),
3632 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3633 NL ("basic_iostream") }
3636 static struct demangle_component
*
3637 d_substitution (struct d_info
*di
, int prefix
)
3641 if (! d_check_char (di
, 'S'))
3644 c
= d_next_char (di
);
3645 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3654 unsigned int new_id
;
3657 new_id
= id
* 36 + c
- '0';
3658 else if (IS_UPPER (c
))
3659 new_id
= id
* 36 + c
- 'A' + 10;
3665 c
= d_next_char (di
);
3672 if (id
>= (unsigned int) di
->next_sub
)
3677 return di
->subs
[id
];
3682 const struct d_standard_sub_info
*p
;
3683 const struct d_standard_sub_info
*pend
;
3685 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3686 if (! verbose
&& prefix
)
3690 peek
= d_peek_char (di
);
3691 if (peek
== 'C' || peek
== 'D')
3695 pend
= (&standard_subs
[0]
3696 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3697 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3703 struct demangle_component
*c
;
3705 if (p
->set_last_name
!= NULL
)
3706 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3707 p
->set_last_name_len
);
3710 s
= p
->full_expansion
;
3715 s
= p
->simple_expansion
;
3716 len
= p
->simple_len
;
3718 di
->expansion
+= len
;
3719 c
= d_make_sub (di
, s
, len
);
3720 if (d_peek_char (di
) == 'B')
3722 /* If there are ABI tags on the abbreviation, it becomes
3723 a substitution candidate. */
3724 c
= d_abi_tags (di
, c
);
3725 d_add_substitution (di
, c
);
3736 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3738 checkpoint
->n
= di
->n
;
3739 checkpoint
->next_comp
= di
->next_comp
;
3740 checkpoint
->next_sub
= di
->next_sub
;
3741 checkpoint
->did_subs
= di
->did_subs
;
3742 checkpoint
->expansion
= di
->expansion
;
3746 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3748 di
->n
= checkpoint
->n
;
3749 di
->next_comp
= checkpoint
->next_comp
;
3750 di
->next_sub
= checkpoint
->next_sub
;
3751 di
->did_subs
= checkpoint
->did_subs
;
3752 di
->expansion
= checkpoint
->expansion
;
3755 /* Initialize a growable string. */
3758 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3763 dgs
->allocation_failure
= 0;
3766 d_growable_string_resize (dgs
, estimate
);
3769 /* Grow a growable string to a given size. */
3772 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3777 if (dgs
->allocation_failure
)
3780 /* Start allocation at two bytes to avoid any possibility of confusion
3781 with the special value of 1 used as a return in *palc to indicate
3782 allocation failures. */
3783 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3784 while (newalc
< need
)
3787 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3794 dgs
->allocation_failure
= 1;
3801 /* Append a buffer to a growable string. */
3804 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3805 const char *s
, size_t l
)
3809 need
= dgs
->len
+ l
+ 1;
3810 if (need
> dgs
->alc
)
3811 d_growable_string_resize (dgs
, need
);
3813 if (dgs
->allocation_failure
)
3816 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3817 dgs
->buf
[dgs
->len
+ l
] = '\0';
3821 /* Bridge growable strings to the callback mechanism. */
3824 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3826 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3828 d_growable_string_append_buffer (dgs
, s
, l
);
3831 /* Walk the tree, counting the number of templates encountered, and
3832 the number of times a scope might be saved. These counts will be
3833 used to allocate data structures for d_print_comp, so the logic
3834 here must mirror the logic d_print_comp will use. It is not
3835 important that the resulting numbers are exact, so long as they
3836 are larger than the actual numbers encountered. */
3839 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
3840 const struct demangle_component
*dc
)
3847 case DEMANGLE_COMPONENT_NAME
:
3848 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3849 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3850 case DEMANGLE_COMPONENT_SUB_STD
:
3851 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3852 case DEMANGLE_COMPONENT_OPERATOR
:
3853 case DEMANGLE_COMPONENT_CHARACTER
:
3854 case DEMANGLE_COMPONENT_NUMBER
:
3855 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3858 case DEMANGLE_COMPONENT_TEMPLATE
:
3860 goto recurse_left_right
;
3862 case DEMANGLE_COMPONENT_REFERENCE
:
3863 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3864 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
3866 goto recurse_left_right
;
3868 case DEMANGLE_COMPONENT_QUAL_NAME
:
3869 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3870 case DEMANGLE_COMPONENT_TYPED_NAME
:
3871 case DEMANGLE_COMPONENT_VTABLE
:
3872 case DEMANGLE_COMPONENT_VTT
:
3873 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3874 case DEMANGLE_COMPONENT_TYPEINFO
:
3875 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3876 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3877 case DEMANGLE_COMPONENT_THUNK
:
3878 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3879 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3880 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3881 case DEMANGLE_COMPONENT_GUARD
:
3882 case DEMANGLE_COMPONENT_TLS_INIT
:
3883 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
3884 case DEMANGLE_COMPONENT_REFTEMP
:
3885 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3886 case DEMANGLE_COMPONENT_RESTRICT
:
3887 case DEMANGLE_COMPONENT_VOLATILE
:
3888 case DEMANGLE_COMPONENT_CONST
:
3889 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3890 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3891 case DEMANGLE_COMPONENT_CONST_THIS
:
3892 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
3893 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
3894 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3895 case DEMANGLE_COMPONENT_POINTER
:
3896 case DEMANGLE_COMPONENT_COMPLEX
:
3897 case DEMANGLE_COMPONENT_IMAGINARY
:
3898 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3899 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3900 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3901 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3902 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
3903 case DEMANGLE_COMPONENT_ARGLIST
:
3904 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3905 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
3906 case DEMANGLE_COMPONENT_CAST
:
3907 case DEMANGLE_COMPONENT_NULLARY
:
3908 case DEMANGLE_COMPONENT_UNARY
:
3909 case DEMANGLE_COMPONENT_BINARY
:
3910 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3911 case DEMANGLE_COMPONENT_TRINARY
:
3912 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3913 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3914 case DEMANGLE_COMPONENT_LITERAL
:
3915 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3916 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
3917 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
3918 case DEMANGLE_COMPONENT_DECLTYPE
:
3919 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
3920 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
3921 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
3922 case DEMANGLE_COMPONENT_TAGGED_NAME
:
3923 case DEMANGLE_COMPONENT_CLONE
:
3925 d_count_templates_scopes (num_templates
, num_scopes
,
3927 d_count_templates_scopes (num_templates
, num_scopes
,
3931 case DEMANGLE_COMPONENT_CTOR
:
3932 d_count_templates_scopes (num_templates
, num_scopes
,
3936 case DEMANGLE_COMPONENT_DTOR
:
3937 d_count_templates_scopes (num_templates
, num_scopes
,
3941 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3942 d_count_templates_scopes (num_templates
, num_scopes
,
3943 dc
->u
.s_extended_operator
.name
);
3946 case DEMANGLE_COMPONENT_FIXED_TYPE
:
3947 d_count_templates_scopes (num_templates
, num_scopes
,
3948 dc
->u
.s_fixed
.length
);
3951 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
3952 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
3953 d_count_templates_scopes (num_templates
, num_scopes
,
3957 case DEMANGLE_COMPONENT_LAMBDA
:
3958 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
3959 d_count_templates_scopes (num_templates
, num_scopes
,
3960 dc
->u
.s_unary_num
.sub
);
3965 /* Initialize a print information structure. */
3968 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
3969 void *opaque
, const struct demangle_component
*dc
)
3972 dpi
->last_char
= '\0';
3973 dpi
->templates
= NULL
;
3974 dpi
->modifiers
= NULL
;
3975 dpi
->pack_index
= 0;
3976 dpi
->flush_count
= 0;
3978 dpi
->callback
= callback
;
3979 dpi
->opaque
= opaque
;
3981 dpi
->demangle_failure
= 0;
3983 dpi
->component_stack
= NULL
;
3985 dpi
->saved_scopes
= NULL
;
3986 dpi
->next_saved_scope
= 0;
3987 dpi
->num_saved_scopes
= 0;
3989 dpi
->copy_templates
= NULL
;
3990 dpi
->next_copy_template
= 0;
3991 dpi
->num_copy_templates
= 0;
3993 d_count_templates_scopes (&dpi
->num_copy_templates
,
3994 &dpi
->num_saved_scopes
, dc
);
3995 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
3997 dpi
->current_template
= NULL
;
4000 /* Indicate that an error occurred during printing, and test for error. */
4003 d_print_error (struct d_print_info
*dpi
)
4005 dpi
->demangle_failure
= 1;
4009 d_print_saw_error (struct d_print_info
*dpi
)
4011 return dpi
->demangle_failure
!= 0;
4014 /* Flush buffered characters to the callback. */
4017 d_print_flush (struct d_print_info
*dpi
)
4019 dpi
->buf
[dpi
->len
] = '\0';
4020 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4025 /* Append characters and buffers for printing. */
4028 d_append_char (struct d_print_info
*dpi
, char c
)
4030 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4031 d_print_flush (dpi
);
4033 dpi
->buf
[dpi
->len
++] = c
;
4038 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4042 for (i
= 0; i
< l
; i
++)
4043 d_append_char (dpi
, s
[i
]);
4047 d_append_string (struct d_print_info
*dpi
, const char *s
)
4049 d_append_buffer (dpi
, s
, strlen (s
));
4053 d_append_num (struct d_print_info
*dpi
, long l
)
4056 sprintf (buf
,"%ld", l
);
4057 d_append_string (dpi
, buf
);
4061 d_last_char (struct d_print_info
*dpi
)
4063 return dpi
->last_char
;
4066 /* Turn components into a human readable string. OPTIONS is the
4067 options bits passed to the demangler. DC is the tree to print.
4068 CALLBACK is a function to call to flush demangled string segments
4069 as they fill the intermediate buffer, and OPAQUE is a generalized
4070 callback argument. On success, this returns 1. On failure,
4071 it returns 0, indicating a bad parse. It does not use heap
4072 memory to build an output string, so cannot encounter memory
4073 allocation failure. */
4075 CP_STATIC_IF_GLIBCPP_V3
4077 cplus_demangle_print_callback (int options
,
4078 const struct demangle_component
*dc
,
4079 demangle_callbackref callback
, void *opaque
)
4081 struct d_print_info dpi
;
4083 d_print_init (&dpi
, callback
, opaque
, dc
);
4086 #ifdef CP_DYNAMIC_ARRAYS
4087 __extension__
struct d_saved_scope scopes
[dpi
.num_saved_scopes
];
4088 __extension__
struct d_print_template temps
[dpi
.num_copy_templates
];
4090 dpi
.saved_scopes
= scopes
;
4091 dpi
.copy_templates
= temps
;
4093 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4094 * sizeof (*dpi
.saved_scopes
));
4095 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4096 * sizeof (*dpi
.copy_templates
));
4099 d_print_comp (&dpi
, options
, dc
);
4102 d_print_flush (&dpi
);
4104 return ! d_print_saw_error (&dpi
);
4107 /* Turn components into a human readable string. OPTIONS is the
4108 options bits passed to the demangler. DC is the tree to print.
4109 ESTIMATE is a guess at the length of the result. This returns a
4110 string allocated by malloc, or NULL on error. On success, this
4111 sets *PALC to the size of the allocated buffer. On failure, this
4112 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4115 CP_STATIC_IF_GLIBCPP_V3
4117 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4118 int estimate
, size_t *palc
)
4120 struct d_growable_string dgs
;
4122 d_growable_string_init (&dgs
, estimate
);
4124 if (! cplus_demangle_print_callback (options
, dc
,
4125 d_growable_string_callback_adapter
,
4133 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4137 /* Returns the I'th element of the template arglist ARGS, or NULL on
4140 static struct demangle_component
*
4141 d_index_template_argument (struct demangle_component
*args
, int i
)
4143 struct demangle_component
*a
;
4149 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4155 if (i
!= 0 || a
== NULL
)
4161 /* Returns the template argument from the current context indicated by DC,
4162 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4164 static struct demangle_component
*
4165 d_lookup_template_argument (struct d_print_info
*dpi
,
4166 const struct demangle_component
*dc
)
4168 if (dpi
->templates
== NULL
)
4170 d_print_error (dpi
);
4174 return d_index_template_argument
4175 (d_right (dpi
->templates
->template_decl
),
4176 dc
->u
.s_number
.number
);
4179 /* Returns a template argument pack used in DC (any will do), or NULL. */
4181 static struct demangle_component
*
4182 d_find_pack (struct d_print_info
*dpi
,
4183 const struct demangle_component
*dc
)
4185 struct demangle_component
*a
;
4191 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4192 a
= d_lookup_template_argument (dpi
, dc
);
4193 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4197 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4200 case DEMANGLE_COMPONENT_LAMBDA
:
4201 case DEMANGLE_COMPONENT_NAME
:
4202 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4203 case DEMANGLE_COMPONENT_OPERATOR
:
4204 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4205 case DEMANGLE_COMPONENT_SUB_STD
:
4206 case DEMANGLE_COMPONENT_CHARACTER
:
4207 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4208 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4209 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4210 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4211 case DEMANGLE_COMPONENT_NUMBER
:
4214 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4215 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4216 case DEMANGLE_COMPONENT_CTOR
:
4217 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4218 case DEMANGLE_COMPONENT_DTOR
:
4219 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4222 a
= d_find_pack (dpi
, d_left (dc
));
4225 return d_find_pack (dpi
, d_right (dc
));
4229 /* Returns the length of the template argument pack DC. */
4232 d_pack_length (const struct demangle_component
*dc
)
4235 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4236 && d_left (dc
) != NULL
)
4244 /* DC is a component of a mangled expression. Print it, wrapped in parens
4248 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4249 const struct demangle_component
*dc
)
4252 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4253 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4254 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4255 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4258 d_append_char (dpi
, '(');
4259 d_print_comp (dpi
, options
, dc
);
4261 d_append_char (dpi
, ')');
4264 /* Save the current scope. */
4267 d_save_scope (struct d_print_info
*dpi
,
4268 const struct demangle_component
*container
)
4270 struct d_saved_scope
*scope
;
4271 struct d_print_template
*src
, **link
;
4273 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4275 d_print_error (dpi
);
4278 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4279 dpi
->next_saved_scope
++;
4281 scope
->container
= container
;
4282 link
= &scope
->templates
;
4284 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4286 struct d_print_template
*dst
;
4288 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4290 d_print_error (dpi
);
4293 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4294 dpi
->next_copy_template
++;
4296 dst
->template_decl
= src
->template_decl
;
4304 /* Attempt to locate a previously saved scope. Returns NULL if no
4305 corresponding saved scope was found. */
4307 static struct d_saved_scope
*
4308 d_get_saved_scope (struct d_print_info
*dpi
,
4309 const struct demangle_component
*container
)
4313 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4314 if (dpi
->saved_scopes
[i
].container
== container
)
4315 return &dpi
->saved_scopes
[i
];
4320 /* Subroutine to handle components. */
4323 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
4324 const struct demangle_component
*dc
)
4326 /* Magic variable to let reference smashing skip over the next modifier
4327 without needing to modify *dc. */
4328 const struct demangle_component
*mod_inner
= NULL
;
4330 /* Variable used to store the current templates while a previously
4331 captured scope is used. */
4332 struct d_print_template
*saved_templates
;
4334 /* Nonzero if templates have been stored in the above variable. */
4335 int need_template_restore
= 0;
4339 d_print_error (dpi
);
4342 if (d_print_saw_error (dpi
))
4347 case DEMANGLE_COMPONENT_NAME
:
4348 if ((options
& DMGL_JAVA
) == 0)
4349 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4351 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4354 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4355 d_print_comp (dpi
, options
, d_left (dc
));
4356 d_append_string (dpi
, "[abi:");
4357 d_print_comp (dpi
, options
, d_right (dc
));
4358 d_append_char (dpi
, ']');
4361 case DEMANGLE_COMPONENT_QUAL_NAME
:
4362 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4363 d_print_comp (dpi
, options
, d_left (dc
));
4364 if ((options
& DMGL_JAVA
) == 0)
4365 d_append_string (dpi
, "::");
4367 d_append_char (dpi
, '.');
4369 struct demangle_component
*local_name
= d_right (dc
);
4370 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4372 d_append_string (dpi
, "{default arg#");
4373 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4374 d_append_string (dpi
, "}::");
4375 local_name
= local_name
->u
.s_unary_num
.sub
;
4377 d_print_comp (dpi
, options
, local_name
);
4381 case DEMANGLE_COMPONENT_TYPED_NAME
:
4383 struct d_print_mod
*hold_modifiers
;
4384 struct demangle_component
*typed_name
;
4385 struct d_print_mod adpm
[4];
4387 struct d_print_template dpt
;
4389 /* Pass the name down to the type so that it can be printed in
4390 the right place for the type. We also have to pass down
4391 any CV-qualifiers, which apply to the this parameter. */
4392 hold_modifiers
= dpi
->modifiers
;
4395 typed_name
= d_left (dc
);
4396 while (typed_name
!= NULL
)
4398 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4400 d_print_error (dpi
);
4404 adpm
[i
].next
= dpi
->modifiers
;
4405 dpi
->modifiers
= &adpm
[i
];
4406 adpm
[i
].mod
= typed_name
;
4407 adpm
[i
].printed
= 0;
4408 adpm
[i
].templates
= dpi
->templates
;
4411 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4412 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4413 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4414 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4415 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4418 typed_name
= d_left (typed_name
);
4421 if (typed_name
== NULL
)
4423 d_print_error (dpi
);
4427 /* If typed_name is a template, then it applies to the
4428 function type as well. */
4429 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4431 dpt
.next
= dpi
->templates
;
4432 dpi
->templates
= &dpt
;
4433 dpt
.template_decl
= typed_name
;
4436 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4437 there may be CV-qualifiers on its right argument which
4438 really apply here; this happens when parsing a class which
4439 is local to a function. */
4440 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4442 struct demangle_component
*local_name
;
4444 local_name
= d_right (typed_name
);
4445 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4446 local_name
= local_name
->u
.s_unary_num
.sub
;
4447 if (local_name
== NULL
)
4449 d_print_error (dpi
);
4452 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4453 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4454 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4455 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4456 || (local_name
->type
4457 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4459 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4461 d_print_error (dpi
);
4465 adpm
[i
] = adpm
[i
- 1];
4466 adpm
[i
].next
= &adpm
[i
- 1];
4467 dpi
->modifiers
= &adpm
[i
];
4469 adpm
[i
- 1].mod
= local_name
;
4470 adpm
[i
- 1].printed
= 0;
4471 adpm
[i
- 1].templates
= dpi
->templates
;
4474 local_name
= d_left (local_name
);
4478 d_print_comp (dpi
, options
, d_right (dc
));
4480 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4481 dpi
->templates
= dpt
.next
;
4483 /* If the modifiers didn't get printed by the type, print them
4488 if (! adpm
[i
].printed
)
4490 d_append_char (dpi
, ' ');
4491 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4495 dpi
->modifiers
= hold_modifiers
;
4500 case DEMANGLE_COMPONENT_TEMPLATE
:
4502 struct d_print_mod
*hold_dpm
;
4503 struct demangle_component
*dcl
;
4504 const struct demangle_component
*hold_current
;
4506 /* This template may need to be referenced by a cast operator
4507 contained in its subtree. */
4508 hold_current
= dpi
->current_template
;
4509 dpi
->current_template
= dc
;
4511 /* Don't push modifiers into a template definition. Doing so
4512 could give the wrong definition for a template argument.
4513 Instead, treat the template essentially as a name. */
4515 hold_dpm
= dpi
->modifiers
;
4516 dpi
->modifiers
= NULL
;
4520 if ((options
& DMGL_JAVA
) != 0
4521 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4522 && dcl
->u
.s_name
.len
== 6
4523 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4525 /* Special-case Java arrays, so that JArray<TYPE> appears
4526 instead as TYPE[]. */
4528 d_print_comp (dpi
, options
, d_right (dc
));
4529 d_append_string (dpi
, "[]");
4533 d_print_comp (dpi
, options
, dcl
);
4534 if (d_last_char (dpi
) == '<')
4535 d_append_char (dpi
, ' ');
4536 d_append_char (dpi
, '<');
4537 d_print_comp (dpi
, options
, d_right (dc
));
4538 /* Avoid generating two consecutive '>' characters, to avoid
4539 the C++ syntactic ambiguity. */
4540 if (d_last_char (dpi
) == '>')
4541 d_append_char (dpi
, ' ');
4542 d_append_char (dpi
, '>');
4545 dpi
->modifiers
= hold_dpm
;
4546 dpi
->current_template
= hold_current
;
4551 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4553 struct d_print_template
*hold_dpt
;
4554 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4556 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4557 a
= d_index_template_argument (a
, dpi
->pack_index
);
4561 d_print_error (dpi
);
4565 /* While processing this parameter, we need to pop the list of
4566 templates. This is because the template parameter may
4567 itself be a reference to a parameter of an outer
4570 hold_dpt
= dpi
->templates
;
4571 dpi
->templates
= hold_dpt
->next
;
4573 d_print_comp (dpi
, options
, a
);
4575 dpi
->templates
= hold_dpt
;
4580 case DEMANGLE_COMPONENT_CTOR
:
4581 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4584 case DEMANGLE_COMPONENT_DTOR
:
4585 d_append_char (dpi
, '~');
4586 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4589 case DEMANGLE_COMPONENT_VTABLE
:
4590 d_append_string (dpi
, "vtable for ");
4591 d_print_comp (dpi
, options
, d_left (dc
));
4594 case DEMANGLE_COMPONENT_VTT
:
4595 d_append_string (dpi
, "VTT for ");
4596 d_print_comp (dpi
, options
, d_left (dc
));
4599 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4600 d_append_string (dpi
, "construction vtable for ");
4601 d_print_comp (dpi
, options
, d_left (dc
));
4602 d_append_string (dpi
, "-in-");
4603 d_print_comp (dpi
, options
, d_right (dc
));
4606 case DEMANGLE_COMPONENT_TYPEINFO
:
4607 d_append_string (dpi
, "typeinfo for ");
4608 d_print_comp (dpi
, options
, d_left (dc
));
4611 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4612 d_append_string (dpi
, "typeinfo name for ");
4613 d_print_comp (dpi
, options
, d_left (dc
));
4616 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4617 d_append_string (dpi
, "typeinfo fn for ");
4618 d_print_comp (dpi
, options
, d_left (dc
));
4621 case DEMANGLE_COMPONENT_THUNK
:
4622 d_append_string (dpi
, "non-virtual thunk to ");
4623 d_print_comp (dpi
, options
, d_left (dc
));
4626 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4627 d_append_string (dpi
, "virtual thunk to ");
4628 d_print_comp (dpi
, options
, d_left (dc
));
4631 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4632 d_append_string (dpi
, "covariant return thunk to ");
4633 d_print_comp (dpi
, options
, d_left (dc
));
4636 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4637 d_append_string (dpi
, "java Class for ");
4638 d_print_comp (dpi
, options
, d_left (dc
));
4641 case DEMANGLE_COMPONENT_GUARD
:
4642 d_append_string (dpi
, "guard variable for ");
4643 d_print_comp (dpi
, options
, d_left (dc
));
4646 case DEMANGLE_COMPONENT_TLS_INIT
:
4647 d_append_string (dpi
, "TLS init function for ");
4648 d_print_comp (dpi
, options
, d_left (dc
));
4651 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4652 d_append_string (dpi
, "TLS wrapper function for ");
4653 d_print_comp (dpi
, options
, d_left (dc
));
4656 case DEMANGLE_COMPONENT_REFTEMP
:
4657 d_append_string (dpi
, "reference temporary #");
4658 d_print_comp (dpi
, options
, d_right (dc
));
4659 d_append_string (dpi
, " for ");
4660 d_print_comp (dpi
, options
, d_left (dc
));
4663 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4664 d_append_string (dpi
, "hidden alias for ");
4665 d_print_comp (dpi
, options
, d_left (dc
));
4668 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4669 d_append_string (dpi
, "transaction clone for ");
4670 d_print_comp (dpi
, options
, d_left (dc
));
4673 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4674 d_append_string (dpi
, "non-transaction clone for ");
4675 d_print_comp (dpi
, options
, d_left (dc
));
4678 case DEMANGLE_COMPONENT_SUB_STD
:
4679 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4682 case DEMANGLE_COMPONENT_RESTRICT
:
4683 case DEMANGLE_COMPONENT_VOLATILE
:
4684 case DEMANGLE_COMPONENT_CONST
:
4686 struct d_print_mod
*pdpm
;
4688 /* When printing arrays, it's possible to have cases where the
4689 same CV-qualifier gets pushed on the stack multiple times.
4690 We only need to print it once. */
4692 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4694 if (! pdpm
->printed
)
4696 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4697 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4698 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4700 if (pdpm
->mod
->type
== dc
->type
)
4702 d_print_comp (dpi
, options
, d_left (dc
));
4710 case DEMANGLE_COMPONENT_REFERENCE
:
4711 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4713 /* Handle reference smashing: & + && = &. */
4714 const struct demangle_component
*sub
= d_left (dc
);
4715 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4717 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4718 struct demangle_component
*a
;
4722 /* This is the first time SUB has been traversed.
4723 We need to capture the current templates so
4724 they can be restored if SUB is reentered as a
4726 d_save_scope (dpi
, sub
);
4727 if (d_print_saw_error (dpi
))
4732 const struct d_component_stack
*dcse
;
4733 int found_self_or_parent
= 0;
4735 /* This traversal is reentering SUB as a substition.
4736 If we are not beneath SUB or DC in the tree then we
4737 need to restore SUB's template stack temporarily. */
4738 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
4739 dcse
= dcse
->parent
)
4743 && dcse
!= dpi
->component_stack
))
4745 found_self_or_parent
= 1;
4750 if (!found_self_or_parent
)
4752 saved_templates
= dpi
->templates
;
4753 dpi
->templates
= scope
->templates
;
4754 need_template_restore
= 1;
4758 a
= d_lookup_template_argument (dpi
, sub
);
4759 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4760 a
= d_index_template_argument (a
, dpi
->pack_index
);
4764 if (need_template_restore
)
4765 dpi
->templates
= saved_templates
;
4767 d_print_error (dpi
);
4774 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4775 || sub
->type
== dc
->type
)
4777 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4778 mod_inner
= d_left (sub
);
4782 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4783 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4784 case DEMANGLE_COMPONENT_CONST_THIS
:
4785 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4786 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4787 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4788 case DEMANGLE_COMPONENT_POINTER
:
4789 case DEMANGLE_COMPONENT_COMPLEX
:
4790 case DEMANGLE_COMPONENT_IMAGINARY
:
4793 /* We keep a list of modifiers on the stack. */
4794 struct d_print_mod dpm
;
4796 dpm
.next
= dpi
->modifiers
;
4797 dpi
->modifiers
= &dpm
;
4800 dpm
.templates
= dpi
->templates
;
4803 mod_inner
= d_left (dc
);
4805 d_print_comp (dpi
, options
, mod_inner
);
4807 /* If the modifier didn't get printed by the type, print it
4810 d_print_mod (dpi
, options
, dc
);
4812 dpi
->modifiers
= dpm
.next
;
4814 if (need_template_restore
)
4815 dpi
->templates
= saved_templates
;
4820 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4821 if ((options
& DMGL_JAVA
) == 0)
4822 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
4823 dc
->u
.s_builtin
.type
->len
);
4825 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
4826 dc
->u
.s_builtin
.type
->java_len
);
4829 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
4830 d_print_comp (dpi
, options
, d_left (dc
));
4833 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
4835 if ((options
& DMGL_RET_POSTFIX
) != 0)
4836 d_print_function_type (dpi
,
4837 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4838 dc
, dpi
->modifiers
);
4840 /* Print return type if present */
4841 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
4842 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4844 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
4846 struct d_print_mod dpm
;
4848 /* We must pass this type down as a modifier in order to
4849 print it in the right location. */
4850 dpm
.next
= dpi
->modifiers
;
4851 dpi
->modifiers
= &dpm
;
4854 dpm
.templates
= dpi
->templates
;
4856 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4859 dpi
->modifiers
= dpm
.next
;
4864 /* In standard prefix notation, there is a space between the
4865 return type and the function signature. */
4866 if ((options
& DMGL_RET_POSTFIX
) == 0)
4867 d_append_char (dpi
, ' ');
4870 if ((options
& DMGL_RET_POSTFIX
) == 0)
4871 d_print_function_type (dpi
,
4872 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
4873 dc
, dpi
->modifiers
);
4878 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
4880 struct d_print_mod
*hold_modifiers
;
4881 struct d_print_mod adpm
[4];
4883 struct d_print_mod
*pdpm
;
4885 /* We must pass this type down as a modifier in order to print
4886 multi-dimensional arrays correctly. If the array itself is
4887 CV-qualified, we act as though the element type were
4888 CV-qualified. We do this by copying the modifiers down
4889 rather than fiddling pointers, so that we don't wind up
4890 with a d_print_mod higher on the stack pointing into our
4891 stack frame after we return. */
4893 hold_modifiers
= dpi
->modifiers
;
4895 adpm
[0].next
= hold_modifiers
;
4896 dpi
->modifiers
= &adpm
[0];
4898 adpm
[0].printed
= 0;
4899 adpm
[0].templates
= dpi
->templates
;
4902 pdpm
= hold_modifiers
;
4904 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
4905 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
4906 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
4908 if (! pdpm
->printed
)
4910 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4912 d_print_error (dpi
);
4917 adpm
[i
].next
= dpi
->modifiers
;
4918 dpi
->modifiers
= &adpm
[i
];
4926 d_print_comp (dpi
, options
, d_right (dc
));
4928 dpi
->modifiers
= hold_modifiers
;
4930 if (adpm
[0].printed
)
4936 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4939 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
4944 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
4945 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
4947 struct d_print_mod dpm
;
4949 dpm
.next
= dpi
->modifiers
;
4950 dpi
->modifiers
= &dpm
;
4953 dpm
.templates
= dpi
->templates
;
4955 d_print_comp (dpi
, options
, d_right (dc
));
4957 /* If the modifier didn't get printed by the type, print it
4960 d_print_mod (dpi
, options
, dc
);
4962 dpi
->modifiers
= dpm
.next
;
4967 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4968 if (dc
->u
.s_fixed
.sat
)
4969 d_append_string (dpi
, "_Sat ");
4970 /* Don't print "int _Accum". */
4971 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
4972 != &cplus_demangle_builtin_types
['i'-'a'])
4974 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
4975 d_append_char (dpi
, ' ');
4977 if (dc
->u
.s_fixed
.accum
)
4978 d_append_string (dpi
, "_Accum");
4980 d_append_string (dpi
, "_Fract");
4983 case DEMANGLE_COMPONENT_ARGLIST
:
4984 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
4985 if (d_left (dc
) != NULL
)
4986 d_print_comp (dpi
, options
, d_left (dc
));
4987 if (d_right (dc
) != NULL
)
4990 unsigned long int flush_count
;
4991 /* Make sure ", " isn't flushed by d_append_string, otherwise
4992 dpi->len -= 2 wouldn't work. */
4993 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
4994 d_print_flush (dpi
);
4995 d_append_string (dpi
, ", ");
4997 flush_count
= dpi
->flush_count
;
4998 d_print_comp (dpi
, options
, d_right (dc
));
4999 /* If that didn't print anything (which can happen with empty
5000 template argument packs), remove the comma and space. */
5001 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5006 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5008 struct demangle_component
*type
= d_left (dc
);
5009 struct demangle_component
*list
= d_right (dc
);
5012 d_print_comp (dpi
, options
, type
);
5013 d_append_char (dpi
, '{');
5014 d_print_comp (dpi
, options
, list
);
5015 d_append_char (dpi
, '}');
5019 case DEMANGLE_COMPONENT_OPERATOR
:
5021 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5024 d_append_string (dpi
, "operator");
5025 /* Add a space before new/delete. */
5026 if (IS_LOWER (op
->name
[0]))
5027 d_append_char (dpi
, ' ');
5028 /* Omit a trailing space. */
5029 if (op
->name
[len
-1] == ' ')
5031 d_append_buffer (dpi
, op
->name
, len
);
5035 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5036 d_append_string (dpi
, "operator ");
5037 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5040 case DEMANGLE_COMPONENT_CAST
:
5041 d_append_string (dpi
, "operator ");
5042 d_print_cast (dpi
, options
, dc
);
5045 case DEMANGLE_COMPONENT_NULLARY
:
5046 d_print_expr_op (dpi
, options
, d_left (dc
));
5049 case DEMANGLE_COMPONENT_UNARY
:
5051 struct demangle_component
*op
= d_left (dc
);
5052 struct demangle_component
*operand
= d_right (dc
);
5053 const char *code
= NULL
;
5055 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5057 code
= op
->u
.s_operator
.op
->code
;
5058 if (!strcmp (code
, "ad"))
5060 /* Don't print the argument list for the address of a
5062 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5063 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5064 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5065 operand
= d_left (operand
);
5067 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5069 /* This indicates a suffix operator. */
5070 operand
= d_left (operand
);
5071 d_print_subexpr (dpi
, options
, operand
);
5072 d_print_expr_op (dpi
, options
, op
);
5077 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5078 d_print_expr_op (dpi
, options
, op
);
5081 d_append_char (dpi
, '(');
5082 d_print_cast (dpi
, options
, op
);
5083 d_append_char (dpi
, ')');
5085 if (code
&& !strcmp (code
, "gs"))
5086 /* Avoid parens after '::'. */
5087 d_print_comp (dpi
, options
, operand
);
5088 else if (code
&& !strcmp (code
, "st"))
5089 /* Always print parens for sizeof (type). */
5091 d_append_char (dpi
, '(');
5092 d_print_comp (dpi
, options
, operand
);
5093 d_append_char (dpi
, ')');
5096 d_print_subexpr (dpi
, options
, operand
);
5100 case DEMANGLE_COMPONENT_BINARY
:
5101 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5103 d_print_error (dpi
);
5107 if (op_is_new_cast (d_left (dc
)))
5109 d_print_expr_op (dpi
, options
, d_left (dc
));
5110 d_append_char (dpi
, '<');
5111 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5112 d_append_string (dpi
, ">(");
5113 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5114 d_append_char (dpi
, ')');
5118 /* We wrap an expression which uses the greater-than operator in
5119 an extra layer of parens so that it does not get confused
5120 with the '>' which ends the template parameters. */
5121 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5122 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5123 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5124 d_append_char (dpi
, '(');
5126 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5127 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5129 /* Function call used in an expression should not have printed types
5130 of the function arguments. Values of the function arguments still
5131 get printed below. */
5133 const struct demangle_component
*func
= d_left (d_right (dc
));
5135 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5136 d_print_error (dpi
);
5137 d_print_subexpr (dpi
, options
, d_left (func
));
5140 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5141 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5143 d_append_char (dpi
, '[');
5144 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5145 d_append_char (dpi
, ']');
5149 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5150 d_print_expr_op (dpi
, options
, d_left (dc
));
5151 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5154 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5155 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5156 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5157 d_append_char (dpi
, ')');
5161 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5162 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5163 d_print_error (dpi
);
5166 case DEMANGLE_COMPONENT_TRINARY
:
5167 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5168 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5170 d_print_error (dpi
);
5174 struct demangle_component
*op
= d_left (dc
);
5175 struct demangle_component
*first
= d_left (d_right (dc
));
5176 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5177 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5179 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5181 d_print_subexpr (dpi
, options
, first
);
5182 d_print_expr_op (dpi
, options
, op
);
5183 d_print_subexpr (dpi
, options
, second
);
5184 d_append_string (dpi
, " : ");
5185 d_print_subexpr (dpi
, options
, third
);
5189 d_append_string (dpi
, "new ");
5190 if (d_left (first
) != NULL
)
5192 d_print_subexpr (dpi
, options
, first
);
5193 d_append_char (dpi
, ' ');
5195 d_print_comp (dpi
, options
, second
);
5197 d_print_subexpr (dpi
, options
, third
);
5202 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5203 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5204 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5205 d_print_error (dpi
);
5208 case DEMANGLE_COMPONENT_LITERAL
:
5209 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5211 enum d_builtin_type_print tp
;
5213 /* For some builtin types, produce simpler output. */
5214 tp
= D_PRINT_DEFAULT
;
5215 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5217 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5221 case D_PRINT_UNSIGNED
:
5223 case D_PRINT_UNSIGNED_LONG
:
5224 case D_PRINT_LONG_LONG
:
5225 case D_PRINT_UNSIGNED_LONG_LONG
:
5226 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5228 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5229 d_append_char (dpi
, '-');
5230 d_print_comp (dpi
, options
, d_right (dc
));
5235 case D_PRINT_UNSIGNED
:
5236 d_append_char (dpi
, 'u');
5239 d_append_char (dpi
, 'l');
5241 case D_PRINT_UNSIGNED_LONG
:
5242 d_append_string (dpi
, "ul");
5244 case D_PRINT_LONG_LONG
:
5245 d_append_string (dpi
, "ll");
5247 case D_PRINT_UNSIGNED_LONG_LONG
:
5248 d_append_string (dpi
, "ull");
5256 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5257 && d_right (dc
)->u
.s_name
.len
== 1
5258 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5260 switch (d_right (dc
)->u
.s_name
.s
[0])
5263 d_append_string (dpi
, "false");
5266 d_append_string (dpi
, "true");
5279 d_append_char (dpi
, '(');
5280 d_print_comp (dpi
, options
, d_left (dc
));
5281 d_append_char (dpi
, ')');
5282 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5283 d_append_char (dpi
, '-');
5284 if (tp
== D_PRINT_FLOAT
)
5285 d_append_char (dpi
, '[');
5286 d_print_comp (dpi
, options
, d_right (dc
));
5287 if (tp
== D_PRINT_FLOAT
)
5288 d_append_char (dpi
, ']');
5292 case DEMANGLE_COMPONENT_NUMBER
:
5293 d_append_num (dpi
, dc
->u
.s_number
.number
);
5296 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5297 d_append_string (dpi
, "java resource ");
5298 d_print_comp (dpi
, options
, d_left (dc
));
5301 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5302 d_print_comp (dpi
, options
, d_left (dc
));
5303 d_print_comp (dpi
, options
, d_right (dc
));
5306 case DEMANGLE_COMPONENT_CHARACTER
:
5307 d_append_char (dpi
, dc
->u
.s_character
.character
);
5310 case DEMANGLE_COMPONENT_DECLTYPE
:
5311 d_append_string (dpi
, "decltype (");
5312 d_print_comp (dpi
, options
, d_left (dc
));
5313 d_append_char (dpi
, ')');
5316 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5320 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5323 /* d_find_pack won't find anything if the only packs involved
5324 in this expansion are function parameter packs; in that
5325 case, just print the pattern and "...". */
5326 d_print_subexpr (dpi
, options
, d_left (dc
));
5327 d_append_string (dpi
, "...");
5331 len
= d_pack_length (a
);
5333 for (i
= 0; i
< len
; ++i
)
5335 dpi
->pack_index
= i
;
5336 d_print_comp (dpi
, options
, dc
);
5338 d_append_string (dpi
, ", ");
5343 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5345 long num
= dc
->u
.s_number
.number
;
5347 d_append_string (dpi
, "this");
5350 d_append_string (dpi
, "{parm#");
5351 d_append_num (dpi
, num
);
5352 d_append_char (dpi
, '}');
5357 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5358 d_append_string (dpi
, "global constructors keyed to ");
5359 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5362 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5363 d_append_string (dpi
, "global destructors keyed to ");
5364 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5367 case DEMANGLE_COMPONENT_LAMBDA
:
5368 d_append_string (dpi
, "{lambda(");
5369 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5370 d_append_string (dpi
, ")#");
5371 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5372 d_append_char (dpi
, '}');
5375 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5376 d_append_string (dpi
, "{unnamed type#");
5377 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5378 d_append_char (dpi
, '}');
5381 case DEMANGLE_COMPONENT_CLONE
:
5382 d_print_comp (dpi
, options
, d_left (dc
));
5383 d_append_string (dpi
, " [clone ");
5384 d_print_comp (dpi
, options
, d_right (dc
));
5385 d_append_char (dpi
, ']');
5389 d_print_error (dpi
);
5395 d_print_comp (struct d_print_info
*dpi
, int options
,
5396 const struct demangle_component
*dc
)
5398 struct d_component_stack self
;
5401 self
.parent
= dpi
->component_stack
;
5402 dpi
->component_stack
= &self
;
5404 d_print_comp_inner (dpi
, options
, dc
);
5406 dpi
->component_stack
= self
.parent
;
5409 /* Print a Java dentifier. For Java we try to handle encoded extended
5410 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5411 so we don't it for C++. Characters are encoded as
5415 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5421 for (p
= name
; p
< end
; ++p
)
5432 for (q
= p
+ 3; q
< end
; ++q
)
5438 else if (*q
>= 'A' && *q
<= 'F')
5439 dig
= *q
- 'A' + 10;
5440 else if (*q
>= 'a' && *q
<= 'f')
5441 dig
= *q
- 'a' + 10;
5447 /* If the Unicode character is larger than 256, we don't try
5448 to deal with it here. FIXME. */
5449 if (q
< end
&& *q
== '_' && c
< 256)
5451 d_append_char (dpi
, c
);
5457 d_append_char (dpi
, *p
);
5461 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5462 qualifiers on this after printing a function. */
5465 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5466 struct d_print_mod
*mods
, int suffix
)
5468 struct d_print_template
*hold_dpt
;
5470 if (mods
== NULL
|| d_print_saw_error (dpi
))
5475 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5476 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5477 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5478 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5480 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5482 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5488 hold_dpt
= dpi
->templates
;
5489 dpi
->templates
= mods
->templates
;
5491 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5493 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5494 dpi
->templates
= hold_dpt
;
5497 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5499 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5500 dpi
->templates
= hold_dpt
;
5503 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5505 struct d_print_mod
*hold_modifiers
;
5506 struct demangle_component
*dc
;
5508 /* When this is on the modifier stack, we have pulled any
5509 qualifiers off the right argument already. Otherwise, we
5510 print it as usual, but don't let the left argument see any
5513 hold_modifiers
= dpi
->modifiers
;
5514 dpi
->modifiers
= NULL
;
5515 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5516 dpi
->modifiers
= hold_modifiers
;
5518 if ((options
& DMGL_JAVA
) == 0)
5519 d_append_string (dpi
, "::");
5521 d_append_char (dpi
, '.');
5523 dc
= d_right (mods
->mod
);
5525 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5527 d_append_string (dpi
, "{default arg#");
5528 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5529 d_append_string (dpi
, "}::");
5530 dc
= dc
->u
.s_unary_num
.sub
;
5533 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5534 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5535 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5536 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5537 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5540 d_print_comp (dpi
, options
, dc
);
5542 dpi
->templates
= hold_dpt
;
5546 d_print_mod (dpi
, options
, mods
->mod
);
5548 dpi
->templates
= hold_dpt
;
5550 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5553 /* Print a modifier. */
5556 d_print_mod (struct d_print_info
*dpi
, int options
,
5557 const struct demangle_component
*mod
)
5561 case DEMANGLE_COMPONENT_RESTRICT
:
5562 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5563 d_append_string (dpi
, " restrict");
5565 case DEMANGLE_COMPONENT_VOLATILE
:
5566 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5567 d_append_string (dpi
, " volatile");
5569 case DEMANGLE_COMPONENT_CONST
:
5570 case DEMANGLE_COMPONENT_CONST_THIS
:
5571 d_append_string (dpi
, " const");
5573 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5574 d_append_char (dpi
, ' ');
5575 d_print_comp (dpi
, options
, d_right (mod
));
5577 case DEMANGLE_COMPONENT_POINTER
:
5578 /* There is no pointer symbol in Java. */
5579 if ((options
& DMGL_JAVA
) == 0)
5580 d_append_char (dpi
, '*');
5582 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5583 /* For the ref-qualifier, put a space before the &. */
5584 d_append_char (dpi
, ' ');
5585 case DEMANGLE_COMPONENT_REFERENCE
:
5586 d_append_char (dpi
, '&');
5588 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5589 d_append_char (dpi
, ' ');
5590 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5591 d_append_string (dpi
, "&&");
5593 case DEMANGLE_COMPONENT_COMPLEX
:
5594 d_append_string (dpi
, "complex ");
5596 case DEMANGLE_COMPONENT_IMAGINARY
:
5597 d_append_string (dpi
, "imaginary ");
5599 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5600 if (d_last_char (dpi
) != '(')
5601 d_append_char (dpi
, ' ');
5602 d_print_comp (dpi
, options
, d_left (mod
));
5603 d_append_string (dpi
, "::*");
5605 case DEMANGLE_COMPONENT_TYPED_NAME
:
5606 d_print_comp (dpi
, options
, d_left (mod
));
5608 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5609 d_append_string (dpi
, " __vector(");
5610 d_print_comp (dpi
, options
, d_left (mod
));
5611 d_append_char (dpi
, ')');
5615 /* Otherwise, we have something that won't go back on the
5616 modifier stack, so we can just print it. */
5617 d_print_comp (dpi
, options
, mod
);
5622 /* Print a function type, except for the return type. */
5625 d_print_function_type (struct d_print_info
*dpi
, int options
,
5626 const struct demangle_component
*dc
,
5627 struct d_print_mod
*mods
)
5631 struct d_print_mod
*p
;
5632 struct d_print_mod
*hold_modifiers
;
5636 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5641 switch (p
->mod
->type
)
5643 case DEMANGLE_COMPONENT_POINTER
:
5644 case DEMANGLE_COMPONENT_REFERENCE
:
5645 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5648 case DEMANGLE_COMPONENT_RESTRICT
:
5649 case DEMANGLE_COMPONENT_VOLATILE
:
5650 case DEMANGLE_COMPONENT_CONST
:
5651 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5652 case DEMANGLE_COMPONENT_COMPLEX
:
5653 case DEMANGLE_COMPONENT_IMAGINARY
:
5654 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5658 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5659 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5660 case DEMANGLE_COMPONENT_CONST_THIS
:
5661 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5662 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5675 if (d_last_char (dpi
) != '('
5676 && d_last_char (dpi
) != '*')
5679 if (need_space
&& d_last_char (dpi
) != ' ')
5680 d_append_char (dpi
, ' ');
5681 d_append_char (dpi
, '(');
5684 hold_modifiers
= dpi
->modifiers
;
5685 dpi
->modifiers
= NULL
;
5687 d_print_mod_list (dpi
, options
, mods
, 0);
5690 d_append_char (dpi
, ')');
5692 d_append_char (dpi
, '(');
5694 if (d_right (dc
) != NULL
)
5695 d_print_comp (dpi
, options
, d_right (dc
));
5697 d_append_char (dpi
, ')');
5699 d_print_mod_list (dpi
, options
, mods
, 1);
5701 dpi
->modifiers
= hold_modifiers
;
5704 /* Print an array type, except for the element type. */
5707 d_print_array_type (struct d_print_info
*dpi
, int options
,
5708 const struct demangle_component
*dc
,
5709 struct d_print_mod
*mods
)
5717 struct d_print_mod
*p
;
5720 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5724 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5739 d_append_string (dpi
, " (");
5741 d_print_mod_list (dpi
, options
, mods
, 0);
5744 d_append_char (dpi
, ')');
5748 d_append_char (dpi
, ' ');
5750 d_append_char (dpi
, '[');
5752 if (d_left (dc
) != NULL
)
5753 d_print_comp (dpi
, options
, d_left (dc
));
5755 d_append_char (dpi
, ']');
5758 /* Print an operator in an expression. */
5761 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5762 const struct demangle_component
*dc
)
5764 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5765 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5766 dc
->u
.s_operator
.op
->len
);
5768 d_print_comp (dpi
, options
, dc
);
5774 d_print_cast (struct d_print_info
*dpi
, int options
,
5775 const struct demangle_component
*dc
)
5777 struct d_print_template dpt
;
5779 /* For a cast operator, we need the template parameters from
5780 the enclosing template in scope for processing the type. */
5781 if (dpi
->current_template
!= NULL
)
5783 dpt
.next
= dpi
->templates
;
5784 dpi
->templates
= &dpt
;
5785 dpt
.template_decl
= dpi
->current_template
;
5788 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
5790 d_print_comp (dpi
, options
, d_left (dc
));
5791 if (dpi
->current_template
!= NULL
)
5792 dpi
->templates
= dpt
.next
;
5796 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
5798 /* For a templated cast operator, we need to remove the template
5799 parameters from scope after printing the operator name,
5800 so we need to handle the template printing here. */
5801 if (dpi
->current_template
!= NULL
)
5802 dpi
->templates
= dpt
.next
;
5804 if (d_last_char (dpi
) == '<')
5805 d_append_char (dpi
, ' ');
5806 d_append_char (dpi
, '<');
5807 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
5808 /* Avoid generating two consecutive '>' characters, to avoid
5809 the C++ syntactic ambiguity. */
5810 if (d_last_char (dpi
) == '>')
5811 d_append_char (dpi
, ' ');
5812 d_append_char (dpi
, '>');
5816 /* Initialize the information structure we use to pass around
5819 CP_STATIC_IF_GLIBCPP_V3
5821 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
5825 di
->send
= mangled
+ len
;
5826 di
->options
= options
;
5830 /* We can not need more components than twice the number of chars in
5831 the mangled string. Most components correspond directly to
5832 chars, but the ARGLIST types are exceptions. */
5833 di
->num_comps
= 2 * len
;
5836 /* Similarly, we can not need more substitutions than there are
5837 chars in the mangled string. */
5842 di
->last_name
= NULL
;
5845 di
->is_expression
= 0;
5846 di
->is_conversion
= 0;
5849 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
5850 mangled name, return strings in repeated callback giving the demangled
5851 name. OPTIONS is the usual libiberty demangler options. On success,
5852 this returns 1. On failure, returns 0. */
5855 d_demangle_callback (const char *mangled
, int options
,
5856 demangle_callbackref callback
, void *opaque
)
5867 struct demangle_component
*dc
;
5870 if (mangled
[0] == '_' && mangled
[1] == 'Z')
5872 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
5873 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
5874 && (mangled
[9] == 'D' || mangled
[9] == 'I')
5875 && mangled
[10] == '_')
5876 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
5879 if ((options
& DMGL_TYPES
) == 0)
5884 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
5887 #ifdef CP_DYNAMIC_ARRAYS
5888 __extension__
struct demangle_component comps
[di
.num_comps
];
5889 __extension__
struct demangle_component
*subs
[di
.num_subs
];
5894 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
5895 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
5901 dc
= cplus_demangle_type (&di
);
5904 dc
= cplus_demangle_mangled_name (&di
, 1);
5906 case DCT_GLOBAL_CTORS
:
5907 case DCT_GLOBAL_DTORS
:
5908 d_advance (&di
, 11);
5909 dc
= d_make_comp (&di
,
5910 (type
== DCT_GLOBAL_CTORS
5911 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
5912 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
5913 d_make_demangle_mangled_name (&di
, d_str (&di
)),
5915 d_advance (&di
, strlen (d_str (&di
)));
5918 abort (); /* We have listed all the cases. */
5921 /* If DMGL_PARAMS is set, then if we didn't consume the entire
5922 mangled string, then we didn't successfully demangle it. If
5923 DMGL_PARAMS is not set, we didn't look at the trailing
5925 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
5928 #ifdef CP_DEMANGLE_DEBUG
5932 status
= (dc
!= NULL
)
5933 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
5940 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
5941 name, return a buffer allocated with malloc holding the demangled
5942 name. OPTIONS is the usual libiberty demangler options. On
5943 success, this sets *PALC to the allocated size of the returned
5944 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
5945 a memory allocation failure, and returns NULL. */
5948 d_demangle (const char *mangled
, int options
, size_t *palc
)
5950 struct d_growable_string dgs
;
5953 d_growable_string_init (&dgs
, 0);
5955 status
= d_demangle_callback (mangled
, options
,
5956 d_growable_string_callback_adapter
, &dgs
);
5964 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
5968 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
5970 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
5972 /* ia64 ABI-mandated entry point in the C++ runtime library for
5973 performing demangling. MANGLED_NAME is a NUL-terminated character
5974 string containing the name to be demangled.
5976 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
5977 *LENGTH bytes, into which the demangled name is stored. If
5978 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
5979 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
5980 is placed in a region of memory allocated with malloc.
5982 If LENGTH is non-NULL, the length of the buffer containing the
5983 demangled name, is placed in *LENGTH.
5985 The return value is a pointer to the start of the NUL-terminated
5986 demangled name, or NULL if the demangling fails. The caller is
5987 responsible for deallocating this memory using free.
5989 *STATUS is set to one of the following values:
5990 0: The demangling operation succeeded.
5991 -1: A memory allocation failure occurred.
5992 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
5993 -3: One of the arguments is invalid.
5995 The demangling is performed using the C++ ABI mangling rules, with
5999 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6000 size_t *length
, int *status
)
6005 if (mangled_name
== NULL
)
6012 if (output_buffer
!= NULL
&& length
== NULL
)
6019 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6021 if (demangled
== NULL
)
6033 if (output_buffer
== NULL
)
6040 if (strlen (demangled
) < *length
)
6042 strcpy (output_buffer
, demangled
);
6044 demangled
= output_buffer
;
6048 free (output_buffer
);
6059 extern int __gcclibcxx_demangle_callback (const char *,
6061 (const char *, size_t, void *),
6064 /* Alternative, allocationless entry point in the C++ runtime library
6065 for performing demangling. MANGLED_NAME is a NUL-terminated character
6066 string containing the name to be demangled.
6068 CALLBACK is a callback function, called with demangled string
6069 segments as demangling progresses; it is called at least once,
6070 but may be called more than once. OPAQUE is a generalized pointer
6071 used as a callback argument.
6073 The return code is one of the following values, equivalent to
6074 the STATUS values of __cxa_demangle() (excluding -1, since this
6075 function performs no memory allocations):
6076 0: The demangling operation succeeded.
6077 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6078 -3: One of the arguments is invalid.
6080 The demangling is performed using the C++ ABI mangling rules, with
6084 __gcclibcxx_demangle_callback (const char *mangled_name
,
6085 void (*callback
) (const char *, size_t, void *),
6090 if (mangled_name
== NULL
|| callback
== NULL
)
6093 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6101 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6103 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6104 mangled name, return a buffer allocated with malloc holding the
6105 demangled name. Otherwise, return NULL. */
6108 cplus_demangle_v3 (const char *mangled
, int options
)
6112 return d_demangle (mangled
, options
, &alc
);
6116 cplus_demangle_v3_callback (const char *mangled
, int options
,
6117 demangle_callbackref callback
, void *opaque
)
6119 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6122 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6123 conventions, but the output formatting is a little different.
6124 This instructs the C++ demangler not to emit pointer characters ("*"), to
6125 use Java's namespace separator symbol ("." instead of "::"), and to output
6126 JArray<TYPE> as TYPE[]. */
6129 java_demangle_v3 (const char *mangled
)
6133 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6137 java_demangle_v3_callback (const char *mangled
,
6138 demangle_callbackref callback
, void *opaque
)
6140 return d_demangle_callback (mangled
,
6141 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6145 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6147 #ifndef IN_GLIBCPP_V3
6149 /* Demangle a string in order to find out whether it is a constructor
6150 or destructor. Return non-zero on success. Set *CTOR_KIND and
6151 *DTOR_KIND appropriately. */
6154 is_ctor_or_dtor (const char *mangled
,
6155 enum gnu_v3_ctor_kinds
*ctor_kind
,
6156 enum gnu_v3_dtor_kinds
*dtor_kind
)
6159 struct demangle_component
*dc
;
6162 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6163 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6165 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6168 #ifdef CP_DYNAMIC_ARRAYS
6169 __extension__
struct demangle_component comps
[di
.num_comps
];
6170 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6175 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6176 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6179 dc
= cplus_demangle_mangled_name (&di
, 1);
6181 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6182 to demangle the entire string. */
6189 /* These cannot appear on a constructor or destructor. */
6190 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6191 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6192 case DEMANGLE_COMPONENT_CONST_THIS
:
6193 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6194 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6198 case DEMANGLE_COMPONENT_TYPED_NAME
:
6199 case DEMANGLE_COMPONENT_TEMPLATE
:
6202 case DEMANGLE_COMPONENT_QUAL_NAME
:
6203 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6206 case DEMANGLE_COMPONENT_CTOR
:
6207 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6211 case DEMANGLE_COMPONENT_DTOR
:
6212 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6223 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6224 name. A non-zero return indicates the type of constructor. */
6226 enum gnu_v3_ctor_kinds
6227 is_gnu_v3_mangled_ctor (const char *name
)
6229 enum gnu_v3_ctor_kinds ctor_kind
;
6230 enum gnu_v3_dtor_kinds dtor_kind
;
6232 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6233 return (enum gnu_v3_ctor_kinds
) 0;
6238 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6239 name. A non-zero return indicates the type of destructor. */
6241 enum gnu_v3_dtor_kinds
6242 is_gnu_v3_mangled_dtor (const char *name
)
6244 enum gnu_v3_ctor_kinds ctor_kind
;
6245 enum gnu_v3_dtor_kinds dtor_kind
;
6247 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6248 return (enum gnu_v3_dtor_kinds
) 0;
6252 #endif /* IN_GLIBCPP_V3 */
6254 #ifdef STANDALONE_DEMANGLER
6257 #include "dyn-string.h"
6259 static void print_usage (FILE* fp
, int exit_value
);
6261 #define IS_ALPHA(CHAR) \
6262 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6263 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6265 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6266 #define is_mangled_char(CHAR) \
6267 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6268 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6270 /* The name of this program, as invoked. */
6271 const char* program_name
;
6273 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6276 print_usage (FILE* fp
, int exit_value
)
6278 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6279 fprintf (fp
, "Options:\n");
6280 fprintf (fp
, " -h,--help Display this message.\n");
6281 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6282 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6283 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6288 /* Option specification for getopt_long. */
6289 static const struct option long_options
[] =
6291 { "help", no_argument
, NULL
, 'h' },
6292 { "no-params", no_argument
, NULL
, 'p' },
6293 { "verbose", no_argument
, NULL
, 'v' },
6294 { NULL
, no_argument
, NULL
, 0 },
6297 /* Main entry for a demangling filter executable. It will demangle
6298 its command line arguments, if any. If none are provided, it will
6299 filter stdin to stdout, replacing any recognized mangled C++ names
6300 with their demangled equivalents. */
6303 main (int argc
, char *argv
[])
6307 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6309 /* Use the program name of this program, as invoked. */
6310 program_name
= argv
[0];
6312 /* Parse options. */
6315 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6318 case '?': /* Unrecognized option. */
6319 print_usage (stderr
, 1);
6323 print_usage (stdout
, 0);
6327 options
&= ~ DMGL_PARAMS
;
6331 options
|= DMGL_VERBOSE
;
6335 while (opt_char
!= -1);
6338 /* No command line arguments were provided. Filter stdin. */
6340 dyn_string_t mangled
= dyn_string_new (3);
6343 /* Read all of input. */
6344 while (!feof (stdin
))
6348 /* Pile characters into mangled until we hit one that can't
6349 occur in a mangled name. */
6351 while (!feof (stdin
) && is_mangled_char (c
))
6353 dyn_string_append_char (mangled
, c
);
6359 if (dyn_string_length (mangled
) > 0)
6361 #ifdef IN_GLIBCPP_V3
6362 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6364 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6374 /* It might not have been a mangled name. Print the
6376 fputs (dyn_string_buf (mangled
), stdout
);
6379 dyn_string_clear (mangled
);
6382 /* If we haven't hit EOF yet, we've read one character that
6383 can't occur in a mangled name, so print it out. */
6388 dyn_string_delete (mangled
);
6391 /* Demangle command line arguments. */
6393 /* Loop over command line arguments. */
6394 for (i
= optind
; i
< argc
; ++i
)
6397 #ifdef IN_GLIBCPP_V3
6401 /* Attempt to demangle. */
6402 #ifdef IN_GLIBCPP_V3
6403 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6405 s
= cplus_demangle_v3 (argv
[i
], options
);
6408 /* If it worked, print the demangled name. */
6416 #ifdef IN_GLIBCPP_V3
6417 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6419 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6428 #endif /* STANDALONE_DEMANGLER */