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 targ.c



details:   https://anonhg.NetBSD.org/src/rev/e07a308a4e61
branches:  trunk
changeset: 1013468:e07a308a4e61
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 28 19:14:07 2020 +0000

description:
make(1): clean up targ.c

The main part is removing redundant or outdated information from
comments.  In a few places, the expression cond ? TRUE : FALSE has been
simplified.

diffstat:

 usr.bin/make/make.h |    6 +-
 usr.bin/make/targ.c |  325 ++++++++-------------------------------------------
 2 files changed, 56 insertions(+), 275 deletions(-)

diffs (truncated from 566 to 300 lines):

diff -r ffd384fb1098 -r e07a308a4e61 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Fri Aug 28 19:02:19 2020 +0000
+++ b/usr.bin/make/make.h       Fri Aug 28 19:14:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.128 2020/08/28 03:35:45 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.129 2020/08/28 19:14:07 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -326,8 +326,8 @@
     char cohort_num[8];
     /* The number of unmade instances on the cohorts list */
     int unmade_cohorts;
-    /* Pointer to the first instance of a :: node; only set when on a cohorts
-     * list */
+    /* Pointer to the first instance of a '::' node; only set when on a
+     * cohorts list */
     struct GNode *centurion;
 
     /* Last time (sequence number) we tried to make this node */
diff -r ffd384fb1098 -r e07a308a4e61 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c       Fri Aug 28 19:02:19 2020 +0000
+++ b/usr.bin/make/targ.c       Fri Aug 28 19:14:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: targ.c,v 1.76 2020/08/28 04:48:57 rillig Exp $ */
+/*     $NetBSD: targ.c,v 1.77 2020/08/28 19:14:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: targ.c,v 1.76 2020/08/28 04:48:57 rillig Exp $";
+static char rcsid[] = "$NetBSD: targ.c,v 1.77 2020/08/28 19:14:07 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)targ.c     8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: targ.c,v 1.76 2020/08/28 04:48:57 rillig Exp $");
+__RCSID("$NetBSD: targ.c,v 1.77 2020/08/28 19:14:07 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -84,8 +84,7 @@
 /*-
  * targ.c --
  *     Functions for maintaining the Lst allTargets. Target nodes are
- * kept in two structures: a Lst, maintained by the list library, and a
- * hash table, maintained by the hash library.
+ *     kept in two structures: a Lst and a hash table.
  *
  * Interface:
  *     Targ_Init               Initialization procedure.
@@ -133,7 +132,6 @@
 #include         <time.h>
 
 #include         "make.h"
-#include         "hash.h"
 #include         "dir.h"
 
 static Lst        allTargets;  /* the list of all targets found so far */
