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 more functions to the global-...
details: https://anonhg.NetBSD.org/src/rev/38e205ccdbcf
branches: trunk
changeset: 954035:38e205ccdbcf
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Mar 28 09:08:13 2021 +0000
description:
lint: move more functions to the global-variables-free section
No functional change.
diffstat:
usr.bin/xlint/lint1/init.c | 121 +++++++++++++++++++++++---------------------
1 files changed, 63 insertions(+), 58 deletions(-)
diffs (170 lines):
diff -r b30235b87028 -r 38e205ccdbcf usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sun Mar 28 08:43:05 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Sun Mar 28 09:08:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.146 2021/03/28 08:30:22 rillig Exp $ */
+/* $NetBSD: init.c,v 1.147 2021/03/28 09:08:13 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.146 2021/03/28 08:30:22 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.147 2021/03/28 09:08:13 rillig Exp $");
#endif
#include <stdlib.h>
@@ -426,6 +426,64 @@
#define brace_level_debug(level) do { } while (false)
#endif
+static const sym_t *
+brace_level_look_up_member(const struct brace_level *level, const char *name)
+{
+ const type_t *tp = level->bl_type;
+ const sym_t *m;
+
+ lint_assert(tp->t_tspec == STRUCT || tp->t_tspec == UNION);
+
+ for (m = tp->t_str->sou_first_member; m != NULL; m = m->s_next) {
+ if (m->s_bitfield && m->s_name == unnamed)
+ continue;
+ if (strcmp(m->s_name, name) == 0)
+ return m;
+ }
+
+ return NULL;
+}
+
+/* TODO: merge duplicate code */
+static sym_t *
+brace_level_look_up_member_bloated(struct brace_level *level,
+ const struct designator *dr, int *count)
+{
+ sym_t *m;
+
+ for (m = level->bl_type->t_str->sou_first_member;
+ m != NULL; m = m->s_next) {
+ if (m->s_bitfield && m->s_name == unnamed)
+ continue;
+ /*
+ * TODO: split into separate functions:
+ *
+ * look_up_array_next
+ * look_up_array_designator
+ * look_up_struct_next
+ * look_up_struct_designator
+ */
+ if (dr != NULL) {
+ /* XXX: this log entry looks unnecessarily verbose */
+ debug_step("have member '%s', want member '%s'",
+ m->s_name, dr->name);
+ if (strcmp(m->s_name, dr->name) == 0) {
+ (*count)++;
+ break;
+ } else
+ continue;
+ }
+
+ /* XXX: What is this code for? */
+ if (++(*count) == 1) {
+ level->bl_next_member = m;
+ level->bl_subtype = m->s_type;
+ }
+ }
+
+ return m;
+}
+
static struct initialization *
initialization_new(sym_t *sym)
@@ -594,24 +652,6 @@
return level;
}
-static const sym_t *
-brace_level_look_up_member(const char *name)
-{
- const type_t *tp = current_brace_level()->bl_type;
- const sym_t *m;
-
- lint_assert(tp->t_tspec == STRUCT || tp->t_tspec == UNION);
-
- for (m = tp->t_str->sou_first_member; m != NULL; m = m->s_next) {
- if (m->s_bitfield && m->s_name == unnamed)
- continue;
- if (strcmp(m->s_name, name) == 0)
- return m;
- }
-
- return NULL;
-}
-
static void
brace_level_set_array_dimension(int dim)
{
@@ -729,7 +769,7 @@
return;
}
- m = brace_level_look_up_member(name);
+ m = brace_level_look_up_member(level, name);
if (m == NULL) {
/* TODO: add type information to the message */
/* undefined struct/union member: %s */
@@ -898,42 +938,6 @@
type_name(level->bl_type), level->bl_remaining);
}
-static sym_t *
-look_up_member(struct brace_level *level, int *count)
-{
- sym_t *m;
-
- for (m = level->bl_type->t_str->sou_first_member;
- m != NULL; m = m->s_next) {
- if (m->s_bitfield && m->s_name == unnamed)
- continue;
- /*
- * TODO: split into separate functions:
- *
- * look_up_array_next
- * look_up_array_designator
- * look_up_struct_next
- * look_up_struct_designator
- */
- if (current_designation().head != NULL) {
- /* XXX: this log entry looks unnecessarily verbose */
- debug_step("have member '%s', want member '%s'",
- m->s_name, current_designation().head->name);
- if (strcmp(m->s_name,
- current_designation().head->name) == 0) {
- (*count)++;
- break;
- } else
- continue;
- }
- if (++(*count) == 1) {
- level->bl_next_member = m;
- level->bl_subtype = m->s_type;
- }
- }
-
- return m;
-}
/* TODO: document me */
/* TODO: think of a better name than 'push' */
@@ -961,7 +965,8 @@
type_name(level->bl_type),
level->bl_seen_named_member ? ", seen named member" : "");
- m = look_up_member(level, &cnt);
+ m = brace_level_look_up_member_bloated(level,
+ current_designation().head, &cnt);
if (current_designation().head != NULL) {
if (m == NULL) {
Home |
Main Index |
Thread Index |
Old Index