Commit Graph

695 Commits

Author SHA1 Message Date
Owen Pan
82e19318e6 [clang-format] Fix a bug in annotating lambda l_square (#95084)
Fixes #95072.
2024-06-12 00:56:48 -07:00
Owen Pan
798f2019a2 [clang-format] Don't format comments in SkipMacroDefinitionBody (#94425)
Fixes #94326.
2024-06-05 17:57:36 -07:00
Owen Pan
13f6797826 [clang-format] Handle AttributeMacros in parseRecord() (#94189)
Fixes #94184.
2024-06-03 12:55:10 -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
c5fdb5c34e [clang-format] Insert a space between a keyword and a literal (#93632)
Fixes #93603.
2024-05-30 22:13:00 -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
88d351e2e6 [clang-format] Fix a regression in annotating struct braces (#92352)
Fixes #92350.
2024-05-16 19:24:35 -07:00
Owen Pan
b11a6607cb [clang-format][NFC] Reformat with 18.1.5 2024-05-15 21:04:46 -07:00
Owen Pan
364f988d3f Reland "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"
Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-13 21:54:23 -07:00
Owen Pan
1fadb2b0c8 Revert "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"
This reverts commits e62ce1f884, 5cd280433e, and de641e2892 due to
buildbot failures.
2024-05-12 23:15:35 -07:00
Owen Pan
e62ce1f884 [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)
Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-10 19:27:02 -07:00
Owen Pan
6ce4c4ca2b [clang-format][NFC] Drop a redundant clang::format:: 2024-05-10 00:05:16 -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
Owen Pan
db0ed55333 [clang-format] Don't remove parentheses of fold expressions (#91045)
Fixes #90966.
2024-05-05 21:33:41 -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
d2af1ea81d [clang-format][NFC] Minor improvement to parseLabel() 2024-05-02 19:42:01 -07: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
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
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
943db678da [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (#87868) 2024-04-07 13:58:49 -07:00
Owen Pan
684f27d37a [clang-format][NFC] Use is instead of getType() == 2024-04-06 01:51:45 -07:00
Owen Pan
770202343e [clang-format][NFC] Rename kind to Kind 2024-04-05 22:17:50 -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
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
Owen Pan
b92d6dd704 [clang-format][NFC] Delete 100+ redundant #include lines in .cpp files 2024-03-16 22:24:11 -07:00
Owen Pan
84b5178124 [clang-format] Correctly parse C++11 attributes in enum specifiers (#85498)
Fixes #85476.
2024-03-16 13:51:36 -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
051e910b8b [clang-format][NFC] Replace Style.isCpp() with IsCpp (#83533) 2024-03-02 12:57:24 -08:00
r4nt
ddb4450a46 [ClangFormat] Fix indent in child lines within a macro argument. (#82523)
When reconstructing lines from a macro expansion, make sure that lines
at different levels in the expanded code get indented correctly as part
of the macro argument.
2024-02-23 13:18:00 +01:00
Owen Pan
4af24d4ab7 [clang-format] Don't remove parentheses in macro definitions (#81444)
Closes #81399.
2024-02-12 19:20:26 -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
Hirofumi Nakamura
df4ba00c7b [clang-format] Support of TableGen statements in unwrapped line parser (#78846)
Make TableGen's statements to be parsed considering their structure.
- Avoid to parse label
- Avoid class from being parsed as c++'s class
- Support if statement of the form `if <cond> then { ... }` 
- Support defset statement of the form `defset <type> <name> {}`

---------

Co-authored-by: Björn Schäpers <github@hazardy.de>
2024-01-22 21:35:01 +09:00
XDeme
a464e05109 [clang-format] Handle templated elaborated type specifier in function… (#77013)
… return type.

The behavior now is consistent with the non template version.
Enabled and updated old test.
2024-01-20 14:47:58 -08:00
Owen Pan
a7d7da6e45 [clang-format] Add SkipMacroDefinitionBody option (#78682)
Closes #67991.

See also: #70338

Co-authored-by: @tomekpaszek
2024-01-20 00:08:23 -08: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
XDeme
093e6bdd4b [clang-format] Fix crash involving array designators (#77045)
Fixes llvm/llvm-project#76716
Fixes parsing of `[0]{}`. Before this patch it was begin parsed as a
lambda, now it is correctly parsed as a designator initializer.
2024-01-10 19:46:11 -08: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
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
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