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: use precise type information in me...
details: https://anonhg.NetBSD.org/src/rev/a06a8a87819f
branches: trunk
changeset: 953861:a06a8a87819f
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Mar 22 15:29:43 2021 +0000
description:
lint: use precise type information in message about type mismatch
While here, reword the message, avoiding operators and parentheses.
Since 2021-01-02, providing the precise type name is as easy as the
broad type classification (just replace tspec_name with type_name), and
it's definitely more useful to the human readers.
diffstat:
tests/usr.bin/xlint/lint1/msg_171.c | 4 +-
tests/usr.bin/xlint/lint1/msg_171.exp | 10 +++---
usr.bin/xlint/lint1/err.c | 6 ++--
usr.bin/xlint/lint1/tree.c | 47 ++++++++++++++++++++--------------
4 files changed, 37 insertions(+), 30 deletions(-)
diffs (216 lines):
diff -r fb08f5cf3248 -r a06a8a87819f tests/usr.bin/xlint/lint1/msg_171.c
--- a/tests/usr.bin/xlint/lint1/msg_171.c Mon Mar 22 15:12:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_171.c Mon Mar 22 15:29:43 2021 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: msg_171.c,v 1.3 2021/03/22 15:05:00 rillig Exp $ */
+/* $NetBSD: msg_171.c,v 1.4 2021/03/22 15:29:43 rillig Exp $ */
# 3 "msg_171.c"
-// Test for message: assignment type mismatch (%s != %s) [171]
+// Test for message: cannot assign to '%s' from '%s' [171]
struct s {
int member;
diff -r fb08f5cf3248 -r a06a8a87819f tests/usr.bin/xlint/lint1/msg_171.exp
--- a/tests/usr.bin/xlint/lint1/msg_171.exp Mon Mar 22 15:12:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_171.exp Mon Mar 22 15:29:43 2021 +0000
@@ -1,5 +1,5 @@
-msg_171.c(14): error: assignment type mismatch (int != struct) [171]
-msg_171.c(15): error: assignment type mismatch (struct != int) [171]
-msg_171.c(17): error: assignment type mismatch (pointer != struct) [171]
-msg_171.c(18): error: assignment type mismatch (struct != pointer) [171]
-msg_171.c(36): error: assignment type mismatch (struct != pointer) [171]
+msg_171.c(14): error: cannot assign to 'int' from 'struct s' [171]
+msg_171.c(15): error: cannot assign to 'struct s' from 'int' [171]
+msg_171.c(17): error: cannot assign to 'pointer to void' from 'struct s' [171]
+msg_171.c(18): error: cannot assign to 'struct s' from 'pointer to void' [171]
+msg_171.c(36): error: cannot assign to 'struct point' from 'pointer to struct point' [171]
diff -r fb08f5cf3248 -r a06a8a87819f usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Mon Mar 22 15:12:24 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Mon Mar 22 15:29:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.91 2021/03/21 20:44:59 rillig Exp $ */
+/* $NetBSD: err.c,v 1.92 2021/03/22 15:29:43 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.91 2021/03/21 20:44:59 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.92 2021/03/22 15:29:43 rillig Exp $");
#endif
#include <sys/types.h>
@@ -225,7 +225,7 @@
"array subscript cannot be > %d: %ld", /* 168 */
"precedence confusion possible: parenthesize!", /* 169 */
"first operand must have scalar type, op ? :", /* 170 */
- "assignment type mismatch (%s != %s)", /* 171 */
+ "cannot assign to '%s' from '%s'", /* 171 */
"too many struct/union initializers", /* 172 */
"too many array initializers, expected %d", /* 173 */
"too many initializers", /* 174 */
diff -r fb08f5cf3248 -r a06a8a87819f usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Mon Mar 22 15:12:24 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Mon Mar 22 15:29:43 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.245 2021/03/21 19:08:10 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.246 2021/03/22 15:29:43 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.245 2021/03/21 19:08:10 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.246 2021/03/22 15:29:43 rillig Exp $");
#endif
#include <float.h>
@@ -63,7 +63,8 @@
const tnode_t *, const tnode_t *);
static tnode_t *new_tnode(op_t, type_t *, tnode_t *, tnode_t *);
static void balance(op_t, tnode_t **, tnode_t **);
-static void warn_incompatible_types(op_t, tspec_t, tspec_t);
+static void warn_incompatible_types(op_t, const type_t *, tspec_t,
+ const type_t *, tspec_t);
static void warn_incompatible_pointers(const mod_t *,
const type_t *, const type_t *);
static void merge_qualifiers(type_t **, type_t *, type_t *);
@@ -845,11 +846,13 @@
}
static bool
-typeok_plus(op_t op, tspec_t lt, tspec_t rt)
+typeok_plus(op_t op,
+ const type_t *ltp, tspec_t lt,
+ const type_t *rtp, tspec_t rt)
{
/* operands have scalar types (checked above) */
if ((lt == PTR && !is_integer(rt)) || (rt == PTR && !is_integer(lt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
return true;
@@ -862,10 +865,10 @@
{
/* operands have scalar types (checked above) */
if (lt == PTR && (!is_integer(rt) && rt != PTR)) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
} else if (rt == PTR && lt != PTR) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
if (lt == PTR && rt == PTR) {
@@ -990,7 +993,7 @@
return true;
if (!is_integer(lt) && !is_integer(rt)) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
@@ -1264,30 +1267,32 @@
/* Check the types using the information from modtab[]. */
static bool
-typeok_scalar(op_t op, const mod_t *mp, tspec_t lt, tspec_t rt)
+typeok_scalar(op_t op, const mod_t *mp,
+ const type_t *ltp, tspec_t lt,
+ const type_t *rtp, tspec_t rt)
{
if (mp->m_takes_bool && lt == BOOL && rt == BOOL)
return true;
if (mp->m_requires_integer) {
if (!is_integer(lt) || (mp->m_binary && !is_integer(rt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
} else if (mp->m_requires_integer_or_complex) {
if ((!is_integer(lt) && !is_complex(lt)) ||
(mp->m_binary && (!is_integer(rt) && !is_complex(rt)))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
} else if (mp->m_requires_scalar) {
if (!is_scalar(lt) || (mp->m_binary && !is_scalar(rt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
} else if (mp->m_requires_arith) {
if (!is_arithmetic(lt) ||
(mp->m_binary && !is_arithmetic(rt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
}
@@ -1342,7 +1347,7 @@
return false;
break;
case PLUS:
- if (!typeok_plus(op, lt, rt))
+ if (!typeok_plus(op, ltp, lt, rtp, rt))
return false;
break;
case MINUS:
@@ -1396,7 +1401,7 @@
case SUBASS:
/* operands have scalar types (checked above) */
if ((lt == PTR && !is_integer(rt)) || rt == PTR) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
goto assign;
@@ -1493,7 +1498,7 @@
if (Tflag && !typeok_scalar_strict_bool(op, mp, arg, ln, rn))
return false;
- if (!typeok_scalar(op, mp, lt, rt))
+ if (!typeok_scalar(op, mp, ltp, lt, rtp, rt))
return false;
if (!typeok_op(op, mp, arg, ln, ltp, lt, rn, rtp, rt))
@@ -1677,7 +1682,7 @@
warning(155, arg);
break;
default:
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
break;
}
@@ -2528,7 +2533,9 @@
* Prints a appropriate warning.
*/
static void
-warn_incompatible_types(op_t op, tspec_t lt, tspec_t rt)
+warn_incompatible_types(op_t op,
+ const type_t *ltp, tspec_t lt,
+ const type_t *rtp, tspec_t rt)
{
const mod_t *mp;
@@ -2543,8 +2550,8 @@
/* assignment of different structures (%s != %s) */
error(240, tspec_name(lt), tspec_name(rt));
} else {
- /* assignment type mismatch (%s != %s) */
- error(171, tspec_name(lt), tspec_name(rt));
+ /* cannot assign to '%s' from '%s' */
+ error(171, type_name(ltp), type_name(rtp));
}
} else if (mp->m_binary) {
/* operands of '%s' have incompatible types (%s != %s) */
Home |
Main Index |
Thread Index |
Old Index