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: clean up duplicate code for findin...



details:   https://anonhg.NetBSD.org/src/rev/819f3cc004e8
branches:  trunk
changeset: 377517:819f3cc004e8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 15 15:51:22 2023 +0000

description:
lint: clean up duplicate code for finding struct/union members

diffstat:

 usr.bin/xlint/lint1/externs1.h |   4 ++--
 usr.bin/xlint/lint1/init.c     |  17 +++++++----------
 usr.bin/xlint/lint1/tree.c     |  35 ++++++++++++-----------------------
 3 files changed, 21 insertions(+), 35 deletions(-)

diffs (133 lines):

diff -r 7dafc71482ae -r 819f3cc004e8 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Jul 15 15:38:03 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Jul 15 15:51:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.197 2023/07/15 13:51:36 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.198 2023/07/15 15:51:22 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -294,7 +294,7 @@ void        check_expr_misc(const tnode_t *, bo
 bool   constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
 strg_t *cat_strings(strg_t *, strg_t *);
 unsigned int type_size_in_bits(const type_t *);
-sym_t  *find_member(const type_t *, const char *);
+sym_t  *find_member(const struct_or_union *, const char *);
 
 void begin_statement_expr(void);
 void do_statement_expr(tnode_t *);
diff -r 7dafc71482ae -r 819f3cc004e8 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sat Jul 15 15:38:03 2023 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sat Jul 15 15:51:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.247 2023/07/15 13:35:24 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.248 2023/07/15 15:51:22 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.247 2023/07/15 13:35:24 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.248 2023/07/15 15:51:22 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -837,20 +837,17 @@ initialization_add_designator_member(ini
        const type_t *tp = brace_level_sub_type(bl);
        if (is_struct_or_union(tp->t_tspec))
                goto proceed;
-       else if (tp->t_tspec == ARRAY) {
+       else if (tp->t_tspec == ARRAY)
                /* syntax error '%s' */
                error(249, "designator '.member' is only for struct/union");
-               in->in_err = true;
-               return;
-       } else {
+       else
                /* syntax error '%s' */
                error(249, "scalar type cannot use designator");
-               in->in_err = true;
-               return;
-       }
+       in->in_err = true;
+       return;
 
 proceed:;
-       const sym_t *member = find_member(tp, name);
+       const sym_t *member = find_member(tp->t_sou, name);
        if (member == NULL) {
                /* type '%s' does not have member '%s' */
                error(101, type_name(tp), name);
diff -r 7dafc71482ae -r 819f3cc004e8 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jul 15 15:38:03 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jul 15 15:51:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.572 2023/07/15 15:38:03 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.573 2023/07/15 15:51:22 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.572 2023/07/15 15:38:03 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.573 2023/07/15 15:51:22 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1871,20 +1871,22 @@ all_members_compatible(const sym_t *msym
 }
 
 sym_t *
-find_member(const type_t *tp, const char *name)
+find_member(const struct_or_union *sou, const char *name)
 {
-       for (sym_t *mem = tp->t_sou->sou_first_member;
+       for (sym_t *mem = sou->sou_first_member;
             mem != NULL; mem = mem->s_next) {
                lint_assert(is_member(mem));
-               lint_assert(mem->u.s_member.sm_containing_type == tp->t_sou);
+               lint_assert(mem->u.s_member.sm_containing_type == sou);
                if (strcmp(mem->s_name, name) == 0)
                        return mem;
        }
-       for (sym_t *mem = tp->t_sou->sou_first_member;
+
+       for (sym_t *mem = sou->sou_first_member;
             mem != NULL; mem = mem->s_next) {
-               if (is_struct_or_union(mem->s_type->t_tspec) &&
-                   mem->s_name == unnamed) {
-                       sym_t *nested_mem = find_member(mem->s_type, name);
+               if (is_struct_or_union(mem->s_type->t_tspec)
+                   && mem->s_name == unnamed) {
+                       sym_t *nested_mem =
+                           find_member(mem->s_type->t_sou, name);
                        if (nested_mem != NULL)
                                return nested_mem;
                }
@@ -1934,21 +1936,8 @@ struct_or_union_member(tnode_t *tn, op_t
                tp = tn->tn_type->t_subt;
        struct_or_union *sou = tp != NULL ? tp->t_sou : NULL;
 
-       /*
-        * If this struct/union has a member with the name of msym, return it.
-        */
        if (sou != NULL) {
-               for (sym_t *sym = msym;
-                    sym != NULL; sym = sym->s_symtab_next) {
-                       if (is_member(sym) &&
-                           sym->u.s_member.sm_containing_type == sou &&
-                           strcmp(sym->s_name, msym->s_name) == 0)
-                               return sym;
-               }
-       }
-
-       if (tp != NULL) {
-               sym_t *nested_mem = find_member(tp, msym->s_name);
+               sym_t *nested_mem = find_member(sou, msym->s_name);
                if (nested_mem != NULL)
                        return nested_mem;
        }



Home | Main Index | Thread Index | Old Index