Commit Graph

174 Commits

Author SHA1 Message Date
rillig dd8677cc23 indent: inline input-related macros
No binary change.
2023-12-03 21:44:42 +00:00
rillig 1cdfe3a93c indent: use line number of the token start in diagnostics
Previously, the line number of the end of the token was used, which was
confusing in debug mode.
2023-12-03 21:03:58 +00:00
rillig 12dc98af47 indent: fix scanning of no-wrap comments (since 2021.11.07.10.34.03)
The "refactoring" back then tried to be too clever.
2023-06-23 20:59:04 +00:00
rillig c4d462617d indent: only add blank lines before actual block comments 2023-06-18 07:32:33 +00:00
rillig 926f8bd544 indent: remove support for backspace in code and comments
The C code in the whole tree does not contain a single literal
backspace.
2023-06-18 07:10:24 +00:00
rillig 519ec34df3 indent: clean up
Extract duplicate code for handling line continuations.

Prevent theoretic undefined behavior in strspn, as inp.s is not
null-terminated.

Remove adding extra space characters when processing comments, as these
are not necessary to force a line of output.

No functional change.
2023-06-17 23:03:20 +00:00
rillig 8e0980dcd7 indent: miscellaneous cleanups
No binary change.
2023-06-17 22:28:49 +00:00
rillig 37a177106a indent: rename a field of the parser state
The previous name 'comment_in_first_line' was misleading, as it could
mean that there was a comment in the first line of the file.

No functional change.
2023-06-16 11:27:49 +00:00
rillig 641fe74526 indent: allow more than 20 nested parentheses or brackets 2023-06-14 14:11:28 +00:00
rillig ed7b435925 indent: clean up handling of comments
One less moving part in the parser state.

No functional change.
2023-06-14 09:31:05 +00:00
rillig bf8496de58 indent: remove another flag from parser state
When processing a comment, the flag ps.next_col_1 was not used for the
next token, but for a line within a comment.  As its scope was limited
to a single comment, there is no need to store it any longer than that

No functional change.
2023-06-14 08:36:51 +00:00
rillig 61c5d6b6d0 indent: remove a redundant flag from the parser state
No functional change.
2023-06-14 08:25:15 +00:00
rillig b3bf029a38 indent: miscellaneous cleanups 2023-06-10 16:43:55 +00:00
rillig 9e1c17039c indent: in debug mode, null-terminate buffers 2023-06-10 12:59:31 +00:00
rillig 338e471fd4 indent: rename and sort variables in parser state
No functional change.
2023-06-10 06:38:20 +00:00
rillig 545ff05aaa indent: format its own code 2023-06-09 07:20:30 +00:00
rillig 0fcafc89fc indent: preserve block comments with delimiters 2023-06-09 07:18:52 +00:00
rillig 2ecab2e1dd indent: express more clearly how delimited and no-wrap comments relate
No functional change.
2023-06-09 07:04:51 +00:00
rillig 9f9251e958 indent: right-trim single-line comments 2023-06-06 07:51:35 +00:00
rillig 84ea33d3df indent: clean up formatting of comments
No functional change.
2023-06-06 07:14:20 +00:00
rillig c147dd9d85 indent: simplify handling of comments
No functional change.
2023-06-06 06:59:39 +00:00
rillig 6f1b23d83f indent: split printing of comments into smaller functions
No functional change.
2023-06-06 06:51:44 +00:00
rillig c6e9afe1fe indent: remove read pointer from buffers that don't need it
The only buffer that needs a read pointer is the current input line in
'inp'.

