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: remove overengineered Enum_ValueToString



details:   https://anonhg.NetBSD.org/src/rev/e1286e6cdc8b
branches:  trunk
changeset: 959157:e1286e6cdc8b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Feb 02 17:56:31 2021 +0000

description:
make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options.  This bug is one of the
oldest in make, dating back to at least 1993.

diffstat:

 usr.bin/make/enum.c                              |  16 ++--------------
 usr.bin/make/enum.h                              |  22 +++-------------------
 usr.bin/make/make.c                              |  12 ++++--------
 usr.bin/make/nonints.h                           |   3 ++-
 usr.bin/make/targ.c                              |  12 ++++++------
 usr.bin/make/unit-tests/gnode-submake.exp        |  16 ++++++++--------
 usr.bin/make/unit-tests/opt-debug-graph1.exp     |  16 ++++++++--------
 usr.bin/make/unit-tests/opt-debug-graph2.exp     |  12 ++++++------
 usr.bin/make/unit-tests/opt-debug-graph3.exp     |  12 ++++++------
 usr.bin/make/unit-tests/suff-incomplete.exp      |   4 ++--
 usr.bin/make/unit-tests/suff-main-several.exp    |  16 ++++++++--------
 usr.bin/make/unit-tests/suff-transform-debug.exp |   2 +-
 12 files changed, 56 insertions(+), 87 deletions(-)

diffs (truncated from 383 to 300 lines):

diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/enum.c
--- a/usr.bin/make/enum.c       Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/enum.c       Tue Feb 02 17:56:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: enum.c,v 1.14 2021/01/09 16:06:09 rillig Exp $ */
+/*     $NetBSD: enum.c,v 1.15 2021/02/02 17:56:31 rillig Exp $ */
 
 /*
  Copyright (c) 2020 Roland Illig <rillig%NetBSD.org@localhost>
@@ -29,7 +29,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: enum.c,v 1.14 2021/01/09 16:06:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: enum.c,v 1.15 2021/02/02 17:56:31 rillig Exp $");
 
 /*
  * Convert a bitset into a string representation, showing the names of the
@@ -78,15 +78,3 @@
        buf[0] = '\0';
        return buf_start;
 }
-
-/* Convert a fixed-value enum into a string representation. */
-const char *
-Enum_ValueToString(int value, const EnumToStringSpec *spec)
-{
-       for (; spec->es_name[0] != '\0'; spec++) {
-               if (value == spec->es_value)
-                       return spec->es_name;
-       }
-       abort(/* unknown enum value */);
-       /*NOTREACHED*/
-}
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/enum.h
--- a/usr.bin/make/enum.h       Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/enum.h       Tue Feb 02 17:56:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: enum.h,v 1.16 2021/01/30 15:53:55 rillig Exp $ */
+/*     $NetBSD: enum.h,v 1.17 2021/02/02 17:56:31 rillig Exp $ */
 
 /*
  Copyright (c) 2020 Roland Illig <rillig%NetBSD.org@localhost>
@@ -39,8 +39,9 @@
        const char *es_name;
 } EnumToStringSpec;
 
+
 const char *Enum_FlagsToString(char *, size_t, int, const EnumToStringSpec *);
-const char *Enum_ValueToString(int, const EnumToStringSpec *);
+
 
 /* For Enum_FlagsToString, the separator between flags. */
 #define ENUM__SEP "|"
@@ -100,13 +101,6 @@
 #define ENUM__SPECS_5(part1, part2, part3, part4, part5) \
        { part1, part2, part3, part4, part5, { 0, "" } }
 
