Skip to content

Commit 943db67

Browse files
authored
[clang-format][NFC] Add getNextNonComment() to FormatTokenSource (#87868)
1 parent 15d11a4 commit 943db67

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

clang/lib/Format/FormatTokenSource.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ class FormatTokenSource {
7272
// getNextToken() -> a1
7373
// getNextToken() -> a2
7474
virtual FormatToken *insertTokens(ArrayRef<FormatToken *> Tokens) = 0;
75+
76+
[[nodiscard]] FormatToken *getNextNonComment() {
77+
FormatToken *Tok;
78+
do {
79+
Tok = getNextToken();
80+
assert(Tok);
81+
} while (Tok->is(tok::comment));
82+
return Tok;
83+
}
7584
};
7685

7786
class IndexedTokenSource : public FormatTokenSource {

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
427427
break;
428428
case tok::kw_default: {
429429
unsigned StoredPosition = Tokens->getPosition();
430-
FormatToken *Next;
431-
do {
432-
Next = Tokens->getNextToken();
433-
assert(Next);
434-
} while (Next->is(tok::comment));
430+
auto *Next = Tokens->getNextNonComment();
435431
FormatTok = Tokens->setPosition(StoredPosition);
436432
if (Next->isNot(tok::colon)) {
437433
// default not followed by ':' is not a case label; treat it like
@@ -497,10 +493,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
497493
assert(Tok->is(tok::l_brace));
498494

499495
do {
500-
FormatToken *NextTok;
501-
do {
502-
NextTok = Tokens->getNextToken();
503-
} while (NextTok->is(tok::comment));
496+
auto *NextTok = Tokens->getNextNonComment();
504497

505498
if (!Line->InMacroBody && !Style.isTableGen()) {
506499
// Skip PPDirective lines and comments.

0 commit comments

Comments
 (0)