-
Notifications
You must be signed in to change notification settings - Fork 4
/
cp-demangle.c
6317 lines (5394 loc) · 165 KB
/
cp-demangle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Demangler for g++ V3 ABI.
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014
Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@wasabisystems.com>.
This file is part of the libiberty library, which is part of GCC.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combined
executable.)
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* This code implements a demangler for the g++ V3 ABI. The ABI is
described on this web page:
http://www.codesourcery.com/cxx-abi/abi.html#mangling
This code was written while looking at the demangler written by
Alex Samuel <samuel@codesourcery.com>.
This code first pulls the mangled name apart into a list of
components, and then walks the list generating the demangled
name.
This file will normally define the following functions, q.v.:
char *cplus_demangle_v3(const char *mangled, int options)
char *java_demangle_v3(const char *mangled)
int cplus_demangle_v3_callback(const char *mangled, int options,
demangle_callbackref callback)
int java_demangle_v3_callback(const char *mangled,
demangle_callbackref callback)
enum gnu_v3_ctor_kinds is_gnu_v3_mangled_ctor (const char *name)
enum gnu_v3_dtor_kinds is_gnu_v3_mangled_dtor (const char *name)
Also, the interface to the component list is public, and defined in
demangle.h. The interface consists of these types, which are
defined in demangle.h:
enum demangle_component_type
struct demangle_component
demangle_callbackref
and these functions defined in this file:
cplus_demangle_fill_name
cplus_demangle_fill_extended_operator
cplus_demangle_fill_ctor
cplus_demangle_fill_dtor
cplus_demangle_print
cplus_demangle_print_callback
and other functions defined in the file cp-demint.c.
This file also defines some other functions and variables which are
only to be used by the file cp-demint.c.
Preprocessor macros you can define while compiling this file:
IN_LIBGCC2
If defined, this file defines the following functions, q.v.:
char *__cxa_demangle (const char *mangled, char *buf, size_t *len,
int *status)
int __gcclibcxx_demangle_callback (const char *,
void (*)
(const char *, size_t, void *),
void *)
instead of cplus_demangle_v3[_callback]() and
java_demangle_v3[_callback]().
IN_GLIBCPP_V3
If defined, this file defines only __cxa_demangle() and
__gcclibcxx_demangle_callback(), and no other publically visible
functions or variables.
STANDALONE_DEMANGLER
If defined, this file defines a main() function which demangles
any arguments, or, if none, demangles stdin.
CP_DEMANGLE_DEBUG
If defined, turns on debugging mode, which prints information on
stdout about the mangled string. This is not generally useful.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#include <malloc.h> // alloca
#endif
//#include "ansidecl.h"
//#include "libiberty.h"
#include "demangle.h"
#include "cp-demangle.h"
/* If IN_GLIBCPP_V3 is defined, some functions are made static. We
also rename them via #define to avoid compiler errors when the
static definition conflicts with the extern declaration in a header
file. */
#ifdef IN_GLIBCPP_V3
#define CP_STATIC_IF_GLIBCPP_V3 static
#define cplus_demangle_fill_name d_fill_name
static int d_fill_name (struct demangle_component *, const char *, int);
#define cplus_demangle_fill_extended_operator d_fill_extended_operator
static int
d_fill_extended_operator (struct demangle_component *, int,
struct demangle_component *);
#define cplus_demangle_fill_ctor d_fill_ctor
static int
d_fill_ctor (struct demangle_component *, enum gnu_v3_ctor_kinds,
struct demangle_component *);
#define cplus_demangle_fill_dtor d_fill_dtor
static int
d_fill_dtor (struct demangle_component *, enum gnu_v3_dtor_kinds,
struct demangle_component *);
#define cplus_demangle_mangled_name d_mangled_name
static struct demangle_component *d_mangled_name (struct d_info *, int);
#define cplus_demangle_type d_type
static struct demangle_component *d_type (struct d_info *);
#define cplus_demangle_print d_print
static char *d_print (int, const struct demangle_component *, int, size_t *);
#define cplus_demangle_print_callback d_print_callback
static int d_print_callback (int, const struct demangle_component *,
demangle_callbackref, void *);
#define cplus_demangle_init_info d_init_info
static void d_init_info (const char *, int, size_t, struct d_info *);
#else /* ! defined(IN_GLIBCPP_V3) */
#define CP_STATIC_IF_GLIBCPP_V3
#endif /* ! defined(IN_GLIBCPP_V3) */
/* See if the compiler supports dynamic arrays. */
#ifdef __GNUC__
#define CP_DYNAMIC_ARRAYS
#else
#ifdef __STDC__
#ifdef __STDC_VERSION__
#if __STDC_VERSION__ >= 199901L
#define CP_DYNAMIC_ARRAYS
#endif /* __STDC__VERSION >= 199901L */
#endif /* defined (__STDC_VERSION__) */
#endif /* defined (__STDC__) */
#endif /* ! defined (__GNUC__) */
/* We avoid pulling in the ctype tables, to prevent pulling in
additional unresolved symbols when this code is used in a library.
FIXME: Is this really a valid reason? This comes from the original
V3 demangler code.
As of this writing this file has the following undefined references
when compiled with -DIN_GLIBCPP_V3: realloc, free, memcpy, strcpy,
strcat, strlen. */
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
/* The prefix prepended by GCC to an identifier represnting the
anonymous namespace. */
#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_"
#define ANONYMOUS_NAMESPACE_PREFIX_LEN \
(sizeof (ANONYMOUS_NAMESPACE_PREFIX) - 1)
/* Information we keep for the standard substitutions. */
struct d_standard_sub_info
{
/* The code for this substitution. */
char code;
/* The simple string it expands to. */
const char *simple_expansion;
/* The length of the simple expansion. */
int simple_len;
/* The results of a full, verbose, expansion. This is used when
qualifying a constructor/destructor, or when in verbose mode. */
const char *full_expansion;
/* The length of the full expansion. */
int full_len;
/* What to set the last_name field of d_info to; NULL if we should
not set it. This is only relevant when qualifying a
constructor/destructor. */
const char *set_last_name;
/* The length of set_last_name. */
int set_last_name_len;
};
/* Accessors for subtrees of struct demangle_component. */
#define d_left(dc) ((dc)->u.s_binary.left)
#define d_right(dc) ((dc)->u.s_binary.right)
/* A list of templates. This is used while printing. */
struct d_print_template
{
/* Next template on the list. */
struct d_print_template *next;
/* This template. */
const struct demangle_component *template_decl;
};
/* A list of type modifiers. This is used while printing. */
struct d_print_mod
{
/* Next modifier on the list. These are in the reverse of the order
in which they appeared in the mangled string. */
struct d_print_mod *next;
/* The modifier. */
const struct demangle_component *mod;
/* Whether this modifier was printed. */
int printed;
/* The list of templates which applies to this modifier. */
struct d_print_template *templates;
};
/* We use these structures to hold information during printing. */
struct d_growable_string
{
/* Buffer holding the result. */
char *buf;
/* Current length of data in buffer. */
size_t len;
/* Allocated size of buffer. */
size_t alc;
/* Set to 1 if we had a memory allocation failure. */
int allocation_failure;
};
/* A demangle component and some scope captured when it was first
traversed. */
struct d_saved_scope
{
/* The component whose scope this is. */
const struct demangle_component *container;
/* The list of templates, if any, that was current when this
scope was captured. */
struct d_print_template *templates;
};
/* Checkpoint structure to allow backtracking. This holds copies
of the fields of struct d_info that need to be restored
if a trial parse needs to be backtracked over. */
struct d_info_checkpoint
{
const char *n;
int next_comp;
int next_sub;
int did_subs;
int expansion;
};
enum { D_PRINT_BUFFER_LENGTH = 256 };
struct d_print_info
{
/* Fixed-length allocated buffer for demangled data, flushed to the
callback with a NUL termination once full. */
char buf[D_PRINT_BUFFER_LENGTH];
/* Current length of data in buffer. */
size_t len;
/* The last character printed, saved individually so that it survives
any buffer flush. */
char last_char;
/* Callback function to handle demangled buffer flush. */
demangle_callbackref callback;
/* Opaque callback argument. */
void *opaque;
/* The current list of templates, if any. */
struct d_print_template *templates;
/* The current list of modifiers (e.g., pointer, reference, etc.),
if any. */
struct d_print_mod *modifiers;
/* Set to 1 if we saw a demangling error. */
int demangle_failure;
/* The current index into any template argument packs we are using
for printing. */
int pack_index;
/* Number of d_print_flush calls so far. */
unsigned long int flush_count;
/* Array of saved scopes for evaluating substitutions. */
struct d_saved_scope *saved_scopes;
/* Index of the next unused saved scope in the above array. */
int next_saved_scope;
/* Number of saved scopes in the above array. */
int num_saved_scopes;
/* Array of templates for saving into scopes. */
struct d_print_template *copy_templates;
/* Index of the next unused copy template in the above array. */
int next_copy_template;
/* Number of copy templates in the above array. */
int num_copy_templates;
/* The nearest enclosing template, if any. */
const struct demangle_component *current_template;
};
#ifdef CP_DEMANGLE_DEBUG
static void d_dump (struct demangle_component *, int);
#endif
static struct demangle_component *
d_make_empty (struct d_info *);
static struct demangle_component *
d_make_comp (struct d_info *, enum demangle_component_type,
struct demangle_component *,
struct demangle_component *);
static struct demangle_component *
d_make_name (struct d_info *, const char *, int);
static struct demangle_component *
d_make_demangle_mangled_name (struct d_info *, const char *);
static struct demangle_component *
d_make_builtin_type (struct d_info *,
const struct demangle_builtin_type_info *);
static struct demangle_component *
d_make_operator (struct d_info *,
const struct demangle_operator_info *);
static struct demangle_component *
d_make_extended_operator (struct d_info *, int,
struct demangle_component *);
static struct demangle_component *
d_make_ctor (struct d_info *, enum gnu_v3_ctor_kinds,
struct demangle_component *);
static struct demangle_component *
d_make_dtor (struct d_info *, enum gnu_v3_dtor_kinds,
struct demangle_component *);
static struct demangle_component *
d_make_template_param (struct d_info *, long);
static struct demangle_component *
d_make_sub (struct d_info *, const char *, int);
static int
has_return_type (struct demangle_component *);
static int
is_ctor_dtor_or_conversion (struct demangle_component *);
static struct demangle_component *d_encoding (struct d_info *, int);
static struct demangle_component *d_name (struct d_info *);
static struct demangle_component *d_nested_name (struct d_info *);
static struct demangle_component *d_prefix (struct d_info *);
static struct demangle_component *d_unqualified_name (struct d_info *);
static struct demangle_component *d_source_name (struct d_info *);
static long d_number (struct d_info *);
static struct demangle_component *d_identifier (struct d_info *, int);
static struct demangle_component *d_operator_name (struct d_info *);
static struct demangle_component *d_special_name (struct d_info *);
static int d_call_offset (struct d_info *, int);
static struct demangle_component *d_ctor_dtor_name (struct d_info *);
static struct demangle_component **
d_cv_qualifiers (struct d_info *, struct demangle_component **, int);
static struct demangle_component *
d_ref_qualifier (struct d_info *, struct demangle_component *);
static struct demangle_component *
d_function_type (struct d_info *);
static struct demangle_component *
d_bare_function_type (struct d_info *, int);
static struct demangle_component *
d_class_enum_type (struct d_info *);
static struct demangle_component *d_array_type (struct d_info *);
static struct demangle_component *d_vector_type (struct d_info *);
static struct demangle_component *
d_pointer_to_member_type (struct d_info *);
static struct demangle_component *
d_template_param (struct d_info *);
static struct demangle_component *d_template_args (struct d_info *);
static struct demangle_component *
d_template_arg (struct d_info *);
static struct demangle_component *d_expression (struct d_info *);
static struct demangle_component *d_expr_primary (struct d_info *);
static struct demangle_component *d_local_name (struct d_info *);
static int d_discriminator (struct d_info *);
static struct demangle_component *d_lambda (struct d_info *);
static struct demangle_component *d_unnamed_type (struct d_info *);
static struct demangle_component *
d_clone_suffix (struct d_info *, struct demangle_component *);
static int
d_add_substitution (struct d_info *, struct demangle_component *);
static struct demangle_component *d_substitution (struct d_info *, int);
static void d_checkpoint (struct d_info *, struct d_info_checkpoint *);
static void d_backtrack (struct d_info *, struct d_info_checkpoint *);
static void d_growable_string_init (struct d_growable_string *, size_t);
static void
d_growable_string_resize (struct d_growable_string *, size_t);
static void
d_growable_string_append_buffer (struct d_growable_string *,
const char *, size_t);
static void
d_growable_string_callback_adapter (const char *, size_t, void *);
static void
d_print_init (struct d_print_info *, demangle_callbackref, void *,
const struct demangle_component *);
static void d_print_error (struct d_print_info *);
static int d_print_saw_error (struct d_print_info *);
static void d_print_flush (struct d_print_info *);
static void d_append_char (struct d_print_info *, char);
static void d_append_buffer (struct d_print_info *,
const char *, size_t);
static void d_append_string (struct d_print_info *, const char *);
static char d_last_char (struct d_print_info *);
static void
d_print_comp (struct d_print_info *, int, const struct demangle_component *);
static void
d_print_java_identifier (struct d_print_info *, const char *, int);
static void
d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int);
static void
d_print_mod (struct d_print_info *, int, const struct demangle_component *);
static void
d_print_function_type (struct d_print_info *, int,
const struct demangle_component *,
struct d_print_mod *);
static void
d_print_array_type (struct d_print_info *, int,
const struct demangle_component *,
struct d_print_mod *);
static void
d_print_expr_op (struct d_print_info *, int, const struct demangle_component *);
static void
d_print_cast (struct d_print_info *, int, const struct demangle_component *);
static int d_demangle_callback (const char *, int,
demangle_callbackref, void *);
static char *d_demangle (const char *, int, size_t *);
#ifdef CP_DEMANGLE_DEBUG
static void
d_dump (struct demangle_component *dc, int indent)
{
int i;
if (dc == NULL)
{
if (indent == 0)
printf ("failed demangling\n");
return;
}
for (i = 0; i < indent; ++i)
putchar (' ');
switch (dc->type)
{
case DEMANGLE_COMPONENT_NAME:
printf ("name '%.*s'\n", dc->u.s_name.len, dc->u.s_name.s);
return;
case DEMANGLE_COMPONENT_TAGGED_NAME:
printf ("tagged name\n");
d_dump (dc->u.s_binary.left, indent + 2);
d_dump (dc->u.s_binary.right, indent + 2);
return;
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
printf ("template parameter %ld\n", dc->u.s_number.number);
return;
case DEMANGLE_COMPONENT_CTOR:
printf ("constructor %d\n", (int) dc->u.s_ctor.kind);
d_dump (dc->u.s_ctor.name, indent + 2);
return;
case DEMANGLE_COMPONENT_DTOR:
printf ("destructor %d\n", (int) dc->u.s_dtor.kind);
d_dump (dc->u.s_dtor.name, indent + 2);
return;
case DEMANGLE_COMPONENT_SUB_STD:
printf ("standard substitution %s\n", dc->u.s_string.string);
return;
case DEMANGLE_COMPONENT_BUILTIN_TYPE:
printf ("builtin type %s\n", dc->u.s_builtin.type->name);
return;
case DEMANGLE_COMPONENT_OPERATOR:
printf ("operator %s\n", dc->u.s_operator.op->name);
return;
case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
printf ("extended operator with %d args\n",
dc->u.s_extended_operator.args);
d_dump (dc->u.s_extended_operator.name, indent + 2);
return;
case DEMANGLE_COMPONENT_QUAL_NAME:
printf ("qualified name\n");
break;
case DEMANGLE_COMPONENT_LOCAL_NAME:
printf ("local name\n");
break;
case DEMANGLE_COMPONENT_TYPED_NAME:
printf ("typed name\n");
break;
case DEMANGLE_COMPONENT_TEMPLATE:
printf ("template\n");
break;
case DEMANGLE_COMPONENT_VTABLE:
printf ("vtable\n");
break;
case DEMANGLE_COMPONENT_VTT:
printf ("VTT\n");
break;
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
printf ("construction vtable\n");
break;
case DEMANGLE_COMPONENT_TYPEINFO:
printf ("typeinfo\n");
break;
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
printf ("typeinfo name\n");
break;
case DEMANGLE_COMPONENT_TYPEINFO_FN:
printf ("typeinfo function\n");
break;
case DEMANGLE_COMPONENT_THUNK:
printf ("thunk\n");
break;
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
printf ("virtual thunk\n");
break;
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
printf ("covariant thunk\n");
break;
case DEMANGLE_COMPONENT_JAVA_CLASS:
printf ("java class\n");
break;
case DEMANGLE_COMPONENT_GUARD:
printf ("guard\n");
break;
case DEMANGLE_COMPONENT_REFTEMP:
printf ("reference temporary\n");
break;
case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
printf ("hidden alias\n");
break;
case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
printf ("transaction clone\n");
break;
case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
printf ("non-transaction clone\n");
break;
case DEMANGLE_COMPONENT_RESTRICT:
printf ("restrict\n");
break;
case DEMANGLE_COMPONENT_VOLATILE:
printf ("volatile\n");
break;
case DEMANGLE_COMPONENT_CONST:
printf ("const\n");
break;
case DEMANGLE_COMPONENT_RESTRICT_THIS:
printf ("restrict this\n");
break;
case DEMANGLE_COMPONENT_VOLATILE_THIS:
printf ("volatile this\n");
break;
case DEMANGLE_COMPONENT_CONST_THIS:
printf ("const this\n");
break;
case DEMANGLE_COMPONENT_REFERENCE_THIS:
printf ("reference this\n");
break;
case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
printf ("rvalue reference this\n");
break;
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
printf ("vendor type qualifier\n");
break;
case DEMANGLE_COMPONENT_POINTER:
printf ("pointer\n");
break;
case DEMANGLE_COMPONENT_REFERENCE:
printf ("reference\n");
break;
case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
printf ("rvalue reference\n");
break;
case DEMANGLE_COMPONENT_COMPLEX:
printf ("complex\n");
break;
case DEMANGLE_COMPONENT_IMAGINARY:
printf ("imaginary\n");
break;
case DEMANGLE_COMPONENT_VENDOR_TYPE:
printf ("vendor type\n");
break;
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
printf ("function type\n");
break;
case DEMANGLE_COMPONENT_ARRAY_TYPE:
printf ("array type\n");
break;
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
printf ("pointer to member type\n");
break;
case DEMANGLE_COMPONENT_FIXED_TYPE:
printf ("fixed-point type\n");
break;
case DEMANGLE_COMPONENT_ARGLIST:
printf ("argument list\n");
break;
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
printf ("template argument list\n");
break;
case DEMANGLE_COMPONENT_INITIALIZER_LIST:
printf ("initializer list\n");
break;
case DEMANGLE_COMPONENT_CAST:
printf ("cast\n");
break;
case DEMANGLE_COMPONENT_NULLARY:
printf ("nullary operator\n");
break;
case DEMANGLE_COMPONENT_UNARY:
printf ("unary operator\n");
break;
case DEMANGLE_COMPONENT_BINARY:
printf ("binary operator\n");
break;
case DEMANGLE_COMPONENT_BINARY_ARGS:
printf ("binary operator arguments\n");
break;
case DEMANGLE_COMPONENT_TRINARY:
printf ("trinary operator\n");
break;
case DEMANGLE_COMPONENT_TRINARY_ARG1:
printf ("trinary operator arguments 1\n");
break;
case DEMANGLE_COMPONENT_TRINARY_ARG2:
printf ("trinary operator arguments 1\n");
break;
case DEMANGLE_COMPONENT_LITERAL:
printf ("literal\n");
break;
case DEMANGLE_COMPONENT_LITERAL_NEG:
printf ("negative literal\n");
break;
case DEMANGLE_COMPONENT_JAVA_RESOURCE:
printf ("java resource\n");
break;
case DEMANGLE_COMPONENT_COMPOUND_NAME:
printf ("compound name\n");
break;
case DEMANGLE_COMPONENT_CHARACTER:
printf ("character '%c'\n", dc->u.s_character.character);
return;
case DEMANGLE_COMPONENT_DECLTYPE:
printf ("decltype\n");
break;
case DEMANGLE_COMPONENT_PACK_EXPANSION:
printf ("pack expansion\n");
break;
case DEMANGLE_COMPONENT_TLS_INIT:
printf ("tls init function\n");
break;
case DEMANGLE_COMPONENT_TLS_WRAPPER:
printf ("tls wrapper function\n");
break;
case DEMANGLE_COMPONENT_DEFAULT_ARG:
printf ("default argument %d\n", dc->u.s_unary_num.num);
d_dump (dc->u.s_unary_num.sub, indent+2);
return;
case DEMANGLE_COMPONENT_LAMBDA:
printf ("lambda %d\n", dc->u.s_unary_num.num);
d_dump (dc->u.s_unary_num.sub, indent+2);
return;
}
d_dump (d_left (dc), indent + 2);
d_dump (d_right (dc), indent + 2);
}
#endif /* CP_DEMANGLE_DEBUG */
/* Fill in a DEMANGLE_COMPONENT_NAME. */
CP_STATIC_IF_GLIBCPP_V3
int
cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
{
if (p == NULL || s == NULL || len == 0)
return 0;
p->type = DEMANGLE_COMPONENT_NAME;
p->u.s_name.s = s;
p->u.s_name.len = len;
return 1;
}
/* Fill in a DEMANGLE_COMPONENT_EXTENDED_OPERATOR. */
CP_STATIC_IF_GLIBCPP_V3
int
cplus_demangle_fill_extended_operator (struct demangle_component *p, int args,
struct demangle_component *name)
{
if (p == NULL || args < 0 || name == NULL)
return 0;
p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
p->u.s_extended_operator.args = args;
p->u.s_extended_operator.name = name;
return 1;
}
/* Fill in a DEMANGLE_COMPONENT_CTOR. */
CP_STATIC_IF_GLIBCPP_V3
int
cplus_demangle_fill_ctor (struct demangle_component *p,
enum gnu_v3_ctor_kinds kind,
struct demangle_component *name)
{
if (p == NULL
|| name == NULL
|| (int) kind < gnu_v3_complete_object_ctor
|| (int) kind > gnu_v3_object_ctor_group)
return 0;
p->type = DEMANGLE_COMPONENT_CTOR;
p->u.s_ctor.kind = kind;
p->u.s_ctor.name = name;
return 1;
}
/* Fill in a DEMANGLE_COMPONENT_DTOR. */
CP_STATIC_IF_GLIBCPP_V3
int
cplus_demangle_fill_dtor (struct demangle_component *p,
enum gnu_v3_dtor_kinds kind,
struct demangle_component *name)
{
if (p == NULL
|| name == NULL
|| (int) kind < gnu_v3_deleting_dtor
|| (int) kind > gnu_v3_object_dtor_group)
return 0;
p->type = DEMANGLE_COMPONENT_DTOR;
p->u.s_dtor.kind = kind;
p->u.s_dtor.name = name;
return 1;
}
/* Add a new component. */
static struct demangle_component *
d_make_empty (struct d_info *di)
{
struct demangle_component *p;
if (di->next_comp >= di->num_comps)
return NULL;
p = &di->comps[di->next_comp];
++di->next_comp;
return p;
}
/* Add a new generic component. */
static struct demangle_component *
d_make_comp (struct d_info *di, enum demangle_component_type type,
struct demangle_component *left,
struct demangle_component *right)
{
struct demangle_component *p;
/* We check for errors here. A typical error would be a NULL return
from a subroutine. We catch those here, and return NULL
upward. */
switch (type)
{
/* These types require two parameters. */
case DEMANGLE_COMPONENT_QUAL_NAME:
case DEMANGLE_COMPONENT_LOCAL_NAME:
case DEMANGLE_COMPONENT_TYPED_NAME:
case DEMANGLE_COMPONENT_TAGGED_NAME:
case DEMANGLE_COMPONENT_TEMPLATE:
case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE:
case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
case DEMANGLE_COMPONENT_UNARY:
case DEMANGLE_COMPONENT_BINARY:
case DEMANGLE_COMPONENT_BINARY_ARGS:
case DEMANGLE_COMPONENT_TRINARY:
case DEMANGLE_COMPONENT_TRINARY_ARG1:
case DEMANGLE_COMPONENT_LITERAL:
case DEMANGLE_COMPONENT_LITERAL_NEG:
case DEMANGLE_COMPONENT_COMPOUND_NAME:
case DEMANGLE_COMPONENT_VECTOR_TYPE:
case DEMANGLE_COMPONENT_CLONE:
if (left == NULL || right == NULL)
return NULL;
break;
/* These types only require one parameter. */
case DEMANGLE_COMPONENT_VTABLE:
case DEMANGLE_COMPONENT_VTT:
case DEMANGLE_COMPONENT_TYPEINFO:
case DEMANGLE_COMPONENT_TYPEINFO_NAME:
case DEMANGLE_COMPONENT_TYPEINFO_FN:
case DEMANGLE_COMPONENT_THUNK:
case DEMANGLE_COMPONENT_VIRTUAL_THUNK:
case DEMANGLE_COMPONENT_COVARIANT_THUNK:
case DEMANGLE_COMPONENT_JAVA_CLASS:
case DEMANGLE_COMPONENT_GUARD:
case DEMANGLE_COMPONENT_TLS_INIT:
case DEMANGLE_COMPONENT_TLS_WRAPPER:
case DEMANGLE_COMPONENT_REFTEMP:
case DEMANGLE_COMPONENT_HIDDEN_ALIAS:
case DEMANGLE_COMPONENT_TRANSACTION_CLONE:
case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE:
case DEMANGLE_COMPONENT_POINTER:
case DEMANGLE_COMPONENT_REFERENCE:
case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
case DEMANGLE_COMPONENT_COMPLEX:
case DEMANGLE_COMPONENT_IMAGINARY:
case DEMANGLE_COMPONENT_VENDOR_TYPE:
case DEMANGLE_COMPONENT_CAST:
case DEMANGLE_COMPONENT_JAVA_RESOURCE:
case DEMANGLE_COMPONENT_DECLTYPE:
case DEMANGLE_COMPONENT_PACK_EXPANSION:
case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
case DEMANGLE_COMPONENT_NULLARY:
case DEMANGLE_COMPONENT_TRINARY_ARG2:
if (left == NULL)
return NULL;
break;
/* This needs a right parameter, but the left parameter can be
empty. */
case DEMANGLE_COMPONENT_ARRAY_TYPE:
case DEMANGLE_COMPONENT_INITIALIZER_LIST:
if (right == NULL)
return NULL;
break;
/* These are allowed to have no parameters--in some cases they
will be filled in later. */
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
case DEMANGLE_COMPONENT_RESTRICT:
case DEMANGLE_COMPONENT_VOLATILE:
case DEMANGLE_COMPONENT_CONST:
case DEMANGLE_COMPONENT_RESTRICT_THIS:
case DEMANGLE_COMPONENT_VOLATILE_THIS:
case DEMANGLE_COMPONENT_CONST_THIS:
case DEMANGLE_COMPONENT_REFERENCE_THIS:
case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
case DEMANGLE_COMPONENT_ARGLIST:
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
break;
/* Other types should not be seen here. */
default:
return NULL;
}
p = d_make_empty (di);
if (p != NULL)
{
p->type = type;
p->u.s_binary.left = left;
p->u.s_binary.right = right;
}
return p;
}
/* Add a new demangle mangled name component. */
static struct demangle_component *
d_make_demangle_mangled_name (struct d_info *di, const char *s)
{
if (d_peek_char (di) != '_' || d_peek_next_char (di) != 'Z')
return d_make_name (di, s, strlen (s));
d_advance (di, 2);
return d_encoding (di, 0);
}
/* Add a new name component. */
static struct demangle_component *
d_make_name (struct d_info *di, const char *s, int len)
{
struct demangle_component *p;
p = d_make_empty (di);
if (! cplus_demangle_fill_name (p, s, len))
return NULL;
return p;
}
/* Add a new builtin type component. */
static struct demangle_component *
d_make_builtin_type (struct d_info *di,
const struct demangle_builtin_type_info *type)
{
struct demangle_component *p;
if (type == NULL)
return NULL;
p = d_make_empty (di);
if (p != NULL)
{
p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
p->u.s_builtin.type = type;
}
return p;
}
/* Add a new operator component. */
static struct demangle_component *
d_make_operator (struct d_info *di, const struct demangle_operator_info *op)
{
struct demangle_component *p;
p = d_make_empty (di);
if (p != NULL)