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: align comments in code with actual...



details:   https://anonhg.NetBSD.org/src/rev/3e49c0a2e1ea
branches:  trunk
changeset: 958314:3e49c0a2e1ea
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 01 00:00:24 2021 +0000

description:
lint: align comments in code with actual messages

Redundancy is bad.  Especially in this case, separating the format
strings from the actual arguments prevents the compiler from
cross-checking them.

diffstat:

 usr.bin/xlint/lint1/check-msgs.lua |   24 ++++++-
 usr.bin/xlint/lint1/decl.c         |   46 +++++++-------
 usr.bin/xlint/lint1/func.c         |   18 +++---
 usr.bin/xlint/lint1/init.c         |    8 +-
 usr.bin/xlint/lint1/tree.c         |  110 ++++++++++++++++++------------------
 5 files changed, 111 insertions(+), 95 deletions(-)

diffs (truncated from 806 to 300 lines):

diff -r 417da06567d9 -r 3e49c0a2e1ea usr.bin/xlint/lint1/check-msgs.lua
--- a/usr.bin/xlint/lint1/check-msgs.lua        Thu Dec 31 22:48:33 2020 +0000
+++ b/usr.bin/xlint/lint1/check-msgs.lua        Fri Jan 01 00:00:24 2021 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.1 2020/12/31 22:48:33 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.2 2021/01/01 00:00:24 rillig Exp $
 
 --[[
 
@@ -36,12 +36,28 @@
     return
   end
 
+  msg = string.gsub(msg, "/%*", "**")
+  msg = string.gsub(msg, "%*/", "**")
+  comment = string.gsub(comment, "arg%.", "argument")
+  comment = string.gsub(comment, "bitop%.", "bitwise operation")
+  comment = string.gsub(comment, "comb%.", "combination")
+  comment = string.gsub(comment, "conv%.", "conversion")
+  comment = string.gsub(comment, "decl%.", "declaration")
+  comment = string.gsub(comment, "defn%.", "definition")
+  comment = string.gsub(comment, "expr%.", "expression")
+  comment = string.gsub(comment, "func%.", "function")
+  comment = string.gsub(comment, "incomp%.", "incompatible")
+  comment = string.gsub(comment, "init%.", "initialize")
+  comment = string.gsub(comment, "param%.", "parameter")
+  comment = string.gsub(comment, "poss%.", "possibly")
+  comment = string.gsub(comment, "trad%.", "traditional")
+
   if comment == msg then
     return
   end
 
-  local prefix = comment:match("(.*) %.%.%.$")
-  if prefix ~= nil and msg:find(prefix) == 1 then
+  local prefix = comment:match("^(.-)%s*%.%.%.$")
+  if prefix ~= nil and msg:find(prefix, 1, 1) == 1 then
     return
   end
 
@@ -66,7 +82,7 @@
       id = line:match("^%s+error%((%d+)[),]")
     end
     if id ~= nil then
-      local comment = prev:match("^%s+/%*%s+(.+)%s+%*/$")
+      local comment = prev:match("^%s+/%* (.+) %*/$")
       if comment ~= nil then
         check_message(fname, lineno, tonumber(id), comment, msgs, errors)
       end
diff -r 417da06567d9 -r 3e49c0a2e1ea usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Thu Dec 31 22:48:33 2020 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Jan 01 00:00:24 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.87 2020/12/30 13:17:42 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.88 2021/01/01 00:00:24 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.87 2020/12/30 13:17:42 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.88 2021/01/01 00:00:24 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -562,7 +562,7 @@
 
        if (q == CONST) {
                if (dcs->d_const) {
-                       /* duplicate "%s" */
+                       /* duplicate '%s' */
                        warning(10, "const");
                }
                dcs->d_const = 1;
@@ -572,7 +572,7 @@
                if (q != VOLATILE)
                        LERROR("add_qualifier()");
                if (dcs->d_volatile) {
-                       /* duplicate "%s" */
+                       /* duplicate '%s' */
                        warning(10, "volatile");
                }
                dcs->d_volatile = 1;
@@ -772,7 +772,7 @@
                                l = NOTSPEC;
                                t = DOUBLE;
                                if (!tflag)
-                                       /* use 'double' instead of ...  */
+                                       /* use 'double' instead of 'long ... */
                                        warning(6);
                        }
                        break;
@@ -828,7 +828,7 @@
                }
        } else if (dcs->d_ctx == ARG || dcs->d_ctx == PARG) {
                if (scl != NOSCL && scl != REG) {
-                       /* only "register" valid ... */
+                       /* only register valid ... */
                        error(9);
                        scl = NOSCL;
                }
@@ -839,13 +839,13 @@
        if (dcs->d_const && dcs->d_type->t_const) {
                if (!dcs->d_type->t_typedef)
                        LERROR("deftyp()");
-               /* typedef already qualified with "%s" */
+               /* typedef already qualified with '%s' */
                warning(68, "const");
        }
        if (dcs->d_volatile && dcs->d_type->t_volatile) {
                if (!dcs->d_type->t_typedef)
                        LERROR("deftyp()");
-               /* typedef already qualified with "%s" */
+               /* typedef already qualified with '%s' */
                warning(68, "volatile");
        }
 
@@ -1034,7 +1034,7 @@
                                error(17);
                                return;
                        } else if (t == VOID) {
-                               /* illegal use of void */
+                               /* illegal use of 'void' */
                                error(18);
                                *tpp = gettyp(INT);
 #if 0  /* errors are produced by length() */
@@ -1052,7 +1052,7 @@
                                if (sym->s_scl != ABSTRACT) {
                                        if (sym->s_name == unnamed)
                                                LERROR("check_type()");
-                                       /* void param cannot have name: %s */
+                                       /* void param. cannot have name: %s */
                                        error(61, sym->s_name);
                                        *tpp = gettyp(INT);
                                }
@@ -1066,7 +1066,7 @@
                }
                if (t == VOID && to != PTR) {
                        if (tp->t_const || tp->t_volatile) {
-                               /* inappropriate qualifiers with "void" */
+                               /* inappropriate qualifiers with 'void' */
                                warning(69);
                                tp->t_const = tp->t_volatile = 0;
                        }
@@ -1149,7 +1149,7 @@
                        }
                }
                if ((len = tp->t_flen) < 0 || len > (ssize_t)size(t)) {
-                       /* illegal bit-field size */
+                       /* illegal bit-field size: %d */
                        error(36, len);
                        tp->t_flen = size(t);
                } else if (len == 0 && dsym->s_name != unnamed) {
@@ -1276,14 +1276,14 @@
        } else {
                if (p2->p_const) {
                        if (p1->p_const) {
-                               /* duplicate %s */
+                               /* duplicate '%s' */
                                warning(10, "const");
                        }
                        p1->p_const = 1;
                }
                if (p2->p_volatile) {
                        if (p1->p_volatile) {
-                               /* duplicate %s */
+                               /* duplicate '%s' */
                                warning(10, "volatile");
                        }
                        p1->p_volatile = 1;
@@ -1347,7 +1347,7 @@
        tp->t_dim = n;
 
        if (n < 0) {
-               /* negative array dimension */
+               /* negative array dimension (%d) */
                error(20, n);
                n = 0;
        } else if (n == 0 && dim) {
@@ -1433,7 +1433,7 @@
        for (arg = args; arg != NULL; arg = arg->s_next) {
                if (arg->s_type->t_tspec == VOID) {
                        if (n > 1 || arg->s_next != NULL) {
-                               /* "void" must be sole parameter */
+                               /* void must be sole parameter */
                                error(60);
                                arg->s_type = gettyp(INT);
                        }
@@ -1707,7 +1707,7 @@
                                            tag->s_name);
                                tag = pushdown(tag);
                        } else if (tag->s_scl != scl) {
-                               /* base type is really "%s %s" */
+                               /* base type is really '%s %s' */
                                warning(45, storage_class_name(tag->s_scl),
                                    tag->s_name);
                        }
@@ -1720,7 +1720,7 @@
                        tag = pushdown(tag);
                        dcs->d_next->d_nedecl = 1;
                } else if (tag->s_scl != scl) {
-                       /* base type is really "%s %s" */
+                       /* base type is really '%s %s' */
                        warning(45, storage_class_name(tag->s_scl),
                            tag->s_name);
                        /* declaration introduces new type in ANSI C: %s %s */
@@ -2274,7 +2274,7 @@
                 * not set we print only a warning.
                 */
                if (!eqtype(arg->s_type, parg->s_type, 1, 1, &dowarn) || dowarn) {
-                       /* prototype does not match old-style def., arg #%d */
+                       /* prototype does not match old style defn., arg #%d */
                        error(299, n);
                        msg = 1;
                }
@@ -2477,7 +2477,7 @@
         */
        for (arg = args; arg != NULL; arg = arg->s_next) {
                if (arg->s_defarg) {
-                       /* argument type defaults to int: %s */
+                       /* argument type defaults to 'int': %s */
                        warning(32, arg->s_name);
                        arg->s_defarg = 0;
                        mark_as_set(arg);
@@ -3053,7 +3053,7 @@
 
        if (lab->s_set && !lab->s_used) {
                curr_pos = lab->s_set_pos;
-               /* label %s unused in function %s */
+               /* %s unused in function %s */
                warning(192, lab->s_name, funcsym->s_name);
        } else if (!lab->s_set) {
                curr_pos = lab->s_use_pos;
@@ -3143,7 +3143,7 @@
                if (sym->s_type->t_tspec == FUNC) {
                        if (sym->s_used && sym->s_def != DEF) {
                                curr_pos = sym->s_use_pos;
-                               /* static func. called but not def.. */
+                               /* static func. called but not def... */
                                error(225, sym->s_name);
                        }
                }
@@ -3155,7 +3155,7 @@
                                                /* static function %s unused */
                                                warning(236, sym->s_name);
                                } else {
-                                       /* static function %s decl. but ... */
+                                       /* static function %s declared but... */
                                        warning(290, sym->s_name);
                                }
                        } else if (!sym->s_set) {
diff -r 417da06567d9 -r 3e49c0a2e1ea usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Thu Dec 31 22:48:33 2020 +0000
+++ b/usr.bin/xlint/lint1/func.c        Fri Jan 01 00:00:24 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.39 2020/12/31 18:51:28 rillig Exp $ */
+/*     $NetBSD: func.c,v 1.40 2021/01/01 00:00:24 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.39 2020/12/31 18:51:28 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.40 2021/01/01 00:00:24 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -483,10 +483,10 @@
                                        break;
                        }
                        if (cl != NULL && tspec_is_uint(nv.v_tspec)) {
-                               /* duplicate case in switch, %lu */
+                               /* duplicate case in switch: %lu */
                                error(200, (u_long)nv.v_quad);
                        } else if (cl != NULL) {
-                               /* duplicate case in switch, %ld */
+                               /* duplicate case in switch: %ld */
                                error(199, (long)nv.v_quad);
                        } else {
                                /*
@@ -1046,7 +1046,7 @@
        if (nargusg != -1) {
                if (!silent) {
                        curr_pos = argsused_pos;
-                       /* must precede function definition: %s */
+                       /* must precede function definition: ** %s ** */
                        warning(282, "ARGSUSED");
                }
                nargusg = -1;
@@ -1054,7 +1054,7 @@
        if (nvararg != -1) {
                if (!silent) {
                        curr_pos = vapos;
-                       /* must precede function definition: %s */
+                       /* must precede function definition: ** %s ** */



Home | Main Index | Thread Index | Old Index