[PATCH] Prefer breaking in places other than '(' for default style

Eric Christopher echristo at gmail.com
Tue Oct 22 17:37:56 PDT 2013


Hi Daniel,

Thought I'd send it out and get some discussion if people care and
then I can update the tests and commit if we think it's a good idea.

It'll change code like in (one of the) failing tests:

Value of: format(messUp(Code), Style)
  Actual: "CharSourceRange LineRange =\n
CharSourceRange::getTokenRange(Line.Tokens.front().Tok.getLo(),\n
                             Line.Tokens.back().Tok.getLoc());"
Expected: Code.str()
Which is: "CharSourceRange LineRange =
CharSourceRange::getTokenRange(\n    Line.Tokens.front().Tok.getLo(),
Line.Tokens.back().Tok.getLoc());"
[  FAILED  ] FormatTest.BreaksAfterAssignments (5 ms)
[----------] 1 test from FormatTest (5 ms total)

this:

<pre style='color:#000000;background:#ffffff;'><html><body
style='color:#000000; background:#ffffff; '><pre>
CharSourceRange LineRange <span style='color:#808030; '>=</span>
      CharSourceRange<span style='color:#800080;
'>::</span>getTokenRange<span style='color:#808030;
'>(</span>Line<span style='color:#808030; '>.</span>Tokens<span
style='color:#808030; '>.</span>front<span style='color:#808030;
'>(</span><span style='color:#808030; '>)</span><span
style='color:#808030; '>.</span>Tok<span style='color:#808030;
'>.</span>getLo<span style='color:#808030; '>(</span><span
style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
                                     Line<span style='color:#808030;
'>.</span>Tokens<span style='color:#808030; '>.</span>back<span
style='color:#808030; '>(</span><span style='color:#808030;
'>)</span><span style='color:#808030; '>.</span>Tok<span
style='color:#808030; '>.</span>getLoc<span style='color:#808030;
'>(</span><span style='color:#808030; '>)</span><span
style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
</pre>

versus:

<pre style='color:#000000;background:#ffffff;'><html><body
style='color:#000000; background:#ffffff; '><pre>
CharSourceRange LineRange <span style='color:#808030; '>=</span>
CharSourceRange<span style='color:#800080;
'>::</span>getTokenRange<span style='color:#808030; '>(</span>
        Line<span style='color:#808030; '>.</span>Tokens<span
style='color:#808030; '>.</span>front<span style='color:#808030;
'>(</span><span style='color:#808030; '>)</span><span
style='color:#808030; '>.</span>Tok<span style='color:#808030;
'>.</span>getLo<span style='color:#808030; '>(</span><span
style='color:#808030; '>)</span><span style='color:#808030; '>,</span>
Line<span style='color:#808030; '>.</span>Tokens<span
style='color:#808030; '>.</span>back<span style='color:#808030;
'>(</span><span style='color:#808030; '>)</span><span
style='color:#808030; '>.</span>Tok<span style='color:#808030;
'>.</span>getLoc<span style='color:#808030; '>(</span><span
style='color:#808030; '>)</span><span style='color:#808030;
'>)</span><span style='color:#800080; '>;</span>
</pre>

which while the former is more lines I think it is a much more legible
general formatting style.

Thoughts?

-eric
-------------- next part --------------
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 733f70d..f269347 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1177,7 +1177,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
     return 20;
 
-  if (Left.is(tok::l_paren) && Line.MightBeFunctionDecl)
+  if (Left.is(tok::l_paren))
     return 100;
   if (Left.opensScope())
     return Left.ParameterCount > 1 ? prec::Comma : 19;


More information about the cfe-commits mailing list