Commit Graph

17570 Commits

Author SHA1 Message Date
rillig
f21f69f749 indent: clean up target column computation in process_comment
No functional change.
2021-03-14 04:42:17 +00:00
rillig
3cc06592f5 indent: make compute_code_indent more readable
The '?:' operator computing the factor was too hard to read.  When
quickly scanning the code, the 1 in the expression looked too much like
it would be added to the indentation, which would turn the indentation
length into a column number, and that again would smell like an
off-by-one error.

No functional change.
2021-03-14 01:44:37 +00:00
rillig
1e4c413bac indent: fix off-by-one error in comment wrapping
The manual page says that the default maximum length of a comment line
is 78.  The test 'comments.0' wrongly assumed that this 78 would refer
to the maximum _column_ allowed, which is off by one.

Fix the wording in the test 'comments.0' and remove the (now satisfied)
expectation comments in the test 'token-comment.0'.

Several other tests just happened to hit that limit, fix these as well.
2021-03-14 01:34:13 +00:00
rillig
bd908d33db indent: give indent a try at formatting its own code
Formatting indent.h required the following manual corrections
afterwards:

The first tab in the comment in line 1 was replaced with a space but
shouldn't be.

The spacing around the '...' in function prototypes was completely
wrong.  It looked like 'const char *,...)__printflike', without any
spaces.

The '*' of the return type 'const char *' was tied to the function name,
even though this declaration was only for a single function.  In such a
case, it's more appropriate to line up the function names.

The function-like macros were not indented to -di.  This is something
that I would not expect from indent, so it's ok to do that manually.
2021-03-14 00:33:25 +00:00
rillig
744982a9b6 indent: fix lint warnings
No functional change.
2021-03-14 00:22:16 +00:00
rillig
1eb04b8cb5 indent: remove disabled duplicate RCS ID from header
By convention, headers don't record their RCS ID.
2021-03-13 23:42:23 +00:00
rillig
c960730f11 indent: fix documentation of parser_state.paren_indents
The column position is not the same as the indentation (off-by-one).
2021-03-13 23:36:10 +00:00
rillig
fea66a5127 indent: add debug logging for switching the input buffer
No functional change outside debug mode.
2021-03-13 18:46:39 +00:00
rillig
eb340c3e4a indent: align comments in indent's own code
No functional change.
2021-03-13 18:24:56 +00:00
rillig
56c4653e3f indent: remove the '+ 1' from right margin calculation in comment
No functional change.
2021-03-13 18:11:31 +00:00
christos
cf29492e59 Handle \t too (RVP) 2021-03-13 15:46:54 +00:00
rillig
7e11a5f382 indent: rename local variable in dump_line
This clarifies that the variable names a column, not an indentation.
2021-03-13 13:55:42 +00:00
rillig
7301e2c2d1 indent: in dump_line, reduce scope of local variable
This allows the variable 'target' in the lower half of the function to
get a more specific name.

No functional change.
2021-03-13 13:54:01 +00:00
rillig
66af9142ab indent: distinguish between 'column' and 'indentation'
column == 1 + indentation.

In addition, indentation is a relative distance while column is an
absolute position.  Therefore, don't confuse these two concepts, to
prevent off-by-one errors.

No functional change.
2021-03-13 13:51:08 +00:00
rillig
7ad6720446 indent: rename pr_comment to process_comment, clean up documentation
No functional change.
2021-03-13 13:25:23 +00:00
rillig
93e110b15f indent: fix handling of '/*' in string literal in preprocessing line
Previously, the '/*' in the string literal had been interpreted as the
beginning of a comment, which was wrong.  Because of that, the variable
declaration in the following line was still interpreted as part of the
comment.  The comment even continued until the end of the file.

Due to indent's forgiving nature, it neither complained nor even
mentioned that anything had gone wrong.  The decision of rather
producing wrong output than failing early is a dangerous one.

At least, there should have been an error message that at the end of the
file, the parser was still in a a comment, expecting the closing '*/'.
2021-03-13 13:14:14 +00:00
rillig
102d371a8a indent: split 'main_loop' into several functions
No functional change.
2021-03-13 12:52:24 +00:00
rillig
b97b269d52 indent: split 'main' into manageable parts
Since several years (maybe even decades) compilers know how to inline
static functions that are only used once.  Therefore there is no need to
have overly long functions anymore, especially not 'main', which is only
called a single time and thus does not add any noticeable performance
degradation.

No functional change.
2021-03-13 11:47:22 +00:00
rillig
acec5beac9 indent: remove redundant parentheses
No functional change.
2021-03-13 11:27:01 +00:00
rillig
0a99ae80ca indent: fix confusing variable names
The word 'col' should only be used for the 1-based column number.  This
name is completely inappropriate for a line length since that provokes
off-by-one errors.  The name 'cols' would be acceptable although
confusing since it sounds so similar to 'col'.

Therefore, rename variables that are related to the maximum line length
to 'line_length' since that makes for obvious code and nicely relates to
the description of the option in the manual page.

No functional change.
2021-03-13 11:19:43 +00:00
rillig
2c2459a1fa indent: document undefined behavior in processing of comments
No functional change.
2021-03-13 10:47:59 +00:00
rillig
f3b63c94c8 indent: inline calls to count_spaces and count_spaces_until
These two functions operated on column numbers instead of indentation,
which required adjustments of '+ 1' and '- 1'.  Their names were
completely wrong since these functions did not count anything, instead
they computed the column.

No functional change.
2021-03-13 10:32:25 +00:00
rillig
526591ce10 indent: replace column computation with indentation computation
No functional change.
2021-03-13 10:20:54 +00:00
rillig
0c51d9451c indent: replace compute_code_column with compute_code_indent
The goal is to only ever be concerned about the _indentation_ of a
token, never the _column_ it appears in.  Having only one of these
avoids off-by-one errors.

No functional change.
2021-03-13 10:06:47 +00:00
rillig
5888ddac66 indent: replace compute_label_column with compute_label_indent
Using the invariant 'column == 1 + indent'.  This removes several overly
complicated '+ 1' from the code that are not needed conceptually.

No functional change.
2021-03-13 09:54:11 +00:00
rillig
4f1ab5eff9 indent: manually fix indentation in indent's own source code 2021-03-13 09:48:04 +00:00
rillig
6f2286deb6 indent: add debug logging for actually writing to the output file
Together with the results of the tokenizer and the 4 buffers for token,
label, code and comment, the debug log now provides a good high-level
view on how the indentation happens and where to look for the many
remaining bugs.
2021-03-13 09:21:57 +00:00
rillig
6892e0dc50 indent: remove strange debugging code that went in the output file
Whenever the code to be output contained the magic byte 0x80, instead of
writing this byte, indent wrote the column number at the beginning of
the code snippet, times 7.  Especially the 'times 7' does not make any
sense at all.

