owenpan created this revision. Herald added projects: All, clang, clang-format. Herald added a subscriber: cfe-commits. Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay. owenpan requested review of this revision.
Repository: rG LLVM Github Monorepo 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,
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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits