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: clean up warn_incompatible_types



details:   https://anonhg.NetBSD.org/src/rev/bd21899dc237
branches:  trunk
changeset: 1017577:bd21899dc237
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 01 01:38:14 2021 +0000

description:
lint: clean up warn_incompatible_types

Splitting the code arbitrarily in separate phases made the code harder
to understand, both for humans as well as automated tools.

One of these tools, check-msgs.lua, couldn't check whether the comments
match the actual messages, and of course, the comments were wrong.
There was no good reason to deviate from the pattern followed by all the
rest of the code.

diffstat:

 usr.bin/xlint/lint1/tree.c |  37 +++++++++++--------------------------
 1 files changed, 11 insertions(+), 26 deletions(-)

diffs (70 lines):

diff -r 7952ed5be99b -r bd21899dc237 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Jan 01 01:29:30 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Jan 01 01:38:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.109 2021/01/01 01:07:08 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.110 2021/01/01 01:38:14 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.109 2021/01/01 01:07:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.110 2021/01/01 01:38:14 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2190,42 +2190,27 @@
 warn_incompatible_types(op_t op, tspec_t lt, tspec_t rt)
 {
        mod_t   *mp;
-       int e = 0;
 
        mp = &modtab[op];
 
        if (lt == VOID || (mp->m_binary && rt == VOID)) {
                /* void type illegal in expression */
-               e = 109;
+               error(109);
        } else if (op == ASSIGN) {
                if ((lt == STRUCT || lt == UNION) &&
                    (rt == STRUCT || rt == UNION)) {
-                       /* assignment of different structures */
-                       e = 240;
+                       /* assignment of different structures (%s != %s) */
+                       error(240, basic_type_name(lt), basic_type_name(rt));
                } else {
-                       /* assignment type mismatch */
-                       e = 171;
+                       /* assignment type mismatch (%s != %s) */
+                       error(171, basic_type_name(lt), basic_type_name(rt));
                }
        } else if (mp->m_binary) {
-               /* operands of %s have incompatible types */
-               e = 107;
+               /* operands of '%s' have incompatible types (%s != %s) */
+               error(107, mp->m_name, basic_type_name(lt), basic_type_name(rt));
        } else {
-               /* operand of %s has incompatible type */
-               e = 108;
-       }
-       switch (e) {
-       case 0:
-               return;
-       case 109:
-               error(e);
-               return;
-       case 108:
-       case 107:
-               error(e, mp->m_name, basic_type_name(lt), basic_type_name(rt));
-               return;
-       default:
-               error(e, basic_type_name(lt), basic_type_name(rt));
-               return;
+               /* operand of '%s' has incompatible type (%s != %s) */
+               error(108, mp->m_name, basic_type_name(lt), basic_type_name(rt));
        }
 }
 



Home | Main Index | Thread Index | Old Index