Commit Graph

213 Commits

Author SHA1 Message Date
rillig
3e21e61f57 make: clean up remaining references to VarEvalFlags
VarEvalFlags has been replaced with VarEvalMode.  There were some
comments and tests that still referred to the old names.

No functional change.
2021-04-11 13:35:56 +00:00
rillig
b306e574c3 make: add types Substring and LazyBuf
These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.
2021-04-11 12:06:53 +00:00
rillig
7d5e8f8e1b make: convert VarEvalFlags back into an enum, but not a bit-set
As was apparent in VarEvalFlags_ToString, a bit-set was not the best
data type since most of the flags were not freely combinable.  The two
flags that could be combined were keepDollar and keepUndef, but even
these have distinguished names in the debug log.

The downside of struct bit-fields is that they need extra helper
functions in C90 (see nonints.h).  Exchange these for a few helper
functions in var.c, to keep the code outside var.c simple.

No functional change.
2021-04-04 11:56:43 +00:00
rillig
1d7f9c44eb make: remove filler word 'Do' from function names for parsing
No functional change, except for debug logging.
2021-04-04 10:13:09 +00:00
rillig
730db1a03f make: rename a few functions to be more descriptive
No functional change.
2021-04-04 10:05:08 +00:00
rillig
a71bce0149 make: backport to C90
In the past few months I had accidentally used C99 features in the make
code.  According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be.  The identifier __func__ is
still used, as in other tools.

No functional change.
2021-04-03 14:39:02 +00:00
rillig
244fd9f4c4 make: use C99 bool type instead of defining its own
No functional change.
2021-04-03 11:08:40 +00:00
rillig
4a38bf21f4 make: change debug log for variable evaluation flags to lowercase
This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
2021-03-15 15:39:13 +00:00
rillig
2f8026b0e5 make: replace enum bit-field with struct bit-field for VarEvalFlags
This makes the code easier to read, especially in var.c.  It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases.  Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly.  This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
2021-03-15 12:15:03 +00:00
rillig
4fd3cf6eed make: rename VARE_NONE to VARE_PARSE_ONLY
The name 'NONE' described the bit pattern, which was not useful to
understand its meaning.  Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
2021-03-15 11:41:07 +00:00
rillig
370ad03170 make: clean up FStr and MFStr memory in cleanup mode 2021-02-14 21:32:58 +00:00
rillig
835b4db442 make: in the Var_ functions, move the scope to the front
This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
2021-02-05 05:15:12 +00:00
rillig
715bef6038 make: add shortcut Global_Delete for deleting a global variable 2021-02-05 04:41:17 +00:00
rillig
738d26da74 make: rename Var_ValueDirect to GNode_ValueDirect 2021-02-04 21:50:39 +00:00
rillig
701ef5fa30 make: group shortcuts for manipulating global variables
No functional change.
2021-02-04 20:14:33 +00:00
rillig
62f0c38b61 make: rename Var_SetWithFlags to Var_SetExpandWithFlags
Add back Var_SetWithFlags for the one call that doesn't need to expand
the name.

Now one of the flags is encoded in the function name while the others
are encoded in VarSetFlags.  This is inconsistent.  Maybe there is a
better way to model the different variants of setting a variable.
2021-02-04 19:15:13 +00:00
rillig
8660931fea make: rename Var_Set to Var_SetExpand
After doing the textual renaming across all files, I added a new
function Var_Set that does not expand the variable name.  I then undid
the renaming for all calls where the variable name cannot ever contain a
dollar sign.  I omitted the word "Expand" from the textual references in
the unit tests and in the debug logging messages since the focus is
usually on the "Set" part, not on the "Expand".

No functional change.
2021-02-04 19:00:45 +00:00
rillig
b3cadd8df0 make: rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete
The function names now follow the naming scheme from the other functions
that handle variables.

There are several calls that remain syntactically unchanged but that
omit the call to strchr('$') now.  Since all these calls use constant
variable names, there is no functional change.
2021-02-03 15:08:17 +00:00
rillig
785cdc035e make: split Var_Exists into plain Var_Exists and Var_ExistsExpand
Most previous calls to Var_Exists use constant variable names.  Only the
two calls in parse.c need to expand the variable name.

It may be a good idea to expand the variable name once in VarAssign_Eval
instead of repeating the expansion in each of its special cases.

No functional change.
2021-02-03 14:33:09 +00:00
rillig
a1bc5ad8cf make: replace Global_AppendExpand with Global_Append
All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand.  After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
2021-02-03 13:53:12 +00:00
rillig
8c8241ebce make: split Var_Append into Var_Append and Var_AppendExpand
The plain Var_Append now does not expand the variable name anymore.  It
is used in situations where the variable name is known to not contain a
dollar sign.

