1/* vi: set ft=c inde=: */
2
3#ifndef op_convert_list
4
5#define CHECKOP(type,o) \
6    ((PL_op_mask && PL_op_mask[type])                           \
7     ? ( op_free((OP*)o),                                       \
8         Perl_croak(aTHX_ "'%s' trapped by operation mask", PL_op_desc[type]),  \
9         (OP*)0 )                                               \
10     : PL_check[type](aTHX_ (OP*)o))
11
12static OP *S_op_std_init(pTHX_ OP *o) {
13    I32 type = o->op_type;
14
15    if (PL_opargs[type] & OA_RETSCALAR)
16        op_contextualize(o, G_SCALAR);
17    if (PL_opargs[type] & OA_TARGET && !o->op_targ)
18        o->op_targ = pad_alloc(type, SVs_PADTMP);
19
20    return o;
21}
22
23#define op_convert_list(A, B, C) S_op_convert_list(aTHX_ A, B, C)
24
25static OP *S_op_convert_list(pTHX_ I32 type, I32 flags, OP *o)
26{
27    dVAR;
28    assert(type >= 0);
29    if (!o || o->op_type != OP_LIST)
30        o = newLISTOP(OP_LIST, 0, o, NULL);
31    else
32        o->op_flags &= ~OPf_WANT;
33
34    if (!(PL_opargs[type] & OA_MARK))
35        op_null(cLISTOPo->op_first);
36    else {
37#if HAVE_PERL_VERSION(5, 15, 3)
38        OP * const kid2 = cLISTOPo->op_first->op_sibling;
39        if (kid2 && kid2->op_type == OP_COREARGS) {
40            op_null(cLISTOPo->op_first);
41            kid2->op_private |= OPpCOREARGS_PUSHMARK;
42        }
43#endif
44    }
45
46    o->op_type = (OPCODE)type;
47    o->op_ppaddr = PL_ppaddr[type];
48    o->op_flags |= flags;
49
50    o = CHECKOP(type, o);
51    if (o->op_type != type) {
52        return o;
53    }
54
55    return S_op_std_init(aTHX_ o);
56}
57
58#endif
59