Skip to content

Commit b1bcd59

Browse files
committed
[clang-format][NFC] Clean up AlignConsecutiveStyle
1 parent b5f6689 commit b1bcd59

File tree

4 files changed

+63
-69
lines changed

4 files changed

+63
-69
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.
@@ -449,11 +450,12 @@ the configuration (without a prefix: ``Auto``).
449450
Alignment options.
450451

451452
They can also be read as a whole for compatibility. The choices are:
452-
- None
453-
- Consecutive
454-
- AcrossEmptyLines
455-
- AcrossComments
456-
- AcrossEmptyLinesAndComments
453+
454+
* ``None``
455+
* ``Consecutive``
456+
* ``AcrossEmptyLines``
457+
* ``AcrossComments``
458+
* ``AcrossEmptyLinesAndComments``
457459

458460
For example, to align across empty lines and not across comments, either
459461
of these work.
@@ -591,11 +593,12 @@ the configuration (without a prefix: ``Auto``).
591593
Alignment options.
592594

593595
They can also be read as a whole for compatibility. The choices are:
594-
- None
595-
- Consecutive
596-
- AcrossEmptyLines
597-
- AcrossComments
598-
- AcrossEmptyLinesAndComments
596+
597+
* ``None``
598+
* ``Consecutive``
599+
* ``AcrossEmptyLines``
600+
* ``AcrossComments``
601+
* ``AcrossEmptyLinesAndComments``
599602

600603
For example, to align across empty lines and not across comments, either
601604
of these work.
@@ -734,11 +737,12 @@ the configuration (without a prefix: ``Auto``).
734737
Alignment options.
735738

736739
They can also be read as a whole for compatibility. The choices are:
737-
- None
738-
- Consecutive
739-
- AcrossEmptyLines
740-
- AcrossComments
741-
- AcrossEmptyLinesAndComments
740+
741+
* ``None``
742+
* ``Consecutive``
743+
* ``AcrossEmptyLines``
744+
* ``AcrossComments``
745+
* ``AcrossEmptyLinesAndComments``
742746

743747
For example, to align across empty lines and not across comments, either
744748
of these work.
@@ -996,11 +1000,12 @@ the configuration (without a prefix: ``Auto``).
9961000
Alignment options.
9971001

9981002
They can also be read as a whole for compatibility. The choices are:
999-
- None
1000-
- Consecutive
1001-
- AcrossEmptyLines
1002-
- AcrossComments
1003-
- AcrossEmptyLinesAndComments
1003+
1004+
* ``None``
1005+
* ``Consecutive``
1006+
* ``AcrossEmptyLines``
1007+
* ``AcrossComments``
1008+
* ``AcrossEmptyLinesAndComments``
10041009

10051010
For example, to align across empty lines and not across comments, either
10061011
of these work.
@@ -1136,11 +1141,12 @@ the configuration (without a prefix: ``Auto``).
11361141
Alignment options.
11371142

11381143
They can also be read as a whole for compatibility. The choices are:
1139-
- None
1140-
- Consecutive
1141-
- AcrossEmptyLines
1142-
- AcrossComments
1143-
- AcrossEmptyLinesAndComments
1144+
1145+
* ``None``
1146+
* ``Consecutive``
1147+
* ``AcrossEmptyLines``
1148+
* ``AcrossComments``
1149+
* ``AcrossEmptyLinesAndComments``
11441150

11451151
For example, to align across empty lines and not across comments, either
11461152
of these work.
@@ -1276,11 +1282,12 @@ the configuration (without a prefix: ``Auto``).
12761282
Alignment options.
12771283

12781284
They can also be read as a whole for compatibility. The choices are:
1279-
- None
1280-
- Consecutive
1281-
- AcrossEmptyLines
1282-
- AcrossComments
1283-
- AcrossEmptyLinesAndComments
1285+
1286+
* ``None``
1287+
* ``Consecutive``
1288+
* ``AcrossEmptyLines``
1289+
* ``AcrossComments``
1290+
* ``AcrossEmptyLinesAndComments``
12841291

12851292
For example, to align across empty lines and not across comments, either
12861293
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: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ struct ScalarEnumerationTraits<FormatStyle::BreakBeforeNoexceptSpecifierStyle> {
4444

4545
template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
4646
static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
47-
IO.enumCase(Value, "None",
48-
FormatStyle::AlignConsecutiveStyle(
49-
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
50-
/*AcrossComments=*/false, /*AlignCompound=*/false,
51-
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
47+
IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({}));
5248
IO.enumCase(Value, "Consecutive",
5349
FormatStyle::AlignConsecutiveStyle(
5450
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
@@ -76,11 +72,7 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
7672
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
7773
/*AcrossComments=*/false, /*AlignCompound=*/false,
7874
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
79-
IO.enumCase(Value, "false",
80-
FormatStyle::AlignConsecutiveStyle(
81-
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
82-
/*AcrossComments=*/false, /*AlignCompound=*/false,
83-
/*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
75+
IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({}));
8476
}
8577

8678
static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
@@ -1441,11 +1433,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14411433
LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
14421434
LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
14431435
LLVMStyle.AlignConsecutiveAssignments = {};
1444-
LLVMStyle.AlignConsecutiveAssignments.AcrossComments = false;
1445-
LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
1446-
LLVMStyle.AlignConsecutiveAssignments.AlignCompound = false;
1447-
LLVMStyle.AlignConsecutiveAssignments.AlignFunctionPointers = false;
1448-
LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
14491436
LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
14501437
LLVMStyle.AlignConsecutiveBitFields = {};
14511438
LLVMStyle.AlignConsecutiveDeclarations = {};

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,8 @@ TEST(ConfigParseTest, ParsesConfiguration) {
300300
#define CHECK_ALIGN_CONSECUTIVE(FIELD) \
301301
do { \
302302
Style.FIELD.Enabled = true; \
303-
CHECK_PARSE( \
304-
#FIELD ": None", FIELD, \
305-
FormatStyle::AlignConsecutiveStyle( \
306-
{/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
307-
/*AcrossComments=*/false, /*AlignCompound=*/false, \
308-
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
303+
CHECK_PARSE(#FIELD ": None", FIELD, \
304+
FormatStyle::AlignConsecutiveStyle({})); \
309305
CHECK_PARSE( \
310306
#FIELD ": Consecutive", FIELD, \
311307
FormatStyle::AlignConsecutiveStyle( \
@@ -319,18 +315,20 @@ TEST(ConfigParseTest, ParsesConfiguration) {
319315
/*AcrossComments=*/false, /*AlignCompound=*/false, \
320316
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
321317
CHECK_PARSE( \
322-
#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
318+
#FIELD ": AcrossComments", FIELD, \
323319
FormatStyle::AlignConsecutiveStyle( \
324-
{/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
320+
{/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
325321
/*AcrossComments=*/true, /*AlignCompound=*/false, \
326322
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
327-
/* For backwards compability, false / true should still parse */ \
328323
CHECK_PARSE( \
329-
#FIELD ": false", FIELD, \
324+
#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
330325
FormatStyle::AlignConsecutiveStyle( \
331-
{/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
332-
/*AcrossComments=*/false, /*AlignCompound=*/false, \
326+
{/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
327+
/*AcrossComments=*/true, /*AlignCompound=*/false, \
333328
/*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
329+
/* For backwards compability, false / true should still parse */ \
330+
CHECK_PARSE(#FIELD ": false", FIELD, \
331+
FormatStyle::AlignConsecutiveStyle({})); \
334332
CHECK_PARSE( \
335333
#FIELD ": true", FIELD, \
336334
FormatStyle::AlignConsecutiveStyle( \
@@ -342,6 +340,7 @@ TEST(ConfigParseTest, ParsesConfiguration) {
342340
CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines); \
343341
CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments); \
344342
CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); \
343+
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionPointers); \
345344
CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators); \
346345
} while (false)
347346

0 commit comments

Comments
 (0)