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: reduce code size for handling lint...



details:   https://anonhg.NetBSD.org/src/rev/ecd95c048d9e
branches:  trunk
changeset: 377462:ecd95c048d9e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 13 07:19:24 2023 +0000

description:
lint: reduce code size for handling lint comments

diffstat:

 usr.bin/xlint/lint1/cgram.y    |   6 +-
 usr.bin/xlint/lint1/externs1.h |  15 +------
 usr.bin/xlint/lint1/func.c     |  89 +++++++++++++----------------------------
 usr.bin/xlint/lint1/lex.c      |  58 ++++++++++++---------------
 usr.bin/xlint/lint1/lint1.h    |  17 +++++++-
 5 files changed, 75 insertions(+), 110 deletions(-)

diffs (truncated from 349 to 300 lines):

diff -r d1eb842408e1 -r ecd95c048d9e usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Thu Jul 13 06:41:27 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Thu Jul 13 07:19:24 2023 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.458 2023/07/13 06:41:27 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.459 2023/07/13 07:19:24 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.458 2023/07/13 06:41:27 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.459 2023/07/13 07:19:24 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -2205,7 +2205,7 @@ gcc_attribute:
                    is_either(name, "unused", "__unused__"))
                        dcs_set_used();
                else if (is_either(name, "fallthrough", "__fallthrough__"))
-                       fallthru(1);
+                       suppress_fallthrough = true;
        }
 |      T_NAME T_LPAREN T_RPAREN
 |      T_NAME T_LPAREN gcc_attribute_parameters T_RPAREN
diff -r d1eb842408e1 -r ecd95c048d9e usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Thu Jul 13 06:41:27 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Thu Jul 13 07:19:24 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.192 2023/07/13 06:41:27 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.193 2023/07/13 07:19:24 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -333,18 +333,7 @@ void       stmt_continue(void);
 void   stmt_break(void);
 void   stmt_return(bool, tnode_t *);
 void   global_clean_up_decl(bool);
-void   argsused(int);
-void   constcond(int);
-void   fallthru(int);
-void   not_reached(int);
-void   lintlib(int);
-void   linted(int);
-void   varargs(int);
-void   printflike(int);
-void   scanflike(int);
-void   protolib(int);
-void   longlong(int);
-void   bitfieldtype(int);
+void   handle_lint_comment(lint_comment, int);
 
 /*
  * init.c
diff -r d1eb842408e1 -r ecd95c048d9e usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Thu Jul 13 06:41:27 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Thu Jul 13 07:19:24 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.168 2023/07/13 06:41:27 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.169 2023/07/13 07:19:24 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.168 2023/07/13 06:41:27 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.169 2023/07/13 07:19:24 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -1123,12 +1123,10 @@ global_clean_up_decl(bool silent)
 }
 
 /*
- * ARGSUSED comment
- *
- * Only the first n arguments of the following function are checked
- * for usage. A missing argument is taken to be 0.
+ * Only the first n arguments of the following function are checked for usage.
+ * A missing argument is taken to be 0.
  */
-void
+static void
 argsused(int n)
 {
 
@@ -1148,7 +1146,7 @@ argsused(int n)
        argsused_pos = curr_pos;
 }
 
