Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/xlint lint: add option to accept C11 features



details:   https://anonhg.NetBSD.org/src/rev/c75cc386b517
branches:  trunk
changeset: 961287:c75cc386b517
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Apr 14 20:06:40 2021 +0000

description:
lint: add option to accept C11 features

The list of available letters for the command line options gets shorter
and shorter.  Most of the interesting letters are already used for some
warning categories.  Curiously, -A, -W and -E were all still available.

The option -A nicely matches the intention of the option, which is to
allow a certain set of language features.  To keep the option available
for further extensions, define -Ac11 as the currently only valid option
of that kind.  This allows straight-forward extension for C17 and future
language standards, as well as independent feature-sets.  The options -W
and -E may someday complement the -A option, using the allow/warn/error
categories.

diffstat:

 tests/usr.bin/xlint/lint1/msg_343.c |   4 ++--
 usr.bin/xlint/lint1/err.c           |  14 +++++---------
 usr.bin/xlint/lint1/externs1.h      |   3 ++-
 usr.bin/xlint/lint1/main1.c         |  21 +++++++++++++++++----
 usr.bin/xlint/xlint/lint.1          |   7 +++++--
 usr.bin/xlint/xlint/xlint.c         |  13 +++++++++----
 6 files changed, 40 insertions(+), 22 deletions(-)

diffs (219 lines):

diff -r d61b1a94acf6 -r c75cc386b517 tests/usr.bin/xlint/lint1/msg_343.c
--- a/tests/usr.bin/xlint/lint1/msg_343.c       Wed Apr 14 19:25:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_343.c       Wed Apr 14 20:06:40 2021 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: msg_343.c,v 1.2 2021/04/14 18:35:40 rillig Exp $       */
+/*     $NetBSD: msg_343.c,v 1.3 2021/04/14 20:06:40 rillig Exp $       */
 # 3 "msg_343.c"
 
 /* Test for message: static array size is a C11 extension [343] */
 
-/* lint1-flags: -sw */
+/* lint1-flags: -gSw */
 
 void takes_int_pointer(int []);
 void takes_int_pointer_with_ignored_size(int [3]);
diff -r d61b1a94acf6 -r c75cc386b517 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Wed Apr 14 19:25:48 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Wed Apr 14 20:06:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.109 2021/04/14 18:38:06 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.110 2021/04/14 20:06:40 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.109 2021/04/14 18:38:06 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.110 2021/04/14 20:06:40 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -612,19 +612,15 @@
        va_end(ap);
 }
 
-/* TODO: add a command line option for allowing C99 but not C11. */
 void
 (c11ism)(int n, ...)
 {
        va_list ap;
-       bool extensions_ok = Sflag || gflag;
 
+       if (c11flag)
+               return;
        va_start(ap, n);
-       if (sflag && !extensions_ok) {
-               verror(n, ap);
-       } else if (sflag || !extensions_ok) {
-               vwarning(n, ap);
-       }
+       verror(n, ap);
        va_end(ap);
 }
 
diff -r d61b1a94acf6 -r c75cc386b517 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Wed Apr 14 19:25:48 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Wed Apr 14 20:06:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.104 2021/04/14 18:35:40 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.105 2021/04/14 20:06:40 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,6 +37,7 @@
 extern int     aflag;
 extern bool    bflag;
 extern bool    cflag;
+extern bool    c11flag;
 extern bool    dflag;
 extern bool    eflag;
 extern bool    Fflag;
diff -r d61b1a94acf6 -r c75cc386b517 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Wed Apr 14 19:25:48 2021 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Wed Apr 14 20:06:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.42 2021/04/02 12:16:50 rillig Exp $        */
+/*     $NetBSD: main1.c,v 1.43 2021/04/14 20:06:40 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.42 2021/04/02 12:16:50 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.43 2021/04/14 20:06:40 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -68,6 +68,9 @@
 /* Print warnings for pointer casts. */
 bool   cflag;
 
+/* Allow features from C11, C99 and C90. */
+bool   c11flag;
+
 /* Print various debug information. */
 bool   dflag;
 
@@ -178,7 +181,7 @@
        setprogname(argv[0]);
 
        ERR_ZERO(&msgset);
