[PATCH] D72144: Treat C# `using` as a control statement
Jonathan B Coe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 3 05:38:47 PST 2020
jbcoe created this revision.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Unless SpaceBeforeParensOptions is set to SBPO_Never, a space will be put between `using` and `(` in C# code.
Repository:
rG LLVM Github Monorepo
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,15 @@
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);
}
TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2763,7 +2763,7 @@
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
(Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
tok::kw_switch, tok::kw_case, TT_ForEachMacro,
- TT_ObjCForIn) ||
+ tok::kw_using, TT_ObjCForIn) ||
Left.isIf(Line.Type != LT_PreprocessorDirective) ||
(Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
@@ -2861,7 +2861,7 @@
// 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_Never;
} else if (Style.Language == FormatStyle::LK_JavaScript) {
if (Left.is(TT_JsFatArrow))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72144.236028.patch
Type: text/x-patch
Size: 1827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200103/84f950d0/attachment.bin>
More information about the cfe-commits
mailing list