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: merge duplicate code for getting t...



details:   https://anonhg.NetBSD.org/src/rev/a1793c6e7071
branches:  trunk
changeset: 377402:a1793c6e7071
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jul 10 19:47:12 2023 +0000

description:
lint: merge duplicate code for getting the name of an operator

diffstat:

 usr.bin/xlint/lint1/cgram.y  |    6 +-
 usr.bin/xlint/lint1/ckbool.c |   10 +---
 usr.bin/xlint/lint1/debug.c  |    6 +-
 usr.bin/xlint/lint1/lint1.h  |    8 ++-
 usr.bin/xlint/lint1/tree.c   |  105 ++++++++++++++++++------------------------
 5 files changed, 60 insertions(+), 75 deletions(-)

diffs (truncated from 456 to 300 lines):

diff -r 7ea7f7c5e2e0 -r a1793c6e7071 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Mon Jul 10 19:04:52 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Mon Jul 10 19:47:12 2023 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.450 2023/07/10 19:04:52 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.451 2023/07/10 19:47:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.450 2023/07/10 19:04:52 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.451 2023/07/10 19:47:12 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -2223,7 +2223,7 @@ cgram_to_string(int token, YYSTYPE val)
        case T_RELATIONAL:
        case T_EQUALITY:
        case T_OPASSIGN:
-               return modtab[val.y_op].m_name;
+               return op_name(val.y_op);
        case T_SCLASS:
                return scl_name(val.y_scl);
        case T_TYPE:
diff -r 7ea7f7c5e2e0 -r a1793c6e7071 usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Mon Jul 10 19:04:52 2023 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Mon Jul 10 19:47:12 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.24 2023/07/09 10:42:07 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.25 2023/07/10 19:47:12 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.24 2023/07/09 10:42:07 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.25 2023/07/10 19:47:12 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -50,12 +50,6 @@
  */
 
 
-static const char *
-op_name(op_t op)
-{
-       return modtab[op].m_name;
-}
-
 /*
  * See if in strict bool mode, the operator takes either two bool operands
  * or two arbitrary other operands.
diff -r 7ea7f7c5e2e0 -r a1793c6e7071 usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Mon Jul 10 19:04:52 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Mon Jul 10 19:47:12 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.48 2023/07/10 16:20:52 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.49 2023/07/10 19:47:12 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.48 2023/07/10 16:20:52 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.49 2023/07/10 19:47:12 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -166,7 +166,7 @@ debug_node(const tnode_t *tn) // NOLINT(
        op = tn->tn_op;
        debug_print_indent();
        debug_printf("'%s'",
-           op == CVT && !tn->tn_cast ? "convert" : modtab[op].m_name);
+           op == CVT && !tn->tn_cast ? "convert" : op_name(op));
        if (op == NAME)
                debug_printf(" '%s' with %s",
                    tn->tn_sym->s_name,
diff -r 7ea7f7c5e2e0 -r a1793c6e7071 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Mon Jul 10 19:04:52 2023 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Mon Jul 10 19:47:12 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.183 2023/07/10 19:00:33 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.184 2023/07/10 19:47:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -551,6 +551,12 @@ is_nonzero(const tnode_t *tn)
        return tn != NULL && tn->tn_op == CON && is_nonzero_val(&tn->tn_val);
 }
 
+static inline const char *
+op_name(op_t op)
+{
+       return modtab[op].m_name;
+}
+
 static inline bool
 is_binary(const tnode_t *tn)
 {
diff -r 7ea7f7c5e2e0 -r a1793c6e7071 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Jul 10 19:04:52 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Jul 10 19:47:12 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.559 2023/07/10 09:51:30 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.560 2023/07/10 19:47:12 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.559 2023/07/10 09:51:30 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.560 2023/07/10 19:47:12 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -82,12 +82,6 @@ str_ends_with(const char *haystack, cons
               memcmp(haystack + hlen - nlen, needle, nlen) == 0;
 }
 
-static const char *
-op_name(op_t op)
-{
-       return modtab[op].m_name;
-}
-
 static unsigned
 width_in_bits(const type_t *tp)
 {
@@ -1703,13 +1697,13 @@ build_binary(tnode_t *ln, op_t op, bool 
        if (mp->m_warn_if_left_unsigned_in_c90 &&
            ln->tn_op == CON && ln->tn_val.v_unsigned_since_c90) {
                /* ANSI C treats constant as unsigned, op '%s' */
-               warning(218, mp->m_name);
+               warning(218, op_name(op));
                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_since_c90) {
                /* ANSI C treats constant as unsigned, op '%s' */
-               warning(218, mp->m_name);
+               warning(218, op_name(op));
                rn->tn_val.v_unsigned_since_c90 = false;
        }
 
@@ -2159,8 +2153,7 @@ typeok_incdec(op_t op, const tnode_t *tn
 }
 
 static bool
