Sun Apr 18 10:09:49 2021 UTC ()
lint: rename parameter to diagnostic functions and macros

The first parameter is not just an arbitrary number, it's a message ID.


(rillig)
diff -r1.114 -r1.115 src/usr.bin/xlint/lint1/err.c
diff -r1.98 -r1.99 src/usr.bin/xlint/lint1/lint1.h

cvs diff -r1.114 -r1.115 src/usr.bin/xlint/lint1/err.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/err.c 2021/04/18 10:02:16 1.114
+++ src/usr.bin/xlint/lint1/err.c 2021/04/18 10:09:49 1.115
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: err.c,v 1.114 2021/04/18 10:02:16 rillig Exp $ */ 1/* $NetBSD: err.c,v 1.115 2021/04/18 10:09:49 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) && !defined(lint) 39#if defined(__RCSID) && !defined(lint)
40__RCSID("$NetBSD: err.c,v 1.114 2021/04/18 10:02:16 rillig Exp $"); 40__RCSID("$NetBSD: err.c,v 1.115 2021/04/18 10:09:49 rillig Exp $");
41#endif 41#endif
42 42
43#include <sys/types.h> 43#include <sys/types.h>
44#include <stdarg.h> 44#include <stdarg.h>
45#include <stdlib.h> 45#include <stdlib.h>
46 46
47#include "lint1.h" 47#include "lint1.h"
48 48
49/* number of errors found */ 49/* number of errors found */
50int nerr; 50int nerr;
51 51
52/* number of syntax errors */ 52/* number of syntax errors */
53int sytxerr; 53int sytxerr;
@@ -474,97 +474,97 @@ lbasename(const char *path) @@ -474,97 +474,97 @@ lbasename(const char *path)
474 return path; 474 return path;
475 475
476 p = base = dir = path; 476 p = base = dir = path;
477 while (*p != '\0') { 477 while (*p != '\0') {
478 if (*p++ == '/') { 478 if (*p++ == '/') {
479 dir = base; 479 dir = base;
480 base = p; 480 base = p;
481 } 481 }
482 } 482 }
483 return *base != '\0' ? base : dir; 483 return *base != '\0' ? base : dir;
484} 484}
485 485
486static void 486static void
487verror_at(int n, pos_t pos, va_list ap) 487verror_at(int msgid, pos_t pos, va_list ap)
488{ 488{
489 const char *fn; 489 const char *fn;
490 490
491 if (ERR_ISSET(n, &msgset)) 491 if (ERR_ISSET(msgid, &msgset))
492 return; 492 return;
493 493
494 fn = lbasename(pos.p_file); 494 fn = lbasename(pos.p_file);
495 (void)printf("%s(%d): error: ", fn, pos.p_line); 495 (void)printf("%s(%d): error: ", fn, pos.p_line);
496 (void)vprintf(msgs[n], ap); 496 (void)vprintf(msgs[msgid], ap);
497 (void)printf(" [%d]\n", n); 497 (void)printf(" [%d]\n", msgid);
498 nerr++; 498 nerr++;
499 print_stack_trace(); 499 print_stack_trace();
500} 500}
501 501
502static void 502static void
503vwarning_at(int n, pos_t pos, va_list ap) 503vwarning_at(int msgid, pos_t pos, va_list ap)
504{ 504{
505 const char *fn; 505 const char *fn;
506 506
507 if (ERR_ISSET(n, &msgset)) 507 if (ERR_ISSET(msgid, &msgset))
508 return; 508 return;
509 509
510#ifdef DEBUG 510#ifdef DEBUG
511 printf("%s: lwarn=%d n=%d\n", __func__, lwarn, n); 511 printf("%s: lwarn=%d msgid=%d\n", __func__, lwarn, msgid);
512#endif 512#endif
513 if (lwarn == LWARN_NONE || lwarn == n) 513 if (lwarn == LWARN_NONE || lwarn == msgid)
514 /* this warning is suppressed by a LINTED comment */ 514 /* this warning is suppressed by a LINTED comment */
515 return; 515 return;
516 516
517 fn = lbasename(pos.p_file); 517 fn = lbasename(pos.p_file);
518 (void)printf("%s(%d): warning: ", fn, pos.p_line); 518 (void)printf("%s(%d): warning: ", fn, pos.p_line);
519 (void)vprintf(msgs[n], ap); 519 (void)vprintf(msgs[msgid], ap);
520 (void)printf(" [%d]\n", n); 520 (void)printf(" [%d]\n", msgid);
521 if (wflag) 521 if (wflag)
522 nerr++; 522 nerr++;
523 print_stack_trace(); 523 print_stack_trace();
524} 524}
525 525
526static void 526static void
527vmessage_at(int n, pos_t pos, va_list ap) 527vmessage_at(int msgid, pos_t pos, va_list ap)
528{ 528{
529 const char *fn; 529 const char *fn;
530 530
531 if (ERR_ISSET(n, &msgset)) 531 if (ERR_ISSET(msgid, &msgset))
532 return; 532 return;
533 533
534 fn = lbasename(pos.p_file); 534 fn = lbasename(pos.p_file);
535 (void)printf("%s(%d): ", fn, pos.p_line); 535 (void)printf("%s(%d): ", fn, pos.p_line);
536 (void)vprintf(msgs[n], ap); 536 (void)vprintf(msgs[msgid], ap);
537 (void)printf(" [%d]\n", n); 537 (void)printf(" [%d]\n", msgid);
538 print_stack_trace(); 538 print_stack_trace();
539} 539}
540 540
541void 541void
542(error_at)(int n, pos_t pos, ...) 542(error_at)(int msgid, pos_t pos, ...)
543{ 543{
544 va_list ap; 544 va_list ap;
545 545
546 va_start(ap, pos); 546 va_start(ap, pos);
547 verror_at(n, pos, ap); 547 verror_at(msgid, pos, ap);
548 va_end(ap); 548 va_end(ap);
549} 549}
550 550
551void 551void
552(error)(int n, ...) 552(error)(int msgid, ...)
553{ 553{
554 va_list ap; 554 va_list ap;
555 555
556 va_start(ap, n); 556 va_start(ap, msgid);
557 verror_at(n, curr_pos, ap); 557 verror_at(msgid, curr_pos, ap);
558 va_end(ap); 558 va_end(ap);
559} 559}
560 560
561void 561void
562internal_error(const char *file, int line, const char *msg, ...) 562internal_error(const char *file, int line, const char *msg, ...)
563{ 563{
564 va_list ap; 564 va_list ap;
565 const char *fn; 565 const char *fn;
566 566
567 fn = lbasename(curr_pos.p_file); 567 fn = lbasename(curr_pos.p_file);
568 (void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ", 568 (void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ",
569 file, line, fn, curr_pos.p_line); 569 file, line, fn, curr_pos.p_line);
570 va_start(ap, msg); 570 va_start(ap, msg);
@@ -579,98 +579,98 @@ void @@ -579,98 +579,98 @@ void
579assert_failed(const char *file, int line, const char *func, const char *cond) 579assert_failed(const char *file, int line, const char *func, const char *cond)
580{ 580{
581 const char *fn; 581 const char *fn;
582 582
583 fn = lbasename(curr_pos.p_file); 583 fn = lbasename(curr_pos.p_file);
584 (void)fprintf(stderr, 584 (void)fprintf(stderr,
585 "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n", 585 "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
586 cond, func, file, line, fn, curr_pos.p_line); 586 cond, func, file, line, fn, curr_pos.p_line);
587 print_stack_trace(); 587 print_stack_trace();
588 abort(); 588 abort();
589} 589}
590 590
591void 591void
592(warning_at)(int n, pos_t pos, ...) 592(warning_at)(int msgid, pos_t pos, ...)
593{ 593{
594 va_list ap; 594 va_list ap;
595 595
596 va_start(ap, pos); 596 va_start(ap, pos);
597 vwarning_at(n, pos, ap); 597 vwarning_at(msgid, pos, ap);
598 va_end(ap); 598 va_end(ap);
599} 599}
600 600
601void 601void
602(warning)(int n, ...) 602(warning)(int msgid, ...)
603{ 603{
604 va_list ap; 604 va_list ap;
605 605
606 va_start(ap, n); 606 va_start(ap, msgid);
607 vwarning_at(n, curr_pos, ap); 607 vwarning_at(msgid, curr_pos, ap);
608 va_end(ap); 608 va_end(ap);
609} 609}
610 610
611void 611void
612(message_at)(int n, pos_t pos, ...) 612(message_at)(int msgid, pos_t pos, ...)
613{ 613{
614 va_list ap; 614 va_list ap;
615 615
616 va_start(ap, pos); 616 va_start(ap, pos);
617 vmessage_at(n, pos, ap); 617 vmessage_at(msgid, pos, ap);
618 va_end(ap); 618 va_end(ap);
619} 619}
620 620
621void 621void
622(message)(int n, ...) 622(message)(int msgid, ...)
623{ 623{
624 va_list ap; 624 va_list ap;
625 625
626 va_start(ap, n); 626 va_start(ap, msgid);
627 vmessage_at(n, curr_pos, ap); 627 vmessage_at(msgid, curr_pos, ap);
628 va_end(ap); 628 va_end(ap);
629} 629}
630 630
631/* 631/*
632 * XXX I think the logic is possibly somewhat screwed up here. The 632 * XXX I think the logic is possibly somewhat screwed up here. The
633 * question is, how do we want to interpret the -s and -S flags going 633 * question is, how do we want to interpret the -s and -S flags going
634 * forward? We need to answer that and then we can fix this to be 634 * forward? We need to answer that and then we can fix this to be
635 * "right"... [perry, 2 Nov 2002] 635 * "right"... [perry, 2 Nov 2002]
636*/ 636*/
637void 637void
638(c99ism)(int n, ...) 638(c99ism)(int msgid, ...)
639{ 639{
640 va_list ap; 640 va_list ap;
641 bool extensions_ok = Sflag || gflag; 641 bool extensions_ok = Sflag || gflag;
642 642
643 va_start(ap, n); 643 va_start(ap, msgid);
644 if (sflag && !extensions_ok) { 644 if (sflag && !extensions_ok) {
645 verror_at(n, curr_pos, ap); 645 verror_at(msgid, curr_pos, ap);
646 } else if (sflag || !extensions_ok) { 646 } else if (sflag || !extensions_ok) {
647 vwarning_at(n, curr_pos, ap); 647 vwarning_at(msgid, curr_pos, ap);
648 } 648 }
649 va_end(ap); 649 va_end(ap);
650} 650}
651 651
652void 652void
653(c11ism)(int n, ...) 653(c11ism)(int msgid, ...)
654{ 654{
655 va_list ap; 655 va_list ap;
656 656
657 if (c11flag || gflag) 657 if (c11flag || gflag)
658 return; 658 return;
659 va_start(ap, n); 659 va_start(ap, msgid);
660 verror_at(n, curr_pos, ap); 660 verror_at(msgid, curr_pos, ap);
661 va_end(ap); 661 va_end(ap);
662} 662}
663 663
664void 664void
665(gnuism)(int n, ...) 665(gnuism)(int msgid, ...)
666{ 666{
667 va_list ap; 667 va_list ap;
668 668
669 va_start(ap, n); 669 va_start(ap, msgid);
670 if (sflag && !gflag) { 670 if (sflag && !gflag) {
671 verror_at(n, curr_pos, ap); 671 verror_at(msgid, curr_pos, ap);
672 } else if (sflag || !gflag) { 672 } else if (sflag || !gflag) {
673 vwarning_at(n, curr_pos, ap); 673 vwarning_at(msgid, curr_pos, ap);
674 } 674 }
675 va_end(ap); 675 va_end(ap);
676} 676}

cvs diff -r1.98 -r1.99 src/usr.bin/xlint/lint1/lint1.h (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/lint1.h 2021/04/18 10:04:23 1.98
+++ src/usr.bin/xlint/lint1/lint1.h 2021/04/18 10:09:49 1.99
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lint1.h,v 1.98 2021/04/18 10:04:23 rillig Exp $ */ 1/* $NetBSD: lint1.h,v 1.99 2021/04/18 10:09:49 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -466,51 +466,51 @@ typedef struct err_set { @@ -466,51 +466,51 @@ typedef struct err_set {
466 466
467extern err_set msgset; 467extern err_set msgset;
468 468
469 469
470#ifdef DEBUG 470#ifdef DEBUG
471# include "err-msgs.h" 471# include "err-msgs.h"
472 472
473/* ARGSUSED */ 473/* ARGSUSED */
474static inline void __attribute__((format(printf, 1, 2))) 474static inline void __attribute__((format(printf, 1, 2)))
475check_printf(const char *fmt, ...) 475check_printf(const char *fmt, ...)
476{ 476{
477} 477}
478 478
479# define wrap_check_printf_at(func, id, pos, args...) \ 479# define wrap_check_printf_at(func, msgid, pos, args...) \
480 do { \ 480 do { \
481 check_printf(__CONCAT(MSG_, id), ##args); \ 481 check_printf(__CONCAT(MSG_, msgid), ##args); \
482 (func)(id, pos, ##args); \ 482 (func)(msgid, pos, ##args); \
483 } while (/*CONSTCOND*/false) 483 } while (/*CONSTCOND*/false)
484 484
485# define error_at(id, pos, args...) \ 485# define error_at(msgid, pos, args...) \
486 wrap_check_printf_at(error_at, id, pos, ##args) 486 wrap_check_printf_at(error_at, msgid, pos, ##args)
487# define warning_at(id, pos, args...) \ 487# define warning_at(msgid, pos, args...) \
488 wrap_check_printf_at(warning_at, id, pos, ##args) 488 wrap_check_printf_at(warning_at, msgid, pos, ##args)
489# define message_at(id, pos, args...) \ 489# define message_at(msgid, pos, args...) \
490 wrap_check_printf_at(message_at, id, pos, ##args) 490 wrap_check_printf_at(message_at, msgid, pos, ##args)
491 491
492# define wrap_check_printf(func, id, args...) \ 492# define wrap_check_printf(func, msgid, args...) \
493 do { \ 493 do { \
494 check_printf(__CONCAT(MSG_, id), ##args); \ 494 check_printf(__CONCAT(MSG_, msgid), ##args); \
495 (func)(id, ##args); \ 495 (func)(msgid, ##args); \
496 } while (/*CONSTCOND*/false) 496 } while (/*CONSTCOND*/false)
497 497
498# define error(id, args...) wrap_check_printf(error, id, ##args) 498# define error(msgid, args...) wrap_check_printf(error, msgid, ##args)
499# define warning(id, args...) wrap_check_printf(warning, id, ##args) 499# define warning(msgid, args...) wrap_check_printf(warning, msgid, ##args)
500# define message(id, args...) wrap_check_printf(message, id, ##args) 500# define message(msgid, args...) wrap_check_printf(message, msgid, ##args)
501# define gnuism(id, args...) wrap_check_printf(gnuism, id, ##args) 501# define gnuism(msgid, args...) wrap_check_printf(gnuism, msgid, ##args)
502# define c99ism(id, args...) wrap_check_printf(c99ism, id, ##args) 502# define c99ism(msgid, args...) wrap_check_printf(c99ism, msgid, ##args)
503# define c11ism(id, args...) wrap_check_printf(c11ism, id, ##args) 503# define c11ism(msgid, args...) wrap_check_printf(c11ism, msgid, ##args)
504#endif 504#endif
505 505
506static inline bool 506static inline bool
507is_nonzero_val(const val_t *val) 507is_nonzero_val(const val_t *val)
508{ 508{
509 return is_floating(val->v_tspec) 509 return is_floating(val->v_tspec)
510 ? val->v_ldbl != 0.0 510 ? val->v_ldbl != 0.0
511 : val->v_quad != 0; 511 : val->v_quad != 0;
512} 512}
513 513
514static inline bool 514static inline bool
515constant_is_nonzero(const tnode_t *tn) 515constant_is_nonzero(const tnode_t *tn)
516{ 516{