Module Name:    src
Committed By:   rillig
Date:           Sun Nov 28 22:27:35 UTC 2021

Modified Files:
        src/usr.bin/make: suff.c

Log Message:
make: inline SuffixFlags into the Suffix itself

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.352 -r1.353 src/usr.bin/make/suff.c

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/suff.c
diff -u src/usr.bin/make/suff.c:1.352 src/usr.bin/make/suff.c:1.353
--- src/usr.bin/make/suff.c:1.352	Sun Nov 28 18:58:58 2021
+++ src/usr.bin/make/suff.c	Sun Nov 28 22:27:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.352 2021/11/28 18:58:58 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.353 2021/11/28 22:27:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
 #include "dir.h"
 
 /*	"@(#)suff.c	8.4 (Berkeley) 3/21/94"	*/
-MAKE_RCSID("$NetBSD: suff.c,v 1.352 2021/11/28 18:58:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.353 2021/11/28 22:27:35 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -142,21 +142,27 @@ static GNodeList transforms = LST_INIT;
  */
 static int sNum = 0;
 
-typedef enum SuffixFlags {
-	SUFF_NONE	= 0,
+typedef List SuffixListList;
 
+/*
+ * A suffix such as ".c" or ".o" that is used in suffix transformation rules
+ * such as ".c.o:".
+ */
+typedef struct Suffix {
+	/* The suffix itself, such as ".c" */
+	char *name;
+	/* Length of the name, to avoid strlen calls */
+	size_t nameLen;
 	/*
 	 * This suffix marks include files.  Their search path ends up in the
 	 * undocumented special variable '.INCLUDES'.
 	 */
-	SUFF_INCLUDE	= 1 << 0,
-
+	bool include:1;
 	/*
 	 * This suffix marks library files.  Their search path ends up in the
 	 * undocumented special variable '.LIBS'.
 	 */
-	SUFF_LIBRARY	= 1 << 1,
-
+	bool library:1;
 	/*
 	 * The empty suffix.
 	 *
@@ -166,39 +172,26 @@ typedef enum SuffixFlags {
 	 * XXX: Why is SUFF_NULL needed at all? Wouldn't nameLen == 0 mean
 	 * the same?
 	 */
-	SUFF_NULL	= 1 << 2
-
-} SuffixFlags;
-
-typedef List SuffixListList;
-
-/*
- * A suffix such as ".c" or ".o" that is used in suffix transformation rules
- * such as ".c.o:".
- */
-typedef struct Suffix {
-	/* The suffix itself, such as ".c" */
-	char *name;
-	/* Length of the name, to avoid strlen calls */
-	size_t nameLen;
-	/* Type of suffix */
-	SuffixFlags flags;
+	bool isNull:1;
 	/* The path along which files of this suffix may be found */
 	SearchPath *searchPath;
+
 	/* The suffix number; TODO: document the purpose of this number */
 	int sNum;
 	/* Reference count of list membership and several other places */
 	int refCount;
+
 	/* Suffixes we have a transformation to */
 	SuffixList parents;
 	/* Suffixes we have a transformation from */
 	SuffixList children;
-
-	/* Lists in which this suffix is referenced.
+	/*
+	 * Lists in which this suffix is referenced.
 	 *
 	 * XXX: These lists are used nowhere, they are just appended to, for
 	 * no apparent reason.  They do have the side effect of increasing
-	 * refCount though. */
+	 * refCount though.
+	 */
 	SuffixListList ref;
 } Suffix;
 
@@ -472,7 +465,9 @@ Suffix_New(const char *name)
 	Lst_Init(&suff->parents);
 	Lst_Init(&suff->ref);
 	suff->sNum = sNum++;
-	suff->flags = SUFF_NONE;
+	suff->include = false;
+	suff->library = false;
+	suff->isNull = false;
 	suff->refCount = 1; /* XXX: why 1? It's not assigned anywhere yet. */
 
 	return suff;
@@ -499,7 +494,9 @@ Suff_ClearSuffixes(void)
 	emptySuff = nullSuff = Suffix_New("");
 
 	SearchPath_AddAll(nullSuff->searchPath, &dirSearchPath);
-	nullSuff->flags = SUFF_NULL;
+	nullSuff->include = false;
+	nullSuff->library = false;
+	nullSuff->isNull = true;
 }
 
 /*
@@ -886,12 +883,12 @@ Suff_ExtendPaths(void)
 		Suffix *suff = ln->datum;
 		if (!Lst_IsEmpty(&suff->searchPath->dirs)) {
 #ifdef INCLUDES
-			if (suff->flags & SUFF_INCLUDE)
+			if (suff->include)
 				SearchPath_AddAll(includesPath,
 				    suff->searchPath);
 #endif
 #ifdef LIBRARIES
-			if (suff->flags & SUFF_LIBRARY)
+			if (suff->library)
 				SearchPath_AddAll(libsPath, suff->searchPath);
 #endif
 			SearchPath_AddAll(suff->searchPath, &dirSearchPath);
@@ -924,7 +921,7 @@ Suff_AddInclude(const char *suffName)
 {
 	Suffix *suff = FindSuffixByName(suffName);
 	if (suff != NULL)
-		suff->flags |= SUFF_INCLUDE;
+		suff->include = true;
 }
 
 /*
@@ -938,7 +935,7 @@ Suff_AddLib(const char *suffName)
 {
 	Suffix *suff = FindSuffixByName(suffName);
 	if (suff != NULL)
-		suff->flags |= SUFF_LIBRARY;
+		suff->library = true;
 }
 
 /********** Implicit Source Search Functions *********/
@@ -1041,7 +1038,7 @@ CandidateList_AddCandidatesFor(Candidate
 	for (ln = cand->suff->children.first; ln != NULL; ln = ln->next) {
 		Suffix *suff = ln->datum;
 
-		if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') {
+		if (suff->isNull && suff->name[0] != '\0') {
 			/*
 			 * If the suffix has been marked as the NULL suffix,
 			 * also create a candidate for a file with no suffix
@@ -1916,7 +1913,7 @@ FindDepsRegular(GNode *gn, CandidateSear
 	 * If the suffix indicates that the target is a library, mark that in
 	 * the node's type field.
 	 */
-	if (targ->suff->flags & SUFF_LIBRARY)
+	if (targ->suff->library)
 		gn->type |= OP_LIB;
 
 	/*
@@ -2081,8 +2078,8 @@ Suff_SetNull(const char *name)
 	}
 
 	if (nullSuff != NULL)
-		nullSuff->flags &= ~(unsigned)SUFF_NULL;
-	suff->flags |= SUFF_NULL;
+		nullSuff->isNull = false;
+	suff->isNull = true;
 	/* XXX: Here's where the transformation mangling would take place. */
 	nullSuff = suff;
 }
@@ -2115,13 +2112,13 @@ Suff_End(void)
 
 
 static void
-PrintSuffNames(const char *prefix, SuffixList *suffs)
+PrintSuffNames(const char *prefix, const SuffixList *suffs)
 {
 	SuffixListNode *ln;
 
 	debug_printf("#\t%s: ", prefix);
 	for (ln = suffs->first; ln != NULL; ln = ln->next) {
-		Suffix *suff = ln->datum;
+		const Suffix *suff = ln->datum;
 		debug_printf("%s ", suff->name);
 	}
 	debug_printf("\n");
@@ -2138,28 +2135,26 @@ Buf_AddFlag(Buffer *buf, bool flag, cons
 }
 
 static const char *
-SuffixFlags_ToString(SuffixFlags flags, void **freeIt)
+SuffixFlags_ToString(const Suffix *suff, void **freeIt)
 {
 	Buffer buf;
 
 	Buf_InitSize(&buf, 32);
-#define ADD(flag) Buf_AddFlag(&buf, (flags & (flag)) != 0, #flag)
-	ADD(SUFF_INCLUDE);
-	ADD(SUFF_LIBRARY);
-	ADD(SUFF_NULL);
-#undef ADD
+	Buf_AddFlag(&buf, suff->include, "SUFF_INCLUDE");
+	Buf_AddFlag(&buf, suff->library, "SUFF_LIBRARY");
+	Buf_AddFlag(&buf, suff->isNull, "SUFF_NULL");
 	return buf.len == 0 ? "none" : (*freeIt = Buf_DoneData(&buf));
 }
 
 static void
-Suffix_Print(Suffix *suff)
+Suffix_Print(const Suffix *suff)
 {
 	debug_printf("# \"%s\" (num %d, ref %d)",
 	    suff->name, suff->sNum, suff->refCount);
-	if (suff->flags != 0) {
+	if (suff->include || suff->library || suff->isNull) {
 		void *flags_freeIt = NULL;
 		debug_printf(" (%s)",
-		    SuffixFlags_ToString(suff->flags, &flags_freeIt));
+		    SuffixFlags_ToString(suff, &flags_freeIt));
 		free(flags_freeIt);
 	}
 	debug_printf("\n");

Reply via email to