Skip to content

Commit f281964

Browse files
committed
ParseXS: refactor: add Node::OUTPUT_line fields
This is #6 of a small series of commits to refactor OUTPUT keyword handling. The main job of parsing an OUTPUT 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 OUTPUT_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 bf8ea9f commit f281964

File tree

1 file changed

+16
-2
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,11 @@ package ExtUtils::ParseXS::Node::OUTPUT_line;
30533053
# Handle one line from an OUTPUT keyword block
30543054

30553055
BEGIN { $build_subclass->('keyline', # parent
3056-
'param', # the param object associated with this OUTPUT line.
3056+
'param', # the param object associated with this OUTPUT line.
3057+
'is_setmagic', # bool: the line is a SETMAGIC: line
3058+
'do_setmagic', # bool: the current SETMAGIC state
3059+
'name', # name of the parameter to output
3060+
'code', # optional setting code
30573061
)};
30583062

30593063

@@ -3069,8 +3073,16 @@ sub parse {
30693073

30703074
return unless $line =~ /\S/; # skip blank lines
30713075

3076+
# set some sane default values in case we do one of the early returns
3077+
# below
3078+
3079+
$self->{do_setmagic} = $pxs->{xsub_SETMAGIC_state};
3080+
$self->{is_setmagic} = 0;
3081+
30723082
if ($line =~ /^\s*SETMAGIC\s*:\s*(ENABLE|DISABLE)\s*/) {
30733083
$pxs->{xsub_SETMAGIC_state} = ($1 eq "ENABLE" ? 1 : 0);
3084+
$self->{do_setmagic} = $pxs->{xsub_SETMAGIC_state};
3085+
$self->{is_setmagic} = 1;
30743086
return;
30753087
}
30763088

@@ -3080,6 +3092,8 @@ sub parse {
30803092
#
30813093
my ($outarg, $outcode) = $line =~ /^\s*(\S+)\s*(.*?)\s*$/s;
30823094

3095+
$self->{name} = $outarg;
3096+
30833097
my ExtUtils::ParseXS::Node::Param $param =
30843098
$pxs->{xsub_sig}{names}{$outarg};
30853099
$self->{param} = $param;
@@ -3106,7 +3120,7 @@ sub parse {
31063120
$param->{do_setmagic} = $outarg eq 'RETVAL'
31073121
? 0 # RETVAL never needs magic setting
31083122
: $pxs->{xsub_SETMAGIC_state};
3109-
$param->{output_code} = $outcode if length $outcode;
3123+
$self->{code} = $param->{output_code} = $outcode if length $outcode;
31103124

31113125
if ($outarg eq 'RETVAL') {
31123126
# Postpone processing the RETVAL line to last (it's left to the

0 commit comments

Comments
 (0)