Skip to content

Commit 2db64d2

Browse files
committed
ParseXS: refactor: delete param field from Params
The Node::Params class has a 'params' field which holds a list of Node::Param objects. This class was one of the first Node classes to be created during my recent refactoring work, and at the time, Node subclasses didn't have a generic 'kids' field. They do now, so just store the list of Param objects of 'kids' of the Params object.
1 parent 34ec182 commit 2db64d2

File tree

1 file changed

+28
-26
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+28
-26
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ sub parse {
378378
grep { defined $_->{in_out}
379379
&& $_->{in_out} =~ /OUTLIST$/
380380
}
381-
@{$self->{decl}{params}{params}};
381+
@{$self->{decl}{params}{kids}};
382382
1;
383383
}
384384

@@ -1792,9 +1792,11 @@ package ExtUtils::ParseXS::Node::Params;
17921792
# It is a mainly a list of Node::Param children.
17931793

17941794
BEGIN { $build_subclass->('', # parent
1795-
'params', # Array ref of Node::Param objects representing
1795+
1796+
# inherited 'kids' field:
1797+
# Array ref of Node::Param objects representing
17961798
# the parameters of this XSUB - either the
1797-
# original ones as seen in thre XSUB's signature,
1799+
# original ones as seen in the XSUB's signature,
17981800
# or per-xbody ones augmented by info from INPUT
17991801
# and OUTPUT sections.
18001802

@@ -1927,7 +1929,7 @@ sub parse {
19271929
is_synthetic => 1,
19281930
arg_num => ++$nargs,
19291931
});
1930-
push @{$self->{params}}, $param;
1932+
push @{$self->{kids}}, $param;
19311933
$self->{names}{$var} = $param;
19321934
}
19331935

@@ -1943,7 +1945,7 @@ sub parse {
19431945
#
19441946
# semi-real Same as fully-synthetic, but with a defined
19451947
# arg_num, and with an updated position within
1946-
# @{$self->{params}}.
1948+
# @{$self->{kids}}.
19471949
# A RETVAL has appeared in the signature, but
19481950
# without a type yet specified, so it continues to
19491951
# use $xsub->{decl}{return_type}{type}.
@@ -1961,7 +1963,7 @@ sub parse {
19611963
is_synthetic => 1,
19621964
} );
19631965

1964-
push @{$self->{params}}, $param;
1966+
push @{$self->{kids}}, $param;
19651967
$self->{names}{RETVAL} = $param;
19661968
}
19671969

