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: reorganize Parse_Error



details:   https://anonhg.NetBSD.org/src/rev/754f845b8315
branches:  trunk
changeset: 366755:754f845b8315
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 12 13:37:32 2022 +0000

description:
make: reorganize Parse_Error

Determining the location where the error occurred is now done by
ParseVErrorInternal.  This frees the remaining code from keeping the
filename and the line number together.  It also makes Parse_Error short
enough that it might be worth providing a separate function for each of
the 3 log levels.

No functional change.

diffstat:

 usr.bin/make/make.h  |   4 ++--
 usr.bin/make/parse.c |  50 +++++++++++++++++++++++++-------------------------
 usr.bin/make/var.c   |   7 +++----
 3 files changed, 30 insertions(+), 31 deletions(-)

diffs (171 lines):

diff -r 23c1f4e01145 -r 754f845b8315 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sun Jun 12 11:36:42 2022 +0000
+++ b/usr.bin/make/make.h       Sun Jun 12 13:37:32 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.302 2022/05/07 17:49:47 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.303 2022/06/12 13:37:32 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -852,7 +852,7 @@
 void Parse_Init(void);
 void Parse_End(void);
 
-void PrintLocation(FILE *, bool, const char *, unsigned);
+void PrintLocation(FILE *, bool, const GNode *);
 void PrintStackTrace(bool);
 void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
 bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
diff -r 23c1f4e01145 -r 754f845b8315 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Jun 12 11:36:42 2022 +0000
+++ b/usr.bin/make/parse.c      Sun Jun 12 13:37:32 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.679 2022/06/11 17:58:15 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.680 2022/06/12 13:37:32 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.679 2022/06/11 17:58:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.680 2022/06/12 13:37:32 rillig Exp $");
 
 /*
  * A file being read.
@@ -436,10 +436,22 @@
 }
 
 void
-PrintLocation(FILE *f, bool useVars, const char *fname, unsigned lineno)
+PrintLocation(FILE *f, bool useVars, const GNode *gn)
 {
        char dirbuf[MAXPATHLEN + 1];
        FStr dir, base;
+       const char *fname;
+       unsigned lineno;
+
+       if (gn != NULL) {
+               fname = gn->fname;
+               lineno = gn->lineno;
+       } else if (includes.len > 0) {
+               IncludedFile *curFile = CurFile();
+               fname = curFile->name.str;
+               lineno = curFile->lineno;
+       } else
+               return;
 
        if (!useVars || fname[0] == '/' || strcmp(fname, "(stdin)") == 0) {
                (void)fprintf(f, "\"%s\" line %u: ", fname, lineno);
@@ -462,16 +474,15 @@
        FStr_Done(&dir);
 }
 
-static void MAKE_ATTR_PRINTFLIKE(6, 0)
-ParseVErrorInternal(FILE *f, bool useVars, const char *fname, unsigned lineno,
+static void MAKE_ATTR_PRINTFLIKE(5, 0)
+ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn,
                    ParseErrorLevel level, const char *fmt, va_list ap)
 {
        static bool fatal_warning_error_printed = false;
 
        (void)fprintf(f, "%s: ", progname);
 
-       if (fname != NULL)
-               PrintLocation(f, useVars, fname, lineno);
+       PrintLocation(f, useVars, gn);
        if (level == PARSE_WARNING)
                (void)fprintf(f, "warning: ");
        (void)vfprintf(f, fmt, ap);
@@ -492,20 +503,20 @@
                PrintStackTrace(false);
 }
 
-static void MAKE_ATTR_PRINTFLIKE(4, 5)
-ParseErrorInternal(const char *fname, unsigned lineno,
+static void MAKE_ATTR_PRINTFLIKE(3, 4)
+ParseErrorInternal(const GNode *gn,
                   ParseErrorLevel level, const char *fmt, ...)
 {
        va_list ap;
 
        (void)fflush(stdout);
        va_start(ap, fmt);
-       ParseVErrorInternal(stderr, false, fname, lineno, level, fmt, ap);
+       ParseVErrorInternal(stderr, false, gn, level, fmt, ap);
        va_end(ap);
 
        if (opts.debug_file != stdout && opts.debug_file != stderr) {
                va_start(ap, fmt);
-               ParseVErrorInternal(opts.debug_file, false, fname, lineno,
+               ParseVErrorInternal(opts.debug_file, false, gn,
                    level, fmt, ap);
                va_end(ap);
        }
@@ -523,26 +534,15 @@
 Parse_Error(ParseErrorLevel level, const char *fmt, ...)
 {
        va_list ap;
-       const char *fname;
-       unsigned lineno;
-
-       if (includes.len == 0) {
-               fname = NULL;
-               lineno = 0;
-       } else {
-               IncludedFile *curFile = CurFile();
-               fname = curFile->name.str;
-               lineno = curFile->lineno;
-       }
 
        (void)fflush(stdout);
        va_start(ap, fmt);
-       ParseVErrorInternal(stderr, true, fname, lineno, level, fmt, ap);
+       ParseVErrorInternal(stderr, true, NULL, level, fmt, ap);
        va_end(ap);
 
        if (opts.debug_file != stdout && opts.debug_file != stderr) {
                va_start(ap, fmt);
-               ParseVErrorInternal(opts.debug_file, true, fname, lineno,
+               ParseVErrorInternal(opts.debug_file, true, NULL,
                    level, fmt, ap);
                va_end(ap);
        }
@@ -1921,7 +1921,7 @@
                Parse_Error(PARSE_WARNING,
                    "duplicate script for target \"%s\" ignored",
                    gn->name);
-               ParseErrorInternal(gn->fname, gn->lineno, PARSE_WARNING,
+               ParseErrorInternal(gn, PARSE_WARNING,
                    "using previous script for \"%s\" defined here",
                    gn->name);
 #endif
diff -r 23c1f4e01145 -r 754f845b8315 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Jun 12 11:36:42 2022 +0000
+++ b/usr.bin/make/var.c        Sun Jun 12 13:37:32 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.1021 2022/05/14 12:25:16 rillig Exp $        */
+/*     $NetBSD: var.c,v 1.1022 2022/06/12 13:37:32 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1021 2022/05/14 12:25:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1022 2022/06/12 13:37:32 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4523,8 +4523,7 @@
        if (v->inUse) {
                if (scope->fname != NULL) {
                        fprintf(stderr, "In a command near ");
-                       PrintLocation(stderr, false,
-                           scope->fname, scope->lineno);
+                       PrintLocation(stderr, false, scope);
                }
                Fatal("Variable %s is recursive.", v->name.str);
        }



Home | Main Index | Thread Index | Old Index