r174718 - Fix handling of fake parenthesis during formatting.

Daniel Jasper djasper at google.com
Fri Feb 8 08:49:27 PST 2013


Author: djasper
Date: Fri Feb  8 10:49:27 2013
New Revision: 174718

URL: http://llvm.org/viewvc/llvm-project?rev=174718&view=rev
Log:
Fix handling of fake parenthesis during formatting.

They are much easier to handle when attached to the previous token.

Before:
unsigned Indent =
    formatFirstToken(TheLine.First, IndentForLevel[TheLine.Level] >=
                                    0 ? IndentForLevel[TheLine.Level]
: TheLine.Level * 2, TheLine.InPPDirective, PreviousEndOfLineColumn);

After:
unsigned Indent = formatFirstToken(
    TheLine.First, IndentForLevel[TheLine.Level] >= 0
                       ? IndentForLevel[TheLine.Level] : TheLine.Level * 2,
    TheLine.InPPDirective, PreviousEndOfLineColumn);

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/lib/Format/TokenAnnotator.h
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=174718&r1=174717&r2=174718&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Feb  8 10:49:27 2013
@@ -722,7 +722,7 @@ public:
         if (OperatorFound) {
           ++Start->FakeLParens;
           if (Current != NULL)
-            ++Current->FakeRParens;
+            ++Current->Parent->FakeRParens;
         }
         return;
       }

Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=174718&r1=174717&r2=174718&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Fri Feb  8 10:49:27 2013
@@ -121,7 +121,7 @@ public:
 
   /// \brief Insert this many fake ( before this token for correct indentation.
   unsigned FakeLParens;
-  /// \brief Insert this many fake ) before this token for correct indentation.
+  /// \brief Insert this many fake ) after this token for correct indentation.
   unsigned FakeRParens;
 
   const AnnotatedToken *getPreviousNoneComment() const {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174718&r1=174717&r2=174718&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Feb  8 10:49:27 2013
@@ -1271,6 +1271,11 @@ TEST_F(FormatTest, BreaksConditionalExpr
                "           : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
                "                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
                "       aaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+  verifyFormat(
+      "unsigned Indent = formatFirstToken(\n"
+      "    TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
+      "                       ? IndentForLevel[TheLine.Level] : TheLine * 2,\n"
+      "    TheLine.InPPDirective, PreviousEndOfLineColumn);");
 }
 
 TEST_F(FormatTest, DeclarationsOfMultipleVariables) {





More information about the cfe-commits mailing list