Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[.joined/src/trunk]: .joined/src/usr.bin/make make: clean up parsing of makef...



details:   https://anonhg.NetBSD.org/.joined/src/rev/091648af517b
branches:  trunk
changeset: 359397:091648af517b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 02 02:39:55 2022 +0000

description:
make: clean up parsing of makefiles

Remove redundant comments.

Rename IFile.first_lineno to forBodyLineno since it only contains a
useful value in .for loops but not in .include files.  Also clarify that
this line number is the start of the loop body, since in PrintStackTrace
this line is used as a human-readable line number.  For a .for loop in
which the loop head spans multiple lines, this line number is wrong
anyway.

No functional change.

diffstat:

 usr.bin/make/parse.c |  77 ++++++++++++++++++---------------------------------
 1 files changed, 27 insertions(+), 50 deletions(-)

diffs (176 lines):

diff -r 175a8a742563 -r 091648af517b usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Jan 02 02:16:12 2022 +0000
+++ b/usr.bin/make/parse.c      Sun Jan 02 02:39:55 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.617 2022/01/02 02:16:12 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.618 2022/01/02 02:39:55 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -74,10 +74,6 @@
  * Parse_File is the main entry point and controls most of the other
  * functions in this module.
  *
- * The directories for the .include "..." directive are kept in
- * 'parseIncPath', while those for .include <...> are kept in 'sysIncPath'.
- * The targets currently being defined are kept in 'targets'.
- *
  * Interface:
  *     Parse_Init      Initialize the module
  *
@@ -110,9 +106,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.617 2022/01/02 02:16:12 rillig Exp $");
-
-/* types and constants */
+MAKE_RCSID("$NetBSD: parse.c,v 1.618 2022/01/02 02:39:55 rillig Exp $");
 
 /*
  * Structure for a file being read ("included file")
@@ -120,15 +114,12 @@
 typedef struct IFile {
        FStr name;              /* absolute or relative to the cwd */
        int lineno;             /* current line number in file */
-       int first_lineno;       /* line number of start of text */
+       int forBodyLineno;      /* start of the .for loop body, 0-based */
        unsigned int cond_depth; /* 'if' nesting when file opened */
-       bool depending; /* state of doing_depend on EOF */
-
-       /*
-        * The buffer from which the file's content or the body of the .for
-        * loop is read.  The buffer always ends with '\n'.
-        */
-       Buffer buf;
+       bool depending;         /* state of doing_depend on EOF */
+
+       Buffer buf;             /* the file's content or the body of the .for
+                                * loop; always ends with '\n' */
        char *buf_ptr;          /* next char to be read */
        char *buf_end;          /* buf_end[-1] == '\n' */
 
@@ -178,16 +169,12 @@
 typedef List SearchPathList;
 typedef ListNode SearchPathListNode;
 
-/* result data */
-
 /*
  * The main target to create. This is the first target defined in any of the
  * makefiles.
  */
 static GNode *mainNode;
 
-/* eval state */
-
 /*
  * During parsing, the targets from the left-hand side of the currently
  * active dependency line, or NULL if the current line does not belong to a
@@ -213,16 +200,10 @@
  */
 static GNode *order_pred;
 
-/* parser state */
-
 /* number of fatal errors */
 static int parseErrors = 0;
 
 /*
- * Variables for doing includes
- */
-
-/*
  * The include chain of makefiles.  At index 0 is the top-level makefile from
  * the command line, followed by the included files or .for loops, up to and
  * including the current file.
@@ -231,26 +212,10 @@
  */
 static Vector /* of IFile */ includes;
 
-static IFile *
-GetInclude(size_t i)
-{
-       return Vector_Get(&includes, i);
-}
-
-/* The file that is currently being read. */
-static IFile *
-CurFile(void)
-{
-       return GetInclude(includes.len - 1);
-}
-
-/* include paths */
 SearchPath *parseIncPath;      /* directories for "..." includes */
 SearchPath *sysIncPath;                /* directories for <...> includes */
 SearchPath *defSysIncPath;     /* default for sysIncPath */
 
-/* parser tables */
-
 /*
  * The parseKeywords table is searched using binary search when deciding
  * if a target or source is special. The 'spec' field is the ParseSpecial
@@ -310,6 +275,19 @@
 };
 
 
+static IFile *
+GetInclude(size_t i)
+{
+       return Vector_Get(&includes, i);
+}
+
+/* The file that is currently being read. */
+static IFile *
+CurFile(void)
+{
+       return GetInclude(includes.len - 1);
+}
+
 static Buffer
 loadfile(const char *path, int fd)
 {
@@ -367,11 +345,10 @@
        n--;                    /* This entry is already in the diagnostic. */
 
        /*
-        * For the IFiles with fromForLoop, lineno seems to be sorted
-        * backwards.  This is because lineno is the number of completely
-        * parsed lines, which for a .for loop is right after the
-        * corresponding .endfor.  The intuitive line number comes from
-        * first_lineno instead, which points at the start of the .for loop.
+        * For the IFiles with forLoop, lineno is the number of completely
+        * parsed lines, which is right after the corresponding .endfor.  The
+        * intuitive line number comes from first_lineno instead, which
+        * points at the start of the .for loop.
         *
         * To make the stack trace intuitive, the entry below each chain of
         * .for loop entries must be ignored completely since neither its
@@ -393,7 +370,7 @@
                            fname, entry->lineno);
                if (entry->forLoop != NULL)
                        debug_printf("\tin .for loop from %s:%d\n",
-                           fname, entry->first_lineno);
+                           fname, entry->forBodyLineno - 1 + 1);
        }
 }
 
@@ -2173,7 +2150,7 @@
        curFile = Vector_Push(&includes);
        curFile->name = FStr_InitOwn(bmake_strdup(name));
        curFile->lineno = lineno;
-       curFile->first_lineno = lineno;
+       curFile->forBodyLineno = lineno;
        curFile->buf = buf;
        curFile->depending = doing_depend;      /* restore this on EOF */
        curFile->forLoop = forLoop;
@@ -2312,7 +2289,7 @@
            For_NextIteration(curFile->forLoop, &curFile->buf)) {
                curFile->buf_ptr = curFile->buf.data;
                curFile->buf_end = curFile->buf.data + curFile->buf.len;
-               curFile->lineno = curFile->first_lineno;
+               curFile->lineno = curFile->forBodyLineno;
                return true;
        }
 



Home | Main Index | Thread Index | Old Index