[clang-format] treat 'lock' as a keyword for C# code
authorJonathan Coe <jbcoe@google.com>
Fri, 5 Jun 2020 12:23:34 +0000 (13:23 +0100)
committerJonathan Coe <jbcoe@google.com>
Mon, 8 Jun 2020 12:31:22 +0000 (13:31 +0100)
Summary: This will put a space in `lock (process)` when spaces are required after keywords.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D81255

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp

index 9f25803..6e8dc69 100644 (file)
@@ -3080,7 +3080,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
 
     // space between keywords and paren e.g. "using ("
     if (Right.is(tok::l_paren))
-      if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when))
+      if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when,
+                       Keywords.kw_lock))
         return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements ||
                spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
index dd2ed29..584b8ae 100644 (file)
@@ -741,6 +741,9 @@ foreach ((A a, B b) in someList) {
 })",
                Style);
 
+  // space after lock in `lock (processes)`.
+  verifyFormat("lock (process)", Style);
+
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
   verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);