r224513 - clang-format: Fix incorrect detection of ObjC "in" keyword.

Daniel Jasper djasper at google.com
Thu Dec 18 04:11:02 PST 2014


Author: djasper
Date: Thu Dec 18 06:11:01 2014
New Revision: 224513

URL: http://llvm.org/viewvc/llvm-project?rev=224513&view=rev
Log:
clang-format: Fix incorrect detection of ObjC "in" keyword.

Before:
  for (auto v : in [1]) { ..

After:
  for (auto v : in[1]) { ..

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    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=224513&r1=224512&r2=224513&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Dec 18 06:11:01 2014
@@ -511,7 +511,8 @@ private:
       parseTemplateDeclaration();
       break;
     case tok::identifier:
-      if (Line.First->is(tok::kw_for) && Tok->is(Keywords.kw_in))
+      if (Line.First->is(tok::kw_for) && Tok->is(Keywords.kw_in) &&
+          Tok->Previous->isNot(tok::colon))
         Tok->Type = TT_ObjCForIn;
       break;
     case tok::comma:

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=224513&r1=224512&r2=224513&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Dec 18 06:11:01 2014
@@ -6781,6 +6781,7 @@ TEST_F(FormatTest, FormatObjCMethodExpr)
   // Whew!
 
   verifyFormat("return in[42];");
+  verifyFormat("for (auto v : in[1]) {\n}");
   verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"
                "}");
   verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");





More information about the cfe-commits mailing list