]> granicus.if.org Git - clang/commitdiff
Formatter: Format @ literals better. Array and dictionary literals need more work.
authorNico Weber <nicolasweber@gmx.de>
Tue, 8 Jan 2013 19:40:21 +0000 (19:40 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 8 Jan 2013 19:40:21 +0000 (19:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171887 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 120b54d83116ca5385d2ba4713ddd8e618a79c79..1205c424b1a4ed0d03c729059d85a8487dde97ea 100644 (file)
@@ -940,7 +940,10 @@ private:
       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;
index 2bd094bb83cedbdc97ad1817983c72a42f1c88b1..d5f74d3daa5d919ec995c7d090cd255dd78b5d8b 100644 (file)
@@ -1137,6 +1137,20 @@ TEST_F(FormatTest, ObjCAt) {
   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