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: remove option -d, clean up debug l...



details:   https://anonhg.NetBSD.org/src/rev/f747e3f6b080
branches:  trunk
changeset: 984957:f747e3f6b080
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 01 18:37:29 2021 +0000

description:
lint: remove option -d, clean up debug logging

The command line option -d was not used by /usr/bin/lint, and it only
triggered a handful of debug messages.  Move this debug logging over to
the compile-time -DDEBUG setting.

Move display_expression further up to avoid the forward declaration.

diffstat:

 usr.bin/xlint/lint1/decl.c     |   11 +--
 usr.bin/xlint/lint1/externs1.h |    3 +-
 usr.bin/xlint/lint1/main1.c    |   10 +--
 usr.bin/xlint/lint1/tree.c     |  132 ++++++++++++++++++++--------------------
 4 files changed, 72 insertions(+), 84 deletions(-)

diffs (282 lines):

diff -r c8700b9b361f -r f747e3f6b080 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Aug 01 18:13:53 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Aug 01 18:37:29 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.216 2021/08/01 06:40:37 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.217 2021/08/01 18:37:29 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: decl.c,v 1.216 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.217 2021/08/01 18:37:29 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -649,8 +649,7 @@
        dcs = di;
        di->d_ctx = sc;
        di->d_ldlsym = &di->d_dlsyms;
-       if (dflag)
-               (void)printf("%s(%p %s)\n", __func__, dcs, scl_name(sc));
+       debug_step("%s(%p %s)", __func__, dcs, scl_name(sc));
 }
 
 /*
@@ -661,9 +660,7 @@
 {
        dinfo_t *di;
 
-       if (dflag)
-               (void)printf("%s(%p %s)\n",
-                   __func__, dcs, scl_name(dcs->d_ctx));
+       debug_step("%s(%p %s)", __func__, dcs, scl_name(dcs->d_ctx));
 
        lint_assert(dcs->d_next != NULL);
        di = dcs;
diff -r c8700b9b361f -r f747e3f6b080 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Aug 01 18:13:53 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Aug 01 18:37:29 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.126 2021/07/31 19:12:35 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.127 2021/08/01 18:37:29 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,6 @@
 extern bool    bflag;
 extern bool    cflag;
 extern bool    c11flag;
-extern bool    dflag;
 extern bool    eflag;
 extern bool    Fflag;
 extern bool    gflag;
diff -r c8700b9b361f -r f747e3f6b080 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Sun Aug 01 18:13:53 2021 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Sun Aug 01 18:37:29 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.51 2021/08/01 06:40:37 rillig Exp $        */
+/*     $NetBSD: main1.c,v 1.52 2021/08/01 18:37:29 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.51 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.52 2021/08/01 18:37:29 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -71,9 +71,6 @@
 /* Allow features from C11, C99 and C90. */
 bool   c11flag;
 
-/* Print various debug information. */
-bool   dflag;
-
 /* Perform stricter checking of enum types and operations on enum types. */
 bool   eflag;
 
@@ -186,7 +183,6 @@
                case 'a':       aflag++;        break;
                case 'b':       bflag = true;   break;
                case 'c':       cflag = true;   break;
-               case 'd':       dflag = true;   break;
                case 'e':       eflag = true;   break;
                case 'F':       Fflag = true;   break;
                case 'g':       gflag = true;   break;
@@ -257,8 +253,6 @@
 #ifdef DEBUG
        setvbuf(stdout, NULL, _IONBF, 0);
 #endif
-       if (dflag)
-               setvbuf(stdout, NULL, _IONBF, 0);
 #ifdef YYDEBUG
        if (yflag)
                yydebug = 1;
diff -r c8700b9b361f -r f747e3f6b080 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Aug 01 18:13:53 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Aug 01 18:37:29 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.324 2021/08/01 14:45:39 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.325 2021/08/01 18:37:29 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.324 2021/08/01 14:45:39 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.325 2021/08/01 18:37:29 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -90,7 +90,6 @@
 static tnode_t *check_function_arguments(type_t *, tnode_t *);
 static tnode_t *check_prototype_argument(int, type_t *, tnode_t *);
 static void    check_null_effect(const tnode_t *);
-static void    display_expression(const tnode_t *, int);
 static void    check_array_index(tnode_t *, bool);
 static void    check_integer_comparison(op_t, tnode_t *, tnode_t *);
 static void    check_precedence_confusion(tnode_t *);
@@ -3603,8 +3602,7 @@
 
        if (tn == NULL) {
                lint_assert(nerr != 0);
-               if (dflag)
-                       printf("constant node is null; returning 1 instead\n");
+               debug_step("constant node is null; returning 1 instead");
                v->v_tspec = INT;
                v->v_quad = 1;
                return v;
@@ -3645,6 +3643,67 @@
               tn->tn_op == CON && tn->tn_val->v_quad == 0;
 }
 
