r215632 - clang-format: Support chained dereferenced assignments.

Daniel Jasper djasper at google.com
Thu Aug 14 03:53:20 PDT 2014


Author: djasper
Date: Thu Aug 14 05:53:19 2014
New Revision: 215632

URL: http://llvm.org/viewvc/llvm-project?rev=215632&view=rev
Log:
clang-format: Support chained dereferenced assignments.

Before:
  x = * a(x) = *a(y);

After:
  x = *a(x) = *a(y);

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=215632&r1=215631&r2=215632&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Aug 14 05:53:19 2014
@@ -708,7 +708,8 @@ private:
         }
         if ((Previous->Type == TT_BinaryOperator ||
              Previous->Type == TT_UnaryOperator) &&
-            Previous->isOneOf(tok::star, tok::amp)) {
+            Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
+            Previous->Previous->isNot(tok::equal)) {
           Previous->Type = TT_PointerOrReference;
         }
       }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=215632&r1=215631&r2=215632&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Aug 14 05:53:19 2014
@@ -4823,6 +4823,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
       "const char* const p = reinterpret_cast<const char* const>(q);");
   verifyGoogleFormat("void f(int i = 0, SomeType** temps = NULL);");
 
+  FormatStyle Left = getLLVMStyle();
+  Left.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("x = *a(x) = *a(y);", Left);
+
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
   verifyIndependentOfContext("*(x + y).call();");





More information about the cfe-commits mailing list