1366 Commits

Author SHA1 Message Date
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
Jared Grubb
6f46bcc609 [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:44:57 -07:00
Owen Pan
42c564df2f [clang-format][NFC] Make InsertNewlineAtEOF a little more efficient 2023-10-09 01:09:45 -07:00
Owen Pan
7e856d1894 Reland "[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)"
Reland 6a621ed8e4cb which failed on Windows but not macOS.

The failures were caused by moving the annotation of the children from the
top to the bottom of TokenAnnotator::annotate(), resulting in invalid lines
including incomplete ones being skipped.
2023-10-03 22:26:48 -07:00
Owen Pan
d08fcc817e Revert "[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)"
This reverts commit 6a621ed8e4cb02bd55fe4a4a0254615576b70a55 as it caused
buildbots to fail.
2023-10-03 18:19:23 -07:00
Owen Pan
6a621ed8e4
[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)
After annotating constructors/destructors as FunctionDeclarationName in
commit 08630512088, we have seen several issues because ctors/dtors had
been treated differently than functions in aligning, wrapping, and
indenting.

This patch annotates ctors/dtors as CtorDtorDeclName instead and would
effectively revert commit 0468fa07f87f, which is obsolete now.

Fixed #67903.
Fixed #67907.
2023-10-03 18:02:09 -07:00
Owen Pan
c83d64f17a
[clang-format] Fix a bug in mis-annotating arrows (#67780)
Fixed #66923.
2023-10-02 00:38:26 -07:00
Owen Pan
151d0a4db3
[clang-format] Handle __attribute/__declspec/AttributeMacro consistently (#67518) 2023-09-29 12:03:08 -07:00
Owen Pan
67b99fa8ba
[clang-format] Correctly annotate keyword operator function name (#66904)
Fixes #66890.
2023-09-27 13:12:55 -07:00
Owen Pan
cef9f40cd4
[clang-format] Split TT_AttributeParen (#67396)
Replaced TT_AttributeParen with TT_AttributeLParen and
TT_AttributeRParen.
2023-09-26 20:27:15 -07:00
Owen Pan
6e608dc44b
[clang-format] Correctly annotate return type of function pointer (#66893)
Fixes #66857.
2023-09-26 14:17:49 -07:00
Owen Pan
38dd67c8b3 [clang-format][NFC] Minor cleanup of the parser and annotator 2023-09-25 22:20:02 -07:00
Owen Pan
a2046ca9af
[clang-format][NFC] Clean up signatures of some parser functions (#66569)
Removed TT_CompoundRequirementLBrace and parameters
CanContainBracedList and NextLBracesType.
2023-09-20 01:13:05 -07:00
Owen Pan
0b2c88eea7
[clang-format] Fix a bug in annotating && followed by * or & (#65933)
Fixes #65877.
2023-09-13 23:57:34 -07:00
Owen Pan
b908123c3c [clang-format][NFC] Minor cleanup of token annotator and test cases 2023-09-11 00:18:57 -07:00
Björn Schäpers
84e3fdfc65
[clang-format] BreakBeforeNoexceptSpecifier option added (#65808)
It really bugs me that it breaks to
``` c++
...) noexcept(
    noexcept(condition)...
```

This is a fix for people like me.
2023-09-09 22:31:58 +02:00