my $input_line_number = $line_of_tokens->{_line_number};
my $line_type = $line_of_tokens->{_line_type};
- my ( $j, $num );
-
my $token_str = "$input_line_number: ";
my $reconstructed_original = "$input_line_number: ";
$pattern .= $rtoken_type->[$j];
}
$reconstructed_original .= $rtokens->[$j];
- $num = length( $rtokens->[$j] );
+ my $num = length( $rtokens->[$j] );
my $type_str = $rtoken_type->[$j];
# be sure there are no blank tokens (shouldn't happen)
sub new {
- my ( $class, @args ) = @_;
+ my ( $class, @arglist ) = @_;
+ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
# we are given an object with a write_line() method to take lines
my %defaults = (
is_encoded_data => EMPTY_STRING,
fh_tee => undef,
);
- my %args = ( %defaults, @args );
+ my %args = ( %defaults, @arglist );
my $length_function = $args{length_function};
my $is_encoded_data = $args{is_encoded_data};
# tightness = 1 means pad inside if "complex"
# tightness = 2 means never pad inside with space
- my $tightness;
+ my $tightness_here;
if ( $last_block_type && $last_token eq '{' ) {
- $tightness = $rOpts_block_brace_tightness;
+ $tightness_here = $rOpts_block_brace_tightness;
}
- else { $tightness = $tightness{$last_token} }
+ else { $tightness_here = $tightness{$last_token} }
#=============================================================
# Patch for test problem <<snippets/fabrice_bug.in>>
# to bt=1. Note that here we must set tightness=1 and not 2 so
# that the closing space is also avoided
# (via the $j_tight_closing_paren flag in coding)
- if ( $type eq 'w' && $token =~ /^\^/ ) { $tightness = 1 }
+ if ( $type eq 'w' && $token =~ /^\^/ ) { $tightness_here = 1 }
#=============================================================
- if ( $tightness <= 0 ) {
+ if ( $tightness_here <= 0 ) {
$ws = WS_YES;
}
- elsif ( $tightness > 1 ) {
+ elsif ( $tightness_here > 1 ) {
$ws = WS_NO;
}
else {
&& $j < $jmax )
{
my $level = $rLL->[$j]->[_LEVEL_];
- my $jp = $j;
## NOTE: we might use the KNEXT variable to avoid this loop
## but profiling shows that little would be saved
- foreach my $inc ( 1 .. 9 ) {
- $jp++;
+ foreach my $jp ( $j + 1 .. $j + 9 ) {
last if ( $jp > $jmax );
last if ( $rLL->[$jp]->[_LEVEL_] != $level ); # b1236
next unless ( $rLL->[$jp]->[_TOKEN_] eq '(' );
if ( !defined($ws) ) {
- my $tightness;
+ my $tightness_here;
my $block_type = $rblock_type_of_seqno->{$seqno}
|| $block_type_for_tightness{$seqno};
if ( $block_type && $token eq '}' ) {
- $tightness = $rOpts_block_brace_tightness;
+ $tightness_here = $rOpts_block_brace_tightness;
}
- else { $tightness = $tightness{$token} }
+ else { $tightness_here = $tightness{$token} }
- $ws = ( $tightness > 1 ) ? WS_NO : WS_YES;
+ $ws = ( $tightness_here > 1 ) ? WS_NO : WS_YES;
}
}
{
$ws =
$rOpts_space_function_paren
- ? $self->ws_space_function_paren( $j, $rtokh_last_last )
+ ? $self->ws_space_function_paren($rtokh_last_last)
: WS_NO;
set_container_ws_by_keyword( $last_token, $seqno );
# treatment for its inside space. If so we set a hash value using the
# sequence number as key.
if ( $word && $sequence_number ) {
- my $tightness = $keyword_paren_inner_tightness{$word};
- if ( defined($tightness) && $tightness != 1 ) {
- my $ws_flag = $tightness == 0 ? WS_YES : WS_NO;
+ my $tightness_here = $keyword_paren_inner_tightness{$word};
+ if ( defined($tightness_here) && $tightness_here != 1 ) {
+ my $ws_flag = $tightness_here == 0 ? WS_YES : WS_NO;
$opening_container_inside_ws{$sequence_number} = $ws_flag;
$closing_container_inside_ws{$sequence_number} = $ws_flag;
}
sub ws_space_function_paren {
- my ( $self, $j, $rtokh_last_last ) = @_;
+ my ( $self, $rtokh_last_last ) = @_;
# Called if --space-function-paren is set to see if it might cause
# a problem. The manual warns the user about potential problems with
if (DEBUG_SET_CI) {
my @output_lines;
- foreach my $KK ( 0 .. $Klimit ) {
- my $line = $debug_lines[$KK];
+ foreach my $Kd ( 0 .. $Klimit ) {
+ my $line = $debug_lines[$Kd];
if ($line) {
- my $Kp = $self->K_previous_code($KK);
- my $Kn = $self->K_next_code($KK);
+ my $Kp = $self->K_previous_code($Kd);
+ my $Kn = $self->K_next_code($Kd);
if ( DEBUG_SET_CI > 1
|| $Kp && $saw_ci_diff{$Kp}
- || $saw_ci_diff{$KK}
+ || $saw_ci_diff{$Kd}
|| $Kn && $saw_ci_diff{$Kn} )
{
push @output_lines, $line;
# always pop the stack if this token is on the stack
if ($is_on_stack) {
my $stack_item = pop @{$rblock_stack};
- my $popped_seqno = $stack_item->{seqno};
my $rpopped_vars = $stack_item->{rvars};
# if we popped a block token
# if not on the stack: error if this is a block
elsif ($block_type) {
- my $lno = $ix_line + 1;
- my $popped_seqno = $rblock_stack->[-1]->{seqno};
+ my $lno = $ix_line + 1;
+ my $stack_seqno = $rblock_stack->[-1]->{seqno};
DEVEL_MODE
&& Fault(
-"stack error: seqno=$seqno ne $popped_seqno near line $lno\n"
+"stack error: seqno=$seqno ne $stack_seqno near line $lno\n"
);
# give up - file may be unbalanced
return if ( $parent_seqno_to_go[$i2] ne $parent_seqno_1 );
if ( $i2 < $i1 ) { ( $i1, $i2 ) = ( $i2, $i1 ) }
- my $K1 = $K_to_go[$i1];
- my $K2 = $K_to_go[$i2];
- my $rLL = $self->[_rLL_];
+ my $K1 = $K_to_go[$i1];
+ my $K2 = $K_to_go[$i2];
my $depth_1 = $nesting_depth_to_go[$i1];
return if ( $depth_1 < 0 );
for my $n ( 1 .. 2 ) {
my $il_n = $ri_left->[$n];
my $ir_n = $ri_right->[$n];
- foreach my $i ( $il_n + 1 .. $ir_n ) {
- my $type = $types_to_go[$i];
+ foreach my $ii ( $il_n + 1 .. $ir_n ) {
+ my $type = $types_to_go[$ii];
return
if ( $is_assignment{$type}
- && $nesting_depth_to_go[$i] eq $depth_beg );
+ && $nesting_depth_to_go[$ii] eq $depth_beg );
}
}
&& $ibeg_2 == $iend_2
&& token_sequence_length( $ibeg_2, $ibeg_2 ) <
$rOpts_short_concatenation_item_length );
- my $is_ternary = (
+ my $is_ternary_joint = (
$type_ibeg_1 eq '?' && ( $ibeg_3 >= 0
&& $types_to_go[$ibeg_3] eq ':' )
);
# will put ?/: at start of adjacent lines
if ( $ibeg_1 != $iend_1
&& !$is_short_quote
- && !$is_ternary )
+ && !$is_ternary_joint )
{
my $combine_ok = (
(
@item_count_stack,
@last_comma_index,
@last_dot_index,
- @last_nonblank_type,
+ @last_nonblank_type_stack,
@old_breakpoint_count_stack,
@opening_structure_index_stack,
@rfor_semicolon_list,
if ( $rOpts_comma_arrow_breakpoints == 3 && $seqno ) {
$override_cab3[$depth_t] = $self->[_roverride_cab3_]->{$seqno};
}
- $breakpoint_stack[$depth_t] = $starting_breakpoint_count;
- $container_type[$depth_t] = EMPTY_STRING;
- $identifier_count_stack[$depth_t] = 0;
- $index_before_arrow[$depth_t] = -1;
- $interrupted_list[$depth_t] = 1;
- $item_count_stack[$depth_t] = 0;
- $last_nonblank_type[$depth_t] = EMPTY_STRING;
+ $breakpoint_stack[$depth_t] = $starting_breakpoint_count;
+ $container_type[$depth_t] = EMPTY_STRING;
+ $identifier_count_stack[$depth_t] = 0;
+ $index_before_arrow[$depth_t] = -1;
+ $interrupted_list[$depth_t] = 1;
+ $item_count_stack[$depth_t] = 0;
+ $last_nonblank_type_stack[$depth_t] = EMPTY_STRING;
$opening_structure_index_stack[$depth_t] = -1;
$breakpoint_undo_stack[$depth_t] = undef;
# barewords, identifiers (that is, anything that doesn't
# look like a function call)
# c250: added new sub identifier type 'S'
- my $must_break_open = $last_nonblank_type[$dd] !~ /^[kwiUS]$/;
+ my $must_break_open =
+ $last_nonblank_type_stack[$dd] !~ /^[kwiUS]$/;
$self->table_maker(
{
# Look for breaks in this order:
# 0 1 2 3
# or and || &&
- foreach my $i ( 0 .. 3 ) {
- if ( $rand_or_list[$dd][$i] ) {
- foreach ( @{ $rand_or_list[$dd][$i] } ) {
+ foreach my $ii ( 0 .. 3 ) {
+ if ( $rand_or_list[$dd][$ii] ) {
+ foreach ( @{ $rand_or_list[$dd][$ii] } ) {
$self->set_forced_breakpoint($_);
}
$index_before_arrow[$depth] = -1;
$interrupted_list[$depth] = 0;
$item_count_stack[$depth] = 0;
- $last_nonblank_type[$depth] = $last_nonblank_type;
+ $last_nonblank_type_stack[$depth] = $last_nonblank_type;
$opening_structure_index_stack[$depth] = $i;
$breakpoint_undo_stack[$depth] = $forced_breakpoint_undo_count;
my $last_length = undef;
my $total_variation_1 = 0;
my $total_variation_2 = 0;
- my @total_variation_2 = ( 0, 0 );
+
+ my @total_variation_2_sums = ( 0, 0 );
foreach my $j ( 0 .. $item_count - 1 ) {
my $ll = $last_length_2[$is_odd];
if ( defined($ll) ) {
my $dl = abs( $length - $ll );
- $total_variation_2[$is_odd] += $dl;
+ $total_variation_2_sums[$is_odd] += $dl;
}
else {
$first_length_2[$is_odd] = $length;
}
$last_length_2[$is_odd] = $length;
}
- $total_variation_2 = $total_variation_2[0] + $total_variation_2[1];
+ $total_variation_2 =
+ $total_variation_2_sums[0] + $total_variation_2_sums[1];
my $factor = ( $item_count > 10 ) ? 1 : ( $item_count > 5 ) ? 0.75 : 0;
if ( $total_variation_2 >= $factor * $total_variation_1 ) {
# These routines are called once per batch when the --closing-side-comments flag
# has been set.
- my %block_leading_text;
+ my $rblock_leading_text;
my %block_opening_line_number;
my $csc_new_statement_ok;
my $csc_last_label;
my $leading_block_text_line_number;
sub initialize_csc_vars {
- %block_leading_text = ();
+ $rblock_leading_text = {};
%block_opening_line_number = ();
$csc_new_statement_ok = 1;
$csc_last_label = EMPTY_STRING;
if ( $token eq '}' ) {
# restore any leading text saved when we entered this block
- if ( defined( $block_leading_text{$type_sequence} ) ) {
+ if ( defined( $rblock_leading_text->{$type_sequence} ) ) {
( $block_leading_text, $rblock_leading_if_elsif_text )
- = @{ $block_leading_text{$type_sequence} };
+ = @{ $rblock_leading_text->{$type_sequence} };
$i_block_leading_text = $i;
- delete $block_leading_text{$type_sequence};
+ delete $rblock_leading_text->{$type_sequence};
$rleading_block_if_elsif_text =
$rblock_leading_if_elsif_text;
}
if ( $accumulating_text_for_block eq $block_type ) {
# save any leading text before we enter this block
- $block_leading_text{$type_sequence} = [
+ $rblock_leading_text->{$type_sequence} = [
$leading_block_text,
$rleading_block_if_elsif_text
];
use warnings;
our $VERSION = '20230912.06';
+use Carp;
use English qw( -no_match_vars );
use File::Basename;
sub new {
- my ( $class, @args ) = @_;
+ my ( $class, @arglist ) = @_;
+ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
my %defaults = (
input_file => undef,
html_toc_extension => undef,
html_src_extension => undef,
);
- my %args = ( %defaults, @args );
+ my %args = ( %defaults, @arglist );
my $input_file = $args{input_file};
my $html_file = $args{html_file};
use strict;
use warnings;
our $VERSION = '20230912.06';
+use Carp;
use English qw( -no_match_vars );
use constant DEVEL_MODE => 0;
sub new {
- my ( $class, @args ) = @_;
+ my ( $class, @arglist ) = @_;
+ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
my %defaults = (
rOpts => undef,
is_encoded_data => undef,
);
- my %args = ( %defaults, @args );
+ my %args = ( %defaults, @arglist );
my $rOpts = $args{rOpts};
my $log_file = $args{log_file};
sub new {
- my ( $class, @args ) = @_;
+ my ( $class, @arglist ) = @_;
+ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
my %defaults = (
source_object => undef,
starting_line_number => 1,
rOpts => {},
);
- my %args = ( %defaults, @args );
+ my %args = ( %defaults, @arglist );
# we are given an object with a get_line() method to supply source lines
my $source_object = $args{source_object};
#---------------------------------------------------------
# Arrays to hold token values for this line:
- my ( @levels, @block_type, @type_sequence, @token_type, @tokens );
+ my (
+ @output_levels, @output_block_type, @output_type_sequence,
+ @output_token_type, @output_tokens
+ );
$line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
# Loop over tokens
#-----------------
# $i is the index of the pretoken which starts this full token
- foreach my $i ( @{$routput_token_list} ) {
+ foreach my $ii ( @{$routput_token_list} ) {
- my $type_i = $routput_token_type->[$i];
+ my $type_i = $routput_token_type->[$ii];
#----------------------------------------
# Section 1. Handle a non-sequenced token
#----------------------------------------
- if ( !$routput_type_sequence->[$i] ) {
+ if ( !$routput_type_sequence->[$ii] ) {
#-------------------------------
# Section 1.1. types ';' and 't'
# - output __END__, __DATA__, and format as type 'k' instead
# of ';' to make html colors correct, etc.
if ( $is_semicolon_or_t{$type_i} ) {
- my $tok_i = $rtokens->[$i];
+ my $tok_i = $rtokens->[$ii];
if ( $is_END_DATA_format_sub{$tok_i} ) {
$type_i = 'k';
}
#----------------------------------------------------
# Section 1.3. Store values for a non-sequenced token
#----------------------------------------------------
- push( @levels, $level_in_tokenizer );
- push( @block_type, EMPTY_STRING );
- push( @type_sequence, EMPTY_STRING );
- push( @token_type, $type_i );
+ push( @output_levels, $level_in_tokenizer );
+ push( @output_block_type, EMPTY_STRING );
+ push( @output_type_sequence, EMPTY_STRING );
+ push( @output_token_type, $type_i );
}
my $level_i = $level_in_tokenizer;
# $tok_i is the PRE-token. It only equals the token for symbols
- my $tok_i = $rtokens->[$i];
+ my $tok_i = $rtokens->[$ii];
- # $routput_indent_flag->[$i] indicates that we need a change
+ # $routput_indent_flag->[$ii] indicates that we need a change
# in level at a nested ternary, as follows
# 1 => at a nested ternary ?
# -1 => at a nested ternary :
if ( $type_i eq '?' ) {
- if ( $routput_indent_flag->[$i] > 0 ) {
+ if ( $routput_indent_flag->[$ii] > 0 ) {
$level_in_tokenizer++;
# break BEFORE '?' in a nested ternary
$level_in_tokenizer++;
- if ( $routput_block_type->[$i] ) {
+ if ( $routput_block_type->[$ii] ) {
$nesting_block_flag = 1;
$nesting_block_string .= '1';
}
|| $type_i eq 'R'
# only the second and higher ? : have levels
- || $type_i eq ':' && $routput_indent_flag->[$i] < 0
+ || $type_i eq ':' && $routput_indent_flag->[$ii] < 0
)
{
# The starting nesting block string, which is used in any .LOG
# output, should include the first token of the line
- if ( !@levels ) {
+ if ( !@output_levels ) {
$nesting_block_string_0 = $nesting_block_string;
}
# Store values for a sequenced token
- push( @levels, $level_i );
- push( @block_type, $routput_block_type->[$i] );
- push( @type_sequence, $routput_type_sequence->[$i] );
- push( @token_type, $type_i );
+ push( @output_levels, $level_i );
+ push( @output_block_type, $routput_block_type->[$ii] );
+ push( @output_type_sequence, $routput_type_sequence->[$ii] );
+ push( @output_token_type, $type_i );
}
} ## End loop to over tokens
$line_of_tokens->{_nesting_blocks_0} = $nesting_block_string_0;
# Form and store the tokens
- if (@levels) {
+ if (@output_levels) {
my $im = shift @{$routput_token_list};
my $offset = $rtoken_map->[$im];
- foreach my $i ( @{$routput_token_list} ) {
- my $numc = $rtoken_map->[$i] - $offset;
- push( @tokens, substr( $input_line, $offset, $numc ) );
+ foreach my $ii ( @{$routput_token_list} ) {
+ my $numc = $rtoken_map->[$ii] - $offset;
+ push( @output_tokens, substr( $input_line, $offset, $numc ) );
$offset += $numc;
# programming note: it seems most efficient to 'next' out of
# Form and store the final token of this line
my $numc = length($input_line) - $offset;
- push( @tokens, substr( $input_line, $offset, $numc ) );
+ push( @output_tokens, substr( $input_line, $offset, $numc ) );
if (DEVEL_MODE) {
if ( $numc <= 0 ) {
}
# Make sure we didn't gain or lose any characters
- my $test_line = join EMPTY_STRING, @tokens;
+ my $test_line = join EMPTY_STRING, @output_tokens;
if ( $test_line ne $input_line ) {
my $len_input = length($input_line);
my $len_test = length($test_line);
}
# Wrap up this line of tokens for shipping to the Formatter
- $line_of_tokens->{_rtoken_type} = \@token_type;
- $line_of_tokens->{_rtokens} = \@tokens;
- $line_of_tokens->{_rblock_type} = \@block_type;
- $line_of_tokens->{_rtype_sequence} = \@type_sequence;
- $line_of_tokens->{_rlevels} = \@levels;
+ $line_of_tokens->{_rtoken_type} = \@output_token_type;
+ $line_of_tokens->{_rtokens} = \@output_tokens;
+ $line_of_tokens->{_rblock_type} = \@output_block_type;
+ $line_of_tokens->{_rtype_sequence} = \@output_type_sequence;
+ $line_of_tokens->{_rlevels} = \@output_levels;
return;
} ## end sub tokenizer_wrapup_line
sub new {
- my ( $class, @args ) = @_;
+ my ( $class, @arglist ) = @_;
+ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
my %defaults = (
rOpts => undef,
logger_object => undef,
diagnostics_object => undef,
);
- my %args = ( %defaults, @args );
+ my %args = ( %defaults, @arglist );
# Initialize other caches and buffers
initialize_step_B_cache();
# so that lines can just look back one line for their pair info.
if ( @{$rlines} > @{$rnew_lines} ) {
my $last_pair_info = -1;
- foreach my $line ( @{$rlines} ) {
- if ( $line->{'is_hanging_side_comment'} ) {
- $line->{'imax_pair'} = $last_pair_info;
+ foreach my $line_t ( @{$rlines} ) {
+ if ( $line_t->{'is_hanging_side_comment'} ) {
+ $line_t->{'imax_pair'} = $last_pair_info;
}
else {
- $last_pair_info = $line->{'imax_pair'};
+ $last_pair_info = $line_t->{'imax_pair'};
}
}
}
# Otherwise see if anything changed and update the tree if so
else {
- foreach my $depth ( 0 .. $MAX_DEPTH ) {
+ foreach my $dep ( 0 .. $MAX_DEPTH ) {
- my $def_current = defined( $token_patterns_current[$depth] );
- my $def_next = defined( $token_patterns_next[$depth] );
+ my $def_current = defined( $token_patterns_current[$dep] );
+ my $def_next = defined( $token_patterns_next[$dep] );
last if ( !$def_current && !$def_next );
if ( !$def_current
|| !$def_next
- || $token_patterns_current[$depth] ne
- $token_patterns_next[$depth] )
+ || $token_patterns_current[$dep] ne
+ $token_patterns_next[$dep] )
{
my $n_parent;
- if ( $depth > 0 && defined( $match_tree[ $depth - 1 ] ) ) {
- $n_parent = @{ $match_tree[ $depth - 1 ] } - 1;
+ if ( $dep > 0 && defined( $match_tree[ $dep - 1 ] ) ) {
+ $n_parent = @{ $match_tree[ $dep - 1 ] } - 1;
}
- $end_node->( $depth, $jm, $n_parent );
+ $end_node->( $dep, $jm, $n_parent );
last;
}
}
# Loop over the groups with side comments
my $column_limit;
- foreach my $ng (@todo) {
- my ( $jbeg, $jend ) = @{ $rgroups->[$ng] };
+ foreach my $ngr (@todo) {
+ my ( $jbeg, $jend ) = @{ $rgroups->[$ngr] };
# Note that since all lines in a group have common alignments, we
# just have to work on one of the lines (the first line).