@@ -6179,6 +6179,25 @@ Perl_invmap_dump(pTHX_ SV* invlist, UV *map)
61796179 }
61806180}
61816181
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+
61826201/* Given an OP_TRANS / OP_TRANSR op o, plus OP_CONST ops expr and repl
61836202 * containing the search and replacement strings, assemble into
61846203 * a translation table attached as o->op_pv.
@@ -6528,6 +6547,13 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
65286547
65296548 PL_hints |= HINT_BLOCK_SCOPE;
65306549
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+
65316557 /* If /c, the search list is sorted and complemented. This is now done by
65326558 * creating an inversion list from it, and then trivially inverting that.
65336559 * The previous implementation used qsort, but creating the list
@@ -6609,6 +6635,11 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
66096635 tend = t0 + temp_len;
66106636 tstr_utf8 = TRUE;
66116637
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+
66126643 SvREFCNT_dec_NN(inverted_tlist);
66136644 }
66146645
@@ -6788,7 +6819,7 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
67886819#ifdef DEBUGGING
67896820 if (DEBUG_y_TEST && ! del) {
67906821 PerlIO_printf(Perl_debug_log,
6791- "final_map =%" UVXf "\n", final_map);
6822+ "final_map = %" UVXf "\n", final_map);
67926823 }
67936824#endif
67946825 }
@@ -6904,9 +6935,25 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
69046935 * has been set up so that all members in it will be of the same
69056936 * ilk) */
69066937 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
69106957
69116958 /* This is the first definition for this chunk, hence is valid
69126959 * and needs to be processed. Here and in the comments below,
@@ -7418,7 +7465,16 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
74187465 : (short) TR_R_EMPTY;
74197466#ifdef DEBUGGING
74207467 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+
74227478 for (i = 0; i < tbl->size; i++) {
74237479 if (tbl->map[i] < 0) {
74247480 PerlIO_printf(Perl_debug_log," %02x=>%d",
@@ -7432,8 +7488,32 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
74327488 PerlIO_printf(Perl_debug_log,"\n");
74337489 }
74347490 }
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+ }
74377517 };
74387518#endif
74397519
0 commit comments