[PATCH] D115060: [clang-format][NFC] Code Tidies in UnwrappedLineFormatter

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 16 23:47:23 PST 2022


HazardyKnusperkeks marked 5 inline comments as done.
HazardyKnusperkeks added inline comments.


================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:215
+    const auto &NextLine = *I[1];
+    const auto *PreviousLine = I != AnnotatedLines.begin() ? I[-1] : nullptr;
+    if (NextLine.Type == LT_Invalid || NextLine.First->MustBreakBefore)
----------------
owenpan wrote:
> I would move this line to just before handling empty record blocks below.
I'd rather keep the definitions close together.


================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:268-289
+        [this, B = AnnotatedLines.begin(), &NextLine,
+         TheLine](SmallVectorImpl<AnnotatedLine *>::const_iterator I) {
           if (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All)
             return true;
           if (Style.AllowShortFunctionsOnASingleLine >=
                   FormatStyle::SFS_Empty &&
+              NextLine.First->is(tok::r_brace))
----------------
owenpan wrote:
> I'd either leave this lambda alone or further simplify it as suggested here.
I'm no fan of capturing everything, but some things I've applied.


================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:406-417
+    if (PreviousLine && TheLine->First->is(tok::l_brace) &&
+        PreviousLine->First->is(tok::at) && PreviousLine->First->Next) {
+      tok::ObjCKeywordKind kwId =
+          PreviousLine->First->Next->Tok.getObjCKeywordID();
       if (kwId == clang::tok::objc_autoreleasepool ||
           kwId == clang::tok::objc_synchronized)
         return 0;
----------------
owenpan wrote:
> If you want, you can factor out `PreviousLine && TheLine->First->is(tok::l_brace)` and even combine the two `if` statements as they both return 0.
Kept the two cases apart for their comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115060/new/

https://reviews.llvm.org/D115060



More information about the cfe-commits mailing list