summaryrefslogtreecommitdiff
path: root/usr.bin/make/for.c
AgeCommit message (Collapse)Author
2023-06-01make: add more details to debug logging of .for loopsrillig
2023-06-01make: shorten function names, clean up commentsrillig
No functional change.
2023-05-09make: skip syntactically wrong .for loopsrillig
When a .for loop cannot be interpreted correctly, for example when there are no iteration variables or the number of words doesn't match the iteration variables, skip the body of the .for loop instead of interpreting it once.
2023-05-08make: disallow characters like '$' in variable names in .for loopsrillig
Fixes PR 53146.
2023-05-08make: fix parsing of unusual line continuations in .for loopsrillig
2023-02-14make: clean up calls to Var_Substrillig
None of the calls to Var_Subst used the return value, and the return value was always VPR_OK. No functional change.
2022-09-03make: clean up handling of .break in .for loopsrillig
Move For_Break further up, as the functions in that file are sorted from small to big. The cast from size_t to unsigned int is required by lint. In parse.c, move the code into a separate function to keep ParseDirective small. Its only job is to parse the directive and then delegate to another function doing the actual work. In the manual page, remove empty lines. In the test, ensure that .break stops processing of the .for loop immediately; anything after the .break is not processed anymore. Replace ':=' with '=', as there is no need to evaluate '$i' early. Check the expected value in the .mk file instead of the .exp file, to keep the reading scope as small as possible.
2022-09-02make: add .break to terminate .for loop earlysjg
When .break is encountered within a .for loop it causes immediate termination. Outside of a .for loop .break causes a parse error. Reviewed by: christos
2022-06-12make: document ExprLen, which is part of a .for looprillig
No binary change
2022-02-04make: use unsigned int for line numbers everywhererillig
Previously, some line numbers were stored as signed int while others were stored as size_t. Since line numbers are never negative, use an unsigned type. Since the maximum file size for makefiles is 1 GB (see loadfile), unsigned int is large enough even on 64-bit platforms. Using a single data types reduces the number of type conversions. Using unsigned int improves compatibility with C90 (printf %u instead of %zu), which is needed by bmake, which is derived from usr.bin/make. No functional change.
2022-01-27make: clean up AddEscape for building the body of a .for looprillig
Adding 1 + len bytes but only incrementing the pointer by len bytes looked suspicious, so use the same expression in both places. No functional change.
2022-01-09make: extract low-level character operations into utility functionrillig
Suggested by nia. https://mail-index.netbsd.org/source-changes-d/2022/01/09/msg013564.html No functional change.
2022-01-09make: fix crash for newline in .for value in -dp mode (since yesterday)rillig
2022-01-09make: fix use-after-free in -dp mode (since yesterday)rillig
In a .for loop that contains an unclosed .if directive, Cond_restore_depth generates an error message. If stack traces are enabled using the option '-dp', the details of the .for loop are added to the stack trace, but at that point, the ForLoop had already been freed. To reproduce: make-2022.01.09.00.33.57 -r -f unit-tests/directive-for.mk -dp
2022-01-09make: remove redundant parameter from ForLoop_SubstVarLongrillig
The buffer of a .for loop is always either empty or ends with '\n'. A variable name consists of arbitrary non-whitespace characters. Therefore a variable name can never reach the end of the buffer. No functional change.
2022-01-08make: add details about .for loop variables to stack tracesrillig
The stack traces are enabled with the debug logging option '-dp'.
2022-01-08make: fix reported line numbers of continuation lines (since 2002)rillig
Previously, multi-line directives like '.info' or '.error' reported the line number of their last line instead of their first line, which is more usual. This also affected the debug log from '-dp'.
2022-01-08make: inline Buf_Clearrillig
No functional change.
2022-01-07make: clean up structure of For_Evalrillig
Put related decisions on the same indentation level, remove unnecessary negation, keep the code for the '.for' directive together. No functional change.
2022-01-07make: clean up handling of .for loopsrillig
Sort ForLoop members in natural reading order. Remove redundant condition in ForLoop_ParseItems; at that point, the number of variables is non-zero. Rename Buf_AddEscaped since that function is not part of the Buffer API, it is specific to .for loops. No functional change.
2022-01-07make: eliminate file-scope variable forLevelrillig
No functional change.
2022-01-07make: use simpler code for handling .for loopsrillig
Since the body of a .for loop is scanned from start to end, there is no need to remember the length of a variable name. Using memcmp for comparing the variable name was probably overkill since the variable names are usually very short, so rather compare them byte by byte. No functional change.
2022-01-02make: clean up handling of .for loops and .include directivesrillig
No functional change.
2022-01-02make: in .for loops, pass the body to be filled as parameterrillig
This is a preparation for cleaning up the code for loading and parsing files, especially the part for including other files and for .for loops. No functional change.
2022-01-01make: remove unused parameter from Parse_PushInputrillig
The parameter readMore was never NULL. No functional change.
2021-12-15make: format comments according to /usr/share/misc/stylerillig
Assisted by indent(1), with manual corrections due to its many remaining bugs. No functional change.
2021-12-12make: rename Parse_SetInput to Parse_PushInputrillig
The word 'set' sounded too much like it would replace the current file, but instead the file is pushed to the stack, and the previous file is continued later. No functional change.
2021-12-12make: rename ForLoop.sub_next to nextItemrillig
This matches the naming style of the other ForLoop members. No functional change.
2021-12-05make: inline Str_Words into .for loop handlingrillig
This saves one memory allocation and a bit of copying, per .for loop. No functional change.
2021-09-02make: rename for_var_len to ExprLenrillig
The text ${VAR} is not a variable, it's a variable expression. No functional change.
2021-09-02make: inline strchr call, make ForLoop_SubstBody clearerrillig
In ForLoop_SubstBody, GCC already merged the common subexpressions p[1] and p[-1], but that was difficult to see for humans as well. No functional change.
2021-09-01make: remove optimization for single-letter .for variablesrillig
Most .for loops have a single iteration variable. For these loops, the difference between the optimized and the unoptimized versions of the code is negligible. Remove the optimization since the comment for explaining it was almost larger than the code itself.
2021-06-25make: prevent newline injection in .for loopsrillig
When a value of a .for loop contained a literal newline, such as from the expression ${.newline}, that newline was passed verbatim to the "expanded current body" of the .for loop. There it was interpreted as a literal newline, which ended the current line and started a new one. This resulted in several syntax errors. In cases like these, print a more precise error message.
2021-06-24make: sprinkle constrillig
2021-04-03make: use C99 bool type instead of defining its ownrillig
No functional change.
2021-02-04make: rename some VAR constants to SCOPErillig
The word "context" does not fit perfectly to the variables that are associate with a GNode, as the context is usually something from the outside and the variables are more like properties inherent to the GNode. The term "global context" fits even less. Since the thing where variables are looked up is commonly named a scope, use that term instead. This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL and VAR_CMDLINE, plus a few very closely related comments. These are: GNode.vars (because of line breaks) GNode_Free (dito) varname-make_print_var_on_error.mk varname-make_print_var_on_error-jobs.mk The debug message in Var_Stats is left as-is since there is no unit test for it yet. The other renamings (variable names "context", "ctxt", as well as further comments) will be done in a follow-up commit.
2021-02-01make(1): clean up variable names and comments in .for loop coderillig
2021-01-30make(1): split Buf_Destroy into Buf_Done and Buf_DoneDatarillig
In all cases except one, the boolean argument to Buf_Destroy was constant. Removing that argument by splitting the function into two separate functions makes the intention clearer on the call site. It also removes the possibility for using the return value of Buf_Done, which would have made no sense. The function Buf_Done now pairs with Buf_Init, just as in HashTable and Lst. Even though Buf_Done is essentially a no-op, it is kept as a function, both for symmetry with Buf_Init and for clearing the Buffer members after use (this will be done only in CLEANUP mode, in a follow-up commit).
2021-01-25make(1): split For_Eval into separate functionsrillig
2021-01-25make(1): extract ForLoop_New to separate functionrillig
2021-01-25make(1): rename struct For to struct ForLooprillig
This removes the ambiguity whether For_Free is meant to be a module-exported function or a local function associate with that struct. Rename the affected functions as well.
2021-01-19make(1): remove do-not-format markers from commentsrillig
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-10make(1): consistently use boolean expressions in conditionsrillig
Most of the make code already followed the style of explicitly writing (ptr != NULL) instead of the shorter (ptr) in conditions. The remaining 50 instances have been found by an experimental, unpublished check in lint(1) that treats bool expressions as incompatible to any other scalar type, just as in Java, C#, Pascal and several other languages. The only unsafe operation on Boolean that is left over is (flags & FLAG), for an enum implementing a bit set. If Boolean is an ordinary integer type (the default), some high bits may get lost. But if Boolean is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2 defines that a conversion from any scalar to the type _Bool acts as a comparison to 0, which cannot lose any bits.
2021-01-09make(1): fix lint warningsrillig
2020-12-31make(1): fix undefined behavior in SubstVarLongrillig
A memcmp implementation that would check the start and end pointers first would have detected this possible out-of-bounds memory read.
2020-12-31make(1): make control flow in SubstVarLong of .for loops more obviousrillig
2020-12-31make(1): clean up SubstVarShort in .for loopsrillig
This function does not need to advance the parsing position, which removes duplicate code.
2020-12-31make(1): move detailed comment to ForSubstBodyrillig
2020-12-31make(1): extract ForSubstBody from ForReadMorerillig
This leaves ForReadMore with the single responsibility of interfacing with ReadMoreProc in Parse_SetInput.
2020-12-31make(1): rename ech to endcrillig
Focusing on the "end" is more important than on the data type "ch".