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: clean up code related to lint comm...



details:   https://anonhg.NetBSD.org/src/rev/d1eb842408e1
branches:  trunk
changeset: 377461:d1eb842408e1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 13 06:41:27 2023 +0000

description:
lint: clean up code related to lint comments

Remove type information from variable names, as the word 'flag' did not
indicate that the variables were negated.

Remove contradicting comments. Suppressing a warning for 'this line',
'this and the following line' and 'this statement or declaration' cannot
all be accurate at the same time.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  22 +++++-----
 usr.bin/xlint/lint1/decl.c     |  23 ++++-------
 usr.bin/xlint/lint1/externs1.h |  10 ++--
 usr.bin/xlint/lint1/func.c     |  81 +++++++++++------------------------------
 usr.bin/xlint/lint1/lex.c      |   8 ++--
 usr.bin/xlint/lint1/tree.c     |  10 ++--
 6 files changed, 57 insertions(+), 97 deletions(-)

diffs (truncated from 489 to 300 lines):

diff -r b7292259596b -r d1eb842408e1 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Wed Jul 12 20:13:28 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Thu Jul 13 06:41:27 2023 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.458 2023/07/13 06:41:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.458 2023/07/13 06:41:27 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -614,7 +614,7 @@ gcc_statement_expr_item:
                        if ($1->tn_op == NAME)
                                $1->tn_sym->s_used = true;
                        expr($1, false, false, false, false);
-                       seen_fallthrough = false;
+                       suppress_fallthrough = false;
                        $$ = $1;
                }
        }
@@ -1764,7 +1764,7 @@ non_expr_statement:               /* helper for C99 6
 |      selection_statement
 |      iteration_statement
 |      jump_statement {
-               seen_fallthrough = false;
+               suppress_fallthrough = false;
        }
 |      asm_statement
 ;
@@ -1780,16 +1780,16 @@ label:
        }
 |      T_CASE constant_expression T_COLON {
                case_label($2);
-               seen_fallthrough = true;
+               suppress_fallthrough = true;
        }
 |      T_CASE constant_expression T_ELLIPSIS constant_expression T_COLON {
                /* XXX: We don't fill all cases */
                case_label($2);
-               seen_fallthrough = true;
+               suppress_fallthrough = true;
        }
 |      T_DEFAULT T_COLON {
                default_label();
-               seen_fallthrough = true;
+               suppress_fallthrough = true;
        }
 ;
 
@@ -1812,7 +1812,7 @@ compound_statement_rbrace:
                level_free_all(mem_block_level);
                mem_block_level--;
                block_level--;
-               seen_fallthrough = false;
+               suppress_fallthrough = false;
        }
 ;
 
@@ -1840,11 +1840,11 @@ block_item:                     /* C99 6.8.2 */
 expression_statement:          /* C99 6.8.3 */
        expression T_SEMI {
                expr($1, false, false, false, false);
-               seen_fallthrough = false;
+               suppress_fallthrough = false;
        }
 |      T_SEMI {
                check_statement_reachable();
-               seen_fallthrough = false;
+               suppress_fallthrough = false;
        }
 ;
 
@@ -1905,7 +1905,7 @@ iteration_statement:              /* C99 6.8.5 */
        }
 |      do_statement do_while_expr {
                stmt_do_while_expr($2);
-               seen_fallthrough = false;
+               suppress_fallthrough = false;
        }
 |      do error {
                clear_warning_flags();
diff -r b7292259596b -r d1eb842408e1 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Wed Jul 12 20:13:28 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Thu Jul 13 06:41:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.349 2023/07/12 16:07:35 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.350 2023/07/13 06:41:27 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.349 2023/07/12 16:07:35 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.350 2023/07/13 06:41:27 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -303,7 +303,7 @@ dcs_add_type(type_t *tp)
                /* "long long" or "long ... long" */
                t = LLONG;
                dcs->d_rank_mod = NO_TSPEC;
-               if (!long_long_flag)
+               if (!suppress_longlong)
                        /* %s does not support 'long long' */
                        c99ism(265, allow_c90 ? "C90" : "traditional C");
        }
@@ -962,7 +962,7 @@ check_bit_field_type(sym_t *dsym, type_t
 
        if (t == CHAR || t == UCHAR || t == SCHAR ||
            t == SHORT || t == USHORT || t == ENUM) {
-               if (!bitfieldtype_ok) {
+               if (!suppress_bitfieldtype) {
                        /* TODO: Make this an error in C99 mode as well. */
                        if (!allow_trad && !allow_c99) {
                                type_t *btp = block_dup_type(tp);
@@ -977,19 +977,18 @@ check_bit_field_type(sym_t *dsym, type_t
                        }
                }
        } else if (t == INT && dcs->d_sign_mod == NO_TSPEC) {
-               if (pflag && !bitfieldtype_ok) {
+               if (pflag && !suppress_bitfieldtype) {
                        /* bit-field of type plain 'int' has ... */
                        warning(344);
                }
-       } else if (!(t == INT || t == UINT || t == BOOL ||
-                    (is_integer(t) && (bitfieldtype_ok || allow_gcc)))) {
+       } else if (!(t == INT || t == UINT || t == BOOL
+               || (is_integer(t) && (suppress_bitfieldtype || allow_gcc)))) {
 
                type_t *btp = block_dup_type(tp);
                btp->t_bitfield = false;
                /* illegal bit-field type '%s' */
                warning(35, type_name(btp));
 
-               // XXX: What about _Bool bit-fields since C99 6.7.2.1?
                unsigned int width = tp->t_bit_field_width;
                dsym->s_type = tp = block_dup_type(gettyp(t = INT));
                if ((tp->t_bit_field_width = width) > size_in_bits(t))
@@ -1067,7 +1066,7 @@ declare_unnamed_member(void)
        mem->s_block_level = -1;
 
        dcs_add_member(mem);
-       bitfieldtype_ok = false;
+       suppress_bitfieldtype = false;
        return mem;
 }
 
@@ -1115,11 +1114,7 @@ declare_member(sym_t *dsym)
 
        check_function_definition(dsym, false);
 
-       /*
-        * Clear the BITFIELDTYPE indicator after processing each
-        * structure element.
-        */
-       bitfieldtype_ok = false;
+       suppress_bitfieldtype = false;
 
        return dsym;
 }
diff -r b7292259596b -r d1eb842408e1 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Wed Jul 12 20:13:28 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Thu Jul 13 06:41:27 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.191 2023/07/12 16:07:35 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.192 2023/07/13 06:41:27 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -293,7 +293,7 @@ tnode_t *end_statement_expr(void);
 extern sym_t   *funcsym;
 extern bool    reached;
 extern bool    warn_about_unreachable;
-extern bool    seen_fallthrough;
+extern bool    suppress_fallthrough;
 extern int     nargusg;
 extern pos_t   argsused_pos;
 extern int     nvararg;
@@ -302,12 +302,12 @@ extern    int     printflike_argnum;
 extern pos_t   printflike_pos;
 extern int     scanflike_argnum;
 extern pos_t   scanflike_pos;
-extern bool    constcond_flag;
+extern bool    suppress_constcond;
 extern bool    llibflg;
 extern int     lwarn;
-extern bool    bitfieldtype_ok;
+extern bool    suppress_bitfieldtype;
 extern bool    plibflg;
-extern bool    long_long_flag;
+extern bool    suppress_longlong;
 
 void   begin_control_statement(control_statement_kind);
 void   end_control_statement(control_statement_kind);
diff -r b7292259596b -r d1eb842408e1 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Wed Jul 12 20:13:28 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Thu Jul 13 06:41:27 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.167 2023/07/09 12:15:07 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.168 2023/07/13 06:41:27 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.167 2023/07/09 12:15:07 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.168 2023/07/13 06:41:27 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -67,13 +67,14 @@ bool        warn_about_unreachable;
  * Reset by each statement and set by FALLTHROUGH, stmt_switch_expr and
  * case_label.
  *
- * Control statements if, for, while and switch do not reset seen_fallthrough
- * because this must be done by the controlled statement. At least for if this
- * is important because ** FALLTHROUGH ** after "if (expr) statement" is
- * evaluated before the following token, which causes reduction of above.
- * This means that ** FALLTHROUGH ** after "if ..." would always be ignored.
+ * The control statements 'if', 'for', 'while' and 'switch' do not reset
+ * suppress_fallthrough because this must be done by the controlled statement.
+ * At least for 'if', this is important because ** FALLTHROUGH ** after "if
+ * (expr) statement" is evaluated before the following token, which causes
+ * reduction of above. This means that ** FALLTHROUGH ** after "if ..." would
+ * always be ignored.
  */
-bool   seen_fallthrough;
+bool   suppress_fallthrough;
 
 /* The innermost control statement */
 static control_statement *cstmt;
@@ -115,11 +116,8 @@ pos_t      scanflike_pos;
  */
 bool   plibflg;
 
-/*
- * True means that no warnings about constants in conditional
- * context are printed.
- */
-bool   constcond_flag;
+/* Temporarily suppress warnings about constants in conditional context. */
+bool   suppress_constcond;
 
 /*
  * Whether a lint library shall be created. The effect of this flag is that
@@ -138,17 +136,11 @@ bool      llibflg;
  */
 int    lwarn = LWARN_ALL;
 
-/*
- * Whether bitfield type errors are suppressed by a BITFIELDTYPE
- * directive.
- */
-bool   bitfieldtype_ok;
+/* Temporarily suppress warnings about wrong types for bit-fields. */
+bool   suppress_bitfieldtype;
 
-/*
- * Whether complaints about use of "long long" are suppressed in
- * the next statement or declaration.
- */
-bool   long_long_flag;
+/* Temporarily suppress warnings about use of 'long long'. */
+bool   suppress_longlong;
 
 void
 begin_control_statement(control_statement_kind kind)
@@ -514,7 +506,7 @@ check_case_label(tnode_t *tn, control_st
 
        lint_assert(cs->c_switch_type != NULL);
 
-       if (reached && !seen_fallthrough) {
+       if (reached && !suppress_fallthrough) {
                if (hflag)
                        /* fallthrough on case statement */
                        warning(220);
@@ -591,7 +583,7 @@ default_label(void)
                /* duplicate default in switch */
                error(202);
        } else {
-               if (reached && !seen_fallthrough) {
+               if (reached && !suppress_fallthrough) {
                        if (hflag)
                                /* fallthrough on default statement */
                                warning(284);
@@ -718,7 +710,7 @@ stmt_switch_expr(tnode_t *tn)
        cstmt->c_switch_expr = tn;
 



Home | Main Index | Thread Index | Old Index