-void
+static void
 varargs(int n)
 {
 
@@ -1172,7 +1170,7 @@ varargs(int n)
  * Check all arguments until the (n-1)-th as usual. The n-th argument is
  * used the check the types of remaining arguments.
  */
-void
+static void
 printflike(int n)
 {
 
@@ -1196,7 +1194,7 @@ printflike(int n)
  * Check all arguments until the (n-1)-th as usual. The n-th argument is
  * used the check the types of remaining arguments.
  */
-void
+static void
 scanflike(int n)
 {
 
@@ -1216,34 +1214,8 @@ scanflike(int n)
        scanflike_pos = curr_pos;
 }
 
-/* ARGSUSED */
-void
-constcond(int n)
-{
-
-       suppress_constcond = true;
-}
-
-/* ARGSUSED */
-void
-fallthru(int n)
-{
-
-       suppress_fallthrough = true;
-}
-
-/* ARGSUSED */
-void
-not_reached(int n)
-{
-
-       set_reached(false);
-       warn_about_unreachable = false;
-}
-
-/* ARGSUSED */
-void
-lintlib(int n)
+static void
+lintlib(void)
 {
 
        if (dcs->d_kind != DLK_EXTERN) {
@@ -1255,30 +1227,12 @@ lintlib(int n)
        vflag = true;
 }
 
-void
-linted(int n)
-{
-
-       debug_step("set lwarn %d", n);
-       lwarn = n;
-}
-
-/* ARGSUSED */
-void
-bitfieldtype(int n)
-{
-
-       debug_step("%s:%d: suppress_bitfieldtype = true",
-           curr_pos.p_file, curr_pos.p_line);
-       suppress_bitfieldtype = true;
-}
-
 /*
  * PROTOLIB in conjunction with LINTLIBRARY can be used to handle
  * prototypes like function definitions. This is done if the argument
  * to PROTOLIB is nonzero. Otherwise, prototypes are handled normally.
  */
-void
+static void
 protolib(int n)
 {
 
@@ -1290,10 +1244,23 @@ protolib(int n)
        plibflg = n != 0;
 }
 
-/* ARGSUSED */
 void
-longlong(int n)
+handle_lint_comment(lint_comment comment, int arg)
 {
-
-       suppress_longlong = true;
+       switch (comment) {
+       case LC_ARGSUSED:       argsused(arg);                  break;
+       case LC_BITFIELDTYPE:   suppress_bitfieldtype = true;   break;
+       case LC_CONSTCOND:      suppress_constcond = true;      break;
+       case LC_FALLTHROUGH:    suppress_fallthrough = true;    break;
+       case LC_LINTLIBRARY:    lintlib();                      break;
+       case LC_LINTED:         debug_step("set lwarn %d", arg);
+                               lwarn = arg;                    break;
+       case LC_LONGLONG:       suppress_longlong = true;       break;
+       case LC_NOTREACHED:     set_reached(false);
+                               warn_about_unreachable = false; break;
+       case LC_PRINTFLIKE:     printflike(arg);                break;
+       case LC_PROTOLIB:       protolib(arg);                  break;
+       case LC_SCANFLIKE:      scanflike(arg);                 break;
+       case LC_VARARGS:        varargs(arg);                   break;
+       }
 }
diff -r d1eb842408e1 -r ecd95c048d9e usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Thu Jul 13 06:41:27 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Thu Jul 13 07:19:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.179 2023/07/13 06:41:27 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.180 2023/07/13 07:19:24 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.179 2023/07/13 06:41:27 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.180 2023/07/13 07:19:24 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -1050,39 +1050,34 @@ lex_directive(const char *yytext)
        }
 }
 
-/*
- * Handle lint comments such as ARGSUSED.
- *
- * If one of these comments is recognized, the argument, if any, is
- * parsed and a function which handles this comment is called.
- */
+/* Handle lint comments such as ARGSUSED. */
 void
 lex_comment(void)
 {
        int c;
        static const struct {
-               const   char *keywd;
+               const   char name[18];
                bool    arg;
-               void    (*func)(int);
+               lint_comment comment;
        } keywtab[] = {
-               { "ARGSUSED",           true,   argsused        },
-               { "BITFIELDTYPE",       false,  bitfieldtype    },
-               { "CONSTCOND",          false,  constcond       },
-               { "CONSTANTCOND",       false,  constcond       },
-               { "CONSTANTCONDITION",  false,  constcond       },
-               { "FALLTHRU",           false,  fallthru        },
-               { "FALLTHROUGH",        false,  fallthru        },
-               { "FALL THROUGH",       false,  fallthru        },
-               { "fallthrough",        false,  fallthru        },
-               { "LINTLIBRARY",        false,  lintlib         },
-               { "LINTED",             true,   linted          },
-               { "LONGLONG",           false,  longlong        },
-               { "NOSTRICT",           true,   linted          },
-               { "NOTREACHED",         false,  not_reached     },
-               { "PRINTFLIKE",         true,   printflike      },
-               { "PROTOLIB",           true,   protolib        },
-               { "SCANFLIKE",          true,   scanflike       },
-               { "VARARGS",            true,   varargs         },
+               { "ARGSUSED",           true,   LC_ARGSUSED     },
+               { "BITFIELDTYPE",       false,  LC_BITFIELDTYPE },
+               { "CONSTCOND",          false,  LC_CONSTCOND    },
+               { "CONSTANTCOND",       false,  LC_CONSTCOND    },
+               { "CONSTANTCONDITION",  false,  LC_CONSTCOND    },
+               { "FALLTHRU",           false,  LC_FALLTHROUGH  },
+               { "FALLTHROUGH",        false,  LC_FALLTHROUGH  },
+               { "FALL THROUGH",       false,  LC_FALLTHROUGH  },
+               { "fallthrough",        false,  LC_FALLTHROUGH  },
+               { "LINTLIBRARY",        false,  LC_LINTLIBRARY  },
+               { "LINTED",             true,   LC_LINTED       },
+               { "LONGLONG",           false,  LC_LONGLONG     },
+               { "NOSTRICT",           true,   LC_LINTED       },
+               { "NOTREACHED",         false,  LC_NOTREACHED   },
+               { "PRINTFLIKE",         true,   LC_PRINTFLIKE   },
+               { "PROTOLIB",           true,   LC_PROTOLIB     },
+               { "SCANFLIKE",          true,   LC_SCANFLIKE    },
+               { "VARARGS",            true,   LC_VARARGS      },
        };
        char keywd[32];
        char arg[32];
@@ -1110,7 +1105,7 @@ lex_comment(void)
 
        /* look for the keyword */
        for (i = 0; i < sizeof(keywtab) / sizeof(keywtab[0]); i++) {
-               if (strcmp(keywtab[i].keywd, keywd) == 0)
+               if (strcmp(keywtab[i].name, keywd) == 0)



Home | Main Index | Thread Index | Old Index