[PATCH] D75455: [clang-format] Allow nested [] in C# attributes
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 09:42:14 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f8a7e82b850: [clang-format] Allow nested [] in C# attributes (authored by Jonathan Coe <jbcoe at google.com>).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75455/new/
https://reviews.llvm.org/D75455
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -273,6 +273,15 @@
"{\n"
"}");
+ // [] in an attribute do not cause premature line wrapping or indenting.
+ verifyFormat(R"(//
+public class A
+{
+ [SomeAttribute(new[] { RED, GREEN, BLUE }, -1.0f, 1.0f)]
+ [DoNotSerialize]
+ public Data MemberVariable;
+})");
+
// Unwrappable lines go on a line of their own.
// 'target:' is not treated as a label.
// Modify Style to enforce a column limit.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -324,12 +324,21 @@
}
void UnwrappedLineParser::parseCSharpAttribute() {
+ int UnpairedSquareBrackets = 1;
do {
switch (FormatTok->Tok.getKind()) {
case tok::r_square:
nextToken();
- addUnwrappedLine();
- return;
+ --UnpairedSquareBrackets;
+ if (UnpairedSquareBrackets == 0) {
+ addUnwrappedLine();
+ return;
+ }
+ break;
+ case tok::l_square:
+ ++UnpairedSquareBrackets;
+ nextToken();
+ break;
default:
nextToken();
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75455.247942.patch
Type: text/x-patch
Size: 1406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200303/b6822a5c/attachment.bin>
More information about the cfe-commits
mailing list