Skip to content

Commit caa8c16

Browse files
committed
ParseXS: refactor: fetch_para(): invert if
change if (cond) { ... lots lines ... } to if (!cond) { goto read_next_line; } ... lots lines ... read_next_line: which might be considered a bit regressive in a 'goto considered harmful' sort of way, but will will help with further refactoring, and emphasises that the current input line is discarded if the condition isn't met (i.e. it strips out code comments, which wasn't obvious).
1 parent 21e6471 commit caa8c16

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,18 +662,14 @@ sub fetch_para {
662662
return 1;
663663
}
664664

665-
my $final;
666-
667-
# Process this line unless it looks like a '#', comment
668-
669-
if ($self->{lastline} !~ /^\s*#/ # not a CPP directive
665+
if ($self->{lastline} =~ /^\s*#/
670666
# CPP directives:
671667
# ANSI: if ifdef ifndef elif else endif define undef
672668
# line error pragma
673669
# gcc: warning include_next
674670
# obj-c: import
675671
# others: ident (gcc notes that some cpps have this one)
676-
|| $self->{lastline} =~ /^\#[ \t]*
672+
&& $self->{lastline} !~ /^\#[ \t]*
677673
(?:
678674
(?:if|ifn?def|elif|else|endif|elifn?def|
679675
define|undef|pragma|error|
@@ -683,14 +679,22 @@ sub fetch_para {
683679
\s* ["<] .* [>"]
684680
)
685681
/x
686-
)
687-
{
682+
) {
683+
# A line starting with # but not a CPP directive?
684+
# Must be a code comment. Skip it.
685+
goto read_next_line;
686+
}
687+
688+
# A general line: process it
689+
690+
my $final;
691+
688692
# Blank line followed by char in column 1. Start of next XSUB?
689693
last if $self->{lastline} =~ /^\S/
690694
&& @{ $self->{line} }
691695
&& $self->{line}->[-1] eq "";
692696

693-
# processes CPP conditionals
697+
# analyse CPP conditionals
694698
if ($self->{lastline}
695699
=~/^#[ \t]*(if|ifn?def|elif|else|endif|elifn?def)\b/)
696700
{
@@ -721,8 +725,9 @@ sub fetch_para {
721725

722726
push(@{ $self->{line} }, $self->{lastline});
723727
push(@{ $self->{line_no} }, $self->{lastline_no});
724-
} # end of processing non-comment lines
725728

729+
730+
read_next_line:
726731
# Read next line and continuation lines
727732
last unless defined($self->{lastline} = readline($self->{in_fh}));
728733
$self->{lastline_no} = $.;

0 commit comments

Comments
 (0)