No functional change.
2023-06-04 20:51:19 +00:00
rillig 3d214a88cc indent: fix out-of-bounds read when reading a comment 2023-06-04 20:23:12 +00:00
rillig c99fb69e72 tests/indent: fix outdated or wrong comments 2023-05-21 10:18:44 +00:00
rillig 4fb425a29f indent: extract the output state from the parser state
The parser state depends on the preprocessing lines, the output state
shouldn't.
2023-05-20 11:53:53 +00:00
rillig 5a9a628018 indent: implement blank line above block comment 2023-05-20 11:19:17 +00:00
rillig 2d18db1bfc indent: manually wrap overly long lines
No functional change.
2023-05-18 05:33:27 +00:00
rillig 3bf5120b21 indent: switch to standard code style
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-18 04:23:03 +00:00
rillig 6c7dba2d21 indent: directly access the input buffer
No functional change.
2023-05-16 13:26:26 +00:00
rillig 81c7fd789d indent: remove support for form feed characters inside a line
Form feeds are occasionally used to split code into pages, and this use
is still supported.  Having a form feed in the middle of a line is
exotic.
2023-05-16 11:32:01 +00:00
rillig 2aaa93dadf indent: fix line wrapping of comments to the right of code 2023-05-15 19:55:51 +00:00
rillig c5f73abc75 indent: let indent format its own code
With manual corrections, as indent does not properly indent multi-line
'?:' expressions nor multi-line controlling expressions.
2023-05-15 09:22:53 +00:00
rillig 9a2185a149 indent: clean up memory and buffer management
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-15 07:28:45 +00:00
rillig 506e3bec5c indent: only null-terminate the buffers if necessary
The only case where a buffer is used as a C-style string is when looking
up a keyword.

No functional change.
2023-05-14 22:26:37 +00:00
rillig 942c4f27e1 indent: shorten variable names for indenting comments
No functional change.
2023-05-14 18:05:52 +00:00
rillig 1304bdca7f indent: fix handling of multiple block comments in a line 2023-05-14 17:53:38 +00:00
rillig 217e4d847d indent: in comments, keep a leading tab
This kind of comments is used for the CVS IDs at the top of files.
2023-05-14 17:13:37 +00:00
rillig 0cd0431ee6 indent: fix vertical spacing after declarations
A comment is not supposed to change the state of the 'blank line after
declaration', but it did.  The initialization of saved_just_saw_decl was
wrong though since it tried to capture the previous value after it had
already been overwritten.
2023-05-14 16:47:06 +00:00
rillig eb14db9dab indent: reduce code for scanning tokens
The input line is guaranteed to end with '\n', so there's no need to
carry another pointer around.

No functional change.
2023-05-14 14:14:07 +00:00
rillig 0081badbbf indent: remove foreign RCS IDs 2023-05-14 12:12:02 +00:00
rillig ae0013d277 indent: use enum instead of magic numbers for tracking declarations
No functional change.
2023-05-13 14:30:48 +00:00
rillig ae2b6a8fde indent: rename struct fields for buffers
No binary change except for assertion line numbers.
2023-05-13 12:31:02 +00:00
rillig 0cdf93c9f3 indent: remove statistics
The numbers from the statistics were wrong.
2023-05-12 10:53:33 +00:00
rillig d54ae284ce indent: remove broken code for handling blank lines
This fixes several bugs where blank lines were erroneously added or
removed, treating these old bugs for new bugs in different places.
These new bugs are expected to be easier to fix, as the old bugs will
not interfere anymore.
2023-05-11 18:13:55 +00:00
rillig 115b3170bc indent: clean up control flow, remove Capsicum
No functional change.
2022-05-09 21:41:49 +00:00
rillig c3f896e4dd indent: group global variables related to output control
No functional change.
2022-04-23 06:43:22 +00:00
rillig 9a2baf090b indent: rename dump functions to output
No functional change.
2021-11-27 18:37:17 +00:00
rillig 80501c8f97 indent: add buf_add_range for adding characters to a buffer
No functional change.
2021-11-26 15:18:18 +00:00
rillig 1039243a64 indent: make fits_in_one_line independent of ps
This makes it easier to understand the function. Having the dependency
to the input line handling is already complicated enough.

No functional change.
2021-11-25 21:01:32 +00:00