hax/ckcall_constfold.c.inc

filter: Statementstmt 98.1% 54 / 55 Branchbran 66.0% 33 / 50 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 82.8% 87 / 105 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« hax/sv_regexp_match.c.inc ↑ Summary lib/Data/Checks.xs »
1 /* vi: set ft=c : */
2  
3 137 static bool op_is_const(OP *o)
4 {
5 137 switch(o->op_type) {
6 131 case OP_CONST:
7 131 return true;
8  
9 2 case OP_LIST:
10 {
11 2 OP *oelem = cLISTOPo->op_first;
12 2 ▶ if(oelem->op_type == OP_PUSHMARK)
Branch: 1 branch
BranchTrueFalseTotal
if(oelem->op_type == OP_PUSHMARK) 2 0 2
13 2 ▶ oelem = OpSIBLING(oelem);
Branch: 1 branch
BranchTrueFalseTotal
oelem = OpSIBLING(oelem); 2 0 2
14 8 ▶ for(; oelem; oelem = OpSIBLING(oelem))
Branch: 2 branches
BranchTrueFalseTotal
for(; oelem; oelem = OpSIBLING(oelem)) 4 2 6
for(; oelem; oelem = OpSIBLING(oelem)) 6 2 8
15 6 ▶ if(oelem->op_type != OP_CONST)
Branch: 1 branch
BranchTrueFalseTotal
if(oelem->op_type != OP_CONST) 0 6 6
16 0 return false;
17 2 return true;
18 }
19  
20 4 default:
21 4 return false;
22 }
23 }
24  
25 141 static OP *ckcall_constfold(pTHX_ OP *o, GV *namegv, SV *ckobj)
26 {
27 assert(o->op_type == OP_ENTERSUB);
28  
29 141 OP *kid = cUNOPo->op_first;
30 /* The first kid is usually an ex-list whose ->op_first begins the actual args list */
31 141 ▶ if(kid->op_type == OP_NULL && kid->op_targ == OP_LIST)
Branch: 2 branches
BranchTrueFalseTotal
if(kid->op_type == OP_NULL && kid->op_targ == OP_LIST) 141 0 141
if(kid->op_type == OP_NULL && kid->op_targ == OP_LIST) 141 0 141
32 141 kid = cUNOPx(kid)->op_first;
33  
34 /* First actual arg is likely a OP_PUSHMARK */
35 141 ▶ if(kid->op_type == OP_PUSHMARK)
Branch: 1 branch
BranchTrueFalseTotal
if(kid->op_type == OP_PUSHMARK) 141 0 141
36 141 ▶ kid = OpSIBLING(kid);
Branch: 1 branch
BranchTrueFalseTotal
kid = OpSIBLING(kid); 141 0 141
37 141 OP *firstarg = kid;
38  
39 274 ▶ for(; kid && OpSIBLING(kid); kid = OpSIBLING(kid)) {
Branch: 4 branches
BranchTrueFalseTotal
for(; kid && OpSIBLING(kid); kid = OpSIBLING(kid)) { 133 0 133
for(; kid && OpSIBLING(kid); kid = OpSIBLING(kid)) { 274 0 274
for(; kid && OpSIBLING(kid); kid = OpSIBLING(kid)) { 137 137 274
for(; kid && OpSIBLING(kid); kid = OpSIBLING(kid)) { 137 0 137
40 137 ▶ if(op_is_const(kid))
Branch: 1 branch
BranchTrueFalseTotal
if(op_is_const(kid)) 133 4 137
41 133 continue;
42  
43 4 return o;
44 }
45  
46 137 CV *cv = GvCV(namegv);
47 assert(SvTYPE(cv) == SVt_PVCV);
48  
49 /* We've not rejected it now, so lets invoke it and inline the result */
50  
51 /* TODO: I tried invoking the actual optree by linking it, setting it as
52 * PL_op and invoking CALLRUNOPS(), but it seems the pad isn't set up
53 * correctly yet to permit this for OP_PADCV ops.
54 * Instead, we'll simulated it by PUSHs()ing ourselves
55 */
56  
57 137 dSP;
58 137 ENTER;
59 137 SAVETMPS;
60 137 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 137 137
61  
62 270 ▶ for(OP *oarg = firstarg; oarg && OpSIBLING(oarg); oarg = OpSIBLING(oarg)) {
Branch: 4 branches
BranchTrueFalseTotal
for(OP *oarg = firstarg; oarg && OpSIBLING(oarg); oarg = OpSIBLING(oarg)) { 133 0 133
for(OP *oarg = firstarg; oarg && OpSIBLING(oarg); oarg = OpSIBLING(oarg)) { 270 0 270
for(OP *oarg = firstarg; oarg && OpSIBLING(oarg); oarg = OpSIBLING(oarg)) { 133 137 270
for(OP *oarg = firstarg; oarg && OpSIBLING(oarg); oarg = OpSIBLING(oarg)) { 133 0 133
63 133 switch(oarg->op_type) {
64 131 case OP_CONST:
65 131 PUSHs(cSVOPx(oarg)->op_sv);
66 131 break;
67  
68 2 case OP_LIST:
69 {
70 2 OP *oelem = cUNOPx(oarg)->op_first;
71 2 ▶ if(oelem->op_type == OP_PUSHMARK)
Branch: 1 branch
BranchTrueFalseTotal
if(oelem->op_type == OP_PUSHMARK) 2 0 2
72 2 ▶ oelem = OpSIBLING(oelem);
Branch: 1 branch
BranchTrueFalseTotal
oelem = OpSIBLING(oelem); 2 0 2
73 8 ▶ for(; oelem; oelem = OpSIBLING(oelem)) {
Branch: 1 branch
BranchTrueFalseTotal
for(; oelem; oelem = OpSIBLING(oelem)) { 6 2 8
74 assert(oelem->op_type == OP_CONST);
75 6 ▶ PUSHs(cSVOPx(oelem)->op_sv);
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(cSVOPx(oelem)->op_sv); 4 2 6
76 }
77 2 break;
78 }
79 }
80 }
81  
82 137 PUTBACK;
83  
84 /* TODO: Currently always presume scalar context */
85 137 I32 count = call_sv((SV *)cv, G_SCALAR|G_EVAL);
86 137 bool got_err = SvTRUE(GvSV(PL_errgv));
87  
88 137 SPAGAIN;
89  
90 137 SV *retval = SvREFCNT_inc(POPs);
91  
92 137 PUTBACK;
93  
94 137 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 137 0 137
95 137 LEAVE;
96  
97 137 ▶ if(got_err)
Branch: 1 branch
BranchTrueFalseTotal
if(got_err) 1 136 137
98 /* Error was raised; abort */
99 1 return o;
100  
101 136 op_free(o);
102  
103 136 o = newSVOP(OP_CONST, 0, retval);
104 136 return o;
105 }
« hax/sv_regexp_match.c.inc ↑ Summary lib/Data/Checks.xs »