[PATCH] D158104: [clang-format][NFC] Simplify getFirstNonComment() in the annotator
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 18 13:24:09 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07181e289e3c: [clang-format][NFC] Simplify getFirstNonComment() in the annotator (authored by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158104/new/
https://reviews.llvm.org/D158104
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
Index: clang/lib/Format/TokenAnnotator.h
===================================================================
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -151,6 +151,11 @@
startsWith(tok::kw_export, tok::kw_namespace);
}
+ FormatToken *getFirstNonComment() const {
+ assert(First);
+ return First->is(tok::comment) ? First->getNextNonComment() : First;
+ }
+
FormatToken *First;
FormatToken *Last;
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4763,16 +4763,6 @@
!Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
}
-// Returns the first token on the line that is not a comment.
-static const FormatToken *getFirstNonComment(const AnnotatedLine &Line) {
- const FormatToken *Next = Line.First;
- if (!Next)
- return Next;
- if (Next->is(tok::comment))
- Next = Next->getNextNonComment();
- return Next;
-}
-
bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
const FormatToken &Right) const {
const FormatToken &Left = *Right.Previous;
@@ -5044,7 +5034,7 @@
return Right.HasUnescapedNewline;
if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
- auto FirstNonComment = getFirstNonComment(Line);
+ auto *FirstNonComment = Line.getFirstNonComment();
bool AccessSpecifier =
FirstNonComment &&
FirstNonComment->isOneOf(Keywords.kw_internal, tok::kw_public,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158104.551623.patch
Type: text/x-patch
Size: 1584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230818/9c5a563b/attachment-0001.bin>
More information about the cfe-commits
mailing list