Author: Jonathan Coe Date: 2020-03-23T14:33:10Z New Revision: 5e1a026c2d81e83e2b88cc6b6f27fbefbfe0de16
URL: https://github.com/llvm/llvm-project/commit/5e1a026c2d81e83e2b88cc6b6f27fbefbfe0de16 DIFF: https://github.com/llvm/llvm-project/commit/5e1a026c2d81e83e2b88cc6b6f27fbefbfe0de16.diff LOG: [clang-format] Do not indent C# array initialisers as continuations Summary: Flag '= {' as a braced init list when parsing C# code. Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits, MyDeveloperDay Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D75760 Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestCSharp.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e2a6389cb26d..d8202bd61458 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1460,6 +1460,11 @@ void UnwrappedLineParser::parseStructuralElement() { nextToken(); if (FormatTok->Tok.is(tok::l_brace)) { + // Block kind should probably be set to BK_BracedInit for any language. + // C# needs this change to ensure that array initialisers and object + // initialisers are indented the same way. + if (Style.isCSharp()) + FormatTok->BlockKind = BK_BracedInit; nextToken(); parseBracedList(); } else if (Style.Language == FormatStyle::LK_Proto && @@ -1652,7 +1657,7 @@ bool UnwrappedLineParser::tryToParseBracedList() { bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons, tok::TokenKind ClosingBraceKind) { bool HasError = false; - + // FIXME: Once we have an expression parser in the UnwrappedLineParser, // replace this by using parseAssigmentExpression() inside. do { diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index a0f60ce799d2..0b770b4dfd3c 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -562,6 +562,17 @@ var myDict = new Dictionary<string, string> { Style); } +TEST_F(FormatTestCSharp, CSharpArrayInitializers) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + + verifyFormat(R"(// +private MySet<Node>[] setPoints = { + new Point<Node>(), + new Point<Node>(), +};)", + Style); +} + TEST_F(FormatTestCSharp, CSharpNamedArguments) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits