1366 Commits

Author SHA1 Message Date
Owen Pan
df232d46f5
[clang-format] Don't re-annotate CaseLabelColon as ConditionalExpr (#114639)
Fixes #114627.
2024-11-02 14:42:41 -07:00
Owen Pan
d989c2410e
[clang-format] Add RemoveEmptyLinesInUnwrappedLines option (#112325)
Fixes #111340.
2024-10-17 20:21:42 -07:00
Owen Pan
ee6468494e Revert "[clang-format] Correctly annotate */& in if condition with braced init (#109505)"
This reverts commit 98281da29f7e36e22ff1e20b9cfefda8c31dbe56 which caused a
regression.

Fixes #112176.
2024-10-14 19:29:44 -07:00
sstwcw
253ff32724
[clang-format] Stop crashing when formatting Verilog (#112043)
The part of the code for parsing Verilog module instantiations
dereferenced a pointer without checking for null pointer. The pointer
may be null if the input is not complete and a line starts with a comma.
2024-10-14 13:57:35 +00:00
Owen Pan
1809d0fa1c
[clang-format] Insert a space between l_paren and ref-qualifier (#111465)
Fixes #111346.
2024-10-08 21:24:17 -07:00
Owen Pan
4b6e41b61e
[clang-format] Don't insert spaces after keywords in protobuf field o… (#111229)
…ptions

Fixes #54848.
2024-10-07 19:10:24 -07:00
Owen Pan
b5f6689dc9
[clang-format] Annotate ::operator as FunctionDeclarationName (#111115)
Fixes #111011.
2024-10-04 18:20:21 -07:00
Owen Pan
eaff3a7434
[clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)
Fixes #110879.
2024-10-03 18:57:50 -07:00
Owen Pan
14e1fef736
[clang-format] Handle template closer followed by empty paretheses (#110408)
Fixes #109925.
2024-10-02 19:06:56 -07:00
Owen Pan
688bc958bd
[clang-format] Add TemplateNames option to help parse C++ angles (#109916)
Closes #109912.
2024-10-02 18:10:56 -07:00
Owen Pan
98281da29f
[clang-format] Correctly annotate */& in if condition with braced init (#109505)
Fixes #109371.
2024-10-02 18:07:57 -07:00
Owen Pan
6ae14c0505
[clang-format] Annotate the l_paren of function pointer types (#109229)
Fixes #109146.
2024-10-02 18:01:25 -07:00
Owen Pan
c28e268c32
[clang-format] Correctly annotate pointer/reference in if statement (#109370)
Fixes #60146.
2024-09-20 18:13:21 -07:00
Owen Pan
4fd14b9a3a
[clang-format] Correctly annotate pointer/reference in range-for loop (#109361)
Fixes #109358.
2024-09-20 18:12:09 -07:00
Owen Pan
4d18ce1dd2
[clang-format] Handle C-style cast of qualified type (#108929)
Fixes #102874.
2024-09-17 21:19:56 -07:00
Owen Pan
a8dd8f6302
[clang-format] Fix a bug in SpacesInParens InConditionalStatements (#108797)
Fixes #64416.
2024-09-17 21:17:30 -07:00
Owen Pan
7153a4bbf6
[clang-format] Reimplement InsertNewlineAtEOF (#108513)
Fixes #108333.
2024-09-17 21:16:20 -07:00
Owen Pan
bcd586b5ab
[clang-format] Fix a bug in annotating CastRParen (#107675)
Fixes #107568.
2024-09-07 16:56:28 -07:00
Owen Pan
812c96e8b9
[clang-format] Handle pointer/reference in macro definitions (#107074)
A macro definition needs its own scope stack in the annotator, so we add
the MacroBodyScopes stack and use ScopeStack to refer to it when in the
macro definition body.

Also, we need to have a scope type for a child block because its parent
line is parsed (and thus the scope type for the braces is popped off the
scope stack) before the lines in the child block are.

Fixes #99271.
2024-09-03 19:11:12 -07:00
Owen Pan
a27ff17034
[clang-format] Fix a regression in annotating ObjCBlockLParen (#107021)
Fixes #106994.
2024-09-03 19:07:14 -07:00
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
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
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
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
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
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
Kazu Hirata
7a6acd9844
[clang] Use llvm::is_contained (NFC) (#102720) 2024-08-09 22:39:19 -07:00
Owen Pan
8c7a038f90
[clang-format] Fix a bug in annotating CastRParen (#102261)
Fixes #102102.
2024-08-07 21:05:42 -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
b2ac7f52fa
[clang-format][NFC] Annotate function/ctor/dtor declaration l_paren (#97938) 2024-07-10 00:10:24 -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
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
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
749876e8e5
[clang-format[NFC] Clean up AnnotatingParser::rParenEndsCast() (#96128) 2024-06-20 18:59:23 -07:00
Owen Pan
3c6a1090b2
[clang-format][NFC] Add FormatToken::isAccessSpecifierKeyword() (#95727) 2024-06-17 18:45:01 -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
a106131a34
[clang-format] Handle AttributeMacro before access modifiers (#95634)
Closes #95094.
2024-06-16 13:50:59 -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