https://github.com/owenca created https://github.com/llvm/llvm-project/pull/111285
None >From 7745a5d103f73a093bd856d23b3fb1c4ef80d5ac Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Sun, 6 Oct 2024 02:27:59 -0700 Subject: [PATCH] [clang-format][NFC] Clean up AlignConsecutiveStyle --- clang/lib/Format/Format.cpp | 18 ++-------------- clang/unittests/Format/ConfigParseTest.cpp | 22 +++++++++----------- clang/unittests/Format/FormatTest.cpp | 5 +---- clang/unittests/Format/FormatTestVerilog.cpp | 1 + 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5350c66ea5132b..d691d198f8025d 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -44,11 +44,7 @@ struct ScalarEnumerationTraits<FormatStyle::BreakBeforeNoexceptSpecifierStyle> { template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> { static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { - IO.enumCase(Value, "None", - FormatStyle::AlignConsecutiveStyle( - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, - /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({})); IO.enumCase(Value, "Consecutive", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, @@ -76,11 +72,7 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> { {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); - IO.enumCase(Value, "false", - FormatStyle::AlignConsecutiveStyle( - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, - /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({})); } static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { @@ -1441,12 +1433,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 = {}; LLVMStyle.AlignConsecutiveMacros = {}; diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index b8bdfaaa74e10e..4d723981d73926 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -300,12 +300,8 @@ TEST(ConfigParseTest, ParsesConfiguration) { #define CHECK_ALIGN_CONSECUTIVE(FIELD) \ do { \ Style.FIELD.Enabled = true; \ - CHECK_PARSE( \ - #FIELD ": None", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ + CHECK_PARSE(#FIELD ": None", FIELD, \ + FormatStyle::AlignConsecutiveStyle({})); \ CHECK_PARSE( \ #FIELD ": Consecutive", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ @@ -319,18 +315,20 @@ TEST(ConfigParseTest, ParsesConfiguration) { /*AcrossComments=*/false, /*AlignCompound=*/false, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ CHECK_PARSE( \ - #FIELD ": AcrossEmptyLinesAndComments", FIELD, \ + #FIELD ": AcrossComments", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ + {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/true, /*AlignCompound=*/false, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ - /* For backwards compability, false / true should still parse */ \ CHECK_PARSE( \ - #FIELD ": false", FIELD, \ + #FIELD ": AcrossEmptyLinesAndComments", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ + {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ + /*AcrossComments=*/true, /*AlignCompound=*/false, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ + /* For backwards compability, false / true should still parse */ \ + CHECK_PARSE(#FIELD ": false", FIELD, \ + FormatStyle::AlignConsecutiveStyle({})); \ CHECK_PARSE( \ #FIELD ": true", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5d386c1bbdbcd9..72350a50c4a80b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -20261,10 +20261,7 @@ TEST_F(FormatTest, AlignWithLineBreaks) { auto Style = getLLVMStyleWithColumns(120); EXPECT_EQ(Style.AlignConsecutiveAssignments, - FormatStyle::AlignConsecutiveStyle( - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, - /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + FormatStyle::AlignConsecutiveStyle({})); EXPECT_EQ(Style.AlignConsecutiveDeclarations, FormatStyle::AlignConsecutiveStyle({})); verifyFormat("void foo() {\n" diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp index fbaf289fbc4d6d..f719fcebb2f55a 100644 --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -56,6 +56,7 @@ TEST_F(FormatTestVerilog, Align) { "sfdbddfbdfbb <= x;", Style); Style.AlignConsecutiveAssignments.AlignCompound = true; + Style.AlignConsecutiveAssignments.PadOperators = true; verifyFormat("x <= x;\n" "sfdbddfbdfbb <= x;", Style); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits