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 integer constant expressions wit...



details:   https://anonhg.NetBSD.org/src/rev/652b211b19ec
branches:  trunk
changeset: 949771:652b211b19ec
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 16 16:53:23 2021 +0000

description:
lint: replace integer constant expressions with true and false

LINTFLAGS=-gST make lint, with manual review.

The error messages from lint are all correct, they are not complete
though.  The return value of a function returning bool may still be
compared to the integer 0.

diffstat:

 usr.bin/xlint/common/tyname.c |   8 ++--
 usr.bin/xlint/lint1/decl.c    |  71 +++++++++++++++++++++---------------------
 usr.bin/xlint/lint1/emit1.c   |   8 ++--
 usr.bin/xlint/lint1/func.c    |  28 ++++++++--------
 usr.bin/xlint/lint1/init.c    |  24 +++++++-------
 usr.bin/xlint/lint1/lint1.h   |   8 ++--
 usr.bin/xlint/lint1/main1.c   |   6 +-
 usr.bin/xlint/lint1/tree.c    |  18 +++++-----
 usr.bin/xlint/lint2/chk.c     |  46 ++++++++++++++-------------
 usr.bin/xlint/lint2/read.c    |  24 +++++++-------
 usr.bin/xlint/xlint/xlint.c   |  26 +++++++-------
 11 files changed, 135 insertions(+), 132 deletions(-)

diffs (truncated from 1048 to 300 lines):

diff -r 735617a3507c -r 652b211b19ec usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Sat Jan 16 16:03:46 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Sat Jan 16 16:53:23 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.23 2021/01/16 02:40:02 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.24 2021/01/16 16:53:23 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.23 2021/01/16 02:40:02 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.24 2021/01/16 16:53:23 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -50,7 +50,7 @@
        do { \
                (void)warnx("%s, %d: " fmt, __FILE__, __LINE__, ##args); \
                abort(); \
-       } while (/*CONSTCOND*/0)
+       } while (/*CONSTCOND*/false)
 #endif
 
 /* A tree of strings. */
@@ -228,7 +228,7 @@
        case FCOMPLEX:
        case DCOMPLEX:
        case LCOMPLEX:
-               return 1;
+               return true;
        case ARRAY:
                if (t1->t_dim != t2->t_dim)
                        return false;
diff -r 735617a3507c -r 652b211b19ec usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jan 16 16:03:46 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jan 16 16:53:23 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.123 2021/01/16 16:03:46 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.124 2021/01/16 16:53:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.123 2021/01/16 16:03:46 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.124 2021/01/16 16:53:23 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -177,7 +177,7 @@
        tspec_t t;
 
        if ((t = tp->t_tspec) == VOID) {
-               return 1;
+               return true;
        } else if (t == ARRAY) {
                return tp->t_aincompl;
        } else if (t == STRUCT || t == UNION) {
@@ -185,7 +185,7 @@
        } else if (t == ENUM) {
                return tp->t_enum->eincompl;
        }
-       return 0;
+       return false;
 }
 
 /*
@@ -661,7 +661,7 @@
                /* there is nothing after external declarations */
                /* FALLTHROUGH */
        default:
-               lint_assert(/*CONSTCOND*/0);
+               lint_assert(/*CONSTCOND*/false);
        }
        free(di);
 }
@@ -1190,7 +1190,7 @@
                        dcs->d_offset = o;
        }
 
-       check_function_definition(dsym, 0);
+       check_function_definition(dsym, false);
 
        /*
         * Clear the BITFIELDTYPE indicator after processing each
@@ -1344,7 +1344,7 @@
                /* zero sized array is a C99 extension */
                c99ism(322);
        } else if (n == 0 && !dim) {
-               setcomplete(tp, 0);
+               setcomplete(tp, false);
        }
 
        return decl;
@@ -1568,7 +1568,7 @@
                }
                break;
        default:
-               lint_assert(/*CONSTCOND*/0);
+               lint_assert(/*CONSTCOND*/false);
        }
        sym->s_scl = sc;
 
@@ -1668,7 +1668,7 @@
                        tp->t_enum = getblk(sizeof(*tp->t_enum));
                        tp->t_enum->etag = tag;
                }
-               setcomplete(tp, 0);
+               setcomplete(tp, false);
        }
        return tp;
 }
@@ -1751,7 +1751,7 @@
        case STRTAG:    s = "struct";   break;
        case UNIONTAG:  s = "union";    break;
        case ENUMTAG:   s = "enum";     break;
-       default:        lint_assert(/*CONSTCOND*/0);
+       default:        lint_assert(/*CONSTCOND*/false);
        }
        return s;
 }
@@ -1767,7 +1767,7 @@
        int     n;
        sym_t   *mem;
 
-       setcomplete(tp, 1);
+       setcomplete(tp, true);
 
        t = tp->t_tspec;
        align(dcs->d_stralign, 0);
@@ -1811,7 +1811,7 @@
 complete_tag_enum(type_t *tp, sym_t *fmem)
 {
 
-       setcomplete(tp, 1);
+       setcomplete(tp, true);
        tp->t_enum->elem = fmem;
        return tp;
 }
@@ -1872,7 +1872,7 @@
        bool    dowarn, rval, redec;
        sym_t   *rdsym;
 
