Skip to content

Commit b16f661

Browse files
committed
ParseXS: refactor: INPUT_handler() reindent.
This is #4 of a small series of commits to refactor the INPUT_handler() method and turn it into a Node subclass method. This commit reindents INPUT_handler() and INPUT_handler_line() from 2-indent to 4-indent to match the policy of the file they were moved to in the previous commit. Whitespace-only change
1 parent 44b694a commit b16f661

File tree

1 file changed

+110
-109
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+110
-109
lines changed

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

Lines changed: 110 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,20 +2249,20 @@ package ExtUtils::ParseXS; # XXX tmp
22492249
# block which can follow an xsub signature or CASE keyword.
22502250

22512251
sub INPUT_handler {
2252-
my ExtUtils::ParseXS $self = shift;
2253-
my $line = shift;
2252+
my ExtUtils::ParseXS $self = shift;
2253+
my $line = shift;
22542254

2255-
# In this loop: process each line until the next keyword or end of
2256-
# paragraph.
2255+
# In this loop: process each line until the next keyword or end of
2256+
# paragraph.
22572257

2258-
for (; $line !~ /^$ExtUtils::ParseXS::BLOCK_regexp/o; $line = shift(@{ $self->{line} })) {
2259-
# treat NOT_IMPLEMENTED_YET as another block separator, in addition to
2260-
# $BLOCK_regexp.
2261-
last if $line =~ /^\s*NOT_IMPLEMENTED_YET/;
2258+
for (; $line !~ /^$ExtUtils::ParseXS::BLOCK_regexp/o; $line = shift(@{ $self->{line} })) {
2259+
# treat NOT_IMPLEMENTED_YET as another block separator, in addition to
2260+
# $BLOCK_regexp.
2261+
last if $line =~ /^\s*NOT_IMPLEMENTED_YET/;
22622262

2263-
$self->INPUT_handler_line($line);
2264-
} # foreach line in INPUT block
2265-
$_ = $line;
2263+
$self->INPUT_handler_line($line);
2264+
} # foreach line in INPUT block
2265+
$_ = $line;
22662266
}
22672267

22682268

@@ -2273,8 +2273,8 @@ package ExtUtils::ParseXS; # XXX tmp
22732273
# process a single line from an INPUT section
22742274

