[cfe-dev] [PATCH] Fix some issues in clang-format's AlignConsecutive modes
Ben Harper via cfe-dev
cfe-dev at lists.llvm.org
Mon Jun 6 05:17:21 PDT 2016
This patch fixes issues with AlignConsecutiveAssignments and
AlignConsecutiveDeclarations such as this:
OLD:
int fun1(int a);
double fun2(int b);
NEW
int fun1(int a);
double fun2(int b);
Also...
OLD:
void fun(int x = 1) {
int y = 2;
}
NEW:
void fun(int x = 1) {
int y = 2;
}
The old alignment function was incapable of maintaining alignment whenever
the scope changed. To illustrate - in the first example mentioned, the
alignment of fun1 is lost by entering the nested scope of (int a).
This would cause the alignment to give up, and cause fun2 to start from a
blank slate. It would also cause false alignment, which is illustrated in
the second example above.
This modification changes the alignment function so that it calls itself
recursively, at each change in scope depth. This allows it to maintain state
across different scope depths.
There are some new test cases which stress this functionality. In addition,
there were two historical test cases marked as "FIX ME", which now work as
intended.
In order to sense check, I have run this new implementation against the
Clang
source code, with AlignConsecutiveAssignments:true and
AlignConsecutiveDeclarations:true. I then compared the old output with those
settings, vs the new output, with the same settings. All changes that I
observed are explainable by the new logic, and IMO the formatted code looks
better with the new method.
Regards,
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160606/6e18008d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FormatFixAlign.patch
Type: application/octet-stream
Size: 19647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160606/6e18008d/attachment.obj>
More information about the cfe-dev
mailing list