wanders updated this revision to Diff 279010.
wanders added a comment.

- Regenerated rst
- Fixed clang format errors
- Added release note
- Added bool parsing test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84090/new/

https://reviews.llvm.org/D84090

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2165,6 +2165,14 @@
                "  uchar : 8;\n"
                "  uchar other;\n"
                "};");
+  FormatStyle LLVMWithNoSpaceAroundBitfields = getLLVMStyle();
+  LLVMWithNoSpaceAroundBitfields.SpaceAroundBitFieldColon = false;
+  verifyFormat("struct Bitfields {\n"
+               "  unsigned sClass:8;\n"
+               "  unsigned ValueKind:2;\n"
+               "  uchar other;\n"
+               "};",
+               LLVMWithNoSpaceAroundBitfields);
 }
 
 TEST_F(FormatTest, FormatsNamespaces) {
@@ -12156,6 +12164,11 @@
                "int       oneTwoThree : 23 = 0;",
                Alignment);
 
+  Alignment.SpaceAroundBitFieldColon = false;
+  verifyFormat("int const a          :5;\n"
+               "int       oneTwoThree:23;",
+               Alignment);
+
   // Known limitations: ':' is only recognized as a bitfield colon when
   // followed by a number.
   /*
@@ -13685,6 +13698,7 @@
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceAfterLogicalNot);
+  CHECK_PARSE_BOOL(SpaceAroundBitFieldColon);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
   CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3251,6 +3251,8 @@
   if (Right.is(TT_RangeBasedForLoopColon) &&
       !Style.SpaceBeforeRangeBasedForLoopColon)
     return false;
+  if (Left.is(TT_BitFieldColon))
+    return Style.SpaceAroundBitFieldColon;
   if (Right.is(tok::colon)) {
     if (Line.First->isOneOf(tok::kw_case, tok::kw_default) ||
         !Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi))
@@ -3267,6 +3269,8 @@
       return false;
     if (Right.is(TT_CSharpNamedArgumentColon))
       return false;
+    if (Right.is(TT_BitFieldColon))
+      return Style.SpaceAroundBitFieldColon;
     return true;
   }
   if (Left.is(TT_UnaryOperator)) {
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -593,6 +593,7 @@
     IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
     IO.mapOptional("SpaceBeforeSquareBrackets",
                    Style.SpaceBeforeSquareBrackets);
+    IO.mapOptional("SpaceAroundBitFieldColon", Style.SpaceAroundBitFieldColon);
     IO.mapOptional("Standard", Style.Standard);
     IO.mapOptional("StatementMacros", Style.StatementMacros);
     IO.mapOptional("TabWidth", Style.TabWidth);
@@ -918,6 +919,7 @@
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
   LLVMStyle.SpaceBeforeCpp11BracedList = false;
   LLVMStyle.SpaceBeforeSquareBrackets = false;
+  LLVMStyle.SpaceAroundBitFieldColon = true;
   LLVMStyle.SpacesInAngles = false;
   LLVMStyle.SpacesInConditionalStatement = false;
 
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2233,6 +2233,13 @@
   /// \endcode
   bool SpaceBeforeSquareBrackets;
 
+  /// If ``true``, space will be inserted around ``:`` in bitfield declarations.
+  /// \code
+  ///    true:                                  false:
+  ///    unsigned bf : 3;              vs.      unsigned bf:3;
+  /// \endcode
+  bool SpaceAroundBitFieldColon;
+
   /// Supported language standards for parsing and formatting C++ constructs.
   /// \code
   ///    Latest:                                vector<set<int>>
@@ -2409,6 +2416,7 @@
            SpacesInParentheses == R.SpacesInParentheses &&
            SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
            SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
+           SpaceAroundBitFieldColon == R.SpaceAroundBitFieldColon &&
            Standard == R.Standard && TabWidth == R.TabWidth &&
            StatementMacros == R.StatementMacros && UseTab == R.UseTab &&
            UseCRLF == R.UseCRLF && TypenameMacros == R.TypenameMacros;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -149,7 +149,17 @@
 clang-format
 ------------
 
-- ...
+- Option ``SpaceAroundBitFieldColon`` has been added to make spaces
+  between identifier, colon and bitwidth optional.
+
+  .. code-block:: c++
+
+    // true:                    // false:
+    struct F {                  struct F {
+      unsigned dscp : 6;          unsigned dscp:6;
+      unsigned ecn : 2;           unsigned ecn:2;
+    };                          };
+
 
 libclang
 --------
Index: clang/docs/ClangFormatStyleOptions.rst
===================================================================
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -2378,6 +2378,14 @@
      true:                                  false:
      template <int> void foo();     vs.     template<int> void foo();
 
+**SpaceAroundBitFieldColon** (``bool``)
+  If ``true``, space will be inserted around ``:`` in bitfield declarations.
+
+  .. code-block:: c++
+
+     true:                                  false:
+     unsigned bf : 3;              vs.      unsigned bf:3;
+
 **SpaceBeforeAssignmentOperators** (``bool``)
   If ``false``, spaces will be removed before assignment operators.
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to