1281 Commits

Author SHA1 Message Date
Hirofumi Nakamura
8c1c94e8c1
[clang-format] Support of TableGen basic format restrictions. (#81611)
- Allow/force to break the line or not.
- Allow/force to insert space or not.
2024-02-16 21:35:45 +09:00
rmarker
d821650e13
[clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (#81591)
Complete the switch from "AlwaysBreakAfterReturnType" to
"BreakAfterReturnType".
2024-02-14 20:10:56 -08:00
Owen Pan
eafe98f937
[clang-format] Always add a space after #if and #elif (#81578)
Fixes #81569.
2024-02-13 22:35:52 -08:00
Haojian Wu
c9afeaa643 [format] Remove an unused variable. 2024-02-12 16:19:42 +01: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
Owen Pan
7664ddf881 [clang-format][NFC] Drop "Always" in "AlwaysBreakTemplateDeclarations" 2024-02-09 20:18:24 -08:00
Owen Pan
d033799050
[clang-format] Add Leave to AlwaysBreakTemplateDeclarations (#80569)
Closes #78067.
2024-02-07 20:24:44 -08:00
rmarker
2562007321
[clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (#78011)
The RTBS_None option in Clang-format avoids breaking after a short
return type.
However, there was an issue with the behaviour in that it wouldn't take
the leading indentation of the line into account.
This meant that the behaviour wasn't applying when intended.

In order to address this situation without breaking the existing
formatting, RTBS_None has been deprecated.
In its place are two new options for AlwaysBreakAfterReturnType.
The option RTBS_Automatic will break after the return type based on
PenaltyReturnTypeOnItsOwnLine.
The option RTBS_ExceptShortType will take the leading indentation into
account and prevent breaking after short return types.

This allows the inconsistent behaviour of RTBS_None to be avoided and
users to decide whether they want to allow breaking after short return
types or not.

Resolves #78010
2024-02-04 12:26:32 -08:00
Owen Pan
908fd09a13
[clang-format] Simplify the AfterPlacementOperator option (#79796)
Change AfterPlacementOperator to a boolean and deprecate SBPO_Never,
which meant never inserting a space except when after new/delete.

Fixes #78892.
2024-01-31 20:20:26 -08:00
Owen Pan
f826f55b2a
[clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (#79549)
Fixes #78965.
2024-01-26 18:32:03 -08:00
Ilya Biryukov
5723fce088
[Format] Fix isStartOfName to recognize attributes (#76804)
This addresses a problem with formatting attributes. Some context:
- eaff083035c8 changed `isStartOfName` to fix problems inside
`#pragma`s, but this behavior changed formatting of attribute macros in
an undesirable way.
- efeb546865c233dfa7706ee0316c676de9f69897 changed Google format style
to fix some widely used attributes.

Instead of changing the format style, this commit specializes behavior
introduced in eaff083035c8 to `#pragma`s. This seems to work well in
both cases.

Also update the test with two `GUARDED_BY` directives. While the
formatting after efeb546865c233dfa7706ee0316c676de9f69897 seems better,
this case is rare enough to not warrant the extra complexity. We are
reverting it back to the state it had before
efeb546865c233dfa7706ee0316c676de9f69897.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-01-15 14:57:05 +01:00
rmarker
60a9874f54
[clang-format] Add PenaltyBreakScopeResolution option. (#78015)
Resolves #78014
2024-01-14 20:55:44 +01:00
MyDeveloperDay
c65b939fb7
[clang-format] SpacesInSquareBrackets not working for Java (#77833)
spaces in [] needs to be handled the same in Java the same as C#.

Co-authored-by: paul_hoad <paul_hoad@amat.com>
2024-01-12 08:30:53 +00:00
Emilia Kond
791637e782
[clang-format] Don't allow casts in front of ampamp (#77704)
clang-format performs a heuristic to see if a right parenthesis is the
parenthesis of a cast expression. This check never looked ahead to see
if the next token is an ampamp && token. This resulted in the paren
being set as an CastRParen, and the following ampamp got annotated as an
UnaryOperator!

Since && can never be a unary operator is standard C++, this patch
forbids the right paren from ever becoming a cast.

Fixes https://github.com/llvm/llvm-project/issues/77680
2024-01-12 03:47:37 +02:00
Hirofumi Nakamura
0cc31579e0
[clang-format] TableGen keywords support. (#77477)
Add TableGen keywords to the additional keyword list of the formatter.

This pull request is the splited part from
https://github.com/llvm/llvm-project/pull/76059 .
2024-01-11 20:07:49 +01:00
r4nt
b7770befee
[ClangFormat] Fix formatting bugs. (#76245)
1. There are multiple calls to addFakeParenthesis; move the guard to not
   assign fake parenthesis into the function to make sure we cover all
   calls.
2. MustBreakBefore can be set on a token in two cases: either during
   unwrapped line parsing, or later, during token annotation. We must
   keep the latter, but reset the former.
3. Added a test to document that the intended behavior of preferring not
   to break between a return type and a function identifier.
   For example, with MOCK_METHOD(r, n, a)=r n a, the code
   MOCK_METHOD(void, f, (int a, int b)) should prefer the same breaks as
   the expanded void f(int a, int b).
2024-01-11 13:28:45 +01:00
kadir çetinkaya
27f547968c
[clang-format] Break after string literals with trailing line breaks (#76795)
This restores a subset of functionality that was forego in
d68826dfbd987377ef6771d40c1d984f09ee3b9e.

Streaming multiple string literals is rare enough in practice, hence
that change makes sense in general. But it seems people were
incidentally relying on this for having line breaks after string
literals that ended with `\n`.

This patch tries to restore that behavior to prevent regressions in the
upcoming LLVM release, until we can implement some configuration based
approach as proposed in https://github.com/llvm/llvm-project/pull/69859.
2024-01-08 11:11:02 +01:00
Owen Pan
f8f8926054
[clang-format] Fix a bug in annotating function declaration names (#76206)
Annotates function declaration names having unnamed parameters.
2023-12-22 22:51:00 -08:00
XDeme
9512d6d213
[clang-format] Fix parsing of operator<() {} (#75144)
Fixes #74876.

During the parsing of `operator<(Foo&) {}`, there was no handling for
the operator<, so it called `consumeToken()` again, causing the
`AnnotationParser::Scopes` to have one additional left brace each time
it tried to parse it, leaving it unbalanced.
Because of this, in the following code:
```cpp
class Foo {
  void operator<(Foo&) {}
  Foo& f;
};
```
The `&` in the reference member, was being interpreted as
`TT_BinaryOperator` instead of `TT_PointerOrReference`.
2023-12-13 11:57:56 -08:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
sstwcw
b3e80d8ed2
[clang-format] Add space in Verilog tagged unions (#71354)
In a tagged union expression, there should be a space between the field
name and the data. Previously, the tag could be recognized as part of a
dotted identifier or a struct literal, and the space would be omitted.
2023-12-02 19:26:07 +00:00
Owen Pan
4c17452076
[clang-format][NFC] Extend isProto() to also cover LK_TextProto (#73582) 2023-11-29 12:52:01 -08:00
sstwcw
3af82b3962
[clang-format] Add spaces around the Verilog implication operator (#71352)
The Verilog implication operator `->` is a binary operator meaning
either the left hand side is false or the right hand side is true.
Previously it was treated as the C++ struct member operator.

I didn't even know it existed when I added the operator formatting part.
And I didn't check all the tests for all the operators I added. That is
how the bad test got in.
2023-11-29 15:17:59 +00:00
Owen Pan
39faf13dde
[clang-format] Add BreakAdjacentStringLiterals option (#73432)
Closes #70451.
2023-11-27 13:01:16 -08:00
Owen Pan
659e4017b7 [clang-format][NFC] Improve an if conditional in the annotator 2023-11-26 22:54:44 -08:00
Owen Pan
dcab84fd5e Reland [clang-format][NFC] Remove a redundant isLiteral() call 2023-11-21 04:17:03 +00:00
Gulfem Savrun Yeniceri
3e6d629ccf Revert "[clang-format][NFC] Remove a redundant isLiteral() call"
This reverts commit f6033699646b7650123a273c043a93e5eeaac6d8.
This change is labeled as NFC, but introduces a functional change
without a test, and caused a breakage as reported in
https://reviews.llvm.org/rGf6033699646b7650123a273c043a93e5eeaac6d8.
2023-11-20 22:15:07 +00:00
Owen Pan
edad025d1e
[clang-format] Correctly annotate braces of empty functions (#72733)
Also fixed some existing test cases.

Fixed #57305.
Fixed #58251.
2023-11-19 15:10:27 -08:00
Owen Pan
cb3a605c5d
[clang-format] Fix a bug in isStartOfName() on macro definitions (#72768)
Fixed #72751.
2023-11-19 15:08:54 -08:00
Owen Pan
5860d248a7
[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
Fixed #72785.
2023-11-19 14:59:53 -08:00
Owen Pan
f603369964 [clang-format][NFC] Remove a redundant isLiteral() call 2023-11-17 18:18:49 -08:00
Owen Pan
eaff083035
[clang-format] Fix more bugs in isStartOfName() (#72336)
Fixed #72264.
2023-11-15 14:31:30 -08:00
Gedare Bloom
a852869398 [clang-format] Fix a bug in parsing function/variable names
Function and variable names are not detected when there is a
__attribute__((x)) preceding the name.

Fixes #64137.

Differential Revision: https://reviews.llvm.org/D156370
2023-11-13 19:35:28 -08:00
Owen Pan
40671bbdef
[clang-format] Handle control statements in BreakAfterAttributes (#71995)
This patch doesn't work for do-while loops.

Fixed #64474.
2023-11-12 01:08:27 -08:00
Owen Pan
199fc973ce
[clang-format] Handle variable declarations in BreakAfterAttributes (#71935)
Also fixed a bug in `isStartOfName()` and cleaned up some old test
cases.

Fixed #71563.

This is a rework of #71755.
2023-11-10 13:25:57 -08:00
Owen Pan
86ef9d3651 Revert "[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)"
This reverts commit f7bbb58690910a8320b0927525dfba19df69a910 which caused
another formatting failure in polly.
2023-11-10 02:03:35 -08:00
Owen Pan
f7bbb58690 Reland "[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)"
Also fixed another bug in isStartOfName().
2023-11-10 01:53:43 -08:00
Owen Pan
cc75e52016 [clang-format][NFC] Refactor isPointerOrReference 2023-11-10 01:23:05 -08:00
Owen Pan
a0710e162d Revert "[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)"
This reverts commit 5c36f4332d93c6f9bd9b01a34149a635e07a00d3 which caused a
formatting error in polly.
2023-11-09 23:34:06 -08:00
Owen Pan
5c36f4332d
[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)
Also cleaned up some old test cases.

Fixes #71563.
2023-11-09 23:01:48 -08:00
Björn Schäpers
c280bed85a
[clang-format] Fix annotating annotations after requires clause
Fixes #69325.
2023-10-31 13:10:46 +01:00
Björn Schäpers
91b9a661c2
[clang-format][NFC] Reduce indent
By using if init statement.
2023-10-29 20:55:12 +01:00
Owen Pan
e00d32afb9
[clang-format][NFC] Delete TT_LambdaArrow (#70519)
It's one type of TT_TrailingReturnArrow.
2023-10-28 12:48:00 -07:00
Owen Pan
d68826dfbd
[clang-format] Don't break between string literal operands of << (#69871)
Fixes #44363.
2023-10-24 02:42:39 -07:00
Owen Pan
853fb0a8ac
[clang-format] Don't alter SpacesRequiredBefore of finalized tokens (#69897)
Fixes #69237.
2023-10-23 13:12:51 -07:00
Owen Pan
3e86cc4b86 [clang-format][NFC] Simplify the logic in a return statement 2023-10-22 13:46:32 -07:00
Omar Ahmed
7c15dd60ec [clang-format] Add space in placement new expression
Add AfterPlacementNew option to SpaceBeforeParensOptions to have more
control on placement new expressions.

Fixes #41501
Relates to #54703

Differential Revision: https://reviews.llvm.org/D127270
2023-10-20 03:16:28 -07:00
Owen Pan
0ae998c4ae
[clang-format] Fix a bug in annotating TrailingReturnArrow (#69249)
Skip TrailingAnnotation when looking for TrailingReturnArrow.

Fixes #69234.
2023-10-18 14:04:51 -07:00
Jared Grubb
7f881a2abe [clang-format] Treat AttributeMacro more like __attribute__
There are two parts to this fix:
- Annotate the paren after an AttributeMacro as an AttributeLParen.
- Treat an AttributeMacro-without-paren the same as one with a paren.

I added a new test-case to differentiate a macro that is or is-not an
AttributeMacro; also handled whether ColumnLimit is set to infinite (0) or a
finite value, as part of this patch is in ContinuationIndenter.

Closes #68722.

Differential Revision: https://reviews.llvm.org/D145262
2023-10-15 15:58:24 -07:00
Owen Pan
6c7cf74a75 Revert "[clang-format] Treat AttributeMacro more like __attribute__"
This reverts commit 6f46bcc609f14121e6942763ba9871f98541ea0e.
2023-10-15 15:52:17 -07:00