diff options
author | James E. Keenan <jkeenan@cpan.org> | 2010-04-03 15:00:02 -0400 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2011-07-12 20:53:54 +0200 |
commit | a7fa83459a57b807d31dd217c012d13355deb026 (patch) | |
tree | 06fdfd6f22261669133ee1cd4f09a89d4fc43283 | |
parent | e8697f90d03af120d21259c941f9e40d76902b0e (diff) | |
download | perl-a7fa83459a57b807d31dd217c012d13355deb026.tar.gz |
Refactor code inside process_file() into print_preprocessor_statements()
-rw-r--r-- | dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm index ca71735a2e..bd832f5bbd 100644 --- a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm +++ b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm @@ -308,34 +308,8 @@ EOF my $ln = shift(@{ $self->{line} }); print $ln, "\n"; next unless $ln =~ /^\#\s*((if)(?:n?def)?|elsif|else|endif)\b/; - my $statement = $+; - if ($statement eq 'if') { - $XSS_work_idx = @{ $self->{XSStack} }; - push(@{ $self->{XSStack} }, {type => 'if'}); - } - else { - death ("Error: `$statement' with no matching `if'") - if $self->{XSStack}->[-1]{type} ne 'if'; - if ($self->{XSStack}->[-1]{varname}) { - push(@{ $self->{InitFileCode} }, "#endif\n"); - push(@{ $BootCode_ref }, "#endif"); - } - - my(@fns) = keys %{$self->{XSStack}->[-1]{functions}}; - if ($statement ne 'endif') { - # Hide the functions defined in other #if branches, and reset. - @{$self->{XSStack}->[-1]{other_functions}}{@fns} = (1) x @fns; - @{$self->{XSStack}->[-1]}{qw(varname functions)} = ('', {}); - } - else { - my($tmp) = pop(@{ $self->{XSStack} }); - 0 while (--$XSS_work_idx - && $self->{XSStack}->[$XSS_work_idx]{type} ne 'if'); - # Keep all new defined functions - push(@fns, keys %{$tmp->{other_functions}}); - @{$self->{XSStack}->[$XSS_work_idx]{functions}}{@fns} = (1) x @fns; - } - } + ( $XSS_work_idx, $BootCode_ref ) = + print_preprocessor_statements( $self, $XSS_work_idx, $BootCode_ref ); } next PARAGRAPH unless @{ $self->{line} }; @@ -1947,4 +1921,38 @@ sub death { exit 1; } +sub print_preprocessor_statements { + my ($self, $XSS_work_idx, $BootCode_ref) = @_; + + my $statement = $+; + if ($statement eq 'if') { + $XSS_work_idx = @{ $self->{XSStack} }; + push(@{ $self->{XSStack} }, {type => 'if'}); + } + else { + death ("Error: `$statement' with no matching `if'") + if $self->{XSStack}->[-1]{type} ne 'if'; + if ($self->{XSStack}->[-1]{varname}) { + push(@{ $self->{InitFileCode} }, "#endif\n"); + push(@{ $BootCode_ref }, "#endif"); + } + + my(@fns) = keys %{$self->{XSStack}->[-1]{functions}}; + if ($statement ne 'endif') { + # Hide the functions defined in other #if branches, and reset. + @{$self->{XSStack}->[-1]{other_functions}}{@fns} = (1) x @fns; + @{$self->{XSStack}->[-1]}{qw(varname functions)} = ('', {}); + } + else { + my($tmp) = pop(@{ $self->{XSStack} }); + 0 while (--$XSS_work_idx + && $self->{XSStack}->[$XSS_work_idx]{type} ne 'if'); + # Keep all new defined functions + push(@fns, keys %{$tmp->{other_functions}}); + @{$self->{XSStack}->[$XSS_work_idx]{functions}}{@fns} = (1) x @fns; + } + } + return ($XSS_work_idx, $BootCode_ref); +} + 1; |