Commit Graph

17531 Commits

Author SHA1 Message Date
rillig
7ccd7b1468 lint: use macro for initializing keywords table
Since today, lint's strict bool mode requires initializers to have the
correct type.  The flags in kwtab are of type bool and were initialized
with an int, for brevity.  Keep the brevity and do the conversion from
int to bool in a macro.

By defining several macros for the different kinds of keywords, reduce
the clutter of having 2 additional zeroes per line.  The macros also
remove the redundancy and thereby the possible inconsistency of filling
the wrong fields since these depend on the token type.

No functional change.  The only change to the binary is due to the
changed line numbers in the calls to lint_assert.
2021-03-20 19:24:56 +00:00
rillig
e18860fa07 lint: use macro for encoding type information
In lint's strict bool mode, initialization must be of the correct type.
This affects the bool fields in ttab_t, which are initialized with int.
To keep the code brief, preserve these ints and let a macro do the
actual work of converting them to bool.

No change to the generated binary.
2021-03-20 18:59:00 +00:00
rillig
6a451d6268 lint: inline access to type properties in check_bad_enum_operation
No functional change.
2021-03-20 18:38:25 +00:00
rillig
10736dfe07 lint: in strict bool mode, check initialization as well
C99 6.7.8p11 says for initialization that "the same type constraints and
conversions as for simple assignments apply", so actually apply them.
(I had just forgotten this "operator" when I first implemented strict
bool mode.)
2021-03-20 17:18:50 +00:00
rillig
87876a2355 lint: rename ftflg to seen_fallthrough
One less abbreviation to remember when reading the code.

No functional change.
2021-03-20 16:16:32 +00:00
rillig
73790b7671 lint: make the calls to clear_warning_flags stand out less
Even though clear_warning_flags and its companions are implemented as
macros, they act like ordinary functions.  Do not distract the reader by
using uppercase names for them.

No functional change.
2021-03-20 16:11:12 +00:00
rillig
f5c815bc77 lint: clean up grammar for declaration after statement
No functional change.
2021-03-20 15:30:58 +00:00
rillig
fb9b10bc8d lint: fix check for declaration after statement in pre-C99 mode
The new code may not be the most beautiful, but it fixes all bugs that
occurred while testing message 327.  The grammar rules are taken from
C99 6.8.2, so it's no surprise they work well.
2021-03-20 15:28:07 +00:00
cheusov
736f809ed1 cmp.c: use C99 strtoll(3) instead of legacy strtoq(3) 2021-03-20 14:27:47 +00:00
rillig
daef7ea921 lint: properly name C99 in message about declaration after statement
Now that C99 has been released and published, there is no reason anymore
to refer to it as C9X.
2021-03-20 14:17:56 +00:00
rillig
b925668ec9 lint: use proper boolean literals instead of 0/1
The code in the C grammar is generated by yacc and is not checked by
lint's strict bool mode, therefore the replacement was done manually.

No change to the resulting change.
2021-03-20 13:53:28 +00:00
rillig
e4fa7e61a5 lint: update comment on setasm for C99
No functional change.
2021-03-20 13:25:31 +00:00
rillig
4f4415984d lint: reduce indentation and braces in merge_type_specifiers
No functional change.
2021-03-20 13:22:06 +00:00
rillig
e305d7be33 lint: extract adjusting of the storage class into separate function
No functional change.
2021-03-20 13:06:05 +00:00
rillig
1cf2c45884 lint: document the struct for declarations more precisely
No functional change.
2021-03-20 13:00:43 +00:00
rillig
d37415b4e9 lint: remove unnecessary '%prec T_COMMA' from grammar
My previous commit message was wrong in saying that the '%prec' was
necessary.  It is not necessary.

Most probably I misspelled the name of the grammar rule as opt_comma
instead of comma_opt, which would lead to the same number of conflicts
in the grammar plus a warning, but no build failure.
2021-03-20 11:33:50 +00:00
rillig
941875ba2d lint: join grammar rules for initialization
The '%prec T_COMMA' is necessary to avoid lots of parse errors in the
lint1 unit tests.  Curiously, further down in the grammar, for compound
literals, the '%prec T_COMMA' is not necessary, even though the context
looks very similar.

No functional change.
2021-03-20 11:24:49 +00:00
rillig
5f7e254669 lint: fix grammar for initialization
Previously, the grammar syntactically accepted the following code:

	int var = .member = 12345;

The designation '.member =' can only be used with brace-enclosed
initializers.
2021-03-20 11:05:16 +00:00
rillig
b61f069794 lint: align rule names in grammar with C99
No functional change.
2021-03-20 10:32:43 +00:00
rillig
80b7b20b36 lint: fix assertion failure after error in designation
In d_c99_init.c, the initialization of array_with_designator failed.
The designator '.member' from that initialization was not cleaned up
before starting the next initialization.
2021-03-20 08:54:27 +00:00
rillig
88e315e145 lint: replace segmentation fault with assertion failure 2021-03-20 08:16:30 +00:00
rillig
1a007aec0b lint: improve debug loggin for initialization 2021-03-19 18:17:46 +00:00
rillig
a8fb7d4818 lint: rename designator_pop_name to designator_shift_name
The entries are removed from the beginning, not from the end.

No functional change.
2021-03-19 17:37:57 +00:00
rillig
4c27df2433 lint: use standard form of statement macro for debug_node
No functional change.
2021-03-19 08:23:39 +00:00
rillig
5acb533d3d lint: rename in_bit to in_bits
No functional change.
2021-03-19 08:21:26 +00:00
rillig
527774e33b lint: rename tsize to type_size_in_bits
The shorter name size_in_bits was already taken by the function-like
macro with argument type tspec_t.

No functional change.
2021-03-19 08:19:24 +00:00
rillig
19ff95ceea lint: add reminder that C99 does not allow '{}' in initializer
No functional change.
2021-03-19 07:54:13 +00:00
rillig
0b45cbea90 lint: replace assertion in initialization with proper error message 2021-03-19 01:02:52 +00:00
rillig
674baf6361 lint: rename push_member and pop_member
These two functions are supposed to model the designator that is used
for initializing structs and arrays.  The implementation is still buggy
and does not work at all for C99 designators with multiple names, see
d_init_pop_member.c.

For now, just rename the functions to head in the right direction.

No functional change.
2021-03-19 00:55:02 +00:00
rillig
bde88c228c lint: extend documentation about initialization
No functional change.
2021-03-19 00:39:17 +00:00
rillig
89239b6de5 lint: split initstack_pop_item into separate functions
No functional change.
2021-03-19 00:19:32 +00:00
rillig
e2bce8130d lint: improve debug logging in initstack_push
No functional change outside debug mode.
2021-03-19 00:08:13 +00:00
rillig
dc7202e285 lint: split initstack_push into smaller functions
No functional change.
2021-03-18 23:45:20 +00:00
rillig
d68805fd28 lint: clean up control flow in initstack_push
No functional change.
2021-03-18 23:37:31 +00:00
rillig
77fa05a23f lint: extract extend_if_array_of_unknown_size from initstack_push
No functional change.
2021-03-18 23:23:40 +00:00
rillig
d30c5846db lint: replace undefined behavior during initialization with assertion
This only affects code that is already rejected by the compiler.
2021-03-18 22:51:32 +00:00
rillig
b4cc35448b lint: improve debug logging during initialization
No functional change outside debug mode.
2021-03-18 22:08:05 +00:00
rillig
5f25f85e8f lint: make the debug log for nodes more readable
The operator NAME has the name 'name', therefore no special case is
needed.

Having the words 'with type' in the message makes the message easier to
find from the debug log.  Given that the operator name is used unquoted,
the log message 'name: int value=111' was nearly impossible to find in
the code.

Replace the '()' with an actual word, to avoid any confusion about
whether the type name might be a function type without prototype.

Reduce the amount of '=' signs, instead use commas to separate the
properties of the node.