-       check_function_definition(dsym, 1);
+       check_function_definition(dsym, true);
 
        check_type(dsym);
 
@@ -1904,7 +1904,7 @@
                 * written as a function definition to the output file.
                 */
                rval = dsym->s_type->t_subt->t_tspec != VOID;
-               outfdef(dsym, &dsym->s_def_pos, rval, 0, NULL);
+               outfdef(dsym, &dsym->s_def_pos, rval, false, NULL);
        } else {
                outsym(dsym, dsym->s_scl, dsym->s_def);
        }
@@ -2034,7 +2034,7 @@
                print_previous_declaration(-1, rsym);
                return true;
        }
-       if (!eqtype(rsym->s_type, dsym->s_type, 0, 0, dowarn)) {
+       if (!eqtype(rsym->s_type, dsym->s_type, false, false, dowarn)) {
                /* redeclaration of %s */
                error(27, dsym->s_name);
                print_previous_declaration(-1, rsym);
@@ -2135,30 +2135,30 @@
                }
 
                if (t != tp2->t_tspec)
-                       return 0;
+                       return false;
 
                if (!qualifiers_correspond(tp1, tp2, ignqual))
-                       return 0;
+                       return false;
 
                if (t == STRUCT || t == UNION)
                        return tp1->t_str == tp2->t_str;
 
                if (t == ARRAY && tp1->t_dim != tp2->t_dim) {
                        if (tp1->t_dim != 0 && tp2->t_dim != 0)
-                               return 0;
+                               return false;
                }
 
                /* dont check prototypes for traditional */
                if (t == FUNC && !tflag) {
                        if (tp1->t_proto && tp2->t_proto) {
                                if (!eqargs(tp1, tp2, dowarn))
-                                       return 0;
+                                       return false;
                        } else if (tp1->t_proto) {
                                if (!mnoarg(tp1, dowarn))
-                                       return 0;
+                                       return false;
                        } else if (tp2->t_proto) {
                                if (!mnoarg(tp2, dowarn))
-                                       return 0;
+                                       return false;
                        }
                }
 
@@ -2180,15 +2180,15 @@
        sym_t   *a1, *a2;
 
        if (tp1->t_vararg != tp2->t_vararg)
-               return 0;
+               return false;
 
        a1 = tp1->t_args;
        a2 = tp2->t_args;
 
        while (a1 != NULL && a2 != NULL) {
 
-               if (eqtype(a1->s_type, a2->s_type, 1, 0, dowarn) == 0)
-                       return 0;
+               if (eqtype(a1->s_type, a2->s_type, true, false, dowarn) == 0)
+                       return false;
 
                a1 = a1->s_next;
                a2 = a2->s_next;
@@ -2266,7 +2266,8 @@
                 * If it does not match due to promotion and sflag is
                 * not set we print only a warning.
                 */
-               if (!eqtype(arg->s_type, parg->s_type, 1, 1, &dowarn) || dowarn) {
+               if (!eqtype(arg->s_type, parg->s_type, true, true, &dowarn) ||
+                   dowarn) {
                        /* prototype does not match old style defn., arg #%d */
                        error(299, n);
                        msg = true;
@@ -2310,7 +2311,7 @@
                        if (dst->t_dim == 0 && src->t_dim != 0) {
                                *dstp = dst = duptyp(dst);
                                dst->t_dim = src->t_dim;
-                               setcomplete(dst, 1);
+                               setcomplete(dst, true);
                        }
                } else if (dst->t_tspec == FUNC) {
                        if (!dst->t_proto && src->t_proto) {
@@ -2332,7 +2333,7 @@
 {
        tspec_t t;
 
-       check_function_definition(sym, 1);
+       check_function_definition(sym, true);
 
        check_type(sym);
 
@@ -2536,8 +2537,8 @@
        msg = false;
        dowarn = false;
 
-       if (!eqtype(tp, ptp, 1, 1, &dowarn)) {
-               if (eqtype(tp, ptp, 1, 0, &dowarn)) {
+       if (!eqtype(tp, ptp, true, true, &dowarn)) {
+               if (eqtype(tp, ptp, true, false, &dowarn)) {
                        /* type does not match prototype: %s */
                        gnuism(58, arg->s_name);
                        msg = sflag || !gflag;
@@ -2601,7 +2602,7 @@
                }
        }
 
-       check_function_definition(dsym, 1);
+       check_function_definition(dsym, true);
 
        check_type(dsym);
 
@@ -2647,7 +2648,7 @@
                                 */
                                break;
                        default:
-                               lint_assert(/*CONSTCOND*/0);
+                               lint_assert(/*CONSTCOND*/false);
                        }
 
                } else if (dcs->d_rdcsym->s_blklev == blklev) {
@@ -2731,7 +2732,7 @@
        }
 
        dowarn = false;
-       eqt = eqtype(esym->s_type, dsym->s_type, 0, 0, &dowarn);
+       eqt = eqtype(esym->s_type, dsym->s_type, false, false, &dowarn);
 
        if (!eqt || dowarn) {
                if (esym->s_scl == EXTERN) {
@@ -2833,7 +2834,7 @@
         * remove all information about pending lint directives without
         * warnings.
         */
-       global_clean_up_decl(1);
+       global_clean_up_decl(true);
 }



Home | Main Index | Thread Index | Old Index