| 1 |
|
| #ifndef EX_OP_REG_H |
| 2 |
|
| #define EX_OP_REG_H |
| 3 |
|
| |
| 4 |
|
| static void eo_arm(pTHX_ CV *cv, eo_op_t *e); |
| 5 |
|
| static bool eo_tail_dep(OP *o); |
| 6 |
|
| |
| 7 |
|
| static int |
| 8 |
2001 |
| eo_mg_free(pTHX_ SV *sv, MAGIC *mg) |
| 9 |
|
| { |
| 10 |
2001 |
| eo_op_t *e = (eo_op_t *)mg->mg_ptr; |
| 11 |
|
| PERL_UNUSED_ARG(sv); |
| 12 |
2001 |
▶ | if (e) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (e) { |
2001 |
0 |
2001 |
|
| 13 |
2001 |
| Safefree(e->params); |
| 14 |
2001 |
| Safefree(e->why); |
| 15 |
2001 |
| Safefree(e); |
| 16 |
2001 |
| mg->mg_ptr = NULL; |
| 17 |
|
| } |
| 18 |
2001 |
| return 0; |
| 19 |
|
| } |
| 20 |
|
| |
| 21 |
|
| #ifdef USE_ITHREADS |
| 22 |
|
| static int |
| 23 |
|
| eo_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param) |
| 24 |
|
| { |
| 25 |
|
| eo_op_t *from = (eo_op_t *)mg->mg_ptr; |
| 26 |
|
| eo_op_t *to; |
| 27 |
|
| PERL_UNUSED_ARG(param); |
| 28 |
|
| if (!from) |
| 29 |
|
| return 0; |
| 30 |
|
| Newx(to, 1, eo_op_t); |
| 31 |
|
| StructCopy(from, to, eo_op_t); |
| 32 |
|
| to->params = NULL; |
| 33 |
|
| if (from->nparams) { |
| 34 |
|
| Newx(to->params, from->nparams, PADOFFSET); |
| 35 |
|
| Copy(from->params, to->params, from->nparams, PADOFFSET); |
| 36 |
|
| } |
| 37 |
|
| to->why = from->why ? savepv(from->why) : NULL; |
| 38 |
|
| mg->mg_ptr = (char *)to; |
| 39 |
|
| return 0; |
| 40 |
|
| } |
| 41 |
|
| #endif |
| 42 |
|
| |
| 43 |
|
| static MGVTBL eo_op_vtbl = { |
| 44 |
|
| NULL, NULL, NULL, NULL, eo_mg_free, NULL, |
| 45 |
|
| #ifdef USE_ITHREADS |
| 46 |
|
| eo_mg_dup, |
| 47 |
|
| #else |
| 48 |
|
| NULL, |
| 49 |
|
| #endif |
| 50 |
|
| NULL |
| 51 |
|
| }; |
| 52 |
|
| |
| 53 |
|
| static eo_op_t * |
| 54 |
1682411 |
| eo_op_find(pTHX_ CV *cv) |
| 55 |
|
| { |
| 56 |
1682411 |
| MAGIC *mg = mg_findext((SV *)cv, PERL_MAGIC_ext, &eo_op_vtbl); |
| 57 |
1682411 |
▶ | return mg ? (eo_op_t *)mg->mg_ptr : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return mg ? (eo_op_t *)mg->mg_ptr : NULL; |
1682404 |
7 |
1682411 |
|
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
|
| /* An op whose sub has been redefined in place, or undefined, has a body |
| 61 |
|
| * that is no longer the one registration looked at. */ |
| 62 |
|
| static eo_op_t * |
| 63 |
1682362 |
| eo_op_live(pTHX_ CV *cv) |
| 64 |
|
| { |
| 65 |
1682362 |
| eo_op_t *e = eo_op_find(aTHX_ cv); |
| 66 |
1682362 |
▶ | if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) |
1682357 |
5 |
1682362 |
| if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) |
1682300 |
57 |
1682357 |
| if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) |
1682300 |
0 |
1682300 |
| if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) |
2 |
1682298 |
1682300 |
|
| 67 |
64 |
| return NULL; |
| 68 |
1682298 |
| return e; |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
|
| static OP * |
| 72 |
22714 |
| eo_kid(OP *o) |
| 73 |
|
| { |
| 74 |
22714 |
▶ | return (o && (o->op_flags & OPf_KIDS)) ? cUNOPx(o)->op_first : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| return (o && (o->op_flags & OPf_KIDS)) ? cUNOPx(o)->op_first : NULL; |
22714 |
0 |
22714 |
| return (o && (o->op_flags & OPf_KIDS)) ? cUNOPx(o)->op_first : NULL; |
22714 |
0 |
22714 |
|
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
|
| static bool |
| 78 |
25029 |
| eo_is_type(OP *o, OPCODE type) |
| 79 |
|
| { |
| 80 |
25029 |
▶ | return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); |
Branch: 4 branches
| Branch | True | False | Total |
| return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); |
25029 |
0 |
25029 |
| return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); |
18196 |
6833 |
25029 |
| return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); |
4600 |
13596 |
18196 |
| return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); |
4528 |
72 |
4600 |
|
| 81 |
|
| } |
| 82 |
|
| |
| 83 |
|
| static bool |
| 84 |
2270 |
| eo_is_defgv(pTHX_ OP *o) |
| 85 |
|
| { |
| 86 |
2270 |
▶ | return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; |
Branch: 3 branches
| Branch | True | False | Total |
| return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; |
2270 |
0 |
2270 |
| return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; |
2269 |
1 |
2270 |
| return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; |
2267 |
2 |
2269 |
|
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
|
| typedef struct { |
| 90 |
|
| const char *why; |
| 91 |
|
| U32 loops; |
| 92 |
|
| U32 unwind; |
| 93 |
|
| bool has_return; |
| 94 |
|
| bool ret_dep; |
| 95 |
|
| bool warns; |
| 96 |
|
| OP *skip; |
| 97 |
|
| } eo_walk_t; |
| 98 |
|
| |
| 99 |
|
| /* Whether a statement could raise an "uninitialized" warning, whose message |
| 100 |
|
| * names the variable by looking in the running sub's pad. With no lexical |
| 101 |
|
| * warnings it depends on $^W, which can change at any time. */ |
| 102 |
|
| static bool |
| 103 |
2285 |
| eo_cop_warns_uninit(pTHX_ COP *cop) |
| 104 |
|
| { |
| 105 |
|
| bool on; |
| 106 |
|
| COP *was; |
| 107 |
2285 |
▶ | if (cop->cop_warnings == pWARN_STD) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cop->cop_warnings == pWARN_STD) |
0 |
2285 |
2285 |
|
| 108 |
0 |
| return TRUE; |
| 109 |
2285 |
▶ | if (cop->cop_warnings == pWARN_NONE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cop->cop_warnings == pWARN_NONE) |
5 |
2280 |
2285 |
|
| 110 |
5 |
| return FALSE; |
| 111 |
2280 |
| was = PL_curcop; |
| 112 |
2280 |
| PL_curcop = cop; |
| 113 |
2280 |
| on = ckWARN(WARN_UNINITIALIZED) ? TRUE : FALSE; |
| 114 |
2280 |
| PL_curcop = was; |
| 115 |
2280 |
| return on; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
|
| static bool |
| 119 |
9728 |
| eo_is_context_op(OP *o) |
| 120 |
|
| { |
| 121 |
9728 |
▶ | switch (o->op_type) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (o->op_type) { |
21 |
9707 |
9728 |
|
| 122 |
21 |
| case OP_LEAVELOOP: |
| 123 |
|
| case OP_LEAVE: |
| 124 |
|
| case OP_LEAVETRY: |
| 125 |
|
| case OP_GREPWHILE: |
| 126 |
|
| case OP_MAPWHILE: |
| 127 |
|
| case OP_SORT: |
| 128 |
|
| case OP_LEAVEGIVEN: |
| 129 |
|
| case OP_LEAVEWHEN: |
| 130 |
|
| #if PERL_VERSION_GE(5,34,0) |
| 131 |
|
| case OP_LEAVETRYCATCH: |
| 132 |
|
| #endif |
| 133 |
|
| #if PERL_VERSION_GE(5,36,0) |
| 134 |
|
| case OP_PUSHDEFER: |
| 135 |
|
| #endif |
| 136 |
21 |
| return TRUE; |
| 137 |
9707 |
| default: |
| 138 |
9707 |
| return FALSE; |
| 139 |
|
| } |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
|
| static void eo_walk_list(pTHX_ eo_walk_t *w, OP *o); |
| 143 |
|
| |
| 144 |
|
| static void |
| 145 |
26240 |
| eo_walk_one(pTHX_ eo_walk_t *w, OP *o) |
| 146 |
|
| { |
| 147 |
26240 |
▶ | if (o == w->skip) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o == w->skip) |
2262 |
23978 |
26240 |
|
| 148 |
2262 |
| return; |
| 149 |
|
| |
| 150 |
23978 |
▶ | if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns |
Branch: 3 branches
| Branch | True | False | Total |
| if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns |
19355 |
4623 |
23978 |
| if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns |
0 |
19355 |
19355 |
| if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns |
2285 |
2338 |
4623 |
|
| 151 |
2285 |
▶ | && eo_cop_warns_uninit(aTHX_ (COP *)o)) |
Branch: 1 branch
| Branch | True | False | Total |
| && eo_cop_warns_uninit(aTHX_ (COP *)o)) |
2278 |
7 |
2285 |
|
| 152 |
2278 |
| w->warns = TRUE; |
| 153 |
|
| |
| 154 |
23978 |
| switch (o->op_type) { |
| 155 |
5 |
| case OP_WANTARRAY: |
| 156 |
5 |
| w->why = "it calls wantarray"; |
| 157 |
5 |
| return; |
| 158 |
2 |
| case OP_CALLER: |
| 159 |
2 |
| w->why = "it calls caller"; |
| 160 |
2 |
| return; |
| 161 |
2 |
| case OP_GOTO: |
| 162 |
|
| case OP_DUMP: |
| 163 |
2 |
| w->why = "it uses goto"; |
| 164 |
2 |
| return; |
| 165 |
1 |
| case OP_ENTEREVAL: |
| 166 |
1 |
| w->why = "it uses a string eval"; |
| 167 |
1 |
| return; |
| 168 |
|
| #if PERL_VERSION_GE(5,16,0) |
| 169 |
1 |
| case OP_RUNCV: |
| 170 |
1 |
| w->why = "it uses __SUB__"; |
| 171 |
1 |
| return; |
| 172 |
|
| #endif |
| 173 |
|
| #if PERL_VERSION_GE(5,26,0) |
| 174 |
0 |
| case OP_ARGCHECK: |
| 175 |
0 |
| w->why = "it has a signature"; |
| 176 |
0 |
| return; |
| 177 |
|
| #endif |
| 178 |
|
| #if PERL_VERSION_GE(5,43,3) |
| 179 |
1 |
| case OP_MULTIPARAM: |
| 180 |
1 |
| w->why = "it has a signature"; |
| 181 |
1 |
| return; |
| 182 |
|
| #endif |
| 183 |
6 |
| case OP_RV2AV: |
| 184 |
6 |
▶ | if (eo_is_defgv(aTHX_ eo_kid(o))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eo_is_defgv(aTHX_ eo_kid(o))) { |
3 |
3 |
6 |
|
| 185 |
3 |
| w->why = "it reads @_ after its parameters"; |
| 186 |
3 |
| return; |
| 187 |
|
| } |
| 188 |
3 |
| break; |
| 189 |
3 |
| case OP_ANONCODE: { |
| 190 |
|
| /* A closure is cloned with find_runcv, which reads the context |
| 191 |
|
| * stack, so a frameless call would hand it the caller's pad. */ |
| 192 |
3 |
| CV *proto = (CV *)PAD_SVl(o->op_targ); |
| 193 |
3 |
▶ | if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto)) { |
3 |
0 |
3 |
| if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto)) { |
3 |
0 |
3 |
| if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto)) { |
3 |
0 |
3 |
|
| 194 |
3 |
| w->why = "it makes a closure over its own variables"; |
| 195 |
3 |
| return; |
| 196 |
|
| } |
| 197 |
0 |
| break; |
| 198 |
|
| } |
| 199 |
|
| #ifdef PMf_HAS_CV |
| 200 |
1 |
| case OP_QR: |
| 201 |
1 |
▶ | if (cPMOPo->op_pmflags & PMf_HAS_CV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cPMOPo->op_pmflags & PMf_HAS_CV) { |
1 |
0 |
1 |
|
| 202 |
1 |
| w->why = "it makes a qr with a code block"; |
| 203 |
1 |
| return; |
| 204 |
|
| } |
| 205 |
0 |
| break; |
| 206 |
|
| #endif |
| 207 |
2 |
| case OP_SHIFT: |
| 208 |
|
| case OP_POP: |
| 209 |
2 |
▶ | if (!(o->op_flags & OPf_KIDS)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(o->op_flags & OPf_KIDS)) { |
2 |
0 |
2 |
|
| 210 |
2 |
| w->why = "it reads @_ after its parameters"; |
| 211 |
2 |
| return; |
| 212 |
|
| } |
| 213 |
0 |
| break; |
| 214 |
0 |
| case OP_RV2GV: |
| 215 |
0 |
▶ | if (eo_is_defgv(aTHX_ eo_kid(o))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (eo_is_defgv(aTHX_ eo_kid(o))) { |
0 |
0 |
0 |
|
| 216 |
0 |
| w->why = "it uses *_"; |
| 217 |
0 |
| return; |
| 218 |
|
| } |
| 219 |
0 |
| break; |
| 220 |
1 |
| case OP_AELEMFAST: |
| 221 |
|
| #if !PERL_VERSION_GE(5,16,0) |
| 222 |
|
| if (o->op_flags & OPf_SPECIAL) |
| 223 |
|
| break; |
| 224 |
|
| #endif |
| 225 |
1 |
▶ | if (cGVOPx_gv(o) == PL_defgv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cGVOPx_gv(o) == PL_defgv) { |
1 |
0 |
1 |
|
| 226 |
1 |
| w->why = "it reads @_ after its parameters"; |
| 227 |
1 |
| return; |
| 228 |
|
| } |
| 229 |
0 |
| break; |
| 230 |
45 |
| case OP_ENTERSUB: |
| 231 |
45 |
▶ | if (!(o->op_flags & OPf_STACKED)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(o->op_flags & OPf_STACKED)) { |
1 |
44 |
45 |
|
| 232 |
1 |
| w->why = "it calls a sub as &name; which passes on @_"; |
| 233 |
1 |
| return; |
| 234 |
|
| } |
| 235 |
44 |
| break; |
| 236 |
19 |
| case OP_RETURN: |
| 237 |
19 |
▶ | if (w->unwind) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->unwind) { |
8 |
11 |
19 |
|
| 238 |
8 |
| w->why = "it returns from inside a loop or a block"; |
| 239 |
8 |
| return; |
| 240 |
|
| } |
| 241 |
11 |
| w->has_return = TRUE; |
| 242 |
|
| { |
| 243 |
|
| OP *k; |
| 244 |
33 |
▶ | for (k = eo_kid(o); k; k = OpSIBLING(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
11 |
11 |
22 |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
22 |
11 |
33 |
|
| 245 |
22 |
▶ | if (k->op_type != OP_PUSHMARK && eo_tail_dep(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (k->op_type != OP_PUSHMARK && eo_tail_dep(k)) |
11 |
11 |
22 |
| if (k->op_type != OP_PUSHMARK && eo_tail_dep(k)) |
0 |
11 |
11 |
|
| 246 |
0 |
| w->ret_dep = TRUE; |
| 247 |
|
| } |
| 248 |
11 |
| break; |
| 249 |
3 |
| case OP_NEXT: |
| 250 |
|
| case OP_LAST: |
| 251 |
|
| case OP_REDO: |
| 252 |
3 |
▶ | if (!(o->op_flags & OPf_SPECIAL) || !w->loops) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(o->op_flags & OPf_SPECIAL) || !w->loops) { |
2 |
1 |
3 |
| if (!(o->op_flags & OPf_SPECIAL) || !w->loops) { |
1 |
1 |
2 |
|
| 253 |
2 |
| w->why = "it leaves a loop it is not inside"; |
| 254 |
2 |
| return; |
| 255 |
|
| } |
| 256 |
1 |
| break; |
| 257 |
23886 |
| default: |
| 258 |
23886 |
| break; |
| 259 |
|
| } |
| 260 |
|
| |
| 261 |
23945 |
▶ | if (o->op_flags & OPf_KIDS) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_flags & OPf_KIDS) { |
9728 |
14217 |
23945 |
|
| 262 |
9728 |
| bool ctx = eo_is_context_op(o); |
| 263 |
9728 |
| bool loop = o->op_type == OP_LEAVELOOP; |
| 264 |
9728 |
▶ | if (ctx) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) |
21 |
9707 |
9728 |
|
| 265 |
21 |
| w->unwind++; |
| 266 |
9728 |
▶ | if (loop) |
Branch: 1 branch
| Branch | True | False | Total |
| if (loop) |
7 |
9721 |
9728 |
|
| 267 |
7 |
| w->loops++; |
| 268 |
9728 |
| eo_walk_list(aTHX_ w, cUNOPo->op_first); |
| 269 |
9728 |
▶ | if (ctx) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) |
21 |
9707 |
9728 |
|
| 270 |
21 |
| w->unwind--; |
| 271 |
9728 |
▶ | if (loop) |
Branch: 1 branch
| Branch | True | False | Total |
| if (loop) |
7 |
9721 |
9728 |
|
| 272 |
7 |
| w->loops--; |
| 273 |
|
| } |
| 274 |
|
| } |
| 275 |
|
| |
| 276 |
|
| static void |
| 277 |
12010 |
| eo_walk_list(pTHX_ eo_walk_t *w, OP *o) |
| 278 |
|
| { |
| 279 |
38250 |
▶ | for (; o && !w->why; o = OpSIBLING(o)) |
Branch: 3 branches
| Branch | True | False | Total |
| for (; o && !w->why; o = OpSIBLING(o)) |
14254 |
11986 |
26240 |
| for (; o && !w->why; o = OpSIBLING(o)) |
26264 |
11986 |
38250 |
| for (; o && !w->why; o = OpSIBLING(o)) |
26240 |
24 |
26264 |
|
| 280 |
26240 |
| eo_walk_one(aTHX_ w, o); |
| 281 |
12010 |
| } |
| 282 |
|
| |
| 283 |
|
| static bool |
| 284 |
9100 |
| eo_is_stmt(OP *o) |
| 285 |
|
| { |
| 286 |
9100 |
▶ | return eo_is_type(o, OP_NEXTSTATE) || eo_is_type(o, OP_DBSTATE); |
Branch: 2 branches
| Branch | True | False | Total |
| return eo_is_type(o, OP_NEXTSTATE) || eo_is_type(o, OP_DBSTATE); |
4550 |
4550 |
9100 |
| return eo_is_type(o, OP_NEXTSTATE) || eo_is_type(o, OP_DBSTATE); |
0 |
4550 |
4550 |
|
| 287 |
|
| } |
| 288 |
|
| |
| 289 |
|
| /* Whether an op in tail position takes its context at run time. The last |
| 290 |
|
| * statement of a sub has none of its own: an op there with no want flag |
| 291 |
|
| * asks block_gimme, which reads the nearest sub context. A frameless call |
| 292 |
|
| * has none of its own, so it lends the call's context to the one it |
| 293 |
|
| * finds. */ |
| 294 |
|
| static bool |
| 295 |
4581 |
| eo_tail_dep(OP *o) |
| 296 |
|
| { |
| 297 |
|
| OP *k, *last; |
| 298 |
|
| |
| 299 |
4581 |
▶ | if (!o || (o->op_flags & OPf_WANT)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!o || (o->op_flags & OPf_WANT)) |
4581 |
0 |
4581 |
| if (!o || (o->op_flags & OPf_WANT)) |
2155 |
2426 |
4581 |
|
| 300 |
2155 |
| return FALSE; |
| 301 |
|
| |
| 302 |
2426 |
| switch (o->op_type) { |
| 303 |
6 |
| case OP_NEXTSTATE: |
| 304 |
|
| case OP_DBSTATE: |
| 305 |
|
| case OP_RETURN: |
| 306 |
6 |
| return FALSE; |
| 307 |
2249 |
| case OP_LINESEQ: |
| 308 |
|
| case OP_SCOPE: |
| 309 |
|
| case OP_LEAVE: |
| 310 |
2249 |
| last = NULL; |
| 311 |
11349 |
▶ | for (k = eo_kid(o); k; k = OpSIBLING(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
6851 |
2249 |
9100 |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
9100 |
2249 |
11349 |
|
| 312 |
9100 |
▶ | if (!eo_is_stmt(k) && k->op_type != OP_ENTER) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!eo_is_stmt(k) && k->op_type != OP_ENTER) |
4550 |
4550 |
9100 |
| if (!eo_is_stmt(k) && k->op_type != OP_ENTER) |
4550 |
0 |
4550 |
|
| 313 |
4550 |
| last = k; |
| 314 |
2249 |
| return eo_tail_dep(last); |
| 315 |
19 |
| case OP_NULL: |
| 316 |
19 |
▶ | if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { |
19 |
0 |
19 |
| if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { |
19 |
0 |
19 |
| if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { |
0 |
19 |
19 |
|
| 317 |
0 |
| last = NULL; |
| 318 |
0 |
▶ | for (k = eo_kid(o); k; k = OpSIBLING(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
0 |
0 |
0 |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
0 |
0 |
0 |
|
| 319 |
0 |
▶ | if (!eo_is_stmt(k) && k->op_type != OP_ENTER) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!eo_is_stmt(k) && k->op_type != OP_ENTER) |
0 |
0 |
0 |
| if (!eo_is_stmt(k) && k->op_type != OP_ENTER) |
0 |
0 |
0 |
|
| 320 |
0 |
| last = k; |
| 321 |
0 |
| return eo_tail_dep(last); |
| 322 |
|
| } |
| 323 |
32 |
▶ | for (k = eo_kid(o); k; k = OpSIBLING(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
0 |
13 |
13 |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
19 |
13 |
32 |
|
| 324 |
19 |
▶ | if (eo_tail_dep(k)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (eo_tail_dep(k)) |
6 |
13 |
19 |
|
| 325 |
6 |
| return TRUE; |
| 326 |
13 |
| return FALSE; |
| 327 |
19 |
| case OP_AND: |
| 328 |
|
| case OP_OR: |
| 329 |
|
| case OP_DOR: |
| 330 |
|
| case OP_COND_EXPR: |
| 331 |
66 |
▶ | for (k = eo_kid(o); k; k = OpSIBLING(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
34 |
13 |
47 |
| for (k = eo_kid(o); k; k = OpSIBLING(k)) |
53 |
13 |
66 |
|
| 332 |
53 |
▶ | if (eo_tail_dep(k)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (eo_tail_dep(k)) |
6 |
47 |
53 |
|
| 333 |
6 |
| return TRUE; |
| 334 |
13 |
| return FALSE; |
| 335 |
133 |
| default: |
| 336 |
133 |
| return TRUE; |
| 337 |
|
| } |
| 338 |
|
| } |
| 339 |
|
| |
| 340 |
|
| /* `my ($a, $b, ...) = @_;` as the first statement. The tree keeps its shape |
| 341 |
|
| * when padrange rewrites the execution order (5.18 on), so the tree is read, |
| 342 |
|
| * not the order. Returns the aassign, or NULL when the first statement is |
| 343 |
|
| * something else. */ |
| 344 |
|
| static OP * |
| 345 |
2284 |
| eo_find_binding(pTHX_ OP *body, PADOFFSET **params, U16 *nparams, const char **why) |
| 346 |
|
| { |
| 347 |
|
| OP *stmt, *aassign, *rhs, *lhs, *k; |
| 348 |
2284 |
| U16 n = 0; |
| 349 |
|
| |
| 350 |
2284 |
| *params = NULL; |
| 351 |
2284 |
| *nparams = 0; |
| 352 |
|
| |
| 353 |
2284 |
| stmt = eo_kid(body); |
| 354 |
4567 |
▶ | while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) |
Branch: 3 branches
| Branch | True | False | Total |
| while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) |
4567 |
0 |
4567 |
| while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) |
2283 |
2284 |
4567 |
| while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) |
0 |
2284 |
2284 |
|
| 355 |
2283 |
▶ | stmt = OpSIBLING(stmt); |
Branch: 1 branch
| Branch | True | False | Total |
| stmt = OpSIBLING(stmt); |
2283 |
0 |
2283 |
|
| 356 |
2284 |
▶ | if (!stmt || stmt->op_type != OP_AASSIGN) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!stmt || stmt->op_type != OP_AASSIGN) |
2284 |
0 |
2284 |
| if (!stmt || stmt->op_type != OP_AASSIGN) |
20 |
2264 |
2284 |
|
| 357 |
20 |
| return NULL; |
| 358 |
2264 |
| aassign = stmt; |
| 359 |
|
| |
| 360 |
2264 |
| rhs = eo_kid(aassign); |
| 361 |
2264 |
▶ | lhs = rhs ? OpSIBLING(rhs) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| lhs = rhs ? OpSIBLING(rhs) : NULL; |
2264 |
0 |
2264 |
| lhs = rhs ? OpSIBLING(rhs) : NULL; |
2264 |
0 |
2264 |
|
| 362 |
2264 |
▶ | if (!eo_is_type(rhs, OP_LIST) || !eo_is_type(lhs, OP_LIST)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!eo_is_type(rhs, OP_LIST) || !eo_is_type(lhs, OP_LIST)) |
2264 |
0 |
2264 |
| if (!eo_is_type(rhs, OP_LIST) || !eo_is_type(lhs, OP_LIST)) |
0 |
2264 |
2264 |
|
| 363 |
0 |
| return NULL; |
| 364 |
|
| |
| 365 |
2264 |
| k = eo_kid(rhs); |
| 366 |
2264 |
▶ | if (!k || !(k->op_type == OP_PUSHMARK |
Branch: 2 branches
| Branch | True | False | Total |
| if (!k || !(k->op_type == OP_PUSHMARK |
2264 |
0 |
2264 |
| if (!k || !(k->op_type == OP_PUSHMARK |
2264 |
0 |
2264 |
|
| 367 |
|
| #if PERL_VERSION_GE(5,18,0) |
| 368 |
2264 |
▶ | || k->op_type == OP_PADRANGE |
Branch: 1 branch
| Branch | True | False | Total |
| || k->op_type == OP_PADRANGE |
0 |
2264 |
2264 |
|
| 369 |
|
| #endif |
| 370 |
|
| )) |
| 371 |
0 |
| return NULL; |
| 372 |
2264 |
▶ | k = OpSIBLING(k); |
Branch: 1 branch
| Branch | True | False | Total |
| k = OpSIBLING(k); |
2264 |
0 |
2264 |
|
| 373 |
2264 |
▶ | if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) |
Branch: 5 branches
| Branch | True | False | Total |
| if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) |
2264 |
0 |
2264 |
| if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) |
2264 |
0 |
2264 |
| if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) |
2264 |
0 |
2264 |
| if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) |
0 |
2264 |
2264 |
| if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) |
0 |
0 |
0 |
|
| 374 |
0 |
| return NULL; |
| 375 |
|
| |
| 376 |
2264 |
| k = eo_kid(lhs); |
| 377 |
2264 |
▶ | if (!k || k->op_type != OP_PUSHMARK) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!k || k->op_type != OP_PUSHMARK) |
2264 |
0 |
2264 |
| if (!k || k->op_type != OP_PUSHMARK) |
0 |
2264 |
2264 |
|
| 378 |
0 |
| return NULL; |
| 379 |
4566 |
▶ | for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { |
Branch: 3 branches
| Branch | True | False | Total |
| for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { |
2264 |
0 |
2264 |
| for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { |
40 |
2262 |
2302 |
| for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { |
2304 |
2262 |
4566 |
|
| 380 |
2304 |
▶ | if (k->op_type == OP_PADSV && (k->op_private & OPpLVAL_INTRO) |
Branch: 2 branches
| Branch | True | False | Total |
| if (k->op_type == OP_PADSV && (k->op_private & OPpLVAL_INTRO) |
2303 |
1 |
2304 |
| if (k->op_type == OP_PADSV && (k->op_private & OPpLVAL_INTRO) |
2302 |
1 |
2303 |
|
| 381 |
|
| #ifdef OPpPAD_STATE |
| 382 |
2302 |
▶ | && !(k->op_private & OPpPAD_STATE) |
Branch: 1 branch
| Branch | True | False | Total |
| && !(k->op_private & OPpPAD_STATE) |
2302 |
0 |
2302 |
|
| 383 |
|
| #endif |
| 384 |
|
| ) { |
| 385 |
2302 |
| n++; |
| 386 |
2302 |
| continue; |
| 387 |
|
| } |
| 388 |
2 |
▶ | if (k->op_type == OP_PADAV || k->op_type == OP_PADHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (k->op_type == OP_PADAV || k->op_type == OP_PADHV) |
1 |
1 |
2 |
| if (k->op_type == OP_PADAV || k->op_type == OP_PADHV) |
0 |
1 |
1 |
|
| 389 |
1 |
| *why = "its parameters end in an array or a hash"; |
| 390 |
|
| else |
| 391 |
1 |
| *why = "its first statement assigns @_ to something other than new scalars"; |
| 392 |
2 |
| return NULL; |
| 393 |
|
| } |
| 394 |
2262 |
▶ | if (!n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!n) |
0 |
2262 |
2262 |
|
| 395 |
0 |
| return NULL; |
| 396 |
|
| |
| 397 |
2262 |
| Newx(*params, n, PADOFFSET); |
| 398 |
2262 |
| n = 0; |
| 399 |
4563 |
▶ | for (k = OpSIBLING(eo_kid(lhs)); k; k = OpSIBLING(k)) |
Branch: 2 branches
| Branch | True | False | Total |
| for (k = OpSIBLING(eo_kid(lhs)); k; k = OpSIBLING(k)) |
2262 |
0 |
2262 |
| for (k = OpSIBLING(eo_kid(lhs)); k; k = OpSIBLING(k)) |
2301 |
2262 |
4563 |
|
| 400 |
2301 |
▶ | (*params)[n++] = k->op_targ; |
Branch: 1 branch
| Branch | True | False | Total |
| (*params)[n++] = k->op_targ; |
39 |
2262 |
2301 |
|
| 401 |
2262 |
| *nparams = n; |
| 402 |
2262 |
| return aassign; |
| 403 |
|
| } |
| 404 |
|
| |
| 405 |
|
| /* Registers a CV and says whether it can run as an op. The answer is kept |
| 406 |
|
| * on the CV whichever it is, so why_not can give the reason. */ |
| 407 |
|
| static eo_op_t * |
| 408 |
2286 |
| eo_register(pTHX_ CV *cv) |
| 409 |
|
| { |
| 410 |
|
| eo_op_t *e; |
| 411 |
2286 |
| MAGIC *mg = mg_findext((SV *)cv, PERL_MAGIC_ext, &eo_op_vtbl); |
| 412 |
2286 |
| const char *why = NULL; |
| 413 |
|
| |
| 414 |
2286 |
▶ | if (mg && mg->mg_ptr) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (mg && mg->mg_ptr) { |
1 |
2285 |
2286 |
| if (mg && mg->mg_ptr) { |
1 |
0 |
1 |
|
| 415 |
1 |
| e = (eo_op_t *)mg->mg_ptr; |
| 416 |
1 |
| Safefree(e->params); |
| 417 |
1 |
| Safefree(e->why); |
| 418 |
1 |
| Zero(e, 1, eo_op_t); |
| 419 |
|
| } |
| 420 |
|
| else { |
| 421 |
2285 |
| Newxz(e, 1, eo_op_t); |
| 422 |
|
| } |
| 423 |
|
| |
| 424 |
2286 |
▶ | if (CvISXSUB(cv) || !CvROOT(cv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (CvISXSUB(cv) || !CvROOT(cv)) |
2285 |
1 |
2286 |
| if (CvISXSUB(cv) || !CvROOT(cv)) |
0 |
2285 |
2285 |
|
| 425 |
1 |
| why = "it is not a Perl sub with a body"; |
| 426 |
2285 |
▶ | else if (CvLVALUE(cv)) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (CvLVALUE(cv)) |
1 |
2284 |
2285 |
|
| 427 |
1 |
| why = "it is an lvalue sub"; |
| 428 |
2284 |
▶ | else if (CvROOT(cv)->op_type != OP_LEAVESUB) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (CvROOT(cv)->op_type != OP_LEAVESUB) |
0 |
2284 |
2284 |
|
| 429 |
0 |
| why = "its body does not end in an ordinary sub return"; |
| 430 |
|
| |
| 431 |
2286 |
▶ | if (!why) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!why) { |
2284 |
2 |
2286 |
|
| 432 |
2284 |
| OP *body = eo_kid(CvROOT(cv)); |
| 433 |
|
| OP *binding; |
| 434 |
|
| eo_walk_t w; |
| 435 |
2284 |
| Zero(&w, 1, eo_walk_t); |
| 436 |
|
| |
| 437 |
2284 |
| ENTER; |
| 438 |
2284 |
| SAVECOMPPAD(); |
| 439 |
2284 |
| PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1); |
| 440 |
|
| |
| 441 |
2284 |
| binding = eo_find_binding(aTHX_ body, &e->params, &e->nparams, &why); |
| 442 |
2284 |
▶ | if (!why) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!why) { |
2282 |
2 |
2284 |
|
| 443 |
2282 |
▶ | w.skip = binding ? eo_kid(binding) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| w.skip = binding ? eo_kid(binding) : NULL; |
2262 |
20 |
2282 |
|
| 444 |
2282 |
| eo_walk_list(aTHX_ &w, body); |
| 445 |
2282 |
| why = w.why; |
| 446 |
|
| } |
| 447 |
|
| |
| 448 |
2284 |
| LEAVE; |
| 449 |
|
| |
| 450 |
2284 |
▶ | if (!why) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!why) { |
2249 |
35 |
2284 |
|
| 451 |
2249 |
| e->root = CvROOT(cv); |
| 452 |
2249 |
▶ | e->entry = binding ? binding->op_next : CvSTART(cv); |
Branch: 1 branch
| Branch | True | False | Total |
| e->entry = binding ? binding->op_next : CvSTART(cv); |
2243 |
6 |
2249 |
|
| 453 |
2249 |
| e->has_return = w.has_return; |
| 454 |
2249 |
▶ | e->ctx_dep = eo_tail_dep(body) || w.ret_dep; |
Branch: 2 branches
| Branch | True | False | Total |
| e->ctx_dep = eo_tail_dep(body) || w.ret_dep; |
2116 |
133 |
2249 |
| e->ctx_dep = eo_tail_dep(body) || w.ret_dep; |
0 |
2116 |
2116 |
|
| 455 |
2249 |
| e->need_runcv = w.warns; |
| 456 |
2249 |
| e->accepted = TRUE; |
| 457 |
2249 |
| eo_arm(aTHX_ cv, e); |
| 458 |
|
| } |
| 459 |
|
| } |
| 460 |
|
| |
| 461 |
2286 |
▶ | if (why) |
Branch: 1 branch
| Branch | True | False | Total |
| if (why) |
37 |
2249 |
2286 |
|
| 462 |
37 |
| e->why = savepv(why); |
| 463 |
|
| |
| 464 |
2286 |
▶ | if (!mg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mg) { |
2285 |
1 |
2286 |
|
| 465 |
2285 |
| mg = sv_magicext((SV *)cv, NULL, PERL_MAGIC_ext, &eo_op_vtbl, (const char *)e, 0); |
| 466 |
|
| #ifdef USE_ITHREADS |
| 467 |
|
| mg->mg_flags |= MGf_DUP; |
| 468 |
|
| #endif |
| 469 |
|
| } |
| 470 |
2286 |
| return e; |
| 471 |
|
| } |
| 472 |
|
| |
| 473 |
|
| static bool |
| 474 |
37 |
| eo_strict_on(pTHX) |
| 475 |
|
| { |
| 476 |
|
| #if PERL_VERSION_GE(5,13,7) |
| 477 |
37 |
| SV *v = cop_hints_fetch_pvs(PL_curcop, EO_STRICT_KEY, 0); |
| 478 |
37 |
▶ | return v && v != &PL_sv_placeholder && SvTRUE(v); |
Branch: 3 branches
| Branch | True | False | Total |
| return v && v != &PL_sv_placeholder && SvTRUE(v); |
37 |
0 |
37 |
| return v && v != &PL_sv_placeholder && SvTRUE(v); |
2 |
35 |
37 |
| return v && v != &PL_sv_placeholder && SvTRUE(v); |
2 |
0 |
2 |
|
| 479 |
|
| #else |
| 480 |
|
| HV *hh = GvHV(PL_hintgv); |
| 481 |
|
| SV **v = hh ? hv_fetchs(hh, EO_STRICT_KEY, 0) : NULL; |
| 482 |
|
| return v && SvTRUE(*v); |
| 483 |
|
| #endif |
| 484 |
|
| } |
| 485 |
|
| |
| 486 |
|
| static CV * |
| 487 |
2378 |
| eo_code_arg(pTHX_ SV *code, const char *who) |
| 488 |
|
| { |
| 489 |
2378 |
▶ | SvGETMAGIC(code); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(code); |
0 |
2378 |
2378 |
| SvGETMAGIC(code); |
0 |
0 |
0 |
|
| 490 |
2378 |
▶ | if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) |
2376 |
2 |
2378 |
| if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) |
0 |
2376 |
2376 |
|
| 491 |
2 |
| Perl_croak(aTHX_ "%s needs a code reference", who); |
| 492 |
2376 |
| return (CV *)SvRV(code); |
| 493 |
|
| } |
| 494 |
|
| |
| 495 |
|
| #endif |