Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint lint: use is_struct_or_union instead of compar...



details:   https://anonhg.NetBSD.org/src/rev/0b6dc981aedf
branches:  trunk
changeset: 367682:0b6dc981aedf
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 21 22:10:30 2022 +0000

description:
lint: use is_struct_or_union instead of comparing twice

No functional change.

diffstat:

 usr.bin/xlint/common/tyname.c |   6 +++---
 usr.bin/xlint/lint1/decl.c    |  10 +++++-----
 usr.bin/xlint/lint1/emit1.c   |   6 +++---
 usr.bin/xlint/lint1/tree.c    |  27 +++++++++++++--------------
 4 files changed, 24 insertions(+), 25 deletions(-)

diffs (207 lines):

diff -r 96e962cbf6ce -r 0b6dc981aedf usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Tue Jun 21 21:18:30 2022 +0000
+++ b/usr.bin/xlint/common/tyname.c     Tue Jun 21 22:10:30 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.51 2022/05/20 21:18:54 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.52 2022/06/21 22:10:30 rillig Exp $       */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tyname.c,v 1.51 2022/05/20 21:18:54 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.52 2022/06/21 22:10:30 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -264,7 +264,7 @@
                buf_add(&buf, "volatile ");
 
 #ifdef IS_LINT1
-       if ((t == STRUCT || t == UNION) && tp->t_str->sou_incomplete)
+       if (is_struct_or_union(t) && tp->t_str->sou_incomplete)
                buf_add(&buf, "incomplete ");
 #endif
        buf_add(&buf, tspec_name(t));
