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

Nico Weber nicolasweber at gmx.de
Tue Jan 8 11:40:21 PST 2013


Author: nico
Date: Tue Jan  8 13:40:21 2013
New Revision: 171887

URL: http://llvm.org/viewvc/llvm-project?rev=171887&view=rev
Log:
Formatter: Format @ literals better. Array and dictionary literals need more work.

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=171887&r1=171886&r2=171887&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Tue Jan  8 13:40:21 2013
@@ -940,7 +940,10 @@
       return false;
     if (Left.is(tok::exclaim) || Left.is(tok::tilde))
       return false;
-    if (Left.is(tok::at) && Right.is(tok::identifier))
+    if (Left.is(tok::at) &&
+        (Right.is(tok::identifier) || Right.is(tok::string_literal) ||
+         Right.is(tok::char_constant) || Right.is(tok::numeric_constant) ||
+         Right.is(tok::l_paren) || Right.is(tok::l_brace)))
       return false;
     if (Left.is(tok::less) || Right.is(tok::greater) || Right.is(tok::less))
       return false;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171887&r1=171886&r2=171887&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan  8 13:40:21 2013
@@ -1137,6 +1137,20 @@
   verifyFormat("@throw");
   verifyFormat("@try");
 
+  // FIXME: Make the uncommented lines below pass.
+  verifyFormat("@\"String\"");
+  verifyFormat("@1");
+  //verifyFormat("@+4.8");
+  //verifyFormat("@-4");
+  verifyFormat("@1LL");
+  verifyFormat("@.5");
+  verifyFormat("@'c'");
+  verifyFormat("@true");
+  verifyFormat("NSNumber *smallestInt = @(-INT_MAX - 1);");
+  verifyFormat("@[");
+  verifyFormat("@{");
+
+
   EXPECT_EQ("@interface", format("@ interface"));
 
   // The precise formatting of this doesn't matter, nobody writes code like





More information about the cfe-commits mailing list