-typeok_address(const mod_t *mp,
-              const tnode_t *tn, const type_t *tp, tspec_t t)
+typeok_address(op_t op, const tnode_t *tn, const type_t *tp, tspec_t t)
 {
        if (t == ARRAY || t == FUNC) {
                /* ok, a warning comes later (in build_address()) */
@@ -2171,7 +2164,7 @@ typeok_address(const mod_t *mp,
                        error(163);
                }
                /* %soperand of '%s' must be lvalue */
-               error(114, "", mp->m_name);
+               error(114, "", op_name(op));
                return false;
        } else if (is_scalar(t)) {
                if (tp->t_bitfield) {
@@ -2181,7 +2174,7 @@ typeok_address(const mod_t *mp,
                }
        } else if (t != STRUCT && t != UNION) {
                /* unacceptable operand of '%s' */
-               error(111, mp->m_name);
+               error(111, op_name(op));
                return false;
        }
        if (tn->tn_op == NAME && tn->tn_sym->s_register) {
@@ -2209,21 +2202,21 @@ warn_incompatible_types(op_t op,
                        const type_t *ltp, tspec_t lt,
                        const type_t *rtp, tspec_t rt)
 {
-       const mod_t *mp = &modtab[op];
-
-       if (lt == VOID || (mp->m_binary && rt == VOID)) {
+       bool binary = modtab[op].m_binary;
+
+       if (lt == VOID || (binary && rt == VOID)) {
                /* void type illegal in expression */
                error(109);
        } else if (op == ASSIGN) {
                /* cannot assign to '%s' from '%s' */
                error(171, type_name(ltp), type_name(rtp));
-       } else if (mp->m_binary) {
+       } else if (binary) {
                /* operands of '%s' have incompatible types '%s' and '%s' */
-               error(107, mp->m_name, type_name(ltp), type_name(rtp));
+               error(107, op_name(op), type_name(ltp), type_name(rtp));
        } else {
                lint_assert(rt == NO_TSPEC);
                /* operand of '%s' has invalid type '%s' */
-               error(108, mp->m_name, type_name(ltp));
+               error(108, op_name(op), type_name(ltp));
        }
 }
 
@@ -2260,7 +2253,7 @@ typeok_minus(op_t op,
 }
 
 static void
-typeok_shr(const mod_t *mp,
+typeok_shr(op_t op,
           const tnode_t *ln, tspec_t lt,
           const tnode_t *rn, tspec_t rt)
 {
@@ -2279,17 +2272,17 @@ typeok_shr(const mod_t *mp,
                 */
                if (ln->tn_op != CON) {
                        /* bitwise '%s' on signed value possibly nonportable */
-                       warning(117, mp->m_name);
+                       warning(117, op_name(op));
                } else if (ln->tn_val.u.integer < 0) {
                        /* bitwise '%s' on signed value nonportable */
-                       warning(120, mp->m_name);
+                       warning(120, op_name(op));
                }
        } else if (allow_trad && allow_c90 &&
                   !is_uinteger(olt) && is_uinteger(ort)) {
                /* The left operand would become unsigned in traditional C. */
                if (hflag && (ln->tn_op != CON || ln->tn_val.u.integer < 0)) {
                        /* semantics of '%s' change in ANSI C; use ... */
-                       warning(118, mp->m_name);
+                       warning(118, op_name(op));
                }
        } else if (allow_trad && allow_c90 &&
                   !is_uinteger(olt) && !is_uinteger(ort) &&
@@ -2300,13 +2293,13 @@ typeok_shr(const mod_t *mp,
                 */
                if (hflag && (ln->tn_op != CON || ln->tn_val.u.integer < 0)) {
                        /* semantics of '%s' change in ANSI C; use ... */
-                       warning(118, mp->m_name);
+                       warning(118, op_name(op));
                }
        }
 }
 
 static void
-typeok_shl(const mod_t *mp, tspec_t lt, tspec_t rt)
+typeok_shl(op_t op, tspec_t lt, tspec_t rt)
 {
        /*
         * C90 does not perform balancing for shift operations,
@@ -2324,7 +2317,7 @@ typeok_shl(const mod_t *mp, tspec_t lt, 
                 */
                if (hflag && allow_trad && allow_c90)
                        /* semantics of '%s' change in ANSI C; use ... */
-                       warning(118, mp->m_name);
+                       warning(118, op_name(op));
        }
 }
 
@@ -2363,8 +2356,7 @@ is_typeok_eq(const tnode_t *ln, tspec_t 
  * Print an appropriate warning.
  */
 static void
-warn_incompatible_pointers(const mod_t *mp,
-                          const type_t *ltp, const type_t *rtp)
+warn_incompatible_pointers(op_t op, const type_t *ltp, const type_t *rtp)
 {
        lint_assert(ltp->t_tspec == PTR);
        lint_assert(rtp->t_tspec == PTR);
@@ -2373,21 +2365,22 @@ warn_incompatible_pointers(const mod_t *
        tspec_t rt = rtp->t_subt->t_tspec;
 
        if (is_struct_or_union(lt) && is_struct_or_union(rt)) {
-               if (mp == NULL) {
+               if (op == RETURN) {
                        /* illegal structure pointer combination */
                        warning(244);
                } else {
                        /* incompatible structure pointers: '%s' '%s' '%s' */
-                       warning(245, type_name(ltp), mp->m_name, type_name(rtp));
+                       warning(245, type_name(ltp),
+                           op_name(op), type_name(rtp));
                }
        } else {
-               if (mp == NULL) {
+               if (op == RETURN) {
                        /* illegal combination of '%s' and '%s' */
                        warning(184, type_name(ltp), type_name(rtp));
                } else {
                        /* illegal combination of '%s' and '%s', op '%s' */
                        warning(124,
-                           type_name(ltp), type_name(rtp), mp->m_name);
+                           type_name(ltp), type_name(rtp), op_name(op));



Home | Main Index | Thread Index | Old Index