Module Name:    src
Committed By:   rillig
Date:           Sat Mar 27 16:37:12 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: init.c

Log Message:
lint: extract look_up_member from initstack_push_struct_or_union

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.137 src/usr.bin/xlint/lint1/init.c:1.138
--- src/usr.bin/xlint/lint1/init.c:1.137	Sat Mar 27 16:24:21 2021
+++ src/usr.bin/xlint/lint1/init.c	Sat Mar 27 16:37:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.137 2021/03/27 16:24:21 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.138 2021/03/27 16:37:12 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.137 2021/03/27 16:24:21 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.138 2021/03/27 16:37:12 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -798,32 +798,11 @@ initstack_push_array(void)
 	    type_name(istk->i_type), istk->i_remaining);
 }
 
-/* TODO: document me */
-/* TODO: think of a better name than 'push' */
-static bool
-initstack_push_struct_or_union(void)
+static sym_t *
+look_up_member(initstack_element *istk, int *count)
 {
-	/*
-	 * TODO: remove unnecessary 'const' for variables in functions that
-	 * fit on a single screen.  Keep it for larger functions.
-	 */
-	initstack_element *istk = initstk_lvalue;
-	int cnt;
 	sym_t *m;
 
-	if (is_incomplete(istk->i_type)) {
-		/* initialization of an incomplete type */
-		error(175);
-		initerr = true;
-		return false;
-	}
-
-	cnt = 0;
-	debug_designation();
-	debug_step("lookup for '%s'%s",
-	    type_name(istk->i_type),
-	    istk->i_seen_named_member ? ", seen named member" : "");
-
 	for (m = istk->i_type->t_str->sou_first_member;
 	     m != NULL; m = m->s_next) {
 		if (m->s_bitfield && m->s_name == unnamed)
@@ -842,17 +821,48 @@ initstack_push_struct_or_union(void)
 			    m->s_name, current_designation().head->name);
 			if (strcmp(m->s_name,
 			    current_designation().head->name) == 0) {
-				cnt++;
+				(*count)++;
 				break;
 			} else
 				continue;
 		}
-		if (++cnt == 1) {
+		if (++(*count) == 1) {
 			istk->i_next_member = m;
 			istk->i_subt = m->s_type;
 		}
 	}
 
+	return m;
+}
+
+/* TODO: document me */
+/* TODO: think of a better name than 'push' */
+static bool
+initstack_push_struct_or_union(void)
+{
+	/*
+	 * TODO: remove unnecessary 'const' for variables in functions that
+	 * fit on a single screen.  Keep it for larger functions.
+	 */
+	initstack_element *istk = initstk_lvalue;
+	int cnt;
+	sym_t *m;
+
+	if (is_incomplete(istk->i_type)) {
+		/* initialization of an incomplete type */
+		error(175);
+		initerr = true;
+		return false;
+	}
+
+	cnt = 0;
+	debug_designation();
+	debug_step("lookup for '%s'%s",
+	    type_name(istk->i_type),
+	    istk->i_seen_named_member ? ", seen named member" : "");
+
+	m = look_up_member(istk, &cnt);
+
 	if (current_designation().head != NULL) {
 		if (m == NULL) {
 			debug_step("pop struct");

Reply via email to