aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Format/Format.cpp7
-rw-r--r--lib/Format/TokenAnnotator.cpp11
-rw-r--r--unittests/Format/FormatTest.cpp19
3 files changed, 21 insertions, 16 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index c50bfb0a70..92c138aa7e 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -675,7 +675,7 @@ private:
std::set<LineState> Seen;
// Insert start element into queue.
- StateNode *Node=
+ StateNode *Node =
new (Allocator.Allocate()) StateNode(InitialState, false, NULL);
Queue.push(QueueItem(OrderedPenalty(0, Count), Node));
++Count;
@@ -683,7 +683,7 @@ private:
// While not empty, take first element and follow edges.
while (!Queue.empty()) {
unsigned Penalty = Queue.top().first.first;
- StateNode *Node= Queue.top().second;
+ StateNode *Node = Queue.top().second;
if (Node->State.NextToken == NULL) {
DEBUG(llvm::errs() << "\n---\nPenalty for line: " << Penalty << "\n");
break;
@@ -1024,8 +1024,7 @@ private:
/// \p IndentForLevel must contain the indent for the level \c l
/// at \p IndentForLevel[l], or a value < 0 if the indent for
/// that level is unknown.
- unsigned getIndent(const std::vector<int> IndentForLevel,
- unsigned Level) {
+ unsigned getIndent(const std::vector<int> IndentForLevel, unsigned Level) {
if (IndentForLevel[Level] != -1)
return IndentForLevel[Level];
if (Level == 0)
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 22e67df1ec..ace6d25467 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -524,11 +524,9 @@ private:
struct ScopedContextCreator {
AnnotatingParser &P;
- ScopedContextCreator(AnnotatingParser &P, unsigned Increase)
- : P(P) {
- P.Contexts.push_back(Context(
- P.Contexts.back().BindingStrength + Increase,
- P.Contexts.back().IsExpression));
+ ScopedContextCreator(AnnotatingParser &P, unsigned Increase) : P(P) {
+ P.Contexts.push_back(Context(P.Contexts.back().BindingStrength + Increase,
+ P.Contexts.back().IsExpression));
}
~ScopedContextCreator() { P.Contexts.pop_back(); }
@@ -865,6 +863,9 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Right.is(tok::arrow) || Right.is(tok::period)) {
if (Left.is(tok::r_paren) && Line.Type == LT_BuilderTypeCall)
return 5; // Should be smaller than breaking at a nested comma.
+ if ((Left.is(tok::r_paren) || Left.is(tok::r_square)) &&
+ Left.MatchingParen && Left.MatchingParen->ParameterCount > 0)
+ return 10;
return 150;
}
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 232cd6b98a..38f926a7e2 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1180,8 +1180,8 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
" aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)));");
verifyGoogleFormat(
- "aaaaaaaaaaaaaaa(\n"
- " aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();");
+ "aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa)\n"
+ " .aaaaaaaaaaaaaaaaaa();");
verifyGoogleFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa);");
@@ -1208,11 +1208,11 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
" aaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);",
Style);
- verifyFormat("void f() {\n"
- " aaaaaaaaaaaaaaaaaaaaaaaa(\n"
- " aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa).aaaaaaa();\n"
- "}",
- Style);
+ verifyFormat(
+ "void f() {\n"
+ " aaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa)\n"
+ " .aaaaaaa();\n"
+ "}", Style);
}
TEST_F(FormatTest, FormatsBuilderPattern) {
@@ -1441,6 +1441,11 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
"function(LoooooooooooooooooooooooooooooooooooongObject\n"
" ->loooooooooooooooooooooooooooooooooooooooongFunction());");
+ verifyFormat("EXPECT_CALL(SomeObject, SomeFunction(Parameter))\n"
+ " .WillRepeatedly(Return(SomeValue));");
+ verifyFormat("SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)]\n"
+ " .insert(ccccccccccccccccccccccc);");
+
// Here, it is not necessary to wrap at "." or "->".
verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaa) ||\n"
" aaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");