3749 Commits

Author SHA1 Message Date
Owen Pan
3bd8b02aa0
[clang-format] Handle leading C++11 attribute in QualifierAlignment (#123690)
Fixes #123573.
2025-01-21 21:22:13 -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
Ander
e2402615a5
[clang-format] Fix option BreakBinaryOperations for operator >> (#122282)
Fixes #106228.
2025-01-17 19:45:10 -08:00
Owen Pan
a7bca1861b
[clang-format] Correctly annotate braces in macro definitions (#123279)
Fixes #123179.
2025-01-17 19:26:00 -08:00
sstwcw
fbef1f835f
[clang-format][NFC] Make formatting Verilog faster (#121139)
A regular expression was used in the lexing process. It made the program
take more than linear time with regards to the length of the input. It
looked like the entire buffer could be scanned for every token lexed.
Now the regular expression is replaced with code. Previously it took 20
minutes for the program to format 125 000 lines of code on my computer.
Now it takes 315 milliseconds.
2025-01-14 15:37:06 +00:00
Owen Pan
2ea34cdf2b
[clang-format] Stop fixing indentation on namespace closing brace (#122234)
Fixes #119790.
2025-01-09 19:10:15 -08:00
Owen Pan
064da423c3 [clang-format][NFC] Remove unneeded ST_ChildBlock in annotator
Also, remove redundant llvm:: in the annotator and return early for globstar
in matchFilePath().
2025-01-07 00:51:29 -08:00
Owen Pan
9e4774b934
[clang-format] Add LT_RequiresExpression and LT_SimpleRequirement (#121681)
The new line types help to annotate */&/&& in simple requirements as
binary operators.

Fixes #121675.
2025-01-06 01:46:17 -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
dmasloff
1c997feff1
[clang-format] Add option WrapNamespaceBodyWithNewlines (#106145)
It wraps the body of namespace with additional newlines, turning this code:
```
namespace N {
int function();
}
```
into the following:
```
namespace N {

int function();

}
```

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-01-02 21:52:01 -08:00
Owen Pan
1a0d0ae234
[clang-format] Add VariableTemplates option (#121318)
Closes #120148.
2025-01-01 18:24:56 -08:00
Owen Pan
cd239493c1
[clang-format] Support globstar in .clang-format-ignore (#121404)
Closes #110160.
Closes #114969.
2025-01-01 15:37:59 -08:00
Galen Elias
486ec4bd74
[clang-format] Add AllowShortNamespacesOnASingleLine option (#105597)
This fixes #101363 which is a resurrection of a previously opened but
never completed review: https://reviews.llvm.org/D11851

The feature is to allow code like the following not to be broken across
multiple lines:

```
namespace foo { class bar; }
namespace foo { namespace bar { class baz; } }
```

Code like this is commonly used for forward declarations, which are
ideally kept compact. This is also apparently the format that
include-what-you-use will insert for forward declarations.

Also, fix an off-by-one error in `CompactNamespaces` code. For nested
namespaces with 3 or more namespaces, it was incorrectly compacting
lines which were 1 or two spaces over the `ColumnLimit`, leading to
incorrect formatting results.
2024-12-30 01:28:03 -08:00
Owen Pan
141c544c03
[clang-format] Skip line splices when sorting C++ includes (#120680)
Fixes #109864.
2024-12-24 21:47:53 -08:00
天音あめ
cac6777ca1
[clang-format] Fix crashes when the macro expansion is empty (#119428)
An empty expansion should be valid, like `echo 'A()' | clang-format
--style='{Macros: [A(x)=x]}'`.

Fixes #119258.
2024-12-21 22:21:27 -08:00
Owen Pan
40acaa394f
[clang-format] Fix a crash in QualifierAlignment: Right (#120821)
Fixes #120793.
2024-12-21 17:16:29 -08:00
Owen Pan
fe2685303b [clang-format] Fix a crash caused by commit f03bf8c45f43 2024-12-18 19:41:50 -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
f03bf8c45f
[clang-format] Don't change breaking before CtorInitializerColon (#119522)
Don't change breaking before CtorInitializerColon with `ColumnLimit: 0`.

Fixes #119519.
2024-12-18 12:42:26 -08:00
Gedare Bloom
57c161a647
[clang-format] Detect nesting in template strings (#119989)
The helper to check if a token is in a template string scans too far
backward. It should stop if a different scope is found.

Fixes #107571
2024-12-17 08:05:01 -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
Gedare Bloom
46bf67d8fa
[clang-format] Reorder TokenAnnotator::canBreakBefore (#119044)
Move the checks related to breaking before right braces and right parens
earlier to avoid conflicting checks that prevent breaking based on the
left-hand token. This allows properly formatting declarations with
pointers and references at a minimum.
2024-12-09 21:05:28 -08:00
Owen Pan
6b1c357acc [clang-format] Add cmake target clang-format-help to update ClangFormat.rst 2024-12-07 22:41:50 -08:00
Owen Pan
cb61a5e420
[clang-format] Fix an assertion failure in RemoveSemicolon (#117472)
Fixes #117290.
2024-12-07 16:47:35 -08:00
Owen Pan
d76650bced [clang-format] Clean up cmake target clang-format-check-format 2024-12-07 00:19:11 -08:00
Owen Pan
f0b09dfd4c [clang-format] Add cmake target clang-format-style-options
This new custom target is for running dump_format_style.py to update
ClangFormatStyleOptions.rst if any of its dependencies changes.
2024-12-05 19:38:34 -08:00
Nikita Popov
3740fac0d4 Revert "[clang-format] Add cmake target clang-format-style-options for updating ClangFormatStyleOptions.rst (#111513)"
Breaks the build when docs are not enabled.

This reverts commit f7560ee97b7441eb3f5b2d0744aad857fafa5855.
This reverts commit 6bec1806c9cc90f6e72fc04698f4221c86c5f95e.
2024-12-05 12:45:44 +01:00
Owen Pan
6bec1806c9 [clang-format] Add plurals.txt to DEPENDS of style_options_depends 2024-12-04 23:02:02 -08:00
Iuri Chaer
f7560ee97b
[clang-format] Add cmake target clang-format-style-options for updating ClangFormatStyleOptions.rst (#111513)
* Create a new `clang-format-style-options` build target which
re-generates ClangFormatStyleOptions.rst from its source header files.

As discussed in
https://github.com/llvm/llvm-project/pull/96804#discussion_r1718407404

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-12-04 22:50:01 -08:00
Jim B
56ab56c857
[clang-format] Add support for .cjs as JavaScript file extension (#118188)
Node uses `.cjs` as an extension for 'common javascript' modules.
2024-12-03 09:03:51 -08:00
Owen Pan
6e57186c0c [clang-format][NFC] Clean up RemoveBraces, RemoveSemi, etc. 2024-11-25 21:11:15 -08:00
Owen Pan
0fe12a7db3 [clang-format][NFC] Remove a pointer in ContinuationIndenter 2024-11-25 00:35:50 -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
df232d46f5
[clang-format] Don't re-annotate CaseLabelColon as ConditionalExpr (#114639)
Fixes #114627.
2024-11-02 14:42:41 -07: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
78e7d9592d [clang-format][NFC] Use CLANG_SOURCE_DIR in CMakeLists 2024-10-24 18:36:58 -07:00
Owen Pan
786db636b9
[clang-format] Add KeepFormFeed option (#113268)
Closes #113170.
2024-10-23 19:55:32 -07:00
Owen Pan
d005be33ee
[clang-format] Handle C# goto case constructs (#113257)
Fixes #113256.
2024-10-22 18:39:32 -07:00
Owen Pan
b69ac31a3b
[clang-format] Use RemoveEmptyLinesInUnwrappedLines in clang-format s… (#113260)
…tyle
2024-10-22 18:37:43 -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
d989c2410e
[clang-format] Add RemoveEmptyLinesInUnwrappedLines option (#112325)
Fixes #111340.
2024-10-17 20:21:42 -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
Owen Pan
ee6468494e Revert "[clang-format] Correctly annotate */& in if condition with braced init (#109505)"
This reverts commit 98281da29f7e36e22ff1e20b9cfefda8c31dbe56 which caused a
regression.

Fixes #112176.
2024-10-14 19:29:44 -07:00
sstwcw
253ff32724
[clang-format] Stop crashing when formatting Verilog (#112043)
The part of the code for parsing Verilog module instantiations
dereferenced a pointer without checking for null pointer. The pointer
may be null if the input is not complete and a line starts with a comma.
2024-10-14 13:57:35 +00: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