Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make: convert debugging flags from enum to bit-...



details:   https://anonhg.NetBSD.org/src/rev/49a34d04f1f4
branches:  trunk
changeset: 1027626:49a34d04f1f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 13 22:26:21 2021 +0000

description:
make: convert debugging flags from enum to bit-field

This gets rid of the magic numbers, making it possible to add another
debug flag without renumbering the others.

No functional change.

diffstat:

 usr.bin/make/main.c |  50 +++++++++++++++++++++++++-------------------------
 usr.bin/make/make.h |  48 +++++++++++++++++++++++-------------------------
 2 files changed, 48 insertions(+), 50 deletions(-)

diffs (195 lines):

diff -r 7a335de55b96 -r 49a34d04f1f4 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Mon Dec 13 21:15:26 2021 +0000
+++ b/usr.bin/make/main.c       Mon Dec 13 22:26:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.542 2021/12/13 05:25:04 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.543 2021/12/13 22:26:21 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.542 2021/12/13 05:25:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.543 2021/12/13 22:26:21 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -247,79 +247,79 @@
        for (modules = argvalue; *modules != '\0'; modules++) {
                switch (*modules) {
                case '0':       /* undocumented, only intended for tests */
-                       debug = DEBUG_NONE;
+                       memset(&debug, 0, sizeof(debug));
                        break;
                case 'A':
-                       debug = DEBUG_ALL;
+                       memset(&debug, ~0, sizeof(debug));
                        break;
                case 'a':
-                       debug |= DEBUG_ARCH;
+                       debug.DEBUG_ARCH = true;
                        break;
                case 'C':
-                       debug |= DEBUG_CWD;
+                       debug.DEBUG_CWD = true;
                        break;
                case 'c':
-                       debug |= DEBUG_COND;
+                       debug.DEBUG_COND = true;
                        break;
                case 'd':
-                       debug |= DEBUG_DIR;
+                       debug.DEBUG_DIR = true;
                        break;
                case 'e':
-                       debug |= DEBUG_ERROR;
+                       debug.DEBUG_ERROR = true;
                        break;
                case 'f':
-                       debug |= DEBUG_FOR;
+                       debug.DEBUG_FOR = true;
                        break;
                case 'g':
                        if (modules[1] == '1') {
-                               debug |= DEBUG_GRAPH1;
+                               debug.DEBUG_GRAPH1 = true;
                                modules++;
                        } else if (modules[1] == '2') {
-                               debug |= DEBUG_GRAPH2;
+                               debug.DEBUG_GRAPH2 = true;
                                modules++;
                        } else if (modules[1] == '3') {
-                               debug |= DEBUG_GRAPH3;
+                               debug.DEBUG_GRAPH3 = true;
                                modules++;
                        }
                        break;
                case 'h':
-                       debug |= DEBUG_HASH;
+                       debug.DEBUG_HASH = true;
                        break;
                case 'j':
-                       debug |= DEBUG_JOB;
+                       debug.DEBUG_JOB = true;
                        break;
                case 'L':
                        opts.strict = true;
                        break;
                case 'l':
-                       debug |= DEBUG_LOUD;
+                       debug.DEBUG_LOUD = true;
                        break;
                case 'M':
-                       debug |= DEBUG_META;
+                       debug.DEBUG_META = true;
                        break;
                case 'm':
-                       debug |= DEBUG_MAKE;
+                       debug.DEBUG_MAKE = true;
                        break;
                case 'n':
-                       debug |= DEBUG_SCRIPT;
+                       debug.DEBUG_SCRIPT = true;
                        break;
                case 'p':
-                       debug |= DEBUG_PARSE;
+                       debug.DEBUG_PARSE = true;
                        break;
                case 's':
-                       debug |= DEBUG_SUFF;
+                       debug.DEBUG_SUFF = true;
                        break;
                case 't':
-                       debug |= DEBUG_TARG;
+                       debug.DEBUG_TARG = true;
                        break;
                case 'V':
                        opts.debugVflag = true;
                        break;
                case 'v':
-                       debug |= DEBUG_VAR;
+                       debug.DEBUG_VAR = true;
                        break;
                case 'x':
-                       debug |= DEBUG_SHELL;
+                       debug.DEBUG_SHELL = true;
                        break;
                case 'F':
                        MainParseArgDebugFile(modules + 1);
@@ -1114,7 +1114,7 @@
 CmdOpts_Init(void)
 {
        opts.compatMake = false;
-       opts.debug = DEBUG_NONE;
+       memset(&opts.debug, 0, sizeof(opts.debug));
        /* opts.debug_file has already been initialized earlier */
        opts.strict = false;
        opts.debugVflag = false;
diff -r 7a335de55b96 -r 49a34d04f1f4 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Mon Dec 13 21:15:26 2021 +0000
+++ b/usr.bin/make/make.h       Mon Dec 13 22:26:21 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.271 2021/12/13 05:25:04 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.272 2021/12/13 22:26:21 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -543,34 +543,32 @@
 # define MAKE_LEVEL_ENV        "MAKELEVEL"
 #endif
 
-typedef enum DebugFlags {
-       DEBUG_NONE      = 0,
-       DEBUG_ARCH      = 1 << 0,
-       DEBUG_COND      = 1 << 1,
-       DEBUG_CWD       = 1 << 2,
-       DEBUG_DIR       = 1 << 3,
-       DEBUG_ERROR     = 1 << 4,
-       DEBUG_FOR       = 1 << 5,
-       DEBUG_GRAPH1    = 1 << 6,
-       DEBUG_GRAPH2    = 1 << 7,
-       DEBUG_GRAPH3    = 1 << 8,
-       DEBUG_HASH      = 1 << 9,
-       DEBUG_JOB       = 1 << 10,
-       DEBUG_LOUD      = 1 << 11,
-       DEBUG_MAKE      = 1 << 12,
-       DEBUG_META      = 1 << 13,
-       DEBUG_PARSE     = 1 << 14,
-       DEBUG_SCRIPT    = 1 << 15,
-       DEBUG_SHELL     = 1 << 16,
-       DEBUG_SUFF      = 1 << 17,
-       DEBUG_TARG      = 1 << 18,
-       DEBUG_VAR       = 1 << 19,
-       DEBUG_ALL       = (1 << 20) - 1
+typedef struct DebugFlags {
+       bool DEBUG_ARCH: 1;
+       bool DEBUG_COND: 1;
+       bool DEBUG_CWD: 1;
+       bool DEBUG_DIR: 1;
+       bool DEBUG_ERROR: 1;
+       bool DEBUG_FOR: 1;
+       bool DEBUG_GRAPH1: 1;
+       bool DEBUG_GRAPH2: 1;
+       bool DEBUG_GRAPH3: 1;
+       bool DEBUG_HASH: 1;
+       bool DEBUG_JOB: 1;
+       bool DEBUG_LOUD: 1;
+       bool DEBUG_MAKE: 1;
+       bool DEBUG_META: 1;
+       bool DEBUG_PARSE: 1;
+       bool DEBUG_SCRIPT: 1;
+       bool DEBUG_SHELL: 1;
+       bool DEBUG_SUFF: 1;
+       bool DEBUG_TARG: 1;
+       bool DEBUG_VAR: 1;
 } DebugFlags;
 
 #define CONCAT(a, b) a##b
 
-#define DEBUG(module) ((opts.debug & CONCAT(DEBUG_, module)) != 0)
+#define DEBUG(module) (opts.debug.CONCAT(DEBUG_, module))
 
 void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 



Home | Main Index | Thread Index | Old Index