Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint lint: replace 0 and 1 with false and true, whe...



details:   https://anonhg.NetBSD.org/src/rev/03adcf65fc4a
branches:  trunk
changeset: 949757:03adcf65fc4a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 16 02:40:02 2021 +0000

description:
lint: replace 0 and 1 with false and true, where appropriate

Change in behavior: Passing the option -h exactly 4294967296 times or
any multiple thereof is no longer equivalent to passing it never at all,
it is now equivalent to passing it once.  See main2.c, hflag++ for the
actual change.

Other than that, no functional change intended.

A very large portion of the code already conformed to the requirements
of the strict bool mode.  The only missing thing was using the constant
literals false and true instead of 0 and 1.  For sure there are some
integer literals left that can be converted.  For now, all literals that
appeared in the form " = 0" or " = 1" have been replaced.

diffstat:

 usr.bin/xlint/common/emit.c    |    6 +-
 usr.bin/xlint/common/externs.h |    6 +-
 usr.bin/xlint/common/lint.h    |   12 +-
 usr.bin/xlint/common/tyname.c  |   16 +-
 usr.bin/xlint/lint1/cgram.y    |   44 ++--
 usr.bin/xlint/lint1/decl.c     |  314 ++++++++++++++++++++--------------------
 usr.bin/xlint/lint1/emit1.c    |   23 +-
 usr.bin/xlint/lint1/externs1.h |  100 ++++++------
 usr.bin/xlint/lint1/func.c     |  140 +++++++++---------
 usr.bin/xlint/lint1/init.c     |   44 ++--
 usr.bin/xlint/lint1/lint1.h    |    6 +-
 usr.bin/xlint/lint1/main1.c    |   84 +++++-----
 usr.bin/xlint/lint1/mem1.c     |    8 +-
 usr.bin/xlint/lint1/oper.c     |    4 +-
 usr.bin/xlint/lint1/scan.l     |   43 ++--
 usr.bin/xlint/lint1/tree.c     |  198 +++++++++++++------------
 usr.bin/xlint/lint2/chk.c      |  104 +++++++------
 usr.bin/xlint/lint2/externs2.h |   22 +-
 usr.bin/xlint/lint2/hash.c     |   12 +-
 usr.bin/xlint/lint2/main2.c    |   46 +++---
 usr.bin/xlint/lint2/msg.c      |    7 +-
 usr.bin/xlint/lint2/read.c     |  117 +++++++-------
 usr.bin/xlint/xlint/xlint.c    |   32 ++--
 23 files changed, 708 insertions(+), 680 deletions(-)

diffs (truncated from 4638 to 300 lines):

diff -r 6ff549b20c2b -r 03adcf65fc4a usr.bin/xlint/common/emit.c
--- a/usr.bin/xlint/common/emit.c       Sat Jan 16 02:21:26 2021 +0000
+++ b/usr.bin/xlint/common/emit.c       Sat Jan 16 02:40:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: emit.c,v 1.9 2020/12/30 11:47:15 rillig Exp $  */
+/*     $NetBSD: emit.c,v 1.10 2021/01/16 02:40:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit.c,v 1.9 2020/12/30 11:47:15 rillig Exp $");
+__RCSID("$NetBSD: emit.c,v 1.10 2021/01/16 02:40:02 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -139,7 +139,7 @@
 outqchar(int c)
 {
 
-       if (isprint(c) && c != '\\' && c != '"' && c != '\'') {
+       if (ch_isprint(c) && c != '\\' && c != '"' && c != '\'') {
                outchar(c);
        } else {
                outchar('\\');
diff -r 6ff549b20c2b -r 03adcf65fc4a usr.bin/xlint/common/externs.h
--- a/usr.bin/xlint/common/externs.h    Sat Jan 16 02:21:26 2021 +0000
+++ b/usr.bin/xlint/common/externs.h    Sat Jan 16 02:40:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs.h,v 1.13 2021/01/12 20:42:00 rillig Exp $      */
+/*     $NetBSD: externs.h,v 1.14 2021/01/16 02:40:02 rillig Exp $      */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -34,7 +34,7 @@
 /*
  * main[12].c
  */
-extern int     pflag;
+extern bool    pflag;
 /* Treat _Bool as incompatible to all other scalar types. */
 extern bool    Tflag;
 
@@ -47,7 +47,7 @@
  * tyname.c
  */
 extern const char *type_name(const type_t *);
-extern int     sametype(const type_t *, const type_t *);
+extern bool    sametype(const type_t *, const type_t *);
 extern const   char *tspec_name(tspec_t);
 
 /*
diff -r 6ff549b20c2b -r 03adcf65fc4a usr.bin/xlint/common/lint.h
--- a/usr.bin/xlint/common/lint.h       Sat Jan 16 02:21:26 2021 +0000
+++ b/usr.bin/xlint/common/lint.h       Sat Jan 16 02:40:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lint.h,v 1.24 2021/01/10 00:05:45 rillig Exp $ */
+/*     $NetBSD: lint.h,v 1.25 2021/01/16 02:40:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,6 +38,7 @@
 #endif
 
 #include <sys/types.h>
+#include <ctype.h>
 #include <err.h>
 #include <inttypes.h>
 #include <stdbool.h>
@@ -137,3 +138,12 @@
 typedef struct type type_t;
 
 #include "externs.h"
+
+static inline bool
+ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
+static inline bool
+ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
+static inline bool
+ch_isprint(char ch) { return isprint((unsigned char)ch) != 0; }
+static inline bool
+ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
diff -r 6ff549b20c2b -r 03adcf65fc4a usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Sat Jan 16 02:21:26 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Sat Jan 16 02:40:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.22 2021/01/04 22:26:50 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.23 2021/01/16 02:40:02 rillig Exp $       */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.22 2021/01/04 22:26:50 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.23 2021/01/16 02:40:02 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -192,13 +192,13 @@
        }
 }
 
