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: rename val_t.v_unsigned to avoid c...



details:   https://anonhg.NetBSD.org/src/rev/b37f9ddfbaec
branches:  trunk
changeset: 984068:b37f9ddfbaec
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 20 20:32:42 2021 +0000

description:
lint: rename val_t.v_unsigned to avoid confusion

The name v_unsigned suggested that the value would be interpreted as
unsigned, which was wrong.  Whether a value is signed or unsigned is
decided by v_tspec instead.

Revert the previous commit for boolen constants since their value is
already interpreted as unsigned, and there is no need for any warning
about differences between traditional C and ANSI C since the _Bool type
has only been added ten years later in C99.

The code for printing a tree node was also confused by this struct
member, even with its old name v_ansiu.  That code will be fixed in a
follow-up commit.

No functional change.

diffstat:

 usr.bin/xlint/lint1/ckbool.c |   8 ++++----
 usr.bin/xlint/lint1/lex.c    |   6 +++---
 usr.bin/xlint/lint1/lint1.h  |  11 ++++++++---
 usr.bin/xlint/lint1/print.c  |   7 ++++---
 usr.bin/xlint/lint1/tree.c   |  25 +++++++++++++------------
 5 files changed, 32 insertions(+), 25 deletions(-)

diffs (200 lines):

diff -r c92488c8ea87 -r b37f9ddfbaec usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Sun Jun 20 19:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Sun Jun 20 20:32:42 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.3 2021/06/20 19:15:58 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.4 2021/06/20 20:32:42 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckbool.c,v 1.3 2021/06/20 19:15:58 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.4 2021/06/20 20:32:42 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -252,7 +252,7 @@
                sym->s_scl = CTCONST; /* close enough */
                sym->s_type = gettyp(BOOL);
                sym->s_value.v_tspec = BOOL;
-               sym->s_value.v_unsigned = true;
+               sym->s_value.v_unsigned_since_c90 = false;
                sym->s_value.v_quad = 0;
                return true;
        }
@@ -261,7 +261,7 @@
                sym->s_scl = CTCONST; /* close enough */
                sym->s_type = gettyp(BOOL);
                sym->s_value.v_tspec = BOOL;
-               sym->s_value.v_unsigned = true;
+               sym->s_value.v_unsigned_since_c90 = false;
                sym->s_value.v_quad = 1;
                return true;
        }
diff -r c92488c8ea87 -r b37f9ddfbaec usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Jun 20 19:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Jun 20 20:32:42 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.45 2021/06/20 19:04:50 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.46 2021/06/20 20:32:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.45 2021/06/20 19:04:50 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.46 2021/06/20 20:32:42 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -672,7 +672,7 @@
 
        yylval.y_val = xcalloc(1, sizeof(*yylval.y_val));
        yylval.y_val->v_tspec = typ;
-       yylval.y_val->v_unsigned = ansiu;
+       yylval.y_val->v_unsigned_since_c90 = ansiu;
        yylval.y_val->v_quad = (int64_t)uq;
 
        return T_CON;
