[PATCH] D57923: [Format/ObjC] Fix [foo bar]->baz formatting as lambda arrow
Ben Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 8 07:54:59 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rC353531: [Format/ObjC] Fix [foo bar]->baz formatting as lambda arrow (authored by benhamilton, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D57923?vs=185859&id=185975#toc
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57923/new/
https://reviews.llvm.org/D57923
Files:
lib/Format/TokenAnnotator.cpp
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestObjC.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1426,6 +1426,9 @@
nextToken();
break;
case tok::arrow:
+ // This might or might not actually be a lambda arrow (this could be an
+ // ObjC method invocation followed by a dereferencing arrow). We might
+ // reset this back to TT_Unknown in TokenAnnotator.
FormatTok->Type = TT_LambdaArrow;
nextToken();
break;
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -520,6 +520,10 @@
if (Parent && Parent->is(TT_PointerOrReference))
Parent->Type = TT_BinaryOperator;
}
+ // An arrow after an ObjC method expression is not a lambda arrow.
+ if (CurrentToken->Type == TT_ObjCMethodExpr && CurrentToken->Next &&
+ CurrentToken->Next->is(TT_LambdaArrow))
+ CurrentToken->Next->Type = TT_Unknown;
Left->MatchingParen = CurrentToken;
CurrentToken->MatchingParen = Left;
// FirstObjCSelectorName is set when a colon is found. This does
Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -611,6 +611,7 @@
TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
verifyFormat("[foo bar:baz];");
+ verifyFormat("[foo bar]->baz;");
verifyFormat("return [foo bar:baz];");
verifyFormat("return (a)[foo bar:baz];");
verifyFormat("f([foo bar:baz]);");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57923.185975.patch
Type: text/x-patch
Size: 1747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190208/c8401007/attachment.bin>
More information about the cfe-commits
mailing list