Re: [PATCH] D15643: [clang-format] Don't allow newline after uppercase Obj-C block return types

2016-09-26 Thread Kent Sutherland via cfe-commits
ksuther updated this revision to Diff 72578.
ksuther added a comment.

Added a unit test.


https://reviews.llvm.org/D15643

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11156,6 +11156,8 @@
"  }\n"
"});");
   verifyFormat("Block b = ^int *(A *a, B *b) {}");
+  verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n"
+   "};");
 
   FormatStyle FourIndent = getLLVMStyle();
   FourIndent.ObjCBlockIndentWidth = 4;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1037,12 +1037,17 @@
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
  tok::period, tok::arrow, tok::coloncolon))
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration))
-Current.Type = TT_FunctionAnnotationRParen;
+if (FormatToken *AfterParen = Current.MatchingParen->Next) {
+  // Make sure this isn't the return type of an Obj-C block declaration
+  if (AfterParen->Tok.isNot(tok::caret)) {
+if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
+  if (BeforeParen->is(tok::identifier) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration))
+Current.Type = TT_FunctionAnnotationRParen;
+  }
+   }
 } else if (Current.is(tok::at) && Current.Next) {
   if (Current.Next->isStringLiteral()) {
 Current.Type = TT_ObjCStringLiteral;


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11156,6 +11156,8 @@
"  }\n"
"});");
   verifyFormat("Block b = ^int *(A *a, B *b) {}");
+  verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n"
+   "};");
 
   FormatStyle FourIndent = getLLVMStyle();
   FourIndent.ObjCBlockIndentWidth = 4;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1037,12 +1037,17 @@
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
  tok::period, tok::arrow, tok::coloncolon))
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration))
-Current.Type = TT_FunctionAnnotationRParen;
+if (FormatToken *AfterParen = Current.MatchingParen->Next) {
+  // Make sure this isn't the return type of an Obj-C block declaration
+  if (AfterParen->Tok.isNot(tok::caret)) {
+if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
+  if (BeforeParen->is(tok::identifier) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration))
+Current.Type = TT_FunctionAnnotationRParen;
+  }
+		}
 } else if (Current.is(tok::at) && Current.Next) {
   if (Current.Next->isStringLiteral()) {
 Current.Type = TT_ObjCStringLiteral;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15643: [clang-format] Don't allow newline after uppercase Obj-C block return types

2016-08-22 Thread Kent Sutherland via cfe-commits
ksuther updated this revision to Diff 68930.
ksuther added a comment.

This was accepted a few months ago but it got buried and was never committed. 
The diff has been updated so that it can be committed cleanly.


https://reviews.llvm.org/D15643

Files:
  lib/Format/TokenAnnotator.cpp

Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1037,12 +1037,17 @@
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
  tok::period, tok::arrow, tok::coloncolon))
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration))
-Current.Type = TT_FunctionAnnotationRParen;
+if (FormatToken *AfterParen = Current.MatchingParen->Next) {
+  // Make sure this isn't the return type of an Obj-C block declaration
+  if (AfterParen->Tok.isNot(tok::caret)) {
+if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
+  if (BeforeParen->is(tok::identifier) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration))
+Current.Type = TT_FunctionAnnotationRParen;
+  }
+   }
 } else if (Current.is(tok::at) && Current.Next) {
   if (Current.Next->isStringLiteral()) {
 Current.Type = TT_ObjCStringLiteral;


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1037,12 +1037,17 @@
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
  tok::period, tok::arrow, tok::coloncolon))
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration))
-Current.Type = TT_FunctionAnnotationRParen;
+if (FormatToken *AfterParen = Current.MatchingParen->Next) {
+  // Make sure this isn't the return type of an Obj-C block declaration
+  if (AfterParen->Tok.isNot(tok::caret)) {
+if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
+  if (BeforeParen->is(tok::identifier) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration))
+Current.Type = TT_FunctionAnnotationRParen;
+  }
+		}
 } else if (Current.is(tok::at) && Current.Next) {
   if (Current.Next->isStringLiteral()) {
 Current.Type = TT_ObjCStringLiteral;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17922: [clang-format] Don't add a space before Obj-C selector methods that are also clang-format keywords

2016-03-06 Thread Kent Sutherland via cfe-commits
ksuther created this revision.
ksuther added a reviewer: djasper.
ksuther added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The following Obj-C methods will get formatted with an extra space between the 
right paren and the name:

`- (void)delete:(id)sender`
`- (void)export:(id)sender`

So they'll incorrectly appear as:

`- (void) delete:(id)sender`
`- (void) export:(id)sender`

The fix is to check if the token is a TT_SelectorName instead of 
tok::identifier. That way keywords recognized by clang-format still get treated 
as an Obj-C method name (because they're both a TT_SelectorName and tok::delete 
type).

http://reviews.llvm.org/D17922

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7433,6 +7433,7 @@
" y:(id)y\n"
"NS_DESIGNATED_INITIALIZER;",
getLLVMStyleWithColumns(60));
+  verifyFormat("- (void)delete:(id)sender\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2077,7 +2077,7 @@
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && Right.is(tok::identifier))
+if (Left.is(tok::r_paren) && Right.is(TT_SelectorName))
   // Don't space between ')' and 
   return false;
   }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7433,6 +7433,7 @@