@@ -2022,7 +2024,7 @@ sub parse {
20222024
if (/^ SV \s* \* $/x) {
20232025
# special-case SV* as a placeholder for backwards
20242026
# compatibility.
2025-
push @{$self->{params}},
2027+
push @{$self->{kids}},
20262028
ExtUtils::ParseXS::Node::Param->new( {
20272029
var => 'SV *',
20282030
arg_num => ++$nargs,
@@ -2053,7 +2055,7 @@ sub parse {
20532055
# been declared as a parameter too, override any implicit
20542056
# RETVAL declaration. Delete the original param from the
20552057
# param list.
2056-
@{$self->{params}} = grep $_ != $old_param, @{$self->{params}};
2058+
@{$self->{kids}} = grep $_ != $old_param, @{$self->{kids}};
20572059
# If the param declaration includes a type, it becomes a
20582060
# real parameter. Otherwise the param is kept as
20592061
# 'semi-real' (synthetic, but with an arg_num) until such
@@ -2068,7 +2070,7 @@ sub parse {
20682070
}
20692071
}
20702072

2071-
push @{$self->{params}}, $param;
2073+
push @{$self->{kids}}, $param;
20722074
$self->{names}{$name} = $param;
20732075

20742076
# Process optional IN/OUT etc modifier
@@ -2153,7 +2155,7 @@ sub parse {
21532155

21542156
# for each parameter of the form 'length(foo)', mark the corresponding
21552157
# 'foo' parameter as 'has_length', or error out if foo not found.
2156-
for my $param (@{$self->{params}}) {
2158+
for my $param (@{$self->{kids}}) {
21572159
next unless $param->{is_length};
21582160
my $name = $param->{len_name};
21592161
if (exists $self->{names}{$name}) {
@@ -2183,7 +2185,7 @@ sub usage_string {
21832185
grep {
21842186
defined $_->{arg_num},
21852187
}
2186-
@{$self->{params}};
2188+
@{$self->{kids}};
21872189

21882190
push @args, '...' if $self->{seen_ellipsis};
21892191
return join ', ', @args;
@@ -2200,7 +2202,7 @@ sub C_func_signature {
22002202
my ExtUtils::ParseXS $pxs = shift;
22012203

22022204
my @args;
2203-
for my $param (@{$self->{params}}) {
2205+
for my $param (@{$self->{kids}}) {
22042206
next if $param->{is_synthetic} # THIS/CLASS/RETVAL
22052207
# if a synthetic RETVAL has acquired an arg_num, then
22062208
# it's appeared in the signature (although without a
@@ -2248,7 +2250,7 @@ sub proto_string {
22482250
# overridden entry.
22492251
my @p = map defined $_->{proto} ? $_->{proto} : '$',
22502252
grep defined $_->{arg_num} && $_->{arg_num} > 0,
2251-
@{$self->{params}};
2253+
@{$self->{kids}};
22522254

22532255
my @sep = (';'); # separator between required and optional args
22542256
my $min = $self->{min_args};
@@ -2319,15 +2321,15 @@ sub parse {
23192321
# now duplicate (deep copy) any Param objects and regenerate a new
23202322
# names-mapping hash
23212323

2322-
$ioparams->{params} = [];
2324+
$ioparams->{kids} = [];
23232325
$ioparams->{names} = {};
23242326

2325-
for my $op (@{$orig->{params}}) {
2327+
for my $op (@{$orig->{kids}}) {
23262328
my $p = ExtUtils::ParseXS::Node::Param->new($op);
23272329
# don't copy the current proto state (from the most recent
23282330
# CASE) into the new CASE.
23292331
undef $p->{proto};
2330-
push @{$ioparams->{params}}, $p;
2332+
push @{$ioparams->{kids}}, $p;
23312333
$ioparams->{names}{$p->{var}} = $p;
23322334
}
23332335

@@ -2448,7 +2450,7 @@ sub parse {
24482450
# also use that value to update the per-XSUB value, warning if the
24492451
# value changes.
24502452

2451-
for my $ioparam (@{$xbody->{ioparams}{params}}) {
2453+
for my $ioparam (@{$xbody->{ioparams}{kids}}) {
24522454
$ioparam->set_proto($pxs);
24532455
my $ioproto = $ioparam->{proto};
24542456
my $name = $ioparam->{var};
@@ -2493,7 +2495,7 @@ EOF
24932495

24942496
# Emit any 'char * CLASS' or 'Foo::Bar *THIS' declaration if needed
24952497

2496-
for my $param (grep $_->{is_synthetic}, @{$ioparams->{params}}) {
2498+
for my $param (grep $_->{is_synthetic}, @{$ioparams->{kids}}) {
24972499
$param->as_code($pxs, $xsub, $xbody);
24982500
}
24992501

@@ -2511,8 +2513,8 @@ EOF
25112513
for my $param (
25122514
grep $_->{is_ansi},
25132515
(
2514-
grep( $_->{is_length}, @{$ioparams->{params}} ),
2515-
grep(! $_->{is_length}, @{$ioparams->{params}} ),
2516+
grep( $_->{is_length}, @{$ioparams->{kids}} ),
2517+
grep(! $_->{is_length}, @{$ioparams->{kids}} ),
25162518
)
25172519
)
25182520

@@ -2703,7 +2705,7 @@ sub as_code {
27032705
&& $_->{in_out} =~ /OUT$/
27042706
&& !$_->{in_output}
27052707
}
2706-
@{$ioparams->{params}})
2708+
@{$ioparams->{kids}})
27072709
{
27082710
$param->as_output_code($pxs, $xsub, $xbody);
27092711
}
@@ -2745,7 +2747,7 @@ sub as_code {
27452747
for my $param (grep { defined $_->{in_out}
27462748
&& $_->{in_out} =~ /OUTLIST$/
27472749
}
2748-
@{$ioparams->{params}}
2750+
@{$ioparams->{kids}}
27492751
) {
27502752
$param->as_output_code($pxs, $xsub, $xbody, $basic++);
27512753
}
@@ -4088,9 +4090,9 @@ sub parse {
40884090
# type, and has already been moved to the correct position;
40894091
# otherwise, it's an alien var that didn't appear in the
40904092
# signature; move to the correct position.
4091-
@{$ioparams->{params}} =
4092-
grep $_ != $param, @{$ioparams->{params}};
4093-
push @{$ioparams->{params}}, $param;
4093+
@{$ioparams->{kids}} =
4094+
grep $_ != $param, @{$ioparams->{kids}};
4095+
push @{$ioparams->{kids}}, $param;
40944096
$is_alien = 1;
40954097
$param->{is_alien} = 1;
40964098
}
@@ -4109,7 +4111,7 @@ sub parse {
41094111
is_alien => 1,
41104112
});
41114113

4112-
push @{$ioparams->{params}}, $param;
4114+
push @{$ioparams->{kids}}, $param;
41134115
$ioparams->{names}{$var_name} = $param;
41144116
}
41154117

0 commit comments

Comments
 (0)