Commit Graph

3326 Commits

Author SHA1 Message Date
XDeme
8097a5d37b [clang-format] Fix operator overload inconsistency in BreakAfterAttributes: Always (#74943)
Fixes llvm/llvm-project#74901
2023-12-22 23:02:47 -08: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
Ilya Biryukov
efeb546865 [clang-format] Add common attribute macros to Google style (#76239)
We have found that 199fc973ce regresses
formatting of our codebases because we do not properly configure the
names of attribute macros.

`GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases
so it is reasonable to include them by default to avoid the need for
extra configuration in every Google repository.
2023-12-22 15:07:43 +01:00
Ilya Biryukov
d03beb9419 [clang-format] Do not break on JS fields like on goto labels (#76233)
This regressions was introduced in
70d7ea0ceb.
The commit moved some code and correctly picked up an explicit check for
not running on Verilog.
However, the moved code also never ran for JavaScript and after the
commit we run it there and
this causes the wrong formatting of:

```js
export type Params = Config&{
  columns: Column[];
};
```
into
```js
export type Params = Config&{
columns:
  Column[];
};
```
2023-12-22 14:41:38 +01:00
Owen Pan
401f0396c3 [clang-format] Fix a bug in IndentExternBlock: NoIndent (#75731)
Fixes #36620.
Fixes #75719.
2023-12-17 15:07:11 -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
Owen Pan
3791b3fca6 [clang-format][NFC] Clean up the driver and getStyle() in Format.cpp (#74794) 2023-12-08 15:23:01 -08:00
Owen Pan
b683709ea6 [clang-format] Fix a possible crash in AlignAfterOpenBracket: BlockIndent 2023-12-06 17:40:41 -08:00
Owen Pan
e1a4b0032f [clang-format] Handle merging functions containing only a block comment (#74651)
Fixed #41854.
2023-12-06 16:56:22 -08:00
Owen Pan
1241b5b05b [clang-format][NFC] Refactor getting first/last non-comment of line (#74570) 2023-12-06 11:45:41 -08:00
Owen Pan
924f6ca1bd [clang-format] Remove duplicates in @property using std::set (#74235)
Re-implement ObjCPropertyAttributeOrder using std::set for sorting and
removing duplicates. (We can't use llvm::SmallSet because it's
unordered.)
2023-12-04 16:33:20 -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
Jared Grubb
c45a66ecd4 [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes
Add a style option to specify the order that property attributes should
appear in ObjC property declarations (property attributes are things like
`nonatomic, strong, nullable`).

Closes #71323.

Differential Revision: https://reviews.llvm.org/D150083
2023-12-01 17:41:30 -08:00
Owen Pan
5c60e2ce78 [clang-format][NFC] Reformat source code with clang-format style 2023-11-30 20:19:30 -08:00
Emilia Kond
a112921d88 [clang-format] Don't skip stringizing when determining brace kind (#73886)
PR #69473 introduced skipping PP directives when determining the brace
kind of an lbrace. However, it did so by skipping to the end of the line
when encountering a hash character. This means it also skipped to the
end of line when encountering a macro stringizing operator, which,
unlike PP directives, don't have effect until the end of line.

This led to cases where the rbrace could be completely skipped if it was
on the same line as a stringizing operator.

This patch skips hash characters if we're already in a PP directive, as
you can't define a macro inside of a macro

Fixes https://github.com/llvm/llvm-project/issues/72662
2023-11-30 21:26:39 +02:00
Owen Pan
bbae59ae71 [clang-format] Finalize children after formatting them (#73753)
This would also fix the overlapping replacements below:
```
$ clang-format
 a(
 #else
 #endif
) = []() {      
)}
The new replacement overlaps with an existing replacement.
New replacement: <stdin>: 38:+7:"
"
Existing replacement: <stdin>: 38:+7:" "
```
Fixed #73487.
2023-11-29 12:56:05 -08:00
Owen Pan
4c17452076 [clang-format][NFC] Extend isProto() to also cover LK_TextProto (#73582) 2023-11-29 12:52:01 -08:00
sstwcw
9fa2d74be4 [clang-format] Indent Verilog case statements with comments (#71353)
If a line contains a comment outside of (fake) parentheses, the part
following it is indented according to `CurrentState.Indent`. A Verilog
case label and the statement that follows are broken with
mustBreakBefore. So the part that follows the case label needs some
special handling. Previously, that variable was left out. So the
indentation was wrong when there was a comment.

old:

```Verilog
case (data)
  16'd0:
    result = //
        10'b0111111111;
endcase
case (data)
  16'd0:
    //

  //
  result = //
  10'b0111111111;
endcase
```

new:

```Verilog
case (data)
  16'd0:
    result = //
        10'b0111111111;
endcase
case (data)
  16'd0:
    //

    //
    result = //
        10'b0111111111;
endcase
```
2023-11-29 15:19:13 +00: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
a369a5946f [clang-format] Fix a bug in formating #define A x: (#73220)
Fixed #70789.
2023-11-26 16:20:19 -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
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
e16a8344d0 [clang-format][NFC] Skip alignArrayInitializers() for 1-row matrices (#72166) 2023-11-19 14:58:44 -08:00
Owen Pan
f603369964 [clang-format][NFC] Remove a redundant isLiteral() call 2023-11-17 18:18:49 -08:00
Owen Pan
5679f5515b [clang-format] Fix crashes in AlignArrayOfStructures (#72520)
Fixed #54815.
Fixed #55269.
Fixed #55493.
Fixed #68431.
2023-11-17 14:35:30 -08:00
Owen Pan
f0ad9ea36a [clang-format] Handle lambdas in QualifierAlignment (#72456)
Fixed #62780.
2023-11-16 15:00:09 -08:00
Owen Pan
eaff083035 [clang-format] Fix more bugs in isStartOfName() (#72336)
Fixed #72264.
2023-11-15 14:31:30 -08:00
Owen Pan
b04664be6f [clang-format] Handle constrained auto in QualifierAlignment (#72251)
Fixed #69610.
2023-11-15 14:28:37 -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
fff993b7cf [clang-format] Fix a bug in aligning comments in vector of structs (#72099)
Fixed #71825.
2023-11-13 13:41:01 -08:00
Owen Pan
a699ab5adb [clang-format][NFC] Remove redundant Block/Line Comment in is() 2023-11-13 02:14:37 -08:00
Owen Pan
a533b76468 [clang-format][NFC] Simplify parseBracedList() (#72010) 2023-11-12 15:55:06 -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
Kazu Hirata
651c502fc8 [clang] Stop including llvm/ADT/DenseSet.h (NFC)
Identified with clangd.
2023-11-11 22:25:48 -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 f7bbb58690 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 5c36f4332d 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
Emilia Kond
063e3fe648 [clang-format] Skip PP directives when determining brace kind (#69473)
Pull request #65409 changed the brace kind heuristic to not treat a
preprocessor if directive as a in statement, however, this caused some
regressions.

If the contents of a brace don't immediately determine the brace kind,
the heuristic will look at the characters immediately before and after
the closing brace to determine the brace type.

Unfortunately, if the closing brace was preceded by a preprocessor
directive, for example `#endif`, the preceding token was `endif`, seen
as just an identifier, so the braces were understood as a braced list.

This patch fixes this behaviour by skipping all preprocessor directives
when calculating brace types. Comments were already being skipped, so
now preprocessor lines are skipped alongside comments.

Fixes https://github.com/llvm/llvm-project/issues/68404
2023-11-03 05:51:20 +02:00
Owen Pan
2c2fb8e10a [clang-format] Treat empty for/while loops as short loops (#70768)
A for/while loop with only a semicolon as its body should be treated as
an empty loop.

Fixes #61708.
2023-11-02 14:09:00 -07: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