forked from OSchip/llvm-project
Revert "[clang-format] Add the possibility to align assignments spanning empty lines or comments"
This reverts commit f00a20e51c
.
This commit is contained in:
parent
f00a20e51c
commit
7b9d88ab38
|
@ -195,84 +195,23 @@ the configuration (without a prefix: ``Auto``).
|
|||
|
||||
|
||||
|
||||
**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``)
|
||||
Style of aligning consecutive assignments.
|
||||
**AlignConsecutiveAssignments** (``bool``)
|
||||
If ``true``, aligns consecutive assignments.
|
||||
|
||||
``Consecutive`` will result in formattings like:
|
||||
This will align the assignment operators of consecutive lines. This
|
||||
will result in formattings like
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int a = 1;
|
||||
int somelongname = 2;
|
||||
double c = 3;
|
||||
int aaaa = 12;
|
||||
int b = 23;
|
||||
int ccc = 23;
|
||||
|
||||
Possible values:
|
||||
**AlignConsecutiveBitFields** (``bool``)
|
||||
If ``true``, aligns consecutive bitfield members.
|
||||
|
||||
* ``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-block:: c++
|
||||
|
||||
int a = 1;
|
||||
int somelongname = 2;
|
||||
double c = 3;
|
||||
|
||||
int d = 3;
|
||||
/* A comment. */
|
||||
double e = 4;
|
||||
|
||||
* ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
|
||||
Same as ACS_Consecutive, but also spans over empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int a = 1;
|
||||
int somelongname = 2;
|
||||
double c = 3;
|
||||
|
||||
int d = 3;
|
||||
/* A comment. */
|
||||
double e = 4;
|
||||
|
||||
* ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int a = 1;
|
||||
int somelongname = 2;
|
||||
double c = 3;
|
||||
|
||||
int d = 3;
|
||||
/* A comment. */
|
||||
double e = 4;
|
||||
|
||||
* ``ACS_AcrossEmptyLinesAndComments``
|
||||
(in configuration: ``AcrossEmptyLinesAndComments``)
|
||||
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments and empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int a = 1;
|
||||
int somelongname = 2;
|
||||
double c = 3;
|
||||
|
||||
int d = 3;
|
||||
/* A comment. */
|
||||
double e = 4;
|
||||
|
||||
**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``)
|
||||
Style of aligning consecutive bit field.
|
||||
|
||||
``Consecutive`` will align the bitfield separators of consecutive lines.
|
||||
This will result in formattings like:
|
||||
This will align the bitfield separators of consecutive lines. This
|
||||
will result in formattings like
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
|
@ -280,146 +219,23 @@ the configuration (without a prefix: ``Auto``).
|
|||
int b : 12;
|
||||
int ccc : 8;
|
||||
|
||||
Possible values:
|
||||
**AlignConsecutiveDeclarations** (``bool``)
|
||||
If ``true``, aligns consecutive declarations.
|
||||
|
||||
* ``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-block:: c++
|
||||
|
||||
int aaaa : 1;
|
||||
int b : 12;
|
||||
int ccc : 8;
|
||||
|
||||
int d : 2;
|
||||
/* A comment. */
|
||||
int ee : 3;
|
||||
|
||||
* ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
|
||||
Same as ACS_Consecutive, but also spans over empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa : 1;
|
||||
int b : 12;
|
||||
int ccc : 8;
|
||||
|
||||
int d : 2;
|
||||
/* A comment. */
|
||||
int ee : 3;
|
||||
|
||||
* ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa : 1;
|
||||
int b : 12;
|
||||
int ccc : 8;
|
||||
|
||||
int d : 2;
|
||||
/* A comment. */
|
||||
int ee : 3;
|
||||
|
||||
* ``ACS_AcrossEmptyLinesAndComments``
|
||||
(in configuration: ``AcrossEmptyLinesAndComments``)
|
||||
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments and empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa : 1;
|
||||
int b : 12;
|
||||
int ccc : 8;
|
||||
|
||||
int d : 2;
|
||||
/* A comment. */
|
||||
int ee : 3;
|
||||
|
||||
**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``)
|
||||
Style of aligning consecutive declarations.
|
||||
|
||||
``Consecutive`` will align the declaration names of consecutive lines.
|
||||
This will result in formattings like:
|
||||
This will align the declaration names of consecutive lines. This
|
||||
will result in formattings like
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa = 12;
|
||||
float b = 23;
|
||||
std::string ccc;
|
||||
std::string ccc = 23;
|
||||
|
||||
Possible values:
|
||||
**AlignConsecutiveMacros** (``bool``)
|
||||
If ``true``, aligns consecutive C/C++ preprocessor macros.
|
||||
|
||||
* ``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-block:: c++
|
||||
|
||||
int aaaa = 12;
|
||||
float b = 23;
|
||||
std::string ccc;
|
||||
|
||||
int a = 42;
|
||||
/* A comment. */
|
||||
bool c = false;
|
||||
|
||||
* ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
|
||||
Same as ACS_Consecutive, but also spans over empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa = 12;
|
||||
float b = 23;
|
||||
std::string ccc;
|
||||
|
||||
int a = 42;
|
||||
/* A comment. */
|
||||
bool c = false;
|
||||
|
||||
* ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa = 12;
|
||||
float b = 23;
|
||||
std::string ccc;
|
||||
|
||||
int a = 42;
|
||||
/* A comment. */
|
||||
bool c = false;
|
||||
|
||||
* ``ACS_AcrossEmptyLinesAndComments``
|
||||
(in configuration: ``AcrossEmptyLinesAndComments``)
|
||||
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments and empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
int aaaa = 12;
|
||||
float b = 23;
|
||||
std::string ccc;
|
||||
|
||||
int a = 42;
|
||||
/* A comment. */
|
||||
bool c = false;
|
||||
|
||||
**AlignConsecutiveMacros** (``AlignConsecutiveStyle``)
|
||||
Style of aligning consecutive macro definitions.
|
||||
|
||||
``Consecutive`` will result in formattings like:
|
||||
This will align C/C++ preprocessor macros of consecutive lines.
|
||||
Will result in formattings like
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
|
@ -429,68 +245,6 @@ the configuration (without a prefix: ``Auto``).
|
|||
#define foo(x) (x * x)
|
||||
#define bar(y, z) (y + z)
|
||||
|
||||
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-block:: c++
|
||||
|
||||
#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)
|
||||
|
||||
* ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``)
|
||||
Same as ACS_Consecutive, but also spans over empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
#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)
|
||||
|
||||
* ``ACS_AcrossComments`` (in configuration: ``AcrossComments``)
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
#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)
|
||||
|
||||
* ``ACS_AcrossEmptyLinesAndComments``
|
||||
(in configuration: ``AcrossEmptyLinesAndComments``)
|
||||
|
||||
Same as ACS_Consecutive, but also spans over lines only containing
|
||||
comments and empty lines, e.g.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
#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)
|
||||
|
||||
**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
|
||||
Options for aligning backslashes in escaped newlines.
|
||||
|
||||
|
|
|
@ -289,11 +289,9 @@ clang-format
|
|||
|
||||
- Option ``IndentRequires`` has been added to indent the ``requires`` keyword
|
||||
in templates.
|
||||
|
||||
- Option ``BreakBeforeConceptDeclarations`` has been added to aid the formatting of concepts.
|
||||
|
||||
- Option ``IndentPragmas`` has been added to allow #pragma to indented with the current scope
|
||||
level. This is especially useful when using #pragma to mark OpenMP sections of code.
|
||||
- Option ``IndentPragmas`` has been added to allow #pragma to indented with the current scope level. This is especially useful when using #pragma to mark OpenMP sections of code.
|
||||
|
||||
- Option ``SpaceBeforeCaseColon`` has been added to add a space before the
|
||||
colon in a case or default statement.
|
||||
|
@ -302,9 +300,6 @@ clang-format
|
|||
macros which are not parsed as a type in front of a statement. See
|
||||
the documentation for an example.
|
||||
|
||||
- Options ``AlignConsecutiveAssignments``, ``AlignConsecutiveBitFields``,
|
||||
``AlignConsecutiveDeclarations`` and ``AlignConsecutiveMacros`` have been modified to allow
|
||||
alignment across empty lines and/or comments.
|
||||
|
||||
libclang
|
||||
--------
|
||||
|
|
|
@ -42,7 +42,7 @@ class Option(object):
|
|||
def __str__(self):
|
||||
s = '**%s** (``%s``)\n%s' % (self.name, self.type,
|
||||
doxygen2rst(indent(self.comment, 2)))
|
||||
if self.enum and self.enum.values:
|
||||
if self.enum:
|
||||
s += indent('\n\nPossible values:\n\n%s\n' % self.enum, 2)
|
||||
if self.nested_struct:
|
||||
s += indent('\n\nNested configuration flags:\n\n%s\n' %self.nested_struct,
|
||||
|
@ -104,18 +104,13 @@ class EnumValue(object):
|
|||
doxygen2rst(indent(self.comment, 2)))
|
||||
|
||||
def clean_comment_line(line):
|
||||
match = re.match(r'^/// (?P<indent> +)?\\code(\{.(?P<lang>\w+)\})?$', line)
|
||||
match = re.match(r'^/// \\code(\{.(\w+)\})?$', line)
|
||||
if match:
|
||||
indent = match.group('indent')
|
||||
if not indent:
|
||||
indent = ''
|
||||
lang = match.group('lang')
|
||||
lang = match.groups()[1]
|
||||
if not lang:
|
||||
lang = 'c++'
|
||||
return '\n%s.. code-block:: %s\n\n' % (indent, lang)
|
||||
|
||||
endcode_match = re.match(r'^/// +\\endcode$', line)
|
||||
if endcode_match:
|
||||
return '\n.. code-block:: %s\n\n' % lang
|
||||
if line == '/// \\endcode':
|
||||
return ''
|
||||
return line[4:] + '\n'
|
||||
|
||||
|
@ -189,9 +184,7 @@ def read_options(header):
|
|||
state = State.InStruct
|
||||
enums[enum.name] = enum
|
||||
else:
|
||||
# Enum member without documentation. Must be documented where the enum
|
||||
# is used.
|
||||
pass
|
||||
raise Exception('Invalid format, expected enum field comment or };')
|
||||
elif state == State.InEnumMemberComment:
|
||||
if line.startswith('///'):
|
||||
comment += clean_comment_line(line)
|
||||
|
|
|
@ -84,23 +84,10 @@ struct FormatStyle {
|
|||
/// brackets.
|
||||
BracketAlignmentStyle AlignAfterOpenBracket;
|
||||
|
||||
/// 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
|
||||
};
|
||||
|
||||
/// Style of aligning consecutive macro definitions.
|
||||
/// \brief If ``true``, aligns consecutive C/C++ preprocessor macros.
|
||||
///
|
||||
/// ``Consecutive`` will result in formattings like:
|
||||
/// This will align C/C++ preprocessor macros of consecutive lines.
|
||||
/// Will result in formattings like
|
||||
/// \code
|
||||
/// #define SHORT_NAME 42
|
||||
/// #define LONGER_NAME 0x007f
|
||||
|
@ -108,271 +95,40 @@ struct FormatStyle {
|
|||
/// #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
|
||||
AlignConsecutiveStyle AlignConsecutiveMacros;
|
||||
bool AlignConsecutiveMacros;
|
||||
|
||||
/// Style of aligning consecutive assignments.
|
||||
/// If ``true``, aligns consecutive assignments.
|
||||
///
|
||||
/// ``Consecutive`` will result in formattings like:
|
||||
/// This will align the assignment operators of consecutive lines. This
|
||||
/// will result in formattings like
|
||||
/// \code
|
||||
/// int a = 1;
|
||||
/// int somelongname = 2;
|
||||
/// double c = 3;
|
||||
/// int aaaa = 12;
|
||||
/// int b = 23;
|
||||
/// int ccc = 23;
|
||||
/// \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
|
||||
AlignConsecutiveStyle AlignConsecutiveAssignments;
|
||||
bool AlignConsecutiveAssignments;
|
||||
|
||||
/// Style of aligning consecutive bit field.
|
||||
/// If ``true``, aligns consecutive bitfield members.
|
||||
///
|
||||
/// ``Consecutive`` will align the bitfield separators of consecutive lines.
|
||||
/// This will result in formattings like:
|
||||
/// This will align the bitfield separators of consecutive lines. This
|
||||
/// will result in formattings like
|
||||
/// \code
|
||||
/// int aaaa : 1;
|
||||
/// 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
|
||||
AlignConsecutiveStyle AlignConsecutiveBitFields;
|
||||
bool AlignConsecutiveBitFields;
|
||||
|
||||
/// Style of aligning consecutive declarations.
|
||||
/// If ``true``, aligns consecutive declarations.
|
||||
///
|
||||
/// ``Consecutive`` will align the declaration names of consecutive lines.
|
||||
/// This will result in formattings like:
|
||||
/// This will align the declaration names of consecutive lines. This
|
||||
/// will result in formattings like
|
||||
/// \code
|
||||
/// int aaaa = 12;
|
||||
/// float b = 23;
|
||||
/// std::string ccc;
|
||||
/// std::string ccc = 23;
|
||||
/// \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
|
||||
AlignConsecutiveStyle AlignConsecutiveDeclarations;
|
||||
bool AlignConsecutiveDeclarations;
|
||||
|
||||
/// Different styles for aligning escaped newlines.
|
||||
enum EscapedNewlineAlignmentStyle : unsigned char {
|
||||
|
@ -2969,7 +2725,6 @@ struct FormatStyle {
|
|||
AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
|
||||
AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
|
||||
AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
|
||||
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
|
||||
AlignEscapedNewlines == R.AlignEscapedNewlines &&
|
||||
AlignOperands == R.AlignOperands &&
|
||||
AlignTrailingComments == R.AlignTrailingComments &&
|
||||
|
|
|
@ -128,21 +128,6 @@ template <> struct ScalarEnumerationTraits<FormatStyle::ShortFunctionStyle> {
|
|||
}
|
||||
};
|
||||
|
||||
template <> struct ScalarEnumerationTraits<FormatStyle::AlignConsecutiveStyle> {
|
||||
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);
|
||||
IO.enumCase(Value, "AcrossEmptyLinesAndComments",
|
||||
FormatStyle::ACS_AcrossEmptyLinesAndComments);
|
||||
|
||||
// For backward compability.
|
||||
IO.enumCase(Value, "true", FormatStyle::ACS_Consecutive);
|
||||
IO.enumCase(Value, "false", FormatStyle::ACS_None);
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct ScalarEnumerationTraits<FormatStyle::ShortIfStyle> {
|
||||
static void enumeration(IO &IO, FormatStyle::ShortIfStyle &Value) {
|
||||
IO.enumCase(Value, "Never", FormatStyle::SIS_Never);
|
||||
|
@ -872,10 +857,10 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
|
|||
LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
|
||||
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 = false;
|
||||
LLVMStyle.AlignConsecutiveBitFields = false;
|
||||
LLVMStyle.AlignConsecutiveDeclarations = false;
|
||||
LLVMStyle.AlignConsecutiveMacros = false;
|
||||
LLVMStyle.AllowAllArgumentsOnNextLine = true;
|
||||
LLVMStyle.AllowAllConstructorInitializersOnNextLine = true;
|
||||
LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
|
||||
|
|
|
@ -361,10 +361,9 @@ AlignTokenSequence(unsigned Start, unsigned End, unsigned Column, F &&Matches,
|
|||
// that are split across multiple lines. See the test case in FormatTest.cpp
|
||||
// that mentions "split function parameter alignment" for an example of this.
|
||||
template <typename F>
|
||||
static unsigned AlignTokens(
|
||||
const FormatStyle &Style, F &&Matches,
|
||||
SmallVector<WhitespaceManager::Change, 16> &Changes, unsigned StartAt,
|
||||
const FormatStyle::AlignConsecutiveStyle &ACS = FormatStyle::ACS_None) {
|
||||
static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
|
||||
SmallVector<WhitespaceManager::Change, 16> &Changes,
|
||||
unsigned StartAt) {
|
||||
unsigned MinColumn = 0;
|
||||
unsigned MaxColumn = UINT_MAX;
|
||||
|
||||
|
@ -387,9 +386,6 @@ static unsigned AlignTokens(
|
|||
// Whether a matching token has been found on the current line.
|
||||
bool FoundMatchOnLine = false;
|
||||
|
||||
// Whether the current line consists purely of comments.
|
||||
bool LineIsComment = true;
|
||||
|
||||
// Aligns a sequence of matching tokens, on the MinColumn column.
|
||||
//
|
||||
// Sequences start from the first matching token to align, and end at the
|
||||
|
@ -415,38 +411,19 @@ static unsigned AlignTokens(
|
|||
if (Changes[i].NewlinesBefore != 0) {
|
||||
CommasBeforeMatch = 0;
|
||||
EndOfSequence = i;
|
||||
|
||||
// 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);
|
||||
|
||||
// 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)));
|
||||
|
||||
if (EmptyLineBreak || NoMatchBreak)
|
||||
// If there is a blank line, or if the last line didn't contain any
|
||||
// matching token, the sequence ends here.
|
||||
if (Changes[i].NewlinesBefore > 1 || !FoundMatchOnLine)
|
||||
AlignCurrentSequence();
|
||||
|
||||
// A new line starts, re-initialize line status tracking bools.
|
||||
FoundMatchOnLine = false;
|
||||
LineIsComment = true;
|
||||
}
|
||||
|
||||
if (!Changes[i].Tok->is(tok::comment)) {
|
||||
LineIsComment = false;
|
||||
}
|
||||
|
||||
if (Changes[i].Tok->is(tok::comma)) {
|
||||
++CommasBeforeMatch;
|
||||
} else if (Changes[i].indentAndNestingLevel() > IndentAndNestingLevel) {
|
||||
// Call AlignTokens recursively, skipping over this scope block.
|
||||
unsigned StoppedAt = AlignTokens(Style, Matches, Changes, i, ACS);
|
||||
unsigned StoppedAt = AlignTokens(Style, Matches, Changes, i);
|
||||
i = StoppedAt - 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -541,7 +518,7 @@ static void AlignMacroSequence(
|
|||
}
|
||||
|
||||
void WhitespaceManager::alignConsecutiveMacros() {
|
||||
if (Style.AlignConsecutiveMacros == FormatStyle::ACS_None)
|
||||
if (!Style.AlignConsecutiveMacros)
|
||||
return;
|
||||
|
||||
auto AlignMacrosMatches = [](const Change &C) {
|
||||
|
@ -583,41 +560,17 @@ void WhitespaceManager::alignConsecutiveMacros() {
|
|||
// Whether a matching token has been found on the current line.
|
||||
bool FoundMatchOnLine = false;
|
||||
|
||||
// Whether the current line consists only of comments
|
||||
bool LineIsComment = true;
|
||||
|
||||
unsigned I = 0;
|
||||
for (unsigned E = Changes.size(); I != E; ++I) {
|
||||
if (Changes[I].NewlinesBefore != 0) {
|
||||
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);
|
||||
|
||||
// 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)));
|
||||
|
||||
if (EmptyLineBreak || NoMatchBreak)
|
||||
// If there is a blank line, or if the last line didn't contain any
|
||||
// matching token, the sequence ends here.
|
||||
if (Changes[I].NewlinesBefore > 1 || !FoundMatchOnLine)
|
||||
AlignMacroSequence(StartOfSequence, EndOfSequence, MinColumn, MaxColumn,
|
||||
FoundMatchOnLine, AlignMacrosMatches, Changes);
|
||||
|
||||
// A new line starts, re-initialize line status tracking bools.
|
||||
FoundMatchOnLine = false;
|
||||
LineIsComment = true;
|
||||
}
|
||||
|
||||
if (!Changes[I].Tok->is(tok::comment)) {
|
||||
LineIsComment = false;
|
||||
}
|
||||
|
||||
if (!AlignMacrosMatches(Changes[I]))
|
||||
|
@ -644,7 +597,7 @@ void WhitespaceManager::alignConsecutiveMacros() {
|
|||
}
|
||||
|
||||
void WhitespaceManager::alignConsecutiveAssignments() {
|
||||
if (Style.AlignConsecutiveAssignments == FormatStyle::ACS_None)
|
||||
if (!Style.AlignConsecutiveAssignments)
|
||||
return;
|
||||
|
||||
AlignTokens(
|
||||
|
@ -660,11 +613,11 @@ void WhitespaceManager::alignConsecutiveAssignments() {
|
|||
|
||||
return C.Tok->is(tok::equal);
|
||||
},
|
||||
Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments);
|
||||
Changes, /*StartAt=*/0);
|
||||
}
|
||||
|
||||
void WhitespaceManager::alignConsecutiveBitFields() {
|
||||
if (Style.AlignConsecutiveBitFields == FormatStyle::ACS_None)
|
||||
if (!Style.AlignConsecutiveBitFields)
|
||||
return;
|
||||
|
||||
AlignTokens(
|
||||
|
@ -680,11 +633,11 @@ void WhitespaceManager::alignConsecutiveBitFields() {
|
|||
|
||||
return C.Tok->is(TT_BitFieldColon);
|
||||
},
|
||||
Changes, /*StartAt=*/0, Style.AlignConsecutiveBitFields);
|
||||
Changes, /*StartAt=*/0);
|
||||
}
|
||||
|
||||
void WhitespaceManager::alignConsecutiveDeclarations() {
|
||||
if (Style.AlignConsecutiveDeclarations == FormatStyle::ACS_None)
|
||||
if (!Style.AlignConsecutiveDeclarations)
|
||||
return;
|
||||
|
||||
// FIXME: Currently we don't handle properly the PointerAlignment: Right
|
||||
|
@ -717,7 +670,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
|
|||
}
|
||||
return true;
|
||||
},
|
||||
Changes, /*StartAt=*/0, Style.AlignConsecutiveDeclarations);
|
||||
Changes, /*StartAt=*/0);
|
||||
}
|
||||
|
||||
void WhitespaceManager::alignChainedConditionals() {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue