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

Manuel Klimek klimek at google.com
Fri Jan 18 06:46:43 PST 2013


Author: klimek
Date: Fri Jan 18 08:46:43 2013
New Revision: 172822

URL: http://llvm.org/viewvc/llvm-project?rev=172822&view=rev
Log:
Fixes issues around pulling in the next line in simple if statements.

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=172822&r1=172821&r2=172822&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jan 18 08:46:43 2013
@@ -1749,6 +1749,10 @@
                         unsigned Limit) {
     if (!Style.AllowShortIfStatementsOnASingleLine)
       return;
+    if ((I + 1)->InPPDirective != I->InPPDirective ||
+        ((I + 1)->InPPDirective &&
+         (I + 1)->First.FormatTok.HasUnescapedNewline))
+      return;
     AnnotatedLine &Line = *I;
     if (Line.Last->isNot(tok::r_paren))
       return;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172822&r1=172821&r2=172822&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 18 08:46:43 2013
@@ -1542,20 +1542,23 @@
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
   verifyFormat("void f() { f(); }\n#error E", AllowsMergedIf);
   verifyFormat("if (true) return 42;\n#error E", AllowsMergedIf);
-
-  // FIXME:
-  // verifyFormat("if (true)\n#error E\n  return 42;", AllowsMergedIf);
+  verifyFormat("if (true)\n#error E\n  return 42;", AllowsMergedIf);
+  EXPECT_EQ("if (true) return 42;",
+            format("if (true)\nreturn 42;", AllowsMergedIf));
+  FormatStyle ShortMergedIf = AllowsMergedIf;
+  ShortMergedIf.ColumnLimit = 25;
+  verifyFormat("#define A               \\\n"
+               "  if (true) return 42;", ShortMergedIf);
+  verifyFormat("#define A               \\\n"
+               "  f();                  \\\n"
+               "  if (true)\n"
+               "#define B", ShortMergedIf);
+  verifyFormat("#define A               \\\n"
+               "  f();                  \\\n"
+               "  if (true)\n"
+               "g();", ShortMergedIf);
 }
 
-// FIXME: This breaks the order of the unwrapped lines:
-// TEST_F(FormatTest, OrderUnwrappedLines) {
-//   verifyFormat("{\n"
-//                "  bool a; //\n"
-//                "#error {\n"
-//                "  int a;\n"
-//                "}");
-// }
-
 //===----------------------------------------------------------------------===//
 // Objective-C tests.
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list