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(1): clean up VarParseResult constants



details:   https://anonhg.NetBSD.org/src/rev/0906ba81a35e
branches:  trunk
changeset: 948331:0906ba81a35e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 27 10:53:23 2020 +0000

description:
make(1): clean up VarParseResult constants

The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished.  There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
    undefined variables.  The old constants VPR_PARSE_MSG and
    VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
    Previously the documentation for VPR_UNDEF_SILENT talked about
    undefined expressions in situations where they were not allowed.
    That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored.  These are probably bugs.

(4) Everything went fine, the expression has a defined value.

diffstat:

 usr.bin/make/cond.c    |   6 ++--
 usr.bin/make/nonints.h |  70 +++++++++++--------------------------------------
 usr.bin/make/var.c     |  36 +++++++++++++++++--------
 3 files changed, 43 insertions(+), 69 deletions(-)

diffs (218 lines):

diff -r 7b1e6230bfc6 -r 0906ba81a35e usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Dec 27 10:09:53 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Dec 27 10:53:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.231 2020/12/23 13:50:54 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.232 2020/12/27 10:53:23 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.231 2020/12/23 13:50:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.232 2020/12/27 10:53:23 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -452,7 +452,7 @@
                            &str);
                        /* TODO: handle errors */
                        if (str.str == var_Error) {
-                               if (parseResult & VPR_ANY_MSG)
+                               if (parseResult == VPR_ERR)
                                        par->printedError = TRUE;
                                /*
                                 * XXX: Can there be any situation in which
diff -r 7b1e6230bfc6 -r 0906ba81a35e usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Dec 27 10:09:53 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Dec 27 10:53:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.183 2020/12/27 10:09:53 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.184 2020/12/27 10:53:23 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -316,67 +316,29 @@
        VAR_SET_READONLY        = 1 << 1
 } VarSetFlags;
 
-/* The state of error handling returned by Var_Parse.
- *
- * As of 2020-09-13, this bitset looks quite bloated,
- * with all the constants doubled.
- *
- * Its purpose is to first document the existing behavior,
- * and then migrate away from the SILENT constants, step by step,
- * as these are not suited for reliable, consistent error handling
- * and reporting. */
+/* The state of error handling returned by Var_Parse. */
 typedef enum VarParseResult {
 
        /* Both parsing and evaluation succeeded. */
-       VPR_OK          = 0x0000,
-
-       /* See if a message has already been printed for this error. */
-       VPR_ANY_MSG             = 0x0001,
+       VPR_OK,
 
-       /*
-        * Parsing failed.
-        * No error message has been printed yet.
-        * Deprecated, migrate to VPR_PARSE_MSG instead.
-        */
-       VPR_PARSE_SILENT        = 0x0002,
+       /* Parsing or evaluating failed, with an error message. */
+       VPR_ERR,
 
-       /*
-        * Parsing failed.
-        * An error message has already been printed.
-        */
-       VPR_PARSE_MSG   = VPR_PARSE_SILENT | VPR_ANY_MSG,
+       /* deprecated */
+       VPR_ERR_SILENT,
 
        /*
-        * Parsing succeeded.
-        * During evaluation, VARE_UNDEFERR was set and there was an undefined
-        * variable.
-        * No error message has been printed yet.
-        * Deprecated, migrate to VPR_UNDEF_MSG instead.
-        */
-       VPR_UNDEF_SILENT        = 0x0004,
-
-       /*
-        * Parsing succeeded.
-        * During evaluation, VARE_UNDEFERR was set and there was an undefined
-        * variable.
-        * An error message has already been printed.
+        * Parsing succeeded, undefined expressions are allowed and the
+        * expression was still undefined after applying all modifiers.
+        * No error message is printed in this case.
+        *
+        * Some callers handle this case differently, so return this
+        * information to them, for now.
+        *
+        * TODO: Replace this with a new flag VARE_KEEP_UNDEFINED.
         */
-       VPR_UNDEF_MSG   = VPR_UNDEF_SILENT | VPR_ANY_MSG,
-
-       /*
-        * Parsing succeeded.
-        * Evaluation failed.
-        * No error message has been printed yet.
-        * Deprecated, migrate to VPR_EVAL_MSG instead.
-        */
-       VPR_EVAL_SILENT = 0x0006,
-
-       /*
-        * Parsing succeeded.
-        * Evaluation failed.
-        * An error message has already been printed.
-        */
-       VPR_EVAL_MSG    = VPR_EVAL_SILENT | VPR_ANY_MSG
+       VPR_UNDEF
 
 } VarParseResult;
 
diff -r 7b1e6230bfc6 -r 0906ba81a35e usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 27 10:09:53 2020 +0000
+++ b/usr.bin/make/var.c        Sun Dec 27 10:53:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.766 2020/12/27 10:09:53 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.767 2020/12/27 10:53:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.766 2020/12/27 10:09:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.767 2020/12/27 10:53:23 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -2098,7 +2098,7 @@
                Error("Unfinished modifier for %s ('%c' missing)",
                    st->var->name.str, delim);
                *out_part = NULL;
-               return VPR_PARSE_MSG;
+               return VPR_ERR;
        }
 
        *pp = ++p;
