# NEW_TOKENS must add bond strength rules
my %is_good_keyword_breakpoint;
- my %is_lt_gt_le_ge;
my %is_container_token;
my %binary_bond_strength_nospace;
@q = qw(if unless while until for foreach);
@is_good_keyword_breakpoint{@q} = (1) x scalar(@q);
- @q = qw(lt gt le ge);
- @is_lt_gt_le_ge{@q} = (1) x scalar(@q);
-
@q = qw/ ( [ { } ] ) /;
@is_container_token{@q} = (1) x scalar(@q);
$left_bond_strength{'or'} = VERY_WEAK - 0.02;
$left_bond_strength{'err'} = VERY_WEAK - 0.02;
$left_bond_strength{'xor'} = VERY_WEAK - 0.01;
- $left_bond_strength{'ne'} = NOMINAL;
- $left_bond_strength{'lt'} = 0.9 * NOMINAL + 0.1 * STRONG;
- $left_bond_strength{'gt'} = 0.9 * NOMINAL + 0.1 * STRONG;
- $left_bond_strength{'le'} = 0.9 * NOMINAL + 0.1 * STRONG;
- $left_bond_strength{'ge'} = 0.9 * NOMINAL + 0.1 * STRONG;
- $left_bond_strength{'eq'} = NOMINAL;
-
- $right_bond_strength{'and'} = NOMINAL;
- $right_bond_strength{'or'} = NOMINAL;
- $right_bond_strength{'err'} = NOMINAL;
- $right_bond_strength{'xor'} = NOMINAL;
- $right_bond_strength{'ne'} = NOMINAL;
- $right_bond_strength{'eq'} = NOMINAL;
+
+ @q = qw(ne eq);
+ @left_bond_strength{@q} = (NOMINAL) x scalar(@q);
+
+ @q = qw(lt gt le ge);
+ @left_bond_strength{@q} = ( 0.9 * NOMINAL + 0.1 * STRONG ) x scalar(@q);
+
+ @q = qw(and or err xor ne eq);
+ @right_bond_strength{@q} = (NOMINAL) x scalar(@q);
#---------------------------------------------------------------
# Bond Strength BEGIN Section 2.
my @words = split /-+/, $string; # allow multiple dashes
# we could look for and report possible errors here...
- next unless ( @words > 0 );
+ next if ( @words <= 0 );
# allow either '-continue' or *-continue' for arbitrary starting type
my $start = '*';
# correctly.
my ( $rtokens, $rtoken_type, $rtype_sequence, $input_line_no ) = @_;
my $jmax = @{$rtokens} - 1;
- return unless ( $jmax >= 0 );
+ return if ( $jmax < 0 );
foreach my $j ( 0 .. $jmax ) {
my $seqno = $rtype_sequence->[$j];
my $token = $rtokens->[$j];
DEVEL_MODE && Fault("did not get a comment\n");
next;
}
- next unless ( $Klast > $Kfirst ); # maybe HSC
+ next if ( $Klast <= $Kfirst ); # maybe HSC
my $token_sc = $rLL->[$Klast]->[_TOKEN_];
my $K_m = $Klast - 1;
my $type_m = $rLL->[$K_m]->[_TYPE_];
my ( $self, $KK, $rLL ) = @_;
# return the index K of the next nonblank, non-comment token
- return unless ( defined($KK) && $KK >= 0 );
+ return if ( !defined($KK) );
+ return if ( $KK < 0 );
# use the standard array unless given otherwise
- $rLL = $self->[_rLL_] unless ( defined($rLL) );
+ $rLL = $self->[_rLL_] if ( !defined($rLL) );
my $Num = @{$rLL};
my $Knnb = $KK + 1;
while ( $Knnb < $Num ) {
# return the index K of the next nonblank token, or
# return undef if none
- return unless ( defined($KK) && $KK >= 0 );
+ return if ( !defined($KK) );
+ return if ( $KK < 0 );
# The third arg allows this routine to be used on any array. This is
# useful in sub respace_tokens when we are copying tokens from an old $rLL
# to a new $rLL array. But usually the third arg will not be given and we
# will just use the $rLL array in $self.
- $rLL = $self->[_rLL_] unless ( defined($rLL) );
+ $rLL = $self->[_rLL_] if ( !defined($rLL) );
my $Num = @{$rLL};
my $Knnb = $KK + 1;
- return unless ( $Knnb < $Num );
+ return if ( $Knnb >= $Num );
return $Knnb if ( $rLL->[$Knnb]->[_TYPE_] ne 'b' );
- return unless ( ++$Knnb < $Num );
+ return if ( ++$Knnb >= $Num );
return $Knnb if ( $rLL->[$Knnb]->[_TYPE_] ne 'b' );
# Backup loop. Very unlikely to get here; it means we have neighboring
return;
}
my $Kpnb = $KK - 1;
- return unless ( $Kpnb >= 0 );
+ return if ( $Kpnb < 0 );
return $Kpnb if ( $rLL->[$Kpnb]->[_TYPE_] ne 'b' );
- return unless ( --$Kpnb >= 0 );
+ return if ( --$Kpnb < 0 );
return $Kpnb if ( $rLL->[$Kpnb]->[_TYPE_] ne 'b' );
# Backup loop. We should not get here unless some routine
# slipped repeated blanks into the token stream.
- return unless ( --$Kpnb >= 0 );
+ return if ( --$Kpnb < 0 );
while ( $Kpnb >= 0 ) {
if ( $rLL->[$Kpnb]->[_TYPE_] ne 'b' ) { return $Kpnb }
$Kpnb--;
# returns true if token at i is contained in a LIST
# returns false otherwise
my $seqno = $parent_seqno_to_go[$i];
- return unless ( $seqno && $seqno ne SEQ_ROOT );
+ return if ( !$seqno );
+ return if ( $seqno eq SEQ_ROOT );
if ( $self->[_ris_list_by_seqno_]->{$seqno} ) {
return 1;
}
# Fix for b1120: only for parens, not braces
elsif ( $token eq ')' ) {
my $Kn = $self->K_next_nonblank($Kfirst);
- next
- unless ( defined($Kn)
- && $Kn <= $Klast
- && $rLL->[$Kn]->[_TYPE_] eq '->' );
+ next if ( !defined($Kn) );
+ next if ( $Kn > $Klast );
+ next if ( $rLL->[$Kn]->[_TYPE_] ne '->' );
my $seqno = $rLL->[$Kfirst]->[_TYPE_SEQUENCE_];
- next unless ($seqno);
+ next if ( !$seqno );
# Note: in previous versions there was a fix here to avoid
# instability between conflicting -bom and -pvt or -pvtc flags.
if ( $K_outer_closing < $Num
&& $rLL->[$K_outer_closing]->[_TYPE_] eq 'b' );
- next unless ( $K_outer_closing < $Num );
+ next if ( $K_outer_closing >= $Num );
my $outer_seqno = $rLL->[$K_outer_closing]->[_TYPE_SEQUENCE_];
- next unless ($outer_seqno);
+ next if ( !$outer_seqno );
my $token_outer_closing = $rLL->[$K_outer_closing]->[_TOKEN_];
- next unless ( $is_closing_token{$token_outer_closing} );
+ next if ( !$is_closing_token{$token_outer_closing} );
# Simple filter: No commas or semicolons in the outer container
my $rtype_count = $self->[_rtype_count_by_seqno_]->{$outer_seqno};
# Now we have to check the opening tokens.
my $K_outer_opening = $K_opening_container->{$outer_seqno};
my $K_inner_opening = $K_opening_container->{$inner_seqno};
- next unless defined($K_outer_opening) && defined($K_inner_opening);
+ next if ( !defined($K_outer_opening) );
+ next if ( !defined($K_inner_opening) );
my $inner_blocktype = $rblock_type_of_seqno->{$inner_seqno};
my $outer_blocktype = $rblock_type_of_seqno->{$outer_seqno};
my $Kn = $KK + 1;
$Kn += 1
if ( $Kn < $Num && $rLL->[$Kn]->[_TYPE_] eq 'b' );
- next unless ( $Kn < $Num );
+ next if ( $Kn >= $Num );
my $next_token = $rLL->[$Kn]->[_TOKEN_];
my $next_type = $rLL->[$Kn]->[_TYPE_];
# We are only marking nested code blocks,
# so check for a previous block on the stack
- next unless ( @open_block_stack > 1 );
+ next if ( @open_block_stack <= 1 );
# Looks OK, mark this as a short nested block
$rshort_nested->{$type_sequence} = 1;
# continue up the tree marking parent containers
while (1) {
$parent_seqno = $self->[_rparent_of_seqno_]->{$parent_seqno};
- last
- unless ( defined($parent_seqno)
- && $parent_seqno ne SEQ_ROOT );
+ last if ( !defined($parent_seqno) );
+ last if ( $parent_seqno eq SEQ_ROOT );
$ris_excluded_lp_container->{$parent_seqno} = 1;
}
}
# 0 = never (delete if exist)
# 1 = stable (keep unchanged)
# 2 = always (insert if missing)
- return $rhash_of_desires
- unless $rOpts_kgb_size_min > 0
+ my $ok = $rOpts_kgb_size_min > 0
&& ( $rOpts_kgb_before != 1
|| $rOpts_kgb_after != 1
|| $rOpts_kgb_inside
|| $rOpts_kgb_delete );
+ return $rhash_of_desires if ( !$ok );
+
return;
} ## end sub kgb_initialize_options
# delete line $i if it is blank
my $rlines = $self->[_rlines_];
- return unless ( $i >= 0 && $i < @{$rlines} );
+ return if ( $i < 0 || $i >= @{$rlines} );
return if ( $rlines->[$i]->{_line_type} ne 'CODE' );
my $code_type = $rlines->[$i]->{_code_type};
if ( $code_type eq 'BL' ) { $rhash_of_desires->{$i} = 2; }
# Opening container must exist and be on this line
my $Ko = $self->[_K_opening_container_]->{$parent_seqno};
- return unless ( defined($Ko) && $Ko > $K_first && $Ko <= $K_last );
+ return if ( !defined($Ko) || $Ko <= $K_first || $Ko > $K_last );
# Verify that the closing container exists and is on a later line
my $Kc = $self->[_K_closing_container_]->{$parent_seqno};
- return unless ( defined($Kc) && $Kc > $K_last );
+ return if ( !defined($Kc) || $Kc <= $K_last );
# That's it
$K_closing = $Kc;
$self->store_token_to_go( $Ktoken_vars, $rtoken_vars );
$self->end_batch()
- unless (
- $no_internal_newlines
- || ( $rOpts_keep_interior_semicolons
- && $Ktoken_vars < $K_last )
- || ( $next_nonblank_token eq '}' )
+ if (
+ !$no_internal_newlines
+ && ( !$rOpts_keep_interior_semicolons
+ || $Ktoken_vars >= $K_last )
+ && ( $next_nonblank_token ne '}' )
);
}
{
if ( !$rbrace_follower ) {
$self->end_batch()
- unless ( $no_internal_newlines
- || $max_index_to_go < 0 );
+ if (!$no_internal_newlines
+ && $max_index_to_go >= 0 );
}
}
elsif ($rbrace_follower) {
}
else {
$self->end_batch()
- unless ( $no_internal_newlines
- || $max_index_to_go < 0 );
+ if (!$no_internal_newlines
+ && $max_index_to_go >= 0 );
}
$rbrace_follower = undef;
else {
$self->end_batch()
- unless ( $no_internal_newlines
- || $max_index_to_go < 0 );
+ if ( !$no_internal_newlines && $max_index_to_go >= 0 );
}
} ## end treatment of closing block token
my $seqno = $type_sequence_to_go[$i_start];
return unless ($seqno);
my $K_opening = $K_opening_container->{$seqno};
- return unless defined($K_opening);
+ return if ( !defined($K_opening) );
my $i_opening = $i_start + ( $K_opening - $K_start );
# give up if not on this line
- return unless ( $i_opening >= 0 );
+ return if ( $i_opening < 0 );
$i_start = $i_opening;
# go back one token before the opening paren
# - the index of the token after which the break was set, or
# - undef if no break was set
- return unless ( defined($i) && $i >= 0 );
+ return if ( !defined($i) );
+ return if ( $i < 0 );
# Back up at a blank so we have a token to examine.
# This was added to fix for cases like b932 involving an '=' break.
#
my ( $self, $ri_left, $ri_right ) = @_;
my $nmax = @{$ri_right} - 1;
- return unless ( $nmax >= 2 );
+ return if ( $nmax < 2 );
# scan the left ends of first two lines
my $tokbeg = EMPTY_STRING;
# do not recombine after a comma unless this will
# leave just 1 more line
- return unless ( $n + 1 >= $nmax );
+ return if ( $n + 1 < $nmax );
# do not recombine if there is a change in
# indentation depth
&& !$is_short_quote
&& !$is_ternary )
{
- return
- unless (
+ my $combine_ok = (
(
# unless we can reduce this to two lines
$nmax < $n + 2
- # or three lines, the last with a leading
- # semicolon
- || ( $nmax == $n + 2
+ # or three lines, the last with a leading
+ # semicolon
+ || ( $nmax == $n + 2
&& $types_to_go[$ibeg_nmax] eq ';' )
- # or the next line ends with a here doc
- || $type_iend_2 eq 'h'
+ # or the next line ends with a here doc
+ || $type_iend_2 eq 'h'
- # or the next line ends in an open paren or
- # brace and the break hasn't been forced
- # [dima.t]
- || ( !$forced_breakpoint_to_go[$iend_1]
+ # or the next line ends in an open paren or
+ # brace and the break hasn't been forced
+ # [dima.t]
+ || (!$forced_breakpoint_to_go[$iend_1]
&& $type_iend_2 eq '{' )
)
- # do not recombine if the two lines might align
- # well this is a very approximate test for this
- && (
+ # do not recombine if the two lines might align
+ # well this is a very approximate test for this
+ && (
# RT#127633 - the leading tokens are not
# operators
# or they are different
|| ( $ibeg_3 >= 0
&& $type_ibeg_2 ne $types_to_go[$ibeg_3] )
- )
- );
+ )
+ );
+
+ return if ( !$combine_ok );
if (
$summed_lengths_to_go[$ibeg_2];
my $iend_1_minus = max( $ibeg_1, iprev_to_go($iend_1) );
- return
- unless (
+ my $combine_ok = (
# ... unless there is just one and we can reduce
# this to two lines if we do. For example, this
# check for 2 lines, not in a long broken '.' chain
( $n == 2 && $n == $nmax && $type_iend_1 ne $type_iend_2 )
- # ... or this would strand a short quote , like this
- # "some long quote" .
- # "\n";
- || (
+ # ... or this would strand a short quote , like this
+ # "some long quote" .
+ # "\n";
+ || (
$types_to_go[$i_next_nonblank] eq 'Q'
&& $i_next_nonblank >= $iend_2 - 2
&& $token_lengths_to_go[$i_next_nonblank] <
# additional constraints to fix c167
&& ( $types_to_go[$iend_1_minus] ne 'Q'
|| $summed_len_2 < $summed_len_1 )
- )
- );
+ )
+ );
+ return if ( !$combine_ok );
}
else {
## ok - not a special type
&& $types_to_go[$ii] eq ':'
&& $levels_to_go[$ii] == $lev;
}
- return unless ( $local_count > 1 );
+ return if ( $local_count <= 1 );
}
$forced_breakpoint_to_go[$iend_1] = 0;
}
my $summed_len_2 = $summed_lengths_to_go[ $iend_2 + 1 ] -
$summed_lengths_to_go[$ibeg_2];
- return
- unless (
+ my $combine_ok = (
# ... unless there is just one and we can reduce
# this to two lines if we do. For example, this
( $n == 2 && $n == $nmax && $type_ibeg_1 ne $type_ibeg_2 )
- # ... or this would strand a short quote , like this
- # . "some long quote"
- # . "\n";
- || (
+ # ... or this would strand a short quote , like this
+ # . "some long quote"
+ # . "\n";
+ || (
$types_to_go[$i_next_nonblank] eq 'Q'
&& $i_next_nonblank >= $iend_2 - 1
&& $token_lengths_to_go[$i_next_nonblank] <
&& $n == $nmax
&& $this_line_is_semicolon_terminated )
)
- )
- );
+ )
+ );
+
+ return if ( !$combine_ok );
}
# handle leading keyword..
# handle leading "or"
if ( $tokens_to_go[$ibeg_2] eq 'or' ) {
- return
- unless (
+
+ my $combine_ok = (
$this_line_is_semicolon_terminated
- && (
+ && (
$type_ibeg_1 eq '}'
|| (
# then combine everything together
&& ( $iend_2 - $ibeg_2 <= 7 )
)
- )
- );
+ )
+ );
+
+ return if ( !$combine_ok );
#X: RT #81854
$forced_breakpoint_to_go[$iend_1] = 0
- unless ( $old_breakpoint_to_go[$iend_1] );
+ if ( !$old_breakpoint_to_go[$iend_1] );
}
# handle leading 'and' and 'xor'
return unless %break_before_container_types;
my $nmax = @{$ri_right} - 1;
- return unless ( $nmax >= 0 );
+ return if ( $nmax < 0 );
my $rLL = $self->[_rLL_];
for my $n ( 0 .. $nmax ) {
my $il = $ri_left->[$n];
my $ir = $ri_right->[$n];
- next unless ( $ir > $il );
+ next if ( $ir <= $il );
my $Kl = $K_to_go[$il];
my $Kr = $K_to_go[$ir];
my $Kend = $Kr;
}
my $token = $rLL->[$Kend]->[_TOKEN_];
- next unless ( $is_opening_token{$token} );
- next unless ( $Kl < $Kend - 1 );
+ next if ( !$is_opening_token{$token} );
+ next if ( $Kl >= $Kend - 1 );
my $seqno = $rLL->[$Kend]->[_TYPE_SEQUENCE_];
- next unless ( defined($seqno) );
+ next if ( !defined($seqno) );
# Use the flag which was previously set
next unless ( $rbreak_before_container_by_seqno->{$seqno} );
my $max_line = @{$ri_first} - 1;
# must be multiple lines
- return unless $max_line > $line_open;
+ return if ( $max_line <= $line_open );
my $lev_start = $levels_to_go[$i_start];
my $ci_start_plus = 1 + $ci_levels_to_go[$i_start];
# break open container...
my $i_opening = $opening_structure_index_stack[$dd];
if ( defined($i_opening) && $i_opening >= 0 ) {
- $self->set_forced_breakpoint($i_opening)
- unless (
+
+ my $no_break = (
is_unbreakable_container($dd)
- # Avoid a break which would place an isolated ' or "
- # on a line
- || ( $type eq 'Q'
+ # Avoid a break which would place an isolated ' or "
+ # on a line
+ || ( $type eq 'Q'
&& $i_opening >= $max_index_to_go - 2
&& ( $token eq "'" || $token eq '"' ) )
- );
+ );
+
+ $self->set_forced_breakpoint($i_opening)
+ if ( !$no_break );
}
} ## end for ( my $dd = $current_depth...)
}
$lp_position_predictor -= $deleted_spaces;
$spaces_needed -= $deleted_spaces;
- last unless ( $spaces_needed > 0 );
+ last if ( $spaces_needed <= 0 );
}
return;
} ## end sub check_for_long_gnu_style_lines
$ok_comma = $tok_next_next eq $tok_next;
}
- next
- unless (
- $is_assignment{ $types_to_go[$iendm] }
- || $ok_comma
- || ( $nesting_depth_to_go[$ibegm] <
+ my $ok_pad = (
+ $is_assignment{ $types_to_go[$iendm] }
+ || $ok_comma
+ || ( $nesting_depth_to_go[$ibegm] <
$nesting_depth_to_go[$ibeg] )
- || ( $types_to_go[$iendm] eq 'k'
+ || ( $types_to_go[$iendm] eq 'k'
&& $tokens_to_go[$iendm] eq 'return' )
- );
+ );
+ next if ( !$ok_pad );
# we will add padding before the first token
$ipad = $ibeg;
# find any unclosed container
next
- unless ( $type_sequence_to_go[$i]
- && defined( $mate_index_to_go[$i] )
- && $mate_index_to_go[$i] > $iend );
+ if ( !$type_sequence_to_go[$i]
+ || !defined( $mate_index_to_go[$i] )
+ || $mate_index_to_go[$i] <= $iend );
# find next nonblank token to pad
$ipad = $inext_to_go[$i];
my ( $self, $ri_first, $ri_last ) = @_;
# Must be 2 or more lines
- return unless ( @{$ri_first} > 1 );
+ return if ( @{$ri_first} <= 1 );
# Pull indentation object from start of second line
my $ibeg_1 = $ri_first->[1];
my $line_count = $self->group_line_count();
my $min_lines = $rvertical_tightness_flags->{_vt_min_lines};
my $max_lines = $rvertical_tightness_flags->{_vt_max_lines};
- $min_lines = 0 unless ($min_lines);
- $max_lines = 1 unless ($max_lines);
+ $min_lines = 0 if ( !$min_lines );
+ $max_lines = 1 if ( !$max_lines );
if ( ( $line_count >= $min_lines )
&& ( $line_count <= $max_lines ) )
{
my $rfields = $new_line->{'rfields'};
# the first field must be empty
- return 0 unless $rfields->[0] =~ /^\s*$/;
+ return 0 if ( $rfields->[0] !~ /^\s*$/ );
# the current line must have fewer fields
my $maximum_field_index = $old_line->{'jmax'};
return 0
- unless $maximum_field_index > $jmax;
+ if ( $maximum_field_index <= $jmax );
# looks ok..
my $rpatterns = $new_line->{'rpatterns'};
$group_level )
= @_;
- return unless ($old_line);
+ return if ( !$old_line );
use constant EXPLAIN_TERNARY => 0;
if (%valign_control_hash) {
my $align_ok = $valign_control_hash{'?'};
$align_ok = $valign_control_default unless defined($align_ok);
- return unless ($align_ok);
+ return if ( !$align_ok );
}
my $jmax = @{$rfields} - 1;
$depth_question = $lev;
# depth must be correct
- next unless ( $depth_question eq $group_level );
+ next if ( $depth_question ne $group_level );
$jquestion = $j;
if ( $rfields_old->[ $j + 1 ] =~ /^(\?\s*)/ ) {
last;
}
}
- return unless ( defined($jquestion) ); # shouldn't happen
+ return if ( !defined($jquestion) ); # shouldn't happen
# Now splice the tokens and patterns of the previous line
# into the else line to insure a match. Add empty fields
( $len_colon, $pad_length + $field_length1 - $len_colon );
# change the leading pattern from : to ?
- return unless ( $patterns[0] =~ s/^\:/?/ );
+ return if ( $patterns[0] !~ s/^\:/?/ );
# install leading tokens and patterns of existing line
unshift( @tokens, @{$rtokens_old}[ 0 .. $jquestion ] );
# : ( $mname = $name . '->' );
else {
- return unless ( $jmax > 0 && $tokens[0] ne '#' ); # shouldn't happen
+ return if ( $jmax <= 0 || $tokens[0] eq '#' ); # shouldn't happen
# prepend a leading ? onto the second pattern
$patterns[1] = "?b" . $patterns[1];
#
my ( $old_line, $rfields, $rtokens, $rpatterns, $rfield_lengths ) = @_;
- return unless ($old_line);
+ return if ( !$old_line );
my $jmax = @{$rfields} - 1;
- return unless ( $jmax > 0 );
+ return if ( $jmax <= 0 );
if (%valign_control_hash) {
my $align_ok = $valign_control_hash{'{'};
$align_ok = $valign_control_default unless defined($align_ok);
- return unless ($align_ok);
+ return if ( !$align_ok );
}
# check for balanced else block following if/elsif/unless
my $rfields_old = $old_line->{'rfields'};
# TBD: add handling for 'case'
- return unless ( $rfields_old->[0] =~ /^(if|elsif|unless)\s*$/ );
+ return if ( $rfields_old->[0] !~ /^(?:if|elsif|unless)\s*$/ );
# look for the opening brace after the else, and extract the depth
my $tok_brace = $rtokens->[0];
my $jparen = 0;
my $tok_paren = '(' . $depth_brace;
my $tok_test = $rtokens_old->[$jparen];
- return unless ( $tok_test eq $tok_paren ); # shouldn't happen
+ return if ( $tok_test ne $tok_paren ); # shouldn't happen
# Now find the opening block brace
my ($jbrace);
last;
}
}
- return unless ( defined($jbrace) ); # shouldn't happen
+ return if ( !defined($jbrace) ); # shouldn't happen
# Now splice the tokens and patterns of the previous line
# into the else line to insure a match. Add empty fields
my ($self) = @_;
my $rgroup_lines = $self->[_rgroup_lines_];
- return unless ( @{$rgroup_lines} );
+ return if ( !@{$rgroup_lines} );
my $group_level = $self->[_group_level_];
my $group_maximum_line_length = $self->[_group_maximum_line_length_];
my $leading_space_count = $self->[_comment_leading_space_count_];
# Note: only the sign of the jump is needed
my $rgroup_lines = $self->[_rgroup_lines_];
- return unless ( @{$rgroup_lines} );
+ return if ( !@{$rgroup_lines} );
my $group_type = $self->[_group_type_];
my $group_level = $self->[_group_level_];
sub get_rgroup_jrange {
- return unless @{$rgroups};
- return unless ( $group_line_count > 0 );
+ return if ( !@{$rgroups} );
+ return if ( $group_line_count <= 0 );
my ( $jbeg, $jend ) = @{ $rgroups->[-1] };
return ( $jbeg, $jend );
} ## end sub get_rgroup_jrange
sub end_rgroup {
my ($imax_align) = @_;
- return unless @{$rgroups};
- return unless ( $group_line_count > 0 );
+ return if ( !@{$rgroups} );
+ return if ( $group_line_count <= 0 );
my ( $jbeg, $jend ) = @{ pop @{$rgroups} };
push @{$rgroups}, [ $jbeg, $jend, $imax_align ];
# emergency reset to prevent sweep_left_to_right from trying to match a
# failed terminal else match
- return unless @{$rgroups} > 1;
+ return if ( @{$rgroups} <= 1 );
$rgroups->[-2]->[2] = -1;
return;
} ## end sub block_penultimate_match
my $prev_comment =
$rall_lines->[ $jline - 1 ]->{'rfields'}->[-1];
my $side_comment = $new_line->{'rfields'}->[-1];
- end_rgroup(-1) unless ( $side_comment && $prev_comment );
+ end_rgroup(-1) if ( !$side_comment || !$prev_comment );
}
else {
##ok: continue
# Safety check - shouldn't happen
return 0
- unless $imax_min < @{$rfield_lengths} && $imax_min < @{$rfield_lengths_m};
+ if ( $imax_min >= @{$rfield_lengths}
+ || $imax_min >= @{$rfield_lengths_m} );
my $lensum_m = 0;
my $lensum = 0;
# nothing to do if just one group
my $ng_max = @{$rgroups} - 1;
- return unless ( $ng_max > 0 );
+ return if ( $ng_max <= 0 );
#---------------------------------------------------------------------
# Step 1: Loop over groups to find all common leading alignment tokens
$line = $rlines->[$jbeg];
$rtokens = $line->{'rtokens'};
$imax = $line->{'jmax'} - 2;
- $istop = -1 unless ( defined($istop) );
+ $istop = -1 if ( !defined($istop) );
$istop = $imax if ( $istop > $imax );
# Initialize on first group
{
# We will just align assignments and simple lists
- next unless ( $imax_min >= 0 );
+ next if ( $imax_min < 0 );
next
- unless ( $rtokens->[0] =~ /^=\d/
- || $list_type );
+ if ( $rtokens->[0] !~ /^=\d/
+ && !$list_type );
# In this case we will limit padding to a short distance. This
# is a compromise to keep some vertical alignment but prevent large
# gaps, which do not look good for just two lines.
my $pad_max =
two_line_pad( $rlines->[$jbeg], $rlines->[$jbeg_m], $imax_min );
- next unless ($pad_max);
+ next if ( !$pad_max );
my $ng_m = $ng - 1;
$max_move{"$ng_m"} = $pad_max;
$max_move{"$ng"} = $pad_max;
my ( $rlines, $rgroups, $rmax_move, $ngb, $nge, $itok, $col_want,
$raw_tok )
= @_;
- return unless ( defined($ngb) && $nge > $ngb );
+ return if ( !defined($ngb) || $nge <= $ngb );
foreach my $ng ( $ngb .. $nge ) {
my ( $jbeg, $jend ) = @{ $rgroups->[$ng] };
my ( $itok, $ng_beg, $ng_end, $raw_tok, $lev ) = @{$task};
# Nothing to do for a single group
- next unless ( $ng_end > $ng_beg );
+ next if ( $ng_end <= $ng_beg );
my $ng_first; # index of the first group of a continuous sequence
my $col_want; # the common alignment column of a sequence of groups
# remove an unused alignment token(s) to improve alignment chances
- return unless ( defined($line_obj) && defined($ridel) && @{$ridel} );
+ return if ( !defined($line_obj) || !defined($ridel) || !@{$ridel} );
my $jmax_old = $line_obj->{'jmax'};
my $rfields_old = $line_obj->{'rfields'};
# nothing to do if all lines were hanging side comments
my $jmax = @{$rnew_lines} - 1;
- return ( $max_lev_diff, $saw_side_comment ) unless ( $jmax >= 0 );
+ return ( $max_lev_diff, $saw_side_comment ) if ( $jmax < 0 );
#----------------------------------------------------
# Create a hash of alignment token info for each line
foreach my $item ( @{$rsubgroups} ) {
my ( $jbeg, $jend ) = @{$item};
my $nlines = $jend - $jbeg + 1;
- next unless ( $nlines > 1 );
+ next if ( $nlines <= 1 );
# loop over lines in a subgroup
foreach my $jj ( $jbeg .. $jend ) {
sub prune_alignment_tree {
my ($rlines) = @_;
my $jmax = @{$rlines} - 1;
- return unless $jmax > 0;
+ return if ( $jmax <= 0 );
# Vertical alignment in perltidy is done as an iterative process. The
# starting point is to mark all possible alignment tokens ('=', ',', '=>',
my $def_current = defined( $token_patterns_current[$depth] );
my $def_next = defined( $token_patterns_next[$depth] );
- last unless ( $def_current || $def_next );
+ last if ( !$def_current && !$def_next );
if ( !$def_current
|| !$def_next
|| $token_patterns_current[$depth] ne
}
foreach my $depth ( 0 .. $MAX_DEPTH ) {
- last unless (@todo_list);
+ last if ( !@todo_list );
my @todo_next;
foreach my $np (@todo_list) {
my ( $jbeg_p, $jend_p, $np_p, $lev_p, $pat_p, $nc_beg_p, $nc_end_p,
# lines of a list are back together again.
#----------------------------------------------------------
- return 0 unless ( @{$rlines} && @{$rgroups} );
+ return 0 if ( !@{$rlines} || !@{$rgroups} );
my $object = $rlines->[0]->{'indentation'};
- return 0 unless ( ref($object) );
+ return 0 if ( !ref($object) );
my $extra_leading_spaces = 0;
my $extra_indentation_spaces_wanted = get_recoverable_spaces($object);
- return ($extra_leading_spaces) unless ($extra_indentation_spaces_wanted);
+ return ($extra_leading_spaces) if ( !$extra_indentation_spaces_wanted );
my $min_spaces = $extra_indentation_spaces_wanted;
if ( $min_spaces > 0 ) { $min_spaces = 0 }
# '$num5' is the number of comments in the first 5 lines after the first
# comment. It is needed to keep a compact group of side comments from
# being influenced by a more distant side comment.
- $num5 = 1 unless ($num5);
+ $num5 = 1 if ( !$num5 );
# Some values:
my $line = $rlines->[$jj];
my $jmax = $line->{'jmax'};
my $sc_len = $line->{'rfield_lengths'}->[$jmax];
- next unless ($sc_len);
+ next if ( !$sc_len );
$num5++;
}
# First delete the unwanted tokens
my $jmax_old = $line_0->{'jmax'};
my @idel = ( $imax_align + 1 .. $jmax_old - 2 );
- return unless (@idel);
+ return if ( !@idel );
# Get old alignments before any changes are made
my @old_alignments = @{ $line_0->{'ralignments'} };