[cfe-commits] r173150 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Tue Jan 22 03:46:26 PST 2013


Author: djasper
Date: Tue Jan 22 05:46:26 2013
New Revision: 173150

URL: http://llvm.org/viewvc/llvm-project?rev=173150&view=rev
Log:
Fix "*" formatting when creating arrays of pointers.

Before: A = new int * [10]();
After:  A = new int *[10]();

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

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173150&r1=173149&r2=173150&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Jan 22 05:46:26 2013
@@ -958,6 +958,13 @@
 
       while (CurrentToken != NULL) {
         if (CurrentToken->is(tok::r_square)) {
+          if (!CurrentToken->Children.empty() &&
+              CurrentToken->Children[0].is(tok::l_paren)) {
+            // An ObjC method call can't be followed by an open parenthesis.
+            // FIXME: Do we incorrectly label ":" with this?
+            StartsObjCMethodExpr = false;
+            Left->Type = TT_Unknown;
+	  }
           if (StartsObjCMethodExpr)
             objCSelector.markEnd(*CurrentToken);
           Left->MatchingParen = CurrentToken;
@@ -1325,6 +1332,9 @@
     if (NextToken == NULL)
       return TT_Unknown;
 
+    if (NextToken->is(tok::l_square) && NextToken->Type != TT_ObjCMethodExpr)
+      return TT_PointerOrReference;
+
     if (PrevToken->is(tok::l_paren) || PrevToken->is(tok::l_square) ||
         PrevToken->is(tok::l_brace) || PrevToken->is(tok::comma) ||
         PrevToken->is(tok::kw_return) || PrevToken->is(tok::colon) ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173150&r1=173149&r2=173150&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 22 05:46:26 2013
@@ -1338,6 +1338,9 @@
   verifyFormat("if (*b[i])");
   verifyFormat("if (int *a = (&b))");
   verifyFormat("while (int *a = &b)");
+
+  verifyFormat("A = new SomeType *[Length]();");
+  verifyGoogleFormat("A = new SomeType* [Length]();");
 }
 
 TEST_F(FormatTest, FormatsCasts) {





More information about the cfe-commits mailing list