[PATCH] Revamp indentation behavior for complex binary expressions.

Daniel Jasper djasper at google.com
Mon Apr 8 12:45:16 PDT 2013



================
Comment at: lib/Format/Format.cpp:874
@@ -886,1 +873,3 @@
 
+    // If return is "part" of a binary expression, align after it.
+    if (Current.is(tok::kw_return) && !Current.FakeLParens.empty())
----------------
Manuel Klimek wrote:
> As discussed offline, change comment.
Done.

================
Comment at: lib/Format/Format.cpp:886
@@ +885,3 @@
+    // Don't add extra indentation for the first fake parenthesis after
+    // 'return', assignements or opening <({[. The indendtation for these cases
+    // is special cased.
----------------
Manuel Klimek wrote:
> *indentation
Done.

================
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:
> 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

================
Comment at: lib/Format/TokenAnnotator.cpp:787
@@ -789,2 +786,3 @@
     // Eagerly consume trailing comments.
-    while (isTrailingComment(Current)) {
+    while (Current && Current->FormatTok.NewlinesBefore == 0 &&
+           isTrailingComment(Current)) {
----------------
Manuel Klimek wrote:
> Is this independent of newline escaping? (NewlinesBefore includes escaped newlines)
Actually this change is not necessary anymore. Reverted.

================
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:
> 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.


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



More information about the cfe-commits mailing list