Commit Graph

1304 Commits

Author SHA1 Message Date
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
684f27d37a [clang-format][NFC] Use is instead of getType() == 2024-04-06 01:51:45 -07:00
Owen Pan
a7f4576ff4 [clang-format] Fix a regression in annotating TrailingReturnArrow (#86624)
Fixes #86559.
2024-04-02 14:48:14 -07:00
Ameer J
13be0d4a34 [clang-format] Add BreakFunctionDefinitionParameters option (#84988)
This adds an option to break function definition parameters, putting
them on the next line after the function's opening paren.

This was a missing step towards allowing styles which require all
function definition parameters be on their own lines.

Closes #62963
2024-04-02 21:00:51 +02:00
Owen Pan
e766f87b92 [clang-format] Handle C++ Core Guidelines suppression tags (#86458)
Fixes #86451.
2024-03-27 21:22:57 -07:00
Owen Pan
47423e9827 [clang-format][NFC] Clean up IsQualifiedPointerOrReference in TokenAnnotator 2024-03-23 02:24:56 -07:00
Owen Pan
579dc7f844 [clang-forma] Support PointerAlignment for pointers to members (#86253)
Fixes #85761.
2024-03-23 02:03:45 -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
b2082a9817 Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"
This reverts commit b92d6dd704. See
github.com/llvm/llvm-project/commit/b92d6dd704d7#commitcomment-139992444

We should use a tool like Visual Studio to clean up the headers.
2024-03-19 21:28:22 -07:00
Owen Pan
6f31cf51df Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)"
This reverts c3a1eb6207 (and the related commit f3c5278efa) 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
scythris
8e5de66af3 [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (#85470)
This resolves an issue in clang-format where `new` and `delete` were
incorrectly formatted as keywords in C files. The fix modifies
`TokenAnnotator::spaceRequiredBetween` to handle `new` and `delete` when
used as identifiers for function pointers in structs in C code.
2024-03-17 21:06:32 +01:00
Owen Pan
b92d6dd704 [clang-format][NFC] Delete 100+ redundant #include lines in .cpp files 2024-03-16 22:24:11 -07:00
Owen Pan
d33d5630b2 [clang-format] Fix a bug in SpaceInEmptyBlock option (#85508)
Fixes #84695.
2024-03-16 14:48:51 -07: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
Jie Fu
83fe0b1382 [clang] Fix -Wunused-lambda-capture in TokenAnnotator.cpp (NFC)
llvm-project/clang/lib/Format/TokenAnnotator.cpp:2707:43:
error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
    auto IsQualifiedPointerOrReference = [this](FormatToken *T) {
                                          ^~~~
1 error generated.
2024-03-09 20:26:10 +08: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
051e910b8b [clang-format][NFC] Replace Style.isCpp() with IsCpp (#83533) 2024-03-02 12:57:24 -08:00
Emilia Kond
2e7cacfced [clang-format] Fix crash in TokenAnnotator (#82349)
The while loop on line 3814 can cause a segmentation fault getting the
Next field on a nullptr. This is because further down, on line 3823,
there is another for loop, which assigns Tok to Tok->Next in its
initializer. This for loop has a condition to check if the result of
that isn't null. If it is, the loop is skipped and we drop back out to
the outer loop, except, now Tok is null, and we try to dereference it
without checking first.

This patch adds a defensive check that returns if Tok->Next is null
before we make it to the second for loop.

Fixes https://github.com/llvm/llvm-project/issues/82328

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-02-22 20:22:05 +02: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
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:
- eaff083035 changed `isStartOfName` to fix problems inside
`#pragma`s, but this behavior changed formatting of attribute macros in
an undesirable way.
- efeb546865 changed Google format style
to fix some widely used attributes.

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

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

---------

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
d68826dfbd.

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 f603369964.
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