[PATCH] clang-format: Support @synchronized.

Daniel Jasper djasper at google.com
Thu Jun 11 21:21:59 PDT 2015


================
Comment at: docs/ClangFormatStyleOptions.rst:422-424
@@ -421,1 +421,5 @@
 
+**ObjCSpaceAfterSynchronized** (``bool``)
+  Add a space after ``@synchronized`` in Objective-C, i.e. use
+  ``\@synchronized (lock)`` instead of ``@synchronized(lock)``.
+
----------------
strager wrote:
> djasper wrote:
> > Don't write these by hand. They should be auto-generated with cfe/docs/tools/dump_format_style.py.
> Good to know. I assume that applies for my other diffs as well.
Yes.

================
Comment at: lib/Format/FormatToken.h:287
@@ -286,1 +286,3 @@
   }
+  bool is(clang::tok::ObjCKeywordKind Kind) const {
+    return Tok.getObjCKeywordID() == Kind;
----------------
strager wrote:
> djasper wrote:
> > 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.
> Sure. I'll do it in a separate patch, along with similar types like preprocessor keywords.
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.

================
Comment at: lib/Format/TokenAnnotator.cpp:1850-1851
@@ -1848,2 +1849,4 @@
               (!Left.Previous || Left.Previous->isNot(tok::period))))) ||
+           (Style.ObjCSpaceAfterSynchronized &&
+            Left.is(tok::objc_synchronized)) ||
            (Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
----------------
strager wrote:
> djasper wrote:
> > Can you swap the operand order? I would find that easier to read.
> You mean:
> 
> ````
> (Left.is(tok::objc_synchronized) &&
>  Style.ObjCSpaceAfterSynchronized)
> ````
> 
> ?
> 
> I was keeping consistent with lines 1852 and 1844, where the `Style` check comes first.
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.

http://reviews.llvm.org/D10371

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list