@@ -3754,8 +3754,10 @@
                return VPR_OK;
        }
 
-       if (!opts.strict)
-               return VPR_PARSE_SILENT;
+       if (!opts.strict) {
+               /* XXX: Should rather be a parse error with error message. */
+               return VPR_ERR_SILENT;
+       }
 
        if (varname == '$')
                Parse_Error(PARSE_FATAL,
@@ -3766,7 +3768,7 @@
                Parse_Error(PARSE_FATAL,
                    "Invalid variable name '%c', at \"%s\"", varname, start);
 
-       return VPR_PARSE_MSG;
+       return VPR_ERR;
 }
 
 /* Parse a single-character variable name such as $V or $@.
@@ -3805,11 +3807,21 @@
                if (opts.strict && *out_FALSE_val == var_Error) {
                        Parse_Error(PARSE_FATAL,
                            "Variable \"%s\" is undefined", name);
-                       *out_FALSE_res = VPR_UNDEF_MSG;
+                       *out_FALSE_res = VPR_ERR;
                        return FALSE;
                }
-               *out_FALSE_res =
-                   eflags & VARE_UNDEFERR ? VPR_UNDEF_SILENT : VPR_OK;
+
+               /*
+                * XXX: This looks completely wrong.
+                *
+                * If undefined expressions are not allowed, this should
+                * rather be VPR_ERR instead of VPR_UNDEF, together with an
+                * error message.
+                *
+                * If undefined expressions are allowed, this should rather
+                * be VPR_UNDEF instead of VPR_OK.
+                */
+               *out_FALSE_res = eflags & VARE_UNDEFERR ? VPR_UNDEF : VPR_OK;
                return FALSE;
        }
 
@@ -3864,13 +3876,13 @@
                    "Variable \"%s\" is undefined", varname);
                free(varname);
                *out_val = FStr_InitRefer(var_Error);
-               return VPR_UNDEF_MSG;
+               return VPR_ERR;
        }
 
        if (eflags & VARE_UNDEFERR) {
                free(varname);
                *out_val = FStr_InitRefer(var_Error);
-               return VPR_UNDEF_SILENT;
+               return VPR_UNDEF;       /* XXX: Should be VPR_ERR instead. */
        }
 
        free(varname);
@@ -3923,7 +3935,7 @@
                free(varname);
                *out_FALSE_pp = p;
                *out_FALSE_val = FStr_InitRefer(var_Error);
-               *out_FALSE_res = VPR_PARSE_MSG;
+               *out_FALSE_res = VPR_ERR;
                return FALSE;
        }
 



Home | Main Index | Thread Index | Old Index