3239 Commits

Author SHA1 Message Date
Owen Pan
438ad9f2bf
[clang-format] Revert "[clang-format][NFC] Delete TT_LambdaArrow (#70… (#105923)
…519)"

This reverts commit e00d32afb9d33a1eca48e2b041c9688436706c5b and adds a
test for lambda arrow SplitPenalty.

Fixes #105480.
2024-08-28 18:23:54 -07:00
Krasimir Georgiev
77d63cfd18
[clang-format] js handle anonymous classes (#106242)
Addresses a regression in JavaScript when formatting anonymous classes.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-08-28 13:45:17 +02:00
Owen Pan
fac7e87d66
[clang-format] Insert a space between new/delete and a C-style cast (#106175)
It doesn't make sense to remove the space between new/delete and a
C-style cast when SpaceBeforeParensOptions.AfterPlacementOperator is set
to false.

Fixes #105628.
2024-08-27 19:14:16 -07:00
Owen Pan
656d5aa958
[clang-format] Fix misalignments of pointers in angle brackets (#106013)
Fixes #105898.
2024-08-27 19:13:27 -07:00
Owen Pan
0916ae49b8
[clang-format] Fix a misannotation of less/greater as angle brackets (#105941)
Fixes #105877.
2024-08-24 20:10:03 -07:00
Owen Pan
6bc225e063
[clang-format] Fix a misannotation of redundant r_paren as CastRParen (#105921)
Fixes #105880.
2024-08-24 19:12:15 -07:00
kadir çetinkaya
e439fdf4ea
[clang-format] Treat new expressions as simple functions (#105168)
ccae7b461be339e717d02f99ac857cf0bc7d17f improved handling for nested
calls, but this resulted in a lot of changes near `new` expressions.

This patch tries to restore previous behavior around new expressions, by
treating them as simple functions, which seem to align with the concept.

Fixes https://github.com/llvm/llvm-project/issues/105133.
2024-08-24 03:04:30 +02:00
Tom
7c3237d778
[clang-format] Change BinPackParameters to enum and add AlwaysOnePerLine (#101882)
Related issues that have requested this feature:
#51833
#23796 
#53190 Partially solves - this issue requests is for both arguments and
parameters
2024-08-22 21:42:22 -07:00
Owen Pan
714033a6bf
[clang-format] Don't insert a space between :: and * (#105043)
Also, don't insert a space after ::* for method pointers.

See
https://github.com/llvm/llvm-project/pull/86253#issuecomment-2298404887.

Fixes #100841.
2024-08-22 20:02:48 -07:00
Owen Pan
3496245ed3
[clang-format] Change GNU style language standard to LS_Latest (#104669)
Fixes #104655.
2024-08-18 12:02:15 -07:00
Nathan Sidwell
4cf9a42661
[clang-format] Adjust requires clause wrapping (#101550) (#102078)
Address #101550 by adding OwnLineWithBrace option for RequiresClausePosition. This permits placing a following '{' on the same line as the requires clause.

Thus, instead of:
```
bool Foo ()
  requires(true)
{
  return true;
}
```

we have:
```
bool Foo ()
  requires(true) {
  return true;
}
```

If the function body is empty, we'll get:
```
bool Foo ()
  requires(true) {}
```

I attempted to get a line break between the open and close braces, but
failed. Perhaps that's fine -- it's rare and only happens in the empty
body case.
2024-08-16 21:05:08 -04:00
Owen Pan
ee2359968f
[clang-format] Fix annotation of braces enclosing stringification (#102998)
Fixes #102937.
2024-08-13 12:39:33 -07:00
Owen Pan
d990cc4568
[clang-format] Correctly handle C# attribute on auto property (#102921)
Fixes #101487.
2024-08-12 18:27:32 -07:00
Ameer J
c5a4291fb7
[clang-format] Add BreakBinaryOperations configuration (#95013)
By default, clang-format packs binary operations, but it may be
desirable to have compound operations be on individual lines instead of
being packed.

This PR adds the option `BreakBinaryOperations` to break up large
compound binary operations to be on one line each.

This applies to all logical and arithmetic/bitwise binary operations

Maybe partially addresses #79487 ?
Closes #58014 
Closes #57280
2024-08-10 13:28:33 -07:00
Owen Pan
8c7a038f90
[clang-format] Fix a bug in annotating CastRParen (#102261)
Fixes #102102.
2024-08-07 21:05:42 -07:00
Kazu Hirata
1fa7f05b70
[clang] Construct SmallVector with ArrayRef (NFC) (#101898) 2024-08-04 23:46:34 -07:00
Owen Pan
9fa17fea3c
[clang-format] Handle parenthesized list in RemoveParentheses (#100852)
Also, reformat clang-format source to remove redundant parentheses
enclosing single list items.

Fixes #100768.
2024-08-02 01:29:05 -07:00
Owen Pan
8abdf7cc71
[clang-format] Fix a misannotation of PointerOrReference (#101291)
Fixes #101138.
2024-08-01 21:55:43 -07:00
Owen Pan
73c961a334
[clang-format] Fix misannotations of < in ternary expressions (#100980)
Fixes #100300.
2024-07-29 18:01:44 -07:00
Gedare Bloom
ccae7b461b
[clang-format] Improve BlockIndent at ColumnLimit (#93140)
Fixes #55731

The reported formatting problems were related to ignoring deep nesting
of "simple" functions (causing #54808) and to allowing the trailing
annotation to become separated from the closing parens, which allowed a
break to occur between the closing parens and the trailing annotation.
The fix for the nesting of "simple" functions is to detect them more
carefully. "Simple" was defined in a comment as being a single
non-expression argument. I tried to stay as close to the original intent
of the implementation while fixing the various bad formatting reports.

In the process of fixing these bugs, some latent bugs were discovered
related to how JavaScript Template Strings are handled. Those are also
fixed here.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-07-24 19:47:11 -07:00
Owen Pan
7e7a9069d4 Revert "[clang-format] Fix a bug in annotating * in #defines (#99433)"
This reverts commit ce1a87437cc143889665c41046107e84cdf6246e.

Closes #100304.
2024-07-24 19:33:44 -07:00
Owen Pan
0387cd052b
[clang-format] Fix a bug in annotating FunctionAnnotationRParen (#99802)
Fixes #37906.
2024-07-21 14:54:50 -07:00
Owen Pan
dcebe29736
[clang-format] Fix a bug in annotating StartOfName (#99791)
Fixes #99758.
2024-07-21 13:14:18 -07:00
Owen Pan
ce1a87437c
[clang-format] Fix a bug in annotating * in #defines (#99433)
Fixes #99271.
2024-07-20 12:22:50 -07:00
Owen Pan
5bb3492892
[clang-format] Fix a bug in SpaceBeforeParensOptions (#98849)
Handle constructors/destructors for AfterFunctionDeclarationName and
AfterFunctionDefinitionName.

Fixes #98812.
Fixes #98820.
2024-07-15 19:17:36 -07:00
Owen Pan
dcf6b7a8ea
[clang-format] Fix a bug in TCAS_Leave using tabs for indentation (#98427)
Fixes #92530.
2024-07-11 19:36:42 -07:00
Owen Pan
b2ac7f52fa
[clang-format][NFC] Annotate function/ctor/dtor declaration l_paren (#97938) 2024-07-10 00:10:24 -07:00
Owen Pan
ceade83ad5
[clang-format] Skip block commented out includes when sorting them (#97787)
Fixes #97539.
2024-07-05 15:28:16 -07:00
Gedare Bloom
54f040fff3
[clang-format] Add SpacesInParensOption for filtering repeated parens (#77522)
The __attribute((specifier-list)) currently is formatted based on the
SpacesInParensOptions.Other (previously, SpacesInParentheses). This
change allows finer control over addition of spaces between the
consecutive parens, and between the inner parens and the list of
attribute specifiers.

Differential Revision: https://reviews.llvm.org/D155529

This is migrated from Phabricator, see more discussion there.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-07-02 00:00:14 -07:00
sstwcw
2853a838d2 [clang-format] Add option to remove leading blank lines (#91221)
The options regarding which blank lines are kept are also aggregated.
The new option is `KeepEmptyLines`.

This patch was initially part of 9267f8f19a2e502e.  I neglected to check
the server builds before I added it.  It broke clangd.  Jie Fu fixed the
problem in 4c91b49bab0728d4.  I was unaware of it.  I thought the main
branch was still broken.  I reverted the first patch in
70cfece24d6cbb57.  It broke his fix.  He reverted it in
c69ea04fb9738db2.  Now the feature is added again including the fix.
2024-06-30 01:20:20 +00:00
Emilia Kond
834ac2e205
[clang-format] Allow ternary in all templates (#96801)
Currently, question mark and colon tokens are not allowed between angle
brackets, as a template argument, if we are in an expression context.

However, expressions can still allowed in non-expression contexts,
leading to inconsistent formatting.

Removing this check entirely fixes this issue, and, surprisingly, breaks
no tests.

Fixes https://github.com/llvm/llvm-project/issues/81385
2024-06-29 14:39:34 +03:00
sstwcw
70cfece24d Revert "[clang-format] Add option to remove leading blank lines (#91221)"
This reverts commit 9267f8f19a2e502ef5a216c0d52b352b3699d399.

I changed a formatter option.  I forgot to update other components that
depend on the formatter when the option name changed.
2024-06-25 13:12:32 +00:00
sstwcw
9267f8f19a [clang-format] Add option to remove leading blank lines (#91221)
The options regarding which blank lines are kept are also aggregated.
The new option is `KeepEmptyLines`.
2024-06-25 03:50:11 +00:00
Emilia Kond
6621505a1e
[clang-format] Don't count template template parameter as declaration (#96396)
Reapply 4a7bf42a9b83144db8a11ac06cce4da21166e6a2
which was reverted in 34d44eb41dfbbbf01712719558b02763334fbeb3

Not sure why there are tests elsewhere in clang that rely on the output
of clang-format, but they were wrong
2024-06-22 21:16:51 +03:00
Mehdi Amini
34d44eb41d
Revert "[clang-format] Don't count template template parameter as declaration" (#96388)
Reverts llvm/llvm-project#95025 ; many bots are broken
2024-06-22 14:18:59 +02:00
Emilia Kond
4a7bf42a9b
[clang-format] Don't count template template parameter as declaration (#95025)
In ContinuationIndenter::mustBreak, a break is required between a
template declaration and the function/class declaration it applies to,
if the template declaration spans multiple lines.

However, this also includes template template parameters, which can
cause extra erroneous line breaks in some declarations.

This patch makes template template parameters not be counted as template
declarations.

Fixes https://github.com/llvm/llvm-project/issues/93793
Fixes https://github.com/llvm/llvm-project/issues/48746
2024-06-22 12:51:36 +03:00
Owen Pan
d69050d614
[clang-format] Annotate r_paren before braced list as TT_CastRParen (#96271)
Fixes #96096.
2024-06-21 20:23:18 -07:00
Owen Pan
fa00e8bb6a
[clang-format] Correctly annotate l_brace after TypenameMacro (#96026)
Closes #95418.
2024-06-19 17:49:35 -07:00
Owen Pan
61571e9046
[clang-format] Handle function try block with ctor-initializer (#95878)
Fixes #58987.
Fixes #95679.
2024-06-18 18:56:33 -07:00
sstwcw
ef18986b20 [clang-format] Handle Verilog delay control (#95703)
I made a mistake when I tried to make the code handle the backtick
character like the hash character.  The code did not recognize the delay
control structure.  It caused net names in the declaration to be aligned
to the type name instead of the first net name.

new

```Verilog
wire logic #0 mynet, //
              mynet1;
```

old

```Verilog
wire logic #0 mynet, //
     mynet1;
```
2024-06-17 01:46:04 +00:00
Owen Pan
527e732860 [clang-format][NFC] Suppress diagnostic noise in GetStyleOfFile test 2024-06-16 14:56:02 -07:00
pointhex
fe9aef05c2
[clang-format] Add DiagHandler parameter to format::getStyle() (#91317)
It allows to control of error output for the function.

Closes #94205.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-06-16 13:58:26 -07:00
Owen Pan
a106131a34
[clang-format] Handle AttributeMacro before access modifiers (#95634)
Closes #95094.
2024-06-16 13:50:59 -07:00
Owen Pan
cddb9ce04e
[clang-format] Don't over-indent comment below unbraced body (#95354)
Fixes #45002.
2024-06-14 20:49:13 -07:00
Owen Pan
82e19318e6
[clang-format] Fix a bug in annotating lambda l_square (#95084)
Fixes #95072.
2024-06-12 00:56:48 -07:00
c8ef
d9593c1edd
[clang-format] Fix a bug in indenting lambda trailing arrows (#94560)
Closes #94181
2024-06-10 09:10:30 -07:00
Gedare Bloom
a10135f492
[clang-format]: Annotate colons found in inline assembly (#92617)
Short-circuit the parsing of tok::colon to label colons found within
lines starting with asm as InlineASMColon.

Fixes #92616.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-06-06 18:38:21 -07:00
Owen Pan
5e0fc93d01
[clang-format] Fix a bug in AlignAfterOpenBracket: DontAlign (#94561)
Fixes #94555.
2024-06-06 17:25:46 -07:00
Owen Pan
798f2019a2
[clang-format] Don't format comments in SkipMacroDefinitionBody (#94425)
Fixes #94326.
2024-06-05 17:57:36 -07:00
Owen Pan
13f6797826
[clang-format] Handle AttributeMacros in parseRecord() (#94189)
Fixes #94184.
2024-06-03 12:55:10 -07:00