Commit 0a887b7c42 for perl
commit 0a887b7c4289aef86fbac237b30155b6efde887c
Author: Branislav Zahradník <barney@cpan.org>
Date: Sun Sep 27 13:19:05 2026 +0200
[perly] method invocation -> Action build_method_invocation_arguments
Replace implementation details with intention in `bison` actions.
A reader of the grammar should not need to know the exact op-tree logic
to write or maintain parser actions.
diff --git a/embed.fnc b/embed.fnc
index 7b13eb8e28..4bdb4671ae 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1019,6 +1019,9 @@ p |OP * |build_infix_plugin \
|NN OP *lhs \
|NN OP *rhs \
|NN void *tokendata
+dp |OP * |build_method_invocation_arguments \
+ |NN OP *target \
+ |NULLOK OP *arguments
EXp |const char *|byte_dump_string_ \
|NULLOK const U8 * const start \
|const STRLEN len \
diff --git a/embed.h b/embed.h
index 0ba94dd5bc..e2faf55664 100644
--- a/embed.h
+++ b/embed.h
@@ -1004,6 +1004,7 @@
# define boot_core_builtin() Perl_boot_core_builtin(aTHX)
# define boot_core_mro() Perl_boot_core_mro(aTHX)
# define build_infix_plugin(a,b,c) Perl_build_infix_plugin(aTHX_ a,b,c)
+# define build_method_invocation_arguments(a,b) Perl_build_method_invocation_arguments(aTHX_ a,b)
# define cando(a,b,c) Perl_cando(aTHX_ a,b,c)
# define check_utf8_print(a,b) Perl_check_utf8_print(aTHX_ a,b)
# define closest_cop(a,b,c,d) Perl_closest_cop(aTHX_ a,b,c,d)
diff --git a/op.c b/op.c
index 39a3d00a1f..dad34088a4 100644
--- a/op.c
+++ b/op.c
@@ -4892,6 +4892,45 @@ Perl_block_end(pTHX_ I32 floor, OP *seq)
return retval;
}
+/*
+
+=for apidoc build_method_invocation_arguments
+
+ build_method_invocation_arguments ($target, $arguments);
+ build_method_invocation_arguments ($target, NULL);
+
+Build an C<OP *> representing the structure recognised as method call arguments.
+
+Arguments:
+
+=over
+
+=item C<target>
+
+Expression on which the method call is invoked.
+
+=item C<arguments>
+
+Expression (list) representing the method call arguments.
+
+=back
+
+Available since: v5.46
+
+=cut
+*/
+
+OP*
+Perl_build_method_invocation_arguments (pTHX_ OP *target, OP *arguments)
+{
+ PERL_ARGS_ASSERT_BUILD_METHOD_INVOCATION_ARGUMENTS;
+
+ return arguments
+ ? op_prepend_elem (OP_LIST, target, arguments)
+ : target
+ ;
+}
+
/*
=for apidoc new_block_statement
diff --git a/perly.act b/perly.act
index 45b15abc93..9728423638 100644
--- a/perly.act
+++ b/perly.act
@@ -1230,7 +1230,7 @@ case 2: /* @1: %empty */
OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, scalar ((ps[-5].val.opval)), (ps[-1].val.opval)),
+ build_method_invocation_arguments (scalar ((ps[-5].val.opval)), (ps[-1].val.opval)),
newMETHOP (OP_METHOD, 0, (ps[-3].val.opval))
)
);
@@ -1246,7 +1246,7 @@ case 2: /* @1: %empty */
OPf_STACKED,
op_append_elem (
OP_LIST,
- scalar ((ps[-2].val.opval)),
+ build_method_invocation_arguments (scalar ((ps[-2].val.opval)), NULL),
newMETHOP (OP_METHOD, 0, (ps[0].val.opval))
)
);
@@ -1262,7 +1262,7 @@ case 2: /* @1: %empty */
OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, scalar ((ps[-6].val.opval)), (ps[-1].val.opval)),
+ build_method_invocation_arguments (scalar ((ps[-6].val.opval)), (ps[-1].val.opval)),
newCVREF (0, (ps[-3].val.opval))
)
);
@@ -1278,7 +1278,7 @@ case 2: /* @1: %empty */
OPf_STACKED,
op_append_elem (
OP_LIST,
- scalar ((ps[-3].val.opval)),
+ build_method_invocation_arguments (scalar ((ps[-3].val.opval)), NULL),
newCVREF (0, (ps[0].val.opval))
)
);
@@ -1294,7 +1294,7 @@ case 2: /* @1: %empty */
OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, (ps[-1].val.opval), (ps[0].val.opval)),
+ build_method_invocation_arguments ((ps[-1].val.opval), (ps[0].val.opval)),
newMETHOP (OP_METHOD, 0, (ps[-2].val.opval))
)
);
@@ -1309,7 +1309,7 @@ case 2: /* @1: %empty */
OP_ENTERSUB, OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, (ps[-3].val.opval), (ps[-1].val.opval)),
+ build_method_invocation_arguments ((ps[-3].val.opval), (ps[-1].val.opval)),
newMETHOP(OP_METHOD, 0, (ps[-4].val.opval))
)
);
@@ -2360,6 +2360,6 @@ case 2: /* @1: %empty */
/* Generated from:
- * 649c3163c4f5dbe83dfd3e8ec4616b10c6f200e6dd5e22e406f35c89ca6015b2 perly.y
+ * b12d68c6ed2e81f035beefd1839db151da3de7f4f927226ab445f4f26d83aac2 perly.y
* ba173fe7f0e9b6b5465fb5d0705af3290ac7d8b511f0eead585307eb6c68918d regen_perly.pl
* ex: set ro ft=c: */
diff --git a/perly.h b/perly.h
index 1d904cd58a..0fccf3e929 100644
--- a/perly.h
+++ b/perly.h
@@ -248,6 +248,6 @@ int yyparse (void);
/* Generated from:
- * 649c3163c4f5dbe83dfd3e8ec4616b10c6f200e6dd5e22e406f35c89ca6015b2 perly.y
+ * b12d68c6ed2e81f035beefd1839db151da3de7f4f927226ab445f4f26d83aac2 perly.y
* ba173fe7f0e9b6b5465fb5d0705af3290ac7d8b511f0eead585307eb6c68918d regen_perly.pl
* ex: set ro ft=c: */
diff --git a/perly.tab b/perly.tab
index 2066e1df51..c309288b01 100644
--- a/perly.tab
+++ b/perly.tab
@@ -1667,6 +1667,6 @@ static const toketypes yy_type_tab[] =
};
/* Generated from:
- * 649c3163c4f5dbe83dfd3e8ec4616b10c6f200e6dd5e22e406f35c89ca6015b2 perly.y
+ * b12d68c6ed2e81f035beefd1839db151da3de7f4f927226ab445f4f26d83aac2 perly.y
* ba173fe7f0e9b6b5465fb5d0705af3290ac7d8b511f0eead585307eb6c68918d regen_perly.pl
* ex: set ro ft=c: */
diff --git a/perly.y b/perly.y
index ebf43c0859..a107e387df 100644
--- a/perly.y
+++ b/perly.y
@@ -1351,7 +1351,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, scalar ($target), $arguments),
+ build_method_invocation_arguments (scalar ($target), $arguments),
newMETHOP (OP_METHOD, 0, $method)
)
);
@@ -1366,7 +1366,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
OPf_STACKED,
op_append_elem (
OP_LIST,
- scalar ($target),
+ build_method_invocation_arguments (scalar ($target), NULL),
newMETHOP (OP_METHOD, 0, $method)
)
);
@@ -1385,7 +1385,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, scalar ($target), $arguments),
+ build_method_invocation_arguments (scalar ($target), $arguments),
newCVREF (0, $method)
)
);
@@ -1401,7 +1401,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
OPf_STACKED,
op_append_elem (
OP_LIST,
- scalar ($target),
+ build_method_invocation_arguments (scalar ($target), NULL),
newCVREF (0, $method)
)
);
@@ -1416,7 +1416,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, $target, $arguments),
+ build_method_invocation_arguments ($target, $arguments),
newMETHOP (OP_METHOD, 0, $method)
)
);
@@ -1432,7 +1432,7 @@ listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
OP_ENTERSUB, OPf_STACKED,
op_append_elem (
OP_LIST,
- op_prepend_elem (OP_LIST, $target, $arguments),
+ build_method_invocation_arguments ($target, $arguments),
newMETHOP(OP_METHOD, 0, $method)
)
);
diff --git a/proto.h b/proto.h
index adcd232651..2f683993e1 100644
--- a/proto.h
+++ b/proto.h
@@ -571,6 +571,16 @@ Perl_build_infix_plugin(pTHX_ OP *lhs, OP *rhs, void *tokendata)
assert(tokendata); PERL_UNUSED_CONTEXT_FOR_ARGS_ASSERT; \
} STMT_END
+PERL_CALLCONV OP *
+Perl_build_method_invocation_arguments(pTHX_ OP *target, OP *arguments)
+ Perl_attribute_nonnull_aTHX
+ Perl_attribute_nonnull(pTHX_1)
+ __attribute__visibility__("hidden");
+#define PERL_ARGS_ASSERT_BUILD_METHOD_INVOCATION_ARGUMENTS \
+ STMT_START { Perl_assert_aTHX; assert(target); \
+ PERL_UNUSED_CONTEXT_FOR_ARGS_ASSERT; \
+ } STMT_END
+
PERL_CALLCONV const char *
Perl_byte_dump_string_(pTHX_ const U8 * const start, const STRLEN len, const bool format)
Perl_attribute_nonnull_aTHX;