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: move maximum seen subscript from b...
details: https://anonhg.NetBSD.org/src/rev/49ff20d510c9
branches: trunk
changeset: 1027741:49ff20d510c9
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Dec 18 13:06:33 2021 +0000
description:
lint: move maximum seen subscript from brace level to initialization
There is no need to store this information at every brace level since in
any translation unit that survives a conforming C99 compiler, an array
of unknown size is only possible once per initialization, not once per
brace level.
diffstat:
usr.bin/xlint/lint1/init.c | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diffs (90 lines):
diff -r 14bd745e267e -r 49ff20d510c9 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sat Dec 18 11:37:00 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Sat Dec 18 13:06:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.218 2021/12/18 11:25:15 rillig Exp $ */
+/* $NetBSD: init.c,v 1.219 2021/12/18 13:06:33 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.218 2021/12/18 11:25:15 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.219 2021/12/18 13:06:33 rillig Exp $");
#endif
#include <stdlib.h>
@@ -136,11 +136,6 @@
* unless a specific subscript is selected by a designator.
*/
size_t bl_subscript;
- /*
- * The maximum subscript that has ever be seen; only relevant for an
- * array of unknown size at the outermost brace level.
- */
- size_t bl_max_subscript;
bool bl_scalar_done: 1; /* for scalars */
bool bl_confused: 1; /* skip further checks */
@@ -161,6 +156,12 @@
struct brace_level *in_brace_level;
/*
+ * The maximum subscript that has ever be seen for an array of
+ * unknown size, which can only occur at the outermost brace level.
+ */
+ size_t in_max_subscript;
+
+ /*
* Is set when a structural error occurred in the initialization.
* The effect is that the rest of the initialization is ignored
* (parsed by yacc, expression trees built, but no initialization
@@ -595,7 +596,7 @@
* C99 6.7.8p17
*/
static void
-brace_level_advance(struct brace_level *bl)
+brace_level_advance(struct brace_level *bl, size_t *max_subscript)
{
switch (bl->bl_type->t_tspec) {
@@ -608,8 +609,8 @@
break;
case ARRAY:
bl->bl_subscript++;
- if (bl->bl_subscript > bl->bl_max_subscript)
- bl->bl_max_subscript = bl->bl_subscript;
+ if (bl->bl_subscript > *max_subscript)
+ *max_subscript = bl->bl_subscript;
break;
default:
bl->bl_scalar_done = true;
@@ -735,7 +736,7 @@
in->in_brace_level->bl_enclosing == NULL))
return;
- dim = in->in_brace_level->bl_max_subscript;
+ dim = in->in_max_subscript;
if (dim == 0 && (in->in_err || in->in_brace_level->bl_confused))
dim = 1; /* prevent "empty array declaration: %s" */
@@ -759,7 +760,7 @@
bl = in->in_brace_level;
if (bl != NULL)
- brace_level_advance(bl);
+ brace_level_advance(bl, &in->in_max_subscript);
if (bl != NULL)
designation_reset(&bl->bl_designation);
@@ -913,7 +914,7 @@
advance:
if (bl != NULL)
- brace_level_advance(bl);
+ brace_level_advance(bl, &in->in_max_subscript);
done:
if (bl != NULL)
designation_reset(&bl->bl_designation);
Home |
Main Index |
Thread Index |
Old Index