308 Commits

Author SHA1 Message Date
Gedare Bloom
c669541c96 [clang-format] Add SpacesInParens with SpacesInParensOptions
This is a refactoring of:
- SpacesInConditionalStatement
- SpacesInCStyleCastParentheses
- SpaceInEmptyParentheses
- SpacesInParentheses

These are now options under the new Style Option: SpacesInParens. The
existing options are maintained for backward compatibility.

Within SpacesInParens, there are currently options for:
- Never
- Custom

The currently available options for Custom are:
- InConditionalStatements
- InCStyleCasts
- InEmptyParentheses
- Other

Setting InConditionalStatements and Other to true enables the same space
additions as SpacesInParentheses.

This refactoring does not add or remove any existing features, but it makes
it possible to more easily extend and maintain the addition of spaces within
parentheses.

Related to #55428.

Differential Revision: https://reviews.llvm.org/D155239
2023-07-24 19:27:23 -07:00
Galen Elias
74720d1b33 [clang-format] Add AlignConsecutiveShortCaseStatements
This adds a new AlignConsecutiveShortCaseStatements option in line with the
existing AlignConsecutive* options , which when
AllowShortCaseLabelsOnASingleLine is enabled will align the tokens after the
case statement's colon. This also adds a AlignCaseColons option to allow
aligning the case label colon itself rather than the token after it.

Fixes #55475.

Differential Revision: https://reviews.llvm.org/D151761
2023-07-24 18:39:25 -07:00
Owen Pan
87ad34ffdc Revert "[clang-format] Add AlignConsecutiveShortCaseStatements"
This reverts commit 4ba00844174db562d2bd8b15dab6aac605eddf57.
2023-07-24 18:37:42 -07:00
Owen Pan
ac6e55146f Revert "Revert "[clang-format] Add AlignConsecutiveShortCaseStatements""
This reverts commit 4f093b31669a4f8e417259583141159586a05b28.
2023-07-24 18:24:30 -07:00
Owen Pan
4f093b3166 Revert "[clang-format] Add AlignConsecutiveShortCaseStatements"
This reverts commit 4ba00844174db562d2bd8b15dab6aac605eddf57 due to missing
authorship.
2023-07-24 18:19:38 -07:00
Owen Pan
4ba0084417 [clang-format] Add AlignConsecutiveShortCaseStatements
This adds a new AlignConsecutiveShortCaseStatements option in line with the
existing AlignConsecutive* options , which when
AllowShortCaseLabelsOnASingleLine is enabled will align the tokens after the
case statement's colon. This also adds a AlignCaseColons option to allow
aligning the case label colon itself rather than the token after it.

Fixes #55475.

Differential Revision: https://reviews.llvm.org/D151761
2023-07-24 18:16:21 -07:00
Owen Pan
8f54b8331f [clang-format][doc] Replace single back quotes with double ones 2023-07-18 18:27:15 -07:00
Owen Pan
5c106f7b94 [clang-format] Add TypeNames option to disambiguate types/objects
If a non-keyword identifier is found in TypeNames, then a *, &, or && that
follows it is annotated as TT_PointerOrReference.

Differential Revision: https://reviews.llvm.org/D155273
2023-07-18 14:18:40 -07:00
Owen Pan
3a6a0702c2 [clang-format] Add an option to remove redundant parentheses
Differential Revision: https://reviews.llvm.org/D154484
2023-07-11 16:33:19 -07:00
Gedare Bloom
9ec5dc6944 [clang-format] Add note directive generation for docs
Generate a ..note:: directive when the \note is encountered in Format.h.

Differential Revision: https://reviews.llvm.org/D154552
2023-07-09 12:24:55 -07:00
Gedare Bloom
413a7cb6e0 [clang-format] Support block indenting array/struct list initializers
C89 and C99 list initializers are treated differently than Cpp11 braced
initializers. This patch identifies the C array/struct initializer lists by
finding the preceding equal sign before a left brace, and applies formatting
rules for BracketAlignmentStyle.BlockIndent to those list initializers.