diff -r c92488c8ea87 -r b37f9ddfbaec usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Jun 20 19:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Jun 20 20:32:42 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.104 2021/06/20 19:04:50 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.105 2021/06/20 20:32:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -107,8 +107,13 @@
 /* An integer or floating-point value. */
 typedef struct {
        tspec_t v_tspec;
-       bool    v_unsigned;             /* set if an integer constant is
-                                          unsigned in C90 and later */
+       /*
+        * Set if an integer constant is unsigned only in C90 and later, but
+        * not in traditional C.
+        *
+        * See the operators table in ops.def, columns "l r".
+        */
+       bool    v_unsigned_since_c90;
        union {
                int64_t _v_quad;        /* integers */
                ldbl_t  _v_ldbl;        /* floats */
diff -r c92488c8ea87 -r b37f9ddfbaec usr.bin/xlint/lint1/print.c
--- a/usr.bin/xlint/lint1/print.c       Sun Jun 20 19:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/print.c       Sun Jun 20 20:32:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print.c,v 1.13 2021/06/20 19:04:50 rillig Exp $        */
+/*     $NetBSD: print.c,v 1.14 2021/06/20 20:32:42 rillig Exp $        */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: print.c,v 1.13 2021/06/20 19:04:50 rillig Exp $");
+__RCSID("$NetBSD: print.c,v 1.14 2021/06/20 20:32:42 rillig Exp $");
 #endif
 
 #include <stdio.h>
@@ -63,7 +63,8 @@
                        break;
                default:
                        (void)snprintf(buf, bufsiz,
-                           v->v_unsigned ? "%llu" : "%lld",
+                           /* FIXME */
+                           v->v_unsigned_since_c90 ? "%llu" : "%lld",
                            (unsigned long long)v->v_quad);
                        break;
                }
diff -r c92488c8ea87 -r b37f9ddfbaec usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jun 20 19:15:58 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jun 20 20:32:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.288 2021/06/20 19:04:50 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.289 2021/06/20 20:32:42 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.288 2021/06/20 19:04:50 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.289 2021/06/20 20:32:42 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -183,7 +183,7 @@
        n->tn_type = tp;
        n->tn_val = expr_zalloc(sizeof(*n->tn_val));
        n->tn_val->v_tspec = tp->t_tspec;
-       n->tn_val->v_unsigned = v->v_unsigned;
+       n->tn_val->v_unsigned_since_c90 = v->v_unsigned_since_c90;
        n->tn_val->v_u = v->v_u;
        free(v);
        return n;
@@ -532,16 +532,16 @@
         * ANSI C, print a warning.
         */
        if (mp->m_warn_if_left_unsigned_in_c90 &&
-           ln->tn_op == CON && ln->tn_val->v_unsigned) {
+           ln->tn_op == CON && ln->tn_val->v_unsigned_since_c90) {
                /* ANSI C treats constant as unsigned, op %s */
                warning(218, mp->m_name);
-               ln->tn_val->v_unsigned = false;
+               ln->tn_val->v_unsigned_since_c90 = false;
        }
        if (mp->m_warn_if_right_unsigned_in_c90 &&
-           rn->tn_op == CON && rn->tn_val->v_unsigned) {
+           rn->tn_op == CON && rn->tn_val->v_unsigned_since_c90) {
                /* ANSI C treats constant as unsigned, op %s */
                warning(218, mp->m_name);
-               rn->tn_val->v_unsigned = false;
+               rn->tn_val->v_unsigned_since_c90 = false;
        }
 
        /* Make sure both operands are of the same type */
@@ -2364,7 +2364,7 @@
        range_check = false;
 
        if (nt == BOOL) {       /* C99 6.3.1.2 */
-               nv->v_unsigned = false;
+               nv->v_unsigned_since_c90 = false;
                nv->v_quad = is_nonzero_val(v) ? 1 : 0;
                return;
        }
@@ -2376,13 +2376,13 @@
                nv->v_quad = v->v_quad;
        }
 
-       if ((v->v_unsigned && is_floating(nt)) ||
-           (v->v_unsigned && (is_integer(nt) && !is_uinteger(nt) &&
+       if ((v->v_unsigned_since_c90 && is_floating(nt)) ||
+           (v->v_unsigned_since_c90 && (is_integer(nt) && !is_uinteger(nt) &&
                            portable_size_in_bits(nt) >
                            portable_size_in_bits(ot)))) {
                /* ANSI C treats constant as unsigned */
                warning(157);
-               v->v_unsigned = false;
+               v->v_unsigned_since_c90 = false;
        }
 
        switch (nt) {
@@ -3618,7 +3618,8 @@
        if (tn->tn_op == CON) {
                lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
                if (is_integer(tn->tn_val->v_tspec)) {
-                       v->v_unsigned = tn->tn_val->v_unsigned;
+                       v->v_unsigned_since_c90 =
+                           tn->tn_val->v_unsigned_since_c90;
                        v->v_quad = tn->tn_val->v_quad;
                        return v;
                }



Home | Main Index | Thread Index | Old Index