Module Name:    src
Committed By:   rillig
Date:           Tue Jan  5 17:37:57 UTC 2021

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

Log Message:
lint: make check_precedence_confusion simpler

In C, only binary operators have possibly confusing precedence.  All
binary operators have lower precedence than an explicit cast.  When an
expression is parsed, the parentheses are associated with the innermost
possible node.  This means that as soon as a cast operator is
parenthesized, its contained expression can no longer have confusing
precedence.

This allows the code to be written more succinct since the local
variables are no longer necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 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/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.134 src/usr.bin/xlint/lint1/tree.c:1.135
--- src/usr.bin/xlint/lint1/tree.c:1.134	Tue Jan  5 00:17:21 2021
+++ src/usr.bin/xlint/lint1/tree.c	Tue Jan  5 17:37:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.134 2021/01/05 00:17:21 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.135 2021/01/05 17:37:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.134 2021/01/05 00:17:21 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.135 2021/01/05 17:37:57 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4027,32 +4027,22 @@ is_confusing_precedence(op_t op, op_t lo
 static void
 check_precedence_confusion(tnode_t *tn)
 {
-	tnode_t	*ln, *rn;
-	op_t	lop, rop;
-	bool	lparn, rparn;
-	mod_t	*mp;
+	tnode_t *ln, *rn;
 
 	if (!hflag)
 		return;
 
-	mp = &modtab[tn->tn_op];
-	lint_assert(mp->m_binary);
-
 	dprint_node(tn);
 
-	lparn = false;
+	lint_assert(modtab[tn->tn_op].m_binary);
 	for (ln = tn->tn_left; ln->tn_op == CVT; ln = ln->tn_left)
-		lparn |= ln->tn_parenthesized;
-	lparn |= ln->tn_parenthesized;
-	lop = ln->tn_op;
-
-	rparn = false;
+		continue;
 	for (rn = tn->tn_right; rn->tn_op == CVT; rn = rn->tn_left)
-		rparn |= rn->tn_parenthesized;
-	rparn |= rn->tn_parenthesized;
-	rop = rn->tn_op;
+		continue;
 
-	if (is_confusing_precedence(tn->tn_op, lop, lparn, rop, rparn)) {
+	if (is_confusing_precedence(tn->tn_op,
+	    ln->tn_op, ln->tn_parenthesized,
+	    rn->tn_op, rn->tn_parenthesized)) {
 		/* precedence confusion possible: parenthesize! */
 		warning(169);
 	}

Reply via email to