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: split struct_or_union_member into ...



details:   https://anonhg.NetBSD.org/src/rev/cb5c38b78006
branches:  trunk
changeset: 377514:cb5c38b78006
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 15 14:50:47 2023 +0000

description:
lint: split struct_or_union_member into separate parts

diffstat:

 usr.bin/xlint/lint1/tree.c |  50 +++++++++++++++++++++++++--------------------
 1 files changed, 28 insertions(+), 22 deletions(-)

diffs (79 lines):

diff -r b5abb108cb6d -r cb5c38b78006 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jul 15 13:51:36 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jul 15 14:50:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.569 2023/07/15 13:51:36 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.570 2023/07/15 14:50:47 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.569 2023/07/15 13:51:36 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.570 2023/07/15 14:50:47 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1891,6 +1891,31 @@ find_member(const type_t *tp, const char
 }
 
 /*
+ * Remove the member if it was unknown until now, which means
+ * that no defined struct or union has a member with the same name.
+ */
+static void
+remove_unknown_member(tnode_t *tn, sym_t *msym)
+{
+       /* type '%s' does not have member '%s' */
+       error(101, type_name(tn->tn_type), msym->s_name);
+       rmsym(msym);
+       msym->s_kind = FMEMBER;
+       msym->s_scl = STRUCT_MEMBER;
+
+       struct_or_union *sou = expr_zero_alloc(sizeof(*sou),
+           "struct_or_union");
+       sou->sou_tag = expr_zero_alloc(sizeof(*sou->sou_tag), "sym");
+       sou->sou_tag->s_name = unnamed;
+
+       msym->u.s_member.sm_containing_type = sou;
+       /*
+        * The member sm_offset_in_bits is not needed here since this
+        * symbol can only be used for error reporting.
+        */
+}
+
+/*
  * Returns a symbol which has the same name as the msym argument and is a
  * member of the struct or union specified by the tn argument.
  */
@@ -1898,27 +1923,8 @@ static sym_t *
 struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym)
 {
 
-       /*
-        * Remove the member if it was unknown until now, which means
-        * that no defined struct or union has a member with the same name.
-        */
        if (msym->s_scl == NOSCL) {
-               /* type '%s' does not have member '%s' */
-               error(101, type_name(tn->tn_type), msym->s_name);
-               rmsym(msym);
-               msym->s_kind = FMEMBER;
-               msym->s_scl = STRUCT_MEMBER;
-
-               struct_or_union *sou = expr_zero_alloc(sizeof(*sou),
-                   "struct_or_union");
-               sou->sou_tag = expr_zero_alloc(sizeof(*sou->sou_tag), "sym");
-               sou->sou_tag->s_name = unnamed;
-
-               msym->u.s_member.sm_containing_type = sou;
-               /*
-                * The member sm_offset_in_bits is not needed here since this
-                * symbol can only be used for error reporting.
-                */
+               remove_unknown_member(tn, msym);
                return msym;
        }
 



Home | Main Index | Thread Index | Old Index