aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/WhitespaceManager.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-06[clang-format][NFC] Replace size() with empty() (#147164)Owen Pan1-4/+4
2025-04-13[clang-format] Fix a bug in AlignConsecutiveDeclarations (#135516)Owen Pan1-7/+2
Fix #109768
2024-10-23[clang-format] Add KeepFormFeed option (#113268)Owen Pan1-10/+13
Closes #113170.
2024-10-06[clang-format] Add AlignFunctionDeclarations to AlignConsecutiveDeclarations ↵Brad House1-1/+1
(#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-08-27[clang-format] Fix misalignments of pointers in angle brackets (#106013)Owen Pan1-1/+3
Fixes #105898.
2024-07-11[clang-format] Fix a bug in TCAS_Leave using tabs for indentation (#98427)Owen Pan1-1/+1
Fixes #92530.
2024-05-27[clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (#93402)Owen Pan1-11/+18
Closes #92999.
2024-05-06[clang-format] Handle Java switch expressions (#91112)Owen Pan1-8/+14
Also adds AllowShortCaseExpressionOnASingleLine option and AlignCaseArrows suboption of AlignConsecutiveShortCaseStatements. Fixes #55903.
2024-04-28[clang-format] Set Change.TokenLength to ColumnWidth (#90378)Owen Pan1-4/+7
Fixes #37705. Fixes #47333. Fixes #47624. Fixes #58850. Fixes #75929. Fixes #87885. Fixes #89916.
2024-04-27[clang-format][NFC] Don't repeat Changes[i]/Changes[i - 1]Owen Pan1-21/+18
2024-04-06[clang-format][NFC] Use `is` instead of `getType() ==`Owen Pan1-2/+1
2024-03-27[clang-format] Fix anonymous reference parameter with default value (#86254)rayroudc1-2/+3
When enabling alignment of consecutive declarations and reference right alignment, the needed space between `& ` and ` = ` is removed in the following use case. Problem (does not compile) ``` int a(const Test &= Test()); double b(); ``` Expected: ``` int a(const Test & = Test()); double b(); ``` Test command: ``` echo "int a(const Test& = Test()); double b();" | clang-format -style="{AlignConsecutiveDeclarations: true, ReferenceAlignment: Right}" ```
2024-03-24[clang-format] Fix a crash with AlignArrayOfStructures option (#86420)Owen Pan1-1/+1
Fixes #86109.
2024-03-22[clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. ↵Hirofumi Nakamura1-0/+6
(#86150) The option to specify the style of alignment of the colons inside TableGen's DAGArg.
2024-03-19Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"Owen Pan1-0/+3
This reverts commit b92d6dd704d789240685a336ad8b25a9f381b4cc. 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-16[clang-format][NFC] Delete 100+ redundant #include lines in .cpp filesOwen Pan1-3/+0
2024-02-27[clang-format] Add AlignConsecutiveTableGenDefinitions option. (#83008)Hirofumi Nakamura1-1/+8
To align TableGen consecutive definitions.
2024-02-26[clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (#82878)Hirofumi Nakamura1-3/+15
To align colons inside TableGen !cond operators.
2024-01-27[clang-format] Fix an issue reported by static analyzerOwen Pan1-1/+1
Fixes #79685.
2024-01-20[clang-format] Fix poor spacing in `AlignArrayOfStructures: Left` (#77868)XDeme1-5/+6
Fixes llvm/llvm-project#62904 `AlignArrayOfStructures: Left` combined with `SpacesInParentheses: true` causes the first cell of every row to have 1 additional space. We were only setting the first cell of the first row to be against the left brace, now every row will be against the left brace.
2024-01-12[clang-format] Handle possible crash in `getCells` (#77723)XDeme1-1/+3
Done as requested in llvm/llvm-project#77045 I have changed the test a bit, because since the root problem was fixed, the original test would possibly never crash.
2024-01-10[clang-format]: Split alignment of declarations around assignment (#69340)Gedare Bloom1-1/+8
Function pointers are detected as a type of declaration using FunctionTypeLParen. They are aligned based on rules for AlignConsecutiveDeclarations. When a function pointer is on the right-hand side of an assignment, the alignment of the function pointer can result in excessive whitespace padding due to the ordering of alignment, as the alignment processes a line from left-to-right and first aligns the declarations before and after the assignment operator, and then aligns the assignment operator. Injection of whitespace by alignment of declarations after the equal sign followed by alignment of the equal sign results in the excessive whitespace. Fixes #68079.
2023-11-17[clang-format] Fix crashes in AlignArrayOfStructures (#72520)Owen Pan1-1/+3
Fixed #54815. Fixed #55269. Fixed #55493. Fixed #68431.
2023-11-13[clang-format] Fix a bug in aligning comments in vector of structs (#72099)Owen Pan1-1/+1
Fixed #71825.
2023-11-10[clang-format][NFC] Refactor isPointerOrReferenceOwen Pan1-2/+1
2023-10-25[clang-format] Don't align comments over scopesBjörn Schäpers1-9/+44
We now stop aligning trailing comments on all closing braces, for classes etc. we even check for the semicolon between the comment and the brace. Fixes #67906.
2023-10-24Revert "[clang-format] Fix align consecutive declarations over function ↵Owen Pan1-1/+1
pointers" This reverts commit a84e0b4bdc9999872adbdaafbade8164b197784b. Fixes #68079.
2023-10-04[clang-format][NFC] AlignTokenSequence: Skip loop iterationBjörn Schäpers1-1/+4
When Shift is 0 there does nothing happen in the remainder of the loop, express that directly.
2023-10-04[clang-format][NFC] AlignTokenSequence: Rename Changes[i] to CurrentC…Björn Schäpers1-30/+31
…hange To improve debugging experience.
2023-10-04[clang-format][NFC] AlignTokens: Rename Changes[i] to CurrentChange (#68152)Björn Schäpers1-12/+13
To improve debugging experience.
2023-10-03Reland "[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead ↵Owen Pan1-5/+1
(#67955)" Reland 6a621ed8e4cb which failed on Windows but not macOS. The failures were caused by moving the annotation of the children from the top to the bottom of TokenAnnotator::annotate(), resulting in invalid lines including incomplete ones being skipped.
2023-10-03Revert "[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead ↵Owen Pan1-1/+5
(#67955)" This reverts commit 6a621ed8e4cb02bd55fe4a4a0254615576b70a55 as it caused buildbots to fail.
2023-10-03[clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (#67955)Owen Pan1-5/+1
After annotating constructors/destructors as FunctionDeclarationName in commit 08630512088, we have seen several issues because ctors/dtors had been treated differently than functions in aligning, wrapping, and indenting. This patch annotates ctors/dtors as CtorDtorDeclName instead and would effectively revert commit 0468fa07f87f, which is obsolete now. Fixed #67903. Fixed #67907.
2023-10-03[clang-format] Fix alignment in presence of template functions (#68029)Björn Schäpers1-2/+3
Fixes #68102.
2023-09-29[clang-format] Don't align ctors and dtors with other functions (#67618)Owen Pan1-1/+5
Fixed #67604.
2023-09-24[clang-format] Fix a bug in aligning trailing comments (#67221)Owen Pan1-1/+1
Fixes #67116.
2023-09-24[clang-format] Fix an assertion failure in Whitespace ManagerOwen Pan1-2/+2
2023-09-24[clang-format][NFC] Clean up alignTrailingComments() (#67218)Owen Pan1-47/+51
2023-09-05[clang-format] Break long string literals in C#, etc.sstwcw1-6/+56
Now strings that are too long for one line in C#, Java, JavaScript, and Verilog get broken into several lines. C# and JavaScript interpolated strings are not broken. A new subclass BreakableStringLiteralUsingOperators is used to handle the logic for adding plus signs and commas. The updateAfterBroken method was added because now parentheses or braces may be required after the parentheses or commas are added. In order to decide whether the added plus sign should be unindented in the BreakableToken object, the logic for it is taken out into a separate function shouldUnindentNextOperator. The logic for finding the continuation indentation when the option AlignAfterOpenBracket is set to DontAlign is not implemented yet. So in that case the new line may have the wrong indentation, and the parts may have the wrong length if the string needs to be broken more than once because finding where to break the string depends on where the string starts. The preambles for the C# and Java unit tests are changed to the newer style in order to allow the 3-argument verifyFormat macro. Some cases are changed from verifyFormat to verifyImcompleteFormat because those use incomplete code and the new verifyFormat function checks that the code is complete. The line in the doc was changed to being indented by 4 spaces, that is, the default continuation indentation. It has always been the case. It was probably a mistake that the doc showed 2 spaces previously. This commit was fist committed as 16ccba51072b. The tests caused assertion failures. Then it was reverted in 547bce36132a. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D154093
2023-08-31[clang-format] Fix AlignArrayOfStructures + Cpp11BracedListStyle=falseGalen Elias1-6/+9
Currently AlignArrayOfStructures=Left is hard coding setting Spaces to 0 for the token following the initial opening brace, but not touching Spaces for the subsequent lines, which leads to the array being misaligned. Additionally, it's not adding a space before the trailing } which is generally done when Cpp11BracedListStyle=false. I'm not exactly sure why this function needs to override the Spaces as it seems to generally already be set to either 0 or 1 according to the other formatting settings, but I'm going with an explicit fix where I just force the padding to 1 when Cpp11BracedListStyle=false. AlignArrayOfStructures=Right doesn't have any alignment problems, but isn't adding the expected padding around the braces either, so I'm giving that the same treatment. Fixes #57611. Differential Revision: https://reviews.llvm.org/D158795
2023-08-29[clang-format] Handle Template Arguments with AlignConsecutiveXXBjörn Schäpers1-0/+4
This fixes https://github.com/llvm/llvm-project/issues/64928. Differential-Revision: https://reviews.llvm.org/D158945
2023-08-24[clang-format][NFC] Replace !is() with isNot()Owen Pan1-6/+6
Differential Revision: https://reviews.llvm.org/D158571
2023-08-24Revert "[clang-format] Break long string literals in C#, etc."David Spickett1-56/+6
This reverts commit 16ccba51072bbc5ff4c66f91f939163dc91e5d96. This is failing across Linaro's bots e.g.: https://lab.llvm.org/buildbot/#/builders/188/builds/34393
2023-08-24[clang-format] Break long string literals in C#, etc.sstwcw1-6/+56
Now strings that are too long for one line in C#, Java, JavaScript, and Verilog get broken into several lines. C# and JavaScript interpolated strings are not broken. A new subclass BreakableStringLiteralUsingOperators is used to handle the logic for adding plus signs and commas. The updateAfterBroken method was added because now parentheses or braces may be required after the parentheses or commas are added. In order to decide whether the added plus sign should be unindented in the BreakableToken object, the logic for it is taken out into a separate function shouldUnindentNextOperator. The logic for finding the continuation indentation when the option AlignAfterOpenBracket is set to DontAlign is not implemented yet. So in that case the new line may have the wrong indentation, and the parts may have the wrong length if the string needs to be broken more than once because finding where to break the string depends on where the string starts. The preambles for the C# and Java unit tests are changed to the newer style in order to allow the 3-argument verifyFormat macro. Some cases are changed from verifyFormat to verifyImcompleteFormat because those use incomplete code and the new verifyFormat function checks that the code is complete. The line in the doc was changed to being indented by 4 spaces, that is, the default continuation indentation. It has always been the case. It was probably a mistake that the doc showed 2 spaces previously. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D154093
2023-08-02[clang-format] Supress aligning of trailing namespace commentsBjörn Schäpers1-6/+5
Fixes https://github.com/llvm/llvm-project/issues/57504. Differential Revision: https://reviews.llvm.org/D138263
2023-07-24[clang-format] Add AlignConsecutiveShortCaseStatementsGalen Elias1-19/+114
This adds a new AlignConsecutiveShortCaseStatements option in line with the existing AlignConsecutive* options , which when AllowShortCaseLabelsOnASingleLine is enabled will align the tokens after the case statement's colon. This also adds a AlignCaseColons option to allow aligning the case label colon itself rather than the token after it. Fixes #55475. Differential Revision: https://reviews.llvm.org/D151761
2023-07-24Revert "[clang-format] Add AlignConsecutiveShortCaseStatements"Owen Pan1-114/+19
This reverts commit 4ba00844174db562d2bd8b15dab6aac605eddf57.
2023-07-24Revert "Revert "[clang-format] Add AlignConsecutiveShortCaseStatements""Owen Pan1-19/+114
This reverts commit 4f093b31669a4f8e417259583141159586a05b28.
2023-07-24Revert "[clang-format] Add AlignConsecutiveShortCaseStatements"Owen Pan1-114/+19
This reverts commit 4ba00844174db562d2bd8b15dab6aac605eddf57 due to missing authorship.
2023-07-24[clang-format] Add AlignConsecutiveShortCaseStatementsOwen Pan1-19/+114
This adds a new AlignConsecutiveShortCaseStatements option in line with the existing AlignConsecutive* options , which when AllowShortCaseLabelsOnASingleLine is enabled will align the tokens after the case statement's colon. This also adds a AlignCaseColons option to allow aligning the case label colon itself rather than the token after it. Fixes #55475. Differential Revision: https://reviews.llvm.org/D151761