Skip to content

Commit a9182b6

Browse files
committed
ParseXS: refactor: Sig::parse(): rename arg vars
This method splits the XSUB signature string into individual parameter strings and then parses them. Rename the var from '@Args' to '@param_texts' since it contains parameters rather than args. The _text suffix is to distinguish them from $param objects. This is one of the last steps in my quiet mission to rename variables etc from *arg* to *param* where they hold info about params rather than args. This is particularly significant as some parameters (like 'length(foo)') don't get bound to args, so there isn't a 1:1 correspondence. Also, shorten the names of a couple of lex vars now that they're only in a small method with limited scope: $args_count => $nargs $optional_args_count => $opt_args Should be no functional changes.
1 parent c4a0b1e commit a9182b6

File tree

1 file changed

+15
-14
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+15
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ sub parse {
533533
$self->{sig_text} =~ s/\\\s*/ /g;
534534
my $sig_text = $self->{sig_text};
535535

536-
my @args;
537-
my $optional_args_count = 0;# how many default params seen
538-
my $args_count = 0; # how many args are expected
536+
my @param_texts;
537+
my $opt_args = 0; # how many params with default values seen
538+
my $nargs = 0; # how many args are expected
539539

540540
# First, split signature into separate parameters
541541

@@ -550,21 +550,21 @@ sub parse {
550550
# regex, do so. This splits the params on commas, but can handle
551551
# things like foo(a = ",", b)
552552
use re 'eval';
553-
@args = ($sig_c =~ /\G ( (??{ $C_arg }) ) , /xg);
553+
@param_texts = ($sig_c =~ /\G ( (??{ $C_arg }) ) , /xg);
554554
}
555555
else {
556556
# This is the fallback parameter-splitting path for when the $C_arg
557557
# regex doesn't work. This code path should ideally never be
558558
# reached, and indicates a design weakness in $C_arg.
559-
@args = split(/\s*,\s*/, $sig_text);
559+
@param_texts = split(/\s*,\s*/, $sig_text);
560560
Warn($pxs, "Warning: cannot parse argument list '$sig_text', fallback to split");
561561
}
562562
}
563563
else {
564-
@args = ();
564+
@param_texts = ();
565565
}
566566

567-
# C++ methods get a fake object/class arg at the start.
567+
# C++ methods get a fake object/class param at the start.
568568
# This affects arg numbering.
569569
if (defined($pxs->{xsub_class})) {
570570
my ($var, $type) =
@@ -577,14 +577,14 @@ sub parse {
577577
var => $var,
578578
type => $type,
579579
is_synthetic => 1,
580-
arg_num => ++$args_count,
580+
arg_num => ++$nargs,
581581
});
582582
push @{$self->{params}}, $param;
583583
$self->{names}{$var} = $param;
584584
$param->check($pxs)
585585
}
586586

587-
for (@args) {
587+
for (@param_texts) {
588588
# Process each parameter. A parameter is of the general form:
589589
#
590590
# OUT char* foo = expression
@@ -718,7 +718,7 @@ sub parse {
718718
# to be used in "usage: ..." error messages.
719719
my $report_def = '';
720720
if (defined $default) {
721-
$optional_args_count++;
721+
$opt_args++;
722722
# The default expression for reporting usage. For backcompat,
723723
# sometimes preserve the spaces either side of the '='
724724
$report_def = ((defined $type or $is_length) ? '' : $sp1)
@@ -731,14 +731,15 @@ sub parse {
731731
$param->{arg_num} = undef;
732732
}
733733
else {
734-
$param->{arg_num} = ++$args_count;
734+
$param->{arg_num} = ++$nargs;
735735
}
736-
} # for (@args)
736+
} # for (@param_texts)
737737

738-
$self->{nargs} = $args_count;
739-
$self->{min_args} = $args_count - $optional_args_count;
738+
$self->{nargs} = $nargs;
739+
$self->{min_args} = $nargs - $opt_args;
740740
}
741741

742+
742743
# Return a string to be used in "usage: .." error messages.
743744

744745
sub usage_string {

0 commit comments

Comments
 (0)