Skip to content

Commit 4ccada0

Browse files
committed
ParseXS: refactor: set default alias at parse time
If the list of aliases for an XSUB doesn't include the XSUB's main name, an extra alias entry is added, mapping the main name to ix 0. Move this setting from the code generation phase to the end of the parsing phase, because the AST should really be complete by the end of parsing. Also add a test for this behaviour. Shouldn't affect hat code is generated.
1 parent ee5c48e commit 4ccada0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ sub parse {
379379
&& $_->{in_out} =~ /OUTLIST$/
380380
}
381381
@{$self->{decl}{params}{kids}};
382+
383+
# If any aliases have been declared, make the main sub name ix 0
384+
# if not specified.
385+
386+
if ( $self->{map_alias_name_to_value}
387+
and keys %{ $self->{map_alias_name_to_value} })
388+
{
389+
my $pname = $self->{decl}{full_perl_name};
390+
$self->{map_alias_name_to_value}{$pname} = 0
391+
unless defined $self->{map_alias_name_to_value}{$pname};
392+
}
393+
382394
1;
383395
}
384396

@@ -567,10 +579,6 @@ sub boot_code {
567579
# For the main XSUB and for each alias name, generate a newXS() call
568580
# and 'XSANY.any_i32 = ix' line.
569581

570-
# Make the main name one of the aliases if it isn't already
571-
$self->{map_alias_name_to_value}->{$pname} = 0
572-
unless defined $self->{map_alias_name_to_value}{$pname};
573-
574582
foreach my $xname (sort keys
575583
%{ $self->{map_alias_name_to_value} })
576584
{

dist/ExtUtils-ParseXS/t/001-basic.t

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,6 +4288,20 @@ EOF
42884288
[ 0, 0, qr{\QCV * cv;}, "has cv declaration" ],
42894289
],
42904290
4291+
[
4292+
"ALIAS with main as default of 0",
4293+
[ Q(<<'EOF') ],
4294+
|void
4295+
|foo()
4296+
| ALIAS:
4297+
| bar = 2
4298+
EOF
4299+
[ 0, 0, qr{"Foo::foo",.*\n.*= 0;},
4300+
"has Foo::foo" ],
4301+
[ 0, 0, qr{"Foo::bar",.*\n.*= 2;},
4302+
"has Foo::bar" ],
4303+
],
4304+
42914305
[
42924306
"ALIAS multi-perl-line, blank lines",
42934307
[ Q(<<'EOF') ],

0 commit comments

Comments
 (0)