Hi djasper,

Fix for code breaking formatting of #pragma option
[[ 
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devwin32/pndsnpragmaoption_xml.html
 | pragma option documentation ]]

http://reviews.llvm.org/D8121

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -572,6 +572,17 @@
         CurrentToken->Type = TT_ImplicitStringLiteral;
         next();
       }
+    } else if (CurrentToken && CurrentToken->TokenText == "option") {
+      auto PreviousToken = CurrentToken;
+      next(); // Consume "option".
+      while (CurrentToken) {
+        // Don't add space after binary operator.
+        if (PreviousToken->Type == TT_BinaryOperator) {
+          CurrentToken->Type = TT_ImplicitStringLiteral;
+        }
+        PreviousToken = CurrentToken;
+        next();
+      }
     }
   }
 
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -8710,6 +8710,12 @@
                    "(including parentheses)."));
 }
 
+TEST_F(FormatTest, UnderstandPragmaOption) {
+  verifyFormat("#pragma option -C -A");
+
+  EXPECT_EQ("#pragma option -C -A", format("#pragma    option   -C   -A"));
+}
+
 #define EXPECT_ALL_STYLES_EQUAL(Styles)                                        
\
   for (size_t i = 1; i < Styles.size(); ++i)                                   
\
     EXPECT_EQ(Styles[0], Styles[i]) << "Style #" << i << " of "                
\

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -572,6 +572,17 @@
         CurrentToken->Type = TT_ImplicitStringLiteral;
         next();
       }
+    } else if (CurrentToken && CurrentToken->TokenText == "option") {
+      auto PreviousToken = CurrentToken;
+      next(); // Consume "option".
+      while (CurrentToken) {
+        // Don't add space after binary operator.
+        if (PreviousToken->Type == TT_BinaryOperator) {
+          CurrentToken->Type = TT_ImplicitStringLiteral;
+        }
+        PreviousToken = CurrentToken;
+        next();
+      }
     }
   }
 
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -8710,6 +8710,12 @@
                    "(including parentheses)."));
 }
 
+TEST_F(FormatTest, UnderstandPragmaOption) {
+  verifyFormat("#pragma option -C -A");
+
+  EXPECT_EQ("#pragma option -C -A", format("#pragma    option   -C   -A"));
+}
+
 #define EXPECT_ALL_STYLES_EQUAL(Styles)                                        \
   for (size_t i = 1; i < Styles.size(); ++i)                                   \
     EXPECT_EQ(Styles[0], Styles[i]) << "Style #" << i << " of "                \
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to