]> git.donarmstrong.com Git - perltidy.git/commitdiff
removed unused syntax check coding; updated some error messages
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 12 Oct 2021 00:53:32 +0000 (17:53 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 12 Oct 2021 00:53:32 +0000 (17:53 -0700)
lib/Perl/Tidy.pm
lib/Perl/Tidy/Logger.pm
lib/Perl/Tidy/Tokenizer.pm

index e33fd335f93784ade4f9855a30c812ecb5742abf..aa37dfc415033edc37b182aaf733b6de56ecec0d 100644 (file)
@@ -1644,7 +1644,7 @@ EOM
             $source_object->close_input_file();
         }
 
-        # Save names of the input and output files for syntax check
+        # Save names of the input and output files
         my $ifname = $input_file;
         my $ofname = $output_file;
 
@@ -1782,21 +1782,6 @@ EOM
             }
         }
 
-        #---------------------------------------------------------------
-        # Do syntax check if requested and possible
-        # This is permanently deactivated but the code remains for reference
-        #---------------------------------------------------------------
-        my $infile_syntax_ok = 0;    # -1 no  0=don't know   1 yes
-        if (   0
-            && $logger_object
-            && $rOpts->{'check-syntax'}
-            && $ifname
-            && $ofname )
-        {
-            $infile_syntax_ok =
-              check_syntax( $ifname, $ofname, $logger_object, $rOpts );
-        }
-
         #---------------------------------------------------------------
         # remove the original file for in-place modify as follows:
         #   $delete_backup=0 never
@@ -1828,7 +1813,7 @@ EOM
             }
         }
 
-        $logger_object->finish( $infile_syntax_ok, $formatter )
+        $logger_object->finish($formatter)
           if $logger_object;
     } ## end of main loop to process all files
 
