Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: for gnuism and c99ism, calculate s...



details:   https://anonhg.NetBSD.org/src/rev/758693eed4ae
branches:  trunk
changeset: 365259:758693eed4ae
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 16 15:55:10 2022 +0000

description:
lint: for gnuism and c99ism, calculate severity

Calculating the severity as a simple sum removes the condition sequence
'a && !b, or else a || !b', which can quickly become a brain twister,
especially when negations are involved.

No functional change.

diffstat:

 usr.bin/xlint/lint1/err.c |  17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diffs (52 lines):

diff -r a617910bdb37 -r 758693eed4ae usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Apr 16 14:26:26 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Apr 16 15:55:10 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.160 2022/04/16 13:25:27 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.161 2022/04/16 15:55:10 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.160 2022/04/16 13:25:27 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.161 2022/04/16 15:55:10 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -634,14 +634,13 @@
 (c99ism)(int msgid, ...)
 {
        va_list ap;
-       bool extensions_ok = Sflag || gflag;
+       int severity = (!allow_c99 && !allow_gcc ? 1 : 0) + (sflag ? 1 : 0);
 
        va_start(ap, msgid);
-       if (sflag && !extensions_ok) {
+       if (severity == 2)
                verror_at(msgid, &curr_pos, ap);
-       } else if (sflag || !extensions_ok) {
+       if (severity == 1)
                vwarning_at(msgid, &curr_pos, ap);
-       }
        va_end(ap);
 }
 
@@ -661,12 +660,12 @@
 (gnuism)(int msgid, ...)
 {
        va_list ap;
+       int severity = (!allow_gcc ? 1 : 0) + (sflag ? 1 : 0);
 
        va_start(ap, msgid);
-       if (sflag && !gflag) {
+       if (severity == 2)
                verror_at(msgid, &curr_pos, ap);
-       } else if (sflag || !gflag) {
+       if (severity == 1)
                vwarning_at(msgid, &curr_pos, ap);
-       }
        va_end(ap);
 }



Home | Main Index | Thread Index | Old Index