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: add error_at, warning_at, message_at



details:   https://anonhg.NetBSD.org/src/rev/5fe5379e5cb7
branches:  trunk
changeset: 1020630:5fe5379e5cb7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 18 08:52:04 2021 +0000

description:
lint: add error_at, warning_at, message_at

Right now there are several places in the code that use the global
variable curr_pos for passing a parameter to the diagnostic functions.
That's not what global variables are for.

Make it easy for the code to migrate to the parameter-passing style.

No functional change.

diffstat:

 usr.bin/xlint/lint1/err.c      |  85 ++++++++++++++++++++++++++++++-----------
 usr.bin/xlint/lint1/externs1.h |   5 +-
 usr.bin/xlint/lint1/lint1.h    |  15 ++++++-
 3 files changed, 79 insertions(+), 26 deletions(-)

diffs (232 lines):

diff -r af1a7201a2fb -r 5fe5379e5cb7 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun Apr 18 08:07:04 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun Apr 18 08:52:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.112 2021/04/18 08:07:04 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.113 2021/04/18 08:52:04 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.112 2021/04/18 08:07:04 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.113 2021/04/18 08:52:04 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -484,15 +484,15 @@
 }
 
 static void
-verror(int n, va_list ap)
+verror_at(pos_t pos, int n, va_list ap)
 {
        const   char *fn;
 
        if (ERR_ISSET(n, &msgset))
                return;
 
-       fn = lbasename(curr_pos.p_file);
-       (void)printf("%s(%d): error: ", fn, curr_pos.p_line);
+       fn = lbasename(pos.p_file);
+       (void)printf("%s(%d): error: ", fn, pos.p_line);
        (void)vprintf(msgs[n], ap);
        (void)printf(" [%d]\n", n);
        nerr++;
@@ -500,7 +500,7 @@
 }
 
 static void
-vwarning(int n, va_list ap)
+vwarning_at(pos_t pos, int n, va_list ap)
 {
        const   char *fn;
 
@@ -514,8 +514,8 @@
                /* this warning is suppressed by a LINTED comment */
                return;
 
-       fn = lbasename(curr_pos.p_file);
-       (void)printf("%s(%d): warning: ", fn, curr_pos.p_line);
+       fn = lbasename(pos.p_file);
+       (void)printf("%s(%d): warning: ", fn, pos.p_line);
        (void)vprintf(msgs[n], ap);
        (void)printf(" [%d]\n", n);
        if (wflag)
@@ -523,13 +523,38 @@
        print_stack_trace();
 }
 
+static void
+vmessage_at(int n, pos_t pos, va_list ap)
+{
+       const char *fn;
+
+       if (ERR_ISSET(n, &msgset))
+               return;
+
+       fn = lbasename(pos.p_file);
+       (void)printf("%s(%d): ", fn, pos.p_line);
+       (void)vprintf(msgs[n], ap);
+       (void)printf(" [%d]\n", n);
+       print_stack_trace();
+}
+
+void
+(error_at)(int n, pos_t pos, ...)
+{
+       va_list ap;
+
+       va_start(ap, pos);
+       verror_at(pos, n, ap);
+       va_end(ap);
+}
+
 void
 (error)(int n, ...)
 {
        va_list ap;
 
        va_start(ap, n);
-       verror(n, ap);
+       verror_at(curr_pos, n, ap);
        va_end(ap);
 }
 
@@ -564,12 +589,32 @@
 }
 
 void
+(warning_at)(int n, pos_t pos, ...)
+{
+       va_list ap;
+
+       va_start(ap, pos);
+       vwarning_at(pos, n, ap);
+       va_end(ap);
+}
+
+void
 (warning)(int n, ...)
 {
        va_list ap;
 
        va_start(ap, n);
-       vwarning(n, ap);
+       vwarning_at(curr_pos, n, ap);
+       va_end(ap);
+}
+
+void
+(message_at)(int n, pos_t pos, ...)
+{
+       va_list ap;
+
+       va_start(ap, pos);
+       vmessage_at(n, pos, ap);
        va_end(ap);
 }
 
@@ -577,18 +622,10 @@
 (message)(int n, ...)
 {
        va_list ap;
-       const   char *fn;
-
-       if (ERR_ISSET(n, &msgset))
-               return;
 
        va_start(ap, n);
-       fn = lbasename(curr_pos.p_file);
-       (void)printf("%s(%d): ", fn, curr_pos.p_line);
-       (void)vprintf(msgs[n], ap);
-       (void)printf(" [%d]\n", n);
+       vmessage_at(n, curr_pos, ap);
        va_end(ap);
-       print_stack_trace();
 }
 
 /*
@@ -605,9 +642,9 @@
 
        va_start(ap, n);
        if (sflag && !extensions_ok) {
-               verror(n, ap);
+               verror_at(curr_pos, n, ap);
        } else if (sflag || !extensions_ok) {
-               vwarning(n, ap);
+               vwarning_at(curr_pos, n, ap);
        }
        va_end(ap);
 }
@@ -620,7 +657,7 @@
        if (c11flag || gflag)
                return;
        va_start(ap, n);
-       verror(n, ap);
+       verror_at(curr_pos, n, ap);
        va_end(ap);
 }
 
@@ -631,9 +668,9 @@
 
        va_start(ap, n);
        if (sflag && !gflag) {
-               verror(n, ap);
+               verror_at(curr_pos, n, ap);
        } else if (sflag || !gflag) {
-               vwarning(n, ap);
+               vwarning_at(curr_pos, n, ap);
        }
        va_end(ap);
 }
diff -r af1a7201a2fb -r 5fe5379e5cb7 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Apr 18 08:07:04 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Apr 18 08:52:04 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.106 2021/04/18 08:07:04 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.107 2021/04/18 08:52:04 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -120,6 +120,9 @@
 extern const char *const msgs[];
 
 extern void    msglist(void);
+extern void    error_at(int, pos_t, ...);
+extern void    warning_at(int, pos_t, ...);
+extern void    message_at(int, pos_t, ...);
 extern void    error(int, ...);
 extern void    warning(int, ...);
 extern void    message(int, ...);
diff -r af1a7201a2fb -r 5fe5379e5cb7 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Apr 18 08:07:04 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Apr 18 08:52:04 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.96 2021/04/18 07:31:47 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.97 2021/04/18 08:52:04 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -476,6 +476,19 @@
 {
 }
 
+#  define wrap_check_printf_at(func, id, pos, args...)                 \
+       do {                                                            \
+               check_printf(__CONCAT(MSG_, id), ##args);               \
+               (func)(id, pos, ##args);                                \
+       } while (/*CONSTCOND*/false)
+
+#  define error_at(id, pos, args...) \
+       wrap_check_printf_at(error_at, id, pos, ##args)
+#  define warning_at(id, pos, args...) \
+       wrap_check_printf_at(warning_at, id, pos, ##args)
+#  define message_at(id, pos, args...) \
+       wrap_check_printf_at(message_at, id, pos, ##args)
+
 #  define wrap_check_printf(func, id, args...)                         \
        do {                                                            \
                check_printf(__CONCAT(MSG_, id), ##args);               \



Home | Main Index | Thread Index | Old Index