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: extract typeok_incdec from typeok



details:   https://anonhg.NetBSD.org/src/rev/658b7ef834e0
branches:  trunk
changeset: 979755:658b7ef834e0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 09 18:15:14 2021 +0000

description:
lint: extract typeok_incdec from typeok

No functional change.

diffstat:

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

diffs (73 lines):

diff -r 4287fd54f5f4 -r 658b7ef834e0 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jan 09 17:36:10 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jan 09 18:15:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.137 2021/01/09 17:21:33 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.138 2021/01/09 18:15: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.137 2021/01/09 17:21:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.138 2021/01/09 18:15:14 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -686,6 +686,29 @@
        return tn;
 }
 
+static bool
+typeok_incdec(mod_t *const mp, tnode_t *const ln, type_t *const ltp)
+{
+       /* operand has scalar type (checked in typeok) */
+       if (!ln->tn_lvalue) {
+               if (ln->tn_op == CVT && ln->tn_cast &&
+                   ln->tn_left->tn_op == LOAD) {
+                       if (ln->tn_type->t_tspec == PTR)
+                               return true;
+                       /* a cast does not yield an lvalue */
+                       error(163);
+               }
+               /* %soperand of '%s' must be lvalue */
+               error(114, "", mp->m_name);
+               return false;
+       } else if (ltp->t_const) {
+               if (!tflag)
+                       /* %soperand of '%s' must be modifiable ... */
+                       warning(115, "", mp->m_name);
+       }
+       return true;
+}
+
 /*
  * Perform most type checks. First the types are checked using
  * the information from modtab[]. After that it is done by hand for
@@ -783,23 +806,8 @@
        case DECAFT:
        case INCBEF:
        case DECBEF:
-               /* operands have scalar types (checked above) */
-               if (!ln->tn_lvalue) {
-                       if (ln->tn_op == CVT && ln->tn_cast &&
-                           ln->tn_left->tn_op == LOAD) {
-                               if (ln->tn_type->t_tspec == PTR)
-                                       break;
-                               /* a cast does not yield an lvalue */
-                               error(163);
-                       }
-                       /* %soperand of '%s' must be lvalue */
-                       error(114, "", mp->m_name);
+               if (!typeok_incdec(mp, ln, ltp))
                        return 0;
-               } else if (ltp->t_const) {
-                       if (!tflag)
-                               /* %soperand of '%s' must be modifiable ... */
-                               warning(115, "", mp->m_name);
-               }
                break;
        case AMPER:
                if (lt == ARRAY || lt == FUNC) {



Home | Main Index | Thread Index | Old Index