[PATCH] clang-format: Add ability to align assignment operators
Daniel Jasper
djasper at google.com
Mon Apr 20 05:12:50 PDT 2015
I think this is taking great shape. Thanks for continuing to work on it!
================
Comment at: lib/Format/WhitespaceManager.cpp:145
@@ -143,1 +144,3 @@
+void WhitespaceManager::alignConsecutiveAssignments() {
+ if (!Style.AlignConsecutiveAssignments)
----------------
Please add some comments.
================
Comment at: lib/Format/WhitespaceManager.cpp:157
@@ +156,3 @@
+ if (Changes[i].NewlinesBefore == 1) {
+ CurrentLine += Changes[i].NewlinesBefore;
+ if (!FoundAssignmentOnLine && StartOfSequence > 0) {
----------------
Maybe rewrite this whole thing (ll. 156-174) as:
if (Changes[i].NewLinesBefore != 0) {
CurrentLine += Changes[i].NewlinesBefore;
if (StartOfSequence > 0 &&
(Changes[i].NewLinesBefore > 1 || !FoundAssignmentOnLine)) {
alignConsecutiveAssignments(StartOfSequence, i, MinColumn);
MinColumn = 0;
StartOfSequence = 0;
}
FoundAssignmentOnLine = false;
FoundLeftParenOnLine = false;
}
================
Comment at: lib/Format/WhitespaceManager.cpp:177
@@ +176,3 @@
+ if ((FoundAssignmentOnLine && Changes[i].Kind == tok::equal) ||
+ (Changes[i].Kind == tok::equal &&
+ (Changes[i].NewlinesBefore > 0 ||
----------------
I think you can simplify this boolean expression by pulling out "Changes[i].Kind == tok::equal"
================
Comment at: lib/Format/WhitespaceManager.cpp:182-184
@@ +181,5 @@
+ if (StartOfSequence > 0) {
+ alignConsecutiveAssignments(StartOfSequence, EndOfSequence, MinColumn);
+ MinColumn = 0;
+ StartOfSequence = 0;
+ }
----------------
These three statements are used at least three times. Maybe pull out a local lambda?
================
Comment at: unittests/Format/FormatTest.cpp:8417
@@ +8416,3 @@
+ " int ccc = 234; \\\n"
+ " int dddddddddd = 2345;", Alignment);
+ Alignment.AlignEscapedNewlinesLeft = false;
----------------
Format these changes with clang-format (it will break before "Alignment").
================
Comment at: unittests/Format/FormatTest.cpp:8452
@@ +8451,3 @@
+ verifyFormat("int i = 1;\n"
+ "LooooooooooongType loooooooooooooooooooooongVariable\n"
+ " = someLooooooooooooooooongFunction();\n"
----------------
Add (and fix if you have ideas):
verifyFormat("int i = 1;\n"
"SomeType a = SomeFunction(looooooooooooooooooooooongParameterA,\n"
" loooooooooooooooooooooongParameterB);\n"
"int j = 2;", Alignment);
If not, still add the test (as clang-format would currently format it, probably aligning the first two equals) and a FIXME.
http://reviews.llvm.org/D8821
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list