| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| |
| 7 |
|
| #include "confold_compat.h" |
| 8 |
|
| |
| 9 |
|
| #define CONFOLD_HINT_KEY "Confold/on" |
| 10 |
|
| #define CONFOLD_HINT_LEN (sizeof(CONFOLD_HINT_KEY) - 1) |
| 11 |
|
| |
| 12 |
|
| #define CONFOLD_SENTINEL_CH 'C' |
| 13 |
|
| |
| 14 |
|
| static Perl_infix_plugin_t cf_next_infix_plugin; |
| 15 |
|
| static Perl_keyword_plugin_t cf_next_keyword_plugin; |
| 16 |
|
| |
| 17 |
|
| static int cf_armed = 0; |
| 18 |
|
| static IV cf_offset = -1; |
| 19 |
|
| |
| 20 |
|
| static XOP cf_confold_xop; |
| 21 |
|
| |
| 22 |
|
| static OP * |
| 23 |
15 |
| cf_pp_confold(pTHX) |
| 24 |
|
| { |
| 25 |
15 |
| dSP; |
| 26 |
15 |
| SV *sv = TOPs; |
| 27 |
|
| SV *copy; |
| 28 |
|
| |
| 29 |
15 |
▶ | SvGETMAGIC(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(sv); |
1 |
14 |
15 |
| SvGETMAGIC(sv); |
0 |
1 |
1 |
|
| 30 |
15 |
| copy = sv_2mortal(newSVsv_nomg(sv)); |
| 31 |
15 |
| SvREADONLY_on(copy); |
| 32 |
|
| |
| 33 |
15 |
| SETs(copy); |
| 34 |
15 |
| RETURN; |
| 35 |
|
| } |
| 36 |
|
| |
| 37 |
|
| static bool |
| 38 |
64 |
| cf_hint_active(pTHX) |
| 39 |
|
| { |
| 40 |
64 |
| HV *hints = GvHV(PL_hintgv); |
| 41 |
|
| SV **hent; |
| 42 |
|
| |
| 43 |
64 |
▶ | if (!hints) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hints) |
0 |
64 |
64 |
|
| 44 |
0 |
| return FALSE; |
| 45 |
|
| |
| 46 |
64 |
| hent = hv_fetch(hints, CONFOLD_HINT_KEY, (I32)CONFOLD_HINT_LEN, 0); |
| 47 |
64 |
▶ | return cBOOL(hent && *hent && SvTRUE(*hent)); |
Branch: 3 branches
| Branch | True | False | Total |
| return cBOOL(hent && *hent && SvTRUE(*hent)); |
63 |
1 |
64 |
| return cBOOL(hent && *hent && SvTRUE(*hent)); |
63 |
0 |
63 |
| return cBOOL(hent && *hent && SvTRUE(*hent)); |
63 |
0 |
63 |
|
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
|
| typedef struct { |
| 51 |
|
| CV *cv; |
| 52 |
|
| PADOFFSET off; |
| 53 |
|
| SV *sv; |
| 54 |
|
| } cf_slot; |
| 55 |
|
| |
| 56 |
|
| static cf_slot *cf_slots = NULL; |
| 57 |
|
| static IV cf_slot_used = 0; |
| 58 |
|
| static IV cf_slot_size = 0; |
| 59 |
|
| |
| 60 |
|
| #define CF_PENDING_MAX 32 |
| 61 |
|
| static OP *cf_pending[CF_PENDING_MAX]; |
| 62 |
|
| static int cf_pending_used = 0; |
| 63 |
|
| |
| 64 |
|
| static void |
| 65 |
40 |
| cf_mark_const(OP *o) |
| 66 |
|
| { |
| 67 |
40 |
▶ | if (cf_pending_used >= CF_PENDING_MAX) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cf_pending_used >= CF_PENDING_MAX) |
0 |
40 |
40 |
|
| 68 |
0 |
| cf_pending_used = 0; |
| 69 |
40 |
| cf_pending[cf_pending_used++] = o; |
| 70 |
40 |
| } |
| 71 |
|
| |
| 72 |
|
| static bool |
| 73 |
2724 |
| cf_is_marked(const OP *o) |
| 74 |
|
| { |
| 75 |
|
| int i; |
| 76 |
3668 |
▶ | for (i = 0; i < cf_pending_used; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cf_pending_used; i++) |
967 |
2701 |
3668 |
|
| 77 |
967 |
▶ | if (cf_pending[i] == o) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cf_pending[i] == o) |
23 |
944 |
967 |
|
| 78 |
23 |
| return TRUE; |
| 79 |
2701 |
| return FALSE; |
| 80 |
|
| } |
| 81 |
|
| |
| 82 |
|
| static void |
| 83 |
23 |
| cf_slot_record(pTHX_ CV *cv, PADOFFSET off, SV *sv) |
| 84 |
|
| { |
| 85 |
|
| IV i; |
| 86 |
|
| |
| 87 |
96 |
▶ | for (i = 0; i < cf_slot_used; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cf_slot_used; i++) { |
73 |
23 |
96 |
|
| 88 |
73 |
▶ | if (cf_slots[i].cv == cv && cf_slots[i].off == off) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cf_slots[i].cv == cv && cf_slots[i].off == off) { |
64 |
9 |
73 |
| if (cf_slots[i].cv == cv && cf_slots[i].off == off) { |
0 |
64 |
64 |
|
| 89 |
0 |
| SvREFCNT_dec(cf_slots[i].sv); |
| 90 |
0 |
| cf_slots[i].sv = newSVsv(sv); |
| 91 |
0 |
| SvREADONLY_on(cf_slots[i].sv); |
| 92 |
0 |
| return; |
| 93 |
|
| } |
| 94 |
|
| } |
| 95 |
|
| |
| 96 |
23 |
▶ | if (cf_slot_used >= cf_slot_size) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cf_slot_used >= cf_slot_size) { |
4 |
19 |
23 |
|
| 97 |
4 |
▶ | cf_slot_size = cf_slot_size ? cf_slot_size * 2 : 16; |
Branch: 1 branch
| Branch | True | False | Total |
| cf_slot_size = cf_slot_size ? cf_slot_size * 2 : 16; |
0 |
4 |
4 |
|
| 98 |
4 |
▶ | Renew(cf_slots, cf_slot_size, cf_slot); |
Branch: 1 branch
| Branch | True | False | Total |
| Renew(cf_slots, cf_slot_size, cf_slot); |
0 |
4 |
4 |
|
| 99 |
|
| } |
| 100 |
|
| |
| 101 |
23 |
| cf_slots[cf_slot_used].cv = cv; |
| 102 |
23 |
| cf_slots[cf_slot_used].off = off; |
| 103 |
23 |
| cf_slots[cf_slot_used].sv = newSVsv(sv); |
| 104 |
23 |
| SvREADONLY_on(cf_slots[cf_slot_used].sv); |
| 105 |
23 |
| cf_slot_used++; |
| 106 |
|
| } |
| 107 |
|
| |
| 108 |
|
| static SV * |
| 109 |
5165 |
| cf_slot_lookup_one(pTHX_ CV *cv, PADOFFSET off) |
| 110 |
|
| { |
| 111 |
|
| IV i; |
| 112 |
19049 |
▶ | for (i = 0; i < cf_slot_used; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cf_slot_used; i++) |
13907 |
5142 |
19049 |
|
| 113 |
13907 |
▶ | if (cf_slots[i].cv == cv && cf_slots[i].off == off) |
Branch: 2 branches
| Branch | True | False | Total |
| if (cf_slots[i].cv == cv && cf_slots[i].off == off) |
126 |
13781 |
13907 |
| if (cf_slots[i].cv == cv && cf_slots[i].off == off) |
23 |
103 |
126 |
|
| 114 |
23 |
| return cf_slots[i].sv; |
| 115 |
5142 |
| return NULL; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
|
| static SV * |
| 119 |
4919 |
| cf_slot_lookup(pTHX_ CV *cv, PADOFFSET off) |
| 120 |
|
| { |
| 121 |
4919 |
| int guard = 0; |
| 122 |
|
| |
| 123 |
5166 |
▶ | while (cv && off && guard++ < 32) { |
Branch: 3 branches
| Branch | True | False | Total |
| while (cv && off && guard++ < 32) { |
5166 |
0 |
5166 |
| while (cv && off && guard++ < 32) { |
5165 |
1 |
5166 |
| while (cv && off && guard++ < 32) { |
5165 |
0 |
5165 |
|
| 124 |
|
| PADNAMELIST *pnl; |
| 125 |
|
| PADNAME *pn; |
| 126 |
5165 |
| SV *found = cf_slot_lookup_one(aTHX_ cv, off); |
| 127 |
|
| |
| 128 |
5165 |
▶ | if (found) |
Branch: 1 branch
| Branch | True | False | Total |
| if (found) |
23 |
5142 |
5165 |
|
| 129 |
23 |
| return found; |
| 130 |
|
| |
| 131 |
5142 |
▶ | if (!CvPADLIST(cv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!CvPADLIST(cv)) |
0 |
5142 |
5142 |
|
| 132 |
0 |
| return NULL; |
| 133 |
|
| |
| 134 |
5142 |
| pnl = PadlistNAMES(CvPADLIST(cv)); |
| 135 |
5142 |
▶ | if (!pnl || (SSize_t)off > PadnamelistMAX(pnl)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!pnl || (SSize_t)off > PadnamelistMAX(pnl)) |
5142 |
0 |
5142 |
| if (!pnl || (SSize_t)off > PadnamelistMAX(pnl)) |
0 |
5142 |
5142 |
|
| 136 |
0 |
| return NULL; |
| 137 |
|
| |
| 138 |
5142 |
| pn = PadnamelistARRAY(pnl)[off]; |
| 139 |
5142 |
▶ | if (!pn || !PadnameOUTER(pn)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!pn || !PadnameOUTER(pn)) |
5142 |
0 |
5142 |
| if (!pn || !PadnameOUTER(pn)) |
4895 |
247 |
5142 |
|
| 140 |
4895 |
| return NULL; |
| 141 |
|
| |
| 142 |
247 |
| off = PARENT_PAD_INDEX(pn); |
| 143 |
247 |
| cv = CvOUTSIDE(cv); |
| 144 |
|
| } |
| 145 |
|
| |
| 146 |
1 |
| return NULL; |
| 147 |
|
| } |
| 148 |
|
| |
| 149 |
|
| static SV * |
| 150 |
0 |
| cf_const_sv(pTHX_ const OP *o) |
| 151 |
|
| { |
| 152 |
0 |
▶ | if (!o) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!o) |
0 |
0 |
0 |
|
| 153 |
0 |
| return NULL; |
| 154 |
|
| |
| 155 |
0 |
▶ | if (o->op_type == OP_CONST) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_type == OP_CONST) |
0 |
0 |
0 |
|
| 156 |
0 |
| return cSVOPx_sv((OP *)o); |
| 157 |
|
| |
| 158 |
0 |
▶ | if (o->op_type == OP_PADSV) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_type == OP_PADSV) |
0 |
0 |
0 |
|
| 159 |
0 |
| return cf_slot_lookup(aTHX_ PL_compcv, o->op_targ); |
| 160 |
|
| |
| 161 |
0 |
| return NULL; |
| 162 |
|
| } |
| 163 |
|
| |
| 164 |
|
| static OP * |
| 165 |
63 |
| cf_wrap(pTHX_ OP *operand) |
| 166 |
|
| { |
| 167 |
|
| OP *o; |
| 168 |
|
| |
| 169 |
63 |
▶ | if (!operand) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!operand) |
0 |
63 |
63 |
|
| 170 |
0 |
| return NULL; |
| 171 |
|
| |
| 172 |
63 |
▶ | if (operand->op_type == OP_CONST) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (operand->op_type == OP_CONST) { |
35 |
28 |
63 |
|
| 173 |
35 |
| cf_mark_const(operand); |
| 174 |
35 |
| return operand; |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
28 |
▶ | if (operand->op_type == OP_PADSV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (operand->op_type == OP_PADSV) { |
21 |
7 |
28 |
|
| 178 |
21 |
| SV *known = cf_slot_lookup(aTHX_ PL_compcv, operand->op_targ); |
| 179 |
21 |
▶ | if (known) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (known) { |
5 |
16 |
21 |
|
| 180 |
5 |
| OP *k = newSVOP(OP_CONST, 0, newSVsv(known)); |
| 181 |
5 |
| SvREADONLY_on(cSVOPx_sv(k)); |
| 182 |
5 |
| op_free(operand); |
| 183 |
5 |
| cf_mark_const(k); |
| 184 |
5 |
| return k; |
| 185 |
|
| } |
| 186 |
|
| } |
| 187 |
|
| |
| 188 |
23 |
| o = newUNOP(OP_NULL, 0, operand); |
| 189 |
23 |
| CF_MAKE_CUSTOM(o, cf_pp_confold); |
| 190 |
23 |
| return o; |
| 191 |
|
| } |
| 192 |
|
| |
| 193 |
|
| static bool |
| 194 |
67 |
| cf_looser_than_refgen(const OP *o) |
| 195 |
|
| { |
| 196 |
67 |
▶ | switch (o->op_type) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (o->op_type) { |
8 |
59 |
67 |
|
| 197 |
8 |
| case OP_ADD: case OP_I_ADD: |
| 198 |
|
| case OP_SUBTRACT: case OP_I_SUBTRACT: |
| 199 |
|
| case OP_MULTIPLY: case OP_I_MULTIPLY: |
| 200 |
|
| case OP_DIVIDE: case OP_I_DIVIDE: |
| 201 |
|
| case OP_MODULO: case OP_I_MODULO: |
| 202 |
|
| case OP_CONCAT: |
| 203 |
|
| case OP_REPEAT: |
| 204 |
|
| case OP_LEFT_SHIFT: |
| 205 |
|
| case OP_RIGHT_SHIFT: |
| 206 |
8 |
| return TRUE; |
| 207 |
59 |
| default: |
| 208 |
59 |
| return FALSE; |
| 209 |
|
| } |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
|
| static void |
| 213 |
174 |
| cf_drop_op_next(pTHX_ OP *o) |
| 214 |
|
| { |
| 215 |
|
| OP *kid; |
| 216 |
|
| |
| 217 |
174 |
▶ | if (!o) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!o) |
0 |
174 |
174 |
|
| 218 |
0 |
| return; |
| 219 |
|
| |
| 220 |
174 |
| o->op_next = NULL; |
| 221 |
|
| |
| 222 |
174 |
▶ | if (o->op_flags & OPf_KIDS) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_flags & OPf_KIDS) { |
72 |
102 |
174 |
|
| 223 |
220 |
▶ | for (kid = cUNOPx(o)->op_first; kid; kid = OpSIBLING(kid)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (kid = cUNOPx(o)->op_first; kid; kid = OpSIBLING(kid)) |
76 |
72 |
148 |
| for (kid = cUNOPx(o)->op_first; kid; kid = OpSIBLING(kid)) |
148 |
72 |
220 |
|
| 224 |
148 |
| cf_drop_op_next(aTHX_ kid); |
| 225 |
|
| } |
| 226 |
|
| } |
| 227 |
|
| |
| 228 |
|
| static OP * |
| 229 |
63 |
| cf_rebalance(pTHX_ OP *o) |
| 230 |
|
| { |
| 231 |
63 |
| OP *parent = NULL; |
| 232 |
63 |
| OP *cur = o; |
| 233 |
|
| OP *kid; |
| 234 |
|
| |
| 235 |
63 |
| while (!(cur->op_flags & OPf_PARENS) |
| 236 |
67 |
▶ | && cf_looser_than_refgen(cur) |
Branch: 1 branch
| Branch | True | False | Total |
| && cf_looser_than_refgen(cur) |
8 |
59 |
67 |
|
| 237 |
8 |
▶ | && (cur->op_flags & OPf_KIDS) |
Branch: 1 branch
| Branch | True | False | Total |
| && (cur->op_flags & OPf_KIDS) |
8 |
0 |
8 |
|
| 238 |
8 |
▶ | && cBINOPx(cur)->op_first |
Branch: 1 branch
| Branch | True | False | Total |
| && cBINOPx(cur)->op_first |
8 |
0 |
8 |
|
| 239 |
79 |
▶ | && OpHAS_SIBLING(cBINOPx(cur)->op_first)) |
Branch: 2 branches
| Branch | True | False | Total |
| && OpHAS_SIBLING(cBINOPx(cur)->op_first)) |
67 |
4 |
71 |
| && OpHAS_SIBLING(cBINOPx(cur)->op_first)) |
8 |
0 |
8 |
|
| 240 |
|
| { |
| 241 |
8 |
| parent = cur; |
| 242 |
8 |
| cur = cBINOPx(cur)->op_first; |
| 243 |
|
| } |
| 244 |
|
| |
| 245 |
63 |
▶ | if (!parent) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!parent) |
55 |
8 |
63 |
|
| 246 |
55 |
| return cf_wrap(aTHX_ o); |
| 247 |
|
| |
| 248 |
8 |
| kid = op_sibling_splice(parent, NULL, 1, NULL); |
| 249 |
8 |
| op_sibling_splice(parent, NULL, 0, |
| 250 |
|
| op_contextualize(cf_wrap(aTHX_ kid), G_SCALAR)); |
| 251 |
|
| |
| 252 |
8 |
| cf_drop_op_next(aTHX_ o); |
| 253 |
|
| |
| 254 |
8 |
| return o; |
| 255 |
|
| } |
| 256 |
|
| |
| 257 |
|
| static char * |
| 258 |
63 |
| cf_find_glyph(pTHX) |
| 259 |
|
| { |
| 260 |
63 |
| char *p = CF_bufptr; |
| 261 |
63 |
| char *end = CF_bufend; |
| 262 |
|
| |
| 263 |
63 |
▶ | if (!p || !end) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!p || !end) |
63 |
0 |
63 |
| if (!p || !end) |
0 |
63 |
63 |
|
| 264 |
0 |
| return NULL; |
| 265 |
|
| |
| 266 |
105 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
105 |
0 |
105 |
|
| 267 |
105 |
▶ | if (isSPACE(*p)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (isSPACE(*p)) |
42 |
63 |
105 |
|
| 268 |
42 |
| p++; |
| 269 |
63 |
▶ | else if (*p == '#') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*p == '#') { |
0 |
63 |
63 |
|
| 270 |
0 |
▶ | while (p < end && *p != '\n') |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '\n') |
0 |
0 |
0 |
| while (p < end && *p != '\n') |
0 |
0 |
0 |
|
| 271 |
0 |
| p++; |
| 272 |
|
| } |
| 273 |
63 |
| else break; |
| 274 |
|
| } |
| 275 |
|
| |
| 276 |
63 |
▶ | if (p + 1 < end && p[0] == '<' && p[1] == ':') |
Branch: 3 branches
| Branch | True | False | Total |
| if (p + 1 < end && p[0] == '<' && p[1] == ':') |
63 |
0 |
63 |
| if (p + 1 < end && p[0] == '<' && p[1] == ':') |
63 |
0 |
63 |
| if (p + 1 < end && p[0] == '<' && p[1] == ':') |
63 |
0 |
63 |
|
| 277 |
63 |
| return p; |
| 278 |
|
| |
| 279 |
0 |
| return NULL; |
| 280 |
|
| } |
| 281 |
|
| |
| 282 |
|
| static Perl_check_t cf_next_ck_padsv_store; |
| 283 |
|
| static Perl_check_t cf_next_ck_sassign; |
| 284 |
|
| |
| 285 |
|
| static void |
| 286 |
3970 |
| cf_slot_forget(pTHX_ CV *cv, PADOFFSET off) |
| 287 |
|
| { |
| 288 |
|
| IV i; |
| 289 |
|
| |
| 290 |
14804 |
▶ | for (i = 0; i < cf_slot_used; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cf_slot_used; i++) { |
10835 |
3969 |
14804 |
|
| 291 |
10835 |
▶ | if (cf_slots[i].cv == cv && cf_slots[i].off == off) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cf_slots[i].cv == cv && cf_slots[i].off == off) { |
54 |
10781 |
10835 |
| if (cf_slots[i].cv == cv && cf_slots[i].off == off) { |
1 |
53 |
54 |
|
| 292 |
1 |
| SvREFCNT_dec(cf_slots[i].sv); |
| 293 |
1 |
| cf_slots[i] = cf_slots[--cf_slot_used]; |
| 294 |
1 |
| return; |
| 295 |
|
| } |
| 296 |
|
| } |
| 297 |
|
| } |
| 298 |
|
| |
| 299 |
|
| static void |
| 300 |
2724 |
| cf_note_declaration(pTHX_ OP *store, OP *value, PADOFFSET off) |
| 301 |
|
| { |
| 302 |
|
| PERL_UNUSED_ARG(store); |
| 303 |
|
| |
| 304 |
2724 |
▶ | if (!off) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!off) |
0 |
2724 |
2724 |
|
| 305 |
0 |
| return; |
| 306 |
|
| |
| 307 |
2724 |
▶ | if (value && cf_is_marked(value)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (value && cf_is_marked(value)) { |
2724 |
0 |
2724 |
| if (value && cf_is_marked(value)) { |
23 |
2701 |
2724 |
|
| 308 |
23 |
| cf_slot_record(aTHX_ PL_compcv, off, cSVOPx_sv(value)); |
| 309 |
23 |
| cf_pending_used = 0; |
| 310 |
23 |
| return; |
| 311 |
|
| } |
| 312 |
|
| |
| 313 |
2701 |
| cf_slot_forget(aTHX_ PL_compcv, off); |
| 314 |
|
| } |
| 315 |
|
| |
| 316 |
|
| static Perl_check_t cf_next_ck_entersub; |
| 317 |
|
| |
| 318 |
|
| static OP * |
| 319 |
12028 |
| cf_ck_entersub(pTHX_ OP *o) |
| 320 |
|
| { |
| 321 |
|
| OP *kid; |
| 322 |
|
| |
| 323 |
12028 |
▶ | if (PL_compcv && (o->op_flags & OPf_KIDS)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (PL_compcv && (o->op_flags & OPf_KIDS)) { |
12028 |
0 |
12028 |
| if (PL_compcv && (o->op_flags & OPf_KIDS)) { |
12028 |
0 |
12028 |
|
| 324 |
12028 |
| OP *parent = o; |
| 325 |
12028 |
| OP *prev = NULL; |
| 326 |
|
| |
| 327 |
12028 |
| kid = cUNOPx(o)->op_first; |
| 328 |
12028 |
▶ | if (kid && (kid->op_type == OP_LIST || kid->op_type == OP_NULL) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kid && (kid->op_type == OP_LIST || kid->op_type == OP_NULL) |
12028 |
0 |
12028 |
| if (kid && (kid->op_type == OP_LIST || kid->op_type == OP_NULL) |
12028 |
0 |
12028 |
| if (kid && (kid->op_type == OP_LIST || kid->op_type == OP_NULL) |
8024 |
4004 |
12028 |
|
| 329 |
8024 |
▶ | && (kid->op_flags & OPf_KIDS)) { |
Branch: 1 branch
| Branch | True | False | Total |
| && (kid->op_flags & OPf_KIDS)) { |
8024 |
0 |
8024 |
|
| 330 |
8024 |
| parent = kid; |
| 331 |
8024 |
| kid = cUNOPx(kid)->op_first; |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
48286 |
▶ | while (kid) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (kid) { |
36258 |
12028 |
48286 |
|
| 335 |
36258 |
▶ | OP *next = OpSIBLING(kid); |
Branch: 1 branch
| Branch | True | False | Total |
| OP *next = OpSIBLING(kid); |
24230 |
12028 |
36258 |
|
| 336 |
36258 |
| SV *known = NULL; |
| 337 |
|
| |
| 338 |
36258 |
▶ | if (kid->op_type == OP_PADSV |
Branch: 1 branch
| Branch | True | False | Total |
| if (kid->op_type == OP_PADSV |
4898 |
31360 |
36258 |
|
| 339 |
4898 |
▶ | && kid->op_targ |
Branch: 1 branch
| Branch | True | False | Total |
| && kid->op_targ |
4898 |
0 |
4898 |
|
| 340 |
4898 |
▶ | && !(kid->op_private & OPpLVAL_INTRO)) |
Branch: 1 branch
| Branch | True | False | Total |
| && !(kid->op_private & OPpLVAL_INTRO)) |
4898 |
0 |
4898 |
|
| 341 |
4898 |
| known = cf_slot_lookup(aTHX_ PL_compcv, kid->op_targ); |
| 342 |
|
| |
| 343 |
36258 |
▶ | if (known) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (known) { |
18 |
36240 |
36258 |
|
| 344 |
18 |
| OP *k = newSVOP(OP_CONST, 0, newSVsv(known)); |
| 345 |
|
| |
| 346 |
18 |
| SvREADONLY_on(cSVOPx_sv(k)); |
| 347 |
18 |
| op_free(op_sibling_splice(parent, prev, 1, k)); |
| 348 |
18 |
| op_contextualize(k, G_SCALAR); |
| 349 |
18 |
| cf_drop_op_next(aTHX_ o); |
| 350 |
18 |
| prev = k; |
| 351 |
|
| } |
| 352 |
|
| else { |
| 353 |
36240 |
| prev = kid; |
| 354 |
|
| } |
| 355 |
|
| |
| 356 |
36258 |
| kid = next; |
| 357 |
|
| } |
| 358 |
|
| } |
| 359 |
|
| |
| 360 |
12028 |
| return cf_next_ck_entersub(aTHX_ o); |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
|
| static OP * |
| 364 |
0 |
| cf_ck_padsv_store(pTHX_ OP *o) |
| 365 |
|
| { |
| 366 |
0 |
| o = cf_next_ck_padsv_store(aTHX_ o); |
| 367 |
|
| |
| 368 |
0 |
▶ | if (o->op_type == OP_PADSV_STORE && (o->op_flags & OPf_KIDS)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (o->op_type == OP_PADSV_STORE && (o->op_flags & OPf_KIDS)) |
0 |
0 |
0 |
| if (o->op_type == OP_PADSV_STORE && (o->op_flags & OPf_KIDS)) |
0 |
0 |
0 |
|
| 369 |
0 |
| cf_note_declaration(aTHX_ o, cUNOPx(o)->op_first, o->op_targ); |
| 370 |
|
| |
| 371 |
0 |
| return o; |
| 372 |
|
| } |
| 373 |
|
| |
| 374 |
|
| static OP * |
| 375 |
6349 |
| cf_ck_sassign(pTHX_ OP *o) |
| 376 |
|
| { |
| 377 |
6349 |
| o = cf_next_ck_sassign(aTHX_ o); |
| 378 |
|
| |
| 379 |
6349 |
▶ | if (o->op_type == OP_SASSIGN && (o->op_flags & OPf_KIDS)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (o->op_type == OP_SASSIGN && (o->op_flags & OPf_KIDS)) { |
6175 |
174 |
6349 |
| if (o->op_type == OP_SASSIGN && (o->op_flags & OPf_KIDS)) { |
6175 |
0 |
6175 |
|
| 380 |
6175 |
| OP *value = cBINOPx(o)->op_first; |
| 381 |
6175 |
▶ | OP *target = value ? OpSIBLING(value) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| OP *target = value ? OpSIBLING(value) : NULL; |
6175 |
0 |
6175 |
| OP *target = value ? OpSIBLING(value) : NULL; |
5979 |
196 |
6175 |
|
| 382 |
|
| |
| 383 |
6175 |
▶ | if (target && target->op_type == OP_PADSV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (target && target->op_type == OP_PADSV) { |
5979 |
196 |
6175 |
| if (target && target->op_type == OP_PADSV) { |
3993 |
1986 |
5979 |
|
| 384 |
3993 |
▶ | if (target->op_private & OPpLVAL_INTRO) |
Branch: 1 branch
| Branch | True | False | Total |
| if (target->op_private & OPpLVAL_INTRO) |
2724 |
1269 |
3993 |
|
| 385 |
2724 |
| cf_note_declaration(aTHX_ o, value, target->op_targ); |
| 386 |
|
| else |
| 387 |
1269 |
| cf_slot_forget(aTHX_ PL_compcv, target->op_targ); |
| 388 |
|
| } |
| 389 |
|
| } |
| 390 |
|
| |
| 391 |
6349 |
| return o; |
| 392 |
|
| } |
| 393 |
|
| |
| 394 |
|
| static STRLEN |
| 395 |
249907 |
| cf_infix_plugin(pTHX_ char *opname, STRLEN oplen, struct Perl_custom_infix **def) |
| 396 |
|
| { |
| 397 |
249907 |
▶ | if (oplen >= 2 && opname[0] == '<' && opname[1] == ':' |
Branch: 3 branches
| Branch | True | False | Total |
| if (oplen >= 2 && opname[0] == '<' && opname[1] == ':' |
103926 |
145981 |
249907 |
| if (oplen >= 2 && opname[0] == '<' && opname[1] == ':' |
190 |
103736 |
103926 |
| if (oplen >= 2 && opname[0] == '<' && opname[1] == ':' |
64 |
126 |
190 |
|
| 398 |
64 |
▶ | && PL_parser && CF_expect != XOPERATOR |
Branch: 2 branches
| Branch | True | False | Total |
| && PL_parser && CF_expect != XOPERATOR |
64 |
0 |
64 |
| && PL_parser && CF_expect != XOPERATOR |
64 |
0 |
64 |
|
| 399 |
64 |
▶ | && cf_hint_active(aTHX)) |
Branch: 1 branch
| Branch | True | False | Total |
| && cf_hint_active(aTHX)) |
63 |
1 |
64 |
|
| 400 |
|
| { |
| 401 |
63 |
| char *glyph = cf_find_glyph(aTHX); |
| 402 |
|
| |
| 403 |
63 |
▶ | if (glyph) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (glyph) { |
63 |
0 |
63 |
|
| 404 |
63 |
| cf_offset = glyph - SvPVX(CF_linestr); |
| 405 |
63 |
| cf_armed = 1; |
| 406 |
63 |
| glyph[0] = CONFOLD_SENTINEL_CH; |
| 407 |
63 |
| glyph[1] = ' '; |
| 408 |
63 |
| return 0; |
| 409 |
|
| } |
| 410 |
|
| } |
| 411 |
|
| |
| 412 |
249844 |
| return cf_next_infix_plugin(aTHX_ opname, oplen, def); |
| 413 |
|
| } |
| 414 |
|
| |
| 415 |
|
| static int |
| 416 |
39886 |
| cf_keyword_plugin(pTHX_ char *keyword_ptr, STRLEN keyword_len, OP **op_ptr) |
| 417 |
|
| { |
| 418 |
39886 |
▶ | if (cf_armed |
Branch: 1 branch
| Branch | True | False | Total |
| if (cf_armed |
63 |
39823 |
39886 |
|
| 419 |
63 |
▶ | && keyword_len == 1 |
Branch: 1 branch
| Branch | True | False | Total |
| && keyword_len == 1 |
63 |
0 |
63 |
|
| 420 |
63 |
▶ | && keyword_ptr[0] == CONFOLD_SENTINEL_CH |
Branch: 1 branch
| Branch | True | False | Total |
| && keyword_ptr[0] == CONFOLD_SENTINEL_CH |
63 |
0 |
63 |
|
| 421 |
63 |
▶ | && PL_parser |
Branch: 1 branch
| Branch | True | False | Total |
| && PL_parser |
63 |
0 |
63 |
|
| 422 |
63 |
▶ | && (CF_bufptr - SvPVX(CF_linestr)) == cf_offset + 1) |
Branch: 1 branch
| Branch | True | False | Total |
| && (CF_bufptr - SvPVX(CF_linestr)) == cf_offset + 1) |
63 |
0 |
63 |
|
| 423 |
|
| { |
| 424 |
63 |
| IV off = cf_offset; |
| 425 |
|
| OP *operand; |
| 426 |
|
| char *base; |
| 427 |
|
| |
| 428 |
63 |
| cf_armed = 0; |
| 429 |
63 |
| cf_offset = -1; |
| 430 |
|
| |
| 431 |
63 |
| operand = parse_arithexpr(0); |
| 432 |
|
| |
| 433 |
63 |
| base = SvPVX(CF_linestr); |
| 434 |
63 |
▶ | if (off >= 0 && off + 1 < (IV)SvCUR(CF_linestr) |
Branch: 2 branches
| Branch | True | False | Total |
| if (off >= 0 && off + 1 < (IV)SvCUR(CF_linestr) |
63 |
0 |
63 |
| if (off >= 0 && off + 1 < (IV)SvCUR(CF_linestr) |
61 |
2 |
63 |
|
| 435 |
61 |
▶ | && base[off] == CONFOLD_SENTINEL_CH && base[off + 1] == ' ') |
Branch: 2 branches
| Branch | True | False | Total |
| && base[off] == CONFOLD_SENTINEL_CH && base[off + 1] == ' ') |
61 |
0 |
61 |
| && base[off] == CONFOLD_SENTINEL_CH && base[off + 1] == ' ') |
61 |
0 |
61 |
|
| 436 |
|
| { |
| 437 |
61 |
| base[off] = '<'; |
| 438 |
61 |
| base[off + 1] = ':'; |
| 439 |
|
| } |
| 440 |
|
| |
| 441 |
63 |
▶ | if (!operand) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!operand) |
0 |
63 |
63 |
|
| 442 |
0 |
| croak("confold: missing operand for <:"); |
| 443 |
|
| |
| 444 |
63 |
| *op_ptr = cf_rebalance(aTHX_ operand); |
| 445 |
63 |
| return KEYWORD_PLUGIN_EXPR; |
| 446 |
|
| } |
| 447 |
|
| |
| 448 |
39823 |
| return cf_next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr); |
| 449 |
|
| } |
| 450 |
|
| |
| 451 |
|
| MODULE = Confold PACKAGE = Confold |
| 452 |
|
| |
| 453 |
|
| PROTOTYPES: DISABLE |
| 454 |
|
| |
| 455 |
|
| void |
| 456 |
|
| _hint_on() |
| 457 |
|
| CODE: |
| 458 |
|
| { |
| 459 |
10 |
| HV *hints = GvHV(PL_hintgv); |
| 460 |
10 |
▶ | if (hints) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hints) { |
10 |
0 |
10 |
|
| 461 |
10 |
| (void)hv_store(hints, CONFOLD_HINT_KEY, (I32)CONFOLD_HINT_LEN, |
| 462 |
|
| newSViv(1), 0); |
| 463 |
10 |
| PL_hints |= HINT_LOCALIZE_HH; |
| 464 |
|
| } |
| 465 |
|
| } |
| 466 |
|
| |
| 467 |
|
| void |
| 468 |
|
| _hint_off() |
| 469 |
|
| CODE: |
| 470 |
|
| { |
| 471 |
1 |
| HV *hints = GvHV(PL_hintgv); |
| 472 |
1 |
▶ | if (hints) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (hints) { |
1 |
0 |
1 |
|
| 473 |
1 |
| (void)hv_delete(hints, CONFOLD_HINT_KEY, (I32)CONFOLD_HINT_LEN, |
| 474 |
|
| G_DISCARD); |
| 475 |
1 |
| PL_hints |= HINT_LOCALIZE_HH; |
| 476 |
|
| } |
| 477 |
|
| } |
| 478 |
|
| |
| 479 |
|
| BOOT: |
| 480 |
|
| { |
| 481 |
8 |
| XopENTRY_set(&cf_confold_xop, xop_name, "confold"); |
| 482 |
8 |
| XopENTRY_set(&cf_confold_xop, xop_desc, "constant fold"); |
| 483 |
8 |
| XopENTRY_set(&cf_confold_xop, xop_class, OA_UNOP); |
| 484 |
8 |
| Perl_custom_op_register(aTHX_ cf_pp_confold, &cf_confold_xop); |
| 485 |
|
| |
| 486 |
8 |
| wrap_infix_plugin(cf_infix_plugin, &cf_next_infix_plugin); |
| 487 |
|
| |
| 488 |
8 |
| cf_next_keyword_plugin = PL_keyword_plugin; |
| 489 |
8 |
| PL_keyword_plugin = cf_keyword_plugin; |
| 490 |
|
| |
| 491 |
8 |
| wrap_op_checker(OP_ENTERSUB, cf_ck_entersub, &cf_next_ck_entersub); |
| 492 |
8 |
| wrap_op_checker(OP_PADSV_STORE, cf_ck_padsv_store, &cf_next_ck_padsv_store); |
| 493 |
8 |
| wrap_op_checker(OP_SASSIGN, cf_ck_sassign, &cf_next_ck_sassign); |
| 494 |
|
| } |