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