3749 Commits

Author SHA1 Message Date
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
f2b17d2582
[clang-format][NFC] Add CMake target clang-format-check-format (#95873)
Adapted from polly-check-format.
2024-06-21 09:06:26 -07:00
Owen Pan
749876e8e5
[clang-format[NFC] Clean up AnnotatingParser::rParenEndsCast() (#96128) 2024-06-20 18:59:23 -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
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
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
Owen Pan
80303cb287
[clang-format] Handle attributes before lambda return arrow (#94119)
Fixes #92657.
2024-06-02 12:26:10 -07:00
Owen Pan
c5fdb5c34e
[clang-format] Insert a space between a keyword and a literal (#93632)
Fixes #93603.
2024-05-30 22:13:00 -07:00
Owen Pan
3db1f3110e
[clang-format] Fix a regression in annotating class decl braces (#93657)
Fixes #93604.
2024-05-29 21:05:32 -07:00
Owen Pan
dba2aa265c
[clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (#93402)
Closes #92999.
2024-05-27 15:20:58 -07:00
Owen Pan
a6d97dec89
[clang-format] Correctly annotate C++ alternative operators in C (#92880)
PR #90161 uncovered a bug that annotates C++ xor as UnaryOperator if
followed by a binary operator. This patch fixes that and all other C++
alternative operator keywords when followed by a binary operator in C.

Fixes #92688.
2024-05-21 19:16:39 -07:00
Owen Pan
d89f20058b
[clang-format] Fix a bug in formatting goto labels in macros (#92494)
Fixes #92300.
2024-05-21 01:35:31 -07:00
Owen Pan
1c58208d89 [clang-format][NFC] Remove redundnat llvm::, clang::, etc. 2024-05-20 20:32:18 -07:00
Owen Pan
88d351e2e6
[clang-format] Fix a regression in annotating struct braces (#92352)
Fixes #92350.
2024-05-16 19:24:35 -07:00
Owen Pan
8fe39e64c0
[clang-format] Don't always break before << between string literals (#92214)
Instead, leave the line wrapping as is.

Fixes #43887.
Fixes #44363.
2024-05-16 19:23:47 -07:00
Owen Pan
b11a6607cb [clang-format][NFC] Reformat with 18.1.5 2024-05-15 21:04:46 -07:00
Owen Pan
72b2c37de6 [clang-format][NFC] Clean up TokenAnnotator::mustBreakBefore() 2024-05-14 20:31:53 -07:00
Owen Pan
364f988d3f Reland "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"
Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-13 21:54:23 -07:00
Owen Pan
c72e94382c
[clang-format][NFC] Move LeftRightQualifierAlignmentFixer::is...() (#91930)
Move static member functions LeftRightQualifierAlignmentFixer::is...()
out of the class so that #91712 can reland.
2024-05-13 19:19:15 -07:00
Owen Pan
1fadb2b0c8 Revert "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"
This reverts commits e62ce1f8842c, 5cd280433e8e, and de641e289269 due to
buildbot failures.
2024-05-12 23:15:35 -07:00
Owen Pan
626025ac77 Revert "[clang-format] Fix buildbot failures"
This reverts commit 0869204cff22831d0bb19a82c99bf85e4deb4ae3, which caused a
buildbot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/43322
2024-05-12 18:35:35 -07:00
Owen Pan
0869204cff [clang-format] Fix buildbot failures
This effectively reverts 5cd280433e8e and changes to QualifierFixerTest.cpp
from e62ce1f8842c.

Failed buidbots:
https://lab.llvm.org/buildbot/#/builders/236/builds/11223
https://lab.llvm.org/buildbot/#/builders/239/builds/6968
2024-05-11 15:23:35 -07:00