Module Name:    src
Committed By:   rillig
Date:           Sun Aug  1 18:37:29 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: decl.c externs1.h main1.c tree.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/xlint/lint1/main1.c
cvs rdiff -u -r1.324 -r1.325 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.216 src/usr.bin/xlint/lint1/decl.c:1.217
--- src/usr.bin/xlint/lint1/decl.c:1.216	Sun Aug  1 06:40:37 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun Aug  1 18:37:29 2021
@@ -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 @@ begin_declaration_level(scl_t sc)
 	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 @@ end_declaration_level(void)
 {
 	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;

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.126 src/usr.bin/xlint/lint1/externs1.h:1.127
--- src/usr.bin/xlint/lint1/externs1.h:1.126	Sat Jul 31 19:12:35 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sun Aug  1 18:37:29 2021
@@ -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	int	aflag;
 extern	bool	bflag;
 extern	bool	cflag;
 extern	bool	c11flag;
-extern	bool	dflag;
 extern	bool	eflag;
 extern	bool	Fflag;
 extern	bool	gflag;

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.51 src/usr.bin/xlint/lint1/main1.c:1.52
--- src/usr.bin/xlint/lint1/main1.c:1.51	Sun Aug  1 06:40:37 2021
+++ src/usr.bin/xlint/lint1/main1.c	Sun Aug  1 18:37:29 2021
@@ -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 @@ bool	cflag;
 /* 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 @@ main(int argc, char *argv[])
 		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 @@ main(int argc, char *argv[])
 #ifdef DEBUG
 	setvbuf(stdout, NULL, _IONBF, 0);
 #endif
-	if (dflag)
-		setvbuf(stdout, NULL, _IONBF, 0);
 #ifdef YYDEBUG
 	if (yflag)
 		yydebug = 1;

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.324 src/usr.bin/xlint/lint1/tree.c:1.325
--- src/usr.bin/xlint/lint1/tree.c:1.324	Sun Aug  1 14:45:39 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Aug  1 18:37:29 2021
@@ -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	*fold_float(tnode_t *);
 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 @@ constant(tnode_t *tn, bool required)
 
 	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 @@ is_constcond_false(const tnode_t *tn, ts
 	       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 @@ expr(tnode_t *tn, bool vctx, bool tctx, 
 		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 @@ check_null_effect(const tnode_t *tn)
 }
 
 /*
- * 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 */

Reply via email to