summaryrefslogtreecommitdiff
path: root/usr.bin/indent/parse.c
AgeCommit message (Collapse)Author
2023-06-18indent: untangle code for handling the statement indentationrillig
The expression 'psyms.level-- - 2' did too much in a single line, so extract the '--' to a separate statement, to highlight the symmetry between the 'sym' and 'ind_level' code. No functional change.
2023-06-17indent: miscellaneous cleanupsrillig
No binary change.
2023-06-14indent: clean up the code, add a few testsrillig
2023-06-14indent: allow more than 128 brace levelsrillig
2023-06-14indent: fix out-of-bounds read when reducing a statementrillig
Since parse.c 1.73 from today. The parser symbol psym_stmt_list that was removed in that commit acted as a stop symbol, so that psyms_reduce_stmt would save a memory access.
2023-06-14indent: clean up array indexing for parser symbolsrillig
With 'top' pointing to the actual top element, the array was indexed in the closed range from 0 to top. All other arrays are indexed by the usual half-open interval from 0 to len. No functional change.
2023-06-14indent: merge parser symbols for stmt and stmt_listrillig
They were handled in exactly the same way.
2023-06-10indent: fix stack overflow, add more testsrillig
For several parser symbols, 2 symbols are pushed in a row, which led to an out-of-bounds write.
2023-06-10indent: miscellaneous cleanupsrillig
2023-06-09indent: format its own coderillig
2023-06-07indent: extract the stack of parser symbols to a separate structrillig
No functional change.
2023-06-06indent: sort functions in call orderrillig
No functional change.
2023-06-06indent: compute indentation of 'case' labels on-demandrillig
One less moving part to keep track of. No functional change.
2023-06-05indent: rename variables, clean up commentsrillig
No binary change.
2023-06-04indent: track the kind of '{' on the parser stackrillig
2023-06-03indent: clean up handling of brace indentationrillig
No functional change.
2023-06-02indent: fix formatting of declarations with preprocessing linesrillig
2023-05-23indent: split debug output into paragraphsrillig
The paragraphs separate the different processing steps: getting a token from the lexer, processing the token, updating the parser state, sending a finished line to the output.
2023-05-18indent: manually wrap overly long linesrillig
No functional change.
2023-05-18indent: switch to standard code stylerillig
Taken from share/misc/indent.pro. Indent does not wrap code to fit into the line width, it only does so for comments. The 'INDENT OFF' sections and too long lines will be addressed in a follow-up commit. No functional change.
2023-05-16indent: allow comments in column 1 to be formattedrillig
2023-05-15indent: format its own code, extend some commentsrillig
With manual corrections, as there are still some bugs left. No functional change.
2023-05-15indent: remove redundant include linesrillig
2023-05-15indent: clean up memory and buffer managementrillig
Remove the need to explicitly initialize the buffers. To avoid subtracting null pointers or comparing them using '<', migrate the buffers from the (start, end) form to the (start, len) form. This form also avoids inconsistencies in whether 'buf.e == buf.s' or 'buf.s == buf.e' is used. Make buffer.st const, to avoid accidental modification of the buffer's content. Replace '*buf.e++ = ch' with buf_add_char, to avoid having to keep track how much unwritten space is left in the buffer. Remove all safety margins, that is, no more unchecked access to buf.st[-1] or appending using '*buf.e++'. Fix line number counting in lex_word for words that contain line breaks. No functional change.
2023-05-14indent: remove foreign RCS IDsrillig
2023-05-13indent: move debugging code to separate filerillig
No functional change.
2023-05-12indent: rename placeholder symbol for parser stackrillig
No functional change outside debug mode.
2023-05-12tests/indent: test pushing the placeholder symbol to the parser stackrillig
2023-05-12indent: condense code for handling spaced expressionsrillig
No functional change outside debug mode.
2023-05-11indent: remove buggy code for swapping tokensrillig
It is not the job of an indenter to swap tokens, even if it's only about placing comments elsewhere. The code that swapped the tokens was complicated, buggy and impossible to understand. In -br (brace right) mode, indent no longer moves a '{' from the beginning of a line to the end of the previous line, as that was handled by the token swapping code as well. This change is unintended, but it will be easier to re-add that now that the code is simpler.
2022-04-22indent: remove FreeBSD IDsrillig
Most of the IDs were empty anyway.
2021-11-07indent: various cleanupsrillig
Make several comments more precise. Rename process_end_of_file to process_eof to match the token name. Change the order of assignments in analyze_comment to keep the com_ind computations closer together. In copy_comment_wrap, use pointer difference instead of pointer addition to stay away from undefined behavior. No functional change.
2021-10-29indent: remove redundant comments, remove punctuation from debug logrillig
The comment about 'null stmt' between braces probably meant 'no statements between braces'. The comments at psym_switch_expr only repeated what the code says or had been outdated 29 years ago already since opt.case_indent does not have to be 'one level down'. In the debug log, the quotes around the symbol names are not necessary after a ':'. The parse stack also does not need this much punctuation. Reducing a do-while loop to nothing instead of a statement saves a few CPU cycles. It works because after each lbrace, a stmt is pushed to the parser stack. This stmt can only ever be reduced to a stmt_list but never be removed.
2021-10-29indent: remove redundant commentsrillig
The comments only repeated what the constants for the parser symbols already express in their names. In the past, the names of these constants were inconsistent and misleading; back then, it made sense to make the comments express the actual meaning of the constants.
2021-10-29indent: reduce indentation in parse, extract decl_levelrillig
No functional change.
2021-10-28indent: clean up indentation, comments, reducerillig
No functional change.
2021-10-28indent: clean up comments and function namesrillig
Having accurate names for the lexer symbols and the parser symbols makes most of the comments redundant. Remove these. Rename process_decl to process_type, to match the name of the corresponding lexer symbol. In this phase, it's just a single type token, not a whole declaration. No functional change.
2021-10-26indent: run indent on its own source coderillig
With manual corrections afterwards, to compensate for the remaining bugs in indent. Without the type definitions in .indent.pro, the opening braces of the functions kw_name and lexi_alnum would not be at the beginning of the line.
2021-10-25indent: do not output token in debug moderillig
When the parse stack is manipulated, the text of the token is not relevant anymore and may even be confusing, for example when parsing if_expr, the token may contain "}".
2021-10-25indent: rename search_brace to search_stmtrillig
No functional change.
2021-10-25indent: split type token_type into 3 separate typesrillig
Previously, token_type was used for 3 different purposes: 1. symbol types from the lexer 2. symbol types on the parser stack 3. kind of control statement for 'if (expr)' and similar statements Splitting the 41 constants into separate types makes it immediately clear that the parser stack never handles comments, preprocessing lines, newlines, form feeds, the inner structure of expressions. Previously, the constant switch_expr was especially confusing since it was used for 3 different purposes: when returned from lexi, it represented the keyword 'switch', in the parser stack it represented 'switch (expr)', and it was used for a statement head as well. The only overlap between the lexer symbols and the parser symbols are '{' and '}', and the keywords 'do' and 'else'. To increase confusion, the constants of the previous token_type were in apparently random order and before 2021, they had cryptic, highly abbreviated names. No functional change.
2021-10-24indent: split kw_do_or_else into separate constantsrillig
It was unnecessarily confusing to have the token types keyword_do_else, keyword_do and keyword_else at the same time, without any hint in what they differed. Some of the token types seem to be used by the lexer while others are used in the parse stack. Maybe all token types can be partitioned into these groups, which would suggest to use two different types for them. And if not, it's still clearer to have this distinction in the names of the constants. No functional change.
2021-10-24indent: run indent on its own source coderillig
With manual corrections afterwards. Indent still does not get extra_expr_indent correctly, it also indents global variables after tagged declarations too deep. No functional change.
2021-10-20indent: rename parser stack variablesrillig
No functional change.
2021-10-08indent: clean up comments, parentheses, debug messages, boolean operatorrillig
No functional change.
2021-10-08indent: clean up 'parse', add test for dangling elserillig
No functional change.
2021-10-07indent: rename opt.btype_2 to brace_same_linerillig
No functional change.
2021-10-07indent: let the code breathe a bit by inserting empty linesrillig
No functional change.
2021-10-07indent: clean up commentsrillig
No functional change.
2021-10-07indent: remove redundant commentsrillig
No functional change.