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: rename initstack_element to brace_...
details: https://anonhg.NetBSD.org/src/rev/8aa5f42f0797
branches: trunk
changeset: 1019990:8aa5f42f0797
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Mar 27 19:48:00 2021 +0000
description:
lint: rename initstack_element to brace_level
No functional change.
diffstat:
usr.bin/xlint/lint1/init.c | 416 ++++++++++++++++++++++----------------------
1 files changed, 209 insertions(+), 207 deletions(-)
diffs (truncated from 966 to 300 lines):
diff -r 0d5af7e73947 -r 8aa5f42f0797 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sat Mar 27 18:55:02 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Sat Mar 27 19:48:00 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.138 2021/03/27 16:37:12 rillig Exp $ */
+/* $NetBSD: init.c,v 1.139 2021/03/27 19:48:00 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.138 2021/03/27 16:37:12 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.139 2021/03/27 19:48:00 rillig Exp $");
#endif
#include <stdlib.h>
@@ -78,14 +78,11 @@
* init_rbrace for each '}'
* end_initialization
*
- * The state of the current initialization is stored in initstk, a stack of
- * initstack_element, one element per type aggregate level.
- * XXX: Or is that "one element per brace level"? C99 mandates in 6.7.8p17
- * that "each brace-enclosed initializer list has an associated current
- * object".
+ * Each '{' begins a new brace level, each '}' ends the current brace level.
+ * Each brace level has an associated "current object".
*
- * Most of the time, the topmost level of initstk contains a scalar type, and
- * its remaining count toggles between 1 and 0.
+ * Most of the time, the topmost level of brace_level contains a scalar type,
+ * and its remaining count toggles between 1 and 0.
*
* See also:
* C99 6.7.8 "Initialization"
@@ -94,7 +91,7 @@
/*
- * Describes a single level of an ongoing initialization.
+ * Describes a single brace level of an ongoing initialization.
*
* XXX: Since C99, the initializers can be listed in arbitrary order by using
* designators to specify the sub-object to be initialized. The member names
@@ -104,10 +101,11 @@
* See C99 6.7.8, which spans 6 pages full of tricky details and carefully
* selected examples.
*/
-typedef struct initstack_element {
+struct brace_level {
/*
- * The type to be initialized at this level.
+ * The type of the current object that is initialized at this brace
+ * level.
*
* On the outermost element, this is always NULL since the outermost
* initializer-expression may be enclosed in an optional pair of
@@ -119,7 +117,7 @@
*
* Everywhere else it is nonnull.
*/
- type_t *i_type;
+ type_t *bl_type;
/*
* The type that will be initialized at the next initialization level,
@@ -130,19 +128,19 @@
* For a struct or union type, it is one of the member types, but
* without 'const'.
*
- * The outermost stack element has no i_type but nevertheless has
- * i_subt. For example, in 'int var = { 12345 }', initially there is
- * an initstack_element with i_subt 'int'. When the '{' is processed,
- * an element with i_type 'int' is pushed to the stack. When the
+ * The outermost stack element has no bl_type but nevertheless has
+ * bl_subtype. For example, in 'int var = { 12345 }', initially there
+ * is a brace_level with bl_subtype 'int'. When the '{' is processed,
+ * an element with bl_type 'int' is pushed to the stack. When the
* corresponding '}' is processed, the inner element is popped again.
*
* During initialization, only the top 2 elements of the stack are
* looked at.
*
- * XXX: Having i_subt here is the wrong approach, it should not be
- * necessary at all; see i_type.
+ * XXX: Having bl_subtype here is the wrong approach, it should not be
+ * necessary at all; see bl_type.
*/
- type_t *i_subt;
+ type_t *bl_subtype;
/*
* Whether this level of the initializer requires a '}' to be
@@ -152,16 +150,13 @@
* an inner array; for example, { 1, 2, 3, 4 } is a valid initializer
* for 'int arr[2][2]'.
*
- * TODO: Do structs containing structs need a closing brace?
- * TODO: Do arrays of structs need a closing brace after each struct?
- *
* XXX: Double-check whether this is the correct approach at all; see
- * i_type.
+ * bl_type.
*/
- bool i_brace: 1;
+ bool bl_brace: 1;
- /* Whether i_type is an array of unknown size. */
- bool i_array_of_unknown_size: 1;
+ /* Whether bl_type is an array of unknown size. */
+ bool bl_array_of_unknown_size: 1;
/*
* XXX: This feels wrong. Whether or not there has been a named
@@ -169,15 +164,15 @@
* all. Even after an initializer with designation, counting of the
* remaining elements continues, see C99 6.7.8p17.
*/
- bool i_seen_named_member: 1;
+ bool bl_seen_named_member: 1;
/*
* For structs, the next member to be initialized by a designator-less
* initializer.
*/
- sym_t *i_next_member;
+ sym_t *bl_next_member;
- /* TODO: Add i_next_subscript for arrays. */
+ /* TODO: Add bl_next_subscript for arrays. */
/* TODO: Understand C99 6.7.8p17 and footnote 128 for unions. */
@@ -197,10 +192,10 @@
* XXX: for arrays?
*
* XXX: Having the count of remaining objects should not be necessary.
- * It is probably clearer to use i_next_member and i_next_subscript
+ * It is probably clearer to use bl_next_member and bl_next_subscript
* for this purpose.
*/
- int i_remaining;
+ int bl_remaining;
/*
* The initialization state of the enclosing data structure
@@ -210,9 +205,8 @@
* in redundant braces such as '{{{{ 0 }}}}' (not yet implemented as
* of 2021-03-25).
*/
- struct initstack_element *i_enclosing;
-
-} initstack_element;
+ struct brace_level *bl_enclosing;
+};
/*
* A single component on the path to the sub-object that is initialized by an
@@ -248,11 +242,11 @@
*/
bool initerr;
- /* Pointer to the symbol which is to be initialized. */
+ /* The symbol that is to be initialized. */
sym_t *initsym;
- /* Points to the top element of the initialization stack. */
- initstack_element *initstk;
+ /* The innermost brace level. */
+ struct brace_level *brace_level;
/*
* The C99 designator, if any, for the current initialization
@@ -301,26 +295,26 @@
return *current_designation_mod();
}
-static const initstack_element *
-current_initstk(void)
+static const struct brace_level *
+current_brace_level(void)
{
- return current_init()->initstk;
+ return current_init()->brace_level;
}
-static initstack_element **
-current_initstk_lvalue(void)
+static struct brace_level **
+current_brace_level_lvalue(void)
{
- return ¤t_init()->initstk;
+ return ¤t_init()->brace_level;
}
static void
free_initialization(struct initialization *in)
{
- initstack_element *el, *next;
+ struct brace_level *level, *next;
- for (el = in->initstk; el != NULL; el = next) {
- next = el->i_enclosing;
- free(el);
+ for (level = in->brace_level; level != NULL; level = next) {
+ next = level->bl_enclosing;
+ free(level);
}
free(in);
@@ -328,8 +322,8 @@
#define initerr (*current_initerr())
#define initsym (*current_initsym())
-#define initstk (current_initstk())
-#define initstk_lvalue (*current_initstk_lvalue())
+#define brace_level_rvalue (current_brace_level())
+#define brace_level_lvalue (*current_brace_level_lvalue())
#ifndef DEBUG
@@ -339,7 +333,7 @@
#define debug_step(fmt, ...) do { } while (false)
#define debug_leave(a) do { } while (false)
#define debug_designation() do { } while (false)
-#define debug_initstack_element(elem) do { } while (false)
+#define debug_brace_level(level) do { } while (false)
#define debug_initstack() do { } while (false)
#else
@@ -403,32 +397,32 @@
/*
* TODO: only log the top of the stack after each modifying operation
*
- * TODO: wrap all write accesses to initstack_element in setter functions
+ * TODO: wrap all write accesses to brace_level in setter functions
*/
static void
-debug_initstack_element(const initstack_element *elem)
+debug_brace_level(const struct brace_level *level)
{
- if (elem->i_type != NULL)
- debug_printf("type '%s'", type_name(elem->i_type));
- if (elem->i_type != NULL && elem->i_subt != NULL)
+ if (level->bl_type != NULL)
+ debug_printf("type '%s'", type_name(level->bl_type));
+ if (level->bl_type != NULL && level->bl_subtype != NULL)
debug_printf(", ");
- if (elem->i_subt != NULL)
- debug_printf("subtype '%s'", type_name(elem->i_subt));
+ if (level->bl_subtype != NULL)
+ debug_printf("subtype '%s'", type_name(level->bl_subtype));
- if (elem->i_brace)
+ if (level->bl_brace)
debug_printf(", needs closing brace");
- if (elem->i_array_of_unknown_size)
+ if (level->bl_array_of_unknown_size)
debug_printf(", array of unknown size");
- if (elem->i_seen_named_member)
+ if (level->bl_seen_named_member)
debug_printf(", seen named member");
- const type_t *eff_type = elem->i_type != NULL
- ? elem->i_type : elem->i_subt;
- if (eff_type->t_tspec == STRUCT && elem->i_next_member != NULL)
+ const type_t *eff_type = level->bl_type != NULL
+ ? level->bl_type : level->bl_subtype;
+ if (eff_type->t_tspec == STRUCT && level->bl_next_member != NULL)
debug_printf(", next member '%s'",
- elem->i_next_member->s_name);
+ level->bl_next_member->s_name);
- debug_printf(", remaining %d\n", elem->i_remaining);
+ debug_printf(", remaining %d\n", level->bl_remaining);
}
/*
@@ -437,17 +431,17 @@
static void
debug_initstack(void)
{
- if (initstk == NULL) {
- debug_step("initstk is empty");
+ if (brace_level_rvalue == NULL) {
+ debug_step("no brace level in the current initialization");
return;
}
size_t i = 0;
- for (const initstack_element *elem = initstk;
- elem != NULL; elem = elem->i_enclosing) {
+ for (const struct brace_level *level = brace_level_rvalue;
+ level != NULL; level = level->bl_enclosing) {
debug_indent();
- debug_printf("initstk[%zu]: ", i);
- debug_initstack_element(elem);
Home |
Main Index |
Thread Index |
Old Index