+#ifdef DEBUG
+/* Dump an expression to stdout. */
+static void
+display_expression(const tnode_t *tn, int offs)
+{
+       uint64_t uq;
+
+       if (tn == NULL) {
+               (void)printf("%*s%s\n", offs, "", "NULL");
+               return;
+       }
+       (void)printf("%*sop %s  ", offs, "", op_name(tn->tn_op));
+
+       if (tn->tn_op == NAME) {
+               (void)printf("%s: %s ",
+                   tn->tn_sym->s_name,
+                   storage_class_name(tn->tn_sym->s_scl));
+       } else if (tn->tn_op == CON && is_floating(tn->tn_type->t_tspec)) {
+               (void)printf("%#g ", (double)tn->tn_val->v_ldbl);
+       } else if (tn->tn_op == CON && is_integer(tn->tn_type->t_tspec)) {
+               uq = tn->tn_val->v_quad;
+               (void)printf("0x %08lx %08lx ",
+                   (long)(uq >> 32) & 0xffffffffl,
+                   (long)uq & 0xffffffffl);
+       } else if (tn->tn_op == CON && tn->tn_type->t_tspec == BOOL) {
+               (void)printf("%s ",
+                   tn->tn_val->v_quad != 0 ? "true" : "false");
+       } else if (tn->tn_op == CON) {
+               lint_assert(tn->tn_type->t_tspec == PTR);
+               (void)printf("0x%0*lx ", (int)(sizeof(void *) * CHAR_BIT / 4),
+                   (u_long)tn->tn_val->v_quad);
+       } else if (tn->tn_op == STRING) {
+               if (tn->tn_string->st_tspec == CHAR) {
+                       (void)printf("\"%s\"", tn->tn_string->st_cp);
+               } else {
+                       char    *s;
+                       size_t  n;
+                       n = MB_CUR_MAX * (tn->tn_string->st_len + 1);
+                       s = xmalloc(n);
+                       (void)wcstombs(s, tn->tn_string->st_wcp, n);
+                       (void)printf("L\"%s\"", s);
+                       free(s);
+               }
+               (void)printf(" ");
+       } else if (tn->tn_op == FSEL) {
+               (void)printf("o=%d, l=%d ", tn->tn_type->t_foffs,
+                   tn->tn_type->t_flen);
+       }
+       (void)printf("%s\n", type_name(tn->tn_type));
+       if (tn->tn_op == NAME || tn->tn_op == CON || tn->tn_op == STRING)
+               return;
+       display_expression(tn->tn_left, offs + 2);
+       if (modtab[tn->tn_op].m_binary ||
+       (tn->tn_op == PUSH && tn->tn_right != NULL)) {
+               display_expression(tn->tn_right, offs + 2);
+       }
+}
+#else
+#define        display_expression(tn, offs)    debug_noop()
+#endif
+
 /*
  * Perform some tests on expressions which can't be done in build_binary()
  * and functions called by build_binary(). These tests must be done here
@@ -3687,8 +3746,7 @@
                if (tn->tn_op != COMMA && !vctx && !tctx)
                        check_null_effect(tn);
        }
-       if (dflag)
-               display_expression(tn, 0);
+       display_expression(tn, 0);
 
        /* free the tree memory */
        if (dofreeblk)
@@ -3733,66 +3791,6 @@
 }
 
 /*
- * Dump an expression to stdout
- * only used for debugging
- */
-static void
-display_expression(const tnode_t *tn, int offs)
-{
-       uint64_t uq;
-
-       if (tn == NULL) {
-               (void)printf("%*s%s\n", offs, "", "NULL");
-               return;
-       }
-       (void)printf("%*sop %s  ", offs, "", op_name(tn->tn_op));
-
-       if (tn->tn_op == NAME) {
-               (void)printf("%s: %s ",
-                   tn->tn_sym->s_name,
-                   storage_class_name(tn->tn_sym->s_scl));
-       } else if (tn->tn_op == CON && is_floating(tn->tn_type->t_tspec)) {
-               (void)printf("%#g ", (double)tn->tn_val->v_ldbl);
-       } else if (tn->tn_op == CON && is_integer(tn->tn_type->t_tspec)) {
-               uq = tn->tn_val->v_quad;
-               (void)printf("0x %08lx %08lx ",
-                   (long)(uq >> 32) & 0xffffffffl,
-                   (long)uq & 0xffffffffl);
-       } else if (tn->tn_op == CON && tn->tn_type->t_tspec == BOOL) {
-               (void)printf("%s ",
-                   tn->tn_val->v_quad != 0 ? "true" : "false");
-       } else if (tn->tn_op == CON) {
-               lint_assert(tn->tn_type->t_tspec == PTR);
-               (void)printf("0x%0*lx ", (int)(sizeof(void *) * CHAR_BIT / 4),
-                            (u_long)tn->tn_val->v_quad);
-       } else if (tn->tn_op == STRING) {
-               if (tn->tn_string->st_tspec == CHAR) {
-                       (void)printf("\"%s\"", tn->tn_string->st_cp);
-               } else {
-                       char    *s;
-                       size_t  n;
-                       n = MB_CUR_MAX * (tn->tn_string->st_len + 1);
-                       s = xmalloc(n);
-                       (void)wcstombs(s, tn->tn_string->st_wcp, n);
-                       (void)printf("L\"%s\"", s);
-                       free(s);
-               }
-               (void)printf(" ");
-       } else if (tn->tn_op == FSEL) {
-               (void)printf("o=%d, l=%d ", tn->tn_type->t_foffs,
-                            tn->tn_type->t_flen);
-       }
-       (void)printf("%s\n", type_name(tn->tn_type));
-       if (tn->tn_op == NAME || tn->tn_op == CON || tn->tn_op == STRING)
-               return;
-       display_expression(tn->tn_left, offs + 2);
-       if (modtab[tn->tn_op].m_binary ||
-           (tn->tn_op == PUSH && tn->tn_right != NULL)) {
-               display_expression(tn->tn_right, offs + 2);
-       }
-}
-
-/*
  * Called by expr() to recursively perform some tests.
  */
 /* ARGSUSED */



Home | Main Index | Thread Index | Old Index