summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-11-19 11:48:19 +0000
committerPaul Evans <leonerd@leonerd.org.uk>2022-11-26 15:47:22 +0000
commitf17d9825ab9b50967fd3d8742cc1bbccec96c049 (patch)
tree1835ae9ad258f5fadd48b08c96b33887768c3352 /op.c
parent5bd919dc87af18e1bce77d3ead83b704a2903292 (diff)
downloadperl-f17d9825ab9b50967fd3d8742cc1bbccec96c049.tar.gz
Recognise `//=` and `||=` syntax in signature parameter defaults
These create parameters where the default expression is assigned whenever the caller did not pass a defined (or true) value. I.e. both if it is missing, or is present but undef (or false).
Diffstat (limited to 'op.c')
-rw-r--r--op.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/op.c b/op.c
index eec6da5067..8851dce046 100644
--- a/op.c
+++ b/op.c
@@ -7975,6 +7975,32 @@ S_newONCEOP(pTHX_ OP *initop, OP *padop)
}
/*
+=for apidoc newARGDEFELEMOP
+
+Constructs and returns a new C<OP_ARGDEFELEM> op which provides a defaulting
+expression given by C<expr> for the signature parameter at the index given
+by C<argindex>. The expression optree is consumed by this function and
+becomes part of the returned optree.
+
+=cut
+*/
+
+OP *
+Perl_newARGDEFELEMOP(pTHX_ I32 flags, OP *expr, I32 argindex)
+{
+ PERL_ARGS_ASSERT_NEWARGDEFELEMOP;
+
+ OP *o = (OP *)alloc_LOGOP(OP_ARGDEFELEM, expr, LINKLIST(expr));
+ o->op_flags |= (U8)(flags);
+ o->op_private = 1 | (U8)(flags >> 8);
+
+ /* re-purpose op_targ to hold @_ index */
+ o->op_targ = (PADOFFSET)(argindex);
+
+ return o;
+}
+
+/*
=for apidoc newASSIGNOP
Constructs, checks, and returns an assignment op. C<left> and C<right>