Module Name: src
Committed By: rillig
Date: Sat Sep 26 16:00:12 UTC 2020
Modified Files:
src/usr.bin/make: arch.c compat.c cond.c job.c main.c make.c make.h
nonints.h parse.c suff.c targ.c var.c
Log Message:
make(1): clean up API for finding and creating GNodes
The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.
Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/make/arch.c
cvs rdiff -u -r1.150 -r1.151 src/usr.bin/make/compat.c
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/make/cond.c
cvs rdiff -u -r1.238 -r1.239 src/usr.bin/make/job.c
cvs rdiff -u -r1.345 -r1.346 src/usr.bin/make/main.c
cvs rdiff -u -r1.144 -r1.145 src/usr.bin/make/make.c
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/make/make.h
cvs rdiff -u -r1.129 -r1.130 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.331 -r1.332 src/usr.bin/make/parse.c
cvs rdiff -u -r1.167 -r1.168 src/usr.bin/make/suff.c
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/make/targ.c
cvs rdiff -u -r1.542 -r1.543 src/usr.bin/make/var.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/arch.c
diff -u src/usr.bin/make/arch.c:1.122 src/usr.bin/make/arch.c:1.123
--- src/usr.bin/make/arch.c:1.122 Sat Sep 26 14:48:31 2020
+++ src/usr.bin/make/arch.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.122 2020/09/26 14:48:31 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.123 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -133,7 +133,7 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.122 2020/09/26 14:48:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.123 2020/09/26 16:00:12 rillig Exp $");
#ifdef TARGET_MACHINE
#undef MAKE_MACHINE
@@ -345,15 +345,10 @@ Arch_ParseArchive(char **linePtr, GNodeL
* Just create an ARCHV node for the thing and let
* SuffExpandChildren handle it...
*/
- gn = Targ_FindNode(buf, TARG_CREATE);
+ gn = Targ_GetNode(buf);
+ gn->type |= OP_ARCHV;
+ Lst_Append(nodeLst, gn);
- if (gn == NULL) {
- free(buf);
- return FALSE;
- } else {
- gn->type |= OP_ARCHV;
- Lst_Append(nodeLst, gn);
- }
} else if (!Arch_ParseArchive(&sacrifice, nodeLst, ctxt)) {
/*
* Error in nested call -- free buffer and return FALSE
@@ -375,12 +370,9 @@ Arch_ParseArchive(char **linePtr, GNodeL
char *fullname = str_concat4(libName, "(", member, ")");
free(member);
- gn = Targ_FindNode(fullname, TARG_CREATE);
+ gn = Targ_GetNode(fullname);
free(fullname);
- if (gn == NULL)
- return FALSE;
-
/*
* We've found the node, but have to make sure the rest of
* the world knows it's an archive member, without having
@@ -394,12 +386,9 @@ Arch_ParseArchive(char **linePtr, GNodeL
Lst_Free(members);
} else {
char *fullname = str_concat4(libName, "(", memName, ")");
- gn = Targ_FindNode(fullname, TARG_CREATE);
+ gn = Targ_GetNode(fullname);
free(fullname);
- if (gn == NULL)
- return FALSE;
-
/*
* We've found the node, but have to make sure the rest of the
* world knows it's an archive member, without having to
Index: src/usr.bin/make/compat.c
diff -u src/usr.bin/make/compat.c:1.150 src/usr.bin/make/compat.c:1.151
--- src/usr.bin/make/compat.c:1.150 Thu Sep 24 07:11:29 2020
+++ src/usr.bin/make/compat.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.150 2020/09/24 07:11:29 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.151 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,7 +99,7 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.150 2020/09/24 07:11:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.151 2020/09/26 16:00:12 rillig Exp $");
static GNode *curTarg = NULL;
static void CompatInterrupt(int);
@@ -145,7 +145,7 @@ CompatInterrupt(int signo)
* Run .INTERRUPT only if hit with interrupt signal
*/
if (signo == SIGINT) {
- gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
+ gn = Targ_FindNode(".INTERRUPT");
if (gn != NULL) {
Compat_Make(gn, gn);
}
@@ -692,7 +692,7 @@ Compat_Run(GNodeList *targs)
* to it.
*/
if (!queryFlag) {
- gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
+ gn = Targ_FindNode(".BEGIN");
if (gn != NULL) {
Compat_Make(gn, gn);
if (gn->made == ERROR) {
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.151 src/usr.bin/make/cond.c:1.152
--- src/usr.bin/make/cond.c:1.151 Fri Sep 25 20:48:23 2020
+++ src/usr.bin/make/cond.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.151 2020/09/25 20:48:23 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.152 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.151 2020/09/25 20:48:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.152 2020/09/26 16:00:12 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -329,9 +329,7 @@ FuncExists(int argLen MAKE_ATTR_UNUSED,
static Boolean
FuncTarget(int argLen MAKE_ATTR_UNUSED, const char *arg)
{
- GNode *gn;
-
- gn = Targ_FindNode(arg, TARG_NOCREATE);
+ GNode *gn = Targ_FindNode(arg);
return gn != NULL && !OP_NOP(gn->type);
}
@@ -340,9 +338,7 @@ FuncTarget(int argLen MAKE_ATTR_UNUSED,
static Boolean
FuncCommands(int argLen MAKE_ATTR_UNUSED, const char *arg)
{
- GNode *gn;
-
- gn = Targ_FindNode(arg, TARG_NOCREATE);
+ GNode *gn = Targ_FindNode(arg);
return gn != NULL && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands);
}
Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.238 src/usr.bin/make/job.c:1.239
--- src/usr.bin/make/job.c:1.238 Fri Sep 25 06:20:44 2020
+++ src/usr.bin/make/job.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.238 2020/09/25 06:20:44 rillig Exp $ */
+/* $NetBSD: job.c,v 1.239 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -140,7 +140,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.238 2020/09/25 06:20:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.239 2020/09/26 16:00:12 rillig Exp $");
# define STATIC static
@@ -2572,7 +2572,7 @@ JobInterrupt(int runINTERRUPT, int signo
JobSigUnlock(&mask);
if (runINTERRUPT && !touchFlag) {
- interrupt = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
+ interrupt = Targ_FindNode(".INTERRUPT");
if (interrupt != NULL) {
ignoreErrors = FALSE;
JobRun(interrupt);
@@ -2968,8 +2968,7 @@ Job_TokenWithdraw(void)
*/
Boolean
Job_RunTarget(const char *target, const char *fname) {
- GNode *gn = Targ_FindNode(target, TARG_NOCREATE);
-
+ GNode *gn = Targ_FindNode(target);
if (gn == NULL)
return FALSE;
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.345 src/usr.bin/make/main.c:1.346
--- src/usr.bin/make/main.c:1.345 Fri Sep 25 23:18:59 2020
+++ src/usr.bin/make/main.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.345 2020/09/25 23:18:59 rillig Exp $ */
+/* $NetBSD: main.c,v 1.346 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
#endif
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.345 2020/09/25 23:18:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.346 2020/09/26 16:00:12 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
The Regents of the University of California. All rights reserved.");
@@ -907,7 +907,7 @@ runTargets(void)
if (Lst_IsEmpty(create))
targs = Parse_MainName();
else
- targs = Targ_FindList(create, TARG_CREATE);
+ targs = Targ_FindList(create);
if (!compatMake) {
/*
@@ -2039,7 +2039,7 @@ PrintOnError(GNode *gn, const char *s)
/*
* Finally, see if there is a .ERROR target, and run it if so.
*/
- en = Targ_FindNode(".ERROR", TARG_NOCREATE);
+ en = Targ_FindNode(".ERROR");
if (en) {
en->type |= OP_SPECIAL;
Compat_Make(en, en);
Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.144 src/usr.bin/make/make.c:1.145
--- src/usr.bin/make/make.c:1.144 Fri Sep 25 14:00:17 2020
+++ src/usr.bin/make/make.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.144 2020/09/25 14:00:17 rillig Exp $ */
+/* $NetBSD: make.c,v 1.145 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
#include "job.h"
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: make.c,v 1.144 2020/09/25 14:00:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.145 2020/09/26 16:00:12 rillig Exp $");
static unsigned int checked = 1;/* Sequence # to detect recursion */
static GNodeList *toBeMade; /* The current fringe of the graph. These
@@ -483,7 +483,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
/* TODO: handle errors */
if (gn->uname && strcmp(gn->name, gn->uname) != 0) {
/* See if we have a target for this node. */
- GNode *tgn = Targ_FindNode(gn->name, TARG_NOCREATE);
+ GNode *tgn = Targ_FindNode(gn->name);
if (tgn != NULL)
gn = tgn;
}
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.146 src/usr.bin/make/make.h:1.147
--- src/usr.bin/make/make.h:1.146 Thu Sep 24 07:37:42 2020
+++ src/usr.bin/make/make.h Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.146 2020/09/24 07:37:42 rillig Exp $ */
+/* $NetBSD: make.h,v 1.147 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -367,18 +367,6 @@ typedef struct GNode {
#define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)
/*
- * The TARG_ constants are used when calling the Targ_FindNode and
- * Targ_FindList functions in targ.c. They simply tell the functions what to
- * do if the desired node(s) is (are) not found. If the TARG_CREATE constant
- * is given, a new, empty node will be created for the target, placed in the
- * table of all targets and its address returned. If TARG_NOCREATE is given,
- * a NULL pointer will be returned.
- */
-#define TARG_NOCREATE 0x00 /* don't create it */
-#define TARG_CREATE 0x01 /* create node if not found */
-#define TARG_NOHASH 0x02 /* don't look in/add to hash table */
-
-/*
* Error levels for parsing. PARSE_FATAL means the process cannot continue
* once the makefile has been parsed. PARSE_WARNING means it can. Passed
* as the first argument to Parse_Error.
Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.129 src/usr.bin/make/nonints.h:1.130
--- src/usr.bin/make/nonints.h:1.129 Fri Sep 25 19:50:04 2020
+++ src/usr.bin/make/nonints.h Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.129 2020/09/25 19:50:04 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.130 2020/09/26 16:00:12 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -173,9 +173,11 @@ void Targ_End(void);
void Targ_Stats(void);
GNodeList *Targ_List(void);
GNode *Targ_NewGN(const char *);
-GNode *Targ_FindNode(const char *, int);
+GNode *Targ_FindNode(const char *);
+GNode *Targ_GetNode(const char *);
+GNode *Targ_NewInternalNode(const char *);
GNode *Targ_GetEndNode(void);
-GNodeList *Targ_FindList(StringList *, int);
+GNodeList *Targ_FindList(StringList *);
Boolean Targ_Ignore(GNode *);
Boolean Targ_Silent(GNode *);
Boolean Targ_Precious(GNode *);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.331 src/usr.bin/make/parse.c:1.332
--- src/usr.bin/make/parse.c:1.331 Sat Sep 26 00:03:29 2020
+++ src/usr.bin/make/parse.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.331 2020/09/26 00:03:29 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.332 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.331 2020/09/26 00:03:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.332 2020/09/26 16:00:12 rillig Exp $");
/* types and constants */
@@ -871,7 +871,7 @@ ParseDoOp(void *gnp, void *opp)
*/
gn->type |= op & ~OP_OPMASK;
- cohort = Targ_FindNode(gn->name, TARG_NOHASH);
+ cohort = Targ_NewInternalNode(gn->name);
if (doing_depend)
ParseMark(cohort);
/*
@@ -946,7 +946,7 @@ ParseDoSrc(int tOp, const char *src, Par
* We give each .WAIT node a unique name (mainly for diag).
*/
snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number);
- gn = Targ_FindNode(wait_src, TARG_NOHASH);
+ gn = Targ_NewInternalNode(wait_src);
if (doing_depend)
ParseMark(gn);
gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
@@ -982,7 +982,7 @@ ParseDoSrc(int tOp, const char *src, Par
* Create proper predecessor/successor links between the previous
* source and the current one.
*/
- gn = Targ_FindNode(src, TARG_CREATE);
+ gn = Targ_GetNode(src);
if (doing_depend)
ParseMark(gn);
if (predecessor != NULL) {
@@ -1015,7 +1015,7 @@ ParseDoSrc(int tOp, const char *src, Par
*/
/* Find/create the 'src' node and attach to all targets */
- gn = Targ_FindNode(src, TARG_CREATE);
+ gn = Targ_GetNode(src);
if (doing_depend)
ParseMark(gn);
if (tOp) {
@@ -1309,7 +1309,7 @@ ParseDoDependency(char *line)
case Stale:
case dotError:
case Interrupt: {
- GNode *gn = Targ_FindNode(line, TARG_CREATE);
+ GNode *gn = Targ_GetNode(line);
if (doing_depend)
ParseMark(gn);
gn->type |= OP_NOTMAIN|OP_SPECIAL;
@@ -1393,7 +1393,7 @@ ParseDoDependency(char *line)
char *targName = Lst_Dequeue(curTargs);
GNode *gn = Suff_IsTransform(targName)
? Suff_AddTransform(targName)
- : Targ_FindNode(targName, TARG_CREATE);
+ : Targ_GetNode(targName);
if (doing_depend)
ParseMark(gn);
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.167 src/usr.bin/make/suff.c:1.168
--- src/usr.bin/make/suff.c:1.167 Fri Sep 25 19:50:04 2020
+++ src/usr.bin/make/suff.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.167 2020/09/25 19:50:04 rillig Exp $ */
+/* $NetBSD: suff.c,v 1.168 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.167 2020/09/25 19:50:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.168 2020/09/26 16:00:12 rillig Exp $");
#define SUFF_DEBUG0(fmt) \
if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt)
@@ -1061,7 +1061,7 @@ SuffFindThem(SrcList *srcs, SrcList *sls
* A file is considered to exist if either a node exists in the
* graph for it or the file actually exists.
*/
- if (Targ_FindNode(s->file, TARG_NOCREATE) != NULL) {
+ if (Targ_FindNode(s->file) != NULL) {
#ifdef DEBUG_SRC
fprintf(debug_file, "remove %p from %p\n", s, srcs);
#endif
@@ -1263,7 +1263,7 @@ SuffExpandChildren(GNodeListNode *cln, G
* add it, skip any further spaces.
*/
*cp++ = '\0';
- gn = Targ_FindNode(start, TARG_CREATE);
+ gn = Targ_GetNode(start);
Lst_Append(members, gn);
while (*cp == ' ' || *cp == '\t') {
cp++;
@@ -1310,7 +1310,7 @@ SuffExpandChildren(GNodeListNode *cln, G
/*
* Stuff left over -- add it to the list too
*/
- gn = Targ_FindNode(start, TARG_CREATE);
+ gn = Targ_GetNode(start);
Lst_Append(members, gn);
}
/*
@@ -1376,7 +1376,7 @@ SuffExpandWildcards(GNodeListNode *cln,
char *cp = Lst_Dequeue(explist);
SUFF_DEBUG1("%s...", cp);
- gn = Targ_FindNode(cp, TARG_CREATE);
+ gn = Targ_GetNode(cp);
/* Add gn to the parents child list before the original child */
Lst_InsertBefore(pgn->children, cln, gn);
@@ -1562,7 +1562,7 @@ SuffFindArchiveDeps(GNode *gn, SrcList *
* use for the archive without having to do a quadratic search over the
* suffix list, backtracking for each one...
*/
- mem = Targ_FindNode(name, TARG_CREATE);
+ mem = Targ_GetNode(name);
SuffFindDeps(mem, slst);
/*
@@ -1957,7 +1957,7 @@ sfnd_abort:
* Etc.
*/
if (bottom->node == NULL) {
- bottom->node = Targ_FindNode(bottom->file, TARG_CREATE);
+ bottom->node = Targ_GetNode(bottom->file);
}
for (src = bottom; src->parent != NULL; src = src->parent) {
@@ -1969,7 +1969,7 @@ sfnd_abort:
src->node->suffix->refCount++;
if (targ->node == NULL) {
- targ->node = Targ_FindNode(targ->file, TARG_CREATE);
+ targ->node = Targ_GetNode(targ->file);
}
SuffApplyTransform(targ->node, src->node,
Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.94 src/usr.bin/make/targ.c:1.95
--- src/usr.bin/make/targ.c:1.94 Sat Sep 26 14:59:21 2020
+++ src/usr.bin/make/targ.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: targ.c,v 1.94 2020/09/26 14:59:21 rillig Exp $ */
+/* $NetBSD: targ.c,v 1.95 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -90,10 +90,7 @@
* flags are right (TARG_CREATE)
*
* Targ_FindList Given a list of names, find nodes for all
- * of them. If a name doesn't exist and the
- * TARG_NOCREATE flag was given, an error message
- * is printed. Else, if a name doesn't exist,
- * its node is created.
+ * of them, creating them as necessary.
*
* Targ_Ignore Return TRUE if errors should be ignored when
* creating the given target.
@@ -122,7 +119,7 @@
#include "dir.h"
/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: targ.c,v 1.94 2020/09/26 14:59:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.95 2020/09/26 16:00:12 rillig Exp $");
static GNodeList *allTargets; /* the list of all targets found so far */
#ifdef CLEANUP
@@ -239,6 +236,9 @@ TargFreeGN(void *gnp)
}
#endif
+#define TARG_NOCREATE 0x00 /* don't create it */
+#define TARG_CREATE 0x01 /* create node if not found */
+#define TARG_NOHASH 0x02 /* don't look in/add to hash table */
/* Find a node in the list using the given name for matching.
* If the node is created, it is added to the .ALLTARGETS list.
@@ -252,8 +252,8 @@ TargFreeGN(void *gnp)
* flags was TARG_NOCREATE or the newly created and initialized node
* if it was TARG_CREATE
*/
-GNode *
-Targ_FindNode(const char *name, int flags)
+static GNode *
+Targ_FindNodeImpl(const char *name, int flags)
{
GNode *gn; /* node in that element */
Hash_Entry *he; /* New or used hash entry for node */
@@ -278,6 +278,30 @@ Targ_FindNode(const char *name, int flag
return gn;
}
+/* Get the existing global node, or return NULL. */
+GNode *
+Targ_FindNode(const char *name)
+{
+ return Targ_FindNodeImpl(name, TARG_NOCREATE);
+}
+
+/* Get the existing global node, or create it. */
+GNode *
+Targ_GetNode(const char *name)
+{
+ return Targ_FindNodeImpl(name, TARG_CREATE);
+}
+
+/* Create a node, register it in .ALLTARGETS but don't store it in the
+ * table of global nodes. This means it cannot be found by name.
+ *
+ * This is used for internal nodes, such as cohorts or .WAIT nodes. */
+GNode *
+Targ_NewInternalNode(const char *name)
+{
+ return Targ_FindNodeImpl(name, TARG_NOHASH);
+}
+
/* Return the .END node, which contains the commands to be executed when
* everything else is done. */
GNode *Targ_GetEndNode(void)
@@ -285,7 +309,7 @@ GNode *Targ_GetEndNode(void)
/* Save the node locally to avoid having to search for it all the time. */
static GNode *endNode = NULL;
if (endNode == NULL) {
- endNode = Targ_FindNode(".END", TARG_CREATE);
+ endNode = Targ_GetNode(".END");
endNode->type = OP_SPECIAL;
}
return endNode;
@@ -305,7 +329,7 @@ GNode *Targ_GetEndNode(void)
* the names in names.
*/
GNodeList *
-Targ_FindList(StringList *names, int flags)
+Targ_FindList(StringList *names)
{
GNodeList *nodes;
StringListNode *ln;
@@ -315,12 +339,8 @@ Targ_FindList(StringList *names, int fla
Lst_Open(names);
while ((ln = Lst_Next(names)) != NULL) {
char *name = LstNode_Datum(ln);
- GNode *gn = Targ_FindNode(name, flags);
- if (gn != NULL) {
- Lst_Append(nodes, gn);
- } else if (flags == TARG_NOCREATE) {
- Error("\"%s\" -- target unknown.", name);
- }
+ GNode *gn = Targ_GetNode(name);
+ Lst_Append(nodes, gn);
}
Lst_Close(names);
return nodes;
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.542 src/usr.bin/make/var.c:1.543
--- src/usr.bin/make/var.c:1.542 Sat Sep 26 14:48:31 2020
+++ src/usr.bin/make/var.c Sat Sep 26 16:00:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.542 2020/09/26 14:48:31 rillig Exp $ */
+/* $NetBSD: var.c,v 1.543 2020/09/26 16:00:12 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.542 2020/09/26 14:48:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.543 2020/09/26 16:00:12 rillig Exp $");
#define VAR_DEBUG_IF(cond, fmt, ...) \
if (!(DEBUG(VAR) && (cond))) \
@@ -2131,7 +2131,7 @@ ApplyModifier_Path(const char **pp, Appl
ApplyModifiersState_Define(st);
- gn = Targ_FindNode(st->v->name, TARG_NOCREATE);
+ gn = Targ_FindNode(st->v->name);
if (gn == NULL || gn->type & OP_NOPATH) {
path = NULL;
} else if (gn->path) {