@@ -6179,6 +6179,25 @@ Perl_invmap_dump(pTHX_ SV* invlist, UV *map)
6179
6179
}
6180
6180
}
6181
6181
6182
+ #ifdef DEBUGGING
6183
+
6184
+ static const char *
6185
+ S_get_displayable_tr_operand(pTHX_ const U8 * s, STRLEN len, bool is_utf8)
6186
+ {
6187
+ SV * output = sv_2mortal(newSVpvs(""));
6188
+ if (is_utf8) {
6189
+ return pv_uni_display(output, s, len, 1000, UNI_DISPLAY_TR_);
6190
+ }
6191
+ else {
6192
+ return pv_pretty(output, (const char *) s, len, 256, NULL, NULL,
6193
+ ( PERL_PV_ESCAPE_NONASCII
6194
+ |PERL_PV_PRETTY_LTGT
6195
+ |PERL_PV_PRETTY_ELLIPSES));
6196
+ }
6197
+ }
6198
+
6199
+ #endif
6200
+
6182
6201
/* Given an OP_TRANS / OP_TRANSR op o, plus OP_CONST ops expr and repl
6183
6202
* containing the search and replacement strings, assemble into
6184
6203
* a translation table attached as o->op_pv.
@@ -6528,6 +6547,13 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
6528
6547
6529
6548
PL_hints |= HINT_BLOCK_SCOPE;
6530
6549
6550
+ DEBUG_y(PerlIO_printf(Perl_debug_log,
6551
+ "%s: %d: Compiling tr/*t/*r/; /c=%d; /d=%d; /s=%d\n"
6552
+ "*t is '%s'\n*r is '%s'\n",
6553
+ __FILE__, __LINE__, complement, del, squash,
6554
+ get_displayable_tr_operand(t0, tlen, tstr_utf8),
6555
+ get_displayable_tr_operand(r0, rlen, rstr_utf8)));
6556
+
6531
6557
/* If /c, the search list is sorted and complemented. This is now done by
6532
6558
* creating an inversion list from it, and then trivially inverting that.
6533
6559
* The previous implementation used qsort, but creating the list
@@ -6609,6 +6635,11 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
6609
6635
tend = t0 + temp_len;
6610
6636
tstr_utf8 = TRUE;
6611
6637
6638
+ DEBUG_y(PerlIO_printf(Perl_debug_log,
6639
+ "%s: %d: *t after complementing=\n%s\n",
6640
+ __FILE__, __LINE__,
6641
+ get_displayable_tr_operand(t0, temp_len, tstr_utf8)));
6642
+
6612
6643
SvREFCNT_dec_NN(inverted_tlist);
6613
6644
}
6614
6645
@@ -6788,7 +6819,7 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
6788
6819
#ifdef DEBUGGING
6789
6820
if (DEBUG_y_TEST && ! del) {
6790
6821
PerlIO_printf(Perl_debug_log,
6791
- "final_map =%" UVXf "\n", final_map);
6822
+ "final_map = %" UVXf "\n", final_map);
6792
6823
}
6793
6824
#endif
6794
6825
}
@@ -6904,9 +6935,25 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
6904
6935
* has been set up so that all members in it will be of the same
6905
6936
* ilk) */
6906
6937
if (r_map[i] == TR_UNLISTED) {
6907
- DEBUG_yv(PerlIO_printf(Perl_debug_log,
6908
- "Processing %" UVxf "-%" UVxf " => %" UVxf "-%" UVxf "\n",
6909
- t_cp, t_cp_end, r_cp, r_cp_end));
6938
+
6939
+ #ifdef DEBUGGING
6940
+ if (DEBUG_yv_TEST) {
6941
+ PerlIO_printf(Perl_debug_log,
6942
+ "Processing %" UVxf "-%" UVxf " => ",
6943
+ t_cp, t_cp_end);
6944
+ if (r_cp == r_cp_end && r_cp == TR_UNLISTED) {
6945
+ PerlIO_printf(Perl_debug_log, "TR_UNLISTED\n");
6946
+ }
6947
+ else if (r_cp == r_cp_end && r_cp == TR_SPECIAL_HANDLING) {
6948
+ PerlIO_printf(Perl_debug_log, "TR_SPECIAL_HANDLING\n");
6949
+ }
6950
+ else {
6951
+ PerlIO_printf(Perl_debug_log,
6952
+ "%" UVxf "-%" UVxf "\n",
6953
+ r_cp, r_cp_end);
6954
+ }
6955
+ }
6956
+ #endif
6910
6957
6911
6958
/* This is the first definition for this chunk, hence is valid
6912
6959
* and needs to be processed. Here and in the comments below,
@@ -7418,7 +7465,16 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7418
7465
: (short) TR_R_EMPTY;
7419
7466
#ifdef DEBUGGING
7420
7467
if (DEBUG_y_TEST) {
7421
- PerlIO_printf(Perl_debug_log,"%s: %d\n", __FILE__, __LINE__);
7468
+ PerlIO_printf(Perl_debug_log,
7469
+ "\n%s: %d: Final generated translation table:\n %"
7470
+ IVdf " means this char not involved in this transliteration\n",
7471
+ __FILE__, __LINE__, TR_UNLISTED);
7472
+ if (del) {
7473
+ PerlIO_printf(Perl_debug_log,
7474
+ " %" IVdf " means delete this char\n",
7475
+ TR_SPECIAL_HANDLING);
7476
+ }
7477
+
7422
7478
for (i = 0; i < tbl->size; i++) {
7423
7479
if (tbl->map[i] < 0) {
7424
7480
PerlIO_printf(Perl_debug_log," %02x=>%d",
@@ -7432,8 +7488,32 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7432
7488
PerlIO_printf(Perl_debug_log,"\n");
7433
7489
}
7434
7490
}
7435
- PerlIO_printf(Perl_debug_log,"Final map 0x%x=>%02x\n",
7436
- (unsigned) tbl->size, tbl->map[tbl->size]);
7491
+
7492
+ PerlIO_printf(Perl_debug_log,
7493
+ "The next (and final) byte ");
7494
+ if ((UV) tbl->map[tbl->size] == TR_UNLISTED) {
7495
+ PerlIO_printf(Perl_debug_log,
7496
+ " indicates no other characters are involved in"
7497
+ " the transliteration\n");
7498
+ }
7499
+ else if ((UV) tbl->map[tbl->size] == TR_SPECIAL_HANDLING) {
7500
+ if (! del) {
7501
+ const int size = tbl->size;
7502
+ croak("panic: Unexpected value %x in [%d]",
7503
+ tbl->map[size], size);
7504
+ }
7505
+ else {
7506
+ PerlIO_printf(Perl_debug_log,
7507
+ "indicates that all code points above"
7508
+ " 0xFF are to be deleted\n");
7509
+ }
7510
+ }
7511
+ else if ((UV) tbl->map[tbl->size] == TR_R_EMPTY) {
7512
+ PerlIO_printf(Perl_debug_log, "is unused\n");
7513
+ }
7514
+ else {
7515
+ PerlIO_printf(Perl_debug_log, "%x UNUSED\n", tbl->map[256]);
7516
+ }
7437
7517
};
7438
7518
#endif
7439
7519
0 commit comments