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: clean up comments, variable names, functi...



details:   https://anonhg.NetBSD.org/src/rev/4df547abd66e
branches:  trunk
changeset: 359491:4df547abd66e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 07 20:37:25 2022 +0000

description:
make: clean up comments, variable names, function names

The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

No binary change, except for assertion line numbers.

diffstat:

 usr.bin/make/main.c  |  40 +++++++++++-----------
 usr.bin/make/parse.c |  90 +++++++++++++++++++--------------------------------
 usr.bin/make/targ.c  |  14 ++-----
 usr.bin/make/var.c   |  12 +++---
 4 files changed, 65 insertions(+), 91 deletions(-)

diffs (truncated from 415 to 300 lines):

diff -r b7fe635c587d -r 4df547abd66e usr.bin/make/main.c
--- a/usr.bin/make/main.c       Fri Jan 07 20:15:10 2022 +0000
+++ b/usr.bin/make/main.c       Fri Jan 07 20:37:25 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.565 2022/01/01 21:41:50 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.566 2022/01/07 20:37:25 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.565 2022/01/01 21:41:50 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.566 2022/01/07 20:37:25 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -1799,22 +1799,22 @@
 Error(const char *fmt, ...)
 {
        va_list ap;
-       FILE *err_file;
+       FILE *f;
 
-       err_file = opts.debug_file;
-       if (err_file == stdout)
-               err_file = stderr;
+       f = opts.debug_file;
+       if (f == stdout)
+               f = stderr;
        (void)fflush(stdout);
        for (;;) {
                va_start(ap, fmt);
-               fprintf(err_file, "%s: ", progname);
-               (void)vfprintf(err_file, fmt, ap);
+               fprintf(f, "%s: ", progname);
+               (void)vfprintf(f, fmt, ap);
                va_end(ap);
-               (void)fprintf(err_file, "\n");
-               (void)fflush(err_file);
-               if (err_file == stderr)
+               (void)fprintf(f, "\n");
+               (void)fflush(f);
+               if (f == stderr)
                        break;
-               err_file = stderr;
+               f = stderr;
        }
        main_errors++;
 }
@@ -2093,21 +2093,21 @@
 Main_ExportMAKEFLAGS(bool first)
 {
        static bool once = true;
-       const char *expr;
-       char *s;
+       char *flags;
 
        if (once != first)
                return;
        once = false;
 
-       expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}";
-       (void)Var_Subst(expr, SCOPE_CMDLINE, VARE_WANTRES, &s);
+       (void)Var_Subst(
+           "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
+           SCOPE_CMDLINE, VARE_WANTRES, &flags);
        /* TODO: handle errors */
-       if (s[0] != '\0') {
+       if (flags[0] != '\0') {
 #ifdef POSIX
-               setenv("MAKEFLAGS", s, 1);
+               setenv("MAKEFLAGS", flags, 1);
 #else
-               setenv("MAKE", s, 1);
+               setenv("MAKE", flags, 1);
 #endif
        }
 }
@@ -2121,7 +2121,7 @@
        if (tmpdir != NULL)
                return tmpdir;
 
-       /* Honor $TMPDIR but only if it is valid. Ensure it ends with '/'. */
+       /* Honor $TMPDIR if it is valid, strip a trailing '/'. */
        (void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP ":S,/$,,W}/",
            SCOPE_GLOBAL, VARE_WANTRES, &tmpdir);
        /* TODO: handle errors */
diff -r b7fe635c587d -r 4df547abd66e usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Fri Jan 07 20:15:10 2022 +0000
+++ b/usr.bin/make/parse.c      Fri Jan 07 20:37:25 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.629 2022/01/07 20:09:58 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.630 2022/01/07 20:37:25 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -106,7 +106,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.629 2022/01/07 20:09:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.630 2022/01/07 20:37:25 rillig Exp $");
 
 /*
  * A file being read.
@@ -334,7 +334,7 @@
        if (!Buf_EndsWith(&buf, '\n'))
                Buf_AddByte(&buf, '\n');
 
-       return buf;
+       return buf;             /* may not be null-terminated */
 }
 
 static void
@@ -568,11 +568,9 @@
 }
 
 /*
- * Add the child to the parent's children.
- *
- * Additionally, add the parent to the child's parents, but only if the
- * target is not special.  An example for such a special target is .END,
- * which does not need to be informed once the child target has been made.
+ * Add the child to the parent's children, and for non-special targets, vice
+ * versa.  Special targets such as .END do not need to be informed once the
+ * child target has been made.
  */
 static void
 LinkSource(GNode *pgn, GNode *cgn, bool isSpecial)
@@ -728,17 +726,17 @@
        return false;
 }
 
