r199198 - clang-format: Fix bug introduced in r198871.

Daniel Jasper djasper at google.com
Tue Jan 14 01:53:07 PST 2014


Author: djasper
Date: Tue Jan 14 03:53:07 2014
New Revision: 199198

URL: http://llvm.org/viewvc/llvm-project?rev=199198&view=rev
Log:
clang-format: Fix bug introduced in r198871.

We cannot simply change the start column to accomodate for the @ in an
ObjC string literal as that will make clang-format happily violate the
column limit.

Use a different workaround instead. However, a better long-term
solution might be to join the @ and the rest of the literal into a
single token.

Modified:
    cfe/trunk/lib/Format/BreakableToken.cpp
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=199198&r1=199197&r2=199198&view=diff
==============================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Tue Jan 14 03:53:07 2014
@@ -172,9 +172,16 @@ BreakableStringLiteral::getSplit(unsigne
 void BreakableStringLiteral::insertBreak(unsigned LineIndex,
                                          unsigned TailOffset, Split Split,
                                          WhitespaceManager &Whitespaces) {
+  unsigned LeadingSpaces = StartColumn;
+  // The '@' of an ObjC string literal (@"Test") does not become part of the
+  // string token.
+  // FIXME: It might be a cleaner solution to merge the tokens as a
+  // precomputation step.
+  if (Prefix.startswith("@"))
+    --LeadingSpaces;
   Whitespaces.replaceWhitespaceInToken(
       Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix,
-      Prefix, InPPDirective, 1, IndentLevel, StartColumn);
+      Prefix, InPPDirective, 1, IndentLevel, LeadingSpaces);
 }
 
 static StringRef getLineCommentPrefix(StringRef Comment) {

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=199198&r1=199197&r2=199198&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jan 14 03:53:07 2014
@@ -811,7 +811,6 @@ unsigned ContinuationIndenter::breakProt
         Current.Previous->is(tok::at)) {
       IsNSStringLiteral = true;
       Prefix = "@\"";
-      --StartColumn;
     }
     if ((Text.endswith(Postfix = "\"") &&
          (IsNSStringLiteral || Text.startswith(Prefix = "\"") ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=199198&r1=199197&r2=199198&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jan 14 03:53:07 2014
@@ -6266,7 +6266,7 @@ TEST_F(FormatTest, BreaksWideAndNSString
             format("L\"wide string literal\";", getGoogleStyleWithColumns(16)));
   EXPECT_EQ("@\"NSString \"\n"
             "@\"literal\";",
-            format("@\"NSString literal\";", getGoogleStyleWithColumns(16)));
+            format("@\"NSString literal\";", getGoogleStyleWithColumns(19)));
 }
 
 TEST_F(FormatTest, BreaksRawStringLiterals) {





More information about the cfe-commits mailing list