Allow breaking between type and name in for loops.

This fixes llvm.org/PR15033.

Also: Always break before a parameter, if the previous parameter was
split over multiple lines. This was necessary to make the right
decisions in for-loops, almost always makes the code more readable and
also fixes llvm.org/PR14873.

Before:
for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope()
         .begin(), E = FD->getDeclsInPrototypeScope().end();
     I != E; ++I) {
}
foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
        ccccccccccccccccccccccccccccc), d, bar(e, f));

After:
for (llvm::ArrayRef<NamedDecl *>::iterator
         I = FD->getDeclsInPrototypeScope().begin(),
         E = FD->getDeclsInPrototypeScope().end();
     I != E; ++I) {
}
foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
        ccccccccccccccccccccccccccccc),
    d, bar(e, f));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175741 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 2bce7c0..dcbdb78 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -886,9 +886,8 @@
   }
 
   // In for-loops, prefer breaking at ',' and ';'.
-  if (Line.First.is(tok::kw_for) &&
-      (Left.isNot(tok::comma) && Left.isNot(tok::semi)))
-    return 20;
+  if (Line.First.is(tok::kw_for) && Left.is(tok::equal))
+    return 4;
 
   if (Left.is(tok::semi))
     return 0;
@@ -1066,6 +1065,8 @@
   if (Left.Type == TT_RangeBasedForLoopColon ||
       Left.Type == TT_InheritanceColon)
     return true;
+  if (Right.Type == TT_RangeBasedForLoopColon)
+    return false;
   if (Left.Type == TT_PointerOrReference || Left.Type == TT_TemplateCloser ||
       Left.Type == TT_UnaryOperator || Left.Type == TT_ConditionalExpr ||
       Left.is(tok::question) || Left.is(tok::kw_operator))
@@ -1078,6 +1079,12 @@
     // change the "binding" behavior of a comment.
     return false;
 
+  // FIXME: We can probably remove this special case once we have implemented
+  // breaking after types in general.
+  if (Line.First.is(tok::kw_for) && !Right.Children.empty() &&
+      Right.Children[0].is(tok::equal))
+    return true;
+
   // Allow breaking after a trailing 'const', e.g. after a method declaration,
   // unless it is follow by ';', '{' or '='.
   if (Left.is(tok::kw_const) && Left.Parent != NULL &&