Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/xlint lint: remove unnecessary abstraction lay...



details:   https://anonhg.NetBSD.org/src/rev/fbcd52b61170
branches:  trunk
changeset: 373145:fbcd52b61170
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 21 11:22:21 2023 +0000

description:
lint: remove unnecessary abstraction layer for passing arguments

The abstraction layer of the pass_to functions wasn't worth its weight.
After inlining the functions, the code is even clearer than before.

No functional change.

diffstat:

 usr.bin/xlint/xlint/xlint.c |  112 ++++++++++++++++---------------------------
 1 files changed, 42 insertions(+), 70 deletions(-)

diffs (223 lines):

diff -r fe2e72b22f6a -r fbcd52b61170 usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Sat Jan 21 10:41:51 2023 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Sat Jan 21 11:22:21 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.105 2023/01/20 23:06:26 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.106 2023/01/21 11:22:21 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: xlint.c,v 1.105 2023/01/20 23:06:26 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.106 2023/01/21 11:22:21 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -152,6 +152,13 @@
 }
 
 static void
+list_add_flag(list *l, int c)
+{
+
+       list_add(l, (const char[3]){ '-', (char)c, '\0' });
+}
+
+static void
 list_add_unique(list *l, const char *s)
 {
 
@@ -177,41 +184,6 @@
                free(l->items[--l->len]);
 }
 
-static void
-pass_to_cpp(const char *opt)
-{
-
-       list_add(&cpp.flags, opt);
-}
-
-static void
-pass_to_lint1(const char *opt)
-{
-
-       list_add(&lint1.flags, opt);
-}
-
-static void
-pass_flag_to_lint1(int flag)
-{
-
-       pass_to_lint1((const char[3]){ '-', (char)flag, '\0' });
-}
-
-static void
-pass_to_lint2(const char *opt)
-{
-
-       list_add(&lint2.flags, opt);
-}
-
-static void
-pass_flag_to_lint2(int flag)
-{
-
-       pass_to_lint2((const char[3]){ '-', (char)flag, '\0' });
-}
-
 static char *
 concat2(const char *s1, const char *s2)
 {
@@ -400,19 +372,19 @@
                terminate(-1);
        }
 
-       pass_to_cpp("-E");
-       pass_to_cpp("-x");
-       pass_to_cpp("c");
-       pass_to_cpp("-U__GNUC__");
-       pass_to_cpp("-U__PCC__");
-       pass_to_cpp("-U__SSE__");
-       pass_to_cpp("-U__SSE4_1__");
-       pass_to_cpp("-Wp,-CC");
-       pass_to_cpp("-Wcomment");
-       pass_to_cpp("-D__LINT__");
-       pass_to_cpp("-Dlint");          /* XXX don't define with -s */
-       pass_to_cpp("-D__lint");
-       pass_to_cpp("-D__lint__");
+       list_add(&cpp.flags, "-E");
+       list_add(&cpp.flags, "-x");
+       list_add(&cpp.flags, "c");
+       list_add(&cpp.flags, "-U__GNUC__");
+       list_add(&cpp.flags, "-U__PCC__");
+       list_add(&cpp.flags, "-U__SSE__");
+       list_add(&cpp.flags, "-U__SSE4_1__");
+       list_add(&cpp.flags, "-Wp,-CC");
+       list_add(&cpp.flags, "-Wcomment");
+       list_add(&cpp.flags, "-D__LINT__");
+       list_add(&cpp.flags, "-Dlint"); /* XXX don't define with -s */
+       list_add(&cpp.flags, "-D__lint");
+       list_add(&cpp.flags, "-D__lint__");
 
        list_add(&deflibs, "c");
 
@@ -437,15 +409,15 @@
                case 'w':
                case 'z':
                case 'P':
-                       pass_flag_to_lint1(c);
+                       list_add_flag(&lint1.flags, c);
                        break;
 
                case 'A':
                case 'q':
                case 'R':
                case 'X':
-                       pass_flag_to_lint1(c);
-                       pass_to_lint1(optarg);
+                       list_add_flag(&lint1.flags, c);
+                       list_add(&lint1.flags, optarg);
                        break;
 
                case 'F':
@@ -453,8 +425,8 @@
                        /* FALLTHROUGH */
                case 'u':
                case 'h':
-                       pass_flag_to_lint1(c);
-                       pass_flag_to_lint2(c);
+                       list_add_flag(&lint1.flags, c);
+                       list_add_flag(&lint2.flags, c);
                        break;
 
                case 'i':
@@ -473,7 +445,7 @@
                                list_clear(&deflibs);
                                list_add(&deflibs, "c");
                        }
-                       pass_flag_to_lint1(c);
+                       list_add_flag(&lint1.flags, c);
                        break;
 
                case 's':
@@ -486,20 +458,20 @@
                        list_add(&cpp.lcflags, "-pedantic");
                        list_add(&cpp.lcflags, "-D__STRICT_ANSI__");
                        sflag = true;
-                       pass_flag_to_lint1(c);
-                       pass_flag_to_lint2(c);
+                       list_add_flag(&lint1.flags, c);
+                       list_add_flag(&lint2.flags, c);
                        break;
 
                case 'S':
                        if (tflag)
                                usage("%c and %s flags cannot be specified "
                                    "together", 'S', "t");
-                       pass_flag_to_lint1(c);
+                       list_add_flag(&lint1.flags, c);
                        break;
 
                case 'T':
-                       pass_to_cpp("-I" PATH_STRICT_BOOL_INCLUDE);
-                       pass_flag_to_lint1(c);
+                       list_add(&cpp.flags, "-I" PATH_STRICT_BOOL_INCLUDE);
+                       list_add_flag(&lint1.flags, c);
                        break;
 
 #if !HAVE_NBTOOL_CONFIG_H
@@ -513,14 +485,14 @@
                        list_add(&cpp.lcflags, "-Wtraditional");
                        list_add(&cpp.lcflags, "-D" MACHINE);
                        list_add(&cpp.lcflags, "-D" MACHINE_ARCH);
-                       pass_flag_to_lint1(c);
-                       pass_flag_to_lint2(c);
+                       list_add_flag(&lint1.flags, c);
+                       list_add_flag(&lint2.flags, c);
                        break;
 #endif
 
                case 'x':
                case 'H':
-                       pass_flag_to_lint2(c);
+                       list_add_flag(&lint2.flags, c);
                        break;
 
                case 'C':
@@ -530,8 +502,8 @@
                                usage("%c and %s flags cannot be specified "
                                    "together", 'C', "o or i");
                        Cflag = true;
-                       pass_flag_to_lint2(c);
-                       pass_to_lint2(optarg);
+                       list_add_flag(&lint2.flags, c);
+                       list_add(&lint2.flags, optarg);
                        lint2.outlib = xasprintf("llib-l%s.ln", optarg);
                        list_clear(&deflibs);
                        break;
@@ -540,9 +512,9 @@
                        if (dflag)
                                usage("%c flag already specified", 'd');
                        dflag = true;
-                       pass_to_cpp("-nostdinc");
-                       pass_to_cpp("-isystem");
-                       pass_to_cpp(optarg);
+                       list_add(&cpp.flags, "-nostdinc");
+                       list_add(&cpp.flags, "-isystem");
+                       list_add(&cpp.flags, optarg);
                        break;
 
                case 'D':
@@ -581,7 +553,7 @@
                        break;
 
                case 'Z':
-                       pass_to_cpp(optarg);
+                       list_add(&cpp.flags, optarg);
                        break;
 
                default:



Home | Main Index | Thread Index | Old Index