[PATCH] D56226: [clang-format] square parens that are followed by '=' are not Objective-C message sends
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 3 11:24:52 PST 2019
arphaman updated this revision to Diff 180110.
arphaman added a comment.
Do not annotate one token `[ .... ]` expressions as Objective-C message sends as suggested by Duncan.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56226/new/
https://reviews.llvm.org/D56226
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestObjC.cpp
Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -166,6 +166,20 @@
EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
}
+TEST(FormatTestObjCStyle, AvoidDetectingDesignatedInitializersAsObjCInHeaders) {
+ auto Style = getStyle("LLVM", "a.h", "none",
+ "static const char *names[] = {[0] = \"foo\",\n"
+ "[kBar] = \"bar\"};");
+ ASSERT_TRUE((bool)Style);
+ EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+ Style = getStyle("LLVM", "a.h", "none",
+ "static const char *names[] = {[0] EQ \"foo\",\n"
+ "[kBar] EQ \"bar\"};");
+ ASSERT_TRUE((bool)Style);
+ EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+}
+
TEST_F(FormatTestObjC, FormatObjCTryCatch) {
verifyFormat("@try {\n"
" f();\n"
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -495,9 +495,13 @@
if (CurrentToken->is(tok::r_square)) {
if (IsCpp11AttributeSpecifier)
CurrentToken->Type = TT_AttributeSquare;
- else if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) &&
+ else if (((CurrentToken->Next &&
+ (CurrentToken->Next->is(tok::l_paren) ||
+ CurrentToken->Next->is(tok::equal))) ||
+ (CurrentToken->Previous->Previous == Left)) &&
Left->is(TT_ObjCMethodExpr)) {
- // An ObjC method call is rarely followed by an open parenthesis.
+ // An ObjC method call is rarely followed by an open parenthesis or
+ // an assignment. It also usually contains more than one token.
// FIXME: Do we incorrectly label ":" with this?
StartsObjCMethodExpr = false;
Left->Type = TT_Unknown;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56226.180110.patch
Type: text/x-patch
Size: 2007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190103/d1323f42/attachment.bin>
More information about the cfe-commits
mailing list