[PATCH] Revamp indentation behavior for complex binary expressions.

Daniel Jasper djasper at google.com
Mon Apr 8 13:04:37 PDT 2013



================
Comment at: lib/Format/Format.cpp:903
@@ +902,3 @@
+      // the 'operator' is ',', ';' or an assignment as those have different
+      // indentation rules.
+      if (*I == prec::Conditional ||
----------------
Manuel Klimek wrote:
> Daniel Jasper wrote:
> > Manuel Klimek wrote:
> > > Why does SkipFirstExtraIndent only apply to the latter?
> > Because the rule for conditional expressions supersedes the one for assignments etc.. Thus "always indent conditional expressions.". Otherwise, we would end up with:
> > 
> >   int aaaaaa = bbbbbb
> >                ? ccccccc
> >                : dddddd
> The next sentence also says "never indent ...", but it's under !SkipFirstExtraIndent, or am I missing something?
Ok, I'll update the "Never indent .. " sentence.

================
Comment at: lib/Format/TokenAnnotator.cpp:803
@@ -804,4 +802,3 @@
           CurrentPrecedence = 1 + (int) prec::Conditional;
-        else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
-                 Current->Type == TT_CtorInitializerColon)
+        else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon)
           CurrentPrecedence = 1;
----------------
Manuel Klimek wrote:
> Daniel Jasper wrote:
> > Manuel Klimek wrote:
> > > Why did this change?
> > Because it is no longer necessary to "cheat" by regarding constructor initializers as binary operators. They follow different rules and thus should be handled in a different fashion.
> I assume that was already the case before, and is not necessarily related to this change?
There is another change in line Format.cpp:868 that basically does the same thing, but at a more appropriate location. Otherwise the handling of those colons don't play nice with the new binary expression indentation.


http://llvm-reviews.chandlerc.com/D631



More information about the cfe-commits mailing list