Commit Graph

139 Commits

Author SHA1 Message Date
rillig a0c9252554 make(1): clean up code stylistically
* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
  beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
  stays the same.  (Assertions further down in the code would get
  different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
2020-11-07 10:16:18 +00:00
rillig 143a32671d make(1): remove redundant parentheses from sizeof operator
The parentheses are only needed if the argument is a type, not an
expression.
2020-11-05 17:27:16 +00:00
rillig f374fbd233 make(1): remove mistyped extern variable
Robust programs don't have extern variable declarations in .c files, as
that risks incomatible definitions that are not detected by the compiler
and invoke undefined behavior.  Make make a little more robust.
2020-11-04 13:27:00 +00:00
rillig ff78291f2d make(1): make memory allocation simpler in meta_create and meta_oodate
Since there is only a single variable left that needs to be freed at the
end (and probably never actually needs to be freed since nobody defines
an environment variable named .OBJDIR), there is no need to loop over
these variables.
2020-10-31 12:04:24 +00:00
rillig f015e31c48 make(1): do not look up local variables like .TARGET anywhere else
Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else.  This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter.  Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
2020-10-31 11:54:33 +00:00
rillig 59a15951ab make(1): fix indentation in source code 2020-10-31 09:57:47 +00:00
rillig e8b104bf6c make(1): change char * to void * in Var_Value
The only purpose of the parameter freeIt is to free the memory
associated with the return value.  To do this, no pointer arithmetic is
needed.  Therefore, change to a void pointer, to catch accidental use of
that pointer.
2020-10-30 20:30:44 +00:00
rillig 09c6b7ecfa make(1): fix indentation in source code 2020-10-30 15:39:17 +00:00
rillig bc562b20b4 make(1): add GNode_Path to access the path of a GNode 2020-10-25 21:51:48 +00:00
rillig a455fbee67 make(1): inline Lst_Find in meta_oodate 2020-10-24 10:32:25 +00:00
rillig 9c2db9fe5e make(1): make Lst_RemoveIf simpler in meta_oodate
Using Lst_Find and Lst_FindFrom to implement Lst_RemoveIf was a bad
idea.  It made the code much more complicated than necessary.  There is
no predefined Lst_RemoveIf, but that can be implemented easily.  By
inlining the list handling, path_match does not need void pointers
anymore.

Freeing the path from the missingFiles list had been implemented in a
surprisingly complicated way, intermangling it unnecessarily with the
list operations, even though these are completely independent.
2020-10-24 10:17:21 +00:00
rillig 37bfc650f3 make(1): remove redundant parameter from meta_name 2020-10-24 04:31:53 +00:00
rillig 859199ba81 make(1): inline simple Lst getters
The function call variant takes more screen space than the direct field
access.  Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
2020-10-19 21:57:37 +00:00
rillig c679cfbc3e make(1): remove void pointers from printCMD 2020-10-19 20:41:53 +00:00
rillig 92688ee547 make(1): rename Lst_Init to Lst_New
For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
2020-10-18 13:02:10 +00:00
rillig 5658125d0a make(1): prepare for WARNS=6
The FD_* macros from sys/sys/fd_set.h use signed integers on NetBSD 8
and thus produce conversion errors.  On NetBSD 9, these macros are fixed
to use 1U instead of 1.
2020-10-18 11:54:43 +00:00
rillig 2309709fed make(1): replace execError with execDie
All calls to this function were followed by _exit(1).
2020-10-18 07:46:04 +00:00
rillig 37111947f1 make(1): make debug logging simpler
This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
2020-09-28 22:23:35 +00:00
rillig ae6e2b2c4b make(1): make debugging code shorter 2020-09-28 20:46:11 +00:00
rillig 073f669ad5 make(1): inline and remove LstNode_Prev and LstNode_Next
These functions made the code larger than necessary.  The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically.  (On the execution level, the
function calls had been inlined anyway.)
2020-09-26 17:15:20 +00:00
rillig 6d249710d5 make(1): migrate printCMD in meta mode to Lst_ForEach 2020-09-24 07:53:32 +00:00
rillig 4ec7405c5c make(1): rename Lst_ForEach to Lst_ForEachUntil
Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account.  The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
2020-09-24 07:11:29 +00:00
rillig e366c9989a make(1): prepare Var_Subst for proper error handling
Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
2020-09-22 20:19:46 +00:00
rillig a2ec3df107 make(1): use fine-grained type names for lists and their nodes
This is only intended to help the human reader.  There is no additional
type safety yet.
2020-09-22 04:05:41 +00:00
rillig d5631b520f make(1): add specific typedefs for lists
These typedefs are only intended to help human readers, they do not
provide any type-safety.  They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode.  Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again.  Register allocation is the job of the
compiler, not of the human source code reader.
2020-09-21 17:44:25 +00:00
rillig de1804033e make(1): fix inconsistent code indentation 2020-09-12 14:41:00 +00:00
rillig 0c93b3da8f make(1): reduce number of stat fields returned by cached_stat
Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero.  To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.
2020-09-02 04:08:54 +00:00
rillig eb0c83b502 make(1): rename Lst_Datum to LstNode_Datum 2020-08-30 11:15:05 +00:00
rillig 82fdd8ef8a make(1): trust that Var_Subst never returns NULL
It really never does, and it doesn't even report errors.  It just
returns the content of the buffer, up to the first parse error.
2020-08-29 13:16:54 +00:00
rillig bb2ba6a0e5 make(1): rename LstNode functions to match their type 2020-08-29 10:41:12 +00:00
rillig f6a7d0bc31 make(1): rename Lst_FindB back to Lst_Find
The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
2020-08-29 10:12:06 +00:00
rillig db2e5ed453 make(1): migrate remaining Lst_Find to Lst_FindB
While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
2020-08-29 10:06:23 +00:00
rillig 2c8df40906 make(1): fix the other assertion from Lst_FindFrom
When I migrated the Lst_FindFrom to the strict API variant, I forgot
that Lst_FindFrom requires both arguments (list and node) to be
non-null.  I had only checked that the list is non-null.

There are only very few calls to Lst_FindFrom, and they are all ok now.
2020-08-28 06:47:14 +00:00
rillig 942d06c278 make(1): remove trailing 'S' from names of Lst functions
The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL.  The latter case is especially surprising since
that function turns into an almost-nop in that case.  This is another
case where probably 2 independent functions have been squeezed into a
single function.  This may be improved in a follow-up commit.

All other lists were fine.  They were always defined and thus didn't
need much work.
2020-08-28 04:48:56 +00:00
rillig 4acfd85d5e make(1): migrate Lst_Find to Lst_FindS 2020-08-28 04:28:45 +00:00
rillig 4b307a6103 make(1): migrate Lst_First to Lst_FirstS 2020-08-28 04:14:31 +00:00
rillig 74fd7ff4cd make(1): migrate Lst_IsEmpty to Lst_IsEmptyS 2020-08-27 19:15:35 +00:00
rillig b855b10134 make(1): migrate Lst_Succ to Lst_SuccS 2020-08-27 07:00:29 +00:00
rillig 6c196ebe9c make(1): migrate Lst_ForEach to Lst_ForEachS
Most lists are always valid.  Only the "targets" variable may be null in
some cases, probably.
2020-08-27 06:53:57 +00:00
rillig 4862a68b32 make(1): add stricter variants for remaining Lst functions
In most cases the Lst functions are only called when the arguments are
indeed valid.  It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
2020-08-26 22:55:46 +00:00
rillig 27d66938d5 make(1): reverse order of the Lst_Find parameters
The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
2020-08-23 16:58:02 +00:00
rillig 4b0e7734a8 make(1): define aliases for function types in list processing
This makes the prototypes of the functions clearer.
2020-08-23 16:43:34 +00:00
rillig 885e5a1b8a make(1): fix indentation 2020-08-22 17:34:25 +00:00
rillig 4ea2d96bef make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS 2020-08-22 15:17:09 +00:00
rillig f5115d01e4 make(1): convert remaining Lst_AtEnd to the stricter Lst_Append
The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers.  This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
2020-08-22 13:28:20 +00:00
rillig 7b0da2fa03 make(1): make list library code stricter
Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage.  There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is.  When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
2020-08-21 03:36:03 +00:00
rillig 7f136885e3 make(1): remove unused code for circular lists
The list library had probably been imported from a general-purpose
library that also supported circular lists.  These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
2020-08-21 02:20:47 +00:00
rillig 86abf69ed1 make(1): no declaration-after-statement anymore
NetBSD make is intended to be maximally portable, therefore it uses only
C89.  This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments.  These will be fixed in a follow-up commit.
2020-08-03 20:26:09 +00:00
rillig ad6695e0a6 make(1): avoid calls to free(3) in the common case of a NULL pointer 2020-08-01 09:55:00 +00:00
rillig ab2bfed61f make(1): let Var_Value return a const char *
The return value must not be modified anyway, so let the compiler check
this for free.
2020-08-01 09:25:36 +00:00