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: make check_precedence_confusion si...



details:   https://anonhg.NetBSD.org/src/rev/59f4056e6f8a
branches:  trunk
changeset: 1017713:59f4056e6f8a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jan 05 17:37:57 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/tree.c |  30 ++++++++++--------------------
 1 files changed, 10 insertions(+), 20 deletions(-)

diffs (59 lines):

diff -r 9cbcd93fd2ab -r 59f4056e6f8a usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue Jan 05 17:13:44 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Jan 05 17:37:57 2021 +0000
@@ -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 @@
 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;
-
-       if (is_confusing_precedence(tn->tn_op, lop, lparn, rop, rparn)) {
+               continue;
+
+       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);
        }



Home | Main Index | Thread Index | Old Index