No functional change outside debug mode.
2021-03-18 22:05:33 +00:00
rillig
b1117d0cb9 lint: rename operator 'const' to 'constant'
The previous name could be too easily confused with the type qualifier
'const'.  The operator name is mainly used in the debug log, only
occasionally in the output.  Since 'constant' is not a "real" operator,
it probably doesn't occur in messages at all.
2021-03-18 21:56:34 +00:00
rillig
ebe3bde9bf lint: reword message about type mismatch in initialization
Using parentheses for quotes is unusual, furthermore the previous
message didn't follow proper grammar rules, sacrificing clarity for
brevity.
2021-03-18 21:26:56 +00:00
rillig
e82f0a6950 lint: reduce debug logging for initialization, update documentation
No functional change outside debug mode.
2021-03-18 20:55:58 +00:00
rillig
ce64b8cc18 lint: document how initialization works, improve debug logging
No functional change outside debug mode.
2021-03-18 20:22:50 +00:00
cheusov
37e902b261 join.c: print usage after warning "illegal option..." as it was originally intended 2021-03-18 19:47:41 +00:00
cheusov
47b5db6ce5 join.c: explicitly convert -1 to u_long in order to fix compiler warnings 2021-03-18 19:41:54 +00:00
cheusov
61b08b6410 ipcs.c: do not #include sys/inttypes.h header which is not necessary 2021-03-18 19:34:05 +00:00
cheusov
93a814dc9d find: use POSIX strtoll(3) instead of legacy strtoq(3) 2021-03-18 18:24:14 +00:00
cheusov
4e50b167d1 find: use POSIX type uint32_t instead of u_int32_t 2021-03-18 18:21:18 +00:00
cheusov
0dc4923bc1 cksum: use POSIX type uint32_t instead of u_int32_t 2021-03-18 18:12:35 +00:00
rillig
1250e70dfe lint: document the initialization of an object in more detail
This will help fixing the bugs that are currently demonstrated in
msg_168.c and d_struct_init_nested.c.
2021-03-18 14:58:44 +00:00
rillig
d8304c1dc3 lint: add debug logging for C99-style initialization of arrays
No functional change outside debug mode.
2021-03-17 15:45:30 +00:00
rillig
59329564e5 lint: move debug logging for the designator to the top of the code
The debugging code is needed by the soon-to-be-added proper handling of
array subscript initializers such as '.member[123].member = 12345'.

No functional change.
2021-03-17 15:37:42 +00:00
rillig
d07ef6733f lint: clean up documentation of dinfo_t
No functional change.
2021-03-17 02:24:06 +00:00
rillig
c026af7a30 lint: rename dinfo_t members to be more expressive
While here, sync redundant but diverging comments, split
multi-assignments and initialize the members in declaration order.

No functional change.
2021-03-17 02:18:03 +00:00
rillig
16ce4325a7 lint: move to_int_constant from the grammar to decl.c
This way, the code is covered by running 'make lint'.  The code from the
grammar is not covered, therefore it still uses int instead of bool in a
few places.

Inline the comparison functions for uint64_t.  These functions didn't
add any clarity to the code.

No functional change.
2021-03-17 01:53:21 +00:00
rillig
e61595b13a lint: move main part of idecl over to decl.c and rename it
No functional change.
2021-03-17 01:38:31 +00:00
rillig
ce90f2b2d5 lint: replace a call to LERROR with lint_assert
No functional change.
2021-03-17 01:22:55 +00:00
rillig
068b6bffae lint: rename 'toicon' to 'to_int_constant'
No functional change.
2021-03-17 01:19:50 +00:00
rillig
0351b7e6cb lint: rename 'blklev' to 'block_level'
No functional change.
2021-03-17 01:15:31 +00:00
rillig
923306e4b7 lint: rename 'parn' to 'paren' in the grammar
No functional change.
2021-03-17 01:07:33 +00:00
rillig
5850837c3b make: fix documentation for ModChain
The outer ModChain can be interrupted by an inner ModChain, but it
continues to exist.

No functional change.
2021-03-16 16:21:27 +00:00
rillig
ebbd921098 make: rename ApplyModifiersState to ModChain
The new name accurately describes the structural element that holds such
properties as the separator character and whether the expression value
is considered a single word.  The old name ApplyModifiersState was too
long and was meant as a placeholder anyway, when I introduced it in
var.c 1.236 from 2020-07-03.
2021-03-15 20:00:50 +00:00
rillig
ac07af747c make: improve documentation of ApplyModifiersState
No functional change.
2021-03-15 19:15:04 +00:00
rillig
a05498199d make: document an example for a 'chain of modifiers'
No functional change.
2021-03-15 19:02:57 +00:00
rillig
507bcc82b8 make: fix double varname expansion in the variable modifier '::='
This is an edge case that doesn't occur in practice since pretty much
nobody dares to use variable names that contain an actual '$' in their
name.  This is not about the fairly common VAR.${param} (as written in
the makefile), but instead about the variable whose name is literally
'VAR.${param}'.

