[clang] 6568827 - [clang-format][NFC] Clean up AlignConsecutiveStyle (#111285)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 19:12:50 PDT 2024
Author: Owen Pan
Date: 2024-10-07T19:12:47-07:00
New Revision: 65688274b14f5d0e7dabbbaf9f3fd135646ef1d1
URL: https://github.com/llvm/llvm-project/commit/65688274b14f5d0e7dabbbaf9f3fd135646ef1d1
DIFF: https://github.com/llvm/llvm-project/commit/65688274b14f5d0e7dabbbaf9f3fd135646ef1d1.diff
LOG: [clang-format][NFC] Clean up AlignConsecutiveStyle (#111285)
- Add a `CHECK_PARSE` for `AcrossComments`.
- Add a `CHECK_PARSE_NESTED_BOOL` for `AlignFunctionPointers`.
- Remove redundant statements.
- Clean up documentation.
Added:
Modified:
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp
Removed:
################################################################################
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 7a1508ee858c41..a9bfb4c4a0fcb2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -249,7 +249,7 @@ the configuration (without a prefix: ``Auto``).
.. _AlignArrayOfStructures:
**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <AlignArrayOfStructures>`
- if not ``None``, when using initialization for an array of structs
+ If not ``None``, when using initialization for an array of structs
aligns the fields into columns.
@@ -307,11 +307,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
@@ -464,11 +465,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
@@ -621,11 +623,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
@@ -779,11 +782,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
@@ -1056,11 +1060,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
@@ -1211,11 +1216,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
@@ -1366,11 +1372,12 @@ the configuration (without a prefix: ``Auto``).
Alignment options.
They can also be read as a whole for compatibility. The choices are:
- - None
- - Consecutive
- - AcrossEmptyLines
- - AcrossComments
- - AcrossEmptyLinesAndComments
+
+ * ``None``
+ * ``Consecutive``
+ * ``AcrossEmptyLines``
+ * ``AcrossComments``
+ * ``AcrossEmptyLinesAndComments``
For example, to align across empty lines and not across comments, either
of these work.
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 82cd863e615a87..3d3e4330902a30 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -131,7 +131,7 @@ struct FormatStyle {
/// Don't align array initializer columns.
AIAS_None
};
- /// if not ``None``, when using initialization for an array of structs
+ /// If not ``None``, when using initialization for an array of structs
/// aligns the fields into columns.
///
/// \note
@@ -145,11 +145,12 @@ struct FormatStyle {
/// Alignment options.
///
/// They can also be read as a whole for compatibility. The choices are:
- /// - None
- /// - Consecutive
- /// - AcrossEmptyLines
- /// - AcrossComments
- /// - AcrossEmptyLinesAndComments
+ ///
+ /// * ``None``
+ /// * ``Consecutive``
+ /// * ``AcrossEmptyLines``
+ /// * ``AcrossComments``
+ /// * ``AcrossEmptyLinesAndComments``
///
/// For example, to align across empty lines and not across comments, either
/// of these work.
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 01b4b6f0b0d2c1..f97127f09d2096 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -50,29 +50,25 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
- /*AlignFunctionPointers=*/false,
- /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
IO.enumCase(Value, "AcrossEmptyLines",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
/*AcrossComments=*/false, /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
- /*AlignFunctionPointers=*/false,
- /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
IO.enumCase(Value, "AcrossComments",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/true, /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
- /*AlignFunctionPointers=*/false,
- /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
IO.enumCase(Value, "AcrossEmptyLinesAndComments",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
/*AcrossComments=*/true, /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
- /*AlignFunctionPointers=*/false,
- /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
// For backward compatibility.
IO.enumCase(Value, "true",
@@ -80,8 +76,7 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
- /*AlignFunctionPointers=*/false,
- /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({}));
}
@@ -1445,11 +1440,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
LLVMStyle.AlignConsecutiveAssignments = {};
- LLVMStyle.AlignConsecutiveAssignments.AcrossComments = false;
- LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
- LLVMStyle.AlignConsecutiveAssignments.AlignCompound = false;
- LLVMStyle.AlignConsecutiveAssignments.AlignFunctionPointers = false;
- LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
LLVMStyle.AlignConsecutiveBitFields = {};
LLVMStyle.AlignConsecutiveDeclarations = {};
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index aa8fbb874e1516..9abb8a110bf8ee 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -316,6 +316,13 @@ TEST(ConfigParseTest, ParsesConfiguration) {
/*AcrossComments=*/false, /*AlignCompound=*/false, \
/*AlignFunctionDeclarations=*/true, \
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": AcrossComments", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/true, /*AlignCompound=*/false, \
+ /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
CHECK_PARSE( \
#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
FormatStyle::AlignConsecutiveStyle( \
@@ -339,6 +346,7 @@ TEST(ConfigParseTest, ParsesConfiguration) {
CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments); \
CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); \
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); \
+ CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionPointers); \
CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators); \
} while (false)
More information about the cfe-commits
mailing list