+/*
+ * In a line like ".MAIN: source1 source2", add all sources to the list of
+ * things to create, but only if the user didn't specify a target on the
+ * command line and .MAIN occurs for the first time.
+ *
+ * See HandleDependencyTargetSpecial, branch SP_MAIN.
+ * See unit-tests/cond-func-make-main.mk.
+ */
 static void
 ApplyDependencySourceMain(const char *src)
 {
-       /*
-        * In a line like ".MAIN: source1 source2", add all sources to the
-        * list of things to create, but only if the user didn't specify a
-        * target on the command line and .MAIN occurs for the first time.
-        *
-        * See HandleDependencyTargetSpecial, branch SP_MAIN.
-        * See unit-tests/cond-func-make-main.mk.
-        */
        Lst_Append(&opts.create, bmake_strdup(src));
        /*
         * Add the name to the .TARGETS variable as well, so the user can
@@ -775,24 +773,13 @@
        order_pred = gn;
 }
 
+/* The source is not an attribute, so find/create a node for it. */
 static void
 ApplyDependencySourceOther(const char *src, GNodeType targetAttr,
                           ParseSpecial special)
 {
        GNode *gn;
 
-       /*
-        * The source is not an attribute, so find/create a node for it.
-        * After that, apply any operator to it from a special target or
-        * link it to its parents, as appropriate.
-        *
-        * In the case of a source that was the object of a '::' operator,
-        * the attribute is applied to all of its instances (as kept in
-        * the 'cohorts' list of the node) or all the cohorts are linked
-        * to all the targets.
-        */
-
-       /* Find/create the 'src' node and attach to all targets */
        gn = Targ_GetNode(src);
        if (doing_depend)
                RememberLocation(gn);
@@ -830,7 +817,7 @@
  * actually a real target (i.e. isn't a .USE or .EXEC rule) to be made.
  */
 static void
-FindMainTarget(void)
+MaybeUpdateMainTarget(void)
 {
        GNodeListNode *ln;
 
@@ -849,15 +836,15 @@
 }
 
 static void
-InvalidLineType(const char *lstart)
+InvalidLineType(const char *line)
 {
-       if ((strncmp(lstart, "<<<<<<", 6) == 0) ||
-           (strncmp(lstart, "======", 6) == 0) ||
-           (strncmp(lstart, ">>>>>>", 6) == 0))
+       if (strncmp(line, "<<<<<<", 6) == 0 ||
+           strncmp(line, "======", 6) == 0 ||
+           strncmp(line, ">>>>>>", 6) == 0)
                Parse_Error(PARSE_FATAL,
                    "Makefile appears to contain unresolved CVS/RCS/??? merge conflicts");
-       else if (lstart[0] == '.') {
-               const char *dirstart = lstart + 1;
+       else if (line[0] == '.') {
+               const char *dirstart = line + 1;
                const char *dirend;
                cpp_skip_whitespace(&dirstart);
                dirend = dirstart;
@@ -1106,7 +1093,7 @@
        if (**pp == '!')
                return (*pp)++, OP_FORCE;
        if ((*pp)[1] == ':')
-               return (*pp) += 2, OP_DOUBLEDEP;
+               return *pp += 2, OP_DOUBLEDEP;
        else
                return (*pp)++, OP_DEPENDS;
 }
@@ -1123,17 +1110,9 @@
        Dir_SetPATH();
 }
 
-/*
- * Several special targets take different actions if present with no
- * sources:
- *     a .SUFFIXES line with no sources clears out all old suffixes
- *     a .PRECIOUS line makes all targets precious
- *     a .IGNORE line ignores errors for all targets
- *     a .SILENT line creates silence when making all targets
- *     a .PATH removes all directories from the search path(s).
- */
+/* Handle a "dependency" line like '.SPECIAL:' without any sources. */
 static void
-ParseDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths)
+HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths)
 {
        switch (special) {
        case SP_SUFFIXES:
@@ -1364,7 +1343,7 @@
                       ParseSpecial special, SearchPathList **inout_paths)
 {
        if (*p == '\0') {
-               ParseDependencySourcesEmpty(special, *inout_paths);
+               HandleDependencySourcesEmpty(special, *inout_paths);
        } else if (special == SP_MFLAGS) {
                Main_ParseArgLine(p);
                return;
@@ -1397,7 +1376,7 @@
                        return;
        }
 
-       FindMainTarget();
+       MaybeUpdateMainTarget();
 }
 
 /*
@@ -1621,6 +1600,7 @@
        }
 }
 
+/* Perform a variable assignment that uses the operator ':='. */
 static void
 VarAssign_EvalSubst(GNode *scope, const char *name, const char *uvalue,
                    FStr *out_avalue)
@@ -1633,6 +1613,7 @@
         *
         * TODO: Add a test that demonstrates why this code is needed,
         *  apart from making the debug log longer.
+        * XXX: The variable name is expanded up to 3 times.
         */
        if (!Var_ExistsExpand(scope, name))
                Var_SetExpand(scope, name, "");
@@ -1645,6 +1626,7 @@
        *out_avalue = FStr_InitOwn(evalue);
 }
 
+/* Perform a variable assignment that uses the operator '!='. */
 static void
 VarAssign_EvalShell(const char *name, const char *uvalue, GNode *scope,
                    FStr *out_avalue)
@@ -1696,6 +1678,7 @@
        else if (op == VAR_SHELL)
                VarAssign_EvalShell(name, uvalue, scope, &avalue);
        else {
+               /* XXX: The variable name is expanded up to 2 times. */
                if (op == VAR_DEFAULT && Var_ExistsExpand(scope, name))
                        return false;
 
@@ -2113,11 +2096,7 @@
 }
 
 
-/*
- * Start parsing from the given source.
- *



Home | Main Index | Thread Index | Old Index