This is a preparation for adding Global_Append, corresponding to
Global_AppendExpand.
2021-02-03 13:44:39 +00:00
rillig
87686000da make: replace Global_SetExpand with Global_Set for constant names 2021-02-03 08:08:18 +00:00
rillig
3ec10f8db6 make: use shortcut functions Global_SetExpand and Global_AppendExpand
There are many places where global variables are set or appended to.  To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded.  In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
2021-02-03 08:00:36 +00:00
rillig
0840915c87 make: remove overengineered Enum_ValueToString
For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options.  This bug is one of the
oldest in make, dating back to at least 1993.
2021-02-02 17:56:31 +00:00
rillig
53f49756f4 make: remove outdated comment about VarEvalFlags
The previous variable preserveUndefined is now the flag VARE_KEEP_UNDEF.
2021-02-01 21:38:20 +00:00
rillig
f1a32e5707 make(1): convert SearchPath to struct
This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
2021-01-24 20:11:55 +00:00
rillig
85aee7a6f7 make(1): remove do-not-format markers from comments
These markers had been used inconsistently.  Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
2021-01-19 20:51:46 +00:00
rillig
fc135022e2 make(1): replace global preserveUndefined with VARE_KEEP_UNDEF
Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1.  The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27.  Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2.  There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well.  This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier.  In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
2020-12-28 00:46:24 +00:00
rillig
8eecc3ec3e make(1): remove unnecessary VPR_ERR_SILENT 2020-12-27 14:02:12 +00:00
rillig
fab83987ed make(1): clean up VarParseResult constants
The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished.  There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
    undefined variables.  The old constants VPR_PARSE_MSG and
    VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
    Previously the documentation for VPR_UNDEF_SILENT talked about
    undefined expressions in situations where they were not allowed.
    That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored.  These are probably bugs.

(4) Everything went fine, the expression has a defined value.
2020-12-27 10:53:23 +00:00
rillig
e0ea9a9396 make(1): remove unnecessary VPR_UNKNOWN for error handling
There is no sensible way for a caller of Var_Parse to deal with an error
state of "maybe successful, maybe not", therefore remove the constant
for it.
2020-12-27 10:09:53 +00:00
rillig
ea8c5a40a4 make(1): align names of VarExportMode with the directives 2020-12-27 05:06:17 +00:00
rillig
a542a5a6b7 make(1): allow .undef to undefine multiple variables at once
Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature.  Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
2020-12-22 20:10:21 +00:00
rillig
5196cc55b0 make(1): omit linear search for command in Compat_RunCommand 2020-12-20 21:07:32 +00:00
rillig
431ba0ec4b make(1): remove constant parameter from MakeMode 2020-12-20 14:39:46 +00:00
rillig
0307413016 make(1): change return type of Var_Value to FStr 2020-12-20 14:32:13 +00:00
rillig
7b3d8cbe3a make(1): return FStr from Var_Parse
This reduces the number of variable declarations at the call sites.
2020-12-20 13:38:43 +00:00
rillig
81b5e18281 make(1): export FStr and MFStr
These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.
2020-12-20 12:53:34 +00:00
rillig
715d1d3bec make(1): extract Var_DeleteVar from Var_Delete 2020-12-19 20:47:24 +00:00
rillig
a4d0870803 make(1): extract Var_Undef from ParseDirective 2020-12-19 20:16:36 +00:00
rillig
6e3f82b272 make(1): constify Targ_FmtTime 2020-12-18 14:36:46 +00:00
rillig
a44c2b10bb make(1): indent nonints.h and util.c with tabs instead of spaces 2020-12-15 20:39:15 +00:00
rillig
7f604d4793 make(1): add str_basename to reduce duplicate code
The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory.  This is too unreliable,
therefore this trivial own implementation.
2020-12-13 20:14:48 +00:00
rillig
2eebef5d2b make(1): remove dead code from GetVarnamesToUnexport
Now that the parsing of the directives is unified and strict, there is
no need anymore for the dispatched functions to check for unknown
directives.  These functions don't even get the information to decide
that since this decision is already done.
2020-12-13 02:15:49 +00:00
rillig
b506ce346a make(1): clean up Var_Export 2020-12-13 01:41:12 +00:00
rillig
ffcddf1eb1 make(1): eliminate boolean argument of Var_Export 2020-12-12 21:20:30 +00:00
rillig
bd57be24af make(1): rename Var_ExportVars to Var_ReexportVars 2020-12-12 18:53:53 +00:00
rillig
f650bd93fa make(1): inline Targ_Ignore and Targ_Silent
Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
2020-12-12 00:05:05 +00:00
rillig
227529d0a8 make(1): rename IFile.nextbuf to readMore
The previous name sounded too much like a noun, which was too confusing.
See unit-tests/opt-file.mk for the history of this part of the code.
2020-12-06 20:09:01 +00:00
rillig
3e7b0787d3 make(1): reduce memory allocation for targets
This change moves the initialization and finalization of the list of
targets to the same function.  They had been split before.
2020-11-29 00:04:22 +00:00