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: make Targ_PrintType simpler



details:   https://anonhg.NetBSD.org/src/rev/9cfcbf9fa206
branches:  trunk
changeset: 985883:9cfcbf9fa206
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 12 07:50:45 2021 +0000

description:
make: make Targ_PrintType simpler

No functional change.

diffstat:

 usr.bin/make/targ.c |  58 ++++++++++++++++++++++++++--------------------------
 1 files changed, 29 insertions(+), 29 deletions(-)

diffs (80 lines):

diff -r 8f1e32d71172 -r 9cfcbf9fa206 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Sun Sep 12 07:14:50 2021 +0000
+++ b/usr.bin/make/targ.c       Sun Sep 12 07:50:45 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: targ.c,v 1.168 2021/04/03 12:01:00 rillig Exp $        */
+/*     $NetBSD: targ.c,v 1.169 2021/09/12 07:50:45 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.168 2021/04/03 12:01:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.169 2021/09/12 07:50:45 rillig Exp $");
 
 /*
  * All target nodes that appeared on the left-hand side of one of the
@@ -418,34 +418,34 @@
 void
 Targ_PrintType(int type)
 {
-       int tbit;
-
-       type &= ~OP_OPMASK;
-
-       while (type != 0) {
-               tbit = 1 << (ffs(type) - 1);
-               type &= ~tbit;
+       static const struct {
+               GNodeType bit;
+               bool internal;
+               const char *name;
+       } names[] = {
+               { OP_MEMBER,    true,   "MEMBER"        },
+               { OP_LIB,       true,   "LIB"           },
+               { OP_ARCHV,     true,   "ARCHV"         },
+               { OP_PHONY,     true,   "PHONY"         },
+               { OP_NOTMAIN,   false,  "NOTMAIN"       },
+               { OP_INVISIBLE, false,  "INVISIBLE"     },
+               { OP_MADE,      true,   "MADE"          },
+               { OP_JOIN,      false,  "JOIN"          },
+               { OP_MAKE,      false,  "MAKE"          },
+               { OP_SILENT,    false,  "SILENT"        },
+               { OP_PRECIOUS,  false,  "PRECIOUS"      },
+               { OP_IGNORE,    false,  "IGNORE"        },
+               { OP_EXEC,      false,  "EXEC"          },
+               { OP_USE,       false,  "USE"           },
+               { OP_OPTIONAL,  false,  "OPTIONAL"      },
+       };
 
-               switch (tbit) {
-#define PRINTBIT(bit, attr) case bit: debug_printf(" " attr); break
-#define PRINTDBIT(bit, attr) case bit: DEBUG0(TARG, " " attr); break
-               PRINTBIT(OP_OPTIONAL, ".OPTIONAL");
-               PRINTBIT(OP_USE, ".USE");
-               PRINTBIT(OP_EXEC, ".EXEC");
-               PRINTBIT(OP_IGNORE, ".IGNORE");
-               PRINTBIT(OP_PRECIOUS, ".PRECIOUS");
-               PRINTBIT(OP_SILENT, ".SILENT");
-               PRINTBIT(OP_MAKE, ".MAKE");
-               PRINTBIT(OP_JOIN, ".JOIN");
-               PRINTBIT(OP_INVISIBLE, ".INVISIBLE");
-               PRINTBIT(OP_NOTMAIN, ".NOTMAIN");
-               PRINTDBIT(OP_LIB, ".LIB");
-               PRINTDBIT(OP_MEMBER, ".MEMBER");
-               PRINTDBIT(OP_ARCHV, ".ARCHV");
-               PRINTDBIT(OP_MADE, ".MADE");
-               PRINTDBIT(OP_PHONY, ".PHONY");
-#undef PRINTBIT
-#undef PRINTDBIT
+       for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
+               if (type & names[i].bit) {
+                       if (names[i].internal)
+                               DEBUG1(TARG, " .%s", names[i].name);
+                       else
+                               debug_printf(" .%s", names[i].name);
                }
        }
 }



Home | Main Index | Thread Index | Old Index