[PATCH] D66662: [clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 23 08:58:19 PDT 2019
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: djasper, klimek, owenpan.
MyDeveloperDay added a project: clang.
Addresses https://bugs.llvm.org/show_bug.cgi?id=43100
Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is !
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
this change simply overcomes this for when using C# settings in the .clang-format file
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1))
All FormatTests pass..
[==========] 688 tests from 21 test cases ran. (88508 ms total)
[ PASSED ] 688 tests.
Repository:
rC Clang
https://reviews.llvm.org/D66662
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
@@ -165,6 +165,10 @@
"public string Host {\n set;\n get;\n}");
}
+TEST_F(FormatTestCSharp, CSharpUsing) {
+ verifyFormat("using (StreamWriter sw = new StreamWriter(filename) { }");
+}
+
TEST_F(FormatTestCSharp, CSharpRegions) {
verifyFormat("#region aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa "
"aaaaaaaaaaaaaaa long region");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2614,6 +2614,9 @@
if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
(Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
return true;
+ // using (FileStream fs...
+ if (Style.isCSharp() && Left.is(tok::kw_using) && Right.is(tok::l_paren))
+ return true;
return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
(Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66662.216870.patch
Type: text/x-patch
Size: 1289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190823/65617aa4/attachment.bin>
More information about the cfe-commits
mailing list