From 8c8fdb93c620b9ec75f9ba1fbb682920da0df8e3 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 13 Jan 2023 07:53:21 -0800 Subject: [PATCH] simplify coding for essential old breakpoints This eliminates the need for variable _ris_essential_old_breakpoint_ --- lib/Perl/Tidy/Formatter.pm | 63 ++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 33da2e66..0b942ff7 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -531,7 +531,6 @@ BEGIN { _rcollapsed_length_by_seqno_ => $i++, _rbreak_before_container_by_seqno_ => $i++, - _ris_essential_old_breakpoint_ => $i++, _roverride_cab3_ => $i++, _ris_assigned_structure_ => $i++, _ris_short_broken_eval_block_ => $i++, @@ -965,7 +964,6 @@ sub new { $self->[_rcollapsed_length_by_seqno_] = {}; $self->[_rbreak_before_container_by_seqno_] = {}; - $self->[_ris_essential_old_breakpoint_] = {}; $self->[_roverride_cab3_] = {}; $self->[_ris_assigned_structure_] = {}; $self->[_ris_short_broken_eval_block_] = {}; @@ -9560,36 +9558,8 @@ EOM my $file_writer_object = $self->[_file_writer_object_]; $file_writer_object->setup_convergence_test( \@Klast_valign_code ); - # Mark essential old breakpoints if combination -iob -lp is used. These - # two options do not work well together, but we can avoid turning -iob off - # by ignoring -iob at certain essential line breaks. - # Fixes cases b1021 b1023 b1034 b1048 b1049 b1050 b1056 b1058 - if ( $rOpts_ignore_old_breakpoints && $rOpts_line_up_parentheses ) { - my %is_assignment_or_fat_comma = %is_assignment; - $is_assignment_or_fat_comma{'=>'} = 1; - my $ris_essential_old_breakpoint = - $self->[_ris_essential_old_breakpoint_]; - my ( $Kfirst, $Klast ); - foreach my $line_of_tokens ( @{$rlines} ) { - my $line_type = $line_of_tokens->{_line_type}; - if ( $line_type ne 'CODE' ) { - ( $Kfirst, $Klast ) = ( undef, undef ); - next; - } - my ( $Kfirst_prev, $Klast_prev ) = ( $Kfirst, $Klast ); - ( $Kfirst, $Klast ) = @{ $line_of_tokens->{_rK_range} }; - - next unless defined($Klast_prev); - next unless defined($Kfirst); - my $type_last = $rLL->[$Klast_prev]->[_TOKEN_]; - my $type_first = $rLL->[$Kfirst]->[_TOKEN_]; - next - unless ( $is_assignment_or_fat_comma{$type_last} - || $is_assignment_or_fat_comma{$type_first} ); - $ris_essential_old_breakpoint->{$Klast_prev} = 1; - } - } return ( $severe_error, $rqw_lines ); + } ## end sub resync_lines_and_tokens sub check_for_old_break { @@ -14723,6 +14693,13 @@ EOM return; } ## end sub flush + my %is_assignment_or_fat_comma; + + BEGIN { + %is_assignment_or_fat_comma = %is_assignment; + $is_assignment_or_fat_comma{'=>'} = 1; + } + sub process_line_of_CODE { my ( $self, $my_line_of_tokens ) = @_; @@ -14958,6 +14935,17 @@ EOM # This is a good place to kill incomplete one-line blocks if ( $max_index_to_go >= 0 ) { + + # For -iob and -lp, mark essential old breakpoints. + # Fixes b1021 b1023 b1034 b1048 b1049 b1050 b1056 b1058 + # See related code below. + if ( $rOpts_ignore_old_breakpoints && $rOpts_line_up_parentheses ) { + my $type_first = $rLL->[$K_first_true]->[_TYPE_]; + if ( $is_assignment_or_fat_comma{$type_first} ) { + $old_breakpoint_to_go[$max_index_to_go] = 1; + } + } + if ( # this check needed -mangle (for example rt125012) @@ -15061,8 +15049,17 @@ EOM } # mark old line breakpoints in current output stream - if ( !$rOpts_ignore_old_breakpoints - || $self->[_ris_essential_old_breakpoint_]->{$K_last} ) + if ( + !$rOpts_ignore_old_breakpoints + + # Mark essential old breakpoints if combination -iob -lp is + # used. These two options do not work well together, but + # we can avoid turning -iob off by ignoring -iob at certain + # essential line breaks. See also related code above. + # Fixes b1021 b1023 b1034 b1048 b1049 b1050 b1056 b1058 + || ( $rOpts_line_up_parentheses + && $is_assignment_or_fat_comma{$type} ) + ) { my $jobp = $max_index_to_go; if ( $types_to_go[$max_index_to_go] eq 'b' -- 2.39.5