if (TheLine.Last->TotalLength + Indent <= ColumnLimit) {
LineState State = Indenter->getInitialState(Indent, &TheLine, DryRun);
- while (State.NextToken)
+ while (State.NextToken) {
+ formatChildren(State, /*Newline=*/false, /*DryRun=*/false, Penalty);
Indenter->addTokenToState(State, /*Newline=*/false, DryRun);
+ }
} else if (Style.ColumnLimit == 0) {
// FIXME: Implement nested blocks for ColumnLimit = 0.
NoColumnLimitFormatter Formatter(Indenter);
}
void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
+ for (SmallVectorImpl<AnnotatedLine *>::iterator I = Line.Children.begin(),
+ E = Line.Children.end();
+ I != E; ++I) {
+ calculateFormattingInformation(**I);
+ }
+
Line.First->TotalLength =
Line.First->IsMultiline ? Style.ColumnLimit : Line.First->ColumnWidth;
if (!Line.First->Next)
Current->CanBreakBefore =
Current->MustBreakBefore || canBreakBefore(Line, *Current);
- if (Current->MustBreakBefore || !Current->Children.empty() ||
+ unsigned ChildSize = 0;
+ if (Current->Previous->Children.size() == 1) {
+ FormatToken &LastOfChild = *Current->Previous->Children[0]->Last;
+ ChildSize = LastOfChild.isTrailingComment() ? Style.ColumnLimit
+ : LastOfChild.TotalLength + 1;
+ }
+ if (Current->MustBreakBefore || Current->Previous->Children.size() > 1 ||
Current->IsMultiline)
Current->TotalLength = Current->Previous->TotalLength + Style.ColumnLimit;
else
Current->TotalLength = Current->Previous->TotalLength +
- Current->ColumnWidth +
+ Current->ColumnWidth + ChildSize +
Current->SpacesRequiredBefore;
if (Current->Type == TT_CtorInitializerColon)
}
DEBUG({ printDebugInfo(Line); });
-
- for (SmallVectorImpl<AnnotatedLine *>::iterator I = Line.Children.begin(),
- E = Line.Children.end();
- I != E; ++I) {
- calculateFormattingInformation(**I);
- }
}
void TokenAnnotator::calculateUnbreakableTailLengths(AnnotatedLine &Line) {
}
TEST_F(FormatTest, FormatsLambdas) {
- verifyFormat("int c = [b]() mutable {\n"
- " return [&b] { return b++; }();\n"
- "}();\n");
- verifyFormat("int c = [&] {\n"
- " [=] { return b++; }();\n"
- "}();\n");
- verifyFormat("int c = [&, &a, a] {\n"
- " [=, c, &d] { return b++; }();\n"
- "}();\n");
- verifyFormat("int c = [&a, &a, a] {\n"
- " [=, a, b, &c] { return b++; }();\n"
- "}();\n");
- verifyFormat("auto c = {[&a, &a, a] {\n"
- " [=, a, b, &c] { return b++; }();\n"
- "}}\n");
+ verifyFormat("int c = [b]() mutable { return [&b] { return b++; }(); }();\n");
+ verifyFormat("int c = [&] { [=] { return b++; }(); }();\n");
+ verifyFormat("int c = [&, &a, a] { [=, c, &d] { return b++; }(); }();\n");
+ verifyFormat("int c = [&a, &a, a] { [=, a, b, &c] { return b++; }(); }();\n");
+ verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] { return b++; }(); }}\n");
verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] {}(); }}\n");
verifyFormat("void f() {\n"
" other(x.begin(), x.end(), [&](int, int) { return 1; });\n"
verifyFormat("int a = [operation block:^int(int *i) { return 1; }];");
verifyFormat("[myObject doSomethingWith:arg1\n"
" aaa:^int(int *a) { return 1; }\n"
- " bbb:f(a * b)];");
+ " bbb:f(a * bbbbbbbb)];");
verifyFormat("[operation setCompletionBlock:^{\n"
" [self.delegate newDataAvailable];\n"
" foo();\n"
" bar();\n"
"}, this);");
+
+ verifyFormat("var x = {a: function() { return 1; }};",
+ getGoogleJSStyleWithColumns(38));
+ verifyFormat("var x = {\n"
+ " a: function() { return 1; }\n"
+ "};",
+ getGoogleJSStyleWithColumns(37));
}
TEST_F(FormatTestJS, ReturnStatements) {