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): make Make_HandleUse simpler



details:   https://anonhg.NetBSD.org/src/rev/afdfe1a14c5b
branches:  trunk
changeset: 942928:afdfe1a14c5b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 22 13:06:39 2020 +0000

description:
make(1): make Make_HandleUse simpler

Since the function names now contain the text from the comments, the
comments can be shortened a bit.

diffstat:

 usr.bin/make/lst.c  |  51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 usr.bin/make/lst.h  |   5 ++++-
 usr.bin/make/make.c |  24 +++++++-----------------
 3 files changed, 57 insertions(+), 23 deletions(-)

diffs (171 lines):

diff -r 618b9cccefa2 -r afdfe1a14c5b usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 22 12:51:11 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 22 13:06:39 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.22 2020/08/22 13:06:39 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.22 2020/08/22 13:06:39 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.21 2020/08/22 09:40:18 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.22 2020/08/22 13:06:39 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -83,12 +83,14 @@
     return node != NULL;
 }
 
+/* Allocate and initialize a list node.
+ *
+ * The fields 'prev' and 'next' must be initialized by the caller.
+ */
 static LstNode
 LstNodeNew(void *datum)
 {
     LstNode node = bmake_malloc(sizeof *node);
-    /* prev will be initialized by the calling code. */
-    /* next will be initialized by the calling code. */
     node->useCount = 0;
     node->deleted = FALSE;
     node->datum = datum;
@@ -280,6 +282,28 @@
     return Lst_InsertAfter(list, end, datum);
 }
 
+/* Add a piece of data at the start of the given list. */
+void
+Lst_PrependS(Lst list, void *datum)
+{
+    LstNode node;
+
+    assert(LstIsValid(list));
+    assert(datum != NULL);
+
+    node = LstNodeNew(datum);
+    node->prev = NULL;
+    node->next = list->first;
+
+    if (list->first == NULL) {
+       list->first = node;
+       list->last = node;
+    } else {
+       list->first->prev = node;
+       list->first = node;
+    }
+}
+
 /* Add a piece of data at the end of the given list. */
 void
 Lst_AppendS(Lst list, void *datum)
@@ -640,6 +664,23 @@
     return SUCCESS;
 }
 
+/* Copy the element data from src to the start of dst. */
+void
+Lst_PrependAllS(Lst dst, Lst src)
+{
+    LstNode node;
+    for (node = src->last; node != NULL; node = node->prev)
+        Lst_PrependS(dst, node->datum);
+}
+
+/* Copy the element data from src to the end of dst. */
+void
+Lst_AppendAllS(Lst dst, Lst src)
+{
+    LstNode node;
+    for (node = src->first; node != NULL; node = node->next)
+        Lst_AppendS(dst, node->datum);
+}
 
 /*
  * these functions are for dealing with a list as a table, of sorts.
diff -r 618b9cccefa2 -r afdfe1a14c5b usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 22 12:51:11 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 22 13:06:39 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.28 2020/08/22 09:40:18 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.29 2020/08/22 13:06:39 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -119,6 +119,7 @@
 ReturnStatus   Lst_InsertAfter(Lst, LstNode, void *);
 /* Place an element at the front of a lst. */
 ReturnStatus   Lst_AtFront(Lst, void *);
+void           Lst_PrependS(Lst, void *);
 /* Place an element at the end of a lst. */
 ReturnStatus   Lst_AtEnd(Lst, void *);
 void           Lst_AppendS(Lst, void *);
@@ -128,6 +129,8 @@
 void           Lst_ReplaceS(LstNode, void *);
 /* Concatenate two lists */
 ReturnStatus   Lst_Concat(Lst, Lst, int);
+void           Lst_PrependAllS(Lst, Lst);
+void           Lst_AppendAllS(Lst, Lst);
 
 /*
  * Node-specific functions
diff -r 618b9cccefa2 -r afdfe1a14c5b usr.bin/make/make.c
--- a/usr.bin/make/make.c       Sat Aug 22 12:51:11 2020 +0000
+++ b/usr.bin/make/make.c       Sat Aug 22 13:06:39 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.111 2020/08/22 11:57:18 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.112 2020/08/22 13:06:39 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.111 2020/08/22 11:57:18 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.112 2020/08/22 13:06:39 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c     8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.111 2020/08/22 11:57:18 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.112 2020/08/22 13:06:39 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -439,21 +439,11 @@
 
     if ((cgn->type & (OP_USE|OP_USEBEFORE)) || Lst_IsEmpty(pgn->commands)) {
            if (cgn->type & OP_USEBEFORE) {
-               /*
-                * .USEBEFORE --
-                *      prepend the child's commands to the parent.
-                */
-               LstNode node;
-               for (node = Lst_Last(cgn->commands);
-                    node != NULL;
-                    node = Lst_Prev(node))
-                   Lst_AtFront(pgn->commands, Lst_Datum(node));
+               /* .USEBEFORE */
+               Lst_PrependAllS(pgn->commands, cgn->commands);
            } else {
-               /*
-                * .USE or target has no commands --
-                *      append the child's commands to the parent.
-                */
-               (void)Lst_Concat(pgn->commands, cgn->commands, LST_CONCNEW);
+               /* .USE, or target has no commands */
+               Lst_AppendAllS(pgn->commands, cgn->commands);
            }
     }
 



Home | Main Index | Thread Index | Old Index