]> git.donarmstrong.com Git - perltidy.git/commitdiff
some coding cleanups
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 28 Dec 2019 17:07:51 +0000 (09:07 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 28 Dec 2019 17:07:51 +0000 (09:07 -0800)
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/VerticalAligner.pm

index eb6a3d1713507ad23eb2bd8ad763af4da0b21003..3ecfcb15685c1af37bc2b831aa0b3ce462992e2d 100644 (file)
@@ -3997,44 +3997,5 @@ sub do_syntax_check {
     return;
 }
 
-=pod
-sub do_syntax_check {
-    my ( $stream, $flags, $error_redirection ) = @_;
-
-    ############################################################
-    # This code is not reachable because syntax check is deactivated,
-    # but it is retained for reference.
-    ############################################################
-
-    # We need a named input file for executing perl
-    my ( $stream_filename, $is_tmpfile ) = get_stream_as_named_file($stream);
-
-    # TODO: Need to add name of file to log somewhere
-    # otherwise Perl output is hard to read
-    if ( !$stream_filename ) { return $stream_filename, "" }
-
-    # We have to quote the filename in case it has unusual characters
-    # or spaces.  Example: this filename #CM11.pm# gives trouble.
-    my $quoted_stream_filename = '"' . $stream_filename . '"';
-
-    # Under VMS something like -T will become -t (and an error) so we
-    # will put quotes around the flags.  Double quotes seem to work on
-    # Unix/Windows/VMS, but this may not work on all systems.  (Single
-    # quotes do not work under Windows).  It could become necessary to
-    # put double quotes around each flag, such as:  -"c"  -"T"
-    # We may eventually need some system-dependent coding here.
-    $flags = '"' . $flags . '"';
-
-    # now wish for luck...
-    my $msg = qx/perl $flags $quoted_stream_filename $error_redirection/; 
-
-    if ($is_tmpfile) {
-        unlink $stream_filename
-          or Perl::Tidy::Die("couldn't unlink stream $stream_filename: $!\n");
-    }
-    return $stream_filename, $msg;
-}
-=cut
-
 1;
 
index e806b11f7713a3a79c442da4c70fe796d3d85e5c..e16faf9d4e0702be25aa69013da029ac9a51bc75 100644 (file)
@@ -3305,23 +3305,6 @@ sub respace_tokens {
             }
         }
 
-=pod
-        # NOTE: This does not work yet. Version in print-line-of-tokens 
-        # is Still used until fixed
-
-        # compare input/output indentation except for continuation lines
-        # (because they have an unknown amount of initial blank space)
-        # and lines which are quotes (because they may have been outdented)
-        # Note: this test is placed here because we know the continuation flag
-        # at this point, which allows us to avoid non-meaningful checks.
-        my $structural_indentation_level = $rLL->[$Kfirst]->[_LEVEL_];
-        compare_indentation_levels( $guessed_indentation_level,
-            $structural_indentation_level )
-          unless ( $rLL->[$Kfirst]->[_CI_LEVEL_] > 0
-            || $guessed_indentation_level == 0
-            && $rLL->[$Kfirst]->[_TYPE_] eq 'Q' );
-=cut
-
         #   Patch needed for MakeMaker.  Do not break a statement
         #   in which $VERSION may be calculated.  See MakeMaker.pm;
         #   this is based on the coding in it.
@@ -7273,12 +7256,9 @@ EOM
             return;
         }
 
-        # TODO: Move to sub scan_comments
         # compare input/output indentation except for continuation lines
         # (because they have an unknown amount of initial blank space)
         # and lines which are quotes (because they may have been outdented)
-        # Note: this test is placed here because we know the continuation flag
-        # at this point, which allows us to avoid non-meaningful checks.
         my $structural_indentation_level = $rinput_token_array->[0]->[_LEVEL_];
         compare_indentation_levels( $guessed_indentation_level,
             $structural_indentation_level )
