Skip to content

Commit 4841c28

Browse files
committed
ParseXS: refactor: add POSTCALL node
add this class: ExtUtils::ParseXS::Node::POSTCALL and add a few basic tests for the POSTCALL keyword. Note that (similarly to other codeblock-derived Node classes), this commit causes a (harmless) slight change of '#line' output for an empty code block. In particular, this: 5: void 6: foo() 7: POSTCALL: 8: used to generate these two adjacent lines of C code: #line 7 "foo.xs" #line NNN "foo.c" but now outputs: #line 8 "foo.xs" #line NNN "foo.c"
1 parent 3ca4844 commit 4841c28

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,12 +1812,6 @@ sub CLEANUP_handler {
18121812
}
18131813

18141814

1815-
sub POSTCALL_handler {
1816-
my ExtUtils::ParseXS $self = shift;
1817-
$self->print_section();
1818-
}
1819-
1820-
18211815
sub FALLBACK_handler {
18221816
my ExtUtils::ParseXS $self = shift;
18231817
my ($setting) = @_;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,18 @@ BEGIN { $build_subclass->('codeblock', # parent
24342434
# Currently all methods are just inherited.
24352435

24362436

2437+
# ======================================================================
2438+
2439+
package ExtUtils::ParseXS::Node::POSTCALL;
2440+
2441+
# Store the code lines associated with the POSTCALL: keyword
2442+
2443+
BEGIN { $build_subclass->('codeblock', # parent
2444+
)};
2445+
2446+
# Currently all methods are just inherited.
2447+
2448+
24372449
# ======================================================================
24382450

24392451
package ExtUtils::ParseXS::Node::PPCODE;

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,4 +4217,46 @@ EOF
42174217
}
42184218
42194219
4220+
{
4221+
# Test POSTCALL keyword
4222+
4223+
my $preamble = Q(<<'EOF');
4224+
|MODULE = Foo PACKAGE = Foo
4225+
|
4226+
|PROTOTYPES: DISABLE
4227+
|
4228+
EOF
4229+
4230+
my @test_fns = (
4231+
[
4232+
"POSTCALL basic",
4233+
[ Q(<<'EOF') ],
4234+
|int
4235+
|foo(int aaa)
4236+
| POSTCALL:
4237+
| YYY
4238+
EOF
4239+
[ 0, 0, qr{\bint\s+aaa}, "has aaa decl" ],
4240+
[ 0, 0, qr{^\s+\QRETVAL = foo(aaa);}m, "has code body" ],
4241+
[ 0, 0, qr{^\s+YYY\n}m, "has postcall body" ],
4242+
[ 0, 0, qr{aaa.*foo\(aaa\).*YYY.*TARGi}s, "in sequence" ],
4243+
[ 0, 0, qr{\#line 8 .*\n\s+YYY}, "correct #line" ],
4244+
],
4245+
[
4246+
"POSTCALL empty",
4247+
[ Q(<<'EOF') ],
4248+
|void
4249+
|foo(int aaa)
4250+
| POSTCALL:
4251+
EOF
4252+
[ 0, 0, qr{\bint\s+aaa}, "has aaa decl" ],
4253+
[ 0, 0, qr{^\s+\Qfoo(aaa);}m, "has code body" ],
4254+
[ 0, 0, qr{\Qfoo(aaa);\E\n\#line 8 }, "correct #line" ],
4255+
],
4256+
);
4257+
4258+
test_many($preamble, 'XS_Foo_', \@test_fns);
4259+
}
4260+
4261+
42204262
done_testing;

0 commit comments

Comments
 (0)