]> git.donarmstrong.com Git - perltidy.git/commitdiff
simplify diagnostics object
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 22 Mar 2023 14:41:55 +0000 (07:41 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 22 Mar 2023 14:41:55 +0000 (07:41 -0700)
Previously, the diagnostics object made a call back to the tokenizer to get
the input line number. Now the line number arrives as an optional arg.

lib/Perl/Tidy/Diagnostics.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm

index 4d9b6b1906f646cd7566d9d5a920b0ed8987201b..f65d4cea275b14d2e04f7e9c4843885761fa1e0d 100644 (file)
@@ -12,9 +12,6 @@
 # scanned at once for some particular condition of interest.  It was
 # particularly useful for developing guessing strategies.
 #
-# NOTE: This feature is deactivated in final releases but can be
-# reactivated for debugging by un-commenting the 'I' options flag
-#
 #####################################################################
 
 package Perl::Tidy::Diagnostics;
@@ -69,13 +66,22 @@ sub set_input_file {
 }
 
 sub write_diagnostics {
-    my ( $self, $msg ) = @_;
+    my ( $self, $msg, $line_number ) = @_;
+
+    # Write a message to the diagnostics file
+    # Input parameters:
+    #  $msg = string describing the event
+    #  $line_number = optional line number
 
     unless ( $self->{_write_diagnostics_count} ) {
         open( $self->{_fh}, ">", "DIAGNOSTICS" )
           or Perl::Tidy::Die("couldn't open DIAGNOSTICS: $ERRNO\n");
     }
 
+    if ( defined($line_number) ) {
+        $msg = "$line_number:\t$msg";
+    }
+
     my $fh                   = $self->{_fh};
     my $last_diagnostic_file = $self->{_last_diagnostic_file};
     my $input_file           = $self->{_input_file};
@@ -83,11 +89,9 @@ sub write_diagnostics {
         $fh->print("\nFILE:$input_file\n");
     }
     $self->{_last_diagnostic_file} = $input_file;
-    my $input_line_number = Perl::Tidy::Tokenizer::get_input_line_number();
-    $fh->print("$input_line_number:\t$msg");
+    $fh->print($msg);
     $self->{_write_diagnostics_count}++;
     return;
 }
 
 1;
-
index b6052a628b82798eccad55a7cc6468cc25d23869..cccb27f45eeb70e642bf6e9919218a0453a88c98 100644 (file)
@@ -1282,10 +1282,11 @@ sub check_token_array {
         return;
     }
 
+    # Available for debugging but not currently used:
     sub write_diagnostics {
-        my ($msg) = @_;
+        my ( $msg, $line_number ) = @_;
         if ($diagnostics_object) {
-            $diagnostics_object->write_diagnostics($msg);
+            $diagnostics_object->write_diagnostics( $msg, $line_number );
         }
         return;
     } ## end sub write_diagnostics
index e12807ca5ea285b75fbd997e636440b8c1abc11b..50c85f179b94a8dab2541bd5f431cd8f9aae5364 100644 (file)
@@ -626,11 +626,13 @@ sub get_unexpected_error_count {
     return $self->[_unexpected_error_count_];
 }
 
-# interface to Perl::Tidy::Diagnostics routines
+# Interface to Perl::Tidy::Diagnostics
 sub write_diagnostics {
-    my $msg = shift;
-    if ( $tokenizer_self->[_diagnostics_object_] ) {
-        $tokenizer_self->[_diagnostics_object_]->write_diagnostics($msg);
+    my ($msg)              = @_;
+    my $input_line_number  = $tokenizer_self->[_last_line_number_];
+    my $diagnostics_object = $tokenizer_self->[_diagnostics_object_];
+    if ($diagnostics_object) {
+        $diagnostics_object->write_diagnostics( $msg, $input_line_number );
     }
     return;
 } ## end sub write_diagnostics