" y:(id)y\n"
"NS_DESIGNATED_INITIALIZER;",
getLLVMStyleWithColumns(60));
+  verifyFormat("- (void)delete:(id)sender\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2077,7 +2077,7 @@
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && Right.is(tok::identifier))
+if (Left.is(tok::r_paren) && Right.is(TT_SelectorName))
   // Don't space between ')' and 
   return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17700: [clang-format] Proposal for changes to Objective-C block formatting

2016-03-06 Thread Kent Sutherland via cfe-commits
ksuther updated this revision to Diff 49928.
ksuther added a comment.

Thanks for the comments. I've made some changes that eliminates reverting 
r236598 and instead makes the behavior part of `IndentNestedBlocks`. That 
allows the Google Obj-C code style 
(https://google.github.io/styleguide/objcguide.xml#Blocks) to still work by 
default. The issue with a parameter between block parameters has also been 
fixed (as part of `AllowNewlineBeforeBlockParameter`).

Apologies if I'm missing something obvious, but I don't see how 
`AllowNewlineBeforeBlockParameter` belongs in `BraceWrapping`. Blocks aren't 
the same as braces, in the original example, this option would be controlling 
the newline insertion for `completionBlock:^(SessionWindow* window) {` and not 
just the opening brace.


http://reviews.llvm.org/D17700

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7136,6 +7136,22 @@
"  outRange8:(NSRange)out_range8\n"
"  outRange9:(NSRange)out_range9;");
 
+  FormatStyle NoIndentStyle = getLLVMStyle();
+  NoIndentStyle.IndentNestedBlocks = false;
+  verifyFormat("- (NSUInteger)indexOfObject:(id)anObject\n"
+   "inRange:(NSRange)range\n"
+   "   outRange:(NSRange)out_range\n"
+   "  outRange1:(NSRange)out_range1\n"
+   "  outRange2:(NSRange)out_range2\n"
+   "  outRange3:(NSRange)out_range3\n"
+   "  outRange4:(NSRange)out_range4\n"
+   "  outRange5:(NSRange)out_range5\n"
+   "  outRange6:(NSRange)out_range6\n"
+   "  outRange7:(NSRange)out_range7\n"
+   "  outRange8:(NSRange)out_range8\n"
+   "  outRange9:(NSRange)out_range9;",
+   NoIndentStyle);
+
   // When the function name has to be wrapped.
   FormatStyle Style = getLLVMStyle();
   Style.IndentWrappedFunctionNames = false;
@@ -10849,6 +10865,20 @@
"[self onOperationDone];\n"
"}];",
FourIndent);
+
+  FormatStyle NoNestedBlocks = getLLVMStyle();
+  NoNestedBlocks.IndentNestedBlocks = false;
+  verifyFormat("[self block:^(void) {\n"
+   "  doStuff();\n"
+   "} completionHandler:^(void) {\n"
+   "  doStuff();\n"
+   "  [self block:^(void) {\n"
+   "doStuff();\n"
+   "  } completionHandler:^(void) {\n"
+   "doStuff();\n"
+   "  }];\n"
+   "}];",
+   NoNestedBlocks);
 }
 
 TEST_F(FormatTest, FormatsBlocksWithZeroColumnWidth) {
@@ -10916,6 +10946,24 @@
 "  int i;\n"
 "};",
 format("void   (^largeBlock)(void) = ^{ int   i; };", ZeroColumn));
