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: clean up visual clutter



details:   https://anonhg.NetBSD.org/src/rev/f9eef8f1f2a0
branches:  trunk
changeset: 369702:f9eef8f1f2a0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 28 12:04:47 2022 +0000

description:
lint: clean up visual clutter

No functional change.

diffstat:

 usr.bin/xlint/lint1/decl.c     |  503 ++++++++++++++++++----------------------
 usr.bin/xlint/lint1/externs1.h |    8 +-
 usr.bin/xlint/lint1/init.c     |    6 +-
 usr.bin/xlint/lint1/tree.c     |   41 +-
 usr.bin/xlint/lint2/chk.c      |   30 +-
 5 files changed, 269 insertions(+), 319 deletions(-)

diffs (truncated from 1464 to 300 lines):

diff -r b0ba1f69a8b5 -r f9eef8f1f2a0 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Aug 28 11:32:19 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Aug 28 12:04:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.297 2022/08/28 10:43:18 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.298 2022/08/28 12:04:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.297 2022/08/28 10:43:18 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.298 2022/08/28 12:04:47 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -66,7 +66,7 @@
 static void    set_first_typedef(type_t *, sym_t *);
 static void    dcs_align(unsigned int, unsigned int);
 static sym_t   *new_tag(sym_t *, scl_t, bool, bool);
-static bool    eq_prototype_args(const type_t *, const type_t *, bool *);
+static bool    prototypes_compatible(const type_t *, const type_t *, bool *);
 static bool    matches_no_arg_function(const type_t *, bool *);
 static bool    check_old_style_definition(sym_t *, sym_t *);
 static bool    check_prototype_declaration(sym_t *, sym_t *);
@@ -190,8 +190,8 @@
         * In case of a struct or union type, the members should lose their
         * qualifiers as well, but that would require a deep copy of the
         * struct or union type.  This in turn would defeat the type
-        * comparison in eqtype, which simply tests whether tp1->t_str ==
-        * tp2->t_str.
+        * comparison in types_compatible, which simply tests whether
+        * tp1->t_str == tp2->t_str.
         */
 
        return ntp;
@@ -206,15 +206,15 @@
 {
        tspec_t t;
 
-       if ((t = tp->t_tspec) == VOID) {
+       if ((t = tp->t_tspec) == VOID)
                return true;
-       } else if (t == ARRAY) {
+       if (t == ARRAY)
                return tp->t_incomplete_array;
-       } else if (is_struct_or_union(t)) {
+       if (is_struct_or_union(t))
                return tp->t_str->sou_incomplete;
-       } else if (t == ENUM) {
+       if (t == ENUM)
                return tp->t_enum->en_incomplete;
-       }
+
        return false;
 }
 
@@ -233,16 +233,17 @@
                dcs->d_inline = true;
                return;
        }
+
        if (dcs->d_type != NULL || dcs->d_abstract_type != NOTSPEC ||
            dcs->d_sign_mod != NOTSPEC || dcs->d_rank_mod != NOTSPEC) {
                /* storage class after type is obsolescent */
                warning(83);
        }
-       if (dcs->d_scl == NOSCL) {
+
+       if (dcs->d_scl == NOSCL)
                dcs->d_scl = sc;
-       } else {
+       else
                dcs->d_multiple_storage_classes = true;
-       }
 }
 
 /*
@@ -419,31 +420,33 @@
                return td;
        }
 
-       if (t == LONG &&
-           (t2 == INT || t2 == UINT || t2 == LONG || t2 == ULONG ||
-            t2 == FLOAT || t2 == DOUBLE || t2 == DCOMPLEX)) {
-               /* modifying typedef with '%s'; only qualifiers allowed */
-               warning(5, "long");
-               if (t2 == INT) {
-                       td = gettyp(LONG);
-               } else if (t2 == UINT) {
-                       td = gettyp(ULONG);
-               } else if (t2 == LONG) {
-                       td = gettyp(QUAD);
-               } else if (t2 == ULONG) {
-                       td = gettyp(UQUAD);
-               } else if (t2 == FLOAT) {
-                       td = gettyp(DOUBLE);
-               } else if (t2 == DOUBLE) {
-                       td = gettyp(LDOUBLE);
-               } else if (t2 == DCOMPLEX) {
-                       td = gettyp(LCOMPLEX);
-               }
-               td = block_dup_type(td);
-               td->t_typedef = true;
-               return td;
-       }
-
+       if (t != LONG)
+               goto invalid;
+
+       if (t2 == INT)
+               td = gettyp(LONG);
+       else if (t2 == UINT)
+               td = gettyp(ULONG);
+       else if (t2 == LONG)
+               td = gettyp(QUAD);
+       else if (t2 == ULONG)
+               td = gettyp(UQUAD);
+       else if (t2 == FLOAT)
+               td = gettyp(DOUBLE);
+       else if (t2 == DOUBLE)
+               td = gettyp(LDOUBLE);
+       else if (t2 == DCOMPLEX)
+               td = gettyp(LCOMPLEX);
+       else
+               goto invalid;
+
+       /* modifying typedef with '%s'; only qualifiers allowed */
+       warning(5, "long");
+       td = block_dup_type(td);
+       td->t_typedef = true;
+       return td;
+
+invalid:
        /* Anything else is not accepted. */
        dcs->d_invalid_type_combination = true;
        return td;
@@ -463,7 +466,7 @@
 {
        tspec_t t;
 
-       if ((t = tp->t_tspec) == STRUCT || t == UNION) {
+       if (is_struct_or_union(t = tp->t_tspec)) {
                if (tp->t_str->sou_first_typedef == NULL)
                        tp->t_str->sou_first_typedef = sym;
        } else if (t == ENUM) {
@@ -619,9 +622,8 @@
                        dcs->d_func_proto_syms = di->d_dlsyms;
                }
                break;
-       case DK_ABSTRACT:
+       case DK_ABSTRACT:       /* casts and sizeof */
                /*
-                * casts and sizeof
                 * Append all symbols declared in the abstract declaration
                 * to the list of symbols declared in the surrounding
                 * declaration or block.
@@ -668,9 +670,8 @@
 void
 dcs_set_asm(void)
 {
-       dinfo_t *di;
-
-       for (di = dcs; di != NULL; di = di->d_enclosing)
+
+       for (dinfo_t *di = dcs; di != NULL; di = di->d_enclosing)
                di->d_asm = true;
 }
 
@@ -786,10 +787,9 @@
 }
 
 /*
- * Create a type structure from the information gathered in
- * the declaration stack.
- * Complain about storage classes which are not possible in current
- * context.
+ * Create a type structure from the information gathered in the declaration
+ * stack.
+ * Complain about storage classes which are not possible in current context.
  */
 void
 dcs_end_type(void)
@@ -894,15 +894,15 @@
        while (tp->t_tspec == ARRAY)
                tp = tp->t_subt;
 
-       if (is_struct_or_union(t = tp->t_tspec)) {
+       if (is_struct_or_union(t = tp->t_tspec))
                a = tp->t_str->sou_align_in_bits;
-       } else {
+       else {
                lint_assert(t != FUNC);
-               if ((a = size_in_bits(t)) == 0) {
+               if ((a = size_in_bits(t)) == 0)
                        a = CHAR_SIZE;
-               } else if (a > worst_align_in_bits) {
+               else if (a > worst_align_in_bits)
                        a = worst_align_in_bits;
-               }
+
        }
        lint_assert(a >= CHAR_SIZE);
        lint_assert(a <= worst_align_in_bits);
@@ -960,14 +960,11 @@
                        if (t == FUNC || t == ARRAY) {
                                /* function returns illegal type '%s' */
                                error(15, type_name(tp));
-                               if (t == FUNC) {
-                                       *tpp = block_derive_type(*tpp, PTR);
-                               } else {
-                                       *tpp = block_derive_type(
-                                           (*tpp)->t_subt, PTR);
-                               }
+                               *tpp = block_derive_type(
+                                   t == FUNC ? *tpp : (*tpp)->t_subt, PTR);
                                return;
-                       } else if (tp->t_const || tp->t_volatile) {
+                       }
+                       if (tp->t_const || tp->t_volatile) {
                                /* TODO: Make this a warning in C99 mode as well. */
                                if (!allow_trad && !allow_c99) {        /* XXX or better allow_c90? */
                                        /* function cannot return const... */
@@ -980,27 +977,21 @@
                                error(16);
                                *tpp = gettyp(INT);
                                return;
-                       } else if (t == ARRAY && tp->t_dim == 0) {
+                       }
+                       if (t == ARRAY && tp->t_dim == 0) {
                                /* null dimension */
                                error(17);
                                return;
-                       } else if (t == VOID) {
+                       }
+                       if (t == VOID) {
                                /* illegal use of 'void' */
                                error(18);
                                *tpp = gettyp(INT);
-#if 0  /* errors are produced by length_in_bits */
-                       } else if (is_incomplete(tp)) {
-                               /* array of incomplete type */
-                               /* TODO: Make this an error in C99 mode as well. */
-                               if (!allow_trad && !allow_c99) {
-                                       /* array of incomplete type */
-                                       error(301);
-                               } else {
-                                       /* array of incomplete type */
-                                       warning(301);
-                               }
-#endif
                        }
+                       /*
+                        * No need to check for incomplete types here as
+                        * length_in_bits already does this.
+                        */
                } else if (to == NOTSPEC && t == VOID) {
                        if (dcs->d_kind == DK_PROTO_ARG) {
                                if (sym->s_scl != ABSTRACT) {
@@ -1139,9 +1130,9 @@
 
        t = (tp = dsym->s_type)->t_tspec;
 
-       if (dsym->s_bitfield) {
+       if (dsym->s_bitfield)
                declare_bit_field(dsym, &t, &tp);
-       } else if (t == FUNC) {
+       else if (t == FUNC) {
                /* function illegal in structure or union */
                error(38);
                dsym->s_type = tp = block_derive_type(tp, t = PTR);
@@ -1175,10 +1166,8 @@
                dsym->u.s_member.sm_offset_in_bits = dcs->d_offset_in_bits;
                dcs->d_offset_in_bits += sz;
        }
-       if (dcs->d_kind == DK_MOU) {
-               if (o > dcs->d_offset_in_bits)
-                       dcs->d_offset_in_bits = o;
-       }
+       if (dcs->d_kind == DK_MOU && o > dcs->d_offset_in_bits)
+               dcs->d_offset_in_bits = o;
 
        check_function_definition(dsym, false);
 
@@ -1299,12 +1288,10 @@
 sym_t *
 add_pointer(sym_t *decl, qual_ptr *p)
 {
-       type_t **tpp;
-       qual_ptr *next;
 
        debug_dinfo(dcs);
 
-       tpp = &decl->s_type;
+       type_t **tpp = &decl->s_type;
        while (*tpp != NULL && *tpp != dcs->d_type)
                tpp = &(*tpp)->t_subt;
        if (*tpp == NULL) {



Home | Main Index | Thread Index | Old Index