3239 Commits

Author SHA1 Message Date
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
8c681a929b [clang-format][NFC] Add a TypeScript test case
See #108530.
2024-12-14 19:42:43 -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
cb61a5e420
[clang-format] Fix an assertion failure in RemoveSemicolon (#117472)
Fixes #117290.
2024-12-07 16:47:35 -08:00
Owen Pan
aa2d084f9a [clang-format][NFC] Reformat testcases added in 0ff8b7916050 2024-11-23 06:31:14 -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
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
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
Owen Pan
1809d0fa1c
[clang-format] Insert a space between l_paren and ref-qualifier (#111465)
Fixes #111346.
2024-10-08 21:24:17 -07:00
Owen Pan
65688274b1
[clang-format][NFC] Clean up AlignConsecutiveStyle (#111285)
- Add a `CHECK_PARSE` for `AcrossComments`.
- Add a `CHECK_PARSE_NESTED_BOOL` for `AlignFunctionPointers`.
- Remove redundant statements.
- Clean up documentation.
2024-10-07 19:12:47 -07:00
Owen Pan
4b6e41b61e
[clang-format] Don't insert spaces after keywords in protobuf field o… (#111229)
…ptions

Fixes #54848.
2024-10-07 19:10:24 -07:00
Brad House
f0bd62d870
[clang-format] Add AlignFunctionDeclarations to AlignConsecutiveDeclarations (#108241)
Enabling AlignConsecutiveDeclarations also aligns function prototypes
or declarations.  This is often unexpected as typically function
prototypes, especially in public headers, don't use any padding.

Setting AlignFunctionDeclarations to false will skip this alignment.
It is by default set to true to keep compatibility with prior
versions to not make unexpected changes.

Fixes #74320
2024-10-06 17:46:43 -07:00
Owen Pan
b5f6689dc9
[clang-format] Annotate ::operator as FunctionDeclarationName (#111115)
Fixes #111011.
2024-10-04 18:20:21 -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
eaff3a7434
[clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)
Fixes #110879.
2024-10-03 18:57:50 -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
Owen Pan
688bc958bd
[clang-format] Add TemplateNames option to help parse C++ angles (#109916)
Closes #109912.
2024-10-02 18:10:56 -07:00
Owen Pan
98281da29f
[clang-format] Correctly annotate */& in if condition with braced init (#109505)
Fixes #109371.
2024-10-02 18:07:57 -07:00
Owen Pan
6ae14c0505
[clang-format] Annotate the l_paren of function pointer types (#109229)
Fixes #109146.
2024-10-02 18:01:25 -07:00
Gedare Bloom
df935ff4ec
[clang-format] Fix regression with BlockIndent of Braced Initializers (#108717)
Fixes #73584.
2024-09-22 14:31:19 -07:00
Owen Pan
c28e268c32
[clang-format] Correctly annotate pointer/reference in if statement (#109370)
Fixes #60146.
2024-09-20 18:13:21 -07:00
Owen Pan
4fd14b9a3a
[clang-format] Correctly annotate pointer/reference in range-for loop (#109361)
Fixes #109358.
2024-09-20 18:12:09 -07:00
Gedare Bloom
c9aa9d53b6
[clang-format] Fix regression in BAS_AlwaysBreak for-await (#108634)
Fixes #108589.
2024-09-18 19:44:09 -07:00
Owen Pan
4d18ce1dd2
[clang-format] Handle C-style cast of qualified type (#108929)
Fixes #102874.
2024-09-17 21:19:56 -07:00
Owen Pan
a8dd8f6302
[clang-format] Fix a bug in SpacesInParens InConditionalStatements (#108797)
Fixes #64416.
2024-09-17 21:17:30 -07:00
Owen Pan
7153a4bbf6
[clang-format] Reimplement InsertNewlineAtEOF (#108513)
Fixes #108333.
2024-09-17 21:16:20 -07:00
Owen Pan
ddbe6c412b
[clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (#108334) 2024-09-17 21:15:44 -07:00
kadir çetinkaya
04d71ea11b
[Format] Dont treat LBrace after extends/implements as initializer list (#108524)
This extends the fix in https://github.com/llvm/llvm-project/pull/106242
for other derived class types.
2024-09-16 20:18:39 +02:00
Owen Pan
94698369e9 [clang-format][NFC] Minor clean of TokenAnnotatorTest 2024-09-11 20:35:13 -07:00
Owen Pan
8168088f0a
[clang-format] Fix regressions in BAS_AlwaysBreak (#107506)
Fixes #107401.
Fixes #107574.
2024-09-11 19:34:54 -07:00
Owen Pan
bcd586b5ab
[clang-format] Fix a bug in annotating CastRParen (#107675)
Fixes #107568.
2024-09-07 16:56:28 -07:00
Owen Pan
616a8ce620
[clang-format] Correctly annotate braces in macro definition (#107352)
Also add a test case for #107096.

Fixes #106418.
2024-09-05 18:45:21 -07:00
Owen Pan
3449ed8dec Revert "[clang-format] Correctly annotate braces in macro definition (#106662)"
This reverts commit 0fa78b6c7bd43c2498700a98c47a02cf4fd06388 due to
regression.

Fixes #107096.
2024-09-03 22:54:50 -07:00
Owen Pan
812c96e8b9
[clang-format] Handle pointer/reference in macro definitions (#107074)
A macro definition needs its own scope stack in the annotator, so we add
the MacroBodyScopes stack and use ScopeStack to refer to it when in the
macro definition body.

Also, we need to have a scope type for a child block because its parent
line is parsed (and thus the scope type for the braces is popped off the
scope stack) before the lines in the child block are.

Fixes #99271.
2024-09-03 19:11:12 -07:00
Owen Pan
a27ff17034
[clang-format] Fix a regression in annotating ObjCBlockLParen (#107021)
Fixes #106994.
2024-09-03 19:07:14 -07:00
Owen Pan
0fa78b6c7b
[clang-format] Correctly annotate braces in macro definition (#106662)
Fixes #106418.
2024-09-02 01:40:13 -07:00
Owen Pan
e0f2368cde
[clang-format] Correctly annotate braces in ObjC square brackets (#106654)
See
https://github.com/llvm/llvm-project/pull/88238#issuecomment-2316954781.
2024-08-30 19:23:45 -07:00
Owen Pan
7579787e05
[clang-format] Correctly identify token-pasted record names (#106484)
See
https://github.com/llvm/llvm-project/pull/89706#issuecomment-2315549955.
2024-08-29 19:14:19 -07:00