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: replace global variables with func...
details: https://anonhg.NetBSD.org/src/rev/8ec57fa09855
branches: trunk
changeset: 960744:8ec57fa09855
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Mar 28 09:20:51 2021 +0000
description:
lint: replace global variables with function parameters
No functional change.
diffstat:
usr.bin/xlint/lint1/init.c | 129 ++++++++++++++++++++------------------------
1 files changed, 60 insertions(+), 69 deletions(-)
diffs (truncated from 414 to 300 lines):
diff -r 8b7cc80c92b9 -r 8ec57fa09855 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sun Mar 28 09:11:38 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Sun Mar 28 09:20:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.147 2021/03/28 09:08:13 rillig Exp $ */
+/* $NetBSD: init.c,v 1.148 2021/03/28 09:20:51 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.147 2021/03/28 09:08:13 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.148 2021/03/28 09:20:51 rillig Exp $");
#endif
#include <stdlib.h>
@@ -534,7 +534,7 @@
#endif
/* XXX: unnecessary prototype since it is not recursive */
-static bool init_array_using_string(tnode_t *);
+static bool init_array_using_string(struct initialization *, tnode_t *);
static struct initialization *
@@ -556,18 +556,6 @@
return ¤t_init()->initsym;
}
-static struct designation *
-current_designation_mod(void)
-{
- return ¤t_init()->designation;
-}
-
-static struct designation
-current_designation(void)
-{
- return *current_designation_mod();
-}
-
static const struct brace_level *
current_brace_level(void)
{
@@ -633,12 +621,12 @@
void
designation_add_name(sbuf_t *sb)
{
- designation_add(current_designation_mod(),
+ designation_add(¤t_init()->designation,
designator_new(sb->sb_name));
}
/* TODO: Move the function body up here, to avoid the forward declaration. */
-static void initstack_pop_nobrace(void);
+static void initstack_pop_nobrace(struct initialization *);
static struct brace_level *
brace_level_new(type_t *type, type_t *subtype, int remaining)
@@ -705,7 +693,8 @@
debug_step("subscript range is %zu ... %zu",
range.lo, range.hi);
- initstack_pop_nobrace();
+ /* XXX: This call is wrong here, it must be somewhere else. */
+ initstack_pop_nobrace(current_init());
level = brace_level_lvalue;
if (level->bl_array_of_unknown_size) {
@@ -752,7 +741,8 @@
static void
initstack_pop_item_named_member(const char *name)
{
- struct brace_level *level = brace_level_lvalue;
+ struct initialization *in = current_init();
+ struct brace_level *level = in->brace_level;
const sym_t *m;
/*
@@ -775,7 +765,7 @@
/* undefined struct/union member: %s */
error(101, name);
- designation_shift_level(current_designation_mod());
+ designation_shift_level(&in->designation);
level->bl_seen_named_member = true;
return;
}
@@ -785,7 +775,7 @@
/* XXX: why ++? */
level->bl_remaining++;
/* XXX: why is bl_seen_named_member not set? */
- designation_shift_level(current_designation_mod());
+ designation_shift_level(&in->designation);
}
/* TODO: think of a better name than 'pop' */
@@ -807,10 +797,9 @@
/* TODO: think of a better name than 'pop' */
static void
-initstack_pop_item(void)
+initstack_pop_item(struct initialization *in)
{
struct brace_level *level;
- struct designator *first_designator;
debug_enter();
@@ -828,9 +817,8 @@
lint_assert(level->bl_remaining >= 0);
debug_step("%d elements remaining", level->bl_remaining);
- first_designator = current_designation().head;
- if (first_designator != NULL && first_designator->name != NULL)
- initstack_pop_item_named_member(first_designator->name);
+ if (in->designation.head != NULL && in->designation.head->name != NULL)
+ initstack_pop_item_named_member(in->designation.head->name);
else
initstack_pop_item_unnamed();
@@ -843,19 +831,19 @@
* from the stack.
*/
static void
-initstack_pop_brace(void)
+initstack_pop_brace(struct initialization *in)
{
bool brace;
debug_enter();
- initialization_debug(current_init());
+ initialization_debug(in);
do {
brace = brace_level_rvalue->bl_brace;
/* TODO: improve wording of the debug message */
debug_step("loop brace=%d", brace);
- initstack_pop_item();
+ initstack_pop_item(in);
} while (!brace);
- initialization_debug(current_init());
+ initialization_debug(in);
debug_leave();
}
@@ -865,14 +853,14 @@
*/
/* TODO: think of a better name than 'pop' */
static void
-initstack_pop_nobrace(void)
+initstack_pop_nobrace(struct initialization *in)
{
debug_enter();
- while (!brace_level_rvalue->bl_brace &&
- brace_level_rvalue->bl_remaining == 0 &&
- !brace_level_rvalue->bl_array_of_unknown_size)
- initstack_pop_item();
+ while (!in->brace_level->bl_brace &&
+ in->brace_level->bl_remaining == 0 &&
+ !in->brace_level->bl_array_of_unknown_size)
+ initstack_pop_item(in);
debug_leave();
}
@@ -909,9 +897,9 @@
/* TODO: document me */
/* TODO: think of a better name than 'push' */
static void
-initstack_push_array(void)
+initstack_push_array(struct initialization *in)
{
- struct brace_level *level = brace_level_lvalue;
+ struct brace_level *level = in->brace_level;
if (level->bl_enclosing->bl_seen_named_member) {
level->bl_brace = true;
@@ -933,7 +921,7 @@
level->bl_subtype = level->bl_type->t_subt;
level->bl_array_of_unknown_size = is_incomplete(level->bl_type);
level->bl_remaining = level->bl_type->t_dim;
- designation_debug(current_designation_mod());
+ designation_debug(&in->designation);
debug_step("type '%s' remaining %d",
type_name(level->bl_type), level->bl_remaining);
}
@@ -942,7 +930,7 @@
/* TODO: document me */
/* TODO: think of a better name than 'push' */
static bool
-initstack_push_struct_or_union(void)
+initstack_push_struct_or_union(struct initialization *in)
{
/*
* TODO: remove unnecessary 'const' for variables in functions that
@@ -960,15 +948,15 @@
}
cnt = 0;
- designation_debug(current_designation_mod());
+ designation_debug(&in->designation);
debug_step("lookup for '%s'%s",
type_name(level->bl_type),
level->bl_seen_named_member ? ", seen named member" : "");
m = brace_level_look_up_member_bloated(level,
- current_designation().head, &cnt);
+ in->designation.head, &cnt);
- if (current_designation().head != NULL) {
+ if (in->designation.head != NULL) {
if (m == NULL) {
debug_step("pop struct");
return true;
@@ -977,8 +965,8 @@
level->bl_subtype = m->s_type;
level->bl_seen_named_member = true;
debug_step("named member '%s'",
- current_designation().head->name);
- designation_shift_level(current_designation_mod());
+ in->designation.head->name);
+ designation_shift_level(&in->designation);
cnt = level->bl_type->t_tspec == STRUCT ? 2 : 1;
}
level->bl_brace = true;
@@ -999,7 +987,7 @@
/* TODO: document me */
/* TODO: think of a better name than 'push' */
static void
-initstack_push(void)
+initstack_push(struct initialization *in)
{
struct brace_level *level, *enclosing;
@@ -1024,14 +1012,14 @@
lint_assert(level->bl_type != NULL);
switch (level->bl_type->t_tspec) {
case ARRAY:
- if (current_designation().head != NULL) {
+ if (in->designation.head != NULL) {
debug_step("pop array, named member '%s'%s",
- current_designation().head->name,
+ in->designation.head->name,
level->bl_brace ? ", needs closing brace" : "");
goto pop;
}
- initstack_push_array();
+ initstack_push_array(in);
break;
case UNION:
@@ -1040,11 +1028,11 @@
warning(238);
/* FALLTHROUGH */
case STRUCT:
- if (initstack_push_struct_or_union())
+ if (initstack_push_struct_or_union(in))
goto pop;
break;
default:
- if (current_designation().head != NULL) {
+ if (in->designation.head != NULL) {
debug_step("pop scalar");
pop:
/* TODO: extract this into end_initializer_level */
@@ -1094,11 +1082,11 @@
* initialization level.
*/
static void
-initstack_next_brace(void)
+initstack_next_brace(struct initialization *in)
{
debug_enter();
- initialization_debug(current_init());
+ initialization_debug(in);
if (brace_level_rvalue->bl_type != NULL &&
is_scalar(brace_level_rvalue->bl_type->t_tspec)) {
@@ -1109,10 +1097,10 @@
if (!initerr)
check_too_many_initializers();
if (!initerr)
- initstack_push();
+ initstack_push(in);
if (!initerr) {
brace_level_lvalue->bl_brace = true;
- designation_debug(current_designation_mod());
+ designation_debug(&in->designation);
debug_step("expecting type '%s'",
type_name(brace_level_rvalue->bl_type != NULL
? brace_level_rvalue->bl_type
@@ -1125,7 +1113,7 @@
/* TODO: document me, or think of a better name */
static void
-initstack_next_nobrace(tnode_t *tn)
Home |
Main Index |
Thread Index |
Old Index