3239 Commits

Author SHA1 Message Date
Owen Pan
0ed2945a59
[clang-format] Don't sort includes for C# (#129369)
Fixes #106194
2025-03-03 17:40:02 -08:00
Owen Pan
80f34e2716
[clang-format] Change BracedInitializerIndentWidth to int (#128988)
Fixes #108526
2025-02-27 20:18:02 -08:00
Owen Pan
d29a1be94b
[clang-format] Don't break before *const (#128817)
Fixes #28919
2025-02-26 18:25:09 -08:00
Owen Pan
2d585ccecc
[clang-format] Fix a bug that changes keyword or to an identifier (#128410)
Fixes #105482
2025-02-26 18:14:26 -08:00
Owen Pan
8fc8a84e23
[clang-format] Allow breaking before kw___attribute (#128623)
Fixes #74784
2025-02-25 19:44:54 -08:00
Owen Pan
0968df9c3a
[clang-format] Add the C language instead of treating it like C++ (#128287)
Closes #128120
2025-02-23 00:36:19 -08:00
Owen Pan
ffc61dc393
[clang-format] Allow specifying the language for .h files (#128122)
Closes #128119
2025-02-21 20:46:43 -08:00
Owen Pan
204dcafec0
[clang-format] Fix a bug in BCIS_AfterColon and ColumnLimit: 0 (#127964)
Fixes #127622
2025-02-20 19:06:51 -08:00
Owen Pan
13de15c9c4
[clang-format] Fix a bug in annotating StartOfName (#127545)
Also ensure we can break before ClassHeadName like StartOfName.

Fixes #127470
2025-02-18 00:15:01 -08:00
Owen Pan
885382f437
[clang-format] Fix a bug in annotating braces (#127306)
Fixes #107616.
2025-02-16 19:30:33 -08:00
Owen Pan
3063153b56
[clang-format] Fix a bug in annotating ObjCMethodSpecifier (#127159)
Fixes #58202.
2025-02-14 21:10:08 -08:00
Galen Elias
083f099a34
[clang-format] Support BraceWrapping.AfterNamespace with AllowShortNamespacesOnASingleLine (#123010)
AllowShortNamespacesOnASingleLine assumes that there is no newline
before the namespace brace, however, there is no actual reason this
shouldn't be compatible with BraceWrapping.AfterNamespace = true.

This is a little tricky in the implementation because
UnwrappedLineFormatter works on lines, so being flexible about the
offsets is awkward.

Not sure if there is a better pattern for combining the 'AllowShort'
options with the various configurations of BraceWrapping, but this
seemed mostly reasonable. Really, it would almost be preferable to just
pattern match on the direct token stream, rather than the
AnnotatedLines, but I'm not seeing a straightforward way to do that.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-02-13 20:14:39 -08:00
Owen Pan
3ca9238cb0 [clang-format][NFC] Fix test case format 2025-02-11 23:58:53 -08:00
Owen Pan
8d373ceaec
[clang-format] Handle C-style cast of member function pointer type (#126340)
Fixes #125012.
2025-02-08 23:22:33 -08:00
Gedare Bloom
e0a21e23a7
[clang-format] Add BinPackLongBracedList style option (#112482)
The use of Cpp11BracedListStyle with BinPackArguments=False avoids bin
packing until reaching a hard-coded limit of 20 items. This is an
arbitrary choice. Introduce a new style option to allow disabling this
limit.
2025-02-07 22:10:35 -08:00
leijurv
d2b45ce100
[clang-format] Add BreakBeforeTemplateCloser option (#118046)
In clang-format, multiline templates have the `>` on the same line as
the last parameter:

```c++
template <
    typename Foo,
    typename Bar>
void foo() {
```

I would like to add an option to put the `>` on the next line, like
this:

```c++
template <
    typename Foo,
    typename Bar
>
void foo() {
```

An example of a large project that uses this style is NVIDIA's CUTLASS,
here is an example:


https://github.com/NVIDIA/cutlass/blob/main/include/cutlass/epilogue/dispatch_policy.hpp#L149-L156

My reasoning is that it reminds me of this style of braces:

```c++
if (foo()) {
    bar();
    baz();}
```

Most people agree this is better:

```c++
if (foo()) {
    bar();
    baz();
}
```

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-02-06 01:15:47 -08:00
Owen Pan
eb6ca1242c
[clang-format] Hanlde qualified type name for QualifierAlignment (#125327)
Fixes #125178.
2025-02-04 01:33:44 -08:00
Owen Pan
6980d97946
[clang-format] Fix a bug in annotating ClassHeadName (#125326) 2025-02-01 20:20:43 -08:00
Gedare Bloom
b8734797a3
[clang-format] Fix mismatched break in BlockIndent (#124998)
Near the ColumnLimit a break could be inserted before a right parens
with BlockIndent without a break after the matching left parens. Avoid
these hanging right parens by disallowing breaks before right parens
unless there was a break after the left parens.

Fixes #103306
2025-01-30 19:38:43 -08:00
Owen Pan
1a25bea852
[clang-format] Add ClassHeadName to help annotating StartOfName (#124891)
Fixes #124574.
2025-01-30 19:33:15 -08:00
Owen Pan
ea84474966
[clang-format] Fix annotation of Java/JavaScript keyword extends (#125038)
Uncovered in #124891.
2025-01-30 18:03:42 -08:00
Owen Pan
14178deab0
[clang-format] Fix a crash on parsing requires clause (#125021)
Fixes #124921.
2025-01-30 18:03:04 -08:00
Owen Pan
4fb8078887
[clang-format] Fix annotation of class name after requires clause (#125019)
Uncovered in #124891.
2025-01-30 18:02:40 -08:00
Owen Pan
b28e879a83
[clang-format] Simplify ConfigParseTest for int/unsigned options (#124704)
Also add a number of missing tests for unsigned options.
2025-01-28 21:04:41 -08:00
Gedare Bloom
d50ebd47ae
[clang-format] Add style option PenaltyBreakBeforeMemberAccess (#118409)
The penalty for breaking before a member access is hard-coded to 150.
Add a configuration option to allow setting it.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-01-27 21:40:17 -08:00
Owen Pan
1e89355dad
[clang-format] Treat f<N | M>(a) as template function call (#124438)
Fixes #123144.
2025-01-27 09:28:29 -08:00
Owen Pan
9452ee4f75
[clang-format] Treat uppercase identifiers after struct as macros (#124397)
This restores the behavior before llvmorg-20-init.

Fixes #94184.
Fixes #117477.
Fixes #122690.
Fixes #123142.
2025-01-27 00:11:18 -08:00
Owen Pan
c1ec5beb4a
[clang-format] Fix a TableGen crash on comment after l_paren (#124380)
Fixes #124248.
2025-01-25 18:31:42 -08:00
Owen Pan
8e31050bc2
[clang-format] Fix a bug in annotating overloaded co_await decl (#124240)
Fixes #124223.
2025-01-24 17:57:04 -08:00
Owen Pan
6330f1e052
[clang-format] Fix a regression in PointerAlignment: Left (#124085)
Don't insert a space between a type declaration r_paren and &/&&.

Fixes #124073.
2025-01-23 21:44:29 -08:00
Owen Pan
3bd8b02aa0
[clang-format] Handle leading C++11 attribute in QualifierAlignment (#123690)
Fixes #123573.
2025-01-21 21:22:13 -08:00
Sirraide
33656932b0
[clang-format] Rename ExportBlockIndentation -> IndentExportBlock (#123493)
This renames the `ExportBlockIndentation` option and adds a config parse
test, as requested in #110381.
2025-01-21 14:13:13 +01:00
Sirraide
106c483a10
[clang-format] Improve brace wrapping and add an option to control indentation of export { ... } (#110381)
`export { ... }` blocks can get a bit long, so I thought it would make
sense to have an option that makes it so their contents are not indented
(basically the same argument as for namespaces).

This is based on the `NamespaceIndentation` option, except that there is
no option to control the behaviour of `export` blocks when nested because
nesting them doesn’t really make sense.

Additionally, brace wrapping of short `export { ... }` blocks is now controlled by the
`AllowShortBlocksOnASingleLine` option. There is no separate option just for `export`
blocks because you can just write e.g. `export int x;` instead of `export { int x; }`.

This closes #121723.
2025-01-19 00:26:40 +01:00
Ander
e2402615a5
[clang-format] Fix option BreakBinaryOperations for operator >> (#122282)
Fixes #106228.
2025-01-17 19:45:10 -08:00
Owen Pan
a7bca1861b
[clang-format] Correctly annotate braces in macro definitions (#123279)
Fixes #123179.
2025-01-17 19:26:00 -08:00
sstwcw
fbef1f835f
[clang-format][NFC] Make formatting Verilog faster (#121139)
A regular expression was used in the lexing process. It made the program
take more than linear time with regards to the length of the input. It
looked like the entire buffer could be scanned for every token lexed.
Now the regular expression is replaced with code. Previously it took 20
minutes for the program to format 125 000 lines of code on my computer.
Now it takes 315 milliseconds.
2025-01-14 15:37:06 +00:00
Owen Pan
2ea34cdf2b
[clang-format] Stop fixing indentation on namespace closing brace (#122234)
Fixes #119790.
2025-01-09 19:10:15 -08:00
Owen Pan
9e4774b934
[clang-format] Add LT_RequiresExpression and LT_SimpleRequirement (#121681)
The new line types help to annotate */&/&& in simple requirements as
binary operators.

Fixes #121675.
2025-01-06 01:46:17 -08:00
Owen Pan
00934505d4
[clang-format] Add TT_CompoundRequirementLBrace for better annotation (#121539)
Also, add `ST_CompoundRequirement` to help annotating */&/&& in compound
requirement expressions as `TT_BinaryOperator`.

Fixes #121471.
2025-01-04 20:51:00 -08:00
Owen Pan
c1ea05eaf0
[clang-format] Don't break short macro call followed by l_paren (#121626)
Fixes #105658.
2025-01-04 16:24:41 -08:00
Owen Pan
44b83e81b5
[clang-format] Add TT_AfterPPDirective for better annotation (#121622)
For now, we only need to annotate the token after #error or #warning.

Fixes #117706.
2025-01-04 16:22:54 -08:00
Owen Pan
66f16e682f
[clang-format][NFC] Add missing config tests for List of Strings (#121451)
Also, simplify the existing test for NamespaceMacros. Like the options
tested by the added tests, it's also a list of arbitrary strings and
initialized to an empty list. (The other existing tests for list of
strings either are initialized to a list of one or more strings or
require specific strings.)
2025-01-04 16:14:25 -08:00
dmasloff
1c997feff1
[clang-format] Add option WrapNamespaceBodyWithNewlines (#106145)
It wraps the body of namespace with additional newlines, turning this code:
```
namespace N {
int function();
}
```
into the following:
```
namespace N {

int function();

}
```

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-01-02 21:52:01 -08:00
Owen Pan
1a0d0ae234
[clang-format] Add VariableTemplates option (#121318)
Closes #120148.
2025-01-01 18:24:56 -08:00
Owen Pan
cd239493c1
[clang-format] Support globstar in .clang-format-ignore (#121404)
Closes #110160.
Closes #114969.
2025-01-01 15:37:59 -08:00
Galen Elias
486ec4bd74
[clang-format] Add AllowShortNamespacesOnASingleLine option (#105597)
This fixes #101363 which is a resurrection of a previously opened but
never completed review: https://reviews.llvm.org/D11851

The feature is to allow code like the following not to be broken across
multiple lines:

```
namespace foo { class bar; }
namespace foo { namespace bar { class baz; } }
```

Code like this is commonly used for forward declarations, which are
ideally kept compact. This is also apparently the format that
include-what-you-use will insert for forward declarations.

Also, fix an off-by-one error in `CompactNamespaces` code. For nested
namespaces with 3 or more namespaces, it was incorrectly compacting
lines which were 1 or two spaces over the `ColumnLimit`, leading to
incorrect formatting results.
2024-12-30 01:28:03 -08:00
Owen Pan
141c544c03
[clang-format] Skip line splices when sorting C++ includes (#120680)
Fixes #109864.
2024-12-24 21:47:53 -08:00
天音あめ
cac6777ca1
[clang-format] Fix crashes when the macro expansion is empty (#119428)
An empty expansion should be valid, like `echo 'A()' | clang-format
--style='{Macros: [A(x)=x]}'`.

Fixes #119258.
2024-12-21 22:21:27 -08:00
Owen Pan
40acaa394f
[clang-format] Fix a crash in QualifierAlignment: Right (#120821)
Fixes #120793.
2024-12-21 17:16:29 -08:00
Owen Pan
fe2685303b [clang-format] Fix a crash caused by commit f03bf8c45f43 2024-12-18 19:41:50 -08:00