You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1: You should use the option nl_after_semicolon = true to get something better
at the main part.
2. The bug is present. I make now a new issue for it at #1352. A bugfix is coming soon.
3. The bugfix would not completely solve your problem, because uncrustify cannot put a newline at the "right" place as a human would do. It might be necessary to "prepare" your source a little bit before.
In fact, before applying uncrustify, I'm preprocessing the source files by removing as much extra space or newlines in C source as possible. So basically the whole code ends up on a single line, without blank lines or doubled spaces, except of course for preprocessor lines and line comments. Then I apply uncrustify five times. By doing this, I'm trying to achieve a canonical indentation, i.e. one code, one indentation. Even if the code style is modified, the indentation will revert it back to the canonical one.
So far it works quite well, except for the long initializer lines.
I run this new version through our code base, and could isolate a few issues.
Here one with list of hex uint8_t, where some hex are only one digit. In that case we see that uncrustify fails to indent correctly.
Also, here the config file that generates the buggy behavior:
code_width = 115 # unsigned number# This is the settings giving the bug
align_struct_init_span = 5 # unsigned number# These settings interacts with the bug.# Usually if set, changes whether the last line is splitted or not# sp_after_comma = force # ignore/add/remove/force# indent_columns = 4 # unsigned number# nl_after_semicolon = true # false/true
There are some spaces inserted after the commas after 5th value in the array initializer. I think these are due to alignment of the first 0x0 on the second line. Strangely uncrustify inserts two spaces (when one is enough), and keep doing so for the next column, although this is not necessary for the before-last column. In fact this problem gets even worse if you run uncrustify twice.
Some indentation are no longer applied for variable c[][8]. These are: alignment of the { with those on next line, use of tabs instead of space to align the next lines, and insertion of space to align the values in the array.
Also, after c[][8], the next variables are no longer indented. They are just listed on the same line, as in the original source file.
The second source file, b.c, is (same as in comment above):
The problems are the same as in a-uncrustified.c, except that we don't have the first issue (addition of an extra and persistent space after the comma).
There are bugs here.
The first one is an alignment bug: I am working on it.
The second one is a width bug. I propose a bugfix for it at #1378
Please test it and report.
Hello,
I just tested #1378 (I took version Uncrustify-0.65-300-d396bff) and indeed the width problem is gone for the test case b.c listed above. The output is perfect and equal to the expected output listed above. Thank you already!
For a.c, we still have issue (the alignment bug you mention - note that the code width, here 115, is well respected):
I just tried the latest commit on master (b5ce111) and the latest on your branch guymaurel/MoreAlign (40d2fa3), but I don't see any difference on the test case a.c. The output is identical with my latest tests above.
Yes. I work on it.
As we have many examples, please push (as attachment, not online) 3 files:
the source, the config and the expected output. To be sure we are working on the same data.
The problem is having a struct initializer inside a struct initializer inside something.
uncrustify can't yet deal with that.
The output are not predictable.
The problem is having a struct initializer inside a struct initializer inside something.
uncrustify can't yet deal with that.
The output are not predictable.
The problem is having a struct initializer inside a struct initializer inside something.
uncrustify can't yet deal with that.
The output are not predictable.
Activity
Some more logging to help the debug of uncrustify#1349
guy-maurel commentedon Sep 22, 2017
1: You should use the option
nl_after_semicolon = trueto get something betterat the
mainpart.2. The bug is present. I make now a new issue for it at #1352. A bugfix is coming soon.
3. The bugfix would not completely solve your problem, because uncrustify cannot put a newline at the "right" place as a human would do. It might be necessary to "prepare" your source a little bit before.
xeyownt commentedon Sep 22, 2017
Thanks for the quick feedback and the tip.
In fact, before applying uncrustify, I'm preprocessing the source files by removing as much extra space or newlines in C source as possible. So basically the whole code ends up on a single line, without blank lines or doubled spaces, except of course for preprocessor lines and line comments. Then I apply uncrustify five times. By doing this, I'm trying to achieve a canonical indentation, i.e. one code, one indentation. Even if the code style is modified, the indentation will revert it back to the canonical one.
So far it works quite well, except for the long initializer lines.
Merge pull request #1353 from guy-maurel/PrepareLogFor1349
guy-maurel commentedon Sep 25, 2017
The bug is fixed ( #1354 ). Please test and report.
xeyownt commentedon Sep 27, 2017
Hello,
Thanks for the fix.
I run this new version through our code base, and could isolate a few issues.
Here one with list of hex uint8_t, where some hex are only one digit. In that case we see that uncrustify fails to indent correctly.
Here the source file:
When all hex are uniform (2 digits), it is better, although there is still a small issues.
Here the source file:
xeyownt commentedon Sep 27, 2017
Also, here the config file that generates the buggy behavior:
guy-maurel commentedon Sep 30, 2017
What do you mean with: to indent correctly.
Please push the code you wanted to get.
xeyownt commentedon Oct 1, 2017
Let's name
a.cthe first source file with0x0and0x00inside (same file as above):I uncrustify with the config given above, and get
a-uncrustified.c:I should get instead (
a-uncrustified-fixed.c):The problems in
a-uncrustified.c:0x0on the second line. Strangely uncrustify inserts two spaces (when one is enough), and keep doing so for the next column, although this is not necessary for the before-last column. In fact this problem gets even worse if you run uncrustify twice.{with those on next line, use of tabs instead of space to align the next lines, and insertion of space to align the values in the array.c[][8], the next variables are no longer indented. They are just listed on the same line, as in the original source file.The second source file,
b.c, is (same as in comment above):Uncrustified as (
b-uncrustified.c):I would expect an output like:
The problems are the same as in
a-uncrustified.c, except that we don't have the first issue (addition of an extra and persistent space after the comma).A proposal for 2nd part of issue uncrustify#1349
guy-maurel commentedon Oct 14, 2017
There are bugs here.
The first one is an alignment bug: I am working on it.
The second one is a width bug. I propose a bugfix for it at #1378
Please test it and report.
Merge pull request #1378 from guy-maurel/Width
xeyownt commentedon Nov 3, 2017
Hello,
I just tested #1378 (I took version
Uncrustify-0.65-300-d396bff) and indeed the width problem is gone for the test caseb.clisted above. The output is perfect and equal to the expected output listed above. Thank you already!For
a.c, we still have issue (the alignment bug you mention - note that the code width, here 115, is well respected):guy-maurel commentedon Nov 12, 2017
#1438 is a bugfix proposal. Look also at #1428
Please test it and report.
xeyownt commentedon Nov 13, 2017
I just tried the latest commit on master (b5ce111) and the latest on your branch guymaurel/MoreAlign (40d2fa3), but I don't see any difference on the test case
a.c. The output is identical with my latest tests above.guy-maurel commentedon Nov 13, 2017
Yes. I work on it.
As we have many examples, please push (as attachment, not online) 3 files:
the source, the config and the expected output. To be sure we are working on the same data.
xeyownt commentedon Nov 14, 2017
Here the files in the attached tar.gz: code_width_align-1349.tar.gz.
Prepare bugfix for uncrustify#1349
Merge pull request #1445 from guy-maurel/Prepare1349
guy-maurel commentedon Dec 1, 2017
Related to #1293
guy-maurel commentedon Mar 4, 2018
The problem is having a struct initializer inside a struct initializer inside something.
uncrustify can't yet deal with that.
The output are not predictable.
guy-maurel commentedon Jun 4, 2018
The problem is having a struct initializer inside a struct initializer inside something.
uncrustify can't yet deal with that.
The output are not predictable.
Related to #1293, #1601, #1727
guy-maurel commentedon Apr 4, 2019
The problem is having a struct initializer inside a struct initializer inside something.
uncrustify can't yet deal with that.
The output are not predictable.
Related to #967, #1293, #1601, #1727, #1848