This revision was automatically updated to reflect the committed changes.
benhamilton marked an inline comment as done.
Closed by commit rC327285: [clang-format] Improve detection of Objective-C
block types (authored by benhamilton, committed by ).
Changed prior to commit:
benhamilton updated this revision to Diff 138024.
benhamilton added a comment.
- Restore short functionn type variable names and add clarifying comment.
Repository:
rC Clang
https://reviews.llvm.org/D43906
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
benhamilton marked an inline comment as done.
benhamilton added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:210
-bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
-bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star,
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.
Nice.. Removed a lot of complexity :). Let's see whether this heuristic is good
enough.
Comment at: lib/Format/TokenAnnotator.cpp:210
-bool MightBeFunctionType =
benhamilton added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:152
+ const FormatToken *Next = CurrentToken->getNextNonComment();
+ int ParenDepth = 1;
+ // Handle nested parens in case we have an array of blocks with
djasper wrote:
benhamilton updated this revision to Diff 137394.
benhamilton added a comment.
- Greatly clean up ObjC block type logic by re-using `TT_FunctionTypeLParen`
type logic.
Repository:
rC Clang
https://reviews.llvm.org/D43906
Files:
lib/Format/TokenAnnotator.cpp
benhamilton updated this revision to Diff 137320.
benhamilton added a comment.
Fix comment.
Repository:
rC Clang
https://reviews.llvm.org/D43906
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
unittests/Format/FormatTestObjC.cpp
Index:
benhamilton added a comment.
> Right. So the difference is that for blocks, there is always a "(" after the
> "(^.)". That should be easy to parse, no?
Yep, I've updated this diff to implement that as you recommended. I just had to
handle nested parens (I couldn't find an existing way to
benhamilton updated this revision to Diff 137319.
benhamilton added a comment.
- Simplify logic and assume we have an ObjC block whenever we see rparen at the
end of `(^...)(`.
Repository:
rC Clang
https://reviews.llvm.org/D43906
Files:
lib/Format/TokenAnnotator.cpp
djasper added a comment.
Right. So the difference is that for blocks, there is always a "(" after the
"(^.)". That should be easy to parse, no?
Repository:
rC Clang
https://reviews.llvm.org/D43906
___
cfe-commits mailing list
benhamilton added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:155
+ Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren)))
djasper added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:155
+ Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren))) {
benhamilton added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:155
+ Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren)))
benhamilton added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:155
+ Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren)))
djasper added inline comments.
Comment at: lib/Format/TokenAnnotator.cpp:155
+ Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren))) {
krasimir added inline comments.
Comment at: unittests/Format/FormatTest.cpp:7698
+TEST_F(FormatTest, ObjCBlockTypesAndVariables) {
+ verifyFormat("void DoStuffWithBlockType(int (^)(char));");
This should be in `FormatTestObjC.cpp`.
Repository:
rC Clang
benhamilton added a comment.
> Would it be enough to only add the block type case? With the macro false
> positive, there won't be an open paren after the closing paren, right?
Are you asking to remove the block variable cases? I was concerned those would
no longer be handled correctly if we
benhamilton updated this revision to Diff 137095.
benhamilton marked 2 inline comments as done.
benhamilton added a comment.
- Fix comments from @djasper and @krasimir.
Repository:
rC Clang
https://reviews.llvm.org/D43906
Files:
lib/Format/TokenAnnotator.cpp
djasper added a comment.
Would it be enough to only add the block type case? With the macro false
positive, there won't be an open paren after the closing paren, right?
Comment at: lib/Format/TokenAnnotator.cpp:155
+ Next->startsSequence(tok::identifier,
krasimir added inline comments.
Comment at: unittests/Format/FormatTest.cpp:12027
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+ EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
Please also add formatting tests. This might require changes
benhamilton created this revision.
benhamilton added reviewers: krasimir, jolesiak.
Herald added a subscriber: cfe-commits.
Previously, clang-format would detect the following as an
Objective-C block type:
FOO(^);
when it actually must be a C or C++ macro dealing with an XOR
statement or an
21 matches
Mail list logo