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): reduce boilerplate for printing bit se...



details:   https://anonhg.NetBSD.org/src/rev/4d22fab42da7
branches:  trunk
changeset: 980267:4d22fab42da7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 30 15:48:42 2021 +0000

description:
make(1): reduce boilerplate for printing bit sets in debug mode

No functional change.

diffstat:

 usr.bin/make/enum.h |  15 ++++++++++++---
 usr.bin/make/make.c |  12 +++++-------
 usr.bin/make/suff.c |   8 +++-----
 usr.bin/make/var.c  |  27 +++++++++------------------
 4 files changed, 29 insertions(+), 33 deletions(-)

diffs (157 lines):

diff -r 4b7311cfa11d -r 4d22fab42da7 usr.bin/make/enum.h
--- a/usr.bin/make/enum.h       Sat Jan 30 13:50:18 2021 +0000
+++ b/usr.bin/make/enum.h       Sat Jan 30 15:48:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: enum.h,v 1.14 2020/12/30 10:03:16 rillig Exp $ */
+/*     $NetBSD: enum.h,v 1.15 2021/01/30 15:48:42 rillig Exp $ */
 
 /*
  Copyright (c) 2020 Roland Illig <rillig%NetBSD.org@localhost>
@@ -102,12 +102,21 @@
 
 /* Declare the necessary data structures for calling Enum_ValueToString. */
 #define ENUM__VALUE_RTTI(typnam, specs) \
-       static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = 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) \
        static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \
-       enum { typnam ## _ ## ToStringSize = sizeof joined }
+       enum { typnam ## _ ## ToStringSize = sizeof (joined) }; \
+       MAKE_INLINE const char *typnam ## _ToString(char *buf, typnam value) \
+       { return Enum_FlagsToString(buf, typnam ## _ ## ToStringSize, \
+           value, typnam ## _ ## ToStringSpecs); \
+       }; \
+       extern void enum_flags_rtti_dummy(void)
 
 /*
  * Declare the necessary data structures for calling Enum_FlagsToString
diff -r 4b7311cfa11d -r 4d22fab42da7 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Jan 30 13:50:18 2021 +0000
+++ b/usr.bin/make/make.c       Sat Jan 30 15:48:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.235 2021/01/16 20:49:31 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.236 2021/01/30 15:48:42 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.235 2021/01/16 20:49:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.236 2021/01/30 15:48:42 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked_seqno = 1;
@@ -166,11 +166,9 @@
 
        fprintf(f, "%smade %s, type %s, flags %s%s",
            prefix,
-           Enum_ValueToString(gn->made, GNodeMade_ToStringSpecs),
-           Enum_FlagsToString(type_buf, sizeof type_buf,
-               gn->type, GNodeType_ToStringSpecs),
-           Enum_FlagsToString(flags_buf, sizeof flags_buf,
-               gn->flags, GNodeFlags_ToStringSpecs),
+           GNodeMade_ToString(gn->made),
+           GNodeType_ToString(type_buf, gn->type),
+           GNodeFlags_ToString(flags_buf, gn->flags),
            suffix);
 }
 
diff -r 4b7311cfa11d -r 4d22fab42da7 usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Jan 30 13:50:18 2021 +0000
+++ b/usr.bin/make/suff.c       Sat Jan 30 15:48:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.340 2021/01/24 20:11:55 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.341 2021/01/30 15:48:42 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -114,7 +114,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.340 2021/01/24 20:11:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.341 2021/01/30 15:48:42 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -2137,9 +2137,7 @@
                char flags_buf[SuffixFlags_ToStringSize];
 
                debug_printf(" (%s)",
-                   Enum_FlagsToString(flags_buf, sizeof flags_buf,
-                       suff->flags,
-                       SuffixFlags_ToStringSpecs));
+                   SuffixFlags_ToString(flags_buf, suff->flags));
        }
        debug_printf("\n");
 
diff -r 4b7311cfa11d -r 4d22fab42da7 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Jan 30 13:50:18 2021 +0000
+++ b/usr.bin/make/var.c        Sat Jan 30 15:48:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.782 2021/01/16 20:49:31 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.783 2021/01/30 15:48:42 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.782 2021/01/16 20:49:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.783 2021/01/30 15:48:42 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -3402,13 +3402,9 @@
         * be used since the end of the modifier is not yet known. */
        debug_printf("Applying ${%s:%c%s} to \"%s\" (%s, %s, %s)\n",
            st->var->name.str, mod[0], is_single_char ? "" : "...", val,
-           Enum_FlagsToString(eflags_str, sizeof eflags_str,
-               st->eflags, VarEvalFlags_ToStringSpecs),
-           Enum_FlagsToString(vflags_str, sizeof vflags_str,
-               st->var->flags, VarFlags_ToStringSpecs),
-           Enum_FlagsToString(exprflags_str, sizeof exprflags_str,
-               st->exprFlags,
-               VarExprFlags_ToStringSpecs));
+           VarEvalFlags_ToString(eflags_str, st->eflags),
+           VarFlags_ToString(vflags_str, st->var->flags),
+           VarExprFlags_ToString(exprflags_str, st->exprFlags));
 }
 
 static void
@@ -3423,13 +3419,9 @@
 
        debug_printf("Result of ${%s:%.*s} is %s%s%s (%s, %s, %s)\n",
            st->var->name.str, (int)(p - mod), mod, quot, newVal, quot,
-           Enum_FlagsToString(eflags_str, sizeof eflags_str,
-               st->eflags, VarEvalFlags_ToStringSpecs),
-           Enum_FlagsToString(vflags_str, sizeof vflags_str,
-               st->var->flags, VarFlags_ToStringSpecs),
-           Enum_FlagsToString(exprflags_str, sizeof exprflags_str,
-               st->exprFlags,
-               VarExprFlags_ToStringSpecs));
+           VarEvalFlags_ToString(eflags_str, st->eflags),
+           VarFlags_ToString(vflags_str, st->var->flags),
+           VarExprFlags_ToString(exprflags_str, st->exprFlags));
 }
 
 static ApplyModifierResult
@@ -4151,8 +4143,7 @@
        VarExprFlags exprFlags = VEF_NONE;
 
        DEBUG2(VAR, "Var_Parse: %s with %s\n", start,
-           Enum_FlagsToString(eflags_str, sizeof eflags_str, eflags,
-               VarEvalFlags_ToStringSpecs));
+           VarEvalFlags_ToString(eflags_str, eflags));
 
        *out_val = FStr_InitRefer(NULL);
        extramodifiers = NULL;  /* extra modifiers to apply first */



Home | Main Index | Thread Index | Old Index