# It is essential that a final call to flush() be made. Otherwise some
# final lines of text will be lost.
+# Index...
+# CODE SECTION 1: Preliminary code, global definitions and sub new
+# sub new
+# CODE SECTION 2: Some Basic Utilities
+# CODE SECTION 3: Code to accept input and form groups
+# sub valign_input
+# CODE SECTION 4: Code to process comment lines
+# sub _flush_comment_lines
+# CODE SECTION 5: Code to process groups of code lines
+# sub _flush_group_lines
+# CODE SECTION 6: Output Step A
+# sub valign_output_step_A
+# CODE SECTION 7: Output Step B
+# sub valign_output_step_B
+# CODE SECTION 8: Output Step C
+# sub valign_output_step_C
+# CODE SECTION 9: Output Step D
+# sub valign_output_step_D
+# CODE SECTION 10: Summary
+# sub report_anything_unusual
+
+# CODE SECTION 1: Preliminary code, global definitions and sub new
+
sub AUTOLOAD {
# Catch any undefined sub calls so that we are sure to get
# some diagnostic information. This sub should never be called
# except for a programming error.
our $AUTOLOAD;
- return if ($AUTOLOAD eq 'DESTROY');
+ return if ( $AUTOLOAD eq 'DESTROY' );
my ( $pkg, $fname, $lno ) = caller();
print STDERR <<EOM;
======================================================================
}
sub DESTROY {
+
# required to avoid call to AUTOLOAD in some versions of perl
}
-
BEGIN {
# Define the fixed indexes for variables in $self, which is an array
return $self;
}
+# CODE SECTION 2: Basic Utilities
+
sub flush {
# flush() is the external call to completely empty the pipeline.
return $maximum_line_length;
}
+# CODE SECTION 3: Code to accept input and form groups
+
sub push_group_line {
my ( $self, $new_line ) = @_;
= @_;
return unless ($old_line);
- my $EXPLAIN = 0;
+ use constant EXPLAIN_TERNARY => 0;
my $jmax = @{$rfields} - 1;
my $rfields_old = $old_line->get_rfields();
my @tokens = @{$rtokens};
my @field_lengths = @{$rfield_lengths};
- $EXPLAIN && do {
+ EXPLAIN_TERNARY && do {
local $" = '><';
print STDOUT "CURRENT FIELDS=<@{$rfields_old}>\n";
print STDOUT "CURRENT TOKENS=<@{$rtokens_old}>\n";
splice( @field_lengths, 0, 0, (0) x $jadd ) if $jadd;
}
- $EXPLAIN && do {
+ EXPLAIN_TERNARY && do {
local $" = '><';
print STDOUT "MODIFIED TOKENS=<@tokens>\n";
print STDOUT "MODIFIED PATTERNS=<@patterns>\n";
# variable $GoToMsg explains reason for no match, for debugging
my $GoToMsg = "";
- my $EXPLAIN = 0;
+ use constant EXPLAIN_CHECK_MATCH => 0;
my $is_hanging_side_comment = $new_line->get_is_hanging_side_comment();
my $rtokens = $new_line->get_rtokens();
# current group.
if ( $self->check_fit( $new_line, $old_line ) ) {
- $EXPLAIN
+ EXPLAIN_CHECK_MATCH
&& print "match and fit, imax_align=$imax_align, jmax=$jmax\n";
return ( 1, $jlimit );
}
else {
- $EXPLAIN
+ EXPLAIN_CHECK_MATCH
&& print "match but no fit, imax_align=$imax_align, jmax=$jmax\n";
return ( 0, $jlimit );
}
NO_MATCH:
- $EXPLAIN
+ EXPLAIN_CHECK_MATCH
&& print
"no match because $GoToMsg, max match index =i $imax_align, jmax=$jmax\n";
return $level;
}
+# CODE SECTION 4: Code to process comment lines
+
sub _flush_comment_lines {
# Output a group consisting of COMMENT lines
return;
}
+# CODE SECTION 5: Code to process groups of code lines
+
sub _flush_group_lines {
# This is the vertical aligner internal flush, which leaves the cache
$col_matching_terminal =
$base_line->get_column($j_terminal_match);
- # Ignore an undefined value as a defensive step; shouldn't
- # normally happen.
- $col_matching_terminal = 0 unless defined($col_matching_terminal);
+ # Ignore an undefined value as a defensive step; shouldn't
+ # normally happen.
+ $col_matching_terminal = 0
+ unless defined($col_matching_terminal);
}
# -------------------------------------------------------------
$base_line = $new_line;
my $col_now = $base_line->get_column($j_terminal_match);
- # Ignore an undefined value as a defensive step; shouldn't
- # normally happen.
+ # Ignore an undefined value as a defensive step; shouldn't
+ # normally happen.
$col_now = 0 unless defined($col_now);
- my $pad = $col_matching_terminal - $col_now;
+ my $pad = $col_matching_terminal - $col_now;
my $padding_available =
$base_line->get_available_space_on_right();
if ( $col_now && $pad > 0 && $pad <= $padding_available ) {
my $rtokens_old = $line_obj->get_rtokens();
my $j_terminal_match = $line_obj->get_j_terminal_match();
- my $EXPLAIN = 0;
+ use constant EXPLAIN_DELETE_SELECTED => 0;
local $" = '> <';
- $EXPLAIN && print <<EOM;
+ EXPLAIN_DELETE_SELECTED && print <<EOM;
delete indexes: <@{$ridel}>
old jmax: $jmax_old
old tokens: <@{$rtokens_old}>
}
}
- $EXPLAIN && print <<EOM;
+ EXPLAIN_DELETE_SELECTED && print <<EOM;
new jmax: $jmax_new
new tokens: <@{$rtokens_new}>
# depth 2. To cleanly stop there, we will consider depth 2 to contain all
# alignments at depth >=2.
- my $EXPLAIN = 0;
+ use constant EXPLAIN_PRUNE => 0;
####################################################################
# Prune Tree Step 1. Start by scanning the lines and collecting info
}
} ## end loop to make links down to the child nodes
- if ( 0 || $EXPLAIN > 0 ) {
+ EXPLAIN_PRUNE > 0 && do {
print "Tree complete. Found these groups:\n";
foreach my $depth ( 0 .. $MAX_DEPTH ) {
Dump_tree_groups( \@{ $match_tree[$depth] }, "depth=$depth" );
}
- }
+ };
#######################################################
# Prune Tree Step 4. Make a list of nodes to be deleted
return;
}
+# CODE SECTION 6: Output Step A
+
sub valign_output_step_A {
###############################################################
return $nlines + $file_writer_object->get_output_line_number();
}
+# CODE SECTION 7: Output Step B
+
{ ## closure for sub valign_output_step_B
# These are values for a cache used by valign_output_step_B.
}
}
+# CODE SECTION 8: Output Step C
+
{ ## closure for sub valign_output_step_C
# Vertical alignment buffer used by valign_output_step_C
}
}
+# CODE SECTION 9: Output Step D
+
sub valign_output_step_D {
###############################################################
}
} # end get_leading_string
+# CODE SECTION 10: Summary
+
sub report_anything_unusual {
my $self = shift;