@@ -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
@@ -6653,8 +6684,8 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
6653
6684
for (pass2 = 0; pass2 < 2; pass2++) {
6654
6685
if (pass2) {
6655
6686
6656
- DEBUG_yv (PerlIO_printf(Perl_debug_log, "After pass1: \n") );
6657
- DEBUG_yv( invmap_dump(t_invlist, r_map));
6687
+ DEBUG_y (PerlIO_printf(Perl_debug_log, "After pass1: \n");
6688
+ invmap_dump(t_invlist, r_map));
6658
6689
6659
6690
/* In the second pass, we start with a single range */
6660
6691
t_invlist = _add_range_to_invlist(t_invlist, 0, UV_MAX);
@@ -6786,9 +6817,9 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
6786
6817
r_range_count = t_range_count;
6787
6818
6788
6819
#ifdef DEBUGGING
6789
- if (DEBUG_y_TEST && ! del) {
6820
+ if (DEBUG_yv_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,
@@ -7211,8 +7258,8 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7211
7258
7212
7259
DEBUG_yv(PerlIO_printf(Perl_debug_log,
7213
7260
"Before fixing up: len=%d, i=%d\n",
7214
- (int) len, (int) i)) ;
7215
- DEBUG_yv( invmap_dump(t_invlist, r_map));
7261
+ (int) len, (int) i);
7262
+ invmap_dump(t_invlist, r_map));
7216
7263
7217
7264
invlist_extend(t_invlist, len + 2);
7218
7265
t_array = invlist_array(t_invlist);
@@ -7234,10 +7281,11 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7234
7281
r_map[i+2] = TR_UNLISTED;
7235
7282
}
7236
7283
DEBUG_yv(PerlIO_printf(Perl_debug_log,
7237
- "After iteration: span=%" UVuf ", t_range_count=%"
7238
- UVuf " r_range_count=%" UVuf "\n",
7239
- span, t_range_count, r_range_count));
7240
- DEBUG_yv(invmap_dump(t_invlist, r_map));
7284
+ "After iteration: span=%" UVuf
7285
+ ", t_range_count=%" UVuf
7286
+ " r_range_count=%" UVuf "\n",
7287
+ span, t_range_count, r_range_count);
7288
+ invmap_dump(t_invlist, r_map));
7241
7289
} /* End of this chunk needs to be processed */
7242
7290
7243
7291
/* Done with this chunk. */
@@ -7266,8 +7314,8 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7266
7314
7267
7315
SvREFCNT_dec(inverted_tstr);
7268
7316
7269
- DEBUG_y(PerlIO_printf(Perl_debug_log, "After everything: \n")) ;
7270
- DEBUG_y( invmap_dump(t_invlist, r_map));
7317
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "After everything: \n");
7318
+ invmap_dump(t_invlist, r_map));
7271
7319
7272
7320
/* We now have normalized the input into an inversion map.
7273
7321
*
@@ -7417,7 +7465,16 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7417
7465
: (short) TR_R_EMPTY;
7418
7466
#ifdef DEBUGGING
7419
7467
if (DEBUG_y_TEST) {
7420
- 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
+
7421
7478
for (i = 0; i < tbl->size; i++) {
7422
7479
if (tbl->map[i] < 0) {
7423
7480
PerlIO_printf(Perl_debug_log," %02x=>%d",
@@ -7431,8 +7488,32 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
7431
7488
PerlIO_printf(Perl_debug_log,"\n");
7432
7489
}
7433
7490
}
7434
- PerlIO_printf(Perl_debug_log,"Final map 0x%x=>%02x\n",
7435
- (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
+ Perl_croak(aTHX_ "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
+ }
7436
7517
};
7437
7518
#endif
7438
7519
0 commit comments