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: clean up tracking of depth of nested .if ...
details: https://anonhg.NetBSD.org/src/rev/0ada025d0eaa
branches: trunk
changeset: 370686:0ada025d0eaa
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 24 16:13:48 2022 +0000
description:
make: clean up tracking of depth of nested .if directives
The variable cond_min_depth was redundant. It was only accessed while
parsing the makefiles. Merging it into struct IncludedFile removes the
possible confusion between cond_min_depth and including_cond_min_depth.
No functional change.
diffstat:
usr.bin/make/cond.c | 53 ++++++++++++---------------------------------------
usr.bin/make/make.h | 8 +++---
usr.bin/make/parse.c | 25 ++++++++++++-----------
3 files changed, 30 insertions(+), 56 deletions(-)
diffs (218 lines):
diff -r b9213e31f699 -r 0ada025d0eaa usr.bin/make/cond.c
--- a/usr.bin/make/cond.c Sat Sep 24 16:09:04 2022 +0000
+++ b/usr.bin/make/cond.c Sat Sep 24 16:13:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.341 2022/09/24 10:26:31 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -81,13 +81,9 @@
* of one of the .if directives or the condition in a
* ':?then:else' variable modifier.
*
- * Cond_PushMinDepth
- * Cond_PopMinDepth
- * Cond_ResetDepth
- * Save and restore the nesting of the conditions, at
- * the start and end of including another makefile, to
- * ensure that in each makefile the conditional
- * directives are well-balanced.
+ * Cond_EndFile
+ * At the end of reading a makefile, ensure that the
+ * conditional directives are well-balanced.
*/
#include <errno.h>
@@ -96,7 +92,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.341 2022/09/24 10:26:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $");
/*
* Conditional expressions conform to this grammar:
@@ -179,8 +175,7 @@
static CondResult CondParser_Or(CondParser *par, bool);
-static unsigned int cond_depth = 0; /* current .if nesting level */
-static unsigned int cond_min_depth = 0; /* depth at makefile open */
+unsigned int cond_depth = 0; /* current .if nesting level */
/* Names for ComparisonOp. */
static const char opname[][3] = { "<", "<=", ">", ">=", "==", "!=" };
@@ -1138,7 +1133,7 @@
"The .endif directive does not take arguments");
}
- if (cond_depth == cond_min_depth) {
+ if (cond_depth == CurFile_CondMinDepth()) {
Parse_Error(PARSE_FATAL, "if-less endif");
return CR_TRUE;
}
@@ -1168,7 +1163,7 @@
"The .else directive "
"does not take arguments");
- if (cond_depth == cond_min_depth) {
+ if (cond_depth == CurFile_CondMinDepth()) {
Parse_Error(PARSE_FATAL, "if-less else");
return CR_TRUE;
}
@@ -1203,7 +1198,7 @@
return CR_ERROR;
if (isElif) {
- if (cond_depth == cond_min_depth) {
+ if (cond_depth == CurFile_CondMinDepth()) {
Parse_Error(PARSE_FATAL, "if-less elif");
return CR_TRUE;
}
@@ -1256,36 +1251,14 @@
return res;
}
-unsigned int
-Cond_PushMinDepth(void)
+void
+Cond_EndFile(void)
{
- unsigned int depth = cond_min_depth;
+ unsigned int open_conds = cond_depth - CurFile_CondMinDepth();
- cond_min_depth = cond_depth;
- return depth;
-}
-
-void
-Cond_PopMinDepth(unsigned int saved_depth)
-{
- unsigned int open_conds = cond_depth - cond_min_depth;
-
- assert(saved_depth <= cond_depth);
if (open_conds != 0) {
Parse_Error(PARSE_FATAL, "%u open conditional%s",
open_conds, open_conds == 1 ? "" : "s");
- cond_depth = cond_min_depth;
+ cond_depth = CurFile_CondMinDepth();
}
-
- cond_min_depth = saved_depth;
}
-
-/*
- * When breaking out of a .for loop, restore cond_depth to where it was when
- * the loop started.
- */
-void
-Cond_ResetDepth(void)
-{
- cond_depth = cond_min_depth;
-}
diff -r b9213e31f699 -r 0ada025d0eaa usr.bin/make/make.h
--- a/usr.bin/make/make.h Sat Sep 24 16:09:04 2022 +0000
+++ b/usr.bin/make/make.h Sat Sep 24 16:13:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.306 2022/09/24 10:26:31 rillig Exp $ */
+/* $NetBSD: make.h,v 1.307 2022/09/24 16:13:48 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -797,11 +797,10 @@
void Compat_Make(GNode *, GNode *);
/* cond.c */
+extern unsigned int cond_depth;
CondResult Cond_EvalCondition(const char *) MAKE_ATTR_USE;
CondResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
-unsigned int Cond_PushMinDepth(void) MAKE_ATTR_USE;
-void Cond_PopMinDepth(unsigned int);
-void Cond_ResetDepth(void);
+void Cond_EndFile(void);
/* dir.c; see also dir.h */
@@ -864,6 +863,7 @@
struct ForLoop *);
void Parse_MainName(GNodeList *);
int Parse_NumErrors(void) MAKE_ATTR_USE;
+unsigned int CurFile_CondMinDepth(void) MAKE_ATTR_USE;
/* suff.c */
diff -r b9213e31f699 -r 0ada025d0eaa usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sat Sep 24 16:09:04 2022 +0000
+++ b/usr.bin/make/parse.c Sat Sep 24 16:13:48 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.686 2022/09/24 16:09:04 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.687 2022/09/24 16:13:48 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.686 2022/09/24 16:09:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.687 2022/09/24 16:13:48 rillig Exp $");
/*
* A file being read.
@@ -119,9 +119,8 @@
unsigned forBodyReadLines; /* the number of physical lines that have
* been read from the file above the body of
* the .for loop */
- unsigned int including_cond_min_depth; /* depth of nested 'if'
- * directives, at the point where the
- * including file was opened */
+ unsigned int condMinDepth; /* depth of nested 'if' directives, at the
+ * beginning of the file */
bool depending; /* state of doing_depend on EOF */
Buffer buf; /* the file's content or the body of the .for
@@ -311,6 +310,12 @@
return GetInclude(includes.len - 1);
}
+unsigned int
+CurFile_CondMinDepth(void)
+{
+ return CurFile()->condMinDepth;
+}
+
static Buffer
LoadFile(const char *path, int fd)
{
@@ -2142,7 +2147,7 @@
curFile->buf_ptr = curFile->buf.data;
curFile->buf_end = curFile->buf.data + curFile->buf.len;
- curFile->including_cond_min_depth = Cond_PushMinDepth();
+ curFile->condMinDepth = cond_depth;
SetParseFile(name);
}
@@ -2275,11 +2280,7 @@
return true;
}
- /*
- * Ensure the makefile (or .for loop) didn't have mismatched
- * conditionals.
- */
- Cond_PopMinDepth(curFile->including_cond_min_depth);
+ Cond_EndFile();
FStr_Done(&curFile->name);
Buf_Done(&curFile->buf);
@@ -2672,7 +2673,7 @@
if (curFile->forLoop != NULL) {
/* pretend we reached EOF */
For_Break(curFile->forLoop);
- Cond_ResetDepth();
+ cond_depth = CurFile_CondMinDepth();
ParseEOF();
} else
Parse_Error(PARSE_FATAL, "break outside of for loop");
Home |
Main Index |
Thread Index |
Old Index