[PATCH] D72144: Treat C# `using` as a control statement

Jonathan B Coe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 06:43:18 PST 2020


jbcoe updated this revision to Diff 239574.
jbcoe added a comment.

Handle `using` case where SpaceBeforeParensOptions is set to SBPO_NonEmptyParentheses


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72144/new/

https://reviews.llvm.org/D72144

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -249,6 +249,23 @@
 
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
                Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+               "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+               "}",
+               Style);
+
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+               Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+               "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+               "}",
+               Style);
+
+  verifyFormat("using() {}", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2869,7 +2869,8 @@
     // space between keywords and paren e.g. "using ("
     if (Right.is(tok::l_paren))
       if (Left.is(tok::kw_using))
-        return spaceRequiredBeforeParens(Left);
+        return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements ||
+               spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
     if (Left.is(TT_JsFatArrow))
       return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72144.239574.patch
Type: text/x-patch
Size: 1627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200122/b4132061/attachment-0001.bin>


More information about the cfe-commits mailing list