-
Notifications
You must be signed in to change notification settings - Fork 544
/
rust-demangle.c
1575 lines (1364 loc) · 33.9 KB
/
rust-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 the Rust programming language
Copyright (C) 2016-2022 Free Software Foundation, Inc.
Written by David Tolnay (dtolnay@gmail.com).
Rewritten by Eduard-Mihai Burtescu (eddyb@lyken.rs) for v0 support.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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 Library 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 Library 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.)
Libiberty 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "safe-ctype.h"
#include <inttypes.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
extern size_t strlen(const char *s);
extern int strncmp(const char *s1, const char *s2, size_t n);
extern void *memset(void *s, int c, size_t n);
#endif
#include <demangle.h>
#include "libiberty.h"
struct rust_demangler
{
const char *sym;
size_t sym_len;
void *callback_opaque;
demangle_callbackref callback;
/* Position of the next character to read from the symbol. */
size_t next;
/* Non-zero if any error occurred. */
int errored;
/* Non-zero if nothing should be printed. */
int skipping_printing;
/* Non-zero if printing should be verbose (e.g. include hashes). */
int verbose;
/* Rust mangling version, with legacy mangling being -1. */
int version;
/* Recursion depth. */
unsigned int recursion;
/* Maximum number of times demangle_path may be called recursively. */
#define RUST_MAX_RECURSION_COUNT 1024
#define RUST_NO_RECURSION_LIMIT ((unsigned int) -1)
uint64_t bound_lifetime_depth;
};
/* Parsing functions. */
static char
peek (const struct rust_demangler *rdm)
{
if (rdm->next < rdm->sym_len)
return rdm->sym[rdm->next];
return 0;
}
static int
eat (struct rust_demangler *rdm, char c)
{
if (peek (rdm) == c)
{
rdm->next++;
return 1;
}
else
return 0;
}
static char
next (struct rust_demangler *rdm)
{
char c = peek (rdm);
if (!c)
rdm->errored = 1;
else
rdm->next++;
return c;
}
static uint64_t
parse_integer_62 (struct rust_demangler *rdm)
{
char c;
uint64_t x;
if (eat (rdm, '_'))
return 0;
x = 0;
while (!eat (rdm, '_'))
{
c = next (rdm);
x *= 62;
if (ISDIGIT (c))
x += c - '0';
else if (ISLOWER (c))
x += 10 + (c - 'a');
else if (ISUPPER (c))
x += 10 + 26 + (c - 'A');
else
{
rdm->errored = 1;
return 0;
}
}
return x + 1;
}
static uint64_t
parse_opt_integer_62 (struct rust_demangler *rdm, char tag)
{
if (!eat (rdm, tag))
return 0;
return 1 + parse_integer_62 (rdm);
}
static uint64_t
parse_disambiguator (struct rust_demangler *rdm)
{
return parse_opt_integer_62 (rdm, 's');
}
static size_t
parse_hex_nibbles (struct rust_demangler *rdm, uint64_t *value)
{
char c;
size_t hex_len;
hex_len = 0;
*value = 0;
while (!eat (rdm, '_'))
{
*value <<= 4;
c = next (rdm);
if (ISDIGIT (c))
*value |= c - '0';
else if (c >= 'a' && c <= 'f')
*value |= 10 + (c - 'a');
else
{
rdm->errored = 1;
return 0;
}
hex_len++;
}
return hex_len;
}
struct rust_mangled_ident
{
/* ASCII part of the identifier. */
const char *ascii;
size_t ascii_len;
/* Punycode insertion codes for Unicode codepoints, if any. */
const char *punycode;
size_t punycode_len;
};
static struct rust_mangled_ident
parse_ident (struct rust_demangler *rdm)
{
char c;
size_t start, len;
int is_punycode = 0;
struct rust_mangled_ident ident;
ident.ascii = NULL;
ident.ascii_len = 0;
ident.punycode = NULL;
ident.punycode_len = 0;
if (rdm->version != -1)
is_punycode = eat (rdm, 'u');
c = next (rdm);
if (!ISDIGIT (c))
{
rdm->errored = 1;
return ident;
}
len = c - '0';
if (c != '0')
while (ISDIGIT (peek (rdm)))
len = len * 10 + (next (rdm) - '0');
/* Skip past the optional `_` separator (v0). */
if (rdm->version != -1)
eat (rdm, '_');
start = rdm->next;
rdm->next += len;
/* Check for overflows. */
if ((start > rdm->next) || (rdm->next > rdm->sym_len))
{
rdm->errored = 1;
return ident;
}
ident.ascii = rdm->sym + start;
ident.ascii_len = len;
if (is_punycode)
{
ident.punycode_len = 0;
while (ident.ascii_len > 0)
{
ident.ascii_len--;
/* The last '_' is a separator between ascii & punycode. */
if (ident.ascii[ident.ascii_len] == '_')
break;
ident.punycode_len++;
}
if (!ident.punycode_len)
{
rdm->errored = 1;
return ident;
}
ident.punycode = ident.ascii + (len - ident.punycode_len);
}
if (ident.ascii_len == 0)
ident.ascii = NULL;
return ident;
}
/* Printing functions. */
static void
print_str (struct rust_demangler *rdm, const char *data, size_t len)
{
if (!rdm->errored && !rdm->skipping_printing)
rdm->callback (data, len, rdm->callback_opaque);
}
#define PRINT(s) print_str (rdm, s, strlen (s))
static void
print_uint64 (struct rust_demangler *rdm, uint64_t x)
{
char s[21];
snprintf (s, 21, "%" PRIu64, x);
PRINT (s);
}
static void
print_uint64_hex (struct rust_demangler *rdm, uint64_t x)
{
char s[17];
snprintf (s, 17, "%" PRIx64, x);
PRINT (s);
}
/* Return a 0x0-0xf value if the char is 0-9a-f, and -1 otherwise. */
static int
decode_lower_hex_nibble (char nibble)
{
if ('0' <= nibble && nibble <= '9')
return nibble - '0';
if ('a' <= nibble && nibble <= 'f')
return 0xa + (nibble - 'a');
return -1;
}
/* Return the unescaped character for a "$...$" escape, or 0 if invalid. */
static char
decode_legacy_escape (const char *e, size_t len, size_t *out_len)
{
char c = 0;
size_t escape_len = 0;
int lo_nibble = -1, hi_nibble = -1;
if (len < 3 || e[0] != '$')
return 0;
e++;
len--;
if (e[0] == 'C')
{
escape_len = 1;
c = ',';
}
else if (len > 2)
{
escape_len = 2;
if (e[0] == 'S' && e[1] == 'P')
c = '@';
else if (e[0] == 'B' && e[1] == 'P')
c = '*';
else if (e[0] == 'R' && e[1] == 'F')
c = '&';
else if (e[0] == 'L' && e[1] == 'T')
c = '<';
else if (e[0] == 'G' && e[1] == 'T')
c = '>';
else if (e[0] == 'L' && e[1] == 'P')
c = '(';
else if (e[0] == 'R' && e[1] == 'P')
c = ')';
else if (e[0] == 'u' && len > 3)
{
escape_len = 3;
hi_nibble = decode_lower_hex_nibble (e[1]);
if (hi_nibble < 0)
return 0;
lo_nibble = decode_lower_hex_nibble (e[2]);
if (lo_nibble < 0)
return 0;
/* Only allow non-control ASCII characters. */
if (hi_nibble > 7)
return 0;
c = (hi_nibble << 4) | lo_nibble;
if (c < 0x20)
return 0;
}
}
if (!c || len <= escape_len || e[escape_len] != '$')
return 0;
*out_len = 2 + escape_len;
return c;
}
static void
print_ident (struct rust_demangler *rdm, struct rust_mangled_ident ident)
{
char unescaped;
uint8_t *out, *p, d;
size_t len, cap, punycode_pos, j;
/* Punycode parameters and state. */
uint32_t c;
size_t base, t_min, t_max, skew, damp, bias, i;
size_t delta, w, k, t;
if (rdm->errored || rdm->skipping_printing)
return;
if (rdm->version == -1)
{
/* Ignore leading underscores preceding escape sequences.
The mangler inserts an underscore to make sure the
identifier begins with a XID_Start character. */
if (ident.ascii_len >= 2 && ident.ascii[0] == '_'
&& ident.ascii[1] == '$')
{
ident.ascii++;
ident.ascii_len--;
}
while (ident.ascii_len > 0)
{
/* Handle legacy escape sequences ("$...$", ".." or "."). */
if (ident.ascii[0] == '$')
{
unescaped
= decode_legacy_escape (ident.ascii, ident.ascii_len, &len);
if (unescaped)
print_str (rdm, &unescaped, 1);
else
{
/* Unexpected escape sequence, print the rest verbatim. */
print_str (rdm, ident.ascii, ident.ascii_len);
return;
}
}
else if (ident.ascii[0] == '.')
{
if (ident.ascii_len >= 2 && ident.ascii[1] == '.')
{
/* ".." becomes "::" */
PRINT ("::");
len = 2;
}
else
{
PRINT (".");
len = 1;
}
}
else
{
/* Print everything before the next escape sequence, at once. */
for (len = 0; len < ident.ascii_len; len++)
if (ident.ascii[len] == '$' || ident.ascii[len] == '.')
break;
print_str (rdm, ident.ascii, len);
}
ident.ascii += len;
ident.ascii_len -= len;
}
return;
}
if (!ident.punycode)
{
print_str (rdm, ident.ascii, ident.ascii_len);
return;
}
len = 0;
cap = 4;
while (cap < ident.ascii_len)
{
cap *= 2;
/* Check for overflows. */
if ((cap * 4) / 4 != cap)
{
rdm->errored = 1;
return;
}
}
/* Store the output codepoints as groups of 4 UTF-8 bytes. */
out = (uint8_t *)malloc (cap * 4);
if (!out)
{
rdm->errored = 1;
return;
}
/* Populate initial output from ASCII fragment. */
for (len = 0; len < ident.ascii_len; len++)
{
p = out + 4 * len;
p[0] = 0;
p[1] = 0;
p[2] = 0;
p[3] = ident.ascii[len];
}
/* Punycode parameters and initial state. */
base = 36;
t_min = 1;
t_max = 26;
skew = 38;
damp = 700;
bias = 72;
i = 0;
c = 0x80;
punycode_pos = 0;
while (punycode_pos < ident.punycode_len)
{
/* Read one delta value. */
delta = 0;
w = 1;
k = 0;
do
{
k += base;
t = k < bias ? 0 : (k - bias);
if (t < t_min)
t = t_min;
if (t > t_max)
t = t_max;
if (punycode_pos >= ident.punycode_len)
goto cleanup;
d = ident.punycode[punycode_pos++];
if (ISLOWER (d))
d = d - 'a';
else if (ISDIGIT (d))
d = 26 + (d - '0');
else
{
rdm->errored = 1;
goto cleanup;
}
delta += d * w;
w *= base - t;
}
while (d >= t);
/* Compute the new insert position and character. */
len++;
i += delta;
c += i / len;
i %= len;
/* Ensure enough space is available. */
if (cap < len)
{
cap *= 2;
/* Check for overflows. */
if ((cap * 4) / 4 != cap || cap < len)
{
rdm->errored = 1;
goto cleanup;
}
}
p = (uint8_t *)realloc (out, cap * 4);
if (!p)
{
rdm->errored = 1;
goto cleanup;
}
out = p;
/* Move the characters after the insert position. */
p = out + i * 4;
memmove (p + 4, p, (len - i - 1) * 4);
/* Insert the new character, as UTF-8 bytes. */
p[0] = c >= 0x10000 ? 0xf0 | (c >> 18) : 0;
p[1] = c >= 0x800 ? (c < 0x10000 ? 0xe0 : 0x80) | ((c >> 12) & 0x3f) : 0;
p[2] = (c < 0x800 ? 0xc0 : 0x80) | ((c >> 6) & 0x3f);
p[3] = 0x80 | (c & 0x3f);
/* If there are no more deltas, decoding is complete. */
if (punycode_pos == ident.punycode_len)
break;
i++;
/* Perform bias adaptation. */
delta /= damp;
damp = 2;
delta += delta / len;
k = 0;
while (delta > ((base - t_min) * t_max) / 2)
{
delta /= base - t_min;
k += base;
}
bias = k + ((base - t_min + 1) * delta) / (delta + skew);
}
/* Remove all the 0 bytes to leave behind an UTF-8 string. */
for (i = 0, j = 0; i < len * 4; i++)
if (out[i] != 0)
out[j++] = out[i];
print_str (rdm, (const char *)out, j);
cleanup:
free (out);
}
/* Print the lifetime according to the previously decoded index.
An index of `0` always refers to `'_`, but starting with `1`,
indices refer to late-bound lifetimes introduced by a binder. */
static void
print_lifetime_from_index (struct rust_demangler *rdm, uint64_t lt)
{
char c;
uint64_t depth;
PRINT ("'");
if (lt == 0)
{
PRINT ("_");
return;
}
depth = rdm->bound_lifetime_depth - lt;
/* Try to print lifetimes alphabetically first. */
if (depth < 26)
{
c = 'a' + depth;
print_str (rdm, &c, 1);
}
else
{
/* Use `'_123` after running out of letters. */
PRINT ("_");
print_uint64 (rdm, depth);
}
}
/* Demangling functions. */
static void demangle_binder (struct rust_demangler *rdm);
static void demangle_path (struct rust_demangler *rdm, int in_value);
static void demangle_generic_arg (struct rust_demangler *rdm);
static void demangle_type (struct rust_demangler *rdm);
static int demangle_path_maybe_open_generics (struct rust_demangler *rdm);
static void demangle_dyn_trait (struct rust_demangler *rdm);
static void demangle_const (struct rust_demangler *rdm);
static void demangle_const_uint (struct rust_demangler *rdm);
static void demangle_const_int (struct rust_demangler *rdm);
static void demangle_const_bool (struct rust_demangler *rdm);
static void demangle_const_char (struct rust_demangler *rdm);
/* Optionally enter a binder ('G') for late-bound lifetimes,
printing e.g. `for<'a, 'b> `, and make those lifetimes visible
to the caller (via depth level, which the caller should reset). */
static void
demangle_binder (struct rust_demangler *rdm)
{
uint64_t i, bound_lifetimes;
if (rdm->errored)
return;
bound_lifetimes = parse_opt_integer_62 (rdm, 'G');
if (bound_lifetimes > 0)
{
PRINT ("for<");
for (i = 0; i < bound_lifetimes; i++)
{
if (i > 0)
PRINT (", ");
rdm->bound_lifetime_depth++;
print_lifetime_from_index (rdm, 1);
}
PRINT ("> ");
}
}
static void
demangle_path (struct rust_demangler *rdm, int in_value)
{
char tag, ns;
int was_skipping_printing;
size_t i, backref, old_next;
uint64_t dis;
struct rust_mangled_ident name;
if (rdm->errored)
return;
if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
{
++ rdm->recursion;
if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
/* FIXME: There ought to be a way to report
that the recursion limit has been reached. */
goto fail_return;
}
switch (tag = next (rdm))
{
case 'C':
dis = parse_disambiguator (rdm);
name = parse_ident (rdm);
print_ident (rdm, name);
if (rdm->verbose)
{
PRINT ("[");
print_uint64_hex (rdm, dis);
PRINT ("]");
}
break;
case 'N':
ns = next (rdm);
if (!ISLOWER (ns) && !ISUPPER (ns))
goto fail_return;
demangle_path (rdm, in_value);
dis = parse_disambiguator (rdm);
name = parse_ident (rdm);
if (ISUPPER (ns))
{
/* Special namespaces, like closures and shims. */
PRINT ("::{");
switch (ns)
{
case 'C':
PRINT ("closure");
break;
case 'S':
PRINT ("shim");
break;
default:
print_str (rdm, &ns, 1);
}
if (name.ascii || name.punycode)
{
PRINT (":");
print_ident (rdm, name);
}
PRINT ("#");
print_uint64 (rdm, dis);
PRINT ("}");
}
else
{
/* Implementation-specific/unspecified namespaces. */
if (name.ascii || name.punycode)
{
PRINT ("::");
print_ident (rdm, name);
}
}
break;
case 'M':
case 'X':
/* Ignore the `impl`'s own path.*/
parse_disambiguator (rdm);
was_skipping_printing = rdm->skipping_printing;
rdm->skipping_printing = 1;
demangle_path (rdm, in_value);
rdm->skipping_printing = was_skipping_printing;
/* fallthrough */
case 'Y':
PRINT ("<");
demangle_type (rdm);
if (tag != 'M')
{
PRINT (" as ");
demangle_path (rdm, 0);
}
PRINT (">");
break;
case 'I':
demangle_path (rdm, in_value);
if (in_value)
PRINT ("::");
PRINT ("<");
for (i = 0; !rdm->errored && !eat (rdm, 'E'); i++)
{
if (i > 0)
PRINT (", ");
demangle_generic_arg (rdm);
}
PRINT (">");
break;
case 'B':
backref = parse_integer_62 (rdm);
if (!rdm->skipping_printing)
{
old_next = rdm->next;
rdm->next = backref;
demangle_path (rdm, in_value);
rdm->next = old_next;
}
break;
default:
goto fail_return;
}
goto pass_return;
fail_return:
rdm->errored = 1;
pass_return:
if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
-- rdm->recursion;
}
static void
demangle_generic_arg (struct rust_demangler *rdm)
{
uint64_t lt;
if (eat (rdm, 'L'))
{
lt = parse_integer_62 (rdm);
print_lifetime_from_index (rdm, lt);
}
else if (eat (rdm, 'K'))
demangle_const (rdm);
else
demangle_type (rdm);
}
static const char *
basic_type (char tag)
{
switch (tag)
{
case 'b':
return "bool";
case 'c':
return "char";
case 'e':
return "str";
case 'u':
return "()";
case 'a':
return "i8";
case 's':
return "i16";
case 'l':
return "i32";
case 'x':
return "i64";
case 'n':
return "i128";
case 'i':
return "isize";
case 'h':
return "u8";
case 't':
return "u16";
case 'm':
return "u32";
case 'y':
return "u64";
case 'o':
return "u128";
case 'j':
return "usize";
case 'f':
return "f32";
case 'd':
return "f64";
case 'z':
return "!";
case 'p':
return "_";
case 'v':
return "...";
default:
return NULL;
}
}
static void
demangle_type (struct rust_demangler *rdm)
{
char tag;
size_t i, old_next, backref;
uint64_t lt, old_bound_lifetime_depth;
const char *basic;
struct rust_mangled_ident abi;
if (rdm->errored)
return;
tag = next (rdm);
basic = basic_type (tag);
if (basic)
{
PRINT (basic);
return;
}
if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
{
++ rdm->recursion;
if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
/* FIXME: There ought to be a way to report
that the recursion limit has been reached. */
{
rdm->errored = 1;
-- rdm->recursion;
return;
}
}
switch (tag)
{
case 'R':
case 'Q':
PRINT ("&");
if (eat (rdm, 'L'))
{
lt = parse_integer_62 (rdm);
if (lt)
{
print_lifetime_from_index (rdm, lt);
PRINT (" ");
}
}
if (tag != 'R')
PRINT ("mut ");
demangle_type (rdm);
break;
case 'P':
case 'O':
PRINT ("*");
if (tag != 'P')
PRINT ("mut ");
else
PRINT ("const ");
demangle_type (rdm);
break;
case 'A':
case 'S':
PRINT ("[");
demangle_type (rdm);
if (tag == 'A')
{
PRINT ("; ");
demangle_const (rdm);
}
PRINT ("]");
break;
case 'T':
PRINT ("(");
for (i = 0; !rdm->errored && !eat (rdm, 'E'); i++)
{
if (i > 0)
PRINT (", ");
demangle_type (rdm);
}
if (i == 1)
PRINT (",");
PRINT (")");
break;
case 'F':
old_bound_lifetime_depth = rdm->bound_lifetime_depth;
demangle_binder (rdm);
if (eat (rdm, 'U'))
PRINT ("unsafe ");
if (eat (rdm, 'K'))
{
if (eat (rdm, 'C'))
{
abi.ascii = "C";
abi.ascii_len = 1;
}
else
{
abi = parse_ident (rdm);
if (!abi.ascii || abi.punycode)
{
rdm->errored = 1;
goto restore;
}
}
PRINT ("extern \"");
/* If the ABI had any `-`, they were replaced with `_`,
so the parts between `_` have to be re-joined with `-`. */
for (i = 0; i < abi.ascii_len; i++)
{
if (abi.ascii[i] == '_')
{
print_str (rdm, abi.ascii, i);
PRINT ("-");
abi.ascii += i + 1;
abi.ascii_len -= i + 1;
i = 0;
}
}
print_str (rdm, abi.ascii, abi.ascii_len);
PRINT ("\" ");
}
PRINT ("fn(");
for (i = 0; !rdm->errored && !eat (rdm, 'E'); i++)
{