-/* Declare the necessary data structures for calling Enum_ValueToString. */
-#define ENUM__VALUE_RTTI(typnam, specs) \
-       static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \
-       MAKE_INLINE const char *typnam ## _ToString(typnam value) \
-       { return Enum_ValueToString(value, typnam ## _ ## ToStringSpecs); } \
-       extern void enum_value_rtti_dummy(void)
-
 
 /* Declare the necessary data structures for calling Enum_FlagsToString. */
 #define ENUM__FLAGS_RTTI(typnam, specs, joined) \
@@ -184,16 +178,6 @@
                ENUM__JOIN_STR_4(v5, v6, v7, v8)))
 
 /*
- * Declare the necessary data structures for calling Enum_ValueToString
- * for an enum with 8 constants.
- */
-#define ENUM_VALUE_RTTI_8(typnam, v1, v2, v3, v4, v5, v6, v7, v8) \
-       ENUM__VALUE_RTTI(typnam, \
-           ENUM__SPECS_2( \
-               ENUM__SPEC_4(v1, v2, v3, v4), \
-               ENUM__SPEC_4(v5, v6, v7, v8)))
-
-/*
  * Declare the necessary data structures for calling Enum_FlagsToString
  * for an enum with 10 flags.
  */
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/make.c
--- a/usr.bin/make/make.c       Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/make.c       Tue Feb 02 17:56:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.238 2021/02/01 20:42:13 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.239 2021/02/02 17:56:31 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -103,7 +103,7 @@
 #include "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.238 2021/02/01 20:42:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.239 2021/02/02 17:56:31 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked_seqno = 1;
@@ -137,10 +137,6 @@
        abort();
 }
 
