[PATCH] D116316: [clang-format] Add an experimental option to remove optional control statement braces in LLVM C++ code
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 28 12:54:16 PST 2021
HazardyKnusperkeks added a comment.
In D116316#3211269 <https://reviews.llvm.org/D116316#3211269>, @curdeius wrote:
> Could you have a look at preceding reviews and see if there wasn't a similar patch before?
> I think that this option is a bit too limited.
> Only removing braces doesn't seem enough.
> Also, one should probably be able to decide when to add/remove them by e.g. setting the number of lines in what's considered short blocks.
There is D95168 <https://reviews.llvm.org/D95168>.
================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:478
+ if (HasOpeningBrace) {
+ return StatementCount == 1 && !PrecededByCommentOrPPDirective &&
+ /* !StartsWithBrace && */ !precededByCommentOrPPDirective();
----------------
This is very confusing a variable with the same name as the function.
================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2173
+void UnwrappedLineParser::KeepAncestorBraces() {
+ const int MaxNestingLevels = 2;
+ const int Size = NestedTooDeep.size();
----------------
constexpr or configurable?
================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2338
+ KeepAncestorBraces();
+ NestedTooDeep.push_back(false);
if (FormatTok->is(tok::l_brace)) {
----------------
I think it is worth to create a RAII type for that.
================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2937
// Parse the class body after the enum's ";" if any.
- parseLevel(/*HasOpeningBrace=*/true);
+ parseLevel();
nextToken();
----------------
I would like it better if you insert both arguments.
I don't really like default arguments.
================
Comment at: clang/lib/Format/UnwrappedLineParser.h:196
bool isOnNewLine(const FormatToken &FormatTok);
+ bool precededByCommentOrPPDirective();
+ void KeepAncestorBraces();
----------------
I find it nicely if the order of functions in the cpp is the same as in the hpp.
================
Comment at: clang/lib/Format/UnwrappedLineParser.h:197
+ bool precededByCommentOrPPDirective();
+ void KeepAncestorBraces();
----------------
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116316/new/
https://reviews.llvm.org/D116316
More information about the cfe-commits
mailing list