[PATCH] D75731: [clang-format] C# does not indent braced initializers as continuations
Jonathan B Coe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 6 07:09:46 PST 2020
jbcoe updated this revision to Diff 248719.
jbcoe added a comment.
Remove comma to tidy up ugly format test and actually test what is needed.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75731/new/
https://reviews.llvm.org/D75731
Files:
clang/lib/Format/FormatToken.h
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
@@ -527,31 +527,28 @@
verifyFormat(R"(//
Shape[] shapes = new[] {
- new Circle {
- Radius = 2.7281,
- Colour = Colours.Red,
- },
- new Square {
- Side = 101.1,
- Colour = Colours.Yellow,
- },
+ new Circle {
+ Radius = 2.7281,
+ Colour = Colours.Red,
+ },
+ new Square {
+ Side = 101.1,
+ Colour = Colours.Yellow,
+ },
};)",
Style);
// Omitted final `,`s will change the formatting.
verifyFormat(R"(//
Shape[] shapes = new[] { new Circle { Radius = 2.7281, Colour = Colours.Red },
- new Square {
- Side = 101.1,
- Colour = Colours.Yellow,
- } };)",
+ new Square { Side = 101.1, Colour = Colours.Yellow } };)",
Style);
// Lambdas can be supplied as initialiser arguments.
verifyFormat(R"(//
private Transformer _transformer = new X.Y {
- Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
- Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+ Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
+ Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
};)",
Style);
}
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1677,7 +1677,10 @@
}
break;
case tok::l_square:
- tryToParseLambda();
+ if (Style.isCSharp())
+ parseSquare();
+ else
+ tryToParseLambda();
break;
case tok::l_paren:
parseParens();
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -509,6 +509,9 @@
/// Returns \c true if this tokens starts a block-type list, i.e. a
/// list that should be indented with a block indent.
bool opensBlockOrBlockTypeList(const FormatStyle &Style) const {
+ // C# Does not indent object initialisers as continuations.
+ if (is(tok::l_brace) && BlockKind == BK_BracedInit && Style.isCSharp())
+ return true;
if (is(TT_TemplateString) && opensScope())
return true;
return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75731.248719.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200306/1ce62628/attachment-0001.bin>
More information about the cfe-commits
mailing list