Skip to content

Commit 195fee3

Browse files
committed
[MERGE] ParseXS: build an AST for each XSUB
This series 156 commits changes ExtUtils::ParseXS so that, instead of intermixing parsing and code-emitting for each XSUB, it now parses each XSUB into an Abstract Syntax Tree, and then walks the tree to emit all the C code for that XSUB. This makes the code generally more understandable and maintainable. For now it still just discards each tree after the XSUB is parsed; in future work, the AST will be extended so that it holds the whole file (including all the XSUBs) rather than just the current XSUB. This branch contains six types of commit. 1) For terminal AST nodes for keywords such as FOO, the old ExtUtils::ParseXS::handle_FOO() method is removed and a new ExtUtils::ParseXS::Node::FOO class is added with parse() and as_code() methods which copy over the parsing and code-emitting parts of the handle_FOO() method. For a few keywords like INPUT which have values per line, both a Node::FOO and Node::FOO_line class are created, with several FOO_line nodes being children of the FOO node. Note that doing the modifications for a single keyword often consists in fact of several commits in sequence. 2) For higher-level nodes, a Node::foo class is created with parse() and as_code() methods as before, but the contents of these methods are typically populated by moving the relevant bits of code over from the big ExtUtils::ParseXS::process_file() method. 3) Most of the state fields of the ExtUtils::ParseXS class (especially all the xsub_foo ones) are removed, and similar fields added to the various Node subclasses instead. 4) Fixups to ensure that all parse-time code is only in parse() methods or associated helper functions, and similarly for as_code(). 5) Various bug fixes related to state that should be per-CASE rather than per-XSUB. Some of these bugs were pre-existing, some were introduced during this branch. 6) General tidying-up, fixing code comments, adding POD etc.
2 parents 5fa00ea + fec16c7 commit 195fee3

File tree

15 files changed

+6413
-2984
lines changed

15 files changed

+6413
-2984
lines changed

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

Lines changed: 52 additions & 1651 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use strict;
33
use warnings;
44
use Symbol;
55

6-
our $VERSION = '3.57';
6+
our $VERSION = '3.58';
77

88
=head1 NAME
99

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ExtUtils::ParseXS::CountLines;
22
use strict;
33

4-
our $VERSION = '3.57';
4+
our $VERSION = '3.58';
55

66
our $SECTION_END_MARKER;
77

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package ExtUtils::ParseXS::Eval;
22
use strict;
33
use warnings;
44

5-
our $VERSION = '3.57';
5+
our $VERSION = '3.58';
66

77
=head1 NAME
88
@@ -29,23 +29,20 @@ Warns the contents of C<$@> if any.
2929
Not all these variables are necessarily considered "public" wrt. use in
3030
typemaps, so beware. Variables set up from the ExtUtils::ParseXS object:
3131
32-
$Package $ALIAS $func_name $Full_func_name $pname
32+
$Package $func_name $Full_func_name $pname
3333
3434
Variables set up from C<$other_hashref>:
3535
36-
$var $type $ntype $subtype $arg
36+
$var $type $ntype $subtype $arg $ALIAS
3737
3838
=cut
3939

4040
sub eval_output_typemap_code {
4141
my ($_pxs, $_code, $_other) = @_;
4242

43-
my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
44-
= @{$_pxs}{qw(PACKAGE_name xsub_seen_ALIAS xsub_func_name
45-
xsub_func_full_C_name xsub_func_full_perl_name)};
46-
47-
my ($var, $type, $ntype, $subtype, $arg)
48-
= @{$_other}{qw(var type ntype subtype arg)};
43+
my ($Package) = @{$_pxs}{qw(PACKAGE_name)};
44+
my ($var, $type, $ntype, $subtype, $arg, $ALIAS, $func_name, $Full_func_name, $pname)
45+
= @{$_other}{qw(var type ntype subtype arg alias func_name full_C_name full_perl_name)};
4946

5047
my $rv = eval $_code;
5148
warn $@ if $@;
@@ -64,23 +61,20 @@ Warns the contents of C<$@> if any.
6461
Not all these variables are necessarily considered "public" wrt. use in
6562
typemaps, so beware. Variables set up from the ExtUtils::ParseXS object:
6663
67-
$Package $ALIAS $func_name $Full_func_name $pname
64+
$Package $func_name $Full_func_name $pname
6865
6966
Variables set up from C<$other_hashref>:
7067
71-
$var $type $ntype $subtype $num $init $printed_name $arg $argoff
68+
$var $type $ntype $subtype $num $init $printed_name $arg $argoff $ALIAS
7269
7370
=cut
7471

7572
sub eval_input_typemap_code {
7673
my ($_pxs, $_code, $_other) = @_;
7774

78-
my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
79-
= @{$_pxs}{qw(PACKAGE_name xsub_seen_ALIAS xsub_func_name
80-
xsub_func_full_C_name xsub_func_full_perl_name)};
81-
82-
my ($var, $type, $num, $init, $printed_name, $arg, $ntype, $argoff, $subtype)
83-
= @{$_other}{qw(var type num init printed_name arg ntype argoff subtype)};
75+
my ($Package) = @{$_pxs}{qw(PACKAGE_name)};
76+
my ($var, $type, $num, $init, $printed_name, $arg, $ntype, $argoff, $subtype, $ALIAS, $func_name, $Full_func_name, $pname)
77+
= @{$_other}{qw(var type num init printed_name arg ntype argoff subtype alias func_name full_C_name full_perl_name)};
8478

8579
my $rv = eval $_code;
8680
warn $@ if $@;

0 commit comments

Comments
 (0)