The test demonstrates that after the fix, the variable name is taken
exactly as-is for the simple assignment modifier '::='.  There are no
such tests for the modifiers '::+=', '::!=' and '::?=', but that's ok.
The code in ApplyModifier_Assign would look assymetrical and suspicious
enough if one of these modifiers would expand its variable name and the
others wouldn't.
2021-03-15 18:56:37 +00:00
rillig
7eea180375 tests/make: demonstrate that the modifier '::=' expands the varname 2021-03-15 18:46:05 +00:00
rillig
87c62a5243 tests/make: convert varmod-loop to parse-time
In case of unexpected failures, this provides the line number of the
'.error' directive.
2021-03-15 17:54:49 +00:00
rillig
8d27738a97 tests/make: add position marker in test 'varmod-loop' 2021-03-15 17:11:08 +00:00
rillig
e9a9d1718c make: clean up documentation of ApplyModifiersState
No functional change.
2021-03-15 16:51:14 +00:00
rillig
c066baf306 make: fix documentation of Lst_MoveAll
In CLEANUP mode, was originally meant to track memory allocations but is
useful during debugging as well, initialize the list.  There is no
distinct constant representing an invalid pointer, otherwise that would
have been an even better choice.
2021-03-15 16:45:30 +00:00
rillig
c175751478 make: indent inline functions for lists
No functional change.
2021-03-15 16:06:05 +00:00
rillig
0983b9b566 make: clean up header for runtime type information for enums
An enum with 32 bits would lead to signed integer overflow anyway, so
that definition is not worth keeping even if it works on typical
2-complement platforms.

The definitions for 2, 4 and 8 enum have been unused for several months
now.

No functional change.
2021-03-15 16:00:05 +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
8699d6553b tests/make: document today's bug fixes in the test 2021-03-14 20:41:39 +00:00
rillig
3042e42091 make: fix documentation of VarFreeEnv
No functional change.
2021-03-14 20:23:29 +00:00
rillig
259019554f make: skip variable lookup for '::=' modifiers in parse-only mode
This is just to keep the code consistent among the various variable
modifiers.  The performance gain is negligible.

The actual assignment to the variable had already been skipped
previously.

No functional change.
2021-03-14 20:18:33 +00:00
rillig
96491d26ea make: separate parsing and evaluating for modifier '::='
No functional change.
2021-03-14 20:12:16 +00:00
rillig
d4faf73862 make: in parse-only mode, do not update the expression value in ':sh'
No functional change outside debug mode.  The other variable modifiers
behave in the same way.
2021-03-14 20:09:26 +00:00
rillig
96faeb06ee make: do not evaluate the ':O' modifiers in parse-only mode
No functional change in practical usage.  Theoretically this change can
be observed by looking at the generated random numbers for the ':Ox'
modifier, but the quality or exact sequence of these random numbers is
not guaranteed anyway.
2021-03-14 20:03:56 +00:00
rillig
f7a4d3a3e0 make: separate parsing and evaluating in the ':O' modifiers
No functional change.
2021-03-14 20:00:48 +00:00
rillig
812ef981d6 make: do not evaluate modifier ':[...]' in parse-only mode
In parse-only mode, variable expressions in the argument to that
modifier are not resolved.  This led to the error message about the 'Bad
modifier' in var-eval-short.mk.
2021-03-14 19:29:37 +00:00
rillig
ef2d559187 make: do not evaluate modifiers ':M' and ':N' in parse-only mode
No functional change outside debug mode (-dv for ModifyWord_Match).
2021-03-14 19:25:05 +00:00
rillig
aaaf8460b3 make: do not return unevaluated 'else' part from the ':?' modifier
No functional change outside debug mode.
2021-03-14 19:21:28 +00:00
rillig
91f10d43f6 tests/make: add test for the ':?' modifier in parse-only mode
The debug output for this scenario will change a bit in an upcoming
commit, but that will not affect anything outside the debug log.
2021-03-14 19:16:41 +00:00
rillig
c8091d0b16 make: do not evaluate ':gmtime' and ':localtime' in parse-only mode
No functional change.
2021-03-14 18:30:24 +00:00
rillig
99e5bcf513 make: don't evaluate several simple modifiers in parse-only mode
This affects the modifiers ':E', ':H', ':P', ':Q', ':R', ':T', ':hash',
':q', ':range', ':tl', ':ts', ':tu', and ':u'.  All these modifiers are
side-effect free.

