From a7fa83459a57b807d31dd217c012d13355deb026 Mon Sep 17 00:00:00 2001 From: "James E. Keenan" Date: Sat, 3 Apr 2010 15:00:02 -0400 Subject: [PATCH] Refactor code inside process_file() into print_preprocessor_statements() --- dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm | 64 +++++++++++++++------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm index ca71735..bd832f5 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; -- 2.7.4