Author: djasper
Date: Wed Mar  1 05:10:11 2017
New Revision: 296608

URL: http://llvm.org/viewvc/llvm-project?rev=296608&view=rev
Log:
Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=296608&r1=296607&r2=296608&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar  1 05:10:11 2017
@@ -589,11 +589,12 @@ void UnwrappedLineParser::conditionalCom
 }
 
 void UnwrappedLineParser::parsePPIf(bool IfDef) {
+  bool IfNDef = FormatTok->is(tok::pp_ifndef);
   nextToken();
   bool Unreachable = false;
   if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0"))
     Unreachable = true;
-  if (IfDef && FormatTok->TokenText == "SWIG")
+  if (IfDef && !IfNDef && FormatTok->TokenText == "SWIG")
     Unreachable = true;
   conditionalCompilationStart(Unreachable);
   parsePPUnknown();

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=296608&r1=296607&r2=296608&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Mar  1 05:10:11 2017
@@ -1683,14 +1683,6 @@ TEST_F(FormatTestComments, IgnoresIf0Con
                    "void f(  ) {  }\n"
                    "#endif\n"
                    "void g(  ) {  }\n"));
-  EXPECT_EQ("#ifdef SWIG\n"
-            "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
-            "#endif\n"
-            "void f() {}",
-            format("#ifdef SWIG\n"
-                   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
-                   "#endif\n"
-                   "void f(  ) {  }"));
   EXPECT_EQ("enum E {\n"
             "  One,\n"
             "  Two,\n"
@@ -1809,6 +1801,22 @@ TEST_F(FormatTestComments, IgnoresIf0Con
                    "#endif\n"
                    "Five\n"
                    "};"));
+
+  // Ignore stuff in SWIG-blocks.
+  EXPECT_EQ("#ifdef SWIG\n"
+            "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+            "#endif\n"
+            "void f() {}",
+            format("#ifdef SWIG\n"
+                   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+                   "#endif\n"
+                   "void f(  ) {  }"));
+  EXPECT_EQ("#ifndef SWIG\n"
+            "void f() {}\n"
+            "#endif",
+            format("#ifndef SWIG\n"
+                   "void f(      ) {       }\n"
+                   "#endif"));
 }
 
 TEST_F(FormatTestComments, DontCrashOnBlockComments) {


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to