-int
+bool
 sametype(const type_t *t1, const type_t *t2)
 {
        tspec_t t;
 
        if (t1->t_tspec != t2->t_tspec)
-               return 0;
+               return false;
 
        /* Ignore const/void */
 
@@ -231,7 +231,7 @@
                return 1;
        case ARRAY:
                if (t1->t_dim != t2->t_dim)
-                       return 0;
+                       return false;
                /*FALLTHROUGH*/
        case PTR:
                return sametype(t1->t_subt, t2->t_subt);
@@ -240,7 +240,7 @@
                return strcmp(t1->t_enum->etag->s_name,
                    t2->t_enum->etag->s_name) == 0;
 #else
-               return 1;
+               return true;
 #endif
        case STRUCT:
        case UNION:
@@ -248,11 +248,11 @@
                return strcmp(t1->t_str->stag->s_name,
                    t2->t_str->stag->s_name) == 0;
 #else
-               return 1;
+               return true;
 #endif
        default:
                LERROR("tyname(%d)", t);
-               return 0;
+               return false;
        }
 }
 
diff -r 6ff549b20c2b -r 03adcf65fc4a usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jan 16 02:21:26 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jan 16 02:40:02 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.139 2021/01/12 20:42:01 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.140 2021/01/16 02:40:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.139 2021/01/12 20:42:01 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.140 2021/01/16 02:40:02 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -426,7 +426,7 @@
                blklev++;
                pushdecl(ARG);
                if (lwarn == LWARN_NONE)
-                       $1->s_used = 1;
+                       $1->s_used = true;
          } arg_declaration_list_opt {
                popdecl();
                blklev--;
@@ -598,9 +598,9 @@
 
 type_attribute:
          T_ATTRIBUTE T_LPAREN T_LPAREN {
-           attron = 1;
+           attron = true;
          } type_attribute_spec_list {
-           attron = 0;
+           attron = false;
          } T_RPAREN T_RPAREN
        | T_PACKED {
                addpacked();
@@ -1194,9 +1194,9 @@
          T_QUAL {
                $$ = xcalloc(1, sizeof (pqinf_t));
                if ($1 == CONST) {
-                       $$->p_const = 1;
+                       $$->p_const = true;
                } else {
-                       $$->p_volatile = 1;
+                       $$->p_volatile = true;
                }
          }
        ;
@@ -1234,7 +1234,7 @@
                $$ = NULL;
          }
        | abs_decl_lparn vararg_parameter_type_list T_RPAREN {
-               dcs->d_proto = 1;
+               dcs->d_proto = true;
                $$ = $2;
          }
        | abs_decl_lparn error T_RPAREN {
@@ -1254,7 +1254,7 @@
                $$ = $1;
          }
        | parameter_type_list T_COMMA T_ELLIPSE {
-               dcs->d_vararg = 1;
+               dcs->d_vararg = true;
                $$ = $1;
          }
        | T_ELLIPSE {
@@ -1265,7 +1265,7 @@
                        /* ANSI C requires formal parameter before '...' */
                        warning(84);
                }
-               dcs->d_vararg = 1;
+               dcs->d_vararg = true;
                $$ = NULL;
          }
        ;
@@ -1480,7 +1480,7 @@
        | selection_statement
        | iteration_statement
        | jump_statement {
-               ftflg = 0;
+               ftflg = false;
          }
        | asm_statement
 
@@ -1500,16 +1500,16 @@
          }
        | T_CASE constant T_COLON {
                case_label($2);
-               ftflg = 1;
+               ftflg = true;
          }
        | T_CASE constant T_ELLIPSE constant T_COLON {
                /* XXX: We don't fill all cases */
                case_label($2);
-               ftflg = 1;
+               ftflg = true;
          }
        | T_DEFAULT T_COLON {
                default_label();
-               ftflg = 1;
+               ftflg = true;
          }
        ;
 
@@ -1544,7 +1544,7 @@
                freeblk();
                mblklev--;
                blklev--;
-               ftflg = 0;
+               ftflg = false;
          }
        ;
 
@@ -1559,10 +1559,10 @@
 expr_statement:
          expr T_SEMI {
                expr($1, 0, 0, 0);
-               ftflg = 0;
+               ftflg = false;
          }
        | T_SEMI {
-               ftflg = 0;
+               ftflg = false;
          }
        ;
 
@@ -1575,10 +1575,10 @@
          expr T_SEMI {
                /* XXX: We should really do that only on the last name */
                if ($1->tn_op == NAME)
-                       $1->tn_sym->s_used = 1;
+                       $1->tn_sym->s_used = true;
                $$ = $1;
                expr($1, 0, 0, 0);
-               ftflg = 0;
+               ftflg = false;
          }
        | non_expr_statement {
                $$ = getnode();
@@ -1672,7 +1672,7 @@
          }
        | do_statement do_while_expr {
                do2($2);
-               ftflg = 0;
+               ftflg = false;
          }



Home | Main Index | Thread Index | Old Index