@@ -2007,8 +1992,8 @@ sub get_stream_as_named_file {
     #  $fname = name of file if possible, or undef
     #  $if_tmpfile = true if temp file, undef if not temp file
     #
-    # This routine is needed for passing actual files to Perl for
-    # a syntax check.
+    # NOTE: This routine was previously needed for passing actual files to Perl
+    # for a syntax check. It is not currently used.
     my ($stream) = @_;
     my $is_tmpfile;
     my $fname;
@@ -4251,7 +4236,6 @@ I/O control
  -bext=s change default backup extension from 'bak' to s
  -q      deactivate error messages (for running under editor)
  -w      include non-critical warning messages in the .ERR error output
- -syn    run perl -c to check syntax (default under unix systems)
  -log    save .LOG file, which has useful diagnostics
  -f      force perltidy to read a binary file
  -g      like -log but writes more detailed .LOG file, for debugging scripts
@@ -4445,110 +4429,4 @@ sub process_this_file {
 
     return;
 }
-
-sub check_syntax {
-
-    # Use 'perl -c' to make sure that we did not create bad syntax
-    # This is a very good independent check for programming errors
-    #
-    # Given names of the input and output files, ($istream, $ostream),
-    # we do the following:
-    # - check syntax of the input file
-    # - if bad, all done (could be an incomplete code snippet)
-    # - if infile syntax ok, then check syntax of the output file;
-    #   - if outfile syntax bad, issue warning; this implies a code bug!
-    # - set and return flag "infile_syntax_ok" : =-1 bad 0 unknown 1 good
-
-    my ( $istream, $ostream, $logger_object, $rOpts ) = @_;
-    my $infile_syntax_ok = 0;
-    my $line_of_dashes   = '-' x 42 . "\n";
-
-    my $flags = $rOpts->{'perl-syntax-check-flags'};
-
-    # be sure we invoke perl with -c
-    # note: perl will accept repeated flags like '-c -c'.  It is safest
-    # to append another -c than try to find an interior bundled c, as
-    # in -Tc, because such a 'c' might be in a quoted string, for example.
-    if ( $flags !~ /(^-c|\s+-c)/ ) { $flags .= " -c" }
-
-    # be sure we invoke perl with -x if requested
-    # same comments about repeated parameters applies
-    if ( $rOpts->{'look-for-hash-bang'} ) {
-        if ( $flags !~ /(^-x|\s+-x)/ ) { $flags .= " -x" }
-    }
-
-    # this shouldn't happen unless a temporary file couldn't be made
-    if ( $istream eq '-' ) {
-        $logger_object->write_logfile_entry(
-            "Cannot run perl -c on STDIN and STDOUT\n");
-        return $infile_syntax_ok;
-    }
-
-    $logger_object->write_logfile_entry(
-        "checking input file syntax with perl $flags\n");
-
-    # Not all operating systems/shells support redirection of the standard
-    # error output.
-    my $error_redirection = ( $^O eq 'VMS' ) ? "" : '2>&1';
-
-    my ( $istream_filename, $perl_output ) =
-      do_syntax_check( $istream, $flags, $error_redirection );
-    $logger_object->write_logfile_entry(
-        "Input stream passed to Perl as file $istream_filename\n");
-    $logger_object->write_logfile_entry($line_of_dashes);
-    $logger_object->write_logfile_entry("$perl_output\n");
-
-    if ( $perl_output =~ /syntax\s*OK/ ) {
-        $infile_syntax_ok = 1;
-        $logger_object->write_logfile_entry($line_of_dashes);
-        $logger_object->write_logfile_entry(
-            "checking output file syntax with perl $flags ...\n");
-        my ( $ostream_filename, $perl_output ) =
-          do_syntax_check( $ostream, $flags, $error_redirection );
-        $logger_object->write_logfile_entry(
-            "Output stream passed to Perl as file $ostream_filename\n");
-        $logger_object->write_logfile_entry($line_of_dashes);
-        $logger_object->write_logfile_entry("$perl_output\n");
-
-        unless ( $perl_output =~ /syntax\s*OK/ ) {
-            $logger_object->write_logfile_entry($line_of_dashes);
-            $logger_object->warning(
-"The output file has a syntax error when tested with perl $flags $ostream !\n"
-            );
-            $logger_object->warning(
-                "This implies an error in perltidy; the file $ostream is bad\n"
-            );
-            $logger_object->report_definite_bug();
-
-            # the perl version number will be helpful for diagnosing the problem
-            $logger_object->write_logfile_entry( $^V . "\n" );
-        }
-    }
-    else {
-
-        # Only warn of perl -c syntax errors.  Other messages,
-        # such as missing modules, are too common.  They can be
-        # seen by running with perltidy -w
-        $logger_object->complain("A syntax check using perl $flags\n");
-        $logger_object->complain(
-            "for the output in file $istream_filename gives:\n");
-        $logger_object->complain($line_of_dashes);
-        $logger_object->complain("$perl_output\n");
-        $logger_object->complain($line_of_dashes);
-        $infile_syntax_ok = -1;
-        $logger_object->write_logfile_entry($line_of_dashes);
-        $logger_object->write_logfile_entry(
-"The output file will not be checked because of input file problems\n"
-        );
-    }
-    return $infile_syntax_ok;
-}
-
-sub do_syntax_check {
-
-    # This should not be called; the syntax check is deactivated
-    Die("Unexpected call for syntax check-shouldn't happen\n");
-    return;
-}
-
 1;
index 9b7a8ce4f7acdd54e2a2fde6c2e1680fcd2ac2ac..9ec2e2390549695da36dac2ef5e97f7666d653ab 100644 (file)
@@ -435,113 +435,32 @@ sub warning {
     return;
 }
 
-# programming bug codes:
-#   -1 = no bug
-#    0 = maybe, not sure.
-#    1 = definitely
-sub report_possible_bug {
-    my $self         = shift;
-    my $saw_code_bug = $self->{_saw_code_bug};
-    $self->{_saw_code_bug} = ( $saw_code_bug < 0 ) ? 0 : $saw_code_bug;
-    return;
-}
-
 sub report_definite_bug {
     my $self = shift;
     $self->{_saw_code_bug} = 1;
     return;
 }
 
-sub ask_user_for_bug_report {
-
-    my ( $self, $infile_syntax_ok, $formatter ) = @_;
-    my $saw_code_bug = $self->{_saw_code_bug};
-    if ( ( $saw_code_bug == 0 ) && ( $infile_syntax_ok == 1 ) ) {
-        $self->warning(<<EOM);
-
-You may have encountered a code bug in perltidy.  If you think so, and
-the problem is not listed in the BUGS file at
-http://perltidy.sourceforge.net, please report it so that it can be
-corrected.  Include the smallest possible script which has the problem,
-along with the .LOG file. See the manual pages for contact information.
-Thank you!
-EOM
-
-    }
-    elsif ( $saw_code_bug == 1 ) {
-        if ( $self->{_saw_extrude} ) {
-            $self->warning(<<EOM);
-
-You may have encountered a bug in perltidy.  However, since you are using the
--extrude option, the problem may be with perl or one of its modules, which have
-occasional problems with this type of file.  If you believe that the
-problem is with perltidy, and the problem is not listed in the BUGS file at
-http://perltidy.sourceforge.net, please report it so that it can be corrected.
-Include the smallest possible script which has the problem, along with the .LOG
-file. See the manual pages for contact information.
-Thank you!
-EOM
-        }
-        else {
-            $self->warning(<<EOM);
-
-Oops, you seem to have encountered a bug in perltidy.  Please check the
-BUGS file at http://perltidy.sourceforge.net.  If the problem is not
-listed there, please report it so that it can be corrected.  Include the
-smallest possible script which produces this message, along with the
-.LOG file if appropriate.  See the manual pages for contact information.
-Your efforts are appreciated.  
-Thank you!
-EOM
-            my $added_semicolon_count = 0;
-            eval {
-                $added_semicolon_count =
-                  $formatter->get_added_semicolon_count();
-            };
-            if ( $added_semicolon_count > 0 ) {
-                $self->warning(<<EOM);
-
-The log file shows that perltidy added $added_semicolon_count semicolons.
-Please rerun with -nasc to see if that is the cause of the syntax error.  Even
-if that is the problem, please report it so that it can be fixed.
-EOM
-
-            }
-        }
-    }
-    return;
-}
-
 sub get_save_logfile {
 
     # To be called after tokenizer has finished to make formatting more
-    # efficient.  This is not precisely the same as the check used below
-    # because we don't yet have the syntax check result, but since syntax
-    # checking is off by default it will be the same except in debug runs with
-    # syntax checking activated.  In that case it will tell the formatter to
-    # save the logfile even if it may actually be deleted based on the syntax
-    # check.
+    # efficient.
     my $self         = shift;
     my $saw_code_bug = $self->{_saw_code_bug};
     my $rOpts        = $self->{_rOpts};
-    return
-         $saw_code_bug == 1
-      || $rOpts->{'logfile'}
-      || $rOpts->{'check-syntax'};
+    return $saw_code_bug == 1 || $rOpts->{'logfile'};
 }
 
 sub finish {
 
     # called after all formatting to summarize errors
-    my ( $self, $infile_syntax_ok, $formatter ) = @_;
+    my ( $self, $formatter ) = @_;
 
     my $rOpts         = $self->{_rOpts};
     my $warning_count = $self->{_warning_count};
     my $saw_code_bug  = $self->{_saw_code_bug};
 
-    my $save_logfile =
-         ( $saw_code_bug == 0 && $infile_syntax_ok == 1 )
-      || $saw_code_bug == 1
+    my $save_logfile = $saw_code_bug == 1
       || $rOpts->{'logfile'};
     my $log_file = $self->{_log_file};
     if ($warning_count) {
@@ -565,9 +484,6 @@ sub finish {
         }
     }
 
-    # deactivated - prefer Fault reports in DEVEL_MODE during random testing
-    ##$self->ask_user_for_bug_report( $infile_syntax_ok, $formatter );
-
     if ($save_logfile) {
         my $log_file        = $self->{_log_file};
         my $is_encoded_data = $self->{_is_encoded_data};
index 20d8f755bc7728c2578afe1e9afd245b5e4ab64a..c65728bdcecc212484555eaa99d48d4dac9ca627 100644 (file)
@@ -3029,7 +3029,9 @@ EOM
 Program bug; didn't find here doc target
 EOM
                         }
-                        warning("Program bug; didn't find here doc target\n");
+                        warning(
+"Possible program error: didn't find here doc target\n"
+                        );
                         report_definite_bug();
                     }
                 }
