196 Commits

Author SHA1 Message Date
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
b2ac7f52fa
[clang-format][NFC] Annotate function/ctor/dtor declaration l_paren (#97938) 2024-07-10 00:10:24 -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
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
82e19318e6
[clang-format] Fix a bug in annotating lambda l_square (#95084)
Fixes #95072.
2024-06-12 00:56:48 -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
13f6797826
[clang-format] Handle AttributeMacros in parseRecord() (#94189)
Fixes #94184.
2024-06-03 12:55:10 -07:00
Owen Pan
f06f016419 [clang-format][NFC] Add missing parens of __attribute in unit tests 2024-06-02 12:44:40 -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
3db1f3110e
[clang-format] Fix a regression in annotating class decl braces (#93657)
Fixes #93604.
2024-05-29 21:05:32 -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
236b3e1aad
[clang-format] Handle Java switch expressions (#91112)
Also adds AllowShortCaseExpressionOnASingleLine option and
AlignCaseArrows suboption of AlignConsecutiveShortCaseStatements.

Fixes #55903.
2024-05-06 19:55:55 -07:00
Emilia Kond
c609043dd0
[clang-format] Don't allow comma in front of structural enum (#91056)
Assume that a comma in front of `enum` means it is actually a part of an
elaborated type in a template parameter list.

Fixes https://github.com/llvm/llvm-project/issues/47782
2024-05-06 06:44:13 +03:00
Owen Pan
8e9b1e9aa8
[clang-format] Fix a bug in annotating struct braces (#90555)
Fixes #60040.
2024-04-30 20:01:34 -07:00
Owen Pan
4b10ade1a6
[clang-format] Annotate enum braces as BK_Block (#89871)
Fixes #89759.
2024-04-24 21:46:45 -07:00
Owen Pan
469c8a0a4e
[clang-format] Correctly annotate list init braces of class types (#89706)
Fixes #71939.
2024-04-23 21:27:27 -07:00
Owen Pan
c455b462da
[clang-format] Fix a bug in annotating CastRParen before unary && (#89346)
Also fix a bug in annotating TrailingAnnotation.

Closes #61233.
2024-04-19 20:21:43 -07:00
Owen Pan
b6cc667190
[clang-format] Annotate ampamp after new/delete as BinaryOperator (#89033)
Fixes #78789.
2024-04-17 19:53:24 -07:00
Owen Pan
29ecd6d50f
[clang-format] Revert breaking stream operators to previous default (#89016)
Reverts commit d68826dfbd98, which changes the previous default behavior
of always breaking before a stream insertion operator `<<` if both
operands are string literals.

Also reverts the related commits 27f547968cce and bf05be5b87fc.

See the discussion in #88483.
2024-04-17 19:51:46 -07:00
Owen Pan
51f1681424
[clang-format] Don't merge a short block for SBS_Never (#88238)
Also fix unit tests.

Fixes #87484.
2024-04-10 19:06:29 -07:00
Owen Pan
bcf849b1e5
[clang-format] instanceof is a keyword only in Java/JavaScript (#88085)
Fixes #87907.
2024-04-09 20:00:03 -07:00
Owen Pan
58323de2e5
[clang-format] Correctly annotate braces in macros (#87953)
Also fix unit tests and reformat polly.

Fixes #86550.
2024-04-09 19:59:36 -07:00
Owen Pan
7c9c38eaa9
[clang-format] Fix a regression in annotating BK_BracedInit (#87450)
Fixes #86539.
2024-04-04 17:55:18 -07:00
Owen Pan
a7f4576ff4
[clang-format] Fix a regression in annotating TrailingReturnArrow (#86624)
Fixes #86559.
2024-04-02 14:48:14 -07:00
Hirofumi Nakamura
e54af60816
[clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (#86150)
The option to specify the style of alignment of the colons inside TableGen's DAGArg.
2024-03-22 23:11:36 +09:00
Owen Pan
6f31cf51df Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)"
This reverts c3a1eb6207d8 (and the related commit f3c5278efa3b) which makes
cleanupAroundReplacements() no longer thread-safe.
2024-03-19 18:06:59 -07:00
Hirofumi Nakamura
0c423af59c
[clang-format] Add Options to break inside the TableGen DAGArg. (#83149)
Add two options to control the line break inside TableGen DAGArg.
- TableGenBreakInsideDAGArg
- TableGenBreakingDAGArgOperators
2024-03-19 00:13:59 +09:00
Owen Pan
7c460c6205
[clang-format] Fix a bug in annotating FunctionDeclarationName (#85361)
A name is not a FunctionDeclarationName if it's preceded by an
Objective-C keyword.

Fixes #84578.
2024-03-15 19:25:41 -07:00
Owen Pan
c3a1eb6207 Reland [clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)
Initialize IsCpp in LeftRightQualifierAlignmentFixer ctor.
2024-03-14 19:44:40 -07:00
Mehdi Amini
b0d1e32ca2
Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions" (#85353)
Reverts llvm/llvm-project#84599

This broke the presubmit bot.
2024-03-14 19:33:11 -07:00
Owen Pan
0c07102927
[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599) 2024-03-14 18:56:24 -07:00
Owen Pan
0baef3b18c
[clang-format] Handle common C++ non-keyword types as such (#83709)
Fixes #83400.
2024-03-08 19:42:35 -08:00
Owen Pan
8de230093f
[clang-format] Correctly annotate braces of empty ctors/dtors (#82097)
Also reformat Polly.

Fixes #79834.
2024-02-19 12:41:22 -08:00
Hirofumi Nakamura
6a471611a4
[clang-format] Support of TableGen value annotations. (#80299)
This implements the annotation of the values in TableGen.
The main changes are,

- parseTableGenValue(), the simplified parser method for the syntax of
values.
- modified consumeToken() to parseTableGenValue in 'if', 'assert' and
after '='.
- modified parseParens() to call parseTableGenValue inside.
- modified parseSquare() to to call parseTableGenValue inside, with
skipping separator tokens.
- modified parseAngle() to call parseTableGenValue inside, with skipping
separator tokens.
2024-02-12 23:27:09 +09:00
XDeme
7e7f118404
[clang-format] Handles Elaborated type specifier for enum in trailing return (#80085)
Fixes llvm/llvm-project#80062
2024-02-01 14:11:14 -03:00
Emilia Kond
9b68c095d6
[clang-format] Allow decltype in requires clause (#78847)
If clang-format is not sure whether a `requires` keyword starts a
requires clause or a requires expression, it looks ahead to see if any
token disqualifies it from being a requires clause. Among these tokens
was `decltype`, since it fell through the switch.

This patch allows decltype to exist in a require clause.

I'm not 100% sure this change won't have repercussions, but that just
means we need more test coverage!

Fixes https://github.com/llvm/llvm-project/issues/78645
2024-02-01 08:00:45 +02:00