diff -r 96e962cbf6ce -r 0b6dc981aedf usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Tue Jun 21 21:18:30 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Tue Jun 21 22:10:30 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.291 2022/06/21 21:18:30 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.292 2022/06/21 22:10:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.291 2022/06/21 21:18:30 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.292 2022/06/21 22:10:30 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -210,7 +210,7 @@
                return true;
        } else if (t == ARRAY) {
                return tp->t_incomplete_array;
-       } else if (t == STRUCT || t == UNION) {
+       } else if (is_struct_or_union(t)) {
                return tp->t_str->sou_incomplete;
        } else if (t == ENUM) {
                return tp->t_enum->en_incomplete;
@@ -278,7 +278,7 @@
 
        t = tp->t_tspec;
 
-       if (t == STRUCT || t == UNION || t == ENUM) {
+       if (is_struct_or_union(t) || t == ENUM) {
                /*
                 * something like "int struct a ..."
                 * struct/union/enum with anything else is not allowed
@@ -2245,7 +2245,7 @@
                if (!qualifiers_correspond(tp1, tp2, ignqual))
                        return false;
 
-               if (t == STRUCT || t == UNION)
+               if (is_struct_or_union(t))
                        return tp1->t_str == tp2->t_str;
 
                if (t == ENUM && eflag)
diff -r 96e962cbf6ce -r 0b6dc981aedf usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Tue Jun 21 21:18:30 2022 +0000
+++ b/usr.bin/xlint/lint1/emit1.c       Tue Jun 21 22:10:30 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.62 2022/05/20 21:18:55 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.63 2022/06/21 22:10:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.62 2022/05/20 21:18:55 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.63 2022/06/21 22:10:30 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -120,7 +120,7 @@
                        outint(tp->t_dim);
                } else if (ts == ENUM) {
                        outtt(tp->t_enum->en_tag, tp->t_enum->en_first_typedef);
-               } else if (ts == STRUCT || ts == UNION) {
+               } else if (is_struct_or_union(ts)) {
                        outtt(tp->t_str->sou_tag, tp->t_str->sou_first_typedef);
                } else if (ts == FUNC && tp->t_proto) {
                        na = 0;
diff -r 96e962cbf6ce -r 0b6dc981aedf usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue Jun 21 21:18:30 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Jun 21 22:10:30 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.455 2022/06/21 21:18:30 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.456 2022/06/21 22:10:30 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.455 2022/06/21 21:18:30 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.456 2022/06/21 22:10:30 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -563,11 +563,11 @@
        str = NULL;
        t = (tp = tn->tn_type)->t_tspec;
        if (op == POINT) {
-               if (t == STRUCT || t == UNION)
+               if (is_struct_or_union(t))
                        str = tp->t_str;
        } else if (op == ARROW && t == PTR) {
                t = (tp = tp->t_subt)->t_tspec;
-               if (t == STRUCT || t == UNION)
+               if (is_struct_or_union(t))
                        str = tp->t_str;
        }
 
@@ -1349,7 +1349,7 @@
                /* %soperand of '%s' must be lvalue */
                error(114, "left ", op_name(op));
                return false;
-       } else if (ltp->t_const || ((lt == STRUCT || lt == UNION) &&
+       } else if (ltp->t_const || (is_struct_or_union(lt) &&
                                    has_constant_member(ltp))) {
                if (allow_c90)
                        /* %soperand of '%s' must be modifiable lvalue */
@@ -1863,7 +1863,7 @@
        if (is_arithmetic(lt) && (is_arithmetic(rt) || rt == BOOL))
                return true;
 
-       if ((lt == STRUCT || lt == UNION) && (rt == STRUCT || rt == UNION))
+       if (is_struct_or_union(lt) && is_struct_or_union(rt))
                /* both are struct or union */
                return ltp->t_str == rtp->t_str;
 
@@ -2509,7 +2509,7 @@
        if (is_incomplete(nstp) || is_incomplete(ostp))
                return false;
 
-       if ((nst == STRUCT || nst == UNION) && nstp->t_str != ostp->t_str)
+       if (is_struct_or_union(nst) && nstp->t_str != ostp->t_str)
                return true;
 
        if (nst == CHAR || nst == UCHAR)
@@ -2889,8 +2889,7 @@
                /* void type illegal in expression */
                error(109);
        } else if (op == ASSIGN) {
-               if ((lt == STRUCT || lt == UNION) &&
-                   (rt == STRUCT || rt == UNION)) {
+               if (is_struct_or_union(lt) && is_struct_or_union(rt)) {
                        /* assignment of different structures (%s != %s) */
                        error(240, tspec_name(lt), tspec_name(rt));
                } else {
@@ -2923,7 +2922,7 @@
        lt = ltp->t_subt->t_tspec;
        rt = rtp->t_subt->t_tspec;
 
-       if ((lt == STRUCT || lt == UNION) && (rt == STRUCT || rt == UNION)) {
+       if (is_struct_or_union(lt) && is_struct_or_union(rt)) {
                if (mp == NULL) {
                        /* illegal structure pointer combination */
                        warning(244);
@@ -3218,9 +3217,9 @@
                tp = ln->tn_type;
        } else if (lt == VOID || rt == VOID) {
                tp = gettyp(VOID);
-       } else if (lt == STRUCT || lt == UNION) {
+       } else if (is_struct_or_union(lt)) {
                /* Both types must be identical. */
-               lint_assert(rt == STRUCT || rt == UNION);
+               lint_assert(is_struct_or_union(rt));
                lint_assert(ln->tn_type->t_str == rn->tn_type->t_str);
                if (is_incomplete(ln->tn_type)) {
                        /* unknown operand size, op %s */
@@ -3854,7 +3853,7 @@
                /* Casting to a struct is an undocumented GCC extension. */
                if (!(allow_gcc && nt == STRUCT))
                        goto invalid_cast;
-       } else if (ot == STRUCT || ot == UNION) {
+       } else if (is_struct_or_union(ot)) {
                goto invalid_cast;
        } else if (ot == VOID) {
                /* improper cast of void expression */
@@ -3994,7 +3993,7 @@
                        /* void expressions may not be arguments, arg #%d */
                        error(151, n);
                        return NULL;
-               } else if ((at == STRUCT || at == UNION) &&
+               } else if (is_struct_or_union(at) &&
                           is_incomplete(arg->tn_left->tn_type)) {
                        /* argument cannot have unknown size, arg #%d */
                        error(152, n);



Home | Main Index | Thread Index | Old Index