Module Name:    src
Committed By:   rillig
Date:           Sun Jul  2 10:20:46 UTC 2023

Modified Files:
        src/usr.bin/xlint/lint1: debug.c decl.c externs1.h func.c lex.c

Log Message:
lint: extend debug logging for declaration levels

Indent the debug logging according to the declaration level.

Since there are a few cases where the enclosing declaration levels are
modified, log the whole declaration level stack whenever a level begins
or ends.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.334 -r1.335 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.185 -r1.186 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.164 -r1.165 src/usr.bin/xlint/lint1/lex.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/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.42 src/usr.bin/xlint/lint1/debug.c:1.43
--- src/usr.bin/xlint/lint1/debug.c:1.42	Sun Jul  2 08:16:19 2023
+++ src/usr.bin/xlint/lint1/debug.c	Sun Jul  2 10:20:45 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.42 2023/07/02 08:16:19 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.43 2023/07/02 10:20:45 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.42 2023/07/02 08:16:19 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.43 2023/07/02 10:20:45 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -393,8 +393,8 @@ debug_sym(const char *prefix, const sym_
 	debug_printf("%s", suffix);
 }
 
-void
-debug_dinfo(const decl_level *dl)
+static void
+debug_decl_level(const decl_level *dl)
 {
 
 	debug_print_indent();
@@ -446,11 +446,18 @@ debug_dinfo(const decl_level *dl)
 	     sym != NULL; sym = sym->s_next)
 		debug_sym(" func_proto_sym(", sym, ")");
 	debug_printf("\n");
+}
 
-	if (dl->d_enclosing != NULL) {
-		debug_indent_inc();
-		debug_dinfo(dl->d_enclosing);
-		debug_indent_dec();
+void
+debug_dcs(bool all)
+{
+	int prev_indentation = debug_indentation;
+	for (const decl_level *dl = dcs; dl != NULL; dl = dl->d_enclosing) {
+		debug_decl_level(dl);
+		if (!all)
+			return;
+		debug_indentation++;
 	}
+	debug_indentation = prev_indentation;
 }
 #endif

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.334 src/usr.bin/xlint/lint1/decl.c:1.335
--- src/usr.bin/xlint/lint1/decl.c:1.334	Sun Jul  2 09:40:25 2023
+++ src/usr.bin/xlint/lint1/decl.c	Sun Jul  2 10:20:45 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.334 2023/07/02 09:40:25 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.335 2023/07/02 10:20:45 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.334 2023/07/02 09:40:25 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.335 2023/07/02 10:20:45 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -71,7 +71,7 @@ static	bool	prototypes_compatible(const 
 static	bool	matches_no_arg_function(const type_t *, bool *);
 static	bool	check_old_style_definition(sym_t *, sym_t *);
 static	bool	check_prototype_declaration(sym_t *, sym_t *);
-static	sym_t	*new_style_function(sym_t *);
+static	void	check_prototype_parameters(sym_t *);
 static	void	old_style_function(sym_t *, sym_t *);
 static	void	declare_external_in_block(sym_t *);
 static	bool	check_init(sym_t *);
@@ -520,19 +520,20 @@ begin_declaration_level(decl_level_kind 
 	dl->d_kind = kind;
 	dl->d_last_dlsym = &dl->d_first_dlsym;
 	dcs = dl;
-	debug_step("%s(%s)", __func__, decl_level_kind_name(kind));
+	debug_enter();
+	debug_dcs(true);
 }
 
 void
 end_declaration_level(void)
 {
-	decl_level *dl;
 
-	debug_step("%s(%s)", __func__, decl_level_kind_name(dcs->d_kind));
+	debug_dcs(true);
+	debug_leave();
 
-	lint_assert(dcs->d_enclosing != NULL);
-	dl = dcs;
+	decl_level *dl = dcs;
 	dcs = dl->d_enclosing;
+	lint_assert(dcs != NULL);
 
 	switch (dl->d_kind) {
 	case DLK_STRUCT:
@@ -576,7 +577,7 @@ end_declaration_level(void)
 		/* FALLTHROUGH */
 	case DLK_PROTO_PARAMS:
 		/* usage of arguments will be checked by end_function() */
-		rmsyms(dl->d_first_dlsym);
+		symtab_remove_level(dl->d_first_dlsym);
 		break;
 	case DLK_EXTERN:
 		/* there is nothing around an external declarations */
@@ -1213,7 +1214,7 @@ sym_t *
 add_pointer(sym_t *decl, qual_ptr *p)
 {
 
-	debug_dinfo(dcs);
+	debug_dcs(false);
 
 	type_t **tpp = &decl->s_type;
 	while (*tpp != NULL && *tpp != dcs->d_type)
@@ -1283,7 +1284,7 @@ sym_t *
 add_array(sym_t *decl, bool dim, int n)
 {
 
-	debug_dinfo(dcs);
+	debug_dcs(false);
 
 	type_t **tpp = &decl->s_type;
 	while (*tpp != NULL && *tpp != dcs->d_type)
@@ -1317,7 +1318,7 @@ add_function(sym_t *decl, sym_t *args)
 {
 
 	debug_enter();
-	debug_dinfo(dcs);
+	debug_dcs(true);
 	debug_sym("decl: ", decl, "\n");
 #ifdef DEBUG
 	for (const sym_t *arg = args; arg != NULL; arg = arg->s_next)
@@ -1328,7 +1329,9 @@ add_function(sym_t *decl, sym_t *args)
 		if (!allow_c90)
 			/* function prototypes are illegal in traditional C */
 			warning(270);
-		args = new_style_function(args);
+		check_prototype_parameters(args);
+		if (args != NULL && args->s_type->t_tspec == VOID)
+			args = NULL;
 	} else
 		old_style_function(decl, args);
 
@@ -1372,12 +1375,13 @@ add_function(sym_t *decl, sym_t *args)
 	    dcs->d_prototype, args, dcs->d_vararg);
 
 	debug_step("add_function: '%s'", type_name(decl->s_type));
+	debug_dcs(true);
 	debug_leave();
 	return decl;
 }
 
-static sym_t *
-new_style_function(sym_t *args)
+static void
+check_prototype_parameters(sym_t *args)
 {
 
 	for (sym_t *sym = dcs->d_first_dlsym;
@@ -1397,10 +1401,6 @@ new_style_function(sym_t *args)
 			arg->s_type = gettyp(INT);
 		}
 	}
-
-	if (args == NULL || args->s_type->t_tspec == VOID)
-		return NULL;
-	return args;
 }
 
 static void

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.185 src/usr.bin/xlint/lint1/externs1.h:1.186
--- src/usr.bin/xlint/lint1/externs1.h:1.185	Sat Jul  1 09:31:55 2023
+++ src/usr.bin/xlint/lint1/externs1.h	Sun Jul  2 10:20:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.185 2023/07/01 09:31:55 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.186 2023/07/02 10:20:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -90,7 +90,7 @@ void	clean_up_after_error(void);
 sym_t	*pushdown(const sym_t *);
 sym_t	*mktempsym(type_t *);
 void	rmsym(sym_t *);
-void	rmsyms(sym_t *);
+void	symtab_remove_level(sym_t *);
 void	inssym(int, sym_t *);
 void	freeyyv(void *, int);
 int	yylex(void);
@@ -122,7 +122,7 @@ const char *decl_level_kind_name(decl_le
 const char *scl_name(scl_t);
 const char *symt_name(symt_t);
 const char *tqual_name(tqual_t);
-void	debug_dinfo(const decl_level *);
+void	debug_dcs(bool);
 void	debug_node(const tnode_t *);
 void	debug_type(const type_t *);
 void	debug_sym(const char *, const sym_t *, const char *);
@@ -138,7 +138,7 @@ void	debug_leave_func(const char *);
 #define	debug_leave()		debug_leave_func(__func__)
 #else
 #define	debug_noop()		do { } while (false)
-#define	debug_dinfo(d)		debug_noop()
+#define	debug_dcs(all)		debug_noop()
 #define	debug_sym(p, sym, s)	debug_noop()
 #define	debug_symtab()		debug_noop()
 #define	debug_node(tn)		debug_noop()

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.161 src/usr.bin/xlint/lint1/func.c:1.162
--- src/usr.bin/xlint/lint1/func.c:1.161	Sat Jul  1 09:31:55 2023
+++ src/usr.bin/xlint/lint1/func.c	Sun Jul  2 10:20:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.161 2023/07/01 09:31:55 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.162 2023/07/02 10:20:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.161 2023/07/01 09:31:55 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.162 2023/07/02 10:20:45 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -421,7 +421,7 @@ end_function(void)
 	 */
 	lint_assert(dcs->d_enclosing == NULL);
 	lint_assert(dcs->d_kind == DLK_EXTERN);
-	rmsyms(dcs->d_func_proto_syms);
+	symtab_remove_level(dcs->d_func_proto_syms);
 
 	/* must be set on level 0 */
 	set_reached(true);

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.164 src/usr.bin/xlint/lint1/lex.c:1.165
--- src/usr.bin/xlint/lint1/lex.c:1.164	Fri Jun 30 21:39:54 2023
+++ src/usr.bin/xlint/lint1/lex.c	Sun Jul  2 10:20:45 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.164 2023/06/30 21:39:54 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.165 2023/07/02 10:20:45 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.164 2023/06/30 21:39:54 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.165 2023/07/02 10:20:45 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -1403,14 +1403,13 @@ rmsym(sym_t *sym)
  * given symbol.
  */
 void
-rmsyms(sym_t *syms)
+symtab_remove_level(sym_t *syms)
 {
-	sym_t *sym;
 
 	/* Note the use of s_level_next instead of s_symtab_next. */
-	for (sym = syms; sym != NULL; sym = sym->s_level_next) {
+	for (sym_t *sym = syms; sym != NULL; sym = sym->s_level_next) {
 		if (sym->s_block_level != -1) {
-			debug_step("rmsyms '%s' %s '%s'",
+			debug_step("symtab_remove_level '%s' %s '%s'",
 			    sym->s_name, symt_name(sym->s_kind),
 			    type_name(sym->s_type));
 			symtab_remove(sym);

Reply via email to