diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -278,70 +278,121 @@ int somelongname = 2; double c = 3; - Possible values: + Nested configuration flags: + + Alignment options. + + They can also be read as a whole for compatibility. The choices + are: + - None + - Consecutive + - AcrossEmptyLines + - AcrossComments + - AcrossEmptyLinesAndComments + + For example, to align across empty lines and not across comments, + either of these work. + + .. code-block:: c++ + + AlignConsecutiveMacros: AcrossEmptyLines - * ``ACS_None`` (in configuration: ``None``) - Do not align assignments on consecutive lines. + AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false - * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - Align assignments on consecutive lines. This will result in - formattings like: + * ``bool Enabled`` Whether aligning is enabled. - .. code-block:: c++ + .. code-block:: c++ + + #define SHORT_NAME 42 + #define LONGER_NAME 0x007f + #define EVEN_LONGER_NAME (2) + #define foo(x) (x * x) + #define bar(y, z) (y + z) - int a = 1; - int somelongname = 2; - double c = 3; + int a = 1; + int somelongname = 2; + double c = 3; - int d = 3; - /* A comment. */ - double e = 4; + int aaaa : 1; + int b : 12; + int ccc : 8; - * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - Same as ACS_Consecutive, but also spans over empty lines, e.g. + int aaaa = 12; + float b = 23; + std::string ccc; - .. code-block:: c++ + * ``bool AcrossEmptyLines`` Whether to align across empty lines. - int a = 1; - int somelongname = 2; - double c = 3; + .. code-block:: c++ - int d = 3; - /* A comment. */ - double e = 4; + true: + int a = 1; + int somelongname = 2; + double c = 3; - * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - Same as ACS_Consecutive, but also spans over lines only containing - comments, e.g. + int d = 3; - .. code-block:: c++ + false: + int a = 1; + int somelongname = 2; + double c = 3; - int a = 1; - int somelongname = 2; - double c = 3; + int d = 3; - int d = 3; - /* A comment. */ - double e = 4; + * ``bool AcrossComments`` Whether to align across comments. - * ``ACS_AcrossEmptyLinesAndComments`` - (in configuration: ``AcrossEmptyLinesAndComments``) + .. code-block:: c++ - Same as ACS_Consecutive, but also spans over lines only containing - comments and empty lines, e.g. + true: + int d = 3; + /* A comment. */ + double e = 4; - .. code-block:: c++ + false: + int d = 3; + /* A comment. */ + double e = 4; + + * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound + assignments like ``+=`` are aligned along with ``=``. + + .. code-block:: c++ + + true: + a &= 2; + bbb = 2; + + false: + a &= 2; + bbb = 2; + + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short + assignment operators are left-padded to the same length as long + ones in order to put all assignment operators to the right of + the left hand side. + + .. code-block:: c++ + + true: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + false: + a >>= 2; + bbb = 2; - int a = 1; - int somelongname = 2; - double c = 3; + a = 2; + bbb >>= 2; - int d = 3; - /* A comment. */ - double e = 4; **AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` - Style of aligning consecutive bit field. + Style of aligning consecutive bit fields. ``Consecutive`` will align the bitfield separators of consecutive lines. This will result in formattings like: @@ -352,67 +403,118 @@ int b : 12; int ccc : 8; - Possible values: + Nested configuration flags: + + Alignment options. + + They can also be read as a whole for compatibility. The choices + are: + - None + - Consecutive + - AcrossEmptyLines + - AcrossComments + - AcrossEmptyLinesAndComments + + For example, to align across empty lines and not across comments, + either of these work. + + .. code-block:: c++ + + AlignConsecutiveMacros: AcrossEmptyLines - * ``ACS_None`` (in configuration: ``None``) - Do not align bit fields on consecutive lines. + AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false - * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - Align bit fields on consecutive lines. This will result in - formattings like: + * ``bool Enabled`` Whether aligning is enabled. - .. code-block:: c++ + .. code-block:: c++ + + #define SHORT_NAME 42 + #define LONGER_NAME 0x007f + #define EVEN_LONGER_NAME (2) + #define foo(x) (x * x) + #define bar(y, z) (y + z) - int aaaa : 1; - int b : 12; - int ccc : 8; + int a = 1; + int somelongname = 2; + double c = 3; - int d : 2; - /* A comment. */ - int ee : 3; + int aaaa : 1; + int b : 12; + int ccc : 8; - * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - Same as ACS_Consecutive, but also spans over empty lines, e.g. + int aaaa = 12; + float b = 23; + std::string ccc; - .. code-block:: c++ + * ``bool AcrossEmptyLines`` Whether to align across empty lines. - int aaaa : 1; - int b : 12; - int ccc : 8; + .. code-block:: c++ - int d : 2; - /* A comment. */ - int ee : 3; + true: + int a = 1; + int somelongname = 2; + double c = 3; - * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - Same as ACS_Consecutive, but also spans over lines only containing - comments, e.g. + int d = 3; - .. code-block:: c++ + false: + int a = 1; + int somelongname = 2; + double c = 3; - int aaaa : 1; - int b : 12; - int ccc : 8; + int d = 3; - int d : 2; - /* A comment. */ - int ee : 3; + * ``bool AcrossComments`` Whether to align across comments. - * ``ACS_AcrossEmptyLinesAndComments`` - (in configuration: ``AcrossEmptyLinesAndComments``) + .. code-block:: c++ - Same as ACS_Consecutive, but also spans over lines only containing - comments and empty lines, e.g. + true: + int d = 3; + /* A comment. */ + double e = 4; - .. code-block:: c++ + false: + int d = 3; + /* A comment. */ + double e = 4; + + * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound + assignments like ``+=`` are aligned along with ``=``. + + .. code-block:: c++ + + true: + a &= 2; + bbb = 2; + + false: + a &= 2; + bbb = 2; + + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short + assignment operators are left-padded to the same length as long + ones in order to put all assignment operators to the right of + the left hand side. + + .. code-block:: c++ + + true: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + false: + a >>= 2; + bbb = 2; - int aaaa : 1; - int b : 12; - int ccc : 8; + a = 2; + bbb >>= 2; - int d : 2; - /* A comment. */ - int ee : 3; **AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` Style of aligning consecutive declarations. @@ -426,67 +528,118 @@ float b = 23; std::string ccc; - Possible values: + Nested configuration flags: + + Alignment options. + + They can also be read as a whole for compatibility. The choices + are: + - None + - Consecutive + - AcrossEmptyLines + - AcrossComments + - AcrossEmptyLinesAndComments + + For example, to align across empty lines and not across comments, + either of these work. + + .. code-block:: c++ + + AlignConsecutiveMacros: AcrossEmptyLines - * ``ACS_None`` (in configuration: ``None``) - Do not align bit declarations on consecutive lines. + AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false - * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - Align declarations on consecutive lines. This will result in - formattings like: + * ``bool Enabled`` Whether aligning is enabled. - .. code-block:: c++ + .. code-block:: c++ + + #define SHORT_NAME 42 + #define LONGER_NAME 0x007f + #define EVEN_LONGER_NAME (2) + #define foo(x) (x * x) + #define bar(y, z) (y + z) - int aaaa = 12; - float b = 23; - std::string ccc; + int a = 1; + int somelongname = 2; + double c = 3; - int a = 42; - /* A comment. */ - bool c = false; + int aaaa : 1; + int b : 12; + int ccc : 8; - * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - Same as ACS_Consecutive, but also spans over empty lines, e.g. + int aaaa = 12; + float b = 23; + std::string ccc; - .. code-block:: c++ + * ``bool AcrossEmptyLines`` Whether to align across empty lines. - int aaaa = 12; - float b = 23; - std::string ccc; + .. code-block:: c++ - int a = 42; - /* A comment. */ - bool c = false; + true: + int a = 1; + int somelongname = 2; + double c = 3; - * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - Same as ACS_Consecutive, but also spans over lines only containing - comments, e.g. + int d = 3; - .. code-block:: c++ + false: + int a = 1; + int somelongname = 2; + double c = 3; - int aaaa = 12; - float b = 23; - std::string ccc; + int d = 3; - int a = 42; - /* A comment. */ - bool c = false; + * ``bool AcrossComments`` Whether to align across comments. - * ``ACS_AcrossEmptyLinesAndComments`` - (in configuration: ``AcrossEmptyLinesAndComments``) + .. code-block:: c++ - Same as ACS_Consecutive, but also spans over lines only containing - comments and empty lines, e.g. + true: + int d = 3; + /* A comment. */ + double e = 4; - .. code-block:: c++ + false: + int d = 3; + /* A comment. */ + double e = 4; + + * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound + assignments like ``+=`` are aligned along with ``=``. + + .. code-block:: c++ + + true: + a &= 2; + bbb = 2; + + false: + a &= 2; + bbb = 2; + + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short + assignment operators are left-padded to the same length as long + ones in order to put all assignment operators to the right of + the left hand side. + + .. code-block:: c++ + + true: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + false: + a >>= 2; + bbb = 2; - int aaaa = 12; - float b = 23; - std::string ccc; + a = 2; + bbb >>= 2; - int a = 42; - /* A comment. */ - bool c = false; **AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` Style of aligning consecutive macro definitions. @@ -501,67 +654,118 @@ #define foo(x) (x * x) #define bar(y, z) (y + z) - Possible values: + Nested configuration flags: + + Alignment options. + + They can also be read as a whole for compatibility. The choices + are: + - None + - Consecutive + - AcrossEmptyLines + - AcrossComments + - AcrossEmptyLinesAndComments + + For example, to align across empty lines and not across comments, + either of these work. + + .. code-block:: c++ + + AlignConsecutiveMacros: AcrossEmptyLines - * ``ACS_None`` (in configuration: ``None``) - Do not align macro definitions on consecutive lines. + AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false - * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - Align macro definitions on consecutive lines. This will result in - formattings like: + * ``bool Enabled`` Whether aligning is enabled. - .. code-block:: c++ + .. code-block:: c++ + + #define SHORT_NAME 42 + #define LONGER_NAME 0x007f + #define EVEN_LONGER_NAME (2) + #define foo(x) (x * x) + #define bar(y, z) (y + z) - #define SHORT_NAME 42 - #define LONGER_NAME 0x007f - #define EVEN_LONGER_NAME (2) + int a = 1; + int somelongname = 2; + double c = 3; - #define foo(x) (x * x) - /* some comment */ - #define bar(y, z) (y + z) + int aaaa : 1; + int b : 12; + int ccc : 8; - * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - Same as ACS_Consecutive, but also spans over empty lines, e.g. + int aaaa = 12; + float b = 23; + std::string ccc; - .. code-block:: c++ + * ``bool AcrossEmptyLines`` Whether to align across empty lines. - #define SHORT_NAME 42 - #define LONGER_NAME 0x007f - #define EVEN_LONGER_NAME (2) + .. code-block:: c++ - #define foo(x) (x * x) - /* some comment */ - #define bar(y, z) (y + z) + true: + int a = 1; + int somelongname = 2; + double c = 3; - * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - Same as ACS_Consecutive, but also spans over lines only containing - comments, e.g. + int d = 3; - .. code-block:: c++ + false: + int a = 1; + int somelongname = 2; + double c = 3; - #define SHORT_NAME 42 - #define LONGER_NAME 0x007f - #define EVEN_LONGER_NAME (2) + int d = 3; - #define foo(x) (x * x) - /* some comment */ - #define bar(y, z) (y + z) + * ``bool AcrossComments`` Whether to align across comments. - * ``ACS_AcrossEmptyLinesAndComments`` - (in configuration: ``AcrossEmptyLinesAndComments``) + .. code-block:: c++ - Same as ACS_Consecutive, but also spans over lines only containing - comments and empty lines, e.g. + true: + int d = 3; + /* A comment. */ + double e = 4; - .. code-block:: c++ + false: + int d = 3; + /* A comment. */ + double e = 4; + + * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound + assignments like ``+=`` are aligned along with ``=``. + + .. code-block:: c++ + + true: + a &= 2; + bbb = 2; + + false: + a &= 2; + bbb = 2; + + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short + assignment operators are left-padded to the same length as long + ones in order to put all assignment operators to the right of + the left hand side. + + .. code-block:: c++ + + true: + a >>= 2; + bbb = 2; + + a = 2; + bbb >>= 2; + + false: + a >>= 2; + bbb = 2; - #define SHORT_NAME 42 - #define LONGER_NAME 0x007f - #define EVEN_LONGER_NAME (2) + a = 2; + bbb >>= 2; - #define foo(x) (x * x) - /* some comment */ - #define bar(y, z) (y + z) **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` Options for aligning backslashes in escaped newlines. diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py --- a/clang/docs/tools/dump_format_style.py +++ b/clang/docs/tools/dump_format_style.py @@ -290,7 +290,7 @@ comment += self.__clean_comment_line(line) else: state = State.InNestedStruct - field_type, field_name = re.match(r'([<>:\w(,\s)]+)\s+(\w+);', line).groups() + field_type, field_name = re.match(r'([<>:\w(,\s)]+)\s+(\w+)', line).groups() if field_type in enums: nested_struct.values.append(NestedEnum(field_name, field_type, diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -134,18 +134,117 @@ /// \version 13 ArrayInitializerAlignmentStyle AlignArrayOfStructures; - /// Styles for alignment of consecutive tokens. Tokens can be assignment signs - /// (see - /// ``AlignConsecutiveAssignments``), bitfield member separators (see - /// ``AlignConsecutiveBitFields``), names in declarations (see - /// ``AlignConsecutiveDeclarations``) or macro definitions (see - /// ``AlignConsecutiveMacros``). - enum AlignConsecutiveStyle { - ACS_None, - ACS_Consecutive, - ACS_AcrossEmptyLines, - ACS_AcrossComments, - ACS_AcrossEmptyLinesAndComments + /// Alignment options. + /// + /// They can also be read as a whole for compatibility. The choices + /// are: + /// - None + /// - Consecutive + /// - AcrossEmptyLines + /// - AcrossComments + /// - AcrossEmptyLinesAndComments + /// + /// For example, to align across empty lines and not across comments, + /// either of these work. + /// \code + /// AlignConsecutiveMacros: AcrossEmptyLines + /// + /// AlignConsecutiveMacros: + /// Enabled: true + /// AcrossEmptyLines: true + /// AcrossComments: false + /// \endcode + struct AlignConsecutiveStyle { + /// Whether aligning is enabled. + /// \code + /// #define SHORT_NAME 42 + /// #define LONGER_NAME 0x007f + /// #define EVEN_LONGER_NAME (2) + /// #define foo(x) (x * x) + /// #define bar(y, z) (y + z) + /// + /// int a = 1; + /// int somelongname = 2; + /// double c = 3; + /// + /// int aaaa : 1; + /// int b : 12; + /// int ccc : 8; + /// + /// int aaaa = 12; + /// float b = 23; + /// std::string ccc; + /// \endcode + bool Enabled; + /// Whether to align across empty lines. + /// \code + /// true: + /// int a = 1; + /// int somelongname = 2; + /// double c = 3; + /// + /// int d = 3; + /// + /// false: + /// int a = 1; + /// int somelongname = 2; + /// double c = 3; + /// + /// int d = 3; + /// \endcode + bool AcrossEmptyLines; + /// Whether to align across comments. + /// \code + /// true: + /// int d = 3; + /// /* A comment. */ + /// double e = 4; + /// + /// false: + /// int d = 3; + /// /* A comment. */ + /// double e = 4; + /// \endcode + bool AcrossComments; + /// Only for ``AlignConsecutiveAssignments``. Whether compound + /// assignments like ``+=`` are aligned along with ``=``. + /// \code + /// true: + /// a &= 2; + /// bbb = 2; + /// + /// false: + /// a &= 2; + /// bbb = 2; + /// \endcode + bool AlignCompound; + /// Only for ``AlignConsecutiveAssignments``. Whether short + /// assignment operators are left-padded to the same length as long + /// ones in order to put all assignment operators to the right of + /// the left hand side. + /// \code + /// true: + /// a >>= 2; + /// bbb = 2; + /// + /// a = 2; + /// bbb >>= 2; + /// + /// false: + /// a >>= 2; + /// bbb = 2; + /// + /// a = 2; + /// bbb >>= 2; + /// \endcode + bool PadOperators = true; + bool operator==(const AlignConsecutiveStyle &R) const { + return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines && + AcrossComments == R.AcrossComments; + } + bool operator!=(const AlignConsecutiveStyle &R) const { + return !(*this == R); + } }; /// Style of aligning consecutive macro definitions. @@ -158,67 +257,8 @@ /// #define foo(x) (x * x) /// #define bar(y, z) (y + z) /// \endcode - /// - /// Possible values: - /// - /// * ``ACS_None`` (in configuration: ``None``) - /// Do not align macro definitions on consecutive lines. - /// - /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - /// Align macro definitions on consecutive lines. This will result in - /// formattings like: - /// \code - /// #define SHORT_NAME 42 - /// #define LONGER_NAME 0x007f - /// #define EVEN_LONGER_NAME (2) - /// - /// #define foo(x) (x * x) - /// /* some comment */ - /// #define bar(y, z) (y + z) - /// \endcode - /// - /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - /// Same as ACS_Consecutive, but also spans over empty lines, e.g. - /// \code - /// #define SHORT_NAME 42 - /// #define LONGER_NAME 0x007f - /// #define EVEN_LONGER_NAME (2) - /// - /// #define foo(x) (x * x) - /// /* some comment */ - /// #define bar(y, z) (y + z) - /// \endcode - /// - /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments, e.g. - /// \code - /// #define SHORT_NAME 42 - /// #define LONGER_NAME 0x007f - /// #define EVEN_LONGER_NAME (2) - /// - /// #define foo(x) (x * x) - /// /* some comment */ - /// #define bar(y, z) (y + z) - /// \endcode - /// - /// * ``ACS_AcrossEmptyLinesAndComments`` - /// (in configuration: ``AcrossEmptyLinesAndComments``) - /// - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments and empty lines, e.g. - /// \code - /// #define SHORT_NAME 42 - /// #define LONGER_NAME 0x007f - /// #define EVEN_LONGER_NAME (2) - /// - /// #define foo(x) (x * x) - /// /* some comment */ - /// #define bar(y, z) (y + z) - /// \endcode /// \version 9 AlignConsecutiveStyle AlignConsecutiveMacros; - /// Style of aligning consecutive assignments. /// /// ``Consecutive`` will result in formattings like: @@ -227,68 +267,9 @@ /// int somelongname = 2; /// double c = 3; /// \endcode - /// - /// Possible values: - /// - /// * ``ACS_None`` (in configuration: ``None``) - /// Do not align assignments on consecutive lines. - /// - /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - /// Align assignments on consecutive lines. This will result in - /// formattings like: - /// \code - /// int a = 1; - /// int somelongname = 2; - /// double c = 3; - /// - /// int d = 3; - /// /* A comment. */ - /// double e = 4; - /// \endcode - /// - /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - /// Same as ACS_Consecutive, but also spans over empty lines, e.g. - /// \code - /// int a = 1; - /// int somelongname = 2; - /// double c = 3; - /// - /// int d = 3; - /// /* A comment. */ - /// double e = 4; - /// \endcode - /// - /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments, e.g. - /// \code - /// int a = 1; - /// int somelongname = 2; - /// double c = 3; - /// - /// int d = 3; - /// /* A comment. */ - /// double e = 4; - /// \endcode - /// - /// * ``ACS_AcrossEmptyLinesAndComments`` - /// (in configuration: ``AcrossEmptyLinesAndComments``) - /// - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments and empty lines, e.g. - /// \code - /// int a = 1; - /// int somelongname = 2; - /// double c = 3; - /// - /// int d = 3; - /// /* A comment. */ - /// double e = 4; - /// \endcode /// \version 3.8 AlignConsecutiveStyle AlignConsecutiveAssignments; - - /// Style of aligning consecutive bit field. + /// Style of aligning consecutive bit fields. /// /// ``Consecutive`` will align the bitfield separators of consecutive lines. /// This will result in formattings like: @@ -297,67 +278,8 @@ /// int b : 12; /// int ccc : 8; /// \endcode - /// - /// Possible values: - /// - /// * ``ACS_None`` (in configuration: ``None``) - /// Do not align bit fields on consecutive lines. - /// - /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - /// Align bit fields on consecutive lines. This will result in - /// formattings like: - /// \code - /// int aaaa : 1; - /// int b : 12; - /// int ccc : 8; - /// - /// int d : 2; - /// /* A comment. */ - /// int ee : 3; - /// \endcode - /// - /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - /// Same as ACS_Consecutive, but also spans over empty lines, e.g. - /// \code - /// int aaaa : 1; - /// int b : 12; - /// int ccc : 8; - /// - /// int d : 2; - /// /* A comment. */ - /// int ee : 3; - /// \endcode - /// - /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments, e.g. - /// \code - /// int aaaa : 1; - /// int b : 12; - /// int ccc : 8; - /// - /// int d : 2; - /// /* A comment. */ - /// int ee : 3; - /// \endcode - /// - /// * ``ACS_AcrossEmptyLinesAndComments`` - /// (in configuration: ``AcrossEmptyLinesAndComments``) - /// - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments and empty lines, e.g. - /// \code - /// int aaaa : 1; - /// int b : 12; - /// int ccc : 8; - /// - /// int d : 2; - /// /* A comment. */ - /// int ee : 3; - /// \endcode /// \version 11 AlignConsecutiveStyle AlignConsecutiveBitFields; - /// Style of aligning consecutive declarations. /// /// ``Consecutive`` will align the declaration names of consecutive lines. @@ -367,64 +289,6 @@ /// float b = 23; /// std::string ccc; /// \endcode - /// - /// Possible values: - /// - /// * ``ACS_None`` (in configuration: ``None``) - /// Do not align bit declarations on consecutive lines. - /// - /// * ``ACS_Consecutive`` (in configuration: ``Consecutive``) - /// Align declarations on consecutive lines. This will result in - /// formattings like: - /// \code - /// int aaaa = 12; - /// float b = 23; - /// std::string ccc; - /// - /// int a = 42; - /// /* A comment. */ - /// bool c = false; - /// \endcode - /// - /// * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) - /// Same as ACS_Consecutive, but also spans over empty lines, e.g. - /// \code - /// int aaaa = 12; - /// float b = 23; - /// std::string ccc; - /// - /// int a = 42; - /// /* A comment. */ - /// bool c = false; - /// \endcode - /// - /// * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments, e.g. - /// \code - /// int aaaa = 12; - /// float b = 23; - /// std::string ccc; - /// - /// int a = 42; - /// /* A comment. */ - /// bool c = false; - /// \endcode - /// - /// * ``ACS_AcrossEmptyLinesAndComments`` - /// (in configuration: ``AcrossEmptyLinesAndComments``) - /// - /// Same as ACS_Consecutive, but also spans over lines only containing - /// comments and empty lines, e.g. - /// \code - /// int aaaa = 12; - /// float b = 23; - /// std::string ccc; - /// - /// int a = 42; - /// /* A comment. */ - /// bool c = false; - /// \endcode /// \version 3.8 AlignConsecutiveStyle AlignConsecutiveDeclarations; diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -152,18 +152,35 @@ } }; -template <> struct ScalarEnumerationTraits { - static void enumeration(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { - IO.enumCase(Value, "None", FormatStyle::ACS_None); - IO.enumCase(Value, "Consecutive", FormatStyle::ACS_Consecutive); - IO.enumCase(Value, "AcrossEmptyLines", FormatStyle::ACS_AcrossEmptyLines); - IO.enumCase(Value, "AcrossComments", FormatStyle::ACS_AcrossComments); +template <> struct MappingTraits { + static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { + IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({})); + IO.enumCase(Value, "Consecutive", + FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true})); + IO.enumCase(Value, "AcrossEmptyLines", + FormatStyle::AlignConsecutiveStyle( + {/*.Enabled=*/true, /*.AcrossEmptyLines=*/true})); + IO.enumCase(Value, "AcrossComments", + FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true, + /*.AcrossEmptyLines=*/false, + /*.AcrossComments=*/true})); IO.enumCase(Value, "AcrossEmptyLinesAndComments", - FormatStyle::ACS_AcrossEmptyLinesAndComments); + FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true, + /*.AcrossEmptyLines=*/true, + /*.AcrossComments=*/true})); // For backward compatibility. - IO.enumCase(Value, "true", FormatStyle::ACS_Consecutive); - IO.enumCase(Value, "false", FormatStyle::ACS_None); + IO.enumCase(Value, "true", + FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true})); + IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({})); + } + + static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { + IO.mapOptional("Enabled", Value.Enabled); + IO.mapOptional("AcrossEmptyLines", Value.AcrossEmptyLines); + IO.mapOptional("AcrossComments", Value.AcrossComments); + IO.mapOptional("Aligncompound", Value.AlignCompound); + IO.mapOptional("PadOperators", Value.PadOperators); } }; @@ -600,13 +617,13 @@ IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset); IO.mapOptional("AlignAfterOpenBracket", Style.AlignAfterOpenBracket); IO.mapOptional("AlignArrayOfStructures", Style.AlignArrayOfStructures); - IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros); IO.mapOptional("AlignConsecutiveAssignments", Style.AlignConsecutiveAssignments); IO.mapOptional("AlignConsecutiveBitFields", Style.AlignConsecutiveBitFields); IO.mapOptional("AlignConsecutiveDeclarations", Style.AlignConsecutiveDeclarations); + IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros); IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines); IO.mapOptional("AlignOperands", Style.AlignOperands); IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments); @@ -1141,10 +1158,10 @@ LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None; LLVMStyle.AlignOperands = FormatStyle::OAS_Align; LLVMStyle.AlignTrailingComments = true; - LLVMStyle.AlignConsecutiveAssignments = FormatStyle::ACS_None; - LLVMStyle.AlignConsecutiveBitFields = FormatStyle::ACS_None; - LLVMStyle.AlignConsecutiveDeclarations = FormatStyle::ACS_None; - LLVMStyle.AlignConsecutiveMacros = FormatStyle::ACS_None; + LLVMStyle.AlignConsecutiveAssignments = {}; + LLVMStyle.AlignConsecutiveBitFields = {}; + LLVMStyle.AlignConsecutiveDeclarations = {}; + LLVMStyle.AlignConsecutiveMacros = {}; LLVMStyle.AllowAllArgumentsOnNextLine = true; LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true; LLVMStyle.AllowShortEnumsOnASingleLine = true; diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -267,10 +267,13 @@ } // Align a single sequence of tokens, see AlignTokens below. +// Column - The token for which Matches returns true is moved to this column. +// RightJustify - Whether it is the token's right end or left end that gets +// moved to that column. template static void AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, - unsigned Column, F &&Matches, + unsigned Column, bool RightJustify, F &&Matches, SmallVector &Changes) { bool FoundMatchOnLine = false; int Shift = 0; @@ -329,7 +332,8 @@ // shifted by the same amount if (!FoundMatchOnLine && !SkipMatchCheck && Matches(Changes[i])) { FoundMatchOnLine = true; - Shift = Column - Changes[i].StartOfTokenColumn; + Shift = Column - (RightJustify ? Changes[i].TokenLength : 0) - + Changes[i].StartOfTokenColumn; Changes[i].Spaces += Shift; // FIXME: This is a workaround that should be removed when we fix // http://llvm.org/PR53699. An assertion later below verifies this. @@ -456,13 +460,35 @@ // However, the special exception is that we do NOT skip function parameters // that are split across multiple lines. See the test case in FormatTest.cpp // that mentions "split function parameter alignment" for an example of this. +// When the parameter RightJustify is true, the operator will be +// right-justified. It is used to align compound assignments like `+=` +// and `=`. +// When RightJustify and PadAnchors are true, operators in each block to +// be aligned will be padded on the left to the same length before +// aligning. template -static unsigned AlignTokens( - const FormatStyle &Style, F &&Matches, - SmallVector &Changes, unsigned StartAt, - const FormatStyle::AlignConsecutiveStyle &ACS = FormatStyle::ACS_None) { - unsigned MinColumn = 0; - unsigned MaxColumn = UINT_MAX; +static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, + SmallVector &Changes, + unsigned StartAt, + const FormatStyle::AlignConsecutiveStyle &ACS = {}, + bool RightJustify = false) { + // We arrange each line in 3 parts. The operator to be aligned (the + // anchor), and text to its left and right. In the aligned text the + // width of each part will be the maximum of that over the block that + // has been aligned. + // Maximum widths of each part so far. + // When RightJustify is true and ACS.PadOperators is false, the part + // from start of line to the right end of the anchor. Otherwise, only + // the part to the left of the anchor. Including the space that exists + // on its left from the start. Not including the padding added on the + // left to right-justify the anchor. + unsigned WidthLeft = 0; + // The operator to be aligned when RightJustify is true and + // ACS.PadOperators is false. 0 otherwise. + unsigned WidthAnchor = 0; + // Width to the right of the anchor. Plus width of the anchor when + // RightJustify is false. + unsigned WidthRight = 0; // Line number of the start and the end of the current token sequence. unsigned StartOfSequence = 0; @@ -495,10 +521,12 @@ // containing any matching token to be aligned and located after such token. auto AlignCurrentSequence = [&] { if (StartOfSequence > 0 && StartOfSequence < EndOfSequence) - AlignTokenSequence(Style, StartOfSequence, EndOfSequence, MinColumn, - Matches, Changes); - MinColumn = 0; - MaxColumn = UINT_MAX; + AlignTokenSequence(Style, StartOfSequence, EndOfSequence, + WidthLeft + WidthAnchor, RightJustify, Matches, + Changes); + WidthLeft = 0; + WidthAnchor = 0; + WidthRight = 0; StartOfSequence = 0; EndOfSequence = 0; }; @@ -514,17 +542,12 @@ // Whether to break the alignment sequence because of an empty line. bool EmptyLineBreak = - (Changes[i].NewlinesBefore > 1) && - (ACS != FormatStyle::ACS_AcrossEmptyLines) && - (ACS != FormatStyle::ACS_AcrossEmptyLinesAndComments); + (Changes[i].NewlinesBefore > 1) && !ACS.AcrossEmptyLines; // Whether to break the alignment sequence because of a line without a // match. bool NoMatchBreak = - !FoundMatchOnLine && - !(LineIsComment && - ((ACS == FormatStyle::ACS_AcrossComments) || - (ACS == FormatStyle::ACS_AcrossEmptyLinesAndComments))); + !FoundMatchOnLine && !(LineIsComment && ACS.AcrossComments); if (EmptyLineBreak || NoMatchBreak) AlignCurrentSequence(); @@ -563,29 +586,44 @@ if (StartOfSequence == 0) StartOfSequence = i; - unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; - int LineLengthAfter = Changes[i].TokenLength; + unsigned ChangeWidthLeft = Changes[i].StartOfTokenColumn; + unsigned ChangeWidthAnchor = 0; + unsigned ChangeWidthRight = 0; + if (RightJustify) { + if (ACS.PadOperators) + ChangeWidthAnchor = Changes[i].TokenLength; + else + ChangeWidthLeft += Changes[i].TokenLength; + } else + ChangeWidthRight = Changes[i].TokenLength; for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) { - LineLengthAfter += Changes[j].Spaces; + ChangeWidthRight += Changes[j].Spaces; // Changes are generally 1:1 with the tokens, but a change could also be // inside of a token, in which case it's counted more than once: once for // the whitespace surrounding the token (!IsInsideToken) and once for // each whitespace change within it (IsInsideToken). // Therefore, changes inside of a token should only count the space. if (!Changes[j].IsInsideToken) - LineLengthAfter += Changes[j].TokenLength; + ChangeWidthRight += Changes[j].TokenLength; } - unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. - if (ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn || - CommasBeforeLastMatch != CommasBeforeMatch) { + unsigned NewLeft = std::max(ChangeWidthLeft, WidthLeft); + unsigned NewAnchor = std::max(ChangeWidthAnchor, WidthAnchor); + unsigned NewRight = std::max(ChangeWidthRight, WidthRight); + // `ColumnLimit == 0` means there is no column limit. + if (Style.ColumnLimit != 0 && + Style.ColumnLimit < NewLeft + NewAnchor + NewRight) { AlignCurrentSequence(); StartOfSequence = i; + WidthLeft = ChangeWidthLeft; + WidthAnchor = ChangeWidthAnchor; + WidthRight = ChangeWidthRight; + } else { + WidthLeft = NewLeft; + WidthAnchor = NewAnchor; + WidthRight = NewRight; } - - MinColumn = std::max(MinColumn, ChangeMinColumn); - MaxColumn = std::min(MaxColumn, ChangeMaxColumn); } EndOfSequence = i; @@ -639,7 +677,7 @@ } void WhitespaceManager::alignConsecutiveMacros() { - if (Style.AlignConsecutiveMacros == FormatStyle::ACS_None) + if (!Style.AlignConsecutiveMacros.Enabled) return; auto AlignMacrosMatches = [](const Change &C) { @@ -690,20 +728,14 @@ EndOfSequence = I; // Whether to break the alignment sequence because of an empty line. - bool EmptyLineBreak = - (Changes[I].NewlinesBefore > 1) && - (Style.AlignConsecutiveMacros != FormatStyle::ACS_AcrossEmptyLines) && - (Style.AlignConsecutiveMacros != - FormatStyle::ACS_AcrossEmptyLinesAndComments); + bool EmptyLineBreak = (Changes[I].NewlinesBefore > 1) && + !Style.AlignConsecutiveMacros.AcrossEmptyLines; // Whether to break the alignment sequence because of a line without a // match. bool NoMatchBreak = !FoundMatchOnLine && - !(LineIsComment && ((Style.AlignConsecutiveMacros == - FormatStyle::ACS_AcrossComments) || - (Style.AlignConsecutiveMacros == - FormatStyle::ACS_AcrossEmptyLinesAndComments))); + !(LineIsComment && Style.AlignConsecutiveMacros.AcrossComments); if (EmptyLineBreak || NoMatchBreak) AlignMacroSequence(StartOfSequence, EndOfSequence, MinColumn, MaxColumn, @@ -741,7 +773,7 @@ } void WhitespaceManager::alignConsecutiveAssignments() { - if (Style.AlignConsecutiveAssignments == FormatStyle::ACS_None) + if (!Style.AlignConsecutiveAssignments.Enabled) return; AlignTokens( @@ -760,13 +792,16 @@ if (Previous && Previous->is(tok::kw_operator)) return false; - return C.Tok->is(tok::equal); + return Style.AlignConsecutiveAssignments.AlignCompound + ? C.Tok->getPrecedence() == prec::Assignment + : C.Tok->is(tok::equal); }, - Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments); + Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments, + /*RightJustify=*/true); } void WhitespaceManager::alignConsecutiveBitFields() { - if (Style.AlignConsecutiveBitFields == FormatStyle::ACS_None) + if (!Style.AlignConsecutiveBitFields.Enabled) return; AlignTokens( @@ -786,7 +821,7 @@ } void WhitespaceManager::alignConsecutiveDeclarations() { - if (Style.AlignConsecutiveDeclarations == FormatStyle::ACS_None) + if (!Style.AlignConsecutiveDeclarations.Enabled) return; AlignTokens( diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2076,7 +2076,7 @@ " res2 = [](int &a) { return 0000000000000; };", Style); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("Const unsigned int *c;\n" "const unsigned int *d;\n" "Const unsigned int &e;\n" @@ -2117,7 +2117,7 @@ " res2 = [](int& a) { return 0000000000000; };", Style); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("Const unsigned int* c;\n" "const unsigned int* d;\n" "Const unsigned int& e;\n" @@ -2138,7 +2138,7 @@ verifyFormat("for (int a = 0, b = 0; const Foo *c : {1, 2, 3})", Style); verifyFormat("for (int a = 0, b++; const Foo *c : {1, 2, 3})", Style); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("Const unsigned int *c;\n" "const unsigned int *d;\n" "Const unsigned int& e;\n" @@ -2174,7 +2174,7 @@ " res2 = [](int & a) { return 0000000000000; };", Style); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("Const unsigned int* c;\n" "const unsigned int* d;\n" "Const unsigned int & e;\n" @@ -14425,8 +14425,8 @@ "*/\n" "}", Tab)); - Tab.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - Tab.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Tab.AlignConsecutiveAssignments.Enabled = true; + Tab.AlignConsecutiveDeclarations.Enabled = true; Tab.TabWidth = 4; Tab.IndentWidth = 4; verifyFormat("class Assign {\n" @@ -14664,8 +14664,8 @@ "*/\n" "}", Tab)); - Tab.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - Tab.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Tab.AlignConsecutiveAssignments.Enabled = true; + Tab.AlignConsecutiveDeclarations.Enabled = true; Tab.TabWidth = 4; Tab.IndentWidth = 4; verifyFormat("class Assign {\n" @@ -15835,9 +15835,8 @@ TEST_F(FormatTest, AlignConsecutiveMacros) { FormatStyle Style = getLLVMStyle(); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; - Style.AlignConsecutiveMacros = FormatStyle::ACS_None; + Style.AlignConsecutiveAssignments.Enabled = true; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("#define a 3\n" "#define bbbb 4\n" @@ -15861,7 +15860,7 @@ "#define ffff(x, y) (x - y)", Style); - Style.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveMacros.Enabled = true; verifyFormat("#define a 3\n" "#define bbbb 4\n" "#define ccc (5)", @@ -15901,7 +15900,7 @@ "};", Style); - Style.AlignConsecutiveMacros = FormatStyle::ACS_None; + Style.AlignConsecutiveMacros.Enabled = false; Style.ColumnLimit = 20; verifyFormat("#define a \\\n" @@ -15915,7 +15914,7 @@ " \"LLLLLLLL\"\n", Style); - Style.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveMacros.Enabled = true; verifyFormat("#define a \\\n" " \"aabbbbbbbbbbbb\"\n" "#define D \\\n" @@ -15930,7 +15929,7 @@ // Test across comments Style.MaxEmptyLinesToKeep = 10; Style.ReflowComments = false; - Style.AlignConsecutiveMacros = FormatStyle::ACS_AcrossComments; + Style.AlignConsecutiveMacros.AcrossComments = true; EXPECT_EQ("#define a 3\n" "// line comment\n" "#define bbbb 4\n" @@ -15988,7 +15987,8 @@ Style)); // Test across empty lines - Style.AlignConsecutiveMacros = FormatStyle::ACS_AcrossEmptyLines; + Style.AlignConsecutiveMacros.AcrossComments = false; + Style.AlignConsecutiveMacros.AcrossEmptyLines = true; EXPECT_EQ("#define a 3\n" "\n" "#define bbbb 4\n" @@ -16026,7 +16026,7 @@ Style)); // Test across empty lines and comments - Style.AlignConsecutiveMacros = FormatStyle::ACS_AcrossEmptyLinesAndComments; + Style.AlignConsecutiveMacros.AcrossComments = true; verifyFormat("#define a 3\n" "\n" "// line comment\n" @@ -16077,8 +16077,9 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLines) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_AcrossEmptyLines; + Alignment.AlignConsecutiveMacros.Enabled = true; + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = true; Alignment.MaxEmptyLinesToKeep = 10; /* Test alignment across empty lines */ @@ -16151,9 +16152,9 @@ TEST_F(FormatTest, AlignConsecutiveDeclarationsAcrossEmptyLinesAndComments) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveDeclarations = - FormatStyle::ACS_AcrossEmptyLinesAndComments; - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Alignment.AlignConsecutiveDeclarations.Enabled = true; + Alignment.AlignConsecutiveDeclarations.AcrossEmptyLines = true; + Alignment.AlignConsecutiveDeclarations.AcrossComments = true; Alignment.MaxEmptyLinesToKeep = 10; /* Test alignment across empty lines */ @@ -16215,8 +16216,9 @@ TEST_F(FormatTest, AlignConsecutiveBitFieldsAcrossEmptyLinesAndComments) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveBitFields = - FormatStyle::ACS_AcrossEmptyLinesAndComments; + Alignment.AlignConsecutiveBitFields.Enabled = true; + Alignment.AlignConsecutiveBitFields.AcrossEmptyLines = true; + Alignment.AlignConsecutiveBitFields.AcrossComments = true; Alignment.MaxEmptyLinesToKeep = 10; /* Test alignment across empty lines */ @@ -16282,8 +16284,9 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossComments) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_AcrossComments; + Alignment.AlignConsecutiveMacros.Enabled = true; + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.AlignConsecutiveAssignments.AcrossComments = true; Alignment.MaxEmptyLinesToKeep = 10; /* Test alignment across empty lines */ @@ -16369,9 +16372,10 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; - Alignment.AlignConsecutiveAssignments = - FormatStyle::ACS_AcrossEmptyLinesAndComments; + Alignment.AlignConsecutiveMacros.Enabled = true; + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = true; + Alignment.AlignConsecutiveAssignments.AcrossComments = true; verifyFormat("int a = 5;\n" "int oneTwoThree = 123;", Alignment); @@ -16682,10 +16686,122 @@ Alignment)); } +TEST_F(FormatTest, AlignCompoundAssignments) { + FormatStyle Alignment = getLLVMStyle(); + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.AlignConsecutiveAssignments.AlignCompound = true; + Alignment.AlignConsecutiveAssignments.PadOperators = false; + verifyFormat("sfdbddfbdfbb = 5;\n" + "dvsdsv = 5;\n" + "int dsvvdvsdvvv = 123;", + Alignment); + verifyFormat("sfdbddfbdfbb ^= 5;\n" + "dvsdsv |= 5;\n" + "int dsvvdvsdvvv = 123;", + Alignment); + verifyFormat("sfdbddfbdfbb ^= 5;\n" + "dvsdsv <<= 5;\n" + "int dsvvdvsdvvv = 123;", + Alignment); + // Test that `<=` is not treated as a compound assignment. + verifyFormat("aa &= 5;\n" + "b <= 10;\n" + "c = 15;", + Alignment); + Alignment.AlignConsecutiveAssignments.PadOperators = true; + verifyFormat("sfdbddfbdfbb = 5;\n" + "dvsdsv = 5;\n" + "int dsvvdvsdvvv = 123;", + Alignment); + verifyFormat("sfdbddfbdfbb ^= 5;\n" + "dvsdsv |= 5;\n" + "int dsvvdvsdvvv = 123;", + Alignment); + verifyFormat("sfdbddfbdfbb ^= 5;\n" + "dvsdsv <<= 5;\n" + "int dsvvdvsdvvv = 123;", + Alignment); + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "\n" + "int oneTwoThree = 123;\n", + Alignment)); + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree = 123;\n", + Alignment)); + Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = true; + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "\n" + "int oneTwoThree = 123;\n", + Alignment)); + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree = 123;\n", + Alignment)); + Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = false; + Alignment.AlignConsecutiveAssignments.AcrossComments = true; + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "\n" + "int oneTwoThree = 123;\n", + Alignment)); + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree = 123;\n", + Alignment)); + Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = true; + EXPECT_EQ("int a += 5;\n" + "int one >>= 1;\n" + "\n" + "int oneTwoThree = 123;\n", + format("int a += 5;\n" + "int one >>= 1;\n" + "\n" + "int oneTwoThree = 123;\n", + Alignment)); + EXPECT_EQ("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree <<= 123;\n", + format("int a += 5;\n" + "int one = 1;\n" + "//\n" + "int oneTwoThree <<= 123;\n", + Alignment)); +} + TEST_F(FormatTest, AlignConsecutiveAssignments) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Alignment.AlignConsecutiveMacros.Enabled = true; verifyFormat("int a = 5;\n" "int oneTwoThree = 123;", Alignment); @@ -16693,14 +16809,15 @@ "int oneTwoThree = 123;", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveAssignments.Enabled = true; verifyFormat("int a = 5;\n" "int oneTwoThree = 123;", Alignment); verifyFormat("int a = method();\n" "int oneTwoThree = 133;", Alignment); - verifyFormat("a &= 5;\n" + verifyFormat("aa <= 5;\n" + "a &= 5;\n" "bcd *= 5;\n" "ghtyf += 5;\n" "dvfvdb -= 5;\n" @@ -16773,8 +16890,7 @@ Alignment); // https://llvm.org/PR33697 FormatStyle AlignmentWithPenalty = getLLVMStyle(); - AlignmentWithPenalty.AlignConsecutiveAssignments = - FormatStyle::ACS_Consecutive; + AlignmentWithPenalty.AlignConsecutiveAssignments.Enabled = true; AlignmentWithPenalty.PenaltyReturnTypeOnItsOwnLine = 5000; verifyFormat("class SSSSSSSSSSSSSSSSSSSSSSSSSSSS {\n" " void f() = delete;\n" @@ -16993,7 +17109,7 @@ TEST_F(FormatTest, AlignConsecutiveBitFields) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveBitFields = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveBitFields.Enabled = true; verifyFormat("int const a : 5;\n" "int oneTwoThree : 23;", Alignment); @@ -17003,7 +17119,7 @@ "int oneTwoThree : 23 = 0;", Alignment); - Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("int const a : 5;\n" "int oneTwoThree : 23;", Alignment); @@ -17016,7 +17132,7 @@ "int oneTwoThree : 23 = 0;", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveAssignments.Enabled = true; verifyFormat("int const a : 5 = 1;\n" "int oneTwoThree : 23 = 0;", Alignment); @@ -17050,8 +17166,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { FormatStyle Alignment = getLLVMStyle(); - Alignment.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; - Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_None; + Alignment.AlignConsecutiveMacros.Enabled = true; Alignment.PointerAlignment = FormatStyle::PAS_Right; verifyFormat("float const a = 5;\n" "int oneTwoThree = 123;", @@ -17060,7 +17175,7 @@ "float const oneTwoThree = 123;", Alignment); - Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("float const a = 5;\n" "int oneTwoThree = 123;", Alignment); @@ -17171,7 +17286,7 @@ verifyFormat("int a(int x, void (*fp)(int y));\n" "double b();", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveAssignments.Enabled = true; // Ensure recursive alignment is broken by function braces, so that the // "a = 1" does not align with subsequent assignments inside the function // body. @@ -17396,7 +17511,7 @@ "int foobar;\n", AlignmentMiddle); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Alignment.AlignConsecutiveAssignments.Enabled = false; Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign; verifyFormat("#define A \\\n" " int aaaa = 12; \\\n" @@ -17465,7 +17580,7 @@ "int j = 2;", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveAssignments.Enabled = true; verifyFormat("auto lambda = []() {\n" " auto ii = 0;\n" " float j = 0;\n" @@ -17479,7 +17594,7 @@ " i = 3 //\n" "};", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Alignment.AlignConsecutiveAssignments.Enabled = false; verifyFormat( "int i = 1;\n" @@ -17492,7 +17607,7 @@ // We expect declarations and assignments to align, as long as it doesn't // exceed the column limit, starting a new alignment sequence whenever it // happens. - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveAssignments.Enabled = true; Alignment.ColumnLimit = 30; verifyFormat("float ii = 1;\n" "unsigned j = 2;\n" @@ -17502,7 +17617,7 @@ "int myvar = 1;", Alignment); Alignment.ColumnLimit = 80; - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Alignment.AlignConsecutiveAssignments.Enabled = false; verifyFormat( "template 2) ? 3 : 4);\n" "float b[1][] = {{3.f}};\n", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveAssignments.Enabled = true; verifyFormat("float a, b = 1;\n" "int c = 2;\n" "int dd = 3;\n", @@ -17524,7 +17639,7 @@ verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" "float b[1][] = {{3.f}};\n", Alignment); - Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Alignment.AlignConsecutiveAssignments.Enabled = false; Alignment.ColumnLimit = 30; Alignment.BinPackParameters = false; @@ -17555,7 +17670,7 @@ Alignment.PointerAlignment = FormatStyle::PAS_Right; // See llvm.org/PR35641 - Alignment.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Alignment.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("int func() { //\n" " int b;\n" " unsigned c;\n" @@ -17564,7 +17679,7 @@ // See PR37175 FormatStyle Style = getMozillaStyle(); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" "foo(int a);", format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style)); @@ -17603,7 +17718,7 @@ // See PR46529 FormatStyle BracedAlign = getLLVMStyle(); - BracedAlign.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + BracedAlign.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("const auto result{[]() {\n" " const auto something = 1;\n" " return 2;\n" @@ -17630,8 +17745,10 @@ TEST_F(FormatTest, AlignWithLineBreaks) { auto Style = getLLVMStyleWithColumns(120); - EXPECT_EQ(Style.AlignConsecutiveAssignments, FormatStyle::ACS_None); - EXPECT_EQ(Style.AlignConsecutiveDeclarations, FormatStyle::ACS_None); + EXPECT_EQ(Style.AlignConsecutiveAssignments, + FormatStyle::AlignConsecutiveStyle({})); + EXPECT_EQ(Style.AlignConsecutiveDeclarations, + FormatStyle::AlignConsecutiveStyle({})); verifyFormat("void foo() {\n" " int myVar = 5;\n" " double x = 3.14;\n" @@ -17653,7 +17770,7 @@ Style); // clang-format on - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; verifyFormat("void foo() {\n" " int myVar = 5;\n" " double x = 3.14;\n" @@ -17675,8 +17792,8 @@ Style); // clang-format on - Style.AlignConsecutiveAssignments = FormatStyle::ACS_None; - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = false; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("void foo() {\n" " int myVar = 5;\n" " double x = 3.14;\n" @@ -17698,8 +17815,8 @@ Style); // clang-format on - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("void foo() {\n" " int myVar = 5;\n" @@ -17723,7 +17840,7 @@ // clang-format on Style = getLLVMStyleWithColumns(120); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; Style.ContinuationIndentWidth = 4; Style.IndentWidth = 4; @@ -17766,8 +17883,8 @@ "}", Style); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_None; + Style.AlignConsecutiveAssignments.Enabled = true; + Style.AlignConsecutiveDeclarations.Enabled = false; verifyFormat("void foo2(void) {\n" " BYTE p[1] = 1;\n" " A B = {.one_foooooooooooooooo = 2,\n" @@ -17777,8 +17894,8 @@ "}", Style); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_None; - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = false; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("void foo3(void) {\n" " BYTE p[1] = 1;\n" " A B = {.one_foooooooooooooooo = 2,\n" @@ -17788,8 +17905,8 @@ "}", Style); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("void foo4(void) {\n" " BYTE p[1] = 1;\n" " A B = {.one_foooooooooooooooo = 2,\n" @@ -18805,10 +18922,8 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { auto Style = getLLVMStyle(); Style.AlignArrayOfStructures = FormatStyle::AIAS_Right; - Style.AlignConsecutiveAssignments = - FormatStyle::AlignConsecutiveStyle::ACS_Consecutive; - Style.AlignConsecutiveDeclarations = - FormatStyle::AlignConsecutiveStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" @@ -18985,10 +19100,6 @@ Style = getLLVMStyleWithColumns(50); Style.AlignArrayOfStructures = FormatStyle::AIAS_Right; - Style.AlignConsecutiveAssignments = - FormatStyle::AlignConsecutiveStyle::ACS_Consecutive; - Style.AlignConsecutiveDeclarations = - FormatStyle::AlignConsecutiveStyle::ACS_Consecutive; verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" @@ -19000,10 +19111,8 @@ "};", Style); Style.ColumnLimit = 100; - Style.AlignConsecutiveAssignments = - FormatStyle::AlignConsecutiveStyle::ACS_AcrossComments; - Style.AlignConsecutiveDeclarations = - FormatStyle::AlignConsecutiveStyle::ACS_AcrossComments; + Style.AlignConsecutiveAssignments.AcrossComments = true; + Style.AlignConsecutiveDeclarations.AcrossComments = true; verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" @@ -19663,69 +19772,37 @@ CHECK_PARSE("QualifierOrder: [volatile, type]", QualifierOrder, std::vector({"volatile", "type"})); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; - CHECK_PARSE("AlignConsecutiveAssignments: None", AlignConsecutiveAssignments, - FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveAssignments: Consecutive", - AlignConsecutiveAssignments, FormatStyle::ACS_Consecutive); - CHECK_PARSE("AlignConsecutiveAssignments: AcrossEmptyLines", - AlignConsecutiveAssignments, FormatStyle::ACS_AcrossEmptyLines); - CHECK_PARSE("AlignConsecutiveAssignments: AcrossEmptyLinesAndComments", - AlignConsecutiveAssignments, - FormatStyle::ACS_AcrossEmptyLinesAndComments); - // For backwards compability, false / true should still parse - CHECK_PARSE("AlignConsecutiveAssignments: false", AlignConsecutiveAssignments, - FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveAssignments: true", AlignConsecutiveAssignments, - FormatStyle::ACS_Consecutive); - - Style.AlignConsecutiveBitFields = FormatStyle::ACS_Consecutive; - CHECK_PARSE("AlignConsecutiveBitFields: None", AlignConsecutiveBitFields, - FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveBitFields: Consecutive", - AlignConsecutiveBitFields, FormatStyle::ACS_Consecutive); - CHECK_PARSE("AlignConsecutiveBitFields: AcrossEmptyLines", - AlignConsecutiveBitFields, FormatStyle::ACS_AcrossEmptyLines); - CHECK_PARSE("AlignConsecutiveBitFields: AcrossEmptyLinesAndComments", - AlignConsecutiveBitFields, - FormatStyle::ACS_AcrossEmptyLinesAndComments); - // For backwards compability, false / true should still parse - CHECK_PARSE("AlignConsecutiveBitFields: false", AlignConsecutiveBitFields, - FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveBitFields: true", AlignConsecutiveBitFields, - FormatStyle::ACS_Consecutive); - - Style.AlignConsecutiveMacros = FormatStyle::ACS_Consecutive; - CHECK_PARSE("AlignConsecutiveMacros: None", AlignConsecutiveMacros, - FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveMacros: Consecutive", AlignConsecutiveMacros, - FormatStyle::ACS_Consecutive); - CHECK_PARSE("AlignConsecutiveMacros: AcrossEmptyLines", - AlignConsecutiveMacros, FormatStyle::ACS_AcrossEmptyLines); - CHECK_PARSE("AlignConsecutiveMacros: AcrossEmptyLinesAndComments", - AlignConsecutiveMacros, - FormatStyle::ACS_AcrossEmptyLinesAndComments); - // For backwards compability, false / true should still parse - CHECK_PARSE("AlignConsecutiveMacros: false", AlignConsecutiveMacros, - FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveMacros: true", AlignConsecutiveMacros, - FormatStyle::ACS_Consecutive); - - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; - CHECK_PARSE("AlignConsecutiveDeclarations: None", - AlignConsecutiveDeclarations, FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveDeclarations: Consecutive", - AlignConsecutiveDeclarations, FormatStyle::ACS_Consecutive); - CHECK_PARSE("AlignConsecutiveDeclarations: AcrossEmptyLines", - AlignConsecutiveDeclarations, FormatStyle::ACS_AcrossEmptyLines); - CHECK_PARSE("AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments", - AlignConsecutiveDeclarations, - FormatStyle::ACS_AcrossEmptyLinesAndComments); - // For backwards compability, false / true should still parse - CHECK_PARSE("AlignConsecutiveDeclarations: false", - AlignConsecutiveDeclarations, FormatStyle::ACS_None); - CHECK_PARSE("AlignConsecutiveDeclarations: true", - AlignConsecutiveDeclarations, FormatStyle::ACS_Consecutive); +#define CHECK_ALIGN_CONSECUTIVE(FIELD) \ + do { \ + Style.FIELD.Enabled = true; \ + CHECK_PARSE(#FIELD ": None", FIELD, \ + FormatStyle::AlignConsecutiveStyle({})); \ + CHECK_PARSE(#FIELD ": Consecutive", FIELD, \ + FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true})); \ + CHECK_PARSE(#FIELD ": AcrossEmptyLines", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*.Enabled=*/true, /*.AcrossEmptyLines=*/true})); \ + CHECK_PARSE(#FIELD ": AcrossEmptyLinesAndComments", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*.Enabled=*/true, /*.AcrossEmptyLines=*/true, \ + /*.AcrossComments=*/true})); \ + /* For backwards compability, false / true should still parse */ \ + CHECK_PARSE(#FIELD ": false", FIELD, \ + FormatStyle::AlignConsecutiveStyle({})); \ + CHECK_PARSE(#FIELD ": true", FIELD, \ + FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true})); \ + \ + CHECK_PARSE_NESTED_BOOL(FIELD, Enabled); \ + CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines); \ + CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments); \ + } while (false) + + CHECK_ALIGN_CONSECUTIVE(AlignConsecutiveAssignments); + CHECK_ALIGN_CONSECUTIVE(AlignConsecutiveBitFields); + CHECK_ALIGN_CONSECUTIVE(AlignConsecutiveMacros); + CHECK_ALIGN_CONSECUTIVE(AlignConsecutiveDeclarations); + +#undef CHECK_ALIGN_CONSECUTIVE Style.PointerAlignment = FormatStyle::PAS_Middle; CHECK_PARSE("PointerAlignment: Left", PointerAlignment, @@ -23297,7 +23374,7 @@ format("FOO(String-ized&Messy+But,: :\n" " Still=Intentional);", Style)); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; EXPECT_EQ("FOO(String-ized=&Messy+But,: :\n" " Still=Intentional);", format("FOO(String-ized=&Messy+But,: :\n" @@ -24173,7 +24250,7 @@ EXPECT_EQ(Source, format(Source, Style)); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; EXPECT_EQ("void Foo::slot() {\n" " unsigned char MyChar = 'x';\n" " emit signal(MyChar);\n" diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2699,7 +2699,7 @@ TEST_F(FormatTestJS, AlignConsecutiveDeclarations) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; verifyFormat("let letVariable = 5;\n" "double constVariable = 10;", Style); @@ -2736,7 +2736,7 @@ TEST_F(FormatTestJS, AlignConsecutiveAssignments) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveAssignments.Enabled = true; verifyFormat("let letVariable = 5;\n" "double constVariable = 10;", Style); @@ -2772,8 +2772,8 @@ TEST_F(FormatTestJS, AlignConsecutiveAssignmentsAndDeclarations) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript); - Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; - Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations.Enabled = true; + Style.AlignConsecutiveAssignments.Enabled = true; verifyFormat("let letVariable = 5;\n" "double constVariable = 10;", Style);