[PATCH] D14325: [clang-format] Do not align assignments that aren't after the same number of commas. (Closes: 25329)

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 27 05:57:25 PST 2015


djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks awesome :-)


================
Comment at: lib/Format/WhitespaceManager.cpp:242-243
@@ -320,34 +241,4 @@
     }
 
-    if (Changes[i].Kind == tok::r_brace) {
-      if (!FoundLeftBraceOnLine)
-        AlignSequence();
-      FoundLeftBraceOnLine = false;
-    } else if (Changes[i].Kind == tok::l_brace) {
-      FoundLeftBraceOnLine = true;
-      if (!FoundDeclarationOnLine)
-        AlignSequence();
-    } else if (Changes[i].Kind == tok::r_paren) {
-      if (!FoundLeftParenOnLine)
-        AlignSequence();
-      FoundLeftParenOnLine = false;
-    } else if (Changes[i].Kind == tok::l_paren) {
-      FoundLeftParenOnLine = true;
-      if (!FoundDeclarationOnLine)
-        AlignSequence();
-    } else if (!FoundDeclarationOnLine && !FoundLeftBraceOnLine &&
-               !FoundLeftParenOnLine && Changes[i].IsStartOfDeclName) {
-      FoundDeclarationOnLine = true;
-      if (StartOfSequence == 0)
-        StartOfSequence = i;
-
-      unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
-      int LineLengthAfter = -Changes[i].Spaces;
-      for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j)
-        LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength;
-      unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter;
-
-      if (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) {
-        AlignSequence();
-        StartOfSequence = i;
-      }
+    if (Changes[i].Kind == tok::comma) {
+      ++CommasBeforeMatch;
----------------
berenm wrote:
> The code was only checking for a match if none of the previous conditions were true. I changed that and with your suggestion so I guess it's OK now.
Ah, I see, I guess the initial if-else chains were too complicated for me ;-).

This looks good now, thanks.


http://reviews.llvm.org/D14325





More information about the cfe-commits mailing list