This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Support @synchronized.
AbandonedPublic

Authored by strager on Jun 10 2015, 4:07 PM.

Details

Reviewers
thakis
Summary

Format @synchronized properly for the Attach brace style by
recognizing @synchronized similar to 'while'. Doing this
triggers the SpaceBeforeParens rule, so fix up existing
tests which assumed the old behaviour.

Depends on D10420.

Diff Detail

Event Timeline

strager updated this revision to Diff 27472.Jun 10 2015, 4:07 PM
strager retitled this revision from to clang-format: Support @synchronized..
strager updated this object.
strager edited the test plan for this revision. (Show Details)
strager added a reviewer: djasper.
strager added subscribers: sas, abdulras, Unknown Object (MLST).
djasper edited edge metadata.Jun 11 2015, 1:23 AM

I can't see the changes to tests at the moment. Trying to fix that issue with SVN/Phabricator (it's unrelated to you patch).

docs/ClangFormatStyleOptions.rst
422–424 ↗(On Diff #27472)

Don't write these by hand. They should be auto-generated with cfe/docs/tools/dump_format_style.py.

include/clang/Format/Format.h
405 ↗(On Diff #27472)

This should go together with ObjCSpaceAfterProperty.

496 ↗(On Diff #27472)

Sort this to the right place.

lib/Format/FormatToken.h
287 ↗(On Diff #27472)

remove clang::

Also, do you mind cleaning up the other usage of getObjCKeywordID() ==. There shouldn't be that many, so this can be done in the same patch.

lib/Format/TokenAnnotator.cpp
1910–1911

Can you swap the operand order? I would find that easier to read.

strager planned changes to this revision.Jun 11 2015, 2:19 PM
strager added inline comments.
docs/ClangFormatStyleOptions.rst
422–424 ↗(On Diff #27472)

Good to know. I assume that applies for my other diffs as well.

include/clang/Format/Format.h
405 ↗(On Diff #27472)

Yup. (I originally named it SpaceAfterObjCSynchronized, which is why it's placed here.)

lib/Format/FormatToken.h
287 ↗(On Diff #27472)

Sure. I'll do it in a separate patch, along with similar types like preprocessor keywords.

lib/Format/TokenAnnotator.cpp
1910–1911

You mean:

`
(Left.is(tok::objc_synchronized) &&
 Style.ObjCSpaceAfterSynchronized)
`

?

I was keeping consistent with lines 1852 and 1844, where the Style check comes first.

djasper added inline comments.Jun 11 2015, 9:21 PM
docs/ClangFormatStyleOptions.rst
422–424 ↗(On Diff #27472)

Yes.

lib/Format/FormatToken.h
287 ↗(On Diff #27472)

AFAICT, there are only three other places in clang-format that could make use of this. Please do that in this patch. Otherwise, we'll just forget.

lib/Format/TokenAnnotator.cpp
1910–1911

It is what I meant, but you are right, keeping consistent with the rest of this (awful ;-) ) expression is probably better.

My thinking is that I like to read it better the other way round, but having the style flag first can actually bring a performance improvement for the other parts of this expression. So just leave as is.

strager updated this revision to Diff 27599.Jun 12 2015, 2:32 PM
strager updated this object.
strager edited edge metadata.

Fix some things.

strager updated this revision to Diff 27605.Jun 12 2015, 2:46 PM

Fix test diff on Phabricator.

djasper added inline comments.Jun 23 2015, 4:23 AM
docs/ClangFormatStyleOptions.rst
420 ↗(On Diff #27605)

Actually, I don't think we should have this option at all (and possibly not the one above either, but I can try to deprecate that later). Would it work for you to bind this to what is selected for SpaceBeforeParens? Specifically, can we handle this like control statements? If not, can we extend SpacesBeforeParens to have more enum values?

lib/Format/UnwrappedLineParser.cpp
683

Remove "Tok." (and below).

strager planned changes to this revision.Jun 25 2015, 5:31 PM

I'll remove ObjCSpaceAfterSynchronized from this diff.

docs/ClangFormatStyleOptions.rst
420 ↗(On Diff #27605)

Would it work for you to bind this to what is selected for SpaceBeforeParens? Specifically, can we handle this like control statements?

Yes. This patch does that *and* has an option to force spaces. I can split the patch in two so it's obvious. This will cause @synchronized to change its formatting, though.

Would it work for you to bind this to what is selected for SpaceBeforeParens?

Sadly, my code base doesn't work this way. =[

@synchronized(foo) {  // No space.
    bar;
}
if (baz) {  // Space.
    qix;
}

My code base seems to consistently hug ( with Objective-C @ keywords (@property(...), @synchronized(...), etc.).

If not, can we extend SpacesBeforeParens to have more enum values?

Yeah, I think that's a better approach. I'll leave that discussion for a separate patch.

strager updated this revision to Diff 28534.Jun 25 2015, 11:35 PM

Strip out ObjCSpaceAfterSynchronized option.

thakis added a subscriber: thakis.Jun 26 2015, 7:47 AM
thakis added inline comments.
unittests/Format/FormatTest.cpp
7490

Hm, this looks like a bit of a regression. I've never seen @synchronized() with a space before the ( – https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html puts spaces after the if but not after @synchronized for example.

Maybe spaceRequiredBetween() could always return false if Right is '(' and the token before Left is @?

I'm not sure this even needs an option.

strager added inline comments.Jun 26 2015, 1:13 PM
unittests/Format/FormatTest.cpp
7490

I've never seen @synchronized() with a space before the (

I view @synchronized similar to while.

D10760 implements the behaviour you're talking about as an option.

I can treat @synchronized as something different than a ControlStatement, if that works for you.

strager planned changes to this revision.Jun 29 2015, 4:45 PM
djasper edited reviewers, added: thakis; removed: djasper.Jul 1 2015, 2:13 AM
djasper added a subscriber: djasper.
strager updated this revision to Diff 34957.Sep 16 2015, 6:08 PM

Rebase. Fix style issues.

strager abandoned this revision.Oct 10 2019, 6:41 PM