@@ -8074,8 +8054,17 @@ sub output_line_to_go {
         if ( $rOpts_one_line_block_semicolons == 0 ) {
             $self->delete_one_line_semicolons( $ri_first, $ri_last );
         }
-        $self->send_lines_to_vertical_aligner( $ri_first, $ri_last,
-            $do_not_pad );
+
+        # The line breaks for this batch of code have been finalized;
+        my $rlines_i;
+        for ( my $n = 0 ; $n < @{$ri_first} ; $n++ ) {
+            push @{$rlines_i}, [ $ri_first->[$n], $ri_last->[$n] ];
+        }
+        my $rcall_hash = {
+            rlines_i   => $rlines_i,
+            do_not_pad => $do_not_pad,
+        };
+        $self->send_lines_to_vertical_aligner($rcall_hash);
 
         # Insert any requested blank lines after an opening brace.  We have to
         # skip back before any side comment to find the terminal token
@@ -9897,7 +9886,20 @@ sub previous_nonblank_token {
 
 sub send_lines_to_vertical_aligner {
 
-    my ( $self, $ri_first, $ri_last, $do_not_pad ) = @_;
+    my ( $self, $rcall_hash ) = @_;
+
+    my $do_not_pad = $rcall_hash->{do_not_pad};
+    my $rlines_i   = $rcall_hash->{rlines_i};
+    if ( !@{$rlines_i} ) {
+        Fault("Error in send_lines_to_vertical_aligner: no lines");
+        return;
+    }
+    my ( $ri_first, $ri_last );
+    foreach my $rline ( @{$rlines_i} ) {
+        my ( $ibeg, $iend ) = @{$rline};
+        push @{$ri_first}, $ibeg;
+        push @{$ri_last},  $iend;
+    }
 
     my $valign_batch_number = $self->increment_valign_batch_count();
 
@@ -10730,6 +10732,11 @@ sub lookup_opening_indentation {
 
     my ( $i_opening, $ri_start, $ri_last, $rindentation_list ) = @_;
 
+    if ( !@{$ri_last} ) {
+        warning("Error in opening_indentation: no lines");
+        return;
+    }
+
     my $nline = $rindentation_list->[0];    # line number of previous lookup
 
     # reset line location if necessary
index ebd3c0730d791f3489b488f04214d9e43497f485..3f93196650353a855f9669d4d4ee23a15580d77f 100644 (file)
@@ -2053,8 +2053,6 @@ sub my_flush {
         my @new_lines = @group_lines;
         initialize_for_new_group();
 
-        ##my $has_terminal_ternary = $new_lines[-1]->{_is_terminal_ternary};
-
         # remove unmatched tokens in all lines
         delete_unmatched_tokens( \@new_lines );
 
@@ -2099,10 +2097,12 @@ sub my_flush {
             # BEFORE this line unless both it and the previous line have side
             # comments.  This prevents this line from pushing side coments out
             # to the right.
-            ##elsif ( $new_line->get_jmax() == 1 ) {
             elsif ( $new_line->get_jmax() == 1 && !$keep_group_intact ) {
 
-                # There are no matching tokens, so now check side comments:
+                # There are no matching tokens, so now check side comments.
+               # Programming note: accessing arrays with index -1 is 
+               # risky in Perl, but we have verified there is at least one
+               # line in the group and that there is at least one field.
                 my $prev_comment = $group_lines[-1]->get_rfields()->[-1];
                 my $side_comment = $new_line->get_rfields()->[-1];
                 my_flush_code() unless ( $side_comment && $prev_comment );
@@ -3200,7 +3200,9 @@ sub valign_output_step_B {
                         my @seqno_last =
                           ( split /:/, $last_nonblank_seqno_string );
                         my @seqno_now = ( split /:/, $seqno_string );
-                        if (   $seqno_now[-1] == $seqno_last[0]
+                        if (   @seqno_now
+                            && @seqno_last
+                            && $seqno_now[-1] == $seqno_last[0]
                             && $seqno_now[0] == $seqno_last[-1] )
                         {