aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2024-10-07 19:12:47 -0700
committerGitHub <noreply@github.com>2024-10-07 19:12:47 -0700
commit65688274b14f5d0e7dabbbaf9f3fd135646ef1d1 (patch)
tree0eee87c4ad05a1f0444f7538d5a0cc57df2bef65
parent4b6e41b61e2edea2f80de3639e589301fe7c896c (diff)
downloadllvm-65688274b14f5d0e7dabbbaf9f3fd135646ef1d1.zip
llvm-65688274b14f5d0e7dabbbaf9f3fd135646ef1d1.tar.gz
llvm-65688274b14f5d0e7dabbbaf9f3fd135646ef1d1.tar.bz2
[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.
-rw-r--r--clang/docs/ClangFormatStyleOptions.rst79
-rw-r--r--clang/include/clang/Format/Format.h13
-rw-r--r--clang/lib/Format/Format.cpp20
-rw-r--r--clang/unittests/Format/ConfigParseTest.cpp8
4 files changed, 63 insertions, 57 deletions
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 7a1508e..a9bfb4c4a 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 82cd863..3d3e433 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 01b4b6f..f97127f 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 aa8fbb8..9abb8a1 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -317,6 +317,13 @@ TEST(ConfigParseTest, ParsesConfiguration) {
/*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( \
{/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
@@ -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)