r187631 - clang-format: Operator precendence in ObjC method exprs.
Daniel Jasper
djasper at google.com
Thu Aug 1 16:13:03 PDT 2013
Author: djasper
Date: Thu Aug 1 18:13:03 2013
New Revision: 187631
URL: http://llvm.org/viewvc/llvm-project?rev=187631&view=rev
Log:
clang-format: Operator precendence in ObjC method exprs.
Patch (mostly) by Adam Strzelecki. Thanks!
Before:
[self aaaaaa:bbbbbbbbbbbbb
aaaaaaaaaa:bbbbbbbbbbbbbbbbb
aaaaa:bbbbbbbbbbb +
bbbbbbbbbbbb aaaa:bbb];
After:
[self aaaaaa:bbbbbbbbbbbbb
aaaaaaaaaa:bbbbbbbbbbbbbbbbb
aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb
aaaa:bbb];
This fixes llvm.org/PR16150.
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=187631&r1=187630&r2=187631&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Aug 1 18:13:03 2013
@@ -863,6 +863,11 @@ public:
CurrentPrecedence = 1;
else if (Current->Type == TT_BinaryOperator || Current->is(tok::comma))
CurrentPrecedence = 1 + (int)Current->getPrecedence();
+ else if (Current->Type == TT_ObjCSelectorName) {
+ CurrentPrecedence = 1 + (int)prec::Assignment;
+ if (Precedence == CurrentPrecedence)
+ Start = Current;
+ }
}
// At the end of the line or when an operator with higher precedence is
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=187631&r1=187630&r2=187631&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Aug 1 18:13:03 2013
@@ -4787,17 +4787,17 @@ TEST_F(FormatTest, FormatObjCMethodExpr)
verifyFormat(
"void f() {\n"
" if ((self = [super initWithContentRect:contentRect\n"
- " styleMask:styleMask\n"
+ " styleMask:styleMask ?: otherMask\n"
" backing:NSBackingStoreBuffered\n"
" defer:YES]))");
verifyFormat(
"[foo checkThatBreakingAfterColonWorksOk:\n"
- " [bar ifItDoes:reduceOverallLineLengthLikeInThisCase]];");
+ " [bar ifItDoes:reduceOverallLineLengthLikeInThisCase]];");
verifyFormat("[myObj short:arg1 // Force line break\n"
- " longKeyword:arg2\n"
- " evenLongerKeyword:arg3\n"
+ " longKeyword:arg2 != nil ? arg2 : @\"longKeyword\"\n"
+ " evenLongerKeyword:arg3 ?: @\"evenLongerKeyword\"\n"
" error:arg4];");
verifyFormat(
"void f() {\n"
@@ -4834,6 +4834,10 @@ TEST_F(FormatTest, FormatObjCMethodExpr)
"scoped_nsobject<NSTextField> message(\n"
" // The frame will be fixed up when |-setMessageText:| is called.\n"
" [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]);");
+ verifyFormat("[self aaaaaa:bbbbbbbbbbbbb\n"
+ " aaaaaaaaaa:bbbbbbbbbbbbbbbbb\n"
+ " aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb\n"
+ " aaaa:bbb];");
}
TEST_F(FormatTest, ObjCAt) {
More information about the cfe-commits
mailing list