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: fix reported line numbers of continuation...
details: https://anonhg.NetBSD.org/src/rev/5f5a983944ab
branches: trunk
changeset: 359526:5f5a983944ab
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 08 20:21:34 2022 +0000
description:
make: fix reported line numbers of continuation lines (since 2002)
Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
diffstat:
usr.bin/make/for.c | 8 +-
usr.bin/make/nonints.h | 6 +-
usr.bin/make/parse.c | 70 ++++++++++----------------
usr.bin/make/unit-tests/cond-token-plain.exp | 2 +-
usr.bin/make/unit-tests/cond-token-string.exp | 4 +-
usr.bin/make/unit-tests/directive-for.exp | 2 +-
usr.bin/make/unit-tests/directive-info.exp | 2 +-
usr.bin/make/unit-tests/directive-info.mk | 13 ++--
usr.bin/make/unit-tests/directive-undef.exp | 2 +-
usr.bin/make/unit-tests/opt-debug-parse.exp | 2 +-
usr.bin/make/unit-tests/varmod-indirect.exp | 2 +-
usr.bin/make/unit-tests/varmod-indirect.mk | 4 +-
12 files changed, 51 insertions(+), 66 deletions(-)
diffs (truncated from 385 to 300 lines):
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/for.c
--- a/usr.bin/make/for.c Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/for.c Sat Jan 08 20:21:34 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.159 2022/01/08 17:25:19 rillig Exp $ */
+/* $NetBSD: for.c,v 1.160 2022/01/08 20:21:34 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: for.c,v 1.159 2022/01/08 17:25:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.160 2022/01/08 20:21:34 rillig Exp $");
typedef struct ForLoop {
@@ -469,7 +469,7 @@
/* Run the .for loop, imitating the actions of an include file. */
void
-For_Run(int lineno)
+For_Run(int headLineno, int bodyReadLines)
{
Buffer buf;
ForLoop *f = accumFor;
@@ -477,7 +477,7 @@
if (f->items.len > 0) {
Buf_Init(&buf);
- Parse_PushInput(NULL, lineno, buf, f);
+ Parse_PushInput(NULL, headLineno, bodyReadLines, buf, f);
} else
ForLoop_Free(f);
}
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/nonints.h Sat Jan 08 20:21:34 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.233 2022/01/07 20:54:45 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.234 2022/01/08 20:21:34 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -119,7 +119,7 @@
struct ForLoop;
int For_Eval(const char *) MAKE_ATTR_USE;
bool For_Accum(const char *, int *) MAKE_ATTR_USE;
-void For_Run(int);
+void For_Run(int, int);
bool For_NextIteration(struct ForLoop *, Buffer *);
/* job.c */
@@ -147,7 +147,7 @@
bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
void Parse_AddIncludeDir(const char *);
void Parse_File(const char *, int);
-void Parse_PushInput(const char *, int, Buffer, struct ForLoop *);
+void Parse_PushInput(const char *, int, int, Buffer, struct ForLoop *);
void Parse_MainName(GNodeList *);
int Parse_NumErrors(void) MAKE_ATTR_USE;
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/parse.c Sat Jan 08 20:21:34 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.638 2022/01/08 09:55:32 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.639 2022/01/08 20:21:34 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -106,26 +106,20 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.638 2022/01/08 09:55:32 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.639 2022/01/08 20:21:34 rillig Exp $");
/*
* A file being read.
*/
typedef struct IncludedFile {
FStr name; /* absolute or relative to the cwd */
- /* TODO: add lineno for accurate line number information */
+ int lineno; /* 1-based */
int readLines; /* the number of physical lines that have
- * been read from the file; for lines without
- * backslash continuation, it coincidentally
- * equals the 1-based human-readable line
- * number for messages */
- /* TODO: add forHeadLineno for accurate line number information */
+ * been read from the file */
+ int forHeadLineno; /* 1-based */
int forBodyReadLines; /* the number of physical lines that have
* been read from the file above the body of
- * the .for loop; in .for loops whose head
- * fits in a single line, it coincidentally
- * equals the 1-based human-readable line
- * number for messages */
+ * the .for loop */
unsigned int cond_depth; /* 'if' nesting when file opened */
bool depending; /* state of doing_depend on EOF */
@@ -359,20 +353,12 @@
if (fname[0] != '/' && strcmp(fname, "(stdin)") != 0)
fname = realpath(fname, dirbuf);
- /*
- * FIXME: Using readLines is incorrect for multi-line
- * .include directives.
- */
if (entries[i + 1 < n ? i + 1 : i].forLoop == NULL)
debug_printf("\tin .include from %s:%d\n",
- fname, entry->readLines - 1 + 1);
- /*
- * FIXME: Using forBodyReadLines is incorrect for multi-line
- * .for directives.
- */
+ fname, entry->lineno);
if (entry->forLoop != NULL)
debug_printf("\tin .for loop from %s:%d\n",
- fname, entry->forBodyReadLines - 1 + 1);
+ fname, entry->forHeadLineno);
}
}
@@ -395,8 +381,7 @@
{
IncludedFile *curFile = CurFile();
gn->fname = Str_Intern(curFile->name.str);
- /* FIXME: mismatch between lineno and readLines */
- gn->lineno = curFile->readLines;
+ gn->lineno = curFile->lineno;
}
/*
@@ -521,8 +506,7 @@
} else {
IncludedFile *curFile = CurFile();
fname = curFile->name.str;
- /* FIXME: mismatch between lineno and readLines */
- lineno = (size_t)curFile->readLines;
+ lineno = (size_t)curFile->lineno;
}
(void)fflush(stdout);
@@ -1921,7 +1905,7 @@
buf = loadfile(fullname, fd);
(void)close(fd);
- Parse_PushInput(fullname, 0, buf, NULL);
+ Parse_PushInput(fullname, 1, 0, buf, NULL);
if (depinc)
doing_depend = depinc; /* only turn it on */
free(fullname);
@@ -2097,7 +2081,7 @@
/* Parse from the given buffer, later return to the current file. */
void
-Parse_PushInput(const char *name, int lineno, Buffer buf,
+Parse_PushInput(const char *name, int lineno, int readLines, Buffer buf,
struct ForLoop *forLoop)
{
IncludedFile *curFile;
@@ -2112,10 +2096,10 @@
curFile = Vector_Push(&includes);
curFile->name = FStr_InitOwn(bmake_strdup(name));
- /* FIXME: mismatch between readLines and lineno */
- curFile->readLines = lineno;
- /* FIXME: mismatch between readLines and lineno */
- curFile->forBodyReadLines = lineno;
+ curFile->lineno = lineno;
+ curFile->readLines = readLines;
+ curFile->forHeadLineno = lineno;
+ curFile->forBodyReadLines = readLines;
curFile->buf = buf;
curFile->depending = doing_depend; /* restore this on EOF */
curFile->forLoop = forLoop;
@@ -2278,9 +2262,8 @@
}
curFile = CurFile();
- /* FIXME: mismatch between lineno and readLines */
DEBUG2(PARSE, "ParseEOF: returning to file %s, line %d\n",
- curFile->name.str, curFile->readLines);
+ curFile->name.str, curFile->lineno);
SetParseFile(curFile->name.str);
return true;
@@ -2450,13 +2433,15 @@
ReadLowLevelLine(LineKind kind)
{
IncludedFile *curFile = CurFile();
+ ParseRawLineResult res;
char *line;
char *line_end;
char *firstBackslash;
char *commentLineEnd;
for (;;) {
- ParseRawLineResult res = ParseRawLine(curFile,
+ curFile->lineno = curFile->readLines + 1;
+ res = ParseRawLine(curFile,
&line, &line_end, &firstBackslash, &commentLineEnd);
if (res == PRLR_ERROR)
return NULL;
@@ -2517,20 +2502,20 @@
ParseForLoop(const char *line)
{
int rval;
- int firstLineno;
+ int forHeadLineno;
+ int bodyReadLines;
int forLevel;
+ forHeadLineno = CurFile()->lineno;
rval = For_Eval(line);
if (rval == 0)
return false; /* Not a .for line */
if (rval < 0)
return true; /* Syntax error - error printed, ignore line */
- /* FIXME: mismatch between lineno and readLines */
- firstLineno = CurFile()->readLines;
-
/* Accumulate the loop body until the matching '.endfor'. */
forLevel = 1;
+ bodyReadLines = CurFile()->readLines;
do {
line = ReadLowLevelLine(LK_FOR_BODY);
if (line == NULL) {
@@ -2540,7 +2525,7 @@
}
} while (For_Accum(line, &forLevel));
- For_Run(firstLineno);
+ For_Run(forHeadLineno, bodyReadLines);
return true;
}
@@ -2859,13 +2844,12 @@
assert(targets == NULL);
- Parse_PushInput(name, 0, buf, NULL);
+ Parse_PushInput(name, 1, 0, buf, NULL);
do {
while ((line = ReadHighLevelLine()) != NULL) {
- /* FIXME: mismatch between lineno and readLines */
DEBUG2(PARSE, "Parsing line %d: %s\n",
- CurFile()->readLines, line);
+ CurFile()->lineno, line);
ParseLine(line);
}
/* Reached EOF, but it may be just EOF of an include file. */
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/unit-tests/cond-token-plain.exp
--- a/usr.bin/make/unit-tests/cond-token-plain.exp Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.exp Sat Jan 08 20:21:34 2022 +0000
@@ -27,7 +27,7 @@
CondParser_Eval: ${:Uvar}||name != "var||name"
lhs = "var||name", rhs = "var||name", op = !=
CondParser_Eval: bare
-make: "cond-token-plain.mk" line 106: A bare word is treated like defined(...), and the variable 'bare' is not defined.
+make: "cond-token-plain.mk" line 105: A bare word is treated like defined(...), and the variable 'bare' is not defined.
CondParser_Eval: VAR
make: "cond-token-plain.mk" line 111: A bare word is treated like defined(...).
CondParser_Eval: V${:UA}R
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/unit-tests/cond-token-string.exp
--- a/usr.bin/make/unit-tests/cond-token-string.exp Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/unit-tests/cond-token-string.exp Sat Jan 08 20:21:34 2022 +0000
@@ -6,9 +6,9 @@
CondParser_Eval: "UNDEF"
make: "cond-token-string.mk" line 46: The string literal "UNDEF" is not empty.
CondParser_Eval: " "
-make: "cond-token-string.mk" line 55: The string literal " " is not empty, even though it consists of whitespace only.
+make: "cond-token-string.mk" line 54: The string literal " " is not empty, even though it consists of whitespace only.
CondParser_Eval: "${UNDEF}"
-make: "cond-token-string.mk" line 64: An undefined variable in quotes expands to an empty string, which then evaluates to false.
+make: "cond-token-string.mk" line 63: An undefined variable in quotes expands to an empty string, which then evaluates to false.
CondParser_Eval: "${:Uvalue}"
make: "cond-token-string.mk" line 68: A nonempty variable expression evaluates to true.
CondParser_Eval: "${:U}"
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/unit-tests/directive-for.exp
--- a/usr.bin/make/unit-tests/directive-for.exp Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-for.exp Sat Jan 08 20:21:34 2022 +0000
@@ -36,7 +36,7 @@
For: loop body:
.\
endfor
-make: "directive-for.mk" line 228: for-less endfor
+make: "directive-for.mk" line 227: for-less endfor
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff -r 74fedb4380b8 -r 5f5a983944ab usr.bin/make/unit-tests/directive-info.exp
--- a/usr.bin/make/unit-tests/directive-info.exp Sat Jan 08 17:35:05 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-info.exp Sat Jan 08 20:21:34 2022 +0000
Home |
Main Index |
Thread Index |
Old Index