-       while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFPR:STX:")) != -1) {
+       while ((c = getopt(argc, argv, "abcdeghmprstuvwyzA:FPR:STX:")) != -1) {
                switch (c) {
                case 'a':       aflag++;        break;
                case 'b':       bflag = true;   break;
@@ -201,6 +204,15 @@
                case 'y':       yflag = true;   break;
                case 'z':       zflag = false;  break;
 
+               case 'A':
+                       if (strcmp(optarg, "c11") == 0) {
+                               c11flag = true;
+                               Sflag = true;
+                               sflag = true;
+                       } else
+                               usage();
+                       break;
+
                case 'm':
                        msglist();
                        return 0;
@@ -284,7 +296,8 @@
 usage(void)
 {
        (void)fprintf(stderr,
-           "Usage: %s [-abcdeghmprstuvwyzFST] [-X <id>[,<id>]... src dest\n",
+           "usage: %s [-abcdeghmprstuvwyzFST] [-Ac11] [-X <id>[,<id>]... "
+           "src dest\n",
            getprogname());
        exit(1);
 }
diff -r d61b1a94acf6 -r c75cc386b517 usr.bin/xlint/xlint/lint.1
--- a/usr.bin/xlint/xlint/lint.1        Wed Apr 14 19:25:48 2021 +0000
+++ b/usr.bin/xlint/xlint/lint.1        Wed Apr 14 20:06:40 2021 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: lint.1,v 1.42 2021/01/12 20:42:01 rillig Exp $
+.\" $NetBSD: lint.1,v 1.43 2021/04/14 20:06:40 rillig Exp $
 .\"
 .\" Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
 .\" Copyright (c) 1994, 1995 Jochen Pohl
@@ -30,7 +30,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd Jan 12, 2021
+.Dd Apr 14, 2021
 .Dt LINT 1
 .Os
 .Sh NAME
@@ -51,6 +51,7 @@
 .Op Fl o Ar outputfile
 .Op Fl U Ar name
 .Op Fl X Ar id Ns Op ,id ...
+.Op Fl Ac11
 .Op Fl Z Ar cpparg
 .Ar
 .Nm lint
@@ -184,6 +185,8 @@
 .Pp
 .Sy Options
 .Bl -tag -width XoXoutputfileXXX
+.It Fl Ac11
+Allow features from C11, C99 and C90.
 .It Fl a
 Report assignments of
 .Sy long
diff -r d61b1a94acf6 -r c75cc386b517 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Wed Apr 14 19:25:48 2021 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Wed Apr 14 20:06:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.59 2021/04/14 19:25:48 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.60 2021/04/14 20:06:40 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.59 2021/04/14 19:25:48 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.60 2021/04/14 20:06:40 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -297,7 +297,7 @@
            "usage: %s [-abceghprvwxzHFST] [-s|-t] [-i|-nu]\n"
            "%*s [-Dname[=def]] [-Uname] [-Idirectory] [-Z <cpparg>]\n"
            "%*s [-Ldirectory] [-llibrary] [-ooutputfile]\n"
-           "%*s [-X <id>[,<id>]...] file...\n",
+           "%*s [-X <id>[,<id>]...] [-Ac11] file...\n",
            name, indent, "", indent, "", indent, "");
        (void)fprintf(stderr,
            "       %s [-abceghprvwzHFST] [-s|-t] -Clibrary\n"
@@ -375,7 +375,7 @@
        (void)signal(SIGQUIT, terminate);
        (void)signal(SIGTERM, terminate);
        while ((c = getopt(argc, argv,
-           "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:M:PR:STU:VX:Z:")) != -1) {
+           "abcd:eghil:no:prstuvwxzA:B:C:D:FHI:L:M:PR:STU:VX:Z:")) != -1) {
                switch (c) {
 
                case 'a':
@@ -391,6 +391,11 @@
                        appcstrg(&l1flags, flgbuf);
                        break;
 
+               case 'A':
+                       appcstrg(&l1flags, "-A");
+                       appcstrg(&l1flags, optarg);
+                       break;
+
                case 'F':
                        Fflag = true;
                        /* FALLTHROUGH */



Home | Main Index | Thread Index | Old Index