@@ -152,18 +150,6 @@
 static int TargPropagateCohort(void *, void *);
 static int TargPropagateNode(void *, void *);
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_Init --
- *     Initialize this module
- *
- * Results:
- *     None
- *
- * Side Effects:
- *     The allTargets list and the targets hash table are initialized
- *-----------------------------------------------------------------------
- */
 void
 Targ_Init(void)
 {
@@ -171,18 +157,6 @@
     Hash_InitTable(&targets, HTSIZE);
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_End --
- *     Finalize this module
- *
- * Results:
- *     None
- *
- * Side Effects:
- *     All lists and gnodes are cleared
- *-----------------------------------------------------------------------
- */
 void
 Targ_End(void)
 {
@@ -201,39 +175,18 @@
     Hash_DebugStats(&targets, "targets");
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_List --
- *     Return the list of all targets
- *
- * Results:
- *     The list of all targets.
- *
- * Side Effects:
- *     None
- *-----------------------------------------------------------------------
- */
+/* Return the list of all targets. */
 Lst
 Targ_List(void)
 {
     return allTargets;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_NewGN  --
- *     Create and initialize a new graph node
+/* Create and initialize a new graph node. The gnode is added to the list of
+ * all gnodes.
  *
  * Input:
- *     name            the name to stick in the new node
- *
- * Results:
- *     An initialized graph node with the name field filled with a copy
- *     of the passed name
- *
- * Side Effects:
- *     The gnode is added to the list of all gnodes.
- *-----------------------------------------------------------------------
+ *     name            the name of the node, such as "clean", "src.c"
  */
 GNode *
 Targ_NewGN(const char *name)
@@ -244,11 +197,7 @@
     gn->name = bmake_strdup(name);
     gn->uname = NULL;
     gn->path = NULL;
-    if (name[0] == '-' && name[1] == 'l') {
-       gn->type = OP_LIB;
-    } else {
-       gn->type = 0;
-    }
+    gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
     gn->unmade =       0;
     gn->unmade_cohorts = 0;
     gn->cohort_num[0] = 0;
@@ -267,8 +216,8 @@
     Hash_InitTable(&gn->context, 0);
     gn->commands =     Lst_Init();
     gn->suffix =       NULL;
+    gn->fname =        NULL;
     gn->lineno =       0;
-    gn->fname =        NULL;
 
 #ifdef CLEANUP
     if (allGNs == NULL)
@@ -280,28 +229,14 @@
 }
 
 #ifdef CLEANUP
-/*-
- *-----------------------------------------------------------------------
- * TargFreeGN  --
- *     Destroy a GNode
- *
- * Results:
- *     None.
- *
- * Side Effects:
- *     None.
- *-----------------------------------------------------------------------
- */
 static void
 TargFreeGN(void *gnp)
 {
     GNode *gn = (GNode *)gnp;
 
-
     free(gn->name);
     free(gn->uname);
     free(gn->path);
-    /* gn->fname points to name allocated when file was opened, don't free */
 
     Lst_Free(gn->iParents);
     Lst_Free(gn->cohorts);
@@ -311,29 +246,26 @@
     Lst_Free(gn->order_pred);
     Hash_DeleteTable(&gn->context);
     Lst_Free(gn->commands);
+
+    /* XXX: does gn->suffix need to be freed? It is reference-counted. */
+    /* gn->fname points to name allocated when file was opened, don't free */
+
     free(gn);
 }
 #endif
 
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_FindNode  --
- *     Find a node in the list using the given name for matching
+/* Find a node in the list using the given name for matching.
+ * If the node is created, it is added to the .ALLTARGETS list.
  *
  * Input:
  *     name            the name to find
- *     flags           flags governing events when target not
- *                     found
+ *     flags           flags governing events when target not found
  *
  * Results:
- *     The node in the list if it was. If it wasn't, return NULL of
+ *     The node in the list if it was. If it wasn't, return NULL if
  *     flags was TARG_NOCREATE or the newly created and initialized node
  *     if it was TARG_CREATE
- *
- * Side Effects:
- *     Sometimes a node is created and added to the list
- *-----------------------------------------------------------------------
  */
 GNode *
 Targ_FindNode(const char *name, int flags)
@@ -366,10 +298,10 @@
     return gn;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_FindList --
- *     Make a complete list of GNodes from the given list of names
+/* Make a complete list of GNodes from the given list of names.
+ * If flags is TARG_CREATE, nodes will be created for all names in
+ * names which do not yet have graph nodes. If flags is TARG_NOCREATE,
+ * an error message will be printed for each name which can't be found.
  *
  * Input:
  *     name            list of names to find
@@ -378,12 +310,6 @@
  * Results:
  *     A complete list of graph nodes corresponding to all instances of all
  *     the names in names.
- *
- * Side Effects:
- *     If flags is TARG_CREATE, nodes will be created for all names in
- *     names which do not yet have graph nodes. If flags is TARG_NOCREATE,
- *     an error message will be printed for each name which can't be found.
- * -----------------------------------------------------------------------
  */
 Lst
 Targ_FindList(Lst names, int flags)
@@ -414,100 +340,33 @@
     return nodes;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_Ignore  --
- *     Return true if should ignore errors when creating gn
- *
- * Input:
- *     gn              node to check for
- *
- * Results:
- *     TRUE if should ignore errors
- *
- * Side Effects:
- *     None
- *-----------------------------------------------------------------------
- */
+/* Return true if should ignore errors when creating gn. */
 Boolean
 Targ_Ignore(GNode *gn)
 {
-    if (ignoreErrors || gn->type & OP_IGNORE) {
-       return TRUE;
-    } else {
-       return FALSE;
-    }
+    return ignoreErrors || gn->type & OP_IGNORE;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Targ_Silent  --
- *     Return true if be silent when creating gn
- *



Home | Main Index | Thread Index | Old Index