In ISO-8859-1, this character position is not assigned.  In Microsoft
Codepage 1252 it is the Euro sign.  In UTF-8 (which was probably not on
the author's list when the code was originally written) it occurs as the
middle byte for code points like U+2026 (horizontal ellipsis) from the
block General Punctuation.

Remove this strange code, thereby fixing indent for UTF-8 code.  The
code had been there since at least 1993-04-09, when it was first
imported to NetBSD.
2021-03-13 09:06:12 +00:00
rillig
689a1f7922 indent: replace pad_output with output_indent
Calculating the indentation is simpler than calculating the column,
since that saves the constant addition and subtraction of the 1.

No functional change.
2021-03-13 00:26:56 +00:00
rillig
47a823baba indent: clean up verbose documentation comments from the 1970s
Since C90, there is no need to repeat the type of the function
parameters.

In the whole code of indent, there is a lot of confusion between the
concepts of a 'column' (which is a position on the screen, counting
starts at 1) and 'indentation' (which is a length, not a position).  To
avoid this confusion, the code will be rewritten anyway very soon.

Repeatedly adding and subtracting 1 from the 'current column' is not
elegant, this should rather be done by consistently measuring only the
indentation from the left border (at offset 0), as a distance, not as an
absolute position.
2021-03-13 00:03:29 +00:00
rillig
8f15c12d1f indent: add 'const', rename variables, reorder formula for tab width
Column counting starts at 1.  This 1 should rather be at the beginning
of the formula since it is thought of being added at the very beginning
of the line, not at the end.

When adding a tab, the newly added tab is added at the end of the
string, therefore that '+ 1' should be at the end of the formula as
well.

No functional change.
2021-03-12 23:27:41 +00:00
rillig
a0306e684f indent: replace 'target' with 'indent' in function names
The word 'target' was not as specific as possible.

No functional change.
2021-03-12 23:16:00 +00:00
rillig
2be5ec967d indent: use consistent indentation for 'else'
Half of the code used -ce, the other half the opposite -nce.

No functional change.
2021-03-12 23:10:18 +00:00
rillig
2603dcca0f indent: make output_string inline
GCC 9.3.0 didn't notice that the argument to this function is always a
string literal, which makes it worthwhile to inline the call.
2021-03-12 19:14:18 +00:00
rillig
51ad939870 indent: add helper functions for doing the actual output
This allows to add debug logging to these few functions instead of all
other places that might output something.

Reducing the possible output formats to a few primitives makes dump_line
simpler, especially the fprintf calls.  It also removes the non-constant
printf string.

The call to output_int may be meant for debugging, as the character 0x80
is unlikely to appear in any real-world code.

No functional change.
2021-03-12 19:11:29 +00:00
rillig
d07ba49995 indent: fix misleading indentation in indent's own code
No functional change.
2021-03-12 18:11:50 +00:00
rillig
61a2b8d236 indent: move code for tokenizing numbers further up
Having it directly below the table makes it easier understandable.

I also tried to omit this function entirely by moving the code into the
initializer itself, but that made the code redundant and furthermore
increased the size of the resulting binary, probably because of the new
relocation records.

No functional change.
2021-03-12 17:46:48 +00:00
rillig
81c22dc68a indent: manually fix indentation
No functional change.
2021-03-12 00:15:34 +00:00
rillig
200ea2d398 indent: reduce indentation of check_size functions
No functional change.
2021-03-11 22:32:06 +00:00
christos
ff8b561e4a remove extra increment; fixes: echo o | sed -e 's/o/\a/' 2021-03-11 22:31:19 +00:00
rillig
c7f0688822 indent: remove redundant cast after allocation functions
No functional change.
2021-03-11 22:28:30 +00:00
rillig
72f722fd46 indent: use consistent array indexing
No functional change.
2021-03-11 22:15:44 +00:00
rillig
a855cd0537 indent: merge duplicate code for reading from the input buffer
No functional change.
2021-03-11 21:47:36 +00:00
wiz
4481672ffb Remove trailing whitespace. 2021-03-11 17:13:29 +00:00
christos
95cea0cc25 Use the same options like m4 (-g turns on GNU, -G turns off GNU) Suggested
by uwe@
2021-03-11 15:45:55 +00:00
christos
d502916eaa Add -G to support GNU extensions 2021-03-11 15:15:05 +00:00
simonb
4e642ca22c Remove Network ATM soft intr queue reporting, we don't have that in the
kernel anymore.
2021-03-10 00:32:15 +00:00
rillig
5edf0687f7 lint: disable check for enum type mismatch in switch statement
This check has been too quick and broke the lint build.  Among others,
lib/libpuffs has -w included in LINTFLAGS, which means that the build
can fail even for new warnings, not only for errors.

libpuffs compares a uint16_t with constants from an unnamed enum type.
Since the enum type is completely unnamed (neither a tag nor a typedef),
there is no way to define a struct member having this type. This was a
scenario that I just didn't consider when I added the check to lint.

For now, disable the new check completely.  The previously existing lint
checks stay enabled, including the one that warns about mismatched
anonymous enum types in the '==' operator, which is very similar to the
now disabled check.
2021-03-10 00:02:00 +00:00
rillig
ee51961c3d indent: extract search_brace from main
No functional change.
2021-03-09 19:46:28 +00:00
rillig
4ca89b5791 indent: extract capsicum code out of the main function
No functional change.
2021-03-09 19:32:41 +00:00
rillig
d60ce5707b indent: rename a few more token types
The previous names were either too short or ambiguous.

No functional change.
2021-03-09 19:23:08 +00:00
rillig
ed0fd2fe70 indent: make token names more precise
The previous 'casestmt' was wrong since a case label is not a statement
at all.

The previous 'swstmt' was overly short, and wrong as well, since it
represents only the 'switch (expr)' part, which is not a complete switch
statement.  Same for 'ifstmt', 'whilestmt', 'forstmt'.

The previous word 'head' was not precise enough since it didn't specify
exactly where the head ends and the body starts.  Especially for
handling the dangling else, this distinction is important.

No functional change.
2021-03-09 19:14:39 +00:00
rillig
d64e8288e4 indent: rename a few tokens to be more obvious
For casual readers it is not obvious whether the 'sp' meant 'special' or
'space' or something entirely different.
2021-03-09 18:28:10 +00:00
rillig
bd056b6eea indent: extract reduce_stmt from reduce
This refactoring reduces the indentation of the code, as well as
removing any ambiguity as to which 'switch' statement a 'break' belongs,
as there are no more nested 'switch' statements.

No functional change.
2021-03-09 18:21:01 +00:00
rillig
6cabfe5cb2 indent: manually indent comments
It's strange that indent's own code is not formatted by indent itself,
which would be a good demonstration of its capabilities.

In its current state, I don't trust indent to get even the tokenization
correct, therefore the only safe way is to format the code manually.
2021-03-09 16:48:28 +00:00
rillig
cf51428060 indent: remove redundant initializer in dump_line
No functional change.
2021-03-08 22:28:31 +00:00
rillig
439ca385c5 indent: move comment about dump_line to column 1
It looked misplaced on the right side since that area is usually
reserved for small remarks, not long explanations.

No functional change.
2021-03-08 22:26:17 +00:00
rillig
a3dc5dfa03 indent: always use braces in do-while loops
Having a 'while' at the beginning of a line looks as if it would start a
loop.  It's confusing when it _ends_ a loop instead.
2021-03-08 22:23:58 +00:00
rillig
8d6721908d indent: split bsearch comparison function
It may have been a clever trick to use the same memory layout for struct
templ and a string pointer, but it's not worth the extra comment and
difficulty in understanding the code.

No functional change.
2021-03-08 21:13:33 +00:00
rillig
68856268b8 indent: inline macro for backslash
No functional change.
2021-03-08 20:20:11 +00:00
rillig
37bc0e6731 indent: convert big macros to functions
Each of these buffers is only modified in a single file.  This makes it
unnecessary to declare the macros in the global header.
2021-03-08 20:15:42 +00:00
rillig
849f856bf6 indent: make it easy to compile indent in debug mode 2021-03-08 19:21:41 +00:00
rillig
4526c76528 indent: fix printing of uninitialized 'token' in debug output 2021-03-08 19:06:48 +00:00
rillig
73071b8322 indent: fix handling of '//' end-of-line comments 2021-03-07 22:11:01 +00:00
rillig
b65a14572e indent: sprinkle a few const
No functional change.
2021-03-07 20:52:11 +00:00
rillig
ec2de7a28a indent: remove redundant parentheses around return value
No functional change.
2021-03-07 20:47:13 +00:00
rillig
17efe8f8c3 lint: move keyword 'continue' over to the other control flow keywords
No functional change since neither rw_jump nor rw_inline_or_restrict is
mentioned in any switch statement, and lint didn't find any other
suspicious enum operations.
2021-03-07 20:40:18 +00:00
rillig
a3d348a576 indent: use named constants for the different types of keywords
This reduces the magic numbers in the code.  Most of these had their
designated constant name written in a nearby comment anyway.

The one instance where arithmetic was performed on this new enum type
(in indent.c) was a bit tricky to understand.

The combination rw_continue_or_inline_or_restrict looks strange, the
'continue' should intuitively belong to the other control flow keywords
in rw_break_or_goto_or_return.

No functional change.
2021-03-07 20:30:48 +00:00
rillig
36dd5d7651 lint: do not allow assignment-expression for constant-expression
It's a funny idea to do something like 'case a = 13:', but since any
compiler will reject this code, there is no point in lint supporting it.

No functional change since everywhere the grammar allows a constant
expression, there is no ambiguity where an assignment could be
interpreted differently.
2021-03-07 20:06:48 +00:00
rillig
53af70edc9 lint: rename grammar rule 'constant'
C99 6.4.4 already defines a grammar rule named 'constant' for an number
literal or an enum constant, so don't use that name for something else.

No functional change.
2021-03-07 19:57:46 +00:00
rillig
4c83646ad2 lint: align names of C grammar rules with C99
No functional change.
2021-03-07 19:46:18 +00:00
rillig
7bd1775519 lint: in strict C mode, warn about initialization with '[a ... b]'
https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
2021-03-07 19:42:54 +00:00
rillig
8c49e96e03 lint: fix off-by-one error in 'case 3...5'
According to the GCC documentation[1], the high end of the range is
inclusive as well, which makes sense since otherwise there would be no
way of specifying a range that includes the maximum representable
number.

Since the range is not used at all in the code, none of the tests could
possibly fail.

[1] https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html

No functional change.
2021-03-07 18:02:45 +00:00
rillig
26903e6b19 lint: inline 'case 3...5' in grammar
There was no point in having a separate grammar rule for the '3...' part
of a range expression, it just made the code more complicated than
necessary.

No functional change.
2021-03-07 17:57:52 +00:00
rillig
f4d1bba78c lint: in the name of an array type, list the dimension first
before: array of unsigned int[4]
now:    array[4] of unsigned int

Listing the array dimension first keeps it in contact with the keyword
'array'.  This reduces confusion, especially for nested arrays.
2021-03-07 17:12:41 +00:00
rillig
317f4968ee indent: in debug mode, output detailed token information
The main ingredient for understanding how indent works is the tokenizer
and the 4 buffers in which the text is collected.

Inspecting this debug log for the test comment-line-end makes it obvious
why indent messes up code that contains '//' comments.  The cause is
that indent interprets '//' as an operator, just like '&&' or '||'.  The
sequence '/////' is interpreted as a single operator as well, by the
way.

Since '//' is interpreted as an ordinary operator, any words following
it are plain identifiers, usually several of them in a row, which is a
syntax error.  Depending on the context, the operator '//' is either a
unary operator (no space around) or a binary operator (space around).
This explains why the word 'line-end' is expanded to 'line - end'.

No functional change outside of debug mode.
2021-03-07 11:32:05 +00:00
rillig
bf0defb337 indent: for the token types, use enum instead of #define
This makes it easier to step through the code in a debugger.

No functional change.
2021-03-07 10:56:18 +00:00
rillig
3658a7adc6 indent: use all headers in all files
This is a prerequisite for converting the token types to an enum instead
of a preprocessor define, since the return type of lexi will become
token_type.  Having the enum will make debugging easier.

There was a single naming collision, which forced the variable in
scan_profile to be renamed.  All other token names are used nowhere
else.

No change to the resulting binary.
2021-03-07 10:42:48 +00:00
rillig
280e2f10d4 indent.1: sort options alphabetically 2021-03-06 21:08:08 +00:00
rillig
ff2507050a indent: fix space-tab alignment in indent's own code
These parts are not fixed automatically by indent since they are in box
comments.

No functional change.
2021-03-06 20:30:06 +00:00
rillig
b5348831df lint: warn about enum/enum or enum/int type mismatch in switch
This is something that neither GCC 10 nor Clang 8 do, even though it
seems useful.  Lint didn't do it up to now, but that was probably an
oversight since it is easy to miss the implicit '==' operator in the
switch statement.
2021-03-05 17:10:05 +00:00
simonb
6e33305585 For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq.  Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.
2021-03-03 08:25:16 +00:00
christos
5d8f515b0c Only specify the dependencies if we are making the copy target. 2021-03-02 14:26:00 +00:00
uwe
d5a7953cd7 Use proper -width instead of the cargo-cult value. 2021-03-02 10:17:25 +00:00
uwe
e6330ecec4 Sort config file flags and command line options. 2021-03-02 10:14:59 +00:00
uwe
b3a91da400 Fix markup so that literals are typeset as literals. 2021-03-02 10:12:33 +00:00
simonb
ec07c80492 Don't show any of the completely and utterly undocumented VTW info if
the feature isn't enabled (by checking net.inet.tcp.vtw.enable).
2021-03-02 01:02:12 +00:00
wiz
d7baa73527 Sort options in synopsis 2021-03-01 21:43:00 +00:00
otis
3128aa54a9 Implement 'E' flag that prevents newsyslog from rotating empty log files. 2021-03-01 21:37:10 +00:00
rillig
d8822d35c5 lint: only warn once about integer constant overflow on 32-bit
Previously, the test msg_056.c warned twice about the integer literal,
but only on 32-bit platforms.  On 64-bit platforms, there was only a
single warning since the integer constant was converted to type
__uint128_t, and this prevented the second warning.  On 32-bit targets,
there is no __uint128_t though.

Fixes part of PR bin/55976.
2021-03-01 00:51:01 +00:00
rillig
523633c84d lint: fix null pointer dereference on parse error
Fixes PR bin/22119.
2021-02-28 22:12:16 +00:00
rillig
d4dabb45ab lint: document where in C99 the behavior of cconv is specified 2021-02-28 20:04:52 +00:00
rillig
6314f2eb79 lint: replace wrong comment with assertion
The broad type of a value is indeed stored in the value itself, in the
member v_tspec.  For nodes that refer to this value, it is redundantly
stored, it always equals tn->tn_type->t_tspec.

After initialization, neither tn->tn_type nor val->v_tspec are modified.
This is not ensured by the compiler but has to be analyzed manually.

No functional change.
2021-02-28 19:24:15 +00:00
rillig
5cc5fe1a43 lint: rename is_nonzero to constant_is_nonzero
The new function name emphasizes that the given node must have the
operator CON.

No functional change.
2021-02-28 19:16:05 +00:00
rillig
6171ad7d6b lint: rename members and access macros of the basic types
Having the measurement unit in the variable name prevents accidental
confusion between bits and bytes, especially since usually the word
'size' means the size in bytes, while 'width' means the size in bits, at
least for integer types.

No functional change.
2021-02-28 18:51:51 +00:00
rillig
2fe9f15dbb lint2: add redundancy checker for comments in source code
Based on the redundancy checker for lint1.

No functional change.
2021-02-28 18:17:08 +00:00
rillig
8f43f8f65c lint2: align comments in the code with actual messages 2021-02-28 17:16:50 +00:00
rillig
a75e3514c2 tests/lint: shorten code for checking redundancy in files
No functional change.
2021-02-28 12:45:47 +00:00
rillig
f963c8e49b tests/lint: keep messages in test files in sync with actual messages
Each of the tests named msg_*.c repeats the template of the message, to
make the test somewhat self-contained when viewed in isolation.

This creates a redundancy, and keeping track of this manually is next to
impossible.  I tried it and failed in 9 cases, even though it has just
been 2 months since I myself created the initial files and I knew all
the time that this redundancy exists.

Be fool-proof for the future by checking this automatically.
2021-02-28 12:40:00 +00:00
mrg
f4968f58f4 disable the rule to copy resize.c since it fails on r/o src trees:
cp: /home/source/ab/HEAD/src/usr.bin/resize/resize.c: Permission denied
2021-02-28 09:04:28 +00:00
rillig
0d0d46fd3a lint: do not warn about constant expressions involving sizeof
These expressions are indeed constant for a specific platform, but on
another platform their value may change.  This makes them unsuspicious
and legitimate for portable code.

Seen in rump_syscalls.c, as 'sizeof(int) > sizeof(register_t)'.
2021-02-28 03:59:28 +00:00
rillig
597058d81f lint: rename parameter in function 'expr'
For symmetry with the function is_constcond_false.

No functional change.
2021-02-28 03:33:18 +00:00
rillig
bdddf63789 lint: document allowed types for bit-fields
No functional change.
2021-02-28 03:14:44 +00:00
rillig
4eef7b9455 lint: extract declare_bit_field from declarator_1_struct_union
No functional change.
2021-02-28 03:05:12 +00:00
rillig
089670865b lint: add type information to 'illegal bit-field type' 2021-02-28 02:45:37 +00:00
rillig
cc09e52e7b lint: extract type_name_of_array from type_name
No functional change.
2021-02-28 02:37:04 +00:00
rillig
ca54ab8987 lint: output precise type information for struct/union/enum
Previously, 'typedef enum { E } name' was output as 'name', which
omitted the information that this was an enum type.  Now it is output as
'enum typedef name'.

Previously, 'typedef struct { int member; } name' was output as 'struct
<unnamed>', which omitted the typedef name.  Now it is output as 'struct
typedef name'.
2021-02-28 02:29:28 +00:00
rillig
2317ba2476 lint: add type information for 'incompatible struct pointers' 2021-02-28 02:00:05 +00:00
rillig
fb1e12220d lint: add type information to enum type mismatch 2021-02-28 01:30:22 +00:00
rillig
4b52b11627 lint: make messages for incompatible pointers more specific
Message 153 didn't state obviously which of the pointer types was the
one before conversion (or cast) and which was the resulting type.

Message 229 didn't have any type information at all.
2021-02-28 01:06:57 +00:00
christos
8e0f075136 add parens 2021-02-28 00:44:58 +00:00
christos
678ed6abf6 no need to specify SRCS 2021-02-28 00:43:24 +00:00
christos
692ead559b remove unused 2021-02-28 00:42:22 +00:00
rillig
b19a5288ba lint: add type information to 'possible pointer alignment problem [135]'
This warning occurs more than 7400 times in a regular NetBSD build, and
without giving any type information, leaves the reader clueless about
what the underlying issue might be.  Add type information since that is
a no-brainer to implement.
2021-02-28 00:40:22 +00:00
rillig
f6dafdc19b lint: skip alignment computation if possible
Testing a global variable is simpler than calling a 20-line function.

No functional change.
2021-02-28 00:28:47 +00:00
rillig
2659adfbbb lint: rename getbound to alignment_in_bits
No functional change.
2021-02-28 00:23:55 +00:00
christos
7c9ac6ddef Don't define the copy rules if we don't have X sources 2021-02-27 22:37:54 +00:00
christos
ec2d1eb5c3 Bump warns 2021-02-27 16:08:08 +00:00
christos
66a2df677d Add a maintainable version of resize, with a copy target and a header that
provides all the glue needed without other X headers.
2021-02-27 15:36:39 +00:00
rillig
99ea8b90fb lint: rename confusing local variable
The variable name rtp is reserved for the type of the right-hand
operand.

No functional change.
2021-02-27 15:26:30 +00:00
christos
e0ecd16b50 PR/56013: Kouichi Hashikawa: Move setutent/setutxent right before the loops. 2021-02-26 02:45:43 +00:00
rillig
d251e04261 make: document the history of bugs in "cmdline overrides global"
For performance reasons, the implementation of the simple rule "cmdline
overrides global" grew into code that is much more complicated than a
straight-forward implementation.  This added complexity made it easy for
bugs to sneak in.
2021-02-23 21:59:31 +00:00
rillig
c82f512123 make: reduce indentation in Var_Parse
The extra condition had been necessary before FStr made memory
management simpler.

The Coverity annotation got out-of-date when the parameter was converted
to FStr since that type is not allocated on the heap, only its inner
members are.

No functional change.
2021-02-23 16:29:52 +00:00
rillig
1029e78d18 make: restructure code in ParseVarname to target human readers
Breaking the loop once for depth == 0 and once for depth == 1 was
unnecessarily confusing, as was the nested 'if'.  Start counting with 0
since there is no reason to start at 1.

Evaluating the common subexpression '*p == endc' is left as an exercise
to the compiler.

No functional change.
2021-02-23 16:14:11 +00:00
rillig
7121bc3d02 make: improve error message for bad modifier in variable expression
The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
2021-02-23 16:07:14 +00:00
rillig
3429dfe6ac make: add test for confusing error message for bad modifier
In the expression ${:U}, the variable name is empty.  Since these
expressions are generated by .for loops, the error messages for them
must not end with a trailing space.  Putting the variable name in quotes
helps against that.
2021-02-23 16:04:16 +00:00
rillig
985b27d91a make: improve error message for unclosed modifier
Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
2021-02-23 15:56:29 +00:00
rillig
2ede7aa75a make: improve error message for unknown modifier
Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character.  Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is.  The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
2021-02-23 15:19:41 +00:00
rillig
2b3b250de9 make: remove redundant parameter of ApplySingleModifier 2021-02-23 15:07:58 +00:00
rillig
b5e0384378 make: explain non-obvious code around indirect variable modifiers
No functional change.
2021-02-23 15:03:56 +00:00
rillig
a31532eb14 make: comment on possible inconsistency in handling modifier ':sh' 2021-02-23 14:27:27 +00:00
rillig
face6b4c9d make: note inconsistent parsing behavior in modifier ':_=' 2021-02-23 14:21:45 +00:00
rillig
0b7a08866d make: demonstrate how to undefine variables during evaluation
For a very long time now, I had thought that it would be impossible to
undefine global variables during the evaluation of variable expressions.
This is something that the memory management in Var_Parse relies upon,
see the comment 'the value of the variable must not change'.

After several unsuccessful attempts at referring to an already freed
previous value of a variable, today I discovered how to unset a global
variable while evaluating an expression, which has the same effect.  To
demonstrate that this use-after-free can reliably crash make, it would
need a memory allocator with a debug mode that never re-allocates the
same memory block after it has been used once.  This is something that
jemalloc cannot do at the moment.  Valgrind would be another idea, but
that has not been ported to NetBSD.

Undefining a global variable while evaluating an expression is made
possible by an implementation detail of the modifier ':@'.  That
modifier undefines the loop variable, without restoring its previous
value, see ApplyModifier_Loop.

By the very old conventions of ODE Make, these loop variables are named
'.V.' and thus do not conflict with variables from other naming
conventions.  In NetBSD and pkgsrc, these loop variables are typically
called 'var', sometimes '_var' with a leading underscore, which also
doesn't conflict with the typical form 'VAR' of variables in the global
namespace.  Therefore, in practice these loop variables don't interfere
with other variables.

One case that can practically arise is when an outer variable has a
modifier ':@word@${VAR.${word}}@' and one of the referenced variables
uses the same variable name in the modifier, see varmod-loop.mk 1.10
line 91 for a detailed explanation.

By using the ${:@VAR@@} modifier in a place that is evaluated with
cmdline scope, it is not only possible to undefine global variables, it
is possible to undefine cmdline variables as well.  When evaluated in a
specific make target, the expression ${:@\@@@} can even be used to
undefine the variable '.TARGET', which will probably crash make with an
assertion failure.
2021-02-23 14:17:21 +00:00
wiz
dc9173cfee Fix Fl argument.
From Kouichi Hashikawa in PR 56009.
2021-02-23 07:15:41 +00:00
rillig
ac43378364 make: quote ':S' in error message about missing delimiter 2021-02-23 00:27:47 +00:00
rillig
6b851c0577 make: extract ParseModifier_Match into separate function
No functional change.
2021-02-23 00:25:06 +00:00
rillig
54bec0ad03 make: add context information to error message about ':range' modifier 2021-02-23 00:15:22 +00:00
rillig
39ed2c5332 make: fix local variable name for parsing arguments
The variable name 'arg' was misleading since after a successful
TryParseTime, it would no longer point to the argument of the variable
modifier, but to the _end_ of the argument.  To reduce confusion, use p
instead, like everywhere else.  This name is less specific, which is
still better than a wrong name.
2021-02-23 00:11:07 +00:00
rillig
0c470650a5 make: add quotes around variable name in an error message 2021-02-23 00:04:48 +00:00
rillig
ba8edc0160 make: add test for confusing double space in error message 2021-02-22 23:59:43 +00:00
rillig
3d4c16a2c1 make: reorder code in ModifyWords
No functional change.
2021-02-22 23:46:03 +00:00
rillig
cc8e99da10 make: use more common parameter order for VarSelectWords
No functional change.
2021-02-22 23:42:29 +00:00
rillig
236224f584 make: make ModifyWord_Subst a little easier to understand
Addition is easier than subtraction, and the expression 'word + wordLen'
obviously means 'the end of the word', which was not as easy to spot
before.

No functional change.
2021-02-22 23:39:24 +00:00
rillig
49c1680d06 make: remove freestanding freeIt variables
These variables all belong to a string variable.  Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
2021-02-22 23:21:33 +00:00
rillig
4acdc7c93b make: remove boolean parameter and return type from VarFreeEnv
There was only a single case where this parameter was false.  Inline
that case.  That was the only case that needed the return value, so
remove that as well.
2021-02-22 22:55:43 +00:00
rillig
626c9c496d make: add a few open questions to Var_SetWithFlags 2021-02-22 22:34:04 +00:00
rillig
db1760d592 make: do not expand variable name from the command line twice in a row
When

1.  there is a global variable containing a dollar in its expanded name
    (very unlikely since there are lots of undocumented edge cases that
    make variable names containing dollar signs fragile), and

2.  after that (unlikely since that requires .MAKEFLAGS instead of a
    normal command line)

3.  there is a command line variable of the same name (again very
    unlikely since that variable name would contain a dollar sign as
    well in the expanded form),

the global variable would not be undefined as promised by the comments
since its name was expanded once more than intended.

Because of the two 'very unlikely' above, this edge case hopefully does
not affect any practical use cases.

Note that this is not about VAR.${param} (which has a dollar sign in its
unexpanded form), but about the case where param itself would expand to
a dollar sign, such as after param=$$.
2021-02-22 22:26:50 +00:00
rillig
fbed66c0a8 make: add test for cmdline variables overriding global variables 2021-02-22 22:04:28 +00:00
rillig
a1ab648646 make: extract ExistsInCmdline from Var_SetWithFlags
No functional change.
2021-02-22 21:43:57 +00:00
rillig
ae25c3cc92 make: save a hash map lookup when defining a cmdline variable
This is a preparation to extract the code for exporting a cmdline
variable.  That code differs in several details from the other code in
ExportVar.

No functional change.
2021-02-22 21:30:33 +00:00
rillig
fd3f4d79e1 make: document interaction between cmdline and global variables
Make prevents global variables from being or becoming visible when a
command line variable of the same name is already defined.

There is a double safety net here.  Even if the call to Var_DeleteExpand
were removed, there would be no noticeable effect, other than one less
line in the debug log.

No functional change.
2021-02-22 21:14:15 +00:00
rillig
f62aab2842 make: fix report-coverage
On NetBSD 8.0 it still worked.  Maybe gcov doesn't support .c files as
arguments anymore.  Using the .gcda files works and is more reliable
anyway since it covers the inline functions in the headers as well.
2021-02-22 20:45:46 +00:00
rillig
bc82f3aea8 make: update constant names in comments
No functional change.
2021-02-22 20:38:55 +00:00
rillig
199346cc31 lint: change spelling of initialisation to initialization
That's the wording from the ISO C99 standard.
2021-02-22 15:09:50 +00:00
rillig
368c75e0d5 lint: improve debug message and comment 2021-02-22 15:01:03 +00:00
rillig
154c4e09c1 lint: extract check_non_constant_initializer from init_using_expr
No functional change.
2021-02-21 15:02:16 +00:00
rillig
80fb46b343 lint: extract check_bit_field_init from init_using_expr
No functional change.
2021-02-21 14:57:25 +00:00
rillig
4bbce6e96b lint: add debug logging for initializing an array of unknown size
It is possible that the type name 'array[unknown_size]' may spill into
the user-visible diagnostics.  The current test suite does not cover
such a case.  Anyway, saying 'array[unknown_size]' is still better than
saying 'array[0]', which would be misleading.
2021-02-21 14:19:27 +00:00
rillig
881e9b200c lint: rename and condense initstack_check_too_many
No functional change.
2021-02-21 14:02:36 +00:00
rillig
bd3424cb84 lint: remove redundant debug logging
In initstack_pop_nobrace, if anything happens to the initstack, it will
be logged by initstack_pop_item.

In init_using_expr, the address of the node is irrelevant, the node's
contents has already been logged above.
2021-02-21 13:52:21 +00:00
rillig
db03d9f153 lint: clean up comments in mem1.c
The comment for tgetblk had been misplaced.
2021-02-21 13:27:22 +00:00
rillig
329f58d857 lint: document i_brace, add comments, rename initstack_string
No functional change outside debug mode.
2021-02-21 13:13:14 +00:00
rillig
788308fa94 lint: always initialize return values of constant_addr
Before, the caller was responsible for initializing the return values
from the function.  This was an unexpected burden.

Ensure that in each branch that returns true, both return values are
properly set.

Strangely, the only caller of that function, init_using_expr, uses
neither of the return values.  It just tests whether the expression is
constant or not.

No functional change.
2021-02-21 11:23:33 +00:00
rillig
4c4ccffbb5 lint: add type information to message about enum mismatch 2021-02-21 10:28:32 +00:00
rillig
8fb84076f2 lint: clean up debug logging in initstack_pop_item
The debug logging contained much redundant information and was
misleading in a few places.  For example, "pop" did not actually pop an
item, plus there are several things that could be popped, so that didn't
help either.

Sprinkle some comments in places where the code needs to become clearer.

No functional change outside debug mode.  The condition
'istk->i_remaining >= 0' was redundant due to the assertion directly
above it.
2021-02-21 10:03:35 +00:00
rillig
9e32617b0c lint: rename istk to initstack_element
The longer name is more expressive and more correct.  The previous name
called each stack element a stack itself, which was unnecessarily
confusing.

No functional change.
2021-02-21 09:24:32 +00:00
rillig
ab7cfcc59b lint: fix wrong warning about main falling off the bottom in C99 mode
This gets lint a small step closer to implementing C99.
2021-02-21 09:17:55 +00:00
rillig
7274e46a8c lint: reduce amount of debug output during initialization 2021-02-21 08:27:41 +00:00
rillig
a85144e65d lint: rename members of struct istk to be more expressive
No functional change outside debug mode.
2021-02-21 08:01:14 +00:00
rillig
dc5e40131f lint: fix definition of debug_node in non-debug mode 2021-02-21 07:59:17 +00:00
rillig
129bdc0be2 lint: indent node details in debug mode 2021-02-21 07:21:57 +00:00
rillig
22478541ca lint: fix lint warning 'expression has null effect' 2021-02-20 19:56:44 +00:00
rillig
d9430ee79d lint: fix lint warnings
No functional change.
2021-02-20 19:10:37 +00:00
rillig
d4c07c2ea4 lint: do not warn about 'do { ... } while (false)' in strict bool mode 2021-02-20 18:55:10 +00:00
rillig
3bac4cd115 lint: document how to compile lint1 in debug mode 2021-02-20 18:10:22 +00:00
rillig
59c3c702bb lint: add test for using a bool as array index in strict bool mode 2021-02-20 18:02:58 +00:00
rillig
6669b286da lint: in debug mode, print the initialization stack
This is the central data structure of the initializations, it keeps
track of the objects that still need to be initialized.  Seeing its
contents in debug mode helps in finding and understanding the still
incomplete C99 support.
2021-02-20 17:44:39 +00:00
rillig
db97bec5bb lint: define debug_named_member only in debug mode
In non-debug mode it was an expensive no-op.
2021-02-20 17:24:37 +00:00
rillig
8f1bf5e205 lint: document an assumption that has turned wrong with C99 2021-02-20 17:12:00 +00:00
rillig
56d3e49d54 lint: extend debugging for initializing objects
No functional change outside debug mode.
2021-02-20 16:34:57 +00:00
rillig
92a76c943c lint: rename mkinit to init_using_expr
No functional change outside debug mode.
2021-02-20 16:03:56 +00:00
rillig
039617c180 lint: add hierarchical debug logging for initializations
No functional change for default mode.
2021-02-20 15:23:07 +00:00
rillig
486e361bf3 lint: make parsing of GCC line directives stricter
The previous code accepted '# 123 "file.c" 23' as specifying a system
header, just because that number ends with '3'.  The original intention
was to compare the complete word, not its suffix.  Fix that.

No practical change since the only flags that are used by GCC are all
single-digit.
2021-02-20 11:06:56 +00:00
rillig
2cab38691c lint: reduce duplicate code in check for getopt
This also changes the conditions to their positive form, which is easier
to read.

No functional change.  The resulting binary would have been the same as
before, were it not for the changed line numbers in the lint_assert
calls further down in the code.
2021-02-20 10:12:52 +00:00
rillig
7f300e59ba lint: clean up check for getopt
The original options string is not needed during the check.  Having only
the unhandled options suffices.

No functional change.
2021-02-20 10:01:27 +00:00
rillig
46a713f776 lint: fix crash from ckgetopt.c 1.2 and document the data structures 2021-02-20 09:57:02 +00:00
nia
fe9db1e16f fix URL 2021-02-20 09:31:51 +00:00
nia
894dfd713b patch(1): use PATH_MAX for the size of rejname
via freebsd, openbsd
2021-02-20 09:17:13 +00:00
christos
fc13bd7d09 Prevent crashing when options are NULL in libc while linting
src/lib/libc/posix1e/acl_from_text.c
2021-02-20 01:18:02 +00:00
rillig
4e5ad049a7 lint: remove gcov results on "make clean" 2021-02-19 23:25:26 +00:00
rillig
90c29d8403 lint: shorten code in check-msgs.lua
No functional change.
2021-02-19 23:22:19 +00:00
rillig
9c0f980ca3 lint: rename storage class constants to be more expressive
No functional change.
2021-02-19 22:35:42 +00:00
rillig
32266a1930 lint: rename t_isenum and t_aincompl to be more expressive
No functional change.
2021-02-19 22:27:49 +00:00
rillig
468e9e00fb lint: rename tenum_t and its members to be more expressive 2021-02-19 22:20:18 +00:00
rillig
e55559f87e lint: rename str_t and its members to be more expressive
No functional change.
2021-02-19 22:16:12 +00:00
rillig
3fe220d520 lint: replace cryptic sym.s_rimpl with expressive name
No functional change.
2021-02-19 21:35:44 +00:00
nia
8b022a822c patch: make '-V none' work in the expected way
Internally the code confuses the concept of "the user doesn't want
a backup file" and "the user hasn't defined a type of backup file".

Introduce a new "undefined" backup type to serve the purpose "none"
previously did, and make "none" not generate backup files, as expected.

http://mail-index.netbsd.org/tech-userlevel/2021/02/19/msg012901.html

XXX pullup?
2021-02-19 17:46:53 +00:00
rillig
dbf7816e85 lint: fix build in tools mode 2021-02-19 14:44:29 +00:00
rillig
746e9c89cf lint: warn about mismatch in getopt handling 2021-02-19 12:28:56 +00:00
rillig
ded935ea33 videoctl: remove unnecessary code for unknown option -h
The generated binary stays the same.
2021-02-19 11:39:11 +00:00
christos
28a08f1a77 Add examples (Fernando Apesteguía at FreeBSD) 2021-02-18 18:27:24 +00:00
christos
f6eeb08754 Remove the "original line"
Fix lint comment
2021-02-18 18:06:02 +00:00
wiz
6e7948c2ad New sentence, new line. 2021-02-18 18:02:09 +00:00
christos
ca4875f097 Add support for password protected zip files (Alex Kozlov)
Also some KNF
2021-02-18 17:58:51 +00:00
christos
f821809059 Build with linux/glibc (Alex Kozlov) 2021-02-18 17:05:51 +00:00
christos
6dd7d998a4 mention zipx, from Alex Kozlov 2021-02-18 17:04:39 +00:00
christos
af632fea2b add O_CLOEXEC 2021-02-17 21:09:39 +00:00
rillig
e14d525678 make: clean up VarAdd, Var_Delete, Var_ReexportVars
No functional change.
2021-02-16 19:46:15 +00:00
rillig
d78a4ea36f make: document the bad state in which the test varcmd.mk is 2021-02-16 19:43:09 +00:00
rillig
458f6744b0 make: test exporting a variable that itself depends on a subprocess
When the point that "isn't going to end well" is reached, the stacktrace
is quite long but still reasonable:

main
main_ReadFiles
ReadAllMakefiles
ReadMakefile		directive-export.mk
Parse_File
ParseLine				# line 3 has: _!= :;:
ParseVarassign
Parse_DoVar
VarAssign_Eval
VarAssign_EvalShell			# because of the '!='
Cmd_Exec		:;:
Var_ReexportVars			# before starting the subprocess
ExportVar		EMPTY_SHELL
ExportVarEnv				# was only marked for export
Var_Subst		${EMPTY_SHELL}	# to get the value to export
VarSubstExpr		${EMPTY_SHELL}
Var_Parse		${EMPTY_SHELL}
Var_Subst		${:sh}		# since EMPTY_SHELL= ${:sh}
VarSubstExpr		${:sh}
Var_Parse		${:sh}
ApplyModifiers
ApplySingleModifier	:sh
ApplyModifier
ApplyModifier_SunShell	:sh
Cmd_Exec		""		# empty command
Var_ReexportVars
ExportVar		EMPTY_SHELL
ExportVarEnv				# skipping this edge case
2021-02-16 19:01:18 +00:00
rillig
f04cb12800 make: clarify what .export ${:U} means 2021-02-16 18:12:46 +00:00
rillig
a017c69c81 make: demonstrate inconsistency in .undef of an exported variable 2021-02-16 18:02:19 +00:00
rillig
a75802fa16 make: clean up and update comments in var.c
During the refactorings of the last months, several comments have become
outdated, some are now redundant since the code is as clear as the
comment, and some code benefits from a bit of explanation.
2021-02-16 17:41:23 +00:00
rillig
b3224a45e4 make: use bit-shift expressions for VarFlags constants
These are easier to read than hex constants.

There was no need to skip bits 2 and 3 (there were no constants for 0x04
and 0x08).  Close this gap, to avoid confusing future readers.  Keep the
relative order of the flags since that affects the debug output of -dv.

No functional change.
2021-02-16 16:33:40 +00:00
rillig
6e5fc7f457 make: rename constants for VarFlags
The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.
2021-02-16 16:28:41 +00:00
rillig
6544f8c037 make: sync comment about duplicated code with reality
There are only very few places in var.c that contain really duplicate
code anymore.

There is still lots of _almost_ duplicate, for example the code for
parsing variable modifiers.  It differs subtly in behavior:

*   The modifiers ':M' and ':N' use '$$' to escape a '$' sign, while
    almost all other modifiers use '\$' for this purpose.

*   The modifiers ':M', ':N', ':S', ':@' and several others parse
    balanced parentheses and braces, allowing '(' to '}' to match.
    The modifiers ':D' and ':U' only treat the end character special but
    not the other 3 of '(){}'.

*   When parsing the modifier ':S' but not evaluating it, the code for
    nested variable expressions is parsed differently from when it is in
    evaluation mode (VARE_WANTRES).  This applies to an outer ':S'
    modifier and an inner ':D' or ':M' modifier.

Since these inconsistencies affect the behavior in edge cases and some
users of make might depend on it, they cannot be fixed by
behavior-preserving refactorings.
2021-02-16 16:14:27 +00:00
rillig
ffd4a447e8 make: rename ExprDefined constants for debug logging 2021-02-15 18:23:32 +00:00
rillig
70b237ca8a make: rename ExprStatus to ExprDefined
The type describes the definedness of an expression, not a general
status, therefore the new name is more precise.

The constants are renamed as well since their prefix 'VES' does not
match the type name anymore, it was correct 3 days ago when the type was
still named VarExprStatus.  The name VES_NONE was misleading since
'none' does not describe its actual effect.  That name came from the
time when the status was a bit set, and 'none' simply meant 'none of the
bits are set'.

The names used in debug logging will be renamed in a follow-up commit,
to demonstrate that the changes in this commit indeed have no functional
change, especially not the change from '!=' to '==' in line 4304.

No functional change.
2021-02-15 18:21:13 +00:00
rillig
2be3d48f35 make: update comments for Expr, amending the previous commit 2021-02-15 17:59:08 +00:00
rillig
8c6543bd32 make: split parameters for evaluating variable expressions
The details of how variable expressions are evaluated is controlled by
several parameters: startc and endc differ for $(VAR) and ${VAR}, the
value of the expression can be interpreted as a single big word, and
when joining several words (such as with ':M' or ':S'), there may be a
custom word separator (defined with ':ts*').

The scope of half of these parameters is the whole variable expression,
the other half of the parameters are reset after each chain of indirect
modifiers.  To make this distinction obvious in the code, extract Expr
from ApplyModifiersState.  Previously, these details were hidden in how
parameters are passed and restored among ApplyModifiersIndirect and
ApplyModifiers.

The changes in the individual ApplyModifier functions are numerous but
straight-forward.  They mostly replace 'st' with 'expr'.

The changes in ApplyModifiers and ApplyModifiersIndirect are more
subtle.  The value of the expression is no longer passed around but is
stored in a fixed location, in Expr, which makes it easier to reason
about memory management.

The code in ApplyModifiers after 'cleanup' looks quite different but
preserves the existing behavior.  Expr_SetValueRefer is nothing else
than the combination of FStr_Done followed by FStr_InitRefer.  Storing
exprStatus back at the end was responsible for passing the definedness
of the expression after applying the indirect modifiers back to the
outer ApplyModifiersState.  The same effect is now achieved by having
Expr.status with a wider scope.

No functional change.
2021-02-15 17:44:09 +00:00
rillig
a82a3ee139 make: improve comments in test for expansions in .for loops 2021-02-15 07:58:19 +00:00
rillig
9478d5a896 make: fix typo in comment 2021-02-15 07:42:35 +00:00
rillig
5dd7b87974 lint: remove redundant comment
That comment was useful when there was no function is_null_pointer.
Back then, the code for testing a null pointer was written in-line,
which made it really hard to see what's going on.  This is no longer the
case.
2021-02-15 07:40:18 +00:00
rillig
db5ee305d0 lint: extract typeok_colon_pointer from typeok_colon
The subtype information is now only accessed if both operands are
actually pointers.

No functional change.
2021-02-15 07:36:40 +00:00
rillig
0308def1fc make: clean up code and comments around ModifyWord
In ModifyWords, there is no "passed string" anymore since that function
now directly operates on the expression value.

While here, improve the documentation of ModifyWordsCallback and rename
it to ModifyWordProc, focusing on its purpose instead of where it is
used.
2021-02-15 06:46:01 +00:00
rillig
449355e949 make: clean up memory management in evaluation of expressions
The condition "st->newValue.str != val" in ApplySingleModifier made the
memory management look more complicated than it really was.  Freeing an
object based on another object's value is harder to understand than
necessary.

To fix this, the "current value" of the expression is now stored in
ApplyModifiersState, and it gets updated in-place by the ApplyModifier
functions.  This reduces the number of parameters for the ApplyModifier
functions.

Accessing the current value of the expression is now more verbose than
before (st->value.str instead of the simple val).  To compensate for
this verbosity, ApplyModifiersIndirect is now much easier to understand
since there is no extra "current value" floating around.

There is still room for improvement.  In ApplyModifiers, passing an FStr
in and returning another (or possibly the same) makes it difficult to
understand memory management.  Adding a separate Expr type that outlives
the ApplyModifiersState will make this easier, in a follow-up commit.
2021-02-14 22:48:17 +00:00
rillig
6118cc0289 make: reduce redundant code around ModifyWords
The result of ModifyWords had been passed to Expr_SetValueOwn in all
cases.  The last argument to ModifyWords had always been st->sep.
2021-02-14 21:54:42 +00:00
rillig
370ad03170 make: clean up FStr and MFStr memory in cleanup mode 2021-02-14 21:32:58 +00:00
rillig
f9dcbbe347 make: print error about failed shell command before overwriting variable
Memory management of the value of variable expressions is currently more
complicated than necessary.  It is the responsibility of ApplyModifiers,
even though conceptually the value belongs to an expression, so it
should rather be in Expr.  Right now, this is an alias for
ApplyModifiersState, but that will change soon.

When that is done, there will no longer be a "current value" and a "new
value", only a single "value" of an expression.  At that point, before
Expr_SetValueOwn will overwrite the old value with the output of the
shell command, the error message needs to refer to the latter.
2021-02-14 20:22:30 +00:00
rillig
fe211a10c7 make: add test for the variable modifier ':sh' 2021-02-14 20:16:17 +00:00
rillig
bc023be5d8 make: clean up ValidShortVarname
The switch statement was hard to read, especially the "break" that
needed a comment since it was effectively a "continue".
2021-02-14 18:59:36 +00:00
rillig
d0e45fa73b make: clean up ParseVarnameShort
Single-character short variable expressions such as $V neither have a
starting character nor an ending character.  The only interesting
character forms the complete variable name.

No functional change.
2021-02-14 18:55:51 +00:00
rillig
52e5117b68 make: rename VarExprStatus to ExprStatus
It is only used in var.c so there is no need to use a prefix.
2021-02-14 18:21:31 +00:00
rillig
73654455e2 make: add test for indirect ':U' modifier
Unlike ':ts' and ':tW', the effects of ':U' are visible even after the
modifiers from the nested expression have been applied.  These subtle
details, like many others, are not documented in the manual page.
2021-02-14 17:47:33 +00:00
rillig
b37a044ff1 make: revert part of previous commit
That code was not ready yet.
2021-02-14 17:27:25 +00:00
rillig
62b202434d make: update line numbers in expected test output
The documentation from the previous commit added a few lines.
2021-02-14 17:24:47 +00:00
rillig
a6cd09f3da make: document since when indirect modifiers are supported 2021-02-14 17:22:37 +00:00
rillig
7d5825c040 make: add more tests for edge cases in evaluating variable expressions
As a preparation for refactoring the code around variable expressions,
there need to be a few tests for indirect variable modifiers since these
were not covered before.

Indirect modifiers may include ':ts' and ':tW', which change the
interpretation of the variable expression in small details.  The scope
of these changes is limited to the indirect modifier, any evaluations
outside this indirect modifier are unaffected.

The changes to the .exp file are mostly line number changes, plus a
demonstration of a newly found bug, where an expression is evaluated
successfully despite producing a parse error.
2021-02-14 16:12:46 +00:00
rillig
2606f6962c make: add functions for assigning the value of an expression
The plan is to have only the "current value" of the expression as a
member, not the "new value".  To do this consistently and get the memory
management right, there must be a single place (or two) where the value
of the expression is updated.

No functional change.
2021-02-14 13:53:28 +00:00
rillig
733483f46f make: rename ApplyModifiersState_Define to Expr_Define
The type name ApplyModifiersState was only intended as a working draft,
its name is too long and its scope a little too narrow.

Applying the modifiers is the main part of evaluating a variable
expression, and the scope of that type will be extended to parsing the
name of the expression as well.  This will hopefully reduce the number
of parameters, which is currently at 14.

No functional change.
2021-02-14 13:46:01 +00:00
rillig
fe28e4c2f6 make: fix TMPDIR in unit-tests
Combining the assignment operator ':=' with the variable modifier ':U'
on the same variable does not work as intended.  At the point where the
':U' is evaluated, the variable is guaranteed to be defined because the
code in VarAssign_EvalSubst says so.
2021-02-14 13:24:45 +00:00
rillig
635f837c66 make: condense the code for parsing :S and :C modifiers
No functional change.
2021-02-14 12:35:27 +00:00
rillig
35c51735d0 make: rearrange some comments to make them easier to spot 2021-02-14 12:24:53 +00:00
rillig
3b4441442a make: document purpose of stepping back in the parser
In ApplyModifier_Assign there was no need to compute the delimiter from
st->startc since that has already be done at that point.
2021-02-14 12:16:13 +00:00
rillig
c8f6aa36d9 make: add test for ::= modifier enclosed in parentheses 2021-02-14 12:14:37 +00:00
rillig
36505cea47 make: fix typo in comment in test 2021-02-07 17:17:25 +00:00
rillig
6179212f34 make: sync comment for ApplyModifier_Assign with reality
In compat mode, empty shell commands are handled correctly since at
least 1993.

In jobs mode, empty shell commands are handled correctly since at least
job.c 1.93 from 2005-06-16.

The only place where empty shell commands led to problems was in
Cmd_Exec, but that has nothing to do with the example from the comment.
See var-op-shell.mk for more details.
2021-02-06 21:40:14 +00:00
sjg
a487ed8256 Avoid test failures when more than one user run them.
Use a private  TMPDIR
a subdir of .OBJDIR if using it
otherwise /tmp/uid${.MAKE.UID}
2021-02-06 18:26:03 +00:00
dbj
0b6b34c295 tsort: fix typo in comment 2021-02-06 16:02:16 +00:00
sjg
a66bf246af Use plain kill to test signaled child
Recent update to Darwin18 make the test using kill -14
stop working.

Reviewed by: rillig
2021-02-06 04:55:08 +00:00