make: inline SuffixFlags into the Suffix itself

No functional change.
This commit is contained in:
rillig 2021-11-28 22:27:35 +00:00
parent bab23111f8
commit 2c14336b4d
1 changed files with 51 additions and 56 deletions

View File

@ -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,34 +142,6 @@ static GNodeList transforms = LST_INIT;
*/
static int sNum = 0;
typedef enum SuffixFlags {
SUFF_NONE = 0,
/*
* This suffix marks include files. Their search path ends up in the
* undocumented special variable '.INCLUDES'.
*/
SUFF_INCLUDE = 1 << 0,
/*
* This suffix marks library files. Their search path ends up in the
* undocumented special variable '.LIBS'.
*/
SUFF_LIBRARY = 1 << 1,
/*
* The empty suffix.
*
* XXX: What is the difference between the empty suffix and the null
* suffix?
*
* XXX: Why is SUFF_NULL needed at all? Wouldn't nameLen == 0 mean
* the same?
*/
SUFF_NULL = 1 << 2
} SuffixFlags;
typedef List SuffixListList;
/*
@ -181,24 +153,45 @@ typedef struct Suffix {
char *name;
/* Length of the name, to avoid strlen calls */
size_t nameLen;
/* Type of suffix */
SuffixFlags flags;
/*
* This suffix marks include files. Their search path ends up in the
* undocumented special variable '.INCLUDES'.
*/
bool include:1;
/*
* This suffix marks library files. Their search path ends up in the
* undocumented special variable '.LIBS'.
*/
bool library:1;
/*
* The empty suffix.
*
* XXX: What is the difference between the empty suffix and the null
* suffix?
*
* XXX: Why is SUFF_NULL needed at all? Wouldn't nameLen == 0 mean
* the same?
*/
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(CandidateList *list, Candidate *cand)
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, CandidateSearcher *cs)
* 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, const char *name)
}
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");