[PATCH] D50403: AlignConsecutiveAssignments

2018-08-07 Thread Peter Doak via Phabricator via cfe-commits
PDoakORNL created this revision.
PDoakORNL added a project: clang.
Herald added a subscriber: cfe-commits.

Expanding AlignConsecutiveAssignments to compound assignments.


Repository:
  rC Clang

https://reviews.llvm.org/D50403

Files:
  include/clang/Format/Format.h
  lib/Format/WhitespaceManager.cpp


Index: lib/Format/WhitespaceManager.cpp
===
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -432,20 +432,26 @@
 void WhitespaceManager::alignConsecutiveAssignments() {
   if (!Style.AlignConsecutiveAssignments)
 return;
+  std::vector assignment_tokens =
+{tok::equal, tok::pipeequal, tok::caretequal, tok::percentequal,
+ tok::ampequal, tok::plusequal, tok::minusequal, tok::starequal,
+ tok::slashequal, tok::lesslessequal, tok::greatergreaterequal};
+  for (auto assignment_token : assignment_tokens)
+  {
+AlignTokens(Style,
+   [&](const Change &C) {
+ // Do not align on equal signs that are first on a line.
+ if (C.NewlinesBefore > 0)
+   return false;
 
-  AlignTokens(Style,
-  [&](const Change &C) {
-// Do not align on equal signs that are first on a line.
-if (C.NewlinesBefore > 0)
-  return false;
+ // Do not align on equal signs that are last on a line.
+ if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
+   return false;
 
-// Do not align on equal signs that are last on a line.
-if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
-  return false;
-
-return C.Tok->is(tok::equal);
-  },
-  Changes, /*StartAt=*/0);
+ return C.Tok->is(assignment_token);
+   },
+   Changes, /*StartAt=*/0);
+  }
 }
 
 void WhitespaceManager::alignConsecutiveDeclarations() {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -80,12 +80,17 @@
 
   /// If ``true``, aligns consecutive assignments.
   ///
-  /// This will align the assignment operators of consecutive lines. This
-  /// will result in formattings like
+  /// This will align the declaration names of consecutive lines and
+  /// matching assignment operators. This includes consecutive |=, +=
+  /// -=, /=, *=. This will result in formattings like
   /// \code
   ///   int  = 12;
   ///   int b= 23;
   ///   int ccc  = 23;
+  ///
+  ///   int ddd += 12;
+  ///   int ee  += 22;
+  ///   int f   += 23;
   /// \endcode
   bool AlignConsecutiveAssignments;
 


Index: lib/Format/WhitespaceManager.cpp
===
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -432,20 +432,26 @@
 void WhitespaceManager::alignConsecutiveAssignments() {
   if (!Style.AlignConsecutiveAssignments)
 return;
+  std::vector assignment_tokens =
+{tok::equal, tok::pipeequal, tok::caretequal, tok::percentequal,
+ tok::ampequal, tok::plusequal, tok::minusequal, tok::starequal,
+ tok::slashequal, tok::lesslessequal, tok::greatergreaterequal};
+  for (auto assignment_token : assignment_tokens)
+  {
+AlignTokens(Style,
+		[&](const Change &C) {
+		  // Do not align on equal signs that are first on a line.
+		  if (C.NewlinesBefore > 0)
+		return false;
 
-  AlignTokens(Style,
-  [&](const Change &C) {
-// Do not align on equal signs that are first on a line.
-if (C.NewlinesBefore > 0)
-  return false;
+		  // Do not align on equal signs that are last on a line.
+		  if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
+		return false;
 
-// Do not align on equal signs that are last on a line.
-if (&C != &Changes.back() && (&C + 1)->NewlinesBefore > 0)
-  return false;
-
-return C.Tok->is(tok::equal);
-  },
-  Changes, /*StartAt=*/0);
+		  return C.Tok->is(assignment_token);
+		},
+		Changes, /*StartAt=*/0);
+  }
 }
 
 void WhitespaceManager::alignConsecutiveDeclarations() {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -80,12 +80,17 @@
 
   /// If ``true``, aligns consecutive assignments.
   ///
-  /// This will align the assignment operators of consecutive lines. This
-  /// will result in formattings like
+  /// This will align the declaration names of consecutive lines and
+  /// matching assignment operators. This includes consecutive |=, +=
+  /// -=, /=, *=. This will result in formattings like
   /// \code
   ///   int  = 12;
   ///   int b= 23;
   

[PATCH] D50403: [clang-format]AlignConsecutiveAssignments

2018-08-14 Thread Peter Doak via Phabricator via cfe-commits
PDoakORNL added a comment.

So it's been a week, is there an owner for clang/lib/Format?


Repository:
  rC Clang

https://reviews.llvm.org/D50403



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits