Skip to content

Commit ac6d839

Browse files
committed
ParseXS: rm xsub_map_varname_to_seen_in_INPUT
More refactoring: remove the xsub_map_varname_to_seen_in_INPUT field from the ExtUtils::ParseXS class and instead add an in_input field to the ExtUtils::ParseXS::Node::Param class.
1 parent b85d5f8 commit ac6d839

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,6 @@ BEGIN {
345345

346346
# Per-XSUB INPUT section parsing state:
347347

348-
'xsub_map_varname_to_seen_in_INPUT', # Hash: map argument names to a
349-
# 'seen in INPUT' boolean (for duplicate
350-
# spotting).
351-
352348
'xsub_seen_RETVAL_in_INPUT', # Seen var called 'RETVAL' in an INPUT section.
353349

354350

@@ -707,13 +703,6 @@ EOM
707703

708704
# Initialize some per-XSUB instance variables:
709705

710-
foreach my $member (qw(
711-
xsub_map_varname_to_seen_in_INPUT
712-
))
713-
{
714-
$self->{$member} = {};
715-
}
716-
717706
$self->{xsub_seen_PROTOTYPE} = 0;
718707
$self->{xsub_seen_SCOPE} = 0;
719708
$self->{xsub_seen_INTERFACE_or_MACRO} = 0;
@@ -1284,7 +1273,6 @@ EOF
12841273
# PREINIT/INPUT
12851274
#
12861275
# keep track of which vars have been seen
1287-
%{ $self->{xsub_map_varname_to_seen_in_INPUT} } = ();
12881276
$self->{xsub_seen_RETVAL_in_OUTPUT} = 0; # RETVAL seen in OUTPUT section
12891277

12901278
# Process any implicit INPUT section.
@@ -2374,14 +2362,34 @@ sub INPUT_handler {
23742362
# flag 'RETVAL' as having been seen
23752363
$self->{xsub_seen_RETVAL_in_INPUT} |= $var_name eq "RETVAL";
23762364

2365+
my ($var_num, $is_alien);
23772366
my $sig_param = $self->{xsub_sig}{names}{$var_name};
23782367

2379-
# The index number of the parameter. The counting starts at 1 and skips
2380-
# fake parameters like 'length(s))'. If not found, flag it as 'alien':
2381-
# a var which appears in an INPUT section but not in the XSUB's
2382-
# signature. Legal but nasty.
2383-
my $var_num = $sig_param->{arg_num};
2384-
my $is_alien = !defined($var_num);
2368+
if (defined $sig_param) {
2369+
# The var appeared in the signature too.
2370+
2371+
# Check for duplicate definitions of a particular parameter name.
2372+
# This can be either because it has appeared in multiple INPUT
2373+
# lines, or because the type was already defined in the signature,
2374+
# and thus shouldn't be defined again. The exception to this are
2375+
# synthetic params like THIS, which are assigned a provisional type
2376+
# which can be overridden.
2377+
if ( $sig_param->{in_input}
2378+
or (!$sig_param->{is_synthetic} and exists $sig_param->{type})
2379+
) {
2380+
$self->blurt(
2381+
"Error: duplicate definition of argument '$var_name' ignored");
2382+
next;
2383+
}
2384+
$sig_param->{in_input} = 1;
2385+
$var_num = $sig_param->{arg_num};
2386+
}
2387+
else {
2388+
# The var is in an INPUT line, but not in signature. Treat it as a
2389+
# general var declaration (which really should have been in a
2390+
# PREINIT section). Legal but nasty: flag is as 'alien'
2391+
$is_alien = 1;
2392+
}
23852393

23862394
# Parse the initialisation part of the INPUT line (if any)
23872395

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ BEGIN {
105105
'len_name' , # the 'foo' in 'length(foo)' in signature
106106
'is_alien', # var declared in INPUT line, but not in signature
107107
'is_synthetic',# var like 'THIS' - we pretend it was in the sig
108+
'in_input', # the parameter has appeared in an INPUT statement
108109

109110
);
110111

@@ -156,16 +157,6 @@ sub check {
156157
$sigp->{$_} = $self->{$_} if exists $self->{$_};
157158
}
158159
}
159-
#
160-
# Check for duplicate definitions of a particular parameter name.
161-
# Either the name has appeared in more than one INPUT line or
162-
# has appeared also in the signature with a type specified.
163-
164-
if ($pxs->{xsub_map_varname_to_seen_in_INPUT}->{$self->{var}}++) {
165-
$pxs->blurt(
166-
"Error: duplicate definition of argument '$self->{var}' ignored");
167-
return;
168-
}
169160

170161
return 1;
171162
}

0 commit comments

Comments
 (0)