762 Commits

Author SHA1 Message Date
Owen Pan
c384ec431d
[clang-format] Add MacrosSkippedByRemoveParentheses option (#148345)
This allows RemoveParentheses to skip the invocations of function-like
macros.

Fixes #68354.
Fixes #147780.
2025-07-13 14:29:51 -07:00
Owen Pan
a5af874503 [clang-format][NFC] Use empty() instead of comparing size() to 0 or 1 2025-07-06 23:54:00 -07:00
Owen Pan
f2f17e563d
[clang-format][NFC] Remove \brief from comments (#145853)
This was done before in https://reviews.llvm.org/D46320
2025-06-26 19:14:34 -07:00
Owen Pan
9a894ae794
[clang-format] Parse JSON outermost l_brace as braced list brace (#143327)
See
https://github.com/llvm/llvm-project/issues/65400#issuecomment-2922181979.
2025-06-09 20:34:12 -07:00
Owen Pan
05c12b2284
[clang-format] Handle requires clause following a pointer type (#142893)
Fix #142818
2025-06-05 19:55:37 -07:00
Kazu Hirata
dfaa66281a
[Format] Remove unused includes (NFC) (#142296)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-31 19:00:34 -07:00
Owen Pan
6a1d3ea57d
[clang-format] Handle Java record (#139215)
Fix #62089
2025-05-09 18:05:16 -07:00
Owen Pan
79210feb29
[clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
Fix #138097
2025-05-02 19:20:42 -07:00
Owen Pan
d3506ee573
[clang-format] RemoveParentheses shouldn't remove empty parentheses (#138229)
Fix #138124
2025-05-02 19:19:39 -07:00
Owen Pan
ae07f48913
[clang-format] Correctly handle C# new modifier (#137430)
Fix #75815
2025-04-26 12:54:38 -07:00
Owen Pan
0af26149e2 [clang-format][NFC] Use UnwrappedLineParser::eof() whenever possible 2025-04-25 22:16:59 -07:00
Owen Pan
61d78d0c08
[clang-format] Correctly handle C# where clause (#137295)
Fix #74947
2025-04-25 13:08:16 -07:00
Owen Pan
82f1f5e5d4
[clang-format] Correctly identify include guards (#137112)
Fix #136814
2025-04-24 20:17:07 -07:00
Owen Pan
4f71655b64
[clang-format] Fix a bug in parsing C-style cast of lambdas (#136099)
Fix #135959
2025-04-22 21:07:31 -07:00
Owen Pan
9bd0c8726a
[clang-format] Fix a bug in BWACS_MultiLine (#135906)
Fix #51940
2025-04-16 18:48:10 -07:00
Owen Pan
09c8cfe219
[clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (#135466)
Also remove redundant name qualifiers format::, FormatStyle::, and
LanguageKind::.
2025-04-12 15:04:29 -07:00
sstwcw
f7617f7f90
[clang-format] Recognize TableGen paste operator on separate line (#133722)
Formatting this piece of code made the program crash.

```
class TypedVecListRegOperand<RegisterClass Reg, int lanes, string eltsize>
    : RegisterOperand<Reg, "printTypedVectorList<" # lanes # ", '"
                                                   # eltsize # "'>">;
```

The line starting with the `#` was treated as a separate preprocessor
directive line. Then the code dereferenced a null pointer when it tried
to continue parsing the first line that did not end in a semicolon.

Now the 2 problems are fixed.
2025-04-10 12:52:02 +00:00
Owen Pan
75cbb1f0fa
[clang-format][NFC] Add FormatToken::is(tok::ObjCKeywordKind) (#134973)
This allows simplification of code that checks if a token is an
Objective-C keyword.

Also, delete the following in
UnwrappedLineParser::parseStructuralElement():
- an else-after-break in the tok::at case
- the copypasted code in the tok::objc_autoreleasepool case
2025-04-09 17:49:26 -07:00
Owen Pan
d71ee7d230
[clang-format] Set C11 instead of C17 for LK_C (#134472)
Fix #134453
2025-04-05 13:35:45 -07:00
Owen Pan
4fe0d74275
[clang-format] Fix a bug in annotating braces (#134039)
Fix #133873
2025-04-02 20:08:56 -07:00
Owen Pan
2497945a95
[clang-format] Correctly annotate requires clause in && requires( (#132882)
Fix #132334
2025-03-25 08:19:43 -07:00
Owen Pan
7d4d8509cb
[clang-format] Don't remove parentheses separated from ellipsis by comma (#130471)
Also clean up `case tok::r_paren` in
`UnwrappedLineParser::parseParens()`.

Fix #130359
2025-03-10 19:42:54 -07:00
Owen Pan
3664b4e2d5
[clang-format] Remove special handling of C++ access specifiers in C (#129983)
This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9
because of
#129426.
2025-03-06 21:08:25 -08:00
Owen Pan
a6ccda28f7 [clang-format][NFC] Use better names for a couple of data members 2025-03-05 21:45:01 -08:00
Owen Pan
2ca0855059
[clang-format] Fix a bug in wrapping function return type (#129374)
Fixes #113766
2025-03-03 18:15:32 -08:00
Owen Pan
2d585ccecc
[clang-format] Fix a bug that changes keyword or to an identifier (#128410)
Fixes #105482
2025-02-26 18:14:26 -08:00
Owen Pan
0968df9c3a
[clang-format] Add the C language instead of treating it like C++ (#128287)
Closes #128120
2025-02-23 00:36:19 -08:00
Owen Pan
885382f437
[clang-format] Fix a bug in annotating braces (#127306)
Fixes #107616.
2025-02-16 19:30:33 -08:00
Owen Pan
6980d97946
[clang-format] Fix a bug in annotating ClassHeadName (#125326) 2025-02-01 20:20:43 -08:00
Owen Pan
1a25bea852
[clang-format] Add ClassHeadName to help annotating StartOfName (#124891)
Fixes #124574.
2025-01-30 19:33:15 -08:00
Owen Pan
14178deab0
[clang-format] Fix a crash on parsing requires clause (#125021)
Fixes #124921.
2025-01-30 18:03:04 -08:00
Owen Pan
9452ee4f75
[clang-format] Treat uppercase identifiers after struct as macros (#124397)
This restores the behavior before llvmorg-20-init.

Fixes #94184.
Fixes #117477.
Fixes #122690.
Fixes #123142.
2025-01-27 00:11:18 -08:00
Sirraide
33656932b0
[clang-format] Rename ExportBlockIndentation -> IndentExportBlock (#123493)
This renames the `ExportBlockIndentation` option and adds a config parse
test, as requested in #110381.
2025-01-21 14:13:13 +01:00
Sirraide
106c483a10
[clang-format] Improve brace wrapping and add an option to control indentation of export { ... } (#110381)
`export { ... }` blocks can get a bit long, so I thought it would make
sense to have an option that makes it so their contents are not indented
(basically the same argument as for namespaces).

This is based on the `NamespaceIndentation` option, except that there is
no option to control the behaviour of `export` blocks when nested because
nesting them doesn’t really make sense.

Additionally, brace wrapping of short `export { ... }` blocks is now controlled by the
`AllowShortBlocksOnASingleLine` option. There is no separate option just for `export`
blocks because you can just write e.g. `export int x;` instead of `export { int x; }`.

This closes #121723.
2025-01-19 00:26:40 +01:00
Owen Pan
a7bca1861b
[clang-format] Correctly annotate braces in macro definitions (#123279)
Fixes #123179.
2025-01-17 19:26:00 -08:00
Owen Pan
00934505d4
[clang-format] Add TT_CompoundRequirementLBrace for better annotation (#121539)
Also, add `ST_CompoundRequirement` to help annotating */&/&& in compound
requirement expressions as `TT_BinaryOperator`.

Fixes #121471.
2025-01-04 20:51:00 -08:00
Owen Pan
c1ea05eaf0
[clang-format] Don't break short macro call followed by l_paren (#121626)
Fixes #105658.
2025-01-04 16:24:41 -08:00
Owen Pan
44b83e81b5
[clang-format] Add TT_AfterPPDirective for better annotation (#121622)
For now, we only need to annotate the token after #error or #warning.

Fixes #117706.
2025-01-04 16:22:54 -08:00
Owen Pan
04610b901f
[clang-format][NFC] Replace SmallVectorImpl with ArrayRef (#121621) 2025-01-04 16:19:46 -08:00
Owen Pan
b1b60d4c1d
[clang-format] Fix a bug in annotating arrows after init braces (#119958)
Fixes #59066.
2024-12-18 12:44:53 -08:00
Owen Pan
54ca1c4212
[clang-format] Fix idempotent format of hash in macro body (#118513)
Fixes #118334.
2024-12-10 16:47:21 -08:00
sstwcw
0ff8b79160 [clang-format] Stop crashing on slightly off Verilog module headers (#116000)
This piece of code made the program crash.

```Verilog
function pkg::t get
    (int t = 2,
     int f = 2);
```

The way the code is supposed to be parsed is that UnwrappedLineParser
should identify the function header, and then TokenAnnotator should
recognize the result.  But the code in UnwrappedLineParser would
mistakenly not recognize it due to the `::`.  Then TokenAnnotator would
recognize the comma both as TT_VerilogInstancePortComma and
TT_VerilogTypeComma.  The code for annotating the instance port comma
used `setFinalizedType`.  The program would crash when it tried to set
it to another type.

The code in UnwrappedLineParser now recognizes the `::` token.

The are other cases in which TokenAnnotator would recognize the comma as
both of those types, for example if the `function` keyword is removed.
The type is now set using `setType` instead so that the program does not
crash.  The developer no longer knows why he used `setFinalizedType`
back then.
2024-11-20 04:49:58 +00:00
Owen Pan
6ca816f88d
[clang-format] Fix a regression in parsing switch in macro call (#114506)
Fixes #114408.
2024-11-01 18:47:50 -07:00
Owen Pan
d005be33ee
[clang-format] Handle C# goto case constructs (#113257)
Fixes #113256.
2024-10-22 18:39:32 -07:00
Emilia Kond
aea60ab94d
[clang-format] Make bitwise and imply requires clause (#110942)
This patch adjusts the requires clause/expression parser to imply a
requires clause if it is preceded by a bitwise and operator `&`, and
assume it is a reference qualifier. The justification is that bitwise
operations should not be used for requires expressions.

This is a band-aid fix. The real problems lie in the lookahead heuristic
in the same method. It may be worth it to rewrite that whole heuristic
to track more state in the future, instead of just blindly marching
forward across multiple unrelated definitions, since right now, the
definition following the one with the requires clause can influence
whether the heuristic chooses clause or expression.

Fixes https://github.com/llvm/llvm-project/issues/110485
2024-10-22 13:36:28 +03:00
Owen Pan
b5bcdb5cfa
[clang-format] Fix a crash on C# goto case (#113056)
Fixes #113011.
2024-10-21 18:50:13 -07:00
Owen Pan
67f576f31d
[clang-format] Handle template opener/closer in braced list (#112494)
Fixes #112487.
2024-10-17 19:56:09 -07:00
Iuri Chaer
0fba8381d2
[clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (#96804)
* Convert `ReflowComments` from boolean into a new `enum` which can take
on the value `RCS_Never`, `RCS_IndentOnly`, or `RCS_Always`. The first
one is equivalent to the old `false`, the third one is `true`, and the
middle one means that multiline comments should only have their
indentation corrected, which is what Doxygen users will want.
* Preserve backward compatibility while parsing `ReflowComments`.
2024-10-11 19:14:09 -07:00
Owen Pan
e5b05a51b8
[clang-format] Handle template closer followed by braces (#110971)
Fixes #110968.
2024-10-04 18:18:03 -07:00
Owen Pan
14e1fef736
[clang-format] Handle template closer followed by empty paretheses (#110408)
Fixes #109925.
2024-10-02 19:06:56 -07:00