+
+  FormatStyle DisallowNewline = getLLVMStyle();
+  DisallowNewline.AllowNewlineBeforeBlockParameter = false;
+  DisallowNewline.ColumnLimit = 0;
+  verifyFormat("[[SessionService sharedService] loadWindowWithCompletionBlock:^(SessionWindow *window) {\n"
+   "  if (window) {\n"
+   "[self windowDidLoad:window];\n"
+   "  } else {\n"
+   "[self errorLoadingWindow];\n"
+   "  }\n"
+   "}];",
+   DisallowNewline);
+  verifyFormat("[controller test:^{\n"
+   "  doStuff();\n"
+   "} withTimeout:5 completionHandler:^{\n"
+   "  doStuff();\n"
+   "}];",
+   DisallowNewline);
 }
 
 TEST_F(FormatTest, SupportsCRLF) {
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -304,6 +304,10 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentNestedBlocks",
+   Style.IndentNestedBlocks);
+IO.mapOptional("AllowNewlineBeforeBlockParameter",
+   Style.AllowNewlineBeforeBlockParameter);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -519,6 +523,8 @@
  {".*", 1}};
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentWrappedFunctionNames = false;
+  LLVMStyle.IndentNestedBlocks = true;
+  LLVMStyle.AllowNewlineBeforeBlockParameter = true;
   LLVMStyle.IndentWidth = 2;
   LLVMStyle.TabWidth = 8;
   

Re: [PATCH] D15643: [clang-format] Don't allow newline after uppercase Obj-C block return types

2016-03-06 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

Thank you! I don't have commit access, so could this be committed by someone 
who does?


http://reviews.llvm.org/D15643



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17700: [clang-format] Proposal for changes to Objective-C block formatting

2016-02-28 Thread Kent Sutherland via cfe-commits
ksuther created this revision.
ksuther added a reviewer: djasper.
ksuther added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Changes to clang-format's Objective-C block formatting over the past year have 
made clang-format's output deviate from what is expected (in my opinion).

There are three changes in particular:

- Method calls with multiple block parameters has each block indented further in
- Nested blocks get indented one level in
- Method calls that end with a block parameter always get forced to a new line 
and indented

The end of this message has examples of formatting with and without these 
changes.

This patch undoes one revision which causes methods with multiple block 
parameters to indent for each parameter (r236598) and adds two new options.
AllowNewlineBeforeBlockParameter makes the change in r235580 optional.
IndentNestedBlocks makes the change in r234304 optional.

Some relevant Bugzilla issues:
https://llvm.org/bugs/show_bug.cgi?id=23585
https://llvm.org/bugs/show_bug.cgi?id=23317

This patch came out of a discussion here 
https://github.com/square/spacecommander/issues/33, where we're using a custom 
version of clang-format with these options added. Based on the Bugzilla issues, 
it seems that we're not alone.

Thanks!

---

Current trunk:

bin/clang-format -style="{BasedOnStyle: WebKit, ColumnLimit: 0, IndentWidth: 
4}" ~/clang-format.m

```
- (void)test
{
[self block:^(void) {
doStuff();
}
completionHandler:^(void) {
doStuff();

[self block:^(void) {
doStuff();
}
completionHandler:^(void) {
doStuff();
}];
}];

[[SessionService sharedService] loadWindow:aWindow
   completionBlock:^(SessionWindow* window) {
   if (window) {
   [self doStuff];
   }
   }];
}
```

With this patch applied:

bin/clang-format -style="{BasedOnStyle: WebKit, ColumnLimit: 0, IndentWidth: 4, 
IndentNestedBlocks: false, AllowNewlineBeforeBlockParameter: 
false}"~/clang-format.m 

```
- (void)test
{
[self block:^(void) {
doStuff();
} completionHandler:^(void) {
doStuff();

[self block:^(void) {
doStuff();
} completionHandler:^(void) {
doStuff();
}];
}];

[[SessionService sharedService] loadWindow:aWindow 
completionBlock:^(SessionWindow* window) {
if (window) {
[self doStuff];
}
}];
}
```

http://reviews.llvm.org/D17700

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7606,13 +7606,6 @@
   " aaa | aaa | aaa |\n"
   " aaa | aaa];");
 
-  // FIXME: This violates the column limit.
-  verifyFormat(
-  "[a\n"
-  "a:\n"
-  "  aaa:a];",
-  getLLVMStyleWithColumns(60));
-
   // Variadic parameters.
   verifyFormat(
   "NSArray *myStrings = [NSArray stringarray:@\"a\", @\"b\", nil];");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -296,6 +296,10 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentNestedBlocks",
+   Style.IndentNestedBlocks);
+IO.mapOptional("AllowNewlineBeforeBlockParameter",
+   Style.AllowNewlineBeforeBlockParameter);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -510,6 +514,8 @@
  {".*", 1}};
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentWrappedFunctionNames = false;
+  LLVMStyle.IndentNestedBlocks = true;
+  LLVMStyle.AllowNewlineBeforeBlockParameter = true;
   LLVMStyle.IndentWidth = 2;
   LLVMStyle.TabWidth = 8;
   LLVMStyle.MaxEmptyLinesToKeep = 1;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -178,9 +178,6 @@
   ((Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All) ||
Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))
 return true;
