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: in debug mode, print the initializ...



details:   https://anonhg.NetBSD.org/src/rev/fd7426793a51
branches:  trunk
changeset: 959623:fd7426793a51
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 20 17:44:39 2021 +0000

description:
lint: in debug mode, print the initialization stack

This is the central data structure of the initializations, it keeps
track of the objects that still need to be initialized.  Seeing its
contents in debug mode helps in finding and understanding the still
incomplete C99 support.

diffstat:

 usr.bin/xlint/lint1/init.c |  62 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diffs (275 lines):

diff -r b67c910c1a47 -r fd7426793a51 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sat Feb 20 17:24:37 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sat Feb 20 17:44:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.72 2021/02/20 17:24:37 rillig Exp $ */
+/*     $NetBSD: init.c,v 1.73 2021/02/20 17:44:39 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.72 2021/02/20 17:24:37 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.73 2021/02/20 17:44:39 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -227,6 +227,35 @@
 #define debug_named_member() (void)0
 #endif
 
+#ifdef DEBUG
+static void
+debug_initstack(void)
+{
+       static const char *const noyes[] = { "no", "yes" };
+
+       if (initstk == NULL) {
+               debug_step("initstk is empty");
+               return;
+       }
+
+       size_t i = 0;
+       for (const istk_t *elem = initstk; elem != NULL; elem = elem->i_next) {
+               debug_step("initstk[%zu]:", i);
+               debug_step("  i_type      = %s", type_name(elem->i_type));
+               debug_step("  i_subt      = %s", type_name(elem->i_subt));
+               debug_step("  i_brace     = %s", noyes[elem->i_brace]);
+               debug_step("  i_nolimit   = %s", noyes[elem->i_nolimit]);
+               debug_step("  i_namedmem  = %s", noyes[elem->i_namedmem]);
+               debug_step("  i_mem       = %s",
+                   elem->i_mem != NULL ? elem->i_mem->s_name : "(null)");
+               debug_step("  i_remaining = %d", elem->i_remaining);
+               i++;
+       }
+}
+#else
+#define debug_initstack() (void)0
+#endif
+
 /*
  * Initialize the initialisation stack by putting an entry for the variable
  * which is to be initialized on it.
@@ -258,6 +287,7 @@
        istk->i_subt = initsym->s_type;
        istk->i_remaining = 1;
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -305,6 +335,7 @@
                                istk->i_subt = m->s_type;
                                istk->i_remaining++;
                                pop_member();
+                               debug_initstack();
                                debug_leave();
                                return;
                        }
@@ -314,6 +345,7 @@
                debug_step("end rhs.name=%s", namedmem->n_name);
                pop_member();
                istk->i_namedmem = true;
+               debug_initstack();
                debug_leave();
                return;
        }
@@ -330,6 +362,7 @@
                } while (m->s_bitfield && m->s_name == unnamed);
                istk->i_subt = m->s_type;
        }
+       debug_initstack();
        debug_leave();
 }
 
@@ -343,11 +376,13 @@
        bool brace;
 
        debug_enter();
+       debug_initstack();
        do {
                brace = initstk->i_brace;
                debug_step("loop brace=%d", brace);
                initstack_pop_item();
        } while (!brace);
+       debug_initstack();
        debug_leave();
 }
 
@@ -360,9 +395,11 @@
 {
 
        debug_enter();
+       debug_initstack();
        while (!initstk->i_brace && initstk->i_remaining == 0 &&
               !initstk->i_nolimit)
                initstack_pop_item();
+       debug_initstack();
        debug_leave();
 }
 
@@ -374,6 +411,7 @@
        sym_t   *m;
 
        debug_enter();
+       debug_initstack();
 
        istk = initstk;
 
@@ -420,6 +458,7 @@
                        /* initialisation of an incomplete type */
                        error(175);
                        initerr = true;
+                       debug_initstack();
                        debug_leave();
                        return;
                }
@@ -440,6 +479,7 @@
                        /* initialisation of an incomplete type */
                        error(175);
                        initerr = true;
+                       debug_initstack();
                        debug_leave();
                        return;
                }
@@ -485,6 +525,7 @@
                        /* cannot init. struct/union with no named member */
                        error(179);
                        initerr = true;
+                       debug_initstack();
                        debug_leave();
                        return;
                }
@@ -503,6 +544,7 @@
                break;
        }
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -542,6 +584,7 @@
 {
 
        debug_enter();
+       debug_initstack();
 
        if (initstk->i_type != NULL && is_scalar(initstk->i_type->t_tspec)) {
                /* invalid initializer type %s */
@@ -558,6 +601,7 @@
                        initstk->i_type ? initstk->i_type : initstk->i_subt));
        }
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -565,6 +609,7 @@
 initstack_next_nobrace(void)
 {
        debug_enter();
+       debug_initstack();
 
        if (initstk->i_type == NULL && !is_scalar(initstk->i_subt->t_tspec)) {
                /* {}-enclosed initializer required */
@@ -588,6 +633,7 @@
                initstack_push();
        }
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -598,6 +644,7 @@
                return;
 
        debug_enter();
+       debug_initstack();
 
        if ((initsym->s_scl == AUTO || initsym->s_scl == REG) &&
            initstk->i_next == NULL) {
@@ -614,6 +661,7 @@
 
        initstack_next_brace();
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -624,9 +672,11 @@
                return;
 
        debug_enter();
+       debug_initstack();
 
        initstack_pop_brace();
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -643,6 +693,7 @@
        debug_enter();
        debug_named_member();
        debug_node(tn);
+       debug_initstack();
 
        if (initerr || tn == NULL) {
                debug_leave();
@@ -669,6 +720,7 @@
                ln->tn_type->t_const = false;
                tn = build(ASSIGN, ln, tn);
                expr(tn, false, false, false, false);
+               debug_initstack();
                debug_leave();
                return;
        }
@@ -681,12 +733,14 @@
 
        /* Initialisations by strings are done in initstack_string(). */
        if (initstack_string(tn)) {
+               debug_initstack();
                debug_leave();
                return;
        }
 
        initstack_next_nobrace();
        if (initerr || tn == NULL) {
+               debug_initstack();
                debug_leave();
                return;
        }
@@ -709,6 +763,7 @@
        lint_assert(is_scalar(lt));
 
        if (!typeok(INIT, 0, ln, tn)) {
+               debug_initstack();
                debug_leave();
                return;
        }
@@ -748,6 +803,7 @@
                }
        }
 
+       debug_initstack();
        debug_leave();
 }
 
@@ -764,6 +820,7 @@
                return false;
 
        debug_enter();
+       debug_initstack();
 
        istk = initstk;
        strg = tn->tn_string;
@@ -822,6 +879,7 @@
        /* In every case the array is initialized completely. */
        istk->i_remaining = 0;
 
+       debug_initstack();
        debug_leave();
        return true;
 }



Home | Main Index | Thread Index | Old Index