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 */
135 # define INT_MAX (int)(((unsigned int) ~0) >> 1) /* 0x7FFFFFFF */
138 #include "ansidecl.h"
139 #include "libiberty.h"
140 #include "demangle.h"
141 #include "cp-demangle.h"
143 /* If IN_GLIBCPP_V3 is defined, some functions are made static. We
144 also rename them via #define to avoid compiler errors when the
145 static definition conflicts with the extern declaration in a header
149 #define CP_STATIC_IF_GLIBCPP_V3 static
151 #define cplus_demangle_fill_name d_fill_name
152 static int d_fill_name (struct demangle_component
*, const char *, int);
154 #define cplus_demangle_fill_extended_operator d_fill_extended_operator
156 d_fill_extended_operator (struct demangle_component
*, int,
157 struct demangle_component
*);
159 #define cplus_demangle_fill_ctor d_fill_ctor
161 d_fill_ctor (struct demangle_component
*, enum gnu_v3_ctor_kinds
,
162 struct demangle_component
*);
164 #define cplus_demangle_fill_dtor d_fill_dtor
166 d_fill_dtor (struct demangle_component
*, enum gnu_v3_dtor_kinds
,
167 struct demangle_component
*);
169 #define cplus_demangle_mangled_name d_mangled_name
170 static struct demangle_component
*d_mangled_name (struct d_info
*, int);
172 #define cplus_demangle_type d_type
173 static struct demangle_component
*d_type (struct d_info
*);
175 #define cplus_demangle_print d_print
176 static char *d_print (int, const struct demangle_component
*, int, size_t *);
178 #define cplus_demangle_print_callback d_print_callback
179 static int d_print_callback (int, const struct demangle_component
*,
180 demangle_callbackref
, void *);
182 #define cplus_demangle_init_info d_init_info
183 static void d_init_info (const char *, int, size_t, struct d_info
*);
185 #else /* ! defined(IN_GLIBCPP_V3) */
186 #define CP_STATIC_IF_GLIBCPP_V3
187 #endif /* ! defined(IN_GLIBCPP_V3) */
189 /* See if the compiler supports dynamic arrays. */
192 #define CP_DYNAMIC_ARRAYS
195 #ifdef __STDC_VERSION__
196 #if __STDC_VERSION__ >= 199901L
197 #define CP_DYNAMIC_ARRAYS
198 #endif /* __STDC__VERSION >= 199901L */
199 #endif /* defined (__STDC_VERSION__) */
200 #endif /* defined (__STDC__) */
201 #endif /* ! defined (__GNUC__) */
203 /* We avoid pulling in the ctype tables, to prevent pulling in
204 additional unresolved symbols when this code is used in a library.
205 FIXME: Is this really a valid reason? This comes from the original
208 As of this writing this file has the following undefined references
209 when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
212 #define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
213 #define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
214 #define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
216 /* The prefix prepended by GCC to an identifier represnting the
217 anonymous namespace. */
218 #define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
219 #define ANONYMOUS_NAMESPACE_PREFIX_LEN \
220 (sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
222 /* Information we keep for the standard substitutions. */
224 struct d_standard_sub_info
226 /* The code for this substitution. */
228 /* The simple string it expands to. */
229 const char *simple_expansion
;
230 /* The length of the simple expansion. */
232 /* The results of a full, verbose, expansion. This is used when
233 qualifying a constructor/destructor, or when in verbose mode. */
234 const char *full_expansion
;
235 /* The length of the full expansion. */
237 /* What to set the last_name field of d_info to; NULL if we should
238 not set it. This is only relevant when qualifying a
239 constructor/destructor. */
240 const char *set_last_name
;
241 /* The length of set_last_name. */
242 int set_last_name_len
;
245 /* Accessors for subtrees of struct demangle_component. */
247 #define d_left(dc) ((dc)->u.s_binary.left)
248 #define d_right(dc) ((dc)->u.s_binary.right)
250 /* A list of templates. This is used while printing. */
252 struct d_print_template
254 /* Next template on the list. */
255 struct d_print_template
*next
;
257 const struct demangle_component
*template_decl
;
260 /* A list of type modifiers. This is used while printing. */
264 /* Next modifier on the list. These are in the reverse of the order
265 in which they appeared in the mangled string. */
266 struct d_print_mod
*next
;
268 const struct demangle_component
*mod
;
269 /* Whether this modifier was printed. */
271 /* The list of templates which applies to this modifier. */
272 struct d_print_template
*templates
;
275 /* We use these structures to hold information during printing. */
277 struct d_growable_string
279 /* Buffer holding the result. */
281 /* Current length of data in buffer. */
283 /* Allocated size of buffer. */
285 /* Set to 1 if we had a memory allocation failure. */
286 int allocation_failure
;
289 /* Stack of components, innermost first, used to avoid loops. */
291 struct d_component_stack
293 /* This component. */
294 const struct demangle_component
*dc
;
295 /* This component's parent. */
296 const struct d_component_stack
*parent
;
299 /* A demangle component and some scope captured when it was first
304 /* The component whose scope this is. */
305 const struct demangle_component
*container
;
306 /* The list of templates, if any, that was current when this
307 scope was captured. */
308 struct d_print_template
*templates
;
311 /* Checkpoint structure to allow backtracking. This holds copies
312 of the fields of struct d_info that need to be restored
313 if a trial parse needs to be backtracked over. */
315 struct d_info_checkpoint
324 enum { D_PRINT_BUFFER_LENGTH
= 256 };
327 /* Fixed-length allocated buffer for demangled data, flushed to the
328 callback with a NUL termination once full. */
329 char buf
[D_PRINT_BUFFER_LENGTH
];
330 /* Current length of data in buffer. */
332 /* The last character printed, saved individually so that it survives
335 /* Callback function to handle demangled buffer flush. */
336 demangle_callbackref callback
;
337 /* Opaque callback argument. */
339 /* The current list of templates, if any. */
340 struct d_print_template
*templates
;
341 /* The current list of modifiers (e.g., pointer, reference, etc.),
343 struct d_print_mod
*modifiers
;
344 /* Set to 1 if we saw a demangling error. */
345 int demangle_failure
;
346 /* The current index into any template argument packs we are using
347 for printing, or -1 to print the whole pack. */
349 /* Number of d_print_flush calls so far. */
350 unsigned long int flush_count
;
351 /* Stack of components, innermost first, used to avoid loops. */
352 const struct d_component_stack
*component_stack
;
353 /* Array of saved scopes for evaluating substitutions. */
354 struct d_saved_scope
*saved_scopes
;
355 /* Index of the next unused saved scope in the above array. */
356 int next_saved_scope
;
357 /* Number of saved scopes in the above array. */
358 int num_saved_scopes
;
359 /* Array of templates for saving into scopes. */
360 struct d_print_template
*copy_templates
;
361 /* Index of the next unused copy template in the above array. */
362 int next_copy_template
;
363 /* Number of copy templates in the above array. */
364 int num_copy_templates
;
365 /* The nearest enclosing template, if any. */
366 const struct demangle_component
*current_template
;
369 #ifdef CP_DEMANGLE_DEBUG
370 static void d_dump (struct demangle_component
*, int);
373 static struct demangle_component
*
374 d_make_empty (struct d_info
*);
376 static struct demangle_component
*
377 d_make_comp (struct d_info
*, enum demangle_component_type
,
378 struct demangle_component
*,
379 struct demangle_component
*);
381 static struct demangle_component
*
382 d_make_name (struct d_info
*, const char *, int);
384 static struct demangle_component
*
385 d_make_demangle_mangled_name (struct d_info
*, const char *);
387 static struct demangle_component
*
388 d_make_builtin_type (struct d_info
*,
389 const struct demangle_builtin_type_info
*);
391 static struct demangle_component
*
392 d_make_operator (struct d_info
*,
393 const struct demangle_operator_info
*);
395 static struct demangle_component
*
396 d_make_extended_operator (struct d_info
*, int,
397 struct demangle_component
*);
399 static struct demangle_component
*
400 d_make_ctor (struct d_info
*, enum gnu_v3_ctor_kinds
,
401 struct demangle_component
*);
403 static struct demangle_component
*
404 d_make_dtor (struct d_info
*, enum gnu_v3_dtor_kinds
,
405 struct demangle_component
*);
407 static struct demangle_component
*
408 d_make_template_param (struct d_info
*, int);
410 static struct demangle_component
*
411 d_make_sub (struct d_info
*, const char *, int);
414 has_return_type (struct demangle_component
*);
417 is_ctor_dtor_or_conversion (struct demangle_component
*);
419 static struct demangle_component
*d_encoding (struct d_info
*, int);
421 static struct demangle_component
*d_name (struct d_info
*);
423 static struct demangle_component
*d_nested_name (struct d_info
*);
425 static struct demangle_component
*d_prefix (struct d_info
*);
427 static struct demangle_component
*d_unqualified_name (struct d_info
*);
429 static struct demangle_component
*d_source_name (struct d_info
*);
431 static int d_number (struct d_info
*);
433 static struct demangle_component
*d_identifier (struct d_info
*, int);
435 static struct demangle_component
*d_operator_name (struct d_info
*);
437 static struct demangle_component
*d_special_name (struct d_info
*);
439 static int d_call_offset (struct d_info
*, int);
441 static struct demangle_component
*d_ctor_dtor_name (struct d_info
*);
443 static struct demangle_component
**
444 d_cv_qualifiers (struct d_info
*, struct demangle_component
**, int);
446 static struct demangle_component
*
447 d_ref_qualifier (struct d_info
*, struct demangle_component
*);
449 static struct demangle_component
*
450 d_function_type (struct d_info
*);
452 static struct demangle_component
*
453 d_bare_function_type (struct d_info
*, int);
455 static struct demangle_component
*
456 d_class_enum_type (struct d_info
*);
458 static struct demangle_component
*d_array_type (struct d_info
*);
460 static struct demangle_component
*d_vector_type (struct d_info
*);
462 static struct demangle_component
*
463 d_pointer_to_member_type (struct d_info
*);
465 static struct demangle_component
*
466 d_template_param (struct d_info
*);
468 static struct demangle_component
*d_template_args (struct d_info
*);
469 static struct demangle_component
*d_template_args_1 (struct d_info
*);
471 static struct demangle_component
*
472 d_template_arg (struct d_info
*);
474 static struct demangle_component
*d_expression (struct d_info
*);
476 static struct demangle_component
*d_expr_primary (struct d_info
*);
478 static struct demangle_component
*d_local_name (struct d_info
*);
480 static int d_discriminator (struct d_info
*);
482 static struct demangle_component
*d_lambda (struct d_info
*);
484 static struct demangle_component
*d_unnamed_type (struct d_info
*);
486 static struct demangle_component
*
487 d_clone_suffix (struct d_info
*, struct demangle_component
*);
490 d_add_substitution (struct d_info
*, struct demangle_component
*);
492 static struct demangle_component
*d_substitution (struct d_info
*, int);
494 static void d_checkpoint (struct d_info
*, struct d_info_checkpoint
*);
496 static void d_backtrack (struct d_info
*, struct d_info_checkpoint
*);
498 static void d_growable_string_init (struct d_growable_string
*, size_t);
501 d_growable_string_resize (struct d_growable_string
*, size_t);
504 d_growable_string_append_buffer (struct d_growable_string
*,
505 const char *, size_t);
507 d_growable_string_callback_adapter (const char *, size_t, void *);
510 d_print_init (struct d_print_info
*, demangle_callbackref
, void *,
511 const struct demangle_component
*);
513 static inline void d_print_error (struct d_print_info
*);
515 static inline int d_print_saw_error (struct d_print_info
*);
517 static inline void d_print_flush (struct d_print_info
*);
519 static inline void d_append_char (struct d_print_info
*, char);
521 static inline void d_append_buffer (struct d_print_info
*,
522 const char *, size_t);
524 static inline void d_append_string (struct d_print_info
*, const char *);
526 static inline char d_last_char (struct d_print_info
*);
529 d_print_comp (struct d_print_info
*, int, const struct demangle_component
*);
532 d_print_java_identifier (struct d_print_info
*, const char *, int);
535 d_print_mod_list (struct d_print_info
*, int, struct d_print_mod
*, int);
538 d_print_mod (struct d_print_info
*, int, const struct demangle_component
*);
541 d_print_function_type (struct d_print_info
*, int,
542 const struct demangle_component
*,
543 struct d_print_mod
*);
546 d_print_array_type (struct d_print_info
*, int,
547 const struct demangle_component
*,
548 struct d_print_mod
*);
551 d_print_expr_op (struct d_print_info
*, int, const struct demangle_component
*);
553 static void d_print_cast (struct d_print_info
*, int,
554 const struct demangle_component
*);
555 static void d_print_conversion (struct d_print_info
*, int,
556 const struct demangle_component
*);
558 static int d_demangle_callback (const char *, int,
559 demangle_callbackref
, void *);
560 static char *d_demangle (const char *, int, size_t *);
562 #ifdef CP_DEMANGLE_DEBUG
565 d_dump (struct demangle_component
*dc
, int indent
)
572 printf ("failed demangling\n");
576 for (i
= 0; i
< indent
; ++i
)
581 case DEMANGLE_COMPONENT_NAME
:
582 printf ("name '%.*s'\n", dc
->u
.s_name
.len
, dc
->u
.s_name
.s
);
584 case DEMANGLE_COMPONENT_TAGGED_NAME
:
585 printf ("tagged name\n");
586 d_dump (dc
->u
.s_binary
.left
, indent
+ 2);
587 d_dump (dc
->u
.s_binary
.right
, indent
+ 2);
589 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
590 printf ("template parameter %ld\n", dc
->u
.s_number
.number
);
592 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
593 printf ("function parameter %ld\n", dc
->u
.s_number
.number
);
595 case DEMANGLE_COMPONENT_CTOR
:
596 printf ("constructor %d\n", (int) dc
->u
.s_ctor
.kind
);
597 d_dump (dc
->u
.s_ctor
.name
, indent
+ 2);
599 case DEMANGLE_COMPONENT_DTOR
:
600 printf ("destructor %d\n", (int) dc
->u
.s_dtor
.kind
);
601 d_dump (dc
->u
.s_dtor
.name
, indent
+ 2);
603 case DEMANGLE_COMPONENT_SUB_STD
:
604 printf ("standard substitution %s\n", dc
->u
.s_string
.string
);
606 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
607 printf ("builtin type %s\n", dc
->u
.s_builtin
.type
->name
);
609 case DEMANGLE_COMPONENT_OPERATOR
:
610 printf ("operator %s\n", dc
->u
.s_operator
.op
->name
);
612 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
613 printf ("extended operator with %d args\n",
614 dc
->u
.s_extended_operator
.args
);
615 d_dump (dc
->u
.s_extended_operator
.name
, indent
+ 2);
618 case DEMANGLE_COMPONENT_QUAL_NAME
:
619 printf ("qualified name\n");
621 case DEMANGLE_COMPONENT_LOCAL_NAME
:
622 printf ("local name\n");
624 case DEMANGLE_COMPONENT_TYPED_NAME
:
625 printf ("typed name\n");
627 case DEMANGLE_COMPONENT_TEMPLATE
:
628 printf ("template\n");
630 case DEMANGLE_COMPONENT_VTABLE
:
633 case DEMANGLE_COMPONENT_VTT
:
636 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
637 printf ("construction vtable\n");
639 case DEMANGLE_COMPONENT_TYPEINFO
:
640 printf ("typeinfo\n");
642 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
643 printf ("typeinfo name\n");
645 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
646 printf ("typeinfo function\n");
648 case DEMANGLE_COMPONENT_THUNK
:
651 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
652 printf ("virtual thunk\n");
654 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
655 printf ("covariant thunk\n");
657 case DEMANGLE_COMPONENT_JAVA_CLASS
:
658 printf ("java class\n");
660 case DEMANGLE_COMPONENT_GUARD
:
663 case DEMANGLE_COMPONENT_REFTEMP
:
664 printf ("reference temporary\n");
666 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
667 printf ("hidden alias\n");
669 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
670 printf ("transaction clone\n");
672 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
673 printf ("non-transaction clone\n");
675 case DEMANGLE_COMPONENT_RESTRICT
:
676 printf ("restrict\n");
678 case DEMANGLE_COMPONENT_VOLATILE
:
679 printf ("volatile\n");
681 case DEMANGLE_COMPONENT_CONST
:
684 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
685 printf ("restrict this\n");
687 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
688 printf ("volatile this\n");
690 case DEMANGLE_COMPONENT_CONST_THIS
:
691 printf ("const this\n");
693 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
694 printf ("reference this\n");
696 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
697 printf ("rvalue reference this\n");
699 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
700 printf ("transaction_safe this\n");
702 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
703 printf ("vendor type qualifier\n");
705 case DEMANGLE_COMPONENT_POINTER
:
706 printf ("pointer\n");
708 case DEMANGLE_COMPONENT_REFERENCE
:
709 printf ("reference\n");
711 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
712 printf ("rvalue reference\n");
714 case DEMANGLE_COMPONENT_COMPLEX
:
715 printf ("complex\n");
717 case DEMANGLE_COMPONENT_IMAGINARY
:
718 printf ("imaginary\n");
720 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
721 printf ("vendor type\n");
723 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
724 printf ("function type\n");
726 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
727 printf ("array type\n");
729 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
730 printf ("pointer to member type\n");
732 case DEMANGLE_COMPONENT_FIXED_TYPE
:
733 printf ("fixed-point type, accum? %d, sat? %d\n",
734 dc
->u
.s_fixed
.accum
, dc
->u
.s_fixed
.sat
);
735 d_dump (dc
->u
.s_fixed
.length
, indent
+ 2);
737 case DEMANGLE_COMPONENT_ARGLIST
:
738 printf ("argument list\n");
740 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
741 printf ("template argument list\n");
743 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
744 printf ("initializer list\n");
746 case DEMANGLE_COMPONENT_CAST
:
749 case DEMANGLE_COMPONENT_CONVERSION
:
750 printf ("conversion operator\n");
752 case DEMANGLE_COMPONENT_NULLARY
:
753 printf ("nullary operator\n");
755 case DEMANGLE_COMPONENT_UNARY
:
756 printf ("unary operator\n");
758 case DEMANGLE_COMPONENT_BINARY
:
759 printf ("binary operator\n");
761 case DEMANGLE_COMPONENT_BINARY_ARGS
:
762 printf ("binary operator arguments\n");
764 case DEMANGLE_COMPONENT_TRINARY
:
765 printf ("trinary operator\n");
767 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
768 printf ("trinary operator arguments 1\n");
770 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
771 printf ("trinary operator arguments 1\n");
773 case DEMANGLE_COMPONENT_LITERAL
:
774 printf ("literal\n");
776 case DEMANGLE_COMPONENT_LITERAL_NEG
:
777 printf ("negative literal\n");
779 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
780 printf ("java resource\n");
782 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
783 printf ("compound name\n");
785 case DEMANGLE_COMPONENT_CHARACTER
:
786 printf ("character '%c'\n", dc
->u
.s_character
.character
);
788 case DEMANGLE_COMPONENT_NUMBER
:
789 printf ("number %ld\n", dc
->u
.s_number
.number
);
791 case DEMANGLE_COMPONENT_DECLTYPE
:
792 printf ("decltype\n");
794 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
795 printf ("pack expansion\n");
797 case DEMANGLE_COMPONENT_TLS_INIT
:
798 printf ("tls init function\n");
800 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
801 printf ("tls wrapper function\n");
803 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
804 printf ("default argument %d\n", dc
->u
.s_unary_num
.num
);
805 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
807 case DEMANGLE_COMPONENT_LAMBDA
:
808 printf ("lambda %d\n", dc
->u
.s_unary_num
.num
);
809 d_dump (dc
->u
.s_unary_num
.sub
, indent
+2);
813 d_dump (d_left (dc
), indent
+ 2);
814 d_dump (d_right (dc
), indent
+ 2);
817 #endif /* CP_DEMANGLE_DEBUG */
819 /* Fill in a DEMANGLE_COMPONENT_NAME. */
821 CP_STATIC_IF_GLIBCPP_V3
823 cplus_demangle_fill_name (struct demangle_component
*p
, const char *s
, int len
)
825 if (p
== NULL
|| s
== NULL
|| len
== 0)
827 p
->type
= DEMANGLE_COMPONENT_NAME
;
829 p
->u
.s_name
.len
= len
;
833 /* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
835 CP_STATIC_IF_GLIBCPP_V3
837 cplus_demangle_fill_extended_operator (struct demangle_component
*p
, int args
,
838 struct demangle_component
*name
)
840 if (p
== NULL
|| args
< 0 || name
== NULL
)
842 p
->type
= DEMANGLE_COMPONENT_EXTENDED_OPERATOR
;
843 p
->u
.s_extended_operator
.args
= args
;
844 p
->u
.s_extended_operator
.name
= name
;
848 /* Fill in a DEMANGLE_COMPONENT_CTOR. */
850 CP_STATIC_IF_GLIBCPP_V3
852 cplus_demangle_fill_ctor (struct demangle_component
*p
,
853 enum gnu_v3_ctor_kinds kind
,
854 struct demangle_component
*name
)
858 || (int) kind
< gnu_v3_complete_object_ctor
859 || (int) kind
> gnu_v3_object_ctor_group
)
861 p
->type
= DEMANGLE_COMPONENT_CTOR
;
862 p
->u
.s_ctor
.kind
= kind
;
863 p
->u
.s_ctor
.name
= name
;
867 /* Fill in a DEMANGLE_COMPONENT_DTOR. */
869 CP_STATIC_IF_GLIBCPP_V3
871 cplus_demangle_fill_dtor (struct demangle_component
*p
,
872 enum gnu_v3_dtor_kinds kind
,
873 struct demangle_component
*name
)
877 || (int) kind
< gnu_v3_deleting_dtor
878 || (int) kind
> gnu_v3_object_dtor_group
)
880 p
->type
= DEMANGLE_COMPONENT_DTOR
;
881 p
->u
.s_dtor
.kind
= kind
;
882 p
->u
.s_dtor
.name
= name
;
886 /* Add a new component. */
888 static struct demangle_component
*
889 d_make_empty (struct d_info
*di
)
891 struct demangle_component
*p
;
893 if (di
->next_comp
>= di
->num_comps
)
895 p
= &di
->comps
[di
->next_comp
];
900 /* Add a new generic component. */
902 static struct demangle_component
*
903 d_make_comp (struct d_info
*di
, enum demangle_component_type type
,
904 struct demangle_component
*left
,
905 struct demangle_component
*right
)
907 struct demangle_component
*p
;
909 /* We check for errors here. A typical error would be a NULL return
910 from a subroutine. We catch those here, and return NULL
914 /* These types require two parameters. */
915 case DEMANGLE_COMPONENT_QUAL_NAME
:
916 case DEMANGLE_COMPONENT_LOCAL_NAME
:
917 case DEMANGLE_COMPONENT_TYPED_NAME
:
918 case DEMANGLE_COMPONENT_TAGGED_NAME
:
919 case DEMANGLE_COMPONENT_TEMPLATE
:
920 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
921 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
922 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
923 case DEMANGLE_COMPONENT_UNARY
:
924 case DEMANGLE_COMPONENT_BINARY
:
925 case DEMANGLE_COMPONENT_BINARY_ARGS
:
926 case DEMANGLE_COMPONENT_TRINARY
:
927 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
928 case DEMANGLE_COMPONENT_LITERAL
:
929 case DEMANGLE_COMPONENT_LITERAL_NEG
:
930 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
931 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
932 case DEMANGLE_COMPONENT_CLONE
:
933 if (left
== NULL
|| right
== NULL
)
937 /* These types only require one parameter. */
938 case DEMANGLE_COMPONENT_VTABLE
:
939 case DEMANGLE_COMPONENT_VTT
:
940 case DEMANGLE_COMPONENT_TYPEINFO
:
941 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
942 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
943 case DEMANGLE_COMPONENT_THUNK
:
944 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
945 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
946 case DEMANGLE_COMPONENT_JAVA_CLASS
:
947 case DEMANGLE_COMPONENT_GUARD
:
948 case DEMANGLE_COMPONENT_TLS_INIT
:
949 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
950 case DEMANGLE_COMPONENT_REFTEMP
:
951 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
952 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
953 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
954 case DEMANGLE_COMPONENT_POINTER
:
955 case DEMANGLE_COMPONENT_REFERENCE
:
956 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
957 case DEMANGLE_COMPONENT_COMPLEX
:
958 case DEMANGLE_COMPONENT_IMAGINARY
:
959 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
960 case DEMANGLE_COMPONENT_CAST
:
961 case DEMANGLE_COMPONENT_CONVERSION
:
962 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
963 case DEMANGLE_COMPONENT_DECLTYPE
:
964 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
965 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
966 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
967 case DEMANGLE_COMPONENT_NULLARY
:
968 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
973 /* This needs a right parameter, but the left parameter can be
975 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
976 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
981 /* These are allowed to have no parameters--in some cases they
982 will be filled in later. */
983 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
984 case DEMANGLE_COMPONENT_RESTRICT
:
985 case DEMANGLE_COMPONENT_VOLATILE
:
986 case DEMANGLE_COMPONENT_CONST
:
987 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
988 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
989 case DEMANGLE_COMPONENT_CONST_THIS
:
990 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
991 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
992 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
993 case DEMANGLE_COMPONENT_ARGLIST
:
994 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
997 /* Other types should not be seen here. */
1002 p
= d_make_empty (di
);
1006 p
->u
.s_binary
.left
= left
;
1007 p
->u
.s_binary
.right
= right
;
1012 /* Add a new demangle mangled name component. */
1014 static struct demangle_component
*
1015 d_make_demangle_mangled_name (struct d_info
*di
, const char *s
)
1017 if (d_peek_char (di
) != '_' || d_peek_next_char (di
) != 'Z')
1018 return d_make_name (di
, s
, strlen (s
));
1020 return d_encoding (di
, 0);
1023 /* Add a new name component. */
1025 static struct demangle_component
*
1026 d_make_name (struct d_info
*di
, const char *s
, int len
)
1028 struct demangle_component
*p
;
1030 p
= d_make_empty (di
);
1031 if (! cplus_demangle_fill_name (p
, s
, len
))
1036 /* Add a new builtin type component. */
1038 static struct demangle_component
*
1039 d_make_builtin_type (struct d_info
*di
,
1040 const struct demangle_builtin_type_info
*type
)
1042 struct demangle_component
*p
;
1046 p
= d_make_empty (di
);
1049 p
->type
= DEMANGLE_COMPONENT_BUILTIN_TYPE
;
1050 p
->u
.s_builtin
.type
= type
;
1055 /* Add a new operator component. */
1057 static struct demangle_component
*
1058 d_make_operator (struct d_info
*di
, const struct demangle_operator_info
*op
)
1060 struct demangle_component
*p
;
1062 p
= d_make_empty (di
);
1065 p
->type
= DEMANGLE_COMPONENT_OPERATOR
;
1066 p
->u
.s_operator
.op
= op
;
1071 /* Add a new extended operator component. */
1073 static struct demangle_component
*
1074 d_make_extended_operator (struct d_info
*di
, int args
,
1075 struct demangle_component
*name
)
1077 struct demangle_component
*p
;
1079 p
= d_make_empty (di
);
1080 if (! cplus_demangle_fill_extended_operator (p
, args
, name
))
1085 static struct demangle_component
*
1086 d_make_default_arg (struct d_info
*di
, int num
,
1087 struct demangle_component
*sub
)
1089 struct demangle_component
*p
= d_make_empty (di
);
1092 p
->type
= DEMANGLE_COMPONENT_DEFAULT_ARG
;
1093 p
->u
.s_unary_num
.num
= num
;
1094 p
->u
.s_unary_num
.sub
= sub
;
1099 /* Add a new constructor component. */
1101 static struct demangle_component
*
1102 d_make_ctor (struct d_info
*di
, enum gnu_v3_ctor_kinds kind
,
1103 struct demangle_component
*name
)
1105 struct demangle_component
*p
;
1107 p
= d_make_empty (di
);
1108 if (! cplus_demangle_fill_ctor (p
, kind
, name
))
1113 /* Add a new destructor component. */
1115 static struct demangle_component
*
1116 d_make_dtor (struct d_info
*di
, enum gnu_v3_dtor_kinds kind
,
1117 struct demangle_component
*name
)
1119 struct demangle_component
*p
;
1121 p
= d_make_empty (di
);
1122 if (! cplus_demangle_fill_dtor (p
, kind
, name
))
1127 /* Add a new template parameter. */
1129 static struct demangle_component
*
1130 d_make_template_param (struct d_info
*di
, int i
)
1132 struct demangle_component
*p
;
1134 p
= d_make_empty (di
);
1137 p
->type
= DEMANGLE_COMPONENT_TEMPLATE_PARAM
;
1138 p
->u
.s_number
.number
= i
;
1143 /* Add a new function parameter. */
1145 static struct demangle_component
*
1146 d_make_function_param (struct d_info
*di
, int i
)
1148 struct demangle_component
*p
;
1150 p
= d_make_empty (di
);
1153 p
->type
= DEMANGLE_COMPONENT_FUNCTION_PARAM
;
1154 p
->u
.s_number
.number
= i
;
1159 /* Add a new standard substitution component. */
1161 static struct demangle_component
*
1162 d_make_sub (struct d_info
*di
, const char *name
, int len
)
1164 struct demangle_component
*p
;
1166 p
= d_make_empty (di
);
1169 p
->type
= DEMANGLE_COMPONENT_SUB_STD
;
1170 p
->u
.s_string
.string
= name
;
1171 p
->u
.s_string
.len
= len
;
1176 /* <mangled-name> ::= _Z <encoding> [<clone-suffix>]*
1178 TOP_LEVEL is non-zero when called at the top level. */
1180 CP_STATIC_IF_GLIBCPP_V3
1181 struct demangle_component
*
1182 cplus_demangle_mangled_name (struct d_info
*di
, int top_level
)
1184 struct demangle_component
*p
;
1186 if (! d_check_char (di
, '_')
1187 /* Allow missing _ if not at toplevel to work around a
1188 bug in G++ abi-version=2 mangling; see the comment in
1189 write_template_arg. */
1192 if (! d_check_char (di
, 'Z'))
1194 p
= d_encoding (di
, top_level
);
1196 /* If at top level and parsing parameters, check for a clone
1198 if (top_level
&& (di
->options
& DMGL_PARAMS
) != 0)
1199 while (d_peek_char (di
) == '.'
1200 && (IS_LOWER (d_peek_next_char (di
))
1201 || d_peek_next_char (di
) == '_'
1202 || IS_DIGIT (d_peek_next_char (di
))))
1203 p
= d_clone_suffix (di
, p
);
1208 /* Return whether a function should have a return type. The argument
1209 is the function name, which may be qualified in various ways. The
1210 rules are that template functions have return types with some
1211 exceptions, function types which are not part of a function name
1212 mangling have return types with some exceptions, and non-template
1213 function names do not have return types. The exceptions are that
1214 constructors, destructors, and conversion operators do not have
1218 has_return_type (struct demangle_component
*dc
)
1226 case DEMANGLE_COMPONENT_TEMPLATE
:
1227 return ! is_ctor_dtor_or_conversion (d_left (dc
));
1228 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
1229 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
1230 case DEMANGLE_COMPONENT_CONST_THIS
:
1231 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
1232 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
1233 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
1234 return has_return_type (d_left (dc
));
1238 /* Return whether a name is a constructor, a destructor, or a
1239 conversion operator. */
1242 is_ctor_dtor_or_conversion (struct demangle_component
*dc
)
1250 case DEMANGLE_COMPONENT_QUAL_NAME
:
1251 case DEMANGLE_COMPONENT_LOCAL_NAME
:
1252 return is_ctor_dtor_or_conversion (d_right (dc
));
1253 case DEMANGLE_COMPONENT_CTOR
:
1254 case DEMANGLE_COMPONENT_DTOR
:
1255 case DEMANGLE_COMPONENT_CONVERSION
:
1260 /* <encoding> ::= <(function) name> <bare-function-type>
1264 TOP_LEVEL is non-zero when called at the top level, in which case
1265 if DMGL_PARAMS is not set we do not demangle the function
1266 parameters. We only set this at the top level, because otherwise
1267 we would not correctly demangle names in local scopes. */
1269 static struct demangle_component
*
1270 d_encoding (struct d_info
*di
, int top_level
)
1272 char peek
= d_peek_char (di
);
1274 if (peek
== 'G' || peek
== 'T')
1275 return d_special_name (di
);
1278 struct demangle_component
*dc
;
1282 if (dc
!= NULL
&& top_level
&& (di
->options
& DMGL_PARAMS
) == 0)
1284 /* Strip off any initial CV-qualifiers, as they really apply
1285 to the `this' parameter, and they were not output by the
1286 v2 demangler without DMGL_PARAMS. */
1287 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1288 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1289 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
1290 || dc
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
1291 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1292 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1295 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
1296 there may be CV-qualifiers on its right argument which
1297 really apply here; this happens when parsing a class
1298 which is local to a function. */
1299 if (dc
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
1301 struct demangle_component
*dcr
;
1304 while (dcr
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
1305 || dcr
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
1306 || dcr
->type
== DEMANGLE_COMPONENT_CONST_THIS
1307 || dcr
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
1308 || dcr
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
1309 || dcr
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
1311 dc
->u
.s_binary
.right
= dcr
;
1317 peek
= d_peek_char (di
);
1318 if (dc
== NULL
|| peek
== '\0' || peek
== 'E')
1320 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPED_NAME
, dc
,
1321 d_bare_function_type (di
, has_return_type (dc
)));
1325 /* <tagged-name> ::= <name> B <source-name> */
1327 static struct demangle_component
*
1328 d_abi_tags (struct d_info
*di
, struct demangle_component
*dc
)
1330 struct demangle_component
*hold_last_name
;
1333 /* Preserve the last name, so the ABI tag doesn't clobber it. */
1334 hold_last_name
= di
->last_name
;
1336 while (peek
= d_peek_char (di
),
1339 struct demangle_component
*tag
;
1341 tag
= d_source_name (di
);
1342 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TAGGED_NAME
, dc
, tag
);
1345 di
->last_name
= hold_last_name
;
1350 /* <name> ::= <nested-name>
1352 ::= <unscoped-template-name> <template-args>
1355 <unscoped-name> ::= <unqualified-name>
1356 ::= St <unqualified-name>
1358 <unscoped-template-name> ::= <unscoped-name>
1362 static struct demangle_component
*
1363 d_name (struct d_info
*di
)
1365 char peek
= d_peek_char (di
);
1366 struct demangle_component
*dc
;
1371 return d_nested_name (di
);
1374 return d_local_name (di
);
1377 return d_unqualified_name (di
);
1383 if (d_peek_next_char (di
) != 't')
1385 dc
= d_substitution (di
, 0);
1391 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
,
1392 d_make_name (di
, "std", 3),
1393 d_unqualified_name (di
));
1398 if (d_peek_char (di
) != 'I')
1400 /* The grammar does not permit this case to occur if we
1401 called d_substitution() above (i.e., subst == 1). We
1402 don't bother to check. */
1406 /* This is <template-args>, which means that we just saw
1407 <unscoped-template-name>, which is a substitution
1408 candidate if we didn't just get it from a
1412 if (! d_add_substitution (di
, dc
))
1415 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1416 d_template_args (di
));
1424 dc
= d_unqualified_name (di
);
1425 if (d_peek_char (di
) == 'I')
1427 /* This is <template-args>, which means that we just saw
1428 <unscoped-template-name>, which is a substitution
1430 if (! d_add_substitution (di
, dc
))
1432 dc
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, dc
,
1433 d_template_args (di
));
1439 /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1440 ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1443 static struct demangle_component
*
1444 d_nested_name (struct d_info
*di
)
1446 struct demangle_component
*ret
;
1447 struct demangle_component
**pret
;
1448 struct demangle_component
*rqual
;
1450 if (! d_check_char (di
, 'N'))
1453 pret
= d_cv_qualifiers (di
, &ret
, 1);
1457 /* Parse the ref-qualifier now and then attach it
1458 once we have something to attach it to. */
1459 rqual
= d_ref_qualifier (di
, NULL
);
1461 *pret
= d_prefix (di
);
1467 d_left (rqual
) = ret
;
1471 if (! d_check_char (di
, 'E'))
1477 /* <prefix> ::= <prefix> <unqualified-name>
1478 ::= <template-prefix> <template-args>
1479 ::= <template-param>
1484 <template-prefix> ::= <prefix> <(template) unqualified-name>
1485 ::= <template-param>
1489 static struct demangle_component
*
1490 d_prefix (struct d_info
*di
)
1492 struct demangle_component
*ret
= NULL
;
1497 enum demangle_component_type comb_type
;
1498 struct demangle_component
*dc
;
1500 peek
= d_peek_char (di
);
1504 /* The older code accepts a <local-name> here, but I don't see
1505 that in the grammar. The older code does not accept a
1506 <template-param> here. */
1508 comb_type
= DEMANGLE_COMPONENT_QUAL_NAME
;
1511 char peek2
= d_peek_next_char (di
);
1512 if (peek2
== 'T' || peek2
== 't')
1514 dc
= cplus_demangle_type (di
);
1516 /* Destructor name. */
1517 dc
= d_unqualified_name (di
);
1519 else if (IS_DIGIT (peek
)
1524 dc
= d_unqualified_name (di
);
1525 else if (peek
== 'S')
1526 dc
= d_substitution (di
, 1);
1527 else if (peek
== 'I')
1531 comb_type
= DEMANGLE_COMPONENT_TEMPLATE
;
1532 dc
= d_template_args (di
);
1534 else if (peek
== 'T')
1535 dc
= d_template_param (di
);
1536 else if (peek
== 'E')
1538 else if (peek
== 'M')
1540 /* Initializer scope for a lambda. We don't need to represent
1541 this; the normal code will just treat the variable as a type
1542 scope, which gives appropriate output. */
1554 ret
= d_make_comp (di
, comb_type
, ret
, dc
);
1556 if (peek
!= 'S' && d_peek_char (di
) != 'E')
1558 if (! d_add_substitution (di
, ret
))
1564 /* <unqualified-name> ::= <operator-name>
1565 ::= <ctor-dtor-name>
1567 ::= <local-source-name>
1569 <local-source-name> ::= L <source-name> <discriminator>
1572 static struct demangle_component
*
1573 d_unqualified_name (struct d_info
*di
)
1575 struct demangle_component
*ret
;
1578 peek
= d_peek_char (di
);
1579 if (IS_DIGIT (peek
))
1580 ret
= d_source_name (di
);
1581 else if (IS_LOWER (peek
))
1583 ret
= d_operator_name (di
);
1584 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_OPERATOR
)
1586 di
->expansion
+= sizeof "operator" + ret
->u
.s_operator
.op
->len
- 2;
1587 if (!strcmp (ret
->u
.s_operator
.op
->code
, "li"))
1588 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, ret
,
1589 d_source_name (di
));
1592 else if (peek
== 'C' || peek
== 'D')
1593 ret
= d_ctor_dtor_name (di
);
1594 else if (peek
== 'L')
1598 ret
= d_source_name (di
);
1601 if (! d_discriminator (di
))
1604 else if (peek
== 'U')
1606 switch (d_peek_next_char (di
))
1609 ret
= d_lambda (di
);
1612 ret
= d_unnamed_type (di
);
1621 if (d_peek_char (di
) == 'B')
1622 ret
= d_abi_tags (di
, ret
);
1626 /* <source-name> ::= <(positive length) number> <identifier> */
1628 static struct demangle_component
*
1629 d_source_name (struct d_info
*di
)
1632 struct demangle_component
*ret
;
1634 len
= d_number (di
);
1637 ret
= d_identifier (di
, len
);
1638 di
->last_name
= ret
;
1642 /* number ::= [n] <(non-negative decimal integer)> */
1645 d_number (struct d_info
*di
)
1652 peek
= d_peek_char (di
);
1657 peek
= d_peek_char (di
);
1663 if (! IS_DIGIT (peek
))
1669 ret
= ret
* 10 + peek
- '0';
1671 peek
= d_peek_char (di
);
1675 /* Like d_number, but returns a demangle_component. */
1677 static struct demangle_component
*
1678 d_number_component (struct d_info
*di
)
1680 struct demangle_component
*ret
= d_make_empty (di
);
1683 ret
->type
= DEMANGLE_COMPONENT_NUMBER
;
1684 ret
->u
.s_number
.number
= d_number (di
);
1689 /* identifier ::= <(unqualified source code identifier)> */
1691 static struct demangle_component
*
1692 d_identifier (struct d_info
*di
, int len
)
1698 if (di
->send
- name
< len
)
1701 d_advance (di
, len
);
1703 /* A Java mangled name may have a trailing '$' if it is a C++
1704 keyword. This '$' is not included in the length count. We just
1706 if ((di
->options
& DMGL_JAVA
) != 0
1707 && d_peek_char (di
) == '$')
1710 /* Look for something which looks like a gcc encoding of an
1711 anonymous namespace, and replace it with a more user friendly
1713 if (len
>= (int) ANONYMOUS_NAMESPACE_PREFIX_LEN
+ 2
1714 && memcmp (name
, ANONYMOUS_NAMESPACE_PREFIX
,
1715 ANONYMOUS_NAMESPACE_PREFIX_LEN
) == 0)
1719 s
= name
+ ANONYMOUS_NAMESPACE_PREFIX_LEN
;
1720 if ((*s
== '.' || *s
== '_' || *s
== '$')
1723 di
->expansion
-= len
- sizeof "(anonymous namespace)";
1724 return d_make_name (di
, "(anonymous namespace)",
1725 sizeof "(anonymous namespace)" - 1);
1729 return d_make_name (di
, name
, len
);
1732 /* operator_name ::= many different two character encodings.
1734 ::= v <digit> <source-name>
1736 This list is sorted for binary search. */
1738 #define NL(s) s, (sizeof s) - 1
1740 CP_STATIC_IF_GLIBCPP_V3
1741 const struct demangle_operator_info cplus_demangle_operators
[] =
1743 { "aN", NL ("&="), 2 },
1744 { "aS", NL ("="), 2 },
1745 { "aa", NL ("&&"), 2 },
1746 { "ad", NL ("&"), 1 },
1747 { "an", NL ("&"), 2 },
1748 { "at", NL ("alignof "), 1 },
1749 { "az", NL ("alignof "), 1 },
1750 { "cc", NL ("const_cast"), 2 },
1751 { "cl", NL ("()"), 2 },
1752 { "cm", NL (","), 2 },
1753 { "co", NL ("~"), 1 },
1754 { "dV", NL ("/="), 2 },
1755 { "da", NL ("delete[] "), 1 },
1756 { "dc", NL ("dynamic_cast"), 2 },
1757 { "de", NL ("*"), 1 },
1758 { "dl", NL ("delete "), 1 },
1759 { "ds", NL (".*"), 2 },
1760 { "dt", NL ("."), 2 },
1761 { "dv", NL ("/"), 2 },
1762 { "eO", NL ("^="), 2 },
1763 { "eo", NL ("^"), 2 },
1764 { "eq", NL ("=="), 2 },
1765 { "fL", NL ("..."), 3 },
1766 { "fR", NL ("..."), 3 },
1767 { "fl", NL ("..."), 2 },
1768 { "fr", NL ("..."), 2 },
1769 { "ge", NL (">="), 2 },
1770 { "gs", NL ("::"), 1 },
1771 { "gt", NL (">"), 2 },
1772 { "ix", NL ("[]"), 2 },
1773 { "lS", NL ("<<="), 2 },
1774 { "le", NL ("<="), 2 },
1775 { "li", NL ("operator\"\" "), 1 },
1776 { "ls", NL ("<<"), 2 },
1777 { "lt", NL ("<"), 2 },
1778 { "mI", NL ("-="), 2 },
1779 { "mL", NL ("*="), 2 },
1780 { "mi", NL ("-"), 2 },
1781 { "ml", NL ("*"), 2 },
1782 { "mm", NL ("--"), 1 },
1783 { "na", NL ("new[]"), 3 },
1784 { "ne", NL ("!="), 2 },
1785 { "ng", NL ("-"), 1 },
1786 { "nt", NL ("!"), 1 },
1787 { "nw", NL ("new"), 3 },
1788 { "oR", NL ("|="), 2 },
1789 { "oo", NL ("||"), 2 },
1790 { "or", NL ("|"), 2 },
1791 { "pL", NL ("+="), 2 },
1792 { "pl", NL ("+"), 2 },
1793 { "pm", NL ("->*"), 2 },
1794 { "pp", NL ("++"), 1 },
1795 { "ps", NL ("+"), 1 },
1796 { "pt", NL ("->"), 2 },
1797 { "qu", NL ("?"), 3 },
1798 { "rM", NL ("%="), 2 },
1799 { "rS", NL (">>="), 2 },
1800 { "rc", NL ("reinterpret_cast"), 2 },
1801 { "rm", NL ("%"), 2 },
1802 { "rs", NL (">>"), 2 },
1803 { "sP", NL ("sizeof..."), 1 },
1804 { "sZ", NL ("sizeof..."), 1 },
1805 { "sc", NL ("static_cast"), 2 },
1806 { "st", NL ("sizeof "), 1 },
1807 { "sz", NL ("sizeof "), 1 },
1808 { "tr", NL ("throw"), 0 },
1809 { "tw", NL ("throw "), 1 },
1810 { NULL
, NULL
, 0, 0 }
1813 static struct demangle_component
*
1814 d_operator_name (struct d_info
*di
)
1819 c1
= d_next_char (di
);
1820 c2
= d_next_char (di
);
1821 if (c1
== 'v' && IS_DIGIT (c2
))
1822 return d_make_extended_operator (di
, c2
- '0', d_source_name (di
));
1823 else if (c1
== 'c' && c2
== 'v')
1825 struct demangle_component
*type
;
1826 int was_conversion
= di
->is_conversion
;
1827 struct demangle_component
*res
;
1829 di
->is_conversion
= ! di
->is_expression
;
1830 type
= cplus_demangle_type (di
);
1831 if (di
->is_conversion
)
1832 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CONVERSION
, type
, NULL
);
1834 res
= d_make_comp (di
, DEMANGLE_COMPONENT_CAST
, type
, NULL
);
1835 di
->is_conversion
= was_conversion
;
1840 /* LOW is the inclusive lower bound. */
1842 /* HIGH is the exclusive upper bound. We subtract one to ignore
1843 the sentinel at the end of the array. */
1844 int high
= ((sizeof (cplus_demangle_operators
)
1845 / sizeof (cplus_demangle_operators
[0]))
1851 const struct demangle_operator_info
*p
;
1853 i
= low
+ (high
- low
) / 2;
1854 p
= cplus_demangle_operators
+ i
;
1856 if (c1
== p
->code
[0] && c2
== p
->code
[1])
1857 return d_make_operator (di
, p
);
1859 if (c1
< p
->code
[0] || (c1
== p
->code
[0] && c2
< p
->code
[1]))
1869 static struct demangle_component
*
1870 d_make_character (struct d_info
*di
, int c
)
1872 struct demangle_component
*p
;
1873 p
= d_make_empty (di
);
1876 p
->type
= DEMANGLE_COMPONENT_CHARACTER
;
1877 p
->u
.s_character
.character
= c
;
1882 static struct demangle_component
*
1883 d_java_resource (struct d_info
*di
)
1885 struct demangle_component
*p
= NULL
;
1886 struct demangle_component
*next
= NULL
;
1891 len
= d_number (di
);
1895 /* Eat the leading '_'. */
1896 if (d_next_char (di
) != '_')
1909 /* Each chunk is either a '$' escape... */
1927 next
= d_make_character (di
, c
);
1935 /* ... or a sequence of characters. */
1938 while (i
< len
&& str
[i
] && str
[i
] != '$')
1941 next
= d_make_name (di
, str
, i
);
1954 p
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPOUND_NAME
, p
, next
);
1960 p
= d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_RESOURCE
, p
, NULL
);
1965 /* <special-name> ::= TV <type>
1969 ::= GV <(object) name>
1970 ::= T <call-offset> <(base) encoding>
1971 ::= Tc <call-offset> <call-offset> <(base) encoding>
1972 Also g++ extensions:
1973 ::= TC <type> <(offset) number> _ <(base) type>
1978 ::= Gr <resource name>
1983 static struct demangle_component
*
1984 d_special_name (struct d_info
*di
)
1986 di
->expansion
+= 20;
1987 if (d_check_char (di
, 'T'))
1989 switch (d_next_char (di
))
1993 return d_make_comp (di
, DEMANGLE_COMPONENT_VTABLE
,
1994 cplus_demangle_type (di
), NULL
);
1996 di
->expansion
-= 10;
1997 return d_make_comp (di
, DEMANGLE_COMPONENT_VTT
,
1998 cplus_demangle_type (di
), NULL
);
2000 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO
,
2001 cplus_demangle_type (di
), NULL
);
2003 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_NAME
,
2004 cplus_demangle_type (di
), NULL
);
2007 if (! d_call_offset (di
, 'h'))
2009 return d_make_comp (di
, DEMANGLE_COMPONENT_THUNK
,
2010 d_encoding (di
, 0), NULL
);
2013 if (! d_call_offset (di
, 'v'))
2015 return d_make_comp (di
, DEMANGLE_COMPONENT_VIRTUAL_THUNK
,
2016 d_encoding (di
, 0), NULL
);
2019 if (! d_call_offset (di
, '\0'))
2021 if (! d_call_offset (di
, '\0'))
2023 return d_make_comp (di
, DEMANGLE_COMPONENT_COVARIANT_THUNK
,
2024 d_encoding (di
, 0), NULL
);
2028 struct demangle_component
*derived_type
;
2030 struct demangle_component
*base_type
;
2032 derived_type
= cplus_demangle_type (di
);
2033 offset
= d_number (di
);
2036 if (! d_check_char (di
, '_'))
2038 base_type
= cplus_demangle_type (di
);
2039 /* We don't display the offset. FIXME: We should display
2040 it in verbose mode. */
2042 return d_make_comp (di
, DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
,
2043 base_type
, derived_type
);
2047 return d_make_comp (di
, DEMANGLE_COMPONENT_TYPEINFO_FN
,
2048 cplus_demangle_type (di
), NULL
);
2050 return d_make_comp (di
, DEMANGLE_COMPONENT_JAVA_CLASS
,
2051 cplus_demangle_type (di
), NULL
);
2054 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_INIT
,
2058 return d_make_comp (di
, DEMANGLE_COMPONENT_TLS_WRAPPER
,
2065 else if (d_check_char (di
, 'G'))
2067 switch (d_next_char (di
))
2070 return d_make_comp (di
, DEMANGLE_COMPONENT_GUARD
, d_name (di
), NULL
);
2074 struct demangle_component
*name
= d_name (di
);
2075 return d_make_comp (di
, DEMANGLE_COMPONENT_REFTEMP
, name
,
2076 d_number_component (di
));
2080 return d_make_comp (di
, DEMANGLE_COMPONENT_HIDDEN_ALIAS
,
2081 d_encoding (di
, 0), NULL
);
2084 switch (d_next_char (di
))
2087 return d_make_comp (di
, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
,
2088 d_encoding (di
, 0), NULL
);
2090 /* ??? The proposal is that other letters (such as 'h') stand
2091 for different variants of transaction cloning, such as
2092 compiling directly for hardware transaction support. But
2093 they still should all be transactional clones of some sort
2094 so go ahead and call them that. */
2096 return d_make_comp (di
, DEMANGLE_COMPONENT_TRANSACTION_CLONE
,
2097 d_encoding (di
, 0), NULL
);
2101 return d_java_resource (di
);
2111 /* <call-offset> ::= h <nv-offset> _
2114 <nv-offset> ::= <(offset) number>
2116 <v-offset> ::= <(offset) number> _ <(virtual offset) number>
2118 The C parameter, if not '\0', is a character we just read which is
2119 the start of the <call-offset>.
2121 We don't display the offset information anywhere. FIXME: We should
2122 display it in verbose mode. */
2125 d_call_offset (struct d_info
*di
, int c
)
2128 c
= d_next_char (di
);
2135 if (! d_check_char (di
, '_'))
2142 if (! d_check_char (di
, '_'))
2148 /* <ctor-dtor-name> ::= C1
2156 static struct demangle_component
*
2157 d_ctor_dtor_name (struct d_info
*di
)
2159 if (di
->last_name
!= NULL
)
2161 if (di
->last_name
->type
== DEMANGLE_COMPONENT_NAME
)
2162 di
->expansion
+= di
->last_name
->u
.s_name
.len
;
2163 else if (di
->last_name
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2164 di
->expansion
+= di
->last_name
->u
.s_string
.len
;
2166 switch (d_peek_char (di
))
2170 enum gnu_v3_ctor_kinds kind
;
2173 if (d_peek_next_char (di
) == 'I')
2179 switch (d_peek_next_char (di
))
2182 kind
= gnu_v3_complete_object_ctor
;
2185 kind
= gnu_v3_base_object_ctor
;
2188 kind
= gnu_v3_complete_object_allocating_ctor
;
2191 kind
= gnu_v3_unified_ctor
;
2194 kind
= gnu_v3_object_ctor_group
;
2203 cplus_demangle_type (di
);
2205 return d_make_ctor (di
, kind
, di
->last_name
);
2210 enum gnu_v3_dtor_kinds kind
;
2212 switch (d_peek_next_char (di
))
2215 kind
= gnu_v3_deleting_dtor
;
2218 kind
= gnu_v3_complete_object_dtor
;
2221 kind
= gnu_v3_base_object_dtor
;
2223 /* digit '3' is not used */
2225 kind
= gnu_v3_unified_dtor
;
2228 kind
= gnu_v3_object_dtor_group
;
2234 return d_make_dtor (di
, kind
, di
->last_name
);
2242 /* <type> ::= <builtin-type>
2244 ::= <class-enum-type>
2246 ::= <pointer-to-member-type>
2247 ::= <template-param>
2248 ::= <template-template-param> <template-args>
2250 ::= <CV-qualifiers> <type>
2253 ::= O <type> (C++0x)
2256 ::= U <source-name> <type>
2258 <builtin-type> ::= various one letter codes
2262 CP_STATIC_IF_GLIBCPP_V3
2263 const struct demangle_builtin_type_info
2264 cplus_demangle_builtin_types
[D_BUILTIN_TYPE_COUNT
] =
2266 /* a */ { NL ("signed char"), NL ("signed char"), D_PRINT_DEFAULT
},
2267 /* b */ { NL ("bool"), NL ("boolean"), D_PRINT_BOOL
},
2268 /* c */ { NL ("char"), NL ("byte"), D_PRINT_DEFAULT
},
2269 /* d */ { NL ("double"), NL ("double"), D_PRINT_FLOAT
},
2270 /* e */ { NL ("long double"), NL ("long double"), D_PRINT_FLOAT
},
2271 /* f */ { NL ("float"), NL ("float"), D_PRINT_FLOAT
},
2272 /* g */ { NL ("__float128"), NL ("__float128"), D_PRINT_FLOAT
},
2273 /* h */ { NL ("unsigned char"), NL ("unsigned char"), D_PRINT_DEFAULT
},
2274 /* i */ { NL ("int"), NL ("int"), D_PRINT_INT
},
2275 /* j */ { NL ("unsigned int"), NL ("unsigned"), D_PRINT_UNSIGNED
},
2276 /* k */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2277 /* l */ { NL ("long"), NL ("long"), D_PRINT_LONG
},
2278 /* m */ { NL ("unsigned long"), NL ("unsigned long"), D_PRINT_UNSIGNED_LONG
},
2279 /* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT
},
2280 /* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
2282 /* p */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2283 /* q */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2284 /* r */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2285 /* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT
},
2286 /* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT
},
2287 /* u */ { NULL
, 0, NULL
, 0, D_PRINT_DEFAULT
},
2288 /* v */ { NL ("void"), NL ("void"), D_PRINT_VOID
},
2289 /* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT
},
2290 /* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG
},
2291 /* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
2292 D_PRINT_UNSIGNED_LONG_LONG
},
2293 /* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT
},
2294 /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT
},
2295 /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT
},
2296 /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT
},
2297 /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT
},
2298 /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT
},
2299 /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT
},
2300 /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2304 CP_STATIC_IF_GLIBCPP_V3
2305 struct demangle_component
*
2306 cplus_demangle_type (struct d_info
*di
)
2309 struct demangle_component
*ret
;
2312 /* The ABI specifies that when CV-qualifiers are used, the base type
2313 is substitutable, and the fully qualified type is substitutable,
2314 but the base type with a strict subset of the CV-qualifiers is
2315 not substitutable. The natural recursive implementation of the
2316 CV-qualifiers would cause subsets to be substitutable, so instead
2317 we pull them all off now.
2319 FIXME: The ABI says that order-insensitive vendor qualifiers
2320 should be handled in the same way, but we have no way to tell
2321 which vendor qualifiers are order-insensitive and which are
2322 order-sensitive. So we just assume that they are all
2323 order-sensitive. g++ 3.4 supports only one vendor qualifier,
2324 __vector, and it treats it as order-sensitive when mangling
2327 peek
= d_peek_char (di
);
2328 if (peek
== 'r' || peek
== 'V' || peek
== 'K'
2329 || (peek
== 'D' && d_peek_next_char (di
) == 'x'))
2331 struct demangle_component
**pret
;
2333 pret
= d_cv_qualifiers (di
, &ret
, 0);
2336 if (d_peek_char (di
) == 'F')
2338 /* cv-qualifiers before a function type apply to 'this',
2339 so avoid adding the unqualified function type to
2340 the substitution list. */
2341 *pret
= d_function_type (di
);
2344 *pret
= cplus_demangle_type (di
);
2347 if ((*pret
)->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
2348 || (*pret
)->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
)
2350 /* Move the ref-qualifier outside the cv-qualifiers so that
2351 they are printed in the right order. */
2352 struct demangle_component
*fn
= d_left (*pret
);
2353 d_left (*pret
) = ret
;
2357 if (! d_add_substitution (di
, ret
))
2366 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
2367 case 'h': case 'i': case 'j': case 'l': case 'm': case 'n':
2368 case 'o': case 's': case 't':
2369 case 'v': case 'w': case 'x': case 'y': case 'z':
2370 ret
= d_make_builtin_type (di
,
2371 &cplus_demangle_builtin_types
[peek
- 'a']);
2372 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2379 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE
,
2380 d_source_name (di
), NULL
);
2384 ret
= d_function_type (di
);
2387 case '0': case '1': case '2': case '3': case '4':
2388 case '5': case '6': case '7': case '8': case '9':
2391 ret
= d_class_enum_type (di
);
2395 ret
= d_array_type (di
);
2399 ret
= d_pointer_to_member_type (di
);
2403 ret
= d_template_param (di
);
2404 if (d_peek_char (di
) == 'I')
2406 /* This may be <template-template-param> <template-args>.
2407 If this is the type for a conversion operator, we can
2408 have a <template-template-param> here only by following
2409 a derivation like this:
2412 -> <template-prefix> <template-args>
2413 -> <prefix> <template-unqualified-name> <template-args>
2414 -> <unqualified-name> <template-unqualified-name> <template-args>
2415 -> <source-name> <template-unqualified-name> <template-args>
2416 -> <source-name> <operator-name> <template-args>
2417 -> <source-name> cv <type> <template-args>
2418 -> <source-name> cv <template-template-param> <template-args> <template-args>
2420 where the <template-args> is followed by another.
2421 Otherwise, we must have a derivation like this:
2424 -> <template-prefix> <template-args>
2425 -> <prefix> <template-unqualified-name> <template-args>
2426 -> <unqualified-name> <template-unqualified-name> <template-args>
2427 -> <source-name> <template-unqualified-name> <template-args>
2428 -> <source-name> <operator-name> <template-args>
2429 -> <source-name> cv <type> <template-args>
2430 -> <source-name> cv <template-param> <template-args>
2432 where we need to leave the <template-args> to be processed
2433 by d_prefix (following the <template-prefix>).
2435 The <template-template-param> part is a substitution
2437 if (! di
->is_conversion
)
2439 if (! d_add_substitution (di
, ret
))
2441 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2442 d_template_args (di
));
2446 struct demangle_component
*args
;
2447 struct d_info_checkpoint checkpoint
;
2449 d_checkpoint (di
, &checkpoint
);
2450 args
= d_template_args (di
);
2451 if (d_peek_char (di
) == 'I')
2453 if (! d_add_substitution (di
, ret
))
2455 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2459 d_backtrack (di
, &checkpoint
);
2465 /* If this is a special substitution, then it is the start of
2466 <class-enum-type>. */
2470 peek_next
= d_peek_next_char (di
);
2471 if (IS_DIGIT (peek_next
)
2473 || IS_UPPER (peek_next
))
2475 ret
= d_substitution (di
, 0);
2476 /* The substituted name may have been a template name and
2477 may be followed by tepmlate args. */
2478 if (d_peek_char (di
) == 'I')
2479 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2480 d_template_args (di
));
2486 ret
= d_class_enum_type (di
);
2487 /* If the substitution was a complete type, then it is not
2488 a new substitution candidate. However, if the
2489 substitution was followed by template arguments, then
2490 the whole thing is a substitution candidate. */
2491 if (ret
!= NULL
&& ret
->type
== DEMANGLE_COMPONENT_SUB_STD
)
2499 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_RVALUE_REFERENCE
,
2500 cplus_demangle_type (di
), NULL
);
2505 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_POINTER
,
2506 cplus_demangle_type (di
), NULL
);
2511 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_REFERENCE
,
2512 cplus_demangle_type (di
), NULL
);
2517 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_COMPLEX
,
2518 cplus_demangle_type (di
), NULL
);
2523 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_IMAGINARY
,
2524 cplus_demangle_type (di
), NULL
);
2529 ret
= d_source_name (di
);
2530 if (d_peek_char (di
) == 'I')
2531 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, ret
,
2532 d_template_args (di
));
2533 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
,
2534 cplus_demangle_type (di
), ret
);
2540 peek
= d_next_char (di
);
2545 /* decltype (expression) */
2546 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_DECLTYPE
,
2547 d_expression (di
), NULL
);
2548 if (ret
&& d_next_char (di
) != 'E')
2554 /* Pack expansion. */
2555 ret
= d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
2556 cplus_demangle_type (di
), NULL
);
2562 ret
= d_make_name (di
, "auto", 4);
2566 /* 32-bit decimal floating point */
2567 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[26]);
2568 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2572 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[27]);
2573 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2577 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[28]);
2578 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2581 /* 16-bit half-precision FP */
2582 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[29]);
2583 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2587 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[30]);
2588 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2592 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[31]);
2593 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2597 /* Fixed point types. DF<int bits><length><fract bits><sat> */
2598 ret
= d_make_empty (di
);
2599 ret
->type
= DEMANGLE_COMPONENT_FIXED_TYPE
;
2600 if ((ret
->u
.s_fixed
.accum
= IS_DIGIT (d_peek_char (di
))))
2601 /* For demangling we don't care about the bits. */
2603 ret
->u
.s_fixed
.length
= cplus_demangle_type (di
);
2604 if (ret
->u
.s_fixed
.length
== NULL
)
2607 peek
= d_next_char (di
);
2608 ret
->u
.s_fixed
.sat
= (peek
== 's');
2612 ret
= d_vector_type (di
);
2617 /* decltype(nullptr) */
2618 ret
= d_make_builtin_type (di
, &cplus_demangle_builtin_types
[32]);
2619 di
->expansion
+= ret
->u
.s_builtin
.type
->len
;
2633 if (! d_add_substitution (di
, ret
))
2640 /* <CV-qualifiers> ::= [r] [V] [K] [Dx] */
2642 static struct demangle_component
**
2643 d_cv_qualifiers (struct d_info
*di
,
2644 struct demangle_component
**pret
, int member_fn
)
2646 struct demangle_component
**pstart
;
2650 peek
= d_peek_char (di
);
2651 while (peek
== 'r' || peek
== 'V' || peek
== 'K'
2652 || (peek
== 'D' && d_peek_next_char (di
) == 'x'))
2654 enum demangle_component_type t
;
2660 ? DEMANGLE_COMPONENT_RESTRICT_THIS
2661 : DEMANGLE_COMPONENT_RESTRICT
);
2662 di
->expansion
+= sizeof "restrict";
2664 else if (peek
== 'V')
2667 ? DEMANGLE_COMPONENT_VOLATILE_THIS
2668 : DEMANGLE_COMPONENT_VOLATILE
);
2669 di
->expansion
+= sizeof "volatile";
2671 else if (peek
== 'K')
2674 ? DEMANGLE_COMPONENT_CONST_THIS
2675 : DEMANGLE_COMPONENT_CONST
);
2676 di
->expansion
+= sizeof "const";
2680 t
= DEMANGLE_COMPONENT_TRANSACTION_SAFE
;
2681 di
->expansion
+= sizeof "transaction_safe";
2685 *pret
= d_make_comp (di
, t
, NULL
, NULL
);
2688 pret
= &d_left (*pret
);
2690 peek
= d_peek_char (di
);
2693 if (!member_fn
&& peek
== 'F')
2695 while (pstart
!= pret
)
2697 switch ((*pstart
)->type
)
2699 case DEMANGLE_COMPONENT_RESTRICT
:
2700 (*pstart
)->type
= DEMANGLE_COMPONENT_RESTRICT_THIS
;
2702 case DEMANGLE_COMPONENT_VOLATILE
:
2703 (*pstart
)->type
= DEMANGLE_COMPONENT_VOLATILE_THIS
;
2705 case DEMANGLE_COMPONENT_CONST
:
2706 (*pstart
)->type
= DEMANGLE_COMPONENT_CONST_THIS
;
2711 pstart
= &d_left (*pstart
);
2718 /* <ref-qualifier> ::= R
2721 static struct demangle_component
*
2722 d_ref_qualifier (struct d_info
*di
, struct demangle_component
*sub
)
2724 struct demangle_component
*ret
= sub
;
2727 peek
= d_peek_char (di
);
2728 if (peek
== 'R' || peek
== 'O')
2730 enum demangle_component_type t
;
2733 t
= DEMANGLE_COMPONENT_REFERENCE_THIS
;
2734 di
->expansion
+= sizeof "&";
2738 t
= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
;
2739 di
->expansion
+= sizeof "&&";
2743 ret
= d_make_comp (di
, t
, ret
, NULL
);
2749 /* <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] [T] E */
2751 static struct demangle_component
*
2752 d_function_type (struct d_info
*di
)
2754 struct demangle_component
*ret
;
2756 if (! d_check_char (di
, 'F'))
2758 if (d_peek_char (di
) == 'Y')
2760 /* Function has C linkage. We don't print this information.
2761 FIXME: We should print it in verbose mode. */
2764 ret
= d_bare_function_type (di
, 1);
2765 ret
= d_ref_qualifier (di
, ret
);
2767 if (! d_check_char (di
, 'E'))
2774 static struct demangle_component
*
2775 d_parmlist (struct d_info
*di
)
2777 struct demangle_component
*tl
;
2778 struct demangle_component
**ptl
;
2784 struct demangle_component
*type
;
2786 char peek
= d_peek_char (di
);
2787 if (peek
== '\0' || peek
== 'E' || peek
== '.')
2789 if ((peek
== 'R' || peek
== 'O')
2790 && d_peek_next_char (di
) == 'E')
2791 /* Function ref-qualifier, not a ref prefix for a parameter type. */
2793 type
= cplus_demangle_type (di
);
2796 *ptl
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, type
, NULL
);
2799 ptl
= &d_right (*ptl
);
2802 /* There should be at least one parameter type besides the optional
2803 return type. A function which takes no arguments will have a
2804 single parameter type void. */
2808 /* If we have a single parameter type void, omit it. */
2809 if (d_right (tl
) == NULL
2810 && d_left (tl
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
2811 && d_left (tl
)->u
.s_builtin
.type
->print
== D_PRINT_VOID
)
2813 di
->expansion
-= d_left (tl
)->u
.s_builtin
.type
->len
;
2820 /* <bare-function-type> ::= [J]<type>+ */
2822 static struct demangle_component
*
2823 d_bare_function_type (struct d_info
*di
, int has_return_type
)
2825 struct demangle_component
*return_type
;
2826 struct demangle_component
*tl
;
2829 /* Detect special qualifier indicating that the first argument
2830 is the return type. */
2831 peek
= d_peek_char (di
);
2835 has_return_type
= 1;
2838 if (has_return_type
)
2840 return_type
= cplus_demangle_type (di
);
2841 if (return_type
== NULL
)
2847 tl
= d_parmlist (di
);
2851 return d_make_comp (di
, DEMANGLE_COMPONENT_FUNCTION_TYPE
,
2855 /* <class-enum-type> ::= <name> */
2857 static struct demangle_component
*
2858 d_class_enum_type (struct d_info
*di
)
2863 /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
2864 ::= A [<(dimension) expression>] _ <(element) type>
2867 static struct demangle_component
*
2868 d_array_type (struct d_info
*di
)
2871 struct demangle_component
*dim
;
2873 if (! d_check_char (di
, 'A'))
2876 peek
= d_peek_char (di
);
2879 else if (IS_DIGIT (peek
))
2887 peek
= d_peek_char (di
);
2889 while (IS_DIGIT (peek
));
2890 dim
= d_make_name (di
, s
, d_str (di
) - s
);
2896 dim
= d_expression (di
);
2901 if (! d_check_char (di
, '_'))
2904 return d_make_comp (di
, DEMANGLE_COMPONENT_ARRAY_TYPE
, dim
,
2905 cplus_demangle_type (di
));
2908 /* <vector-type> ::= Dv <number> _ <type>
2909 ::= Dv _ <expression> _ <type> */
2911 static struct demangle_component
*
2912 d_vector_type (struct d_info
*di
)
2915 struct demangle_component
*dim
;
2917 peek
= d_peek_char (di
);
2921 dim
= d_expression (di
);
2924 dim
= d_number_component (di
);
2929 if (! d_check_char (di
, '_'))
2932 return d_make_comp (di
, DEMANGLE_COMPONENT_VECTOR_TYPE
, dim
,
2933 cplus_demangle_type (di
));
2936 /* <pointer-to-member-type> ::= M <(class) type> <(member) type> */
2938 static struct demangle_component
*
2939 d_pointer_to_member_type (struct d_info
*di
)
2941 struct demangle_component
*cl
;
2942 struct demangle_component
*mem
;
2944 if (! d_check_char (di
, 'M'))
2947 cl
= cplus_demangle_type (di
);
2951 /* The ABI says, "The type of a non-static member function is considered
2952 to be different, for the purposes of substitution, from the type of a
2953 namespace-scope or static member function whose type appears
2954 similar. The types of two non-static member functions are considered
2955 to be different, for the purposes of substitution, if the functions
2956 are members of different classes. In other words, for the purposes of
2957 substitution, the class of which the function is a member is
2958 considered part of the type of function."
2960 For a pointer to member function, this call to cplus_demangle_type
2961 will end up adding a (possibly qualified) non-member function type to
2962 the substitution table, which is not correct; however, the member
2963 function type will never be used in a substitution, so putting the
2964 wrong type in the substitution table is harmless. */
2966 mem
= cplus_demangle_type (di
);
2970 return d_make_comp (di
, DEMANGLE_COMPONENT_PTRMEM_TYPE
, cl
, mem
);
2973 /* <non-negative number> _ */
2976 d_compact_number (struct d_info
*di
)
2979 if (d_peek_char (di
) == '_')
2981 else if (d_peek_char (di
) == 'n')
2984 num
= d_number (di
) + 1;
2986 if (num
< 0 || ! d_check_char (di
, '_'))
2991 /* <template-param> ::= T_
2992 ::= T <(parameter-2 non-negative) number> _
2995 static struct demangle_component
*
2996 d_template_param (struct d_info
*di
)
3000 if (! d_check_char (di
, 'T'))
3003 param
= d_compact_number (di
);
3009 return d_make_template_param (di
, param
);
3012 /* <template-args> ::= I <template-arg>+ E */
3014 static struct demangle_component
*
3015 d_template_args (struct d_info
*di
)
3017 if (d_peek_char (di
) != 'I'
3018 && d_peek_char (di
) != 'J')
3022 return d_template_args_1 (di
);
3025 /* <template-arg>* E */
3027 static struct demangle_component
*
3028 d_template_args_1 (struct d_info
*di
)
3030 struct demangle_component
*hold_last_name
;
3031 struct demangle_component
*al
;
3032 struct demangle_component
**pal
;
3034 /* Preserve the last name we saw--don't let the template arguments
3035 clobber it, as that would give us the wrong name for a subsequent
3036 constructor or destructor. */
3037 hold_last_name
= di
->last_name
;
3039 if (d_peek_char (di
) == 'E')
3041 /* An argument pack can be empty. */
3043 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, NULL
, NULL
);
3050 struct demangle_component
*a
;
3052 a
= d_template_arg (di
);
3056 *pal
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
, a
, NULL
);
3059 pal
= &d_right (*pal
);
3061 if (d_peek_char (di
) == 'E')
3068 di
->last_name
= hold_last_name
;
3073 /* <template-arg> ::= <type>
3074 ::= X <expression> E
3078 static struct demangle_component
*
3079 d_template_arg (struct d_info
*di
)
3081 struct demangle_component
*ret
;
3083 switch (d_peek_char (di
))
3087 ret
= d_expression (di
);
3088 if (! d_check_char (di
, 'E'))
3093 return d_expr_primary (di
);
3097 /* An argument pack. */
3098 return d_template_args (di
);
3101 return cplus_demangle_type (di
);
3105 /* Parse a sequence of expressions until we hit the terminator
3108 static struct demangle_component
*
3109 d_exprlist (struct d_info
*di
, char terminator
)
3111 struct demangle_component
*list
= NULL
;
3112 struct demangle_component
**p
= &list
;
3114 if (d_peek_char (di
) == terminator
)
3117 return d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, NULL
, NULL
);
3122 struct demangle_component
*arg
= d_expression (di
);
3126 *p
= d_make_comp (di
, DEMANGLE_COMPONENT_ARGLIST
, arg
, NULL
);
3131 if (d_peek_char (di
) == terminator
)
3141 /* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
3142 dynamic_cast, static_cast or reinterpret_cast. */
3145 op_is_new_cast (struct demangle_component
*op
)
3147 const char *code
= op
->u
.s_operator
.op
->code
;
3148 return (code
[1] == 'c'
3149 && (code
[0] == 's' || code
[0] == 'd'
3150 || code
[0] == 'c' || code
[0] == 'r'));
3153 /* <expression> ::= <(unary) operator-name> <expression>
3154 ::= <(binary) operator-name> <expression> <expression>
3155 ::= <(trinary) operator-name> <expression> <expression> <expression>
3156 ::= cl <expression>+ E
3158 ::= <template-param>
3159 ::= sr <type> <unqualified-name>
3160 ::= sr <type> <unqualified-name> <template-args>
3164 static inline struct demangle_component
*
3165 d_expression_1 (struct d_info
*di
)
3169 peek
= d_peek_char (di
);
3171 return d_expr_primary (di
);
3172 else if (peek
== 'T')
3173 return d_template_param (di
);
3174 else if (peek
== 's' && d_peek_next_char (di
) == 'r')
3176 struct demangle_component
*type
;
3177 struct demangle_component
*name
;
3180 type
= cplus_demangle_type (di
);
3181 name
= d_unqualified_name (di
);
3182 if (d_peek_char (di
) != 'I')
3183 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
, name
);
3185 return d_make_comp (di
, DEMANGLE_COMPONENT_QUAL_NAME
, type
,
3186 d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3187 d_template_args (di
)));
3189 else if (peek
== 's' && d_peek_next_char (di
) == 'p')
3192 return d_make_comp (di
, DEMANGLE_COMPONENT_PACK_EXPANSION
,
3193 d_expression_1 (di
), NULL
);
3195 else if (peek
== 'f' && d_peek_next_char (di
) == 'p')
3197 /* Function parameter used in a late-specified return type. */
3200 if (d_peek_char (di
) == 'T')
3202 /* 'this' parameter. */
3208 index
= d_compact_number (di
);
3209 if (index
== INT_MAX
|| index
== -1)
3213 return d_make_function_param (di
, index
);
3215 else if (IS_DIGIT (peek
)
3216 || (peek
== 'o' && d_peek_next_char (di
) == 'n'))
3218 /* We can get an unqualified name as an expression in the case of
3219 a dependent function call, i.e. decltype(f(t)). */
3220 struct demangle_component
*name
;
3223 /* operator-function-id, i.e. operator+(t). */
3226 name
= d_unqualified_name (di
);
3229 if (d_peek_char (di
) == 'I')
3230 return d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
, name
,
3231 d_template_args (di
));
3235 else if ((peek
== 'i' || peek
== 't')
3236 && d_peek_next_char (di
) == 'l')
3238 /* Brace-enclosed initializer list, untyped or typed. */
3239 struct demangle_component
*type
= NULL
;
3241 type
= cplus_demangle_type (di
);
3242 if (!d_peek_next_char (di
))
3245 return d_make_comp (di
, DEMANGLE_COMPONENT_INITIALIZER_LIST
,
3246 type
, d_exprlist (di
, 'E'));
3250 struct demangle_component
*op
;
3251 const char *code
= NULL
;
3254 op
= d_operator_name (di
);
3258 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
3260 code
= op
->u
.s_operator
.op
->code
;
3261 di
->expansion
+= op
->u
.s_operator
.op
->len
- 2;
3262 if (strcmp (code
, "st") == 0)
3263 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3264 cplus_demangle_type (di
));
3271 case DEMANGLE_COMPONENT_OPERATOR
:
3272 args
= op
->u
.s_operator
.op
->args
;
3274 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
3275 args
= op
->u
.s_extended_operator
.args
;
3277 case DEMANGLE_COMPONENT_CAST
:
3285 return d_make_comp (di
, DEMANGLE_COMPONENT_NULLARY
, op
, NULL
);
3289 struct demangle_component
*operand
;
3292 if (code
&& (code
[0] == 'p' || code
[0] == 'm')
3293 && code
[1] == code
[0])
3294 /* pp_ and mm_ are the prefix variants. */
3295 suffix
= !d_check_char (di
, '_');
3297 if (op
->type
== DEMANGLE_COMPONENT_CAST
3298 && d_check_char (di
, '_'))
3299 operand
= d_exprlist (di
, 'E');
3300 else if (code
&& !strcmp (code
, "sP"))
3301 operand
= d_template_args_1 (di
);
3303 operand
= d_expression_1 (di
);
3306 /* Indicate the suffix variant for d_print_comp. */
3307 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3309 DEMANGLE_COMPONENT_BINARY_ARGS
,
3312 return d_make_comp (di
, DEMANGLE_COMPONENT_UNARY
, op
,
3317 struct demangle_component
*left
;
3318 struct demangle_component
*right
;
3322 if (op_is_new_cast (op
))
3323 left
= cplus_demangle_type (di
);
3324 else if (code
[0] == 'f')
3325 /* fold-expression. */
3326 left
= d_operator_name (di
);
3328 left
= d_expression_1 (di
);
3329 if (!strcmp (code
, "cl"))
3330 right
= d_exprlist (di
, 'E');
3331 else if (!strcmp (code
, "dt") || !strcmp (code
, "pt"))
3333 right
= d_unqualified_name (di
);
3334 if (d_peek_char (di
) == 'I')
3335 right
= d_make_comp (di
, DEMANGLE_COMPONENT_TEMPLATE
,
3336 right
, d_template_args (di
));
3339 right
= d_expression_1 (di
);
3341 return d_make_comp (di
, DEMANGLE_COMPONENT_BINARY
, op
,
3343 DEMANGLE_COMPONENT_BINARY_ARGS
,
3348 struct demangle_component
*first
;
3349 struct demangle_component
*second
;
3350 struct demangle_component
*third
;
3354 else if (!strcmp (code
, "qu"))
3356 /* ?: expression. */
3357 first
= d_expression_1 (di
);
3358 second
= d_expression_1 (di
);
3359 third
= d_expression_1 (di
);
3361 else if (code
[0] == 'f')
3363 /* fold-expression. */
3364 first
= d_operator_name (di
);
3365 second
= d_expression_1 (di
);
3366 third
= d_expression_1 (di
);
3368 else if (code
[0] == 'n')
3370 /* new-expression. */
3371 if (code
[1] != 'w' && code
[1] != 'a')
3373 first
= d_exprlist (di
, '_');
3374 second
= cplus_demangle_type (di
);
3375 if (d_peek_char (di
) == 'E')
3380 else if (d_peek_char (di
) == 'p'
3381 && d_peek_next_char (di
) == 'i')
3383 /* Parenthesized initializer. */
3385 third
= d_exprlist (di
, 'E');
3387 else if (d_peek_char (di
) == 'i'
3388 && d_peek_next_char (di
) == 'l')
3389 /* initializer-list. */
3390 third
= d_expression_1 (di
);
3396 return d_make_comp (di
, DEMANGLE_COMPONENT_TRINARY
, op
,
3398 DEMANGLE_COMPONENT_TRINARY_ARG1
,
3401 DEMANGLE_COMPONENT_TRINARY_ARG2
,
3410 static struct demangle_component
*
3411 d_expression (struct d_info
*di
)
3413 struct demangle_component
*ret
;
3414 int was_expression
= di
->is_expression
;
3416 di
->is_expression
= 1;
3417 ret
= d_expression_1 (di
);
3418 di
->is_expression
= was_expression
;
3422 /* <expr-primary> ::= L <type> <(value) number> E
3423 ::= L <type> <(value) float> E
3424 ::= L <mangled-name> E
3427 static struct demangle_component
*
3428 d_expr_primary (struct d_info
*di
)
3430 struct demangle_component
*ret
;
3432 if (! d_check_char (di
, 'L'))
3434 if (d_peek_char (di
) == '_'
3435 /* Workaround for G++ bug; see comment in write_template_arg. */
3436 || d_peek_char (di
) == 'Z')
3437 ret
= cplus_demangle_mangled_name (di
, 0);
3440 struct demangle_component
*type
;
3441 enum demangle_component_type t
;
3444 type
= cplus_demangle_type (di
);
3448 /* If we have a type we know how to print, we aren't going to
3449 print the type name itself. */
3450 if (type
->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
3451 && type
->u
.s_builtin
.type
->print
!= D_PRINT_DEFAULT
)
3452 di
->expansion
-= type
->u
.s_builtin
.type
->len
;
3454 /* Rather than try to interpret the literal value, we just
3455 collect it as a string. Note that it's possible to have a
3456 floating point literal here. The ABI specifies that the
3457 format of such literals is machine independent. That's fine,
3458 but what's not fine is that versions of g++ up to 3.2 with
3459 -fabi-version=1 used upper case letters in the hex constant,
3460 and dumped out gcc's internal representation. That makes it
3461 hard to tell where the constant ends, and hard to dump the
3462 constant in any readable form anyhow. We don't attempt to
3463 handle these cases. */
3465 t
= DEMANGLE_COMPONENT_LITERAL
;
3466 if (d_peek_char (di
) == 'n')
3468 t
= DEMANGLE_COMPONENT_LITERAL_NEG
;
3472 while (d_peek_char (di
) != 'E')
3474 if (d_peek_char (di
) == '\0')
3478 ret
= d_make_comp (di
, t
, type
, d_make_name (di
, s
, d_str (di
) - s
));
3480 if (! d_check_char (di
, 'E'))
3485 /* <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
3486 ::= Z <(function) encoding> E s [<discriminator>]
3487 ::= Z <(function) encoding> E d [<parameter> number>] _ <entity name>
3490 static struct demangle_component
*
3491 d_local_name (struct d_info
*di
)
3493 struct demangle_component
*function
;
3495 if (! d_check_char (di
, 'Z'))
3498 function
= d_encoding (di
, 0);
3500 if (! d_check_char (di
, 'E'))
3503 if (d_peek_char (di
) == 's')
3506 if (! d_discriminator (di
))
3508 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
,
3509 d_make_name (di
, "string literal",
3510 sizeof "string literal" - 1));
3514 struct demangle_component
*name
;
3517 if (d_peek_char (di
) == 'd')
3519 /* Default argument scope: d <number> _. */
3521 num
= d_compact_number (di
);
3530 /* Lambdas and unnamed types have internal discriminators. */
3531 case DEMANGLE_COMPONENT_LAMBDA
:
3532 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3535 if (! d_discriminator (di
))
3539 name
= d_make_default_arg (di
, num
, name
);
3540 return d_make_comp (di
, DEMANGLE_COMPONENT_LOCAL_NAME
, function
, name
);
3544 /* <discriminator> ::= _ <(non-negative) number>
3546 We demangle the discriminator, but we don't print it out. FIXME:
3547 We should print it out in verbose mode. */
3550 d_discriminator (struct d_info
*di
)
3554 if (d_peek_char (di
) != '_')
3557 discrim
= d_number (di
);
3563 /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3565 static struct demangle_component
*
3566 d_lambda (struct d_info
*di
)
3568 struct demangle_component
*tl
;
3569 struct demangle_component
*ret
;
3572 if (! d_check_char (di
, 'U'))
3574 if (! d_check_char (di
, 'l'))
3577 tl
= d_parmlist (di
);
3581 if (! d_check_char (di
, 'E'))
3584 num
= d_compact_number (di
);
3588 ret
= d_make_empty (di
);
3591 ret
->type
= DEMANGLE_COMPONENT_LAMBDA
;
3592 ret
->u
.s_unary_num
.sub
= tl
;
3593 ret
->u
.s_unary_num
.num
= num
;
3596 if (! d_add_substitution (di
, ret
))
3602 /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
3604 static struct demangle_component
*
3605 d_unnamed_type (struct d_info
*di
)
3607 struct demangle_component
*ret
;
3610 if (! d_check_char (di
, 'U'))
3612 if (! d_check_char (di
, 't'))
3615 num
= d_compact_number (di
);
3619 ret
= d_make_empty (di
);
3622 ret
->type
= DEMANGLE_COMPONENT_UNNAMED_TYPE
;
3623 ret
->u
.s_number
.number
= num
;
3626 if (! d_add_substitution (di
, ret
))
3632 /* <clone-suffix> ::= [ . <clone-type-identifier> ] [ . <nonnegative number> ]*
3635 static struct demangle_component
*
3636 d_clone_suffix (struct d_info
*di
, struct demangle_component
*encoding
)
3638 const char *suffix
= d_str (di
);
3639 const char *pend
= suffix
;
3640 struct demangle_component
*n
;
3642 if (*pend
== '.' && (IS_LOWER (pend
[1]) || pend
[1] == '_'))
3645 while (IS_LOWER (*pend
) || *pend
== '_')
3648 while (*pend
== '.' && IS_DIGIT (pend
[1]))
3651 while (IS_DIGIT (*pend
))
3654 d_advance (di
, pend
- suffix
);
3655 n
= d_make_name (di
, suffix
, pend
- suffix
);
3656 return d_make_comp (di
, DEMANGLE_COMPONENT_CLONE
, encoding
, n
);
3659 /* Add a new substitution. */
3662 d_add_substitution (struct d_info
*di
, struct demangle_component
*dc
)
3666 if (di
->next_sub
>= di
->num_subs
)
3668 di
->subs
[di
->next_sub
] = dc
;
3673 /* <substitution> ::= S <seq-id> _
3683 If PREFIX is non-zero, then this type is being used as a prefix in
3684 a qualified name. In this case, for the standard substitutions, we
3685 need to check whether we are being used as a prefix for a
3686 constructor or destructor, and return a full template name.
3687 Otherwise we will get something like std::iostream::~iostream()
3688 which does not correspond particularly well to any function which
3689 actually appears in the source.
3692 static const struct d_standard_sub_info standard_subs
[] =
3697 { 'a', NL ("std::allocator"),
3698 NL ("std::allocator"),
3700 { 'b', NL ("std::basic_string"),
3701 NL ("std::basic_string"),
3702 NL ("basic_string") },
3703 { 's', NL ("std::string"),
3704 NL ("std::basic_string<char, std::char_traits<char>, std::allocator<char> >"),
3705 NL ("basic_string") },
3706 { 'i', NL ("std::istream"),
3707 NL ("std::basic_istream<char, std::char_traits<char> >"),
3708 NL ("basic_istream") },
3709 { 'o', NL ("std::ostream"),
3710 NL ("std::basic_ostream<char, std::char_traits<char> >"),
3711 NL ("basic_ostream") },
3712 { 'd', NL ("std::iostream"),
3713 NL ("std::basic_iostream<char, std::char_traits<char> >"),
3714 NL ("basic_iostream") }
3717 static struct demangle_component
*
3718 d_substitution (struct d_info
*di
, int prefix
)
3722 if (! d_check_char (di
, 'S'))
3725 c
= d_next_char (di
);
3726 if (c
== '_' || IS_DIGIT (c
) || IS_UPPER (c
))
3735 unsigned int new_id
;
3738 new_id
= id
* 36 + c
- '0';
3739 else if (IS_UPPER (c
))
3740 new_id
= id
* 36 + c
- 'A' + 10;
3746 c
= d_next_char (di
);
3753 if (id
>= (unsigned int) di
->next_sub
)
3758 return di
->subs
[id
];
3763 const struct d_standard_sub_info
*p
;
3764 const struct d_standard_sub_info
*pend
;
3766 verbose
= (di
->options
& DMGL_VERBOSE
) != 0;
3767 if (! verbose
&& prefix
)
3771 peek
= d_peek_char (di
);
3772 if (peek
== 'C' || peek
== 'D')
3776 pend
= (&standard_subs
[0]
3777 + sizeof standard_subs
/ sizeof standard_subs
[0]);
3778 for (p
= &standard_subs
[0]; p
< pend
; ++p
)
3784 struct demangle_component
*dc
;
3786 if (p
->set_last_name
!= NULL
)
3787 di
->last_name
= d_make_sub (di
, p
->set_last_name
,
3788 p
->set_last_name_len
);
3791 s
= p
->full_expansion
;
3796 s
= p
->simple_expansion
;
3797 len
= p
->simple_len
;
3799 di
->expansion
+= len
;
3800 dc
= d_make_sub (di
, s
, len
);
3801 if (d_peek_char (di
) == 'B')
3803 /* If there are ABI tags on the abbreviation, it becomes
3804 a substitution candidate. */
3805 dc
= d_abi_tags (di
, dc
);
3806 d_add_substitution (di
, dc
);
3817 d_checkpoint (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3819 checkpoint
->n
= di
->n
;
3820 checkpoint
->next_comp
= di
->next_comp
;
3821 checkpoint
->next_sub
= di
->next_sub
;
3822 checkpoint
->did_subs
= di
->did_subs
;
3823 checkpoint
->expansion
= di
->expansion
;
3827 d_backtrack (struct d_info
*di
, struct d_info_checkpoint
*checkpoint
)
3829 di
->n
= checkpoint
->n
;
3830 di
->next_comp
= checkpoint
->next_comp
;
3831 di
->next_sub
= checkpoint
->next_sub
;
3832 di
->did_subs
= checkpoint
->did_subs
;
3833 di
->expansion
= checkpoint
->expansion
;
3836 /* Initialize a growable string. */
3839 d_growable_string_init (struct d_growable_string
*dgs
, size_t estimate
)
3844 dgs
->allocation_failure
= 0;
3847 d_growable_string_resize (dgs
, estimate
);
3850 /* Grow a growable string to a given size. */
3853 d_growable_string_resize (struct d_growable_string
*dgs
, size_t need
)
3858 if (dgs
->allocation_failure
)
3861 /* Start allocation at two bytes to avoid any possibility of confusion
3862 with the special value of 1 used as a return in *palc to indicate
3863 allocation failures. */
3864 newalc
= dgs
->alc
> 0 ? dgs
->alc
: 2;
3865 while (newalc
< need
)
3868 newbuf
= (char *) realloc (dgs
->buf
, newalc
);
3875 dgs
->allocation_failure
= 1;
3882 /* Append a buffer to a growable string. */
3885 d_growable_string_append_buffer (struct d_growable_string
*dgs
,
3886 const char *s
, size_t l
)
3890 need
= dgs
->len
+ l
+ 1;
3891 if (need
> dgs
->alc
)
3892 d_growable_string_resize (dgs
, need
);
3894 if (dgs
->allocation_failure
)
3897 memcpy (dgs
->buf
+ dgs
->len
, s
, l
);
3898 dgs
->buf
[dgs
->len
+ l
] = '\0';
3902 /* Bridge growable strings to the callback mechanism. */
3905 d_growable_string_callback_adapter (const char *s
, size_t l
, void *opaque
)
3907 struct d_growable_string
*dgs
= (struct d_growable_string
*) opaque
;
3909 d_growable_string_append_buffer (dgs
, s
, l
);
3912 /* Walk the tree, counting the number of templates encountered, and
3913 the number of times a scope might be saved. These counts will be
3914 used to allocate data structures for d_print_comp, so the logic
3915 here must mirror the logic d_print_comp will use. It is not
3916 important that the resulting numbers are exact, so long as they
3917 are larger than the actual numbers encountered. */
3920 d_count_templates_scopes (int *num_templates
, int *num_scopes
,
3921 const struct demangle_component
*dc
)
3928 case DEMANGLE_COMPONENT_NAME
:
3929 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
3930 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
3931 case DEMANGLE_COMPONENT_SUB_STD
:
3932 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
3933 case DEMANGLE_COMPONENT_OPERATOR
:
3934 case DEMANGLE_COMPONENT_CHARACTER
:
3935 case DEMANGLE_COMPONENT_NUMBER
:
3936 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
3939 case DEMANGLE_COMPONENT_TEMPLATE
:
3941 goto recurse_left_right
;
3943 case DEMANGLE_COMPONENT_REFERENCE
:
3944 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
3945 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
3947 goto recurse_left_right
;
3949 case DEMANGLE_COMPONENT_QUAL_NAME
:
3950 case DEMANGLE_COMPONENT_LOCAL_NAME
:
3951 case DEMANGLE_COMPONENT_TYPED_NAME
:
3952 case DEMANGLE_COMPONENT_VTABLE
:
3953 case DEMANGLE_COMPONENT_VTT
:
3954 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
3955 case DEMANGLE_COMPONENT_TYPEINFO
:
3956 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
3957 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
3958 case DEMANGLE_COMPONENT_THUNK
:
3959 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
3960 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
3961 case DEMANGLE_COMPONENT_JAVA_CLASS
:
3962 case DEMANGLE_COMPONENT_GUARD
:
3963 case DEMANGLE_COMPONENT_TLS_INIT
:
3964 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
3965 case DEMANGLE_COMPONENT_REFTEMP
:
3966 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
3967 case DEMANGLE_COMPONENT_RESTRICT
:
3968 case DEMANGLE_COMPONENT_VOLATILE
:
3969 case DEMANGLE_COMPONENT_CONST
:
3970 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
3971 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
3972 case DEMANGLE_COMPONENT_CONST_THIS
:
3973 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
3974 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
3975 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
3976 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
3977 case DEMANGLE_COMPONENT_POINTER
:
3978 case DEMANGLE_COMPONENT_COMPLEX
:
3979 case DEMANGLE_COMPONENT_IMAGINARY
:
3980 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
3981 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
3982 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
3983 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
3984 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
3985 case DEMANGLE_COMPONENT_ARGLIST
:
3986 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
3987 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
3988 case DEMANGLE_COMPONENT_CAST
:
3989 case DEMANGLE_COMPONENT_CONVERSION
:
3990 case DEMANGLE_COMPONENT_NULLARY
:
3991 case DEMANGLE_COMPONENT_UNARY
:
3992 case DEMANGLE_COMPONENT_BINARY
:
3993 case DEMANGLE_COMPONENT_BINARY_ARGS
:
3994 case DEMANGLE_COMPONENT_TRINARY
:
3995 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
3996 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
3997 case DEMANGLE_COMPONENT_LITERAL
:
3998 case DEMANGLE_COMPONENT_LITERAL_NEG
:
3999 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
4000 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
4001 case DEMANGLE_COMPONENT_DECLTYPE
:
4002 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4003 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4004 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4005 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4006 case DEMANGLE_COMPONENT_CLONE
:
4008 d_count_templates_scopes (num_templates
, num_scopes
,
4010 d_count_templates_scopes (num_templates
, num_scopes
,
4014 case DEMANGLE_COMPONENT_CTOR
:
4015 d_count_templates_scopes (num_templates
, num_scopes
,
4019 case DEMANGLE_COMPONENT_DTOR
:
4020 d_count_templates_scopes (num_templates
, num_scopes
,
4024 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4025 d_count_templates_scopes (num_templates
, num_scopes
,
4026 dc
->u
.s_extended_operator
.name
);
4029 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4030 d_count_templates_scopes (num_templates
, num_scopes
,
4031 dc
->u
.s_fixed
.length
);
4034 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
4035 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
4036 d_count_templates_scopes (num_templates
, num_scopes
,
4040 case DEMANGLE_COMPONENT_LAMBDA
:
4041 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4042 d_count_templates_scopes (num_templates
, num_scopes
,
4043 dc
->u
.s_unary_num
.sub
);
4048 /* Initialize a print information structure. */
4051 d_print_init (struct d_print_info
*dpi
, demangle_callbackref callback
,
4052 void *opaque
, const struct demangle_component
*dc
)
4055 dpi
->last_char
= '\0';
4056 dpi
->templates
= NULL
;
4057 dpi
->modifiers
= NULL
;
4058 dpi
->pack_index
= 0;
4059 dpi
->flush_count
= 0;
4061 dpi
->callback
= callback
;
4062 dpi
->opaque
= opaque
;
4064 dpi
->demangle_failure
= 0;
4066 dpi
->component_stack
= NULL
;
4068 dpi
->saved_scopes
= NULL
;
4069 dpi
->next_saved_scope
= 0;
4070 dpi
->num_saved_scopes
= 0;
4072 dpi
->copy_templates
= NULL
;
4073 dpi
->next_copy_template
= 0;
4074 dpi
->num_copy_templates
= 0;
4076 d_count_templates_scopes (&dpi
->num_copy_templates
,
4077 &dpi
->num_saved_scopes
, dc
);
4078 dpi
->num_copy_templates
*= dpi
->num_saved_scopes
;
4080 dpi
->current_template
= NULL
;
4083 /* Indicate that an error occurred during printing, and test for error. */
4086 d_print_error (struct d_print_info
*dpi
)
4088 dpi
->demangle_failure
= 1;
4092 d_print_saw_error (struct d_print_info
*dpi
)
4094 return dpi
->demangle_failure
!= 0;
4097 /* Flush buffered characters to the callback. */
4100 d_print_flush (struct d_print_info
*dpi
)
4102 dpi
->buf
[dpi
->len
] = '\0';
4103 dpi
->callback (dpi
->buf
, dpi
->len
, dpi
->opaque
);
4108 /* Append characters and buffers for printing. */
4111 d_append_char (struct d_print_info
*dpi
, char c
)
4113 if (dpi
->len
== sizeof (dpi
->buf
) - 1)
4114 d_print_flush (dpi
);
4116 dpi
->buf
[dpi
->len
++] = c
;
4121 d_append_buffer (struct d_print_info
*dpi
, const char *s
, size_t l
)
4125 for (i
= 0; i
< l
; i
++)
4126 d_append_char (dpi
, s
[i
]);
4130 d_append_string (struct d_print_info
*dpi
, const char *s
)
4132 d_append_buffer (dpi
, s
, strlen (s
));
4136 d_append_num (struct d_print_info
*dpi
, int l
)
4139 sprintf (buf
,"%d", l
);
4140 d_append_string (dpi
, buf
);
4144 d_last_char (struct d_print_info
*dpi
)
4146 return dpi
->last_char
;
4149 /* Turn components into a human readable string. OPTIONS is the
4150 options bits passed to the demangler. DC is the tree to print.
4151 CALLBACK is a function to call to flush demangled string segments
4152 as they fill the intermediate buffer, and OPAQUE is a generalized
4153 callback argument. On success, this returns 1. On failure,
4154 it returns 0, indicating a bad parse. It does not use heap
4155 memory to build an output string, so cannot encounter memory
4156 allocation failure. */
4158 CP_STATIC_IF_GLIBCPP_V3
4160 cplus_demangle_print_callback (int options
,
4161 const struct demangle_component
*dc
,
4162 demangle_callbackref callback
, void *opaque
)
4164 struct d_print_info dpi
;
4166 d_print_init (&dpi
, callback
, opaque
, dc
);
4169 #ifdef CP_DYNAMIC_ARRAYS
4170 /* Avoid zero-length VLAs, which are prohibited by the C99 standard
4171 and flagged as errors by Address Sanitizer. */
4172 __extension__
struct d_saved_scope scopes
[(dpi
.num_saved_scopes
> 0)
4173 ? dpi
.num_saved_scopes
: 1];
4174 __extension__
struct d_print_template temps
[(dpi
.num_copy_templates
> 0)
4175 ? dpi
.num_copy_templates
: 1];
4177 dpi
.saved_scopes
= scopes
;
4178 dpi
.copy_templates
= temps
;
4180 dpi
.saved_scopes
= alloca (dpi
.num_saved_scopes
4181 * sizeof (*dpi
.saved_scopes
));
4182 dpi
.copy_templates
= alloca (dpi
.num_copy_templates
4183 * sizeof (*dpi
.copy_templates
));
4186 d_print_comp (&dpi
, options
, dc
);
4189 d_print_flush (&dpi
);
4191 return ! d_print_saw_error (&dpi
);
4194 /* Turn components into a human readable string. OPTIONS is the
4195 options bits passed to the demangler. DC is the tree to print.
4196 ESTIMATE is a guess at the length of the result. This returns a
4197 string allocated by malloc, or NULL on error. On success, this
4198 sets *PALC to the size of the allocated buffer. On failure, this
4199 sets *PALC to 0 for a bad parse, or to 1 for a memory allocation
4202 CP_STATIC_IF_GLIBCPP_V3
4204 cplus_demangle_print (int options
, const struct demangle_component
*dc
,
4205 int estimate
, size_t *palc
)
4207 struct d_growable_string dgs
;
4209 d_growable_string_init (&dgs
, estimate
);
4211 if (! cplus_demangle_print_callback (options
, dc
,
4212 d_growable_string_callback_adapter
,
4220 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
4224 /* Returns the I'th element of the template arglist ARGS, or NULL on
4225 failure. If I is negative, return the entire arglist. */
4227 static struct demangle_component
*
4228 d_index_template_argument (struct demangle_component
*args
, int i
)
4230 struct demangle_component
*a
;
4233 /* Print the whole argument pack. */
4240 if (a
->type
!= DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4246 if (i
!= 0 || a
== NULL
)
4252 /* Returns the template argument from the current context indicated by DC,
4253 which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
4255 static struct demangle_component
*
4256 d_lookup_template_argument (struct d_print_info
*dpi
,
4257 const struct demangle_component
*dc
)
4259 if (dpi
->templates
== NULL
)
4261 d_print_error (dpi
);
4265 return d_index_template_argument
4266 (d_right (dpi
->templates
->template_decl
),
4267 dc
->u
.s_number
.number
);
4270 /* Returns a template argument pack used in DC (any will do), or NULL. */
4272 static struct demangle_component
*
4273 d_find_pack (struct d_print_info
*dpi
,
4274 const struct demangle_component
*dc
)
4276 struct demangle_component
*a
;
4282 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4283 a
= d_lookup_template_argument (dpi
, dc
);
4284 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4288 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
4291 case DEMANGLE_COMPONENT_LAMBDA
:
4292 case DEMANGLE_COMPONENT_NAME
:
4293 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4294 case DEMANGLE_COMPONENT_OPERATOR
:
4295 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
4296 case DEMANGLE_COMPONENT_SUB_STD
:
4297 case DEMANGLE_COMPONENT_CHARACTER
:
4298 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
4299 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
4300 case DEMANGLE_COMPONENT_FIXED_TYPE
:
4301 case DEMANGLE_COMPONENT_DEFAULT_ARG
:
4302 case DEMANGLE_COMPONENT_NUMBER
:
4305 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
4306 return d_find_pack (dpi
, dc
->u
.s_extended_operator
.name
);
4307 case DEMANGLE_COMPONENT_CTOR
:
4308 return d_find_pack (dpi
, dc
->u
.s_ctor
.name
);
4309 case DEMANGLE_COMPONENT_DTOR
:
4310 return d_find_pack (dpi
, dc
->u
.s_dtor
.name
);
4313 a
= d_find_pack (dpi
, d_left (dc
));
4316 return d_find_pack (dpi
, d_right (dc
));
4320 /* Returns the length of the template argument pack DC. */
4323 d_pack_length (const struct demangle_component
*dc
)
4326 while (dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
4327 && d_left (dc
) != NULL
)
4335 /* Returns the number of template args in DC, expanding any pack expansions
4339 d_args_length (struct d_print_info
*dpi
, const struct demangle_component
*dc
)
4342 for (; dc
&& dc
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
;
4345 struct demangle_component
*elt
= d_left (dc
);
4348 if (elt
->type
== DEMANGLE_COMPONENT_PACK_EXPANSION
)
4350 struct demangle_component
*a
= d_find_pack (dpi
, d_left (elt
));
4351 count
+= d_pack_length (a
);
4359 /* DC is a component of a mangled expression. Print it, wrapped in parens
4363 d_print_subexpr (struct d_print_info
*dpi
, int options
,
4364 const struct demangle_component
*dc
)
4367 if (dc
->type
== DEMANGLE_COMPONENT_NAME
4368 || dc
->type
== DEMANGLE_COMPONENT_QUAL_NAME
4369 || dc
->type
== DEMANGLE_COMPONENT_INITIALIZER_LIST
4370 || dc
->type
== DEMANGLE_COMPONENT_FUNCTION_PARAM
)
4373 d_append_char (dpi
, '(');
4374 d_print_comp (dpi
, options
, dc
);
4376 d_append_char (dpi
, ')');
4379 /* Save the current scope. */
4382 d_save_scope (struct d_print_info
*dpi
,
4383 const struct demangle_component
*container
)
4385 struct d_saved_scope
*scope
;
4386 struct d_print_template
*src
, **link
;
4388 if (dpi
->next_saved_scope
>= dpi
->num_saved_scopes
)
4390 d_print_error (dpi
);
4393 scope
= &dpi
->saved_scopes
[dpi
->next_saved_scope
];
4394 dpi
->next_saved_scope
++;
4396 scope
->container
= container
;
4397 link
= &scope
->templates
;
4399 for (src
= dpi
->templates
; src
!= NULL
; src
= src
->next
)
4401 struct d_print_template
*dst
;
4403 if (dpi
->next_copy_template
>= dpi
->num_copy_templates
)
4405 d_print_error (dpi
);
4408 dst
= &dpi
->copy_templates
[dpi
->next_copy_template
];
4409 dpi
->next_copy_template
++;
4411 dst
->template_decl
= src
->template_decl
;
4419 /* Attempt to locate a previously saved scope. Returns NULL if no
4420 corresponding saved scope was found. */
4422 static struct d_saved_scope
*
4423 d_get_saved_scope (struct d_print_info
*dpi
,
4424 const struct demangle_component
*container
)
4428 for (i
= 0; i
< dpi
->next_saved_scope
; i
++)
4429 if (dpi
->saved_scopes
[i
].container
== container
)
4430 return &dpi
->saved_scopes
[i
];
4435 /* If DC is a C++17 fold-expression, print it and return true; otherwise
4439 d_maybe_print_fold_expression (struct d_print_info
*dpi
, int options
,
4440 const struct demangle_component
*dc
)
4442 const struct demangle_component
*ops
, *operator_
, *op1
, *op2
;
4445 const char *fold_code
= d_left (dc
)->u
.s_operator
.op
->code
;
4446 if (fold_code
[0] != 'f')
4450 operator_
= d_left (ops
);
4451 op1
= d_right (ops
);
4453 if (op1
->type
== DEMANGLE_COMPONENT_TRINARY_ARG2
)
4455 op2
= d_right (op1
);
4459 /* Print the whole pack. */
4460 save_idx
= dpi
->pack_index
;
4461 dpi
->pack_index
= -1;
4463 switch (fold_code
[1])
4465 /* Unary left fold, (... + X). */
4467 d_append_string (dpi
, "(...");
4468 d_print_expr_op (dpi
, options
, operator_
);
4469 d_print_subexpr (dpi
, options
, op1
);
4470 d_append_char (dpi
, ')');
4473 /* Unary right fold, (X + ...). */
4475 d_append_char (dpi
, '(');
4476 d_print_subexpr (dpi
, options
, op1
);
4477 d_print_expr_op (dpi
, options
, operator_
);
4478 d_append_string (dpi
, "...)");
4481 /* Binary left fold, (42 + ... + X). */
4483 /* Binary right fold, (X + ... + 42). */
4485 d_append_char (dpi
, '(');
4486 d_print_subexpr (dpi
, options
, op1
);
4487 d_print_expr_op (dpi
, options
, operator_
);
4488 d_append_string (dpi
, "...");
4489 d_print_expr_op (dpi
, options
, operator_
);
4490 d_print_subexpr (dpi
, options
, op2
);
4491 d_append_char (dpi
, ')');
4495 dpi
->pack_index
= save_idx
;
4499 /* Subroutine to handle components. */
4502 d_print_comp_inner (struct d_print_info
*dpi
, int options
,
4503 const struct demangle_component
*dc
)
4505 /* Magic variable to let reference smashing skip over the next modifier
4506 without needing to modify *dc. */
4507 const struct demangle_component
*mod_inner
= NULL
;
4509 /* Variable used to store the current templates while a previously
4510 captured scope is used. */
4511 struct d_print_template
*saved_templates
;
4513 /* Nonzero if templates have been stored in the above variable. */
4514 int need_template_restore
= 0;
4518 d_print_error (dpi
);
4521 if (d_print_saw_error (dpi
))
4526 case DEMANGLE_COMPONENT_NAME
:
4527 if ((options
& DMGL_JAVA
) == 0)
4528 d_append_buffer (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4530 d_print_java_identifier (dpi
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
);
4533 case DEMANGLE_COMPONENT_TAGGED_NAME
:
4534 d_print_comp (dpi
, options
, d_left (dc
));
4535 d_append_string (dpi
, "[abi:");
4536 d_print_comp (dpi
, options
, d_right (dc
));
4537 d_append_char (dpi
, ']');
4540 case DEMANGLE_COMPONENT_QUAL_NAME
:
4541 case DEMANGLE_COMPONENT_LOCAL_NAME
:
4542 d_print_comp (dpi
, options
, d_left (dc
));
4543 if ((options
& DMGL_JAVA
) == 0)
4544 d_append_string (dpi
, "::");
4546 d_append_char (dpi
, '.');
4548 struct demangle_component
*local_name
= d_right (dc
);
4549 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4551 d_append_string (dpi
, "{default arg#");
4552 d_append_num (dpi
, local_name
->u
.s_unary_num
.num
+ 1);
4553 d_append_string (dpi
, "}::");
4554 local_name
= local_name
->u
.s_unary_num
.sub
;
4556 d_print_comp (dpi
, options
, local_name
);
4560 case DEMANGLE_COMPONENT_TYPED_NAME
:
4562 struct d_print_mod
*hold_modifiers
;
4563 struct demangle_component
*typed_name
;
4564 struct d_print_mod adpm
[4];
4566 struct d_print_template dpt
;
4568 /* Pass the name down to the type so that it can be printed in
4569 the right place for the type. We also have to pass down
4570 any CV-qualifiers, which apply to the this parameter. */
4571 hold_modifiers
= dpi
->modifiers
;
4574 typed_name
= d_left (dc
);
4575 while (typed_name
!= NULL
)
4577 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4579 d_print_error (dpi
);
4583 adpm
[i
].next
= dpi
->modifiers
;
4584 dpi
->modifiers
= &adpm
[i
];
4585 adpm
[i
].mod
= typed_name
;
4586 adpm
[i
].printed
= 0;
4587 adpm
[i
].templates
= dpi
->templates
;
4590 if (typed_name
->type
!= DEMANGLE_COMPONENT_RESTRICT_THIS
4591 && typed_name
->type
!= DEMANGLE_COMPONENT_VOLATILE_THIS
4592 && typed_name
->type
!= DEMANGLE_COMPONENT_CONST_THIS
4593 && typed_name
->type
!= DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
4594 && typed_name
->type
!= DEMANGLE_COMPONENT_TRANSACTION_SAFE
4595 && typed_name
->type
!= DEMANGLE_COMPONENT_REFERENCE_THIS
)
4598 typed_name
= d_left (typed_name
);
4601 if (typed_name
== NULL
)
4603 d_print_error (dpi
);
4607 /* If typed_name is a template, then it applies to the
4608 function type as well. */
4609 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4611 dpt
.next
= dpi
->templates
;
4612 dpi
->templates
= &dpt
;
4613 dpt
.template_decl
= typed_name
;
4616 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
4617 there may be CV-qualifiers on its right argument which
4618 really apply here; this happens when parsing a class which
4619 is local to a function. */
4620 if (typed_name
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
4622 struct demangle_component
*local_name
;
4624 local_name
= d_right (typed_name
);
4625 if (local_name
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
4626 local_name
= local_name
->u
.s_unary_num
.sub
;
4627 if (local_name
== NULL
)
4629 d_print_error (dpi
);
4632 while (local_name
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
4633 || local_name
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
4634 || local_name
->type
== DEMANGLE_COMPONENT_CONST_THIS
4635 || local_name
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
4636 || local_name
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
4637 || (local_name
->type
4638 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))
4640 if (i
>= sizeof adpm
/ sizeof adpm
[0])
4642 d_print_error (dpi
);
4646 adpm
[i
] = adpm
[i
- 1];
4647 adpm
[i
].next
= &adpm
[i
- 1];
4648 dpi
->modifiers
= &adpm
[i
];
4650 adpm
[i
- 1].mod
= local_name
;
4651 adpm
[i
- 1].printed
= 0;
4652 adpm
[i
- 1].templates
= dpi
->templates
;
4655 local_name
= d_left (local_name
);
4659 d_print_comp (dpi
, options
, d_right (dc
));
4661 if (typed_name
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
4662 dpi
->templates
= dpt
.next
;
4664 /* If the modifiers didn't get printed by the type, print them
4669 if (! adpm
[i
].printed
)
4671 d_append_char (dpi
, ' ');
4672 d_print_mod (dpi
, options
, adpm
[i
].mod
);
4676 dpi
->modifiers
= hold_modifiers
;
4681 case DEMANGLE_COMPONENT_TEMPLATE
:
4683 struct d_print_mod
*hold_dpm
;
4684 struct demangle_component
*dcl
;
4685 const struct demangle_component
*hold_current
;
4687 /* This template may need to be referenced by a cast operator
4688 contained in its subtree. */
4689 hold_current
= dpi
->current_template
;
4690 dpi
->current_template
= dc
;
4692 /* Don't push modifiers into a template definition. Doing so
4693 could give the wrong definition for a template argument.
4694 Instead, treat the template essentially as a name. */
4696 hold_dpm
= dpi
->modifiers
;
4697 dpi
->modifiers
= NULL
;
4701 if ((options
& DMGL_JAVA
) != 0
4702 && dcl
->type
== DEMANGLE_COMPONENT_NAME
4703 && dcl
->u
.s_name
.len
== 6
4704 && strncmp (dcl
->u
.s_name
.s
, "JArray", 6) == 0)
4706 /* Special-case Java arrays, so that JArray<TYPE> appears
4707 instead as TYPE[]. */
4709 d_print_comp (dpi
, options
, d_right (dc
));
4710 d_append_string (dpi
, "[]");
4714 d_print_comp (dpi
, options
, dcl
);
4715 if (d_last_char (dpi
) == '<')
4716 d_append_char (dpi
, ' ');
4717 d_append_char (dpi
, '<');
4718 d_print_comp (dpi
, options
, d_right (dc
));
4719 /* Avoid generating two consecutive '>' characters, to avoid
4720 the C++ syntactic ambiguity. */
4721 if (d_last_char (dpi
) == '>')
4722 d_append_char (dpi
, ' ');
4723 d_append_char (dpi
, '>');
4726 dpi
->modifiers
= hold_dpm
;
4727 dpi
->current_template
= hold_current
;
4732 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
4734 struct d_print_template
*hold_dpt
;
4735 struct demangle_component
*a
= d_lookup_template_argument (dpi
, dc
);
4737 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4738 a
= d_index_template_argument (a
, dpi
->pack_index
);
4742 d_print_error (dpi
);
4746 /* While processing this parameter, we need to pop the list of
4747 templates. This is because the template parameter may
4748 itself be a reference to a parameter of an outer
4751 hold_dpt
= dpi
->templates
;
4752 dpi
->templates
= hold_dpt
->next
;
4754 d_print_comp (dpi
, options
, a
);
4756 dpi
->templates
= hold_dpt
;
4761 case DEMANGLE_COMPONENT_CTOR
:
4762 d_print_comp (dpi
, options
, dc
->u
.s_ctor
.name
);
4765 case DEMANGLE_COMPONENT_DTOR
:
4766 d_append_char (dpi
, '~');
4767 d_print_comp (dpi
, options
, dc
->u
.s_dtor
.name
);
4770 case DEMANGLE_COMPONENT_VTABLE
:
4771 d_append_string (dpi
, "vtable for ");
4772 d_print_comp (dpi
, options
, d_left (dc
));
4775 case DEMANGLE_COMPONENT_VTT
:
4776 d_append_string (dpi
, "VTT for ");
4777 d_print_comp (dpi
, options
, d_left (dc
));
4780 case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE
:
4781 d_append_string (dpi
, "construction vtable for ");
4782 d_print_comp (dpi
, options
, d_left (dc
));
4783 d_append_string (dpi
, "-in-");
4784 d_print_comp (dpi
, options
, d_right (dc
));
4787 case DEMANGLE_COMPONENT_TYPEINFO
:
4788 d_append_string (dpi
, "typeinfo for ");
4789 d_print_comp (dpi
, options
, d_left (dc
));
4792 case DEMANGLE_COMPONENT_TYPEINFO_NAME
:
4793 d_append_string (dpi
, "typeinfo name for ");
4794 d_print_comp (dpi
, options
, d_left (dc
));
4797 case DEMANGLE_COMPONENT_TYPEINFO_FN
:
4798 d_append_string (dpi
, "typeinfo fn for ");
4799 d_print_comp (dpi
, options
, d_left (dc
));
4802 case DEMANGLE_COMPONENT_THUNK
:
4803 d_append_string (dpi
, "non-virtual thunk to ");
4804 d_print_comp (dpi
, options
, d_left (dc
));
4807 case DEMANGLE_COMPONENT_VIRTUAL_THUNK
:
4808 d_append_string (dpi
, "virtual thunk to ");
4809 d_print_comp (dpi
, options
, d_left (dc
));
4812 case DEMANGLE_COMPONENT_COVARIANT_THUNK
:
4813 d_append_string (dpi
, "covariant return thunk to ");
4814 d_print_comp (dpi
, options
, d_left (dc
));
4817 case DEMANGLE_COMPONENT_JAVA_CLASS
:
4818 d_append_string (dpi
, "java Class for ");
4819 d_print_comp (dpi
, options
, d_left (dc
));
4822 case DEMANGLE_COMPONENT_GUARD
:
4823 d_append_string (dpi
, "guard variable for ");
4824 d_print_comp (dpi
, options
, d_left (dc
));
4827 case DEMANGLE_COMPONENT_TLS_INIT
:
4828 d_append_string (dpi
, "TLS init function for ");
4829 d_print_comp (dpi
, options
, d_left (dc
));
4832 case DEMANGLE_COMPONENT_TLS_WRAPPER
:
4833 d_append_string (dpi
, "TLS wrapper function for ");
4834 d_print_comp (dpi
, options
, d_left (dc
));
4837 case DEMANGLE_COMPONENT_REFTEMP
:
4838 d_append_string (dpi
, "reference temporary #");
4839 d_print_comp (dpi
, options
, d_right (dc
));
4840 d_append_string (dpi
, " for ");
4841 d_print_comp (dpi
, options
, d_left (dc
));
4844 case DEMANGLE_COMPONENT_HIDDEN_ALIAS
:
4845 d_append_string (dpi
, "hidden alias for ");
4846 d_print_comp (dpi
, options
, d_left (dc
));
4849 case DEMANGLE_COMPONENT_TRANSACTION_CLONE
:
4850 d_append_string (dpi
, "transaction clone for ");
4851 d_print_comp (dpi
, options
, d_left (dc
));
4854 case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE
:
4855 d_append_string (dpi
, "non-transaction clone for ");
4856 d_print_comp (dpi
, options
, d_left (dc
));
4859 case DEMANGLE_COMPONENT_SUB_STD
:
4860 d_append_buffer (dpi
, dc
->u
.s_string
.string
, dc
->u
.s_string
.len
);
4863 case DEMANGLE_COMPONENT_RESTRICT
:
4864 case DEMANGLE_COMPONENT_VOLATILE
:
4865 case DEMANGLE_COMPONENT_CONST
:
4867 struct d_print_mod
*pdpm
;
4869 /* When printing arrays, it's possible to have cases where the
4870 same CV-qualifier gets pushed on the stack multiple times.
4871 We only need to print it once. */
4873 for (pdpm
= dpi
->modifiers
; pdpm
!= NULL
; pdpm
= pdpm
->next
)
4875 if (! pdpm
->printed
)
4877 if (pdpm
->mod
->type
!= DEMANGLE_COMPONENT_RESTRICT
4878 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_VOLATILE
4879 && pdpm
->mod
->type
!= DEMANGLE_COMPONENT_CONST
)
4881 if (pdpm
->mod
->type
== dc
->type
)
4883 d_print_comp (dpi
, options
, d_left (dc
));
4891 case DEMANGLE_COMPONENT_REFERENCE
:
4892 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
4894 /* Handle reference smashing: & + && = &. */
4895 const struct demangle_component
*sub
= d_left (dc
);
4896 if (sub
->type
== DEMANGLE_COMPONENT_TEMPLATE_PARAM
)
4898 struct d_saved_scope
*scope
= d_get_saved_scope (dpi
, sub
);
4899 struct demangle_component
*a
;
4903 /* This is the first time SUB has been traversed.
4904 We need to capture the current templates so
4905 they can be restored if SUB is reentered as a
4907 d_save_scope (dpi
, sub
);
4908 if (d_print_saw_error (dpi
))
4913 const struct d_component_stack
*dcse
;
4914 int found_self_or_parent
= 0;
4916 /* This traversal is reentering SUB as a substition.
4917 If we are not beneath SUB or DC in the tree then we
4918 need to restore SUB's template stack temporarily. */
4919 for (dcse
= dpi
->component_stack
; dcse
!= NULL
;
4920 dcse
= dcse
->parent
)
4924 && dcse
!= dpi
->component_stack
))
4926 found_self_or_parent
= 1;
4931 if (!found_self_or_parent
)
4933 saved_templates
= dpi
->templates
;
4934 dpi
->templates
= scope
->templates
;
4935 need_template_restore
= 1;
4939 a
= d_lookup_template_argument (dpi
, sub
);
4940 if (a
&& a
->type
== DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
)
4941 a
= d_index_template_argument (a
, dpi
->pack_index
);
4945 if (need_template_restore
)
4946 dpi
->templates
= saved_templates
;
4948 d_print_error (dpi
);
4955 if (sub
->type
== DEMANGLE_COMPONENT_REFERENCE
4956 || sub
->type
== dc
->type
)
4958 else if (sub
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE
)
4959 mod_inner
= d_left (sub
);
4963 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
4964 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
4965 case DEMANGLE_COMPONENT_CONST_THIS
:
4966 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
4967 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
4968 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
4969 case DEMANGLE_COMPONENT_POINTER
:
4970 case DEMANGLE_COMPONENT_COMPLEX
:
4971 case DEMANGLE_COMPONENT_IMAGINARY
:
4972 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
4975 /* We keep a list of modifiers on the stack. */
4976 struct d_print_mod dpm
;
4978 dpm
.next
= dpi
->modifiers
;
4979 dpi
->modifiers
= &dpm
;
4982 dpm
.templates
= dpi
->templates
;
4985 mod_inner
= d_left (dc
);
4987 d_print_comp (dpi
, options
, mod_inner
);
4989 /* If the modifier didn't get printed by the type, print it
4992 d_print_mod (dpi
, options
, dc
);
4994 dpi
->modifiers
= dpm
.next
;
4996 if (need_template_restore
)
4997 dpi
->templates
= saved_templates
;
5002 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5003 if ((options
& DMGL_JAVA
) == 0)
5004 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->name
,
5005 dc
->u
.s_builtin
.type
->len
);
5007 d_append_buffer (dpi
, dc
->u
.s_builtin
.type
->java_name
,
5008 dc
->u
.s_builtin
.type
->java_len
);
5011 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5012 d_print_comp (dpi
, options
, d_left (dc
));
5015 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5017 if ((options
& DMGL_RET_POSTFIX
) != 0)
5018 d_print_function_type (dpi
,
5019 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5020 dc
, dpi
->modifiers
);
5022 /* Print return type if present */
5023 if (d_left (dc
) != NULL
&& (options
& DMGL_RET_POSTFIX
) != 0)
5024 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5026 else if (d_left (dc
) != NULL
&& (options
& DMGL_RET_DROP
) == 0)
5028 struct d_print_mod dpm
;
5030 /* We must pass this type down as a modifier in order to
5031 print it in the right location. */
5032 dpm
.next
= dpi
->modifiers
;
5033 dpi
->modifiers
= &dpm
;
5036 dpm
.templates
= dpi
->templates
;
5038 d_print_comp (dpi
, options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5041 dpi
->modifiers
= dpm
.next
;
5046 /* In standard prefix notation, there is a space between the
5047 return type and the function signature. */
5048 if ((options
& DMGL_RET_POSTFIX
) == 0)
5049 d_append_char (dpi
, ' ');
5052 if ((options
& DMGL_RET_POSTFIX
) == 0)
5053 d_print_function_type (dpi
,
5054 options
& ~(DMGL_RET_POSTFIX
| DMGL_RET_DROP
),
5055 dc
, dpi
->modifiers
);
5060 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5062 struct d_print_mod
*hold_modifiers
;
5063 struct d_print_mod adpm
[4];
5065 struct d_print_mod
*pdpm
;
5067 /* We must pass this type down as a modifier in order to print
5068 multi-dimensional arrays correctly. If the array itself is
5069 CV-qualified, we act as though the element type were
5070 CV-qualified. We do this by copying the modifiers down
5071 rather than fiddling pointers, so that we don't wind up
5072 with a d_print_mod higher on the stack pointing into our
5073 stack frame after we return. */
5075 hold_modifiers
= dpi
->modifiers
;
5077 adpm
[0].next
= hold_modifiers
;
5078 dpi
->modifiers
= &adpm
[0];
5080 adpm
[0].printed
= 0;
5081 adpm
[0].templates
= dpi
->templates
;
5084 pdpm
= hold_modifiers
;
5086 && (pdpm
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT
5087 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE
5088 || pdpm
->mod
->type
== DEMANGLE_COMPONENT_CONST
))
5090 if (! pdpm
->printed
)
5092 if (i
>= sizeof adpm
/ sizeof adpm
[0])
5094 d_print_error (dpi
);
5099 adpm
[i
].next
= dpi
->modifiers
;
5100 dpi
->modifiers
= &adpm
[i
];
5108 d_print_comp (dpi
, options
, d_right (dc
));
5110 dpi
->modifiers
= hold_modifiers
;
5112 if (adpm
[0].printed
)
5118 d_print_mod (dpi
, options
, adpm
[i
].mod
);
5121 d_print_array_type (dpi
, options
, dc
, dpi
->modifiers
);
5126 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5127 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5129 struct d_print_mod dpm
;
5131 dpm
.next
= dpi
->modifiers
;
5132 dpi
->modifiers
= &dpm
;
5135 dpm
.templates
= dpi
->templates
;
5137 d_print_comp (dpi
, options
, d_right (dc
));
5139 /* If the modifier didn't get printed by the type, print it
5142 d_print_mod (dpi
, options
, dc
);
5144 dpi
->modifiers
= dpm
.next
;
5149 case DEMANGLE_COMPONENT_FIXED_TYPE
:
5150 if (dc
->u
.s_fixed
.sat
)
5151 d_append_string (dpi
, "_Sat ");
5152 /* Don't print "int _Accum". */
5153 if (dc
->u
.s_fixed
.length
->u
.s_builtin
.type
5154 != &cplus_demangle_builtin_types
['i'-'a'])
5156 d_print_comp (dpi
, options
, dc
->u
.s_fixed
.length
);
5157 d_append_char (dpi
, ' ');
5159 if (dc
->u
.s_fixed
.accum
)
5160 d_append_string (dpi
, "_Accum");
5162 d_append_string (dpi
, "_Fract");
5165 case DEMANGLE_COMPONENT_ARGLIST
:
5166 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
:
5167 if (d_left (dc
) != NULL
)
5168 d_print_comp (dpi
, options
, d_left (dc
));
5169 if (d_right (dc
) != NULL
)
5172 unsigned long int flush_count
;
5173 /* Make sure ", " isn't flushed by d_append_string, otherwise
5174 dpi->len -= 2 wouldn't work. */
5175 if (dpi
->len
>= sizeof (dpi
->buf
) - 2)
5176 d_print_flush (dpi
);
5177 d_append_string (dpi
, ", ");
5179 flush_count
= dpi
->flush_count
;
5180 d_print_comp (dpi
, options
, d_right (dc
));
5181 /* If that didn't print anything (which can happen with empty
5182 template argument packs), remove the comma and space. */
5183 if (dpi
->flush_count
== flush_count
&& dpi
->len
== len
)
5188 case DEMANGLE_COMPONENT_INITIALIZER_LIST
:
5190 struct demangle_component
*type
= d_left (dc
);
5191 struct demangle_component
*list
= d_right (dc
);
5194 d_print_comp (dpi
, options
, type
);
5195 d_append_char (dpi
, '{');
5196 d_print_comp (dpi
, options
, list
);
5197 d_append_char (dpi
, '}');
5201 case DEMANGLE_COMPONENT_OPERATOR
:
5203 const struct demangle_operator_info
*op
= dc
->u
.s_operator
.op
;
5206 d_append_string (dpi
, "operator");
5207 /* Add a space before new/delete. */
5208 if (IS_LOWER (op
->name
[0]))
5209 d_append_char (dpi
, ' ');
5210 /* Omit a trailing space. */
5211 if (op
->name
[len
-1] == ' ')
5213 d_append_buffer (dpi
, op
->name
, len
);
5217 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
5218 d_append_string (dpi
, "operator ");
5219 d_print_comp (dpi
, options
, dc
->u
.s_extended_operator
.name
);
5222 case DEMANGLE_COMPONENT_CONVERSION
:
5223 d_append_string (dpi
, "operator ");
5224 d_print_conversion (dpi
, options
, dc
);
5227 case DEMANGLE_COMPONENT_NULLARY
:
5228 d_print_expr_op (dpi
, options
, d_left (dc
));
5231 case DEMANGLE_COMPONENT_UNARY
:
5233 struct demangle_component
*op
= d_left (dc
);
5234 struct demangle_component
*operand
= d_right (dc
);
5235 const char *code
= NULL
;
5237 if (op
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5239 code
= op
->u
.s_operator
.op
->code
;
5240 if (!strcmp (code
, "ad"))
5242 /* Don't print the argument list for the address of a
5244 if (operand
->type
== DEMANGLE_COMPONENT_TYPED_NAME
5245 && d_left (operand
)->type
== DEMANGLE_COMPONENT_QUAL_NAME
5246 && d_right (operand
)->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5247 operand
= d_left (operand
);
5249 if (operand
->type
== DEMANGLE_COMPONENT_BINARY_ARGS
)
5251 /* This indicates a suffix operator. */
5252 operand
= d_left (operand
);
5253 d_print_subexpr (dpi
, options
, operand
);
5254 d_print_expr_op (dpi
, options
, op
);
5259 /* For sizeof..., just print the pack length. */
5260 if (code
&& !strcmp (code
, "sZ"))
5262 struct demangle_component
*a
= d_find_pack (dpi
, operand
);
5263 int len
= d_pack_length (a
);
5264 d_append_num (dpi
, len
);
5267 else if (code
&& !strcmp (code
, "sP"))
5269 int len
= d_args_length (dpi
, operand
);
5270 d_append_num (dpi
, len
);
5274 if (op
->type
!= DEMANGLE_COMPONENT_CAST
)
5275 d_print_expr_op (dpi
, options
, op
);
5278 d_append_char (dpi
, '(');
5279 d_print_cast (dpi
, options
, op
);
5280 d_append_char (dpi
, ')');
5282 if (code
&& !strcmp (code
, "gs"))
5283 /* Avoid parens after '::'. */
5284 d_print_comp (dpi
, options
, operand
);
5285 else if (code
&& !strcmp (code
, "st"))
5286 /* Always print parens for sizeof (type). */
5288 d_append_char (dpi
, '(');
5289 d_print_comp (dpi
, options
, operand
);
5290 d_append_char (dpi
, ')');
5293 d_print_subexpr (dpi
, options
, operand
);
5297 case DEMANGLE_COMPONENT_BINARY
:
5298 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_BINARY_ARGS
)
5300 d_print_error (dpi
);
5304 if (op_is_new_cast (d_left (dc
)))
5306 d_print_expr_op (dpi
, options
, d_left (dc
));
5307 d_append_char (dpi
, '<');
5308 d_print_comp (dpi
, options
, d_left (d_right (dc
)));
5309 d_append_string (dpi
, ">(");
5310 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5311 d_append_char (dpi
, ')');
5315 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5318 /* We wrap an expression which uses the greater-than operator in
5319 an extra layer of parens so that it does not get confused
5320 with the '>' which ends the template parameters. */
5321 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5322 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5323 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5324 d_append_char (dpi
, '(');
5326 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") == 0
5327 && d_left (d_right (dc
))->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
5329 /* Function call used in an expression should not have printed types
5330 of the function arguments. Values of the function arguments still
5331 get printed below. */
5333 const struct demangle_component
*func
= d_left (d_right (dc
));
5335 if (d_right (func
)->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5336 d_print_error (dpi
);
5337 d_print_subexpr (dpi
, options
, d_left (func
));
5340 d_print_subexpr (dpi
, options
, d_left (d_right (dc
)));
5341 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "ix") == 0)
5343 d_append_char (dpi
, '[');
5344 d_print_comp (dpi
, options
, d_right (d_right (dc
)));
5345 d_append_char (dpi
, ']');
5349 if (strcmp (d_left (dc
)->u
.s_operator
.op
->code
, "cl") != 0)
5350 d_print_expr_op (dpi
, options
, d_left (dc
));
5351 d_print_subexpr (dpi
, options
, d_right (d_right (dc
)));
5354 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_OPERATOR
5355 && d_left (dc
)->u
.s_operator
.op
->len
== 1
5356 && d_left (dc
)->u
.s_operator
.op
->name
[0] == '>')
5357 d_append_char (dpi
, ')');
5361 case DEMANGLE_COMPONENT_BINARY_ARGS
:
5362 /* We should only see this as part of DEMANGLE_COMPONENT_BINARY. */
5363 d_print_error (dpi
);
5366 case DEMANGLE_COMPONENT_TRINARY
:
5367 if (d_right (dc
)->type
!= DEMANGLE_COMPONENT_TRINARY_ARG1
5368 || d_right (d_right (dc
))->type
!= DEMANGLE_COMPONENT_TRINARY_ARG2
)
5370 d_print_error (dpi
);
5373 if (d_maybe_print_fold_expression (dpi
, options
, dc
))
5376 struct demangle_component
*op
= d_left (dc
);
5377 struct demangle_component
*first
= d_left (d_right (dc
));
5378 struct demangle_component
*second
= d_left (d_right (d_right (dc
)));
5379 struct demangle_component
*third
= d_right (d_right (d_right (dc
)));
5381 if (!strcmp (op
->u
.s_operator
.op
->code
, "qu"))
5383 d_print_subexpr (dpi
, options
, first
);
5384 d_print_expr_op (dpi
, options
, op
);
5385 d_print_subexpr (dpi
, options
, second
);
5386 d_append_string (dpi
, " : ");
5387 d_print_subexpr (dpi
, options
, third
);
5391 d_append_string (dpi
, "new ");
5392 if (d_left (first
) != NULL
)
5394 d_print_subexpr (dpi
, options
, first
);
5395 d_append_char (dpi
, ' ');
5397 d_print_comp (dpi
, options
, second
);
5399 d_print_subexpr (dpi
, options
, third
);
5404 case DEMANGLE_COMPONENT_TRINARY_ARG1
:
5405 case DEMANGLE_COMPONENT_TRINARY_ARG2
:
5406 /* We should only see these are part of DEMANGLE_COMPONENT_TRINARY. */
5407 d_print_error (dpi
);
5410 case DEMANGLE_COMPONENT_LITERAL
:
5411 case DEMANGLE_COMPONENT_LITERAL_NEG
:
5413 enum d_builtin_type_print tp
;
5415 /* For some builtin types, produce simpler output. */
5416 tp
= D_PRINT_DEFAULT
;
5417 if (d_left (dc
)->type
== DEMANGLE_COMPONENT_BUILTIN_TYPE
)
5419 tp
= d_left (dc
)->u
.s_builtin
.type
->print
;
5423 case D_PRINT_UNSIGNED
:
5425 case D_PRINT_UNSIGNED_LONG
:
5426 case D_PRINT_LONG_LONG
:
5427 case D_PRINT_UNSIGNED_LONG_LONG
:
5428 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
)
5430 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5431 d_append_char (dpi
, '-');
5432 d_print_comp (dpi
, options
, d_right (dc
));
5437 case D_PRINT_UNSIGNED
:
5438 d_append_char (dpi
, 'u');
5441 d_append_char (dpi
, 'l');
5443 case D_PRINT_UNSIGNED_LONG
:
5444 d_append_string (dpi
, "ul");
5446 case D_PRINT_LONG_LONG
:
5447 d_append_string (dpi
, "ll");
5449 case D_PRINT_UNSIGNED_LONG_LONG
:
5450 d_append_string (dpi
, "ull");
5458 if (d_right (dc
)->type
== DEMANGLE_COMPONENT_NAME
5459 && d_right (dc
)->u
.s_name
.len
== 1
5460 && dc
->type
== DEMANGLE_COMPONENT_LITERAL
)
5462 switch (d_right (dc
)->u
.s_name
.s
[0])
5465 d_append_string (dpi
, "false");
5468 d_append_string (dpi
, "true");
5481 d_append_char (dpi
, '(');
5482 d_print_comp (dpi
, options
, d_left (dc
));
5483 d_append_char (dpi
, ')');
5484 if (dc
->type
== DEMANGLE_COMPONENT_LITERAL_NEG
)
5485 d_append_char (dpi
, '-');
5486 if (tp
== D_PRINT_FLOAT
)
5487 d_append_char (dpi
, '[');
5488 d_print_comp (dpi
, options
, d_right (dc
));
5489 if (tp
== D_PRINT_FLOAT
)
5490 d_append_char (dpi
, ']');
5494 case DEMANGLE_COMPONENT_NUMBER
:
5495 d_append_num (dpi
, dc
->u
.s_number
.number
);
5498 case DEMANGLE_COMPONENT_JAVA_RESOURCE
:
5499 d_append_string (dpi
, "java resource ");
5500 d_print_comp (dpi
, options
, d_left (dc
));
5503 case DEMANGLE_COMPONENT_COMPOUND_NAME
:
5504 d_print_comp (dpi
, options
, d_left (dc
));
5505 d_print_comp (dpi
, options
, d_right (dc
));
5508 case DEMANGLE_COMPONENT_CHARACTER
:
5509 d_append_char (dpi
, dc
->u
.s_character
.character
);
5512 case DEMANGLE_COMPONENT_DECLTYPE
:
5513 d_append_string (dpi
, "decltype (");
5514 d_print_comp (dpi
, options
, d_left (dc
));
5515 d_append_char (dpi
, ')');
5518 case DEMANGLE_COMPONENT_PACK_EXPANSION
:
5522 struct demangle_component
*a
= d_find_pack (dpi
, d_left (dc
));
5525 /* d_find_pack won't find anything if the only packs involved
5526 in this expansion are function parameter packs; in that
5527 case, just print the pattern and "...". */
5528 d_print_subexpr (dpi
, options
, d_left (dc
));
5529 d_append_string (dpi
, "...");
5533 len
= d_pack_length (a
);
5535 for (i
= 0; i
< len
; ++i
)
5537 dpi
->pack_index
= i
;
5538 d_print_comp (dpi
, options
, dc
);
5540 d_append_string (dpi
, ", ");
5545 case DEMANGLE_COMPONENT_FUNCTION_PARAM
:
5547 long num
= dc
->u
.s_number
.number
;
5549 d_append_string (dpi
, "this");
5552 d_append_string (dpi
, "{parm#");
5553 d_append_num (dpi
, num
);
5554 d_append_char (dpi
, '}');
5559 case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
:
5560 d_append_string (dpi
, "global constructors keyed to ");
5561 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5564 case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
:
5565 d_append_string (dpi
, "global destructors keyed to ");
5566 d_print_comp (dpi
, options
, dc
->u
.s_binary
.left
);
5569 case DEMANGLE_COMPONENT_LAMBDA
:
5570 d_append_string (dpi
, "{lambda(");
5571 d_print_comp (dpi
, options
, dc
->u
.s_unary_num
.sub
);
5572 d_append_string (dpi
, ")#");
5573 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5574 d_append_char (dpi
, '}');
5577 case DEMANGLE_COMPONENT_UNNAMED_TYPE
:
5578 d_append_string (dpi
, "{unnamed type#");
5579 d_append_num (dpi
, dc
->u
.s_number
.number
+ 1);
5580 d_append_char (dpi
, '}');
5583 case DEMANGLE_COMPONENT_CLONE
:
5584 d_print_comp (dpi
, options
, d_left (dc
));
5585 d_append_string (dpi
, " [clone ");
5586 d_print_comp (dpi
, options
, d_right (dc
));
5587 d_append_char (dpi
, ']');
5591 d_print_error (dpi
);
5597 d_print_comp (struct d_print_info
*dpi
, int options
,
5598 const struct demangle_component
*dc
)
5600 struct d_component_stack self
;
5603 self
.parent
= dpi
->component_stack
;
5604 dpi
->component_stack
= &self
;
5606 d_print_comp_inner (dpi
, options
, dc
);
5608 dpi
->component_stack
= self
.parent
;
5611 /* Print a Java dentifier. For Java we try to handle encoded extended
5612 Unicode characters. The C++ ABI doesn't mention Unicode encoding,
5613 so we don't it for C++. Characters are encoded as
5617 d_print_java_identifier (struct d_print_info
*dpi
, const char *name
, int len
)
5623 for (p
= name
; p
< end
; ++p
)
5634 for (q
= p
+ 3; q
< end
; ++q
)
5640 else if (*q
>= 'A' && *q
<= 'F')
5641 dig
= *q
- 'A' + 10;
5642 else if (*q
>= 'a' && *q
<= 'f')
5643 dig
= *q
- 'a' + 10;
5649 /* If the Unicode character is larger than 256, we don't try
5650 to deal with it here. FIXME. */
5651 if (q
< end
&& *q
== '_' && c
< 256)
5653 d_append_char (dpi
, c
);
5659 d_append_char (dpi
, *p
);
5663 /* Print a list of modifiers. SUFFIX is 1 if we are printing
5664 qualifiers on this after printing a function. */
5667 d_print_mod_list (struct d_print_info
*dpi
, int options
,
5668 struct d_print_mod
*mods
, int suffix
)
5670 struct d_print_template
*hold_dpt
;
5672 if (mods
== NULL
|| d_print_saw_error (dpi
))
5677 && (mods
->mod
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5678 || mods
->mod
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5679 || mods
->mod
->type
== DEMANGLE_COMPONENT_CONST_THIS
5680 || mods
->mod
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5681 || mods
->mod
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
5683 == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
))))
5685 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5691 hold_dpt
= dpi
->templates
;
5692 dpi
->templates
= mods
->templates
;
5694 if (mods
->mod
->type
== DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5696 d_print_function_type (dpi
, options
, mods
->mod
, mods
->next
);
5697 dpi
->templates
= hold_dpt
;
5700 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5702 d_print_array_type (dpi
, options
, mods
->mod
, mods
->next
);
5703 dpi
->templates
= hold_dpt
;
5706 else if (mods
->mod
->type
== DEMANGLE_COMPONENT_LOCAL_NAME
)
5708 struct d_print_mod
*hold_modifiers
;
5709 struct demangle_component
*dc
;
5711 /* When this is on the modifier stack, we have pulled any
5712 qualifiers off the right argument already. Otherwise, we
5713 print it as usual, but don't let the left argument see any
5716 hold_modifiers
= dpi
->modifiers
;
5717 dpi
->modifiers
= NULL
;
5718 d_print_comp (dpi
, options
, d_left (mods
->mod
));
5719 dpi
->modifiers
= hold_modifiers
;
5721 if ((options
& DMGL_JAVA
) == 0)
5722 d_append_string (dpi
, "::");
5724 d_append_char (dpi
, '.');
5726 dc
= d_right (mods
->mod
);
5728 if (dc
->type
== DEMANGLE_COMPONENT_DEFAULT_ARG
)
5730 d_append_string (dpi
, "{default arg#");
5731 d_append_num (dpi
, dc
->u
.s_unary_num
.num
+ 1);
5732 d_append_string (dpi
, "}::");
5733 dc
= dc
->u
.s_unary_num
.sub
;
5736 while (dc
->type
== DEMANGLE_COMPONENT_RESTRICT_THIS
5737 || dc
->type
== DEMANGLE_COMPONENT_VOLATILE_THIS
5738 || dc
->type
== DEMANGLE_COMPONENT_CONST_THIS
5739 || dc
->type
== DEMANGLE_COMPONENT_REFERENCE_THIS
5740 || dc
->type
== DEMANGLE_COMPONENT_TRANSACTION_SAFE
5741 || dc
->type
== DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
)
5744 d_print_comp (dpi
, options
, dc
);
5746 dpi
->templates
= hold_dpt
;
5750 d_print_mod (dpi
, options
, mods
->mod
);
5752 dpi
->templates
= hold_dpt
;
5754 d_print_mod_list (dpi
, options
, mods
->next
, suffix
);
5757 /* Print a modifier. */
5760 d_print_mod (struct d_print_info
*dpi
, int options
,
5761 const struct demangle_component
*mod
)
5765 case DEMANGLE_COMPONENT_RESTRICT
:
5766 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5767 d_append_string (dpi
, " restrict");
5769 case DEMANGLE_COMPONENT_VOLATILE
:
5770 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5771 d_append_string (dpi
, " volatile");
5773 case DEMANGLE_COMPONENT_CONST
:
5774 case DEMANGLE_COMPONENT_CONST_THIS
:
5775 d_append_string (dpi
, " const");
5777 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5778 d_append_string (dpi
, " transaction_safe");
5780 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5781 d_append_char (dpi
, ' ');
5782 d_print_comp (dpi
, options
, d_right (mod
));
5784 case DEMANGLE_COMPONENT_POINTER
:
5785 /* There is no pointer symbol in Java. */
5786 if ((options
& DMGL_JAVA
) == 0)
5787 d_append_char (dpi
, '*');
5789 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5790 /* For the ref-qualifier, put a space before the &. */
5791 d_append_char (dpi
, ' ');
5793 case DEMANGLE_COMPONENT_REFERENCE
:
5794 d_append_char (dpi
, '&');
5796 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5797 d_append_char (dpi
, ' ');
5799 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5800 d_append_string (dpi
, "&&");
5802 case DEMANGLE_COMPONENT_COMPLEX
:
5803 d_append_string (dpi
, "complex ");
5805 case DEMANGLE_COMPONENT_IMAGINARY
:
5806 d_append_string (dpi
, "imaginary ");
5808 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5809 if (d_last_char (dpi
) != '(')
5810 d_append_char (dpi
, ' ');
5811 d_print_comp (dpi
, options
, d_left (mod
));
5812 d_append_string (dpi
, "::*");
5814 case DEMANGLE_COMPONENT_TYPED_NAME
:
5815 d_print_comp (dpi
, options
, d_left (mod
));
5817 case DEMANGLE_COMPONENT_VECTOR_TYPE
:
5818 d_append_string (dpi
, " __vector(");
5819 d_print_comp (dpi
, options
, d_left (mod
));
5820 d_append_char (dpi
, ')');
5824 /* Otherwise, we have something that won't go back on the
5825 modifier stack, so we can just print it. */
5826 d_print_comp (dpi
, options
, mod
);
5831 /* Print a function type, except for the return type. */
5834 d_print_function_type (struct d_print_info
*dpi
, int options
,
5835 const struct demangle_component
*dc
,
5836 struct d_print_mod
*mods
)
5840 struct d_print_mod
*p
;
5841 struct d_print_mod
*hold_modifiers
;
5845 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5850 switch (p
->mod
->type
)
5852 case DEMANGLE_COMPONENT_POINTER
:
5853 case DEMANGLE_COMPONENT_REFERENCE
:
5854 case DEMANGLE_COMPONENT_RVALUE_REFERENCE
:
5857 case DEMANGLE_COMPONENT_RESTRICT
:
5858 case DEMANGLE_COMPONENT_VOLATILE
:
5859 case DEMANGLE_COMPONENT_CONST
:
5860 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5861 case DEMANGLE_COMPONENT_COMPLEX
:
5862 case DEMANGLE_COMPONENT_IMAGINARY
:
5863 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5867 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5868 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5869 case DEMANGLE_COMPONENT_CONST_THIS
:
5870 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
5871 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
5872 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
5885 if (d_last_char (dpi
) != '('
5886 && d_last_char (dpi
) != '*')
5889 if (need_space
&& d_last_char (dpi
) != ' ')
5890 d_append_char (dpi
, ' ');
5891 d_append_char (dpi
, '(');
5894 hold_modifiers
= dpi
->modifiers
;
5895 dpi
->modifiers
= NULL
;
5897 d_print_mod_list (dpi
, options
, mods
, 0);
5900 d_append_char (dpi
, ')');
5902 d_append_char (dpi
, '(');
5904 if (d_right (dc
) != NULL
)
5905 d_print_comp (dpi
, options
, d_right (dc
));
5907 d_append_char (dpi
, ')');
5909 d_print_mod_list (dpi
, options
, mods
, 1);
5911 dpi
->modifiers
= hold_modifiers
;
5914 /* Print an array type, except for the element type. */
5917 d_print_array_type (struct d_print_info
*dpi
, int options
,
5918 const struct demangle_component
*dc
,
5919 struct d_print_mod
*mods
)
5927 struct d_print_mod
*p
;
5930 for (p
= mods
; p
!= NULL
; p
= p
->next
)
5934 if (p
->mod
->type
== DEMANGLE_COMPONENT_ARRAY_TYPE
)
5949 d_append_string (dpi
, " (");
5951 d_print_mod_list (dpi
, options
, mods
, 0);
5954 d_append_char (dpi
, ')');
5958 d_append_char (dpi
, ' ');
5960 d_append_char (dpi
, '[');
5962 if (d_left (dc
) != NULL
)
5963 d_print_comp (dpi
, options
, d_left (dc
));
5965 d_append_char (dpi
, ']');
5968 /* Print an operator in an expression. */
5971 d_print_expr_op (struct d_print_info
*dpi
, int options
,
5972 const struct demangle_component
*dc
)
5974 if (dc
->type
== DEMANGLE_COMPONENT_OPERATOR
)
5975 d_append_buffer (dpi
, dc
->u
.s_operator
.op
->name
,
5976 dc
->u
.s_operator
.op
->len
);
5978 d_print_comp (dpi
, options
, dc
);
5984 d_print_cast (struct d_print_info
*dpi
, int options
,
5985 const struct demangle_component
*dc
)
5987 d_print_comp (dpi
, options
, d_left (dc
));
5990 /* Print a conversion operator. */
5993 d_print_conversion (struct d_print_info
*dpi
, int options
,
5994 const struct demangle_component
*dc
)
5996 struct d_print_template dpt
;
5998 /* For a conversion operator, we need the template parameters from
5999 the enclosing template in scope for processing the type. */
6000 if (dpi
->current_template
!= NULL
)
6002 dpt
.next
= dpi
->templates
;
6003 dpi
->templates
= &dpt
;
6004 dpt
.template_decl
= dpi
->current_template
;
6007 if (d_left (dc
)->type
!= DEMANGLE_COMPONENT_TEMPLATE
)
6009 d_print_comp (dpi
, options
, d_left (dc
));
6010 if (dpi
->current_template
!= NULL
)
6011 dpi
->templates
= dpt
.next
;
6015 d_print_comp (dpi
, options
, d_left (d_left (dc
)));
6017 /* For a templated cast operator, we need to remove the template
6018 parameters from scope after printing the operator name,
6019 so we need to handle the template printing here. */
6020 if (dpi
->current_template
!= NULL
)
6021 dpi
->templates
= dpt
.next
;
6023 if (d_last_char (dpi
) == '<')
6024 d_append_char (dpi
, ' ');
6025 d_append_char (dpi
, '<');
6026 d_print_comp (dpi
, options
, d_right (d_left (dc
)));
6027 /* Avoid generating two consecutive '>' characters, to avoid
6028 the C++ syntactic ambiguity. */
6029 if (d_last_char (dpi
) == '>')
6030 d_append_char (dpi
, ' ');
6031 d_append_char (dpi
, '>');
6035 /* Initialize the information structure we use to pass around
6038 CP_STATIC_IF_GLIBCPP_V3
6040 cplus_demangle_init_info (const char *mangled
, int options
, size_t len
,
6044 di
->send
= mangled
+ len
;
6045 di
->options
= options
;
6049 /* We can not need more components than twice the number of chars in
6050 the mangled string. Most components correspond directly to
6051 chars, but the ARGLIST types are exceptions. */
6052 di
->num_comps
= 2 * len
;
6055 /* Similarly, we can not need more substitutions than there are
6056 chars in the mangled string. */
6061 di
->last_name
= NULL
;
6064 di
->is_expression
= 0;
6065 di
->is_conversion
= 0;
6068 /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
6069 mangled name, return strings in repeated callback giving the demangled
6070 name. OPTIONS is the usual libiberty demangler options. On success,
6071 this returns 1. On failure, returns 0. */
6074 d_demangle_callback (const char *mangled
, int options
,
6075 demangle_callbackref callback
, void *opaque
)
6086 struct demangle_component
*dc
;
6089 if (mangled
[0] == '_' && mangled
[1] == 'Z')
6091 else if (strncmp (mangled
, "_GLOBAL_", 8) == 0
6092 && (mangled
[8] == '.' || mangled
[8] == '_' || mangled
[8] == '$')
6093 && (mangled
[9] == 'D' || mangled
[9] == 'I')
6094 && mangled
[10] == '_')
6095 type
= mangled
[9] == 'I' ? DCT_GLOBAL_CTORS
: DCT_GLOBAL_DTORS
;
6098 if ((options
& DMGL_TYPES
) == 0)
6103 cplus_demangle_init_info (mangled
, options
, strlen (mangled
), &di
);
6106 #ifdef CP_DYNAMIC_ARRAYS
6107 __extension__
struct demangle_component comps
[di
.num_comps
];
6108 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6113 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6114 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6120 dc
= cplus_demangle_type (&di
);
6123 dc
= cplus_demangle_mangled_name (&di
, 1);
6125 case DCT_GLOBAL_CTORS
:
6126 case DCT_GLOBAL_DTORS
:
6127 d_advance (&di
, 11);
6128 dc
= d_make_comp (&di
,
6129 (type
== DCT_GLOBAL_CTORS
6130 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
6131 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS
),
6132 d_make_demangle_mangled_name (&di
, d_str (&di
)),
6134 d_advance (&di
, strlen (d_str (&di
)));
6137 abort (); /* We have listed all the cases. */
6140 /* If DMGL_PARAMS is set, then if we didn't consume the entire
6141 mangled string, then we didn't successfully demangle it. If
6142 DMGL_PARAMS is not set, we didn't look at the trailing
6144 if (((options
& DMGL_PARAMS
) != 0) && d_peek_char (&di
) != '\0')
6147 #ifdef CP_DEMANGLE_DEBUG
6151 status
= (dc
!= NULL
)
6152 ? cplus_demangle_print_callback (options
, dc
, callback
, opaque
)
6159 /* Entry point for the demangler. If MANGLED is a g++ v3 ABI mangled
6160 name, return a buffer allocated with malloc holding the demangled
6161 name. OPTIONS is the usual libiberty demangler options. On
6162 success, this sets *PALC to the allocated size of the returned
6163 buffer. On failure, this sets *PALC to 0 for a bad name, or 1 for
6164 a memory allocation failure, and returns NULL. */
6167 d_demangle (const char *mangled
, int options
, size_t *palc
)
6169 struct d_growable_string dgs
;
6172 d_growable_string_init (&dgs
, 0);
6174 status
= d_demangle_callback (mangled
, options
,
6175 d_growable_string_callback_adapter
, &dgs
);
6183 *palc
= dgs
.allocation_failure
? 1 : dgs
.alc
;
6187 #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
6189 extern char *__cxa_demangle (const char *, char *, size_t *, int *);
6191 /* ia64 ABI-mandated entry point in the C++ runtime library for
6192 performing demangling. MANGLED_NAME is a NUL-terminated character
6193 string containing the name to be demangled.
6195 OUTPUT_BUFFER is a region of memory, allocated with malloc, of
6196 *LENGTH bytes, into which the demangled name is stored. If
6197 OUTPUT_BUFFER is not long enough, it is expanded using realloc.
6198 OUTPUT_BUFFER may instead be NULL; in that case, the demangled name
6199 is placed in a region of memory allocated with malloc.
6201 If LENGTH is non-NULL, the length of the buffer containing the
6202 demangled name, is placed in *LENGTH.
6204 The return value is a pointer to the start of the NUL-terminated
6205 demangled name, or NULL if the demangling fails. The caller is
6206 responsible for deallocating this memory using free.
6208 *STATUS is set to one of the following values:
6209 0: The demangling operation succeeded.
6210 -1: A memory allocation failure occurred.
6211 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6212 -3: One of the arguments is invalid.
6214 The demangling is performed using the C++ ABI mangling rules, with
6218 __cxa_demangle (const char *mangled_name
, char *output_buffer
,
6219 size_t *length
, int *status
)
6224 if (mangled_name
== NULL
)
6231 if (output_buffer
!= NULL
&& length
== NULL
)
6238 demangled
= d_demangle (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
, &alc
);
6240 if (demangled
== NULL
)
6252 if (output_buffer
== NULL
)
6259 if (strlen (demangled
) < *length
)
6261 strcpy (output_buffer
, demangled
);
6263 demangled
= output_buffer
;
6267 free (output_buffer
);
6278 extern int __gcclibcxx_demangle_callback (const char *,
6280 (const char *, size_t, void *),
6283 /* Alternative, allocationless entry point in the C++ runtime library
6284 for performing demangling. MANGLED_NAME is a NUL-terminated character
6285 string containing the name to be demangled.
6287 CALLBACK is a callback function, called with demangled string
6288 segments as demangling progresses; it is called at least once,
6289 but may be called more than once. OPAQUE is a generalized pointer
6290 used as a callback argument.
6292 The return code is one of the following values, equivalent to
6293 the STATUS values of __cxa_demangle() (excluding -1, since this
6294 function performs no memory allocations):
6295 0: The demangling operation succeeded.
6296 -2: MANGLED_NAME is not a valid name under the C++ ABI mangling rules.
6297 -3: One of the arguments is invalid.
6299 The demangling is performed using the C++ ABI mangling rules, with
6303 __gcclibcxx_demangle_callback (const char *mangled_name
,
6304 void (*callback
) (const char *, size_t, void *),
6309 if (mangled_name
== NULL
|| callback
== NULL
)
6312 status
= d_demangle_callback (mangled_name
, DMGL_PARAMS
| DMGL_TYPES
,
6320 #else /* ! (IN_LIBGCC2 || IN_GLIBCPP_V3) */
6322 /* Entry point for libiberty demangler. If MANGLED is a g++ v3 ABI
6323 mangled name, return a buffer allocated with malloc holding the
6324 demangled name. Otherwise, return NULL. */
6327 cplus_demangle_v3 (const char *mangled
, int options
)
6331 return d_demangle (mangled
, options
, &alc
);
6335 cplus_demangle_v3_callback (const char *mangled
, int options
,
6336 demangle_callbackref callback
, void *opaque
)
6338 return d_demangle_callback (mangled
, options
, callback
, opaque
);
6341 /* Demangle a Java symbol. Java uses a subset of the V3 ABI C++ mangling
6342 conventions, but the output formatting is a little different.
6343 This instructs the C++ demangler not to emit pointer characters ("*"), to
6344 use Java's namespace separator symbol ("." instead of "::"), and to output
6345 JArray<TYPE> as TYPE[]. */
6348 java_demangle_v3 (const char *mangled
)
6352 return d_demangle (mangled
, DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
, &alc
);
6356 java_demangle_v3_callback (const char *mangled
,
6357 demangle_callbackref callback
, void *opaque
)
6359 return d_demangle_callback (mangled
,
6360 DMGL_JAVA
| DMGL_PARAMS
| DMGL_RET_POSTFIX
,
6364 #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
6366 #ifndef IN_GLIBCPP_V3
6368 /* Demangle a string in order to find out whether it is a constructor
6369 or destructor. Return non-zero on success. Set *CTOR_KIND and
6370 *DTOR_KIND appropriately. */
6373 is_ctor_or_dtor (const char *mangled
,
6374 enum gnu_v3_ctor_kinds
*ctor_kind
,
6375 enum gnu_v3_dtor_kinds
*dtor_kind
)
6378 struct demangle_component
*dc
;
6381 *ctor_kind
= (enum gnu_v3_ctor_kinds
) 0;
6382 *dtor_kind
= (enum gnu_v3_dtor_kinds
) 0;
6384 cplus_demangle_init_info (mangled
, DMGL_GNU_V3
, strlen (mangled
), &di
);
6387 #ifdef CP_DYNAMIC_ARRAYS
6388 __extension__
struct demangle_component comps
[di
.num_comps
];
6389 __extension__
struct demangle_component
*subs
[di
.num_subs
];
6394 di
.comps
= alloca (di
.num_comps
* sizeof (*di
.comps
));
6395 di
.subs
= alloca (di
.num_subs
* sizeof (*di
.subs
));
6398 dc
= cplus_demangle_mangled_name (&di
, 1);
6400 /* Note that because we did not pass DMGL_PARAMS, we don't expect
6401 to demangle the entire string. */
6408 /* These cannot appear on a constructor or destructor. */
6409 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
6410 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
6411 case DEMANGLE_COMPONENT_CONST_THIS
:
6412 case DEMANGLE_COMPONENT_REFERENCE_THIS
:
6413 case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS
:
6414 case DEMANGLE_COMPONENT_TRANSACTION_SAFE
:
6418 case DEMANGLE_COMPONENT_TYPED_NAME
:
6419 case DEMANGLE_COMPONENT_TEMPLATE
:
6422 case DEMANGLE_COMPONENT_QUAL_NAME
:
6423 case DEMANGLE_COMPONENT_LOCAL_NAME
:
6426 case DEMANGLE_COMPONENT_CTOR
:
6427 *ctor_kind
= dc
->u
.s_ctor
.kind
;
6431 case DEMANGLE_COMPONENT_DTOR
:
6432 *dtor_kind
= dc
->u
.s_dtor
.kind
;
6443 /* Return whether NAME is the mangled form of a g++ V3 ABI constructor
6444 name. A non-zero return indicates the type of constructor. */
6446 enum gnu_v3_ctor_kinds
6447 is_gnu_v3_mangled_ctor (const char *name
)
6449 enum gnu_v3_ctor_kinds ctor_kind
;
6450 enum gnu_v3_dtor_kinds dtor_kind
;
6452 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6453 return (enum gnu_v3_ctor_kinds
) 0;
6458 /* Return whether NAME is the mangled form of a g++ V3 ABI destructor
6459 name. A non-zero return indicates the type of destructor. */
6461 enum gnu_v3_dtor_kinds
6462 is_gnu_v3_mangled_dtor (const char *name
)
6464 enum gnu_v3_ctor_kinds ctor_kind
;
6465 enum gnu_v3_dtor_kinds dtor_kind
;
6467 if (! is_ctor_or_dtor (name
, &ctor_kind
, &dtor_kind
))
6468 return (enum gnu_v3_dtor_kinds
) 0;
6472 #endif /* IN_GLIBCPP_V3 */
6474 #ifdef STANDALONE_DEMANGLER
6477 #include "dyn-string.h"
6479 static void print_usage (FILE* fp
, int exit_value
);
6481 #define IS_ALPHA(CHAR) \
6482 (((CHAR) >= 'a' && (CHAR) <= 'z') \
6483 || ((CHAR) >= 'A' && (CHAR) <= 'Z'))
6485 /* Non-zero if CHAR is a character than can occur in a mangled name. */
6486 #define is_mangled_char(CHAR) \
6487 (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \
6488 || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$')
6490 /* The name of this program, as invoked. */
6491 const char* program_name
;
6493 /* Prints usage summary to FP and then exits with EXIT_VALUE. */
6496 print_usage (FILE* fp
, int exit_value
)
6498 fprintf (fp
, "Usage: %s [options] [names ...]\n", program_name
);
6499 fprintf (fp
, "Options:\n");
6500 fprintf (fp
, " -h,--help Display this message.\n");
6501 fprintf (fp
, " -p,--no-params Don't display function parameters\n");
6502 fprintf (fp
, " -v,--verbose Produce verbose demanglings.\n");
6503 fprintf (fp
, "If names are provided, they are demangled. Otherwise filters standard input.\n");
6508 /* Option specification for getopt_long. */
6509 static const struct option long_options
[] =
6511 { "help", no_argument
, NULL
, 'h' },
6512 { "no-params", no_argument
, NULL
, 'p' },
6513 { "verbose", no_argument
, NULL
, 'v' },
6514 { NULL
, no_argument
, NULL
, 0 },
6517 /* Main entry for a demangling filter executable. It will demangle
6518 its command line arguments, if any. If none are provided, it will
6519 filter stdin to stdout, replacing any recognized mangled C++ names
6520 with their demangled equivalents. */
6523 main (int argc
, char *argv
[])
6527 int options
= DMGL_PARAMS
| DMGL_ANSI
| DMGL_TYPES
;
6529 /* Use the program name of this program, as invoked. */
6530 program_name
= argv
[0];
6532 /* Parse options. */
6535 opt_char
= getopt_long (argc
, argv
, "hpv", long_options
, NULL
);
6538 case '?': /* Unrecognized option. */
6539 print_usage (stderr
, 1);
6543 print_usage (stdout
, 0);
6547 options
&= ~ DMGL_PARAMS
;
6551 options
|= DMGL_VERBOSE
;
6555 while (opt_char
!= -1);
6558 /* No command line arguments were provided. Filter stdin. */
6560 dyn_string_t mangled
= dyn_string_new (3);
6563 /* Read all of input. */
6564 while (!feof (stdin
))
6568 /* Pile characters into mangled until we hit one that can't
6569 occur in a mangled name. */
6571 while (!feof (stdin
) && is_mangled_char (c
))
6573 dyn_string_append_char (mangled
, c
);
6579 if (dyn_string_length (mangled
) > 0)
6581 #ifdef IN_GLIBCPP_V3
6582 s
= __cxa_demangle (dyn_string_buf (mangled
), NULL
, NULL
, NULL
);
6584 s
= cplus_demangle_v3 (dyn_string_buf (mangled
), options
);
6594 /* It might not have been a mangled name. Print the
6596 fputs (dyn_string_buf (mangled
), stdout
);
6599 dyn_string_clear (mangled
);
6602 /* If we haven't hit EOF yet, we've read one character that
6603 can't occur in a mangled name, so print it out. */
6608 dyn_string_delete (mangled
);
6611 /* Demangle command line arguments. */
6613 /* Loop over command line arguments. */
6614 for (i
= optind
; i
< argc
; ++i
)
6617 #ifdef IN_GLIBCPP_V3
6621 /* Attempt to demangle. */
6622 #ifdef IN_GLIBCPP_V3
6623 s
= __cxa_demangle (argv
[i
], NULL
, NULL
, &status
);
6625 s
= cplus_demangle_v3 (argv
[i
], options
);
6628 /* If it worked, print the demangled name. */
6636 #ifdef IN_GLIBCPP_V3
6637 fprintf (stderr
, "Failed: %s (status %d)\n", argv
[i
], status
);
6639 fprintf (stderr
, "Failed: %s\n", argv
[i
]);
6648 #endif /* STANDALONE_DEMANGLER */