[PATCH] D126358: clang-format][NFC] Refactor UnwrappedLineParser::parseBlock()
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 26 13:57:06 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5bf44aa434ff: [clang-format][NFC] Refactor UnwrappedLineParser::parseBlock() (authored by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126358/new/
https://reviews.llvm.org/D126358
Files:
clang/lib/Format/UnwrappedLineParser.cpp
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -871,30 +871,33 @@
return IfKind;
}
- if (SimpleBlock && !KeepBraces) {
+ auto RemoveBraces = [=]() mutable {
+ if (KeepBraces || !SimpleBlock)
+ return false;
assert(Tok->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace));
assert(FormatTok->is(tok::r_brace));
+ const bool WrappedOpeningBrace = !Tok->Previous;
+ if (WrappedOpeningBrace && FollowedByComment)
+ return false;
const FormatToken *Previous = Tokens->getPreviousToken();
assert(Previous);
- if (Previous->isNot(tok::r_brace) || Previous->Optional) {
- assert(!CurrentLines->empty());
- const FormatToken *OpeningBrace = Tok;
- if (!Tok->Previous) { // Wrapped l_brace.
- if (FollowedByComment) {
- KeepBraces = true;
- } else {
- assert(Index > 0);
- --Index; // The line above the wrapped l_brace.
- OpeningBrace = nullptr;
- }
- }
- if (!KeepBraces && mightFitOnOneLine(CurrentLines->back()) &&
- (Tok->is(TT_ElseLBrace) ||
- mightFitOnOneLine((*CurrentLines)[Index], OpeningBrace))) {
- Tok->MatchingParen = FormatTok;
- FormatTok->MatchingParen = Tok;
- }
+ if (Previous->is(tok::r_brace) && !Previous->Optional)
+ return false;
+ assert(!CurrentLines->empty());
+ if (!mightFitOnOneLine(CurrentLines->back()))
+ return false;
+ if (Tok->is(TT_ElseLBrace))
+ return true;
+ if (WrappedOpeningBrace) {
+ assert(Index > 0);
+ --Index; // The line above the wrapped l_brace.
+ Tok = nullptr;
}
+ return mightFitOnOneLine((*CurrentLines)[Index], Tok);
+ };
+ if (RemoveBraces()) {
+ Tok->MatchingParen = FormatTok;
+ FormatTok->MatchingParen = Tok;
}
size_t PPEndHash = computePPHash();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126358.432379.patch
Type: text/x-patch
Size: 2002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220526/c55302d9/attachment.bin>
More information about the cfe-commits
mailing list