@@ -3079,7 +3081,9 @@ EOM
 Program bug; didn't find here doc target
 EOM
                         }
-                        warning("Program bug; didn't find here doc target\n");
+                        warning(
+"Possible program error: didn't find here doc target\n"
+                        );
                         report_definite_bug();
                     }
                 }
@@ -4459,7 +4463,9 @@ EOM
 non-number beginning with digit--program bug
 EOM
                     }
-                    warning("non-number beginning with digit--program bug\n");
+                    warning(
+"Unexpected error condition: non-number beginning with digit\n"
+                    );
                     report_definite_bug();
                 }
             }
@@ -6838,7 +6844,7 @@ Program bug in scan_id: undefined type but scan_state=$id_scan_state
 EOM
         }
         warning(
-"Program bug in scan_id: undefined type but scan_state=$id_scan_state\n"
+"Possible program bug in sub scan_id: undefined type but scan_state=$id_scan_state\n"
         );
         report_definite_bug();
     }
@@ -8240,9 +8246,13 @@ sub find_angle_operator_termination {
             # It may be possible that a quote ends midway in a pretoken.
             # If this happens, it may be necessary to split the pretoken.
             if ($error) {
+                if (DEVEL_MODE) {
+                    Fault(<<EOM);
+unexpected error condition returned by inverse_pretoken_map
+EOM
+                }
                 warning(
                     "Possible tokinization error..please check this line\n");
-                report_possible_bug();
             }
 
             # count blanks on inside of brackets