include/ex_op_reg.h

filter: Statementstmt 93.9% 247 / 265 (2 uncoverable) Branchbran 81.8% 212 / 264 (12 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 87.9% 459 / 529 (14 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary Op.xs »
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 2 eo_mg_free(pTHX_ SV *sv, MAGIC *mg)
9 {
10 2 eo_op_t *e = (eo_op_t *)mg->mg_ptr;
11 PERL_UNUSED_ARG(sv);
12 /*
13 # uncoverable branch false
14 # uncoverable condition right count:1 */
15 2 ▶ if (e) {
Branch: 1 branch
BranchTrueFalseTotal
if (e) { 2 0 2
16 2 Safefree(e->params);
17 2 Safefree(e->why);
18 2 Safefree(e);
19 2 mg->mg_ptr = NULL;
20 }
21 2 return 0;
22 }
23  
24 #ifdef USE_ITHREADS
25 static int
26 eo_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param)
27 {
28 eo_op_t *from = (eo_op_t *)mg->mg_ptr;
29 eo_op_t *to;
30 PERL_UNUSED_ARG(param);
31 /*
32 # uncoverable branch true
33 # uncoverable condition left count:1 */
34 if (!from)
35 return 0; /* # uncoverable statement */
36 Newx(to, 1, eo_op_t);
37 StructCopy(from, to, eo_op_t);
38 to->params = NULL;
39 if (from->nparams) {
40 Newx(to->params, from->nparams, PADOFFSET);
41 Copy(from->params, to->params, from->nparams, PADOFFSET);
42 }
43 to->why = from->why ? savepv(from->why) : NULL;
44 mg->mg_ptr = (char *)to;
45 return 0;
46 }
47 #endif
48  
49 static MGVTBL eo_op_vtbl = {
50 NULL, NULL, NULL, NULL, eo_mg_free, NULL,
51 #ifdef USE_ITHREADS
52 eo_mg_dup,
53 #else
54 NULL,
55 #endif
56 NULL
57 };
58  
59 static eo_op_t *
60 1682839 eo_op_find(pTHX_ CV *cv)
61 {
62 1682839 MAGIC *mg = mg_findext((SV *)cv, PERL_MAGIC_ext, &eo_op_vtbl);
63 1682839 ▶ return mg ? (eo_op_t *)mg->mg_ptr : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return mg ? (eo_op_t *)mg->mg_ptr : NULL; 1682835 4 1682839
64 }
65  
66 /* An op whose sub has been redefined in place, or undefined, has a body
67 * that is no longer the one registration looked at. */
68 static eo_op_t *
69 1682783 eo_op_live(pTHX_ CV *cv)
70 {
71 1682783 eo_op_t *e = eo_op_find(aTHX_ cv);
72 1682783 ▶ if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) /* # uncoverable condition left count:3 */
Branch: 4 branches
BranchTrueFalseTotal
if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) /* # uncoverable condition left count:3 */ 1682780 3 1682783
if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) /* # uncoverable condition left count:3 */ 1682729 51 1682780
if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) /* # uncoverable condition left count:3 */ 1682729 0 1682729
if (!e || !e->accepted || CvISXSUB(cv) || CvROOT(cv) != e->root) /* # uncoverable condition left count:3 */ 0 1682729 1682729
73 54 return NULL;
74 1682729 return e;
75 }
76  
77 static OP *
78 3312 eo_kid(OP *o)
79 {
80 3312 ▶ return (o && (o->op_flags & OPf_KIDS)) ? cUNOPx(o)->op_first : NULL; /* # uncoverable condition right count:1 */
Branch: 2 branches
BranchTrueFalseTotal
return (o && (o->op_flags & OPf_KIDS)) ? cUNOPx(o)->op_first : NULL; /* # uncoverable condition right count:1 */ 3312 0 3312
return (o && (o->op_flags & OPf_KIDS)) ? cUNOPx(o)->op_first : NULL; /* # uncoverable condition right count:1 */ 3310 2 3312
81 }
82  
83 static bool
84 3826 eo_is_type(OP *o, OPCODE type)
85 {
86 3826 ▶ return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); /* # uncoverable condition right count:1 */
Branch: 4 branches
BranchTrueFalseTotal
return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); /* # uncoverable condition right count:1 */ 3826 0 3826
return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); /* # uncoverable condition right count:1 */ 2767 1059 3826
return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); /* # uncoverable condition right count:1 */ 746 2021 2767
return o && (o->op_type == type || (o->op_type == OP_NULL && o->op_targ == type)); /* # uncoverable condition right count:1 */ 636 110 746
87 }
88  
89 static bool
90 330 eo_is_defgv(pTHX_ OP *o)
91 {
92 330 ▶ return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; /* # uncoverable condition right count:1 */
Branch: 3 branches
BranchTrueFalseTotal
return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; /* # uncoverable condition right count:1 */ 330 0 330
return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; /* # uncoverable condition right count:1 */ 329 1 330
return o && o->op_type == OP_GV && cGVOPx_gv(o) == PL_defgv; /* # uncoverable condition right count:1 */ 321 8 329
93 }
94  
95 typedef struct {
96 const char *why;
97 U32 loops;
98 U32 unwind;
99 bool has_return;
100 bool ret_dep;
101 bool warns;
102 OP *skip;
103 } eo_walk_t;
104  
105 /* Whether a statement could raise an "uninitialized" warning, whose message
106 * names the variable by looking in the running sub's pad. With no lexical
107 * warnings it depends on $^W, which can change at any time. */
108 static bool
109 341 eo_cop_warns_uninit(pTHX_ COP *cop)
110 {
111 bool on;
112 COP *was;
113 341 ▶ if (cop->cop_warnings == pWARN_STD)
Branch: 1 branch
BranchTrueFalseTotal
if (cop->cop_warnings == pWARN_STD) 1 340 341
114 1 return TRUE;
115 340 ▶ if (cop->cop_warnings == pWARN_NONE)
Branch: 1 branch
BranchTrueFalseTotal
if (cop->cop_warnings == pWARN_NONE) 5 335 340
116 5 return FALSE;
117 335 was = PL_curcop;
118 335 PL_curcop = cop;
119 335 on = ckWARN(WARN_UNINITIALIZED) ? TRUE : FALSE;
120 335 PL_curcop = was;
121 335 return on;
122 }
123  
124 /* Whether an anon sub's pad has a name taken from an outer pad. */
125 static bool
126 4 eo_captures(pTHX_ CV *proto)
127 {
128 4 PADLIST *padlist = CvPADLIST(proto);
129 I32 i;
130 /*
131 # uncoverable branch true
132 # uncoverable condition left count:1 */
133 4 ▶ if (!padlist)
Branch: 1 branch
BranchTrueFalseTotal
if (!padlist) 0 4 4
134 0 return FALSE; /* # uncoverable statement */
135 #if PERL_VERSION_GE(5,22,0)
136 {
137 4 PADNAMELIST *names = PadlistNAMES(padlist);
138 4 PADNAME **pn = PadnamelistARRAY(names);
139 6 ▶ for (i = 1; i <= PadnamelistMAX(names); i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= PadnamelistMAX(names); i++) 5 1 6
140 5 ▶ if (pn[i] && PadnameLEN(pn[i]) && PadnameOUTER(pn[i])) /* # uncoverable condition right count:1 */
Branch: 3 branches
BranchTrueFalseTotal
if (pn[i] && PadnameLEN(pn[i]) && PadnameOUTER(pn[i])) /* # uncoverable condition right count:1 */ 5 0 5
if (pn[i] && PadnameLEN(pn[i]) && PadnameOUTER(pn[i])) /* # uncoverable condition right count:1 */ 4 1 5
if (pn[i] && PadnameLEN(pn[i]) && PadnameOUTER(pn[i])) /* # uncoverable condition right count:1 */ 3 1 4
141 3 return TRUE;
142 }
143 #else
144 {
145 # if PERL_VERSION_GE(5,18,0)
146 AV *names = PadlistNAMES(padlist);
147 # else
148 AV *names = (AV *)AvARRAY((AV *)padlist)[0];
149 # endif
150 SV **pn = AvARRAY(names);
151 for (i = 1; i <= av_len(names); i++)
152 if (pn[i] && pn[i] != &PL_sv_undef && SvPOK(pn[i]) && SvCUR(pn[i]) && SvFAKE(pn[i]))
153 return TRUE;
154 }
155 #endif
156 1 return FALSE;
157 }
158  
159 static bool
160 2167 eo_is_context_op(OP *o)
161 {
162 2167 ▶ switch (o->op_type) {
Branch: 1 branch
BranchTrueFalseTotal
switch (o->op_type) { 45 2122 2167
163 45 case OP_LEAVELOOP:
164 case OP_LEAVE:
165 case OP_LEAVETRY:
166 case OP_GREPWHILE:
167 case OP_MAPWHILE:
168 case OP_SORT:
169 case OP_LEAVEGIVEN:
170 case OP_LEAVEWHEN:
171 #if PERL_VERSION_GE(5,34,0)
172 case OP_LEAVETRYCATCH:
173 #endif
174 #if PERL_VERSION_GE(5,36,0)
175 case OP_PUSHDEFER:
176 #endif
177 45 return TRUE;
178 2122 default:
179 2122 return FALSE;
180 }
181 }
182  
183 static void eo_walk_list(pTHX_ eo_walk_t *w, OP *o);
184  
185 static void
186 5382 eo_walk_one(pTHX_ eo_walk_t *w, OP *o)
187 {
188 5382 ▶ if (o == w->skip)
Branch: 1 branch
BranchTrueFalseTotal
if (o == w->skip) 313 5069 5382
189 313 return;
190  
191 5069 ▶ if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns
Branch: 3 branches
BranchTrueFalseTotal
if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns 4255 814 5069
if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns 4 4251 4255
if ((o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) && !w->warns 341 477 818
192 341 ▶ && eo_cop_warns_uninit(aTHX_ (COP *)o))
Branch: 1 branch
BranchTrueFalseTotal
&& eo_cop_warns_uninit(aTHX_ (COP *)o)) 334 7 341
193 334 w->warns = TRUE;
194  
195 5069 switch (o->op_type) {
196 5 case OP_WANTARRAY:
197 5 w->why = "it calls wantarray";
198 5 return;
199 2 case OP_CALLER:
200 2 w->why = "it calls caller";
201 2 return;
202 2 case OP_GOTO:
203 case OP_DUMP:
204 2 w->why = "it uses goto";
205 2 return;
206 1 case OP_ENTEREVAL:
207 1 w->why = "it uses a string eval";
208 1 return;
209 #if PERL_VERSION_GE(5,16,0)
210 1 case OP_RUNCV:
211 1 w->why = "it uses __SUB__";
212 1 return;
213 #endif
214 #if PERL_VERSION_GE(5,26,0)
215 0 case OP_ARGCHECK:
216 0 w->why = "it has a signature";
217 0 return;
218 #endif
219 #if PERL_VERSION_GE(5,43,3)
220 1 case OP_MULTIPARAM:
221 1 w->why = "it has a signature";
222 1 return;
223 #endif
224 8 case OP_RV2AV:
225 8 ▶ if (eo_is_defgv(aTHX_ eo_kid(o))) {
Branch: 1 branch
BranchTrueFalseTotal
if (eo_is_defgv(aTHX_ eo_kid(o))) { 3 5 8
226 3 w->why = "it reads @_ after its parameters";
227 3 return;
228 }
229 5 break;
230 4 case OP_ANONCODE: {
231 /* A closure is cloned with find_runcv, which reads the context
232 * stack, so a frameless call would hand it the caller's pad. One
233 * that captures nothing never looks there, and with the optimiser
234 * off (the debugger, Devel::Cover) every anon sub is marked for
235 * cloning, so the pad is asked, not the flag. */
236 4 CV *proto = (CV *)PAD_SVl(o->op_targ);
237 /*
238 # uncoverable condition right count:1..2
239 # uncoverable condition right count:3 class:ignore_covered_err */
240 4 ▶ if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto) && eo_captures(aTHX_ proto)) {
Branch: 4 branches
BranchTrueFalseTotal
if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto) && eo_captures(aTHX_ proto)) { 4 0 4
if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto) && eo_captures(aTHX_ proto)) { 4 0 4
if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto) && eo_captures(aTHX_ proto)) { 4 0 4
if (proto && SvTYPE((SV *)proto) == SVt_PVCV && CvCLONE(proto) && eo_captures(aTHX_ proto)) { 3 1 4
241 3 w->why = "it makes a closure over its own variables";
242 3 return;
243 }
244 1 break;
245 }
246 #ifdef PMf_HAS_CV
247 2 case OP_QR:
248 2 ▶ if (cPMOPo->op_pmflags & PMf_HAS_CV) {
Branch: 1 branch
BranchTrueFalseTotal
if (cPMOPo->op_pmflags & PMf_HAS_CV) { 1 1 2
249 1 w->why = "it makes a qr with a code block";
250 1 return;
251 }
252 1 break;
253 #endif
254 4 case OP_SHIFT:
255 case OP_POP:
256 4 ▶ if (!(o->op_flags & OPf_KIDS)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(o->op_flags & OPf_KIDS)) { 3 1 4
257 3 w->why = "it reads @_ after its parameters";
258 3 return;
259 }
260 1 break;
261 4 case OP_RV2GV:
262 4 ▶ if (eo_is_defgv(aTHX_ eo_kid(o))) {
Branch: 1 branch
BranchTrueFalseTotal
if (eo_is_defgv(aTHX_ eo_kid(o))) { 1 3 4
263 1 w->why = "it uses *_";
264 1 return;
265 }
266 3 break;
267 2 case OP_AELEMFAST:
268 #if !PERL_VERSION_GE(5,16,0)
269 if (o->op_flags & OPf_SPECIAL)
270 break;
271 #endif
272 2 ▶ if (cGVOPx_gv(o) == PL_defgv) {
Branch: 1 branch
BranchTrueFalseTotal
if (cGVOPx_gv(o) == PL_defgv) { 1 1 2
273 1 w->why = "it reads @_ after its parameters";
274 1 return;
275 }
276 1 break;
277 61 case OP_ENTERSUB:
278 61 ▶ if (!(o->op_flags & OPf_STACKED)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(o->op_flags & OPf_STACKED)) { 1 60 61
279 1 w->why = "it calls a sub as &name; which passes on @_";
280 1 return;
281 }
282 60 break;
283 55 case OP_RETURN:
284 55 ▶ if (w->unwind) {
Branch: 1 branch
BranchTrueFalseTotal
if (w->unwind) { 3 52 55
285 3 w->why = "it returns from inside an eval, grep, map or sort block";
286 3 return;
287 }
288 52 w->has_return = TRUE;
289 {
290 OP *k;
291 159 ▶ for (k = eo_kid(o); k; k = OpSIBLING(k))
Branch: 2 branches
BranchTrueFalseTotal
for (k = eo_kid(o); k; k = OpSIBLING(k)) 55 52 107
for (k = eo_kid(o); k; k = OpSIBLING(k)) 107 52 159
292 107 ▶ if (k->op_type != OP_PUSHMARK && eo_tail_dep(k))
Branch: 2 branches
BranchTrueFalseTotal
if (k->op_type != OP_PUSHMARK && eo_tail_dep(k)) 55 52 107
if (k->op_type != OP_PUSHMARK && eo_tail_dep(k)) 4 51 55
293 4 w->ret_dep = TRUE;
294 }
295 52 break;
296 3 case OP_NEXT:
297 case OP_LAST:
298 case OP_REDO:
299 3 ▶ if (!(o->op_flags & OPf_SPECIAL) || !w->loops) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(o->op_flags & OPf_SPECIAL) || !w->loops) { 2 1 3
if (!(o->op_flags & OPf_SPECIAL) || !w->loops) { 1 1 2
300 2 w->why = "it leaves a loop it is not inside";
301 2 return;
302 }
303 1 break;
304 4914 default:
305 4914 break;
306 }
307  
308 5039 ▶ if (o->op_flags & OPf_KIDS) {
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_flags & OPf_KIDS) { 2167 2872 5039
309 2167 ▶ bool ctx = eo_is_context_op(o) && o->op_type != OP_LEAVE && o->op_type != OP_LEAVELOOP;
Branch: 3 branches
BranchTrueFalseTotal
bool ctx = eo_is_context_op(o) && o->op_type != OP_LEAVE && o->op_type != OP_LEAVELOOP; 45 2122 2167
bool ctx = eo_is_context_op(o) && o->op_type != OP_LEAVE && o->op_type != OP_LEAVELOOP; 29 16 45
bool ctx = eo_is_context_op(o) && o->op_type != OP_LEAVE && o->op_type != OP_LEAVELOOP; 8 21 29
310 2167 bool loop = o->op_type == OP_LEAVELOOP;
311 2167 ▶ if (ctx)
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) 8 2159 2167
312 8 w->unwind++;
313 2167 ▶ if (loop)
Branch: 1 branch
BranchTrueFalseTotal
if (loop) 21 2146 2167
314 21 w->loops++;
315 2167 eo_walk_list(aTHX_ w, cUNOPo->op_first);
316 2167 ▶ if (ctx)
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) 8 2159 2167
317 8 w->unwind--;
318 2167 ▶ if (loop)
Branch: 1 branch
BranchTrueFalseTotal
if (loop) 21 2146 2167
319 21 w->loops--;
320 }
321 }
322  
323 static void
324 2505 eo_walk_list(pTHX_ eo_walk_t *w, OP *o)
325 {
326 7887 ▶ for (; o && !w->why; o = OpSIBLING(o))
Branch: 3 branches
BranchTrueFalseTotal
for (; o && !w->why; o = OpSIBLING(o)) 2897 2485 5382
for (; o && !w->why; o = OpSIBLING(o)) 5402 2485 7887
for (; o && !w->why; o = OpSIBLING(o)) 5382 20 5402
327 5382 eo_walk_one(aTHX_ w, o);
328 2505 }
329  
330 static bool
331 1443 eo_is_stmt(OP *o)
332 {
333 1443 ▶ return eo_is_type(o, OP_NEXTSTATE) || eo_is_type(o, OP_DBSTATE);
Branch: 2 branches
BranchTrueFalseTotal
return eo_is_type(o, OP_NEXTSTATE) || eo_is_type(o, OP_DBSTATE); 727 716 1443
return eo_is_type(o, OP_NEXTSTATE) || eo_is_type(o, OP_DBSTATE); 4 723 727
334 }
335  
336 /* Whether an op in tail position takes its context at run time. The last
337 * statement of a sub has none of its own: an op there with no want flag
338 * asks block_gimme, which reads the nearest sub context. A frameless call
339 * has none of its own, so it lends the call's context to the one it
340 * finds. */
341 static bool
342 757 eo_tail_dep(OP *o)
343 {
344 OP *k, *last;
345  
346 757 ▶ if (!o || (o->op_flags & OPf_WANT)) /* # uncoverable condition left count:1 */
Branch: 2 branches
BranchTrueFalseTotal
if (!o || (o->op_flags & OPf_WANT)) /* # uncoverable condition left count:1 */ 757 0 757
if (!o || (o->op_flags & OPf_WANT)) /* # uncoverable condition left count:1 */ 243 514 757
347 243 return FALSE;
348  
349 514 switch (o->op_type) {
350 19 case OP_NEXTSTATE:
351 case OP_DBSTATE:
352 case OP_RETURN:
353 19 return FALSE;
354 309 case OP_LINESEQ:
355 case OP_SCOPE:
356 case OP_LEAVE:
357 309 last = NULL;
358 1752 ▶ for (k = eo_kid(o); k; k = OpSIBLING(k))
Branch: 2 branches
BranchTrueFalseTotal
for (k = eo_kid(o); k; k = OpSIBLING(k)) 1134 309 1443
for (k = eo_kid(o); k; k = OpSIBLING(k)) 1443 309 1752
359 1443 ▶ if (!eo_is_stmt(k) && k->op_type != OP_ENTER)
Branch: 2 branches
BranchTrueFalseTotal
if (!eo_is_stmt(k) && k->op_type != OP_ENTER) 723 720 1443
if (!eo_is_stmt(k) && k->op_type != OP_ENTER) 720 3 723
360 720 last = k;
361 309 return eo_tail_dep(last);
362 23 case OP_NULL:
363 /*
364 # uncoverable branch true
365 # uncoverable condition left count:1..3 */
366 23 ▶ if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) {
Branch: 3 branches
BranchTrueFalseTotal
if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { 23 0 23
if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { 23 0 23
if (o->op_targ == OP_LINESEQ || o->op_targ == OP_SCOPE || o->op_targ == OP_LEAVE) { 0 23 23
367 0 last = NULL; /* # uncoverable statement */
368 /*
369 # uncoverable statement
370 # uncoverable branch true
371 # uncoverable branch false
372 # uncoverable condition left count:1..2
373 # uncoverable condition right count:1..2 */
374 0 ▶ for (k = eo_kid(o); k; k = OpSIBLING(k))
Branch: 2 branches
BranchTrueFalseTotal
for (k = eo_kid(o); k; k = OpSIBLING(k)) 0 0 0
for (k = eo_kid(o); k; k = OpSIBLING(k)) 0 0 0
375 /*
376 # uncoverable statement
377 # uncoverable branch true
378 # uncoverable branch false
379 # uncoverable condition left count:1..2
380 # uncoverable condition right count:1..2 */
381 0 ▶ if (!eo_is_stmt(k) && k->op_type != OP_ENTER)
Branch: 2 branches
BranchTrueFalseTotal
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
382 0 last = k; /* # uncoverable statement */
383 0 return eo_tail_dep(last); /* # uncoverable statement */
384 }
385 40 ▶ for (k = eo_kid(o); k; k = OpSIBLING(k)) /* # uncoverable condition left count:1 */
Branch: 2 branches
BranchTrueFalseTotal
for (k = eo_kid(o); k; k = OpSIBLING(k)) /* # uncoverable condition left count:1 */ 0 17 17
for (k = eo_kid(o); k; k = OpSIBLING(k)) /* # uncoverable condition left count:1 */ 23 17 40
386 23 ▶ if (eo_tail_dep(k))
Branch: 1 branch
BranchTrueFalseTotal
if (eo_tail_dep(k)) 6 17 23
387 6 return TRUE;
388 17 return FALSE;
389 22 case OP_AND:
390 case OP_OR:
391 case OP_DOR:
392 case OP_COND_EXPR:
393 78 ▶ for (k = eo_kid(o); k; k = OpSIBLING(k))
Branch: 2 branches
BranchTrueFalseTotal
for (k = eo_kid(o); k; k = OpSIBLING(k)) 40 16 56
for (k = eo_kid(o); k; k = OpSIBLING(k)) 62 16 78
394 62 ▶ if (eo_tail_dep(k))
Branch: 1 branch
BranchTrueFalseTotal
if (eo_tail_dep(k)) 6 56 62
395 6 return TRUE;
396 16 return FALSE;
397 141 default:
398 141 return TRUE;
399 }
400 }
401  
402 /* `my ($a, $b, ...) = @_;` as the first statement. The tree keeps its shape
403 * when padrange rewrites the execution order (5.18 on), so the tree is read,
404 * not the order. Returns the aassign, or NULL when the first statement is
405 * something else. */
406 static OP *
407 342 eo_find_binding(pTHX_ OP *body, PADOFFSET **params, U16 *nparams, const char **why)
408 {
409 OP *stmt, *aassign, *rhs, *lhs, *k;
410 342 U16 n = 0;
411  
412 342 *params = NULL;
413 342 *nparams = 0;
414  
415 342 stmt = eo_kid(body);
416 681 ▶ while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE)))
Branch: 3 branches
BranchTrueFalseTotal
while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) 679 2 681
while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) 338 341 679
while (stmt && (eo_is_type(stmt, OP_NEXTSTATE) || eo_is_type(stmt, OP_DBSTATE))) 1 340 341
417 339 ▶ stmt = OpSIBLING(stmt);
Branch: 1 branch
BranchTrueFalseTotal
stmt = OpSIBLING(stmt); 339 0 339
418 342 ▶ if (!stmt || stmt->op_type != OP_AASSIGN)
Branch: 2 branches
BranchTrueFalseTotal
if (!stmt || stmt->op_type != OP_AASSIGN) 340 2 342
if (!stmt || stmt->op_type != OP_AASSIGN) 22 318 340
419 24 return NULL;
420 318 aassign = stmt;
421  
422 318 rhs = eo_kid(aassign);
423 318 ▶ lhs = rhs ? OpSIBLING(rhs) : NULL; /* # uncoverable condition right count:1..2 */
Branch: 2 branches
BranchTrueFalseTotal
lhs = rhs ? OpSIBLING(rhs) : NULL; /* # uncoverable condition right count:1..2 */ 318 0 318
lhs = rhs ? OpSIBLING(rhs) : NULL; /* # uncoverable condition right count:1..2 */ 318 0 318
424 /*
425 # uncoverable branch true
426 # uncoverable condition left count:1..2 */
427 318 ▶ if (!eo_is_type(rhs, OP_LIST) || !eo_is_type(lhs, OP_LIST))
Branch: 2 branches
BranchTrueFalseTotal
if (!eo_is_type(rhs, OP_LIST) || !eo_is_type(lhs, OP_LIST)) 318 0 318
if (!eo_is_type(rhs, OP_LIST) || !eo_is_type(lhs, OP_LIST)) 0 318 318
428 0 return NULL; /* # uncoverable statement */
429  
430 318 k = eo_kid(rhs);
431 /*
432 # uncoverable branch true
433 # uncoverable condition left count:1..3 */
434 318 ▶ if (!k || !(k->op_type == OP_PUSHMARK
Branch: 2 branches
BranchTrueFalseTotal
if (!k || !(k->op_type == OP_PUSHMARK 318 0 318
if (!k || !(k->op_type == OP_PUSHMARK 316 2 318
435 #if PERL_VERSION_GE(5,18,0)
436 316 ▶ || k->op_type == OP_PADRANGE
Branch: 1 branch
BranchTrueFalseTotal
|| k->op_type == OP_PADRANGE 0 316 316
437 #endif
438 ))
439 0 return NULL; /* # uncoverable statement */
440 318 ▶ k = OpSIBLING(k);
Branch: 1 branch
BranchTrueFalseTotal
k = OpSIBLING(k); 318 0 318
441 318 ▶ if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k))
Branch: 5 branches
BranchTrueFalseTotal
if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) 318 0 318
if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) 318 0 318
if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) 317 1 318
if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) 0 317 317
if (!k || k->op_type != OP_RV2AV || !eo_is_defgv(aTHX_ eo_kid(k)) || OpSIBLING(k)) 0 0 0
442 1 return NULL;
443  
444 317 k = eo_kid(lhs);
445 /*
446 # uncoverable branch true
447 # uncoverable condition left count:1..2 */
448 317 ▶ if (!k || k->op_type != OP_PUSHMARK)
Branch: 2 branches
BranchTrueFalseTotal
if (!k || k->op_type != OP_PUSHMARK) 317 0 317
if (!k || k->op_type != OP_PUSHMARK) 0 317 317
449 0 return NULL; /* # uncoverable statement */
450 671 ▶ for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { /* # uncoverable condition right count:1 */
Branch: 3 branches
BranchTrueFalseTotal
for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { /* # uncoverable condition right count:1 */ 317 0 317
for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { /* # uncoverable condition right count:1 */ 41 313 354
for (k = OpSIBLING(k); k; k = OpSIBLING(k)) { /* # uncoverable condition right count:1 */ 358 313 671
451 358 ▶ if (k->op_type == OP_PADSV && (k->op_private & OPpLVAL_INTRO) /* # uncoverable condition right count:3 */
Branch: 2 branches
BranchTrueFalseTotal
if (k->op_type == OP_PADSV && (k->op_private & OPpLVAL_INTRO) /* # uncoverable condition right count:3 */ 355 3 358
if (k->op_type == OP_PADSV && (k->op_private & OPpLVAL_INTRO) /* # uncoverable condition right count:3 */ 354 1 355
452 #ifdef OPpPAD_STATE
453 354 ▶ && !(k->op_private & OPpPAD_STATE)
Branch: 1 branch
BranchTrueFalseTotal
&& !(k->op_private & OPpPAD_STATE) 354 0 354
454 #endif
455 ) {
456 354 n++;
457 354 continue;
458 }
459 4 ▶ if (k->op_type == OP_PADAV || k->op_type == OP_PADHV)
Branch: 2 branches
BranchTrueFalseTotal
if (k->op_type == OP_PADAV || k->op_type == OP_PADHV) 3 1 4
if (k->op_type == OP_PADAV || k->op_type == OP_PADHV) 1 2 3
460 2 *why = "its parameters end in an array or a hash";
461 else
462 2 *why = "its first statement assigns @_ to something other than new scalars";
463 4 return NULL;
464 }
465 /*
466 # uncoverable branch true
467 # uncoverable condition left count:1 */
468 313 ▶ if (!n)
Branch: 1 branch
BranchTrueFalseTotal
if (!n) 0 313 313
469 0 return NULL; /* # uncoverable statement */
470  
471 313 Newx(*params, n, PADOFFSET);
472 313 n = 0;
473 665 ▶ for (k = OpSIBLING(eo_kid(lhs)); k; k = OpSIBLING(k)) /* # uncoverable condition right count:1 */
Branch: 2 branches
BranchTrueFalseTotal
for (k = OpSIBLING(eo_kid(lhs)); k; k = OpSIBLING(k)) /* # uncoverable condition right count:1 */ 313 0 313
for (k = OpSIBLING(eo_kid(lhs)); k; k = OpSIBLING(k)) /* # uncoverable condition right count:1 */ 352 313 665
474 352 ▶ (*params)[n++] = k->op_targ;
Branch: 1 branch
BranchTrueFalseTotal
(*params)[n++] = k->op_targ; 39 313 352
475 313 *nparams = n;
476 313 return aassign;
477 }
478  
479 /* Registers a CV and says whether it can run as an op. The answer is kept
480 * on the CV whichever it is, so why_not can give the reason. */
481 static eo_op_t *
482 345 eo_register(pTHX_ CV *cv)
483 {
484 eo_op_t *e;
485 345 MAGIC *mg = mg_findext((SV *)cv, PERL_MAGIC_ext, &eo_op_vtbl);
486 345 const char *why = NULL;
487  
488 345 ▶ if (mg && mg->mg_ptr) { /* # uncoverable condition right count:2 */
Branch: 2 branches
BranchTrueFalseTotal
if (mg && mg->mg_ptr) { /* # uncoverable condition right count:2 */ 0 345 345
if (mg && mg->mg_ptr) { /* # uncoverable condition right count:2 */ 0 0 0
489 0 e = (eo_op_t *)mg->mg_ptr;
490 0 Safefree(e->params);
491 0 Safefree(e->why);
492 0 Zero(e, 1, eo_op_t);
493 }
494 else {
495 345 Newxz(e, 1, eo_op_t);
496 }
497  
498 345 ▶ if (CvISXSUB(cv) || !CvROOT(cv))
Branch: 2 branches
BranchTrueFalseTotal
if (CvISXSUB(cv) || !CvROOT(cv)) 344 1 345
if (CvISXSUB(cv) || !CvROOT(cv)) 1 343 344
499 2 why = "it is not a Perl sub with a body";
500 343 ▶ else if (CvLVALUE(cv))
Branch: 1 branch
BranchTrueFalseTotal
else if (CvLVALUE(cv)) 1 342 343
501 1 why = "it is an lvalue sub";
502 /*
503 # uncoverable branch true
504 # uncoverable condition left count:1 */
505 342 ▶ else if (CvROOT(cv)->op_type != OP_LEAVESUB)
Branch: 1 branch
BranchTrueFalseTotal
else if (CvROOT(cv)->op_type != OP_LEAVESUB) 0 342 342
506 0 why = "its body does not end in an ordinary sub return"; /* # uncoverable statement */
507  
508 345 ▶ if (!why) {
Branch: 1 branch
BranchTrueFalseTotal
if (!why) { 342 3 345
509 342 OP *body = eo_kid(CvROOT(cv));
510 OP *binding;
511 eo_walk_t w;
512 342 Zero(&w, 1, eo_walk_t);
513  
514 342 ENTER;
515 342 SAVECOMPPAD();
516 342 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
517  
518 342 binding = eo_find_binding(aTHX_ body, &e->params, &e->nparams, &why);
519 342 ▶ if (!why) {
Branch: 1 branch
BranchTrueFalseTotal
if (!why) { 338 4 342
520 338 ▶ w.skip = binding ? eo_kid(binding) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
w.skip = binding ? eo_kid(binding) : NULL; 313 25 338
521 338 eo_walk_list(aTHX_ &w, body);
522 338 why = w.why;
523 }
524  
525 342 LEAVE;
526  
527 342 ▶ if (!why) {
Branch: 1 branch
BranchTrueFalseTotal
if (!why) { 308 34 342
528 308 e->root = CvROOT(cv);
529 308 ▶ e->entry = binding ? binding->op_next : CvSTART(cv);
Branch: 1 branch
BranchTrueFalseTotal
e->entry = binding ? binding->op_next : CvSTART(cv); 298 10 308
530 308 e->has_return = w.has_return;
531 308 ▶ e->ctx_dep = eo_tail_dep(body) || w.ret_dep;
Branch: 2 branches
BranchTrueFalseTotal
e->ctx_dep = eo_tail_dep(body) || w.ret_dep; 171 137 308
e->ctx_dep = eo_tail_dep(body) || w.ret_dep; 4 167 171
532 308 e->need_runcv = w.warns;
533 308 e->accepted = TRUE;
534 308 eo_arm(aTHX_ cv, e);
535 }
536 }
537  
538 345 ▶ if (why)
Branch: 1 branch
BranchTrueFalseTotal
if (why) 37 308 345
539 37 e->why = savepv(why);
540  
541 345 ▶ if (!mg) {
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) { 345 0 345
542 345 mg = sv_magicext((SV *)cv, NULL, PERL_MAGIC_ext, &eo_op_vtbl, (const char *)e, 0);
543 #ifdef USE_ITHREADS
544 mg->mg_flags |= MGf_DUP;
545 #endif
546 }
547 345 return e;
548 }
549  
550 static bool
551 37 eo_strict_on(pTHX)
552 {
553 #if PERL_VERSION_GE(5,13,7)
554 37 SV *v = cop_hints_fetch_pvs(PL_curcop, EO_STRICT_KEY, 0);
555 37 ▶ return v && v != &PL_sv_placeholder && SvTRUE(v); /* # uncoverable condition right count:1 */
Branch: 3 branches
BranchTrueFalseTotal
return v && v != &PL_sv_placeholder && SvTRUE(v); /* # uncoverable condition right count:1 */ 37 0 37
return v && v != &PL_sv_placeholder && SvTRUE(v); /* # uncoverable condition right count:1 */ 3 34 37
return v && v != &PL_sv_placeholder && SvTRUE(v); /* # uncoverable condition right count:1 */ 2 1 3
556 #else
557 HV *hh = GvHV(PL_hintgv);
558 SV **v = hh ? hv_fetchs(hh, EO_STRICT_KEY, 0) : NULL;
559 return v && SvTRUE(*v);
560 #endif
561 }
562  
563 static CV *
564 442 eo_code_arg(pTHX_ SV *code, const char *who)
565 {
566 442 ▶ SvGETMAGIC(code);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(code); 0 442 442
SvGETMAGIC(code); 0 0 0
567 442 ▶ if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 440 2 442
if (!SvROK(code) || SvTYPE(SvRV(code)) != SVt_PVCV) 1 439 440
568 3 Perl_croak(aTHX_ "%s needs a code reference", who);
569 439 return (CV *)SvRV(code);
570 }
571  
572 #endif
↑ Summary Op.xs »