Fixes #57878.

Differential Revision: https://reviews.llvm.org/D153205
2023-07-06 13:42:11 -07:00
Nikolas Klauser
f6d557ee34 [clang][NFC] Remove trailing whitespaces and enforce it in lib, include and docs
A lot of editors remove trailing whitespaces. This patch removes any trailing whitespaces and makes sure that no new ones are added.

Reviewed By: erichkeane, paulkirth, #libc, philnik

Spies: wangpc, aheejin, MaskRay, pcwang-thead, cfe-commits, libcxx-commits, dschuff, nemanjai, arichardson, kbarton, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, s.egerton, sameer.abuasal, apazos, luismarques, martong, frasercrmck, steakhal, luke

Differential Revision: https://reviews.llvm.org/D151963
2023-06-26 09:34:36 -07:00
Owen Pan
829ed96b77 Reland [clang-format] Add the KeepEmptyLinesAtEOF option 2023-06-13 10:02:10 -07:00
Paul Kirth
b6a718016c [clang-format] Add test case for issue 63170
After https://reviews.llvm.org/D151954 we've noticed some issues w/
clang-format behavior, as outlined in
https://github.com/llvm/llvm-project/issues/63170.

Valid C/C++ files, that were previously accepted, are now rejected by
clang-format, emitting the message:

"The new replacement overlaps with an existing replacement."

This reverts commit 4b9764959dc4b8783e18747c1742ab164e4bc4ee and
d2627cf88d2553a4c2e850430bdb908a4b7d2e52, which depends on it.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D152473
2023-06-09 20:10:19 +00:00
Owen Pan
d2627cf88d [clang-format] Add the KeepEmptyLinesAtEOF option
Adds an option KeepEmptyLinesAtEOF to keep empty lines (up to
MaxEmptyLinesToKeep) before EOF. This remedies the probably unintentional
change in behavior introduced in 3d3ea84a4f8f, which started to always
remove empty lines before EOF.

Fixes #56054.
Fixes #63150.

Differential Revision: https://reviews.llvm.org/D152305
2023-06-07 14:17:58 -07:00
Owen Pan
aed795942b [clang-format][doc] Fix a typo introduced in 9aab0db13fb6d 2023-05-26 02:11:42 -07:00
Mike Matthews
10518feaf3 [clang-format][doc] Fix contradiction in SortIncludes description
Fixes #62033.

Differential Revision: https://reviews.llvm.org/D147894
2023-05-26 01:58:57 -07:00
sstwcw
369e8762b4 [clang-format] Stop comment disrupting indentation of Verilog ports
Before:

```
module x
    #( //
        parameter x)
    ( //
        input y);
endmodule
```

After:

```
module x
    #(//
      parameter x)
    (//
     input y);
endmodule
```

If the first line in a port or parameter list is not a comment, the
following lines will be aligned to the first line as intended:

```
module x
    #(parameter x1,
      parameter x2)
    (input y,
     input y2);
endmodule
```

Previously, the indentation would be changed to an extra continuation
indentation relative to the start of the parenthesis or the hash if
the first token inside the parentheses was a comment.  It is a feature
introduced in ddaa9be97839.  The feature enabled one to insert a `//`
comment right after an opening parentheses to put the function
arguments on a new line with a small indentation regardless of how
long the function name is, like this:

```
someFunction(anotherFunction( // Force break.
    parameter));
```

People are unlikely to use this feature in a Verilog port list because
the formatter already puts the port list on its own lines.  A comment
at the start of a port list is probably a comment for the port on the
next line.

We also removed the space before the comment so that its indentation
would be same as that for a line comment anywhere else in the port
list.

