Commit d8b461df authored by Russ Cox's avatar Russ Cox

rewrite errchk in perl for speed (compared to bash)

R=iant
DELTA=125  (51 added, 53 deleted, 21 changed)
OCL=35508
CL=35511
parent 680ee6af
......@@ -16,22 +16,22 @@ type T struct {
func main() {
{
var x, y sync.Mutex;
x = y; // ERROR "assignment\[ -~\]*Mutex"
x = y; // ERROR "assignment.*Mutex"
_ = x;
}
{
var x, y T;
x = y; // ERROR "assignment\[ -~\]*Mutex"
x = y; // ERROR "assignment.*Mutex"
_ = x;
}
{
var x, y [2]sync.Mutex;
x = y; // ERROR "assignment\[ -~\]*Mutex"
x = y; // ERROR "assignment.*Mutex"
_ = x;
}
{
var x, y [2]T;
x = y; // ERROR "assignment\[ -~\]*Mutex"
x = y; // ERROR "assignment.*Mutex"
_ = x;
}
}
#!/bin/bash
#!/usr/bin/perl
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
......@@ -13,78 +13,76 @@
# If the compiler generates an error for a line which has no such
# commnt, this script will report an error. Likewise if the compiler
# does not generate an error for a line which has a comment, or if the
# error message does not match the <regexp>. The <regexp> is
# interpreted by egrep.
# error message does not match the <regexp>. The <regexp> syntax
# is Perl but its best to stick to egrep.
if test $# -lt 2; then
echo 1>&2 "Usage: errchk COMPILER [OPTS] SOURCEFILE"
exit 1
fi
use POSIX;
ARGCOUNT=$#
SOURCEFILE=${!ARGCOUNT}
TMPOUT=/tmp/errchk-out-$$
TMPERR=/tmp/errchk-err-$$
TMPALL=/tmp/errchk-all-$$
TMPTMP=/tmp/errchk-tmp-$$
TMPBUG=/tmp/errchk-bug-$$
if(@ARGV < 1) {
print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILE\n";
exit 1;
}
rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG
$file = $ARGV[@ARGV-1];
open(SRC, $file) || die "BUG: errchk: open $file: $!";
@src = <SRC>;
close(SRC);
trap "rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG" 0 1 2 3 14 15
# Run command
$cmd = join(' ', @ARGV);
open(CMD, "$cmd </dev/null 2>&1 |") || die "BUG: errchk: run $cmd: $!";
@out = grep { !/^ / } <CMD>;
close CMD;
(if $* >$TMPOUT 2>$TMPERR; then
echo 1>&4 "BUG: errchk: command succeeded unexpectedly"
cat 1>&3 $TMPOUT
cat 1>&4 $TMPERR
rm -f $TMPOUT $TMPERR
fi) 3>&1 4>&2 >$TMPTMP 2>&1
if($? == 0) {
print STDERR "BUG: errchk: command succeeded unexpectedly\n";
print STDERR @out;
exit 0;
}
if ! test -f $TMPOUT; then
exit 0
fi
if(!WIFEXITED($?)) {
print STDERR "BUG: errchk: compiler crashed\n";
exit 0;
}
if test -s $TMPTMP; then
echo 1>&2 BUG: errchk: compiler crashed
cat $TMPOUT
cat 1>&2 $TMPERR
exit 0
fi
sub bug() {
if(!$bug++) {
print STDERR "BUG: ";
}
}
cat $TMPOUT $TMPERR | grep -v '^ ' > $TMPALL
$line = 0;
foreach $src (@src) {
$line++;
next unless $src =~ m|// ERROR (.*)|;
$regexp = $1;
if($regexp !~ /^"([^"]*)"/) {
print STDERR "$file:$line: malformed regexp\n";
next;
}
$regexp = $1;
bug() {
if ! test -f $TMPBUG
then
echo 1>&2 -n BUG: ''
echo >$TMPBUG
fi
@errmsg = grep { /$file:$line:/ } @out;
@out = grep { !/$file:$line:/ } @out;
if(@errmsg == 0) {
bug();
print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n";
next;
}
@match = grep { /$regexp/ } @errmsg;
if(@match == 0) {
bug();
print STDERR "errchk: $file:$line: error message does not match '$regexp'\n";
next;
}
}
header=0
pr -n -t $SOURCEFILE | grep '// ERROR' | while read line; do
lineno=`echo $line | sed -e 's/^[ ]*\([0-9]*\).*$/\1/'`
regexp=`echo $line | sed -e 's|.*// ERROR "\([^"]*\)".*$|\1|'`
errmsg=`grep "$SOURCEFILE:$lineno" <$TMPALL`
grep -v "$SOURCEFILE:$lineno" < $TMPALL > $TMPTMP
mv -f $TMPTMP $TMPALL
if test -z "$errmsg"; then
bug
echo 1>&2 "errchk: $SOURCEFILE:$lineno: missing expected error: '$regexp'"
elif ! echo "$errmsg" | egrep -q "$regexp"; then
bug
echo 1>&2 "errchk: $SOURCEFILE:$lineno: error message does not match '$regexp'"
echo 1>&2 $errmsg
fi
done
if test -s $TMPALL; then
bug
echo 1>&2 "errchk: $SOURCEFILE: unmatched error messages:"
echo 1>&2 "=================================================="
cat 1>&2 $TMPALL
echo 1>&2 "=================================================="
fi
if(@out != 0) {
bug();
print STDERR "errchk: $file: unmatched error messages:\n";
print STDERR "==================================================\n";
print STDERR @out;
print STDERR "==================================================\n";
}
exit 0
exit 0;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment