Skip to content

Commit 46a9935

Browse files
committed
ParseXS: refactor: add CLEANUP node
add this class: ExtUtils::ParseXS::Node::CLEANUP and add a few basic tests for the CLEANUP 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: CLEANUP: 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 b2ed92a commit 46a9935

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
@@ -1806,12 +1806,6 @@ sub OUTPUT_handler {
18061806
}
18071807

18081808

1809-
sub CLEANUP_handler {
1810-
my ExtUtils::ParseXS $self = shift;
1811-
$self->print_section();
1812-
}
1813-
1814-
18151809
sub FALLBACK_handler {
18161810
my ExtUtils::ParseXS $self = shift;
18171811
my ($setting) = @_;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,18 @@ sub parse {
24222422
}
24232423

24242424

2425+
# ======================================================================
2426+
2427+
package ExtUtils::ParseXS::Node::CLEANUP;
2428+
2429+
# Store the code lines associated with the CLEANUP: keyword
2430+
2431+
BEGIN { $build_subclass->('codeblock', # parent
2432+
)};
2433+
2434+
# Currently all methods are just inherited.
2435+
2436+
24252437
# ======================================================================
24262438

24272439
package ExtUtils::ParseXS::Node::INIT;

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4123,6 +4123,48 @@ EOF
41234123
test_many($preamble, 'XS_Foo_', \@test_fns);
41244124
}
41254125
4126+
{
4127+
# Test CLEANUP keyword
4128+
4129+
my $preamble = Q(<<'EOF');
4130+
|MODULE = Foo PACKAGE = Foo
4131+
|
4132+
|PROTOTYPES: DISABLE
4133+
|
4134+
EOF
4135+
4136+
my @test_fns = (
4137+
[
4138+
"CLEANUP basic",
4139+
[ Q(<<'EOF') ],
4140+
|int
4141+
|foo(int aaa)
4142+
| CLEANUP:
4143+
| YYY
4144+
EOF
4145+
[ 0, 0, qr{\bint\s+aaa}, "has aaa decl" ],
4146+
[ 0, 0, qr{^\s+\QRETVAL = foo(aaa);}m, "has code body" ],
4147+
[ 0, 0, qr{^\s+YYY\n}m, "has cleanup body" ],
4148+
[ 0, 0, qr{aaa.*foo\(aaa\).*TARGi.*YYY}s, "in sequence" ],
4149+
[ 0, 0, qr{\#line 8 .*\n\s+YYY}, "correct #line" ],
4150+
],
4151+
[
4152+
"CLEANUP empty",
4153+
[ Q(<<'EOF') ],
4154+
|void
4155+
|foo(int aaa)
4156+
| CLEANUP:
4157+
EOF
4158+
[ 0, 0, qr{\bint\s+aaa}, "has aaa decl" ],
4159+
[ 0, 0, qr{^\s+\Qfoo(aaa);}m, "has code body" ],
4160+
[ 0, 0, qr{\Qfoo(aaa);\E\n\#line 8 }, "correct #line" ],
4161+
],
4162+
);
4163+
4164+
test_many($preamble, 'XS_Foo_', \@test_fns);
4165+
}
4166+
4167+
41264168
41274169
{
41284170
# Test CODE keyword

0 commit comments

Comments
 (0)