22752275
sub INPUT_handler_line {
2276-
my ExtUtils::ParseXS $self = shift;
2277-
my $line = shift;
2276+
my ExtUtils::ParseXS $self = shift;
2277+
my $line = shift;
22782278

22792279
return unless $line =~ /\S/; # skip blank lines
22802280

@@ -2310,77 +2310,77 @@ sub INPUT_handler_line {
23102310
# int a XYZ;
23112311

23122312
my ($var_type, $var_addr, $var_name) =
2313-
$line =~ /^
2314-
( .*? [^&\s] ) # type
2315-
\s*
2316-
(\&?) # addr
2317-
\s* \b
2318-
(\w+ | length\(\w+\)) # name or length(name)
2319-
$
2320-
/xs
2321-
or $self->blurt("Error: invalid parameter declaration '$orig_line'"), return;
2313+
$line =~ /^
2314+
( .*? [^&\s] ) # type
2315+
\s*
2316+
(\&?) # addr
2317+
\s* \b
2318+
(\w+ | length\(\w+\)) # name or length(name)
2319+
$
2320+
/xs
2321+
or $self->blurt("Error: invalid parameter declaration '$orig_line'"), return;
23222322

23232323
# length(s) is only allowed in the XSUB's signature.
23242324
if ($var_name =~ /^length\((\w+)\)$/) {
2325-
$self->blurt("Error: length() not permitted in INPUT section");
2326-
return;
2325+
$self->blurt("Error: length() not permitted in INPUT section");
2326+
return;
23272327
}
23282328

23292329
my ($var_num, $is_alien);
23302330

23312331
my ExtUtils::ParseXS::Node::Param $param
2332-
= $self->{xsub_sig}{names}{$var_name};
2332+
= $self->{xsub_sig}{names}{$var_name};
23332333

23342334

23352335
if (defined $param) {
2336-
# The var appeared in the signature too.
2337-
2338-
# Check for duplicate definitions of a particular parameter name.
2339-
# This can be either because it has appeared in multiple INPUT
2340-
# lines, or because the type was already defined in the signature,
2341-
# and thus shouldn't be defined again. The exception to this are
2342-
# synthetic params like THIS, which are assigned a provisional type
2343-
# which can be overridden.
2344-
if ( $param->{in_input}
2345-
or (!$param->{is_synthetic} and defined $param->{type})
2346-
) {
2347-
$self->blurt(
2348-
"Error: duplicate definition of parameter '$var_name' ignored");
2349-
return;
2350-
}
2351-
2352-
if ($var_name eq 'RETVAL' and $param->{is_synthetic}) {
2353-
# Convert a synthetic RETVAL into a real parameter
2354-
delete $param->{is_synthetic};
2355-
delete $param->{no_init};
2356-
if (! defined $param->{arg_num}) {
2357-
# if has arg_num, RETVAL has appeared in signature but with no
2358-
# type, and has already been moved to the correct position;
2359-
# otherwise, it's an alien var that didn't appear in the
2360-
# signature; move to the correct position.
2361-
@{$self->{xsub_sig}{params}} =
2362-
grep $_ != $param, @{$self->{xsub_sig}{params}};
2363-
push @{$self->{xsub_sig}{params}}, $param;
2364-
$is_alien = 1;
2365-
$param->{is_alien} = 1;
2336+
# The var appeared in the signature too.
2337+
2338+
# Check for duplicate definitions of a particular parameter name.
2339+
# This can be either because it has appeared in multiple INPUT
2340+
# lines, or because the type was already defined in the signature,
2341+
# and thus shouldn't be defined again. The exception to this are
2342+
# synthetic params like THIS, which are assigned a provisional type
2343+
# which can be overridden.
2344+
if ( $param->{in_input}
2345+
or (!$param->{is_synthetic} and defined $param->{type})
2346+
) {
2347+
$self->blurt(
2348+
"Error: duplicate definition of parameter '$var_name' ignored");
2349+
return;
2350+
}
2351+
2352+
if ($var_name eq 'RETVAL' and $param->{is_synthetic}) {
2353+
# Convert a synthetic RETVAL into a real parameter
2354+
delete $param->{is_synthetic};
2355+
delete $param->{no_init};
2356+
if (! defined $param->{arg_num}) {
2357+
# if has arg_num, RETVAL has appeared in signature but with no
2358+
# type, and has already been moved to the correct position;
2359+
# otherwise, it's an alien var that didn't appear in the
2360+
# signature; move to the correct position.
2361+
@{$self->{xsub_sig}{params}} =
2362+
grep $_ != $param, @{$self->{xsub_sig}{params}};
2363+
push @{$self->{xsub_sig}{params}}, $param;
2364+
$is_alien = 1;
2365+
$param->{is_alien} = 1;
2366+
}
23662367
}
2367-
}
23682368

2369-
$param->{in_input} = 1;
2370-
$var_num = $param->{arg_num};
2369+
$param->{in_input} = 1;
2370+
$var_num = $param->{arg_num};
23712371
}
23722372
else {
2373-
# The var is in an INPUT line, but not in signature. Treat it as a
2374-
# general var declaration (which really should have been in a
2375-
# PREINIT section). Legal but nasty: flag is as 'alien'
2376-
$is_alien = 1;
2377-
$param = ExtUtils::ParseXS::Node::Param->new({
2378-
var => $var_name,
2379-
is_alien => 1,
2380-
});
2381-
2382-
push @{$self->{xsub_sig}{params}}, $param;
2383-
$self->{xsub_sig}{names}{$var_name} = $param;
2373+
# The var is in an INPUT line, but not in signature. Treat it as a
2374+
# general var declaration (which really should have been in a
2375+
# PREINIT section). Legal but nasty: flag is as 'alien'
2376+
$is_alien = 1;
2377+
$param = ExtUtils::ParseXS::Node::Param->new({
2378+
var => $var_name,
2379+
is_alien => 1,
2380+
});
2381+
2382+
push @{$self->{xsub_sig}{params}}, $param;
2383+
$self->{xsub_sig}{names}{$var_name} = $param;
23842384
}
23852385

23862386
# Parse the initialisation part of the INPUT line (if any)
@@ -2389,54 +2389,54 @@ sub INPUT_handler_line {
23892389
my $no_init = $param->{no_init}; # may have had OUT in signature
23902390

23912391
if (!$no_init && defined $init_op) {
2392-
# Emit the init code based on overridden $var_init, which was
2393-
# preceded by /[=;+]/ which has been extracted into $init_op
2394-
2395-
if ( $init_op =~ /^[=;]$/
2396-
and $var_init =~ /^NO_INIT\s*;?\s*$/
2397-
) {
2398-
# NO_INIT: skip initialisation
2399-
$no_init = 1;
2400-
}
2401-
elsif ($init_op eq '=') {
2402-
# Overridden typemap, such as '= ($type)SvUV($arg)'
2403-
$var_init =~ s/;\s*$//;
2404-
$init = $var_init,
2405-
}
2406-
else {
2407-
# "; extra code" or "+ extra code" :
2408-
# append the extra code (after passing through eval) after all the
2409-
# INPUT and PREINIT blocks have been processed, indirectly using
2410-
# the $self->{xsub_deferred_code_lines} mechanism.
2411-
# In addition, for '+', also generate the normal initialisation
2412-
# code from the standard typemap - assuming that it's a real
2413-
# parameter that appears in the signature as well as the INPUT
2414-
# line.
2415-
$no_init = !($init_op eq '+' && !$is_alien);
2416-
# But in either case, add the deferred code
2417-
$defer = $var_init;
2418-
}
2392+
# Emit the init code based on overridden $var_init, which was
2393+
# preceded by /[=;+]/ which has been extracted into $init_op
2394+
2395+
if ( $init_op =~ /^[=;]$/
2396+
and $var_init =~ /^NO_INIT\s*;?\s*$/
2397+
) {
2398+
# NO_INIT: skip initialisation
2399+
$no_init = 1;
2400+
}
2401+
elsif ($init_op eq '=') {
2402+
# Overridden typemap, such as '= ($type)SvUV($arg)'
2403+
$var_init =~ s/;\s*$//;
2404+
$init = $var_init,
2405+
}
2406+
else {
2407+
# "; extra code" or "+ extra code" :
2408+
# append the extra code (after passing through eval) after all the
2409+
# INPUT and PREINIT blocks have been processed, indirectly using
2410+
# the $self->{xsub_deferred_code_lines} mechanism.
2411+
# In addition, for '+', also generate the normal initialisation
2412+
# code from the standard typemap - assuming that it's a real
2413+
# parameter that appears in the signature as well as the INPUT
2414+
# line.
2415+
$no_init = !($init_op eq '+' && !$is_alien);
2416+
# But in either case, add the deferred code
2417+
$defer = $var_init;
2418+
}
24192419
}
24202420
else {
2421-
# no initialiser: emit var and init code based on typemap entry,
2422-
# unless: it's alien (so no stack arg to bind to it)
2423-
$no_init = 1 if $is_alien;
2421+
# no initialiser: emit var and init code based on typemap entry,
2422+
# unless: it's alien (so no stack arg to bind to it)
2423+
$no_init = 1 if $is_alien;
24242424
}
24252425

24262426
%$param = (
2427-
%$param,
2428-
type => $var_type,
2429-
arg_num => $var_num,
2430-
var => $var_name,
2431-
defer => $defer,
2432-
init => $init,
2433-
init_op => $init_op,
2434-
no_init => $no_init,
2435-
is_addr => !!$var_addr,
2427+
%$param,
2428+
type => $var_type,
2429+
arg_num => $var_num,
2430+
var => $var_name,
2431+
defer => $defer,
2432+
init => $init,
2433+
init_op => $init_op,
2434+
no_init => $no_init,
2435+
is_addr => !!$var_addr,
24362436
);
24372437

24382438
$param->check($self)
2439-
or return;
2439+
or return;
24402440

24412441
# Emit "type var" declaration and possibly various forms of
24422442
# initialiser code.
@@ -2449,6 +2449,7 @@ sub INPUT_handler_line {
24492449
$param->as_code($self);
24502450
}
24512451

2452+
24522453
# ======================================================================
24532454

24542455

0 commit comments

Comments
 (0)