From 15ccb490cc39ddbf33a54f8538992f5a815444b5 Mon Sep 17 00:00:00 2001 From: rillig Date: Fri, 1 Jan 2021 01:38:14 +0000 Subject: [PATCH] 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. --- usr.bin/xlint/lint1/tree.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 566dfdf8c5aa..611feef12170 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -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 #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 @@ -2190,42 +2190,27 @@ static void 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)); } }