-ENUM_VALUE_RTTI_8(GNodeMade,
-    UNMADE, DEFERRED, REQUESTED, BEINGMADE,
-    MADE, UPTODATE, ERROR, ABORTED);
-
 ENUM_FLAGS_RTTI_31(GNodeType,
     OP_DEPENDS, OP_FORCE, OP_DOUBLEDEP,
 /* OP_OPMASK is omitted since it combines other flags */
@@ -164,9 +160,9 @@
        char type_buf[GNodeType_ToStringSize];
        char flags_buf[GNodeFlags_ToStringSize];
 
-       fprintf(f, "%smade %s, type %s, flags %s%s",
+       fprintf(f, "%s%s, type %s, flags %s%s",
            prefix,
-           GNodeMade_ToString(gn->made),
+           GNodeMade_Name(gn->made),
            GNodeType_ToString(type_buf, gn->type),
            GNodeFlags_ToString(flags_buf, gn->flags),
            suffix);
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/nonints.h    Tue Feb 02 17:56:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.189 2021/02/01 21:38:20 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.190 2021/02/02 17:56:31 rillig Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -278,6 +278,7 @@
 void Targ_PrintType(int);
 void Targ_PrintGraph(int);
 void Targ_Propagate(void);
+const char *GNodeMade_Name(GNodeMade);
 
 /* var.c */
 void Var_Init(void);
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/targ.c       Tue Feb 02 17:56:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: targ.c,v 1.160 2021/01/10 23:59:53 rillig Exp $        */
+/*     $NetBSD: targ.c,v 1.161 2021/02/02 17:56:31 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -113,7 +113,7 @@
 #include "dir.h"
 
 /*     "@(#)targ.c     8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: targ.c,v 1.160 2021/01/10 23:59:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.161 2021/02/02 17:56:31 rillig Exp $");
 
 /*
  * All target nodes that appeared on the left-hand side of one of the
@@ -450,8 +450,8 @@
        }
 }
 
-static const char *
-made_name(GNodeMade made)
+const char *
+GNodeMade_Name(GNodeMade made)
 {
        switch (made) {
        case UNMADE:    return "unmade";
@@ -505,10 +505,10 @@
                        if (gn->mtime != 0) {
                                debug_printf("# last modified %s: %s\n",
                                    Targ_FmtTime(gn->mtime),
-                                   made_name(gn->made));
+                                   GNodeMade_Name(gn->made));
                        } else if (gn->made != UNMADE) {
                                debug_printf("# nonexistent (maybe): %s\n",
-                                   made_name(gn->made));
+                                   GNodeMade_Name(gn->made));
                        } else
                                debug_printf("# unmade\n");
                }
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/unit-tests/gnode-submake.exp
--- a/usr.bin/make/unit-tests/gnode-submake.exp Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/unit-tests/gnode-submake.exp Tue Feb 02 17:56:31 2021 +0000
@@ -1,11 +1,11 @@
 #*** Input graph:
-# all, made UNMADE, type OP_DEPENDS, flags none
-# makeinfo, made UNMADE, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
-# make-index, made UNMADE, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# braces-dot, made UNMADE, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# braces-no-dot, made UNMADE, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# braces-no-dot-modifier, made UNMADE, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
-# parentheses-dot, made UNMADE, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# parentheses-no-dot, made UNMADE, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# all, unmade, type OP_DEPENDS, flags none
+# makeinfo, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
+# make-index, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# braces-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# braces-no-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# braces-no-dot-modifier, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
+# parentheses-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# parentheses-no-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
 
 exit status 0
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/unit-tests/opt-debug-graph1.exp
--- a/usr.bin/make/unit-tests/opt-debug-graph1.exp      Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-graph1.exp      Tue Feb 02 17:56:31 2021 +0000
@@ -1,12 +1,12 @@
 #*** Input graph:
-# all, made UNMADE, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
-# made-target, made UNMADE, type OP_DEPENDS, flags none
-# made-target-no-sources, made UNMADE, type OP_DEPENDS, flags none
-# made-source, made UNMADE, type OP_DEPENDS, flags none
-# unmade-target, made UNMADE, type OP_DEPENDS, flags none
-# unmade-sources, made UNMADE, type none, flags none
-# unmade-silent-source, made UNMADE, type OP_SILENT, flags none
-# unmade-target-no-sources, made UNMADE, type OP_DEPENDS, flags none
+# all, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
+# made-target, unmade, type OP_DEPENDS, flags none
+# made-target-no-sources, unmade, type OP_DEPENDS, flags none
+# made-source, unmade, type OP_DEPENDS, flags none
+# unmade-target, unmade, type OP_DEPENDS, flags none
+# unmade-sources, unmade, type none, flags none
+# unmade-silent-source, unmade, type OP_SILENT, flags none
+# unmade-target-no-sources, unmade, type OP_DEPENDS, flags none
 
 
 #
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/unit-tests/opt-debug-graph2.exp
--- a/usr.bin/make/unit-tests/opt-debug-graph2.exp      Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-graph2.exp      Tue Feb 02 17:56:31 2021 +0000
@@ -5,7 +5,7 @@
 *** Error code 1 (continuing)
 `all' not remade because of errors.
 #*** Input graph:
-# made-target, made MADE, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
+# made-target, made, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
 #
 # *** MAIN TARGET ***
 # No unmade children
@@ -15,7 +15,7 @@
        (null)
 
 
-# error-target, made ERROR, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
+# error-target, error when made, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
 #
 # No unmade children
 # nonexistent (maybe): error when made
@@ -24,8 +24,8 @@
        (null)
 
 
-# aborted-target, made ABORTED, type OP_DEPENDS|OP_PHONY|OP_DEPS_FOUND|OP_MARK, flags none
-# aborted-target-dependency, made ERROR, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
+# aborted-target, aborted, type OP_DEPENDS|OP_PHONY|OP_DEPS_FOUND|OP_MARK, flags none
+# aborted-target-dependency, error when made, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
 #
 # No unmade children
 # nonexistent (maybe): error when made
@@ -34,14 +34,14 @@
        (null)
 
 
-# all, made ABORTED, type OP_DEPENDS|OP_DEPS_FOUND, flags CHILDMADE|FORCE
+# all, aborted, type OP_DEPENDS|OP_DEPS_FOUND, flags CHILDMADE|FORCE
 #
 # 3 unmade children
 # nonexistent (maybe): aborted
 all             : made-target error-target aborted-target
 
 
-# .END, made UNMADE, type OP_SPECIAL, flags none
+# .END, unmade, type OP_SPECIAL, flags none
 
 
 #
diff -r 9c9d87762923 -r e1286e6cdc8b usr.bin/make/unit-tests/opt-debug-graph3.exp
--- a/usr.bin/make/unit-tests/opt-debug-graph3.exp      Tue Feb 02 17:47:56 2021 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-graph3.exp      Tue Feb 02 17:56:31 2021 +0000
@@ -5,7 +5,7 @@
 *** Error code 1 (continuing)
 `all' not remade because of errors.
 #*** Input graph:
-# made-target, made MADE, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
+# made-target, made, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
 #
 # *** MAIN TARGET ***
 # No unmade children
@@ -15,7 +15,7 @@
        (null)
 
 
-# error-target, made ERROR, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
+# error-target, error when made, type OP_DEPENDS|OP_PHONY|OP_HAS_COMMANDS|OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_ALLSRC
 #



Home | Main Index | Thread Index | Old Index