[clang] a679499 - [clang-format] treat 'lock' as a keyword for C# code

Jonathan Coe via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 05:39:14 PDT 2020


Author: Jonathan Coe
Date: 2020-06-08T13:31:22+01:00
New Revision: a67949913a6b19860fdc616da2fad00bf7beb3f8

URL: https://github.com/llvm/llvm-project/commit/a67949913a6b19860fdc616da2fad00bf7beb3f8
DIFF: https://github.com/llvm/llvm-project/commit/a67949913a6b19860fdc616da2fad00bf7beb3f8.diff

LOG: [clang-format] treat 'lock' as a keyword for C# code

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 9f2580367d0f..6e8dc690eeb9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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) {

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index dd2ed292ccd8..584b8aea383f 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -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);


        


More information about the cfe-commits mailing list