r220197 - clang-format: [ObjC] Fix using selector names as macro arguments.
Daniel Jasper
djasper at google.com
Mon Oct 20 05:01:45 PDT 2014
Author: djasper
Date: Mon Oct 20 07:01:45 2014
New Revision: 220197
URL: http://llvm.org/viewvc/llvm-project?rev=220197&view=rev
Log:
clang-format: [ObjC] Fix using selector names as macro arguments.
Before:
[self aaaaa:MACRO(a, b :, c :)];
After:
[self aaaaa:MACRO(a, b:, c:)];
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=220197&r1=220196&r2=220197&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Oct 20 07:01:45 2014
@@ -413,6 +413,11 @@ private:
} else if (Contexts.size() == 1 &&
!Line.First->isOneOf(tok::kw_enum, tok::kw_case)) {
Tok->Type = TT_InheritanceColon;
+ } else if (Tok->Previous->is(tok::identifier) && Tok->Next &&
+ Tok->Next->isOneOf(tok::r_paren, tok::comma)) {
+ // This handles a special macro in ObjC code where selectors including
+ // the colon are passed as macro arguments.
+ Tok->Type = TT_ObjCMethodExpr;
} else if (Contexts.back().ContextKind == tok::l_paren) {
Tok->Type = TT_InlineASMColon;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=220197&r1=220196&r2=220197&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Oct 20 07:01:45 2014
@@ -6539,6 +6539,7 @@ TEST_F(FormatTest, FormatObjCMethodExpr)
verifyFormat("return in[42];");
verifyFormat("for (id foo in [self getStuffFor:bla]) {\n"
"}");
+ verifyFormat("[self aaaaa:MACRO(a, b:, c:)];");
verifyFormat("[self stuffWithInt:(4 + 2) float:4.5];");
verifyFormat("[self stuffWithInt:a ? b : c float:4.5];");
More information about the cfe-commits
mailing list