aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/QualifierAlignmentFixer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-06[clang-format][NFC] Replace size() with empty() (#147164)Owen Pan1-1/+1
2025-06-25[clang-format] Improve QualifierAlignment in guessing macros (#145468)Owen Pan1-7/+18
Fixes #145388
2025-05-31[Format] Remove unused includes (NFC) (#142296)Kazu Hirata1-3/+0
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-02-04[clang-format] Hanlde qualified type name for `QualifierAlignment` (#125327)Owen Pan1-1/+11
Fixes #125178.
2025-01-21[clang-format] Handle leading C++11 attribute in QualifierAlignment (#123690)Owen Pan1-1/+2
Fixes #123573.
2024-12-21[clang-format] Fix a crash in `QualifierAlignment: Right` (#120821)Owen Pan1-1/+1
Fixes #120793.
2024-05-13Reland "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"Owen Pan1-12/+10
Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-13[clang-format][NFC] Move LeftRightQualifierAlignmentFixer::is...() (#91930)Owen Pan1-6/+5
Move static member functions LeftRightQualifierAlignmentFixer::is...() out of the class so that #91712 can reland.
2024-05-12Revert "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"Owen Pan1-11/+13
This reverts commits e62ce1f8842c, 5cd280433e8e, and de641e289269 due to buildbot failures.
2024-05-12Revert "[clang-format] Fix buildbot failures"Owen Pan1-10/+8
This reverts commit 0869204cff22831d0bb19a82c99bf85e4deb4ae3, which caused a buildbot failure: https://lab.llvm.org/buildbot/#/builders/5/builds/43322
2024-05-11[clang-format] Fix buildbot failuresOwen Pan1-8/+10
This effectively reverts 5cd280433e8e and changes to QualifierFixerTest.cpp from e62ce1f8842c. Failed buidbots: https://lab.llvm.org/buildbot/#/builders/236/builds/11223 https://lab.llvm.org/buildbot/#/builders/239/builds/6968
2024-05-10[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)Owen Pan1-13/+11
Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-03-19Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"Owen Pan1-0/+6
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-19Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions ↵Owen Pan1-13/+16
(#84599)" This reverts c3a1eb6207d8 (and the related commit f3c5278efa3b) which makes cleanupAroundReplacements() no longer thread-safe.
2024-03-16[clang-format][NFC] Delete 100+ redundant #include lines in .cpp filesOwen Pan1-6/+0
2024-03-14Reland [clang-format][NFC] Eliminate the IsCpp parameter in all functions ↵Owen Pan1-16/+13
(#84599) Initialize IsCpp in LeftRightQualifierAlignmentFixer ctor.
2024-03-14Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions" ↵Mehdi Amini1-13/+16
(#85353) Reverts llvm/llvm-project#84599 This broke the presubmit bot.
2024-03-14[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)Owen Pan1-16/+13
2024-03-08[clang-format] Handle common C++ non-keyword types as such (#83709)Owen Pan1-12/+16
Fixes #83400.
2024-02-16[clang-format] Don't sort qualifiers across preprocessor directives (#81958)Owen Pan1-0/+2
Fixes #80579.
2023-11-16[clang-format] Handle lambdas in QualifierAlignment (#72456)Owen Pan1-3/+9
Fixed #62780.
2023-11-15[clang-format] Handle constrained auto in QualifierAlignment (#72251)Owen Pan1-0/+6
Fixed #69610.
2023-11-10[clang-format][NFC] Refactor isPointerOrReferenceOwen Pan1-1/+1
2023-08-30[clang-format][NFC] Reformat and fix file modeOwen Pan1-0/+0
Fix file mode errors introduced in 2c9372e78d7c and format errors in https://reviews.llvm.org/D155239.
2023-08-26[clang-format] Rename qualifier file comments (#64354)MyDeveloperDay1-2/+2
* [clang-format] rename the file comments to match the file name * [clang-format] rename the file comments to match the file name * Remove extraneous space * [clang-format] NFC remove EOF --------- Co-authored-by: paul_hoad <paul_hoad@amat.com>
2023-08-24[clang-format][NFC] Replace !is() with isNot()Owen Pan1-3/+3
Differential Revision: https://reviews.llvm.org/D158571
2023-07-11[clang-format][NFC] Remove redundant parentheses in the source codeOwen Pan1-1/+1
Reformat the source code with RemoveParentheses set to ReturnStatement.
2023-07-03[clang-format] Fixed bad performance with enabled qualifier fixer.Sedenion1-55/+5
This fixes github issue #57117: If the "QualifierAlignment" option of clang-format is set to anything else but "Leave", the "QualifierAlignmentFixer" pass gets enabled. This pass scales quadratically with the number of preprocessor branches, i.e. with the number of elements in TokenAnalyzer::UnwrappedLines. The reason is that QualifierAlignmentFixer::process() generates the UnwrappedLines, but then QualifierAlignmentFixer::analyze() calls LeftRightQualifierAlignmentFixer::process() several times (once for each qualifier) which again each time generates the UnwrappedLines. This commit gets rid of this double loop by registering the individual LeftRightQualifierAlignmentFixer passes directly in the top most container of passes (local variable "Passes" in reformat()). With this change, the original example in the github issue #57117 now takes only around 3s instead of >300s to format. Since QualifierAlignmentFixer::analyze() got deleted, we also no longer have the code with the NonNoOpFixes. This causes replacements that end up not changing anything to appear in the list of final replacements. There is a unit test to check that this does not happen: QualifierFixerTest.NoOpQualifierReplacements. However, it got broken at some point in time. So this commit fixes the test. To keep the behavior that no no-op replacements should appear from the qualifier fixer, the corresponding code from QualifierAlignmentFixer::analyze() was moved to the top reformat() function. Thus, is now done for **every** replacement of every formatting pass. If no-op replacements are a problem for the qualifier fixer, then it seems to be a good idea to filter them out always. See https://github.com/llvm/llvm-project/issues/57117#issuecomment-1546716934 for some more details. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D153228
2023-05-04[clang-format] Correctly limit formatted ranges when specifying qualifier ↵Colin Ogilvie1-1/+1
alignment The qualifier alignment fixer appeared to ignore any ranges specified for limiting formatting. This change ensures that it only formats affected lines to avoid unexpected changes. Fixes #54888. Differential Revision: https://reviews.llvm.org/D149643
2023-03-27[clang-format] Improve QualifierAlignmentAlexander Hederstaf1-164/+316
Qualifiers were not moved for non-pointer non-simple types. Add additional support for many special cases such as templates, requires clauses, long qualified names. Fixes https://github.com/llvm/llvm-project/issues/57154 and https://github.com/llvm/llvm-project/issues/60898 Reviewed By: MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D144709
2023-02-25[clang-format] Don't move qualifiers past pointers-to-memberEmilia Dreamer1-1/+4
Previously, given a pointer-to-member type such as `Foo const Bar::*`, clang-format would see the `const Bar::` part as a regular type name with scope resolution operators, and with `QualifierAlignment: Right` it would attempt to "fix" it, resulting in `Foo Bar::const *`, a syntax error. This patch no longer allows qualifiers to be moved across `::*`. Fixes https://github.com/llvm/llvm-project/issues/60898 Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D144537
2022-12-22[clang-format] Add 'friend' to QualifierOrderMicah Weston1-0/+1
For cases of defining friend functions, qualifier ordering can allow multiple positions for the 'friend' token. Closes #59450. Differential Revision: https://reviews.llvm.org/D139801
2022-12-09[Format] Use std::optional in QualifierAlignmentFixer.cpp (NFC)Kazu Hirata1-1/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-20Remove redundant initialization of Optional (NFC)Kazu Hirata1-1/+1
2022-05-26[clang-format] Fix QualifierAlignment with global namespace qualified types.Marek Kurdej1-20/+42
Fixes https://github.com/llvm/llvm-project/issues/55610. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D126096
2022-05-24[clang-format][NFC] Insert/remove braces in clang/lib/Format/owenca1-11/+20
Differential Revision: https://reviews.llvm.org/D126157
2022-04-01[clang-format] Fix a crash in qualifier alignmentOwen Pan1-0/+2
Related to #54513.
2022-03-28[clang-format] Don't format qualifiers in PPDirectiveowenca1-0/+2
Fixes #54513 Differential Revision: https://reviews.llvm.org/D122548
2022-03-05[clang-format] QualifierOrder does not reorder template argumentsmydeveloperday1-2/+18
https://github.com/llvm/llvm-project/issues/53981 Reorder the qualifiers inside the template argument. This should handle the simple cases of ``` <const T> <T const> ``` But only by relaxing that single letter capital variables are not possible macros Fixes: #53981 Reviewed By: HazardyKnusperkeks, curdeius Differential Revision: https://reviews.llvm.org/D120710
2022-02-24[clang-format] Fix QualifierOrder breaking the code with requires clause.Marek Kurdej1-3/+6
Fixes https://github.com/llvm/llvm-project/issues/53962. Given the config: ``` BasedOnStyle: LLVM QualifierAlignment: Custom QualifierOrder: ['constexpr', 'type'] ``` The code: ``` template <typename F> requires std::invocable<F> constexpr constructor(); ``` was incorrectly formatted to: ``` template <typename F> requires constexpr std::invocable<F> constructor(); ``` because we considered `std::invocable<F> constexpr` as a type, not recognising the requires clause. This patch avoids moving the qualifier across the boundary of the requires clause (checking `ClosesRequiresClause`). Reviewed By: HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D120309
2022-02-09[clang-format] Honour "// clang-format off" when using QualifierOrder.Marek Kurdej1-0/+4
Fixes https://github.com/llvm/llvm-project/issues/53643. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D119218
2022-02-08[clang-format] Comment unused parameters. NFC.Marek Kurdej1-3/+5
2022-02-08[clang-format] Fix typo. NFC.Marek Kurdej1-1/+1
2022-02-02[clang-format] Elide unnecessary braces. NFC.Marek Kurdej1-18/+9
2022-01-24[clang-format] Remove unused assignment. NFC.Marek Kurdej1-3/+1
Fixes scan-build reported warning: https://llvm.org/reports/scan-build/report-QualifierAlignmentFixer.cpp-analyzeRight-55-191910.html#EndPath.
2022-01-07[clang-format] Use range-for loops. NFC.Marek Kurdej1-7/+7
* Avoid if check on every element of the loop when printing symbols.
2022-01-06[clang-format] Fix a crash (assertion) in qualifier alignment when matching ↵mydeveloperday1-8/+11
template closer is null https://github.com/llvm/llvm-project/issues/53008 ``` template <class Id> using A = quantity /**/<kind<Id>, 1>; ``` the presence of the comment between identifier and template opener seems to be causing the qualifier alignment to fail Reviewed By: curdeius Fixes: #53008 Differential Revision: https://reviews.llvm.org/D116726
2021-11-19Make clang-format fuzz through Lexing with asserts enabled.Manuel Klimek1-5/+7
Makes clang-format bail out if an in-memory source file with an unsupported BOM is handed in instead of creating source locations that are violating clang's assumptions. In the future, we should add support to better transport error messages like this through clang-format instead of printing to stderr and not creating any changes.
2021-10-13[clang] Use llvm::is_contained (NFC)Kazu Hirata1-3/+2
2021-09-30[format] [docs] Fix typos and clarify QualifierAlignment/QualifierOrder ↵Marek Kurdej1-1/+1
documentation.