| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# This command counts the approximate frequency of each distinct reason for |
| 4 |
# warning suppressions. |
| 5 |
# To invoke it, pass a type system name; for example: |
| 6 |
# count-suppressions nullness |
| 7 |
|
| 8 |
# If warning suppression text contains a colon, this script prints only |
| 9 |
# the text before the colon, under the assumption that the initial text |
| 10 |
# is a category name. |
| 11 |
|
| 12 |
# This script is useful to determine the most frequent reasons for warning |
| 13 |
# suppressions, to help checker developers decide what featuers to add to |
| 14 |
# their type systems. However, use common.util.count.AnnotationStatistics |
| 15 |
# to count the total number of warning suppressions (for example, to report |
| 16 |
# in a paper), because this script gives only an approximate count. |
| 17 |
|
| 18 |
debug=0 |
| 19 |
|
| 20 |
if [[ "$OSTYPE" == "darwin"* ]]; then |
| 21 |
SED="gsed" |
| 22 |
GREP="ggrep" |
| 23 |
else |
| 24 |
SED="sed" |
| 25 |
GREP="grep" |
| 26 |
fi |
| 27 |
|
| 28 |
if [ "$#" -ne 1 ]; then |
| 29 |
echo "Usage: $0 TYPESYSTEM" >&2 |
| 30 |
exit 1 |
| 31 |
fi |
| 32 |
|
| 33 |
regex="$1" |
| 34 |
|
| 35 |
# If argument is a compound checker, make the regex match them all. |
| 36 |
if [ "$regex" = "nullness" ]; then |
| 37 |
regex="\(nullness\|initialization\|keyfor\)" |
| 38 |
fi |
| 39 |
if [ "$regex" = "index" ]; then |
| 40 |
regex="\(index\|lessthan\|lowerbound\|samelen\|searchindex\|substringindex\|upperbound\)" |
| 41 |
fi |
| 42 |
|
| 43 |
# Implementation notes: |
| 44 |
# These are the two types of matching lines: |
| 45 |
# Matching lines: |
| 46 |
# * "KEY" (for @SuppressWarnings, but don't match "@SuppressWarnings" |
| 47 |
# because that might be on the previous line) |
| 48 |
# * @AssumeAssertion(key) |
| 49 |
|
| 50 |
echo "regex=${regex}" |
| 51 |
|
| 52 |
greplines=$(mktemp /tmp/count-suppressions.XXXXXX) |
| 53 |
# This grep command captures a few stray lines; users should ignore them. |
| 54 |
${GREP} -n --recursive --include='*.java' "\"${regex}[:\"]\(.*[^;]\)\?\(\$\|//\)\|@AssumeAssertion(${regex})" | grep -v "@AnnotatedFor" > "${greplines}" |
| 55 |
## Don't output a total, to avoid people using this approximate count. |
| 56 |
# echo -n "Total: " |
| 57 |
# cat ${greplines} | wc -l |
| 58 |
# shellcheck disable=SC2002 |
| 59 |
cat "${greplines}" \ |
| 60 |
| ${SED} 's/.*\/\/ //g' \ |
| 61 |
| ${SED} "s/.*@AssumeAssertion([^)])[ :]*\([^\"]\+\)\";/\1/g" \ |
| 62 |
| ${SED} 's/\([^0-9]\): [^:].*/\1/' \ |
| 63 |
| ${SED} 's/ \+$//' \ |
| 64 |
| sort | uniq -c | sort -rg |
| 65 |
if [ "$debug" -eq "0" ]; then |
| 66 |
rm -f "${greplines}" |
| 67 |
else |
| 68 |
echo Output is in: "${greplines}" |
| 69 |
fi |