Skip to content

Commit f76b840

Browse files
committed
ParseXS: refactor: add Node::INPUT_line fields
This is #7 of a small series of commits to refactor INPUT keyword handling. The main job of parsing an INPUT line is to extract any information on that line and use it to update the associated Param object (which was likely created earlier when the XSUB's signature was parsed). This commit makes that information also be stored in new fields in the INPUT_line object. These new fields aren't currently used for anything, but they could in principle become useful if options for deparsing or exporting were added to ParseXS.
1 parent 101100f commit f76b840

File tree

1 file changed

+39
-6
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+39
-6
lines changed

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,11 +2294,35 @@ package ExtUtils::ParseXS::Node::INPUT_line;
22942294
# Handle one line from an INPUT keyword block
22952295

22962296
BEGIN { $build_subclass->('keyline', # parent
2297-
'param', # the param object associated with this INPUT line.
2297+
'param', # The Param object associated with this INPUT line.
2298+
2299+
# The parsed components of this INPUT line:
2300+
'type', # char *
2301+
'is_addr', # &
2302+
'name', # foo
2303+
'init_op', # =
2304+
'init', # SvIv($arg)
22982305
)};
22992306

23002307

2301-
# Parse one line from an INPUT block
2308+
# Parse one line in an INPUT block. This method does two main things:
2309+
#
2310+
# It parses the line and stores its components in the fields of the
2311+
# INPUT_line object (which aren't further used for parsing or code
2312+
# generation)
2313+
#
2314+
# It also uses those values to create/update the Param object
2315+
# associated with this variable. For example with
2316+
#
2317+
# void
2318+
# foo(a = 0)
2319+
# int a
2320+
#
2321+
# a Param object will already have been created with the name 'a' and
2322+
# default value '0' when the signature was parsed. Parsing the 'int a'
2323+
# line will set the INPUT_line object's fields to (type => 'int',
2324+
# name => 'a'), while the Param object will have its type field set to
2325+
# 'int'. The INPUT_line object also stores a ref to the Param object.
23022326
#
23032327

23042328
sub parse {
@@ -2366,7 +2390,6 @@ sub parse {
23662390
my ExtUtils::ParseXS::Node::Param $param
23672391
= $pxs->{xsub_sig}{names}{$var_name};
23682392

2369-
23702393
if (defined $param) {
23712394
# The var appeared in the signature too.
23722395

@@ -2424,7 +2447,7 @@ sub parse {
24242447
my $no_init = $param->{no_init}; # may have had OUT in signature
24252448

24262449
if (!$no_init && defined $init_op) {
2427-
# Emit the init code based on overridden $var_init, which was
2450+
# Use the init code based on overridden $var_init, which was
24282451
# preceded by /[=;+]/ which has been extracted into $init_op
24292452

24302453
if ( $init_op =~ /^[=;]$/
@@ -2458,6 +2481,18 @@ sub parse {
24582481
$no_init = 1 if $is_alien;
24592482
}
24602483

2484+
# Save the basic information parsed from this line
2485+
2486+
$self->{type} = $var_type,
2487+
$self->{is_addr} = !!$var_addr,
2488+
$self->{name} = $var_name,
2489+
$self->{init_op} = $init_op,
2490+
$self->{init} = $var_init,
2491+
2492+
$self->{param} = $param;
2493+
2494+
# and also update the param object using that information
2495+
24612496
%$param = (
24622497
%$param,
24632498
type => $var_type,
@@ -2470,8 +2505,6 @@ sub parse {
24702505
is_addr => !!$var_addr,
24712506
);
24722507

2473-
$self->{param} = $param;
2474-
24752508
$param->check($pxs)
24762509
or return;
24772510
}

0 commit comments

Comments
 (0)