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: add debug logging for initializati...



details:   https://anonhg.NetBSD.org/src/rev/b38dfede51b2
branches:  trunk
changeset: 1017610:b38dfede51b2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 01 20:02:56 2021 +0000

description:
lint: add debug logging for initialization using named members

diffstat:

 usr.bin/xlint/lint1/init.c |  35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diffs (72 lines):

diff -r 82521c2c47bf -r b38dfede51b2 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Fri Jan 01 19:28:51 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Fri Jan 01 20:02:56 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.54 2021/01/01 19:28:51 rillig Exp $ */
+/*     $NetBSD: init.c,v 1.55 2021/01/01 20:02:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,10 +37,9 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.54 2021/01/01 19:28:51 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.55 2021/01/01 20:02:56 rillig Exp $");
 #endif
 
-#include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -74,6 +73,19 @@
        struct  istk *i_next;           /* previous level */
 } istk_t;
 
+/*
+ * The names for a nested C99 initialization designator, in a circular list.
+ *
+ * Example:
+ *     struct stat st = {
+ *             .st_size = 123,
+ *             .st_mtim.tv_sec = 45,
+ *             .st_mtim.tv_nsec
+ *     };
+ *
+ *     During initialization, this list first contains ["st_size"], then
+ *     ["st_mtim", "tv_sec"], then ["st_mtim", "tv_nsec"].
+ */
 typedef struct namlist {
        const char *n_name;
        struct namlist *n_prev;
@@ -144,6 +156,21 @@
        }
 }
 
+static void
+named_member_dprint(void)
+{
+       namlist_t *name;
+
+       if (namedmem == NULL)
+               return;
+       name = namedmem;
+       DPRINTF(("named member:"));
+       do {
+               DPRINTF((" %s", name->n_name));
+               name = name->n_next;
+       } while (name != namedmem);
+       DPRINTF(("\n"));
+}
 
 /*
  * Initialize the initialisation stack by putting an entry for the variable
@@ -546,6 +573,8 @@
        DPRINTF(("%s: type=%s, value=%s\n", __func__,
            tyname(buf, sizeof(buf), tn->tn_type),
            print_tnode(sbuf, sizeof(sbuf), tn)));
+       named_member_dprint();
+
        if (initerr || tn == NULL)
                return;
 



Home | Main Index | Thread Index | Old Index