Author: owenca Date: 2022-04-22T09:21:28-07:00 New Revision: c9e7eec7bc41e9cb86e01acd5c91faa5c9ee0bf1
URL: https://github.com/llvm/llvm-project/commit/c9e7eec7bc41e9cb86e01acd5c91faa5c9ee0bf1 DIFF: https://github.com/llvm/llvm-project/commit/c9e7eec7bc41e9cb86e01acd5c91faa5c9ee0bf1.diff LOG: [clang-format][NFC] Use isComment() in setCommentLineLevels() Also replace an unnecessary check with assert() in the unwrapped line parser. Differential Revision: https://reviews.llvm.org/D124215 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineParser.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 5f3b434dba956..cb950f2b2198d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2505,17 +2505,10 @@ void TokenAnnotator::setCommentLineLevels( const AnnotatedLine *NextNonCommentLine = nullptr; for (AnnotatedLine *Line : llvm::reverse(Lines)) { assert(Line->First); - bool CommentLine = true; - for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) { - if (!Tok->is(tok::comment)) { - CommentLine = false; - break; - } - } // If the comment is currently aligned with the line immediately following // it, that's probably intentional and we should keep it. - if (NextNonCommentLine && CommentLine && + if (NextNonCommentLine && Line->isComment() && NextNonCommentLine->First->NewlinesBefore <= 1 && NextNonCommentLine->First->OriginalColumn == Line->First->OriginalColumn) { diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 018a7ae3ee794..1e2f4d6761e1e 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2470,8 +2470,9 @@ FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind, Kind = IfStmtKind::IfElseIf; addUnwrappedLine(); } else if (FormatTok->is(tok::kw_if)) { - FormatToken *Previous = Tokens->getPreviousToken(); - const bool IsPrecededByComment = Previous && Previous->is(tok::comment); + const FormatToken *Previous = Tokens->getPreviousToken(); + assert(Previous); + const bool IsPrecededByComment = Previous->is(tok::comment); if (IsPrecededByComment) { addUnwrappedLine(); ++Line->Level; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits