Skip to content

Commit 6568827

Browse files
authored
[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.
1 parent 4b6e41b commit 6568827

File tree

4 files changed

+63
-57
lines changed

4 files changed

+63
-57
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ the configuration (without a prefix: ``Auto``).
249249
.. _AlignArrayOfStructures:
250250

251251
**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`<AlignArrayOfStructures>`
252-
if not ``None``, when using initialization for an array of structs
252+
If not ``None``, when using initialization for an array of structs
253253
aligns the fields into columns.
254254

255255

@@ -307,11 +307,12 @@ the configuration (without a prefix: ``Auto``).
307307
Alignment options.
308308

309309
They can also be read as a whole for compatibility. The choices are:
310-
- None
311-
- Consecutive
312-
- AcrossEmptyLines
313-
- AcrossComments
314-
- AcrossEmptyLinesAndComments
310+
311+
* ``None``
312+
* ``Consecutive``
313+
* ``AcrossEmptyLines``
314+
* ``AcrossComments``
315+
* ``AcrossEmptyLinesAndComments``
315316

316317
For example, to align across empty lines and not across comments, either
317318
of these work.
@@ -464,11 +465,12 @@ the configuration (without a prefix: ``Auto``).
464465
Alignment options.
465466

466467
They can also be read as a whole for compatibility. The choices are:
467-
- None
468-
- Consecutive
469-
- AcrossEmptyLines
470-
- AcrossComments
471-
- AcrossEmptyLinesAndComments
468+
469+
* ``None``
470+
* ``Consecutive``
471+
* ``AcrossEmptyLines``
472+
* ``AcrossComments``
473+
* ``AcrossEmptyLinesAndComments``
472474

473475
For example, to align across empty lines and not across comments, either
474476
of these work.
@@ -621,11 +623,12 @@ the configuration (without a prefix: ``Auto``).
621623
Alignment options.
622624

623625
They can also be read as a whole for compatibility. The choices are:
624-
- None
625-
- Consecutive
626-
- AcrossEmptyLines
627-
- AcrossComments
628-
- AcrossEmptyLinesAndComments
626+
627+
* ``None``
628+
* ``Consecutive``
629+
* ``AcrossEmptyLines``
630+
* ``AcrossComments``
631+
* ``AcrossEmptyLinesAndComments``
629632

630633
For example, to align across empty lines and not across comments, either
631634
of these work.
@@ -779,11 +782,12 @@ the configuration (without a prefix: ``Auto``).
779782
Alignment options.
780783

781784
They can also be read as a whole for compatibility. The choices are:
782-
- None
783-
- Consecutive
784-
- AcrossEmptyLines
785-
- AcrossComments
786-
- AcrossEmptyLinesAndComments
785+
786+
* ``None``
787+
* ``Consecutive``
788+
* ``AcrossEmptyLines``
789+
* ``AcrossComments``
790+
* ``AcrossEmptyLinesAndComments``
787791

788792
For example, to align across empty lines and not across comments, either
789793
of these work.
@@ -1056,11 +1060,12 @@ the configuration (without a prefix: ``Auto``).
10561060
Alignment options.
10571061

10581062
They can also be read as a whole for compatibility. The choices are:
1059-
- None
1060-
- Consecutive
1061-
- AcrossEmptyLines
1062-
- AcrossComments
1063-
- AcrossEmptyLinesAndComments
1063+
1064+
* ``None``
1065+
* ``Consecutive``
1066+
* ``AcrossEmptyLines``
1067+
* ``AcrossComments``
1068+
* ``AcrossEmptyLinesAndComments``
10641069

10651070
For example, to align across empty lines and not across comments, either
10661071
of these work.
@@ -1211,11 +1216,12 @@ the configuration (without a prefix: ``Auto``).
12111216
Alignment options.
12121217

12131218
They can also be read as a whole for compatibility. The choices are:
1214-
- None
1215-
- Consecutive
1216-
- AcrossEmptyLines
1217-
- AcrossComments
1218-
- AcrossEmptyLinesAndComments
1219+
1220+
* ``None``
1221+
* ``Consecutive``
1222+
* ``AcrossEmptyLines``
1223+
* ``AcrossComments``
1224+
* ``AcrossEmptyLinesAndComments``
12191225

12201226
For example, to align across empty lines and not across comments, either
12211227
of these work.
@@ -1366,11 +1372,12 @@ the configuration (without a prefix: ``Auto``).
13661372
Alignment options.
13671373

13681374
They can also be read as a whole for compatibility. The choices are:
1369-
- None
1370-
- Consecutive
1371-
- AcrossEmptyLines
1372-
- AcrossComments
1373-
- AcrossEmptyLinesAndComments
1375+
1376+
* ``None``
1377+
* ``Consecutive``
1378+
* ``AcrossEmptyLines``
1379+
* ``AcrossComments``
1380+
* ``AcrossEmptyLinesAndComments``
13741381

13751382
For example, to align across empty lines and not across comments, either
13761383
of these work.

clang/include/clang/Format/Format.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct FormatStyle {
131131
/// Don't align array initializer columns.
132132
AIAS_None
133133
};
134-
/// if not ``None``, when using initialization for an array of structs
134+
/// If not ``None``, when using initialization for an array of structs
135135
/// aligns the fields into columns.
136136
///
137137
/// \note
@@ -145,11 +145,12 @@ struct FormatStyle {
145145
/// Alignment options.
146146
///
147147
/// They can also be read as a whole for compatibility. The choices are:
148-
/// - None
149-
/// - Consecutive
150-
/// - AcrossEmptyLines
151-
/// - AcrossComments
152-
/// - AcrossEmptyLinesAndComments
148+
///
149+
/// * ``None``
150+
/// * ``Consecutive``
151+
/// * ``AcrossEmptyLines``
152+
/// * ``AcrossComments``
153+
/// * ``AcrossEmptyLinesAndComments``
153154
///
154155
/// For example, to align across empty lines and not across comments, either
155156
/// of these work.

clang/lib/Format/Format.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,33 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
5050
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
5151
/*AcrossComments=*/false, /*AlignCompound=*/false,
5252
/*AlignFunctionDeclarations=*/true,
53-
/*AlignFunctionPointers=*/false,
54-
/*PadOperators=*/true}));
53+
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
5554
IO.enumCase(Value, "AcrossEmptyLines",
5655
FormatStyle::AlignConsecutiveStyle(
5756
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
5857
/*AcrossComments=*/false, /*AlignCompound=*/false,
5958
/*AlignFunctionDeclarations=*/true,
60-
/*AlignFunctionPointers=*/false,
61-
/*PadOperators=*/true}));
59+
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
6260
IO.enumCase(Value, "AcrossComments",
6361
FormatStyle::AlignConsecutiveStyle(
6462
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
6563
/*AcrossComments=*/true, /*AlignCompound=*/false,
6664
/*AlignFunctionDeclarations=*/true,
67-
/*AlignFunctionPointers=*/false,
68-
/*PadOperators=*/true}));
65+
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
6966
IO.enumCase(Value, "AcrossEmptyLinesAndComments",
7067
FormatStyle::AlignConsecutiveStyle(
7168
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
7269
/*AcrossComments=*/true, /*AlignCompound=*/false,
7370
/*AlignFunctionDeclarations=*/true,
74-
/*AlignFunctionPointers=*/false,
75-
/*PadOperators=*/true}));
71+
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
7672

