Module Name:    src
Committed By:   rillig
Date:           Mon Dec 13 22:26:21 UTC 2021

Modified Files:
        src/usr.bin/make: main.c make.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.542 -r1.543 src/usr.bin/make/main.c
cvs rdiff -u -r1.271 -r1.272 src/usr.bin/make/make.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.542 src/usr.bin/make/main.c:1.543
--- src/usr.bin/make/main.c:1.542	Mon Dec 13 05:25:04 2021
+++ src/usr.bin/make/main.c	Mon Dec 13 22:26:21 2021
@@ -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 @@ MainParseArgDebug(const char *argvalue)
 	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 @@ static void
 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;

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.271 src/usr.bin/make/make.h:1.272
--- src/usr.bin/make/make.h:1.271	Mon Dec 13 05:25:04 2021
+++ src/usr.bin/make/make.h	Mon Dec 13 22:26:21 2021
@@ -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 @@ extern pid_t myPid;
 # 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);
 

Reply via email to