Skipping the evaluation for these modifiers is purely for code
consistency and performance.

No functional change.
2021-03-14 18:23:44 +00:00
rillig
a1837566a4 make: skip strdup when parsing an irrelevant ':L' modifier
No functional change.
2021-03-14 18:10:57 +00:00
rillig
ae0a762a50 make: skip memcpy when parsing but not evaluating ':D' and ':U'
No functional change, just a tiny bit of performance improvement,
probably not even measurable.  Having the code nevertheless serves as a
copy-and-paste template for implementing other modifiers that might
perform more costly tasks.
2021-03-14 18:08:25 +00:00
rillig
a1747f17a6 make: only evaluate the ':@' modifier if the result is actually used
The test 'var-eval-short' had produced the output 'unexpected' before,
on stderr.  It had been generated by '${:Uword:@${FAIL}@expr@}' by
combining the following obscure "features" of make:

1.  the ':@' modifier loops over the words of the variable.  This
    modifier is not really obscure, it still takes some time to get used
    to it.

2.  the ':@' modifier allows a '$' sign in the variable name, which is
    useless in practice.

3.  the ':@' modifier creates a temporary loop variable in the global
    namespace.  Luckily there are only few collisions with other
    variable names since their naming conventions differ.

4.  after looping over the words of the expression, the temporary global
    loop variable is deleted, and at that point the '$' is expanded,
    being interpreted as the start of a variable expression.

5.  The ':@' modifier deleted the global variable even when it was
    called in parse-only mode (without VARE_WANTRES).

When the modifier ':@' was initially added to make in var.c 1.40 from
2000-04-29, Var_Delete didn't expand the variable name.  That feature
was added in var.c 1.174 from 2013-05-18, probably without thinking of
this very edge-casey combination of features.

This commit fixes item 5 from the above list.  The other obscurities
remain for now.
2021-03-14 18:02:44 +00:00
rillig
9ac0661025 make: eliminate common subexpression in ApplyModifier_Remember
No functional change.
2021-03-14 17:38:24 +00:00
rillig
71128ca3aa make: merge duplicate code in ApplyModifier_Remember
This way, parsing and evaluating the modifier is only written once in
the code.  The downside is that the variable name is allocated even if
VARE_WANTRES is not set, but since this modifier is so obscure and
seldom used this doesn't matter in practice.
2021-03-14 17:34:50 +00:00
rillig
0fc517c113 make: do not expand the variable name in the ':_' modifier
This edge case had been so obscure that even discovering this takes
quite some time and requires reading the source code of make.

The manual page doesn't document whether the variable name is expanded
or not, it doesn't even give an example.  When this obscure modifier was
initially added in var.c 1.210 from 2017-01-30, Var_Set always expanded
the variable name once, and there was no way around it.  Therefore this
expansion has probably been unintentional.
2021-03-14 17:27:27 +00:00
rillig
a442584d73 tests/make: demonstrate unintended edge case for the ':_' modifier 2021-03-14 17:14:15 +00:00
rillig
d905f14720 tests/make: convert test for ':_' modifier to parse time 2021-03-14 17:07:11 +00:00
rillig
64a393d8af make: only evaluate the ':_' modifier if the expression is needed
See var-eval-short.mk:46 for the test demonstrating this change.
Previously, the expression ${:Uword:_=VAR} was evaluated including all
its side effects even though it was in an irrelevant branch of the
condition.
2021-03-14 16:43:30 +00:00
rillig
c361e1ef2f make: return failure in TryParseIntBase0 for empty string
No functional change since the only caller of TryParseIntBase0 already
handles all possible parse errors.  Without this check, the code just
looked wrong though.
2021-03-14 16:03:04 +00:00
rillig
f3e066bf1b make: add test for edge case in modifier ':[...]'
TryParseIntBase0 wrongly returns successful for a string that does not
start with a number at all.  Its only caller, ApplyModifier_Words,
already handles all error cases properly.

No functional change.
2021-03-14 16:00:07 +00:00
rillig
c9c8cb6d43 make: separate parsing from evaluating for several modifiers
This aligns the implementation of these modifiers with the requirements
in the long comment starting with 'The ApplyModifier functions'.

No functional change.
2021-03-14 15:43:31 +00:00
rillig
54f9178de3 make: reduce indentation in ApplyModifier_SunShell
No functional change.
2021-03-14 15:24:37 +00:00