Skip to content

Commit d14e0cb

Browse files
committed
ParseXS: refactor: make parse_sig a Node::Sig meth
The previous commit moved the signature parsing code into its own method. This commit makes the method be in the Extutils::ParseXS::Node::Sig class. This involves changing the name to just 'parse', and swapping around all the mentions of $self and $sig. The next commit will move the method into Node.pm. (By doing this in 3 commits, code changes don't get hidden in the noise).
1 parent 2a2fb53 commit d14e0cb

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ EOM
881881
# Split $self->{xsub_sub}{sig_text} into parameters, parse them,
882882
# and store them as Node::Param objects within the Node::Sig object.
883883

884-
$self->parse_sig();
884+
$sig->parse($self);
885885

886886
# ----------------------------------------------------------------
887887
# Peek ahead into the body of the XSUB looking for various conditions
@@ -1894,13 +1894,13 @@ EOF
18941894
#
18951895
# ----------------------------------------------------------------
18961896

1897-
sub parse_sig {
1898-
my ExtUtils::ParseXS $self = shift;
1899-
my ExtUtils::ParseXS::Node::Sig $sig = $self->{xsub_sig};
1897+
sub ExtUtils::ParseXS::Node::Sig::parse {
1898+
my ExtUtils::ParseXS::Node::Sig $self = shift;
1899+
my ExtUtils::ParseXS $pxs = shift;
19001900

19011901
# remove line continuation chars (\)
1902-
$sig->{sig_text} =~ s/\\\s*/ /g;
1903-
my $sig_text = $sig->{sig_text};
1902+
$self->{sig_text} =~ s/\\\s*/ /g;
1903+
my $sig_text = $self->{sig_text};
19041904

19051905
my @args;
19061906
my $optional_args_count = 0;# how many default params seen
@@ -1926,7 +1926,7 @@ sub parse_sig {
19261926
# regex doesn't work. This code path should ideally never be
19271927
# reached, and indicates a design weakness in $C_arg.
19281928
@args = split(/\s*,\s*/, $sig_text);
1929-
Warn( $self, "Warning: cannot parse argument list '$sig_text', fallback to split");
1929+
Warn($pxs, "Warning: cannot parse argument list '$sig_text', fallback to split");
19301930
}
19311931
}
19321932
else {
@@ -1935,11 +1935,11 @@ sub parse_sig {
19351935

19361936
# C++ methods get a fake object/class arg at the start.
19371937
# This affects arg numbering.
1938-
if (defined($self->{xsub_class})) {
1938+
if (defined($pxs->{xsub_class})) {
19391939
my ($var, $type) =
1940-
($self->{xsub_seen_static} or $self->{xsub_func_name} eq 'new')
1940+
($pxs->{xsub_seen_static} or $pxs->{xsub_func_name} eq 'new')
19411941
? ('CLASS', "char *")
1942-
: ('THIS', "$self->{xsub_class} *");
1942+
: ('THIS', "$pxs->{xsub_class} *");
19431943

19441944
my ExtUtils::ParseXS::Node::Param $param
19451945
= ExtUtils::ParseXS::Node::Param->new( {
@@ -1948,9 +1948,9 @@ sub parse_sig {
19481948
is_synthetic => 1,
19491949
arg_num => ++$args_count,
19501950
});
1951-
push @{$sig->{params}}, $param;
1952-
$sig->{names}{$var} = $param;
1953-
$param->check($self)
1951+
push @{$self->{params}}, $param;
1952+
$self->{names}{$var} = $param;
1953+
$param->check($pxs)
19541954
}
19551955

19561956
for (@args) {
@@ -1960,27 +1960,27 @@ sub parse_sig {
19601960
#
19611961
# where:
19621962
# IN/OUT/OUTLIST etc are only allowed under
1963-
# $self->{config_allow_inout}
1963+
# $pxs->{config_allow_inout}
19641964
#
19651965
# a C type is only allowed under
1966-
# $self->{config_allow_argtypes}
1966+
# $pxs->{config_allow_argtypes}
19671967
#
19681968
# foo can be a plain C variable name, or can be
1969-
# length(foo) but only under $self->{config_allow_argtypes}
1969+
# length(foo) but only under $pxs->{config_allow_argtypes}
19701970
#
19711971
# = default default value - only allowed under
1972-
# $self->{config_allow_argtypes}
1972+
# $pxs->{config_allow_argtypes}
19731973

19741974
s/^\s+//;
19751975
s/\s+$//;
19761976

19771977
# Process ellipsis (...)
19781978

1979-
$self->blurt("further XSUB parameter seen after ellipsis (...)")
1980-
if $sig->{seen_ellipsis};
1979+
$pxs->blurt("further XSUB parameter seen after ellipsis (...)")
1980+
if $self->{seen_ellipsis};
19811981

19821982
if ($_ eq '...') {
1983-
$sig->{seen_ellipsis} = 1;
1983+
$self->{seen_ellipsis} = 1;
19841984
next;
19851985
}
19861986

@@ -2007,7 +2007,7 @@ sub parse_sig {
20072007
/x;
20082008

20092009
unless (defined $name) {
2010-
$self->blurt("Unparseable XSUB parameter: '$_'");
2010+
$pxs->blurt("Unparseable XSUB parameter: '$_'");
20112011
next;
20122012
}
20132013

@@ -2016,23 +2016,23 @@ sub parse_sig {
20162016
var => $name,
20172017
});
20182018

2019-
if (exists $sig->{names}{$name}) {
2020-
$self->blurt(
2019+
if (exists $self->{names}{$name}) {
2020+
$pxs->blurt(
20212021
"Error: duplicate definition of argument '$name' ignored");
20222022
next;
20232023
}
20242024

2025-
push @{$sig->{params}}, $param;
2026-
$sig->{names}{$name} = $param;
2025+
push @{$self->{params}}, $param;
2026+
$self->{names}{$name} = $param;
20272027

20282028
# Process optional IN/OUT etc modifier
20292029

20302030
if (defined $out_type) {
2031-
if ($self->{config_allow_inout}) {
2031+
if ($pxs->{config_allow_inout}) {
20322032
$out_type = $1 eq 'IN' ? '' : $1;
20332033
}
20342034
else {
2035-
$self->blurt("parameter IN/OUT modifier not allowed under -noinout");
2035+
$pxs->blurt("parameter IN/OUT modifier not allowed under -noinout");
20362036
}
20372037
}
20382038
else {
@@ -2043,8 +2043,8 @@ sub parse_sig {
20432043

20442044
undef $type unless length($type) && $type =~ /\S/;
20452045

2046-
if (defined($type) && !$self->{config_allow_argtypes}) {
2047-
$self->blurt("parameter type not allowed under -noargtypes");
2046+
if (defined($type) && !$pxs->{config_allow_argtypes}) {
2047+
$pxs->blurt("parameter type not allowed under -noargtypes");
20482048
undef $type;
20492049
}
20502050

@@ -2054,16 +2054,16 @@ sub parse_sig {
20542054
my $len_name;
20552055

20562056
if ($name =~ /^length\( \s* (\w+) \s* \)\z/x) {
2057-
if ($self->{config_allow_argtypes}) {
2057+
if ($pxs->{config_allow_argtypes}) {
20582058
$len_name = $1;
20592059
$is_length = 1;
20602060
if (defined $default) {
2061-
$self->blurt("Default value not allowed on length() parameter '$len_name'");
2061+
$pxs->blurt("Default value not allowed on length() parameter '$len_name'");
20622062
undef $default;
20632063
}
20642064
}
20652065
else {
2066-
$self->blurt("length() pseudo-parameter not allowed under -noargtypes");
2066+
$pxs->blurt("length() pseudo-parameter not allowed under -noargtypes");
20672067
}
20682068
}
20692069

@@ -2104,8 +2104,8 @@ sub parse_sig {
21042104
}
21052105
} # for (@args)
21062106

2107-
$sig->{nargs} = $args_count;
2108-
$sig->{min_args} = $args_count - $optional_args_count;
2107+
$self->{nargs} = $args_count;
2108+
$self->{min_args} = $args_count - $optional_args_count;
21092109
}
21102110

21112111

0 commit comments

Comments
 (0)