-  if 

Re: [PATCH] D15643: [clang-format] Don't allow newline after uppercase Obj-C block return types

2016-02-28 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

This patch got buried, giving it a bump to see if anyone can take a look at it.


http://reviews.llvm.org/D15643



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D15643: Don't allow newline after uppercase Obj-C block return types

2015-12-18 Thread Kent Sutherland via cfe-commits
ksuther created this revision.
ksuther added a reviewer: djasper.
ksuther added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Fixes the following:

BOOL (^aaa)(void) = ^BOOL {
};

The first BOOL's token was getting set to TT_FunctionAnnotationRParen 
incorrectly, which was causing an unexpected newline after (^aaa). This was 
introduced in r245846.

http://reviews.llvm.org/D15643

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10608,6 +10608,9 @@
"});");
   verifyFormat("Block b = ^int *(A *a, B *b) {}");
 
+  verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n"
+   "};");
+
   FormatStyle FourIndent = getLLVMStyle();
   FourIndent.ObjCBlockIndentWidth = 4;
   verifyFormat("[operation setCompletionBlock:^{\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -955,12 +955,17 @@
   if (Current.MatchingParen && Current.Next &&
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace))
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration))
-Current.Type = TT_FunctionAnnotationRParen;
+if (FormatToken *AfterParen = Current.MatchingParen->Next) {
+  // Make sure this isn't the return type of an Obj-C block declaration
+  if (AfterParen->Tok.isNot(tok::caret)) {
+if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
+  if (BeforeParen->is(tok::identifier) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration))
+Current.Type = TT_FunctionAnnotationRParen;
+  }
+}
 } else if (Current.is(tok::at) && Current.Next) {
   if (Current.Next->isStringLiteral()) {
 Current.Type = TT_ObjCStringLiteral;


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -10608,6 +10608,9 @@
"});");
   verifyFormat("Block b = ^int *(A *a, B *b) {}");
 
+  verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n"
+   "};");
+
   FormatStyle FourIndent = getLLVMStyle();
   FourIndent.ObjCBlockIndentWidth = 4;
   verifyFormat("[operation setCompletionBlock:^{\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -955,12 +955,17 @@
   if (Current.MatchingParen && Current.Next &&
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace))
-if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
-  if (BeforeParen->is(tok::identifier) &&
-  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
-  (!BeforeParen->Previous ||
-   BeforeParen->Previous->ClosesTemplateDeclaration))
-Current.Type = TT_FunctionAnnotationRParen;
+if (FormatToken *AfterParen = Current.MatchingParen->Next) {
+  // Make sure this isn't the return type of an Obj-C block declaration
+  if (AfterParen->Tok.isNot(tok::caret)) {
+if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
+  if (BeforeParen->is(tok::identifier) &&
+  BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
+  (!BeforeParen->Previous ||
+   BeforeParen->Previous->ClosesTemplateDeclaration))
+Current.Type = TT_FunctionAnnotationRParen;
+  }
+}
 } else if (Current.is(tok::at) && Current.Next) {
   if (Current.Next->isStringLiteral()) {
 Current.Type = TT_ObjCStringLiteral;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-10-10 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

This patch is still awaiting a commit. Sorry to repeatedly post about this, 
just don't want it to get lost.

Thanks!


http://reviews.llvm.org/D12501



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-10-06 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

Do I need to do anything else about this and http://reviews.llvm.org/D12489, or 
do they eventually get committed by someone else? Thanks!


http://reviews.llvm.org/D12501



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-09-22 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

I do not.


http://reviews.llvm.org/D12501



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-17 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

Adding another comment in hopes of getting some visibility on this. Do I need 
to add other people as reviewers?


http://reviews.llvm.org/D12489



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-09-17 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

Adding another comment in hopes of getting some visibility on this. Do I need 
to add other people as reviewers?


http://reviews.llvm.org/D12501



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-09-17 Thread Kent Sutherland via cfe-commits
ksuther added inline comments.


Comment at: lib/Format/TokenAnnotator.cpp:377
@@ -376,1 +376,3 @@
+(!Contexts.back().ColonIsDictLiteral ||
+ Style.Language != FormatStyle::LK_Cpp)) ||
Style.Language == FormatStyle::LK_Proto) &&