Reviewed By: HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D149562
2023-05-16 02:56:58 +00:00
Kazu Hirata
2db0812882 [clang] Fix typos in documentation 2023-05-12 23:19:17 -07:00
Jon Phillips
c12aa69a0b [clang-format] Add BracedInitializerIndentWidth option
The option allows users to specify how many columns to use to indent
the contents of initializer lists.

Closes #51070.

Differential Revision: https://reviews.llvm.org/D146101
2023-04-29 00:36:19 -07:00
Shivam Gupta
64ae7669a7 [Docs] Update ClangFormatStyleOptions.rst's versionbadge's to have min-width
This fix https://github.com/llvm/llvm-project/issues/61934

By default, the width property is used to set the width of a table column.
However, if the content of a cell in that column is wider than the width
specified by the width property, the cell's content will overflow the
column and the table will become wider than the specified width.
This causes the version numbers to be displayed outside of their table cells.

Using the min-width property instead of width ensures that the column is
wide enough to accommodate the content of its cells. If a cell's content is
wider than the specified min-width, the column will expand to fit the content.
2023-04-14 23:57:26 +05:30
sstwcw
8385ee05e5 [clang-format] NFC Document the other space before colon option
There are two options that do much the same thing, but for different
languages.  With the addition to the doc, the user is less likely to
configure the wrong option and get frustrated that it doesn't work.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D147422
2023-04-07 13:52:18 +00:00
Jon Phillips
5c614bd88f [clang-format] Fix bugs with "LambdaBodyIndentation: OuterScope"
The previous implementation of the option corrupted the parenthesis
state stack. (See https://reviews.llvm.org/D102706.)

Fixes #55708.
Fixes #53212.
Fixes #52846.
Fixes #59954.

Differential Revision: https://reviews.llvm.org/D146042
2023-04-05 14:38:38 -07:00
sstwcw
74cc4389f3 [clang-format] Add option for having one port per line in Verilog
We added the option `VerilogBreakBetweenInstancePorts` to put ports on
separate lines in module instantiations.  We made it default to true
because style guides mostly recommend it that way for example:

https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md#module-instantiation

Reviewed By: HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D147327
2023-04-04 14:51:22 +00:00
Owen Pan
253985d58c [clang-format] Add MinDigits suboptions to IntegerLiteralSeparator
Closes #61209.

Differential Revision: https://reviews.llvm.org/D147111
2023-03-31 17:14:33 -07:00
mydeveloperday
af98f3b1f4 [clang-format] JSON Add ability to add a space before the colon
I've seen a couple of request for extra Json formatting to match prettier capability.

Reviewed By: owenpan

Differential Revision: https://reviews.llvm.org/D147003
2023-03-29 21:28:40 +01:00
mydeveloperday
b94175b0ee [clang-format] NFC Format.h and ClangFormatStyleOptions.rst are out of date
Regenerate the style documentation, requires some minor sphinx changes to avoid warnings

Reviewed By: klimek

Differential Revision: https://reviews.llvm.org/D146704
2023-03-24 09:27:23 +00:00
mydeveloperday
7c928205c1 Revert "[clang-format] NFC Format.h and ClangFormatStyleOptions.rst are out of date"
This reverts commit 7a5b95732ade6c2de69b26f1038aa0a5afc39393.
2023-03-23 09:52:59 +00:00
mydeveloperday
7a5b95732a [clang-format] NFC Format.h and ClangFormatStyleOptions.rst are out of date
Regenerate the style documentation, requires some minor sphinx changes to avoid warnings

Differential Revision: https://reviews.llvm.org/D146704
2023-03-23 09:48:24 +00:00
Backl1ght
c24cdd58a1 [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine
fixes https://github.com/llvm/llvm-project/issues/60241

Differential Revision: https://reviews.llvm.org/D143091
2023-02-06 19:39:05 +08:00
Owen Pan
4f37de9c91 [clang-format][doc] Fix a typo 2023-02-03 00:24:54 -08:00
Owen Pan
25e2d0f3c8 [clang-format] Support clang-format on/off line comments as prefix
Closes #60264.

Differential Revision: https://reviews.llvm.org/D142804
2023-02-01 13:07:09 -08:00
Backl1ght
58751f943f [clang-format] SortUsingDeclarations support lexicographic order
fix https://github.com/llvm/llvm-project/issues/59930

Differential Revision: https://reviews.llvm.org/D141694
2023-01-20 21:34:57 +08:00
Owen Pan
e3eca33594 [clang-format] Replace DeriveLineEnding and UseCRLF with LineEnding
Below is the mapping:
LineEnding  DeriveLineEnding UseCRLF
LF                false       false
CRLF              false       true
DeriveLF          true        false
DeriveCRLF        true        true

Differential Revision: https://reviews.llvm.org/D141654
2023-01-13 15:46:34 -08:00
Emilia Dreamer
9cddd7a2a1
[clang-format][docs] Add ability to link to specific config options
This allows for the creation of permalinks to specific clang-format
options, for better sharing of a specific option and its options.

(I'm adding the usual clang-format reviewers on this patch because
I don't know any other reviewers that well, perhaps someone with
docs experience should be added instead...)

Note that I wanted to make minimal changes to make this happen and thus
landed on an unideal setup, but to me, it seems like the best out of
worse ones.

I could have made every style option a subheading, which would add
automatically the logic for permalinks and the little paragraph icon for
sharing.

However, this meant that the links themselves would be suboptimal, as
they'd include the whole text of the heading, including the type and
versionbadge, which is needless noise and could change, breaking the
concept of a "permalink". The format of the page could be changed to
put the option names on their own in a heading, and the other info below
it in a paragraph.

As Sphinx seems unwilling to fix https://github.com/sphinx-doc/sphinx/issues/1961,
there isn't a succinct way to change the "id" html field used for
sections

I could have used an add-on (https://github.com/GeeTransit/sphinx-better-subsection),
or made one myself, but I wanted to avoid extra dependencies for no
reason. (plus, I don't know how to make one myself.)

I could have used raw HTML for each heading, but that would immensely
pollute the rst file, which, while it is generated, is currently still
human-readable and it'd be nice for it to stay that way.

Also note that sphinx treats references as case-insensitive, which means
that they will all be lowercased in the resulting HTML. I envisioned
the ability to simply add #OptionName after the URL to get placed right
at the desired config option, which isn't possible without things such
as inline `raw` HTML.

To reconcile that, I added the ¶ paragraph buttons that can be used to
generate the link to the desired section, but since headings are not
actually used, they are faked and literally just a link following each
option, which means they stylistically don't match all other headings.

Also note that this sort-of assumes HTML output. I know Sphinx can
output other formats but I do not know if they are used. A non-html
output could embed unusable ¶ signs everywhere.

I'm okay with this patch being rejected in its current solution, or if
any of the above listed alternatives are better, they could be pursued
instead. In case the downsides of this solution are too much, I will
just create a feature request issue for this and maybe let someone more
experienced with Sphinx handle it, since this is still a feature I would
like to have. (and I do not want to deal with Sphinx at all after
battling with it for a whole day to produce a mediocre result.)

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay, aaron.ballman

Differential Revision: https://reviews.llvm.org/D138446
2023-01-12 21:05:38 +02:00
Aaron Ballman
a74bc43670 Add a warning comment that this file is generated
This file is partially generated by a Python script in the
clang/docs/tools directory, but it's not obvious for people making
drive-by fixes. This comment hopefully helps people avoid making
changes that are later overwritten by the script.
2023-01-12 08:10:57 -05:00
Aaron Ballman
0d0dab4e5f Fix the Clang sphinx bot again
The changes to fix the bot yesterday got reverted in a subsequent
commit, so this adds those changes back again.

Fixes the issue found in:
https://lab.llvm.org/buildbot/#/builders/92/builds/38593
2023-01-12 07:59:07 -05:00
Owen Pan
b4ad387ec5 [clang-format][doc] Fix C++ code blocks for IntegerLiteralSeparator 2023-01-11 13:24:39 -08:00
Aaron Ballman
c0a5374140 Another round of speculative fixes for Clang sphinx
It seems that changing Format.h is insufficient to get the docs to
rebuild? Changing the .rst file directly to at least see if that gets
the bot back to green finally.
2023-01-11 13:27:33 -05:00
Aaron Ballman
d3b5634446 Speculatively fix the Clang sphinx build
This file builds correctly for me locally, but gives a warning about
not being able to lex the binary literal as C++ code.

This should fix the issue found by:
https://lab.llvm.org/buildbot/#/builders/92/builds/38522
2023-01-11 07:32:55 -05:00
Krasimir Georgiev
922c8891d9 Revert "Revert "[clang-format] Add an option for breaking after C++11 attributes""
This reverts commit 879bfe6a979295f834b76df66b19a203b93eed0f.

owenpan@ pointed out on https://reviews.llvm.org/D140956 that this
actually makes the formatting more consistent, so it's not a regression.
2023-01-11 11:30:30 +00:00
Owen Pan
1b1d8acdfa [clang-format][doc] Fix doc format for IntegerLiteralSeparator 2023-01-11 03:23:34 -08:00
Krasimir Georgiev
879bfe6a97 Revert "[clang-format] Add an option for breaking after C++11 attributes"
This reverts commit a28f0747c2f3728bd8a6f64f7c8ba80b4e0cda9f.

It appears that this regresses some function definitions, added an
example as a comment over at https://reviews.llvm.org/D140956.
2023-01-10 09:23:44 +00:00
Owen Pan
2c6ecc9db6 [clang-format] Add an option to insert a newline at EOF if missing
Closes #38042.

Differential Revision: https://reviews.llvm.org/D141035
2023-01-05 15:25:51 -08:00
Owen Pan
a28f0747c2 [clang-format] Add an option for breaking after C++11 attributes
Fixes #45968.
Fixes #54265.
Fixes #58102.

Differential Revision: https://reviews.llvm.org/D140956
2023-01-05 04:08:58 -08:00
Owen Pan
ed4afd1bba [clang-format][docs] Fix indentation for the Sphinx build
See https://reviews.llvm.org/D140543#4021209.
2023-01-01 15:13:36 -08:00
Owen Pan
89aad1e6a3 Reland [clang-format] Add an option to format integer literal separators
Previously committed in 46c94e5067b5 which was reverted in f0756e086010
due to a memory bug.

Closes #58949.

Differential Revision: https://reviews.llvm.org/D140543
2022-12-31 17:57:33 -08:00
Vitaly Buka
f0756e0860 Revert "[clang-format] Add an option to format integer literal separators"
Revert "[clang-format] Disable FixRanges in IntegerLiteralSeparatorTest"

Breaks buildbots, details in https://reviews.llvm.org/D140543

This reverts commit 879bd9146a2c9ea395abd7c1ebd0f76f414a4967.
This reverts commit 46c94e5067b5f396c24bb950505c79bc819bd4b8.
2022-12-25 13:04:41 -08:00
Owen Pan
46c94e5067 [clang-format] Add an option to format integer literal separators
Closes #58949.

Differential Revision: https://reviews.llvm.org/D140543
2022-12-24 15:35:17 -08:00
Emilia Dreamer
ba4caec64f
[clang-format][docs] Fix invalid CSS syntax in versionbadge
CSS uses colons, not the equals sign. The final semicolon is optional,
but preferred to be included. Really, the font property doesn't really
need to be there, but I suppose it was put there for a reason.

It's surprising how lenient browsers are when parsing

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D138441
2022-12-23 02:15:48 +02:00