Fix handling of fake parenthesis during formatting.
authorDaniel Jasper <djasper@google.com>
Fri, 8 Feb 2013 16:49:27 +0000 (16:49 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 Feb 2013 16:49:27 +0000 (16:49 +0000)
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);

llvm-svn: 174718

clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/unittests/Format/FormatTest.cpp

index 485624b7faa5e805f69344578d6f5177c2164356..db059018c26fc1900b241520f9dd75dbb88eccf1 100644 (file)
@@ -722,7 +722,7 @@ public:
         if (OperatorFound) {
           ++Start->FakeLParens;
           if (Current != NULL)
-            ++Current->FakeRParens;
+            ++Current->Parent->FakeRParens;
         }
         return;
       }
index dc936e48b5ccef3bd22a7fcc16da5a2f6e6afc76..85e41021c213823c2c93794ab92c213a3677bcbc 100644 (file)
@@ -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 {
index 7176fa5a979dfc5140701b8cd734c09968f8bfac..997a55353b1b4277c8e1a5c9e56fea6d0987a908 100644 (file)
@@ -1271,6 +1271,11 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
                "           : 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) {