src/infix.c

filter: Statementstmt 79.6% 488 / 613 Branchbran 50.7% 217 / 428 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 67.7% 705 / 1041 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« hax/make_argcheck_ops.c.inc ↑ Summary share-keyword/include/XSParseKeyword.h »
1 /* You may distribute under the terms of either the GNU General Public License
2 * or the Artistic License (the same terms as Perl itself)
3 *
4 * (C) Paul Evans, 2021-2026 -- leonerd@leonerd.org.uk
5 */
6  
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10  
11 #include "XSParseInfix.h"
12  
13 #include "infix.h"
14  
15 #include "perl-backcompat.c.inc"
16 #include "optree-additions.c.inc"
17  
18 #include "force_list_keeping_pushmark.c.inc"
19 #include "make_argcheck_ops.c.inc"
20 #include "newOP_CUSTOM.c.inc"
21 #include "op_sibling_splice.c.inc"
22  
23 #if HAVE_PERL_VERSION(5,37,7)
24 # define HAVE_PL_INFIX_PLUGIN
25 #endif
26  
27 #if HAVE_PERL_VERSION(5,32,0)
28 # define HAVE_OP_ISA
29 #endif
30  
31 #if HAVE_PERL_VERSION(5,22,0)
32 /* assert() can be used as an expression */
33 # define HAVE_ASSERT_AS_EXPRESSION
34 #endif
35  
36 #if HAVE_PERL_VERSION(5,45,3)
37 # define HAVE_UNDEF_AWARE_EQUALITY
38 #endif
39  
40 /* These only became full API macros at perl v5.22, but they're available as
41 * the full Perl_... name before that
42 */
43 #ifndef block_start
44 # define block_start(a) Perl_block_start(aTHX_ a)
45 #endif
46  
47 #ifndef block_end
48 # define block_end(a,b) Perl_block_end(aTHX_ a,b)
49 #endif
50  
51 #ifndef XS_INTERNAL
52 /* copypasta from perl-v5.16.0/XSUB.h */
53 # if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
54 # define XS_INTERNAL(name) STATIC XSPROTO(name)
55 # endif
56 # if defined(__SYMBIAN32__)
57 # define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
58 # endif
59 # ifndef XS_INTERNAL
60 # if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
61 # define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
62 # else
63 # ifdef __cplusplus
64 # define XS_INTERNAL(name) static XSPROTO(name)
65 # else
66 # define XS_INTERNAL(name) STATIC XSPROTO(name)
67 # endif
68 # endif
69 # endif
70 #endif
71  
72 struct HooksAndData {
73 const struct XSParseInfixHooks *hooks;
74 void *data;
75 };
76  
77 enum OperandShape {
78 SHAPE_SCALARSCALAR,
79 SHAPE_SCALARLIST,
80 SHAPE_LISTLIST,
81 SHAPE_LISTASSOC_SCALARS,
82 SHAPE_LISTASSOC_LISTS,
83 };
84  
85 15 static enum OperandShape operand_shape(const struct HooksAndData *hd)
86 {
87 U8 lhs_gimme;
88 15 switch(hd->hooks->lhs_flags & 0x07) {
89 7 case 0:
90 7 lhs_gimme = G_SCALAR;
91 7 break;
92  
93 8 case XPI_OPERAND_TERM_LIST:
94 case XPI_OPERAND_LIST:
95 8 lhs_gimme = G_LIST;
96 8 break;
97  
98 0 default:
99 0 croak("TODO: Unsure how to classify operand shape of .lhs_flags=%02X\n",
100 hd->hooks->lhs_flags & 0x07);
101 }
102  
103 15 ▶ if(hd->hooks->flags & XPI_FLAG_LISTASSOC) {
Branch: 1 branch
BranchTrueFalseTotal
if(hd->hooks->flags & XPI_FLAG_LISTASSOC) { 4 11 15
104 4 switch(lhs_gimme) {
105 2 case G_SCALAR:
106 2 return SHAPE_LISTASSOC_SCALARS;
107  
108 2 case G_LIST:
109 2 return SHAPE_LISTASSOC_LISTS;
110 }
111 }
112  
113 U8 rhs_gimme;
114 11 switch(hd->hooks->rhs_flags & 0x07) {
115 3 case 0:
116 3 rhs_gimme = G_SCALAR;
117 3 break;
118  
119 8 case XPI_OPERAND_TERM_LIST:
120 case XPI_OPERAND_LIST:
121 8 rhs_gimme = G_LIST;
122 8 break;
123  
124 0 default:
125 0 croak("TODO: Unsure how to classify operand shape of .rhs_flags=%02X\n",
126 hd->hooks->rhs_flags & 0x07);
127 }
128  
129 11 switch((lhs_gimme << 4) | (rhs_gimme)) {
130 /* scalar OP scalar */
131 3 case (G_SCALAR<<4) | G_SCALAR:
132 3 return SHAPE_SCALARSCALAR;
133  
134 /* scalar OP list */
135 2 case (G_SCALAR<<4) | G_LIST:
136 2 return SHAPE_SCALARLIST;
137  
138 /* list OP list */
139 6 case (G_LIST<<4) | G_LIST:
140 6 return SHAPE_LISTLIST;
141  
142 0 default:
143 0 croak("TODO: Unsure how to classify operand shape of lhs_gimme=%d rhs_gimme=%d\n",
144 lhs_gimme, rhs_gimme);
145 break;
146 }
147 }
148  
149 struct Registration;
150 struct Registration {
151 #ifdef HAVE_PL_INFIX_PLUGIN
152 struct Perl_custom_infix def; /* must be first */
153 #endif
154  
155 struct Registration *next;
156 struct XSParseInfixInfo info;
157  
158 STRLEN oplen;
159  
160 struct HooksAndData hd;
161  
162 STRLEN permit_hintkey_len;
163  
164 int opname_is_WIDE : 1;
165 int opname_is_ident : 1;
166 int opname_is_fq : 1;
167 };
168  
169 static struct Registration *registrations, /* for legacy-style global key-enabled ones */
170 *fqregistrations; /* for new lexically named ones */
171  
172 52 static OP *new_op(pTHX_ const struct HooksAndData hd, U32 flags, OP *lhs, OP *rhs, SV **parsedata)
173 {
174 52 ▶ if(hd.hooks->new_op) {
Branch: 1 branch
BranchTrueFalseTotal
if(hd.hooks->new_op) { 0 52 52
175 0 ▶ if(hd.hooks->flags & (1<<15)) {
Branch: 1 branch
BranchTrueFalseTotal
if(hd.hooks->flags & (1<<15)) { 0 0 0
176 0 OP *(*new_op_v1)(pTHX_ U32, OP *, OP *, void *) = (OP *(*)(pTHX_ U32, OP *, OP *, void *))hd.hooks->new_op;
177 0 return (*new_op_v1)(aTHX_ flags, lhs, rhs, hd.data); /* no parsedata */
178 }
179  
180 0 return (*hd.hooks->new_op)(aTHX_ flags, lhs, rhs, parsedata, hd.data);
181 }
182  
183 assert(hd.hooks->ppaddr);
184  
185 OP *ret;
186 52 ▶ if(hd.hooks->flags & XPI_FLAG_LISTASSOC) {
Branch: 1 branch
BranchTrueFalseTotal
if(hd.hooks->flags & XPI_FLAG_LISTASSOC) { 10 42 52
187 10 OP *listop = lhs;
188 /* Skip an ex-list + pushmark structure */
189 10 ▶ if(listop->op_type == OP_NULL && cUNOPx(listop)->op_first &&
Branch: 2 branches
BranchTrueFalseTotal
if(listop->op_type == OP_NULL && cUNOPx(listop)->op_first && 0 10 10
if(listop->op_type == OP_NULL && cUNOPx(listop)->op_first && 0 0 0
190 0 ▶ cUNOPx(listop)->op_first->op_type == OP_PUSHMARK)
Branch: 1 branch
BranchTrueFalseTotal
cUNOPx(listop)->op_first->op_type == OP_PUSHMARK) 0 0 0
191 0 ▶ listop = OpSIBLING(cUNOPx(listop)->op_first);
Branch: 1 branch
BranchTrueFalseTotal
listop = OpSIBLING(cUNOPx(listop)->op_first); 0 0 0
192  
193 10 ▶ if(listop &&
Branch: 1 branch
BranchTrueFalseTotal
if(listop && 10 0 10
194 10 ▶ listop->op_type == OP_CUSTOM && listop->op_ppaddr == hd.hooks->ppaddr &&
Branch: 2 branches
BranchTrueFalseTotal
listop->op_type == OP_CUSTOM && listop->op_ppaddr == hd.hooks->ppaddr && 4 6 10
listop->op_type == OP_CUSTOM && listop->op_ppaddr == hd.hooks->ppaddr && 4 0 4
195 4 ▶ !(listop->op_flags & OPf_PARENS)) {
Branch: 1 branch
BranchTrueFalseTotal
!(listop->op_flags & OPf_PARENS)) { 3 1 4
196 /* combine new operand with existing listop */
197 3 ▶ if(listop->op_private == 255)
Branch: 1 branch
BranchTrueFalseTotal
if(listop->op_private == 255) 0 3 3
198 0 croak("TODO: Unable to handle a list-associative infix operator with > 255 operands");
199  
200 3 OP *last = cLISTOPx(listop)->op_last;
201 3 OpMORESIB_set(last, rhs);
202 3 cLISTOPx(listop)->op_last = rhs;
203 3 OpLASTSIB_set(rhs, listop);
204  
205 3 listop->op_private++;
206  
207 3 ret = lhs;
208 }
209 else {
210 /* base case */
211 7 ret = newLISTOP_CUSTOM(hd.hooks->ppaddr, flags, lhs, rhs);
212 7 ret->op_private = 2;
213 }
214 }
215 else
216 42 ret = newBINOP_CUSTOM(hd.hooks->ppaddr, flags, lhs, rhs);
217  
218 /* TODO: opchecker? */
219  
220 52 return ret;
221 }
222  
223 26 static bool op_extract_onerefgen(OP *o, OP **kidp)
224 {
225 OP *first;
226 26 switch(o->op_type) {
227 13 case OP_SREFGEN:
228 13 first = cUNOPo->op_first;
229 13 ▶ if(first->op_type == OP_NULL && first->op_targ == OP_LIST &&
Branch: 2 branches
BranchTrueFalseTotal
if(first->op_type == OP_NULL && first->op_targ == OP_LIST && 13 0 13
if(first->op_type == OP_NULL && first->op_targ == OP_LIST && 13 0 13
230 13 ▶ (*kidp = cLISTOPx(first)->op_first))
Branch: 1 branch
BranchTrueFalseTotal
(*kidp = cLISTOPx(first)->op_first)) 13 0 13
231 13 return TRUE;
232 0 break;
233  
234 0 case OP_REFGEN:
235 0 first = cUNOPo->op_first;
236 0 ▶ if(first->op_type == OP_NULL && first->op_targ == OP_LIST &&
Branch: 2 branches
BranchTrueFalseTotal
if(first->op_type == OP_NULL && first->op_targ == OP_LIST && 0 0 0
if(first->op_type == OP_NULL && first->op_targ == OP_LIST && 0 0 0
237 #ifdef HAVE_ASSERT_AS_EXPRESSION
238 0 (assert(cLISTOPx(first)->op_first->op_type == OP_PUSHMARK), 1) &&
239 #endif
240 0 ▶ (*kidp = OpSIBLING(cLISTOPx(first)->op_first)) &&
Branch: 2 branches
BranchTrueFalseTotal
(*kidp = OpSIBLING(cLISTOPx(first)->op_first)) && 0 0 0
(*kidp = OpSIBLING(cLISTOPx(first)->op_first)) && 0 0 0
241 0 ▶ !OpSIBLING(*kidp))
Branch: 2 branches
BranchTrueFalseTotal
!OpSIBLING(*kidp)) 0 0 0
!OpSIBLING(*kidp)) 0 0 0
242 0 return TRUE;
243  
244 0 op_dump(first);
245 }
246  
247 13 return FALSE;
248 }
249  
250 #define unwrap_list(o, may_unwrap_anonlist) S_unwrap_list(aTHX_ o, may_unwrap_anonlist)
251 26 static OP *S_unwrap_list(pTHX_ OP *o, bool may_unwrap_anonlist)
252 {
253 OP *kid;
254  
255 /* Look out for some sort of \THING */
256 26 ▶ if(op_extract_onerefgen(o, &kid)) {
Branch: 1 branch
BranchTrueFalseTotal
if(op_extract_onerefgen(o, &kid)) { 13 13 26
257 13 ▶ if(kid->op_type == OP_PADAV) {
Branch: 1 branch
BranchTrueFalseTotal
if(kid->op_type == OP_PADAV) { 7 6 13
258 /* \@padav can just yield the array directly */
259 7 cLISTOPx(cUNOPo->op_first)->op_first = NULL;
260 7 cLISTOPx(cUNOPo->op_first)->op_flags &= ~OPf_KIDS;
261 7 op_free(o);
262  
263 7 kid->op_flags &= ~(OPf_MOD|OPf_REF);
264 7 return force_list_keeping_pushmark(kid);
265 }
266 6 ▶ if(kid->op_type == OP_RV2AV) {
Branch: 1 branch
BranchTrueFalseTotal
if(kid->op_type == OP_RV2AV) { 6 0 6
267 /* we can just yield this op directly at this point. It might be \@pkgav
268 * or something else, but whatever it is we might as well do it
269 */
270 6 cLISTOPx(cUNOPo->op_first)->op_first = NULL;
271 6 cLISTOPx(cUNOPo->op_first)->op_flags &= ~OPf_KIDS;
272 6 op_free(o);
273  
274 6 kid->op_flags &= ~(OPf_MOD|OPf_REF);
275 6 return force_list_keeping_pushmark(kid);
276 }
277 }
278  
279 /* We might be permitted to unwrap a [THING] */
280 13 ▶ if(may_unwrap_anonlist &&
Branch: 1 branch
BranchTrueFalseTotal
if(may_unwrap_anonlist && 7 6 13
281 7 ▶ o->op_type == OP_ANONLIST) {
Branch: 1 branch
BranchTrueFalseTotal
o->op_type == OP_ANONLIST) { 5 2 7
282 /* Just turn it into a list and we're already done */
283 5 o->op_type = OP_LIST;
284 5 return force_list_keeping_pushmark(o);
285 }
286  
287 8 return force_list_keeping_pushmark(newUNOP(OP_RV2AV, 0, o));
288 }
289  
290 enum {
291 FINDREG_SKIP_BUILTIN = (1<<0),
292 };
293  
294 #define find_reg(op, oplen, regp, flags) S_find_reg(aTHX_ op, oplen, regp, flags)
295 722644 static STRLEN S_find_reg(pTHX_ const char *op, STRLEN oplen, struct Registration **regp, U32 flags)
296 {
297 722644 HV *hints = GvHV(PL_hintgv);
298  
299 /* New-style lexically named operators */
300 {
301 722644 ▶ bool opname_is_ident = isIDFIRST_utf8_safe(op, op + oplen);
Branch: 5 branches
BranchTrueFalseTotal
bool opname_is_ident = isIDFIRST_utf8_safe(op, op + oplen); 0 722644 722644
bool opname_is_ident = isIDFIRST_utf8_safe(op, op + oplen); 722642 2 722644
bool opname_is_ident = isIDFIRST_utf8_safe(op, op + oplen); 2 0 2
bool opname_is_ident = isIDFIRST_utf8_safe(op, op + oplen); 0 0 0
bool opname_is_ident = isIDFIRST_utf8_safe(op, op + oplen); 0 0 0
302  
303 722644 SV *keysv = sv_newmortal();
304 1609721 ▶ for(int len = oplen; len > 0; len--) {
Branch: 1 branch
BranchTrueFalseTotal
for(int len = oplen; len > 0; len--) { 1006616 603105 1609721
305 1006616 sv_setpvf(keysv, "XS::Parse::Infix/%.*s", len, op);
306 1006616 HE *ophe = hv_fetch_ent(hints, keysv, 0, 0);
307 1006616 ▶ if(!ophe && opname_is_ident)
Branch: 2 branches
BranchTrueFalseTotal
if(!ophe && opname_is_ident) 1006614 2 1006616
if(!ophe && opname_is_ident) 119537 887077 1006614
308 119537 break;
309 887079 ▶ if(!ophe)
Branch: 1 branch
BranchTrueFalseTotal
if(!ophe) 887077 2 887079
310 887077 continue;
311  
312 /* We found something suitable. Commit to this or fail */
313  
314 2 char *fqop = SvPVX(HeVAL(ophe));
315 2 STRLEN fqoplen = SvCUR(HeVAL(ophe));
316  
317 2 ▶ for(struct Registration *reg = fqregistrations; reg; reg = reg->next) {
Branch: 1 branch
BranchTrueFalseTotal
for(struct Registration *reg = fqregistrations; reg; reg = reg->next) { 2 0 2
318 2 ▶ if(!reg->hd.hooks)
Branch: 1 branch
BranchTrueFalseTotal
if(!reg->hd.hooks) 0 2 2
319 0 continue;
320  
321 2 ▶ if(reg->oplen != fqoplen || !strEQ(reg->info.opname, fqop))
Branch: 2 branches
BranchTrueFalseTotal
if(reg->oplen != fqoplen || !strEQ(reg->info.opname, fqop)) 2 0 2
if(reg->oplen != fqoplen || !strEQ(reg->info.opname, fqop)) 0 2 2
322 0 continue;
323  
324 2 ▶ if(reg->hd.hooks->permit &&
Branch: 1 branch
BranchTrueFalseTotal
if(reg->hd.hooks->permit && 0 2 2
325 0 ▶ !(*reg->hd.hooks->permit)(aTHX_ reg->hd.data))
Branch: 1 branch
BranchTrueFalseTotal
!(*reg->hd.hooks->permit)(aTHX_ reg->hd.data)) 0 0 0
326 0 continue;
327  
328 2 *regp = reg;
329 2 return len;
330 }
331  
332 0 croak("XS::Parse::Infix does not know of a registered infix operator named '%" SVf "'",
333 SVfARG(HeVAL(ophe)));
334 }
335 }
336  
337 /* Legacy hinthash-enabled global operators */
338 722642 struct Registration *reg, *bestreg = NULL;
339 12783678 ▶ for(reg = registrations; reg; reg = reg->next) {
Branch: 1 branch
BranchTrueFalseTotal
for(reg = registrations; reg; reg = reg->next) { 12061036 722642 12783678
340 /* custom registrations have hooks, builtin ones do not */
341 12061036 ▶ if((flags & FINDREG_SKIP_BUILTIN) && !reg->hd.hooks)
Branch: 2 branches
BranchTrueFalseTotal
if((flags & FINDREG_SKIP_BUILTIN) && !reg->hd.hooks) 12060956 80 12061036
if((flags & FINDREG_SKIP_BUILTIN) && !reg->hd.hooks) 11562192 498764 12060956
342 11562192 continue;
343  
344 498844 ▶ if(reg->oplen > oplen || !strnEQ(reg->info.opname, op, reg->oplen))
Branch: 2 branches
BranchTrueFalseTotal
if(reg->oplen > oplen || !strnEQ(reg->info.opname, op, reg->oplen)) 82880 415964 498844
if(reg->oplen > oplen || !strnEQ(reg->info.opname, op, reg->oplen)) 82845 35 82880
345 498809 continue;
346 /* names like identifiers must match the whole length */
347 35 ▶ if(reg->opname_is_ident && reg->oplen != oplen)
Branch: 2 branches
BranchTrueFalseTotal
if(reg->opname_is_ident && reg->oplen != oplen) 31 4 35
if(reg->opname_is_ident && reg->oplen != oplen) 3 28 31
348 3 continue;
349  
350 32 ▶ if(reg->hd.hooks && reg->hd.hooks->permit_hintkey &&
Branch: 3 branches
BranchTrueFalseTotal
if(reg->hd.hooks && reg->hd.hooks->permit_hintkey && 28 4 32
if(reg->hd.hooks && reg->hd.hooks->permit_hintkey && 28 0 28
if(reg->hd.hooks && reg->hd.hooks->permit_hintkey && 28 0 28
351 28 ▶ (!hints || !hv_fetch(hints, reg->hd.hooks->permit_hintkey, reg->permit_hintkey_len, 0)))
Branch: 1 branch
BranchTrueFalseTotal
(!hints || !hv_fetch(hints, reg->hd.hooks->permit_hintkey, reg->permit_hintkey_len, 0))) 0 28 28
352 0 continue;
353  
354 32 ▶ if(reg->hd.hooks && reg->hd.hooks->permit &&
Branch: 2 branches
BranchTrueFalseTotal
if(reg->hd.hooks && reg->hd.hooks->permit && 28 4 32
if(reg->hd.hooks && reg->hd.hooks->permit && 0 28 28
355 0 ▶ !(*reg->hd.hooks->permit)(aTHX_ reg->hd.data))
Branch: 1 branch
BranchTrueFalseTotal
!(*reg->hd.hooks->permit)(aTHX_ reg->hd.data)) 0 0 0
356 0 continue;
357  
358 /* This is a candidate and the best one, unless we already have something
359 * longer
360 */
361 32 ▶ if(bestreg && bestreg->oplen > reg->oplen)
Branch: 2 branches
BranchTrueFalseTotal
if(bestreg && bestreg->oplen > reg->oplen) 0 32 32
if(bestreg && bestreg->oplen > reg->oplen) 0 0 0
362 0 continue;
363  
364 32 bestreg = reg;
365 }
366  
367 722642 ▶ if(!bestreg)
Branch: 1 branch
BranchTrueFalseTotal
if(!bestreg) 722610 32 722642
368 722610 return 0;
369  
370 32 *regp = bestreg;
371 32 return bestreg->oplen;
372 }
373  
374 #ifdef HAVE_PL_INFIX_PLUGIN
375  
376 0 static void parse(pTHX_ SV **parsedata, struct Perl_custom_infix *def)
377 {
378 0 struct Registration *reg = (struct Registration *)def;
379  
380 0 (*reg->hd.hooks->parse)(aTHX_ 0, parsedata, reg->hd.data);
381 0 }
382  
383 30 static OP *build_op(pTHX_ SV **parsedata, OP *lhs, OP *rhs, struct Perl_custom_infix *def)
384 {
385 30 struct Registration *reg = (struct Registration *)def;
386  
387 30 switch(reg->hd.hooks->lhs_flags & 0x07) {
388 28 case 0:
389 28 break;
390  
391 2 case XPI_OPERAND_TERM_LIST:
392 case XPI_OPERAND_LIST:
393 2 lhs = force_list_keeping_pushmark(lhs);
394 2 break;
395 }
396  
397 /* TODO: maybe operator has a 'parse' hook? */
398  
399 30 switch(reg->hd.hooks->rhs_flags & 0x07) {
400 25 case 0:
401 25 break;
402  
403 5 case XPI_OPERAND_TERM_LIST:
404 case XPI_OPERAND_LIST:
405 5 rhs = force_list_keeping_pushmark(rhs);
406 5 break;
407 }
408  
409 30 return new_op(aTHX_ reg->hd, 0, lhs, rhs, parsedata);
410 }
411  
412 static STRLEN (*next_infix_plugin)(pTHX_ char *, STRLEN, struct Perl_custom_infix **);
413  
414 722639 static STRLEN my_infix_plugin(pTHX_ char *op, STRLEN oplen, struct Perl_custom_infix **def)
415 {
416 722639 ▶ if(PL_parser && PL_parser->error_count)
Branch: 2 branches
BranchTrueFalseTotal
if(PL_parser && PL_parser->error_count) 722639 0 722639
if(PL_parser && PL_parser->error_count) 0 722639 722639
417 0 return (*next_infix_plugin)(aTHX_ op, oplen, def);
418  
419 722639 struct Registration *reg = NULL;
420 722639 STRLEN consumed = find_reg(op, oplen, &reg, FINDREG_SKIP_BUILTIN);
421 722639 ▶ if(!consumed)
Branch: 1 branch
BranchTrueFalseTotal
if(!consumed) 722609 30 722639
422 722609 return (*next_infix_plugin)(aTHX_ op, oplen, def);
423  
424 30 *def = &reg->def;
425 30 return consumed;
426 }
427 #endif
428  
429 /* What classifications are included in what selections? */
430 static const U32 infix_selections[] = {
431 [XPI_SELECT_ANY] = 0xFFFFFFFF,
432  
433 [XPI_SELECT_PREDICATE] = (1<<XPI_CLS_PREDICATE)|(1<<XPI_CLS_RELATION)|(1<<XPI_CLS_EQUALITY),
434 [XPI_SELECT_RELATION] = (1<<XPI_CLS_RELATION)|(1<<XPI_CLS_EQUALITY),
435 [XPI_SELECT_EQUALITY] = (1<<XPI_CLS_EQUALITY),
436  
437 [XPI_SELECT_ORDERING] = (1<<XPI_CLS_ORDERING),
438  
439 [XPI_SELECT_MATCH_NOSMART] = (1<<XPI_CLS_EQUALITY)|(1<<XPI_CLS_MATCHRE)|(1<<XPI_CLS_ISA)|(1<<XPI_CLS_MATCH_MISC),
440 [XPI_SELECT_MATCH_SMART] = (1<<XPI_CLS_EQUALITY)|(1<<XPI_CLS_MATCHRE)|(1<<XPI_CLS_ISA)|(1<<XPI_CLS_MATCH_MISC)|
441 (1<<XPI_CLS_SMARTMATCH),
442 };
443  
444 5 bool XSParseInfix_parse(pTHX_ enum XSParseInfixSelection select, struct XSParseInfixInfo **infop)
445 {
446 /* PL_parser->bufptr now points exactly at where we expect to find an operator name */
447  
448 5 int selection = infix_selections[select];
449  
450 5 HV *hints = GvHV(PL_hintgv);
451  
452 5 const char *op = PL_parser->bufptr, *opend;
453  
454 5 ▶ if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) {
Branch: 6 branches
BranchTrueFalseTotal
if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) { 0 5 5
if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) { 5 0 5
if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) { 0 0 0
if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) { 0 0 0
if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) { 0 0 0
if(isIDFIRST_utf8_safe(op, PL_parser->bufend)) { 3 2 5
455 /* If the operator name is an identifer then we don't want to capture a
456 * longer identifier from the incoming source of which this is just a
457 * prefix
458 */
459 3 opend = op + UTF8SKIP(op);
460 7 ▶ while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend))
Branch: 9 branches
BranchTrueFalseTotal
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 7 0 7
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 0 7 7
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 7 0 7
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 4 3 7
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 0 0 0
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 0 0 0
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 0 0 0
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 0 0 0
while(opend < PL_parser->bufend && isIDCONT_utf8_safe(opend, PL_parser->bufend)) 0 0 0
461 4 opend += UTF8SKIP(opend);
462 }
463 else {
464 2 opend = PL_parser->bufend;
465 }
466  
467 5 struct Registration *reg = NULL;
468 5 STRLEN consumed = find_reg(op, opend - op, &reg, 0);
469 5 ▶ if(!consumed)
Branch: 1 branch
BranchTrueFalseTotal
if(!consumed) 1 4 5
470 1 return FALSE;
471  
472 4 ▶ if(!(selection & (1 << reg->info.cls)))
Branch: 1 branch
BranchTrueFalseTotal
if(!(selection & (1 << reg->info.cls))) 1 3 4
473 1 return FALSE;
474  
475 3 *infop = &reg->info;
476  
477 3 lex_read_to(PL_parser->bufptr + consumed);
478 3 return TRUE;
479 }
480  
481 0 OP *XSParseInfix_new_op(pTHX_ const struct XSParseInfixInfo *info, U32 flags, OP *lhs, OP *rhs)
482 {
483 0 ▶ if(info->opcode == OP_CUSTOM)
Branch: 1 branch
BranchTrueFalseTotal
if(info->opcode == OP_CUSTOM) 0 0 0
484 0 return new_op(aTHX_ (struct HooksAndData) {
485 0 .hooks = info->hooks,
486 0 .data = info->hookdata,
487 }, flags, lhs, rhs, NULL);
488  
489 0 return newBINOP(info->opcode, flags, lhs, rhs);
490 }
491  
492 46 static bool op_yields_oneval(OP *o)
493 {
494 46 ▶ if(OP_GIMME(o, 0) == G_SCALAR)
Branch: 1 branch
BranchTrueFalseTotal
if(OP_GIMME(o, 0) == G_SCALAR) 43 3 46
495 43 return TRUE;
496  
497 3 ▶ if(PL_opargs[o->op_type] & OA_RETSCALAR)
Branch: 1 branch
BranchTrueFalseTotal
if(PL_opargs[o->op_type] & OA_RETSCALAR) 0 3 3
498 0 return TRUE;
499  
500 /* It might still yield a single value, we'll just have to check harder */
501 3 ▶ switch(o->op_type) {
Branch: 1 branch
BranchTrueFalseTotal
switch(o->op_type) { 0 3 3
502 0 case OP_REFGEN:
503 {
504 0 OP *list = cUNOPo->op_first;
505 OP *kid;
506 assert(cLISTOPx(list)->op_first->op_type == OP_PUSHMARK);
507 0 ▶ if((kid = OpSIBLING(cLISTOPx(list)->op_first)) &&
Branch: 2 branches
BranchTrueFalseTotal
if((kid = OpSIBLING(cLISTOPx(list)->op_first)) && 0 0 0
if((kid = OpSIBLING(cLISTOPx(list)->op_first)) && 0 0 0
508 0 ▶ !OpSIBLING(kid) &&
Branch: 2 branches
BranchTrueFalseTotal
!OpSIBLING(kid) && 0 0 0
!OpSIBLING(kid) && 0 0 0
509 0 ▶ (kid->op_flags & OPf_REF))
Branch: 1 branch
BranchTrueFalseTotal
(kid->op_flags & OPf_REF)) 0 0 0
510 0 return TRUE;
511 }
512 }
513  
514 3 return FALSE;
515 }
516  
517 20 static bool extract_wrapper2_args(pTHX_ OP *op, OP **leftp, OP **rightp)
518 {
519 assert(op->op_type == OP_ENTERSUB);
520  
521 /* Attempt to extract the LHS and RHS operands, if we can find them */
522  
523 20 OP *kid = cUNOPx(op)->op_first;
524 /* The first kid is usually an ex-list whose ->op_first begins the actual args list */
525 20 ▶ 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) 20 0 20
if(kid->op_type == OP_NULL && kid->op_targ == OP_LIST) 20 0 20
526 20 kid = cUNOPx(kid)->op_first;
527  
528 assert(kid->op_type == OP_PUSHMARK);
529 20 OP *pushmark = kid;
530  
531 20 ▶ OP *left = OpSIBLING(kid);
Branch: 1 branch
BranchTrueFalseTotal
OP *left = OpSIBLING(kid); 20 0 20
532 20 ▶ if(!left)
Branch: 1 branch
BranchTrueFalseTotal
if(!left) 0 20 20
533 0 return FALSE;
534 20 ▶ if(!op_yields_oneval(left))
Branch: 1 branch
BranchTrueFalseTotal
if(!op_yields_oneval(left)) 2 18 20
535 2 return FALSE;
536  
537 18 ▶ OP *right = OpSIBLING(left);
Branch: 1 branch
BranchTrueFalseTotal
OP *right = OpSIBLING(left); 18 0 18
538 18 ▶ if(!right)
Branch: 1 branch
BranchTrueFalseTotal
if(!right) 0 18 18
539 0 return FALSE;
540 18 ▶ if(!op_yields_oneval(right))
Branch: 1 branch
BranchTrueFalseTotal
if(!op_yields_oneval(right)) 0 18 18
541 0 return FALSE;
542  
543 18 ▶ kid = OpSIBLING(right);
Branch: 1 branch
BranchTrueFalseTotal
kid = OpSIBLING(right); 17 1 18
544 18 ▶ if(!kid)
Branch: 1 branch
BranchTrueFalseTotal
if(!kid) 1 17 18
545 1 return FALSE;
546 17 ▶ if(OpSIBLING(kid))
Branch: 2 branches
BranchTrueFalseTotal
if(OpSIBLING(kid)) 1 16 17
if(OpSIBLING(kid)) 1 0 1
547 1 return FALSE;
548  
549 /* Check that kid is now OP_NULL[ OP_GV ] */
550 16 ▶ if(kid->op_type != OP_NULL || kid->op_targ != OP_RV2CV)
Branch: 2 branches
BranchTrueFalseTotal
if(kid->op_type != OP_NULL || kid->op_targ != OP_RV2CV) 16 0 16
if(kid->op_type != OP_NULL || kid->op_targ != OP_RV2CV) 0 16 16
551 0 return FALSE;
552 16 ▶ if(cUNOPx(kid)->op_first->op_type != OP_GV)
Branch: 1 branch
BranchTrueFalseTotal
if(cUNOPx(kid)->op_first->op_type != OP_GV) 0 16 16
553 0 return FALSE;
554  
555 /* Splice out these two args and throw away the old optree */
556 16 OpMORESIB_set(left, NULL);
557 16 OpMORESIB_set(right, NULL);
558 16 OpMORESIB_set(pushmark, kid);
559 16 op_free(op);
560  
561 16 OpLASTSIB_set(left, NULL);
562 16 OpLASTSIB_set(right, NULL);
563  
564 16 *leftp = left;
565 16 *rightp = right;
566 16 return TRUE;
567 }
568  
569 8 static OP *ckcall_wrapper_func_scalarscalar(pTHX_ OP *op, GV *namegv, SV *ckobj)
570 {
571 8 struct HooksAndData *hd = NUM2PTR(struct HooksAndData *, SvUV(ckobj));
572  
573 OP *left, *right;
574 8 ▶ if(!extract_wrapper2_args(aTHX_ op, &left, &right))
Branch: 1 branch
BranchTrueFalseTotal
if(!extract_wrapper2_args(aTHX_ op, &left, &right)) 4 4 8
575 4 return op;
576  
577 4 return new_op(aTHX_ *hd, 0, left, right, NULL);
578 }
579  
580 12 static OP *ckcall_wrapper_func_listlist(pTHX_ OP *op, GV *namegv, SV *ckobj)
581 {
582 12 struct HooksAndData *hd = NUM2PTR(struct HooksAndData *, SvUV(ckobj));
583  
584 OP *left, *right;
585 12 ▶ if(!extract_wrapper2_args(aTHX_ op, &left, &right))
Branch: 1 branch
BranchTrueFalseTotal
if(!extract_wrapper2_args(aTHX_ op, &left, &right)) 0 12 12
586 0 return op;
587  
588 12 return new_op(aTHX_ *hd, 0,
589 12 unwrap_list(left, hd->hooks->lhs_flags & XPI_OPERAND_ONLY_LOOK),
590 12 unwrap_list(right, hd->hooks->rhs_flags & XPI_OPERAND_ONLY_LOOK),
591 NULL);
592 }
593  
594 4 static OP *ckcall_wrapper_func_listassoc_scalars(pTHX_ OP *op, GV *namegv, SV *ckobj)
595 {
596 4 struct HooksAndData *hd = NUM2PTR(struct HooksAndData *, SvUV(ckobj));
597  
598 /* We'll convert this if it looks like a compiletime-constant number of
599 * scalar arguments
600 */
601 assert(op->op_type == OP_ENTERSUB);
602  
603 4 OP *kid = cUNOPx(op)->op_first;
604 /* The first kid is usually an ex-list whose ->op_first begins the actual args list */
605 4 ▶ 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) 4 0 4
if(kid->op_type == OP_NULL && kid->op_targ == OP_LIST) 4 0 4
606 4 kid = cUNOPx(kid)->op_first;
607  
608 assert(kid->op_type == OP_PUSHMARK);
609 4 OP *pushmark = kid;
610  
611 4 ▶ kid = OpSIBLING(kid);
Branch: 1 branch
BranchTrueFalseTotal
kid = OpSIBLING(kid); 4 0 4
612 4 OP *firstarg = kid, *lastarg;
613  
614 4 int argcount = 0;
615 OP *nextkid;
616 9 ▶ while(kid && (nextkid = OpSIBLING(kid))) {
Branch: 3 branches
BranchTrueFalseTotal
while(kid && (nextkid = OpSIBLING(kid))) { 9 0 9
while(kid && (nextkid = OpSIBLING(kid))) { 6 3 9
while(kid && (nextkid = OpSIBLING(kid))) { 6 3 9
617 6 ▶ if(!op_yields_oneval(kid))
Branch: 1 branch
BranchTrueFalseTotal
if(!op_yields_oneval(kid)) 1 5 6
618 1 goto no_wrapper;
619  
620 5 argcount++;
621 5 lastarg = kid;
622 5 kid = nextkid;
623 }
624 /* kid now points at final op which is the gvop of the OP_ENTERSUB */
625  
626 3 ▶ if(!argcount) {
Branch: 1 branch
BranchTrueFalseTotal
if(!argcount) { 1 2 3
627 1 op_free(op);
628 1 return newLISTOP_CUSTOM(hd->hooks->ppaddr, 0, NULL, NULL);
629 }
630  
631 /* Splice out the args list and throw away the old optree */
632 2 OpMORESIB_set(pushmark, kid);
633 2 op_free(op);
634  
635 /* newLISTOP_CUSTOM doesn't quite handle already created child op chains. We
636 * must pass in NULL then set the child ops manually */
637 2 op = newLISTOP_CUSTOM(hd->hooks->ppaddr, 0, NULL, NULL);
638 2 op->op_private = argcount;
639  
640 2 op->op_flags |= OPf_KIDS;
641 2 cLISTOPx(op)->op_first = firstarg;
642 2 cLISTOPx(op)->op_last = lastarg;
643 2 OpLASTSIB_set(lastarg, op);
644  
645 2 return op;
646  
647 1 no_wrapper:
648 1 op = ck_entersub_args_proto_or_list(op, namegv, &PL_sv_undef);
649 1 return op;
650 }
651  
652 2 static OP *ckcall_wrapper_func_listassoc_lists(pTHX_ OP *op, GV *namegv, SV *ckobj)
653 {
654 2 struct HooksAndData *hd = NUM2PTR(struct HooksAndData *, SvUV(ckobj));
655  
656 /* We'll convert this if it looks like a compiletime-constant number of
657 * scalar arguments
658 */
659 assert(op->op_type == OP_ENTERSUB);
660  
661 2 OP *kid = cUNOPx(op)->op_first;
662 /* The first kid is usually an ex-list whose ->op_first begins the actual args list */
663 2 ▶ 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) 2 0 2
if(kid->op_type == OP_NULL && kid->op_targ == OP_LIST) 2 0 2
664 2 kid = cUNOPx(kid)->op_first;
665  
666 assert(kid->op_type == OP_PUSHMARK);
667 2 OP *pushmark = kid;
668  
669 2 ▶ kid = OpSIBLING(kid);
Branch: 1 branch
BranchTrueFalseTotal
kid = OpSIBLING(kid); 2 0 2
670 2 OP *firstarg = kid, *lastarg;
671  
672 2 int argcount = 0;
673 OP *nextkid;
674 4 ▶ while(kid && (nextkid = OpSIBLING(kid))) {
Branch: 3 branches
BranchTrueFalseTotal
while(kid && (nextkid = OpSIBLING(kid))) { 4 0 4
while(kid && (nextkid = OpSIBLING(kid))) { 2 2 4
while(kid && (nextkid = OpSIBLING(kid))) { 2 2 4
675 2 ▶ if(!op_yields_oneval(kid))
Branch: 1 branch
BranchTrueFalseTotal
if(!op_yields_oneval(kid)) 0 2 2
676 0 goto no_wrapper;
677  
678 2 argcount++;
679 2 lastarg = kid;
680 2 kid = nextkid;
681 }
682 /* kid now points at final op which is the gvop of the OP_ENTERSUB */
683  
684 2 ▶ if(!argcount) {
Branch: 1 branch
BranchTrueFalseTotal
if(!argcount) { 1 1 2
685 1 op_free(op);
686 1 return newLISTOP_CUSTOM(hd->hooks->ppaddr, 0, NULL, NULL);
687 }
688  
689 /* Splice out the args list and throw away the old optree */
690 1 OpMORESIB_set(pushmark, kid);
691 1 OpLASTSIB_set(lastarg, NULL);
692 1 op_free(op);
693  
694 /* We now need to unwrap_list() on each of the args ops */
695  
696 1 kid = firstarg;
697 1 firstarg = NULL;
698 1 lastarg = NULL;
699 3 ▶ while(kid) {
Branch: 1 branch
BranchTrueFalseTotal
while(kid) { 2 1 3
700 2 ▶ OP *nextkid = OpSIBLING(kid);
Branch: 1 branch
BranchTrueFalseTotal
OP *nextkid = OpSIBLING(kid); 1 1 2
701 2 OpLASTSIB_set(kid, NULL);
702  
703 2 OP *newkid = unwrap_list(kid, hd->hooks->lhs_flags & XPI_OPERAND_ONLY_LOOK);
704  
705 2 ▶ if(lastarg)
Branch: 1 branch
BranchTrueFalseTotal
if(lastarg) 1 1 2
706 1 OpMORESIB_set(lastarg, newkid);
707  
708 2 ▶ if(!firstarg)
Branch: 1 branch
BranchTrueFalseTotal
if(!firstarg) 1 1 2
709 1 firstarg = newkid;
710 2 lastarg = newkid;
711  
712 2 kid = nextkid;
713 }
714  
715 /* newLISTOP_CUSTOM doesn't quite handle already created child op chains. We
716 * must pass in NULL and then set the child ops manually */
717 1 op = newLISTOP_CUSTOM(hd->hooks->ppaddr, 0, NULL, NULL);
718 1 op->op_private = argcount;
719  
720 1 op->op_flags |= OPf_KIDS;
721 1 cLISTOPx(op)->op_first = firstarg;
722 1 cLISTOPx(op)->op_last = lastarg;
723 1 OpLASTSIB_set(lastarg, op);
724  
725 1 return op;
726  
727 0 no_wrapper:
728 0 op = ck_entersub_args_proto_or_list(op, namegv, &PL_sv_undef);
729 0 return op;
730 }
731  
732 2 static OP *pp_push_defav_with_count(pTHX)
733 {
734 2 dSP;
735 2 AV *defav = GvAV(PL_defgv);
736 2 bool explode = (PL_op->op_flags & OPf_SPECIAL);
737  
738 2 U32 count = av_count(defav);
739 2 SV **svp = AvARRAY(defav);
740 2 ▶ if(!explode)
Branch: 1 branch
BranchTrueFalseTotal
if(!explode) 2 0 2
741 2 ▶ EXTEND(SP, count);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, count); 0 2 2
742 8 ▶ for(U32 i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(U32 i = 0; i < count; i++) 6 2 8
743 6 ▶ if(explode) {
Branch: 1 branch
BranchTrueFalseTotal
if(explode) { 0 6 6
744 0 ▶ if(!SvROK(svp[i]) || SvTYPE(SvRV(svp[i])) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if(!SvROK(svp[i]) || SvTYPE(SvRV(svp[i])) != SVt_PVAV) 0 0 0
if(!SvROK(svp[i]) || SvTYPE(SvRV(svp[i])) != SVt_PVAV) 0 0 0
745 0 croak("Expected an ARRAY reference, got %" SVf, SVfARG(svp[i]));
746 0 AV *av = (AV *)SvRV(svp[i]);
747 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
748 0 U32 acount = av_count(av);
749 0 SV **asvp = AvARRAY(av);
750 0 ▶ EXTEND(SP, acount);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, acount); 0 0 0
751 0 ▶ for(U32 i = 0; i < acount; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(U32 i = 0; i < acount; i++) 0 0 0
752 0 PUSHs(asvp[i]);
753 }
754 else
755 6 PUSHs(svp[i]);
756  
757 2 ▶ mXPUSHu(count);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHu(count); 0 2 2
758  
759 2 RETURN;
760 }
761  
762 10 static void make_wrapper_func(pTHX_ const struct HooksAndData *hd)
763 {
764 10 SV *funcname = newSVpvn(hd->hooks->wrapper_func_name, strlen(hd->hooks->wrapper_func_name));
765  
766 GV *gv;
767 10 ▶ if((gv = gv_fetchsv(funcname, 0, 0)) && GvCV(gv)) {
Branch: 2 branches
BranchTrueFalseTotal
if((gv = gv_fetchsv(funcname, 0, 0)) && GvCV(gv)) { 0 10 10
if((gv = gv_fetchsv(funcname, 0, 0)) && GvCV(gv)) { 0 0 0
768 /* The wrapper function already exists. We presume this is due to a duplicate
769 * registration of identical hooks under a different name and just skip
770 */
771 0 return;
772 }
773  
774 /* Prepare to make a new optree-based CV */
775 10 I32 floor_ix = start_subparse(FALSE, 0);
776 10 SAVEFREESV(PL_compcv);
777  
778 10 I32 save_ix = block_start(TRUE);
779  
780 10 OP *body = NULL;
781 10 OP *(*ckcall)(pTHX_ OP *, GV *, SV *) = NULL;
782  
783 10 switch(operand_shape(hd)) {
784 2 case SHAPE_SCALARSCALAR:
785 2 body = op_append_list(OP_LINESEQ, body,
786 make_argcheck_ops(2, 0, 0, funcname));
787  
788 2 body = op_append_list(OP_LINESEQ, body,
789 newSTATEOP(0, NULL, NULL));
790  
791 /* Body of the function is just $_[0] OP $_[1] */
792 2 body = op_append_list(OP_LINESEQ, body,
793 new_op(aTHX_ *hd, 0, newSLUGOP(0), newSLUGOP(1), NULL));
794  
795 2 ckcall = &ckcall_wrapper_func_scalarscalar;
796 2 break;
797  
798 2 case SHAPE_SCALARLIST:
799 2 body = op_append_list(OP_LINESEQ, body,
800 make_argcheck_ops(1, 0, '@', funcname));
801  
802 2 body = op_append_list(OP_LINESEQ, body,
803 newSTATEOP(0, NULL, NULL));
804  
805 /* Body of the function is just shift OP @_ */
806 2 body = op_append_list(OP_LINESEQ, body,
807 new_op(aTHX_ *hd, 0,
808 newOP(OP_SHIFT, 0),
809 force_list_keeping_pushmark(newUNOP(OP_RV2AV, OPf_WANT_LIST, newGVOP(OP_GV, 0, PL_defgv))),
810 NULL));
811  
812 /* no ckcall */
813 2 break;
814  
815 2 case SHAPE_LISTLIST:
816 2 body = op_append_list(OP_LINESEQ, body,
817 make_argcheck_ops(2, 0, 0, funcname));
818  
819 2 body = op_append_list(OP_LINESEQ, body,
820 newSTATEOP(0, NULL, NULL));
821  
822 /* Body of the function is @{ $_[0] } OP @{ $_[1] } */
823 2 body = op_append_list(OP_LINESEQ, body,
824 new_op(aTHX_ *hd, 0,
825 force_list_keeping_pushmark(newUNOP(OP_RV2AV, 0, newSLUGOP(0))),
826 force_list_keeping_pushmark(newUNOP(OP_RV2AV, 0, newSLUGOP(1))),
827 NULL));
828  
829 2 ckcall = &ckcall_wrapper_func_listlist;
830 2 break;
831  
832 2 case SHAPE_LISTASSOC_SCALARS:
833 2 ▶ if(hd->hooks->new_op)
Branch: 1 branch
BranchTrueFalseTotal
if(hd->hooks->new_op) 0 2 2
834 0 croak("TODO: Cannot make wrapper func for list-associative operator that has hooks->new_op");
835  
836 2 body = op_append_list(OP_LINESEQ, body,
837 newSTATEOP(0, NULL, NULL));
838  
839 /* Body of the function invokes the op with the values from @_, and an extra IV giving the count */
840 2 body = op_append_list(OP_LINESEQ, body,
841 newLISTOP_CUSTOM(hd->hooks->ppaddr, OPf_STACKED,
842 newOP_CUSTOM(&pp_push_defav_with_count, 0),
843 NULL));
844  
845 2 ckcall = &ckcall_wrapper_func_listassoc_scalars;
846 2 break;
847  
848 2 case SHAPE_LISTASSOC_LISTS:
849 2 ▶ if(hd->hooks->new_op)
Branch: 1 branch
BranchTrueFalseTotal
if(hd->hooks->new_op) 0 2 2
850 0 croak("TODO: Cannot make wrapper func for list-associative operator that has hooks->new_op");
851  
852 2 body = op_append_list(OP_LINESEQ, body,
853 newSTATEOP(0, NULL, NULL));
854  
855 /* Body of the function invokes the op with the values from all the
856 * ARRAYs refed by @_, plus marks on the markstack, and an extra IV
857 * giving the count */
858 2 body = op_append_list(OP_LINESEQ, body,
859 newLISTOP_CUSTOM(hd->hooks->ppaddr, OPf_STACKED /* explode */,
860 newOP_CUSTOM(&pp_push_defav_with_count, OPf_SPECIAL),
861 NULL));
862  
863 2 ckcall = &ckcall_wrapper_func_listassoc_lists;
864 2 break;
865 }
866  
867 10 SvREFCNT_inc(PL_compcv);
868 10 body = block_end(save_ix, body);
869  
870 10 CV *cv = newATTRSUB(floor_ix, newSVOP(OP_CONST, 0, funcname), NULL, NULL, body);
871  
872 10 ▶ if(ckcall)
Branch: 1 branch
BranchTrueFalseTotal
if(ckcall) 8 2 10
873 8 cv_set_call_checker(cv, ckcall, newSVuv(PTR2UV(hd)));
874 }
875  
876 XS_INTERNAL(deparse_infix);
877 11 XS_INTERNAL(deparse_infix)
878 {
879 11 dXSARGS;
880 11 struct Registration *reg = XSANY.any_ptr;
881  
882 11 SV *deparseobj = ST(0);
883 SV *ret;
884  
885 #ifdef HAVE_PL_INFIX_PLUGIN
886 11 SV **hinthashsvp = hv_fetchs(MUTABLE_HV(SvRV(deparseobj)), "hinthash", 0);
887 11 ▶ HV *hinthash = hinthashsvp ? MUTABLE_HV(SvRV(*hinthashsvp)) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *hinthash = hinthashsvp ? MUTABLE_HV(SvRV(*hinthashsvp)) : NULL; 11 0 11
888  
889 SV *opnamesv;
890  
891 11 bool infix_is_visible = FALSE;
892 /* Operator visibility rules differ for fully-qualified operator names */
893 11 ▶ if(reg->opname_is_fq) {
Branch: 1 branch
BranchTrueFalseTotal
if(reg->opname_is_fq) { 0 11 11
894 0 hv_iterinit(hinthash);
895 HE *he;
896 0 ▶ while((he = hv_iternext(hinthash))) {
Branch: 1 branch
BranchTrueFalseTotal
while((he = hv_iternext(hinthash))) { 0 0 0
897 #define PREFIXLEN 17
898 STRLEN len;
899 0 ▶ if(!strnEQ(HePV(he, len), "XS::Parse::Infix/", PREFIXLEN))
Branch: 2 branches
BranchTrueFalseTotal
if(!strnEQ(HePV(he, len), "XS::Parse::Infix/", PREFIXLEN)) 0 0 0
if(!strnEQ(HePV(he, len), "XS::Parse::Infix/", PREFIXLEN)) 0 0 0
900 0 continue;
901  
902 0 ▶ if(!strEQ(SvPV_nolen(HeVAL(he)), reg->info.opname))
Branch: 1 branch
BranchTrueFalseTotal
if(!strEQ(SvPV_nolen(HeVAL(he)), reg->info.opname)) 0 0 0
903 0 continue;
904  
905 0 infix_is_visible = TRUE;
906 0 ▶ opnamesv = newSVpvn_flags(HePV(he, len) + PREFIXLEN, len - PREFIXLEN, HeUTF8(he) ? SVf_UTF8 : 0);
Branch: 3 branches
BranchTrueFalseTotal
opnamesv = newSVpvn_flags(HePV(he, len) + PREFIXLEN, len - PREFIXLEN, HeUTF8(he) ? SVf_UTF8 : 0); 0 0 0
opnamesv = newSVpvn_flags(HePV(he, len) + PREFIXLEN, len - PREFIXLEN, HeUTF8(he) ? SVf_UTF8 : 0); 0 0 0
opnamesv = newSVpvn_flags(HePV(he, len) + PREFIXLEN, len - PREFIXLEN, HeUTF8(he) ? SVf_UTF8 : 0); 0 0 0
907 0 break;
908 }
909 }
910 else {
911 11 ▶ infix_is_visible = (hinthash && hv_fetch(hinthash, reg->hd.hooks->permit_hintkey, reg->permit_hintkey_len, 0));
Branch: 2 branches
BranchTrueFalseTotal
infix_is_visible = (hinthash && hv_fetch(hinthash, reg->hd.hooks->permit_hintkey, reg->permit_hintkey_len, 0)); 11 0 11
infix_is_visible = (hinthash && hv_fetch(hinthash, reg->hd.hooks->permit_hintkey, reg->permit_hintkey_len, 0)); 6 5 11
912 11 opnamesv = newSVpvn_flags(reg->info.opname, reg->oplen, reg->opname_is_WIDE ? SVf_UTF8 : 0);
913 }
914  
915 11 ▶ if(infix_is_visible) {
Branch: 1 branch
BranchTrueFalseTotal
if(infix_is_visible) { 6 5 11
916 6 ENTER;
917 6 SAVETMPS;
918  
919 6 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 6 6
920 6 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 6 6
921 6 PUSHs(deparseobj);
922 6 mPUSHs(opnamesv);
923 6 PUSHs(ST(1));
924 6 PUSHs(ST(2));
925 6 PUTBACK;
926  
927 6 call_method("_deparse_infix_named", G_SCALAR);
928  
929 6 SPAGAIN;
930 6 ret = SvREFCNT_inc(POPs);
931  
932 6 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 6 0 6
933 6 LEAVE;
934 }
935 else
936 #endif
937 {
938 5 ENTER;
939 5 SAVETMPS;
940  
941 5 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 5 5
942 5 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 5 5
943 5 PUSHs(deparseobj);
944 5 mPUSHp(reg->hd.hooks->wrapper_func_name, strlen(reg->hd.hooks->wrapper_func_name));
945 5 PUSHs(ST(1));
946 5 PUSHs(ST(2));
947 5 PUTBACK;
948  
949 5 switch(operand_shape(&reg->hd)) {
950 1 case SHAPE_SCALARSCALAR:
951 case SHAPE_SCALARLIST: /* not really */
952 1 call_method("_deparse_infix_wrapperfunc_scalarscalar", G_SCALAR);
953 1 break;
954  
955 4 case SHAPE_LISTLIST:
956 4 call_method("_deparse_infix_wrapperfunc_listlist", G_SCALAR);
957 4 break;
958 }
959  
960 5 SPAGAIN;
961 5 ret = SvREFCNT_inc(POPs);
962  
963 5 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 5 0 5
964 5 LEAVE;
965 }
966  
967 11 ST(0) = sv_2mortal(ret);
968 11 XSRETURN(1);
969 }
970  
971 384 static void reg_builtin(pTHX_ const char *opname, enum XSParseInfixClassification cls, OPCODE opcode)
972 {
973 struct Registration *reg;
974 384 Newx(reg, 1, struct Registration);
975  
976 384 reg->info.opname = savepv(opname);
977 384 reg->info.opcode = opcode;
978 384 reg->info.hooks = NULL;
979 384 reg->info.cls = cls;
980  
981 384 reg->oplen = strlen(opname);
982 384 ▶ reg->opname_is_ident = isIDFIRST_utf8_safe(opname, opname + strlen(opname));
Branch: 5 branches
BranchTrueFalseTotal
reg->opname_is_ident = isIDFIRST_utf8_safe(opname, opname + strlen(opname)); 0 384 384
reg->opname_is_ident = isIDFIRST_utf8_safe(opname, opname + strlen(opname)); 384 0 384
reg->opname_is_ident = isIDFIRST_utf8_safe(opname, opname + strlen(opname)); 0 0 0
reg->opname_is_ident = isIDFIRST_utf8_safe(opname, opname + strlen(opname)); 0 0 0
reg->opname_is_ident = isIDFIRST_utf8_safe(opname, opname + strlen(opname)); 0 0 0
983  
984 384 reg->hd.hooks = NULL;
985 384 reg->hd.data = NULL;
986  
987 384 reg->permit_hintkey_len = 0;
988  
989 {
990 384 reg->next = registrations;
991 384 registrations = reg;
992 }
993 384 }
994  
995 16 bool XSParseInfix_check_opname(pTHX_ const char *opname, STRLEN oplen)
996 {
997 16 const char *opname_end = opname + oplen;
998  
999 16 bool opname_is_fq = strstr(opname, "::") != NULL;
1000 16 ▶ bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end);
Branch: 9 branches
BranchTrueFalseTotal
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 16 0 16
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 16 16
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 14 2 16
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 14 0 14
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 2 0 2
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 2 2
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 0 0
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 0 0
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 0 0
1001  
1002 16 const char *s = opname;
1003 16 s += UTF8SKIP(s);
1004  
1005 76 ▶ while(s < opname_end) {
Branch: 1 branch
BranchTrueFalseTotal
while(s < opname_end) { 60 16 76
1006 60 ▶ if(opname_is_ident) {
Branch: 1 branch
BranchTrueFalseTotal
if(opname_is_ident) { 60 0 60
1007 60 ▶ if(!isIDCONT_utf8_safe(s, opname_end))
Branch: 6 branches
BranchTrueFalseTotal
if(!isIDCONT_utf8_safe(s, opname_end)) 0 60 60
if(!isIDCONT_utf8_safe(s, opname_end)) 60 0 60
if(!isIDCONT_utf8_safe(s, opname_end)) 0 0 0
if(!isIDCONT_utf8_safe(s, opname_end)) 0 0 0
if(!isIDCONT_utf8_safe(s, opname_end)) 0 0 0
if(!isIDCONT_utf8_safe(s, opname_end)) 0 60 60
1008 // name that starts with an identifier may not have non-identifier characters in it
1009 0 return FALSE;
1010 }
1011 else {
1012 0 ▶ if(isIDFIRST_utf8_safe(s, opname_end))
Branch: 6 branches
BranchTrueFalseTotal
if(isIDFIRST_utf8_safe(s, opname_end)) 0 0 0
if(isIDFIRST_utf8_safe(s, opname_end)) 0 0 0
if(isIDFIRST_utf8_safe(s, opname_end)) 0 0 0
if(isIDFIRST_utf8_safe(s, opname_end)) 0 0 0
if(isIDFIRST_utf8_safe(s, opname_end)) 0 0 0
if(isIDFIRST_utf8_safe(s, opname_end)) 0 0 0
1013 // name that does not start with an identifer may not have identifier characters in it
1014 0 return FALSE;
1015 }
1016 60 s += UTF8SKIP(s);
1017 }
1018  
1019 16 return TRUE;
1020 }
1021  
1022 16 void XSParseInfix_register(pTHX_ const char *opname, const struct XSParseInfixHooks *hooks, void *hookdata)
1023 {
1024 16 STRLEN oplen = strlen(opname);
1025 16 const char *opname_end = opname + oplen;
1026 16 bool opname_is_fq = strstr(opname, "::") != NULL;
1027 16 ▶ bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end);
Branch: 9 branches
BranchTrueFalseTotal
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 14 2 16
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 14 14
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 12 2 14
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 12 0 12
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 2 0 2
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 2 2
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 0 0
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 0 0
bool opname_is_ident = !opname_is_fq && isIDFIRST_utf8_safe(opname, opname_end); 0 0 0
1028  
1029 16 ▶ if(!opname_is_fq) {
Branch: 1 branch
BranchTrueFalseTotal
if(!opname_is_fq) { 14 2 16
1030 14 ▶ if(!XSParseInfix_check_opname(aTHX_ opname, oplen))
Branch: 1 branch
BranchTrueFalseTotal
if(!XSParseInfix_check_opname(aTHX_ opname, oplen)) 0 14 14
1031 0 croak("Infix operator name is invalid; must be an identifier or entirely non-identifier characters");
1032 }
1033  
1034 16 bool is_listassoc = hooks->flags & XPI_FLAG_LISTASSOC;
1035 16 ▶ if(hooks->flags & ~(XPI_FLAG_LISTASSOC | (1<<15)))
Branch: 1 branch
BranchTrueFalseTotal
if(hooks->flags & ~(XPI_FLAG_LISTASSOC | (1<<15))) 0 16 16
1036 /* (1<<15) == undocumented internal flag to indicate v1-compatible ->new_op hook function */
1037 0 croak("Unrecognised XSParseInfixHooks.flags value 0x%X", hooks->flags);
1038  
1039 16 ▶ switch(hooks->lhs_flags & ~(XPI_OPERAND_ONLY_LOOK)) {
Branch: 1 branch
BranchTrueFalseTotal
switch(hooks->lhs_flags & ~(XPI_OPERAND_ONLY_LOOK)) { 16 0 16
1040 16 case 0:
1041 case XPI_OPERAND_TERM_LIST:
1042 case XPI_OPERAND_LIST:
1043 16 break;
1044 0 default:
1045 0 croak("Unrecognised XSParseInfixHooks.lhs_flags value 0x%X", hooks->lhs_flags);
1046 }
1047  
1048 16 switch(hooks->rhs_flags & ~(XPI_OPERAND_ONLY_LOOK)) {
1049 16 case 0:
1050 case XPI_OPERAND_TERM_LIST:
1051 case XPI_OPERAND_LIST:
1052 16 break;
1053 0 default:
1054 0 croak("Unrecognised XSParseInfixHooks.rhs_flags value 0x%X", hooks->rhs_flags);
1055  
1056 0 case (1 << 7) /* was XPI_OPERAND_CUSTOM */:
1057 0 croak("TODO: Currently XPI_OPERAND_CUSTOM is not supported");
1058 }
1059  
1060 16 ▶ if(is_listassoc) {
Branch: 1 branch
BranchTrueFalseTotal
if(is_listassoc) { 4 12 16
1061 4 ▶ if(hooks->lhs_flags != hooks->rhs_flags)
Branch: 1 branch
BranchTrueFalseTotal
if(hooks->lhs_flags != hooks->rhs_flags) 0 4 4
1062 0 croak("Cannot register a list-associative infix operator with lhs_flags=%02X not equal to rhs_flags=%02X",
1063 hooks->lhs_flags, hooks->rhs_flags);
1064 }
1065  
1066 #ifdef HAVE_PL_INFIX_PLUGIN
1067 16 enum Perl_custom_infix_precedence prec = 0;
1068  
1069 16 switch(hooks->cls) {
1070 0 case 0:
1071 0 warn("Unspecified operator classification for %s; treating it as RELATION for precedence", opname);
1072 0 case XPI_CLS_RELATION:
1073 case XPI_CLS_EQUALITY:
1074 case XPI_CLS_MATCH_MISC:
1075 0 prec = INFIX_PREC_REL;
1076 0 break;
1077  
1078 0 case XPI_CLS_LOW_MISC:
1079 0 prec = INFIX_PREC_LOW;
1080 0 break;
1081  
1082 0 case XPI_CLS_LOGICAL_OR_LOW_MISC:
1083 0 prec = INFIX_PREC_LOGICAL_OR_LOW;
1084 0 break;
1085  
1086 0 case XPI_CLS_LOGICAL_AND_LOW_MISC:
1087 0 prec = INFIX_PREC_LOGICAL_AND_LOW;
1088 0 break;
1089  
1090 0 case XPI_CLS_ASSIGN_MISC:
1091 0 prec = INFIX_PREC_ASSIGN;
1092 0 break;
1093  
1094 0 case XPI_CLS_LOGICAL_OR_MISC:
1095 0 prec = INFIX_PREC_LOGICAL_OR;
1096 0 break;
1097  
1098 0 case XPI_CLS_LOGICAL_AND_MISC:
1099 0 prec = INFIX_PREC_LOGICAL_AND;
1100 0 break;
1101  
1102 14 case XPI_CLS_ADD_MISC:
1103 14 prec = INFIX_PREC_ADD;
1104 14 break;
1105  
1106 2 case XPI_CLS_MUL_MISC:
1107 2 prec = INFIX_PREC_MUL;
1108 2 break;
1109  
1110 0 case XPI_CLS_POW_MISC:
1111 0 prec = INFIX_PREC_POW;
1112 0 break;
1113  
1114 0 case XPI_CLS_HIGH_MISC:
1115 0 prec = INFIX_PREC_HIGH;
1116 0 break;
1117  
1118 0 default:
1119 0 croak("TODO: need to write code for hooks->cls == %d\n", hooks->cls);
1120 }
1121 #endif
1122  
1123 16 ▶ if(!hooks->new_op && !hooks->ppaddr)
Branch: 2 branches
BranchTrueFalseTotal
if(!hooks->new_op && !hooks->ppaddr) 16 0 16
if(!hooks->new_op && !hooks->ppaddr) 0 16 16
1124 0 croak("Cannot register third-party infix operator without at least one of .new_op or .ppaddr");
1125  
1126 struct Registration *reg;
1127 16 Newx(reg, 1, struct Registration);
1128  
1129 #ifdef HAVE_PL_INFIX_PLUGIN
1130 16 reg->def.prec = prec;
1131 16 ▶ if(hooks->parse)
Branch: 1 branch
BranchTrueFalseTotal
if(hooks->parse) 0 16 16
1132 0 reg->def.parse = &parse;
1133 else
1134 16 reg->def.parse = NULL;
1135 16 reg->def.build_op = &build_op;
1136 #endif
1137  
1138 16 reg->info.opname = savepv(opname);
1139 16 reg->info.opcode = OP_CUSTOM;
1140 16 reg->info.hooks = hooks;
1141 16 reg->info.hookdata = hookdata;
1142 16 reg->info.cls = hooks->cls;
1143  
1144 16 reg->oplen = oplen;
1145 16 reg->opname_is_ident = opname_is_ident;
1146 16 reg->opname_is_fq = opname_is_fq;
1147  
1148 16 reg->hd.hooks = hooks;
1149 16 reg->hd.data = hookdata;
1150  
1151 16 reg->opname_is_WIDE = FALSE;
1152 int i;
1153 106 ▶ for(i = 0; i < reg->oplen; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < reg->oplen; i++) { 92 14 106
1154 92 ▶ if(opname[i] & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if(opname[i] & 0x80) { 2 90 92
1155 2 reg->opname_is_WIDE = TRUE;
1156 2 break;
1157 }
1158 }
1159  
1160 16 ▶ if(hooks->permit_hintkey)
Branch: 1 branch
BranchTrueFalseTotal
if(hooks->permit_hintkey) 14 2 16
1161 14 reg->permit_hintkey_len = strlen(hooks->permit_hintkey);
1162 else
1163 2 reg->permit_hintkey_len = 0;
1164  
1165 16 ▶ if(opname_is_fq) {
Branch: 1 branch
BranchTrueFalseTotal
if(opname_is_fq) { 2 14 16
1166 2 reg->next = fqregistrations;
1167 2 fqregistrations = reg;
1168 }
1169 else {
1170 14 reg->next = registrations;
1171 14 registrations = reg;
1172 }
1173  
1174 16 ▶ if(hooks->wrapper_func_name) {
Branch: 1 branch
BranchTrueFalseTotal
if(hooks->wrapper_func_name) { 10 6 16
1175 10 make_wrapper_func(aTHX_ &reg->hd);
1176 }
1177  
1178 16 ▶ if(hooks->ppaddr) {
Branch: 1 branch
BranchTrueFalseTotal
if(hooks->ppaddr) { 16 0 16
1179 XOP *xop;
1180 16 Newx(xop, 1, XOP);
1181  
1182 /* Use both the opname for human-readability, and the address of its
1183 * ppfunc for disambiguating in case of name clashes
1184 */
1185 16 SV *namesv = newSVpvf("B::Deparse::pp_infix_%s_0x%p", opname, hooks->ppaddr);
1186 {
1187 char *doublecolon;
1188 20 ▶ while((doublecolon = strstr(SvPVX(namesv)+sizeof("B::Deparse::pp::"), "::")))
Branch: 1 branch
BranchTrueFalseTotal
while((doublecolon = strstr(SvPVX(namesv)+sizeof("B::Deparse::pp::"), "::"))) 4 16 20
1189 /* Turn '::' into '__', a length-preserving operation */
1190 4 doublecolon[0] = '_', doublecolon[1] = '_';
1191 }
1192 16 ▶ if(reg->opname_is_WIDE)
Branch: 1 branch
BranchTrueFalseTotal
if(reg->opname_is_WIDE) 2 14 16
1193 2 SvUTF8_on(namesv);
1194 16 SAVEFREESV(namesv);
1195  
1196 16 XopENTRY_set(xop, xop_name, savepv(SvPVX(namesv) + sizeof("B::Deparse::pp")));
1197 16 XopENTRY_set(xop, xop_desc, "custom infix operator");
1198 16 ▶ XopENTRY_set(xop, xop_class, is_listassoc ? OA_LISTOP : OA_BINOP);
Branch: 1 branch
BranchTrueFalseTotal
XopENTRY_set(xop, xop_class, is_listassoc ? OA_LISTOP : OA_BINOP); 4 12 16
1199 16 XopENTRY_set(xop, xop_peep, NULL);
1200  
1201 16 Perl_custom_op_register(aTHX_ hooks->ppaddr, xop);
1202  
1203 16 CV *cv = newXS(SvPVX(namesv), deparse_infix, __FILE__);
1204 16 CvXSUBANY(cv).any_ptr = reg;
1205 }
1206 16 }
1207  
1208 24 void XSParseInfix_boot(pTHX)
1209 {
1210 /* stringy relations */
1211 24 reg_builtin(aTHX_ "eq", XPI_CLS_EQUALITY, OP_SEQ);
1212 24 reg_builtin(aTHX_ "ne", XPI_CLS_RELATION, OP_SNE);
1213 24 reg_builtin(aTHX_ "lt", XPI_CLS_RELATION, OP_SLT);
1214 24 reg_builtin(aTHX_ "le", XPI_CLS_RELATION, OP_SLE);
1215 24 reg_builtin(aTHX_ "ge", XPI_CLS_RELATION, OP_SGE);
1216 24 reg_builtin(aTHX_ "gt", XPI_CLS_RELATION, OP_SGT);
1217 24 reg_builtin(aTHX_ "cmp", XPI_CLS_ORDERING, OP_SCMP);
1218 #ifdef HAVE_UNDEF_AWARE_EQUALITY
1219 reg_builtin(aTHX_ "equ", XPI_CLS_EQUALITY, OP_SEQU);
1220 reg_builtin(aTHX_ "neu", XPI_CLS_EQUALITY, OP_SNEU);
1221 #endif
1222  
1223 /* numerical relations */
1224 24 reg_builtin(aTHX_ "==", XPI_CLS_EQUALITY, OP_EQ);
1225 24 reg_builtin(aTHX_ "!=", XPI_CLS_RELATION, OP_NE);
1226 24 reg_builtin(aTHX_ "<", XPI_CLS_RELATION, OP_LT);
1227 24 reg_builtin(aTHX_ "<=", XPI_CLS_RELATION, OP_LE);
1228 24 reg_builtin(aTHX_ ">=", XPI_CLS_RELATION, OP_GE);
1229 24 reg_builtin(aTHX_ ">", XPI_CLS_RELATION, OP_GT);
1230 24 reg_builtin(aTHX_ "<=>", XPI_CLS_ORDERING, OP_NCMP);
1231 #ifdef HAVE_UNDEF_AWARE_EQUALITY
1232 reg_builtin(aTHX_ "===", XPI_CLS_EQUALITY, OP_EQU);
1233 reg_builtin(aTHX_ "!==", XPI_CLS_EQUALITY, OP_NEU);
1234 #endif
1235  
1236 /* other predicates */
1237 #ifdef OP_SMARTMATCH /* removed in perl 5.41.3 */
1238 reg_builtin(aTHX_ "~~", XPI_CLS_SMARTMATCH, OP_SMARTMATCH);
1239 #endif
1240 24 reg_builtin(aTHX_ "=~", XPI_CLS_MATCHRE, OP_MATCH);
1241 /* TODO: !~ */
1242 #ifdef HAVE_OP_ISA
1243 24 reg_builtin(aTHX_ "isa", XPI_CLS_ISA, OP_ISA);
1244 #endif
1245  
1246 /* TODO:
1247 * Other numerics
1248 * + - * / % **
1249 * << >>
1250 *
1251 * Bitwise
1252 * & | ^
1253 * Stringwise
1254 * &. |. ^.
1255 *
1256 * Boolean
1257 * && || //
1258 */
1259  
1260 24 HV *stash = gv_stashpvs("XS::Parse::Infix", TRUE);
1261 24 bool have_pl_infix_plugin =
1262 #ifdef HAVE_PL_INFIX_PLUGIN
1263 TRUE
1264 #else
1265 FALSE
1266 #endif
1267 ;
1268  
1269 24 ▶ newCONSTSUB(stash, "HAVE_PL_INFIX_PLUGIN", boolSV(have_pl_infix_plugin));
Branch: 1 branch
BranchTrueFalseTotal
newCONSTSUB(stash, "HAVE_PL_INFIX_PLUGIN", boolSV(have_pl_infix_plugin)); 24 0 24
1270  
1271 #ifdef HAVE_PL_INFIX_PLUGIN
1272 24 wrap_infix_plugin(&my_infix_plugin, &next_infix_plugin);
1273 #endif
1274 24 }
« hax/make_argcheck_ops.c.inc ↑ Summary share-keyword/include/XSParseKeyword.h »