summaryrefslogtreecommitdiff
path: root/inline.h
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-12-06 23:32:48 +0000
committerPaul Evans <leonerd@leonerd.org.uk>2022-12-08 11:42:01 +0000
commitdd6f5699e38163de743c93d2641b8ecff455f67c (patch)
tree4ebd43bfb2b4248d4005aa9c37128f057ad69d13 /inline.h
parenta357bb956571f97b412a75b85e8e19a4550e4caa (diff)
downloadperl-dd6f5699e38163de743c93d2641b8ecff455f67c.tar.gz
Define a newPADxVOP() convenience function
This function conveniently sets the ->op_targ field of the returned op, making it neater to use inline in larger trees of new*OP functions used to build optree fragments. This function is implemented as `static inline`, for speed and code-size reasons.
Diffstat (limited to 'inline.h')
-rw-r--r--inline.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/inline.h b/inline.h
index 1a1715f044..d7de926263 100644
--- a/inline.h
+++ b/inline.h
@@ -3086,6 +3086,36 @@ Perl_cx_popgiven(pTHX_ PERL_CONTEXT *cx)
SvREFCNT_dec(sv);
}
+/*
+=for apidoc newPADxVOP
+
+Constructs, checks and returns an op containing a pad offset. C<type> is
+the opcode, which should be one of C<OP_PADSV>, C<OP_PADAV>, C<OP_PADHV>
+or C<OP_PADCV>. The returned op will have the C<op_targ> field set by
+the C<padix> argument.
+
+This is convenient when constructing a large optree in nested function
+calls, as it avoids needing to store the pad op directly to set the
+C<op_targ> field as a side-effect. For example
+
+ o = op_append_elem(OP_LINESEQ, o,
+ newPADxVOP(OP_PADSV, 0, padix));
+
+=cut
+*/
+
+PERL_STATIC_INLINE OP *
+Perl_newPADxVOP(pTHX_ I32 type, I32 flags, PADOFFSET padix)
+{
+ PERL_ARGS_ASSERT_NEWPADXVOP;
+
+ assert(type == OP_PADSV || type == OP_PADAV || type == OP_PADHV
+ || type == OP_PADCV);
+ OP *o = newOP(type, flags);
+ o->op_targ = padix;
+ return o;
+}
+
/* ------------------ util.h ------------------------------------------- */
/*