Module Name:    src
Committed By:   rillig
Date:           Tue Jun 21 22:10:31 UTC 2022

Modified Files:
        src/usr.bin/xlint/common: tyname.c
        src/usr.bin/xlint/lint1: decl.c emit1.c tree.c

Log Message:
lint: use is_struct_or_union instead of comparing twice

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.291 -r1.292 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.455 -r1.456 src/usr.bin/xlint/lint1/tree.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/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.51 src/usr.bin/xlint/common/tyname.c:1.52
--- src/usr.bin/xlint/common/tyname.c:1.51	Fri May 20 21:18:54 2022
+++ src/usr.bin/xlint/common/tyname.c	Tue Jun 21 22:10:30 2022
@@ -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 @@ type_name(const type_t *tp)
 		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));

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.291 src/usr.bin/xlint/lint1/decl.c:1.292
--- src/usr.bin/xlint/lint1/decl.c:1.291	Tue Jun 21 21:18:30 2022
+++ src/usr.bin/xlint/lint1/decl.c	Tue Jun 21 22:10:30 2022
@@ -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 @@ is_incomplete(const type_t *tp)
 		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 @@ add_type(type_t *tp)
 
 	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 @@ eqtype(const type_t *tp1, const type_t *
 		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)

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.62 src/usr.bin/xlint/lint1/emit1.c:1.63
--- src/usr.bin/xlint/lint1/emit1.c:1.62	Fri May 20 21:18:55 2022
+++ src/usr.bin/xlint/lint1/emit1.c	Tue Jun 21 22:10:30 2022
@@ -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 @@ outtype(const type_t *tp)
 			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;

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.455 src/usr.bin/xlint/lint1/tree.c:1.456
--- src/usr.bin/xlint/lint1/tree.c:1.455	Tue Jun 21 21:18:30 2022
+++ src/usr.bin/xlint/lint1/tree.c	Tue Jun 21 22:10:30 2022
@@ -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 @@ struct_or_union_member(tnode_t *tn, op_t
 	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 @@ typeok_assign(op_t op, const tnode_t *ln
 		/* %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 @@ check_assign_types_compatible(op_t op, i
 	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 @@ should_warn_about_pointer_cast(const typ
 	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 @@ warn_incompatible_types(op_t op,
 		/* 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 @@ warn_incompatible_pointers(const mod_t *
 	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 @@ build_colon(bool sys, tnode_t *ln, tnode
 		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 @@ cast(tnode_t *tn, type_t *tp)
 		/* 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 @@ check_function_arguments(type_t *ftp, tn
 			/* 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);

Reply via email to