From d82779b6ab01308d3589dea1637789b2e6e5d660 Mon Sep 17 00:00:00 2001 From: rillig Date: Fri, 1 Jan 2021 20:02:56 +0000 Subject: [PATCH] lint: add debug logging for initialization using named members --- usr.bin/xlint/lint1/init.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/usr.bin/xlint/lint1/init.c b/usr.bin/xlint/lint1/init.c index 7643b3f3a725..0496009faa10 100644 --- a/usr.bin/xlint/lint1/init.c +++ b/usr.bin/xlint/lint1/init.c @@ -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 #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 #include #include @@ -74,6 +73,19 @@ typedef struct istk { 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 @@ pop_member(void) } } +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 @@ mkinit(tnode_t *tn) 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;