djasper wrote:
> Why the language check? If it is needed, can you add a test?
The language check is so that this only applies to Objective-C literals. 
Protocol Buffers already have a test suite that tests the conditional here 
(FormatTestProto.cpp). The reason for the check is that the tree for 
Objective-C literals and Protocol Buffers looks the same in this situation, but 
the format behavior needs to differ.


http://reviews.llvm.org/D12501



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-03 Thread Kent Sutherland via cfe-commits
ksuther updated this revision to Diff 33947.
ksuther added a comment.

Added two tests: One of a for/in loop with a cast, and one without.


http://reviews.llvm.org/D12489

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7430,6 +7430,19 @@
"@import baz;");
 }
 
+TEST_F(FormatTest, ObjCForIn) {
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+}
+
 TEST_F(FormatTest, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1900,7 +1900,8 @@
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
-  tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
+  tok::kw_switch, tok::kw_case, TT_ForEachMacro,
+  TT_ObjCForIn) ||
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7430,6 +7430,19 @@
"@import baz;");
 }
 
+TEST_F(FormatTest, ObjCForIn) {
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+  verifyFormat("- (void)test {\n"
+   "  for (NSString *n in (__bridge NSArray *)arrayOfStrings) {\n"
+   "foo(n);\n"
+   "  }\n"
+   "}");
+}
+
 TEST_F(FormatTest, ObjCLiterals) {
   verifyFormat("@\"String\"");
   verifyFormat("@1");
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1900,7 +1900,8 @@
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
-  tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
+  tok::kw_switch, tok::kw_case, TT_ForEachMacro,
+  TT_ObjCForIn) ||
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-08-31 Thread Kent Sutherland via cfe-commits
ksuther added a reviewer: djasper.
ksuther added a comment.

This is my first commit and I'm trying to figure out the system, hope I'm doing 
this right.


http://reviews.llvm.org/D12489



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-08-31 Thread Kent Sutherland via cfe-commits
ksuther created this revision.
ksuther added a reviewer: djasper.
ksuther added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Fixes this bug: https://llvm.org/bugs/show_bug.cgi?id=22647

The following dictionary was getting formatted oddly:

NSDictionary *query = @{
(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
(__bridge id)kSecReturnData: (__bridge id)kCFBooleanTrue,
};

It was turning into this:

NSDictionary *passwordQuery = @{
  (__bridge id) kSecClass : (__bridge id)kSecClassGenericPassword, (__bridge id)
  kSecReturnData : (__bridge id)kCFBooleanTrue, (__bridge id)
  kSecReturnAttributes : (__bridge id)kCFBooleanTrue,
};

As far as I can tell, changes to format Proto lines correctly was turning the 
key (e.g. kSecClass) into a TT_SelectorName, which was then force the cast to 
get separated from the key. I added an extra check to see if the current 
context is in a dictionary literal, and if so kept the type as TT_Unknown.

http://reviews.llvm.org/D12501

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7502,6 +7502,12 @@
"  bb : b,\n"
"   : ccc\n"
"}];");
+
+  // Ensure that casts before the key are kept on the same line as the key
+  verifyFormat("NSDictionary *query = @{\n"
+   "  (__bridge id)kSecClass : (__bridge 
id)kSecClassGenericPassword,\n"
+   "  (__bridge id)kSecReturnData : (__bridge id)kCFBooleanTrue,\n"
+   "};");
 }
 
 TEST_F(FormatTest, ObjCArrayLiterals) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -372,7 +372,9 @@
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
-  if ((CurrentToken->is(tok::colon) ||
+  if (((CurrentToken->is(tok::colon) &&
+(!Contexts.back().ColonIsDictLiteral ||
+ Style.Language != FormatStyle::LK_Cpp)) ||
Style.Language == FormatStyle::LK_Proto) &&
   Previous->is(tok::identifier))
 Previous->Type = TT_SelectorName;


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7502,6 +7502,12 @@
"  bb : b,\n"
"   : ccc\n"
"}];");
+
+  // Ensure that casts before the key are kept on the same line as the key
+  verifyFormat("NSDictionary *query = @{\n"
+   "  (__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,\n"
+   "  (__bridge id)kSecReturnData : (__bridge id)kCFBooleanTrue,\n"
+   "};");
 }
 
 TEST_F(FormatTest, ObjCArrayLiterals) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -372,7 +372,9 @@
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
-  if ((CurrentToken->is(tok::colon) ||
+  if (((CurrentToken->is(tok::colon) &&
+(!Contexts.back().ColonIsDictLiteral ||
+ Style.Language != FormatStyle::LK_Cpp)) ||
Style.Language == FormatStyle::LK_Proto) &&
   Previous->is(tok::identifier))
 Previous->Type = TT_SelectorName;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits