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: extend debug logging for declarati...



details:   https://anonhg.NetBSD.org/src/rev/0d382d7dd42f
branches:  trunk
changeset: 377231:0d382d7dd42f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 02 10:20:45 2023 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/debug.c    |  23 +++++++++++++++--------
 usr.bin/xlint/lint1/decl.c     |  42 +++++++++++++++++++++---------------------
 usr.bin/xlint/lint1/externs1.h |   8 ++++----
 usr.bin/xlint/lint1/func.c     |   6 +++---
 usr.bin/xlint/lint1/lex.c      |  11 +++++------
 5 files changed, 48 insertions(+), 42 deletions(-)

diffs (280 lines):

diff -r 37576163f4cd -r 0d382d7dd42f usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sun Jul 02 10:02:09 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sun Jul 02 10:20:45 2023 +0000
@@ -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
diff -r 37576163f4cd -r 0d382d7dd42f usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Jul 02 10:02:09 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Jul 02 10:20:45 2023 +0000
@@ -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));
-
-       lint_assert(dcs->d_enclosing != NULL);
-       dl = dcs;
+
+       debug_dcs(true);
+       debug_leave();
+
+       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
diff -r 37576163f4cd -r 0d382d7dd42f usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Jul 02 10:02:09 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Jul 02 10:20:45 2023 +0000
@@ -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()
diff -r 37576163f4cd -r 0d382d7dd42f usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Jul 02 10:02:09 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Jul 02 10:20:45 2023 +0000
@@ -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);
diff -r 37576163f4cd -r 0d382d7dd42f usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Jul 02 10:02:09 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Jul 02 10:20:45 2023 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index