7773
// For backward compatibility.
7874
IO.enumCase(Value, "true",
7975
FormatStyle::AlignConsecutiveStyle(
8076
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
8177
/*AcrossComments=*/false, /*AlignCompound=*/false,
8278
/*AlignFunctionDeclarations=*/true,
83-
/*AlignFunctionPointers=*/false,
84-
/*PadOperators=*/true}));
79+
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
8580
IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({}));
8681
}
8782

@@ -1445,11 +1440,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14451440
LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
14461441
LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
14471442
LLVMStyle.AlignConsecutiveAssignments = {};
1448-
LLVMStyle.AlignConsecutiveAssignments.AcrossComments = false;
1449-
LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
1450-
LLVMStyle.AlignConsecutiveAssignments.AlignCompound = false;
1451-
LLVMStyle.AlignConsecutiveAssignments.AlignFunctionPointers = false;
1452-
LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
14531443
LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
14541444
LLVMStyle.AlignConsecutiveBitFields = {};
14551445
LLVMStyle.AlignConsecutiveDeclarations = {};

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ TEST(ConfigParseTest, ParsesConfiguration) {
316316
/*AcrossComments=*/false, /*AlignCompound=*/false, \
317317
/*AlignFunctionDeclarations=*/true, \
318318
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
319+
CHECK_PARSE( \
320+
#FIELD ": AcrossComments", FIELD, \
321+
FormatStyle::AlignConsecutiveStyle( \
322+
{/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
323+
/*AcrossComments=*/true, /*AlignCompound=*/false, \
324+
/*AlignFunctionDeclarations=*/true, \
325+
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
319326
CHECK_PARSE( \
320327
#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
321328
FormatStyle::AlignConsecutiveStyle( \
@@ -339,6 +346,7 @@ TEST(ConfigParseTest, ParsesConfiguration) {
339346
CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments); \
340347
CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); \
341348
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); \
349+
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionPointers); \
342350
CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators); \
343351
} while (false)
344352

0 commit comments

Comments
 (0)